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,org.eclipse.jetty.websocket.api.WebSocketContainer,org.eclipse.jetty.websocket.api.WebSocketPolicy
public class WebSocketClient
extends org.eclipse.jetty.util.component.ContainerLifeCycle
implements org.eclipse.jetty.websocket.api.WebSocketPolicy, org.eclipse.jetty.websocket.api.WebSocketContainer
-
Nested Class Summary
Nested classes/interfaces inherited from class org.eclipse.jetty.util.component.AbstractLifeCycle
org.eclipse.jetty.util.component.AbstractLifeCycle.AbstractLifeCycleListener, org.eclipse.jetty.util.component.AbstractLifeCycle.StopExceptionNested 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
Fields inherited from class org.eclipse.jetty.util.component.AbstractLifeCycle
FAILED, STARTED, STARTING, STOPPED, STOPPINGFields inherited from interface org.eclipse.jetty.util.component.Dumpable
KEY -
Constructor Summary
ConstructorsConstructorDescriptionInstantiate a WebSocketClient with defaultsWebSocketClient(org.eclipse.jetty.client.HttpClient httpClient) Instantiate a WebSocketClient using HttpClient for defaults -
Method Summary
Modifier and TypeMethodDescriptionvoidaddSessionListener(org.eclipse.jetty.websocket.api.WebSocketSessionListener listener) CompletableFuture<org.eclipse.jetty.websocket.api.Session>CompletableFuture<org.eclipse.jetty.websocket.api.Session>connect(Object websocket, URI toUri, ClientUpgradeRequest request) Connect to remote websocket endpointCompletableFuture<org.eclipse.jetty.websocket.api.Session>connect(Object websocket, URI toUri, ClientUpgradeRequest request, JettyUpgradeListener upgradeListener) Connect to remote websocket endpointprotected voiddoStop()voiddump(Appendable out, String indent) org.eclipse.jetty.websocket.api.WebSocketBehaviororg.eclipse.jetty.io.ByteBufferPoollongorg.eclipse.jetty.client.HttpClientintlonglonglongorg.eclipse.jetty.util.DecoratedObjectFactoryCollection<org.eclipse.jetty.websocket.api.Session>intorg.eclipse.jetty.util.ssl.SslContextFactorylongbooleanbooleanvoidnotifySessionListeners(Consumer<org.eclipse.jetty.websocket.api.WebSocketSessionListener> consumer) booleanremoveSessionListener(org.eclipse.jetty.websocket.api.WebSocketSessionListener listener) voidsetAutoFragment(boolean autoFragment) voidsetBindAddress(SocketAddress bindAddress) voidsetConnectTimeout(long ms) Set the timeout for connecting to the remote server.voidsetCookieStore(CookieStore cookieStore) voidsetIdleTimeout(Duration duration) voidsetInputBufferSize(int size) voidsetMaxBinaryMessageSize(long size) voidsetMaxFrameSize(long maxFrameSize) voidsetMaxTextMessageSize(long size) voidsetOutputBufferSize(int 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 org.eclipse.jetty.util.component.ContainerLifeCycle
addBean, addBean, addEventListener, addManaged, contains, destroy, doStart, dump, dump, dumpObjects, dumpStdErr, getBean, getBeans, getBeans, getContainedBeans, getContainedBeans, isAuto, isManaged, isUnmanaged, manage, removeBean, removeBeans, removeEventListener, setBeans, start, stop, unmanage, updateBean, updateBean, updateBeans, updateBeansMethods inherited from class org.eclipse.jetty.util.component.AbstractLifeCycle
getEventListeners, getState, getState, isFailed, isRunning, isStarted, isStarting, isStopped, isStopping, setEventListeners, start, stopMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface org.eclipse.jetty.util.component.Container
getCachedBeans, getEventListenersMethods inherited from interface org.eclipse.jetty.util.component.Dumpable
dumpSelfMethods inherited from interface org.eclipse.jetty.util.component.Dumpable.DumpableContainer
isDumpable
-
Constructor Details
-
WebSocketClient
public WebSocketClient()Instantiate a WebSocketClient with defaults -
WebSocketClient
public WebSocketClient(org.eclipse.jetty.client.HttpClient httpClient) Instantiate a WebSocketClient using HttpClient for defaults- Parameters:
httpClient- the HttpClient to base internal defaults off of
-
-
Method Details
-
connect
public CompletableFuture<org.eclipse.jetty.websocket.api.Session> connect(Object websocket, URI toUri) throws IOException - Throws:
IOException
-
connect
public CompletableFuture<org.eclipse.jetty.websocket.api.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 CompletableFuture<org.eclipse.jetty.websocket.api.Session> connect(Object websocket, URI toUri, ClientUpgradeRequest request, JettyUpgradeListener 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
-
dump
- Specified by:
dumpin interfaceorg.eclipse.jetty.util.component.Dumpable- Overrides:
dumpin classorg.eclipse.jetty.util.component.ContainerLifeCycle- Throws:
IOException
-
getBehavior
public org.eclipse.jetty.websocket.api.WebSocketBehavior getBehavior()- Specified by:
getBehaviorin interfaceorg.eclipse.jetty.websocket.api.WebSocketPolicy
-
addSessionListener
public void addSessionListener(org.eclipse.jetty.websocket.api.WebSocketSessionListener listener) - Specified by:
addSessionListenerin interfaceorg.eclipse.jetty.websocket.api.WebSocketContainer
-
removeSessionListener
public boolean removeSessionListener(org.eclipse.jetty.websocket.api.WebSocketSessionListener listener) - Specified by:
removeSessionListenerin interfaceorg.eclipse.jetty.websocket.api.WebSocketContainer
-
notifySessionListeners
public void notifySessionListeners(Consumer<org.eclipse.jetty.websocket.api.WebSocketSessionListener> consumer) - Specified by:
notifySessionListenersin interfaceorg.eclipse.jetty.websocket.api.WebSocketContainer
-
getIdleTimeout
- Specified by:
getIdleTimeoutin interfaceorg.eclipse.jetty.websocket.api.WebSocketPolicy
-
getInputBufferSize
public int getInputBufferSize()- Specified by:
getInputBufferSizein interfaceorg.eclipse.jetty.websocket.api.WebSocketPolicy
-
getOutputBufferSize
public int getOutputBufferSize()- Specified by:
getOutputBufferSizein interfaceorg.eclipse.jetty.websocket.api.WebSocketPolicy
-
getMaxBinaryMessageSize
public long getMaxBinaryMessageSize()- Specified by:
getMaxBinaryMessageSizein interfaceorg.eclipse.jetty.websocket.api.WebSocketPolicy
-
getMaxTextMessageSize
public long getMaxTextMessageSize()- Specified by:
getMaxTextMessageSizein interfaceorg.eclipse.jetty.websocket.api.WebSocketPolicy
-
getMaxFrameSize
public long getMaxFrameSize()- Specified by:
getMaxFrameSizein interfaceorg.eclipse.jetty.websocket.api.WebSocketPolicy
-
isAutoFragment
public boolean isAutoFragment()- Specified by:
isAutoFragmentin interfaceorg.eclipse.jetty.websocket.api.WebSocketPolicy
-
setIdleTimeout
- Specified by:
setIdleTimeoutin interfaceorg.eclipse.jetty.websocket.api.WebSocketPolicy
-
setInputBufferSize
public void setInputBufferSize(int size) - Specified by:
setInputBufferSizein interfaceorg.eclipse.jetty.websocket.api.WebSocketPolicy
-
setOutputBufferSize
public void setOutputBufferSize(int size) - Specified by:
setOutputBufferSizein interfaceorg.eclipse.jetty.websocket.api.WebSocketPolicy
-
setMaxBinaryMessageSize
public void setMaxBinaryMessageSize(long size) - Specified by:
setMaxBinaryMessageSizein interfaceorg.eclipse.jetty.websocket.api.WebSocketPolicy
-
setMaxTextMessageSize
public void setMaxTextMessageSize(long size) - Specified by:
setMaxTextMessageSizein interfaceorg.eclipse.jetty.websocket.api.WebSocketPolicy
-
setMaxFrameSize
public void setMaxFrameSize(long maxFrameSize) - Specified by:
setMaxFrameSizein interfaceorg.eclipse.jetty.websocket.api.WebSocketPolicy
-
setAutoFragment
public void setAutoFragment(boolean autoFragment) - Specified by:
setAutoFragmentin interfaceorg.eclipse.jetty.websocket.api.WebSocketPolicy
-
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
-
getCookieStore
-
setCookieStore
-
getBufferPool
public org.eclipse.jetty.io.ByteBufferPool getBufferPool() -
getExecutor
- Specified by:
getExecutorin interfaceorg.eclipse.jetty.websocket.api.WebSocketContainer
-
getHttpClient
public org.eclipse.jetty.client.HttpClient getHttpClient() -
getObjectFactory
public org.eclipse.jetty.util.DecoratedObjectFactory getObjectFactory() -
getOpenSessions
- Specified by:
getOpenSessionsin interfaceorg.eclipse.jetty.websocket.api.WebSocketContainer
-
getSslContextFactory
public org.eclipse.jetty.util.ssl.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
-
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
- Overrides:
doStopin classorg.eclipse.jetty.util.component.ContainerLifeCycle- Throws:
Exception
-
toString
- Overrides:
toStringin classorg.eclipse.jetty.util.component.AbstractLifeCycle
-