public boolean touchSession(long sessionId, int sessionTimeout) { if (localSessionTracker != null && localSessionTracker.touchSession(sessionId, sessionTimeout)) { return true; } return globalSessionTracker.touchSession(sessionId, sessionTimeout); }
public LeaderSessionTracker(SessionExpirer expirer, ConcurrentMap<Long, Integer> sessionsWithTimeouts, int tickTime, long id, boolean localSessionsEnabled, ZooKeeperServerListener listener) { this.globalSessionTracker = new SessionTrackerImpl( expirer, sessionsWithTimeouts, tickTime, id, listener); this.localSessionsEnabled = localSessionsEnabled; if (this.localSessionsEnabled) { createLocalSessionTracker(expirer, tickTime, id, listener); } serverId = id; }
@Override public String toString() { StringWriter sw = new StringWriter(); PrintWriter pwriter = new PrintWriter(sw); dumpSessions(pwriter); pwriter.flush(); pwriter.close(); return sw.toString(); }
public SessionTrackerImpl(SessionExpirer expirer, ConcurrentHashMap<Long, Integer> sessionsWithTimeout, int tickTime, long sid, ZooKeeperServerListener listener) { super("SessionTracker", listener); this.expirer = expirer; this.expirationInterval = tickTime; this.sessionsWithTimeout = sessionsWithTimeout; nextExpirationTime = roundToInterval(Time.currentElapsedTime()); this.nextSessionId = initializeNextSession(sid); for (Entry<Long, Integer> e : sessionsWithTimeout.entrySet()) { addSession(e.getKey(), e.getValue()); } }
public SessionTrackerImpl(SessionExpirer expirer, ConcurrentMap<Long, Integer> sessionsWithTimeout, int tickTime, long serverId, ZooKeeperServerListener listener) { super("SessionTracker", listener); this.expirer = expirer; this.sessionExpiryQueue = new ExpiryQueue<SessionImpl>(tickTime); this.sessionsWithTimeout = sessionsWithTimeout; this.nextSessionId.set(initializeNextSession(serverId)); for (Entry<Long, Integer> e : sessionsWithTimeout.entrySet()) { trackSession(e.getKey(), e.getValue()); } EphemeralType.validateServerId(serverId); }
@Override public void run() { try { while (running) { long waitTime = sessionExpiryQueue.getWaitTime(); if (waitTime > 0) { Thread.sleep(waitTime); continue; } for (SessionImpl s : sessionExpiryQueue.poll()) { setSessionClosing(s.sessionId); expirer.expire(s); } } } catch (InterruptedException e) { handleException(this.getName(), e); } LOG.info("SessionTrackerImpl exited loop!"); }
sessionTrackerImpl.checkSession(sessionId, sessionOwner); sessionTrackerImpl.trackSession(sessionId, sessionTimeout); try { sessionTrackerImpl.checkSession(sessionId, sessionOwner); Assert.fail("Should throw session expiry exception " + "as the session has expired and closed"); .touchSession(sessionId, sessionTimeout)); Assert.assertEquals( "Duplicate session expiry request has been generated", 1,
protected void createSessionTracker() { sessionTracker = new SessionTrackerImpl(this, zkDb.getSessionWithTimeOuts(), tickTime, 1); ((SessionTrackerImpl)sessionTracker).start(); }
protected void startSessionTracker() { ((SessionTrackerImpl)sessionTracker).start(); }
public LearnerSessionTracker(SessionExpirer expirer, ConcurrentHashMap<Long, Integer> sessionsWithTimeouts, long id, ZooKeeperServerListener listener) { this.expirer = expirer; this.sessionsWithTimeouts = sessionsWithTimeouts; this.serverId = id; nextSessionId = SessionTrackerImpl.initializeNextSession(this.serverId); }
/** * Verify the session closure request has reached PrepRequestProcessor soon * after session expiration by the session tracker */ @Test(timeout = 20000) public void testCloseSessionRequestAfterSessionExpiry() throws Exception { ZooKeeperServer zks = setupSessionTracker(); latch = new CountDownLatch(1); zks.sessionTracker.trackSession(sessionId, sessionTimeout); SessionTrackerImpl sessionTrackerImpl = (SessionTrackerImpl) zks.sessionTracker; SessionImpl sessionImpl = sessionTrackerImpl.sessionsById .get(sessionId); Assert.assertNotNull("Sessionid:" + sessionId + " doesn't exists in sessiontracker", sessionImpl); // verify the session existence Object sessionOwner = new Object(); sessionTrackerImpl.checkSession(sessionId, sessionOwner); // waiting for the session expiry latch.await(sessionTimeout * 2, TimeUnit.MILLISECONDS); // Simulating close session request: removeSession() will be executed // while OpCode.closeSession sessionTrackerImpl.removeSession(sessionId); SessionImpl actualSession = sessionTrackerImpl.sessionsById .get(sessionId); Assert.assertNull("Session:" + sessionId + " still exists after removal", actualSession); }
public void checkGlobalSession(long sessionId, Object owner) throws SessionExpiredException, SessionMovedException { try { globalSessionTracker.checkSession(sessionId, owner); } catch (UnknownSessionException e) { // For global session, if we don't know it, it is already expired throw new SessionExpiredException(); } }
synchronized public long createSession(int sessionTimeout) { addSession(nextSessionId, sessionTimeout); return nextSessionId++; }
public void removeSession(long sessionId) { if (localSessionTracker != null) { localSessionTracker.removeSession(sessionId); } globalSessionTracker.removeSession(sessionId); }
public SessionTrackerImpl(SessionExpirer expirer, ConcurrentHashMap<Long, Integer> sessionsWithTimeout, int tickTime, long sid) { super("SessionTracker"); this.expirer = expirer; this.expirationInterval = tickTime; this.sessionsWithTimeout = sessionsWithTimeout; nextExpirationTime = roundToInterval(System.currentTimeMillis()); this.nextSessionId = initializeNextSession(sid); for (Entry<Long, Integer> e : sessionsWithTimeout.entrySet()) { addSession(e.getKey(), e.getValue()); } }
@Override synchronized public void run() { try { while (running) { currentTime = Time.currentElapsedTime(); if (nextExpirationTime > currentTime) { this.wait(nextExpirationTime - currentTime); continue; } SessionSet set; set = sessionSets.remove(nextExpirationTime); if (set != null) { for (SessionImpl s : set.sessions) { setSessionClosing(s.sessionId); expirer.expire(s); } } nextExpirationTime += expirationInterval; } } catch (InterruptedException e) { handleException(this.getName(), e); } LOG.info("SessionTrackerImpl exited loop!"); }
@Override protected void createSessionTracker() { sessionTracker = new SessionTrackerImpl(this, getZKDatabase().getSessionWithTimeOuts(), tickTime, self.getId()); ((SessionTrackerImpl)sessionTracker).start(); }
@Override protected void startSessionTracker() { ((SessionTrackerImpl)sessionTracker).start(); }
public LearnerSessionTracker(SessionExpirer expirer, ConcurrentMap<Long, Integer> sessionsWithTimeouts, int tickTime, long id, boolean localSessionsEnabled, ZooKeeperServerListener listener) { this.expirer = expirer; this.touchTable.set(new ConcurrentHashMap<Long, Integer>()); this.globalSessionsWithTimeouts = sessionsWithTimeouts; this.serverId = id; nextSessionId.set(SessionTrackerImpl.initializeNextSession(serverId)); this.localSessionsEnabled = localSessionsEnabled; if (this.localSessionsEnabled) { createLocalSessionTracker(expirer, tickTime, id, listener); } }
public void checkGlobalSession(long sessionId, Object owner) throws KeeperException.SessionExpiredException, KeeperException.SessionMovedException { try { checkSession(sessionId, owner); } catch (KeeperException.UnknownSessionException e) { throw new KeeperException.SessionExpiredException(); } }