public class SessionTrackerImpl extends ZooKeeperCriticalThread implements SessionTracker
Modifier and Type | Class and Description |
---|---|
static class |
SessionTrackerImpl.SessionImpl |
Thread.State, Thread.UncaughtExceptionHandler
SessionTracker.Session, SessionTracker.SessionExpirer
Modifier and Type | Field and Description |
---|---|
protected ConcurrentHashMap<Long,SessionTrackerImpl.SessionImpl> |
sessionsById |
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
Constructor and Description |
---|
SessionTrackerImpl(SessionTracker.SessionExpirer expirer,
ConcurrentMap<Long,Integer> sessionsWithTimeout,
int tickTime,
long serverId,
ZooKeeperServerListener listener) |
Modifier and Type | Method and Description |
---|---|
void |
checkGlobalSession(long sessionId,
Object owner)
Strictly check that a given session is a global session or not
|
void |
checkSession(long sessionId,
Object owner)
Checks whether the SessionTracker is aware of this session, the session
is still active, and the owner matches.
|
boolean |
commitSession(long id,
int sessionTimeout)
Add the session to the local session map or global one in zkDB.
|
long |
createSession(int sessionTimeout) |
void |
dumpSessions(PrintWriter pwriter)
Text dump of session information, suitable for debugging.
|
long |
getLocalSessionCount()
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.
|
int |
getSessionTimeout(long sessionId) |
static long |
initializeNextSessionId(long id)
Generates an initial sessionId.
|
boolean |
isLocalSessionsEnabled() |
boolean |
isTrackingSession(long sessionId) |
void |
removeSession(long sessionId) |
void |
run() |
void |
setOwner(long id,
Object owner) |
void |
setSessionClosing(long sessionId)
Mark that the session is in the process of closing.
|
void |
shutdown() |
String |
toString() |
boolean |
touchSession(long sessionId,
int timeout) |
boolean |
trackSession(long id,
int sessionTimeout)
Track the session expire, not add to ZkDb.
|
handleException
activeCount, 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
protected final ConcurrentHashMap<Long,SessionTrackerImpl.SessionImpl> sessionsById
public SessionTrackerImpl(SessionTracker.SessionExpirer expirer, ConcurrentMap<Long,Integer> sessionsWithTimeout, int tickTime, long serverId, ZooKeeperServerListener listener)
public static long initializeNextSessionId(long id)
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
id
- server Idpublic void dumpSessions(PrintWriter pwriter)
SessionTracker
dumpSessions
in interface SessionTracker
pwriter
- the output writerpublic Map<Long,Set<Long>> getSessionExpiryMap()
getSessionExpiryMap
in interface SessionTracker
public boolean touchSession(long sessionId, int timeout)
touchSession
in interface SessionTracker
public int getSessionTimeout(long sessionId)
public void setSessionClosing(long sessionId)
SessionTracker
setSessionClosing
in interface SessionTracker
public void removeSession(long sessionId)
removeSession
in interface SessionTracker
public void shutdown()
shutdown
in interface SessionTracker
public long createSession(int sessionTimeout)
createSession
in interface SessionTracker
public boolean trackSession(long id, int sessionTimeout)
SessionTracker
trackSession
in interface SessionTracker
id
- sessionIdsessionTimeout
- sessionTimeoutpublic boolean commitSession(long id, int sessionTimeout)
SessionTracker
commitSession
in interface SessionTracker
id
- sessionIdsessionTimeout
- sessionTimeoutpublic boolean isTrackingSession(long sessionId)
isTrackingSession
in interface SessionTracker
public void checkSession(long sessionId, Object owner) throws KeeperException.SessionExpiredException, KeeperException.SessionMovedException, KeeperException.UnknownSessionException
SessionTracker
checkSession
in interface SessionTracker
KeeperException.SessionExpiredException
KeeperException.SessionMovedException
KeeperException.UnknownSessionException
public void setOwner(long id, Object owner) throws KeeperException.SessionExpiredException
setOwner
in interface SessionTracker
KeeperException.SessionExpiredException
public void checkGlobalSession(long sessionId, Object owner) throws KeeperException.SessionExpiredException, KeeperException.SessionMovedException
SessionTracker
checkGlobalSession
in interface SessionTracker
KeeperException.SessionExpiredException
KeeperException.SessionMovedException
public long getLocalSessionCount()
SessionTracker
getLocalSessionCount
in interface SessionTracker
public boolean isLocalSessionsEnabled()
isLocalSessionsEnabled
in interface SessionTracker
Copyright © 2008–2021 The Apache Software Foundation. All rights reserved.