The project I work on uses astyanax driver to access Cassandra. I want to implement an asynchronous operation:
MutationBatch m;
//…
ListenableFuture<OperationResult<Void>> lf = m.executeAsync();
lf.addListener(myRunnableCallback, myExecutor);
Question: assuming the exception was not thrown right away within executeAsync()
call, how do I distinguish between successful and failed executions?
The only way I can think of is that when the completion callback is invoked lf.get()
throws an exception in case of failure. If this is the right way, is there a document or lines in astyanax sources confirming that?
I found a workaround: instead of ListenableFuture
's addListener
method taking Runnable
parameter I can use Futures.addCallback(ListenableFuture<V>, FutureCallback<V>, Executor)
. FutureCallback
has 2 methods: onSuccess
and onFailure
. That solves my problem.
https://code.google.com/p/guava-libraries/wiki/ListenableFutureExplained