A utility implementation of FrameHandler that aggregates TEXT frames
into a String message before calling onText(String, Callback).
| Modifier and Type | Field and Description |
|---|---|
| private ByteArrayOutputStream | |
| private CoreSession | |
| private byte | |
| private static final Logger | |
| private Utf8StringBuilder |
| Access | Constructor and Description |
|---|---|
| public |
| Modifier and Type | Method and Description |
|---|---|
| public static MessageHandler | |
| private ByteArrayOutputStream | |
| public CoreSession | |
| private Utf8StringBuilder | |
| protected void | onBinary(ByteBuffer
The binary payload message, Callback The callback to signal completion of handling. callback)Method called when a complete binary message is received. |
| protected void | |
| public void | onClosed(CloseStatus
the close status received from the remote peer,
or generated locally in the case of abnormal closures. closeStatus, Callback the callback to indicate success or failure of
the processing of this event. callback)Implements org. Invoked when a WebSocket close event happened. |
| protected void | |
| protected void | |
| public void | onError(Throwable
the error cause cause, Callback the callback to indicate success or failure of
the processing of this event. callback)Implements org. Invoked when an error has occurred or has been detected. |
| public void | onFrame(Frame
the WebSocket frame. frame, Callback the callback to indicate success or failure of
the processing of this event. callback)Implements org. Invoked when a WebSocket frame is received. |
| public void | onOpen(CoreSession
the session associated with this connection. coreSession, Callback the callback to indicate success or failure of
the processing of this event. callback)Implements org. Invoked when the WebSocket connection is opened. |
| protected void | |
| protected void | |
| protected void | |
| protected void | |
| public void | sendBinary(ByteBuffer
The message to send message, Callback The callback to call when the send is complete callback, boolean The batch mode to send the frames in. batch)Send a ByteBuffer as a single binary frame. |
| public void | sendBinary(Callback
The callback to call when the send is complete callback, boolean The batch mode to send the frames in. batch, final ByteBuffer... The parts of the message. parts)Send a sequence of ByteBuffers as a sequences for fragmented text frame. |
| public void | |
| public void |
| binaryMessageBuffer | back to summary |
|---|---|
| private ByteArrayOutputStream binaryMessageBuffer | |
| coreSession | back to summary |
|---|---|
| private CoreSession coreSession | |
| dataType | back to summary |
|---|---|
| private byte dataType | |
| LOG | back to summary |
|---|---|
| private static final Logger LOG | |
| textMessageBuffer | back to summary |
|---|---|
| private Utf8StringBuilder textMessageBuffer | |
| MessageHandler | back to summary |
|---|---|
| public MessageHandler() | |
| from | back to summary |
|---|---|
| public static MessageHandler from(Consumer<String> onText, Consumer<ByteBuffer> onBinary) | |
| getBinaryMessageBuffer | back to summary |
|---|---|
| private ByteArrayOutputStream getBinaryMessageBuffer() | |
| getCoreSession | back to summary |
|---|---|
| public CoreSession getCoreSession() | |
| getTextMessageBuffer | back to summary |
|---|---|
| private Utf8StringBuilder getTextMessageBuffer() | |
| onBinary | back to summary |
|---|---|
| protected void onBinary(ByteBuffer message, Callback callback) Method called when a complete binary message is received.
| |
| onBinaryFrame | back to summary |
|---|---|
| protected void onBinaryFrame(Frame frame, Callback callback) | |
| onClosed | back to summary |
|---|---|
| public void onClosed(CloseStatus closeStatus, Callback callback) Implements org. Doc from org. Invoked when a WebSocket close event happened. The WebSocket connection is closed, no reading or writing is possible anymore. Implementations of this method may cleanup resources that have been allocated. This method will not be called more than once.
| |
| onCloseFrame | back to summary |
|---|---|
| protected void onCloseFrame(Frame frame, Callback callback) | |
| onContinuationFrame | back to summary |
|---|---|
| protected void onContinuationFrame(Frame frame, Callback callback) | |
| onError | back to summary |
|---|---|
| public void onError(Throwable cause, Callback callback) Implements org. Doc from org. Invoked when an error has occurred or has been detected. A call to this method will be followed by a call to
This method will not be called more than once, | |
| onFrame | back to summary |
|---|---|
| public void onFrame(Frame frame, Callback callback) Implements org. Doc from org. Invoked when a WebSocket frame is received. This method will never be called concurrently for the
same session; will be called sequentially to satisfy the
outstanding demand signaled by calls to
Both control and data frames are passed to this method. CLOSE frames may be responded from this method, but if they are not responded, then the implementation will respond when the callback is completed. The callback argument must be completed to indicate that the buffers associated with the frame can be recycled. Additional WebSocket frames (of any type, including CLOSE
frames) cannot be received until a call to
| |
| onOpen | back to summary |
|---|---|
| public void onOpen(CoreSession coreSession, Callback callback) Implements org. Doc from org. Invoked when the WebSocket connection is opened. It is allowed to send WebSocket frames via
WebSocket frames cannot be received until a call to
If the callback argument is failed, the implementation
sends a CLOSE frame with
| |
| onPingFrame | back to summary |
|---|---|
| protected void onPingFrame(Frame frame, Callback callback) | |
| onPongFrame | back to summary |
|---|---|
| protected void onPongFrame(Frame frame, Callback callback) | |
| onText | back to summary |
|---|---|
| protected void onText(String message, Callback callback) Method called when a complete text message is received. | |
| onTextFrame | back to summary |
|---|---|
| protected void onTextFrame(Frame frame, Callback callback) | |
| sendBinary | back to summary |
|---|---|
| public void sendBinary(ByteBuffer message, Callback callback, boolean batch) Send a ByteBuffer as a single binary frame.
| |
| sendBinary | back to summary |
|---|---|
| public void sendBinary(Callback callback, boolean batch, final ByteBuffer... parts) Send a sequence of ByteBuffers as a sequences for fragmented text frame.
| |
| sendText | back to summary |
|---|---|
| public void sendText(String message, Callback callback, boolean batch) Send a String as a single text frame. | |
| sendText | back to summary |
|---|---|
| public void sendText(Callback callback, boolean batch, final String... parts) Send a sequence of Strings as a sequences for fragmented text frame. Sending a large message in fragments can reduce memory overheads as only a single fragment need be converted to bytes | |