Package org.glassfish.tyrus.core.cluster
Class RemoteSession
- java.lang.Object
-
- org.glassfish.tyrus.core.cluster.RemoteSession
-
- All Implemented Interfaces:
java.io.Closeable
,java.lang.AutoCloseable
,Session
,DistributedSession
public class RemoteSession extends java.lang.Object implements Session, DistributedSession
Remote session represents session originating from another node.- Author:
- Pavel Bucek (pavel.bucek at oracle.com)
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
RemoteSession.DistributedMapKey
-
Constructor Summary
Constructors Constructor Description RemoteSession(java.lang.String sessionId, ClusterContext clusterContext, java.util.Map<RemoteSession.DistributedMapKey,java.lang.Object> distributedPropertyMap, TyrusEndpointWrapper endpointWrapper, Session session)
Constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description <T> void
addMessageHandler(java.lang.Class<T> clazz, MessageHandler.Partial<T> handler)
This method is not supported onRemoteSession
.<T> void
addMessageHandler(java.lang.Class<T> clazz, MessageHandler.Whole<T> handler)
This method is not supported onRemoteSession
.void
addMessageHandler(MessageHandler handler)
This method is not supported onRemoteSession
.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.RemoteEndpoint.Async
getAsyncRemote()
Get a reference aRemoteEndpoint.Async
object representing the peer of this conversation that is able to send messages asynchronously to the peer.RemoteEndpoint.Basic
getBasicRemote()
Get a reference aRemoteEndpoint.Basic
object representing the peer of this conversation that is able to send messages synchronously to the peer.WebSocketContainer
getContainer()
This method is not supported onRemoteSession
.java.util.Map<java.lang.String,java.lang.Object>
getDistributedProperties()
Get distributed properties.java.lang.String
getId()
Get a string containing the unique identifier assigned to this session.int
getMaxBinaryMessageBufferSize()
Get the maximum length of incoming binary messages that this Session can buffer.long
getMaxIdleTimeout()
Get the number of milliseconds before this conversation may be closed by the container if it is inactive, i.e.int
getMaxTextMessageBufferSize()
Get the maximum length of incoming text messages that this Session can buffer.java.util.Set<MessageHandler>
getMessageHandlers()
This method is not supported onRemoteSession
.java.util.List<Extension>
getNegotiatedExtensions()
Get the list of extensions currently in use for this conversation.java.lang.String
getNegotiatedSubprotocol()
Get the sub protocol agreed during the websocket handshake for this conversation.java.util.Set<Session>
getOpenSessions()
This method is not supported onRemoteSession
.java.util.Map<java.lang.String,java.lang.String>
getPathParameters()
Get a map of the path parameter names and values used associated with the request this session was opened under.java.lang.String
getProtocolVersion()
Get the version of the websocket protocol currently being used.java.lang.String
getQueryString()
Get the query string associated with the request this session was opened under.java.util.Map<java.lang.String,java.util.List<java.lang.String>>
getRequestParameterMap()
Get the request parameters associated with the request this session was opened under.java.net.URI
getRequestURI()
Get theURI
under which this session was opened, including the query string if there is one.java.security.Principal
getUserPrincipal()
Get the authenticated user for this session ornull
if no user is authenticated for this session.java.util.Map<java.lang.String,java.lang.Object>
getUserProperties()
This method is not supported onRemoteSession
.boolean
isOpen()
Get the information about session state.boolean
isSecure()
Get the information about secure transport.void
removeMessageHandler(MessageHandler handler)
This method is not supported onRemoteSession
.void
setMaxBinaryMessageBufferSize(int length)
This method is not supported onRemoteSession
.void
setMaxIdleTimeout(long milliseconds)
This method is not supported onRemoteSession
.void
setMaxTextMessageBufferSize(int length)
This method is not supported onRemoteSession
.java.lang.String
toString()
-
-
-
Constructor Detail
-
RemoteSession
public RemoteSession(java.lang.String sessionId, ClusterContext clusterContext, java.util.Map<RemoteSession.DistributedMapKey,java.lang.Object> distributedPropertyMap, TyrusEndpointWrapper endpointWrapper, Session session)
Constructor.- Parameters:
sessionId
- session id.clusterContext
- cluster context.distributedPropertyMap
- distributed property map.endpointWrapper
- used just to get encoders/decoders.session
- used just to get encoders/decoders.
-
-
Method Detail
-
getProtocolVersion
public java.lang.String getProtocolVersion()
Get the version of the websocket protocol currently being used. This is taken as the value of the Sec-WebSocket-Version header used in the opening handshake. i.e. "13".- Specified by:
getProtocolVersion
in interfaceSession
- Returns:
- the protocol version.
-
getNegotiatedSubprotocol
public java.lang.String getNegotiatedSubprotocol()
Get the sub protocol agreed during the websocket handshake for this conversation.- Specified by:
getNegotiatedSubprotocol
in interfaceSession
- Returns:
- the negotiated subprotocol, or the empty string if there isn't one.
-
getNegotiatedExtensions
public java.util.List<Extension> getNegotiatedExtensions()
Get the list of extensions currently in use for this conversation.- Specified by:
getNegotiatedExtensions
in interfaceSession
- Returns:
- the negotiated extensions.
-
isSecure
public boolean isSecure()
Get the information about secure transport.
-
isOpen
public boolean isOpen()
Get the information about session state.
-
getMaxIdleTimeout
public long getMaxIdleTimeout()
Get the number of milliseconds before this conversation may be closed by the container if it is inactive, i.e. no messages are either sent or received in that time.- Specified by:
getMaxIdleTimeout
in interfaceSession
- Returns:
- the timeout in milliseconds.
-
getMaxBinaryMessageBufferSize
public int getMaxBinaryMessageBufferSize()
Get the maximum length of incoming binary messages that this Session can buffer. If the implementation receives a binary message that it cannot buffer because it is too large, it must close the session with a close code ofCloseReason.CloseCodes.TOO_BIG
.- Specified by:
getMaxBinaryMessageBufferSize
in interfaceSession
- Returns:
- the maximum binary message size that can be buffered.
-
getMaxTextMessageBufferSize
public int getMaxTextMessageBufferSize()
Get the maximum length of incoming text messages that this Session can buffer. If the implementation receives a text message that it cannot buffer because it is too large, it must close the session with a close code ofCloseReason.CloseCodes.TOO_BIG
.- Specified by:
getMaxTextMessageBufferSize
in interfaceSession
- Returns:
- the maximum text message size that can be buffered.
-
getAsyncRemote
public RemoteEndpoint.Async getAsyncRemote()
Get a reference aRemoteEndpoint.Async
object representing the peer of this conversation that is able to send messages asynchronously to the peer.- Specified by:
getAsyncRemote
in interfaceSession
- Returns:
- the remote endpoint representation.
-
getBasicRemote
public RemoteEndpoint.Basic getBasicRemote()
Get a reference aRemoteEndpoint.Basic
object representing the peer of this conversation that is able to send messages synchronously to the peer.- Specified by:
getBasicRemote
in interfaceSession
- Returns:
- the remote endpoint representation.
-
getId
public java.lang.String getId()
Get a string containing the unique identifier assigned to this session. The identifier is assigned by the web socket implementation and is implementation dependent.
-
close
public void close() throws java.io.IOException
Close the current conversation with a normal status code and no reason phrase.
-
close
public void close(CloseReason closeReason) throws java.io.IOException
Close the current conversation, giving a reason for the closure. The close call causes the implementation to attempt notify the client of the close as soon as it can. This may cause the sending of unsent messages immediately prior to the close notification. After the close notification has been sent the implementation notifies the endpoint's onClose method. Note the websocket specification defines the acceptable uses of status codes and reason phrases. If the application cannot determine a suitable close code to use for the closeReason, it is recommended to useCloseReason.CloseCodes.NO_STATUS_CODE
.
-
getRequestURI
public java.net.URI getRequestURI()
Get theURI
under which this session was opened, including the query string if there is one.- Specified by:
getRequestURI
in interfaceSession
- Returns:
- the request URI.
-
getRequestParameterMap
public java.util.Map<java.lang.String,java.util.List<java.lang.String>> getRequestParameterMap()
Get the request parameters associated with the request this session was opened under.- Specified by:
getRequestParameterMap
in interfaceSession
- Returns:
- the unmodifiable map of the request parameters.
-
getQueryString
public java.lang.String getQueryString()
Get the query string associated with the request this session was opened under.- Specified by:
getQueryString
in interfaceSession
- Returns:
- the query string.
-
getPathParameters
public java.util.Map<java.lang.String,java.lang.String> getPathParameters()
Get a map of the path parameter names and values used associated with the request this session was opened under.- Specified by:
getPathParameters
in interfaceSession
- Returns:
- the unmodifiable map of path parameters. The key of the map is the parameter name, the values in the map are the parameter values.
-
getUserProperties
public java.util.Map<java.lang.String,java.lang.Object> getUserProperties()
This method is not supported onRemoteSession
. Each invocation will throw anUnsupportedOperationException
.- Specified by:
getUserProperties
in interfaceSession
- Returns:
- nothing.
- See Also:
getDistributedProperties()
-
getDistributedProperties
public java.util.Map<java.lang.String,java.lang.Object> getDistributedProperties()
Description copied from interface:DistributedSession
Get distributed properties.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
orRemoteSession
).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.- Specified by:
getDistributedProperties
in interfaceDistributedSession
- Returns:
- map of distributed properties.
- See Also:
TyrusSession
,RemoteSession
-
getUserPrincipal
public java.security.Principal getUserPrincipal()
Get the authenticated user for this session ornull
if no user is authenticated for this session.- Specified by:
getUserPrincipal
in interfaceSession
- Returns:
- the user principal.
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
getContainer
public WebSocketContainer getContainer()
This method is not supported onRemoteSession
. Each invocation will throw anUnsupportedOperationException
.- Specified by:
getContainer
in interfaceSession
- Returns:
- nothing.
-
addMessageHandler
public void addMessageHandler(MessageHandler handler) throws java.lang.IllegalStateException
This method is not supported onRemoteSession
. Each invocation will throw anUnsupportedOperationException
.- Specified by:
addMessageHandler
in interfaceSession
- Parameters:
handler
- nothing.- Throws:
java.lang.IllegalStateException
- if there is already a MessageHandler registered for the same native websocket message type as this handler.
-
addMessageHandler
public <T> void addMessageHandler(java.lang.Class<T> clazz, MessageHandler.Whole<T> handler)
This method is not supported onRemoteSession
. Each invocation will throw anUnsupportedOperationException
.- Specified by:
addMessageHandler
in interfaceSession
- Type Parameters:
T
- type of message that the given handler is intended for.- Parameters:
clazz
- nothing.handler
- nothing.
-
addMessageHandler
public <T> void addMessageHandler(java.lang.Class<T> clazz, MessageHandler.Partial<T> handler)
This method is not supported onRemoteSession
. Each invocation will throw anUnsupportedOperationException
.- Specified by:
addMessageHandler
in interfaceSession
- Type Parameters:
T
- type of message that the given handler is intended for.- Parameters:
clazz
- nothing.handler
- nothing.
-
getMessageHandlers
public java.util.Set<MessageHandler> getMessageHandlers()
This method is not supported onRemoteSession
. Each invocation will throw anUnsupportedOperationException
.- Specified by:
getMessageHandlers
in interfaceSession
- Returns:
- nothing.
-
removeMessageHandler
public void removeMessageHandler(MessageHandler handler)
This method is not supported onRemoteSession
. Each invocation will throw anUnsupportedOperationException
.- Specified by:
removeMessageHandler
in interfaceSession
- Parameters:
handler
- nothing.
-
setMaxIdleTimeout
public void setMaxIdleTimeout(long milliseconds)
This method is not supported onRemoteSession
. Each invocation will throw anUnsupportedOperationException
.- Specified by:
setMaxIdleTimeout
in interfaceSession
- Parameters:
milliseconds
- nothing.
-
setMaxBinaryMessageBufferSize
public void setMaxBinaryMessageBufferSize(int length)
This method is not supported onRemoteSession
. Each invocation will throw anUnsupportedOperationException
.- Specified by:
setMaxBinaryMessageBufferSize
in interfaceSession
- Parameters:
length
- nothing.
-
setMaxTextMessageBufferSize
public void setMaxTextMessageBufferSize(int length)
This method is not supported onRemoteSession
. Each invocation will throw anUnsupportedOperationException
.- Specified by:
setMaxTextMessageBufferSize
in interfaceSession
- Parameters:
length
- nothing.
-
getOpenSessions
public java.util.Set<Session> getOpenSessions()
This method is not supported onRemoteSession
. Each invocation will throw anUnsupportedOperationException
.- Specified by:
getOpenSessions
in interfaceSession
- Returns:
- nothing.
-
-