Class DemandingFlusher
- All Implemented Interfaces:
Callback,Invocable,DemandChain
- Direct Known Subclasses:
FragmentExtension.FragmentingDemandingFlusher
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.
-
Nested Class Summary
Nested classes/interfaces inherited from class org.eclipse.jetty.util.IteratingCallback
IteratingCallback.ActionNested classes/interfaces inherited from interface org.eclipse.jetty.util.Callback
Callback.Completable, Callback.Completing, Callback.NestedNested classes/interfaces inherited from interface org.eclipse.jetty.util.thread.Invocable
Invocable.InvocationType, Invocable.ReadyTask, Invocable.Task -
Field Summary
Fields inherited from interface org.eclipse.jetty.util.thread.Invocable
__nonBlocking -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidUsed to close this flusher when there is no explicit failure.voiddemand(long n) voidThis is used within an implementation ofhandle(Frame, Callback, boolean)to forward a frame onto the next layer of processing.voidUsed to fail this flusher possibly from an external event such as a callback.protected abstract booleanCalled when there is demand for a single frame to be produced.protected voidonCompleteFailure(Throwable cause) Invoked when the overall task has completed with a failure.voidUsed to supply the flusher with a new frame.protected IteratingCallback.Actionprocess()Method called byIteratingCallback.iterate()to process the asynchronous sub-task.voidsetNextDemand(LongConsumer nextDemand) Methods inherited from class org.eclipse.jetty.util.IteratingCallback
close, failed, isClosed, isFailed, isSucceeded, iterate, onCompleteSuccess, reset, succeeded, toStringMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface org.eclipse.jetty.util.Callback
completeWithMethods inherited from interface org.eclipse.jetty.util.thread.Invocable
getInvocationType
-
Constructor Details
-
DemandingFlusher
- Parameters:
emitFrame- where frames generated byhandle(Frame, Callback, boolean)are forwarded.
-
-
Method Details
-
handle
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:
demandin interfaceDemandChain
-
setNextDemand
- Specified by:
setNextDemandin interfaceDemandChain
-
onFrame
Used to supply the flusher with a new frame. This frame should only arrive if demanded through theLongConsumerprovided bysetNextDemand(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
Used to fail this flusher possibly from an external event such as a callback.- Parameters:
t- the failure.
-
emitFrame
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
Description copied from class:IteratingCallbackMethod called byIteratingCallback.iterate()to process the asynchronous sub-task.Implementations must initiate the asynchronous execution of the sub-task (if any) and return an appropriate action:
IteratingCallback.Action.IDLEwhen no sub tasks are available for execution but the overall job is not completed yetIteratingCallback.Action.SCHEDULEDwhen the sub task asynchronous execution has been startedIteratingCallback.Action.SUCCEEDEDwhen the overall job is completed
- Specified by:
processin classIteratingCallback- Returns:
- the appropriate Action
- Throws:
Throwable- if the sub-task processing throws
-
onCompleteFailure
Description copied from class:IteratingCallbackInvoked when the overall task has completed with a failure.- Overrides:
onCompleteFailurein classIteratingCallback- Parameters:
cause- the throwable to indicate cause of failure- See Also:
-