Hello,
So you are correct the operations are asynchronous, even when you put a durability constraints in the call. (PersistTo, ReplicateTo parameters). Let me explain it.
If you look at the signature of the method, it returns an OperationFuture (a Java Future object). This means when you call this methods nothing is blocked or waits.
Then you can check what is the status of this asynchronous call using the OperationFuture, and you are right when you do this this is a blocking operation.
So what is the interest of this, look at this “code snippet”:
OperationFuture op = cb.set("mykey", myDocument, PersistTo.ONE, ReplicateTo.ONE);
// do some other operation or treatment here
// …
// then check the status
if (! op.getStatus().isSuccess()) {
System.out.println(“Key: key:”+ op.getKey() +" failed due to “+ op.getStatus().getMessage() +”. Please retry" );
}
So the benefits is that you can run the operation, and in the “same time” do other things, and then check the status of the operation.
Since the OperationFuture.get() or getStatus is synchronous, if you want to save the data in a synchronous way you can write
cb.set(“mykey”, myDocument, PersistTo.ONE, ReplicateTo.ONE).get();
but as you can guess it could have an impact on your application.
A pattern that we see quite often is a program where you inject execute many asynchronous operations. You keep a reference, for example in a list, to all the operationFuture objects, and then you check the status.
Let me know if you need more information
Regards
Tug
@tgrall