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 Type
    Method
    Description
    void
    afterConnectionClosed(org.springframework.web.socket.WebSocketSession session, org.springframework.web.socket.CloseStatus status)
    Callback to reset the session on close.
    void
    afterConnectionEstablished(org.springframework.web.socket.WebSocketSession session)
    Callback to send a setup message to the client on connection setup.
    static Handler
    Factory method.
    protected void
    handleTextMessage(org.springframework.web.socket.WebSocketSession session, org.springframework.web.socket.TextMessage message)
    Callback to handle messages sent from the client.
    void
    registerAdapter(ai.thinkingrobots.trade.TRADEServiceInfo tsi)
    TRADE service to register new adapters to this handler.
    void
    TRADE service to send messages to the client.

    Methods inherited from class org.springframework.web.socket.handler.TextWebSocketHandler

    handleBinaryMessage

    Methods inherited from class org.springframework.web.socket.handler.AbstractWebSocketHandler

    handleMessage, handlePongMessage, handleTransportError, supportsPartialMessages

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • createHandler

      public static Handler createHandler() throws ai.thinkingrobots.trade.TRADEException
      Factory method. Handles construction, registration with TRADE, and registration to add new GuiAdapters when their corresponding GuiProviders join.
      Returns:
      the handler instance.
      Throws:
      ai.thinkingrobots.trade.TRADEException - if registration of the instance's services fails, if registration of any GuiAdapter fails, 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

      public void sendMessage(String message) throws IOException
      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:
      afterConnectionEstablished in interface org.springframework.web.socket.WebSocketHandler
      Overrides:
      afterConnectionEstablished in class org.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:
      handleTextMessage in class org.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:
      afterConnectionClosed in interface org.springframework.web.socket.WebSocketHandler
      Overrides:
      afterConnectionClosed in class org.springframework.web.socket.handler.AbstractWebSocketHandler
      Parameters:
      session - the closing WebSocket connection.
      status - ignored.
      Throws:
      Exception - ignored.