Hi all,
Using the java-client-2.5.2, I’m trying to do something which should be relatively simple but for some reason I am stuck. I’m creating a standard connection with the CouchbaseAsyncCluster class, getting an AsyncCluster from it, opening an AsyncBucket from that, and then trying to perform a “get” on that bucket. The problem I’m having is getting the “get” method to actually show up as an available method from the AsyncBucket.
To get started overall, I followed the general code example on the documentation for the CouchbaseAsyncCluster class and made the required modifications for the actual output of the AsyncCluster openBucket method call.
My Java class looks like this:
package com.sample;
import com.couchbase.client.java.AsyncBucket;
import com.couchbase.client.java.AsyncCluster;
import com.couchbase.client.java.CouchbaseAsyncCluster;
import com.couchbase.client.java.env.CouchbaseEnvironment;
import com.couchbase.client.java.env.DefaultCouchbaseEnvironment;
import rx.Observable;
public class CouchbaseUtil {
private static CouchbaseUtil instance = null;
private AsyncCluster asyncCluster;
private CouchbaseEnvironment couchbaseEnvironment;
private Observable asyncBucket;
private CouchbaseUtil() {
try {
this.couchbaseEnvironment = DefaultCouchbaseEnvironment.builder().kvTimeout(3000).build();
this.asyncCluster = CouchbaseAsyncCluster.fromConnectionString(this.couchbaseEnvironment, "removed for this post");
this.asyncBucket = this.asyncCluster.openBucket("generic", "generic");
} catch (Exception e) {
e.printStackTrace();
}
}
public static CouchbaseUtil getInstance() {
if (instance == null) {
instance = new CouchbaseUtil();
}
return instance;
}
public Observable<AsyncBucket> getAsyncBucket() {
return this.asyncBucket;
}
public void disconnect() {
this.asyncCluster.disconnect();
this.couchbaseEnvironment.shutdownAsync().toBlocking().single();
}
}
The line after the "this.asyncBucket = … " in the private constructor is where I’ve tried to do “this.asyncBucket.get(“documentId”)”, but no dice. The AsyncCluster.openBucket method signatures all return Observable<AsyncBucket>, which is fine but I am unsure how to unwrap or access the AsyncBucket inside of the Observable to be able to access its “get” (and other) methods. I’ve done searches on the internet to look for examples but have been miraculously unable to find any.
Am I making this too difficult on myself in some way? Is there a more preferred approach to what I’m doing?
Thanks all.