Class WebSocketClient

All Implemented Interfaces:
Container, Destroyable, Dumpable, Dumpable.DumpableContainer, LifeCycle, WebSocketContainerScope

public class WebSocketClient extends ContainerLifeCycle implements WebSocketContainerScope
WebSocketClient provides a means of establishing connections to remote websocket endpoints.
  • Constructor Details

  • Method Details

    • connect

      public Future<org.eclipse.jetty.websocket.api.Session> connect(Object websocket, URI toUri) throws IOException
      Throws:
      IOException
    • connect

      public Future<org.eclipse.jetty.websocket.api.Session> connect(Object websocket, URI toUri, ClientUpgradeRequest request) throws 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:
      IOException - if unable to connect
    • connect

      public Future<org.eclipse.jetty.websocket.api.Session> connect(Object websocket, URI toUri, ClientUpgradeRequest request, UpgradeListener upgradeListener) throws 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:
      IOException - if unable to connect
    • getClassLoader

      public ClassLoader getClassLoader()
      Specified by:
      getClassLoader in interface WebSocketContainerScope
    • setEventDriverFactory

      public void setEventDriverFactory(EventDriverFactory eventDriverFactory)
    • setSessionFactory

      public void setSessionFactory(SessionFactory sessionFactory)
    • doStart

      protected void doStart() throws Exception
      Overrides:
      doStart in class ContainerLifeCycle
      Throws:
      Exception
    • doStop

      protected void doStop() throws Exception
      Overrides:
      doStop in class ContainerLifeCycle
      Throws:
      Exception
    • isDispatchIO

      @Deprecated public boolean isDispatchIO()
      Deprecated.
    • getAsyncWriteTimeout

      @Deprecated public long getAsyncWriteTimeout()
      Deprecated.
      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 SocketAddress getBindAddress()
    • getBufferPool

      public ByteBufferPool getBufferPool()
      Specified by:
      getBufferPool in interface WebSocketContainerScope
    • getConnectionManager

      @Deprecated public ConnectionManager getConnectionManager()
      Deprecated.
    • getConnectTimeout

      public long getConnectTimeout()
    • getCookieStore

      public CookieStore getCookieStore()
    • getEventDriverFactory

      public EventDriverFactory getEventDriverFactory()
    • getExecutor

      public Executor getExecutor()
      Specified by:
      getExecutor in interface 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 DecoratedObjectFactory getObjectFactory()
      Specified by:
      getObjectFactory in interface WebSocketContainerScope
    • getOpenSessions

      public Set<WebSocketSession> getOpenSessions()
    • getPolicy

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

      public Scheduler getScheduler()
    • getSessionFactory

      public SessionFactory getSessionFactory()
    • getSslContextFactory

      public SslContextFactory getSslContextFactory()
      Get the in use SslContextFactory
      Specified by:
      getSslContextFactory in interface WebSocketContainerScope
      Returns:
      the SslContextFactory that manages TLS encryption on the internal HttpClient
      See Also:
    • addSessionListener

      public void addSessionListener(WebSocketSessionListener listener)
      Specified by:
      addSessionListener in interface WebSocketContainerScope
    • removeSessionListener

      public void removeSessionListener(WebSocketSessionListener listener)
      Specified by:
      removeSessionListener in interface WebSocketContainerScope
    • getSessionListeners

      public Collection<WebSocketSessionListener> getSessionListeners()
      Specified by:
      getSessionListeners in interface WebSocketContainerScope
    • newConnectionManager

      @Deprecated protected ConnectionManager newConnectionManager()
      Deprecated.
      has no replacement
      Factory method for new ConnectionManager
      Returns:
      the ConnectionManager instance to use
    • setAsyncWriteTimeout

      public void setAsyncWriteTimeout(long ms)
    • setBindAdddress

      @Deprecated public void setBindAdddress(SocketAddress bindAddress)
      Deprecated.
      (this is a bad bad bad typo, it has 3 { @ code " d " } characters in a row) use HttpClient.setBindAddress(SocketAddress) to the internal WebSocketClient(HttpClient)
      Parameters:
      bindAddress - the address to bind to the internal HttpClient
    • setBindAddress

      public void setBindAddress(SocketAddress bindAddress)
      Sets the Bind Address on the internal HttpClient.
      Parameters:
      bindAddress - the local bind address for the internal HttpClient
    • setBufferPool

      public void setBufferPool(ByteBufferPool bufferPool)
      Set's the Bind Address on the internal HttpClient.
      Parameters:
      bufferPool - The buffer pool
    • setConnectTimeout

      public void setConnectTimeout(long ms)
      Set the timeout for connecting to the remote server on the internal HttpClient
      Parameters:
      ms - the timeout in milliseconds
    • setCookieStore

      public void setCookieStore(CookieStore cookieStore)
      Set the CookieStore to use on the internal 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.
      no longer used, this has no replacement
      Parameters:
      dispatchIO - true to have IO operations be dispatched to Executor
    • setExecutor

      public void setExecutor(Executor executor)
      Sets the Executor in use on the internal HttpClient
      Parameters:
      executor - The executor to use
    • setMasker

      @Deprecated public void setMasker(Masker masker)
      Deprecated.
      not used, no replacement
      Parameters:
      masker - does 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 HttpClient getHttpClient()
      Get the internal HttpClient.

      Note: this can result in a LinkageError if used within a WebApp that runs on a server that also has HttpClient on the server classpath.

      Returns:
      the internal HttpClient
    • 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:
    • isStopAtShutdown

      public boolean isStopAtShutdown()
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • hashCode

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

      public String toString()
      Overrides:
      toString in class AbstractLifeCycle