Class DemandingFlusher

All Implemented Interfaces:
Callback, Invocable, DemandChain
Direct Known Subclasses:

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.

      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.
      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).
      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.
      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

      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
      the appropriate Action
      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.
      onCompleteFailure in class IteratingCallback
      cause - the throwable to indicate cause of failure
      See Also: