T
- The type the operation returnsU
- The protocol type returnedS
- Query info typepublic abstract class FutureOperation<T,U,S> extends Object implements RiakFuture<T,S>
Constructor and Description |
---|
FutureOperation() |
Modifier and Type | Method and Description |
---|---|
void |
addListener(RiakFutureListener<T,S> listener)
Add a listener to this RiakFuture.
|
void |
await()
Waits for this RiakFuture to be completed.
|
boolean |
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.
|
Object |
channelMessage() |
protected U |
checkAndGetSingleResponse(List<U> responses) |
protected abstract T |
convert(List<U> rawResponse) |
protected abstract RiakMessage |
createChannelMessage() |
protected abstract U |
decode(RiakMessage rawMessage) |
protected boolean |
done(U message)
Detect when the streaming operation is finished
|
T |
get()
Waits for this RiakFuture to be completed if necessary and returns the response if available.
|
T |
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.
|
T |
getNow()
Return the result without blocking or throwing an exception.
|
abstract S |
getQueryInfo()
Returns information related to the operation performed.
|
boolean |
isCancelled() |
boolean |
isDone() |
boolean |
isSuccess()
Determine if the operation completed successfully.
|
protected void |
processBatchMessage(U decodedMessage) |
protected void |
processMessage(U decodedMessage) |
void |
removeListener(RiakFutureListener<T,S> listener)
Remove a listener from this RiakFuture.
|
void |
setComplete() |
void |
setResponse(RiakMessage rawResponse) |
public void addListener(RiakFutureListener<T,S> listener)
RiakFuture
addListener
in interface RiakFuture<T,S>
listener
- a RiakFutureListener that will be notified when this RiakFuture completes.public void removeListener(RiakFutureListener<T,S> listener)
RiakFuture
removeListener
in interface RiakFuture<T,S>
listener
- The listener to remove.public final void setResponse(RiakMessage rawResponse)
protected void processMessage(U decodedMessage)
protected void processBatchMessage(U decodedMessage)
public final void setComplete()
protected boolean done(U message)
message
- raw messagepublic final Object channelMessage()
public final boolean cancel(boolean mayInterruptIfRunning)
RiakFuture
At present time there is no way to cancel an operation sent to Riak. This method will never succeed and always return false.
public final boolean isCancelled()
isCancelled
in interface RiakFuture<T,S>
isCancelled
in interface Future<T>
public final boolean isDone()
public final boolean isSuccess()
RiakFuture
isSuccess
in interface RiakFuture<T,S>
public final Throwable cause()
RiakFuture
Note this will return null if the operation completed successfully.
cause
in interface RiakFuture<T,S>
RiakFuture.isSuccess()
public final T get() throws InterruptedException, ExecutionException
RiakFuture
get
in interface RiakFuture<T,S>
get
in interface Future<T>
InterruptedException
- if the current thread was interrupted
while waitingExecutionException
- if the computation threw an
exceptionpublic final T get(long timeout, TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException
RiakFuture
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 RiakFuture<T,S>
get
in interface Future<T>
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.public final T getNow()
RiakFuture
RiakFuture.isDone()
and not rely on the returned null value.getNow
in interface RiakFuture<T,S>
RiakFuture.isDone()
,
RiakFuture.isSuccess()
public final void await() throws InterruptedException
RiakFuture
Upon returning, the operation has completed. Checking isSuccess() tells you if it did so successfully.
await
in interface RiakFuture<T,S>
InterruptedException
- if the current thread was interrupted
while waitingRiakFuture.isSuccess()
public final boolean await(long timeout, TimeUnit unit) throws InterruptedException
RiakFuture
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.
await
in interface RiakFuture<T,S>
timeout
- the amount of time to wait before returning.unit
- the unit of time.true
if the future completed and false
if the waiting time elapsed before it completedInterruptedException
- if the current thread was interrupted
while waitingRiakFuture.isDone()
,
RiakFuture.isSuccess()
protected abstract RiakMessage createChannelMessage()
protected abstract U decode(RiakMessage rawMessage)
public abstract S getQueryInfo()
RiakFuture
Useful in async operations when you want to know what operation this future refers to.
getQueryInfo
in interface RiakFuture<T,S>
Copyright © 2016. All rights reserved.