Java SDK Couchbase Cluster and Bucket Connectivity

Hi Team,

I am working with Couchbase SDK and I need some pointers as to check connectivity with cluster and bucket.

I am using the below code to connect to cluster and bucket.

public static void main(String args) {
Cluster cluster = Cluster.connect(host, userName, password);
System.out.println("Cluster ping : " +;
System.out.println("Cluster diagnostics : " + cluster.diagnostics());
Bucket bucket = cluster.bucket(bucketName);
System.out.println("bucket ping : " +;

Cluster ping : PingResult{endpoints={}, version=2, sdk=‘java/3.0.10 …’, id=’…’}

Cluster diagnostics : DiagnosticsResult{endpoints={KV=[EndpointDiagnostics{type=KV, state=CONNECTING, local=‘null’, remote=‘null’, lastActivityUs=Optional.empty, id=‘Optional.empty’, namespace=Optional.empty}]}, version=2, sdk=‘java/3.0.10 …’, id=’…’, state=OFFLINE}

bucket ping : PingResult{endpoints={}, version=2, sdk=‘java/3.0.10 ‘, id=’…’}

Java sdk version used = java/3.0.10

I need to check the connectivity to cluster and buckets at regular intervals. If it goes down , then I may need to log that to local log.
I checked the methods ping and diagnostics exposed by Cluster . But the method definition uses asyncCluster.
I am working with normal cluster.

I need to know if there is any custom method that I can use to check connectivity or some other options available.

Check the Java API reference for Java SDK 3.1.0. Methods ping() and diagnostics() are also available for within the Cluster and Bucket classes, unless you want to use Async API.