Package com.jsgalactic.axiom.websocket
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 TypeMethodDescriptiondefault voidonClose(WebSocketSession session, int code, String reason) Called once when the session ends, whether by the peer, the application or listener shutdown.default voidonConnect(WebSocketSession session) Called once after the handshake succeeds, before any message.default voidonError(WebSocketSession session, Throwable failure) Called when a callback fails or the transport rejects a frame.default voidonMessage(WebSocketSession session, WebSocketMessage message) Called for every complete text or binary message.
-
Method Details
-
onConnect
Called once after the handshake succeeds, before any message.- Parameters:
session- the established session
-
onMessage
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 messagemessage- immutable message; text or binary
-
onClose
Called once when the session ends, whether by the peer, the application or listener shutdown.- Parameters:
session- session that endedcode- close code, or 1006 when the connection ended without a close framereason- close reason, possibly empty
-
onError
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 failedfailure- cause of the failure
-