Class DemandingFlusher

java.lang.Object
org.eclipse.jetty.util.IteratingCallback
org.eclipse.jetty.websocket.core.internal.DemandingFlusher
All Implemented Interfaces:
Callback, Invocable, DemandChain
Direct Known Subclasses:
FragmentExtension.FragmentingDemandingFlusher

public abstract class DemandingFlusher extends IteratingCallback implements DemandChain

This flusher can be used to mutated and fragment Frames and forwarded them on towards the application using the IncomingFrames provided in the constructor. This can split a single incoming frame into n Frames which are passed on to the IncomingFrames one at a time.

The asynchronous operation performed by this IteratingCallback is demanding from upper layer after which onFrame(Frame, Callback) will called with the new content.

This flusher relies on the interception of demand, and because of this it can only be used in an Extension which implements the DemandChain interface. The methods of DemandChain from the Extension must be forwarded to this flusher.

  • Constructor Details

  • Method Details

    • handle

      protected abstract boolean handle(Frame frame, Callback callback, boolean first)

      Called when there is demand for a single frame to be produced. During this method a single call can be made to emitFrame(Frame, Callback) which will forward this frame towards the application. Returning true from this method signals that you are done processing the current Frame, and the next invocation of this method will have the next frame.

      Note that the callback supplied here is specially wrapped so that you can call it multiple times and it will not be completed more than once. This simplifies the handling of failure cases.

      Parameters:
      frame - the original frame.
      callback - to succeed to release the frame payload.
      first - if this is the first time this method has been called for this frame.
      Returns:
      false to continue processing this frame, true to complete processing and get a new frame.
    • demand

      public void demand(long n)
      Specified by:
      demand in interface DemandChain
    • setNextDemand

      public void setNextDemand(LongConsumer nextDemand)
      Specified by:
      setNextDemand in interface DemandChain
    • onFrame

      public void onFrame(Frame frame, Callback callback)
      Used to supply the flusher with a new frame. This frame should only arrive if demanded through the LongConsumer provided by setNextDemand(LongConsumer).
      Parameters:
      frame - the WebSocket frame.
      callback - to release frame payload.
    • closeFlusher

      public void closeFlusher()
      Used to close this flusher when there is no explicit failure.
    • failFlusher

      public void failFlusher(Throwable t)
      Used to fail this flusher possibly from an external event such as a callback.
      Parameters:
      t - the failure.
    • emitFrame

      public void emitFrame(Frame frame, Callback callback)

      This is used within an implementation of handle(Frame, Callback, boolean) to forward a frame onto the next layer of processing.

      This method should only be called ONCE within each invocation of handle(Frame, Callback, boolean) otherwise

      Parameters:
      frame - the WebSocket frame.
      callback - to release frame payload.
    • process

      protected IteratingCallback.Action process() throws Throwable
      Description copied from class: IteratingCallback
      Method called by IteratingCallback.iterate() to process the asynchronous sub-task.

      Implementations must initiate the asynchronous execution of the sub-task (if any) and return an appropriate action:

      Specified by:
      process in class IteratingCallback
      Returns:
      the appropriate Action
      Throws:
      Throwable - if the sub-task processing throws
    • onCompleteFailure

      protected void onCompleteFailure(Throwable cause)
      Description copied from class: IteratingCallback
      Invoked when the overall task has completed with a failure.
      Overrides:
      onCompleteFailure in class IteratingCallback
      Parameters:
      cause - the throwable to indicate cause of failure
      See Also: