T - the output type of a successful processpublic class SettableFuture<T> extends AbstractFuture<T> implements Settable<T>
Future that can be fulfilled via the Settable interface.
SettableFuture has a default Executor that is used when a
SettableFuture is created without passing this parameter, which runs
callback functions immediately on the stack when the future is fulfilled.ReadyFuture| Constructor and Description |
|---|
SettableFuture()
Construct a
SettableFuture with the default Executor |
SettableFuture(Executor executor)
Construct a
SettableFuture with a specified Executor |
| Modifier and Type | Method and Description |
|---|---|
void |
blockInterruptibly()
Blocks until this
Future is set to either a value or an error. |
void |
blockUntilReady()
Blocks until this
Future is set to either a value or an error. |
void |
cancel()
Cancels this operation or signal.
|
Throwable |
getError()
Gets the error from a
Future if it has been set to this state. |
T |
getIfDone()
Gets the value from this
Future. |
boolean |
isDone()
Gets the readiness of this
Future. |
boolean |
isError()
Tests if this
Future is set to an error |
boolean |
isSet()
Returns
true if this Settable has been set to a value or error. |
boolean |
onCancelled(Runnable r)
Register code to be called if this operation is cancelled.
|
void |
onCancelledCancel(Cancellable c)
Link an operation to cancel in the event that this
Settable is cancelled. |
void |
set(T value)
Set this
Settable to a value. |
void |
setError(Error error)
Set this
Settable to an error. |
void |
setError(RuntimeException error)
Set this
Settable to an error. |
flatMap, get, getInterruptibly, map, rescueRuntimedispose, flatMap, map, onReady, onReadyAlready, rescue, rescueequals, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitdispose, flatMap, map, onReady, onReadyAlready, rescue, rescuepublic SettableFuture()
SettableFuture with the default Executorpublic SettableFuture(Executor executor)
SettableFuture with a specified Executorexecutor - the Executor with which to execute callbackspublic void set(T value)
SettableSettable to a value. This will invoke callbacks, and unblock
all Threads waiting on associated Futures. A Settable
can be set only once and this call
will throw an exception if this object is already set to a value or error. It
is not, however, an error to call this if the operation has been cancelled.
If the task has been cancelled, this call will have no effect.public void setError(Error error)
SettableSettable to an error. This call will invoke callbacks, and unblock
all Threads waiting on associated Futures. A Settable
can be set only once and this call will
throw an exception if this object is already set to a value or error. It
is not, however, an error to call this method if the operation has been cancelled.
If the task has been cancelled, this call will have no effect.public void setError(RuntimeException error)
SettableSettable to an error. This call will invoke callbacks, and unblock
all Threads waiting on associated Futures. A Settable
can be set only once and this call will
throw an exception if this object is already set to a value or error. It
is not, however, an error to call this method if the operation has been cancelled.
If the task has been cancelled, this call will have no effect.public void cancel()
Cancellablecancel in interface Cancellablecancel in interface PartialFuture<T>public boolean isSet()
Settabletrue if this Settable has been set to a value or error.public boolean onCancelled(Runnable r)
SettableSettables can
be cancelled by calls to PartialFuture.cancel() on associated Futures.
If this Settable is already set, the
callback will not be registered and this call will return false. If this
call returns true the registered callback is guaranteed to be called if
the associated Future is cancelled.onCancelled in interface Settable<T>r - routine to execute if cancelled.true if the callback was registered, false otherwise.public void onCancelledCancel(Cancellable c)
SettableSettable is cancelled.
This is a convenience method (for more complicated calls to
Settable.onCancelled(Runnable)) with possible internal optimizations.onCancelledCancel in interface Settable<T>c - the operation to cancelpublic T getIfDone()
AbstractPartialFutureFuture. It must be in the ready and non-error
state. This is a non-blocking call. If this Future is set to
an error get() throws this error.Future has been set.public void blockInterruptibly()
throws InterruptedException
PartialFutureFuture is set to either a value or an error.
When this function returns without an error, PartialFuture.isDone() will return
true.
blockInterruptibly in interface PartialFuture<T>InterruptedException - if the blocked thread is interruptedpublic void blockUntilReady()
PartialFutureFuture is set to either a value or an error.
When this function returns without an error, PartialFuture.isDone() will return
true.
blockUntilReady in interface PartialFuture<T>public boolean isDone()
PartialFutureFuture. A Future is ready
if the value has been set or an error has been set.isDone in interface PartialFuture<T>true if the Future is set to a value or errorpublic boolean isError()
PartialFutureFuture is set to an errorisError in interface PartialFuture<T>true if in error state, false otherwisepublic Throwable getError()
FutureFuture if it has been set to this state. If
this Future is not yet set, or has not been set to an error, throws
an exception. Although this method returns a Throwable, the set of
possible return types is more limited. A Future is limited to being
set to an unchecked exceptions -- that is an Error or a
RuntimeException (or one of its subclasses).