Package edu.tufts.hrilab.gui
Class Handler
java.lang.Object
org.springframework.web.socket.handler.AbstractWebSocketHandler
org.springframework.web.socket.handler.TextWebSocketHandler
edu.tufts.hrilab.gui.Handler
- All Implemented Interfaces:
org.springframework.web.socket.WebSocketHandler
public class Handler
extends org.springframework.web.socket.handler.TextWebSocketHandler
A WebSocket handler which instantiates
GuiAdapters when their
respective GuiProvider are registered with TRADE,
distributes incoming messages to the relevant GuiAdapters,
and collects outgoing messages for transmission to the frontend.-
Method Summary
Modifier and TypeMethodDescriptionvoidafterConnectionClosed(org.springframework.web.socket.WebSocketSession session, org.springframework.web.socket.CloseStatus status) Callback to reset the session on close.voidafterConnectionEstablished(org.springframework.web.socket.WebSocketSession session) Callback to send a setup message to the client on connection setup.static HandlerFactory method.protected voidhandleTextMessage(org.springframework.web.socket.WebSocketSession session, org.springframework.web.socket.TextMessage message) Callback to handle messages sent from the client.voidregisterAdapter(ai.thinkingrobots.trade.TRADEServiceInfo tsi) TRADE service to register new adapters to this handler.voidsendMessage(String message) TRADE service to send messages to the client.Methods inherited from class org.springframework.web.socket.handler.TextWebSocketHandler
handleBinaryMessageMethods inherited from class org.springframework.web.socket.handler.AbstractWebSocketHandler
handleMessage, handlePongMessage, handleTransportError, supportsPartialMessages
-
Method Details
-
createHandler
Factory method. Handles construction, registration with TRADE, and registration to add newGuiAdapters when their correspondingGuiProviders join.- Returns:
- the handler instance.
- Throws:
ai.thinkingrobots.trade.TRADEException- if registration of the instance's services fails, if registration of anyGuiAdapterfails, or if registration for join notifications fails.
-
registerAdapter
public void registerAdapter(ai.thinkingrobots.trade.TRADEServiceInfo tsi) throws ai.thinkingrobots.trade.TRADEException TRADE service to register new adapters to this handler.- Parameters:
tsi- a TRADE service that returns the new adapter's class name. Provided by the notifier.- Throws:
ai.thinkingrobots.trade.TRADEException- if registration of a new adapter with TRADE fails.
-
sendMessage
TRADE service to send messages to the client.- Parameters:
message- the message to send.- Throws:
IOException
-
afterConnectionEstablished
public void afterConnectionEstablished(org.springframework.web.socket.WebSocketSession session) throws Exception Callback to send a setup message to the client on connection setup.- Specified by:
afterConnectionEstablishedin interfaceorg.springframework.web.socket.WebSocketHandler- Overrides:
afterConnectionEstablishedin classorg.springframework.web.socket.handler.AbstractWebSocketHandler- Parameters:
session- the WebSocket connection just established.- Throws:
Exception- ignored.
-
handleTextMessage
protected void handleTextMessage(org.springframework.web.socket.WebSocketSession session, org.springframework.web.socket.TextMessage message) throws Exception Callback to handle messages sent from the client.- Overrides:
handleTextMessagein classorg.springframework.web.socket.handler.AbstractWebSocketHandler- Parameters:
session- the WebSocket connection the message uses.message- the message.- Throws:
Exception- ignored.
-
afterConnectionClosed
public void afterConnectionClosed(org.springframework.web.socket.WebSocketSession session, org.springframework.web.socket.CloseStatus status) throws Exception Callback to reset the session on close.- Specified by:
afterConnectionClosedin interfaceorg.springframework.web.socket.WebSocketHandler- Overrides:
afterConnectionClosedin classorg.springframework.web.socket.handler.AbstractWebSocketHandler- Parameters:
session- the closing WebSocket connection.status- ignored.- Throws:
Exception- ignored.
-