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

public Class UniStreamPair

extends Object
Class Inheritance
Known Direct Subclasses
jdk.internal.net.http.http3.streams.QueuingStreamPair
Imports
java.io.IOException, java.nio.ByteBuffer, java.time.Duration, java.util.Objects, .Optional, java.util.concurrent.CompletableFuture, .CompletionException, java.util.concurrent.locks.ReentrantLock, java.util.function.Consumer, jdk.internal.net.http.Http3Connection, jdk.internal.net.http.common.Logger, .MinimalFuture, .SequentialScheduler, .Utils, jdk.internal.net.http.http3.streams.Http3Streams.StreamType, jdk.internal.net.http.quic.TerminationCause, .QuicConnection, .VariableLengthEncoder, jdk.internal.net.http.quic.streams.QuicReceiverStream, .QuicSenderStream, .QuicStream, .QuicStreamReader, .QuicStreamWriter

A class that models a pair of HTTP/3 unidirectional streams. This class implements a read loop that calls a receiver every time a ByteBuffer is read from the receiver part. The sender stream writer, when available, can be used to write to the sender part. The writerLoop is invoked whenever the writer part becomes unblocked, and writing can be resumed.

API Note

The creator of the stream pair (typically Http3Connection) is expected to complete the futureReceiverStream() completable future when the remote part of the stream pair is created by the remote peer. This class will not listen directly for creation of new remote streams.

The QueuingStreamPair class is a subclass of this class which implements a writer loop over an unbounded queue of ByteBuffer, and can be used when unlimited buffering of data for writing is not an issue.

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static interface

Field Summary

Modifier and TypeField and Description
pack-priv final Logger
pack-priv final UniStreamPair.StreamErrorHandler
private volatile CompletableFuture<QuicSenderStream>
private final Http3Streams.StreamType
private volatile QuicStreamWriter
private final SequentialScheduler
private final ReentrantLock
pack-priv volatile QuicStreamReader
pack-priv final SequentialScheduler
private final CompletableFuture<QuicReceiverStream>
private final QuicConnection
private final Consumer<ByteBuffer>
private final Http3Streams.StreamType
private final CompletableFuture<QuicStreamReader>
private final CompletableFuture<QuicStreamWriter>

Constructor Summary

AccessConstructor and Description
public
UniStreamPair(Http3Streams.StreamType
the HTTP/3 stream type
streamType
,
QuicConnection
the underlying Quic connection
quicConnection
,
Consumer<ByteBuffer>
the receiver callback
receiver
,
Runnable
the writer loop
writerLoop
,
UniStreamPair.StreamErrorHandler
the error handler invoked in case of read errors
errorHandler
,
Logger
the debug logger
logger
)

Creates a new UniStreamPair for the given HTTP/3 streamType.

pack-priv
UniStreamPair(Http3Streams.StreamType
the HTTP/3 stream type
streamType
,
QuicConnection
the underlying Quic connection
quicConnection
,
Consumer<ByteBuffer>
the receiver callback
receiver
,
UniStreamPair.StreamErrorHandler
the error handler invoked in case of read or write errors
errorHandler
,
Logger logger)

A constructor used by the QueuingStreamPair subclass

private
UniStreamPair(Http3Streams.StreamType localStreamType, Http3Streams.StreamType remoteStreamType, QuicConnection quicConnection, Consumer<ByteBuffer> receiver, Optional<Runnable> writerLoop, UniStreamPair.StreamErrorHandler errorHandler, Logger logger)

Method Summary

Modifier and TypeMethod and Description
private QuicStreamReader

Returns:

the peer control stream reader
connectReceiverStream
(QuicReceiverStream
the peer control stream
peerControlStream
)

Connects the peer control stream reader and schedules the receiving of the peer settings from the given peerControlStream.

public CompletableFuture<QuicReceiverStream>

Returns:

a completable future that will be completed with the receiver part of this stream pair after the remote HTTP/3 stream type has been read off the remote initiated stream
futureReceiverStream
()

Returns a completable future that will be completed with the receiver part of this stream pair after the remote HTTP/3 stream type has been read off the remote initiated stream.

public final CompletableFuture<QuicStreamReader>

Returns:

a completable future that will be completed with a reader connected to the receiver part of this stream pair after the remote HTTP/3 stream type has been read off the remote initiated stream
futureReceiverStreamReader
()

Returns a completable future that will be completed with a reader connected to the receiver part of this stream pair after the remote HTTP/3 stream type has been read off the remote initiated stream.

public CompletableFuture<QuicSenderStream>

Returns:

a completable future that will be completed with the sender part of this stream pair after the local HTTP/3 stream type has been queued for writing on the writing queue
futureSenderStream
()

Returns a completable future that will be completed with the sender part of this stream pair after the local HTTP/3 stream type has been queued for writing on the writing queue.

public final CompletableFuture<QuicStreamWriter>

Returns:

a completable future that will be completed with a writer connected to the sender part of this stream pair after the local HTTP/3 stream type has been queued for writing on the writing queue
futureSenderStreamWriter
()

Returns a completable future that will be completed with a writer connected to the sender part of this stream pair after the local HTTP/3 stream type has been queued for writing on the writing queue.

private static Http3Streams.StreamType
local(Http3Streams.StreamType localStreamType)

private CompletableFuture<QuicSenderStream>

Returns:

a completable future that will be completed with the local sender stream
localSenderStream
()

Creates the local sender stream and queues the stream type code in its writer queue.

public final Http3Streams.StreamType

Returns:

the HTTP/3 stream type of the sender part of the stream pair
localStreamType
()

Returns the HTTP/3 stream type of the sender part of the stream pair.

public QuicStreamWriter

Returns:

the writer connected to the sender part of this stream or null if no writer is connected yet
localWriter
()

Returns the writer connected to the sender part of this stream or null if no writer is connected yet.

pack-priv void
localWriterLoop()

This method is overridden by QueuingStreamPair to implement a writer loop for this stream.

public SequentialScheduler

Returns:

the scheduler for the local writer loop
localWriteScheduler
()

Returns the scheduler for the local writer loop.

private QuicSenderStream

Returns:

the given stream
openLocalStream
(QuicSenderStream
a new local unidirectional stream
stream
,
int
the code to queue up on the stream writer queue
code
)

Queues the given HTTP/3 stream type code on the given local unidirectional stream writer queue.

private void
private void
processPeerControlBytes(ByteBuffer
the bytes received
buffer
)

This method is called to process bytes received on the peer control stream.

private static Http3Streams.StreamType
remote(Http3Streams.StreamType localStreamType)

public final Http3Streams.StreamType

Returns:

the HTTP/3 stream type of the receiver part of the stream pair
remoteStreamType
()

Returns the HTTP/3 stream type of the receiver part of the stream pair.

private CompletableFuture<QuicStreamReader>

Returns:

a completable future that will be completed with the QuicStreamReader allowing to read from the remote control stream.
startReceiving
()

Schedules the receiving of server settings

private CompletableFuture<QuicStreamWriter>

Returns:

a completable future that will be completed with the QuicStreamWriter allowing to write to the local control stream
startSending
()

Schedules sending of client settings.

public void
stopSchedulers()

Stops schedulers.

pack-priv QuicStreamWriter

Returns:

a writer that can be safely used.
wrap
(QuicStreamWriter
the downstream writer
writer
)

Used by subclasses to redirect queuing of data to the subclass queue.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

debugback to summary
pack-priv final Logger debug
errorHandlerback to summary
pack-priv final UniStreamPair.StreamErrorHandler errorHandler
localSenderStreamCFback to summary
private volatile CompletableFuture<QuicSenderStream> localSenderStreamCF
localStreamTypeback to summary
private final Http3Streams.StreamType localStreamType
localWriterback to summary
private volatile QuicStreamWriter localWriter
localWriteSchedulerback to summary
private final SequentialScheduler localWriteScheduler
lockback to summary
private final ReentrantLock lock
peerReaderback to summary
pack-priv volatile QuicStreamReader peerReader
peerReadSchedulerback to summary
pack-priv final SequentialScheduler peerReadScheduler
peerReceiverStreamCFback to summary
private final CompletableFuture<QuicReceiverStream> peerReceiverStreamCF
quicConnectionback to summary
private final QuicConnection quicConnection
receiverback to summary
private final Consumer<ByteBuffer> receiver
remoteStreamTypeback to summary
private final Http3Streams.StreamType remoteStreamType
streamReaderCFback to summary
private final CompletableFuture<QuicStreamReader> streamReaderCF
streamWriterCFback to summary
private final CompletableFuture<QuicStreamWriter> streamWriterCF

Constructor Detail

UniStreamPairback to summary
public UniStreamPair(Http3Streams.StreamType streamType, QuicConnection quicConnection, Consumer<ByteBuffer> receiver, Runnable writerLoop, UniStreamPair.StreamErrorHandler errorHandler, Logger logger)

Creates a new UniStreamPair for the given HTTP/3 streamType. Valid values for streamType are StreamType#CONTROL, StreamType#QPACK_ENCODER, and StreamType#QPACK_DECODER.

This class implements a read loop that will call the given receiver whenever a ByteBuffer is received.

Writing to the sender part can be done by interacting directly with the writer. If the writer is blocked due to flow control, and becomes unblocked again, the writeLoop is invoked. The QueuingStreamPair subclass provides a convenient implementation of a writeLoop based on an unbounded queue of ByteBuffer.

Parameters
streamType:Http3Streams.StreamType

the HTTP/3 stream type

quicConnection:QuicConnection

the underlying Quic connection

receiver:Consumer<ByteBuffer>

the receiver callback

writerLoop:Runnable

the writer loop

errorHandler:UniStreamPair.StreamErrorHandler

the error handler invoked in case of read errors

logger:Logger

the debug logger

UniStreamPairback to summary
pack-priv UniStreamPair(Http3Streams.StreamType streamType, QuicConnection quicConnection, Consumer<ByteBuffer> receiver, UniStreamPair.StreamErrorHandler errorHandler, Logger logger)

A constructor used by the QueuingStreamPair subclass

Parameters
streamType:Http3Streams.StreamType

the HTTP/3 stream type

quicConnection:QuicConnection

the underlying Quic connection

receiver:Consumer<ByteBuffer>

the receiver callback

errorHandler:UniStreamPair.StreamErrorHandler

the error handler invoked in case of read or write errors

UniStreamPairback to summary
private UniStreamPair(Http3Streams.StreamType localStreamType, Http3Streams.StreamType remoteStreamType, QuicConnection quicConnection, Consumer<ByteBuffer> receiver, Optional<Runnable> writerLoop, UniStreamPair.StreamErrorHandler errorHandler, Logger logger)

Method Detail

connectReceiverStreamback to summary
private QuicStreamReader connectReceiverStream(QuicReceiverStream peerControlStream)

Connects the peer control stream reader and schedules the receiving of the peer settings from the given peerControlStream.

Parameters
peerControlStream:QuicReceiverStream

the peer control stream

Returns:QuicStreamReader

the peer control stream reader

futureReceiverStreamback to summary
public CompletableFuture<QuicReceiverStream> futureReceiverStream()

Returns a completable future that will be completed with the receiver part of this stream pair after the remote HTTP/3 stream type has been read off the remote initiated stream.

Returns:CompletableFuture<QuicReceiverStream>

a completable future that will be completed with the receiver part of this stream pair after the remote HTTP/3 stream type has been read off the remote initiated stream

futureReceiverStreamReaderback to summary
public final CompletableFuture<QuicStreamReader> futureReceiverStreamReader()

Returns a completable future that will be completed with a reader connected to the receiver part of this stream pair after the remote HTTP/3 stream type has been read off the remote initiated stream.

Returns:CompletableFuture<QuicStreamReader>

a completable future that will be completed with a reader connected to the receiver part of this stream pair after the remote HTTP/3 stream type has been read off the remote initiated stream

futureSenderStreamback to summary
public CompletableFuture<QuicSenderStream> futureSenderStream()

Returns a completable future that will be completed with the sender part of this stream pair after the local HTTP/3 stream type has been queued for writing on the writing queue.

Returns:CompletableFuture<QuicSenderStream>

a completable future that will be completed with the sender part of this stream pair after the local HTTP/3 stream type has been queued for writing on the writing queue

futureSenderStreamWriterback to summary
public final CompletableFuture<QuicStreamWriter> futureSenderStreamWriter()

Returns a completable future that will be completed with a writer connected to the sender part of this stream pair after the local HTTP/3 stream type has been queued for writing on the writing queue.

Returns:CompletableFuture<QuicStreamWriter>

a completable future that will be completed with a writer connected to the sender part of this stream pair after the local HTTP/3 stream type has been queued for writing on the writing queue

localback to summary
private static Http3Streams.StreamType local(Http3Streams.StreamType localStreamType)
localSenderStreamback to summary
private CompletableFuture<QuicSenderStream> localSenderStream()

Creates the local sender stream and queues the stream type code in its writer queue.

Returns:CompletableFuture<QuicSenderStream>

a completable future that will be completed with the local sender stream

localStreamTypeback to summary
public final Http3Streams.StreamType localStreamType()

Returns the HTTP/3 stream type of the sender part of the stream pair.

Returns:Http3Streams.StreamType

the HTTP/3 stream type of the sender part of the stream pair

localWriterback to summary
public QuicStreamWriter localWriter()

Returns the writer connected to the sender part of this stream or null if no writer is connected yet.

Returns:QuicStreamWriter

the writer connected to the sender part of this stream or null if no writer is connected yet

localWriterLoopback to summary
pack-priv void localWriterLoop()

This method is overridden by QueuingStreamPair to implement a writer loop for this stream. It is only called when the concrete subclass is QueuingStreamPair.

localWriteSchedulerback to summary
public SequentialScheduler localWriteScheduler()

Returns the scheduler for the local writer loop.

Returns:SequentialScheduler

the scheduler for the local writer loop

openLocalStreamback to summary
private QuicSenderStream openLocalStream(QuicSenderStream stream, int code)

Queues the given HTTP/3 stream type code on the given local unidirectional stream writer queue.

Parameters
stream:QuicSenderStream

a new local unidirectional stream

code:int

the code to queue up on the stream writer queue

Returns:QuicSenderStream

the given stream

peerReaderLoopback to summary
private void peerReaderLoop()
processPeerControlBytesback to summary
private void processPeerControlBytes(ByteBuffer buffer)

This method is called to process bytes received on the peer control stream.

Parameters
buffer:ByteBuffer

the bytes received

remoteback to summary
private static Http3Streams.StreamType remote(Http3Streams.StreamType localStreamType)
remoteStreamTypeback to summary
public final Http3Streams.StreamType remoteStreamType()

Returns the HTTP/3 stream type of the receiver part of the stream pair.

Returns:Http3Streams.StreamType

the HTTP/3 stream type of the receiver part of the stream pair

startReceivingback to summary
private CompletableFuture<QuicStreamReader> startReceiving()

Schedules the receiving of server settings

Returns:CompletableFuture<QuicStreamReader>

a completable future that will be completed with the QuicStreamReader allowing to read from the remote control stream.

startSendingback to summary
private CompletableFuture<QuicStreamWriter> startSending()

Schedules sending of client settings.

Returns:CompletableFuture<QuicStreamWriter>

a completable future that will be completed with the QuicStreamWriter allowing to write to the local control stream

stopSchedulersback to summary
public void stopSchedulers()

Stops schedulers. Can be called when the connection is closed to stop the reading and writing loops.

wrapback to summary
pack-priv QuicStreamWriter wrap(QuicStreamWriter writer)

Used by subclasses to redirect queuing of data to the subclass queue.

Parameters
writer:QuicStreamWriter

the downstream writer

Returns:QuicStreamWriter

a writer that can be safely used.

jdk.internal.net.http.http3.streams back to summary

public Interface UniStreamPair.StreamErrorHandler


Method Summary

Modifier and TypeMethod and Description
public void
onError(QuicStream
the stream on which the error occurred
stream
,
UniStreamPair
the UniStreamPair to which the stream belongs
uniStreamPair
,
Throwable
the error that occurred
error
)

Will be invoked when there is an error on a QuicStream handled by the UniStreamPair

Method Detail

onErrorback to summary
public void onError(QuicStream stream, UniStreamPair uniStreamPair, Throwable error)

Will be invoked when there is an error on a QuicStream handled by the UniStreamPair

Parameters
stream:QuicStream

the stream on which the error occurred

uniStreamPair:UniStreamPair

the UniStreamPair to which the stream belongs

error:Throwable

the error that occurred