public class TyrusSession extends java.lang.Object implements DistributedSession
Session
.Modifier and Type | Method and Description |
---|---|
<T> void |
addMessageHandler(java.lang.Class<T> clazz,
MessageHandler.Partial<T> handler)
Register to handle to incoming messages in this conversation.
|
<T> void |
addMessageHandler(java.lang.Class<T> clazz,
MessageHandler.Whole<T> handler)
Register to handle to incoming messages in this conversation.
|
void |
addMessageHandler(MessageHandler handler)
|
java.util.Map<Session,java.util.concurrent.Future<?>> |
broadcast(java.nio.ByteBuffer message)
Broadcasts binary message to all connected clients, including remote sessions (if any).
|
java.util.Map<Session,java.util.concurrent.Future<?>> |
broadcast(java.lang.String message)
Broadcasts text message to all connected clients.
|
void |
close()
Close the current conversation with a normal status code and no reason phrase.
|
void |
close(CloseReason closeReason)
Close the current conversation, giving a reason for the closure.
|
java.util.Set<DistributedSession> |
getAllSessions()
Get set of all sessions opened to the same endpoint.
|
RemoteEndpoint.Async |
getAsyncRemote()
Return a reference a RemoteEndpoint object representing the peer of this conversation that is able to send
messages asynchronously to the peer.
|
RemoteEndpoint.Basic |
getBasicRemote()
Return a reference a RemoteEndpoint object representing the peer of this conversation that is able to send
messages synchronously to the peer.
|
WebSocketContainer |
getContainer()
Return the container that this session is part of.
|
java.util.Map<java.lang.String,java.lang.Object> |
getDistributedProperties()
Get distributed properties.
|
long |
getHeartbeatInterval()
Return an interval in milliseconds between scheduled periodic Pong messages.
|
java.lang.String |
getId()
Returns a string containing the unique identifier assigned to this session.
|
int |
getMaxBinaryMessageBufferSize()
The maximum length of incoming binary messages that this Session can buffer.
|
long |
getMaxIdleTimeout()
Return the number of milliseconds before this conversation may be closed by the container if it is inactive, i.e.
|
int |
getMaxTextMessageBufferSize()
The maximum length of incoming text messages that this Session can buffer.
|
java.util.Set<MessageHandler> |
getMessageHandlers()
Return an unmodifiable copy of the set of MessageHandlers for this Session.
|
java.util.List<Extension> |
getNegotiatedExtensions()
Return the list of extensions currently in use for this conversation.
|
java.lang.String |
getNegotiatedSubprotocol()
Return the sub protocol agreed during the websocket handshake for this conversation.
|
java.util.Set<Session> |
getOpenSessions()
Return a copy of the Set of all the open web socket sessions that represent connections to the same endpoint to
which this session represents a connection.
|
java.util.Map<java.lang.String,java.lang.String> |
getPathParameters()
Return a map of the path parameter names and values used associated with the request this session was opened
under.
|
java.lang.String |
getProtocolVersion()
Returns the version of the websocket protocol currently being used.
|
java.lang.String |
getQueryString()
Return the query string associated with the request this session was opened under.
|
java.lang.String |
getRemoteAddr()
Get the Internet Protocol (IP) address of the client or last proxy that sent the request.
|
java.util.Set<RemoteSession> |
getRemoteSessions()
Get set of remote sessions.
|
java.util.Map<java.lang.String,java.util.List<java.lang.String>> |
getRequestParameterMap()
Return the request parameters associated with the request this session was opened under.
|
java.net.URI |
getRequestURI()
Return the URI under which this session was opened, including the query string if there is one.
|
java.security.Principal |
getUserPrincipal()
Return the authenticated user for this Session or
null if no user is authenticated for this session. |
java.util.Map<java.lang.String,java.lang.Object> |
getUserProperties()
While the session is open, this method returns a Map that the developer may use to store application specific
information relating to this session instance.
|
boolean |
isOpen()
Return true if and only if the underlying socket is open.
|
boolean |
isSecure()
Return true if and only if the underlying socket is using a secure transport.
|
void |
removeMessageHandler(MessageHandler handler)
Remove the given MessageHandler from the set belonging to this session.
|
void |
setHeartbeatInterval(long heartbeatInterval)
Set an interval in milliseconds between scheduled periodic Pong messages.
|
void |
setMaxBinaryMessageBufferSize(int maxBinaryMessageBufferSize)
Sets the maximum length of incoming binary messages that this Session can buffer.
|
void |
setMaxIdleTimeout(long maxIdleTimeout)
Set the non-zero number of milliseconds before this session will be closed by the container if it is inactive, ie
no messages are either sent or received.
|
void |
setMaxTextMessageBufferSize(int maxTextMessageBufferSize)
Sets the maximum length of incoming text messages that this Session can buffer.
|
java.lang.String |
toString() |
public java.lang.String getProtocolVersion()
Session
getProtocolVersion
in interface Session
public java.lang.String getNegotiatedSubprotocol()
Session
getNegotiatedSubprotocol
in interface Session
public RemoteEndpoint.Async getAsyncRemote()
Session
getAsyncRemote
in interface Session
public RemoteEndpoint.Basic getBasicRemote()
Session
getBasicRemote
in interface Session
public boolean isOpen()
Session
public void close() throws java.io.IOException
Session
public void close(CloseReason closeReason) throws java.io.IOException
Session
CloseReason.CloseCodes.NO_STATUS_CODE
.public int getMaxBinaryMessageBufferSize()
Session
CloseReason.CloseCodes.TOO_BIG
.getMaxBinaryMessageBufferSize
in interface Session
public void setMaxBinaryMessageBufferSize(int maxBinaryMessageBufferSize)
Session
setMaxBinaryMessageBufferSize
in interface Session
maxBinaryMessageBufferSize
- the maximum length.public int getMaxTextMessageBufferSize()
Session
CloseReason.CloseCodes.TOO_BIG
.getMaxTextMessageBufferSize
in interface Session
public void setMaxTextMessageBufferSize(int maxTextMessageBufferSize)
Session
setMaxTextMessageBufferSize
in interface Session
maxTextMessageBufferSize
- the maximum length.public java.util.Set<Session> getOpenSessions()
Session
getOpenSessions
in interface Session
public java.util.Set<RemoteSession> getRemoteSessions()
Remote sessions are websocket sessions which are bound to another node in the cluster.
public java.util.Set<DistributedSession> getAllSessions()
Set returned from this method contains all "local" and remote
sessions (if any).
RemoteSession
public java.util.List<Extension> getNegotiatedExtensions()
Session
getNegotiatedExtensions
in interface Session
public long getMaxIdleTimeout()
Session
getMaxIdleTimeout
in interface Session
public void setMaxIdleTimeout(long maxIdleTimeout)
Session
setMaxIdleTimeout
in interface Session
maxIdleTimeout
- the number of milliseconds.public boolean isSecure()
Session
public WebSocketContainer getContainer()
Session
getContainer
in interface Session
public void addMessageHandler(MessageHandler handler)
addMessageHandler(Class, jakarta.websocket.MessageHandler.Whole)
or addMessageHandler(Class, jakarta.websocket.MessageHandler.Partial)
MessageHandler.Whole
and MessageHandler.Partial
.
Adding more than one of any one type will result in a runtime exception.
This method is not safe to use unless you are providing an anonymous class derived directly from
MessageHandler.Whole
or MessageHandler.Partial
. In all other
cases (Lambda Expressions, more complex inheritance or generic type arrangements), one of the following methods
have to be used: Session.addMessageHandler(Class, jakarta.websocket.MessageHandler.Whole)
or
Session.addMessageHandler(Class, jakarta.websocket.MessageHandler.Partial)
.
addMessageHandler
in interface Session
handler
- the MessageHandler to be added.public <T> void addMessageHandler(java.lang.Class<T> clazz, MessageHandler.Whole<T> handler)
MessageHandler.Whole
and MessageHandler.Partial
.
Adding more than one of any one type will result in a runtime exception.
See Endpoint
for a usage example.
addMessageHandler
in interface Session
T
- type of message that the given handler is intended for.clazz
- type of the message processed by message handler to be registered.handler
- the MessageHandler to be added.java.lang.IllegalStateException
- if there is already a MessageHandler registered for the same native
websocket message type as this handler.public <T> void addMessageHandler(java.lang.Class<T> clazz, MessageHandler.Partial<T> handler)
MessageHandler.Whole
and MessageHandler.Partial
.
Adding more than one of any one type will result in a runtime exception.
See Endpoint
for a usage example.
addMessageHandler
in interface Session
T
- type of message that the given handler is intended for.clazz
- type of the message processed by message handler to be registered.handler
- the MessageHandler to be added.java.lang.IllegalStateException
- if there is already a MessageHandler registered for the same native
websocket message type as this handler.public java.util.Set<MessageHandler> getMessageHandlers()
Session
getMessageHandlers
in interface Session
public void removeMessageHandler(MessageHandler handler)
Session
removeMessageHandler
in interface Session
handler
- the handler to be removed.public java.net.URI getRequestURI()
Session
getRequestURI
in interface Session
public java.util.Map<java.lang.String,java.util.List<java.lang.String>> getRequestParameterMap()
Session
getRequestParameterMap
in interface Session
public java.util.Map<java.lang.String,java.lang.String> getPathParameters()
Session
getPathParameters
in interface Session
public java.util.Map<java.lang.String,java.lang.Object> getUserProperties()
Session
getUserProperties
in interface Session
public java.util.Map<java.lang.String,java.lang.Object> getDistributedProperties()
DistributedSession
Values put into this map must be Serializable
or serializable by other, implementation-dependent
alternative.
Content of this map is synchronized among all cluster nodes, so putting an entry on any of the nodes will be
visible on all other nodes which have reference to current session (in form of TyrusSession
or RemoteSession
).
Please note that when not running in the distributed environment, this map behaves similarly to Session.getUserProperties()
, so no serialization or deserialization is performed when values are read from or stored to
the returned map.
getDistributedProperties
in interface DistributedSession
TyrusSession
,
RemoteSession
public java.lang.String getQueryString()
Session
getQueryString
in interface Session
public java.lang.String getId()
Session
public java.security.Principal getUserPrincipal()
Session
null
if no user is authenticated for this session.getUserPrincipal
in interface Session
public java.util.Map<Session,java.util.concurrent.Future<?>> broadcast(java.lang.String message)
The broadcast can be executed in parallel, which can be enabled by setting
TyrusWebSocketEngine.PARALLEL_BROADCAST_ENABLED
to true
in server properties.
message
- message to be broadcasted.public java.util.Map<Session,java.util.concurrent.Future<?>> broadcast(java.nio.ByteBuffer message)
The broadcast can be executed in parallel, which can be enabled by setting
TyrusWebSocketEngine.PARALLEL_BROADCAST_ENABLED
to true
in server properties.
message
- message to be broadcasted.public long getHeartbeatInterval()
public void setHeartbeatInterval(long heartbeatInterval)
heartbeatInterval
- interval between periodic Pong messages in milliseconds.public java.lang.String toString()
toString
in class java.lang.Object
public java.lang.String getRemoteAddr()
String
containing the IP address of the client that sent the request or null
when
method is called on client-side.Copyright © 2012–2020 Oracle Corporation. All rights reserved.