A Stream represents a bidirectional exchange of data on top of a Session.
Differently from socket streams, where the input and output streams are permanently associated with the socket (and hence with the connection that the socket represents), there can be multiple HTTP/2 streams present concurrently for an HTTP/2 session.
A Stream maps to an HTTP 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. is the passive part, and
its callbacks are invoked when events happen on the stream.
Stream.Listener
| Modifier and Type | Class and Description |
|---|---|
| public abstract static class | Stream.
A |
| public static interface | Stream.
A |
| Modifier and Type | Method and Description |
|---|---|
| public default CompletableFuture | |
| public void | |
| public void | |
| public Object | getAttribute(String
the attribute key key)Returns: an arbitrary object associated with the given key to this stream or null if no object can be found for the given key. |
| public int | |
| public long | |
| public Stream. | Returns: theorg. associated with this streamGet the |
| public Session | Returns: the session this stream is associated toGet the session this stream is associated to. |
| public default CompletableFuture | Returns: the CompletableFuture that gets notified when the frame has been sentthe HEADERS frame to send frame)Sends the given HEADERS |
| public void | headers(HeadersFrame
the HEADERS frame to send frame, Callback the callback that gets notified when the frame has been sent callback)Sends the given HEADERS |
| public boolean | |
| public boolean | |
| public boolean | |
| public boolean | |
| public default CompletableFuture | Returns: the CompletableFuture that gets notified of the pushed stream creationthe PUSH_PROMISE frame to send frame, Stream.the listener that gets notified of stream events listenerSends the given PUSH_PROMISE |
| public void | |
| public Stream. | Returns: aStream. object containing the DATA frame,
or null if no DATA frame is availableReads DATA frames from this stream, wrapping them in retainable
|
| public Object | removeAttribute(String
the attribute key key)Returns: the arbitrary object associated with the given key to this stream |
| public default CompletableFuture | Returns: the CompletableFuture that gets notified when the frame has been sentthe RST_STREAM frame to send frame)Sends the given RST_STREAM |
| public void | reset(ResetFrame
the RST_STREAM frame to send frame, Callback the callback that gets notified when the frame has been sent callback)Sends the given RST_STREAM |
| public void | setAttribute(String
the attribute key key, Object an arbitrary object to associate with the given key to this stream value)
|
| public void |
| data | back to summary |
|---|---|
| public default CompletableFuture Sends the given DATA
| |
| data | back to summary |
|---|---|
| public void data(DataFrame frame, Callback callback) Sends the given DATA | |
| 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
| |
| getAttribute | back to summary |
|---|---|
public Object getAttribute(String key)
| |
| getId | back to summary |
|---|---|
| public int getId() Get the stream unique id.
| |
| getIdleTimeout | back to summary |
|---|---|
public long getIdleTimeout()
| |
| getListener | back to summary |
|---|---|
| public Stream. Get the
| |
| getSession | back to summary |
|---|---|
| public Session getSession() Get the session this stream is associated to.
| |
| headers | back to summary |
|---|---|
| public default CompletableFuture Sends the given HEADERS
| |
| headers | back to summary |
|---|---|
| public void headers(HeadersFrame frame, Callback callback) Sends the given HEADERS Typically used to send an HTTP response or to send the HTTP response trailers.
| |
| isClosed | back to summary |
|---|---|
public boolean isClosed()
| |
| isLocal | back to summary |
|---|---|
public boolean isLocal()
| |
| isRemotelyClosed | back to summary |
|---|---|
public boolean isRemotelyClosed()
| |
| isReset | back to summary |
|---|---|
public boolean isReset()
| |
| push | back to summary |
|---|---|
| public default CompletableFuture Sends the given PUSH_PROMISE
| |
| push | back to summary |
|---|---|
| public void push(PushPromiseFrame frame, Promise<Stream> promise, Stream. Sends the given PUSH_PROMISE
| |
| readData | back to summary |
|---|---|
| public Stream. Reads DATA frames from this stream, wrapping them in retainable
The returned
When the returned
Once the returned
| |
| removeAttribute | back to summary |
|---|---|
public Object removeAttribute(String key)
| |
| reset | back to summary |
|---|---|
| public default CompletableFuture Sends the given RST_STREAM
| |
| reset | back to summary |
|---|---|
| public void reset(ResetFrame frame, Callback callback) Sends the given RST_STREAM
| |
| setAttribute | back to summary |
|---|---|
public void setAttribute(String key, Object value)
| |
| setIdleTimeout | back to summary |
|---|---|
public void setIdleTimeout(long idleTimeout)
| |
A Retainable wrapper of a DataFrame.
| Modifier and Type | Class and Description |
|---|---|
| private static class |
| Modifier and Type | Method and Description |
|---|---|
| public static Stream. | |
| public DataFrame | |
| public String |
| frame | back to summary |
|---|---|
| private final DataFrame frame | |
| Data | back to summary |
|---|---|
| public Data(DataFrame frame) | |
| eof | back to summary |
|---|---|
| public static Stream. | |
| frame | back to summary |
|---|---|
| public DataFrame frame() | |
| 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 |
|---|---|
| public |
| EOF | back to summary |
|---|---|
| public EOF(int streamId) | |
A Stream. is the passive counterpart of a Stream and receives
events happening on an HTTP/2 stream.
HTTP/2 data is flow controlled - this means that only a finite number of data events are delivered, until the flow control window is exhausted.
Applications control the delivery of data events by requesting them via
Stream#demand(); the first event is always delivered, while subsequent
events must be explicitly demanded.
Applications control the HTTP/2 flow control by completing the callback associated with data events - this allows the implementation to recycle the data buffer and eventually to enlarge the flow control window so that the sender can send more data.
Stream
| Modifier and Type | Field and Description |
|---|---|
| public static final Stream. | AUTO_DISCARD
A convenient constant for a |
| Modifier and Type | Method and Description |
|---|---|
| public default void | |
| public default void | onDataAvailable(Stream
the stream stream)Callback method invoked if the application has expressed
|
| public default void | |
| public default void | onHeaders(Stream
the stream stream, HeadersFrame the HEADERS frame received frame)Callback method invoked when a HEADERS frame representing the HTTP response has been received. |
| public default void | onIdleTimeout(Stream
the stream stream, TimeoutException the timeout failure x, Promise<Boolean> the promise to complete promise)Callback method invoked when the stream exceeds its idle timeout. |
| public default void | onNewStream(Stream
the newly created stream stream)Callback method invoked when a stream is created locally by
|
| public default Stream. | Returns: a Stream.Listener that will be notified of pushed stream eventsthe pushed stream stream, PushPromiseFrame the PUSH_PROMISE frame received frame)Callback method invoked when a PUSH_PROMISE frame has been received. |
| public default void | onReset(Stream
the stream stream, ResetFrame the RST_STREAM frame received frame, Callback the callback to complete when the reset has been handled callback)Callback method invoked when a RST_STREAM frame has been received for this stream. |
| AUTO_DISCARD | back to summary |
|---|---|
| public static final Stream. A convenient constant for a | |
| onClosed | back to summary |
|---|---|
| public default void onClosed(Stream stream) Callback method invoked after the stream has been closed.
| |
| onDataAvailable | back to summary |
|---|---|
| public default void onDataAvailable(Stream stream) Callback method invoked if the application has expressed
Applications that wish to handle DATA frames should call
Server applications should typically demand from 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:
| |
| onFailure | back to summary |
|---|---|
| public default void onFailure(Stream stream, int error, String reason, Throwable failure, Callback callback) Callback method invoked when the stream failed. | |
| onHeaders | back to summary |
|---|---|
| public default void onHeaders(Stream stream, HeadersFrame frame) Callback method invoked when a HEADERS frame representing the HTTP response has been received.
| |
| onIdleTimeout | back to summary |
|---|---|
| public default void onIdleTimeout(Stream stream, TimeoutException x, Promise<Boolean> promise) Callback method invoked when the stream exceeds its idle timeout.
| |
| onNewStream | back to summary |
|---|---|
| public default void onNewStream(Stream stream) Callback method invoked when a stream is created locally by
| |
| onPush | back to summary |
|---|---|
| public default Stream. Callback method invoked when a PUSH_PROMISE frame has been received. Applications that override this method are typically interested in
processing the pushed stream DATA frames, and must demand for pushed
DATA frames via
| |
| onReset | back to summary |
|---|---|
| public default void onReset(Stream stream, ResetFrame frame, Callback callback) Callback method invoked when a RST_STREAM frame has been received for this stream.
| |