Top Description Fields Constructors Methods
org.eclipse.jetty.websocket.core.util

public abstract Class DemandingFlusher

extends IteratingCallback
implements DemandChain
Class Inheritance
All Implemented Interfaces
org.eclipse.jetty.websocket.core.util.DemandChain
Known Direct Subclasses
org.eclipse.jetty.websocket.core.internal.FragmentExtension.FragmentingDemandingFlusher, org.eclipse.jetty.websocket.core.internal.PerMessageDeflateExtension.IncomingFlusher
Imports
java.nio.channels.ReadPendingException, java.util.concurrent.atomic.AtomicBoolean, .AtomicReference, org.eclipse.jetty.util.Callback, .CountingCallback, .IteratingCallback, .StaticException, org.eclipse.jetty.websocket.core.Extension, .Frame, .IncomingFrames

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.

Field Summary

Modifier and TypeField and Description
private Callback
private final AtomicBoolean
private final IncomingFrames
private final AtomicReference<Throwable>
private boolean
private Frame
private boolean
private DemandChain
private static final Throwable

Constructor Summary

AccessConstructor and Description
public
DemandingFlusher(IncomingFrames
where frames generated by handle(Frame, Callback, boolean) are forwarded.
emitFrame
)

Method Summary

Modifier and TypeMethod and Description
public void
closeFlusher()

Used to close this flusher when there is no explicit failure.

public void
public void
emitFrame(Frame
the WebSocket frame.
frame
,
Callback
to release frame payload.
callback
)

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

public void
failFlusher(Throwable
the failure.
t
)

Used to fail this flusher possibly from an external event such as a callback.

protected abstract boolean

Returns:

false to continue processing this frame, true to complete processing and get a new frame.
handle
(Frame
the original frame.
frame
,
Callback
to succeed to release the frame payload.
callback
,
boolean
if this is the first time this method has been called for this frame.
first
)

Called when there is demand for a single frame to be produced.

protected void
onCompleteFailure(Throwable
the throwable to indicate cause of failure
cause
)

Overrides org.eclipse.jetty.util.IteratingCallback.onCompleteFailure.

Invoked when the overall task has completed with a failure.

public void
onFrame(Frame
the WebSocket frame.
frame
,
Callback
to release frame payload.
callback
)

Used to supply the flusher with a new frame.

protected IteratingCallback.Action
process()

Implements abstract org.eclipse.jetty.util.IteratingCallback.process.

Method called by iterate() to process the asynchronous sub-task.

public void
Inherited from org.eclipse.jetty.util.IteratingCallback:
abortclosefailedisAbortedisClosedisFailedisSucceedediterateonCompleteSuccessresetsucceededtoString

Field Detail

_callbackback to summary
private Callback _callback
_demandback to summary
private final AtomicBoolean _demand
_emitFrameback to summary
private final IncomingFrames _emitFrame
_failureback to summary
private final AtomicReference<Throwable> _failure

Hides org.eclipse.jetty.util.IteratingCallback._failure.

_firstback to summary
private boolean _first
_frameback to summary
private Frame _frame
_needContentback to summary
private boolean _needContent
_nextDemandback to summary
private DemandChain _nextDemand
SENTINEL_CLOSE_EXCEPTIONback to summary
private static final Throwable SENTINEL_CLOSE_EXCEPTION

Constructor Detail

DemandingFlusherback to summary
public DemandingFlusher(IncomingFrames emitFrame)
Parameters
emitFrame:IncomingFrames

where frames generated by handle(Frame, Callback, boolean) are forwarded.

Method Detail

closeFlusherback to summary
public void closeFlusher()

Used to close this flusher when there is no explicit failure.

demandback to summary
public void demand()

Implements org.eclipse.jetty.websocket.core.util.DemandChain.demand.

Annotations
@Override
emitFrameback to summary
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:Frame

the WebSocket frame.

callback:Callback

to release frame payload.

failFlusherback to summary
public void failFlusher(Throwable t)

Used to fail this flusher possibly from an external event such as a callback.

Parameters
t:Throwable

the failure.

handleback to summary
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:Frame

the original frame.

callback:Callback

to succeed to release the frame payload.

first:boolean

if this is the first time this method has been called for this frame.

Returns:boolean

false to continue processing this frame, true to complete processing and get a new frame.

onCompleteFailureback to summary
protected void onCompleteFailure(Throwable cause)

Overrides org.eclipse.jetty.util.IteratingCallback.onCompleteFailure.

Doc from org.eclipse.jetty.util.IteratingCallback.onCompleteFailure.

Invoked when the overall task has completed with a failure.

Parameters
cause:Throwable

the throwable to indicate cause of failure

Annotations
@Override
onFrameback to summary
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 DemandChain provided by setNextDemand(DemandChain).

Parameters
frame:Frame

the WebSocket frame.

callback:Callback

to release frame payload.

processback to summary
protected IteratingCallback.Action process() throws Throwable

Implements abstract org.eclipse.jetty.util.IteratingCallback.process.

Doc from org.eclipse.jetty.util.IteratingCallback.process.

Method called by iterate() to process the asynchronous sub-task.

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

  • Action#IDLE when no sub tasks are available for execution but the overall job is not completed yet
  • Action#SCHEDULED when the sub task asynchronous execution has been started
  • Action#SUCCEEDED when the overall job is completed
Returns:IteratingCallback.Action

the appropriate Action

Annotations
@Override
Exceptions
Throwable:
if the sub-task processing throws
setNextDemandback to summary
public void setNextDemand(DemandChain nextDemand)

Overrides default org.eclipse.jetty.websocket.core.util.DemandChain.setNextDemand.

Annotations
@Override