Exemple #1
0
 /**
  * Determines if the given reference is contained in any one data structure, ie. finger table,
  * successor list, or predecessor reference.
  *
  * @param newReference Reference to look up.
  * @throws NullPointerException If given reference is <code>null</code>.
  * @return <code>true</code> if the reference is contained and <code>false</code> if not.
  */
 final synchronized boolean containsReference(Node newReference) {
   if (newReference == null) {
     NullPointerException e = new NullPointerException("Reference to look up must not be null!");
     this.logger.error("Null pointer", e);
     throw e;
   }
   return (this.fingerTable.containsReference(newReference)
       || this.successorList.containsReference(newReference)
       || newReference.equals(this.predecessor));
 }
Exemple #2
0
  /**
   * Sets the given reference as this node's predecessor. If the former value of this predecessor's
   * node was <code>null</code> and if this reference is not used any more (eg. in finger table or
   * successor list), the connection to it is closed.
   *
   * @param potentialPredecessor Reference on the node to be set as new predecessor; may not be null
   * @throws NullPointerException If potential predecessor is null.
   */
  final synchronized void setPredecessor(Node potentialPredecessor) {

    if (potentialPredecessor == null) {
      NullPointerException e =
          new NullPointerException(
              "Potential predecessor of method setPredecessor may not be " + "null!");
      this.logger.error("Null pointer", e);
      throw e;
    }
    this.checkIfProxy(potentialPredecessor);

    boolean info = this.logger.isEnabledFor(INFO);
    if (!(potentialPredecessor.equals(this.predecessor))) {
      Node formerPredecessor = this.predecessor;
      this.predecessor = potentialPredecessor;
      if (formerPredecessor != null) {
        this.disconnectIfUnreferenced(formerPredecessor);
        /*
         * The replicas, which are in the range between the old and the
         * new predecessor, on the last successor of this node have to
         * be removed if the successor list is full. => capacity of sl ==
         * length of sl.
         */
        int sLSize = this.successorList.getSize();
        if (this.successorList.getCapacity() == sLSize) {
          Node lastSuccessor = this.successorList.getReferences().get(sLSize - 1);
          try {
            lastSuccessor.removeReplicas(this.predecessor.getNodeID(), new HashSet<Entry>());
          } catch (CommunicationException e) {
            logger.warn("Could not remove replicas on last predecessor", e);
          }
        }
        if (this.logger.isEnabledFor(DEBUG)) {
          this.logger.debug(
              "Old predecessor " + formerPredecessor + " was replaced by " + potentialPredecessor);
        }
      } else {
        if (info) {
          this.logger.info(
              "Predecessor reference set to " + potentialPredecessor + "; was null before.");
        }
        Set<Entry> entriesToRep =
            this.entries.getEntriesInInterval(this.predecessor.getNodeID(), this.localID);
        List<Node> successors = this.successorList.getReferences();
        for (Node successor : successors) {
          try {
            successor.insertReplicas(entriesToRep);
          } catch (CommunicationException e) {
            this.logger.warn("Damn. Could not replicate to successor " + successor.getNodeID(), e);
          }
        }
      }
    }
  }
Exemple #3
0
  /**
   * Removes the given node reference from the finger table and the successor list. If the given
   * reference is the current predecessor, the predecessor reference will be <code>null</code>
   * afterwards.
   *
   * @param oldReference Reference to remove from ALL data structures.
   * @throws NullPointerException If reference to remove is <code>null</code>.
   */
  final synchronized void removeReference(Node oldReference) {

    if (oldReference == null) {
      NullPointerException e = new NullPointerException("Reference to remove must not be null!");
      this.logger.error("Null pointer", e);
      throw e;
    }

    this.fingerTable.removeReference(oldReference);
    this.successorList.removeReference(oldReference);

    if (oldReference.equals(this.getPredecessor())) {
      this.predecessor = null;
    }

    disconnectIfUnreferenced(oldReference);

    if (this.logger.isEnabledFor(DEBUG)) {
      this.logger.debug(
          "Attempted to remove reference "
              + oldReference
              + " from all data structures including predecessor reference.");
    }
  }