示例#1
0
 /**
  * Send a specific message to the supplied role.
  *
  * @param destination Destination role
  * @param msg Message to send
  */
 public void send(PaxosRole destination, PaxosMessage msg) {
   StaticNetwork.Route route = network.getRoute(destination.getID());
   if (route != null) {
     msg.setDestination(destination.getType());
     pipeline.startClient(route.ip, route.port, msg);
   }
 }
示例#2
0
  /**
   * Multi-cast a message to all nodes with a specific role.
   *
   * @param role Destination role
   * @param msg Message to send
   * @param expected Number of nodes to multicast
   * @return Success code
   */
  public int multicast(PaxosRole.Role role, PaxosMessage msg, int expected) {
    // Get all the nodes in the network.
    Map<String, StaticNetwork.Route> routes = network.getAllRoutes();

    int i = 0;
    for (String id : routes.keySet()) {

      if (!id.equals(home)) {
        // Make sure that we are not sending to a client.
        if (role != PaxosRole.Role.CLIENT && !network.isClientConnection(id)) {
          StaticNetwork.Route route = routes.get(id);

          msg.setDestination(role);
          pipeline.startClient(route.ip, route.port, msg);

          // Increment the number of messages sent.
          ++i;
        }
      }

      // Only send the minimum necessary.
      if (i == expected) {
        break;
      }
    }

    return PaxosCommunicator.SUCCESS;
  }
示例#3
0
  /**
   * Send a message to a non-specific node with the specified role. Usually this means sending to a
   * local role on the same node, unless the sending role is already on the node.
   */
  public void send(PaxosRole sender, PaxosRole.Role role, PaxosMessage msg) {
    // Ask the network for the "desired" target. Depending on the
    // network implementation, this could be the "leader", etc.
    StaticNetwork.Route route = network.getDesirable(home);

    if (route != null) {
      msg.setDestination(role);
      pipeline.startClient(route.ip, route.port, msg);
    }
  }