Top Inners Fields Constructors Methods
org.apache.tomcat.websocket

public Class WsSession

extends Object
implements Session
Class Inheritance
All Implemented Interfaces
jakarta.websocket.Session, java.io.Closeable, java.lang.AutoCloseable
Imports
java.io.IOException, java.net.URI, java.nio.ByteBuffer, java.nio.charset.StandardCharsets, java.security.Principal, java.util.Collections, .HashSet, .List, .Map, .Set, java.util.concurrent.ConcurrentHashMap, .TimeUnit, java.util.concurrent.atomic.AtomicLong, .AtomicReference, javax.naming.NamingException, jakarta.websocket.ClientEndpointConfig, .CloseReason, .CloseReason.CloseCode, .CloseReason.CloseCodes, .DeploymentException, .Endpoint, .EndpointConfig, .Extension, .MessageHandler, .MessageHandler.Partial, .MessageHandler.Whole, .PongMessage, .RemoteEndpoint, .SendResult, .Session, .WebSocketContainer, jakarta.websocket.server.ServerEndpointConfig, .ServerEndpointConfig.Configurator, org.apache.juli.logging.Log, .LogFactory, org.apache.tomcat.InstanceManager, org.apache.tomcat.util.ExceptionUtils, org.apache.tomcat.util.res.StringManager, org.apache.tomcat.websocket.pojo.PojoEndpointServer, org.apache.tomcat.websocket.server.DefaultServerEndpointConfigurator

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static enum

Field Summary

Modifier and TypeField and Description
private final ClassLoader
private volatile MessageHandler
private static final byte[]
private static final int
private final EndpointConfig
private Map<FutureToSendHandler, FutureToSendHandler>
private final String
private final String
private static AtomicLong
private volatile long
private volatile long
private final Endpoint
private final Log
private volatile int
private volatile long
private volatile int
private final List<Extension>
private final Map<String, String>
private volatile MessageHandler.Whole<PongMessage>
private final String
private final RemoteEndpoint.Async
private final RemoteEndpoint.Basic
private final Map<String, List<String>>
private final URI
private static final boolean
private final boolean
private volatile Long
private static final StringManager
private AtomicReference<WsSession.State>
private final String
private volatile MessageHandler
private final Principal
private final Map<String, Object>
private final WsWebSocketContainer
private WsFrameBase
private final WsRemoteEndpointImplBase

Constructor Summary

AccessConstructor and Description
public
WsSession(ClientEndpointHolder
The end point managed by this code
clientEndpointHolder
,
WsRemoteEndpointImplBase
The other / remote end point
wsRemoteEndpoint
,
WsWebSocketContainer
The container that created this session
wsWebSocketContainer
,
List<Extension>
The agreed extensions to use for this session
negotiatedExtensions
,
String
The agreed sub-protocol to use for this session
subProtocol
,
Map<String, String>
The path parameters associated with the request that initiated this session or null if this is a client session
pathParameters
,
boolean
Was this session initiated over a secure connection?
secure
,
ClientEndpointConfig
The configuration information for the client end point
clientEndpointConfig
)

Creates a new WebSocket session for communication between the provided client and remote end points.

public
WsSession(WsRemoteEndpointImplBase
The other / remote end point
wsRemoteEndpoint
,
WsWebSocketContainer
The container that created this session
wsWebSocketContainer
,
URI
The URI used to connect to this end point or null if this is a client session
requestUri
,
Map<String, List<String>>
The parameters associated with the request that initiated this session or null if this is a client session
requestParameterMap
,
String
The query string associated with the request that initiated this session or null if this is a client session
queryString
,
Principal
The principal associated with the request that initiated this session or null if this is a client session
userPrincipal
,
String
The HTTP session ID associated with the request that initiated this session or null if this is a client session
httpSessionId
,
List<Extension>
The agreed extensions to use for this session
negotiatedExtensions
,
String
The agreed sub-protocol to use for this session
subProtocol
,
Map<String, String>
The path parameters associated with the request that initiated this session or null if this is a client session
pathParameters
,
boolean
Was this session initiated over a secure connection?
secure
,
ServerEndpointConfig
The configuration information for the server end point
serverEndpointConfig
)

Creates a new WebSocket session for communication between the provided server and remote end points.

Method Summary

Modifier and TypeMethod and Description
public void
addMessageHandler(MessageHandler
The message handler for a incoming message
listener
)

Implements jakarta.websocket.Session.addMessageHandler.

Registers a MessageHandler for incoming messages.

public <T> void
addMessageHandler(Class<T>
The Class that implements T
clazz
,
MessageHandler.Partial<T>
The message handler for a incoming message
handler
)

Implements jakarta.websocket.Session.addMessageHandler.

Registers a MessageHandler for partial incoming messages.

public <T> void
addMessageHandler(Class<T>
The Class that implements T
clazz
,
MessageHandler.Whole<T>
The message handler for a incoming message
handler
)

Implements jakarta.websocket.Session.addMessageHandler.

Registers a MessageHandler for whole incoming messages.

protected static void
appendCloseReasonWithTruncation(ByteBuffer
The message
msg
,
String
The reason
reason
)

Use protected so unit tests can access this method directly.

protected void
protected void
private void
public void
close()

Implements jakarta.websocket.Session.close.

Close the connection to the remote end point using the code jakarta.websocket.CloseReason.CloseCodes#NORMAL_CLOSURE and an empty reason phrase.

public void
close(CloseReason
The reason the WebSocket session is being closed.
closeReason
)

Implements jakarta.websocket.Session.close.

Close the connection to the remote end point using the specified code and reason phrase.

private void
private void
public void
doClose(CloseReason
The close reason to pass to the remote endpoint
closeReasonMessage
,
CloseReason
The close reason to pass to the local endpoint
closeReasonLocal
)

WebSocket 1.0.

public void
doClose(CloseReason
The close reason to pass to the remote endpoint
closeReasonMessage
,
CloseReason
The close reason to pass to the local endpoint
closeReasonLocal
,
boolean
Should the socket be closed immediately rather than waiting for the server to respond
closeSocket
)

WebSocket 1.0.

private void
private void
public RemoteEndpoint.Async
public RemoteEndpoint.Basic
protected MessageHandler
public WebSocketContainer
getContainer()

Implements jakarta.websocket.Session.getContainer.

Get the container that created this session.

public String
public String
getId()

Implements jakarta.websocket.Session.getId.

Provides a unique identifier for the session.

public InstanceManager
public Endpoint
public int
getMaxBinaryMessageBufferSize()

Implements jakarta.websocket.Session.getMaxBinaryMessageBufferSize.

Get the current maximum buffer size for binary messages.

public long
getMaxIdleTimeout()

Implements jakarta.websocket.Session.getMaxIdleTimeout.

Get the idle timeout for this session.

private long
private long
public int
getMaxTextMessageBufferSize()

Implements jakarta.websocket.Session.getMaxTextMessageBufferSize.

Get the maximum buffer size for text messages.

public Set<MessageHandler>
public List<Extension>
public String
public Set<Session>
getOpenSessions()

Implements jakarta.websocket.Session.getOpenSessions.

Obtain the set of open sessions associated with the same local endpoint as this session.

public Map<String, String>
protected MessageHandler.Whole<PongMessage>
public String
public String
public Map<String, List<String>>
public URI
protected long
private Object
protected MessageHandler
public Principal
public Principal
public Map<String, Object>
public boolean
private boolean
public boolean
public boolean
public void
onClose(CloseReason
The reason contained within the received close message.
closeReason
)

Called when a close message is received.

protected void
registerFuture(FutureToSendHandler
The handler
f2sh
)

Make the session aware of a FutureToSendHandler that will need to be forcibly closed if the session closes before the FutureToSendHandler completes.

public void
public void
resume()

Resumes the reading of the incoming messages.

private void
public void
setMaxBinaryMessageBufferSize(int
The new maximum buffer size in bytes
max
)

Implements jakarta.websocket.Session.setMaxBinaryMessageBufferSize.

Set the current maximum buffer size for binary messages.

public void
setMaxIdleTimeout(long
The new idle timeout for this session in milliseconds. Zero or negative values indicate an infinite timeout.
timeout
)

Implements jakarta.websocket.Session.setMaxIdleTimeout.

Set the idle timeout for this session.

public void
setMaxTextMessageBufferSize(int
The new maximum buffer size in characters.
max
)

Implements jakarta.websocket.Session.setMaxTextMessageBufferSize.

Set the maximum buffer size for text messages.

pack-priv void
public void
suspend()

Suspends the reading of the incoming messages.

protected void
unregisterFuture(FutureToSendHandler
The handler
f2sh
)

Remove a FutureToSendHandler from the set of tracked instances.

protected void
protected void
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait