Class RemoteSession

java.lang.Object
org.glassfish.tyrus.core.cluster.RemoteSession
All Implemented Interfaces:
Session, Closeable, AutoCloseable, DistributedSession

public class RemoteSession extends Object implements Session, DistributedSession
Remote session represents session originating from another node.
Author:
Pavel Bucek
  • Constructor Details

    • RemoteSession

      public RemoteSession(String sessionId, ClusterContext clusterContext, Map<RemoteSession.DistributedMapKey,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 Details

    • getProtocolVersion

      public 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 interface Session
      Returns:
      the protocol version.
    • getNegotiatedSubprotocol

      public String getNegotiatedSubprotocol()
      Get the sub protocol agreed during the websocket handshake for this conversation.
      Specified by:
      getNegotiatedSubprotocol in interface Session
      Returns:
      the negotiated subprotocol, or the empty string if there isn't one.
    • getNegotiatedExtensions

      public List<Extension> getNegotiatedExtensions()
      Get the list of extensions currently in use for this conversation.
      Specified by:
      getNegotiatedExtensions in interface Session
      Returns:
      the negotiated extensions.
    • isSecure

      public boolean isSecure()
      Get the information about secure transport.
      Specified by:
      isSecure in interface Session
      Returns:
      true when the underlying socket is using a secure transport, false otherwise.
    • isOpen

      public boolean isOpen()
      Get the information about session state.
      Specified by:
      isOpen in interface Session
      Returns:
      true when the underlying socket is open, false otherwise.
    • 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 interface Session
      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 of CloseReason.CloseCodes.TOO_BIG.
      Specified by:
      getMaxBinaryMessageBufferSize in interface Session
      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 of CloseReason.CloseCodes.TOO_BIG.
      Specified by:
      getMaxTextMessageBufferSize in interface Session
      Returns:
      the maximum text message size that can be buffered.
    • getAsyncRemote

      public RemoteEndpoint.Async getAsyncRemote()
      Get a reference a RemoteEndpoint.Async object representing the peer of this conversation that is able to send messages asynchronously to the peer.
      Specified by:
      getAsyncRemote in interface Session
      Returns:
      the remote endpoint representation.
    • getBasicRemote

      public RemoteEndpoint.Basic getBasicRemote()
      Get a reference a RemoteEndpoint.Basic object representing the peer of this conversation that is able to send messages synchronously to the peer.
      Specified by:
      getBasicRemote in interface Session
      Returns:
      the remote endpoint representation.
    • getId

      public 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.
      Specified by:
      getId in interface Session
      Returns:
      the unique identifier for this session instance.
    • close

      public void close() throws IOException
      Close the current conversation with a normal status code and no reason phrase.
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
      Specified by:
      close in interface Session
      Throws:
      IOException - if there was a connection error closing the connection.
    • close

      public void close(CloseReason closeReason) throws 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 use CloseReason.CloseCodes.NO_STATUS_CODE.
      Specified by:
      close in interface Session
      Parameters:
      closeReason - the reason for the closure.
      Throws:
      IOException - if there was a connection error closing the connection.
    • getRequestURI

      public URI getRequestURI()
      Get the URI under which this session was opened, including the query string if there is one.
      Specified by:
      getRequestURI in interface Session
      Returns:
      the request URI.
    • getRequestParameterMap

      public Map<String,List<String>> getRequestParameterMap()
      Get the request parameters associated with the request this session was opened under.
      Specified by:
      getRequestParameterMap in interface Session
      Returns:
      the unmodifiable map of the request parameters.
    • getQueryString

      public String getQueryString()
      Get the query string associated with the request this session was opened under.
      Specified by:
      getQueryString in interface Session
      Returns:
      the query string.
    • getPathParameters

      public Map<String,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 interface Session
      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 Map<String,Object> getUserProperties()
      This method is not supported on RemoteSession. Each invocation will throw an UnsupportedOperationException.
      Specified by:
      getUserProperties in interface Session
      Returns:
      nothing.
      See Also:
    • getDistributedProperties

      public Map<String,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 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.

      Specified by:
      getDistributedProperties in interface DistributedSession
      Returns:
      map of distributed properties.
      See Also:
    • getUserPrincipal

      public Principal getUserPrincipal()
      Get the authenticated user for this session or null if no user is authenticated for this session.
      Specified by:
      getUserPrincipal in interface Session
      Returns:
      the user principal.
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • getContainer

      public WebSocketContainer getContainer()
      This method is not supported on RemoteSession. Each invocation will throw an UnsupportedOperationException.
      Specified by:
      getContainer in interface Session
      Returns:
      nothing.
    • addMessageHandler

      public void addMessageHandler(MessageHandler handler) throws IllegalStateException
      This method is not supported on RemoteSession. Each invocation will throw an UnsupportedOperationException.
      Specified by:
      addMessageHandler in interface Session
      Parameters:
      handler - nothing.
      Throws:
      IllegalStateException - if there is already a MessageHandler registered for the same native websocket message type as this handler.
    • addMessageHandler

      public <T> void addMessageHandler(Class<T> clazz, MessageHandler.Whole<T> handler)
      This method is not supported on RemoteSession. Each invocation will throw an UnsupportedOperationException.
      Specified by:
      addMessageHandler in interface Session
      Type Parameters:
      T - type of message that the given handler is intended for.
      Parameters:
      clazz - nothing.
      handler - nothing.
    • addMessageHandler

      public <T> void addMessageHandler(Class<T> clazz, MessageHandler.Partial<T> handler)
      This method is not supported on RemoteSession. Each invocation will throw an UnsupportedOperationException.
      Specified by:
      addMessageHandler in interface Session
      Type Parameters:
      T - type of message that the given handler is intended for.
      Parameters:
      clazz - nothing.
      handler - nothing.
    • getMessageHandlers

      public Set<MessageHandler> getMessageHandlers()
      This method is not supported on RemoteSession. Each invocation will throw an UnsupportedOperationException.
      Specified by:
      getMessageHandlers in interface Session
      Returns:
      nothing.
    • removeMessageHandler

      public void removeMessageHandler(MessageHandler handler)
      This method is not supported on RemoteSession. Each invocation will throw an UnsupportedOperationException.
      Specified by:
      removeMessageHandler in interface Session
      Parameters:
      handler - nothing.
    • setMaxIdleTimeout

      public void setMaxIdleTimeout(long milliseconds)
      This method is not supported on RemoteSession. Each invocation will throw an UnsupportedOperationException.
      Specified by:
      setMaxIdleTimeout in interface Session
      Parameters:
      milliseconds - nothing.
    • setMaxBinaryMessageBufferSize

      public void setMaxBinaryMessageBufferSize(int length)
      This method is not supported on RemoteSession. Each invocation will throw an UnsupportedOperationException.
      Specified by:
      setMaxBinaryMessageBufferSize in interface Session
      Parameters:
      length - nothing.
    • setMaxTextMessageBufferSize

      public void setMaxTextMessageBufferSize(int length)
      This method is not supported on RemoteSession. Each invocation will throw an UnsupportedOperationException.
      Specified by:
      setMaxTextMessageBufferSize in interface Session
      Parameters:
      length - nothing.
    • getOpenSessions

      public Set<Session> getOpenSessions()
      This method is not supported on RemoteSession. Each invocation will throw an UnsupportedOperationException.
      Specified by:
      getOpenSessions in interface Session
      Returns:
      nothing.