T
- The result type associated with the Promise.final class DeferredPromiseImpl<T> extends PromiseImpl<T>
This class is not used directly by clients. Clients should use
PromiseFactory.deferred()
to create a Deferred
which can be
used to obtain a Promise whose resolution can be deferred.
Modifier and Type | Class and Description |
---|---|
private class |
DeferredPromiseImpl.Chain
A callback used to resolve the chained Promise when the Promise is
resolved.
|
private class |
DeferredPromiseImpl.ChainImpl
A callback used to resolve the chained Promise when the PromiseImpl is
resolved.
|
(package private) class |
DeferredPromiseImpl.Delay
A callback used by the
PromiseImpl.delay(long) method to delay
chaining a promise. |
private class |
DeferredPromiseImpl.FallbackChain
A callback used to resolve the chained Promise when the fallback Promise
is resolved.
|
(package private) class |
DeferredPromiseImpl.FallbackTo
A callback used by the
PromiseImpl.fallbackTo(Promise) method. |
(package private) class |
DeferredPromiseImpl.Filter
A callback used by the
PromiseImpl.filter(Predicate) method. |
(package private) class |
DeferredPromiseImpl.FlatMap<P>
A callback used by the
PromiseImpl.flatMap(Function) method. |
(package private) class |
DeferredPromiseImpl.Map<P>
A callback used by the
PromiseImpl.map(Function) method. |
(package private) class |
DeferredPromiseImpl.Recover
A callback used by the
PromiseImpl.recover(Function) method. |
(package private) class |
DeferredPromiseImpl.RecoverWith
A callback used by the
PromiseImpl.recoverWith(Function) method. |
private class |
DeferredPromiseImpl.ResolveWith<P>
A callback used to resolve a Promise with another Promise for the
resolveWith(Promise) method. |
(package private) class |
DeferredPromiseImpl.Submit
A callback used by the
PromiseFactory.submit(Callable) method. |
(package private) class |
DeferredPromiseImpl.Then<P>
A callback used to chain promises for the
PromiseImpl.then(Success, Failure) method. |
(package private) class |
DeferredPromiseImpl.ThenAccept
A callback used by the
PromiseImpl.thenAccept(Consumer) method. |
(package private) class |
DeferredPromiseImpl.Timeout
A callback used by the
PromiseImpl.timeout(long) method to
schedule the timeout and to resolve the chained Promise and cancel the
timeout. |
PromiseImpl.Result<P>
Modifier and Type | Field and Description |
---|---|
private java.lang.Throwable |
fail
The failure of this Promise if resolved with a failure or
null if
successfully resolved. |
private java.util.concurrent.CountDownLatch |
resolved
A CountDownLatch to manage the resolved state of this Promise.
|
private T |
value
The value of this Promise if successfully resolved.
|
Constructor and Description |
---|
DeferredPromiseImpl(PromiseFactory factory)
Initialize this Promise.
|
Modifier and Type | Method and Description |
---|---|
(package private) PromiseImpl.Result<T> |
collect()
Return a holder of the result of this PromiseImpl.
|
java.lang.Throwable |
getFailure()
Returns the failure of this Promise.
|
T |
getValue()
Returns the value of this Promise.
|
boolean |
isDone()
Returns whether this Promise has been resolved.
|
(package private) PromiseImpl<T> |
orDone()
Return a resolved PromiseImpl if this DeferredPromiseImpl is resolved.
|
(package private) void |
resolve(T v,
java.lang.Throwable f)
Resolve this Promise.
|
(package private) Promise<java.lang.Void> |
resolveWith(Promise<? extends T> with)
Resolve this Promise with the specified Promise.
|
java.lang.String |
toString() |
(package private) boolean |
tryResolve(T v,
java.lang.Throwable f)
Try to resolve this Promise.
|
chain, collect, deferred, delay, failed, fallbackTo, filter, flatMap, map, notifyCallbacks, onFailure, onResolve, onSuccess, recover, recoverWith, resolved, schedule, then, then, thenAccept, timeout, uncaughtException
private final java.util.concurrent.CountDownLatch resolved
This object is used as the synchronizing object to provide a critical
section in tryResolve(Object, Throwable)
so that only a single
thread can write the resolved state variables and open the latch.
The resolved state variables, value
and fail
, must only
be written when the latch is closed (getCount() != 0) and must only be
read when the latch is open (getCount() == 0). The latch state must
always be checked before writing or reading since the resolved state
variables' memory consistency is guarded by the latch.
private T value
resolved
private java.lang.Throwable fail
null
if
successfully resolved.resolved
DeferredPromiseImpl(PromiseFactory factory)
factory
- The factory to use for callbacks and scheduled operations.public boolean isDone()
This Promise may be successfully resolved or resolved with a failure.
true
if this Promise was resolved either successfully or
with a failure; false
if this Promise is unresolved.PromiseImpl<T> orDone()
public T getValue() throws java.lang.reflect.InvocationTargetException, java.lang.InterruptedException
If this Promise is not resolved
, this method must block
and wait for this Promise to be resolved before completing.
If this Promise was successfully resolved, this method returns with the
value of this Promise. If this Promise was resolved with a failure, this
method must throw an InvocationTargetException
with the
failure exception
as the cause.
java.lang.reflect.InvocationTargetException
- If this Promise was resolved with a
failure. The cause of the InvocationTargetException
is
the failure exception.java.lang.InterruptedException
- If the current thread was interrupted while
waiting.public java.lang.Throwable getFailure() throws java.lang.InterruptedException
If this Promise is not resolved
, this method must block
and wait for this Promise to be resolved before completing.
If this Promise was resolved with a failure, this method returns with the
failure of this Promise. If this Promise was successfully resolved, this
method must return null
.
null
if this
Promise was successfully resolved.java.lang.InterruptedException
- If the current thread was interrupted while
waiting.PromiseImpl.Result<T> collect()
collect
in class PromiseImpl<T>
public java.lang.String toString()
toString
in class java.lang.Object
boolean tryResolve(T v, java.lang.Throwable f)
If this Promise was already resolved, return false. Otherwise, resolve this Promise and return true.
v
- The value of this Promise.f
- The failure of this Promise.void resolve(T v, java.lang.Throwable f)
If this Promise was already resolved, throw IllegalStateException. Otherwise, resolve this Promise.
v
- The value of this Promise.f
- The failure of this Promise.java.lang.IllegalStateException
- If this Promise was already resolved.Promise<java.lang.Void> resolveWith(Promise<? extends T> with)
If the specified Promise is successfully resolved, this Promise is resolved with the value of the specified Promise. If the specified Promise is resolved with a failure, this Promise is resolved with the failure of the specified Promise.
with
- A Promise whose value or failure must be used to resolve this
Promise. Must not be null
.null
, if this Promise was
resolved by the specified Promise. The returned Promise must be
resolved with a failure of IllegalStateException
, if this
Promise was already resolved when the specified Promise was
resolved.