Class WebSocketHelper


  • public class WebSocketHelper
    extends VertxHelperBase
    A helper class for the webSocket module in JavaScript. Instances of this class are helpers for individual sockets. See the documentation of that module for instructions. This uses Vert.x for the implementation.
    Since:
    Ptolemy II 11.0
    Version:
    $Id$
    Author:
    Hokeun Kim and Edward A. Lee
    See Also:
    WebSocketServerHelper
    Pt.AcceptedRating:
    Red (eal)
    Pt.ProposedRating:
    Yellow (eal)
    • Method Detail

      • close

        public void close()
        Close the web socket.
      • createClientSocket

        public static WebSocketHelper createClientSocket​(java.lang.Object actor,
                                                         jdk.nashorn.api.scripting.ScriptObjectMirror currentObj,
                                                         java.lang.String host,
                                                         boolean sslTls,
                                                         int port,
                                                         java.lang.String receiveType,
                                                         java.lang.String sendType,
                                                         int connectTimeout,
                                                         int numberOfRetries,
                                                         int timeBetweenRetries,
                                                         boolean trustAll,
                                                         java.lang.String trustedCACertPath,
                                                         boolean discardMessagesBeforeOpen,
                                                         int throttleFactor)
        Create a WebSocketHelper instance for the specified JavaScript Socket instance for the client side of the socket.
        Parameters:
        actor - The actor associated with this helper.
        currentObj - The JavaScript instance of the Socket.
        host - IP address or host name of the host.
        port - The port number that the host listens on.
        sslTls - Whether SSL/TLS is enabled. This defaults to false.
        receiveType - The type to assume for incoming messages.
        sendType - The type for outgoing messages.
        connectTimeout - The time to wait before giving up on a connection.
        numberOfRetries - The number of retries.
        timeBetweenRetries - The time between retries, in milliseconds.
        trustAll - Whether to trust any server certificate. This defaults to false.
        trustedCACertPath - The filename for the file that stores the x.509 certificate of a certificate authority (CA) in PEM format.
        discardMessagesBeforeOpen - True to discard messages before the socket is open. False to queue them.
        throttleFactor - The number of milliseconds to stall for each queued item waiting to be sent.
        Returns:
        A new WebSocketHelper instance.
      • createServerSocket

        public static WebSocketHelper createServerSocket​(java.lang.Object actor,
                                                         jdk.nashorn.api.scripting.ScriptObjectMirror currentObj,
                                                         io.vertx.core.http.WebSocketBase serverWebSocket,
                                                         WebSocketServerHelper helper,
                                                         java.lang.String receiveType,
                                                         java.lang.String sendType)
        Create a WebSocketHelper instance for the specified JavaScript Socket instance for the server side of the socket.
        Parameters:
        actor - The actor associated with this helper.
        currentObj - The JavaScript instance of the Socket.
        serverWebSocket - The given server-side Java socket.
        helper - The helper in charge of this socket.
        receiveType - The type to assume for incoming messages.
        sendType - The type for outgoing messages.
        Returns:
        A new WebSocketHelper instance.
      • isOpen

        public boolean isOpen()
        Return whether the web socket is opened successfully.
        Returns:
        True if the socket is open.
      • open

        public void open()
        Open the web socket. This will be deferred to a vertx event loop.
      • send

        public void send​(java.lang.Object msg)
                  throws IllegalActionException
        Send data through the web socket. Note that if throttleFactor is not zero, then this method could block for some time. Thus, it must not be called in a verticle. It is called by the input handler of the actor.
        Parameters:
        msg - A message to be sent.
        Throws:
        IllegalActionException - If establishing the connection to the web socket has permanently failed.
      • supportedReceiveTypes

        public static java.lang.String[] supportedReceiveTypes()
        Return an array of the types supported by the current host for receiveType arguments.
        Returns:
        an array of the types supported by the current host for receiveType arguments.
      • supportedSendTypes

        public static java.lang.String[] supportedSendTypes()
        Return an array of the types supported by the current host for sendType arguments.
        Returns:
        an array of the types supported by the current host for sendType arguments.
      • _sendMessageOverSocket

        protected void _sendMessageOverSocket​(java.lang.Object message)
        Send the specified message over the websocket.
        Parameters:
        message - The message.