Class ClusterContext


  • public abstract class ClusterContext
    extends java.lang.Object
    Cluster related context.

    There is exactly one instance per cluster node and all communication is realized using this instance.

    Author:
    Pavel Bucek (pavel.bucek at oracle.com)
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static java.lang.String CLUSTER_CONTEXT
      ClusterContext registration property.
    • Constructor Summary

      Constructors 
      Constructor Description
      ClusterContext()  
    • Method Summary

      All Methods Instance Methods Abstract Methods 
      Modifier and Type Method Description
      abstract void broadcastBinary​(java.lang.String endpointPath, byte[] data)
      Broadcast binary message.
      abstract void broadcastText​(java.lang.String endpointPath, java.lang.String text)
      Broadcast text message.
      abstract java.util.concurrent.Future<java.lang.Void> close​(java.lang.String sessionId)
      Close remote session.
      abstract java.util.concurrent.Future<java.lang.Void> close​(java.lang.String sessionId, CloseReason closeReason)
      Close remote session with custom CloseReason.
      abstract java.lang.String createConnectionId()
      Create connection id.
      abstract java.lang.String createSessionId()
      Create session id.
      abstract void destroyDistributedUserProperties​(java.lang.String connectionId)
      Destroy map which holds distributed user properties.
      abstract java.util.Map<RemoteSession.DistributedMapKey,​java.lang.Object> getDistributedSessionProperties​(java.lang.String sessionId)
      Get the map containing session properties to be shared among nodes.
      abstract java.util.Map<java.lang.String,​java.lang.Object> getDistributedUserProperties​(java.lang.String connectionId)
      Get the map containing session user properties to be shared among nodes.
      abstract java.util.Set<java.lang.String> getRemoteSessionIds​(java.lang.String endpointPath)
      Get set containing session ids of all remote sessions registered to given endpoint path.
      abstract boolean isSessionOpen​(java.lang.String sessionId, java.lang.String endpointPath)
      Get information about session state.
      abstract void registerBroadcastListener​(java.lang.String endpointPath, BroadcastListener listener)
      Register broadcast listener.
      abstract void registerSession​(java.lang.String sessionId, java.lang.String endpointPath, SessionEventListener listener)
      Register local session.
      abstract void registerSessionListener​(java.lang.String endpointPath, SessionListener listener)
      Register session listener.
      abstract void removeSession​(java.lang.String sessionId, java.lang.String endpointPath)
      Remove session from this Cluster context.
      abstract java.util.concurrent.Future<java.lang.Void> sendBinary​(java.lang.String sessionId, byte[] data)
      Send binary message.
      abstract java.util.concurrent.Future<java.lang.Void> sendBinary​(java.lang.String sessionId, byte[] data, boolean isLast)
      Send partial binary message.
      abstract void sendBinary​(java.lang.String sessionId, byte[] data, SendHandler sendHandler)
      Send binary message with SendHandler.
      abstract java.util.concurrent.Future<java.lang.Void> sendPing​(java.lang.String sessionId, byte[] data)
      Send ping message.
      abstract java.util.concurrent.Future<java.lang.Void> sendPong​(java.lang.String sessionId, byte[] data)
      Send pong message.
      abstract java.util.concurrent.Future<java.lang.Void> sendText​(java.lang.String sessionId, java.lang.String text)
      Send text message.
      abstract java.util.concurrent.Future<java.lang.Void> sendText​(java.lang.String sessionId, java.lang.String text, boolean isLast)
      Send partial text message.
      abstract void sendText​(java.lang.String sessionId, java.lang.String text, SendHandler sendHandler)
      Send text message with SendHandler.
      abstract void shutdown()
      Shutdown this ClusterContext.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • ClusterContext

        public ClusterContext()
    • Method Detail

      • sendText

        public abstract java.util.concurrent.Future<java.lang.Void> sendText​(java.lang.String sessionId,
                                                                             java.lang.String text)
        Send text message.
        Parameters:
        sessionId - remote session id.
        text - text to be sent.
        Returns:
        future representing the send event. Future.get() returns when there is an acknowledge from the other node that the message has been successfully sent. If there is any exception, it will be wrapped into ExecutionException and thrown.
      • sendText

        public abstract java.util.concurrent.Future<java.lang.Void> sendText​(java.lang.String sessionId,
                                                                             java.lang.String text,
                                                                             boolean isLast)
        Send partial text message.
        Parameters:
        sessionId - remote session id.
        text - text to be sent.
        isLast - true when the partial message being sent is the last part of the message.
        Returns:
        future representing the send event. Future.get() returns when there is an acknowledge from the other node that the message has been successfully sent. If there is any exception, it will be wrapped into ExecutionException and thrown.
      • sendBinary

        public abstract java.util.concurrent.Future<java.lang.Void> sendBinary​(java.lang.String sessionId,
                                                                               byte[] data)
        Send binary message.
        Parameters:
        sessionId - remote session id.
        data - data to be sent.
        Returns:
        future representing the send event. Future.get() returns when there is an acknowledge from the other node that the message has been successfully sent. If there is any exception, it will be wrapped into ExecutionException and thrown.
      • sendBinary

        public abstract java.util.concurrent.Future<java.lang.Void> sendBinary​(java.lang.String sessionId,
                                                                               byte[] data,
                                                                               boolean isLast)
        Send partial binary message.
        Parameters:
        sessionId - remote session id.
        data - data to be sent.
        isLast - true when the partial message being sent is the last part of the message.
        Returns:
        future representing the send event. Future.get() returns when there is an acknowledge from the other node that the message has been successfully sent. If there is any exception, it will be wrapped into ExecutionException and thrown.
      • sendPing

        public abstract java.util.concurrent.Future<java.lang.Void> sendPing​(java.lang.String sessionId,
                                                                             byte[] data)
        Send ping message.
        Parameters:
        sessionId - remote session id.
        data - data to be sent as ping message payload.
        Returns:
        future representing the send event. Future.get() returns when there is an acknowledge from the other node that the message has been successfully sent. If there is any exception, it will be wrapped into ExecutionException and thrown.
      • sendPong

        public abstract java.util.concurrent.Future<java.lang.Void> sendPong​(java.lang.String sessionId,
                                                                             byte[] data)
        Send pong message.
        Parameters:
        sessionId - remote session id.
        data - data to be sent as pong message payload.
        Returns:
        future representing the send event. Future.get() returns when there is an acknowledge from the other node that the message has been successfully sent. If there is any exception, it will be wrapped into ExecutionException and thrown.
      • broadcastText

        public abstract void broadcastText​(java.lang.String endpointPath,
                                           java.lang.String text)
        Broadcast text message.
        Parameters:
        endpointPath - endpoint path identifying sessions alignment to the endpoint.
        text - message to be broadcasted.
      • broadcastBinary

        public abstract void broadcastBinary​(java.lang.String endpointPath,
                                             byte[] data)
        Broadcast binary message.
        Parameters:
        endpointPath - endpoint path identifying sessions alignment to the endpoint.
        data - data to be broadcasted.
      • isSessionOpen

        public abstract boolean isSessionOpen​(java.lang.String sessionId,
                                              java.lang.String endpointPath)
        Get information about session state.
        Parameters:
        sessionId - remote session id.
        endpointPath - endpoint path identifying sessions alignment to the endpoint.
        Returns:
        true when session is opened, false otherwise.
        See Also:
        Session.isOpen()
      • close

        public abstract java.util.concurrent.Future<java.lang.Void> close​(java.lang.String sessionId)
        Close remote session.
        Parameters:
        sessionId - remote session id.
        Returns:
        future representing the event. Future.get() returns when there is an acknowledge from the other node that the command was successfully executed. If there is any exception, it will be wrapped into ExecutionException and thrown.
      • close

        public abstract java.util.concurrent.Future<java.lang.Void> close​(java.lang.String sessionId,
                                                                          CloseReason closeReason)
        Close remote session with custom CloseReason.
        Parameters:
        sessionId - remote session id.
        closeReason - custom close reason.
        Returns:
        future representing the event. Future.get() returns when there is an acknowledge from the other node that the command was successfully executed. If there is any exception, it will be wrapped into ExecutionException and thrown.
      • getRemoteSessionIds

        public abstract java.util.Set<java.lang.String> getRemoteSessionIds​(java.lang.String endpointPath)
        Get set containing session ids of all remote sessions registered to given endpoint path.
        Parameters:
        endpointPath - endpoint path identifying endpoint within the cluster.
        Returns:
        set of sessions ids.
      • createSessionId

        public abstract java.lang.String createSessionId()
        Create session id. It has to be unique among all cluster nodes.
        Returns:
        session id.
      • createConnectionId

        public abstract java.lang.String createConnectionId()
        Create connection id. It has to be unique among all cluster nodes.
        Returns:
        connection id.
      • registerSession

        public abstract void registerSession​(java.lang.String sessionId,
                                             java.lang.String endpointPath,
                                             SessionEventListener listener)
        Register local session.

        Session id will be broadcasted to other nodes which will call getDistributedSessionProperties(String) and process its values. The map must be ready before this method is invoked.

        Parameters:
        sessionId - session id to be registered.
        endpointPath - endpoint path identifying sessions alignment to the endpoint.
        listener - session event listener. When remote node sends a message to this session, it will be invoked.
        See Also:
        SessionEventListener
      • registerBroadcastListener

        public abstract void registerBroadcastListener​(java.lang.String endpointPath,
                                                       BroadcastListener listener)
        Register broadcast listener.

        Gets notification about broadcasted messages. Used as an optimized variant of standard websocket broadcast pattern. In this case, only one message is sent to all cluster nodes (instead n when n represent number of clients connected to remote nodes).

        Parameters:
        endpointPath - endpoint path identifying sessions alignment to the endpoint.
        listener - listener instance.
        See Also:
        BroadcastListener
      • getDistributedSessionProperties

        public abstract java.util.Map<RemoteSession.DistributedMapKey,​java.lang.Object> getDistributedSessionProperties​(java.lang.String sessionId)
        Get the map containing session properties to be shared among nodes.

        Changes must be propagated to remote instances.

        Parameters:
        sessionId - remote session id.
        Returns:
        distributed map containing session properties.
      • getDistributedUserProperties

        public abstract java.util.Map<java.lang.String,​java.lang.Object> getDistributedUserProperties​(java.lang.String connectionId)
        Get the map containing session user properties to be shared among nodes.

        Changes must be propagated to remote instances.

        Parameters:
        connectionId - connection id. Connection id may be shared among subsequent TCP connection - represents logical connection.
        Returns:
        distributed map containing session properties.
      • destroyDistributedUserProperties

        public abstract void destroyDistributedUserProperties​(java.lang.String connectionId)
        Destroy map which holds distributed user properties.

        This method should be invoked only when session is properly closed.

        Parameters:
        connectionId - connection id. Connection id may be shared among subsequent TCP connection - represents logical connection.
      • removeSession

        public abstract void removeSession​(java.lang.String sessionId,
                                           java.lang.String endpointPath)
        Remove session from this Cluster context.
        Parameters:
        sessionId - session id.
        endpointPath - endpoint path identifying sessions alignment to the endpoint.
      • shutdown

        public abstract void shutdown()
        Shutdown this ClusterContext.

        This will stop whole clustered node, any operation related to this cluster context will fail after this method is invoked.