public void dumpSessions(PrintWriter pwriter) { pwriter.print("Session "); sessionExpiryQueue.dump(pwriter); }
/** * Returns a mapping from time to session IDs of sessions expiring at that time. */ synchronized public Map<Long, Set<Long>> getSessionExpiryMap() { // Convert time -> sessions map to time -> session IDs map Map<Long, Set<SessionImpl>> expiryMap = sessionExpiryQueue.getExpiryMap(); Map<Long, Set<Long>> sessionExpiryMap = new TreeMap<Long, Set<Long>>(); for (Entry<Long, Set<SessionImpl>> e : expiryMap.entrySet()) { Set<Long> ids = new HashSet<Long>(); sessionExpiryMap.put(e.getKey(), ids); for (SessionImpl s : e.getValue()) { ids.add(s.sessionId); } } return sessionExpiryMap; }
public void run() { try { while (!stopped) { long waitTime = cnxnExpiryQueue.getWaitTime(); if (waitTime > 0) { Thread.sleep(waitTime); continue; } for (NIOServerCnxn conn : cnxnExpiryQueue.poll()) { conn.close(); } } } catch (InterruptedException e) { LOG.info("ConnnectionExpirerThread interrupted"); } } }
/** * Add or update cnxn in our cnxnExpiryQueue * @param cnxn */ public void touchCnxn(NIOServerCnxn cnxn) { cnxnExpiryQueue.update(cnxn, cnxn.getSessionTimeout()); }
public ExpiryQueue(int expirationInterval) { this.expirationInterval = expirationInterval; nextExpirationTime.set(roundToNextInterval(Time.currentElapsedTime())); }
synchronized public void removeSession(long sessionId) { LOG.debug("Removing session 0x" + Long.toHexString(sessionId)); SessionImpl s = sessionsById.remove(sessionId); sessionsWithTimeout.remove(sessionId); if (LOG.isTraceEnabled()) { ZooTrace.logTraceMessage(LOG, ZooTrace.SESSION_TRACE_MASK, "SessionTrackerImpl --- Removing session 0x" + Long.toHexString(sessionId)); } if (s != null) { sessionExpiryQueue.remove(s); } }
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); }
private void updateSessionExpiry(SessionImpl s, int timeout) { logTraceTouchSession(s.sessionId, timeout, ""); sessionExpiryQueue.update(s, timeout); }
Long prevExpiryTime = elemMap.get(elem); long now = Time.currentElapsedTime(); Long newExpiryTime = roundToNextInterval(now + timeout);
/** * De-registers the connection from the various mappings maintained * by the factory. */ public boolean removeCnxn(NIOServerCnxn cnxn) { // If the connection is not in the master list it's already been closed if (!cnxns.remove(cnxn)) { return false; } cnxnExpiryQueue.remove(cnxn); removeCnxnFromSessionMap(cnxn); InetAddress addr = cnxn.getSocketAddress(); if (addr != null) { Set<NIOServerCnxn> set = ipMap.get(addr); if (set != null) { set.remove(cnxn); // Note that we make no effort here to remove empty mappings // from ipMap. } } // unregister from JMX unregisterConnection(cnxn); return true; }
new ExpiryQueue<NIOServerCnxn>(sessionlessCnxnTimeout); expirerThread = new ConnectionExpirerThread();
@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!"); }
public void dumpConnections(PrintWriter pwriter) { pwriter.print("Connections "); cnxnExpiryQueue.dump(pwriter); }