Class AssistantWebSocket
- All Implemented Interfaces:
org.eclipse.jetty.ee8.websocket.api.WebSocketConnectionListener, org.eclipse.jetty.ee8.websocket.api.WebSocketListener
Supports bidirectional communication between the client and AssistantService. Each WebSocket maintains a
conversation per HTTP session, streams AI-generated tokens in real time, and supports cancellation and heartbeat
pings.
Features:
- Streaming tokens from AI assistant to client
- Maintains per-session chat history
- Heartbeat pings to prevent WebSocket timeouts
- Context-aware AI queries using JSON context
- Graceful cancellation on disconnect or error
- Token batching to reduce message overhead
Implements the (legacy/"ee8") WebSocketListener interface directly rather than relying on the
annotation-based API, since the endpoint is registered through
JettyWebSocketServletContainerInitializer, whose frame-handler
factory only recognises org.eclipse.jetty.ee8.websocket.api.annotations.* annotations (not the similarly
named ones in org.eclipse.jetty.websocket.api.annotations), so implementing the interface avoids that
ambiguity.
-
Constructor Summary
ConstructorsConstructorDescriptionAssistantWebSocket(javax.servlet.http.HttpSession httpSession) Constructs a WebSocket instance bound to the given HTTP session. -
Method Summary
Modifier and TypeMethodDescriptionvoidonWebSocketClose(int statusCode, String reason) Called when the WebSocket is closed.voidonWebSocketConnect(org.eclipse.jetty.ee8.websocket.api.Session session) Called when the WebSocket is connected.voidonWebSocketError(Throwable error) Called on WebSocket error.voidonWebSocketText(String message) Called when a message is received from the client.Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.eclipse.jetty.ee8.websocket.api.WebSocketListener
onWebSocketBinary
-
Constructor Details
-
AssistantWebSocket
public AssistantWebSocket(javax.servlet.http.HttpSession httpSession) Constructs a WebSocket instance bound to the given HTTP session.- Parameters:
httpSession- the HTTP session for maintaining conversation state
-
-
Method Details
-
onWebSocketConnect
public void onWebSocketConnect(org.eclipse.jetty.ee8.websocket.api.Session session) Called when the WebSocket is connected.Schedules periodic token flush and heartbeat ping tasks, and sets idle timeout.
- Specified by:
onWebSocketConnectin interfaceorg.eclipse.jetty.ee8.websocket.api.WebSocketConnectionListener- Parameters:
session- the connected WebSocket session
-
onWebSocketText
Called when a message is received from the client.Expected JSON format:
{ "question": "user question", "context": { ... optional AI context ... } }Supports cancellation messages:{ "type": "cancel" }- Specified by:
onWebSocketTextin interfaceorg.eclipse.jetty.ee8.websocket.api.WebSocketListener- Parameters:
message- the raw JSON message from the client
-
onWebSocketClose
Called when the WebSocket is closed.- Specified by:
onWebSocketClosein interfaceorg.eclipse.jetty.ee8.websocket.api.WebSocketConnectionListener- Parameters:
statusCode- the close status codereason- the reason for closure
-
onWebSocketError
Called on WebSocket error.- Specified by:
onWebSocketErrorin interfaceorg.eclipse.jetty.ee8.websocket.api.WebSocketConnectionListener- Parameters:
error- the thrown error
-