Class WebSocketClient

  • All Implemented Interfaces:
    org.eclipse.jetty.util.component.Container, org.eclipse.jetty.util.component.Destroyable, org.eclipse.jetty.util.component.Dumpable, org.eclipse.jetty.util.component.LifeCycle, org.eclipse.jetty.websocket.common.scopes.WebSocketContainerScope, org.eclipse.jetty.websocket.common.WebSocketSessionListener

    public class WebSocketClient
    extends org.eclipse.jetty.util.component.ContainerLifeCycle
    implements org.eclipse.jetty.websocket.common.scopes.WebSocketContainerScope, org.eclipse.jetty.websocket.common.WebSocketSessionListener
    WebSocketClient provides a means of establishing connections to remote websocket endpoints.
    • Nested Class Summary

      • Nested classes/interfaces inherited from class org.eclipse.jetty.util.component.AbstractLifeCycle

        org.eclipse.jetty.util.component.AbstractLifeCycle.AbstractLifeCycleListener
      • Nested classes/interfaces inherited from interface org.eclipse.jetty.util.component.Container

        org.eclipse.jetty.util.component.Container.InheritedListener, org.eclipse.jetty.util.component.Container.Listener
      • Nested classes/interfaces inherited from interface org.eclipse.jetty.util.component.LifeCycle

        org.eclipse.jetty.util.component.LifeCycle.Listener
    • Field Summary

      • Fields inherited from class org.eclipse.jetty.util.component.AbstractLifeCycle

        FAILED, RUNNING, STARTED, STARTING, STOPPED, STOPPING
      • Fields inherited from interface org.eclipse.jetty.util.component.Dumpable

        KEY
    • Constructor Summary

      Constructors 
      Constructor Description
      WebSocketClient()
      Instantiate a WebSocketClient with defaults
      WebSocketClient​(java.util.concurrent.Executor executor)
      Deprecated.
      WebSocketClient​(org.eclipse.jetty.client.HttpClient httpClient)
      Instantiate a WebSocketClient using HttpClient for defaults
      WebSocketClient​(org.eclipse.jetty.client.HttpClient httpClient, org.eclipse.jetty.util.DecoratedObjectFactory objectFactory)
      Instantiate a WebSocketClient using HttpClient for defaults
      WebSocketClient​(org.eclipse.jetty.io.ByteBufferPool bufferPool)
      Deprecated.
      WebSocketClient​(org.eclipse.jetty.util.ssl.SslContextFactory sslContextFactory)
      Deprecated.
      WebSocketClient​(org.eclipse.jetty.util.ssl.SslContextFactory sslContextFactory, java.util.concurrent.Executor executor)
      Deprecated.
      WebSocketClient​(org.eclipse.jetty.util.ssl.SslContextFactory sslContextFactory, java.util.concurrent.Executor executor, org.eclipse.jetty.io.ByteBufferPool bufferPool)
      Create WebSocketClient using sharing instances of SSLContextFactory Executor, and ByteBufferPool
      WebSocketClient​(org.eclipse.jetty.websocket.common.scopes.WebSocketContainerScope scope)
      Create WebSocketClient other Container Scope, to allow sharing of internal features like Executor, ByteBufferPool, SSLContextFactory, etc.
      WebSocketClient​(org.eclipse.jetty.websocket.common.scopes.WebSocketContainerScope scope, org.eclipse.jetty.util.ssl.SslContextFactory sslContextFactory)
      Create WebSocketClient other Container Scope, to allow sharing of internal features like Executor, ByteBufferPool, SSLContextFactory, etc.
      WebSocketClient​(org.eclipse.jetty.websocket.common.scopes.WebSocketContainerScope scope, org.eclipse.jetty.websocket.common.events.EventDriverFactory eventDriverFactory, org.eclipse.jetty.websocket.common.SessionFactory sessionFactory)
      Create WebSocketClient based on pre-existing Container Scope, to allow sharing of internal features like Executor, ByteBufferPool, SSLContextFactory, etc.
      WebSocketClient​(org.eclipse.jetty.websocket.common.scopes.WebSocketContainerScope scope, org.eclipse.jetty.websocket.common.events.EventDriverFactory eventDriverFactory, org.eclipse.jetty.websocket.common.SessionFactory sessionFactory, org.eclipse.jetty.client.HttpClient httpClient)
      Create WebSocketClient based on pre-existing Container Scope, to allow sharing of internal features like Executor, ByteBufferPool, SSLContextFactory, etc.
    • Constructor Detail

      • WebSocketClient

        public WebSocketClient()
        Instantiate a WebSocketClient with defaults
      • WebSocketClient

        public WebSocketClient​(org.eclipse.jetty.client.HttpClient httpClient)
        Instantiate a WebSocketClient using HttpClient for defaults
        Parameters:
        httpClient - the HttpClient to base internal defaults off of
      • WebSocketClient

        public WebSocketClient​(org.eclipse.jetty.client.HttpClient httpClient,
                               org.eclipse.jetty.util.DecoratedObjectFactory objectFactory)
        Instantiate a WebSocketClient using HttpClient for defaults
        Parameters:
        httpClient - the HttpClient to base internal defaults off of
        objectFactory - the DecoratedObjectFactory for all client instantiated classes
      • WebSocketClient

        @Deprecated
        public WebSocketClient​(org.eclipse.jetty.util.ssl.SslContextFactory sslContextFactory)
        Deprecated.
        Create a new WebSocketClient
        Parameters:
        sslContextFactory - ssl context factory to use
      • WebSocketClient

        public WebSocketClient​(java.util.concurrent.Executor executor)
        Deprecated.
        Create a new WebSocketClient
        Parameters:
        executor - the executor to use
      • WebSocketClient

        @Deprecated
        public WebSocketClient​(org.eclipse.jetty.io.ByteBufferPool bufferPool)
        Deprecated.
        Create a new WebSocketClient
        Parameters:
        bufferPool - byte buffer pool to use
      • WebSocketClient

        @Deprecated
        public WebSocketClient​(org.eclipse.jetty.util.ssl.SslContextFactory sslContextFactory,
                               java.util.concurrent.Executor executor)
        Deprecated.
        Create a new WebSocketClient
        Parameters:
        sslContextFactory - ssl context factory to use
        executor - the executor to use
      • WebSocketClient

        public WebSocketClient​(org.eclipse.jetty.websocket.common.scopes.WebSocketContainerScope scope)
        Create WebSocketClient other Container Scope, to allow sharing of internal features like Executor, ByteBufferPool, SSLContextFactory, etc.
        Parameters:
        scope - the Container Scope
      • WebSocketClient

        public WebSocketClient​(org.eclipse.jetty.websocket.common.scopes.WebSocketContainerScope scope,
                               org.eclipse.jetty.util.ssl.SslContextFactory sslContextFactory)
        Create WebSocketClient other Container Scope, to allow sharing of internal features like Executor, ByteBufferPool, SSLContextFactory, etc.
        Parameters:
        scope - the Container Scope
        sslContextFactory - SSL ContextFactory to use in preference to one from WebSocketContainerScope.getSslContextFactory()
      • WebSocketClient

        public WebSocketClient​(org.eclipse.jetty.util.ssl.SslContextFactory sslContextFactory,
                               java.util.concurrent.Executor executor,
                               org.eclipse.jetty.io.ByteBufferPool bufferPool)
        Create WebSocketClient using sharing instances of SSLContextFactory Executor, and ByteBufferPool
        Parameters:
        sslContextFactory - shared SSL ContextFactory
        executor - shared Executor
        bufferPool - shared ByteBufferPool
      • WebSocketClient

        public WebSocketClient​(org.eclipse.jetty.websocket.common.scopes.WebSocketContainerScope scope,
                               org.eclipse.jetty.websocket.common.events.EventDriverFactory eventDriverFactory,
                               org.eclipse.jetty.websocket.common.SessionFactory sessionFactory)
        Create WebSocketClient based on pre-existing Container Scope, to allow sharing of internal features like Executor, ByteBufferPool, SSLContextFactory, etc.
        Parameters:
        scope - the Container Scope
        eventDriverFactory - the EventDriver Factory to use
        sessionFactory - the SessionFactory to use
      • WebSocketClient

        public WebSocketClient​(org.eclipse.jetty.websocket.common.scopes.WebSocketContainerScope scope,
                               org.eclipse.jetty.websocket.common.events.EventDriverFactory eventDriverFactory,
                               org.eclipse.jetty.websocket.common.SessionFactory sessionFactory,
                               org.eclipse.jetty.client.HttpClient httpClient)
        Create WebSocketClient based on pre-existing Container Scope, to allow sharing of internal features like Executor, ByteBufferPool, SSLContextFactory, etc.
        Parameters:
        scope - the Container Scope
        eventDriverFactory - the EventDriver Factory to use
        sessionFactory - the SessionFactory to use
        httpClient - the httpClient to use
    • Method Detail

      • connect

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

        public java.util.concurrent.Future<org.eclipse.jetty.websocket.api.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.Future<org.eclipse.jetty.websocket.api.Session> connect​(java.lang.Object websocket,
                                                                                            java.net.URI toUri,
                                                                                            ClientUpgradeRequest request,
                                                                                            UpgradeListener 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
      • doStart

        protected void doStart()
                        throws java.lang.Exception
        Overrides:
        doStart in class org.eclipse.jetty.util.component.ContainerLifeCycle
        Throws:
        java.lang.Exception
      • doStop

        protected void doStop()
                       throws java.lang.Exception
        Overrides:
        doStop in class org.eclipse.jetty.util.component.ContainerLifeCycle
        Throws:
        java.lang.Exception
      • isDispatchIO

        @Deprecated
        public boolean isDispatchIO()
        Deprecated.
      • getAsyncWriteTimeout

        public long getAsyncWriteTimeout()
        Return the number of milliseconds for a timeout of an attempted write operation.
        Returns:
        number of milliseconds for timeout of an attempted write operation
      • getBindAddress

        public java.net.SocketAddress getBindAddress()
      • getBufferPool

        public org.eclipse.jetty.io.ByteBufferPool getBufferPool()
        Specified by:
        getBufferPool in interface org.eclipse.jetty.websocket.common.scopes.WebSocketContainerScope
      • getConnectionManager

        @Deprecated
        public ConnectionManager getConnectionManager()
        Deprecated.
      • getConnectTimeout

        public long getConnectTimeout()
      • getCookieStore

        public java.net.CookieStore getCookieStore()
      • getEventDriverFactory

        public org.eclipse.jetty.websocket.common.events.EventDriverFactory getEventDriverFactory()
      • getExecutor

        public java.util.concurrent.Executor getExecutor()
        Specified by:
        getExecutor in interface org.eclipse.jetty.websocket.common.scopes.WebSocketContainerScope
      • getExtensionFactory

        public org.eclipse.jetty.websocket.api.extensions.ExtensionFactory getExtensionFactory()
      • getMasker

        @Deprecated
        public Masker getMasker()
        Deprecated.
        not used, no replacement
        Returns:
        a RandomMasker instance
      • getMaxBinaryMessageBufferSize

        public int getMaxBinaryMessageBufferSize()
        Get the maximum size for buffering of a binary message.
        Returns:
        the maximum size of a binary message buffer.
      • getMaxBinaryMessageSize

        public long getMaxBinaryMessageSize()
        Get the maximum size for a binary message.
        Returns:
        the maximum size of a binary message.
      • getMaxIdleTimeout

        public long getMaxIdleTimeout()
        Get the max idle timeout for new connections.
        Returns:
        the max idle timeout in milliseconds for new connections.
      • getMaxTextMessageBufferSize

        public int getMaxTextMessageBufferSize()
        Get the maximum size for buffering of a text message.
        Returns:
        the maximum size of a text message buffer.
      • getMaxTextMessageSize

        public long getMaxTextMessageSize()
        Get the maximum size for a text message.
        Returns:
        the maximum size of a text message.
      • getObjectFactory

        public org.eclipse.jetty.util.DecoratedObjectFactory getObjectFactory()
        Specified by:
        getObjectFactory in interface org.eclipse.jetty.websocket.common.scopes.WebSocketContainerScope
      • getOpenSessions

        public java.util.Set<org.eclipse.jetty.websocket.common.WebSocketSession> getOpenSessions()
      • getPolicy

        public org.eclipse.jetty.websocket.api.WebSocketPolicy getPolicy()
        Specified by:
        getPolicy in interface org.eclipse.jetty.websocket.common.scopes.WebSocketContainerScope
      • getScheduler

        public org.eclipse.jetty.util.thread.Scheduler getScheduler()
      • getSessionFactory

        public org.eclipse.jetty.websocket.common.SessionFactory getSessionFactory()
      • getSslContextFactory

        public org.eclipse.jetty.util.ssl.SslContextFactory getSslContextFactory()
        Specified by:
        getSslContextFactory in interface org.eclipse.jetty.websocket.common.scopes.WebSocketContainerScope
        Returns:
        the SslContextFactory that manages TLS encryption
        See Also:
        WebSocketClient(SslContextFactory)
      • addSessionListener

        public void addSessionListener​(org.eclipse.jetty.websocket.common.WebSocketSessionListener listener)
        Specified by:
        addSessionListener in interface org.eclipse.jetty.websocket.common.scopes.WebSocketContainerScope
      • removeSessionListener

        public void removeSessionListener​(org.eclipse.jetty.websocket.common.WebSocketSessionListener listener)
        Specified by:
        removeSessionListener in interface org.eclipse.jetty.websocket.common.scopes.WebSocketContainerScope
      • getSessionListeners

        public java.util.Collection<org.eclipse.jetty.websocket.common.WebSocketSessionListener> getSessionListeners()
        Specified by:
        getSessionListeners in interface org.eclipse.jetty.websocket.common.scopes.WebSocketContainerScope
      • newConnectionManager

        @Deprecated
        protected ConnectionManager newConnectionManager()
        Deprecated.
        use HttpClient instead
        Factory method for new ConnectionManager
        Returns:
        the ConnectionManager instance to use
      • onSessionClosed

        public void onSessionClosed​(org.eclipse.jetty.websocket.common.WebSocketSession session)
        Specified by:
        onSessionClosed in interface org.eclipse.jetty.websocket.common.WebSocketSessionListener
      • onSessionOpened

        public void onSessionOpened​(org.eclipse.jetty.websocket.common.WebSocketSession session)
        Specified by:
        onSessionOpened in interface org.eclipse.jetty.websocket.common.WebSocketSessionListener
      • setAsyncWriteTimeout

        public void setAsyncWriteTimeout​(long ms)
      • setBindAdddress

        @Deprecated
        public void setBindAdddress​(java.net.SocketAddress bindAddress)
        Deprecated.
        (this is a bad bad bad typo) use HttpClient.setBindAddress(SocketAddress) on instance passed to WebSocketClient(HttpClient)
        Parameters:
        bindAddress - the address to bind to
      • setBindAddress

        @Deprecated
        public void setBindAddress​(java.net.SocketAddress bindAddress)
        Deprecated.
        Use HttpClient.setBindAddress(SocketAddress) on instance passed to WebSocketClient(HttpClient)
        Parameters:
        bindAddress - the address to bind to
      • setBufferPool

        public void setBufferPool​(org.eclipse.jetty.io.ByteBufferPool bufferPool)
        Deprecated.
        Use HttpClient.setByteBufferPool(ByteBufferPool) on the instance passed to WebSocketClient(HttpClient)
        Parameters:
        bufferPool - The buffer pool
      • setConnectTimeout

        public void setConnectTimeout​(long ms)
        Deprecated.
        Use HttpClient.setConnectTimeout(long) on the instance passed to WebSocketClient(HttpClient)
        Set the timeout for connecting to the remote server.
        Parameters:
        ms - the timeout in millisecondspool
      • setCookieStore

        @Deprecated
        public void setCookieStore​(java.net.CookieStore cookieStore)
        Deprecated.
        Use HttpClient.setCookieStore(CookieStore) on the HttpClient instance passed to WebSocketClient(HttpClient)
        Parameters:
        cookieStore - The cookie store
      • setDaemon

        @Deprecated
        public void setDaemon​(boolean daemon)
        Deprecated.
        not used, configure threading in HttpClient instead
        Parameters:
        daemon - do nothing
      • setDispatchIO

        @Deprecated
        public void setDispatchIO​(boolean dispatchIO)
        Deprecated.
      • setExecutor

        @Deprecated
        public void setExecutor​(java.util.concurrent.Executor executor)
        Deprecated.
        Use HttpClient.setExecutor(Executor) on the instance passed to WebSocketClient(HttpClient)
        Parameters:
        executor - The executor to use
      • setMasker

        @Deprecated
        public void setMasker​(Masker masker)
        Deprecated.
        not used, no replacement
        Parameters:
        masker - do nothing
      • setMaxBinaryMessageBufferSize

        public void setMaxBinaryMessageBufferSize​(int max)
      • setMaxIdleTimeout

        public void setMaxIdleTimeout​(long ms)
        Set the max idle timeout for new connections.

        Existing connections will not have their max idle timeout adjusted.

        Parameters:
        ms - the timeout in milliseconds
      • setMaxTextMessageBufferSize

        public void setMaxTextMessageBufferSize​(int max)
      • getHttpClient

        public org.eclipse.jetty.client.HttpClient getHttpClient()
      • 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
      • isStopAtShutdown

        public boolean isStopAtShutdown()
      • equals

        public boolean equals​(java.lang.Object o)
        Overrides:
        equals in class java.lang.Object
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class java.lang.Object
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class org.eclipse.jetty.util.component.AbstractLifeCycle