Class 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.WebSocketAdapter
    Provides the WebSocket endpoint used by a WebSocketServer to receive client connections and messages.

    Binary WebSocket messages are deserialized into Agent instances and queued for processing. Text messages are logged but are not processed as KDC agents.

    Author:
    Charles B. Kozoyed
    See Also:
    WebSocketServer, WebSocketAgentQueue
    • Constructor Detail

      • WebSocketEndpoint

        public WebSocketEndpoint()
        Creates a WebSocket endpoint.
    • 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:
        onWebSocketConnect in interface org.eclipse.jetty.websocket.api.WebSocketConnectionListener
        Overrides:
        onWebSocketConnect in class org.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:
        onWebSocketClose in interface org.eclipse.jetty.websocket.api.WebSocketConnectionListener
        Overrides:
        onWebSocketClose in class org.eclipse.jetty.websocket.api.WebSocketAdapter
        Parameters:
        statusCode - the WebSocket close status code
        reason - 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:
        onWebSocketError in interface org.eclipse.jetty.websocket.api.WebSocketConnectionListener
        Overrides:
        onWebSocketError in class org.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:
        onWebSocketText in interface org.eclipse.jetty.websocket.api.WebSocketListener
        Overrides:
        onWebSocketText in class org.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:
        onWebSocketBinary in interface org.eclipse.jetty.websocket.api.WebSocketListener
        Overrides:
        onWebSocketBinary in class org.eclipse.jetty.websocket.api.WebSocketAdapter
        Parameters:
        payload - the byte array containing the received WebSocket message
        offset - the offset of the message data within payload
        length - the length of the message data