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, WebSocketContainerScope
public class WebSocketClient
extends org.eclipse.jetty.util.component.ContainerLifeCycle
implements WebSocketContainerScope
WebSocketClient provides a means of establishing connections to remote websocket endpoints.
-
Nested Class Summary
Nested classes/interfaces inherited from class org.eclipse.jetty.util.component.AbstractLifeCycle
org.eclipse.jetty.util.component.AbstractLifeCycle.AbstractLifeCycleListenerNested classes/interfaces inherited from interface org.eclipse.jetty.util.component.Container
org.eclipse.jetty.util.component.Container.InheritedListener, org.eclipse.jetty.util.component.Container.ListenerNested classes/interfaces inherited from interface org.eclipse.jetty.util.component.Dumpable
org.eclipse.jetty.util.component.Dumpable.DumpableContainerNested classes/interfaces inherited from interface org.eclipse.jetty.util.component.LifeCycle
org.eclipse.jetty.util.component.LifeCycle.Listener -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final ClassLoaderprivate EventDriverFactoryprivate final WebSocketExtensionFactoryprivate final org.eclipse.jetty.client.HttpClientprivate static final org.eclipse.jetty.util.log.Loggerprivate final Supplier<org.eclipse.jetty.util.DecoratedObjectFactory> private final WebSocketPolicyprivate SessionFactoryprivate final List<WebSocketSessionListener> private final SessionTrackerprivate booleanFields inherited from class org.eclipse.jetty.util.component.AbstractLifeCycle
FAILED, RUNNING, STARTED, STARTING, STOPPED, STOPPINGFields inherited from interface org.eclipse.jetty.util.component.Dumpable
KEY -
Constructor Summary
ConstructorsConstructorDescriptionInstantiate a WebSocketClient with defaults.WebSocketClient(Executor executor) Deprecated.WebSocketClient(org.eclipse.jetty.client.HttpClient httpClient) Instantiate a WebSocketClient using provided HttpClient.WebSocketClient(org.eclipse.jetty.client.HttpClient httpClient, org.eclipse.jetty.util.DecoratedObjectFactory decoratedObjectFactory) Instantiate a WebSocketClient using HttpClient for defaultsWebSocketClient(org.eclipse.jetty.io.ByteBufferPool bufferPool) Deprecated.useWebSocketClient(HttpClient)insteadWebSocketClient(org.eclipse.jetty.util.ssl.SslContextFactory sslContextFactory) Deprecated.useWebSocketClient(HttpClient)insteadWebSocketClient(org.eclipse.jetty.util.ssl.SslContextFactory sslContextFactory, Executor executor) Deprecated.useWebSocketClient(HttpClient)insteadWebSocketClient(org.eclipse.jetty.util.ssl.SslContextFactory sslContextFactory, Executor executor, org.eclipse.jetty.io.ByteBufferPool bufferPool) Deprecated.useWebSocketClient(HttpClient)insteadDeprecated.useWebSocketClient(HttpClient)insteadWebSocketClient(WebSocketContainerScope scope, org.eclipse.jetty.util.ssl.SslContextFactory sslContextFactory) Deprecated.useWebSocketClient(HttpClient)insteadWebSocketClient(WebSocketContainerScope scope, EventDriverFactory eventDriverFactory, SessionFactory sessionFactory) Deprecated.WebSocketClient(WebSocketContainerScope scope, EventDriverFactory eventDriverFactory, SessionFactory sessionFactory, org.eclipse.jetty.client.HttpClient httpClient) Create WebSocketClient based on pre-existing Container Scope, to allow sharing of internal features like Executor, ByteBufferPool, SSLContextFactory, etc. -
Method Summary
Modifier and TypeMethodDescriptionvoidaddSessionListener(WebSocketSessionListener listener) connect(Object websocket, URI toUri, ClientUpgradeRequest request) Connect to remote websocket endpointconnect(Object websocket, URI toUri, ClientUpgradeRequest request, UpgradeListener upgradeListener) Connect to remote websocket endpointprotected voiddoStart()protected voiddoStop()booleanlongDeprecated.org.eclipse.jetty.io.ByteBufferPoolThe configured Container Buffer Pool.The ClassLoader used to load classes for the WebSocketSession.Deprecated.longExecutor in use by the container.org.eclipse.jetty.client.HttpClientGet the internalHttpClient.Deprecated.not used, no replacementintGet the maximum size for buffering of a binary message.longGet the maximum size for a binary message.longGet the max idle timeout for new connections.intGet the maximum size for buffering of a text message.longGet the maximum size for a text message.org.eclipse.jetty.util.DecoratedObjectFactoryObject Factory used to create objects.The policy the container is running on.org.eclipse.jetty.util.thread.Schedulerorg.eclipse.jetty.util.ssl.SslContextFactoryGet the in useSslContextFactoryinthashCode()private voidinit()booleanDeprecated.booleanprotected ConnectionManagerDeprecated.has no replacementprivate static org.eclipse.jetty.client.HttpClientnewHttpClient(org.eclipse.jetty.util.ssl.SslContextFactory sslContextFactory, Executor executor, org.eclipse.jetty.io.ByteBufferPool bufferPool) voidvoidsetAsyncWriteTimeout(long ms) voidsetBindAdddress(SocketAddress bindAddress) Deprecated.(this is a bad bad bad typo, it has 3 { @ code " d " } characters in a row) useHttpClient.setBindAddress(SocketAddress)to the internalWebSocketClient(HttpClient)voidsetBindAddress(SocketAddress bindAddress) Sets the Bind Address on the internalHttpClient.voidsetBufferPool(org.eclipse.jetty.io.ByteBufferPool bufferPool) Set's the Bind Address on the internalHttpClient.voidsetConnectTimeout(long ms) Set the timeout for connecting to the remote server on the internalHttpClientvoidsetCookieStore(CookieStore cookieStore) Set theCookieStoreto use on the internalHttpClientvoidsetDaemon(boolean daemon) Deprecated.not used, configure threading inHttpClientinsteadvoidsetDispatchIO(boolean dispatchIO) Deprecated.no longer used, this has no replacementvoidsetEventDriverFactory(EventDriverFactory eventDriverFactory) voidsetExecutor(Executor executor) Sets the Executor in use on the internalHttpClientvoidDeprecated.not used, no replacementvoidsetMaxBinaryMessageBufferSize(int max) voidsetMaxIdleTimeout(long ms) Set the max idle timeout for new connections.voidsetMaxTextMessageBufferSize(int max) voidsetSessionFactory(SessionFactory sessionFactory) voidsetStopAtShutdown(boolean stop) Set JVM shutdown behavior.toString()Methods inherited from class org.eclipse.jetty.util.component.ContainerLifeCycle
addBean, addBean, addEventListener, addManaged, contains, destroy, dump, dump, dump, dump, dump, dumpBeans, dumpObject, dumpObjects, dumpStdErr, dumpThis, getBean, getBeans, getBeans, getContainedBeans, getContainedBeans, isAuto, isManaged, isUnmanaged, manage, removeBean, removeBeans, removeEventListener, setBeans, setStopTimeout, start, stop, unmanage, updateBean, updateBean, updateBeansMethods inherited from class org.eclipse.jetty.util.component.AbstractLifeCycle
addLifeCycleListener, getState, getState, getStopTimeout, isFailed, isRunning, isStarted, isStarting, isStopped, isStopping, removeLifeCycleListener, start, stopMethods inherited from interface org.eclipse.jetty.util.component.Dumpable
dumpSelfMethods inherited from interface org.eclipse.jetty.util.component.Dumpable.DumpableContainer
isDumpableMethods inherited from interface WebSocketContainerScope
isRunning
-
Field Details
-
LOG
private static final org.eclipse.jetty.util.log.Logger LOG -
httpClient
private final org.eclipse.jetty.client.HttpClient httpClient -
objectFactorySupplier
-
classloader
-
policy
-
extensionRegistry
-
sessionTracker
-
sessionListeners
-
eventDriverFactory
-
sessionFactory
-
stopAtShutdown
private boolean stopAtShutdown
-
-
Constructor Details
-
WebSocketClient
public WebSocketClient()Instantiate a WebSocketClient with defaults. -
WebSocketClient
public WebSocketClient(org.eclipse.jetty.client.HttpClient httpClient) Instantiate a WebSocketClient using provided HttpClient.- Parameters:
httpClient- the HttpClient to use for WebSocketClient.
-
WebSocketClient
public WebSocketClient(org.eclipse.jetty.client.HttpClient httpClient, org.eclipse.jetty.util.DecoratedObjectFactory decoratedObjectFactory) Instantiate a WebSocketClient using HttpClient for defaults- Parameters:
httpClient- the HttpClient that underlying WebSocket client usesdecoratedObjectFactory- the DecoratedObjectFactory for all client instantiated classes
-
WebSocketClient
Deprecated.useWebSocketClient(HttpClient)insteadCreate a new WebSocketClient- Parameters:
sslContextFactory- ssl context factory to use on the internalHttpClient
-
WebSocketClient
Deprecated.useWebSocketClient(HttpClient)insteadCreate a new WebSocketClient- Parameters:
executor- the executor to use on the internalHttpClient
-
WebSocketClient
Deprecated.useWebSocketClient(HttpClient)insteadCreate a new WebSocketClient- Parameters:
bufferPool- byte buffer pool to use on the internalHttpClient
-
WebSocketClient
@Deprecated public WebSocketClient(org.eclipse.jetty.util.ssl.SslContextFactory sslContextFactory, Executor executor) Deprecated.useWebSocketClient(HttpClient)insteadCreate a new WebSocketClient- Parameters:
sslContextFactory- ssl context factory to use on the internalHttpClientexecutor- the executor to use on the internalHttpClient
-
WebSocketClient
Deprecated.useWebSocketClient(HttpClient)insteadCreate WebSocketClient other Container Scope, to allow sharing of internal features like Executor, ByteBufferPool, SSLContextFactory, etc.- Parameters:
scope- the Container Scope
-
WebSocketClient
@Deprecated public WebSocketClient(WebSocketContainerScope scope, org.eclipse.jetty.util.ssl.SslContextFactory sslContextFactory) Deprecated.useWebSocketClient(HttpClient)insteadCreate WebSocketClient other Container Scope, to allow sharing of internal features like Executor, ByteBufferPool, SSLContextFactory, etc.- Parameters:
scope- the Container ScopesslContextFactory- SSL ContextFactory to use in preference to one fromWebSocketContainerScope.getSslContextFactory()
-
WebSocketClient
@Deprecated public WebSocketClient(org.eclipse.jetty.util.ssl.SslContextFactory sslContextFactory, Executor executor, org.eclipse.jetty.io.ByteBufferPool bufferPool) Deprecated.useWebSocketClient(HttpClient)insteadCreate WebSocketClient using sharing instances of SSLContextFactory Executor, and ByteBufferPool- Parameters:
sslContextFactory- shared SSL ContextFactoryexecutor- shared ExecutorbufferPool- shared ByteBufferPool
-
WebSocketClient
@Deprecated public WebSocketClient(WebSocketContainerScope scope, EventDriverFactory eventDriverFactory, SessionFactory sessionFactory) Deprecated.Create WebSocketClient based on pre-existing Container Scope, to allow sharing of internal features like Executor, ByteBufferPool, SSLContextFactory, etc.- Parameters:
scope- the Container ScopeeventDriverFactory- the EventDriver Factory to usesessionFactory- the SessionFactory to use
-
WebSocketClient
public WebSocketClient(WebSocketContainerScope scope, EventDriverFactory eventDriverFactory, SessionFactory sessionFactory, org.eclipse.jetty.client.HttpClient httpClient) Create WebSocketClient based on pre-existing Container Scope, to allow sharing of internal features like Executor, ByteBufferPool, SSLContextFactory, etc.- Parameters:
scope- the Container ScopeeventDriverFactory- the EventDriver Factory to usesessionFactory- the SessionFactory to usehttpClient- the httpClient to use
-
-
Method Details
-
newHttpClient
private static org.eclipse.jetty.client.HttpClient newHttpClient(org.eclipse.jetty.util.ssl.SslContextFactory sslContextFactory, Executor executor, org.eclipse.jetty.io.ByteBufferPool bufferPool) -
connect
- Throws:
IOException
-
connect
public Future<Session> connect(Object websocket, URI toUri, ClientUpgradeRequest request) throws 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:
IOException- if unable to connect
-
connect
public Future<Session> connect(Object websocket, URI toUri, ClientUpgradeRequest request, UpgradeListener upgradeListener) throws 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:
IOException- if unable to connect
-
getClassLoader
Description copied from interface:WebSocketContainerScopeThe ClassLoader used to load classes for the WebSocketSession.
By default this will be the ContextClassLoader at the time this method is called. However this will be overridden by the WebSocketClient to use the ContextClassLoader at the time it was created, this is because the client uses its own
ThreadPoolso the WebSocketSessions may be created when the ContextClassLoader is not set.- Specified by:
getClassLoaderin interfaceWebSocketContainerScope- Returns:
- the classloader.
-
setEventDriverFactory
-
setSessionFactory
-
doStart
-
doStop
-
isDispatchIO
Deprecated. -
getAsyncWriteTimeout
Deprecated.Return the number of milliseconds for a timeout of an attempted write operation.- Returns:
- number of milliseconds for timeout of an attempted write operation
-
getBindAddress
-
getBufferPool
public org.eclipse.jetty.io.ByteBufferPool getBufferPool()Description copied from interface:WebSocketContainerScopeThe configured Container Buffer Pool.- Specified by:
getBufferPoolin interfaceWebSocketContainerScope- Returns:
- the buffer pool (never null)
-
getConnectionManager
Deprecated. -
getConnectTimeout
public long getConnectTimeout() -
getCookieStore
-
getEventDriverFactory
-
getExecutor
Description copied from interface:WebSocketContainerScopeExecutor in use by the container.- Specified by:
getExecutorin interfaceWebSocketContainerScope- Returns:
- the Executor in use by the container.
-
getExtensionFactory
-
getMasker
Deprecated.not used, no replacement- Returns:
- a
RandomMaskerinstance
-
getMaxBinaryMessageBufferSize
public int getMaxBinaryMessageBufferSize()Get the maximum size for buffering of a binary message.- Returns:
- the maximum size of a binary message buffer.
-
getMaxBinaryMessageSize
public long getMaxBinaryMessageSize()Get the maximum size for a binary message.- Returns:
- the maximum size of a binary message.
-
getMaxIdleTimeout
public long getMaxIdleTimeout()Get the max idle timeout for new connections.- Returns:
- the max idle timeout in milliseconds for new connections.
-
getMaxTextMessageBufferSize
public int getMaxTextMessageBufferSize()Get the maximum size for buffering of a text message.- Returns:
- the maximum size of a text message buffer.
-
getMaxTextMessageSize
public long getMaxTextMessageSize()Get the maximum size for a text message.- Returns:
- the maximum size of a text message.
-
getObjectFactory
public org.eclipse.jetty.util.DecoratedObjectFactory getObjectFactory()Description copied from interface:WebSocketContainerScopeObject Factory used to create objects.- Specified by:
getObjectFactoryin interfaceWebSocketContainerScope- Returns:
- Object Factory used to create instances of objects.
-
getOpenSessions
-
getPolicy
Description copied from interface:WebSocketContainerScopeThe policy the container is running on.- Specified by:
getPolicyin interfaceWebSocketContainerScope- Returns:
- the websocket policy
-
getScheduler
public org.eclipse.jetty.util.thread.Scheduler getScheduler() -
getSessionFactory
-
getSslContextFactory
public org.eclipse.jetty.util.ssl.SslContextFactory getSslContextFactory()Get the in useSslContextFactory- Specified by:
getSslContextFactoryin interfaceWebSocketContainerScope- Returns:
- the
SslContextFactorythat manages TLS encryption on the internalHttpClient - See Also:
-
addSessionListener
- Specified by:
addSessionListenerin interfaceWebSocketContainerScope
-
removeSessionListener
- Specified by:
removeSessionListenerin interfaceWebSocketContainerScope
-
getSessionListeners
- Specified by:
getSessionListenersin interfaceWebSocketContainerScope
-
init
private void init() -
newConnectionManager
Deprecated.has no replacementFactory method for new ConnectionManager- Returns:
- the ConnectionManager instance to use
-
setAsyncWriteTimeout
public void setAsyncWriteTimeout(long ms) -
setBindAdddress
Deprecated.(this is a bad bad bad typo, it has 3 { @ code " d " } characters in a row) useHttpClient.setBindAddress(SocketAddress)to the internalWebSocketClient(HttpClient)- Parameters:
bindAddress- the address to bind to the internalHttpClient
-
setBindAddress
Sets the Bind Address on the internalHttpClient.- Parameters:
bindAddress- the local bind address for the internalHttpClient
-
setBufferPool
public void setBufferPool(org.eclipse.jetty.io.ByteBufferPool bufferPool) Set's the Bind Address on the internalHttpClient.- Parameters:
bufferPool- The buffer pool
-
setConnectTimeout
public void setConnectTimeout(long ms) Set the timeout for connecting to the remote server on the internalHttpClient- Parameters:
ms- the timeout in milliseconds
-
setCookieStore
Set theCookieStoreto use on the internalHttpClient- Parameters:
cookieStore- The cookie store
-
setDaemon
Deprecated.not used, configure threading inHttpClientinstead- Parameters:
daemon- do nothing
-
setDispatchIO
Deprecated.no longer used, this has no replacement- Parameters:
dispatchIO- true to have IO operations be dispatched to Executor
-
setExecutor
Sets the Executor in use on the internalHttpClient- Parameters:
executor- The executor to use
-
setMasker
Deprecated.not used, no replacement- Parameters:
masker- does nothing
-
setMaxBinaryMessageBufferSize
public void setMaxBinaryMessageBufferSize(int max) -
setMaxIdleTimeout
public void setMaxIdleTimeout(long ms) Set the max idle timeout for new connections.Existing connections will not have their max idle timeout adjusted.
- Parameters:
ms- the timeout in milliseconds
-
setMaxTextMessageBufferSize
public void setMaxTextMessageBufferSize(int max) -
getHttpClient
public org.eclipse.jetty.client.HttpClient getHttpClient()Get the internalHttpClient.Note: this can result in a
LinkageErrorif used within a WebApp that runs on a server that also hasHttpClienton the server classpath.- Returns:
- the internal
HttpClient
-
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:
-
isStopAtShutdown
public boolean isStopAtShutdown() -
equals
-
hashCode
-
toString
- Overrides:
toStringin classorg.eclipse.jetty.util.component.AbstractLifeCycle
-
WebSocketClient(HttpClient)instead