Class HTTP2Session
- java.lang.Object
-
- org.eclipse.jetty.util.component.AbstractLifeCycle
-
- org.eclipse.jetty.util.component.ContainerLifeCycle
-
- org.eclipse.jetty.http2.HTTP2Session
-
- All Implemented Interfaces:
Session,ISession,Parser.Listener,org.eclipse.jetty.util.component.Container,org.eclipse.jetty.util.component.Destroyable,org.eclipse.jetty.util.component.Dumpable,org.eclipse.jetty.util.component.LifeCycle
@ManagedObject public abstract class HTTP2Session extends org.eclipse.jetty.util.component.ContainerLifeCycle implements ISession, Parser.Listener
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class org.eclipse.jetty.util.component.AbstractLifeCycle
org.eclipse.jetty.util.component.AbstractLifeCycle.AbstractLifeCycleListener
-
Nested classes/interfaces inherited from interface org.eclipse.jetty.util.component.Container
org.eclipse.jetty.util.component.Container.InheritedListener, org.eclipse.jetty.util.component.Container.Listener
-
Nested classes/interfaces inherited from interface org.eclipse.jetty.util.component.LifeCycle
org.eclipse.jetty.util.component.LifeCycle.Listener
-
Nested classes/interfaces inherited from interface org.eclipse.jetty.http2.parser.Parser.Listener
Parser.Listener.Adapter, Parser.Listener.Wrapper
-
Nested classes/interfaces inherited from interface org.eclipse.jetty.http2.api.Session
Session.Listener
-
-
Constructor Summary
Constructors Constructor Description HTTP2Session(org.eclipse.jetty.util.thread.Scheduler scheduler, org.eclipse.jetty.io.EndPoint endPoint, Generator generator, Session.Listener listener, FlowControlStrategy flowControl, int initialStreamId)
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected voidabort(java.lang.Throwable failure)booleanclose(int error, java.lang.String reason, org.eclipse.jetty.util.Callback callback)Invoked internally and by applications to send a GO_AWAY frame to the other peer.protected IStreamcreateLocalStream(int streamId)protected IStreamcreateRemoteStream(int streamId)voiddata(IStream stream, org.eclipse.jetty.util.Callback callback, DataFrame frame)Enqueues the given DATA frame to be written to the connection.voiddisconnect()protected voiddoStop()voiddump(java.lang.Appendable out, java.lang.String indent)voidframes(IStream stream, org.eclipse.jetty.util.Callback callback, Frame frame, Frame... frames)Enqueues the given frames to be written to the connection.longgetBytesWritten()org.eclipse.jetty.io.EndPointgetEndPoint()FlowControlStrategygetFlowControlStrategy()GeneratorgetGenerator()intgetInitialSessionRecvWindow()protected intgetLastRemoteStreamId()intgetMaxLocalStreams()intgetMaxRemoteStreams()intgetRecvWindow()intgetSendWindow()IStreamgetStream(int streamId)Retrieves the stream with the givenstreamId.intgetStreamCount()longgetStreamIdleTimeout()java.util.Collection<Stream>getStreams()intgetWriteThreshold()protected static booleanisClientStream(int streamId)booleanisClosed()booleanisDisconnected()protected booleanisLocalStreamClosed(int streamId)booleanisPushEnabled()protected booleanisRemoteStreamClosed(int streamId)protected IStreamnewStream(int streamId, boolean local)voidnewStream(HeadersFrame frame, org.eclipse.jetty.util.Promise<Stream> promise, Stream.Listener listener)Sends the given HEADERSframeto create a newStream.protected voidnotifyClose(Session session, GoAwayFrame frame, org.eclipse.jetty.util.Callback callback)protected voidnotifyFailure(Session session, java.lang.Throwable failure, org.eclipse.jetty.util.Callback callback)protected voidnotifyHeaders(IStream stream, HeadersFrame frame)protected booleannotifyIdleTimeout(Session session)protected Stream.ListenernotifyNewStream(Stream stream, HeadersFrame frame)protected voidnotifyPing(Session session, PingFrame frame)protected voidnotifyReset(Session session, ResetFrame frame)protected voidnotifySettings(Session session, SettingsFrame frame)voidonConnectionFailure(int error, java.lang.String reason)protected voidonConnectionFailure(int error, java.lang.String reason, org.eclipse.jetty.util.Callback callback)voidonData(DataFrame frame)voidonData(DataFrame frame, org.eclipse.jetty.util.Callback callback)Callback method invoked when a DATA frame is received.voidonFlushed(long bytes)Callback method invoked when bytes are flushed to the network.voidonFrame(Frame frame)Callback method invoked during an HTTP/1.1 to HTTP/2 upgrade requests to process the given synthetic frame.voidonGoAway(GoAwayFrame frame)This method is called when receiving a GO_AWAY from the other peer.abstract voidonHeaders(HeadersFrame frame)booleanonIdleTimeout()This method is invoked when the idle timeout triggers.voidonPing(PingFrame frame)voidonPriority(PriorityFrame frame)voidonReset(ResetFrame frame)protected abstract voidonResetForUnknownStream(ResetFrame frame)voidonSettings(SettingsFrame frame)voidonSettings(SettingsFrame frame, boolean reply)voidonShutdown()A typical close by a remote peer involves a GO_AWAY frame followed by TCP FIN.protected voidonStreamClosed(IStream stream)voidonStreamFailure(int streamId, int error, java.lang.String reason)protected voidonStreamOpened(IStream stream)voidonWindowUpdate(WindowUpdateFrame frame)voidonWindowUpdate(IStream stream, WindowUpdateFrame frame)Callback method invoked when a WINDOW_UPDATE frame has been received.voidping(PingFrame frame, org.eclipse.jetty.util.Callback callback)Sends the given PINGframe.intpriority(PriorityFrame frame, org.eclipse.jetty.util.Callback callback)Sends the given PRIORITYframe.voidpush(IStream stream, org.eclipse.jetty.util.Promise<Stream> promise, PushPromiseFrame frame, Stream.Listener listener)Enqueues the given PUSH_PROMISE frame to be written to the connection.voidremoveStream(IStream stream)Removes the givenstream.protected voidreset(ResetFrame frame, org.eclipse.jetty.util.Callback callback)voidsetInitialSessionRecvWindow(int initialSessionRecvWindow)voidsetMaxLocalStreams(int maxLocalStreams)voidsetMaxRemoteStreams(int maxRemoteStreams)voidsetStreamIdleTimeout(long streamIdleTimeout)voidsettings(SettingsFrame frame, org.eclipse.jetty.util.Callback callback)Sends the given SETTINGSframeto configure the session.voidsetWriteThreshold(int writeThreshold)java.lang.StringtoString()intupdateRecvWindow(int delta)Updates the session receive window by the givendelta.intupdateSendWindow(int delta)Updates the session send window by the givendelta.-
Methods inherited from class org.eclipse.jetty.util.component.ContainerLifeCycle
addBean, addBean, addEventListener, addManaged, contains, destroy, doStart, dump, dump, dump, dump, dumpBeans, dumpObject, dumpObjects, dumpStdErr, dumpThis, getBean, getBeans, getBeans, getContainedBeans, getContainedBeans, isAuto, isManaged, isUnmanaged, manage, removeBean, removeBeans, removeEventListener, setBeans, setStopTimeout, start, stop, unmanage, updateBean, updateBean, updateBeans
-
Methods inherited from class org.eclipse.jetty.util.component.AbstractLifeCycle
addLifeCycleListener, getState, getState, getStopTimeout, isFailed, isRunning, isStarted, isStarting, isStopped, isStopping, removeLifeCycleListener, start, stop
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface org.eclipse.jetty.http2.parser.Parser.Listener
onPushPromise
-
-
-
-
Constructor Detail
-
HTTP2Session
public HTTP2Session(org.eclipse.jetty.util.thread.Scheduler scheduler, org.eclipse.jetty.io.EndPoint endPoint, Generator generator, Session.Listener listener, FlowControlStrategy flowControl, int initialStreamId)
-
-
Method Detail
-
doStop
protected void doStop() throws java.lang.Exception- Overrides:
doStopin classorg.eclipse.jetty.util.component.ContainerLifeCycle- Throws:
java.lang.Exception
-
getFlowControlStrategy
@ManagedAttribute(value="The flow control strategy", readonly=true) public FlowControlStrategy getFlowControlStrategy()
-
getMaxLocalStreams
public int getMaxLocalStreams()
-
setMaxLocalStreams
public void setMaxLocalStreams(int maxLocalStreams)
-
getMaxRemoteStreams
public int getMaxRemoteStreams()
-
setMaxRemoteStreams
public void setMaxRemoteStreams(int maxRemoteStreams)
-
getStreamIdleTimeout
@ManagedAttribute("The stream\'s idle timeout") public long getStreamIdleTimeout()
-
setStreamIdleTimeout
public void setStreamIdleTimeout(long streamIdleTimeout)
-
getInitialSessionRecvWindow
@ManagedAttribute("The initial size of session\'s flow control receive window") public int getInitialSessionRecvWindow()
-
setInitialSessionRecvWindow
public void setInitialSessionRecvWindow(int initialSessionRecvWindow)
-
getWriteThreshold
public int getWriteThreshold()
-
setWriteThreshold
public void setWriteThreshold(int writeThreshold)
-
getEndPoint
public org.eclipse.jetty.io.EndPoint getEndPoint()
-
getGenerator
public Generator getGenerator()
-
getBytesWritten
public long getBytesWritten()
- Specified by:
getBytesWrittenin interfaceISession- Returns:
- the number of bytes written by this session
-
onData
public void onData(DataFrame frame)
- Specified by:
onDatain interfaceParser.Listener
-
onData
public void onData(DataFrame frame, org.eclipse.jetty.util.Callback callback)
Description copied from interface:ISessionCallback method invoked when a DATA frame is received.
-
isLocalStreamClosed
protected boolean isLocalStreamClosed(int streamId)
-
isRemoteStreamClosed
protected boolean isRemoteStreamClosed(int streamId)
-
onHeaders
public abstract void onHeaders(HeadersFrame frame)
- Specified by:
onHeadersin interfaceParser.Listener
-
onPriority
public void onPriority(PriorityFrame frame)
- Specified by:
onPriorityin interfaceParser.Listener
-
onReset
public void onReset(ResetFrame frame)
- Specified by:
onResetin interfaceParser.Listener
-
onResetForUnknownStream
protected abstract void onResetForUnknownStream(ResetFrame frame)
-
onSettings
public void onSettings(SettingsFrame frame)
- Specified by:
onSettingsin interfaceParser.Listener
-
onSettings
public void onSettings(SettingsFrame frame, boolean reply)
-
onPing
public void onPing(PingFrame frame)
- Specified by:
onPingin interfaceParser.Listener
-
onGoAway
public void onGoAway(GoAwayFrame frame)
This method is called when receiving a GO_AWAY from the other peer. We check the close state to act appropriately:- NOT_CLOSED: we move to REMOTELY_CLOSED and queue a disconnect, so
that the content of the queue is written, and then the connection
closed. We notify the application after being terminated.
See
HTTP2Session.ControlEntry#succeeded() - In all other cases, we do nothing since other methods are already performing their actions.
- Specified by:
onGoAwayin interfaceParser.Listener- Parameters:
frame- the GO_AWAY frame that has been received.- See Also:
close(int, String, Callback),onShutdown(),onIdleTimeout()
- NOT_CLOSED: we move to REMOTELY_CLOSED and queue a disconnect, so
that the content of the queue is written, and then the connection
closed. We notify the application after being terminated.
See
-
onWindowUpdate
public void onWindowUpdate(WindowUpdateFrame frame)
- Specified by:
onWindowUpdatein interfaceParser.Listener
-
onStreamFailure
public void onStreamFailure(int streamId, int error, java.lang.String reason)- Specified by:
onStreamFailurein interfaceParser.Listener
-
onConnectionFailure
public void onConnectionFailure(int error, java.lang.String reason)- Specified by:
onConnectionFailurein interfaceParser.Listener
-
onConnectionFailure
protected void onConnectionFailure(int error, java.lang.String reason, org.eclipse.jetty.util.Callback callback)
-
newStream
public void newStream(HeadersFrame frame, org.eclipse.jetty.util.Promise<Stream> promise, Stream.Listener listener)
Description copied from interface:SessionSends the given HEADERS
frameto create a newStream.
-
priority
public int priority(PriorityFrame frame, org.eclipse.jetty.util.Callback callback)
Description copied from interface:SessionSends 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.
-
push
public void push(IStream stream, org.eclipse.jetty.util.Promise<Stream> promise, PushPromiseFrame frame, Stream.Listener listener)
Description copied from interface:ISessionEnqueues the given PUSH_PROMISE frame to be written to the connection.
Differently from
ISession.frames(IStream, Callback, Frame, Frame...), this method generates atomically the stream id for the pushed stream.
-
settings
public void settings(SettingsFrame frame, org.eclipse.jetty.util.Callback callback)
Description copied from interface:SessionSends the given SETTINGS
frameto configure the session.
-
ping
public void ping(PingFrame frame, org.eclipse.jetty.util.Callback callback)
Description copied from interface:SessionSends the given PING
frame.PING frames may be used to test the connection integrity and to measure round-trip time.
-
reset
protected void reset(ResetFrame frame, org.eclipse.jetty.util.Callback callback)
-
close
public boolean close(int error, java.lang.String reason, org.eclipse.jetty.util.Callback callback)Invoked internally and by applications to send a GO_AWAY frame to the other peer. We check the close state to act appropriately:- NOT_CLOSED: we move to LOCALLY_CLOSED and queue a GO_AWAY. When the
GO_AWAY has been written, it will only cause the output to be shut
down (not the connection closed), so that the application can still
read frames arriving from the other peer.
Ideally the other peer will notice the GO_AWAY and close the connection.
When that happen, we close the connection from
onShutdown(). Otherwise, the idle timeout mechanism will close the connection, seeonIdleTimeout(). - In all other cases, we do nothing since other methods are already performing their actions.
- Specified by:
closein interfaceSession- Parameters:
error- the error codereason- the reasoncallback- the callback to invoke when the operation is complete- Returns:
- true if the frame is being sent, false if the session was already closed
- See Also:
onGoAway(GoAwayFrame),onShutdown(),onIdleTimeout()
- NOT_CLOSED: we move to LOCALLY_CLOSED and queue a GO_AWAY. When the
GO_AWAY has been written, it will only cause the output to be shut
down (not the connection closed), so that the application can still
read frames arriving from the other peer.
Ideally the other peer will notice the GO_AWAY and close the connection.
When that happen, we close the connection from
-
isClosed
public boolean isClosed()
-
frames
public void frames(IStream stream, org.eclipse.jetty.util.Callback callback, Frame frame, Frame... frames)
Description copied from interface:ISessionEnqueues the given frames to be written to the connection.
-
data
public void data(IStream stream, org.eclipse.jetty.util.Callback callback, DataFrame frame)
Description copied from interface:ISessionEnqueues the given DATA frame to be written to the connection.
-
createLocalStream
protected IStream createLocalStream(int streamId)
-
createRemoteStream
protected IStream createRemoteStream(int streamId)
-
newStream
protected IStream newStream(int streamId, boolean local)
-
removeStream
public void removeStream(IStream stream)
Description copied from interface:ISessionRemoves the given
stream.- Specified by:
removeStreamin interfaceISession- Parameters:
stream- the stream to remove
-
getStreams
public java.util.Collection<Stream> getStreams()
- Specified by:
getStreamsin interfaceSession- Returns:
- a snapshot of all the streams currently belonging to this session
-
getStreamCount
@ManagedAttribute("The number of active streams") public int getStreamCount()
-
getStream
public IStream getStream(int streamId)
Description copied from interface:SessionRetrieves the stream with the given
streamId.
-
getSendWindow
@ManagedAttribute(value="The flow control send window", readonly=true) public int getSendWindow()
-
getRecvWindow
@ManagedAttribute(value="The flow control receive window", readonly=true) public int getRecvWindow()
-
updateSendWindow
public int updateSendWindow(int delta)
Description copied from interface:ISessionUpdates the session send window by the given
delta.- Specified by:
updateSendWindowin interfaceISession- Parameters:
delta- the delta value (positive or negative) to add to the session send window- Returns:
- the previous value of the session send window
-
updateRecvWindow
public int updateRecvWindow(int delta)
Description copied from interface:ISessionUpdates the session receive window by the given
delta.- Specified by:
updateRecvWindowin interfaceISession- Parameters:
delta- the delta value (positive or negative) to add to the session receive window- Returns:
- the previous value of the session receive window
-
onWindowUpdate
public void onWindowUpdate(IStream stream, WindowUpdateFrame frame)
Description copied from interface:ISessionCallback method invoked when a WINDOW_UPDATE frame has been received.
- Specified by:
onWindowUpdatein interfaceISession- Parameters:
stream- the stream the window update belongs to, or null if the window update belongs to the sessionframe- the WINDOW_UPDATE frame received
-
isPushEnabled
@ManagedAttribute(value="Whether HTTP/2 push is enabled", readonly=true) public boolean isPushEnabled()- Specified by:
isPushEnabledin interfaceISession- Returns:
- whether the push functionality is enabled
-
onShutdown
public void onShutdown()
A typical close by a remote peer involves a GO_AWAY frame followed by TCP FIN. This method is invoked when the TCP FIN is received, or when an exception is thrown while reading, and we check the close state to act appropriately:- NOT_CLOSED: means that the remote peer did not send a GO_AWAY (abrupt close) or there was an exception while reading, and therefore we terminate.
- LOCALLY_CLOSED: we have sent the GO_AWAY to the remote peer, which received
it and closed the connection; we queue a disconnect to close the connection
on the local side.
The GO_AWAY just shutdown the output, so we need this step to make sure the
connection is closed. See
close(int, String, Callback). - REMOTELY_CLOSED: we received the GO_AWAY, and the TCP FIN afterwards, so we
do nothing since the handling of the GO_AWAY will take care of closing the
connection. See
onGoAway(GoAwayFrame).
- Specified by:
onShutdownin interfaceISession- See Also:
onGoAway(GoAwayFrame),close(int, String, Callback),onIdleTimeout()
-
onIdleTimeout
public boolean onIdleTimeout()
This method is invoked when the idle timeout triggers. We check the close state to act appropriately:- NOT_CLOSED: it's a real idle timeout, we just initiate a close, see
close(int, String, Callback). - LOCALLY_CLOSED: we have sent a GO_AWAY and only shutdown the output, but the other peer did not close the connection so we never received the TCP FIN, and therefore we terminate.
- REMOTELY_CLOSED: the other peer sent us a GO_AWAY, we should have queued a
disconnect, but for some reason it was not processed (for example, queue was
stuck because of TCP congestion), therefore we terminate.
See
onGoAway(GoAwayFrame).
- Specified by:
onIdleTimeoutin interfaceISession- Returns:
- true if the session should be closed, false otherwise
- See Also:
onGoAway(GoAwayFrame),close(int, String, Callback),onShutdown()
- NOT_CLOSED: it's a real idle timeout, we just initiate a close, see
-
onFrame
public void onFrame(Frame frame)
Description copied from interface:ISessionCallback method invoked during an HTTP/1.1 to HTTP/2 upgrade requests to process the given synthetic frame.
-
onStreamOpened
protected void onStreamOpened(IStream stream)
-
onStreamClosed
protected void onStreamClosed(IStream stream)
-
onFlushed
public void onFlushed(long bytes) throws java.io.IOExceptionDescription copied from interface:ISessionCallback method invoked when bytes are flushed to the network.
-
disconnect
public void disconnect()
-
abort
protected void abort(java.lang.Throwable failure)
-
isDisconnected
public boolean isDisconnected()
-
getLastRemoteStreamId
protected int getLastRemoteStreamId()
-
notifyNewStream
protected Stream.Listener notifyNewStream(Stream stream, HeadersFrame frame)
-
notifySettings
protected void notifySettings(Session session, SettingsFrame frame)
-
notifyReset
protected void notifyReset(Session session, ResetFrame frame)
-
notifyClose
protected void notifyClose(Session session, GoAwayFrame frame, org.eclipse.jetty.util.Callback callback)
-
notifyIdleTimeout
protected boolean notifyIdleTimeout(Session session)
-
notifyFailure
protected void notifyFailure(Session session, java.lang.Throwable failure, org.eclipse.jetty.util.Callback callback)
-
notifyHeaders
protected void notifyHeaders(IStream stream, HeadersFrame frame)
-
isClientStream
protected static boolean isClientStream(int streamId)
-
dump
public void dump(java.lang.Appendable out, java.lang.String indent) throws java.io.IOException- Specified by:
dumpin interfaceorg.eclipse.jetty.util.component.Dumpable- Overrides:
dumpin classorg.eclipse.jetty.util.component.ContainerLifeCycle- Throws:
java.io.IOException
-
toString
public java.lang.String toString()
- Overrides:
toStringin classorg.eclipse.jetty.util.component.AbstractLifeCycle
-
-