Top Description Fields Constructors Methods
org.osgi.util.promise

pack-priv final Class FailedPromiseImpl<T>

extends PromiseImpl<T>
Class Inheritance
Type Parameters
<T>
The result type associated with the Promise.
Static Imports
java.util.Objects.requireNonNull

Failed Promise implementation.

This class is not used directly by clients. Clients should use PromiseFactory#failed(Throwable) to create a failed Promise.

Author
$Id: faaa1e9812944bb34475ddaff5eacdc145256612 $
Since
1.1

Field Summary

Modifier and TypeField and Description
private final Throwable
fail

The failure of this failed Promise.

Constructor Summary

AccessConstructor and Description
pack-priv
FailedPromiseImpl(Throwable
The failure of this failed Promise. Must not be null.
fail
,
PromiseFactory
The factory to use for callbacks and scheduled operations.
factory
)

Initialize this failed Promise.

Method Summary

Modifier and TypeMethod and Description
private <V> FailedPromiseImpl<V>

Returns:

This FailedPromiseImpl.
coerce
()

Coerce the value type of this FailedPromiseImpl.

public Promise<T>
filter(Predicate<? super T>
The Predicate to evaluate the value of this Promise. Must not be null.
predicate
)

Overrides org.osgi.util.promise.PromiseImpl.filter.

Implements org.osgi.util.promise.Promise.filter.

Filter the value of this Promise.

public <R> Promise<R>
flatMap(Function<? super T, Promise<? extends R>>
The Function that must flatMap the value of this Promise to a Promise that must be used to resolve the returned Promise. Must not be null.
mapper
)

Overrides org.osgi.util.promise.PromiseImpl.flatMap.

Implements org.osgi.util.promise.Promise.flatMap.

FlatMap the value of this Promise.

public Throwable
getFailure()

Implements org.osgi.util.promise.Promise.getFailure.

Returns the failure of this Promise.

public T
getValue()

Implements org.osgi.util.promise.Promise.getValue.

Returns the value of this Promise.

public boolean
isDone()

Implements org.osgi.util.promise.Promise.isDone.

Returns whether this Promise has been resolved.

public <R> Promise<R>
map(Function<? super T, ? extends R>
The Function that must map the value of this Promise to the value that must be used to resolve the returned Promise. Must not be null.
mapper
)

Overrides org.osgi.util.promise.PromiseImpl.map.

Implements org.osgi.util.promise.Promise.map.

Map the value of this Promise.

public Promise<T>
onSuccess(Consumer<? super T>
The Consumer callback that receives the value of this Promise. Must not be null.
success
)

Overrides org.osgi.util.promise.PromiseImpl.onSuccess.

Implements org.osgi.util.promise.Promise.onSuccess.

Register a callback to be called with the result of this Promise when this Promise is resolved successfully.

pack-priv void
result(PromiseImpl.Result<? super T> consumer)

Implements abstract org.osgi.util.promise.PromiseImpl.result.

Accept the result of this PromiseImpl.

public <R> Promise<R>
then(Success<? super T, ? extends R>
The Success callback to be called when this Promise is successfully resolved. May be null if no Success callback is required. In this case, the returned Promise must be resolved with the value null when this Promise is successfully resolved.
success
,
Failure
The Failure callback to be called when this Promise is resolved with a failure. May be null if no Failure callback is required.
failure
)

Overrides org.osgi.util.promise.PromiseImpl.then.

Implements org.osgi.util.promise.Promise.then.

Chain a new Promise to this Promise with Success and Failure callbacks.

public Promise<T>
thenAccept(Consumer<? super T>
The Consumer callback that receives the value of this Promise. Must not be null.
consumer
)

Overrides org.osgi.util.promise.PromiseImpl.thenAccept.

Implements org.osgi.util.promise.Promise.thenAccept.

Chain a new Promise to this Promise with a Consumer callback that receives the value of this Promise when it is successfully resolved.

public Promise<T>
timeout(long
The time to wait in milliseconds. Zero and negative time is treated as an immediate timeout.
millis
)

Overrides org.osgi.util.promise.PromiseImpl.timeout.

Implements org.osgi.util.promise.Promise.timeout.

Time out the resolution of this Promise.

public CompletionStage<T>
toCompletionStage()

Overrides org.osgi.util.promise.PromiseImpl.toCompletionStage.

Implements org.osgi.util.promise.Promise.toCompletionStage.

Returns a new CompletionStage that will be resolved with the result of this Promise.

public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.

Inherited from org.osgi.util.promise.PromiseImpl:
deferreddelayexecutefailedfallbackTofallbackTonotifyCallbacksonFailureonFailureonResolverecoverrecoverrecoverWithrecoverWithresolvedresultschedulethenuncaughtException

Field Detail

failback to summary
private final Throwable fail

The failure of this failed Promise.

Constructor Detail

FailedPromiseImplback to summary
pack-priv FailedPromiseImpl(Throwable fail, PromiseFactory factory)

Initialize this failed Promise.

Parameters
fail:Throwable

The failure of this failed Promise. Must not be null.

factory:PromiseFactory

The factory to use for callbacks and scheduled operations.

Method Detail

coerceback to summary
private <V> FailedPromiseImpl<V> coerce()

Coerce the value type of this FailedPromiseImpl.

Returns:FailedPromiseImpl<V>

This FailedPromiseImpl.

Annotations
@SuppressWarnings:unchecked
filterback to summary
public Promise<T> filter(Predicate<? super T> predicate)

Overrides org.osgi.util.promise.PromiseImpl.filter.

Implements org.osgi.util.promise.Promise.filter.

Doc from org.osgi.util.promise.PromiseImpl.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.

Parameters
predicate:Predicate<? super T>

Doc from org.osgi.util.promise.Promise.filter.

The Predicate to evaluate the value of this Promise. Must not be null.

Returns:Promise<T>

Doc from org.osgi.util.promise.Promise.filter.

A Promise that filters the value of this Promise.

Annotations
@Override
flatMapback to summary
public <R> Promise<R> flatMap(Function<? super T, Promise<? extends R>> mapper)

Overrides org.osgi.util.promise.PromiseImpl.flatMap.

Implements org.osgi.util.promise.Promise.flatMap.

Doc from org.osgi.util.promise.PromiseImpl.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.

Parameters
<R>

Doc from org.osgi.util.promise.Promise.flatMap. The value type associated with the returned Promise.

mapper:Function<? super T, Promise<? extends R>>

Doc from org.osgi.util.promise.Promise.flatMap.

The Function that must flatMap the value of this Promise to a Promise that must be used to resolve the returned Promise. Must not be null.

Returns:Promise<R>

Doc from org.osgi.util.promise.Promise.flatMap.

A Promise that returns the value of this Promise as mapped by the specified Function.

Annotations
@Override
getFailureback to summary
public Throwable getFailure()

Implements org.osgi.util.promise.Promise.getFailure.

Doc from org.osgi.util.promise.Promise.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:Throwable

The failure of this resolved Promise or null if this Promise was successfully resolved.

Annotations
@Override
getValueback to summary
public T getValue() throws InvocationTargetException

Implements org.osgi.util.promise.Promise.getValue.

Doc from org.osgi.util.promise.Promise.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 InvocationTargetException with the failure exception as the cause.

Returns:T

The value of this resolved Promise.

Annotations
@Override
Exceptions
InvocationTargetException:
If this Promise was resolved with a failure. The cause of the InvocationTargetException is the failure exception.
isDoneback to summary
public boolean isDone()

Implements org.osgi.util.promise.Promise.isDone.

Doc from org.osgi.util.promise.Promise.isDone.

Returns whether this Promise has been resolved.

This Promise may be successfully resolved or resolved with a failure.

Returns:boolean

true if this Promise was resolved either successfully or with a failure; false if this Promise is unresolved.

Annotations
@Override
mapback to summary
public <R> Promise<R> map(Function<? super T, ? extends R> mapper)

Overrides org.osgi.util.promise.PromiseImpl.map.

Implements org.osgi.util.promise.Promise.map.

Doc from org.osgi.util.promise.PromiseImpl.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.

Parameters
<R>

Doc from org.osgi.util.promise.Promise.map. The value type associated with the returned Promise.

mapper:Function<? super T, ? extends R>

Doc from org.osgi.util.promise.Promise.map.

The Function that must map the value of this Promise to the value that must be used to resolve the returned Promise. Must not be null.

Returns:Promise<R>

Doc from org.osgi.util.promise.Promise.map.

A Promise that returns the value of this Promise as mapped by the specified Function.

Annotations
@Override
onSuccessback to summary
public Promise<T> onSuccess(Consumer<? super T> success)

Overrides org.osgi.util.promise.PromiseImpl.onSuccess.

Implements org.osgi.util.promise.Promise.onSuccess.

Doc from org.osgi.util.promise.PromiseImpl.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, isDone() must return true and getValue() and 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.

Parameters
success:Consumer<? super T>

Doc from org.osgi.util.promise.Promise.onSuccess.

The Consumer callback that receives the value of this Promise. Must not be null.

Returns:Promise<T>

Doc from org.osgi.util.promise.Promise.onSuccess.

This Promise.

Annotations
@Override
resultback to summary
pack-priv void result(PromiseImpl.Result<? super T> consumer)

Implements abstract org.osgi.util.promise.PromiseImpl.result.

Doc from org.osgi.util.promise.PromiseImpl.result.

Accept the result of this PromiseImpl.

Annotations
@Override
thenback to summary
public <R> Promise<R> then(Success<? super T, ? extends R> success, Failure failure)

Overrides org.osgi.util.promise.PromiseImpl.then.

Implements org.osgi.util.promise.Promise.then.

Doc from org.osgi.util.promise.PromiseImpl.then.

Chain a new Promise to this Promise with Success and Failure callbacks.

The specified Success callback is called when this Promise is successfully resolved and the specified Failure callback 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, isDone() must return true and getValue() and 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.

Parameters
<R>

Doc from org.osgi.util.promise.Promise.then. The value type associated with the returned Promise.

success:Success<? super T, ? extends R>

Doc from org.osgi.util.promise.Promise.then.

The Success callback to be called when this Promise is successfully resolved. May be null if no Success callback is required. In this case, the returned Promise must be resolved with the value null when this Promise is successfully resolved.

failure:Failure

Doc from org.osgi.util.promise.Promise.then.

The Failure callback to be called when this Promise is resolved with a failure. May be null if no Failure callback is required.

Returns:Promise<R>

Doc from org.osgi.util.promise.Promise.then.

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.

Annotations
@Override
thenAcceptback to summary
public Promise<T> thenAccept(Consumer<? super T> consumer)

Overrides org.osgi.util.promise.PromiseImpl.thenAccept.

Implements org.osgi.util.promise.Promise.thenAccept.

Doc from org.osgi.util.promise.PromiseImpl.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 Consumer is 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, isDone() must return true and getValue() and 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.

Parameters
consumer:Consumer<? super T>

Doc from org.osgi.util.promise.Promise.thenAccept.

The Consumer callback that receives the value of this Promise. Must not be null.

Returns:Promise<T>

Doc from org.osgi.util.promise.Promise.thenAccept.

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.

Annotations
@Override
timeoutback to summary
public Promise<T> timeout(long millis)

Overrides org.osgi.util.promise.PromiseImpl.timeout.

Implements org.osgi.util.promise.Promise.timeout.

Doc from org.osgi.util.promise.PromiseImpl.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.

Parameters
millis:long

Doc from org.osgi.util.promise.Promise.timeout.

The time to wait in milliseconds. Zero and negative time is treated as an immediate timeout.

Returns:Promise<T>

Doc from org.osgi.util.promise.Promise.timeout.

A Promise that is resolved when either this Promise is resolved or the specified timeout is reached.

Annotations
@Override
toCompletionStageback to summary
public CompletionStage<T> toCompletionStage()

Overrides org.osgi.util.promise.PromiseImpl.toCompletionStage.

Implements org.osgi.util.promise.Promise.toCompletionStage.

Doc from org.osgi.util.promise.PromiseImpl.toCompletionStage.

Returns a new CompletionStage that will be resolved with the result of this Promise.

Returns:CompletionStage<T>

Doc from org.osgi.util.promise.Promise.toCompletionStage.

A new CompletionStage that will be resolved with the result of this Promise.

Annotations
@Override
toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object. Satisfying this method's contract implies a non-null result must be returned.

Returns:String

a string representation of the object

Annotations
@Override