Class AbstractMessageSink

java.lang.Object
org.eclipse.jetty.websocket.core.messages.AbstractMessageSink
All Implemented Interfaces:
MessageSink
Direct Known Subclasses:
ByteArrayMessageSink, ByteBufferMessageSink, DispatchedMessageSink, PartialByteArrayMessageSink, PartialByteBufferMessageSink, PartialStringMessageSink, StringMessageSink

public abstract class AbstractMessageSink extends Object implements MessageSink

Abstract implementation of MessageSink.

Management of demand for WebSocket frames may either be entirely managed by the MessageSink implementation (autoDemand==true); or it may be managed collaboratively between the application and the MessageSink implementation (autoDemand==true).

MessageSink implementations must handle the demand for WebSocket frames in this way:

  • If autoDemand==false, the MessageSink manages the demand until the conditions to invoke the application function are met; when the MessageSink invokes the application function, then the application is responsible to demand for more WebSocket frames.
  • If autoDemand==true, only the MessageSink manages the demand for WebSocket frames. If the MessageSink invokes the application function, the MessageSink must demand for WebSocket frames after the invocation of the application function returns successfully.

Method autoDemand() helps to manage the demand after the invocation of the application function returns successfully.

  • Constructor Details

    • AbstractMessageSink

      public AbstractMessageSink(CoreSession session, MethodHolder methodHolder, boolean autoDemand)
      Creates a new MessageSink.
      Parameters:
      session - the WebSocket session
      methodHolder - the application function to invoke
      autoDemand - whether this MessageSink manages demand automatically as explained in AbstractMessageSink
  • Method Details

    • getCoreSession

      public CoreSession getCoreSession()
      Get the WebSocket session.
      Returns:
      the WebSocket session
    • getMethodHolder

      public MethodHolder getMethodHolder()
      Get the application function.
      Returns:
      the application function
    • isAutoDemand

      public boolean isAutoDemand()
      Returns:
      whether this MessageSink automatically demands for more WebSocket frames after the invocation of the application function has returned.
    • autoDemand

      protected void autoDemand()

      If isAutoDemand() then demands for one more WebSocket frame via CoreSession.demand(); otherwise it is a no-operation, because the demand is explicitly managed by the application function.