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:
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.WebSocketContainer
,org.eclipse.jetty.websocket.api.WebSocketPolicy
public class WebSocketClient extends org.eclipse.jetty.util.component.ContainerLifeCycle implements org.eclipse.jetty.websocket.api.WebSocketPolicy, org.eclipse.jetty.websocket.api.WebSocketContainer
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class org.eclipse.jetty.util.component.AbstractLifeCycle
org.eclipse.jetty.util.component.AbstractLifeCycle.AbstractLifeCycleListener, org.eclipse.jetty.util.component.AbstractLifeCycle.StopException
-
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
-
-
Constructor Summary
Constructors Constructor Description WebSocketClient()
Instantiate a WebSocketClient with defaultsWebSocketClient(org.eclipse.jetty.client.HttpClient httpClient)
Instantiate a WebSocketClient using HttpClient for defaults
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addSessionListener(org.eclipse.jetty.websocket.api.WebSocketSessionListener listener)
java.util.concurrent.CompletableFuture<org.eclipse.jetty.websocket.api.Session>
connect(java.lang.Object websocket, java.net.URI toUri)
java.util.concurrent.CompletableFuture<org.eclipse.jetty.websocket.api.Session>
connect(java.lang.Object websocket, java.net.URI toUri, ClientUpgradeRequest request)
Connect to remote websocket endpointjava.util.concurrent.CompletableFuture<org.eclipse.jetty.websocket.api.Session>
connect(java.lang.Object websocket, java.net.URI toUri, ClientUpgradeRequest request, JettyUpgradeListener upgradeListener)
Connect to remote websocket endpointprotected void
doStop()
void
dump(java.lang.Appendable out, java.lang.String indent)
org.eclipse.jetty.websocket.api.WebSocketBehavior
getBehavior()
java.net.SocketAddress
getBindAddress()
org.eclipse.jetty.io.ByteBufferPool
getBufferPool()
long
getConnectTimeout()
java.net.CookieStore
getCookieStore()
java.util.concurrent.Executor
getExecutor()
org.eclipse.jetty.client.HttpClient
getHttpClient()
java.time.Duration
getIdleTimeout()
int
getInputBufferSize()
long
getMaxBinaryMessageSize()
long
getMaxFrameSize()
long
getMaxTextMessageSize()
org.eclipse.jetty.util.DecoratedObjectFactory
getObjectFactory()
java.util.Collection<org.eclipse.jetty.websocket.api.Session>
getOpenSessions()
int
getOutputBufferSize()
org.eclipse.jetty.util.ssl.SslContextFactory
getSslContextFactory()
long
getStopTimeout()
boolean
isAutoFragment()
boolean
isStopAtShutdown()
void
notifySessionListeners(java.util.function.Consumer<org.eclipse.jetty.websocket.api.WebSocketSessionListener> consumer)
boolean
removeSessionListener(org.eclipse.jetty.websocket.api.WebSocketSessionListener listener)
void
setAutoFragment(boolean autoFragment)
void
setBindAddress(java.net.SocketAddress bindAddress)
void
setConnectTimeout(long ms)
Set the timeout for connecting to the remote server.void
setCookieStore(java.net.CookieStore cookieStore)
void
setIdleTimeout(java.time.Duration duration)
void
setInputBufferSize(int size)
void
setMaxBinaryMessageSize(long size)
void
setMaxFrameSize(long maxFrameSize)
void
setMaxTextMessageSize(long size)
void
setOutputBufferSize(int size)
void
setStopAtShutdown(boolean stop)
Set JVM shutdown behavior.void
setStopTimeout(long stopTimeout)
The timeout to allow all remaining open Sessions to be closed gracefully using the close codeStatusCode.SHUTDOWN
.java.lang.String
toString()
-
Methods inherited from class org.eclipse.jetty.util.component.ContainerLifeCycle
addBean, addBean, addEventListener, addManaged, contains, destroy, doStart, dump, dump, dumpObjects, dumpStdErr, getBean, getBeans, getBeans, getContainedBeans, getContainedBeans, isAuto, isManaged, isUnmanaged, manage, removeBean, removeBeans, removeEventListener, setBeans, start, stop, unmanage, updateBean, updateBean, updateBeans, updateBeans
-
Methods inherited from class org.eclipse.jetty.util.component.AbstractLifeCycle
getEventListeners, getState, getState, isFailed, isRunning, isStarted, isStarting, isStopped, isStopping, setEventListeners, start, stop
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
-
-
-
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
-
-
Method Detail
-
connect
public java.util.concurrent.CompletableFuture<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.CompletableFuture<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 objecttoUri
- the websocket uri to connect torequest
- 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<org.eclipse.jetty.websocket.api.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 objecttoUri
- the websocket uri to connect torequest
- the upgrade request informationupgradeListener
- 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
- Specified by:
dump
in interfaceorg.eclipse.jetty.util.component.Dumpable
- Overrides:
dump
in classorg.eclipse.jetty.util.component.ContainerLifeCycle
- Throws:
java.io.IOException
-
getBehavior
public org.eclipse.jetty.websocket.api.WebSocketBehavior getBehavior()
- Specified by:
getBehavior
in interfaceorg.eclipse.jetty.websocket.api.WebSocketPolicy
-
addSessionListener
public void addSessionListener(org.eclipse.jetty.websocket.api.WebSocketSessionListener listener)
- Specified by:
addSessionListener
in interfaceorg.eclipse.jetty.websocket.api.WebSocketContainer
-
removeSessionListener
public boolean removeSessionListener(org.eclipse.jetty.websocket.api.WebSocketSessionListener listener)
- Specified by:
removeSessionListener
in interfaceorg.eclipse.jetty.websocket.api.WebSocketContainer
-
notifySessionListeners
public void notifySessionListeners(java.util.function.Consumer<org.eclipse.jetty.websocket.api.WebSocketSessionListener> consumer)
- Specified by:
notifySessionListeners
in interfaceorg.eclipse.jetty.websocket.api.WebSocketContainer
-
getIdleTimeout
public java.time.Duration getIdleTimeout()
- Specified by:
getIdleTimeout
in interfaceorg.eclipse.jetty.websocket.api.WebSocketPolicy
-
getInputBufferSize
public int getInputBufferSize()
- Specified by:
getInputBufferSize
in interfaceorg.eclipse.jetty.websocket.api.WebSocketPolicy
-
getOutputBufferSize
public int getOutputBufferSize()
- Specified by:
getOutputBufferSize
in interfaceorg.eclipse.jetty.websocket.api.WebSocketPolicy
-
getMaxBinaryMessageSize
public long getMaxBinaryMessageSize()
- Specified by:
getMaxBinaryMessageSize
in interfaceorg.eclipse.jetty.websocket.api.WebSocketPolicy
-
getMaxTextMessageSize
public long getMaxTextMessageSize()
- Specified by:
getMaxTextMessageSize
in interfaceorg.eclipse.jetty.websocket.api.WebSocketPolicy
-
getMaxFrameSize
public long getMaxFrameSize()
- Specified by:
getMaxFrameSize
in interfaceorg.eclipse.jetty.websocket.api.WebSocketPolicy
-
isAutoFragment
public boolean isAutoFragment()
- Specified by:
isAutoFragment
in interfaceorg.eclipse.jetty.websocket.api.WebSocketPolicy
-
setIdleTimeout
public void setIdleTimeout(java.time.Duration duration)
- Specified by:
setIdleTimeout
in interfaceorg.eclipse.jetty.websocket.api.WebSocketPolicy
-
setInputBufferSize
public void setInputBufferSize(int size)
- Specified by:
setInputBufferSize
in interfaceorg.eclipse.jetty.websocket.api.WebSocketPolicy
-
setOutputBufferSize
public void setOutputBufferSize(int size)
- Specified by:
setOutputBufferSize
in interfaceorg.eclipse.jetty.websocket.api.WebSocketPolicy
-
setMaxBinaryMessageSize
public void setMaxBinaryMessageSize(long size)
- Specified by:
setMaxBinaryMessageSize
in interfaceorg.eclipse.jetty.websocket.api.WebSocketPolicy
-
setMaxTextMessageSize
public void setMaxTextMessageSize(long size)
- Specified by:
setMaxTextMessageSize
in interfaceorg.eclipse.jetty.websocket.api.WebSocketPolicy
-
setMaxFrameSize
public void setMaxFrameSize(long maxFrameSize)
- Specified by:
setMaxFrameSize
in interfaceorg.eclipse.jetty.websocket.api.WebSocketPolicy
-
setAutoFragment
public void setAutoFragment(boolean autoFragment)
- Specified by:
setAutoFragment
in interfaceorg.eclipse.jetty.websocket.api.WebSocketPolicy
-
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)
-
getBufferPool
public org.eclipse.jetty.io.ByteBufferPool getBufferPool()
-
getExecutor
public java.util.concurrent.Executor getExecutor()
- Specified by:
getExecutor
in interfaceorg.eclipse.jetty.websocket.api.WebSocketContainer
-
getHttpClient
public org.eclipse.jetty.client.HttpClient getHttpClient()
-
getObjectFactory
public org.eclipse.jetty.util.DecoratedObjectFactory getObjectFactory()
-
getOpenSessions
public java.util.Collection<org.eclipse.jetty.websocket.api.Session> getOpenSessions()
- Specified by:
getOpenSessions
in interfaceorg.eclipse.jetty.websocket.api.WebSocketContainer
-
getSslContextFactory
public org.eclipse.jetty.util.ssl.SslContextFactory getSslContextFactory()
- 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:
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 codeStatusCode.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
- Overrides:
doStop
in classorg.eclipse.jetty.util.component.ContainerLifeCycle
- Throws:
java.lang.Exception
-
toString
public java.lang.String toString()
- Overrides:
toString
in classorg.eclipse.jetty.util.component.AbstractLifeCycle
-
-