Class DispatchedMessageSink

java.lang.Object
org.eclipse.jetty.websocket.core.messages.AbstractMessageSink
org.eclipse.jetty.websocket.core.messages.DispatchedMessageSink
All Implemented Interfaces:
MessageSink
Direct Known Subclasses:
InputStreamMessageSink, ReaderMessageSink

public abstract class DispatchedMessageSink extends AbstractMessageSink

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 Details

    • DispatchedMessageSink

      public DispatchedMessageSink(CoreSession session, MethodHandle methodHandle, boolean autoDemand)
  • Method Details

    • newMessageSink

      public abstract MessageSink newMessageSink()
    • accept

      public void accept(Frame frame, Callback callback)
      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 consume
      callback - the callback to complete when the frame is consumed
    • fail

      public void fail(Throwable failure)
      Description copied from interface: MessageSink

      Fails this MessageSink with the given cause.

      Parameters:
      failure - the cause of the failure
    • isDispatched

      public boolean isDispatched()