R
- the type of result of the command handlingpublic class FutureCallback<R> extends Object implements CommandCallback<R>, Future<R>
Constructor and Description |
---|
FutureCallback() |
Modifier and Type | Method and Description |
---|---|
boolean |
awaitCompletion(long timeout,
TimeUnit unit)
Wait for completion of the command, or for the timeout to expire.
|
boolean |
cancel(boolean mayInterruptIfRunning)
Always returns
false , since command execution cannot be cancelled. |
R |
get()
Waits if necessary for the command handling to complete, and then returns its result.
|
R |
get(long timeout,
TimeUnit unit)
Waits if necessary for at most the given time for the command handling to complete, and then retrieves its
result, if available.
|
R |
getResult()
Waits if necessary for the command handling to complete, and then returns its result.
|
R |
getResult(long timeout,
TimeUnit unit)
Waits if necessary for at most the given time for the command handling to complete, and then retrieves its
result, if available.
|
boolean |
isCancelled()
Always returns false, since command execution cannot be cancelled.
|
boolean |
isDone()
Indicates whether command handler execution has finished.
|
void |
onFailure(Throwable cause)
Invoked when command handling execution resulted in an error.
|
void |
onSuccess(R executionResult)
Invoked when command handling execution was successful.
|
public void onSuccess(R executionResult)
CommandCallback
onSuccess
in interface CommandCallback<R>
executionResult
- The result of the command handling execution, if any.public void onFailure(Throwable cause)
CommandCallback
onFailure
in interface CommandCallback<R>
cause
- The exception raised during command handlingpublic R get() throws InterruptedException, ExecutionException
get
in interface Future<R>
InterruptedException
- if the current thread is interrupted while waitingExecutionException
- if the command handler threw an exceptionpublic R get(long timeout, TimeUnit unit) throws TimeoutException, InterruptedException, ExecutionException
get
in interface Future<R>
timeout
- the maximum time to waitunit
- the time unit of the timeout argumentInterruptedException
- if the current thread is interrupted while waitingTimeoutException
- if the wait timed outExecutionException
- if the command handler threw an exceptiongetResult(long, java.util.concurrent.TimeUnit)
public R getResult()
get(long, java.util.concurrent.TimeUnit)
, this method will throw the original exception. Only
checked exceptions are wrapped in a CommandExecutionException
.
If the thread is interrupted while waiting, the interrupt flag is set back on the thread, and null
is returned. To distinguish between an interrupt and a null
result, use the isDone()
method.get()
public R getResult(long timeout, TimeUnit unit)
get(long, java.util.concurrent.TimeUnit)
, this method will throw the original exception. Only
checked exceptions are wrapped in a CommandExecutionException
.
If the timeout expired or the thread is interrupted before completion, null
is returned. In case of
an interrupt, the interrupt flag will have been set back on the thread. To distinguish between an interrupt and
a
null
result, use the isDone()
timeout
- the maximum time to waitunit
- the time unit of the timeout argumentpublic boolean awaitCompletion(long timeout, TimeUnit unit)
timeout
- The amount of time to wait for command processing to completeunit
- The unit in which the timeout is expressedtrue
if command processing completed before the timeout expired, otherwise
false
.public boolean cancel(boolean mayInterruptIfRunning)
false
, since command execution cannot be cancelled.public boolean isCancelled()
isCancelled
in interface Future<R>
Copyright © 2010-2014. All Rights Reserved.