APIdia Launch Partner
Top Description Fields Constructors Methods
jdk.internal.net.http.quic.streams

pack-priv abstract Class StreamWriterQueue

extends Object
Class Inheritance
Known Direct Subclasses
jdk.internal.net.http.quic.streams.QuicSenderStreamImpl.StreamWriterQueueImpl
Imports
java.io.IOException, java.nio.ByteBuffer, java.util.concurrent.ConcurrentLinkedQueue, java.util.concurrent.locks.ReentrantLock, jdk.internal.net.http.common.Logger, .Utils, jdk.internal.net.http.quic.streams.QuicSenderStream.SendingStreamState

A class to handle the writing queue of a QuicSenderStream. This class maintains a queue of byte buffer containing stream data that has not yet been packaged for sending. It also keeps track of the max stream data value. It acts as a mailbox between a producer (typically a QuicStreamWriter), and a consumer (typically a jdk.internal.net.http.quic.QuicConnectionImpl). This class is abstract: a concrete implementation of this class must only implement wakeupProducer() and wakeupConsumer() which should wake up the producer and consumer respectively, when data can be polled or submitted from the queue.

Field Summary

Modifier and TypeField and Description
private static final int
BUFFER_SIZE

The amount of data that a StreamWriterQueue is willing to buffer.

private volatile long
private volatile long
private ByteBuffer
private final ReentrantLock
private volatile long
private final ConcurrentLinkedQueue<ByteBuffer>
private volatile boolean
private volatile long
private volatile long

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
public final long

Returns:

the amount of produced data which has not been consumed yet
available
()

Returns the amount of produced data which has not been consumed yet.

public final long

Returns:

the offset of the data consumed by the consumer
bytesConsumed
()

Returns the offset of the data consumed by the consumer.

public final long

Returns:

the offset of the data provided by the producer
bytesProduced
()

Returns the offset of the data provided by the producer.

pack-priv final void
public final boolean

Returns:

whether the producer is blocked due to flow control
consumerBlocked
()

Whether the consumer is blocked due to flow control.

public final long

Returns:

the credit of the consumer
consumerCredit
()

Returns the credit of the consumer.

protected abstract Logger
public final boolean

Returns:

true if the consumer has reached the end of this stream (equivalent to EOF)
isConsumerDone
()

Returns true if the consumer has reached the end of this stream (equivalent to EOF).

public final boolean

Returns:

true if the producer has reached the end of this stream (equivalent to EOF)
isProducerDone
()

Returns true if the producer has reached the end of this stream (equivalent to EOF).

protected final void
lock()

public final void
public final long

Returns:

the maximum offset that the peer is prepared to accept
maxStreamData
()

Returns the maximum offset that the peer is prepared to accept.

private void
offer(ByteBuffer
the buffer to queue
buffer
,
boolean
whether this is the last data for the stream
last
,
boolean
whether we should wait for the next submission before waking up the consumer
waitForMore
)

Queues a buffer in the writing queue.

public final ByteBuffer

Returns:

a ByteBuffer containing at most maxbytes, or null if no data is available or data is blocked by flow control.
poll
(int
the maximum number of bytes the consumer is prepared to consume.
maxbytes
)

This method is called by the consumer to poll data from the stream queue.

public final boolean

Returns:

whether the producer is blocked due to full buffers
producerBlocked
()

Whether the producer is blocked due to flow control.

public final long

Returns:

the credit of the producer
producerCredit
()

Returns the credit of the producer.

public final void
queue(ByteBuffer
a buffer containing data for the stream
buffer
)

This method is called by the producer to queue data to this stream.

public final long

Returns:

the amount of available data that can be sent with respect to flow control in this stream
readyToSend
()

Returns the amount of available data that can be sent with respect to flow control in this stream.

pack-priv final long

Returns:

-1 minus the error code that was supplied by the peer when requesting for stop sending
resetByPeer
()

Returns -1 minus the error code that was supplied by the peer when requesting for stop sending.

public final long

Returns:

the maximum offset that will be accepted by the consumer.
setMaxStreamData
(long
the maximum offset that will be accepted by the consumer
data
)

Updates the flow control credit for this queue.

protected final boolean
stopSending(long
the error code
errorCode
)

Called when a stop sending frame is received for this stream

protected abstract long

Returns:

the stream id this queue was created for
streamId
()

Returns the stream id this queue was created for.

public final long

Returns:

the stream size if known, -1 otherwise
streamSize
()

Returns the stream size if known, -1 otherwise.

public final void
submit(ByteBuffer
a buffer containing data for the stream
buffer
,
boolean
whether this is the last buffer that will ever be provided by the provided
last
)

This method is called by the producer to submit data to this stream.

protected abstract void
switchState(QuicSenderStream.SendingStreamState
the new state - typically SendingStreamState#DATA_SENT
dataSent
)

Called to switch the sending state when data has been sent.

protected final void
protected abstract void
wakeupConsumer()

This method is called to wake up the consumer when there is credit and data available for the consumer.

protected abstract void
wakeupProducer()

This method is called to wake up the producer when there is credit available for the producer.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

BUFFER_SIZEback to summary
private static final int BUFFER_SIZE

The amount of data that a StreamWriterQueue is willing to buffer. The queue will buffer excess data, but will not wake up the producer until the excess is consumed.

bytesConsumedback to summary
private volatile long bytesConsumed
bytesProducedback to summary
private volatile long bytesProduced
currentback to summary
private ByteBuffer current
lockback to summary
private final ReentrantLock lock
maxStreamDataback to summary
private volatile long maxStreamData
queueback to summary
private final ConcurrentLinkedQueue<ByteBuffer> queue
resetRequestedback to summary
private volatile boolean resetRequested
stopSendingback to summary
private volatile long stopSending
streamSizeback to summary
private volatile long streamSize

Constructor Detail

StreamWriterQueueback to summary
pack-priv StreamWriterQueue()

Method Detail

availableback to summary
public final long available()

Returns the amount of produced data which has not been consumed yet. This is independent of flow control.

API Note

The returned value is only weakly consistent: it is subject to race conditions if submit(ByteBuffer, boolean) or queue(ByteBuffer) or poll(int) are called concurrently by another thread.

Returns:long

the amount of produced data which has not been consumed yet

bytesConsumedback to summary
public final long bytesConsumed()

Returns the offset of the data consumed by the consumer.

API Note

The returned value is only weakly consistent: it is subject to race conditions if poll(int) is called concurrently by another thread.

Returns:long

the offset of the data consumed by the consumer

bytesProducedback to summary
public final long bytesProduced()

Returns the offset of the data provided by the producer.

API Note

The returned value is only weakly consistent: it is subject to race conditions if submit(ByteBuffer, boolean) or queue(ByteBuffer) are called concurrently by another thread.

Returns:long

the offset of the data provided by the producer

closeback to summary
pack-priv final void close()
consumerBlockedback to summary
public final boolean consumerBlocked()

Whether the consumer is blocked due to flow control.

Returns:boolean

whether the producer is blocked due to flow control

consumerCreditback to summary
public final long consumerCredit()

Returns the credit of the consumer.

Implementation Specification

This is equivalent to maxStreamData() - bytesConsumed().

Returns:long

the credit of the consumer

debugback to summary
protected abstract Logger debug()
isConsumerDoneback to summary
public final boolean isConsumerDone()

Returns true if the consumer has reached the end of this stream (equivalent to EOF). This is independent of flow control.

API Note

The returned value is only weakly consistent: it is subject to race conditions if submit(ByteBuffer, boolean) or poll(int) are called concurrently by another thread.

Returns:boolean

true if the consumer has reached the end of this stream (equivalent to EOF)

isProducerDoneback to summary
public final boolean isProducerDone()

Returns true if the producer has reached the end of this stream (equivalent to EOF). This is independent of flow control.

API Note

The returned value is only weakly consistent: it is subject to race conditions if submit(ByteBuffer, boolean) is called concurrently by another thread.

Returns:boolean

true if the producer has reached the end of this stream (equivalent to EOF)

lockback to summary
protected final void lock()
markResetback to summary
public final void markReset()
maxStreamDataback to summary
public final long maxStreamData()

Returns the maximum offset that the peer is prepared to accept.

API Note

The returned value is only weakly consistent: it is subject to race conditions if setMaxStreamData(long) is called concurrently by another thread.

Returns:long

the maximum offset that the peer is prepared to accept

offerback to summary
private void offer(ByteBuffer buffer, boolean last, boolean waitForMore) throws IOException

Queues a buffer in the writing queue.

Parameters
buffer:ByteBuffer

the buffer to queue

last:boolean

whether this is the last data for the stream

waitForMore:boolean

whether we should wait for the next submission before waking up the consumer

Exceptions
IOException:
if the stream was reset by peer
IllegalStateException:
if the last data was submitted already
pollback to summary
public final ByteBuffer poll(int maxbytes)

This method is called by the consumer to poll data from the stream queue. This method will return a ByteBuffer with at most maxbytes remaining bytes. The ByteBuffer may contain less bytes if not enough bytes are available, or if there is not enough credit to send maxbytes to the peer. Only stream credit is taken into account. Taking into account connection credit is the responsibility of the caller. If there is no credit, or if there is no data available, null is returned. When credit and data are available again, wakeupConsumer() is called to wake up the consumer.

API Note

This method increases the consumer offset. It must not be called concurrently by two different threads.

Implementation Note

If the producer was blocked due to full buffer before this method was called and the method removes enough of buffered data, wakeupProducer() is called.

Parameters
maxbytes:int

the maximum number of bytes the consumer is prepared to consume.

Returns:ByteBuffer

a ByteBuffer containing at most maxbytes, or null if no data is available or data is blocked by flow control.

producerBlockedback to summary
public final boolean producerBlocked()

Whether the producer is blocked due to flow control.

Returns:boolean

whether the producer is blocked due to full buffers

producerCreditback to summary
public final long producerCredit()

Returns the credit of the producer.

Implementation Specification

this is the desired buffer size minus the amount of data already buffered.

Returns:long

the credit of the producer

queueback to summary
public final void queue(ByteBuffer buffer) throws IOException

This method is called by the producer to queue data to this stream. The producer should not modify the provided buffer after this point. The provided buffer will be queued even if the produced data exceeds the maximum offset that the peer is prepared to accept.

API Note

The consumer will not be woken, even if enough credit is available. More data should be submitted using submit(ByteBuffer, boolean) in order to wake up the consumer.

Parameters
buffer:ByteBuffer

a buffer containing data for the stream

Exceptions
IOException:
if the stream was reset by peer
IllegalStateException:
if the last data was submitted already
readyToSendback to summary
public final long readyToSend()

Returns the amount of available data that can be sent with respect to flow control in this stream. . This does not take into account the global connection flow control.

Returns:long

the amount of available data that can be sent with respect to flow control in this stream

resetByPeerback to summary
pack-priv final long resetByPeer()

Returns -1 minus the error code that was supplied by the peer when requesting for stop sending.

API Note

a strictly negative value indicates that the stream was reset by the peer. The error code supplied by the peer can be obtained with the formula:

long errorCode = - (resetByPeer() + 1);
   
Returns:long

-1 minus the error code that was supplied by the peer when requesting for stop sending

setMaxStreamDataback to summary
public final long setMaxStreamData(long data)

Updates the flow control credit for this queue. The maximum offset that will be accepted by the consumer can only increase. Value that are less or equal to the current value of the max stream data are ignored.

Implementation Specification

If the consumer was blocked due to flow control before this method was called, and the new value of the max stream data allows to unblock the consumer, and data is available, wakeupConsumer() is called.

Parameters
data:long

the maximum offset that will be accepted by the consumer

Returns:long

the maximum offset that will be accepted by the consumer.

stopSendingback to summary
protected final boolean stopSending(long errorCode)

Called when a stop sending frame is received for this stream

Parameters
errorCode:long

the error code

streamIdback to summary
protected abstract long streamId()

Returns the stream id this queue was created for.

Returns:long

the stream id this queue was created for

streamSizeback to summary
public final long streamSize()

Returns the stream size if known, -1 otherwise.

API Note

The returned value is only weakly consistent: it is subject to race conditions if submit(ByteBuffer, boolean) is called concurrently by another thread.

Returns:long

the stream size if known, -1 otherwise

submitback to summary
public final void submit(ByteBuffer buffer, boolean last) throws IOException

This method is called by the producer to submit data to this stream. The producer should not modify the provided buffer after this point. The provided buffer will be queued even if the produced data exceeds the maximum offset that the peer is prepared to accept.

API Note

If sufficient credit is available, this method will wake up the consumer.

Parameters
buffer:ByteBuffer

a buffer containing data for the stream

last:boolean

whether this is the last buffer that will ever be provided by the provided

Exceptions
IOException:
if the stream was reset by peer
IllegalStateException:
if the last data was submitted already
switchStateback to summary
protected abstract void switchState(QuicSenderStream.SendingStreamState dataSent)

Called to switch the sending state when data has been sent.

Parameters
dataSent:QuicSenderStream.SendingStreamState

the new state - typically SendingStreamState#DATA_SENT

unlockback to summary
protected final void unlock()
wakeupConsumerback to summary
protected abstract void wakeupConsumer()

This method is called to wake up the consumer when there is credit and data available for the consumer.

wakeupProducerback to summary
protected abstract void wakeupProducer()

This method is called to wake up the producer when there is credit available for the producer.