Class WebSocketClient

    • Constructor Detail

      • WebSocketClient

        public WebSocketClient()
        Instantiate a WebSocketClient with defaults
      • WebSocketClient

        public WebSocketClient​(HttpClient httpClient)
        Instantiate a WebSocketClient using HttpClient for defaults
        Parameters:
        httpClient - the HttpClient to base internal defaults off of
    • Method Detail

      • connect

        public java.util.concurrent.CompletableFuture<Session> connect​(java.lang.Object websocket,
                                                                       java.net.URI toUri)
                                                                throws java.io.IOException
        Throws:
        java.io.IOException
      • connect

        public java.util.concurrent.CompletableFuture<Session> connect​(java.lang.Object websocket,
                                                                       java.net.URI toUri,
                                                                       ClientUpgradeRequest request)
                                                                throws java.io.IOException
        Connect to remote websocket endpoint
        Parameters:
        websocket - the websocket object
        toUri - the websocket uri to connect to
        request - the upgrade request information
        Returns:
        the future for the session, available on success of connect
        Throws:
        java.io.IOException - if unable to connect
      • connect

        public java.util.concurrent.CompletableFuture<Session> connect​(java.lang.Object websocket,
                                                                       java.net.URI toUri,
                                                                       ClientUpgradeRequest request,
                                                                       JettyUpgradeListener upgradeListener)
                                                                throws java.io.IOException
        Connect to remote websocket endpoint
        Parameters:
        websocket - the websocket object
        toUri - the websocket uri to connect to
        request - the upgrade request information
        upgradeListener - the upgrade listener
        Returns:
        the future for the session, available on success of connect
        Throws:
        java.io.IOException - if unable to connect
      • dump

        public void dump​(java.lang.Appendable out,
                         java.lang.String indent)
                  throws java.io.IOException
        Description copied from interface: Dumpable
        Dump this object (and children) into an Appendable using the provided indent after any new lines. The indent should not be applied to the first object dumped.
        Specified by:
        dump in interface Dumpable
        Overrides:
        dump in class ContainerLifeCycle
        Parameters:
        out - The appendable to dump to
        indent - The indent to apply after any new lines.
        Throws:
        java.io.IOException - if unable to write to Appendable
      • getIdleTimeout

        public java.time.Duration getIdleTimeout()
        Description copied from interface: WebSocketPolicy
        The duration that a websocket may be idle before being closed by the implementation
        Specified by:
        getIdleTimeout in interface WebSocketPolicy
        Returns:
        the timeout duration
      • getInputBufferSize

        public int getInputBufferSize()
        Description copied from interface: WebSocketPolicy
        The input (read from network layer) buffer size.

        This is the raw read operation buffer size, before the parsing of the websocket frames.

        Specified by:
        getInputBufferSize in interface WebSocketPolicy
        Returns:
        the raw network buffer input size.
      • getOutputBufferSize

        public int getOutputBufferSize()
        Description copied from interface: WebSocketPolicy
        The output (write to network layer) buffer size.

        This is the raw write operation buffer size and has no relationship to the websocket frame.

        Specified by:
        getOutputBufferSize in interface WebSocketPolicy
        Returns:
        the raw network buffer output size.
      • getMaxBinaryMessageSize

        public long getMaxBinaryMessageSize()
        Description copied from interface: WebSocketPolicy
        Get the maximum size of a binary message during parsing.

        This is a memory conservation option, memory over this limit will not be allocated by Jetty for handling binary messages. This applies to individual frames, whole message handling, and partial message handling.

        Binary messages over this maximum will result in a close code 1009 StatusCode.MESSAGE_TOO_LARGE

        Specified by:
        getMaxBinaryMessageSize in interface WebSocketPolicy
        Returns:
        the maximum size of a binary message
      • getMaxTextMessageSize

        public long getMaxTextMessageSize()
        Description copied from interface: WebSocketPolicy
        Get the maximum size of a text message during parsing.

        This is a memory conservation option, memory over this limit will not be allocated by Jetty for handling text messages. This applies to individual frames, whole message handling, and partial message handling.

        Text messages over this maximum will result in a close code 1009 StatusCode.MESSAGE_TOO_LARGE

        Specified by:
        getMaxTextMessageSize in interface WebSocketPolicy
        Returns:
        the maximum size of a text message.
      • getMaxFrameSize

        public long getMaxFrameSize()
        Description copied from interface: WebSocketPolicy
        The maximum payload size of any WebSocket Frame which can be received.
        Specified by:
        getMaxFrameSize in interface WebSocketPolicy
        Returns:
        the maximum size of a WebSocket Frame.
      • isAutoFragment

        public boolean isAutoFragment()
        Description copied from interface: WebSocketPolicy
        If true, frames are automatically fragmented to respect the maximum frame size.
        Specified by:
        isAutoFragment in interface WebSocketPolicy
        Returns:
        whether to automatically fragment incoming WebSocket Frames.
      • setIdleTimeout

        public void setIdleTimeout​(java.time.Duration duration)
        Description copied from interface: WebSocketPolicy
        The duration that a websocket may be idle before being closed by the implementation
        Specified by:
        setIdleTimeout in interface WebSocketPolicy
        Parameters:
        duration - the timeout duration (may not be null or negative)
      • setInputBufferSize

        public void setInputBufferSize​(int size)
        Description copied from interface: WebSocketPolicy
        The input (read from network layer) buffer size.
        Specified by:
        setInputBufferSize in interface WebSocketPolicy
        Parameters:
        size - the size in bytes
      • setOutputBufferSize

        public void setOutputBufferSize​(int size)
        Description copied from interface: WebSocketPolicy
        The output (write to network layer) buffer size.
        Specified by:
        setOutputBufferSize in interface WebSocketPolicy
        Parameters:
        size - the size in bytes
      • setMaxBinaryMessageSize

        public void setMaxBinaryMessageSize​(long size)
        Description copied from interface: WebSocketPolicy
        The maximum size of a binary message during parsing/generating.

        Binary messages over this maximum will result in a close code 1009 StatusCode.MESSAGE_TOO_LARGE

        Specified by:
        setMaxBinaryMessageSize in interface WebSocketPolicy
        Parameters:
        size - the maximum allowed size of a binary message.
      • setMaxTextMessageSize

        public void setMaxTextMessageSize​(long size)
        Description copied from interface: WebSocketPolicy
        The maximum size of a text message during parsing/generating.

        Text messages over this maximum will result in a close code 1009 StatusCode.MESSAGE_TOO_LARGE

        Specified by:
        setMaxTextMessageSize in interface WebSocketPolicy
        Parameters:
        size - the maximum allowed size of a text message.
      • setMaxFrameSize

        public void setMaxFrameSize​(long maxFrameSize)
        Description copied from interface: WebSocketPolicy
        The maximum payload size of any WebSocket Frame which can be received.

        WebSocket Frames over this maximum will result in a close code 1009 StatusCode.MESSAGE_TOO_LARGE

        Specified by:
        setMaxFrameSize in interface WebSocketPolicy
        Parameters:
        maxFrameSize - the maximum allowed size of a WebSocket Frame.
      • setAutoFragment

        public void setAutoFragment​(boolean autoFragment)
        Description copied from interface: WebSocketPolicy
        If set to true, frames are automatically fragmented to respect the maximum frame size.
        Specified by:
        setAutoFragment in interface WebSocketPolicy
        Parameters:
        autoFragment - whether to automatically fragment incoming WebSocket Frames.
      • getBindAddress

        public java.net.SocketAddress getBindAddress()
      • setBindAddress

        public void setBindAddress​(java.net.SocketAddress bindAddress)
      • getConnectTimeout

        public long getConnectTimeout()
      • setConnectTimeout

        public void setConnectTimeout​(long ms)
        Set the timeout for connecting to the remote server.
        Parameters:
        ms - the timeout in milliseconds
      • getCookieStore

        public java.net.CookieStore getCookieStore()
      • setCookieStore

        public void setCookieStore​(java.net.CookieStore cookieStore)
      • getHttpClient

        public HttpClient getHttpClient()
      • getOpenSessions

        public java.util.Collection<Session> getOpenSessions()
        Description copied from interface: WebSocketContainer
        Get the collection of open Sessions being tracked by this container
        Specified by:
        getOpenSessions in interface WebSocketContainer
        Returns:
        the collection of open sessions
      • setStopAtShutdown

        public void setStopAtShutdown​(boolean stop)
        Set JVM shutdown behavior.
        Parameters:
        stop - If true, this client instance will be explicitly stopped when the JVM is shutdown. Otherwise the application is responsible for maintaining the WebSocketClient lifecycle.
        See Also:
        Runtime.addShutdownHook(Thread), ShutdownThread
      • setStopTimeout

        public void setStopTimeout​(long stopTimeout)
        The timeout to allow all remaining open Sessions to be closed gracefully using the close code StatusCode.SHUTDOWN.
        Parameters:
        stopTimeout - the time in ms to wait for the graceful close, use a value less than or equal to 0 to not gracefully close.
      • getStopTimeout

        public long getStopTimeout()
      • isStopAtShutdown

        public boolean isStopAtShutdown()
      • doStop

        protected void doStop()
                       throws java.lang.Exception
        Description copied from class: ContainerLifeCycle
        Stops the managed lifecycle beans in the reverse order they were added.
        Overrides:
        doStop in class ContainerLifeCycle
        Throws:
        java.lang.Exception - If there was a problem stopping. Will cause a transition to FAILED state