Package com.kristensoft.kdc
Class WebSocketEndpoint
- java.lang.Object
-
- org.eclipse.jetty.websocket.api.WebSocketAdapter
-
- com.kristensoft.kdc.WebSocketEndpoint
-
- All Implemented Interfaces:
org.eclipse.jetty.websocket.api.WebSocketConnectionListener,org.eclipse.jetty.websocket.api.WebSocketListener
public class WebSocketEndpoint extends org.eclipse.jetty.websocket.api.WebSocketAdapterProvides the WebSocket endpoint used by aWebSocketServerto receive client connections and messages.Binary WebSocket messages are deserialized into
Agentinstances and queued for processing. Text messages are logged but are not processed as KDC agents.- Author:
- Charles B. Kozoyed
- See Also:
WebSocketServer,WebSocketAgentQueue
-
-
Constructor Summary
Constructors Constructor Description WebSocketEndpoint()Creates a WebSocket endpoint.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidonWebSocketBinary(byte[] payload, int offset, int length)Called when a binary message is received over the WebSocket connection.voidonWebSocketClose(int statusCode, String reason)Called when the WebSocket connection is closed.voidonWebSocketConnect(org.eclipse.jetty.websocket.api.Session session)Called when a WebSocket connection is established.voidonWebSocketError(Throwable cause)Called when an error occurs while processing the WebSocket connection.voidonWebSocketText(String message)Called when a text message is received over the WebSocket connection.
-
-
-
Method Detail
-
onWebSocketConnect
public void onWebSocketConnect(org.eclipse.jetty.websocket.api.Session session)
Called when a WebSocket connection is established.Stores the connected session for use when processing WebSocket messages.
- Specified by:
onWebSocketConnectin interfaceorg.eclipse.jetty.websocket.api.WebSocketConnectionListener- Overrides:
onWebSocketConnectin classorg.eclipse.jetty.websocket.api.WebSocketAdapter- Parameters:
session- the established WebSocket session
-
onWebSocketClose
public void onWebSocketClose(int statusCode, String reason)Called when the WebSocket connection is closed.Stops the WebSocket agent queue and records the connection closure.
- Specified by:
onWebSocketClosein interfaceorg.eclipse.jetty.websocket.api.WebSocketConnectionListener- Overrides:
onWebSocketClosein classorg.eclipse.jetty.websocket.api.WebSocketAdapter- Parameters:
statusCode- the WebSocket close status codereason- the reason the WebSocket connection was closed
-
onWebSocketError
public void onWebSocketError(Throwable cause)
Called when an error occurs while processing the WebSocket connection.End-of-file exceptions caused by a closed connection are logged as normal connection closures; other errors are logged as warnings.
- Specified by:
onWebSocketErrorin interfaceorg.eclipse.jetty.websocket.api.WebSocketConnectionListener- Overrides:
onWebSocketErrorin classorg.eclipse.jetty.websocket.api.WebSocketAdapter- Parameters:
cause- the error that occurred
-
onWebSocketText
public void onWebSocketText(String message)
Called when a text message is received over the WebSocket connection.Text messages are logged but are not processed as KDC agents.
- Specified by:
onWebSocketTextin interfaceorg.eclipse.jetty.websocket.api.WebSocketListener- Overrides:
onWebSocketTextin classorg.eclipse.jetty.websocket.api.WebSocketAdapter- Parameters:
message- the received text message
-
onWebSocketBinary
public void onWebSocketBinary(byte[] payload, int offset, int length)Called when a binary message is received over the WebSocket connection.The received message is deserialized into an
Agent, its receive latency metrics are updated, and the agent is added to the WebSocket agent queue for processing.- Specified by:
onWebSocketBinaryin interfaceorg.eclipse.jetty.websocket.api.WebSocketListener- Overrides:
onWebSocketBinaryin classorg.eclipse.jetty.websocket.api.WebSocketAdapter- Parameters:
payload- the byte array containing the received WebSocket messageoffset- the offset of the message data withinpayloadlength- the length of the message data
-
-