Exemplo n.º 1
0
  public void runQuery() {

    String binName = "bin1";

    Statement stmt = new Statement();
    stmt.setNamespace("test");
    stmt.setSetName("demo");
    stmt.setBinNames(binName);
    // stmt.setFilters(Filter.range(binName, begin, end));

    final AtomicInteger count = new AtomicInteger();

    aclient.query(
        null,
        new RecordSequenceListener() {
          public void onRecord(Key key, Record record) throws AerospikeException {

            System.out.printf(
                "Record found: ns=%s set=%s bin=%s digest=%s value=%s\n",
                key.namespace, key.setName, binName, Buffer.bytesToHexString(key.digest), record);

            count.incrementAndGet();
          }

          public void onSuccess() {}

          public void onFailure(AerospikeException e) {

            System.out.printf("Query failed: " + Util.getErrorMessage(e));
            // notifyComplete();
          }
        },
        stmt);
  }
Exemplo n.º 2
0
  public void awrite(Profile profile) {

    com.aerospike.client.Key key = new com.aerospike.client.Key("test", "demo", profile.getId());
    Bin bin1 = new Bin("bin1", profile.toJSon());

    aclient.put(
        null,
        new WriteListener() {
          @Override
          public void onSuccess(Key key) {}

          @Override
          public void onFailure(AerospikeException e) {}
        },
        key,
        bin1);
  }
  private void writeUsingUdfAsync(final AsyncClient client, final Parameters params) {
    final Key key = new Key(params.namespace, params.set, "audfkey1");
    final Bin bin = new Bin(params.getBinName("audfbin1"), "string value");

    console.info(
        "Write with udf: namespace=%s set=%s key=%s value=%s",
        key.namespace, key.setName, key.userKey, bin.value);

    client.execute(
        params.writePolicy,
        new ExecuteListener() {

          public void onSuccess(final Key key, final Object obj) {
            try {
              // Write succeeded.  Now call read using udf.
              console.info(
                  "Get: namespace=%s set=%s key=%s", key.namespace, key.setName, key.userKey);

              client.execute(
                  params.writePolicy,
                  new ExecuteListener() {

                    public void onSuccess(final Key key, final Object received) {
                      Object expected = bin.value.getObject();

                      if (received != null && received.equals(expected)) {
                        console.info(
                            "Data matched: namespace=%s set=%s key=%s bin=%s value=%s",
                            key.namespace, key.setName, key.userKey, bin.name, received);
                      } else {
                        console.error(
                            "Data mismatch: Expected %s. Received %s.", expected, received);
                      }
                      notifyCompleted();
                    }

                    public void onFailure(AerospikeException e) {
                      console.error(
                          "Failed to get: namespace=%s set=%s key=%s exception=%s",
                          key.namespace, key.setName, key.userKey, e.getMessage());
                      notifyCompleted();
                    }
                  },
                  key,
                  "record_example",
                  "readBin",
                  Value.get(bin.name));
            } catch (Exception e) {
              console.error(
                  "Failed to read: namespace=%s set=%s key=%s exception=%s",
                  key.namespace, key.setName, key.userKey, e.getMessage());
            }
          }

          public void onFailure(AerospikeException e) {
            console.error(
                "Failed to write: namespace=%s set=%s key=%s exception=%s",
                key.namespace, key.setName, key.userKey, e.getMessage());
            notifyCompleted();
          }
        },
        key,
        "record_example",
        "writeBin",
        Value.get(bin.name),
        bin.value);
  }