Top Description Fields Constructors Methods
org.eclipse.jetty.websocket.core.internal

public Class MessageHandler

extends Object
implements FrameHandler
Class Inheritance
All Implemented Interfaces
org.eclipse.jetty.websocket.core.FrameHandler, org.eclipse.jetty.websocket.core.IncomingFrames
Imports
java.io.ByteArrayOutputStream, java.nio.ByteBuffer, java.util.function.Consumer, org.eclipse.jetty.util.BufferUtil, .Callback, .IteratingNestedCallback, .Utf8StringBuilder, org.eclipse.jetty.websocket.core.CloseStatus, .CoreSession, .Frame, .FrameHandler, .OpCode, org.eclipse.jetty.websocket.core.exception.BadPayloadException, .MessageTooLargeException, org.slf4j.Logger, .LoggerFactory

A utility implementation of FrameHandler that aggregates TEXT frames into a String message before calling onText(String, Callback).

Field Summary

Modifier and TypeField and Description
private ByteArrayOutputStream
private CoreSession
private byte
private static final Logger
private Utf8StringBuilder

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public static MessageHandler
from(Consumer<String> onText, Consumer<ByteBuffer> onBinary)

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
onBinaryFrame(Frame frame, Callback callback)

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.eclipse.jetty.websocket.core.FrameHandler.onClosed.

Invoked when a WebSocket close event happened.

protected void
onCloseFrame(Frame frame, Callback callback)

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.eclipse.jetty.websocket.core.FrameHandler.onError.

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.eclipse.jetty.websocket.core.FrameHandler.onFrame.

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.eclipse.jetty.websocket.core.FrameHandler.onOpen.

Invoked when the WebSocket connection is opened.

protected void
onPingFrame(Frame frame, Callback callback)

protected void
onPongFrame(Frame frame, Callback callback)

protected void
onText(String
the received text payload
message
,
Callback
The callback to signal completion of handling.
callback
)

Method called when a complete text message is received.

protected void
onTextFrame(Frame frame, Callback callback)

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
sendText(String
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 String as a single text frame.

public void
sendText(Callback
The callback to call when the send is complete
callback
,
boolean
The batch mode to send the frames in.
batch
,
final String...
The parts of the message.
parts
)

Send a sequence of Strings as a sequences for fragmented text frame.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

binaryMessageBufferback to summary
private ByteArrayOutputStream binaryMessageBuffer
coreSessionback to summary
private CoreSession coreSession
dataTypeback to summary
private byte dataType
LOGback to summary
private static final Logger LOG
textMessageBufferback to summary
private Utf8StringBuilder textMessageBuffer

Constructor Detail

MessageHandlerback to summary
public MessageHandler()

Method Detail

fromback to summary
public static MessageHandler from(Consumer<String> onText, Consumer<ByteBuffer> onBinary)
getBinaryMessageBufferback to summary
private ByteArrayOutputStream getBinaryMessageBuffer()
getCoreSessionback to summary
public CoreSession getCoreSession()
getTextMessageBufferback to summary
private Utf8StringBuilder getTextMessageBuffer()
onBinaryback to summary
protected void onBinary(ByteBuffer message, Callback callback)

Method called when a complete binary message is received.

Parameters
message:ByteBuffer

The binary payload

callback:Callback

The callback to signal completion of handling.

onBinaryFrameback to summary
protected void onBinaryFrame(Frame frame, Callback callback)
onClosedback to summary
public void onClosed(CloseStatus closeStatus, Callback callback)

Implements org.eclipse.jetty.websocket.core.FrameHandler.onClosed.

Doc from org.eclipse.jetty.websocket.core.FrameHandler.onClosed.

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.

Parameters
closeStatus:CloseStatus

the close status received from the remote peer, or generated locally in the case of abnormal closures.

callback:Callback

the callback to indicate success or failure of the processing of this event.

Annotations
@Override
onCloseFrameback to summary
protected void onCloseFrame(Frame frame, Callback callback)
onContinuationFrameback to summary
protected void onContinuationFrame(Frame frame, Callback callback)
onErrorback to summary
public void onError(Throwable cause, Callback callback)

Implements org.eclipse.jetty.websocket.core.FrameHandler.onError.

Doc from org.eclipse.jetty.websocket.core.FrameHandler.onError.

Invoked when an error has occurred or has been detected.

A call to this method will be followed by a call to onClosed(CloseStatus, Callback) with the close status derived from the error.

This method will not be called more than once, onClosed(CloseStatus, Callback) will be called on the callback completion.

Parameters
cause:Throwable

the error cause

callback:Callback

the callback to indicate success or failure of the processing of this event.

Annotations
@Override
onFrameback to summary
public void onFrame(Frame frame, Callback callback)

Implements org.eclipse.jetty.websocket.core.FrameHandler.onFrame.

Doc from org.eclipse.jetty.websocket.core.FrameHandler.onFrame.

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 CoreSession#demand().

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 CoreSession#demand() is made.

Parameters
frame:Frame

the WebSocket frame.

callback:Callback

the callback to indicate success or failure of the processing of this event.

Annotations
@Override
onOpenback to summary
public void onOpen(CoreSession coreSession, Callback callback)

Implements org.eclipse.jetty.websocket.core.FrameHandler.onOpen.

Doc from org.eclipse.jetty.websocket.core.FrameHandler.onOpen.

Invoked when the WebSocket connection is opened.

It is allowed to send WebSocket frames via CoreSession#sendFrame(Frame, Callback, boolean).

WebSocket frames cannot be received until a call to CoreSession#demand() is made.

If the callback argument is failed, the implementation sends a CLOSE frame with CloseStatus#SERVER_ERROR, and the connection will be closed.

Parameters
coreSession:CoreSession

the session associated with this connection.

callback:Callback

the callback to indicate success or failure of the processing of this event.

Annotations
@Override
onPingFrameback to summary
protected void onPingFrame(Frame frame, Callback callback)
onPongFrameback to summary
protected void onPongFrame(Frame frame, Callback callback)
onTextback to summary
protected void onText(String message, Callback callback)

Method called when a complete text message is received.

Parameters
message:String

the received text payload

callback:Callback

The callback to signal completion of handling.

onTextFrameback to summary
protected void onTextFrame(Frame frame, Callback callback)
sendBinaryback to summary
public void sendBinary(ByteBuffer message, Callback callback, boolean batch)

Send a ByteBuffer as a single binary frame.

Parameters
message:ByteBuffer

The message to send

callback:Callback

The callback to call when the send is complete

batch:boolean

The batch mode to send the frames in.

sendBinaryback to summary
public void sendBinary(Callback callback, boolean batch, final ByteBuffer... parts)

Send a sequence of ByteBuffers as a sequences for fragmented text frame.

Parameters
callback:Callback

The callback to call when the send is complete

batch:boolean

The batch mode to send the frames in.

parts:ByteBuffer[]

The parts of the message.

sendTextback to summary
public void sendText(String message, Callback callback, boolean batch)

Send a String as a single text frame.

Parameters
message:String

The message to send

callback:Callback

The callback to call when the send is complete

batch:boolean

The batch mode to send the frames in.

sendTextback 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

Parameters
callback:Callback

The callback to call when the send is complete

batch:boolean

The batch mode to send the frames in.

parts:String[]

The parts of the message.