private void removeMainSession(Session session) { InetSocketAddress remoteSocketAddress = session.getRemoteSocketAddress(); // If it was in failure mode,we don't remove closed session from list. if (this.failureMode) { log.warn( "Client in failure mode,we don't remove session " + SystemUtils.getRawAddress(remoteSocketAddress) + ":" + remoteSocketAddress.getPort()); return; } log.warn( "Remove a session: " + SystemUtils.getRawAddress(remoteSocketAddress) + ":" + remoteSocketAddress.getPort()); Queue<Session> sessionQueue = this.sessionMap.get(session.getRemoteSocketAddress()); if (null != sessionQueue) { sessionQueue.remove(session); if (sessionQueue.size() == 0) { this.sessionMap.remove(session.getRemoteSocketAddress()); } this.updateSessions(); } }
private void addMainSession(Session session) { InetSocketAddress remoteSocketAddress = session.getRemoteSocketAddress(); log.warn( "Add a session: " + SystemUtils.getRawAddress(remoteSocketAddress) + ":" + remoteSocketAddress.getPort()); Queue<Session> sessions = this.sessionMap.get(remoteSocketAddress); if (sessions == null) { sessions = new ConcurrentLinkedQueue<Session>(); Queue<Session> oldSessions = this.sessionMap.putIfAbsent(remoteSocketAddress, sessions); if (null != oldSessions) { sessions = oldSessions; } } // If it is in failure mode,remove closed session from list if (this.failureMode) { Iterator<Session> it = sessions.iterator(); while (it.hasNext()) { Session tmp = it.next(); if (tmp.isClosed()) { it.remove(); break; } } } sessions.offer(session); // Remove old session and close it while (sessions.size() > this.connectionPoolSize) { Session oldSession = sessions.poll(); ((MemcachedSession) oldSession).setAllowReconnect(false); oldSession.close(); } }
private void addStandbySession(Session session, InetSocketAddress mainNodeAddress) { InetSocketAddress remoteSocketAddress = session.getRemoteSocketAddress(); log.warn( "Add a standby session: " + SystemUtils.getRawAddress(remoteSocketAddress) + ":" + remoteSocketAddress.getPort() + " for " + SystemUtils.getRawAddress(mainNodeAddress) + ":" + mainNodeAddress.getPort()); List<Session> sessions = this.standbySessionMap.get(mainNodeAddress); if (sessions == null) { sessions = new CopyOnWriteArrayList<Session>(); List<Session> oldSessions = this.standbySessionMap.putIfAbsent(mainNodeAddress, sessions); if (null != oldSessions) { sessions = oldSessions; } } sessions.add(session); }