Top Description Inners
javax.websocket

public Interface MessageHandler

Known Direct Subinterfaces
javax.websocket.MessageHandler.Whole, javax.websocket.MessageHandler.Partial

Developers implement MessageHandlers in order to receive incoming messages during a web socket conversation. Each web socket session uses no more than one thread at a time to call its MessageHandlers. This means that, provided each message handler instance is used to handle messages for one web socket session, at most one thread at a time can be calling any of its methods. Developers who wish to handle messages from multiple clients within the same message handlers may do so by adding the same instance as a handler on each of the Session objects for the clients. In that case, they will need to code with the possibility of their MessageHandler being called concurrently by multiple threads, each one arising from a different client session.

See Endpoint for a usage example.

Author
dannycoward

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static interface
MessageHandler.Partial<
The type of the object that represent pieces of the incoming message that this MessageHandler will consume.
T
>

This kind of handler is notified by the implementation as it becomes ready to deliver parts of a whole message.

public static interface
MessageHandler.Whole<
The type of the message object that this MessageHandler will consume.
T
>

This kind of handler is notified by the container on arrival of a complete message.

javax.websocket back to summary

public Interface MessageHandler.Partial<T>

extends MessageHandler
Type Parameters
<T>
The type of the object that represent pieces of the incoming message that this MessageHandler will consume.

This kind of handler is notified by the implementation as it becomes ready to deliver parts of a whole message.

For handling parts of text messages, the type T is java.lang.String

For handling parts of binary messages, the allowable types for T are

Developers should not continue to reference message objects of type java.nio.ByteBuffer after the completion of the onMessage() call, since they may be recycled by the implementation.

Note

Implementations may choose their own schemes for delivering large messages in smaller parts through this API. These schemes may or may not bear a relationship to the underlying websocket dataframes in which the message is received off the wire.

Method Summary

Modifier and TypeMethod and Description
public void
onMessage(T
the partial message data.
partialMessage
,
boolean
flag to indicate if this partialMessage is the last of the whole message being delivered.
last
)

Called when the next part of a message has been fully received.

Method Detail

onMessageback to summary
public void onMessage(T partialMessage, boolean last)

Called when the next part of a message has been fully received.

Parameters
partialMessage:T

the partial message data.

last:boolean

flag to indicate if this partialMessage is the last of the whole message being delivered.

javax.websocket back to summary

public Interface MessageHandler.Whole<T>

extends MessageHandler
Type Parameters
<T>
The type of the message object that this MessageHandler will consume.

This kind of handler is notified by the container on arrival of a complete message. If the message is received in parts, the container buffers it until it is has been fully received before this method is called.

For handling incoming text messages, the allowed types for T are

For handling incoming binary messages, the allowed types for T are

For handling incoming pong messages, the type of T is PongMessage

Developers should not continue to reference message objects of type java.io.Reader, java.nio.ByteBuffer or java.io.InputStream after the completion of the onMessage() call, since they may be recycled by the implementation.

Method Summary

Modifier and TypeMethod and Description
public void
onMessage(T
the message data.
message
)

Called when the message has been fully received.

Method Detail

onMessageback to summary
public void onMessage(T message)

Called when the message has been fully received.

Parameters
message:T

the message data.