Class RemoteSession

  • All Implemented Interfaces:
    Session, java.io.Closeable, java.lang.AutoCloseable, DistributedSession

    public class RemoteSession
    extends java.lang.Object
    implements Session, DistributedSession
    Remote session represents session originating from another node.
    Author:
    Pavel Bucek
    • 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 interface Session
        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 interface Session
        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 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 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.
        Specified by:
        getId in interface Session
        Returns:
        the unique identifier for this session instance.
      • close

        public void close()
                   throws java.io.IOException
        Close the current conversation with a normal status code and no reason phrase.
        Specified by:
        close in interface java.lang.AutoCloseable
        Specified by:
        close in interface java.io.Closeable
        Specified by:
        close in interface Session
        Throws:
        java.io.IOException - if there was a connection error closing the connection.
      • 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 use CloseReason.CloseCodes.NO_STATUS_CODE.
        Specified by:
        close in interface Session
        Parameters:
        closeReason - the reason for the closure.
        Throws:
        java.io.IOException - if there was a connection error closing the connection.
      • getRequestURI

        public java.net.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 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 interface Session
        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 interface Session
        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 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 java.util.Map<java.lang.String,​java.lang.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()
      • 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 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:
        TyrusSession, RemoteSession
      • getUserPrincipal

        public java.security.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 java.lang.String toString()
        Overrides:
        toString in class java.lang.Object
      • addMessageHandler

        public void addMessageHandler​(MessageHandler handler)
                               throws java.lang.IllegalStateException
        This method is not supported on RemoteSession. Each invocation will throw an UnsupportedOperationException.
        Specified by:
        addMessageHandler in interface Session
        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 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​(java.lang.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 java.util.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 java.util.Set<Session> getOpenSessions()
        This method is not supported on RemoteSession. Each invocation will throw an UnsupportedOperationException.
        Specified by:
        getOpenSessions in interface Session
        Returns:
        nothing.