Top Methods
jakarta.websocket

public Interface Session

extends Closeable
Known Direct Implementers
org.apache.tomcat.websocket.WsSession
Imports
java.io.Closeable, .IOException, java.net.URI, java.security.Principal, java.util.List, .Map, .Set

Method Summary

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

Registers a MessageHandler for incoming messages.

public <
The type of message that the given handler is intended for
T
>
void
addMessageHandler(Class<T>
The Class that implements T
clazz
,
MessageHandler.Partial<T>
The message handler for a incoming message
handler
)

Registers a MessageHandler for partial incoming messages.

public <
The type of message that the given handler is intended for
T
>
void
addMessageHandler(Class<T>
The Class that implements T
clazz
,
MessageHandler.Whole<T>
The message handler for a incoming message
handler
)

Registers a MessageHandler for whole incoming messages.

public void
close()

Redeclares java.io.Closeable.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
)

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

public RemoteEndpoint.Async
public RemoteEndpoint.Basic
public WebSocketContainer

Returns:

the container that created this session.
getContainer
()

Get the container that created this session.

public String

Returns:

A unique identifier for the session.
getId
()

Provides a unique identifier for the session.

public int

Returns:

The current maximum buffer size in bytes
getMaxBinaryMessageBufferSize
()

Get the current maximum buffer size for binary messages.

public long

Returns:

The current idle timeout for this session in milliseconds. Zero or negative values indicate an infinite timeout.
getMaxIdleTimeout
()

Get the idle timeout for this session.

public int

Returns:

The maximum buffer size in characters.
getMaxTextMessageBufferSize
()

Get the maximum buffer size for text messages.

public Set<MessageHandler>
public List<Extension>
public String
public Set<Session>

Returns:

The set of currently open sessions for the local endpoint that this session is associated with.
getOpenSessions
()

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

public Map<String, String>
public String
public String
public Map<String, List<String>>
public URI
public Principal
public Map<String, Object>
public boolean
public boolean
public void
public void
setMaxBinaryMessageBufferSize(int
The new maximum buffer size in bytes
max
)

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
)

Set the idle timeout for this session.

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

Set the maximum buffer size for text messages.

Method Detail

addMessageHandlerback to summary
public void addMessageHandler(MessageHandler handler) throws IllegalStateException

Registers a MessageHandler for incoming messages. Only one MessageHandler may be registered for each message type (text, binary, pong). The message type will be derived at runtime from the provided MessageHandler instance. It is not always possible to do this so it is better to use addMessageHandler(Class, jakarta.websocket.MessageHandler.Partial) or addMessageHandler(Class, jakarta.websocket.MessageHandler.Whole).

Parameters
handler:MessageHandler

The message handler for a incoming message

Exceptions
IllegalStateException:
If a message handler has already been registered for the associated message type
addMessageHandlerback to summary
public <T> void addMessageHandler(Class<T> clazz, MessageHandler.Partial<T> handler) throws IllegalStateException

Registers a MessageHandler for partial incoming messages. Only one MessageHandler may be registered for each message type (text or binary, pong messages are never presented as partial messages).

Parameters
<T>
The type of message that the given handler is intended for
clazz:Class<T>

The Class that implements T

handler:MessageHandler.Partial<T>

The message handler for a incoming message

Exceptions
IllegalStateException:
If a message handler has already been registered for the associated message type
Since
WebSocket 1.1
addMessageHandlerback to summary
public <T> void addMessageHandler(Class<T> clazz, MessageHandler.Whole<T> handler) throws IllegalStateException

Registers a MessageHandler for whole incoming messages. Only one MessageHandler may be registered for each message type (text, binary, pong).

Parameters
<T>
The type of message that the given handler is intended for
clazz:Class<T>

The Class that implements T

handler:MessageHandler.Whole<T>

The message handler for a incoming message

Exceptions
IllegalStateException:
If a message handler has already been registered for the associated message type
Since
WebSocket 1.1
closeback to summary
public void close() throws IOException

Redeclares java.io.Closeable.close.

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

Annotations
@Override
Exceptions
IOException:
if an I/O error occurs while the WebSocket session is being closed.
closeback to summary
public void close(CloseReason closeReason) throws IOException

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

Parameters
closeReason:CloseReason

The reason the WebSocket session is being closed.

Exceptions
IOException:
if an I/O error occurs while the WebSocket session is being closed.
getAsyncRemoteback to summary
public RemoteEndpoint.Async getAsyncRemote()
getBasicRemoteback to summary
public RemoteEndpoint.Basic getBasicRemote()
getContainerback to summary
public WebSocketContainer getContainer()

Get the container that created this session.

Returns:WebSocketContainer

the container that created this session.

getIdback to summary
public String getId()

Provides a unique identifier for the session. This identifier should not be relied upon to be generated from a secure random source.

Returns:String

A unique identifier for the session.

getMaxBinaryMessageBufferSizeback to summary
public int getMaxBinaryMessageBufferSize()

Get the current maximum buffer size for binary messages.

Returns:int

The current maximum buffer size in bytes

getMaxIdleTimeoutback to summary
public long getMaxIdleTimeout()

Get the idle timeout for this session.

Returns:long

The current idle timeout for this session in milliseconds. Zero or negative values indicate an infinite timeout.

getMaxTextMessageBufferSizeback to summary
public int getMaxTextMessageBufferSize()

Get the maximum buffer size for text messages.

Returns:int

The maximum buffer size in characters.

getMessageHandlersback to summary
public Set<MessageHandler> getMessageHandlers()
getNegotiatedExtensionsback to summary
public List<Extension> getNegotiatedExtensions()
getNegotiatedSubprotocolback to summary
public String getNegotiatedSubprotocol()
getOpenSessionsback to summary
public Set<Session> getOpenSessions()

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

Returns:Set<Session>

The set of currently open sessions for the local endpoint that this session is associated with.

getPathParametersback to summary
public Map<String, String> getPathParameters()
getProtocolVersionback to summary
public String getProtocolVersion()
getQueryStringback to summary
public String getQueryString()
getRequestParameterMapback to summary
public Map<String, List<String>> getRequestParameterMap()
getRequestURIback to summary
public URI getRequestURI()
getUserPrincipalback to summary
public Principal getUserPrincipal()
getUserPropertiesback to summary
public Map<String, Object> getUserProperties()
isOpenback to summary
public boolean isOpen()
isSecureback to summary
public boolean isSecure()
removeMessageHandlerback to summary
public void removeMessageHandler(MessageHandler listener)
setMaxBinaryMessageBufferSizeback to summary
public void setMaxBinaryMessageBufferSize(int max)

Set the current maximum buffer size for binary messages.

Parameters
max:int

The new maximum buffer size in bytes

setMaxIdleTimeoutback to summary
public void setMaxIdleTimeout(long timeout)

Set the idle timeout for this session.

Parameters
timeout:long

The new idle timeout for this session in milliseconds. Zero or negative values indicate an infinite timeout.

setMaxTextMessageBufferSizeback to summary
public void setMaxTextMessageBufferSize(int max)

Set the maximum buffer size for text messages.

Parameters
max:int

The new maximum buffer size in characters.