Class HTTP2ServerConnectionFactory.HTTPServerSessionListener

java.lang.Object
org.eclipse.jetty.http2.server.HTTP2ServerConnectionFactory.HTTPServerSessionListener
All Implemented Interfaces:
ServerSessionListener, Session.Listener, Stream.Listener
Enclosing class:
HTTP2ServerConnectionFactory

protected class HTTP2ServerConnectionFactory.HTTPServerSessionListener extends Object implements ServerSessionListener, Stream.Listener
  • Constructor Details

    • HTTPServerSessionListener

      public HTTPServerSessionListener(EndPoint endPoint)
  • Method Details

    • onPreface

      public Map<Integer,Integer> onPreface(Session session)
      Description copied from interface: Session.Listener

      Callback method invoked:

      • for clients, just before the preface is sent, to gather the SETTINGS configuration options the client wants to send to the server;
      • for servers, just after having received the preface, to gather the SETTINGS configuration options the server wants to send to the client.
      Specified by:
      onPreface in interface Session.Listener
      Parameters:
      session - the session
      Returns:
      a (possibly empty or null) map containing SETTINGS configuration options to send.
    • onNewStream

      public Stream.Listener onNewStream(Stream stream, HeadersFrame frame)
      Description copied from interface: Session.Listener

      Callback method invoked when a new stream is being created upon receiving a HEADERS frame representing an HTTP request.

      Applications should implement this method to process HTTP requests, typically providing an HTTP response via Stream.headers(HeadersFrame, Callback).

      Applications can detect whether request DATA frames will be arriving by testing HeadersFrame.isEndStream(). If the application is interested in processing the DATA frames, it must demand for DATA frames using Stream.demand() and then return either a Stream.Listener implementation that overrides Stream.Listener.onDataAvailable(Stream) where applications can read from the Stream via Stream.readData(), or Stream.Listener.AUTO_DISCARD that automatically reads and discards DATA frames. Returning null is possible but discouraged, and has the same effect of demanding and discarding the DATA frames.

      Specified by:
      onNewStream in interface Session.Listener
      Parameters:
      stream - the newly created stream
      frame - the HEADERS frame received
      Returns:
      a Stream.Listener that will be notified of stream events
    • onIdleTimeout

      public boolean onIdleTimeout(Session session)
      Description copied from interface: Session.Listener

      Callback method invoked when the idle timeout expired.

      Specified by:
      onIdleTimeout in interface Session.Listener
      Parameters:
      session - the session
      Returns:
      whether the session should be closed
    • onClose

      public void onClose(Session session, GoAwayFrame frame, Callback callback)
      Description copied from interface: Session.Listener

      Callback method invoked when a GOAWAY frame caused the session to be closed.

      Specified by:
      onClose in interface Session.Listener
      Parameters:
      session - the session
      frame - the GOAWAY frame that caused the session to be closed
      callback - the callback to notify of the GOAWAY processing
    • onFailure

      public void onFailure(Session session, Throwable failure, Callback callback)
      Description copied from interface: Session.Listener

      Callback method invoked when a failure has been detected for this session.

      Specified by:
      onFailure in interface Session.Listener
      Parameters:
      session - the session
      failure - the failure
      callback - the callback to notify of failure processing
    • onHeaders

      public void onHeaders(Stream stream, HeadersFrame frame)
      Description copied from interface: Stream.Listener

      Callback method invoked when a HEADERS frame representing the HTTP response has been received.

      Specified by:
      onHeaders in interface Stream.Listener
      Parameters:
      stream - the stream
      frame - the HEADERS frame received
    • onPush

      public Stream.Listener onPush(Stream stream, PushPromiseFrame frame)
      Description copied from interface: Stream.Listener

      Callback method invoked when a PUSH_PROMISE frame has been received.

      Applications that override this method are typically interested in processing the pushed stream DATA frames, and must demand for pushed DATA frames via Stream.demand() and then return either a Stream.Listener implementation that overrides Stream.Listener.onDataAvailable(Stream) where applications can read from the Stream via Stream.readData(), or Stream.Listener.AUTO_DISCARD that automatically reads and discards DATA frames. Returning null is possible but discouraged, and has the same effect of demanding and discarding the pushed DATA frames.

      Specified by:
      onPush in interface Stream.Listener
      Parameters:
      stream - the pushed stream
      frame - the PUSH_PROMISE frame received
      Returns:
      a Stream.Listener that will be notified of pushed stream events
    • onDataAvailable

      public void onDataAvailable(Stream stream)
      Description copied from interface: Stream.Listener

      Callback method invoked if the application has expressed demand for DATA frames, and if there may be content available.

      Applications that wish to handle DATA frames should call Stream.demand() for this method to be invoked when the data is available.

      Server applications should typically demand from Stream.Listener.onNewStream(Stream) (upon receiving an HTTP request), while client applications should typically demand from Stream.Listener.onHeaders(Stream, HeadersFrame) (upon receiving an HTTP response).

      Just prior calling this method, the outstanding demand is cancelled; applications that implement this method should read content calling Stream.readData(), and call Stream.demand() to signal to the implementation to call again this method when there may be more content available.

      Only one thread at a time invokes this method, although it may not be the same thread across different invocations.

      It is always guaranteed that invoking Stream.demand() from within this method will not cause a StackOverflowError.

      Typical usage:

      
       class MyStreamListener implements Stream.Listener
       {
           @Override
           public void onDataAvailable(Stream stream)
           {
               // Read a chunk of the content.
               Stream.Data data = stream.readData();
               if (data == null)
               {
                   // No data available now, demand to be called back.
                   stream.demand();
               }
               else
               {
                   // Process the content.
                   process(data.frame().getByteBuffer());
                   // Notify that the content has been consumed.
                   data.release();
                   if (!data.frame().isEndStream())
                   {
                       // Demand to be called back.
                       stream.demand();
                   }
               }
           }
       }
       
      Specified by:
      onDataAvailable in interface Stream.Listener
      Parameters:
      stream - the stream
      See Also:
    • onReset

      public void onReset(Stream stream, ResetFrame frame, Callback callback)
      Description copied from interface: Stream.Listener

      Callback method invoked when a RST_STREAM frame has been received for this stream.

      Specified by:
      onReset in interface Stream.Listener
      Parameters:
      stream - the stream
      frame - the RST_STREAM frame received
      callback - the callback to complete when the reset has been handled
    • onFailure

      public void onFailure(Stream stream, int error, String reason, Throwable failure, Callback callback)
      Description copied from interface: Stream.Listener

      Callback method invoked when the stream failed.

      Specified by:
      onFailure in interface Stream.Listener
      Parameters:
      stream - the stream
      error - the error code
      reason - the error reason, or null
      failure - the failure
      callback - the callback to complete when the failure has been handled
    • onIdleTimeout

      public void onIdleTimeout(Stream stream, TimeoutException x, Promise<Boolean> promise)
      Description copied from interface: Stream.Listener

      Callback method invoked when the stream exceeds its idle timeout.

      Specified by:
      onIdleTimeout in interface Stream.Listener
      Parameters:
      stream - the stream
      x - the timeout failure
      promise - the promise to complete
      See Also: