Class WsListenerBase
- All Implemented Interfaces:
WsListener
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 Summary
ConstructorsModifierConstructorDescriptionprotectedCreate a new listener base for subclasses. -
Method Summary
Modifier and TypeMethodDescriptionprotected voidbinaryBufferData(WsSession session, BufferData buffer, boolean last, Functions.CheckedConsumer<BufferData, ?> bufferDataConsumer) Process a binary message chunk as buffer data.protected voidbinaryByteArray(WsSession session, BufferData buffer, boolean last, Functions.CheckedConsumer<byte[], ?> byteArrayConsumer) Process a binary message chunk as a byte array.protected voidbinaryByteBuffer(WsSession session, BufferData buffer, boolean last, Functions.CheckedConsumer<ByteBuffer, ?> streamConsumer) Process a binary message chunk as a byte buffer.protected voidbinaryInputStream(WsSession session, BufferData buffer, boolean last, Functions.CheckedConsumer<InputStream, ?> streamConsumer) Process a binary message chunk as an input stream.protected voidtextReader(WsSession session, String text, boolean last, Functions.CheckedConsumer<Reader, ?> readerConsumer) Process a text message chunk as a reader.protected voidtextString(WsSession session, String text, boolean last, Functions.CheckedConsumer<String, ?> stringConsumer) Process a text message chunk as a string.Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface WsListener
onClose, onError, onHttpUpgrade, onMessage, onMessage, onOpen, onPing, onPongModifier and TypeMethodDescriptiondefault voidReceived close.default voidError occurred.onHttpUpgrade(HttpPrologue prologue, Headers headers) Invoked during handshake process.default voidonMessage(WsSession session, BufferData buffer, boolean last) Received binary fragment.default voidReceived text fragment.default voidSession is open.default voidonPing(WsSession session, BufferData buffer) Received ping.default voidonPong(WsSession session, BufferData buffer) Received pong.
-
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 aWsCloseExceptionwith close codeWsCloseCodes.TOO_BIG.- Parameters:
session- WebSocket sessiontext- text chunklast- whether this is the last chunkstringConsumer- 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
Readerwithout whole-message buffering and is not limited byWsProtocolConfig.maxBufferedMessageSize().- Parameters:
session- WebSocket sessiontext- text chunklast- whether this is the last chunkreaderConsumer- 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 aWsCloseExceptionwith close codeWsCloseCodes.TOO_BIG.- Parameters:
session- WebSocket sessionbuffer- binary chunklast- whether this is the last chunkbufferDataConsumer- 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 aWsCloseExceptionwith close codeWsCloseCodes.TOO_BIG.- Parameters:
session- WebSocket sessionbuffer- binary chunklast- whether this is the last chunkstreamConsumer- 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 aWsCloseExceptionwith close codeWsCloseCodes.TOO_BIG.- Parameters:
session- WebSocket sessionbuffer- binary chunklast- whether this is the last chunkbyteArrayConsumer- 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
InputStreamwithout whole-message buffering and is not limited byWsProtocolConfig.maxBufferedMessageSize().- Parameters:
session- WebSocket sessionbuffer- binary chunklast- whether this is the last chunkstreamConsumer- consumer of the binary input stream
-