use of com.aerospike.client.listener.WriteListener in project aerospike-client-java by aerospike.
the class TestAsyncQuery method asyncQuery.
@Test
public void asyncQuery() {
final AtomicInteger count = new AtomicInteger();
for (int i = 1; i <= size; i++) {
final Key key = new Key(args.namespace, args.set, keyPrefix + i);
Bin bin = new Bin(binName, i);
client.put(eventLoop, new WriteListener() {
public void onSuccess(final Key key) {
if (count.incrementAndGet() == size) {
runQuery();
}
}
public void onFailure(AerospikeException e) {
setError(e);
notifyComplete();
}
}, null, key, bin);
}
waitTillComplete();
}
use of com.aerospike.client.listener.WriteListener in project aerospike-client-java by aerospike.
the class AsyncPutGet method runPutGetInline.
// Inline asynchronous put/get calls.
private void runPutGetInline(final AerospikeClient client, final EventLoop eventLoop, final Key key, final Bin bin) {
console.info("Put: namespace=%s set=%s key=%s value=%s", key.namespace, key.setName, key.userKey, bin.value);
client.put(eventLoop, new WriteListener() {
public void onSuccess(final Key key) {
try {
// Write succeeded. Now call read.
console.info("Get: namespace=%s set=%s key=%s", key.namespace, key.setName, key.userKey);
client.get(eventLoop, new RecordListener() {
public void onSuccess(final Key key, final Record record) {
validateBin(key, bin, record);
notifyComplete();
}
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());
notifyComplete();
}
}, policy, key);
} catch (Exception e) {
console.error("Failed to get: 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 put: namespace=%s set=%s key=%s exception=%s", key.namespace, key.setName, key.userKey, e.getMessage());
notifyComplete();
}
}, writePolicy, key, bin);
}
use of com.aerospike.client.listener.WriteListener in project aerospike-client-java by aerospike.
the class AsyncQuery method runQueryExample.
private void runQueryExample(final AerospikeClient client, final EventLoop eventLoop, final String keyPrefix, final String binName, final int size) {
console.info("Write " + size + " records.");
final AtomicInteger count = new AtomicInteger();
for (int i = 1; i <= size; i++) {
final Key key = new Key(params.namespace, params.set, keyPrefix + i);
Bin bin = new Bin(binName, i);
client.put(eventLoop, new WriteListener() {
public void onSuccess(final Key key) {
if (count.incrementAndGet() == size) {
runQuery(client, eventLoop, binName);
}
}
public void onFailure(AerospikeException e) {
console.error("Failed to put: namespace=%s set=%s key=%s exception=%s", key.namespace, key.setName, key.userKey, e.getMessage());
notifyComplete();
}
}, writePolicy, key, bin);
}
}
use of com.aerospike.client.listener.WriteListener in project aerospike-client-java by aerospike.
the class TestAsyncPutGet method asyncPutGetInline.
@Test
public void asyncPutGetInline() {
final Key key = new Key(args.namespace, args.set, "putgetkey1");
final Bin bin = new Bin(binName, "value");
client.put(eventLoop, new WriteListener() {
public void onSuccess(final Key key) {
try {
// Write succeeded. Now call read.
client.get(eventLoop, new RecordListener() {
public void onSuccess(final Key key, final Record record) {
assertBinEqual(key, record, bin);
notifyComplete();
}
public void onFailure(AerospikeException e) {
setError(e);
notifyComplete();
}
}, null, key);
} catch (Exception e) {
setError(e);
notifyComplete();
}
}
public void onFailure(AerospikeException e) {
setError(e);
notifyComplete();
}
}, null, key, bin);
waitTillComplete();
}
Aggregations