java.lang.Object
de.iip_ecosphere.platform.services.environment.services.WsAdapter
Direct Known Subclasses:
PythonWsProcessService.PyWebSocket, WsSenderClient, WsWatcher

public abstract class WsAdapter extends Object
Adapts the web sockets to the interface used before.
Author:
Holger Eichelberger, SSE
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    private String
     
    private de.iip_ecosphere.platform.support.logging.Logger
     
    private de.iip_ecosphere.platform.support.websocket.WebsocketFactory.WebSocket
     
  • Constructor Summary

    Constructors
    Constructor
    Description
    WsAdapter(URI serverUri, de.iip_ecosphere.platform.support.logging.Logger logger)
    Creates a web socket for the given server URI.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Closes the socket.
    void
    Closes the socket while blocking.
    void
    Connects the socket.
    boolean
    Connects and blocks until connected or failed.
    Returns the socket URI.
    boolean
    Returns whether the socket is closed.
    boolean
    Returns whether the socket is open.
    protected abstract void
    Called when a message arrived.
    void
    send(String text)
    Sends the given text through the websocket.

    Methods inherited from class java.lang.Object

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

    • socket

      private de.iip_ecosphere.platform.support.websocket.WebsocketFactory.WebSocket socket
    • logger

      private de.iip_ecosphere.platform.support.logging.Logger logger
    • lastError

      private String lastError
  • Constructor Details

    • WsAdapter

      public WsAdapter(URI serverUri, de.iip_ecosphere.platform.support.logging.Logger logger)
      Creates a web socket for the given server URI.
      Parameters:
      serverUri - the server URI
  • Method Details

    • onMessage

      protected abstract void onMessage(String text)
      Called when a message arrived.
      Parameters:
      text - the message text
    • send

      public void send(String text) throws IOException
      Sends the given text through the websocket.
      Parameters:
      text - the text to send
      Throws:
      IOException - if sending fails
    • close

      public void close()
      Closes the socket.
    • connectBlocking

      public boolean connectBlocking()
      Connects and blocks until connected or failed.
      Returns:
      whether connecting was successful
    • getURI

      public URI getURI()
      Returns the socket URI.
      Returns:
      the URI
    • connect

      public void connect()
      Connects the socket.
    • isOpen

      public boolean isOpen()
      Returns whether the socket is open.
      Returns:
      true for open, false else
    • isClosed

      public boolean isClosed()
      Returns whether the socket is closed.
      Returns:
      true for closed, false else
    • closeBlocking

      public void closeBlocking() throws IOException
      Closes the socket while blocking.
      Throws:
      IOException - if closing fails