Package org.apache.tomcat.websocket
Class WsWebSocketContainer
- java.lang.Object
-
- org.apache.tomcat.websocket.WsWebSocketContainer
-
- All Implemented Interfaces:
WebSocketContainer,BackgroundProcess
- Direct Known Subclasses:
WsServerContainer
public class WsWebSocketContainer extends java.lang.Object implements WebSocketContainer, BackgroundProcess
Client-side WebSocket container implementation.
-
-
Constructor Summary
Constructors Constructor Description WsWebSocketContainer()Default constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidbackgroundProcess()Performs background processing.SessionconnectToServer(Endpoint endpoint, ClientEndpointConfig clientEndpointConfiguration, java.net.URI path)Creates a new connection to the WebSocket.SessionconnectToServer(java.lang.Class<?> annotatedEndpointClass, java.net.URI path)Creates a new connection to the WebSocket server endpoint.SessionconnectToServer(java.lang.Class<? extends Endpoint> clazz, ClientEndpointConfig clientEndpointConfiguration, java.net.URI path)Creates a new connection to the WebSocket.SessionconnectToServer(java.lang.Object pojo, java.net.URI path)Creates a new connection to the WebSocket server endpoint.voiddestroy()Cleans up the resources still in use by WebSocket sessions created from this container.longgetDefaultAsyncSendTimeout()Get the default timeout for sending a message asynchronously.intgetDefaultMaxBinaryMessageBufferSize()Get the default maximum buffer size for binary messages.longgetDefaultMaxSessionIdleTimeout()Get the current default session idle timeout.intgetDefaultMaxTextMessageBufferSize()Get the default maximum buffer size for text messages.java.util.Set<Extension>getInstalledExtensions()Get the installed extensions.protected InstanceManagergetInstanceManager(java.lang.ClassLoader classLoader)Returns the instance manager for the given class loader.intgetProcessPeriod()The default value is 10 which means session expirations are processed every 10 seconds.protected voidregisterSession(java.lang.Object key, WsSession wsSession)Registers a WebSocket session.voidsetAsyncSendTimeout(long timeout)Set the default timeout for sending a message asynchronously.voidsetDefaultMaxBinaryMessageBufferSize(int max)Set the default maximum buffer size for binary messages.voidsetDefaultMaxSessionIdleTimeout(long timeout)Set the default session idle timeout.voidsetDefaultMaxTextMessageBufferSize(int max)Set the default maximum buffer size for text messages.protected voidsetInstanceManager(InstanceManager instanceManager)Sets the instance manager for this container.voidsetProcessPeriod(int period)Sets the period, in seconds, between invocations ofBackgroundProcess.backgroundProcess().protected voidunregisterSession(java.lang.Object key, WsSession wsSession)Unregisters a WebSocket session.
-
-
-
Method Detail
-
getInstanceManager
protected InstanceManager getInstanceManager(java.lang.ClassLoader classLoader)
Returns the instance manager for the given class loader.- Parameters:
classLoader- the class loader- Returns:
- the instance manager
-
setInstanceManager
protected void setInstanceManager(InstanceManager instanceManager)
Sets the instance manager for this container.- Parameters:
instanceManager- the instance manager
-
connectToServer
public Session connectToServer(java.lang.Object pojo, java.net.URI path) throws DeploymentException
Description copied from interface:jakarta.websocket.WebSocketContainerCreates a new connection to the WebSocket server endpoint.- Specified by:
connectToServerin interfaceWebSocketContainer- Parameters:
pojo- The POJO endpoint instance that will handle responses from the serverpath- The full URL of the WebSocket endpoint to connect to- Returns:
- The WebSocket session for the connection
- Throws:
DeploymentException- If the connection cannot be established
-
connectToServer
public Session connectToServer(java.lang.Class<?> annotatedEndpointClass, java.net.URI path) throws DeploymentException
Description copied from interface:jakarta.websocket.WebSocketContainerCreates a new connection to the WebSocket server endpoint.- Specified by:
connectToServerin interfaceWebSocketContainer- Parameters:
annotatedEndpointClass- The annotated endpoint class. An instance of this class will be created to handle responses from the serverpath- The full URL of the WebSocket endpoint to connect to- Returns:
- The WebSocket session for the connection
- Throws:
DeploymentException- If the connection cannot be established
-
connectToServer
public Session connectToServer(java.lang.Class<? extends Endpoint> clazz, ClientEndpointConfig clientEndpointConfiguration, java.net.URI path) throws DeploymentException
Description copied from interface:jakarta.websocket.WebSocketContainerCreates a new connection to the WebSocket.- Specified by:
connectToServerin interfaceWebSocketContainer- Parameters:
clazz- An instance of this class will be created to handle responses from the serverclientEndpointConfiguration- Used to configure the new connectionpath- The full URL of the WebSocket endpoint to connect to- Returns:
- The WebSocket session for the connection
- Throws:
DeploymentException- If the connection cannot be established
-
connectToServer
public Session connectToServer(Endpoint endpoint, ClientEndpointConfig clientEndpointConfiguration, java.net.URI path) throws DeploymentException
Description copied from interface:jakarta.websocket.WebSocketContainerCreates a new connection to the WebSocket.- Specified by:
connectToServerin interfaceWebSocketContainer- Parameters:
endpoint- The endpoint instance that will handle responses from the serverclientEndpointConfiguration- Used to configure the new connectionpath- The full URL of the WebSocket endpoint to connect to- Returns:
- The WebSocket session for the connection
- Throws:
DeploymentException- If the connection cannot be established
-
registerSession
protected void registerSession(java.lang.Object key, WsSession wsSession)Registers a WebSocket session.- Parameters:
key- the session keywsSession- the session to register
-
unregisterSession
protected void unregisterSession(java.lang.Object key, WsSession wsSession)Unregisters a WebSocket session.- Parameters:
key- the session keywsSession- the session to unregister
-
getDefaultMaxSessionIdleTimeout
public long getDefaultMaxSessionIdleTimeout()
Description copied from interface:jakarta.websocket.WebSocketContainerGet the current default session idle timeout.- Specified by:
getDefaultMaxSessionIdleTimeoutin interfaceWebSocketContainer- Returns:
- The current default session idle timeout in milliseconds. Zero or negative values indicate an infinite timeout.
-
setDefaultMaxSessionIdleTimeout
public void setDefaultMaxSessionIdleTimeout(long timeout)
Description copied from interface:jakarta.websocket.WebSocketContainerSet the default session idle timeout.- Specified by:
setDefaultMaxSessionIdleTimeoutin interfaceWebSocketContainer- Parameters:
timeout- The new default session idle timeout in milliseconds. Zero or negative values indicate an infinite timeout.
-
getDefaultMaxBinaryMessageBufferSize
public int getDefaultMaxBinaryMessageBufferSize()
Description copied from interface:jakarta.websocket.WebSocketContainerGet the default maximum buffer size for binary messages.- Specified by:
getDefaultMaxBinaryMessageBufferSizein interfaceWebSocketContainer- Returns:
- The current default maximum buffer size in bytes
-
setDefaultMaxBinaryMessageBufferSize
public void setDefaultMaxBinaryMessageBufferSize(int max)
Description copied from interface:jakarta.websocket.WebSocketContainerSet the default maximum buffer size for binary messages.- Specified by:
setDefaultMaxBinaryMessageBufferSizein interfaceWebSocketContainer- Parameters:
max- The new default maximum buffer size in bytes
-
getDefaultMaxTextMessageBufferSize
public int getDefaultMaxTextMessageBufferSize()
Description copied from interface:jakarta.websocket.WebSocketContainerGet the default maximum buffer size for text messages.- Specified by:
getDefaultMaxTextMessageBufferSizein interfaceWebSocketContainer- Returns:
- The current default maximum buffer size in characters
-
setDefaultMaxTextMessageBufferSize
public void setDefaultMaxTextMessageBufferSize(int max)
Description copied from interface:jakarta.websocket.WebSocketContainerSet the default maximum buffer size for text messages.- Specified by:
setDefaultMaxTextMessageBufferSizein interfaceWebSocketContainer- Parameters:
max- The new default maximum buffer size in characters
-
getInstalledExtensions
public java.util.Set<Extension> getInstalledExtensions()
Get the installed extensions. Currently, this implementation does not support any extensions.- Specified by:
getInstalledExtensionsin interfaceWebSocketContainer- Returns:
- The set of extensions that are supported by this WebSocket implementation.
-
getDefaultAsyncSendTimeout
public long getDefaultAsyncSendTimeout()
Get the default timeout for sending a message asynchronously. The default value for this implementation is -1.- Specified by:
getDefaultAsyncSendTimeoutin interfaceWebSocketContainer- Returns:
- The current default timeout in milliseconds. A non-positive value means an infinite timeout.
-
setAsyncSendTimeout
public void setAsyncSendTimeout(long timeout)
Set the default timeout for sending a message asynchronously. The default value for this implementation is -1.- Specified by:
setAsyncSendTimeoutin interfaceWebSocketContainer- Parameters:
timeout- The new default timeout in milliseconds. A non-positive value means an infinite timeout.
-
destroy
public void destroy()
Cleans up the resources still in use by WebSocket sessions created from this container. This includes closing sessions and cancellingFutures associated with blocking read/writes.
-
backgroundProcess
public void backgroundProcess()
Description copied from interface:BackgroundProcessPerforms background processing.- Specified by:
backgroundProcessin interfaceBackgroundProcess
-
setProcessPeriod
public void setProcessPeriod(int period)
Description copied from interface:BackgroundProcessSets the period, in seconds, between invocations ofBackgroundProcess.backgroundProcess().- Specified by:
setProcessPeriodin interfaceBackgroundProcess- Parameters:
period- the period in seconds
-
getProcessPeriod
public int getProcessPeriod()
The default value is 10 which means session expirations are processed every 10 seconds.- Specified by:
getProcessPeriodin interfaceBackgroundProcess
-
-