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
,WebSocketContainerScope
public class WebSocketClient extends 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
AbstractLifeCycle.AbstractLifeCycleListener
-
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(java.util.concurrent.Executor executor)
Create a new WebSocketClientWebSocketClient(HttpClient httpClient)
Instantiate a WebSocketClient using HttpClient for defaultsWebSocketClient(HttpClient httpClient, DecoratedObjectFactory objectFactory)
Instantiate a WebSocketClient using HttpClient for defaultsWebSocketClient(ByteBufferPool bufferPool)
Create a new WebSocketClientWebSocketClient(SslContextFactory sslContextFactory)
Create a new WebSocketClientWebSocketClient(SslContextFactory sslContextFactory, java.util.concurrent.Executor executor)
Create a new WebSocketClientWebSocketClient(SslContextFactory sslContextFactory, java.util.concurrent.Executor executor, ByteBufferPool bufferPool)
Create WebSocketClient using sharing instances of SSLContextFactory Executor, and ByteBufferPoolWebSocketClient(WebSocketContainerScope scope)
Create WebSocketClient other Container Scope, to allow sharing of internal features like Executor, ByteBufferPool, SSLContextFactory, etc.WebSocketClient(WebSocketContainerScope scope, SslContextFactory sslContextFactory)
Create WebSocketClient other Container Scope, to allow sharing of internal features like Executor, ByteBufferPool, SSLContextFactory, etc.WebSocketClient(WebSocketContainerScope scope, EventDriverFactory eventDriverFactory, SessionFactory sessionFactory)
Create WebSocketClient based on pre-existing Container Scope, to allow sharing of internal features like Executor, ByteBufferPool, SSLContextFactory, etc.WebSocketClient(WebSocketContainerScope scope, EventDriverFactory eventDriverFactory, SessionFactory sessionFactory, HttpClient httpClient)
Create WebSocketClient based on pre-existing Container Scope, to allow sharing of internal features like Executor, ByteBufferPool, SSLContextFactory, etc.
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description void
addSessionListener(WebSocketSessionListener listener)
java.util.concurrent.Future<org.eclipse.jetty.websocket.api.Session>
connect(java.lang.Object websocket, java.net.URI toUri)
java.util.concurrent.Future<org.eclipse.jetty.websocket.api.Session>
connect(java.lang.Object websocket, java.net.URI toUri, ClientUpgradeRequest request)
Connect to remote websocket endpointjava.util.concurrent.Future<org.eclipse.jetty.websocket.api.Session>
connect(java.lang.Object websocket, java.net.URI toUri, ClientUpgradeRequest request, UpgradeListener upgradeListener)
Connect to remote websocket endpointprotected void
doStart()
protected void
doStop()
boolean
equals(java.lang.Object o)
long
getAsyncWriteTimeout()
Return the number of milliseconds for a timeout of an attempted write operation.java.net.SocketAddress
getBindAddress()
ByteBufferPool
getBufferPool()
ConnectionManager
getConnectionManager()
Deprecated.long
getConnectTimeout()
java.net.CookieStore
getCookieStore()
EventDriverFactory
getEventDriverFactory()
java.util.concurrent.Executor
getExecutor()
org.eclipse.jetty.websocket.api.extensions.ExtensionFactory
getExtensionFactory()
HttpClient
getHttpClient()
Get the internalHttpClient
.Masker
getMasker()
Deprecated.not used, no replacementint
getMaxBinaryMessageBufferSize()
Get the maximum size for buffering of a binary message.long
getMaxBinaryMessageSize()
Get the maximum size for a binary message.long
getMaxIdleTimeout()
Get the max idle timeout for new connections.int
getMaxTextMessageBufferSize()
Get the maximum size for buffering of a text message.long
getMaxTextMessageSize()
Get the maximum size for a text message.DecoratedObjectFactory
getObjectFactory()
java.util.Set<WebSocketSession>
getOpenSessions()
org.eclipse.jetty.websocket.api.WebSocketPolicy
getPolicy()
Scheduler
getScheduler()
SessionFactory
getSessionFactory()
java.util.Collection<WebSocketSessionListener>
getSessionListeners()
SslContextFactory
getSslContextFactory()
Get the in useSslContextFactory
int
hashCode()
boolean
isDispatchIO()
Deprecated.boolean
isStopAtShutdown()
protected ConnectionManager
newConnectionManager()
Deprecated.has no replacementvoid
removeSessionListener(WebSocketSessionListener listener)
void
setAsyncWriteTimeout(long ms)
void
setBindAdddress(java.net.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)
void
setBindAddress(java.net.SocketAddress bindAddress)
Sets the Bind Address on the internalHttpClient
.void
setBufferPool(ByteBufferPool bufferPool)
Set's the Bind Address on the internalHttpClient
.void
setConnectTimeout(long ms)
Set the timeout for connecting to the remote server on the internalHttpClient
void
setCookieStore(java.net.CookieStore cookieStore)
Set theCookieStore
to use on the internalHttpClient
void
setDaemon(boolean daemon)
Deprecated.not used, configure threading inHttpClient
insteadvoid
setDispatchIO(boolean dispatchIO)
Deprecated.no longer used, this has no replacementvoid
setExecutor(java.util.concurrent.Executor executor)
Sets the Executor in use on the internalHttpClient
void
setMasker(Masker masker)
Deprecated.not used, no replacementvoid
setMaxBinaryMessageBufferSize(int max)
void
setMaxIdleTimeout(long ms)
Set the max idle timeout for new connections.void
setMaxTextMessageBufferSize(int max)
void
setStopAtShutdown(boolean stop)
Set JVM shutdown behavior.java.lang.String
toString()
-
Methods inherited from class org.eclipse.jetty.util.component.ContainerLifeCycle
addBean, 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, updateBeans
-
Methods inherited from class org.eclipse.jetty.util.component.AbstractLifeCycle
addLifeCycleListener, getState, getState, getStopTimeout, isFailed, isRunning, isStarted, isStarting, isStopped, isStopping, removeLifeCycleListener, start, stop
-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface org.eclipse.jetty.websocket.common.scopes.WebSocketContainerScope
isRunning
-
-
-
-
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
-
WebSocketClient
public WebSocketClient(HttpClient httpClient, DecoratedObjectFactory objectFactory)
Instantiate a WebSocketClient using HttpClient for defaults- Parameters:
httpClient
- the HttpClient to base internal defaults off ofobjectFactory
- the DecoratedObjectFactory for all client instantiated classes
-
WebSocketClient
public WebSocketClient(SslContextFactory sslContextFactory)
Create a new WebSocketClient- Parameters:
sslContextFactory
- ssl context factory to use on the internalHttpClient
-
WebSocketClient
public WebSocketClient(java.util.concurrent.Executor executor)
Create a new WebSocketClient- Parameters:
executor
- the executor to use on the internalHttpClient
-
WebSocketClient
public WebSocketClient(ByteBufferPool bufferPool)
Create a new WebSocketClient- Parameters:
bufferPool
- byte buffer pool to use on the internalHttpClient
-
WebSocketClient
public WebSocketClient(SslContextFactory sslContextFactory, java.util.concurrent.Executor executor)
Create a new WebSocketClient- Parameters:
sslContextFactory
- ssl context factory to use on the internalHttpClient
executor
- the executor to use on the internalHttpClient
-
WebSocketClient
public WebSocketClient(WebSocketContainerScope scope)
Create WebSocketClient other Container Scope, to allow sharing of internal features like Executor, ByteBufferPool, SSLContextFactory, etc.- Parameters:
scope
- the Container Scope
-
WebSocketClient
public WebSocketClient(WebSocketContainerScope scope, SslContextFactory sslContextFactory)
Create 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
public WebSocketClient(SslContextFactory sslContextFactory, java.util.concurrent.Executor executor, ByteBufferPool bufferPool)
Create WebSocketClient using sharing instances of SSLContextFactory Executor, and ByteBufferPool- Parameters:
sslContextFactory
- shared SSL ContextFactoryexecutor
- shared ExecutorbufferPool
- shared ByteBufferPool
-
WebSocketClient
public WebSocketClient(WebSocketContainerScope scope, EventDriverFactory eventDriverFactory, SessionFactory sessionFactory)
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, 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 Detail
-
connect
public java.util.concurrent.Future<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.Future<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.Future<org.eclipse.jetty.websocket.api.Session> connect(java.lang.Object websocket, java.net.URI toUri, ClientUpgradeRequest request, UpgradeListener 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
-
doStart
protected void doStart() throws java.lang.Exception
- Overrides:
doStart
in classContainerLifeCycle
- Throws:
java.lang.Exception
-
doStop
protected void doStop() throws java.lang.Exception
- Overrides:
doStop
in classContainerLifeCycle
- Throws:
java.lang.Exception
-
isDispatchIO
@Deprecated public boolean isDispatchIO()
Deprecated.
-
getAsyncWriteTimeout
public long getAsyncWriteTimeout()
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
public java.net.SocketAddress getBindAddress()
-
getBufferPool
public ByteBufferPool getBufferPool()
- Specified by:
getBufferPool
in interfaceWebSocketContainerScope
-
getConnectionManager
@Deprecated public ConnectionManager getConnectionManager()
Deprecated.
-
getConnectTimeout
public long getConnectTimeout()
-
getCookieStore
public java.net.CookieStore getCookieStore()
-
getEventDriverFactory
public EventDriverFactory getEventDriverFactory()
-
getExecutor
public java.util.concurrent.Executor getExecutor()
- Specified by:
getExecutor
in interfaceWebSocketContainerScope
-
getExtensionFactory
public org.eclipse.jetty.websocket.api.extensions.ExtensionFactory getExtensionFactory()
-
getMasker
@Deprecated public Masker getMasker()
Deprecated.not used, no replacement- Returns:
- a
RandomMasker
instance
-
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 DecoratedObjectFactory getObjectFactory()
- Specified by:
getObjectFactory
in interfaceWebSocketContainerScope
-
getOpenSessions
public java.util.Set<WebSocketSession> getOpenSessions()
-
getPolicy
public org.eclipse.jetty.websocket.api.WebSocketPolicy getPolicy()
- Specified by:
getPolicy
in interfaceWebSocketContainerScope
-
getScheduler
public Scheduler getScheduler()
-
getSessionFactory
public SessionFactory getSessionFactory()
-
getSslContextFactory
public SslContextFactory getSslContextFactory()
Get the in useSslContextFactory
- Specified by:
getSslContextFactory
in interfaceWebSocketContainerScope
- Returns:
- the
SslContextFactory
that manages TLS encryption on the internalHttpClient
- See Also:
WebSocketClient(SslContextFactory)
-
addSessionListener
public void addSessionListener(WebSocketSessionListener listener)
- Specified by:
addSessionListener
in interfaceWebSocketContainerScope
-
removeSessionListener
public void removeSessionListener(WebSocketSessionListener listener)
- Specified by:
removeSessionListener
in interfaceWebSocketContainerScope
-
getSessionListeners
public java.util.Collection<WebSocketSessionListener> getSessionListeners()
- Specified by:
getSessionListeners
in interfaceWebSocketContainerScope
-
newConnectionManager
@Deprecated protected ConnectionManager newConnectionManager()
Deprecated.has no replacementFactory method for new ConnectionManager- Returns:
- the ConnectionManager instance to use
-
setAsyncWriteTimeout
public void setAsyncWriteTimeout(long ms)
-
setBindAdddress
@Deprecated public void setBindAdddress(java.net.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)
- Parameters:
bindAddress
- the address to bind to the internalHttpClient
-
setBindAddress
public void setBindAddress(java.net.SocketAddress bindAddress)
Sets the Bind Address on the internalHttpClient
.- Parameters:
bindAddress
- the local bind address for the internalHttpClient
-
setBufferPool
public void setBufferPool(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
public void setCookieStore(java.net.CookieStore cookieStore)
Set theCookieStore
to use on the internalHttpClient
- Parameters:
cookieStore
- The cookie store
-
setDaemon
@Deprecated public void setDaemon(boolean daemon)
Deprecated.not used, configure threading inHttpClient
instead- Parameters:
daemon
- do nothing
-
setDispatchIO
@Deprecated public void setDispatchIO(boolean dispatchIO)
Deprecated.no longer used, this has no replacement- Parameters:
dispatchIO
- true to have IO operations be dispatched to Executor
-
setExecutor
public void setExecutor(java.util.concurrent.Executor executor)
Sets the Executor in use on the internalHttpClient
- Parameters:
executor
- The executor to use
-
setMasker
@Deprecated public void setMasker(Masker masker)
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 HttpClient getHttpClient()
Get the internalHttpClient
.Note: this can result in a
LinkageError
if used within a WebApp that runs on a server that also hasHttpClient
on 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:
Runtime.addShutdownHook(Thread)
,ShutdownThread
-
isStopAtShutdown
public boolean isStopAtShutdown()
-
equals
public boolean equals(java.lang.Object o)
- Overrides:
equals
in classjava.lang.Object
-
hashCode
public int hashCode()
- Overrides:
hashCode
in classjava.lang.Object
-
toString
public java.lang.String toString()
- Overrides:
toString
in classAbstractLifeCycle
-
-