public interface Session
A Session
represents the client-side endpoint of a 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.Adapter() { 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.Listener
is the passive part of the endpoint, and
has callbacks that are invoked when events happen on the connection.
Session.Listener
Modifier and Type | Interface and Description |
---|---|
static interface |
Session.Listener
A
Session.Listener is the passive counterpart of a Session and
receives events happening on a HTTP/2 connection. |
Modifier and Type | Method and Description |
---|---|
boolean |
close(int error,
String payload,
Callback callback)
Closes the session by sending a GOAWAY frame with the given error code
and payload.
|
Stream |
getStream(int streamId)
Retrieves the stream with the given
streamId . |
Collection<Stream> |
getStreams() |
boolean |
isClosed() |
void |
newStream(HeadersFrame frame,
Promise<Stream> promise,
Stream.Listener listener)
Sends the given HEADERS
frame to create a new Stream . |
void |
ping(PingFrame frame,
Callback callback)
Sends the given PING
frame . |
void |
settings(SettingsFrame frame,
Callback callback)
Sends the given SETTINGS
frame to configure the session. |
void newStream(HeadersFrame frame, Promise<Stream> promise, Stream.Listener listener)
Sends the given HEADERS frame
to create a new Stream
.
frame
- the HEADERS frame containing the HTTP headerspromise
- the promise that gets notified of the stream creationlistener
- the listener that gets notified of stream eventsvoid settings(SettingsFrame frame, Callback callback)
Sends the given SETTINGS frame
to configure the session.
frame
- the SETTINGS frame to sendcallback
- the callback that gets notified when the frame has been sentvoid ping(PingFrame frame, Callback callback)
Sends the given PING frame
.
PING frames may be used to test the connection integrity and to measure round-trip time.
frame
- the PING frame to sendcallback
- the callback that gets notified when the frame has been sentboolean close(int error, String payload, Callback callback)
Closes the session by sending a GOAWAY frame with the given error code and payload.
The GOAWAY frame is sent only once; subsequent or concurrent attempts to close the session will have no effect.
error
- the error codepayload
- an optional payload (may be null)callback
- the callback that gets notified when the frame has been sentboolean isClosed()
Collection<Stream> getStreams()
Stream getStream(int streamId)
Retrieves the stream with the given streamId
.
streamId
- the stream id of the stream looked forCopyright © 1995-2015 Webtide. All Rights Reserved.