Class WebSocketDemander
- All Implemented Interfaces:
Callback
,Invocable
,DemandChain
This flusher can be used to mutated and fragment Frame
s and forwarded them on towards the application using the
IncomingFrames
provided in the constructor. This can split a single incoming frame into n Frame
s 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.Action
Nested classes/interfaces inherited from interface org.eclipse.jetty.util.Callback
Callback.Combination, Callback.Completable, Callback.Completing, Callback.Nested
Nested classes/interfaces inherited from interface org.eclipse.jetty.util.thread.Invocable
Invocable.Callable, Invocable.InvocationType, Invocable.ReadyTask, Invocable.Task
-
Field Summary
Fields inherited from interface org.eclipse.jetty.util.Callback
NOOP, NOT_CALLED
Fields inherited from interface org.eclipse.jetty.util.thread.Invocable
__nonBlocking
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
Used to close this flusher when there is no explicit failure.void
demand()
This is demand is called by the application to demand a new frame to be processed inhandle(Frame, Callback, boolean)
.void
This is used within an implementation ofhandle(Frame, Callback, boolean)
to forward a frame onto the next layer of processing.void
Used to fail this flusher possibly from an external event such as a callback.protected abstract boolean
Called when there is demand for a single frame to be produced.protected void
onCompleteFailure
(Throwable cause) Invoked when the overall task has completed with a failure.void
Used to supply the flusher with a new frame.protected IteratingCallback.Action
process()
Method called byIteratingCallback.iterate()
to process the asynchronous sub-task.void
setNextDemand
(DemandChain nextDemand) Set the nextDemandChain
instance towards the transport side of theDemandChain
pipeline.Methods inherited from class org.eclipse.jetty.util.IteratingCallback
abort, close, failed, isAborted, isClosed, isFailed, isSucceeded, iterate, onAborted, onCompleted, onCompleteSuccess, onFailure, onSuccess, reset, succeeded, toString
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface org.eclipse.jetty.util.Callback
completeWith
Methods inherited from interface org.eclipse.jetty.util.thread.Invocable
getInvocationType
-
Constructor Details
-
WebSocketDemander
- Parameters:
emitFrame
- where frames generated byhandle(Frame, Callback, boolean)
are forwarded.
-
-
Method Details
-
setNextDemand
Description copied from interface:DemandChain
Set the nextDemandChain
instance towards the transport side of theDemandChain
pipeline.- Specified by:
setNextDemand
in interfaceDemandChain
- Parameters:
nextDemand
- the next link in the demand chain.
-
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.
-
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.
-
demand
public void demand()This is demand is called by the application to demand a new frame to be processed inhandle(Frame, Callback, boolean)
.- Specified by:
demand
in interfaceDemandChain
-
onFrame
Used to supply the flusher with a new frame. This frame should only arrive if demanded through theDemandChain
provided bysetNextDemand(DemandChain)
.- 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.
-
process
Description copied from class:IteratingCallback
Method 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.IDLE
when no sub tasks are available for execution but the overall job is not completed yetIteratingCallback.Action.SCHEDULED
when the sub task asynchronous execution has been startedIteratingCallback.Action.SUCCEEDED
when the overall job is completed
- Specified by:
process
in classIteratingCallback
- Returns:
- the appropriate Action
- Throws:
Throwable
- if the sub-task processing throws
-
onCompleteFailure
Description copied from class:IteratingCallback
Invoked when the overall task has completed with a failure.Calls to this method are serialized with respect to
IteratingCallback.process()
,IteratingCallback.onAborted(Throwable)
andIteratingCallback.onCompleted(Throwable)
. If this method is called, thenIteratingCallback.onCompleteSuccess()
will never be called.- Overrides:
onCompleteFailure
in classIteratingCallback
- Parameters:
cause
- the throwable to indicate cause of failure- See Also:
-