public void dump() throws RemoteException {
    int num_ins = instances.size();

    System.out.println(getServerName() + ":");

    for (int i = 1; i <= num_ins; i++) {
      Instance tmp = instances.get(i);

      System.out.println(i + ": " + tmp.toString());
    }

    return;
  }
  public int accept(int ins_num, int income_seq, String content) throws RemoteException {
    if (!work) return -1;

    Instance res = instances.get(ins_num);

    if (res == null) return -1;
    else {

      if (income_seq >= res.n_p) {

        res.n_p = income_seq;

        res.n_a = income_seq;

        res.content = content;

        res.decided = true;

        INS_NUM++;

        return income_seq;
      }
    }

    return -1;
  }
  public KeyValueServerInterfaceImpl(String server_name, int instance_capibility)
      throws RemoteException {
    this.server_name = server_name;
    // loghelper = new LogHelper(server_name+"_log");
    INS_NUM = 0;

    work = true;

    for (int i = 1; i <= instance_capibility; i++) instances.put(new Integer(i), new Instance());
  }
  public Instance prepare(int ins_num, int income_seq) throws RemoteException {
    if (!work) return null;

    Instance res = instances.get(ins_num);

    if (res == null) return null;
    else {

      if (income_seq > res.n_p) {

        res.n_p = income_seq;

        return res;
      } else return null;
    }
  }
  public void decide(int income_seq, Operation op) throws RemoteException {

    // set corresponding Op decided, assume no collision happens

    if (!work) return;

    if (op == null) return;

    Instance ins = instances.get(op.op_num);

    if (!ins.decided) {

      ins.decided = true;

      INS_NUM++;

      ins.n_a = income_seq;

      ins.content = op.content;
    }

    return;
  }