Class FailedPromiseImpl<T>
- Type Parameters:
T- The result type associated with the Promise.
- All Implemented Interfaces:
Promise<T>
This class is not used directly by clients. Clients should use
PromiseFactory.failed(Throwable) to create a failed Promise.
- Since:
- 1.1
-
Nested Class Summary
Nested classes/interfaces inherited from class org.osgi.util.promise.PromiseImpl
PromiseImpl.Result<P> -
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionFailedPromiseImpl(Throwable fail, PromiseFactory factory) Initialize this failed Promise. -
Method Summary
Modifier and TypeMethodDescriptionprivate <V> FailedPromiseImpl<V> coerce()Coerce the value type of this FailedPromiseImpl.(package private) PromiseImpl.Result<T> collect()Return a holder of the result of this PromiseImpl.Filter the value of this Promise.<R> Promise<R> FlatMap the value of this Promise.Returns the failure of this Promise.getValue()Returns the value of this Promise.booleanisDone()Returns whether this Promise has been resolved.<R> Promise<R> Map the value of this Promise.Register a callback to be called with the result of this Promise when this Promise is resolved successfully.<R> Promise<R> Chain a new Promise to this Promise with Success and Failure callbacks.thenAccept(Consumer<? super T> consumer) Chain a new Promise to this Promise with a Consumer callback that receives the value of this Promise when it is successfully resolved.timeout(long millis) Time out the resolution of this Promise.toString()Methods inherited from class org.osgi.util.promise.PromiseImpl
chain, collect, deferred, delay, failed, fallbackTo, notifyCallbacks, onFailure, onResolve, recover, recoverWith, resolved, schedule, then, uncaughtException
-
Field Details
-
fail
The failure of this failed Promise.
-
-
Constructor Details
-
FailedPromiseImpl
FailedPromiseImpl(Throwable fail, PromiseFactory factory) Initialize this failed Promise.- Parameters:
fail- The failure of this failed Promise. Must not benull.factory- The factory to use for callbacks and scheduled operations.
-
-
Method Details
-
isDone
public boolean isDone()Returns whether this Promise has been resolved.This Promise may be successfully resolved or resolved with a failure.
- Returns:
trueif this Promise was resolved either successfully or with a failure;falseif this Promise is unresolved.
-
getValue
Returns the value of this Promise.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
InvocationTargetExceptionwith thefailure exceptionas the cause.- Returns:
- The value of this resolved Promise.
- Throws:
InvocationTargetException- If this Promise was resolved with a failure. The cause of theInvocationTargetExceptionis the failure exception.
-
getFailure
Returns the failure of this Promise.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.- Returns:
- The failure of this resolved Promise or
nullif this Promise was successfully resolved.
-
collect
PromiseImpl.Result<T> collect()Return a holder of the result of this PromiseImpl.- Specified by:
collectin classPromiseImpl<T>
-
toString
-
coerce
Coerce the value type of this FailedPromiseImpl.- Returns:
- This FailedPromiseImpl.
-
onSuccess
Register a callback to be called with the result of this Promise when this Promise is resolved successfully. The callback will not be called if this Promise is resolved with a failure.This method may be called at any time including before and after this Promise has been resolved.
Resolving this Promise happens-before any registered callback is called. That is, in a registered callback,
Promise.isDone()must returntrueandPromise.getValue()andPromise.getFailure()must not block.A callback may be called on a different thread than the thread which registered the callback. So the callback must be thread safe but can rely upon that the registration of the callback happens-before the registered callback is called.
-
then
Chain a new Promise to this Promise with Success and Failure callbacks.The specified
Successcallback is called when this Promise is successfully resolved and the specifiedFailurecallback is called when this Promise is resolved with a failure.This method returns a new Promise which is chained to this Promise. The returned Promise must be resolved when this Promise is resolved after the specified Success or Failure callback is executed. The result of the executed callback must be used to resolve the returned Promise. Multiple calls to this method can be used to create a chain of promises which are resolved in sequence.
If this Promise is successfully resolved, the Success callback is executed and the result Promise, if any, or thrown exception is used to resolve the returned Promise from this method. If this Promise is resolved with a failure, the Failure callback is executed and the returned Promise from this method is failed.
This method may be called at any time including before and after this Promise has been resolved.
Resolving this Promise happens-before any registered callback is called. That is, in a registered callback,
Promise.isDone()must returntrueandPromise.getValue()andPromise.getFailure()must not block.A callback may be called on a different thread than the thread which registered the callback. So the callback must be thread safe but can rely upon that the registration of the callback happens-before the registered callback is called.
- Specified by:
thenin interfacePromise<T>- Overrides:
thenin classPromiseImpl<T>- Type Parameters:
R- The value type associated with the returned Promise.- Parameters:
success- The Success callback to be called when this Promise is successfully resolved. May benullif no Success callback is required. In this case, the returned Promise must be resolved with the valuenullwhen this Promise is successfully resolved.failure- The Failure callback to be called when this Promise is resolved with a failure. May benullif no Failure callback is required.- Returns:
- A new Promise which is chained to this Promise. The returned Promise must be resolved when this Promise is resolved after the specified Success or Failure callback, if any, is executed.
-
thenAccept
Chain a new Promise to this Promise with a Consumer callback that receives the value of this Promise when it is successfully resolved.The specified
Consumeris called when this Promise is resolved successfully.This method returns a new Promise which is chained to this Promise. The returned Promise must be resolved when this Promise is resolved after the specified callback is executed. If the callback throws an exception, the returned Promise is failed with that exception. Otherwise the returned Promise is resolved with the success value from this Promise.
This method may be called at any time including before and after this Promise has been resolved.
Resolving this Promise happens-before any registered callback is called. That is, in a registered callback,
Promise.isDone()must returntrueandPromise.getValue()andPromise.getFailure()must not block.A callback may be called on a different thread than the thread which registered the callback. So the callback must be thread safe but can rely upon that the registration of the callback happens-before the registered callback is called.
- Specified by:
thenAcceptin interfacePromise<T>- Overrides:
thenAcceptin classPromiseImpl<T>- Parameters:
consumer- The Consumer callback that receives the value of this Promise. Must not benull.- Returns:
- A new Promise which is chained to this Promise. The returned Promise must be resolved when this Promise is resolved after the specified Consumer is executed.
-
filter
Filter the value of this Promise.If this Promise is successfully resolved, the returned Promise must either be resolved with the value of this Promise, if the specified Predicate accepts that value, or failed with a
NoSuchElementException, if the specified Predicate does not accept that value. If the specified Predicate throws an exception, the returned Promise must be failed with the exception.If this Promise is resolved with a failure, the returned Promise must be failed with that failure.
This method may be called at any time including before and after this Promise has been resolved.
-
map
Map the value of this Promise.If this Promise is successfully resolved, the returned Promise must be resolved with the value of specified Function as applied to the value of this Promise. If the specified Function throws an exception, the returned Promise must be failed with the exception.
If this Promise is resolved with a failure, the returned Promise must be failed with that failure.
This method may be called at any time including before and after this Promise has been resolved.
- Specified by:
mapin interfacePromise<T>- Overrides:
mapin classPromiseImpl<T>- Type Parameters:
R- The value type associated with the returned Promise.- Parameters:
mapper- The Function that must map the value of this Promise to the value that must be used to resolve the returned Promise. Must not benull.- Returns:
- A Promise that returns the value of this Promise as mapped by the specified Function.
-
flatMap
FlatMap the value of this Promise.If this Promise is successfully resolved, the returned Promise must be resolved with the Promise from the specified Function as applied to the value of this Promise. If the specified Function throws an exception, the returned Promise must be failed with the exception.
If this Promise is resolved with a failure, the returned Promise must be failed with that failure.
This method may be called at any time including before and after this Promise has been resolved.
- Specified by:
flatMapin interfacePromise<T>- Overrides:
flatMapin classPromiseImpl<T>- Type Parameters:
R- The value type associated with the returned Promise.- Parameters:
mapper- The Function that must flatMap the value of this Promise to a Promise that must be used to resolve the returned Promise. Must not benull.- Returns:
- A Promise that returns the value of this Promise as mapped by the specified Function.
-
timeout
Time out the resolution of this Promise.If this Promise is successfully resolved before the timeout, the returned Promise is resolved with the value of this Promise. If this Promise is resolved with a failure before the timeout, the returned Promise is resolved with the failure of this Promise. If the timeout is reached before this Promise is resolved, the returned Promise is failed with a
TimeoutException.- Specified by:
timeoutin interfacePromise<T>- Overrides:
timeoutin classPromiseImpl<T>- Parameters:
millis- The time to wait in milliseconds. Zero and negative time is treated as an immediate timeout.- Returns:
- A Promise that is resolved when either this Promise is resolved or the specified timeout is reached.
-