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.Dumpable.DumpableContainer, org.eclipse.jetty.util.component.LifeCycle
Direct Known Subclasses:
HTTP2ClientSession, HTTP2ServerSession

@ManagedObject public abstract class HTTP2Session extends org.eclipse.jetty.util.component.ContainerLifeCycle implements ISession, Parser.Listener
  • Field Details

    • LOG

      private static final org.eclipse.jetty.util.log.Logger LOG
    • streams

      private final ConcurrentMap<Integer,IStream> streams
    • streamsOpened

      private final AtomicLong streamsOpened
    • streamsClosed

      private final AtomicLong streamsClosed
    • streamsState

      private final HTTP2Session.StreamsState streamsState
    • localStreamIds

      private final AtomicInteger localStreamIds
    • lastRemoteStreamId

      private final AtomicInteger lastRemoteStreamId
    • localStreamCount

      private final AtomicInteger localStreamCount
    • remoteStreamCount

      private final org.eclipse.jetty.util.AtomicBiInteger remoteStreamCount
    • sendWindow

      private final AtomicInteger sendWindow
    • recvWindow

      private final AtomicInteger recvWindow
    • bytesWritten

      private final AtomicLong bytesWritten
    • scheduler

      private final org.eclipse.jetty.util.thread.Scheduler scheduler
    • endPoint

      private final org.eclipse.jetty.io.EndPoint endPoint
    • parser

      private final Parser parser
    • generator

      private final Generator generator
    • listener

      private final Session.Listener listener
    • flowControl

      private final FlowControlStrategy flowControl
    • flusher

      private final HTTP2Flusher flusher
    • maxLocalStreams

      private int maxLocalStreams
    • maxRemoteStreams

      private int maxRemoteStreams
    • streamIdleTimeout

      private long streamIdleTimeout
    • initialSessionRecvWindow

      private int initialSessionRecvWindow
    • writeThreshold

      private int writeThreshold
    • maxEncoderTableCapacity

      private int maxEncoderTableCapacity
    • pushEnabled

      private boolean pushEnabled
  • Constructor Details

  • Method Details

    • doStop

      protected void doStop() throws Exception
      Overrides:
      doStop in class org.eclipse.jetty.util.component.ContainerLifeCycle
      Throws:
      Exception
    • getFlowControlStrategy

      @ManagedAttribute(value="The flow control strategy", readonly=true) public FlowControlStrategy getFlowControlStrategy()
    • getStreamsOpened

      @ManagedAttribute(value="The total number of streams opened", readonly=true) public long getStreamsOpened()
    • getStreamsClosed

      @ManagedAttribute(value="The total number of streams closed", readonly=true) public long getStreamsClosed()
    • getMaxLocalStreams

      @ManagedAttribute("The maximum number of concurrent local streams") public int getMaxLocalStreams()
    • setMaxLocalStreams

      public void setMaxLocalStreams(int maxLocalStreams)
    • getMaxRemoteStreams

      @ManagedAttribute("The maximum number of concurrent remote streams") 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

      @ManagedAttribute("The number of bytes that trigger a TCP write") public int getWriteThreshold()
    • setWriteThreshold

      public void setWriteThreshold(int writeThreshold)
    • getMaxEncoderTableCapacity

      @ManagedAttribute("The HPACK encoder dynamic table maximum capacity") public int getMaxEncoderTableCapacity()
    • setMaxEncoderTableCapacity

      public void setMaxEncoderTableCapacity(int maxEncoderTableCapacity)
    • getEndPoint

      public org.eclipse.jetty.io.EndPoint getEndPoint()
    • getParser

      public Parser getParser()
    • getGenerator

      public Generator getGenerator()
    • getBytesWritten

      public long getBytesWritten()
      Specified by:
      getBytesWritten in interface ISession
      Returns:
      the number of bytes written by this session
    • onData

      public void onData(DataFrame frame)
      Specified by:
      onData in interface Parser.Listener
    • onData

      public void onData(DataFrame frame, org.eclipse.jetty.util.Callback callback)
      Description copied from interface: ISession

      Callback method invoked when a DATA frame is received.

      Specified by:
      onData in interface ISession
      Parameters:
      frame - the DATA frame received
      callback - the callback to notify when the frame has been processed
    • isStreamClosed

      private boolean isStreamClosed(int streamId)
    • isLocalStream

      private boolean isLocalStream(int streamId)
    • isLocalStreamClosed

      protected boolean isLocalStreamClosed(int streamId)
    • isRemoteStreamClosed

      protected boolean isRemoteStreamClosed(int streamId)
    • onHeaders

      public abstract void onHeaders(HeadersFrame frame)
      Specified by:
      onHeaders in interface Parser.Listener
    • onPriority

      public void onPriority(PriorityFrame frame)
      Specified by:
      onPriority in interface Parser.Listener
    • onReset

      public void onReset(ResetFrame frame)
      Specified by:
      onReset in interface Parser.Listener
    • onResetForUnknownStream

      protected void onResetForUnknownStream(ResetFrame frame)
    • onSettings

      public void onSettings(SettingsFrame frame)
      Specified by:
      onSettings in interface Parser.Listener
    • onSettings

      public void onSettings(SettingsFrame frame, boolean reply)
    • configure

      private void configure(Map<Integer,Integer> settings, boolean local)
    • onPing

      public void onPing(PingFrame frame)
      Specified by:
      onPing in interface Parser.Listener
    • onGoAway

      public void onGoAway(GoAwayFrame frame)

      This method is called when receiving a GO_AWAY from the other peer.

      Specified by:
      onGoAway in interface Parser.Listener
      Parameters:
      frame - the GO_AWAY frame that has been received.
      See Also:
    • onWindowUpdate

      public void onWindowUpdate(WindowUpdateFrame frame)
      Specified by:
      onWindowUpdate in interface Parser.Listener
    • onWindowUpdate

      public void onWindowUpdate(IStream stream, WindowUpdateFrame frame)
      Description copied from interface: ISession

      Callback method invoked when a WINDOW_UPDATE frame has been received.

      Specified by:
      onWindowUpdate in interface ISession
      Parameters:
      stream - the stream the window update belongs to, or null if the window update belongs to the session
      frame - the WINDOW_UPDATE frame received
    • onStreamFailure

      public void onStreamFailure(int streamId, int error, String reason)
      Specified by:
      onStreamFailure in interface Parser.Listener
    • onConnectionFailure

      public void onConnectionFailure(int error, String reason)
      Specified by:
      onConnectionFailure in interface Parser.Listener
    • onSessionFailure

      private void onSessionFailure(int error, String reason, org.eclipse.jetty.util.Callback callback)
    • onWriteFailure

      void onWriteFailure(Throwable failure)
    • abort

      protected void abort(String reason, Throwable failure, org.eclipse.jetty.util.Callback callback)
    • onFailure

      private void onFailure(int error, String reason, Throwable failure, org.eclipse.jetty.util.Callback callback)
    • failStreams

      private void failStreams(Predicate<IStream> matcher, String reason, boolean reset)
    • failStream

      private void failStream(Stream stream, int error, String reason, Throwable failure, org.eclipse.jetty.util.Callback callback)
    • toFailure

      private Throwable toFailure(int error, String reason)
    • newStream

      public void newStream(HeadersFrame frame, org.eclipse.jetty.util.Promise<Stream> promise, Stream.Listener listener)
      Description copied from interface: Session

      Sends the given HEADERS frame to create a new Stream.

      Specified by:
      newStream in interface Session
      Parameters:
      frame - the HEADERS frame containing the HTTP headers
      promise - the promise that gets notified of the stream creation
      listener - the listener that gets notified of stream events
    • newStream

      public void newStream(IStream.FrameList frames, org.eclipse.jetty.util.Promise<Stream> promise, Stream.Listener listener)
      Description copied from interface: ISession

      Sends the given list of frames to create a new Stream.

      Specified by:
      newStream in interface ISession
      Parameters:
      frames - the list of frames to send
      promise - the promise that gets notified of the stream creation
      listener - the listener that gets notified of stream events
    • priority

      public int priority(PriorityFrame frame, org.eclipse.jetty.util.Callback callback)
      Description copied from interface: Session

      Sends the given PRIORITY frame.

      If the frame references a streamId that does not exist (for example 0), then a new streamId will be allocated, to support unused anchor streams that act as parent for other streams.

      Specified by:
      priority in interface Session
      Parameters:
      frame - the PRIORITY frame to send
      callback - 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
    • push

      public void push(IStream stream, org.eclipse.jetty.util.Promise<Stream> promise, PushPromiseFrame frame, Stream.Listener listener)
      Description copied from interface: ISession

      Enqueues the given PUSH_PROMISE frame to be written to the connection.

      Differently from ISession.frames(IStream, List, Callback), this method generates atomically the stream id for the pushed stream.

      Specified by:
      push in interface ISession
      Parameters:
      stream - the stream associated to the pushed stream
      promise - the promise that gets notified of the pushed stream creation
      frame - the PUSH_PROMISE frame to enqueue
      listener - the listener that gets notified of pushed stream events
    • settings

      public void settings(SettingsFrame frame, org.eclipse.jetty.util.Callback callback)
      Description copied from interface: Session

      Sends the given SETTINGS frame to configure the session.

      Specified by:
      settings in interface Session
      Parameters:
      frame - the SETTINGS frame to send
      callback - the callback that gets notified when the frame has been sent
    • ping

      public void ping(PingFrame frame, org.eclipse.jetty.util.Callback callback)
      Description copied from interface: Session

      Sends the given PING frame.

      PING frames may be used to test the connection integrity and to measure round-trip time.

      Specified by:
      ping in interface Session
      Parameters:
      frame - the PING frame to send
      callback - the callback that gets notified when the frame has been sent
    • reset

      void reset(IStream stream, ResetFrame frame, org.eclipse.jetty.util.Callback callback)
    • close

      public boolean close(int error, String reason, org.eclipse.jetty.util.Callback callback)

      Invoked internally and by applications to send a GO_AWAY frame to the other peer.

      Specified by:
      close in interface Session
      Parameters:
      error - the error code
      reason - the reason
      callback - 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:
    • goAway

      public boolean goAway(GoAwayFrame frame, org.eclipse.jetty.util.Callback callback)
    • newGoAwayFrame

      private GoAwayFrame newGoAwayFrame(int error, String reason)
    • newGoAwayFrame

      private GoAwayFrame newGoAwayFrame(int lastRemoteStreamId, int error, String reason)
    • isClosed

      public boolean isClosed()
      Specified by:
      isClosed in interface Session
      Returns:
      whether the session is not open
    • getCloseState

      public CloseState getCloseState()
    • control

      private void control(IStream stream, org.eclipse.jetty.util.Callback callback, Frame frame)
    • frames

      public void frames(IStream stream, List<? extends Frame> frames, org.eclipse.jetty.util.Callback callback)
      Description copied from interface: ISession

      Enqueues the given frames to be written to the connection.

      Specified by:
      frames in interface ISession
      Parameters:
      stream - the stream the frames belong to
      frames - the frames to enqueue
      callback - the callback that gets notified when the frames have been sent
    • newEntry

      private HTTP2Flusher.Entry newEntry(Frame frame, IStream stream, org.eclipse.jetty.util.Callback callback)
    • data

      public void data(IStream stream, org.eclipse.jetty.util.Callback callback, DataFrame frame)
      Description copied from interface: ISession

      Enqueues the given DATA frame to be written to the connection.

      Specified by:
      data in interface ISession
      Parameters:
      stream - the stream the data frame belongs to
      callback - the callback that gets notified when the frame has been sent
      frame - the DATA frame to send
    • frame

      private void frame(HTTP2Flusher.Entry entry, boolean flush)
    • createLocalStream

      protected IStream createLocalStream(int streamId, org.eclipse.jetty.util.Promise<Stream> promise)
    • createRemoteStream

      protected IStream createRemoteStream(int streamId)
    • updateStreamCount

      void updateStreamCount(boolean local, int deltaStreams, int deltaClosing)
    • newStream

      protected IStream newStream(int streamId, boolean local)
    • removeStream

      public boolean removeStream(IStream stream)
      Description copied from interface: ISession

      Removes the given stream.

      Specified by:
      removeStream in interface ISession
      Parameters:
      stream - the stream to remove
      Returns:
      whether the stream was removed
    • getStreams

      public Collection<Stream> getStreams()
      Specified by:
      getStreams in interface Session
      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: Session

      Retrieves the stream with the given streamId.

      Specified by:
      getStream in interface ISession
      Specified by:
      getStream in interface Session
      Parameters:
      streamId - the stream id of the stream looked for
      Returns:
      the stream with the given id, or null if no such stream exist
    • 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: ISession

      Updates the session send window by the given delta.

      Specified by:
      updateSendWindow in interface ISession
      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: ISession

      Updates the session receive window by the given delta.

      Specified by:
      updateRecvWindow in interface ISession
      Parameters:
      delta - the delta value (positive or negative) to add to the session receive window
      Returns:
      the previous value of the session receive window
    • isPushEnabled

      @ManagedAttribute(value="Whether HTTP/2 push is enabled", readonly=true) public boolean isPushEnabled()
      Specified by:
      isPushEnabled in interface ISession
      Returns:
      whether the push functionality is enabled
    • onShutdown

      public void onShutdown()

      This method is called when the TCP FIN is received from the remote peer.

      Specified by:
      onShutdown in interface ISession
      See Also:
    • onIdleTimeout

      public boolean onIdleTimeout()

      This method is invoked when the idle timeout expires.

      Specified by:
      onIdleTimeout in interface ISession
      Returns:
      true if the session should be closed, false otherwise
      See Also:
    • notIdle

      private void notIdle()
    • onFrame

      public void onFrame(Frame frame)
      Description copied from interface: ISession

      Callback method invoked during an HTTP/1.1 to HTTP/2 upgrade requests to process the given synthetic frame.

      Specified by:
      onFrame in interface ISession
      Parameters:
      frame - the synthetic frame to process
    • onStreamCreated

      private void onStreamCreated(int streamId)
    • onStreamOpened

      protected final void onStreamOpened(IStream stream)
    • onStreamClosed

      private void onStreamClosed(IStream stream)
    • onStreamDestroyed

      private void onStreamDestroyed(int streamId)
    • onFlushed

      public void onFlushed(long bytes) throws IOException
      Description copied from interface: ISession

      Callback method invoked when bytes are flushed to the network.

      Specified by:
      onFlushed in interface ISession
      Parameters:
      bytes - the number of bytes flushed to the network
      Throws:
      IOException - if the flush should fail
    • terminate

      private void terminate(Throwable cause)
    • disconnect

      public void disconnect()
    • isDisconnected

      public boolean isDisconnected()
    • getLastRemoteStreamId

      protected int getLastRemoteStreamId()
    • updateLastRemoteStreamId

      protected void updateLastRemoteStreamId(int streamId)
    • notifyNewStream

      protected Stream.Listener notifyNewStream(Stream stream, HeadersFrame frame)
    • notifySettings

      protected void notifySettings(Session session, SettingsFrame frame)
    • notifyPing

      protected void notifyPing(Session session, PingFrame frame)
    • notifyReset

      protected void notifyReset(Session session, ResetFrame frame)
    • notifyGoAway

      protected void notifyGoAway(Session session, GoAwayFrame 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, 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(Appendable out, String indent) throws IOException
      Specified by:
      dump in interface org.eclipse.jetty.util.component.Dumpable
      Overrides:
      dump in class org.eclipse.jetty.util.component.ContainerLifeCycle
      Throws:
      IOException
    • toString

      public String toString()
      Overrides:
      toString in class org.eclipse.jetty.util.component.AbstractLifeCycle