Ejemplo n.º 1
0
 static void invalidate(H2ONode h2o, Key key, Value newval, Futures fs) {
   assert newval._key != null && key.home();
   // Prevent the new Value from being overwritten by Yet Another PUT by
   // read-locking it.  It's safe to read, but not to over-write, until this
   // invalidate completes on the *prior* value.
   newval.read_lock(); // block further writes until all invalidates complete
   fs.add(RPC.call(h2o, new TaskInvalidateKey(key, newval)));
 }
Ejemplo n.º 2
0
  /**
   * Description: Here we are making our remote procedure call specifically using Pandora's JSON
   * protocol. This will return a JSONObject holding the contents of the results key in the
   * response. If an error occurs (ie "stat":"fail") an exception with the message body will be
   * thrown. Caution: When debugging, be sure to note that most data that flows through here is time
   * sensitive, and if stopped in the wrong places, it will cause "stat":"fail" responses from the
   * remote server.
   */
  private JSONObject doCall(
      String method,
      Map<String, Object> json_params,
      boolean http_secure_flag,
      boolean encrypt,
      Map<String, String> opt_url_params)
      throws Exception, RPCException, IOException, HttpResponseException {
    JSONObject response = null;
    JSONObject request = null;
    if (json_params != null) {
      request = new JSONObject(json_params);
    } else {
      request = new JSONObject();
    }

    Map<String, String> url_params = new HashMap<String, String>(standard_url_params);
    url_params.put("method", method);
    if (opt_url_params != null) {
      url_params.putAll(opt_url_params);
    }

    if (user_auth_token != null) {
      request.put("userAuthToken", user_auth_token);
    }
    if (sync_time != 0) {
      request.put("syncTime", calcSync());
    }

    String request_string = request.toString();
    if (encrypt) {
      request_string = this.pandoraEncrypt(request_string);
    }

    String response_string = pandora_rpc.call(url_params, request_string, http_secure_flag);
    response = new JSONObject(response_string);
    if (response.getString("stat").compareTo("ok") != 0) {
      if (response.getString("stat").compareTo("fail") == 0) {
        throw new RPCException(response.getInt("code"), response.getString("message"));
      } else {
        throw new Exception("RPC unknown error. stat: " + response.getString("stat"));
      }
    }

    return response.getJSONObject("result"); // Exception thrown if nonexistent
  }