/** * Checks if this peer has been removed. A peer that has been removed will be stored in a cache * list for a certain time. This method is tread-safe * * @param node The node to check * @return True if the peer has been removed recently */ public boolean isPeerRemovedTemporarly(PeerAddress remotePeer) { Log log; synchronized (peerOfflineLogs) { log = peerOfflineLogs.get(remotePeer); } if (log != null) { synchronized (log) { if (shouldPeerBeRemoved(log)) return true; else if (Timings.currentTimeMillis() - log.getLastOffline() > cacheTimeout) { // remove the peer if timeout occured synchronized (peerOfflineLogs) { peerOfflineLogs.remove(remotePeer); } } } } return false; }
private boolean shouldPeerBeRemoved(Log log) { return Timings.currentTimeMillis() - log.getLastOffline() <= cacheTimeout && log.getCounter() >= maxFail; }