Interface WebSocketHandler


public interface WebSocketHandler
Application callbacks for one WebSocket route. Register one with Application.webSocket(java.lang.String, com.jsgalactic.axiom.websocket.WebSocketHandler).

A handler instance is shared by every session on its route and must be thread-safe. Callbacks run one at a time per session, but different sessions may call the same handler concurrently. A callback that throws is reported to onError(com.jsgalactic.axiom.websocket.WebSocketSession, java.lang.Throwable) for that session and does not close it, so a handler can decide whether the failure is fatal; a failure of onError is logged by the transport. Close is delivered exactly once per session, including when the listener shuts down.

  • Method Summary

    Modifier and Type
    Method
    Description
    default void
    onClose(WebSocketSession session, int code, String reason)
    Called once when the session ends, whether by the peer, the application or listener shutdown.
    default void
    Called once after the handshake succeeds, before any message.
    default void
    onError(WebSocketSession session, Throwable failure)
    Called when a callback fails or the transport rejects a frame.
    default void
    Called for every complete text or binary message.
  • Method Details

    • onConnect

      default void onConnect(WebSocketSession session)
      Called once after the handshake succeeds, before any message.
      Parameters:
      session - the established session
    • onMessage

      default void onMessage(WebSocketSession session, WebSocketMessage message)
      Called for every complete text or binary message. Fragmented frames are aggregated before this call. Control frames are handled by the transport and are not delivered here.
      Parameters:
      session - session that received the message
      message - immutable message; text or binary
    • onClose

      default void onClose(WebSocketSession session, int code, String reason)
      Called once when the session ends, whether by the peer, the application or listener shutdown.
      Parameters:
      session - session that ended
      code - close code, or 1006 when the connection ended without a close frame
      reason - close reason, possibly empty
    • onError

      default void onError(WebSocketSession session, Throwable failure)
      Called when a callback fails or the transport rejects a frame. The session remains usable unless the failure came from the peer's framing, in which case the transport closes it afterwards.
      Parameters:
      session - session that failed
      failure - cause of the failure