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:
Container,Destroyable,Dumpable,LifeCycle,WebSocketContainer,WebSocketPolicy
public class WebSocketClient extends ContainerLifeCycle implements WebSocketPolicy, WebSocketContainer
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class org.eclipse.jetty.util.component.AbstractLifeCycle
AbstractLifeCycle.AbstractLifeCycleListener, AbstractLifeCycle.StopException
-
Nested classes/interfaces inherited from interface org.eclipse.jetty.util.component.Container
Container.InheritedListener, Container.Listener
-
Nested classes/interfaces inherited from interface org.eclipse.jetty.util.component.LifeCycle
LifeCycle.Listener
-
-
Constructor Summary
Constructors Constructor Description WebSocketClient()Instantiate a WebSocketClient with defaultsWebSocketClient(HttpClient httpClient)Instantiate a WebSocketClient using HttpClient for defaults
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddSessionListener(WebSocketSessionListener listener)Register a WebSocketSessionListener with the containerjava.util.concurrent.CompletableFuture<Session>connect(java.lang.Object websocket, java.net.URI toUri)java.util.concurrent.CompletableFuture<Session>connect(java.lang.Object websocket, java.net.URI toUri, UpgradeRequest request)Connect to remote websocket endpointjava.util.concurrent.CompletableFuture<Session>connect(java.lang.Object websocket, java.net.URI toUri, UpgradeRequest request, JettyUpgradeListener upgradeListener)Connect to remote websocket endpointvoiddump(java.lang.Appendable out, java.lang.String indent)Dump this object (and children) into an Appendable using the provided indent after any new lines.WebSocketBehaviorgetBehavior()java.net.SocketAddressgetBindAddress()ByteBufferPoolgetBufferPool()longgetConnectTimeout()java.net.CookieStoregetCookieStore()java.util.concurrent.ExecutorgetExecutor()The Container provided Executor.HttpClientgetHttpClient()java.time.DurationgetIdleTimeout()The duration that a websocket may be idle before being closed by the implementationintgetInputBufferSize()The input (read from network layer) buffer size.longgetMaxBinaryMessageSize()Get the maximum size of a binary message during parsing.longgetMaxFrameSize()The maximum payload size of any WebSocket Frame which can be received.longgetMaxTextMessageSize()Get the maximum size of a text message during parsing.DecoratedObjectFactorygetObjectFactory()java.util.Collection<Session>getOpenSessions()Get the collection of open Sessions being tracked by this containerintgetOutputBufferSize()The output (write to network layer) buffer size.SslContextFactorygetSslContextFactory()booleanisAutoFragment()If true, frames are automatically fragmented to respect the maximum frame size.booleanisStopAtShutdown()voidnotifySessionListeners(java.util.function.Consumer<WebSocketSessionListener> consumer)Notify the Session Listeners of an event.booleanremoveSessionListener(WebSocketSessionListener listener)Remove a WebSocketSessionListener from the containervoidsetAutoFragment(boolean autoFragment)If set to true, frames are automatically fragmented to respect the maximum frame size.voidsetBindAddress(java.net.SocketAddress bindAddress)voidsetConnectTimeout(long ms)Set the timeout for connecting to the remote server.voidsetCookieStore(java.net.CookieStore cookieStore)voidsetIdleTimeout(java.time.Duration duration)The duration that a websocket may be idle before being closed by the implementationvoidsetInputBufferSize(int size)The input (read from network layer) buffer size.voidsetMaxBinaryMessageSize(long size)The maximum size of a binary message during parsing/generating.voidsetMaxFrameSize(long maxFrameSize)The maximum payload size of any WebSocket Frame which can be received.voidsetMaxTextMessageSize(long size)The maximum size of a text message during parsing/generating.voidsetOutputBufferSize(int size)The output (write to network layer) buffer size.voidsetStopAtShutdown(boolean stop)Set JVM shutdown behavior.java.lang.StringtoString()-
Methods inherited from class org.eclipse.jetty.util.component.ContainerLifeCycle
addBean, addBean, addEventListener, addManaged, contains, destroy, doStart, doStop, dump, dump, dumpObjects, dumpStdErr, getBean, getBeans, getBeans, getContainedBeans, getContainedBeans, isAuto, isManaged, isUnmanaged, manage, removeBean, removeBeans, removeEventListener, setBeans, start, stop, unmanage, updateBean, updateBean, 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
-
Methods inherited from interface org.eclipse.jetty.util.component.Container
getCachedBeans, getEventListeners
-
-
-
-
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, UpgradeRequest 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<Session> connect(java.lang.Object websocket, java.net.URI toUri, UpgradeRequest 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.IOExceptionDescription copied from interface:DumpableDump 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:
dumpin interfaceDumpable- Overrides:
dumpin classContainerLifeCycle- Parameters:
out- The appendable to dump toindent- The indent to apply after any new lines.- Throws:
java.io.IOException- if unable to write to Appendable
-
getBehavior
public WebSocketBehavior getBehavior()
- Specified by:
getBehaviorin interfaceWebSocketPolicy
-
addSessionListener
public void addSessionListener(WebSocketSessionListener listener)
Description copied from interface:WebSocketContainerRegister a WebSocketSessionListener with the container- Specified by:
addSessionListenerin interfaceWebSocketContainer- Parameters:
listener- the listener
-
removeSessionListener
public boolean removeSessionListener(WebSocketSessionListener listener)
Description copied from interface:WebSocketContainerRemove a WebSocketSessionListener from the container- Specified by:
removeSessionListenerin interfaceWebSocketContainer- Parameters:
listener- the listener- Returns:
- true if listener was present and removed
-
notifySessionListeners
public void notifySessionListeners(java.util.function.Consumer<WebSocketSessionListener> consumer)
Description copied from interface:WebSocketContainerNotify the Session Listeners of an event.- Specified by:
notifySessionListenersin interfaceWebSocketContainer- Parameters:
consumer- the consumer to call for each tracked listener
-
getIdleTimeout
public java.time.Duration getIdleTimeout()
Description copied from interface:WebSocketPolicyThe duration that a websocket may be idle before being closed by the implementation- Specified by:
getIdleTimeoutin interfaceWebSocketPolicy- Returns:
- the timeout duration
-
getInputBufferSize
public int getInputBufferSize()
Description copied from interface:WebSocketPolicyThe input (read from network layer) buffer size.This is the raw read operation buffer size, before the parsing of the websocket frames.
- Specified by:
getInputBufferSizein interfaceWebSocketPolicy- Returns:
- the raw network buffer input size.
-
getOutputBufferSize
public int getOutputBufferSize()
Description copied from interface:WebSocketPolicyThe 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:
getOutputBufferSizein interfaceWebSocketPolicy- Returns:
- the raw network buffer output size.
-
getMaxBinaryMessageSize
public long getMaxBinaryMessageSize()
Description copied from interface:WebSocketPolicyGet 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:
getMaxBinaryMessageSizein interfaceWebSocketPolicy- Returns:
- the maximum size of a binary message
-
getMaxTextMessageSize
public long getMaxTextMessageSize()
Description copied from interface:WebSocketPolicyGet 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:
getMaxTextMessageSizein interfaceWebSocketPolicy- Returns:
- the maximum size of a text message.
-
getMaxFrameSize
public long getMaxFrameSize()
Description copied from interface:WebSocketPolicyThe maximum payload size of any WebSocket Frame which can be received.- Specified by:
getMaxFrameSizein interfaceWebSocketPolicy- Returns:
- the maximum size of a WebSocket Frame.
-
isAutoFragment
public boolean isAutoFragment()
Description copied from interface:WebSocketPolicyIf true, frames are automatically fragmented to respect the maximum frame size.- Specified by:
isAutoFragmentin interfaceWebSocketPolicy- Returns:
- whether to automatically fragment incoming WebSocket Frames.
-
setIdleTimeout
public void setIdleTimeout(java.time.Duration duration)
Description copied from interface:WebSocketPolicyThe duration that a websocket may be idle before being closed by the implementation- Specified by:
setIdleTimeoutin interfaceWebSocketPolicy- Parameters:
duration- the timeout duration (may not be null or negative)
-
setInputBufferSize
public void setInputBufferSize(int size)
Description copied from interface:WebSocketPolicyThe input (read from network layer) buffer size.- Specified by:
setInputBufferSizein interfaceWebSocketPolicy- Parameters:
size- the size in bytes
-
setOutputBufferSize
public void setOutputBufferSize(int size)
Description copied from interface:WebSocketPolicyThe output (write to network layer) buffer size.- Specified by:
setOutputBufferSizein interfaceWebSocketPolicy- Parameters:
size- the size in bytes
-
setMaxBinaryMessageSize
public void setMaxBinaryMessageSize(long size)
Description copied from interface:WebSocketPolicyThe 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:
setMaxBinaryMessageSizein interfaceWebSocketPolicy- Parameters:
size- the maximum allowed size of a binary message.
-
setMaxTextMessageSize
public void setMaxTextMessageSize(long size)
Description copied from interface:WebSocketPolicyThe 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:
setMaxTextMessageSizein interfaceWebSocketPolicy- Parameters:
size- the maximum allowed size of a text message.
-
setMaxFrameSize
public void setMaxFrameSize(long maxFrameSize)
Description copied from interface:WebSocketPolicyThe 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:
setMaxFrameSizein interfaceWebSocketPolicy- Parameters:
maxFrameSize- the maximum allowed size of a WebSocket Frame.
-
setAutoFragment
public void setAutoFragment(boolean autoFragment)
Description copied from interface:WebSocketPolicyIf set to true, frames are automatically fragmented to respect the maximum frame size.- Specified by:
setAutoFragmentin interfaceWebSocketPolicy- 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)
-
getBufferPool
public ByteBufferPool getBufferPool()
-
getExecutor
public java.util.concurrent.Executor getExecutor()
Description copied from interface:WebSocketContainerThe Container provided Executor.- Specified by:
getExecutorin interfaceWebSocketContainer
-
getHttpClient
public HttpClient getHttpClient()
-
getObjectFactory
public DecoratedObjectFactory getObjectFactory()
-
getOpenSessions
public java.util.Collection<Session> getOpenSessions()
Description copied from interface:WebSocketContainerGet the collection of open Sessions being tracked by this container- Specified by:
getOpenSessionsin interfaceWebSocketContainer- Returns:
- the collection of open sessions
-
getSslContextFactory
public SslContextFactory getSslContextFactory()
- Returns:
- the
SslContextFactorythat 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
-
isStopAtShutdown
public boolean isStopAtShutdown()
-
toString
public java.lang.String toString()
- Overrides:
toStringin classAbstractLifeCycle
-
-