V
- The type for the set value.public class FutureCallback<V> extends Object implements ListenableFuture<V>, Callback<V>
Callback
and ListenableFuture
interfaces.
Used to convert a Callback
into a ListenableFuture
for
returning to callers.Modifier and Type | Field and Description |
---|---|
static Log |
LOG
Logger to log exceptions caught when running myPendingListeners.
|
static long |
SPIN_TIME_NS
Amount of time to spin before yielding.
|
Constructor and Description |
---|
FutureCallback()
Create a new FutureCallback.
|
FutureCallback(LockType lockType)
Create a new FutureCallback.
|
Modifier and Type | Method and Description |
---|---|
void |
addListener(Runnable runnable,
Executor executor)
Add a
Runnable to be executed once the future is completed via
the provided executable. |
void |
callback(V result)
Called when the MongoDB operation has completed with the result of the
operation.
|
boolean |
cancel(boolean mayInterruptIfRunning) |
void |
exception(Throwable thrown)
Called when the operation fails due to an exception.
|
protected void |
execute()
Runs this execution list, executing all existing pairs.
|
V |
get() |
V |
get(long timeout,
TimeUnit unit) |
boolean |
isCancelled() |
boolean |
isDone() |
public static final Log LOG
public static final long SPIN_TIME_NS
public FutureCallback()
public FutureCallback(LockType lockType)
lockType
- The type of lock to use when waiting for the future to be
fulfilled.public void addListener(Runnable runnable, Executor executor)
Runnable
to be executed once the future is completed via
the provided executable.
The order that Runnables
are executed is unspecified.
addListener
in interface ListenableFuture<V>
runnable
- The myRunnable to execute.executor
- Executor to use with the myRunnable.public void callback(V result)
Sets the value for the future and triggers any pending get()
to
return.
callback
in interface Callback<V>
result
- The result of the operation.Callback.callback(V)
public boolean cancel(boolean mayInterruptIfRunning)
If not cancelled and the callback has not completed then cancels the
future, triggers the return of any pending get()
and returns
true. Otherwise returns false. This does not stop the related MongoDB
invocation.
cancel
in interface Future<V>
Future.cancel(boolean)
public void exception(Throwable thrown)
Sets the exception for the future and triggers any pending get()
to throw a ExecutionException
.
exception
in interface Callback<V>
thrown
- The thrown exception.Callback.exception(java.lang.Throwable)
public V get() throws InterruptedException, ExecutionException
Returns the value set via the Callback
.
get
in interface Future<V>
InterruptedException
ExecutionException
Future.get()
public V get(long timeout, TimeUnit unit) throws InterruptedException, TimeoutException, ExecutionException
get
in interface Future<V>
InterruptedException
TimeoutException
ExecutionException
public boolean isCancelled()
Returns true if cancel(boolean)
has been called.
isCancelled
in interface Future<V>
Future.isCancelled()
public boolean isDone()
isDone
in interface Future<V>
Future.isDone()
protected void execute()
All callers of this method will drain the list of listeners.
Copyright © 2011–2014 Allanbank Consulting, Inc.. All rights reserved.