Class ProtocolStreamListener

java.lang.Object
org.eclipse.jetty.quic.common.ProtocolStreamListener
All Implemented Interfaces:
EventListener, Stream.Listener
Direct Known Subclasses:
ProtocolStreamListener.Client, ProtocolStreamListener.Server

public abstract class ProtocolStreamListener extends Object implements Stream.Listener
  • Constructor Details

    • ProtocolStreamListener

      public ProtocolStreamListener()
  • Method Details

    • getStreamEndPoint

      protected abstract StreamEndPoint getStreamEndPoint()
    • onDataAvailable

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

      Callback method invoked when the application has expressed demand for data carried by STREAM frames, and there are STREAM frames available.

      Server applications should typically demand from Stream.Listener.onNewStream(Stream, Frame.WithStreamId) (upon receiving the first stream frame), while client applications should typically demand after obtaining a Stream via Session.newStream(long, Listener).

      Just prior calling this method, the outstanding demand is cancelled; applications that implement this method should read content calling Stream.read(), and call Stream.demand() to signal to the implementation to call again this method when there may be more data 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)
           {
               while (true)
               {
                   // Read a chunk of the content.
                   Content.Chunk chunk = stream.read();
                   if (chunk == null)
                   {
                       // No data available now, demand to be called back.
                       stream.demand();
                       return;
                   }
      
                   // Process the content chunk.
                   process(chunk);
      
                   // Notify that the content has been consumed.
                   chunk.release();
      
                   if (chunk.isLast())
                   {
                       // All data has been processed.
                       return;
                   }
               }
           }
       }
       
      Specified by:
      onDataAvailable in interface Stream.Listener
      Parameters:
      stream - the stream
      See Also:
    • onIdleTimeout

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

      Invoked when the stream is idle for longer than the idle timeout.

      Specified by:
      onIdleTimeout in interface Stream.Listener
      Parameters:
      stream - the stream
      failure - the idle timeout failure
      promise - the promise to complete to notify the other peer that this stream is closing
    • onFailure

      public void onFailure(Stream stream, Throwable failure)
      Description copied from interface: Stream.Listener

      Invoked when a stream failure is detected.

      Specified by:
      onFailure in interface Stream.Listener
      Parameters:
      stream - the stream
      failure - the stream failure