use of com.aerospike.client.listener.RecordListener 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.RecordListener 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