Class DispatchedMessageSink
- All Implemented Interfaces:
MessageSink
- Direct Known Subclasses:
InputStreamMessageSink
,ReaderMessageSink
A partial implementation of MessageSink
for methods that consume WebSocket
messages using blocking stream APIs, typically via InputStream
or Reader
.
The first call to accept(Frame, Callback)
triggers the application function
specified in the constructor to be invoked in a different thread.
Subsequent calls to accept(Frame, Callback)
feed a nested MessageSink
that in turns feeds the InputStream
or Reader
stream.
Implementations of this class must manage the demand for WebSocket frames, and therefore must always be auto-demanding.
Upon return from the application function, the stream is closed. This means that the stream must be consumed synchronously within the invocation of the application function.
The demand for the next WebSocket message is performed when both the application function has returned and the last frame has been consumed (signaled by completing the callback associated with the frame).
Throwing from the application function results in the WebSocket connection to be closed.
-
Constructor Summary
ConstructorDescriptionDispatchedMessageSink
(CoreSession session, MethodHandle methodHandle, boolean autoDemand) -
Method Summary
Modifier and TypeMethodDescriptionvoid
Consumes the WebSocket frame, possibly asynchronously when this method has returned.void
Fails thisMessageSink
with the given cause.boolean
abstract MessageSink
Methods inherited from class org.eclipse.jetty.websocket.core.messages.AbstractMessageSink
autoDemand, getCoreSession, getMethodHandle, isAutoDemand
-
Constructor Details
-
DispatchedMessageSink
-
-
Method Details
-
newMessageSink
-
accept
Description copied from interface:MessageSink
Consumes the WebSocket frame, possibly asynchronously when this method has returned.
The callback argument must be completed when the frame payload is consumed.
The demand for more frames must be explicitly invoked, or arranged to be invoked asynchronously, by the implementation of this method, by calling
CoreSession.demand()
.- Parameters:
frame
- the frame to consumecallback
- the callback to complete when the frame is consumed
-
fail
Description copied from interface:MessageSink
Fails this
MessageSink
with the given cause.- Parameters:
failure
- the cause of the failure
-
isDispatched
public boolean isDispatched()
-