Class WebSocketClient

java.lang.Object
org.eclipse.jetty.util.component.AbstractLifeCycle
org.eclipse.jetty.util.component.ContainerLifeCycle
org.eclipse.jetty.websocket.client.WebSocketClient
All Implemented Interfaces:
AutoCloseable, org.eclipse.jetty.util.component.Container, org.eclipse.jetty.util.component.Destroyable, org.eclipse.jetty.util.component.Dumpable, org.eclipse.jetty.util.component.Dumpable.DumpableContainer, org.eclipse.jetty.util.component.LifeCycle, org.eclipse.jetty.websocket.api.Configurable, org.eclipse.jetty.websocket.api.WebSocketContainer

public class WebSocketClient extends org.eclipse.jetty.util.component.ContainerLifeCycle implements org.eclipse.jetty.websocket.api.Configurable, org.eclipse.jetty.websocket.api.WebSocketContainer, AutoCloseable
  • Constructor Details

    • WebSocketClient

      public WebSocketClient()
      Instantiates a WebSocketClient with a default HttpClient.
    • WebSocketClient

      public WebSocketClient(org.eclipse.jetty.client.HttpClient httpClient)

      Instantiates a WebSocketClient with the given HttpClient.

      Parameters:
      httpClient - the HttpClient to use
  • Method Details

    • connect

      public CompletableFuture<org.eclipse.jetty.websocket.api.Session> connect(Object websocket, URI toUri) throws IOException
      Connect to remote websocket endpoint
      Parameters:
      websocket - the websocket object
      toUri - the websocket uri to connect to
      Returns:
      the future for the session, available on success of connect
      Throws:
      IOException - if unable to connect
    • connect

      public CompletableFuture<org.eclipse.jetty.websocket.api.Session> connect(Object websocket, URI toUri, JettyUpgradeListener upgradeListener) throws IOException
      Connect to remote websocket endpoint
      Parameters:
      websocket - the websocket object
      toUri - the websocket uri to connect to
      Returns:
      the future for the session, available on success of connect
      Throws:
      IOException - if unable to connect
    • connect

      public CompletableFuture<org.eclipse.jetty.websocket.api.Session> connect(Object websocket, ClientUpgradeRequest request) throws IOException
      Connect to remote websocket endpoint
      Parameters:
      websocket - the websocket object
      request - the upgrade request information
      Returns:
      the future for the session, available on success of connect
      Throws:
      IOException - if unable to connect
    • connect

      public CompletableFuture<org.eclipse.jetty.websocket.api.Session> connect(Object websocket, ClientUpgradeRequest request, JettyUpgradeListener upgradeListener) throws IOException
      Connect to remote websocket endpoint
      Parameters:
      websocket - the websocket object
      request - the upgrade request information
      Returns:
      the future for the session, available on success of connect
      Throws:
      IOException - if unable to connect
    • connect

      @Deprecated(forRemoval=true, since="12.1.0") public CompletableFuture<org.eclipse.jetty.websocket.api.Session> connect(Object websocket, URI toUri, ClientUpgradeRequest request) throws IOException
      Deprecated, for removal: This API element is subject to removal in a future version.
      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

      @Deprecated(forRemoval=true, since="12.1.0") public CompletableFuture<org.eclipse.jetty.websocket.api.Session> connect(Object websocket, URI toUri, ClientUpgradeRequest request, JettyUpgradeListener upgradeListener) throws IOException
      Deprecated, for removal: This API element is subject to removal in a future version.
      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
    • dump

      public void dump(Appendable out, String indent) throws IOException
      Specified by:
      dump in interface org.eclipse.jetty.util.component.Dumpable
      Overrides:
      dump in class org.eclipse.jetty.util.component.ContainerLifeCycle
      Throws:
      IOException
    • addSessionListener

      public void addSessionListener(org.eclipse.jetty.websocket.api.WebSocketSessionListener listener)
      Specified by:
      addSessionListener in interface org.eclipse.jetty.websocket.api.WebSocketContainer
    • removeSessionListener

      public boolean removeSessionListener(org.eclipse.jetty.websocket.api.WebSocketSessionListener listener)
      Specified by:
      removeSessionListener in interface org.eclipse.jetty.websocket.api.WebSocketContainer
    • notifySessionListeners

      public void notifySessionListeners(Consumer<org.eclipse.jetty.websocket.api.WebSocketSessionListener> consumer)
      Specified by:
      notifySessionListeners in interface org.eclipse.jetty.websocket.api.WebSocketContainer
    • getIdleTimeout

      public Duration getIdleTimeout()
      Specified by:
      getIdleTimeout in interface org.eclipse.jetty.websocket.api.Configurable
    • setIdleTimeout

      public void setIdleTimeout(Duration duration)
      Specified by:
      setIdleTimeout in interface org.eclipse.jetty.websocket.api.Configurable
    • getInputBufferSize

      public int getInputBufferSize()
      Specified by:
      getInputBufferSize in interface org.eclipse.jetty.websocket.api.Configurable
    • setInputBufferSize

      public void setInputBufferSize(int size)
      Specified by:
      setInputBufferSize in interface org.eclipse.jetty.websocket.api.Configurable
    • getOutputBufferSize

      public int getOutputBufferSize()
      Specified by:
      getOutputBufferSize in interface org.eclipse.jetty.websocket.api.Configurable
    • setOutputBufferSize

      public void setOutputBufferSize(int size)
      Specified by:
      setOutputBufferSize in interface org.eclipse.jetty.websocket.api.Configurable
    • getMaxBinaryMessageSize

      public long getMaxBinaryMessageSize()
      Specified by:
      getMaxBinaryMessageSize in interface org.eclipse.jetty.websocket.api.Configurable
    • setMaxBinaryMessageSize

      public void setMaxBinaryMessageSize(long size)
      Specified by:
      setMaxBinaryMessageSize in interface org.eclipse.jetty.websocket.api.Configurable
    • getMaxTextMessageSize

      public long getMaxTextMessageSize()
      Specified by:
      getMaxTextMessageSize in interface org.eclipse.jetty.websocket.api.Configurable
    • setMaxTextMessageSize

      public void setMaxTextMessageSize(long size)
      Specified by:
      setMaxTextMessageSize in interface org.eclipse.jetty.websocket.api.Configurable
    • getMaxFrameSize

      public long getMaxFrameSize()
      Specified by:
      getMaxFrameSize in interface org.eclipse.jetty.websocket.api.Configurable
    • setMaxFrameSize

      public void setMaxFrameSize(long maxFrameSize)
      Specified by:
      setMaxFrameSize in interface org.eclipse.jetty.websocket.api.Configurable
    • isAutoFragment

      public boolean isAutoFragment()
      Specified by:
      isAutoFragment in interface org.eclipse.jetty.websocket.api.Configurable
    • setAutoFragment

      public void setAutoFragment(boolean autoFragment)
      Specified by:
      setAutoFragment in interface org.eclipse.jetty.websocket.api.Configurable
    • getMaxOutgoingFrames

      public int getMaxOutgoingFrames()
      Specified by:
      getMaxOutgoingFrames in interface org.eclipse.jetty.websocket.api.Configurable
    • setMaxOutgoingFrames

      public void setMaxOutgoingFrames(int maxOutgoingFrames)
      Specified by:
      setMaxOutgoingFrames in interface org.eclipse.jetty.websocket.api.Configurable
    • getBindAddress

      public SocketAddress getBindAddress()
    • setBindAddress

      public void setBindAddress(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
    • getExecutor

      public Executor getExecutor()
      Specified by:
      getExecutor in interface org.eclipse.jetty.websocket.api.WebSocketContainer
    • getHttpClient

      public org.eclipse.jetty.client.HttpClient getHttpClient()
    • getObjectFactory

      public org.eclipse.jetty.util.DecoratedObjectFactory getObjectFactory()
    • getOpenSessions

      public Collection<org.eclipse.jetty.websocket.api.Session> getOpenSessions()
      Specified by:
      getOpenSessions in interface org.eclipse.jetty.websocket.api.WebSocketContainer
    • getSslContextFactory

      public org.eclipse.jetty.util.ssl.SslContextFactory getSslContextFactory()
      Get the SslContextFactory that manages TLS encryption.
      Returns:
      the SslContextFactory that manages TLS encryption
    • 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:
    • 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 Exception
      Overrides:
      doStop in class org.eclipse.jetty.util.component.ContainerLifeCycle
      Throws:
      Exception
    • close

      public void close() throws Exception
      Specified by:
      close in interface AutoCloseable
      Throws:
      Exception
    • toString

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