Search:

Search all manuals
Search this manual
Manual
Membase Client Library: Java
Additional Resources
Community Wiki
Community Forums
Couchbase SDKs
Parent Section
4 Membase Client Library: Java — Retrieve Operations
Chapter Sections
Chapters

4.2. Asynchronous get Methods

The asynchronous asyncGet() methods allow to retrieve a given value for a key without waiting actively for a response.

API Callclient.asyncGet(key)
Asynchronousyes
Description Get one or more key values
ReturnsFuture<Object> ( Asynchronous request value, as Object )
Arguments 
String key Document ID used to identify the value
Exceptions 
TimeoutException Value could not be retrieved

The first form of the asyncGet() method obtains a value for a given key returning a Future object so that the value can be later retrieved. For example, to get a key with a stored String value:

Future<Object> userobj =
    membase.asyncGet("samplekey");

String username;

try {
    username = userobj.get(5, TimeUnit.SECONDS);
} catch(TimeoutException e) {
    userobj.cancel(false);
}
API Callclient.asyncGet(key, transcoder)
Asynchronousyes
Description Get one or more key values
ReturnsFuture<T> ( Asynchronous request value, as Transcoded Object )
Arguments 
String key Document ID used to identify the value
Transcoder<T> transcoder Transcoder class to be used to serialize value

The second form is identical to the first, but includes the ability to use a custom transcoder on the stored value.