Search:

Search all manuals
Search this manual
Manual
Membase Client Library: Java
Additional Resources
Community Wiki
Community Forums
Couchbase SDKs
Parent Section
2 Membase Client Library: Java Method Summary
Chapter Sections
Chapters

2.2. Asynchronous Method Calls

In addition, the spymemcached library also supports a range of asynchronous methods that can be used to store, update and retrieve values without having to explicitly wait for a response.

The asynchronous methods use a Java standard Future object which is returned by the initial method call for the operation. The communication with the Membase server will continue in the background so that the main program loop can continue. You can recover the status of the operation by using a method to check the status on the returned Future object. For example, rather than synchronously getting a key, an asynchronous call might look like this:

Future<Object> future = membase.asyncGet("someKey");

This will populate the Future object future with the response from the server. The Future object class is defined here. The primary methods are:

For example, you can use the timeout method to obtain the value or cancel the operation:

Future<Object> future = membase.asyncGet("someKey");

Object myObj;

try {
    myObj = future.get(5, TimeUnit.SECONDS);
} catch(TimeoutException e) {
    future.cancel(false);
}

Alternatively, you can wait for a response by using the get() method:

Object myObj;

myObj = future.get();