Class DeltaManager

  • All Implemented Interfaces:
    MBeanRegistration, ClusterManager, JmxEnabled, Lifecycle, Manager

    public class DeltaManager
    extends ClusterManagerBase
    The DeltaManager manages replicated sessions by only replicating the deltas in data. For applications written to handle this, the DeltaManager is the optimal way of replicating data. This code is almost identical to StandardManager with a difference in how it persists sessions and some modifications to it. IMPLEMENTATION NOTE : Correct behavior of session storing and reloading depends upon external calls to the start() and stop() methods of this class at the correct times.
    Author:
    Craig R. McClanahan, Peter Rossbach
    • Field Detail

      • log

        public final Log log
      • sm

        protected static final StringManager sm
        The string manager for this package.
    • Constructor Detail

      • DeltaManager

        public DeltaManager()
    • Method Detail

      • setName

        public void setName​(String name)
        Description copied from interface: ClusterManager
        Set the name of the manager, at host /context name and at engine hostname+/context
        Parameters:
        name - The manager name
      • getName

        public String getName()
        Description copied from interface: ClusterManager
        Return the name of the manager, at host /context name and at engine hostname+/context.
        Specified by:
        getName in interface ClusterManager
        Overrides:
        getName in class ManagerBase
        Returns:
        The descriptive short name of this Manager implementation.
      • getCounterSend_EVT_GET_ALL_SESSIONS

        public long getCounterSend_EVT_GET_ALL_SESSIONS()
        Returns:
        Returns the counterSend_EVT_GET_ALL_SESSIONS.
      • getCounterSend_EVT_SESSION_ACCESSED

        public long getCounterSend_EVT_SESSION_ACCESSED()
        Returns:
        Returns the counterSend_EVT_SESSION_ACCESSED.
      • getCounterSend_EVT_SESSION_CREATED

        public long getCounterSend_EVT_SESSION_CREATED()
        Returns:
        Returns the counterSend_EVT_SESSION_CREATED.
      • getCounterSend_EVT_SESSION_DELTA

        public long getCounterSend_EVT_SESSION_DELTA()
        Returns:
        Returns the counterSend_EVT_SESSION_DELTA.
      • getCounterSend_EVT_SESSION_EXPIRED

        public long getCounterSend_EVT_SESSION_EXPIRED()
        Returns:
        Returns the counterSend_EVT_SESSION_EXPIRED.
      • getCounterSend_EVT_ALL_SESSION_DATA

        public long getCounterSend_EVT_ALL_SESSION_DATA()
        Returns:
        Returns the counterSend_EVT_ALL_SESSION_DATA.
      • getCounterSend_EVT_ALL_SESSION_TRANSFERCOMPLETE

        public int getCounterSend_EVT_ALL_SESSION_TRANSFERCOMPLETE()
        Returns:
        Returns the counterSend_EVT_ALL_SESSION_TRANSFERCOMPLETE.
      • getCounterSend_EVT_CHANGE_SESSION_ID

        public long getCounterSend_EVT_CHANGE_SESSION_ID()
        Returns:
        Returns the counterSend_EVT_CHANGE_SESSION_ID.
      • getCounterReceive_EVT_ALL_SESSION_DATA

        public long getCounterReceive_EVT_ALL_SESSION_DATA()
        Returns:
        Returns the counterReceive_EVT_ALL_SESSION_DATA.
      • getCounterReceive_EVT_GET_ALL_SESSIONS

        public long getCounterReceive_EVT_GET_ALL_SESSIONS()
        Returns:
        Returns the counterReceive_EVT_GET_ALL_SESSIONS.
      • getCounterReceive_EVT_SESSION_ACCESSED

        public long getCounterReceive_EVT_SESSION_ACCESSED()
        Returns:
        Returns the counterReceive_EVT_SESSION_ACCESSED.
      • getCounterReceive_EVT_SESSION_CREATED

        public long getCounterReceive_EVT_SESSION_CREATED()
        Returns:
        Returns the counterReceive_EVT_SESSION_CREATED.
      • getCounterReceive_EVT_SESSION_DELTA

        public long getCounterReceive_EVT_SESSION_DELTA()
        Returns:
        Returns the counterReceive_EVT_SESSION_DELTA.
      • getCounterReceive_EVT_SESSION_EXPIRED

        public long getCounterReceive_EVT_SESSION_EXPIRED()
        Returns:
        Returns the counterReceive_EVT_SESSION_EXPIRED.
      • getCounterReceive_EVT_ALL_SESSION_TRANSFERCOMPLETE

        public int getCounterReceive_EVT_ALL_SESSION_TRANSFERCOMPLETE()
        Returns:
        Returns the counterReceive_EVT_ALL_SESSION_TRANSFERCOMPLETE.
      • getCounterReceive_EVT_CHANGE_SESSION_ID

        public long getCounterReceive_EVT_CHANGE_SESSION_ID()
        Returns:
        Returns the counterReceive_EVT_CHANGE_SESSION_ID.
      • getCounterReceive_EVT_ALL_SESSION_NOCONTEXTMANAGER

        public long getCounterReceive_EVT_ALL_SESSION_NOCONTEXTMANAGER()
        Returns:
        Returns the counterReceive_EVT_ALL_SESSION_NOCONTEXTMANAGER.
      • getProcessingTime

        public long getProcessingTime()
        Overrides:
        getProcessingTime in class ManagerBase
        Returns:
        Returns the processingTime.
      • getSessionReplaceCounter

        public long getSessionReplaceCounter()
        Returns:
        Returns the sessionReplaceCounter.
      • getCounterNoStateTransferred

        public int getCounterNoStateTransferred()
        Returns:
        Returns the counterNoStateTransferred.
      • getReceivedQueueSize

        public int getReceivedQueueSize()
      • getStateTransferTimeout

        public int getStateTransferTimeout()
        Returns:
        Returns the stateTransferTimeout.
      • setStateTransferTimeout

        public void setStateTransferTimeout​(int timeoutAllSession)
        Parameters:
        timeoutAllSession - The timeout
      • getStateTransferred

        public boolean getStateTransferred()
        Returns:
        true if the state transfer is complete.
      • setStateTransferred

        public void setStateTransferred​(boolean stateTransferred)
        Set that state transferred is complete
        Parameters:
        stateTransferred - Flag value
      • isNoContextManagerReceived

        public boolean isNoContextManagerReceived()
      • setNoContextManagerReceived

        public void setNoContextManagerReceived​(boolean noContextManagerReceived)
      • getSendAllSessionsWaitTime

        public int getSendAllSessionsWaitTime()
        Returns:
        the sendAllSessionsWaitTime in msec
      • setSendAllSessionsWaitTime

        public void setSendAllSessionsWaitTime​(int sendAllSessionsWaitTime)
        Parameters:
        sendAllSessionsWaitTime - The sendAllSessionsWaitTime to set at msec.
      • isStateTimestampDrop

        public boolean isStateTimestampDrop()
        Returns:
        the stateTimestampDrop.
      • setStateTimestampDrop

        public void setStateTimestampDrop​(boolean isTimestampDrop)
        Parameters:
        isTimestampDrop - The new flag value
      • isSendAllSessions

        public boolean isSendAllSessions()
        Returns:
        the sendAllSessions.
      • setSendAllSessions

        public void setSendAllSessions​(boolean sendAllSessions)
        Parameters:
        sendAllSessions - The sendAllSessions to set.
      • getSendAllSessionsSize

        public int getSendAllSessionsSize()
        Returns:
        the sendAllSessionsSize.
      • setSendAllSessionsSize

        public void setSendAllSessionsSize​(int sendAllSessionsSize)
        Parameters:
        sendAllSessionsSize - The sendAllSessionsSize to set.
      • isNotifySessionListenersOnReplication

        public boolean isNotifySessionListenersOnReplication()
        Returns:
        the notifySessionListenersOnReplication.
      • setNotifySessionListenersOnReplication

        public void setNotifySessionListenersOnReplication​(boolean notifyListenersCreateSessionOnReplication)
        Parameters:
        notifyListenersCreateSessionOnReplication - The notifySessionListenersOnReplication to set.
      • isExpireSessionsOnShutdown

        public boolean isExpireSessionsOnShutdown()
      • setExpireSessionsOnShutdown

        public void setExpireSessionsOnShutdown​(boolean expireSessionsOnShutdown)
      • isNotifyContainerListenersOnReplication

        public boolean isNotifyContainerListenersOnReplication()
      • setNotifyContainerListenersOnReplication

        public void setNotifyContainerListenersOnReplication​(boolean notifyContainerListenersOnReplication)
      • createSession

        public Session createSession​(String sessionId)
        Description copied from interface: Manager
        Construct and return a new session object, based on the default settings specified by this Manager's properties. The session id specified will be used as the session id. If a new session cannot be created for any reason, return null.
        Specified by:
        createSession in interface Manager
        Overrides:
        createSession in class ManagerBase
        Parameters:
        sessionId - The session id which should be used to create the new session; if null, the session id will be assigned by this method, and available via the getId() method of the returned session.
        Returns:
        An empty Session object with the given ID or a newly created session ID if none was specified
      • createSession

        public Session createSession​(String sessionId,
                                     boolean distribute)
        Create new session with check maxActiveSessions and send session creation to other cluster nodes.
        Parameters:
        sessionId - The session id that should be used for the session
        distribute - true to replicate the new session
        Returns:
        The session
      • sendCreateSession

        protected void sendCreateSession​(String sessionId,
                                         DeltaSession session)
        Send create session event to all backup node
        Parameters:
        sessionId - The session id of the session
        session - The session object
      • send

        protected void send​(SessionMessage msg)
        Send messages to other backup member (domain or all)
        Parameters:
        msg - Session message
      • createEmptySession

        public Session createEmptySession()
        Get a session from the recycled ones or create a new empty one. The PersistentManager manager does not need to create session data because it reads it from the Store.

        Creates new DeltaSession instance.

        Specified by:
        createEmptySession in interface Manager
        Overrides:
        createEmptySession in class ManagerBase
        Returns:
        An empty Session object
      • rotateSessionId

        public String rotateSessionId​(Session session)
        Description copied from interface: Manager
        Change the session ID of the current session to a new randomly generated session ID.
        Specified by:
        rotateSessionId in interface Manager
        Overrides:
        rotateSessionId in class ManagerBase
        Parameters:
        session - The session to change the session ID for
        Returns:
        The new session ID
      • changeSessionId

        public void changeSessionId​(Session session,
                                    String newId)
        Description copied from interface: Manager
        Change the session ID of the current session to a specified session ID.
        Specified by:
        changeSessionId in interface Manager
        Overrides:
        changeSessionId in class ManagerBase
        Parameters:
        session - The session to change the session ID for
        newId - new session ID
      • rotateSessionId

        protected String rotateSessionId​(Session session,
                                         boolean notify)
      • changeSessionId

        protected void changeSessionId​(Session session,
                                       String newId,
                                       boolean notify)
      • sendChangeSessionId

        protected void sendChangeSessionId​(String newSessionID,
                                           String orgSessionID)
      • serializeSessionId

        protected byte[] serializeSessionId​(String sessionId)
                                     throws IOException
        serialize sessionID
        Parameters:
        sessionId - Session id to serialize
        Returns:
        byte array with serialized session id
        Throws:
        IOException - if an input/output error occurs
      • deserializeSessionId

        protected String deserializeSessionId​(byte[] data)
                                       throws IOException
        Load sessionID
        Parameters:
        data - serialized session id
        Returns:
        session id
        Throws:
        IOException - if an input/output error occurs
      • deserializeSessions

        protected void deserializeSessions​(byte[] data)
                                    throws ClassNotFoundException,
                                           IOException
        Load sessions from other cluster node. FIXME replace currently sessions with same id without notification. FIXME SSO handling is not really correct with the session replacement!
        Parameters:
        data - Serialized data
        Throws:
        ClassNotFoundException - if a serialized class cannot be found during the reload
        IOException - if an input/output error occurs
      • serializeSessions

        protected byte[] serializeSessions​(Session[] currentSessions)
                                    throws IOException
        Save any currently active sessions in the appropriate persistence mechanism, if any. If persistence is not supported, this method returns without doing anything.
        Parameters:
        currentSessions - Sessions to serialize
        Returns:
        serialized data
        Throws:
        IOException - if an input/output error occurs
      • getAllClusterSessions

        public void getAllClusterSessions()
        get from first session master the backup from all clustered sessions
        See Also:
        findSessionMasterMember()
      • findSessionMasterMember

        protected Member findSessionMasterMember()
        Find the master of the session state
        Returns:
        master member of sessions
      • waitForSendAllSessions

        protected void waitForSendAllSessions​(long beforeSendTime)
        Wait that cluster session state is transferred or timeout after 60 Sec With stateTransferTimeout == -1 wait that backup is transferred (forever mode)
        Parameters:
        beforeSendTime - Start instant of the operation
      • messageDataReceived

        public void messageDataReceived​(ClusterMessage cmsg)
        A message was received from another node, this is the callback method to implement if you are interested in receiving replication messages.
        Parameters:
        cmsg - - the message received.
      • requestCompleted

        public ClusterMessage requestCompleted​(String sessionId)
        When the request has been completed, the replication valve will notify the manager, and the manager will decide whether any replication is needed or not. If there is a need for replication, the manager will create a session message and that will be replicated. The cluster determines where it gets sent.
        Parameters:
        sessionId - - the sessionId that just completed.
        Returns:
        a SessionMessage to be sent,
      • requestCompleted

        public ClusterMessage requestCompleted​(String sessionId,
                                               boolean expires)
        When the request has been completed, the replication valve will notify the manager, and the manager will decide whether any replication is needed or not. If there is a need for replication, the manager will create a session message and that will be replicated. The cluster determines where it gets sent. Session expiration also calls this method, but with expires == true.
        Parameters:
        sessionId - - the sessionId that just completed.
        expires - - whether this method has been called during session expiration
        Returns:
        a SessionMessage to be sent,
      • resetStatistics

        public void resetStatistics()
        Reset manager statistics
      • sessionExpired

        protected void sessionExpired​(String id)
        send session expired to other cluster nodes
        Parameters:
        id - session id
      • expireAllLocalSessions

        public void expireAllLocalSessions()
        Expire all find sessions.
      • getInvalidatedSessions

        public String[] getInvalidatedSessions()
        Description copied from interface: ClusterManager
        When the manager expires session not tied to a request. The cluster will periodically ask for a list of sessions that should expire and that should be sent across the wire.
        Returns:
        String[] The invalidated sessions
      • messageReceived

        protected void messageReceived​(SessionMessage msg,
                                       Member sender)
        This method is called by the received thread when a SessionMessage has been received from one of the other nodes in the cluster.
        Parameters:
        msg - - the message received
        sender - - the sender of the message, this is used if we receive a EVT_GET_ALL_SESSION message, so that we only reply to the requesting node
      • handleALL_SESSION_TRANSFERCOMPLETE

        protected void handleALL_SESSION_TRANSFERCOMPLETE​(SessionMessage msg,
                                                          Member sender)
        handle receive session state is complete transferred
        Parameters:
        msg - Session message
        sender - Member which sent the message
      • handleSESSION_ACCESSED

        protected void handleSESSION_ACCESSED​(SessionMessage msg,
                                              Member sender)
                                       throws IOException
        handle receive session is access at other node ( primary session is now false)
        Parameters:
        msg - Session message
        sender - Member which sent the message
        Throws:
        IOException - Propagated IO error
      • handleSESSION_EXPIRED

        protected void handleSESSION_EXPIRED​(SessionMessage msg,
                                             Member sender)
                                      throws IOException
        handle receive session is expire at other node ( expire session also here)
        Parameters:
        msg - Session message
        sender - Member which sent the message
        Throws:
        IOException - Propagated IO error
      • handleSESSION_CREATED

        protected void handleSESSION_CREATED​(SessionMessage msg,
                                             Member sender)
        handle receive new session is created at other node (create backup - primary false)
        Parameters:
        msg - Session message
        sender - Member which sent the message
      • handleGET_ALL_SESSIONS

        protected void handleGET_ALL_SESSIONS​(SessionMessage msg,
                                              Member sender)
                                       throws IOException
        handle receive that other node want all sessions ( restart ) a) send all sessions with one message b) send session at blocks After sending send state is complete transferred
        Parameters:
        msg - Session message
        sender - Member which sent the message
        Throws:
        IOException - IO error sending messages
      • handleCHANGE_SESSION_ID

        protected void handleCHANGE_SESSION_ID​(SessionMessage msg,
                                               Member sender)
                                        throws IOException
        handle receive change sessionID at other node
        Parameters:
        msg - Session message
        sender - Member which sent the message
        Throws:
        IOException - IO error with serialization
      • handleALL_SESSION_NOCONTEXTMANAGER

        protected void handleALL_SESSION_NOCONTEXTMANAGER​(SessionMessage msg,
                                                          Member sender)
        handle receive no context manager.
        Parameters:
        msg - Session message
        sender - Member which sent the message
      • sendSessions

        protected void sendSessions​(Member sender,
                                    Session[] currentSessions,
                                    long sendTimestamp)
                             throws IOException
        send a block of session to sender
        Parameters:
        sender - Sender member
        currentSessions - Sessions to send
        sendTimestamp - Timestamp
        Throws:
        IOException - IO error sending messages