public void removeCnxnFromSessionMap(ServerCnxn cnxn) { long sessionId = cnxn.getSessionId(); if (sessionId != 0) { sessionMap.remove(sessionId); } }
@Override public synchronized WatchesReport getWatches() { Map<Long, Set<String>> id2paths = new HashMap<Long, Set<String>>(); for (Entry<Watcher, Set<String>> e: watch2Paths.entrySet()) { Long id = ((ServerCnxn) e.getKey()).getSessionId(); Set<String> paths = new HashSet<String>(e.getValue()); id2paths.put(id, paths); } return new WatchesReport(id2paths); }
@Override public synchronized WatchesPathReport getWatchesByPath() { Map<String, Set<Long>> path2ids = new HashMap<String, Set<Long>>(); for (Entry<String, Set<Watcher>> e : watchTable.entrySet()) { Set<Long> ids = new HashSet<Long>(e.getValue().size()); path2ids.put(e.getKey(), ids); for (Watcher watcher : e.getValue()) { ids.add(((ServerCnxn) watcher).getSessionId()); } } return new WatchesPathReport(path2ids); }
public void closeSession(ServerCnxn cnxn, RequestHeader requestHeader) { closeSession(cnxn.getSessionId()); }
@Override public WatchesReport getWatches() { Map<Long, Set<String>> id2paths = new HashMap<Long, Set<String>>(); for (Entry<Watcher, Set<String>> e: getWatcher2PathesMap().entrySet()) { Long id = ((ServerCnxn) e.getKey()).getSessionId(); Set<String> paths = new HashSet<String>(e.getValue()); id2paths.put(id, paths); } return new WatchesReport(id2paths); }
/** * clear all the connections in the selector * */ @Override @SuppressWarnings("unchecked") public void closeAll() { // clear all the connections on which we are selecting for (ServerCnxn cnxn : cnxns) { try { // This will remove the cnxn from cnxns cnxn.close(); } catch (Exception e) { LOG.warn("Ignoring exception closing cnxn sessionid 0x" + Long.toHexString(cnxn.getSessionId()), e); } } }
@Override public synchronized void dumpWatches(PrintWriter pwriter, boolean byPath) { if (byPath) { for (Entry<String, Set<Watcher>> e : watchTable.entrySet()) { pwriter.println(e.getKey()); for (Watcher w : e.getValue()) { pwriter.print("\t0x"); pwriter.print(Long.toHexString(((ServerCnxn)w).getSessionId())); pwriter.print("\n"); } } } else { for (Entry<Watcher, Set<String>> e : watch2Paths.entrySet()) { pwriter.print("0x"); pwriter.println(Long.toHexString(((ServerCnxn)e.getKey()).getSessionId())); for (String path : e.getValue()) { pwriter.print("\t"); pwriter.println(path); } } } }
public ConnectionBean(ServerCnxn connection,ZooKeeperServer zk){ this.connection = connection; this.stats = connection; this.zk = zk; InetSocketAddress sockAddr = connection.getRemoteSocketAddress(); if (sockAddr == null) { remoteIP = "Unknown"; } else { InetAddress addr = sockAddr.getAddress(); if (addr instanceof Inet6Address) { remoteIP = ObjectName.quote(addr.getHostAddress()); } else { remoteIP = addr.getHostAddress(); } } sessionId = connection.getSessionId(); }
public void closeSession(ServerCnxn cnxn, RequestHeader requestHeader) { closeSession(cnxn.getSessionId()); }
@Override public void closeAll() { if (LOG.isDebugEnabled()) { LOG.debug("closeAll()"); } // clear all the connections on which we are selecting int length = cnxns.size(); for (ServerCnxn cnxn : cnxns) { try { // This will remove the cnxn from cnxns cnxn.close(); } catch (Exception e) { LOG.warn("Ignoring exception closing cnxn sessionid 0x" + Long.toHexString(cnxn.getSessionId()), e); } } if (LOG.isDebugEnabled()) { LOG.debug("allChannels size:" + allChannels.size() + " cnxns size:" + length); } }
@Override public void dumpWatches(PrintWriter pwriter, boolean byPath) { if (byPath) { for (Entry<String, BitHashSet> e : pathWatches.entrySet()) { pwriter.println(e.getKey()); BitHashSet watchers = e.getValue(); synchronized (watchers) { for (Integer wbit : watchers) { Watcher w = watcherBitIdMap.get(wbit); if (!(w instanceof ServerCnxn)) { continue; } pwriter.print("\t0x"); pwriter.print( Long.toHexString(((ServerCnxn)w).getSessionId())); pwriter.print("\n"); } } } } else { for (Entry<Watcher, Set<String>> e : getWatcher2PathesMap().entrySet()) { pwriter.print("0x"); pwriter.println(Long.toHexString(((ServerCnxn)e.getKey()).getSessionId())); for (String path : e.getValue()) { pwriter.print("\t"); pwriter.println(path); } } } }
public void removeCnxn(ServerCnxn cnxn) { synchronized(cnxns){ // if this is not in cnxns then it's already closed if (!cnxns.remove(cnxn)) { if (LOG.isDebugEnabled()) { LOG.debug("cnxns size:" + cnxns.size()); } return; } if (LOG.isDebugEnabled()) { LOG.debug("close in progress for sessionid:0x" + Long.toHexString(cnxn.getSessionId())); } synchronized (ipMap) { Set<NettyServerCnxn> s = ipMap.get(cnxn.getSocketAddress()); s.remove(cnxn); } } }
/** * Iterate through ConcurrentHashMap is 'safe', it will reflect the state * of the map at the time iteration began, may miss update while iterating, * given this is used in the commands to get a general idea of the watches * state, we don't care about missing some update. */ @Override public WatchesPathReport getWatchesByPath() { Map<String, Set<Long>> path2ids = new HashMap<String, Set<Long>>(); for (Entry<String, BitHashSet> e : pathWatches.entrySet()) { BitHashSet watchers = e.getValue(); synchronized (watchers) { Set<Long> ids = new HashSet<Long>(watchers.size()); path2ids.put(e.getKey(), ids); for (Integer wbit : watchers) { Watcher watcher = watcherBitIdMap.get(wbit); if (watcher instanceof ServerCnxn) { ids.add(((ServerCnxn) watcher).getSessionId()); } } } } return new WatchesPathReport(path2ids); }
void touch(ServerCnxn cnxn) throws MissingSessionException { if (cnxn == null) { return; } long id = cnxn.getSessionId(); int to = cnxn.getSessionTimeout(); if (!sessionTracker.touchSession(id, to)) { throw new MissingSessionException( "No session with sessionid 0x" + Long.toHexString(id) + " exists, probably expired and removed"); } }
public ConnectionBean(ServerCnxn connection,ZooKeeperServer zk){ this.connection = connection; this.stats = connection; this.zk = zk; InetSocketAddress sockAddr = connection.getRemoteSocketAddress(); if (sockAddr == null) { remoteIP = "Unknown"; } else { InetAddress addr = sockAddr.getAddress(); if (addr instanceof Inet6Address) { remoteIP = ObjectName.quote(addr.getHostAddress()); } else { remoteIP = addr.getHostAddress(); } } sessionId = connection.getSessionId(); }
public synchronized Map<String, Object> getConnectionInfo(boolean brief) { Map<String, Object> info = new LinkedHashMap<String, Object>(); info.put("remote_socket_address", getRemoteSocketAddress()); info.put("interest_ops", getInterestOps()); info.put("outstanding_requests", getOutstandingRequests()); info.put("packets_received", getPacketsReceived()); info.put("packets_sent", getPacketsSent()); if (!brief) { info.put("session_id", getSessionId()); info.put("last_operation", getLastOperation()); info.put("established", getEstablished()); info.put("session_timeout", getSessionTimeout()); info.put("last_cxid", getLastCxid()); info.put("last_zxid", getLastZxid()); info.put("last_response_time", getLastResponseTime()); info.put("last_latency", getLastLatency()); info.put("min_latency", getMinLatency()); info.put("avg_latency", getAvgLatency()); info.put("max_latency", getMaxLatency()); } return info; }
void touch(ServerCnxn cnxn) throws MissingSessionException { if (cnxn == null) { return; } long id = cnxn.getSessionId(); int to = cnxn.getSessionTimeout(); if (!sessionTracker.touchSession(id, to)) { throw new MissingSessionException( "No session with sessionid 0x" + Long.toHexString(id) + " exists, probably expired and removed"); } }
Long.toHexString(cnxn.getSessionId())); return KeeperException.Code.AUTHFAILED; } catch (CertificateException ce) { LOG.error("Failed to trust certificate for session 0x" + Long.toHexString(cnxn.getSessionId()), ce); return KeeperException.Code.AUTHFAILED;
: 0, valid ? cnxn.getSessionId() : 0, // send 0 if session is no valid ? generatePasswd(cnxn.getSessionId()) : new byte[16]); ByteArrayOutputStream baos = new ByteArrayOutputStream(); BinaryOutputArchive bos = BinaryOutputArchive.getArchive(baos); + Long.toHexString(cnxn.getSessionId()) + " with negotiated timeout " + cnxn.getSessionTimeout() + " for client " + Long.toHexString(cnxn.getSessionId()) + " for client " + cnxn.getRemoteSocketAddress()
/** * Checks if a session is registered with the server as a watcher. * * @param long sessionId the session ID to check * @param path the path to check for watchers * @param type the type of watcher * @return true if the client session is a watcher on path for the type */ private boolean isServerSessionWatcher(long sessionId, String path, WatcherType type) { Set<ServerCnxn> cnxns = new HashSet<>(); CollectionUtils.addAll(cnxns, serverFactory.getConnections().iterator()); for (ServerCnxn cnxn : cnxns) { if (cnxn.getSessionId() == sessionId) { return getServer(serverFactory).getZKDatabase().getDataTree() .containsWatcher(path, type, cnxn); } } return false; } }