Interface Session
-
- All Known Subinterfaces:
ISession
- All Known Implementing Classes:
HTTP2ClientSession,HTTP2ServerSession,HTTP2Session
public interface SessionA
Sessionrepresents the client-side endpoint of an HTTP/2 connection to a single origin server.Once a
Sessionhas 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
Sessionis the active part of the endpoint, and by calling its API applications can generate events on the connection; converselySession.Listeneris the passive part of the endpoint, and has callbacks that are invoked when events happen on the connection.- See Also:
Session.Listener
-
-
Nested Class Summary
Nested Classes Modifier and Type Interface Description static interfaceSession.ListenerASession.Listeneris the passive counterpart of aSessionand receives events happening on an HTTP/2 connection.
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description booleanclose(int error, java.lang.String payload, Callback callback)Closes the session by sending a GOAWAY frame with the given error code and payload.StreamgetStream(int streamId)Retrieves the stream with the givenstreamId.java.util.Collection<Stream>getStreams()booleanisClosed()voidnewStream(HeadersFrame frame, Promise<Stream> promise, Stream.Listener listener)Sends the given HEADERSframeto create a newStream.voidping(PingFrame frame, Callback callback)Sends the given PINGframe.intpriority(PriorityFrame frame, Callback callback)Sends the given PRIORITYframe.voidsettings(SettingsFrame frame, Callback callback)Sends the given SETTINGSframeto configure the session.
-
-
-
Method Detail
-
newStream
void newStream(HeadersFrame frame, Promise<Stream> promise, Stream.Listener listener)
Sends the given HEADERS
frameto create a newStream.- Parameters:
frame- the HEADERS frame containing the HTTP headerspromise- the promise that gets notified of the stream creationlistener- the listener that gets notified of stream events
-
priority
int priority(PriorityFrame frame, Callback callback)
Sends the given PRIORITY
frame.If the
framereferences astreamIdthat does not exist (for example0), then a newstreamIdwill be allocated, to support unused anchor streams that act as parent for other streams.- Parameters:
frame- the PRIORITY frame to sendcallback- the callback that gets notified when the frame has been sent- Returns:
- the new stream id generated by the PRIORITY frame, or the stream id that it is already referencing
-
settings
void settings(SettingsFrame frame, Callback callback)
Sends the given SETTINGS
frameto configure the session.- Parameters:
frame- the SETTINGS frame to sendcallback- the callback that gets notified when the frame has been sent
-
ping
void 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.
- Parameters:
frame- the PING frame to sendcallback- the callback that gets notified when the frame has been sent
-
close
boolean close(int error, java.lang.String payload, Callback callback)Closes the session by sending a GOAWAY frame with the given error code and payload.
- Parameters:
error- the error codepayload- an optional payload (may be null)callback- the callback that gets notified when the frame has been sent- Returns:
- true if the frame is being sent, false if the session was already closed
-
isClosed
boolean isClosed()
- Returns:
- whether the session is not open
-
getStreams
java.util.Collection<Stream> getStreams()
- Returns:
- a snapshot of all the streams currently belonging to this session
-
getStream
Stream getStream(int streamId)
Retrieves the stream with the given
streamId.- Parameters:
streamId- the stream id of the stream looked for- Returns:
- the stream with the given id, or null if no such stream exist
-
-