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
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic MessageHandlerfrom(Consumer<String> onText, Consumer<ByteBuffer> onBinary) protected voidonBinary(ByteBuffer message, Callback callback) Method called when a complete binary message is received.protected voidonBinaryFrame(Frame frame, Callback callback) voidonClosed(CloseStatus closeStatus, Callback callback) This is the Close Handshake Complete event.protected voidonCloseFrame(Frame frame, Callback callback) protected voidonContinuationFrame(Frame frame, Callback callback) voidAn error has occurred or been detected in websocket-core and being reported to FrameHandler.voidReceiver of all Frames.voidonOpen(CoreSession coreSession, Callback callback) Async notification that Connection is being opened.protected voidonPingFrame(Frame frame, Callback callback) protected voidonPongFrame(Frame frame, Callback callback) protected voidMethod called when a complete text message is received.protected voidonTextFrame(Frame frame, Callback callback) voidsendBinary(ByteBuffer message, Callback callback, boolean batch) Send a ByteBuffer as a single binary frame.voidsendBinary(Callback callback, boolean batch, ByteBuffer... parts) Send a sequence of ByteBuffers as a sequences for fragmented text frame.voidSend a String as a single text frame.voidSend 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, waitMethods inherited from interface org.eclipse.jetty.websocket.core.FrameHandler
isDemanding
-
Constructor Details
-
MessageHandler
public MessageHandler()
-
-
Method Details
-
from
-
getCoreSession
-
onOpen
Description copied from interface:FrameHandlerAsync 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_ERRORand the connection will be closed.
- Specified by:
onOpenin interfaceFrameHandler- Parameters:
coreSession- the session associated with this connection.callback- the callback to indicate success in processing (or failure)
-
onFrame
Description copied from interface:FrameHandlerReceiver 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:
onFramein interfaceFrameHandler- Specified by:
onFramein interfaceIncomingFrames- Parameters:
frame- the raw framecallback- the callback to indicate success in processing frame (or failure)
-
onError
Description copied from interface:FrameHandlerAn 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:
onErrorin interfaceFrameHandler- Parameters:
cause- the reason for the errorcallback- the callback to indicate success in processing (or failure)
-
onClosed
Description copied from interface:FrameHandlerThis 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:
onClosedin 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.
-