Пример #1
0
  /**
   * Routes the messages if the next hop has been set up.
   *
   * <p>Note, this once lived in the RouteMessaage
   *
   * @param localId the node id of the local node.
   * @return true if the message got routed, false otherwise.
   */
  public boolean routeMessage(RouteMessage rm) {
    if (logger.level <= Logger.FINER) logger.log("routeMessage(" + rm + ")");
    if (rm.getNextHop() == null) return false;
    rm.setSender(thePastryNode.getLocalHandle());

    NodeHandle handle = rm.getNextHop();
    rm.setNextHop(null);
    rm.setPrevNode(thePastryNode.getLocalHandle());

    if (thePastryNode.getLocalHandle().equals(handle)) {
      // the local node is the closest node to the id
      if (rm.getDestinationHandle() != null
          && !rm.getDestinationHandle().equals(thePastryNode.getLocalHandle())) {
        // no idea how to contact the destination, drop
        if (logger.level <= Logger.FINE)
          logger.log(
              "Message "
                  + rm
                  + " has destination "
                  + rm.getDestinationHandle()
                  + " but I'm the root of the id.  Dropping.  This could happen if the destination has died while the route message was in transit, or if the local node does not yet have logging state because it is boostrapping.");

        rm.sendFailed(new NoRouteToHostException(rm.getDestinationHandle().toString()));
        return true;
      }
      thePastryNode.receiveMessage(rm.internalMsg);
      rm.sendSuccess(thePastryNode.getLocalHandle());
    } else {
      sendTheMessage(rm, handle);
    }
    return true;
  }