Search in sources :

Example 1 with RecordListener

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);
}
Also used : AerospikeException(com.aerospike.client.AerospikeException) RecordListener(com.aerospike.client.listener.RecordListener) Record(com.aerospike.client.Record) WriteListener(com.aerospike.client.listener.WriteListener) Key(com.aerospike.client.Key) IOException(java.io.IOException) ConnectException(java.net.ConnectException) AerospikeException(com.aerospike.client.AerospikeException)

Example 2 with RecordListener

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();
}
Also used : AerospikeException(com.aerospike.client.AerospikeException) Bin(com.aerospike.client.Bin) RecordListener(com.aerospike.client.listener.RecordListener) Record(com.aerospike.client.Record) WriteListener(com.aerospike.client.listener.WriteListener) Key(com.aerospike.client.Key) IOException(java.io.IOException) ConnectException(java.net.ConnectException) AerospikeException(com.aerospike.client.AerospikeException) Test(org.junit.Test)

Aggregations

AerospikeException (com.aerospike.client.AerospikeException)2 Key (com.aerospike.client.Key)2 Record (com.aerospike.client.Record)2 RecordListener (com.aerospike.client.listener.RecordListener)2 WriteListener (com.aerospike.client.listener.WriteListener)2 IOException (java.io.IOException)2 ConnectException (java.net.ConnectException)2 Bin (com.aerospike.client.Bin)1 Test (org.junit.Test)1