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

public abstract Class DispatchedMessageSink

extends AbstractMessageSink
Class Inheritance
Known Direct Subclasses
org.eclipse.jetty.websocket.core.messages.InputStreamMessageSink, org.eclipse.jetty.websocket.core.messages.ReaderMessageSink
Imports
java.io.Closeable, .InputStream, .Reader, java.lang.invoke.MethodHandle, java.util.concurrent.CompletableFuture, .CompletionException, .Executor, org.eclipse.jetty.util.Callback, .IO, org.eclipse.jetty.websocket.core.CloseStatus, .CoreSession, .Frame

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.

Field Summary

Modifier and TypeField and Description
private volatile CompletableFuture<Void>
private final Executor
private MessageSink

Constructor Summary

AccessConstructor and Description
public
DispatchedMessageSink(CoreSession session, MethodHandle methodHandle, boolean autoDemand)

Method Summary

Modifier and TypeMethod and Description
public void
accept(Frame
the frame to consume
frame
,
final Callback
the callback to complete when the frame is consumed
callback
)

Implements org.eclipse.jetty.websocket.core.messages.MessageSink.accept.

Consumes the WebSocket frame, possibly asynchronously when this method has returned.

public void
fail(Throwable
the cause of the failure
failure
)

Overrides default org.eclipse.jetty.websocket.core.messages.MessageSink.fail.

Fails this MessageSink with the given cause.

public boolean
public abstract MessageSink
Inherited from org.eclipse.jetty.websocket.core.messages.AbstractMessageSink:
autoDemandgetCoreSessiongetMethodHandleisAutoDemand

Field Detail

dispatchCompleteback to summary
private volatile CompletableFuture<Void> dispatchComplete
executorback to summary
private final Executor executor
typeSinkback to summary
private MessageSink typeSink

Constructor Detail

DispatchedMessageSinkback to summary
public DispatchedMessageSink(CoreSession session, MethodHandle methodHandle, boolean autoDemand)

Method Detail

acceptback to summary
public void accept(Frame frame, final Callback callback)

Implements org.eclipse.jetty.websocket.core.messages.MessageSink.accept.

Doc from org.eclipse.jetty.websocket.core.messages.MessageSink.accept.

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:Frame

the frame to consume

callback:Callback

the callback to complete when the frame is consumed

failback to summary
public void fail(Throwable failure)

Overrides default org.eclipse.jetty.websocket.core.messages.MessageSink.fail.

Doc from org.eclipse.jetty.websocket.core.messages.MessageSink.fail.

Fails this MessageSink with the given cause.

Parameters
failure:Throwable

the cause of the failure

Annotations
@Override
isDispatchedback to summary
public boolean isDispatched()
newMessageSinkback to summary
public abstract MessageSink newMessageSink()