Top Fields Constructors Methods
org.eclipse.jetty.websocket.client

public Class WebSocketClient

extends ContainerLifeCycle
implements Configurable, WebSocketContainer
Class Inheritance
All Implemented Interfaces
org.eclipse.jetty.websocket.api.WebSocketContainer, org.eclipse.jetty.websocket.api.Configurable
Imports
java.io.IOException, java.net.SocketAddress, .URI, java.time.Duration, java.util.Collection, .List, java.util.concurrent.CompletableFuture, .CopyOnWriteArrayList, .Executor, .ThreadLocalRandom, .TimeUnit, java.util.function.Consumer, org.eclipse.jetty.client.HttpClient, .Request, .Response, org.eclipse.jetty.io.Connection, org.eclipse.jetty.util.DecoratedObjectFactory, org.eclipse.jetty.util.component.ContainerLifeCycle, .Graceful, org.eclipse.jetty.util.ssl.SslContextFactory, org.eclipse.jetty.util.thread.ShutdownThread, org.eclipse.jetty.websocket.api.Configurable, .Session, .WebSocketContainer, .WebSocketSessionListener, org.eclipse.jetty.websocket.client.internal.JettyClientUpgradeRequest, org.eclipse.jetty.websocket.common.JettyWebSocketFrameHandler, .JettyWebSocketFrameHandlerFactory, .SessionTracker, org.eclipse.jetty.websocket.core.Configuration, .CoreSession, org.eclipse.jetty.websocket.core.client.UpgradeListener, .WebSocketCoreClient, org.slf4j.Logger, .LoggerFactory

Field Summary

Modifier and TypeField and Description
private long
private final Configuration.ConfigurationCustomizer
private final WebSocketCoreClient
private final JettyWebSocketFrameHandlerFactory
private final int
private static final Logger
private final List<WebSocketSessionListener>
private final SessionTracker
private boolean

Constructor Summary

AccessConstructor and Description
public
WebSocketClient()

Instantiates a WebSocketClient with a default HttpClient.

public
WebSocketClient(HttpClient
the HttpClient to use
httpClient
)

Instantiates a WebSocketClient with the given HttpClient.

Method Summary

Modifier and TypeMethod and Description
public void
addSessionListener(WebSocketSessionListener
the listener
listener
)

Implements org.eclipse.jetty.websocket.api.WebSocketContainer.addSessionListener.

Register a WebSocketSessionListener with the container

public CompletableFuture<Session>
connect(Object websocket, URI toUri)

public CompletableFuture<Session>

Returns:

the future for the session, available on success of connect
connect
(Object
the websocket object
websocket
,
URI
the websocket uri to connect to
toUri
,
ClientUpgradeRequest
the upgrade request information
request
)

Connect to remote websocket endpoint

public CompletableFuture<Session>

Returns:

the future for the session, available on success of connect
connect
(Object
the websocket object
websocket
,
URI
the websocket uri to connect to
toUri
,
ClientUpgradeRequest
the upgrade request information
request
,
JettyUpgradeListener
the upgrade listener
upgradeListener
)

Connect to remote websocket endpoint

protected void
doStop()

Overrides org.eclipse.jetty.util.component.ContainerLifeCycle.doStop.

Stops the managed lifecycle beans in the reverse order they were added.

public void
dump(Appendable
The appendable to dump to
out
,
String
The indent to apply after any new lines.
indent
)

Overrides org.eclipse.jetty.util.component.ContainerLifeCycle.dump.

Implements org.eclipse.jetty.util.component.Dumpable.dump.

Dump this object (and children) into an Appendable using the provided indent after any new lines.

public SocketAddress
public long
public Executor
public HttpClient
public Duration
getIdleTimeout()

Implements org.eclipse.jetty.websocket.api.Configurable.getIdleTimeout.

The duration that a websocket may be idle before being closed by the implementation

public int
getInputBufferSize()

Implements org.eclipse.jetty.websocket.api.Configurable.getInputBufferSize.

The input (read from network layer) buffer size.

public long
getMaxBinaryMessageSize()

Implements org.eclipse.jetty.websocket.api.Configurable.getMaxBinaryMessageSize.

Get the maximum size of a binary message during parsing.

public long
getMaxFrameSize()

Implements org.eclipse.jetty.websocket.api.Configurable.getMaxFrameSize.

The maximum payload size of any WebSocket Frame which can be received.

public int
getMaxOutgoingFrames()

Implements org.eclipse.jetty.websocket.api.Configurable.getMaxOutgoingFrames.

Get the maximum number of data frames allowed to be waiting to be sent at any one time.

public long
getMaxTextMessageSize()

Implements org.eclipse.jetty.websocket.api.Configurable.getMaxTextMessageSize.

Get the maximum size of a text message during parsing.

public DecoratedObjectFactory
public Collection<Session>
getOpenSessions()

Implements org.eclipse.jetty.websocket.api.WebSocketContainer.getOpenSessions.

Get the collection of open Sessions being tracked by this container

public int
getOutputBufferSize()

Implements org.eclipse.jetty.websocket.api.Configurable.getOutputBufferSize.

The output (write to network layer) buffer size.

public SslContextFactory

Returns:

the SslContextFactory that manages TLS encryption
getSslContextFactory
()

Get the SslContextFactory that manages TLS encryption.

public long
public boolean
isAutoFragment()

Implements org.eclipse.jetty.websocket.api.Configurable.isAutoFragment.

If true, frames are automatically fragmented to respect the maximum frame size.

public boolean
public void
notifySessionListeners(Consumer<WebSocketSessionListener>
the consumer to call for each tracked listener
consumer
)

Implements org.eclipse.jetty.websocket.api.WebSocketContainer.notifySessionListeners.

Notify the Session Listeners of an event.

public boolean
removeSessionListener(WebSocketSessionListener
the listener
listener
)

Implements org.eclipse.jetty.websocket.api.WebSocketContainer.removeSessionListener.

Remove a WebSocketSessionListener from the container

public void
setAutoFragment(boolean
whether to automatically fragment incoming WebSocket Frames.
autoFragment
)

Implements org.eclipse.jetty.websocket.api.Configurable.setAutoFragment.

If set to true, frames are automatically fragmented to respect the maximum frame size.

public void
public void
setConnectTimeout(long
the timeout in milliseconds
ms
)

Set the timeout for connecting to the remote server.

public void
setIdleTimeout(Duration
the timeout duration (may not be null or negative)
duration
)

Implements org.eclipse.jetty.websocket.api.Configurable.setIdleTimeout.

The duration that a websocket may be idle before being closed by the implementation

public void
setInputBufferSize(int
the size in bytes
size
)

Implements org.eclipse.jetty.websocket.api.Configurable.setInputBufferSize.

The input (read from network layer) buffer size.

public void
setMaxBinaryMessageSize(long
the maximum allowed size of a binary message.
size
)

Implements org.eclipse.jetty.websocket.api.Configurable.setMaxBinaryMessageSize.

The maximum size of a binary message during parsing/generating.

public void
setMaxFrameSize(long
the maximum allowed size of a WebSocket Frame.
maxFrameSize
)

Implements org.eclipse.jetty.websocket.api.Configurable.setMaxFrameSize.

The maximum payload size of any WebSocket Frame which can be received.

public void
setMaxOutgoingFrames(int
the max number of frames.
maxOutgoingFrames
)

Implements org.eclipse.jetty.websocket.api.Configurable.setMaxOutgoingFrames.

Set the maximum number of data frames allowed to be waiting to be sent at any one time.

public void
setMaxTextMessageSize(long
the maximum allowed size of a text message.
size
)

Implements org.eclipse.jetty.websocket.api.Configurable.setMaxTextMessageSize.

The maximum size of a text message during parsing/generating.

public void
setOutputBufferSize(int
the size in bytes
size
)

Implements org.eclipse.jetty.websocket.api.Configurable.setOutputBufferSize.

The output (write to network layer) buffer size.

public void
setStopAtShutdown(boolean
If true, this client instance will be explicitly stopped when the JVM is shutdown. Otherwise the application is responsible for maintaining the WebSocketClient lifecycle.
stop
)

Set JVM shutdown behavior.

public void
setStopTimeout(long
the time in ms to wait for the graceful close, use a value less than or equal to 0 to not gracefully close.
stopTimeout
)

The timeout to allow all remaining open Sessions to be closed gracefully using the close code org.eclipse.jetty.websocket.api.StatusCode#SHUTDOWN.

public String
toString()

Overrides org.eclipse.jetty.util.component.AbstractLifeCycle.toString.

Returns a string representation of the object.

Inherited from org.eclipse.jetty.util.component.ContainerLifeCycle:
addBeanaddBeanaddEventListeneraddManagedcontainsdestroydoStartdumpdumpdumpObjectsdumpStdErrgetBeangetBeansgetBeansgetContainedBeansgetContainedBeansisAutoisManagedisUnmanagedmanageremoveBeanremoveBeansremoveEventListenersetBeansstartstopunmanageupdateBeanupdateBeanupdateBeansupdateBeans

Field Detail

_stopTimeoutback to summary
private long _stopTimeout
configurationCustomizerback to summary
private final Configuration.ConfigurationCustomizer configurationCustomizer
coreClientback to summary
private final WebSocketCoreClient coreClient
frameHandlerFactoryback to summary
private final JettyWebSocketFrameHandlerFactory frameHandlerFactory
idback to summary
private final int id
LOGback to summary
private static final Logger LOG

Hides org.eclipse.jetty.util.component.ContainerLifeCycle.LOG.

sessionListenersback to summary
private final List<WebSocketSessionListener> sessionListeners
sessionTrackerback to summary
private final SessionTracker sessionTracker
stopAtShutdownback to summary
private boolean stopAtShutdown

Constructor Detail

WebSocketClientback to summary
public WebSocketClient()

Instantiates a WebSocketClient with a default HttpClient.

WebSocketClientback to summary
public WebSocketClient(HttpClient httpClient)

Instantiates a WebSocketClient with the given HttpClient.

Parameters
httpClient:HttpClient

the HttpClient to use

Method Detail

addSessionListenerback to summary
public void addSessionListener(WebSocketSessionListener listener)

Implements org.eclipse.jetty.websocket.api.WebSocketContainer.addSessionListener.

Doc from org.eclipse.jetty.websocket.api.WebSocketContainer.addSessionListener.

Register a WebSocketSessionListener with the container

Parameters
listener:WebSocketSessionListener

the listener

Annotations
@Override
connectback to summary
public CompletableFuture<Session> connect(Object websocket, URI toUri) throws IOException
connectback to summary
public CompletableFuture<Session> connect(Object websocket, URI toUri, ClientUpgradeRequest request) throws IOException

Connect to remote websocket endpoint

Parameters
websocket:Object

the websocket object

toUri:URI

the websocket uri to connect to

request:ClientUpgradeRequest

the upgrade request information

Returns:CompletableFuture<Session>

the future for the session, available on success of connect

Exceptions
IOException:
if unable to connect
connectback to summary
public CompletableFuture<Session> connect(Object websocket, URI toUri, ClientUpgradeRequest request, JettyUpgradeListener upgradeListener) throws IOException

Connect to remote websocket endpoint

Parameters
websocket:Object

the websocket object

toUri:URI

the websocket uri to connect to

request:ClientUpgradeRequest

the upgrade request information

upgradeListener:JettyUpgradeListener

the upgrade listener

Returns:CompletableFuture<Session>

the future for the session, available on success of connect

Exceptions
IOException:
if unable to connect
doStopback to summary
protected void doStop() throws Exception

Overrides org.eclipse.jetty.util.component.ContainerLifeCycle.doStop.

Doc from org.eclipse.jetty.util.component.ContainerLifeCycle.doStop.

Stops the managed lifecycle beans in the reverse order they were added.

Annotations
@Override
Exceptions
Exception:

Doc from org.eclipse.jetty.util.component.AbstractLifeCycle.doStop.

If there was a problem stopping. Will cause a transition to FAILED state

dumpback to summary
public void dump(Appendable out, String indent) throws IOException

Overrides org.eclipse.jetty.util.component.ContainerLifeCycle.dump.

Implements org.eclipse.jetty.util.component.Dumpable.dump.

Doc from org.eclipse.jetty.util.component.Dumpable.dump.

Dump 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.

Parameters
out:Appendable

The appendable to dump to

indent:String

The indent to apply after any new lines.

Annotations
@Override
Exceptions
IOException:
if unable to write to Appendable
getBindAddressback to summary
public SocketAddress getBindAddress()
getConnectTimeoutback to summary
public long getConnectTimeout()
getExecutorback to summary
public Executor getExecutor()

Implements org.eclipse.jetty.websocket.api.WebSocketContainer.getExecutor.

Doc from org.eclipse.jetty.websocket.api.WebSocketContainer.getExecutor.

The Container provided Executor.

Annotations
@Override
getHttpClientback to summary
public HttpClient getHttpClient()
getIdleTimeoutback to summary
public Duration getIdleTimeout()

Implements org.eclipse.jetty.websocket.api.Configurable.getIdleTimeout.

Doc from org.eclipse.jetty.websocket.api.Configurable.getIdleTimeout.

The duration that a websocket may be idle before being closed by the implementation

Returns:Duration

the timeout duration

Annotations
@Override
getInputBufferSizeback to summary
public int getInputBufferSize()

Implements org.eclipse.jetty.websocket.api.Configurable.getInputBufferSize.

Doc from org.eclipse.jetty.websocket.api.Configurable.getInputBufferSize.

The input (read from network layer) buffer size.

This is the raw read operation buffer size, before the parsing of the websocket frames.

Returns:int

the raw network buffer input size.

Annotations
@Override
getMaxBinaryMessageSizeback to summary
public long getMaxBinaryMessageSize()

Implements org.eclipse.jetty.websocket.api.Configurable.getMaxBinaryMessageSize.

Doc from org.eclipse.jetty.websocket.api.Configurable.getMaxBinaryMessageSize.

Get 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

Returns:long

the maximum size of a binary message

Annotations
@Override
getMaxFrameSizeback to summary
public long getMaxFrameSize()

Implements org.eclipse.jetty.websocket.api.Configurable.getMaxFrameSize.

Doc from org.eclipse.jetty.websocket.api.Configurable.getMaxFrameSize.

The maximum payload size of any WebSocket Frame which can be received.

Returns:long

the maximum size of a WebSocket Frame.

Annotations
@Override
getMaxOutgoingFramesback to summary
public int getMaxOutgoingFrames()

Implements org.eclipse.jetty.websocket.api.Configurable.getMaxOutgoingFrames.

Doc from org.eclipse.jetty.websocket.api.Configurable.getMaxOutgoingFrames.

Get 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 a java.nio.channels.WritePendingException but the connection is not failed and will remain open.

Returns:int

the max number of frames.

Annotations
@Override
getMaxTextMessageSizeback to summary
public long getMaxTextMessageSize()

Implements org.eclipse.jetty.websocket.api.Configurable.getMaxTextMessageSize.

Doc from org.eclipse.jetty.websocket.api.Configurable.getMaxTextMessageSize.

Get 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

Returns:long

the maximum size of a text message.

Annotations
@Override
getObjectFactoryback to summary
public DecoratedObjectFactory getObjectFactory()
getOpenSessionsback to summary
public Collection<Session> getOpenSessions()

Implements org.eclipse.jetty.websocket.api.WebSocketContainer.getOpenSessions.

Doc from org.eclipse.jetty.websocket.api.WebSocketContainer.getOpenSessions.

Get the collection of open Sessions being tracked by this container

Returns:Collection<Session>

the collection of open sessions

getOutputBufferSizeback to summary
public int getOutputBufferSize()

Implements org.eclipse.jetty.websocket.api.Configurable.getOutputBufferSize.

Doc from org.eclipse.jetty.websocket.api.Configurable.getOutputBufferSize.

The output (write to network layer) buffer size.

This is the raw write operation buffer size and has no relationship to the websocket frame.

Returns:int

the raw network buffer output size.

Annotations
@Override
getSslContextFactoryback to summary
public SslContextFactory getSslContextFactory()

Get the SslContextFactory that manages TLS encryption.

Returns:SslContextFactory

the SslContextFactory that manages TLS encryption

getStopTimeoutback to summary
public long getStopTimeout()
isAutoFragmentback to summary
public boolean isAutoFragment()

Implements org.eclipse.jetty.websocket.api.Configurable.isAutoFragment.

Doc from org.eclipse.jetty.websocket.api.Configurable.isAutoFragment.

If true, frames are automatically fragmented to respect the maximum frame size.

Returns:boolean

whether to automatically fragment incoming WebSocket Frames.

Annotations
@Override
isStopAtShutdownback to summary
public boolean isStopAtShutdown()
notifySessionListenersback to summary
public void notifySessionListeners(Consumer<WebSocketSessionListener> consumer)

Implements org.eclipse.jetty.websocket.api.WebSocketContainer.notifySessionListeners.

Doc from org.eclipse.jetty.websocket.api.WebSocketContainer.notifySessionListeners.

Notify the Session Listeners of an event.

Parameters
consumer:Consumer<WebSocketSessionListener>

the consumer to call for each tracked listener

Annotations
@Override
removeSessionListenerback to summary
public boolean removeSessionListener(WebSocketSessionListener listener)

Implements org.eclipse.jetty.websocket.api.WebSocketContainer.removeSessionListener.

Doc from org.eclipse.jetty.websocket.api.WebSocketContainer.removeSessionListener.

Remove a WebSocketSessionListener from the container

Parameters
listener:WebSocketSessionListener

the listener

Returns:boolean

true if listener was present and removed

Annotations
@Override
setAutoFragmentback to summary
public void setAutoFragment(boolean autoFragment)

Implements org.eclipse.jetty.websocket.api.Configurable.setAutoFragment.

Doc from org.eclipse.jetty.websocket.api.Configurable.setAutoFragment.

If set to true, frames are automatically fragmented to respect the maximum frame size.

Parameters
autoFragment:boolean

whether to automatically fragment incoming WebSocket Frames.

Annotations
@Override
setBindAddressback to summary
public void setBindAddress(SocketAddress bindAddress)
setConnectTimeoutback to summary
public void setConnectTimeout(long ms)

Set the timeout for connecting to the remote server.

Parameters
ms:long

the timeout in milliseconds

setIdleTimeoutback to summary
public void setIdleTimeout(Duration duration)

Implements org.eclipse.jetty.websocket.api.Configurable.setIdleTimeout.

Doc from org.eclipse.jetty.websocket.api.Configurable.setIdleTimeout.

The duration that a websocket may be idle before being closed by the implementation

Parameters
duration:Duration

the timeout duration (may not be null or negative)

Annotations
@Override
setInputBufferSizeback to summary
public void setInputBufferSize(int size)

Implements org.eclipse.jetty.websocket.api.Configurable.setInputBufferSize.

Doc from org.eclipse.jetty.websocket.api.Configurable.setInputBufferSize.

The input (read from network layer) buffer size.

Parameters
size:int

the size in bytes

Annotations
@Override
setMaxBinaryMessageSizeback to summary
public void setMaxBinaryMessageSize(long size)

Implements org.eclipse.jetty.websocket.api.Configurable.setMaxBinaryMessageSize.

Doc from org.eclipse.jetty.websocket.api.Configurable.setMaxBinaryMessageSize.

The 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

Parameters
size:long

the maximum allowed size of a binary message.

Annotations
@Override
setMaxFrameSizeback to summary
public void setMaxFrameSize(long maxFrameSize)

Implements org.eclipse.jetty.websocket.api.Configurable.setMaxFrameSize.

Doc from org.eclipse.jetty.websocket.api.Configurable.setMaxFrameSize.

The 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

Parameters
maxFrameSize:long

the maximum allowed size of a WebSocket Frame.

Annotations
@Override
setMaxOutgoingFramesback to summary
public void setMaxOutgoingFrames(int maxOutgoingFrames)

Implements org.eclipse.jetty.websocket.api.Configurable.setMaxOutgoingFrames.

Doc from org.eclipse.jetty.websocket.api.Configurable.setMaxOutgoingFrames.

Set 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 a java.nio.channels.WritePendingException but the connection is not failed and will remain open.

Parameters
maxOutgoingFrames:int

the max number of frames.

Annotations
@Override
setMaxTextMessageSizeback to summary
public void setMaxTextMessageSize(long size)

Implements org.eclipse.jetty.websocket.api.Configurable.setMaxTextMessageSize.

Doc from org.eclipse.jetty.websocket.api.Configurable.setMaxTextMessageSize.

The 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

Parameters
size:long

the maximum allowed size of a text message.

Annotations
@Override
setOutputBufferSizeback to summary
public void setOutputBufferSize(int size)

Implements org.eclipse.jetty.websocket.api.Configurable.setOutputBufferSize.

Doc from org.eclipse.jetty.websocket.api.Configurable.setOutputBufferSize.

The output (write to network layer) buffer size.

Parameters
size:int

the size in bytes

Annotations
@Override
setStopAtShutdownback to summary
public void setStopAtShutdown(boolean stop)

Set JVM shutdown behavior.

Parameters
stop:boolean

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
setStopTimeoutback to summary
public void setStopTimeout(long stopTimeout)

The timeout to allow all remaining open Sessions to be closed gracefully using the close code org.eclipse.jetty.websocket.api.StatusCode#SHUTDOWN.

Parameters
stopTimeout:long

the time in ms to wait for the graceful close, use a value less than or equal to 0 to not gracefully close.

toStringback to summary
public String toString()

Overrides org.eclipse.jetty.util.component.AbstractLifeCycle.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object. Satisfying this method's contract implies a non-null result must be returned.

Returns:String

a string representation of the object

Annotations
@Override