Class 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 Detail

      • DispatchedMessageSink

        public DispatchedMessageSink​(CoreSession session,
                                     java.lang.invoke.MethodHandle methodHandle)
    • Method Detail

      • 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