Class MessageHandler
java.lang.Object
org.eclipse.jetty.websocket.core.internal.MessageHandler
- All Implemented Interfaces:
FrameHandler
,IncomingFrames
A utility implementation of FrameHandler that defragments
text frames into a String message before calling
onText(String, Callback)
.
Flow control is by default automatic, but an implementation
may extend FrameHandler.isDemanding()
to return true and then explicityly control
demand with calls to CoreSession.demand(long)
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic MessageHandler
from
(Consumer<String> onText, Consumer<ByteBuffer> onBinary) protected void
onBinary
(ByteBuffer message, Callback callback) Method called when a complete binary message is received.protected void
onBinaryFrame
(Frame frame, Callback callback) void
onClosed
(CloseStatus closeStatus, Callback callback) This is the Close Handshake Complete event.protected void
onCloseFrame
(Frame frame, Callback callback) protected void
onContinuationFrame
(Frame frame, Callback callback) void
An error has occurred or been detected in websocket-core and being reported to FrameHandler.void
Receiver of all Frames.void
onOpen
(CoreSession coreSession, Callback callback) Async notification that Connection is being opened.protected void
onPingFrame
(Frame frame, Callback callback) protected void
onPongFrame
(Frame frame, Callback callback) protected void
Method called when a complete text message is received.protected void
onTextFrame
(Frame frame, Callback callback) void
sendBinary
(ByteBuffer message, Callback callback, boolean batch) Send a ByteBuffer as a single binary frame.void
sendBinary
(Callback callback, boolean batch, ByteBuffer... parts) Send a sequence of ByteBuffers as a sequences for fragmented text frame.void
Send a String as a single text frame.void
Send a sequence of Strings as a sequences for fragmented text frame.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface org.eclipse.jetty.websocket.core.FrameHandler
isDemanding
-
Constructor Details
-
MessageHandler
public MessageHandler()
-
-
Method Details
-
from
-
getCoreSession
-
onOpen
Description copied from interface:FrameHandler
Async notification that Connection is being opened.FrameHandler can write during this call, but can not receive frames until the callback is succeeded.
If the FrameHandler succeeds the callback we transition to OPEN state and can now receive frames if not demanding, or can now call
CoreSession.demand(long)
to receive frames if demanding. If the FrameHandler fails the callback a close frame will be sent withCloseStatus.SERVER_ERROR
and the connection will be closed.
- Specified by:
onOpen
in interfaceFrameHandler
- Parameters:
coreSession
- the session associated with this connection.callback
- the callback to indicate success in processing (or failure)
-
onFrame
Description copied from interface:FrameHandler
Receiver of all Frames. This method will never be called in parallel for the same session and will be called sequentially to satisfy all outstanding demand signaled by calls toCoreSession.demand(long)
. Control and Data frames are passed to this method. Close frames may be responded to by the handler, but if an appropriate close response is not sent once the callback is succeeded, then a response close will be generated and sent.- Specified by:
onFrame
in interfaceFrameHandler
- Specified by:
onFrame
in interfaceIncomingFrames
- Parameters:
frame
- the raw framecallback
- the callback to indicate success in processing frame (or failure)
-
onError
Description copied from interface:FrameHandler
An error has occurred or been detected in websocket-core and being reported to FrameHandler. A call to onError will be followed by a call toFrameHandler.onClosed(CloseStatus, Callback)
giving the close status derived from the error. This will not be called more than once,FrameHandler.onClosed(CloseStatus, Callback)
will be called on the callback completion.- Specified by:
onError
in interfaceFrameHandler
- Parameters:
cause
- the reason for the errorcallback
- the callback to indicate success in processing (or failure)
-
onClosed
Description copied from interface:FrameHandler
This is the Close Handshake Complete event.The connection is now closed, no reading or writing is possible anymore. Implementations of FrameHandler can cleanup their resources for this connection now. This method will be called only once.
- Specified by:
onClosed
in interfaceFrameHandler
- Parameters:
closeStatus
- the close status received from remote, or in the case of abnormal closure from local.callback
- the callback to indicate success in processing (or failure)
-
onTextFrame
-
onBinaryFrame
-
onContinuationFrame
-
onPingFrame
-
onPongFrame
-
onCloseFrame
-
onText
Method called when a complete text message is received.- Parameters:
message
- the received text payloadcallback
- The callback to signal completion of handling.
-
onBinary
Method called when a complete binary message is received.- Parameters:
message
- The binary payloadcallback
- The callback to signal completion of handling.
-
sendText
Send a String as a single text frame.- Parameters:
message
- The message to sendcallback
- The callback to call when the send is completebatch
- The batch mode to send the frames in.
-
sendText
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
- The callback to call when the send is completebatch
- The batch mode to send the frames in.parts
- The parts of the message.
-
sendBinary
Send a ByteBuffer as a single binary frame.- Parameters:
message
- The message to sendcallback
- The callback to call when the send is completebatch
- The batch mode to send the frames in.
-
sendBinary
Send a sequence of ByteBuffers as a sequences for fragmented text frame.- Parameters:
callback
- The callback to call when the send is completebatch
- The batch mode to send the frames in.parts
- The parts of the message.
-