Class WsListenerBase

java.lang.Object
io.helidon.websocket.WsListenerBase
All Implemented Interfaces:
WsListener

public abstract class WsListenerBase extends Object implements WsListener
A base class for WebSocket listeners to support readers and input streams.

IMPORTANT: use this class only for listeners that are registered as suppliers (i.e. you get a new instance for each web socket session), otherwise the thread guarantees will be broken and this will not work.

  • Constructor Details

    • WsListenerBase

      protected WsListenerBase()
      Create a new listener base for subclasses.
  • Method Details

    • textString

      protected void textString(WsSession session, String text, boolean last, Functions.CheckedConsumer<String,?> stringConsumer)
      Process a text message chunk as a string.

      This method buffers text fragments until the complete text message is available. The buffered message size is limited by WsProtocolConfig.maxBufferedMessageSize(). If the limit is exceeded, this method throws a WsCloseException with close code WsCloseCodes.TOO_BIG.

      Parameters:
      session - WebSocket session
      text - text chunk
      last - whether this is the last chunk
      stringConsumer - consumer of the complete text message
      Throws:
      WsCloseException - when the buffered message size exceeds the configured limit
    • textReader

      protected void textReader(WsSession session, String text, boolean last, Functions.CheckedConsumer<Reader,?> readerConsumer)
      Process a text message chunk as a reader.

      This method delivers fragments through a Reader without whole-message buffering and is not limited by WsProtocolConfig.maxBufferedMessageSize().

      Parameters:
      session - WebSocket session
      text - text chunk
      last - whether this is the last chunk
      readerConsumer - consumer of the text reader
    • binaryBufferData

      protected void binaryBufferData(WsSession session, BufferData buffer, boolean last, Functions.CheckedConsumer<BufferData, ?> bufferDataConsumer)
      Process a binary message chunk as buffer data.

      This method buffers binary fragments until the complete binary message is available. The buffered message size is limited by WsProtocolConfig.maxBufferedMessageSize(). If the limit is exceeded, this method throws a WsCloseException with close code WsCloseCodes.TOO_BIG.

      Parameters:
      session - WebSocket session
      buffer - binary chunk
      last - whether this is the last chunk
      bufferDataConsumer - consumer of the complete binary message
      Throws:
      WsCloseException - when the buffered message size exceeds the configured limit
    • binaryByteBuffer

      protected void binaryByteBuffer(WsSession session, BufferData buffer, boolean last, Functions.CheckedConsumer<ByteBuffer, ?> streamConsumer)
      Process a binary message chunk as a byte buffer.

      This method buffers binary fragments until the complete binary message is available. The buffered message size is limited by WsProtocolConfig.maxBufferedMessageSize(). If the limit is exceeded, this method throws a WsCloseException with close code WsCloseCodes.TOO_BIG.

      Parameters:
      session - WebSocket session
      buffer - binary chunk
      last - whether this is the last chunk
      streamConsumer - consumer of the complete binary message
      Throws:
      WsCloseException - when the buffered message size exceeds the configured limit
    • binaryByteArray

      protected void binaryByteArray(WsSession session, BufferData buffer, boolean last, Functions.CheckedConsumer<byte[],?> byteArrayConsumer)
      Process a binary message chunk as a byte array.

      This method buffers binary fragments until the complete binary message is available. The buffered message size is limited by WsProtocolConfig.maxBufferedMessageSize(). If the limit is exceeded, this method throws a WsCloseException with close code WsCloseCodes.TOO_BIG.

      Parameters:
      session - WebSocket session
      buffer - binary chunk
      last - whether this is the last chunk
      byteArrayConsumer - consumer of the complete binary message
      Throws:
      WsCloseException - when the buffered message size exceeds the configured limit
    • binaryInputStream

      protected void binaryInputStream(WsSession session, BufferData buffer, boolean last, Functions.CheckedConsumer<InputStream, ?> streamConsumer)
      Process a binary message chunk as an input stream.

      This method delivers fragments through an InputStream without whole-message buffering and is not limited by WsProtocolConfig.maxBufferedMessageSize().

      Parameters:
      session - WebSocket session
      buffer - binary chunk
      last - whether this is the last chunk
      streamConsumer - consumer of the binary input stream