Class HTTP2Session

All Implemented Interfaces:
Session, Parser.Listener, Container, Destroyable, Dumpable, Dumpable.DumpableContainer, LifeCycle
Direct Known Subclasses:
HTTP2ClientSession, HTTP2ServerSession

@ManagedObject public abstract class HTTP2Session extends ContainerLifeCycle implements Session, Parser.Listener
  • Constructor Details

  • Method Details

    • doStop

      protected void doStop() throws Exception
      Description copied from class: ContainerLifeCycle
      Stops the managed lifecycle beans in the reverse order they were added.
      Overrides:
      doStop in class ContainerLifeCycle
      Throws:
      Exception - If there was a problem stopping. Will cause a transition to FAILED state
    • 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)
    • getMaxTotalLocalStreams

      @ManagedAttribute("The maximum number of local streams that can be opened") public int getMaxTotalLocalStreams()
    • setMaxTotalLocalStreams

      public void setMaxTotalLocalStreams(int maxTotalLocalStreams)
    • 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 EndPoint getEndPoint()
    • getParser

      public Parser getParser()
    • getGenerator

      public Generator getGenerator()
    • getBytesWritten

      public long getBytesWritten()
    • onData

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

      public void onData(Stream.Data data)
    • 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)
    • 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(HTTP2Stream stream, WindowUpdateFrame frame)
    • 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
    • onWriteFailure

      public void onWriteFailure(Throwable failure)
    • abort

      protected void abort(String reason, Throwable failure, Callback callback)
    • newStream

      public void newStream(HeadersFrame frame, 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(HTTP2Stream.FrameList frames, Promise<Stream> promise, Stream.Listener listener)
    • newUpgradeStream

      public Stream newUpgradeStream(HeadersFrame frame, Stream.Listener listener, Consumer<Throwable> failFn)

      Creates a new stream allocating a stream id if the given HEADERS frame does not have one.

      Parameters:
      frame - the HEADERS frame that triggered the stream creation allocated stream id, or null if not interested in the modified headers frame
      listener - the listener that gets notified of stream events
    • newStream

      protected HTTP2Stream newStream(int streamId, MetaData.Request request, boolean local)
    • priority

      public int priority(PriorityFrame frame, 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(Stream stream, Promise<Stream> promise, PushPromiseFrame frame, Stream.Listener listener)
    • settings

      public void settings(SettingsFrame frame, 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, 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
    • close

      public boolean close(int error, String reason, 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:
    • shutdown

      public CompletableFuture<Void> shutdown()
      Description copied from interface: Session

      Gracefully closes the session, returning a CompletableFuture that is completed when all the streams currently being processed are completed.

      Implementation is idempotent, i.e. calling this method a second time or concurrently results in a no-operation.

      Specified by:
      shutdown in interface Session
      Returns:
      a CompletableFuture that is completed when all the streams are completed
    • goAway

      public boolean goAway(GoAwayFrame frame, Callback callback)
    • isClosed

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

      public CloseState getCloseState()
    • frames

      public void frames(HTTP2Stream stream, List<? extends Frame> frames, Callback callback)
    • data

      public void data(HTTP2Stream stream, DataFrame frame, Callback callback)
    • createLocalStream

      protected HTTP2Stream createLocalStream(int streamId, MetaData.Request request, Consumer<Throwable> failFn)
    • createRemoteStream

      protected HTTP2Stream createRemoteStream(int streamId, MetaData.Request request)
    • removeStream

      public boolean removeStream(Stream stream)
    • 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 HTTP2Stream getStream(int streamId)
      Description copied from interface: Session

      Retrieves the stream with the given streamId.

      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
    • getLocalAddress

      public InetSocketAddress getLocalAddress()
      Specified by:
      getLocalAddress in interface Session
      Returns:
      the local network address this session is bound to, or null if this session is not bound to a network address
    • getLocalSocketAddress

      public SocketAddress getLocalSocketAddress()
      Specified by:
      getLocalSocketAddress in interface Session
      Returns:
      the local network address this session is bound to, or null if this session is not bound to a network address
    • getRemoteAddress

      public InetSocketAddress getRemoteAddress()
      Specified by:
      getRemoteAddress in interface Session
      Returns:
      the remote network address this session is connected to, or null if this session is not connected to a network address
    • getRemoteSocketAddress

      public SocketAddress getRemoteSocketAddress()
      Specified by:
      getRemoteSocketAddress in interface Session
      Returns:
      the remote network address this session is connected to, or null if this session is not connected to a network address
    • 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)
    • updateRecvWindow

      public int updateRecvWindow(int delta)
    • isPushEnabled

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

      @ManagedAttribute(value="Whether CONNECT requests supports a protocol", readonly=true) public boolean isConnectProtocolEnabled()
    • setConnectProtocolEnabled

      public void setConnectProtocolEnabled(boolean connectProtocolEnabled)
    • onShutdown

      public void onShutdown()

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

      See Also:
    • onIdleTimeout

      public boolean onIdleTimeout()

      This method is invoked when the idle timeout expires.

      Returns:
      true if the session should be closed, false otherwise
      See Also:
    • onFrame

      public void onFrame(Frame frame)
    • onStreamOpened

      protected final void onStreamOpened(Stream stream)
    • 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, Callback callback)
    • notifyIdleTimeout

      protected boolean notifyIdleTimeout(Session session)
    • notifyFailure

      protected void notifyFailure(Session session, Throwable failure, Callback callback)
    • isClientStream

      protected static boolean isClientStream(int streamId)
    • dump

      public void dump(Appendable out, String indent) throws IOException
      Description copied from interface: Dumpable
      Dump this object (and children) into an Appendable using the provided indent after any new lines. The indent should not be applied to the first object dumped.
      Specified by:
      dump in interface Dumpable
      Overrides:
      dump in class ContainerLifeCycle
      Parameters:
      out - The appendable to dump to
      indent - The indent to apply after any new lines.
      Throws:
      IOException - if unable to write to Appendable
    • toString

      public String toString()
      Overrides:
      toString in class AbstractLifeCycle