Class LearnerSessionTracker

  • All Implemented Interfaces:
    SessionTracker

    public class LearnerSessionTracker
    extends UpgradeableSessionTracker
    The learner session tracker is used by learners (followers and observers) to track zookeeper sessions which may or may not be echoed to the leader. When a new session is created it is saved locally in a wrapped LocalSessionTracker. It can subsequently be upgraded to a global session as required. If an upgrade is requested the session is removed from local collections while keeping the same session ID. It is up to the caller to queue a session creation request for the leader. A secondary function of the learner session tracker is to remember sessions which have been touched in this service. This information is passed along to the leader with a ping.
    • Constructor Detail

      • LearnerSessionTracker

        public LearnerSessionTracker​(SessionTracker.SessionExpirer expirer,
                                     java.util.concurrent.ConcurrentMap<java.lang.Long,​java.lang.Integer> sessionsWithTimeouts,
                                     int tickTime,
                                     long id,
                                     boolean localSessionsEnabled,
                                     ZooKeeperServerListener listener)
    • Method Detail

      • removeSession

        public void removeSession​(long sessionId)
      • shutdown

        public void shutdown()
      • addGlobalSession

        public boolean addGlobalSession​(long sessionId,
                                        int sessionTimeout)
        Description copied from interface: SessionTracker
        Add a global session to those being tracked.
        Parameters:
        sessionId - sessionId
        sessionTimeout - sessionTimeout
        Returns:
        whether the session was newly added (if false, already existed)
      • addSession

        public boolean addSession​(long sessionId,
                                  int sessionTimeout)
        Description copied from interface: SessionTracker
        Add a session to those being tracked. The session is added as a local session if they are enabled, otherwise as global.
        Parameters:
        sessionId - sessionId
        sessionTimeout - sessionTimeout
        Returns:
        whether the session was newly added (if false, already existed)
      • touchSession

        public boolean touchSession​(long sessionId,
                                    int sessionTimeout)
        Returns:
        false if session is no longer active
      • snapshot

        public java.util.Map<java.lang.Long,​java.lang.Integer> snapshot()
      • createSession

        public long createSession​(int sessionTimeout)
      • dumpSessions

        public void dumpSessions​(java.io.PrintWriter pwriter)
        Description copied from interface: SessionTracker
        Text dump of session information, suitable for debugging.
        Parameters:
        pwriter - the output writer
      • setSessionClosing

        public void setSessionClosing​(long sessionId)
        Description copied from interface: SessionTracker
        Mark that the session is in the process of closing.
      • getSessionExpiryMap

        public java.util.Map<java.lang.Long,​java.util.Set<java.lang.Long>> getSessionExpiryMap()
        Description copied from interface: SessionTracker
        Returns a mapping of time to session IDs that expire at that time.