示例#1
0
 public C4SMsgRetrieve(ServiceId a, QoSConstraints b, int amt) {
   assert (b != null);
   svcId = a;
   constraints = b;
   amount = amt;
   span = ID.ServiceId(a);
 }
示例#2
0
  /**
   * Creates that part of the local node which answers remote requests by other nodes. Sole
   * constructor, is invoked by ChordImpl only.
   *
   * @param impl Reference on ChordImpl instance which created this object.
   * @param nodeID This node's Chord ID.
   * @param nodeURL URL, on which this node accepts connections.
   * @param references Routing table of this node.
   * @param entries Repository for entries of this node.
   * @throws IllegalArgumentException If any of the parameter has value <code>null</code>.
   */
  NodeImpl(ChordImpl impl, ID nodeID, URL nodeURL, References references, Entries entries) {

    if (impl == null
        || nodeID == null
        || nodeURL == null
        || references == null
        || entries == null) {
      throw new IllegalArgumentException(
          "Parameters of the constructor may not have a null value!");
    }

    this.logger = Logger.getLogger(NodeImpl.class.getName() + "." + nodeID.toString());

    this.impl = impl;
    this.asyncExecutor = impl.getAsyncExecutor();
    this.nodeID = nodeID;
    this.nodeURL = nodeURL;
    this.references = references;
    this.entries = entries;
    this.notifyLock = new ReentrantLock(true);

    // create endpoint for incoming connections
    this.myEndpoint = Endpoint.createEndpoint(this, nodeURL);
    this.myEndpoint.listen();
  }
示例#3
0
  /** {@inheritDoc} */
  @Override
  public final Set<Entry> retrieveEntries(ID id) throws CommunicationException {

    // Possible, but rare situation: a new node has joined which now is
    // responsible for the id!
    if (this.references.getPredecessor() != null
        && !id.isInInterval(this.references.getPredecessor().getNodeID(), this.nodeID)) {
      this.logger.fatal(
          "The rare situation has occured at time "
              + System.currentTimeMillis()
              + ", id to look up="
              + id
              + ", id of local node="
              + this.nodeID
              + ", id of predecessor="
              + this.references.getPredecessor().getNodeID());
      return this.references.getPredecessor().retrieveEntries(id);
    }

    // return entries from local repository
    // for this purpose create a copy of the Set in order to allow the
    // thread retrieving the entries to modify the Set without modifying the
    // internal Set of entries. sven
    return this.entries.getEntries(id);
  }
示例#4
0
  public static void main(String[] args) throws InterruptedException {
    de.uniba.wiai.lspi.chord.service.PropertiesLoader.loadPropertyFile();
    NotifyCallback cb = new GameCallback();

    String protocol = URL.KNOWN_PROTOCOLS.get(URL.SOCKET_PROTOCOL);
    URL localURL = null;
    try {
      localURL = new URL(protocol + "://localhost:8080/");
    } catch (MalformedURLException e) {
      throw new RuntimeException(e);
    }
    Chord chord = new de.uniba.wiai.lspi.chord.service.impl.ChordImpl();
    chord.setCallback(cb);

    try {
      chord.create(localURL);
    } catch (ServiceException e) {
      throw new RuntimeException("Could not create DHT", e);
    }
    System.out.println("heeeeeeeeeeeeeeeere");

    chord.broadcast(ID.valueOf(BigInteger.valueOf(123)), true);
  }
示例#5
0
  /**
   * Determines the closest preceding node for the given ID based on finger table, successor list,
   * and predecessor, but without testing the node's liveliness.
   *
   * @param key ID to find closest preceding node for.
   * @throws NullPointerException If ID is <code>null</code>.
   * @return Reference on closest preceding node.
   */
  final synchronized Node getClosestPrecedingNode(ID key) {

    if (key == null) {
      NullPointerException e = new NullPointerException("ID may not be null!");
      this.logger.error("Null pointer", e);
      throw e;
    }

    Map<ID, Node> foundNodes = new HashMap<ID, Node>();
    // determine closest preceding reference of finger table
    Node closestNodeFT = this.fingerTable.getClosestPrecedingNode(key);
    if (closestNodeFT != null) {
      foundNodes.put(closestNodeFT.getNodeID(), closestNodeFT);
    }

    // determine closest preceding reference of successor list
    Node closestNodeSL = this.successorList.getClosestPrecedingNode(key);
    if (closestNodeSL != null) {
      foundNodes.put(closestNodeSL.getNodeID(), closestNodeSL);
    }

    // predecessor is appropriate only if it precedes the given id
    Node predecessorIfAppropriate = null;
    if (this.predecessor != null && key.isInInterval(this.predecessor.getNodeID(), this.localID)) {
      predecessorIfAppropriate = this.predecessor;
      foundNodes.put(this.predecessor.getNodeID(), predecessor);
    }

    // with three references which may be null, there are eight (8) cases we
    // have to enumerate...
    Node closestNode = null;
    List<ID> orderedIDList = new ArrayList<ID>(foundNodes.keySet());
    orderedIDList.add(key);
    int sizeOfList = orderedIDList.size();
    // size of list must be greater than one to not only contain the key.
    // if (sizeOfList > 1) {

    /*
     * Sort list in ascending order
     */
    Collections.sort(orderedIDList);
    /*
     * The list item with one index lower than that of the key must be the
     * id of the closest predecessor or the key.
     */
    int keyIndex = orderedIDList.indexOf(key);
    /*
     * As all ids are located on a ring if the key is the first item in the
     * list we have to select the last item as predecessor with help of this
     * calculation.
     */
    int index = (sizeOfList + (keyIndex - 1)) % sizeOfList;
    /*
     * Get the references to the node from the map of collected nodes.
     */
    ID idOfclosestNode = orderedIDList.get(index);
    closestNode = foundNodes.get(idOfclosestNode);
    if (closestNode == null) {
      throw new NullPointerException("closestNode must not be null!");
    }

    /*
     * Following code is too complicated.
     */
    // if (closestNodeFT == null) {
    // if (closestNodeSL == null) {
    // if (predecessorIfAppropriate == null) {
    // // no reference is appropriate
    // closestNode = null;
    // } else {
    // // only predecessor is appropriate (case should not occur,
    // // but anyway...
    // closestNode = predecessorIfAppropriate;
    // }
    // } else {
    // if (predecessorIfAppropriate == null) {
    // // only reference of successor list is appropriate
    // closestNode = closestNodeSL;
    // } else {
    // // either predecessor or reference of successor list is
    // // appropriate; determine one of both
    // if (predecessorIfAppropriate.nodeID.isInInterval(
    // closestNodeSL.nodeID, key)) {
    // closestNode = predecessorIfAppropriate;
    // } else {
    // closestNode = closestNodeSL;
    // }
    // }
    // }
    // } else {
    // if (closestNodeSL == null) {
    // if (predecessorIfAppropriate == null) {
    // // only reference of finger table is appropriate
    // closestNode = closestNodeFT;
    // } else {
    // // either predecessor or reference of finger table is
    // // appropriate; determine one of both
    // if (predecessorIfAppropriate.nodeID.isInInterval(
    // closestNodeFT.nodeID, key)) {
    // closestNode = predecessorIfAppropriate;
    // } else {
    // closestNode = closestNodeFT;
    // }
    // }
    // } else {
    // if (predecessorIfAppropriate == null) {
    // // either reference of successor list or reference of finger
    // // table is appropriate; determine one of both
    // if (closestNodeSL.nodeID.isInInterval(closestNodeFT.nodeID,
    // key)) {
    // closestNode = closestNodeSL;
    // } else {
    // closestNode = closestNodeFT;
    // }
    // } else {
    // // either of the three reference is appropriate; determine
    // // first one of the references of successor list and finger
    // // table is more appropriate and afterwards compare with
    // // predecessor
    // if (closestNodeSL.nodeID.isInInterval(closestNodeFT.nodeID,
    // key)) {
    // if (predecessorIfAppropriate.nodeID.isInInterval(
    // closestNodeSL.nodeID, key)) {
    // closestNode = predecessorIfAppropriate;
    // } else {
    // closestNode = closestNodeSL;
    // }
    // } else {
    // if (predecessorIfAppropriate.nodeID.isInInterval(
    // closestNodeFT.nodeID, key)) {
    // closestNode = predecessorIfAppropriate;
    // } else {
    // closestNode = closestNodeFT;
    // }
    // }
    // }
    // }
    // }
    if (this.logger.isEnabledFor(DEBUG)) {
      this.logger.debug(
          "Closest preceding node of ID "
              + key
              + " at node "
              + this.localID.toString()
              + " is "
              + closestNode.getNodeID()
              + " with closestNodeFT="
              + (closestNodeFT == null ? "null" : "" + closestNodeFT.getNodeID())
              + " and closestNodeSL="
              + (closestNodeSL == null ? "null" : "" + closestNodeSL.getNodeID())
              + " and predecessor (only if it precedes given ID)="
              + (predecessorIfAppropriate == null
                  ? "null"
                  : "" + predecessorIfAppropriate.getNodeID()));
    }
    return closestNode;
  }