Search:

Search all manuals
Search this manual
Manual
Couchbase Client Library: Java 1.0
Community Wiki and Resources
Wiki: Java Client Library
Download Client Library
JavaDoc
Java Client Library
SDK Forum
Additional Resources
Community Wiki
Community Forums
Couchbase SDKs
Parent Section
7 Retrieve Operations
Chapter Sections
Chapters

7.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:

GetFuture<Object> getOp =
    client.asyncGet("samplekey");

String username;

try {
    username = (String) getOp.get(5, TimeUnit.SECONDS);
} catch(Exception e) {
    getOp.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.