Example #1
0
 /**
  * Remove a peer from the list. In order to not reappear, the node is put for a certain time in a
  * cache list to keep the node removed. This method is thread-safe.
  *
  * @param remotePeer The node that should be removed
  * @param force A flag that removes a peer immediately.
  * @return True if the neighbor was removed and added to a cache list. False if peer has not been
  *     removed or is already in the peer removed temporarly list.
  */
 public boolean peerOffline(final PeerAddress remotePeer, final boolean force) {
   if (logger.isDebugEnabled()) {
     logger.debug("peer " + remotePeer + " is offline");
   }
   if (remotePeer.getID().isZero() || self().equals(remotePeer.getID())) {
     return false;
   }
   notifyPeerFail(remotePeer, force);
   Log log;
   synchronized (peerOfflineLogs) {
     log = peerOfflineLogs.get(remotePeer);
     if (log == null) {
       log = new Log();
       peerOfflineLogs.put(remotePeer, log);
     }
   }
   synchronized (log) {
     if (!force) {
       if (shouldPeerBeRemoved(log)) {
         remove(remotePeer, Reason.NOT_REACHABLE);
         return true;
       }
       log.inc();
       if (!shouldPeerBeRemoved(log)) {
         peerMapStat.removeStat(remotePeer);
         addToMaintenanceQueue(remotePeer);
         return false;
       }
     } else {
       log.set(maxFail);
     }
   }
   remove(remotePeer, Reason.NOT_REACHABLE);
   return true;
 }
Example #2
0
 public Collection<PeerAddress> peersForMaintenance() {
   Collection<PeerAddress> result = new ArrayList<PeerAddress>();
   final long now = Timings.currentTimeMillis();
   synchronized (maintenance) {
     for (Iterator<Map.Entry<PeerAddress, Long>> iterator = maintenance.entrySet().iterator();
         iterator.hasNext(); ) {
       Map.Entry<PeerAddress, Long> entry = iterator.next();
       if (entry.getValue() <= now) {
         iterator.remove();
         result.add(entry.getKey());
       }
     }
   }
   // add to maintenance queue with new timings
   for (PeerAddress peerAddress : result) {
     addToMaintenanceQueue(peerAddress);
   }
   return result;
 }
Example #3
0
 private void prepareInsertOrUpdate(PeerAddress remotePeer, boolean firstHand) {
   if (firstHand) {
     peerMapStat.setSeenOnlineTime(remotePeer);
     // get the amount of milliseconds for the online time
     long online = peerMapStat.online(remotePeer);
     // get the time we want to wait between maintenance checks
     if (maintenanceTimeoutsSeconds.length > 0) {
       int checked = peerMapStat.getChecked(remotePeer);
       if (checked >= maintenanceTimeoutsSeconds.length)
         checked = maintenanceTimeoutsSeconds.length - 1;
       long time = maintenanceTimeoutsSeconds[checked] * 1000L;
       // if we have a higer online time than the maintenance time,
       // increase checked to increase the maintenace interval.
       if (online >= time) {
         peerMapStat.incChecked(remotePeer);
       }
     }
   }
   addToMaintenanceQueue(remotePeer);
 }