Class DispatchedMessageSink

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

public abstract class DispatchedMessageSink extends AbstractMessageSink
Centralized logic for Dispatched Message Handling.

A Dispatched MessageSink can consist of 1 or more accept(Frame, Callback) calls.

The first accept(Frame, Callback) in a message will trigger a dispatch to the function specified in the constructor.

The completion of the dispatched function call is the sign that the next message is suitable for processing from the network. (The connection fillAndParse should remain idle for the NEXT message until such time as the dispatched function call has completed)

There are a few use cases we need to handle.

1. Normal Processing

     Connection Thread | DispatchedMessageSink | Thread 2
     TEXT                accept()
                          - dispatch -           function.read(stream)
     CONT                accept()                stream.read()
     CONT                accept()                stream.read()
     CONT=fin            accept()                stream.read()
                           EOF                   stream.read EOF
     IDLE
                                                 exit method
     RESUME(NEXT MSG)
 

2. Early Exit (with no activity)

     Connection Thread | DispatchedMessageSink | Thread 2
     TEXT                accept()
                          - dispatch -           function.read(stream)
     CONT                accept()                exit method (normal return)
     IDLE
     TIMEOUT
 

3. Early Exit (due to exception)

     Connection Thread | DispatchedMessageSink | Thread 2
     TEXT                accept()
                          - dispatch -           function.read(stream)
     CONT                accept()                exit method (throwable)
     callback.fail()
     endpoint.onError()
     close(error)
 

4. Early Exit (with Custom Threading)

     Connection Thread | DispatchedMessageSink | Thread 2              | Thread 3
     TEXT                accept()
                          - dispatch -           function.read(stream)
                                                 thread.new(stream)      stream.read()
                                                 exit method
     CONT                accept()                                        stream.read()
     CONT                accept()                                        stream.read()
     CONT=fin            accept()                                        stream.read()
                           EOF                                           stream.read EOF
     RESUME(NEXT MSG)
 
  • Constructor Details

  • Method Details

    • newSink

      public abstract MessageSink newSink(Frame frame)
    • accept

      public void accept(Frame frame, Callback callback)
      Description copied from interface: MessageSink
      Consume the frame payload to the message.
      Parameters:
      frame - the frame, its payload (and fin state) to append
      callback - the callback for how the frame was consumed
    • fail

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

      Fail the message sink.

      Release any resources and fail all stored callbacks as MessageSink.accept(Frame, Callback) will never be called again.

      Specified by:
      fail in interface MessageSink
      Overrides:
      fail in class AbstractMessageSink
      Parameters:
      failure - the failure that occurred.