V
- the (response) return typeT
- The query info typepublic interface RiakFuture<V,T> extends Future<V>
All Riak operations are asynchronous. It means when you execute an operation on
the cluster it will return immediately with no guarantee that the requested
operation has been completed at the end of the call. Instead, you will be returned
a RiakFuture
instance which gives you the information about the result
or status of the operation.
A RiakFuture
is either uncompleted or completed. When an operation begins, a new future
object is created. The new future is uncompleted initially - it is neither
succeeded, failed, nor canceled because the operation is not finished yet.
If the operation is finished either successfully, with failure, or by cancellation,
the future is marked as completed with more specific information, such as the
cause of the failure. Please note that even failure and cancellation belong to the completed state.
+---------------------------+ | Completed successfully | +---------------------------+ +----> isDone() = true | +--------------------------+ | | isSuccess() = true | | Uncompleted | | +===========================+ +--------------------------+ | | Completed with failure | | isDone() = false | | +---------------------------+ | isSuccess() = false |----+----> isDone() = true | | isCancelled() = false | | | isSuccess() = false | | cause() = null | | | cause() = non-null | +--------------------------+ | +===========================+ | | Completed by cancellation | | +---------------------------+ +----> isDone() = true | | isCancelled() = true | +---------------------------+
The typical use pattern is to call await(), check isSuccess() then call getNow() or cause()
Modifier and Type | Method and Description |
---|---|
void |
addListener(RiakFutureListener<V,T> listener)
Add a listener to this RiakFuture.
|
void |
await()
Waits for this RiakFuture to be completed.
|
void |
await(long timeout,
TimeUnit unit)
Waits for this RiakFuture to be completed for a set amount of time.
|
boolean |
cancel(boolean mayInterruptIfRunning)
Not supported due to limitations of the Riak API.
|
Throwable |
cause()
Return information about the operation and why it failed.
|
V |
get()
Waits for this RiakFuture to be completed if necessary and returns the response if available.
|
V |
get(long timeout,
TimeUnit unit)
Waits if necessary for at most the given time for the computation
to complete, and then retrieves its result, if available.
|
V |
getNow()
Return the result without blocking or throwing an exception.
|
T |
getQueryInfo()
Returns information related to the operation performed.
|
boolean |
isCancelled() |
boolean |
isDone() |
boolean |
isSuccess()
Determine if the operation completed successfully.
|
void |
removeListener(RiakFutureListener<V,T> listener)
Remove a listener from this RiakFuture.
|
boolean cancel(boolean mayInterruptIfRunning)
At present time there is no way to cancel an operation sent to Riak. This method will never succeed and always return false.
V get() throws InterruptedException, ExecutionException
get
in interface Future<V>
InterruptedException
- if the current thread was interrupted
while waitingExecutionException
- if the computation threw an
exceptionV get(long timeout, TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException
Note that the timeout value here is how long you are willing to wait for this RiakFuture to complete. If you wish to set a timeout on the command itself, use the timeout() method provided in the command's associated builder.
get
in interface Future<V>
timeout
- the amount of time to wait before returning.unit
- the unit of time.InterruptedException
- if the current thread was interrupted
while waiting.ExecutionException
- if the computation threw an
exception.TimeoutException
- if the wait timed out.boolean isCancelled()
isCancelled
in interface Future<V>
void await() throws InterruptedException
Upon returning, the operation has completed. Checking isSuccess() tells you if it did so successfully.
InterruptedException
- if the current thread was interrupted
while waitingRiakFuture.isSuccess()
void await(long timeout, TimeUnit unit) throws InterruptedException
Note that the timeout value here is how long you are willing to wait for this RiakFuture to complete. Upon return you can check isDone() to see if the future has completed yet or not. The operation is still in progress if that returns false.
If you wish to set a timeout on the command itself, use the timeout() method provided in the command's associated builder.
timeout
- the amount of time to wait before returning.unit
- the unit of time.InterruptedException
- if the current thread was interrupted
while waitingRiakFuture.isDone()
,
RiakFuture.isSuccess()
V getNow()
RiakFuture.isDone()
and not rely on the returned null value.RiakFuture.isDone()
,
RiakFuture.isSuccess()
boolean isSuccess()
Throwable cause()
Note this will return null if the operation completed successfully.
RiakFuture.isSuccess()
T getQueryInfo()
Useful in async operations when you want to know what operation this future refers to.
void addListener(RiakFutureListener<V,T> listener)
listener
- a FiakFutureListener that will be notified when this RiakFuture completes.void removeListener(RiakFutureListener<V,T> listener)
listener
- The listener to remove.Copyright © 2014. All rights reserved.