Class WebSocketClient
- All Implemented Interfaces:
 AutoCloseable, Container, Destroyable, Dumpable, Dumpable.DumpableContainer, LifeCycle, Configurable, WebSocketContainer
- 
Nested Class Summary
Nested classes/interfaces inherited from class AbstractLifeCycle
AbstractLifeCycle.AbstractLifeCycleListener, AbstractLifeCycle.StopExceptionNested classes/interfaces inherited from interface Container
Container.InheritedListener, Container.ListenerNested classes/interfaces inherited from interface Dumpable
Dumpable.DumpableContainer, Dumpable.DumpAppendableNested classes/interfaces inherited from interface LifeCycle
LifeCycle.Listener - 
Field Summary
 - 
Constructor Summary
ConstructorsConstructorDescriptionInstantiates a WebSocketClient with a defaultHttpClient.WebSocketClient(HttpClient httpClient) Instantiates a WebSocketClient with the givenHttpClient. - 
Method Summary
Modifier and TypeMethodDescriptionvoidaddSessionListener(WebSocketSessionListener listener) Register a WebSocketSessionListener with the containervoidclose()Connect to remote websocket endpointconnect(Object websocket, URI toUri, ClientUpgradeRequest request) Deprecated, for removal: This API element is subject to removal in a future version.connect(Object websocket, URI toUri, ClientUpgradeRequest request, JettyUpgradeListener upgradeListener) Deprecated, for removal: This API element is subject to removal in a future version.connect(Object websocket, URI toUri, JettyUpgradeListener upgradeListener) Connect to remote websocket endpointconnect(Object websocket, ClientUpgradeRequest request) Connect to remote websocket endpointconnect(Object websocket, ClientUpgradeRequest request, JettyUpgradeListener upgradeListener) Connect to remote websocket endpointprotected voiddoStop()Stops the managed lifecycle beans in the reverse order they were added.voiddump(Appendable out, String indent) Dump this object (and children) into an Appendable using the provided indent after any new lines.longThe Container provided Executor.The duration that a websocket may be idle before being closed by the implementationintThe input (read from network layer) buffer size.longGet the maximum size of a binary message during parsing.longThe maximum payload size of any WebSocket Frame which can be received.intGet the maximum number of data frames allowed to be waiting to be sent at any one time.longGet the maximum size of a text message during parsing.Get the collection of open Sessions being tracked by this containerintThe output (write to network layer) buffer size.Get theSslContextFactorythat manages TLS encryption.longbooleanIf true, frames are automatically fragmented to respect the maximum frame size.booleanvoidNotify the Session Listeners of an event.booleanRemove a WebSocketSessionListener from the containervoidsetAutoFragment(boolean autoFragment) If set to true, frames are automatically fragmented to respect the maximum frame size.voidsetBindAddress(SocketAddress bindAddress) voidsetConnectTimeout(long ms) Set the timeout for connecting to the remote server.voidsetIdleTimeout(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.voidsetMaxOutgoingFrames(int maxOutgoingFrames) Set the maximum number of data frames allowed to be waiting to be sent at any one time.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.voidsetStopTimeout(long stopTimeout) The timeout to allow all remaining open Sessions to be closed gracefully using the close codeStatusCode.SHUTDOWN.toString()Methods inherited from class ContainerLifeCycle
addBean, addBean, addEventListener, addManaged, contains, destroy, doStart, dump, dump, dumpObjects, dumpStdErr, getBean, getBeans, getBeans, getContainedBeans, getContainedBeans, installBean, installBean, isAuto, isManaged, isUnmanaged, manage, removeBean, removeBeans, removeEventListener, setBeans, start, stop, unmanage, updateBean, updateBean, updateBeans, updateBeansMethods inherited from class AbstractLifeCycle
getEventListeners, getState, getState, isFailed, isRunning, isStarted, isStarting, isStopped, isStopping, setEventListeners, start, stopMethods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface Container
getCachedBeans, getEventListenersMethods inherited from interface Dumpable.DumpableContainer
isDumpable 
- 
Constructor Details
- 
WebSocketClient
public WebSocketClient()Instantiates a WebSocketClient with a defaultHttpClient. - 
WebSocketClient
Instantiates a WebSocketClient with the given
HttpClient.- Parameters:
 httpClient- the HttpClient to use
 
 - 
 - 
Method Details
- 
connect
Connect to remote websocket endpoint- Parameters:
 websocket- the websocket objecttoUri- 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<Session> connect(Object websocket, URI toUri, JettyUpgradeListener upgradeListener) throws IOException Connect to remote websocket endpoint- Parameters:
 websocket- the websocket objecttoUri- 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<Session> connect(Object websocket, ClientUpgradeRequest request) throws IOException Connect to remote websocket endpoint- Parameters:
 websocket- the websocket objectrequest- the upgrade request information- Returns:
 - the future for the session, available on success of connect
 - Throws:
 IOException- if unable to connect
 - 
connect
public CompletableFuture<Session> connect(Object websocket, ClientUpgradeRequest request, JettyUpgradeListener upgradeListener) throws IOException Connect to remote websocket endpoint- Parameters:
 websocket- the websocket objectrequest- 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<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 objecttoUri- the websocket uri to connect torequest- 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<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 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:
 IOException- if unable to connect
 - 
dump
Description 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:
 IOException- if unable to write to Appendable
 - 
addSessionListener
Description copied from interface:WebSocketContainerRegister a WebSocketSessionListener with the container- Specified by:
 addSessionListenerin interfaceWebSocketContainer- Parameters:
 listener- the listener
 - 
removeSessionListener
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
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
Description copied from interface:ConfigurableThe duration that a websocket may be idle before being closed by the implementation- Specified by:
 getIdleTimeoutin interfaceConfigurable- Returns:
 - the timeout duration
 
 - 
setIdleTimeout
Description copied from interface:ConfigurableThe duration that a websocket may be idle before being closed by the implementation- Specified by:
 setIdleTimeoutin interfaceConfigurable- Parameters:
 duration- the timeout duration (may not be null or negative)
 - 
getInputBufferSize
public int getInputBufferSize()Description copied from interface:ConfigurableThe 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 interfaceConfigurable- Returns:
 - the raw network buffer input size.
 
 - 
setInputBufferSize
public void setInputBufferSize(int size) Description copied from interface:ConfigurableThe input (read from network layer) buffer size.- Specified by:
 setInputBufferSizein interfaceConfigurable- Parameters:
 size- the size in bytes
 - 
getOutputBufferSize
public int getOutputBufferSize()Description copied from interface:ConfigurableThe 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 interfaceConfigurable- Returns:
 - the raw network buffer output size.
 
 - 
setOutputBufferSize
public void setOutputBufferSize(int size) Description copied from interface:ConfigurableThe output (write to network layer) buffer size.- Specified by:
 setOutputBufferSizein interfaceConfigurable- Parameters:
 size- the size in bytes
 - 
getMaxBinaryMessageSize
public long getMaxBinaryMessageSize()Description copied from interface:ConfigurableGet 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 interfaceConfigurable- Returns:
 - the maximum size of a binary message
 
 - 
setMaxBinaryMessageSize
public void setMaxBinaryMessageSize(long size) Description copied from interface:ConfigurableThe 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 interfaceConfigurable- Parameters:
 size- the maximum allowed size of a binary message.
 - 
getMaxTextMessageSize
public long getMaxTextMessageSize()Description copied from interface:ConfigurableGet 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 interfaceConfigurable- Returns:
 - the maximum size of a text message.
 
 - 
setMaxTextMessageSize
public void setMaxTextMessageSize(long size) Description copied from interface:ConfigurableThe 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 interfaceConfigurable- Parameters:
 size- the maximum allowed size of a text message.
 - 
getMaxFrameSize
public long getMaxFrameSize()Description copied from interface:ConfigurableThe maximum payload size of any WebSocket Frame which can be received.- Specified by:
 getMaxFrameSizein interfaceConfigurable- Returns:
 - the maximum size of a WebSocket Frame.
 
 - 
setMaxFrameSize
public void setMaxFrameSize(long maxFrameSize) Description copied from interface:ConfigurableThe 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 interfaceConfigurable- Parameters:
 maxFrameSize- the maximum allowed size of a WebSocket Frame.
 - 
isAutoFragment
public boolean isAutoFragment()Description copied from interface:ConfigurableIf true, frames are automatically fragmented to respect the maximum frame size.- Specified by:
 isAutoFragmentin interfaceConfigurable- Returns:
 - whether to automatically fragment incoming WebSocket Frames.
 
 - 
setAutoFragment
public void setAutoFragment(boolean autoFragment) Description copied from interface:ConfigurableIf set to true, frames are automatically fragmented to respect the maximum frame size.- Specified by:
 setAutoFragmentin interfaceConfigurable- Parameters:
 autoFragment- whether to automatically fragment incoming WebSocket Frames.
 - 
getMaxOutgoingFrames
public int getMaxOutgoingFrames()Description copied from interface:ConfigurableGet the maximum number of data frames allowed to be waiting to be sent at any one time. The default value is -1, this indicates there is no limit on how many frames can be queued to be sent by the implementation. If the limit is exceeded, subsequent frames sent are failed with aWritePendingExceptionbut the connection is not failed and will remain open.- Specified by:
 getMaxOutgoingFramesin interfaceConfigurable- Returns:
 - the max number of frames.
 
 - 
setMaxOutgoingFrames
public void setMaxOutgoingFrames(int maxOutgoingFrames) Description copied from interface:ConfigurableSet the maximum number of data frames allowed to be waiting to be sent at any one time. The default value is -1, this indicates there is no limit on how many frames can be queued to be sent by the implementation. If the limit is exceeded, subsequent frames sent are failed with aWritePendingExceptionbut the connection is not failed and will remain open.- Specified by:
 setMaxOutgoingFramesin interfaceConfigurable- Parameters:
 maxOutgoingFrames- the max number of frames.
 - 
getBindAddress
 - 
setBindAddress
 - 
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
Description copied from interface:WebSocketContainerThe Container provided Executor.- Specified by:
 getExecutorin interfaceWebSocketContainer
 - 
getHttpClient
 - 
getObjectFactory
 - 
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
Get theSslContextFactorythat manages TLS encryption.- 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:
 
 - 
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
Description copied from class:ContainerLifeCycleStops the managed lifecycle beans in the reverse order they were added.- Overrides:
 doStopin classContainerLifeCycle- Throws:
 Exception- If there was a problem stopping. Will cause a transition to FAILED state
 - 
close
- Specified by:
 closein interfaceAutoCloseable- Throws:
 Exception
 - 
toString
- Overrides:
 toStringin classAbstractLifeCycle
 
 - 
 
connect(Object, ClientUpgradeRequest, JettyUpgradeListener)orconnect(Object, URI, JettyUpgradeListener).