A Session represents the client-side endpoint of an HTTP/2 connection to a single origin server.
Once a Session has been obtained, it can be used to open HTTP/2 streams:
Session session = ...;
HeadersFrame frame = ...;
Promise<Stream> promise = ...
session.newStream(frame, promise, new Stream.Listener()
{
public void onHeaders(Stream stream, HeadersFrame frame)
{
// Reply received
}
});
A Session is the active part of the endpoint, and by calling its API applications can generate
events on the connection; conversely Session. is the passive part of the endpoint, and
has callbacks that are invoked when events happen on the connection.
Session.Listener
| Modifier and Type | Class and Description |
|---|---|
| public static interface | Session.
A |
| Modifier and Type | Method and Description |
|---|---|
| public boolean | Returns: true if the frame is being sent, false if the session was already closedthe error code error, String an optional payload (may be null) payload, Callback the callback that gets notified when the frame has been sent callback)Closes the session by sending a GOAWAY frame with the given error code and payload. |
| public InetSocketAddress | getLocalAddress()
Deprecated
use
getLocalSocketAddress() instead
Returns: the local network address this session is bound to,
or |
| public default SocketAddress | getLocalSocketAddress()
Returns: the local network address this session is bound to,
or |
| public InetSocketAddress | getRemoteAddress()
Deprecated
use
getRemoteSocketAddress() instead
Returns: the remote network address this session is connected to,
or |
| public default SocketAddress | getRemoteSocketAddress()
Returns: the remote network address this session is connected to,
or |
| public Stream | Returns: the stream with the given id, or null if no such stream existthe stream id of the stream looked for streamId)Retrieves the stream with the given |
| public Collection | |
| public boolean | |
| public boolean | |
| public default CompletableFuture | Returns: a CompletableFuture that is notified of the stream creationthe HEADERS frame containing the HTTP headers frame, Stream.the listener that gets notified of stream events listenerSends the given HEADERS |
| public void | |
| public void | |
| public int | Returns: the new stream id generated by the PRIORITY frame, or the stream id that it is already referencingthe PRIORITY frame to send frame, Callback the callback that gets notified when the frame has been sent callback)Sends the given PRIORITY |
| public default CompletableFuture | Returns: a CompletableFuture that is notified when the frame has been sentthe SETTINGS frame to send frame)Sends the given SETTINGS |
| public void | settings(SettingsFrame
the SETTINGS frame to send frame, Callback the callback that gets notified when the frame has been sent callback)Sends the given SETTINGS |
| public CompletableFuture | Returns: aCompletableFuture that is completed when all the streams are completedGracefully closes the session, returning a |
| close | back to summary |
|---|---|
| public boolean close(int error, String payload, Callback callback) Closes the session by sending a GOAWAY frame with the given error code and payload. | |
| getLocalAddress | back to summary |
|---|---|
| public InetSocketAddress getLocalAddress()
Deprecated use
| |
| getLocalSocketAddress | back to summary |
|---|---|
public default SocketAddress getLocalSocketAddress()
| |
| getRemoteAddress | back to summary |
|---|---|
| public InetSocketAddress getRemoteAddress()
Deprecated use
| |
| getRemoteSocketAddress | back to summary |
|---|---|
public default SocketAddress getRemoteSocketAddress()
| |
| getStream | back to summary |
|---|---|
| public Stream getStream(int streamId) Retrieves the stream with the given
| |
| getStreams | back to summary |
|---|---|
public Collection
| |
| isClosed | back to summary |
|---|---|
public boolean isClosed()
| |
| isPushEnabled | back to summary |
|---|---|
public boolean isPushEnabled()
| |
| newStream | back to summary |
|---|---|
| public default CompletableFuture Sends the given HEADERS
| |
| newStream | back to summary |
|---|---|
| public void newStream(HeadersFrame frame, Promise<Stream> promise, Stream. Sends the given HEADERS
| |
| ping | back to summary |
|---|---|
| public void ping(PingFrame frame, Callback callback) Sends the given PING PING frames may be used to test the connection integrity and to measure round-trip time. | |
| priority | back to summary |
|---|---|
| public int priority(PriorityFrame frame, Callback callback) Sends the given PRIORITY If the
| |
| settings | back to summary |
|---|---|
| public default CompletableFuture Sends the given SETTINGS
| |
| settings | back to summary |
|---|---|
| public void settings(SettingsFrame frame, Callback callback) Sends the given SETTINGS
| |
| shutdown | back to summary |
|---|---|
| public CompletableFuture Gracefully closes the session, returning a Implementation is idempotent, i.e. calling this method a second time or concurrently results in a no-operation.
| |
A Listener is the passive counterpart of a Session and
receives events happening on an HTTP/2 connection.
Session
| Modifier and Type | Method and Description |
|---|---|
| public default void | onClose(Session
the session session, GoAwayFrame the GOAWAY frame that caused the session to be closed frame, Callback the callback to notify of the GOAWAY processing callback)Callback method invoked when a GOAWAY frame caused the session to be closed. |
| public default void | |
| public default void | onGoAway(Session
the session session, GoAwayFrame the GOAWAY frame received frame)Callback method invoked when a GOAWAY frame has been received. |
| public default boolean | Returns: whether the session should be closedthe session session)Callback method invoked when the idle timeout expired. |
| public default Stream. | Returns: aStream. that will be notified of stream eventsthe newly created stream stream, HeadersFrame the HEADERS frame received frame)Callback method invoked when a new stream is being created upon receiving a HEADERS frame representing an HTTP request. |
| public default void | |
| public default Map | Returns: a (possibly empty or null) map containing SETTINGS configuration options to send.the session session)Callback method invoked:
|
| public default void | onReset(Session
the session session, ResetFrame the RST_STREAM frame received frame)Callback method invoked when a RST_STREAM frame has been received for an unknown stream. |
| public default void | onSettings(Session
the session session, SettingsFrame the SETTINGS frame received frame)Callback method invoked when a SETTINGS frame has been received. |
| onClose | back to summary |
|---|---|
| public default void onClose(Session session, GoAwayFrame frame, Callback callback) Callback method invoked when a GOAWAY frame caused the session to be closed.
| |
| onFailure | back to summary |
|---|---|
| public default void onFailure(Session session, Throwable failure, Callback callback) Callback method invoked when a failure has been detected for this session. | |
| onGoAway | back to summary |
|---|---|
| public default void onGoAway(Session session, GoAwayFrame frame) Callback method invoked when a GOAWAY frame has been received.
| |
| onIdleTimeout | back to summary |
|---|---|
| public default boolean onIdleTimeout(Session session) Callback method invoked when the idle timeout expired.
| |
| onNewStream | back to summary |
|---|---|
| public default Stream. Callback method invoked when a new stream is being created upon receiving a HEADERS frame representing an HTTP request. Applications should implement this method to process HTTP requests,
typically providing an HTTP response via
Applications can detect whether request DATA frames will be arriving
by testing
| |
| onPing | back to summary |
|---|---|
| public default void onPing(Session session, PingFrame frame) Callback method invoked when a PING frame has been received. | |
| onPreface | back to summary |
|---|---|
| public default Map Callback method invoked:
| |
| onReset | back to summary |
|---|---|
| public default void onReset(Session session, ResetFrame frame) Callback method invoked when a RST_STREAM frame has been received for an unknown stream.
| |
| onSettings | back to summary |
|---|---|
| public default void onSettings(Session session, SettingsFrame frame) Callback method invoked when a SETTINGS frame has been received.
| |