コード例 #1
0
  public boolean sendAllAccept(
      int ins_num, int income_seq, String content, ArrayList<KeyValueServerInterface> list)
      throws RemoteException {

    int count = 0;

    for (KeyValueServerInterface server : list) {

      if (server.accept(ins_num, income_seq, content) != -1) count++;
    }

    if (count > (list.size() / 2)) return true;

    return false;
  }
コード例 #2
0
  public int propose(int seq, Operation op) throws RemoteException {

    if (!work) return seq;

    boolean decided = false;

    while (!decided) {

      seq++;

      ArrayList<KeyValueServerInterface> list = getServersList();

      int count = 0;

      int max = -1;

      for (KeyValueServerInterface server : list) {

        Instance ins = server.prepare(op.op_num, seq);

        if (ins != null) {
          count++;
          if (ins.n_a > max) {

            max = ins.n_a;
            // content = ins.content;
            op.content = ins.content;
          }
        }
      }
      if (count > (list.size() / 2)) {

        if (sendAllAccept(op.op_num, seq, op.content, list)) {

          for (KeyValueServerInterface server : list) {

            server.decide(seq, op);
          }

          decided = true;
        }
      }
    }

    return seq;
  }