Reputation: 91
I need to use asynchronous queries using Spring framework. I use Cassandra and Java driver from Datastax. How can call the executeAsync method and get the results.
Upvotes: 2
Views: 1582
Reputation: 3784
I have in mind 3 possible solutions:
executeAsync
returns ResultSetFuture
which has isDone
method, you can have while loop with
!isDoneand jump to some block when it returns
truein
isDone`addListener
in ResultSetFuture
so you can register listener to be fired after Future
computation is doneRegisters a listener to be run on the given executor. The listener will run when the Future's computation is complete or, if the computation is already complete, immediately.
ListenableFuture
from the Guava library since which ResultSetFuture
extends like explained in this stackoverflow question I think 3rd option is way to go and cleanest.
Upvotes: 2