Class AbstractWebsocket<T extends WsData>

java.lang.Object
io.openems.common.websocket.AbstractWebsocket<T>
Direct Known Subclasses:
AbstractWebsocketClient, AbstractWebsocketServer

public abstract class AbstractWebsocket<T extends WsData> extends Object
  • Constructor Details

    • AbstractWebsocket

      public AbstractWebsocket(String name)
      Construct this AbstractWebsocket.
      Parameters:
      name - a name that is used to identify log messages
  • Method Details

    • createWsData

      protected abstract T createWsData()
      Creates an empty WsData object that is attached to the WebSocket as early as possible.
      Returns:
      the typed WsData
    • getOnInternalError

      protected abstract OnInternalError getOnInternalError()
      Callback for internal error.
      Returns:
      the OnInternalError callback
    • getOnOpen

      protected abstract OnOpen getOnOpen()
      Callback for websocket OnOpen event.
      Returns:
      the OnOpen callback
    • getOnRequest

      protected abstract OnRequest getOnRequest()
      Callback for JSON-RPC request.
      Returns:
      the OnRequest callback
    • getOnNotification

      protected abstract OnNotification getOnNotification()
      Callback for JSON-RPC notification.
      Returns:
      the OnNotification callback
    • getOnError

      protected abstract OnError getOnError()
      Callback for websocket error.
      Returns:
      the OnError callback
    • getOnClose

      protected abstract OnClose getOnClose()
      Callback for websocket OnClose event.
      Returns:
      the OnClose callback
    • getName

      public String getName()
      Gets the internal name of this websocket client/server.
      Returns:
      the internal name
    • start

      protected void start()
    • stop

      protected void stop()
    • execute

      protected abstract void execute(Runnable command) throws Exception
      Execute a Runnable.
      Parameters:
      command - the Runnable
      Throws:
      Exception
    • handleInternalErrorAsync

      protected void handleInternalErrorAsync(Throwable t, String wsDataString)
      Handles an internal Error asynchronously.
      Parameters:
      t - the Throwable to be handled
      wsDataString - the toString() content of the WsData attachment of the WebSocket
    • handleInternalErrorSync

      protected void handleInternalErrorSync(Throwable t, String wsDataString)
      Handles an internal Error synchronously.
      Parameters:
      t - the Throwable to be handled
      wsDataString - the toString() content of the WsData attachment of the WebSocket
    • logInfo

      protected abstract void logInfo(org.slf4j.Logger log, String message)
      Log a info message.
      Parameters:
      log - a Logger instance
      message - the message
    • logWarn

      protected abstract void logWarn(org.slf4j.Logger log, String message)
      Log a warn message.
      Parameters:
      log - a Logger instance
      message - the message
    • logError

      protected abstract void logError(org.slf4j.Logger log, String message)
      Log a error message.
      Parameters:
      log - a Logger instance
      message - the message