Class HTTP2Session

    • Method Detail

      • doStop

        protected void doStop()
                       throws java.lang.Exception
        Description copied from class: ContainerLifeCycle
        Stops the managed lifecycle beans in the reverse order they were added.
        Overrides:
        doStop in class ContainerLifeCycle
        Throws:
        java.lang.Exception
      • 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 EndPoint getEndPoint()
      • 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,
                           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
      • isLocalStreamClosed

        protected boolean isLocalStreamClosed​(int streamId)
      • isRemoteStreamClosed

        protected boolean isRemoteStreamClosed​(int streamId)
      • onResetForUnknownStream

        protected abstract void onResetForUnknownStream​(ResetFrame frame)
      • onSettings

        public void onSettings​(SettingsFrame frame,
                               boolean reply)
      • 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:
        onGoAway in interface Parser.Listener
        Parameters:
        frame - the GO_AWAY frame that has been received.
        See Also:
        close(int, String, Callback), onShutdown(), onIdleTimeout()
      • onStreamFailure

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

        protected void onConnectionFailure​(int error,
                                           java.lang.String reason,
                                           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
      • 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​(IStream stream,
                         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, Callback, Frame, Frame...), 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,
                             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,
                             java.lang.String reason,
                             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, see onIdleTimeout().
        • In all other cases, we do nothing since other methods are already performing their actions.
        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:
        onGoAway(GoAwayFrame), onShutdown(), onIdleTimeout()
      • isClosed

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

        public void frames​(IStream stream,
                           Callback callback,
                           Frame frame,
                           Frame... frames)
        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
        callback - the callback that gets notified when the frames have been sent
        frame - the first frame to enqueue
        frames - additional frames to enqueue
      • data

        public void data​(IStream stream,
                         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
      • 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: ISession

        Removes the given stream.

        Specified by:
        removeStream in interface ISession
        Parameters:
        stream - the stream to remove
      • getStreams

        public java.util.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
      • 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
      • 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
      • 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:
        onShutdown in interface ISession
        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:
        onIdleTimeout in interface ISession
        Returns:
        true if the session should be closed, false otherwise
        See Also:
        onGoAway(GoAwayFrame), close(int, String, Callback), onShutdown()
      • 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
      • onStreamOpened

        protected void onStreamOpened​(IStream stream)
      • onStreamClosed

        protected void onStreamClosed​(IStream stream)
      • onFlushed

        public void onFlushed​(long bytes)
                       throws java.io.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:
        java.io.IOException - if the flush should fail
      • disconnect

        public void disconnect()
      • abort

        protected void abort​(java.lang.Throwable failure)
      • isDisconnected

        public boolean isDisconnected()
      • getLastRemoteStreamId

        protected int getLastRemoteStreamId()
      • notifyIdleTimeout

        protected boolean notifyIdleTimeout​(Session session)
      • notifyFailure

        protected void notifyFailure​(Session session,
                                     java.lang.Throwable failure,
                                     Callback callback)
      • isClientStream

        protected static boolean isClientStream​(int streamId)
      • dump

        public void dump​(java.lang.Appendable out,
                         java.lang.String indent)
                  throws java.io.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:
        java.io.IOException - if unable to write to Appendable