Package org.apache.tomcat.websocket
Class WsWebSocketContainer
java.lang.Object
org.apache.tomcat.websocket.WsWebSocketContainer
- All Implemented Interfaces:
WebSocketContainer
,BackgroundProcess
- Direct Known Subclasses:
WsServerContainer
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
connectToServer
(Endpoint endpoint, ClientEndpointConfig clientEndpointConfiguration, URI path) Creates a new connection to the WebSocket.connectToServer
(Class<?> annotatedEndpointClass, URI path) connectToServer
(Class<? extends Endpoint> clazz, ClientEndpointConfig clientEndpointConfiguration, URI path) Creates a new connection to the WebSocket.connectToServer
(Object pojo, URI path) void
destroy()
Cleans up the resources still in use by WebSocket sessions created from this container.long
Get the default timeout for sending a message asynchronously.int
Get the default maximum buffer size for binary messages.long
Get the current default session idle timeout.int
Get the default maximum buffer size for text messages.Get the installed extensions.protected InstanceManager
getInstanceManager
(ClassLoader classLoader) int
The default value is 10 which means session expirations are processed every 10 seconds.protected void
registerSession
(Object key, WsSession wsSession) void
setAsyncSendTimeout
(long timeout) Set the default timeout for sending a message asynchronously.void
setDefaultMaxBinaryMessageBufferSize
(int max) Set the default maximum buffer size for binary messages.void
setDefaultMaxSessionIdleTimeout
(long timeout) Set the default session idle timeout.void
setDefaultMaxTextMessageBufferSize
(int max) Set the default maximum buffer size for text messages.protected void
setInstanceManager
(InstanceManager instanceManager) void
setProcessPeriod
(int period) protected void
unregisterSession
(Object key, WsSession wsSession)
-
Constructor Details
-
WsWebSocketContainer
public WsWebSocketContainer()
-
-
Method Details
-
getInstanceManager
-
setInstanceManager
-
connectToServer
- Specified by:
connectToServer
in interfaceWebSocketContainer
- Throws:
DeploymentException
-
connectToServer
public Session connectToServer(Class<?> annotatedEndpointClass, URI path) throws DeploymentException - Specified by:
connectToServer
in interfaceWebSocketContainer
- Throws:
DeploymentException
-
connectToServer
public Session connectToServer(Class<? extends Endpoint> clazz, ClientEndpointConfig clientEndpointConfiguration, URI path) throws DeploymentException Description copied from interface:jakarta.websocket.WebSocketContainer
Creates a new connection to the WebSocket.- Specified by:
connectToServer
in 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, URI path) throws DeploymentException Description copied from interface:jakarta.websocket.WebSocketContainer
Creates a new connection to the WebSocket.- Specified by:
connectToServer
in 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
-
unregisterSession
-
getDefaultMaxSessionIdleTimeout
public long getDefaultMaxSessionIdleTimeout()Description copied from interface:jakarta.websocket.WebSocketContainer
Get the current default session idle timeout.- Specified by:
getDefaultMaxSessionIdleTimeout
in 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.WebSocketContainer
Set the default session idle timeout.- Specified by:
setDefaultMaxSessionIdleTimeout
in 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.WebSocketContainer
Get the default maximum buffer size for binary messages.- Specified by:
getDefaultMaxBinaryMessageBufferSize
in interfaceWebSocketContainer
- Returns:
- The current default maximum buffer size in bytes
-
setDefaultMaxBinaryMessageBufferSize
public void setDefaultMaxBinaryMessageBufferSize(int max) Description copied from interface:jakarta.websocket.WebSocketContainer
Set the default maximum buffer size for binary messages.- Specified by:
setDefaultMaxBinaryMessageBufferSize
in interfaceWebSocketContainer
- Parameters:
max
- The new default maximum buffer size in bytes
-
getDefaultMaxTextMessageBufferSize
public int getDefaultMaxTextMessageBufferSize()Description copied from interface:jakarta.websocket.WebSocketContainer
Get the default maximum buffer size for text messages.- Specified by:
getDefaultMaxTextMessageBufferSize
in interfaceWebSocketContainer
- Returns:
- The current default maximum buffer size in characters
-
setDefaultMaxTextMessageBufferSize
public void setDefaultMaxTextMessageBufferSize(int max) Description copied from interface:jakarta.websocket.WebSocketContainer
Set the default maximum buffer size for text messages.- Specified by:
setDefaultMaxTextMessageBufferSize
in interfaceWebSocketContainer
- Parameters:
max
- The new default maximum buffer size in characters
-
getInstalledExtensions
Get the installed extensions. Currently, this implementation does not support any extensions.- Specified by:
getInstalledExtensions
in 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:
getDefaultAsyncSendTimeout
in 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:
setAsyncSendTimeout
in 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 cancellingFuture
s associated with blocking read/writes. -
backgroundProcess
public void backgroundProcess()- Specified by:
backgroundProcess
in interfaceBackgroundProcess
-
setProcessPeriod
public void setProcessPeriod(int period) - Specified by:
setProcessPeriod
in interfaceBackgroundProcess
-
getProcessPeriod
public int getProcessPeriod()The default value is 10 which means session expirations are processed every 10 seconds.- Specified by:
getProcessPeriod
in interfaceBackgroundProcess
-