A Stream represents a bidirectional exchange of data within a Session.
A Stream maps to an HTTP/3 request/response cycle, and after the request/response
cycle is completed, the stream is closed and removed from the Session.
Like Session, Stream is the active part and by calling its API applications
can generate events on the stream; conversely, Stream. and
Stream. are the passive part, and their callbacks are invoked when
events happen on the stream.
The client initiates a stream by sending a HEADERS frame containing the HTTP/3 request URI and request headers, and zero or more DATA frames containing request content.
Similarly, the server responds by sending a HEADERS frame containing the HTTP/3 response status code and response headers, and zero or more DATA frames containing response content.
Both client and server can end their side of the stream by sending a final frame with
the last flag set to true, see HeadersFrame#HeadersFrame(MetaData, boolean)
and DataFrame#DataFrame(ByteBuffer, boolean).
| Modifier and Type | Class and Description |
|---|---|
| public static interface | Stream.
The client side version of |
| public abstract static class | Stream.
A |
| public static interface | Stream.
The server side version of |
| Modifier and Type | Method and Description |
|---|---|
| public CompletableFuture | Returns: theCompletableFuture that gets notified when the frame has been sentthe DATA frame containing some or all the bytes of the request or of the response. frame)Sends the given DATA frame containing some or all the bytes of the request content or of the response content. |
| public void | |
| public long | |
| public Session | Returns: the session this stream is associated toGet the session this stream is associated to. |
| public Stream. | Returns: aStream. object containing the request bytes or
the response bytes, or null if no bytes are availableReads request content bytes or response content bytes. |
| public void | |
| public CompletableFuture | Returns: theCompletableFuture that gets notified when the frame has been sentthe HEADERS frame containing the trailer headers frame)Sends the given HEADERS frame containing the trailer headers. |
| data | back to summary |
|---|---|
| public CompletableFuture Sends the given DATA frame containing some or all the bytes of the request content or of the response content.
| |
| demand | back to summary |
|---|---|
| public void demand() Demands more Calling this method causes This method is idempotent: calling it when there already is an
outstanding demand to invoke The thread invoking this method may invoke directly
It is always guaranteed that invoking this method from within
| |
| getId | back to summary |
|---|---|
| public long getId() Get the stream id.
| |
| getSession | back to summary |
|---|---|
| public Session getSession() Get the session this stream is associated to.
| |
| readData | back to summary |
|---|---|
| public Stream. Reads request content bytes or response content bytes. The returned
When the returned
| |
| reset | back to summary |
|---|---|
| public void reset(long error, Throwable failure) Abruptly terminates this stream with the given error.
| |
| trailer | back to summary |
|---|---|
| public CompletableFuture Sends the given HEADERS frame containing the trailer headers.
| |
The client side version of Stream.
| Modifier and Type | Class and Description |
|---|---|
| public static interface | Stream.
A |
A Stream. is the passive counterpart of a Stream.
and receives client-side events happening on an HTTP/3 stream.
Stream.Client
| Modifier and Type | Method and Description |
|---|---|
| public default void | onDataAvailable(Stream.
the stream streamCallback method invoked if the application has expressed
|
| public default void | |
| public default void | |
| public default void | onNewStream(Stream.
the newly created stream streamCallback method invoked when a stream is created locally by
|
| public default void | onResponse(Stream.
the stream stream,the HEADERS frame containing the response headers frame)Callback method invoked when a response is received. |
| public default void | onTrailer(Stream.
the stream stream,the HEADERS frame containing the trailer headers frame)Callback method invoked when a trailer is received. |
| onDataAvailable | back to summary |
|---|---|
| public default void onDataAvailable(Stream. Callback method invoked if the application has expressed
A server application that wishes to handle request content
should typically call A client application that wishes to handle response content
should typically call Just prior calling this method, the outstanding demand is
cancelled; applications that implement this method should read
content calling Only one thread at a time invokes this method, although it may not be the same thread across different invocations. It is always guaranteed that invoking Typical usage:
class MyStreamListener implements Stream.Client.Listener
{
@Override
public void onDataAvailable(Stream.Client stream)
{
// Read a chunk of the content.
Stream.Data data = stream.readData();
if (data == null)
{
// No data available now, demand to be called back.
stream.demand();
}
else
{
// Process the content.
process(data.getByteBuffer());
// Notify that the content has been consumed.
data.release();
if (!data.isLast())
{
// Demand to be called back.
stream.demand();
}
}
}
}
| |
| onFailure | back to summary |
|---|---|
| public default void onFailure(Stream. Callback method invoked when a stream failure occurred. Typical stream failures, among others, are failures to decode a HEADERS frame, or failures to read bytes because the stream has been reset. | |
| onIdleTimeout | back to summary |
|---|---|
| public default void onIdleTimeout(Stream. Callback method invoked when the stream idle timeout elapses. | |
| onNewStream | back to summary |
|---|---|
| public default void onNewStream(Stream. Callback method invoked when a stream is created locally by
| |
| onResponse | back to summary |
|---|---|
| public default void onResponse(Stream. Callback method invoked when a response is received. To read response content, applications should call
| |
| onTrailer | back to summary |
|---|---|
| public default void onTrailer(Stream. Callback method invoked when a trailer is received.
| |
A Stream. instance associates a ByteBuffer
containing request bytes or response bytes.
Stream#readData()
| Modifier and Type | Class and Description |
|---|---|
| private static class |
| Modifier and Type | Field and Description |
|---|---|
| public static final Stream. | |
| private final DataFrame |
| Modifier and Type | Method and Description |
|---|---|
| public ByteBuffer | |
| public boolean | isLast()
Returns: whether this is the instance that ends the stream of bytes received from the remote peer |
| public String |
| EOF | back to summary |
|---|---|
| public static final Stream. | |
| frame | back to summary |
|---|---|
| private final DataFrame frame | |
| Data | back to summary |
|---|---|
| public Data(DataFrame frame) | |
| getByteBuffer | back to summary |
|---|---|
public ByteBuffer getByteBuffer()
| |
| isLast | back to summary |
|---|---|
public boolean isLast()
| |
| toString | back to summary |
|---|---|
| public String toString() Overrides java. Doc from java. Returns a string representation of the object.
Satisfying this method's contract implies a non-
| |
| Access | Constructor and Description |
|---|---|
| private |
| EOFData | back to summary |
|---|---|
| private EOFData() | |
The server side version of Stream.
| Modifier and Type | Class and Description |
|---|---|
| public static interface | Stream.
A |
| Modifier and Type | Method and Description |
|---|---|
| public CompletableFuture | Returns: theCompletableFuture that gets notified when the frame has been sentthe HEADERS frame containing the response headers frame)Responds to a request performed via |
| respond | back to summary |
|---|---|
| public CompletableFuture Responds to a request performed via
| |
A Stream. is the passive counterpart of a Stream.
and receives server-side events happening on an HTTP/3 stream.
Stream.Server
| Modifier and Type | Method and Description |
|---|---|
| public default void | onDataAvailable(Stream.
the stream streamCallback method invoked if the application has expressed
|
| public default void | |
| public default void | onIdleTimeout(Stream.
the stream stream,the timeout failure failure, Promise<Boolean> the promise to complete with true to reset the stream,
false to ignore the idle timeout promise)Callback method invoked when the stream idle timeout elapses. |
| public default void | onTrailer(Stream.
the stream stream,the HEADERS frame containing the trailer headers frame)Callback method invoked when a trailer is received. |
| onDataAvailable | back to summary |
|---|---|
| public default void onDataAvailable(Stream. Callback method invoked if the application has expressed
A server application that wishes to handle request content
should typically call A client application that wishes to handle response content
should typically call Just prior calling this method, the outstanding demand is
cancelled; applications that implement this method should read
content calling Only one thread at a time invokes this method, although it may not be the same thread across different invocations. It is always guaranteed that invoking Typical usage:
class MyStreamListener implements Stream.Server.Listener
{
@Override
public void onDataAvailable(Stream.Server stream)
{
// Read a chunk of the content.
Stream.Data data = stream.readData();
if (data == null)
{
// No data available now, demand to be called back.
stream.demand();
}
else
{
// Process the content.
process(data.getByteBuffer());
// Notify that the content has been consumed.
data.release();
if (!data.isLast())
{
// Demand to be called back.
stream.demand();
}
}
}
}
| |
| onFailure | back to summary |
|---|---|
| public default void onFailure(Stream. Callback method invoked when a stream failure occurred. Typical stream failures, among others, are failures to decode a HEADERS frame, or failures to read bytes because the stream has been reset. | |
| onIdleTimeout | back to summary |
|---|---|
| public default void onIdleTimeout(Stream. Callback method invoked when the stream idle timeout elapses.
| |
| onTrailer | back to summary |
|---|---|
| public default void onTrailer(Stream. Callback method invoked when a trailer is received.
| |