Package org.apache.zookeeper.server
Class SessionTrackerImpl
- java.lang.Object
- 
- java.lang.Thread
- 
- org.apache.zookeeper.server.ZooKeeperThread
- 
- org.apache.zookeeper.server.ZooKeeperCriticalThread
- 
- org.apache.zookeeper.server.SessionTrackerImpl
 
 
 
 
- 
- All Implemented Interfaces:
- Runnable,- SessionTracker
 - Direct Known Subclasses:
- LocalSessionTracker
 
 public class SessionTrackerImpl extends ZooKeeperCriticalThread implements SessionTracker This is a full featured SessionTracker. It tracks session in grouped by tick interval. It always rounds up the tick interval to provide a sort of grace period. Sessions are thus expired in batches made up of sessions that expire in a given interval.
- 
- 
Nested Class SummaryNested Classes Modifier and Type Class Description static classSessionTrackerImpl.SessionImpl- 
Nested classes/interfaces inherited from class java.lang.ThreadThread.State, Thread.UncaughtExceptionHandler
 - 
Nested classes/interfaces inherited from interface org.apache.zookeeper.server.SessionTrackerSessionTracker.Session, SessionTracker.SessionExpirer
 
- 
 - 
Field SummaryFields Modifier and Type Field Description protected ConcurrentHashMap<Long,SessionTrackerImpl.SessionImpl>sessionsByIdprotected ConcurrentMap<Long,Integer>sessionsWithTimeout- 
Fields inherited from class java.lang.ThreadMAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
 
- 
 - 
Constructor SummaryConstructors Constructor Description SessionTrackerImpl(SessionTracker.SessionExpirer expirer, ConcurrentMap<Long,Integer> sessionsWithTimeout, int tickTime, long serverId, ZooKeeperServerListener listener)
 - 
Method SummaryAll Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidcheckGlobalSession(long sessionId, Object owner)Strictly check that a given session is a global session or notvoidcheckSession(long sessionId, Object owner)Checks whether the SessionTracker is aware of this session, the session is still active, and the owner matches.booleancommitSession(long id, int sessionTimeout)Add the session to the local session map or global one in zkDB.longcreateSession(int sessionTimeout)voiddumpSessions(PrintWriter pwriter)Text dump of session information, suitable for debugging.longgetLocalSessionCount()If this session tracker supports local sessions, return how many.Map<Long,Set<Long>>getSessionExpiryMap()Returns a mapping from time to session IDs of sessions expiring at that time.intgetSessionTimeout(long sessionId)Set<Long>globalSessions()Get a set of global session IDsstatic longinitializeNextSessionId(long id)Generates an initial sessionId.booleanisLocalSessionsEnabled()booleanisTrackingSession(long sessionId)Set<Long>localSessions()Get a set of local session IDsvoidremoveSession(long sessionId)voidrun()voidsetOwner(long id, Object owner)voidsetSessionClosing(long sessionId)Mark that the session is in the process of closing.voidshutdown()StringtoString()booleantouchSession(long sessionId, int timeout)booleantrackSession(long id, int sessionTimeout)Track the session expire, not add to ZkDb.- 
Methods inherited from class org.apache.zookeeper.server.ZooKeeperCriticalThreadhandleException
 - 
Methods inherited from class java.lang.ThreadactiveCount, checkAccess, clone, countStackFrames, currentThread, destroy, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, start, stop, stop, suspend, yield
 
- 
 
- 
- 
- 
Field Detail- 
sessionsByIdprotected final ConcurrentHashMap<Long,SessionTrackerImpl.SessionImpl> sessionsById 
 - 
sessionsWithTimeoutprotected final ConcurrentMap<Long,Integer> sessionsWithTimeout 
 
- 
 - 
Constructor Detail- 
SessionTrackerImplpublic SessionTrackerImpl(SessionTracker.SessionExpirer expirer, ConcurrentMap<Long,Integer> sessionsWithTimeout, int tickTime, long serverId, ZooKeeperServerListener listener) 
 
- 
 - 
Method Detail- 
initializeNextSessionIdpublic static long initializeNextSessionId(long id) Generates an initial sessionId.High order 1 byte is serverId, next 5 bytes are from timestamp, and low order 2 bytes are 0s. Use ">>> 8", not ">> 8" to make sure that the high order 1 byte is entirely up to the server Id. See also http://jira.apache.org/jira/browse/ZOOKEEPER-1622 - Parameters:
- id- server Id
- Returns:
- the session Id
 
 - 
dumpSessionspublic void dumpSessions(PrintWriter pwriter) Description copied from interface:SessionTrackerText dump of session information, suitable for debugging.- Specified by:
- dumpSessionsin interface- SessionTracker
- Parameters:
- pwriter- the output writer
 
 - 
getSessionExpiryMappublic Map<Long,Set<Long>> getSessionExpiryMap() Returns a mapping from time to session IDs of sessions expiring at that time.- Specified by:
- getSessionExpiryMapin interface- SessionTracker
 
 - 
touchSessionpublic boolean touchSession(long sessionId, int timeout)- Specified by:
- touchSessionin interface- SessionTracker
- Returns:
- false if session is no longer active
 
 - 
getSessionTimeoutpublic int getSessionTimeout(long sessionId) 
 - 
setSessionClosingpublic void setSessionClosing(long sessionId) Description copied from interface:SessionTrackerMark that the session is in the process of closing.- Specified by:
- setSessionClosingin interface- SessionTracker
 
 - 
removeSessionpublic void removeSession(long sessionId) - Specified by:
- removeSessionin interface- SessionTracker
 
 - 
shutdownpublic void shutdown() - Specified by:
- shutdownin interface- SessionTracker
 
 - 
createSessionpublic long createSession(int sessionTimeout) - Specified by:
- createSessionin interface- SessionTracker
 
 - 
trackSessionpublic boolean trackSession(long id, int sessionTimeout)Description copied from interface:SessionTrackerTrack the session expire, not add to ZkDb.- Specified by:
- trackSessionin interface- SessionTracker
- Parameters:
- id- sessionId
- sessionTimeout- sessionTimeout
- Returns:
- whether the session was newly tracked (if false, already tracked)
 
 - 
commitSessionpublic boolean commitSession(long id, int sessionTimeout)Description copied from interface:SessionTrackerAdd the session to the local session map or global one in zkDB.- Specified by:
- commitSessionin interface- SessionTracker
- Parameters:
- id- sessionId
- sessionTimeout- sessionTimeout
- Returns:
- whether the session was newly added (if false, already existed)
 
 - 
isTrackingSessionpublic boolean isTrackingSession(long sessionId) - Specified by:
- isTrackingSessionin interface- SessionTracker
- Returns:
- whether or not the SessionTracker is aware of this session
 
 - 
checkSessionpublic void checkSession(long sessionId, Object owner) throws KeeperException.SessionExpiredException, KeeperException.SessionMovedException, KeeperException.UnknownSessionExceptionDescription copied from interface:SessionTrackerChecks whether the SessionTracker is aware of this session, the session is still active, and the owner matches. If the owner wasn't previously set, this sets the owner of the session. UnknownSessionException should never been thrown to the client. It is only used internally to deal with possible local session from other machine- Specified by:
- checkSessionin interface- SessionTracker
- Throws:
- KeeperException.SessionExpiredException
- KeeperException.SessionMovedException
- KeeperException.UnknownSessionException
 
 - 
setOwnerpublic void setOwner(long id, Object owner) throws KeeperException.SessionExpiredException- Specified by:
- setOwnerin interface- SessionTracker
- Throws:
- KeeperException.SessionExpiredException
 
 - 
checkGlobalSessionpublic void checkGlobalSession(long sessionId, Object owner) throws KeeperException.SessionExpiredException, KeeperException.SessionMovedExceptionDescription copied from interface:SessionTrackerStrictly check that a given session is a global session or not- Specified by:
- checkGlobalSessionin interface- SessionTracker
- Throws:
- KeeperException.SessionExpiredException
- KeeperException.SessionMovedException
 
 - 
getLocalSessionCountpublic long getLocalSessionCount() Description copied from interface:SessionTrackerIf this session tracker supports local sessions, return how many. otherwise returns 0;- Specified by:
- getLocalSessionCountin interface- SessionTracker
 
 - 
isLocalSessionsEnabledpublic boolean isLocalSessionsEnabled() - Specified by:
- isLocalSessionsEnabledin interface- SessionTracker
 
 - 
globalSessionspublic Set<Long> globalSessions() Description copied from interface:SessionTrackerGet a set of global session IDs- Specified by:
- globalSessionsin interface- SessionTracker
 
 - 
localSessionspublic Set<Long> localSessions() Description copied from interface:SessionTrackerGet a set of local session IDs- Specified by:
- localSessionsin interface- SessionTracker
 
 
- 
 
-