/*
  * (non-Javadoc)
  * @see project3.RMIServerInterface#ASK(java.lang.String, java.lang.String, java.lang.String)
  * ASK method checks with the replica that the command being requested with the key and value is legitimate and acceptable to the server.
  * If the value is not being modified for the key passed in, then reject.
  * Similarly, if the key doesn't exist in the replica, then ASK would reject for this replica.
  * Enforces consistency of data in the absence of failures.
  */
 @Override
 public String ASK(String command, String key, String value) {
   if (hash.containsKey(key)) {
     String existingVal = hash.get(key);
     if (command.toUpperCase().equals("PUT"))
       if (!existingVal.equals(value)) return "ACCEPT";
       else return "REJECT";
     else return "ACCEPT";
   } else {
     if (command.toUpperCase().equals("PUT")) return "ACCEPT";
     else return "REJECT";
   }
 }
  public String GET(String clientId, String key) {
    log.info(
        "Server at "
            + hostname
            + ":"
            + port
            + " "
            + "received [GET "
            + key
            + "] from client "
            + clientId);
    String response = "";

    if (hash.containsKey(key)) response = hash.get(key);
    else {
      response = "No key " + key + " matches db ";
      log.error(response);
    }
    return response;
  }
 public String DELETE(boolean go, String clientId, String key) {
   // synchronize delete function on hash
   if (go) {
     log.info(
         "Server at "
             + hostname
             + ":"
             + port
             + " "
             + "received [DELETE "
             + key
             + "] from client "
             + clientId);
     String response = "";
     if (hash.containsKey(key)) {
       hash.remove(key);
       response = ACK;
     } else {
       response = "No such key - " + key + " exists";
       log.error(response);
     }
     return response;
   } else return TwoPCommit("DELETE", key, "") ? ACK : NACK;
 }
 /*
  * (non-Javadoc)
  * @see project3.RMIServerInterface#PUT(boolean, java.lang.String, java.lang.String, java.lang.String)
  * Two phase commit for PUT operation. Only if go is true. we would commit to disk.
  */
 public String PUT(boolean go, String clientId, String key, String value) {
   if (go) {
     log.info(
         "Server at "
             + hostname
             + ":"
             + port
             + " "
             + "received [PUT "
             + key
             + "|"
             + value.trim()
             + "] from client "
             + clientId);
     String response = "";
     // this would overwrite the values of the key
     hash.put(key, value);
     response = ACK;
     return response;
   } else return TwoPCommit("PUT", key, value) ? ACK : NACK;
 }