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

pack-priv final Class ResolvedPromiseImpl<T>

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

Resolved Promise implementation.

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

Author
$Id: 78041b82f182acc1502944509dd445cfe7d86cfb $
Since
1.1

Field Summary

Modifier and TypeField and Description
private final T
value

The value of this resolved Promise.

Constructor Summary

AccessConstructor and Description
pack-priv
ResolvedPromiseImpl(T
The value of this resolved Promise.
value
,
PromiseFactory
The factory to use for callbacks and scheduled operations.
factory
)

Initialize this resolved Promise.

Method Summary

Modifier and TypeMethod and Description
public Promise<T>
fallbackTo(Promise<? extends T>
The Promise whose value must be used to resolve the returned Promise if this Promise resolves with a failure. Must not be null.
fallback
)

Overrides org.osgi.util.promise.PromiseImpl.fallbackTo.

Implements org.osgi.util.promise.Promise.fallbackTo.

Fall back to the value of the specified Promise if this Promise fails.

public Promise<T>
fallbackTo(Promise<? extends T>
The Promise whose value must be used to resolve the returned Promise if this Promise resolves with a failure and the failure is an instance of the specified failure type. Must not be null.
fallback
,
Class<?>
The type of failure for which this recovery will be used. If the failure is not an instance of the failure type, the specified recovery will not be called and the returned Promise must be failed with the failure of this Promise. Must not be null.
failureType
)

Overrides org.osgi.util.promise.PromiseImpl.fallbackTo.

Implements org.osgi.util.promise.Promise.fallbackTo.

Fall back to the value of the specified Promise if this Promise fails and the failure is an instance of a failure type.

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 Promise<T>
onFailure(Consumer<? super Throwable>
The Consumer callback that receives the failure of this Promise. Must not be null.
failure
)

Overrides org.osgi.util.promise.PromiseImpl.onFailure.

Implements org.osgi.util.promise.Promise.onFailure.

Register a callback to be called with the failure for this Promise when this Promise is resolved with a failure.

public <F> Promise<T>
onFailure(Consumer<? super F>
The Consumer callback that receives the failure of this Promise if the failure is an instance of the specified failure type. Must not be null.
failure
,
Class<? extends F>
The type of failure for which this callback will be called. If the failure is not an instance of the specified failure type, the specified callback will not be called. Must not be null.
failureType
)

Overrides org.osgi.util.promise.PromiseImpl.onFailure.

Implements org.osgi.util.promise.Promise.onFailure.

Register a callback to be called with the failure for this Promise when this Promise is resolved with a failure of a failure type.

public Promise<T>
recover(Function<Promise<?>, ? extends T>
If this Promise resolves with a failure, the specified Function is called to produce a recovery value to be used to resolve the returned Promise. Must not be null.
recovery
)

Overrides org.osgi.util.promise.PromiseImpl.recover.

Implements org.osgi.util.promise.Promise.recover.

Recover from a failure of this Promise with a recovery value.

public Promise<T>
recover(Function<Promise<?>, ? extends T>
If this Promise resolves with a failure and the failure is an instance of the specified failure type, the specified Function is called to produce a recovery value to be used to resolve the returned Promise. Must not be null.
recovery
,
Class<?>
The type of failure for which the specified recovery will be used. If the failure is not an instance of the failure type, the specified recovery will not be called and the returned Promise must be failed with the failure of this Promise. Must not be null.
failureType
)

Overrides org.osgi.util.promise.PromiseImpl.recover.

Implements org.osgi.util.promise.Promise.recover.

Recover from a failure of this Promise with a recovery value if the failure is an instance of a failure type.

public Promise<T>
recoverWith(Function<Promise<?>, Promise<? extends T>>
If this Promise resolves with a failure, the specified Function is called to produce a recovery Promise to be used to resolve the returned Promise. Must not be null.
recovery
)

Overrides org.osgi.util.promise.PromiseImpl.recoverWith.

Implements org.osgi.util.promise.Promise.recoverWith.

Recover from a failure of this Promise with a recovery Promise.

public Promise<T>
recoverWith(Function<Promise<?>, Promise<? extends T>>
If this Promise resolves with a failure and the failure is an instance of the specified failure type, the specified Function is called to produce a recovery Promise to be used to resolve the returned Promise. Must not be null.
recovery
,
Class<?>
The type of failure for which this recovery will be used. If the failure is not an instance of the failure type, the specified recovery will not be called and the returned Promise must be failed with the failure of this Promise. Must not be null.
failureType
)

Overrides org.osgi.util.promise.PromiseImpl.recoverWith.

Implements org.osgi.util.promise.Promise.recoverWith.

Recover from a failure of this Promise with a recovery Promise if the failure is an instance of a failure type.

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>
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:
deferreddelayexecutefailedfilterflatMapmapnotifyCallbacksonResolveonSuccessresolvedresultschedulethenthenAcceptuncaughtException

Field Detail

valueback to summary
private final T value

The value of this resolved Promise.

Constructor Detail

ResolvedPromiseImplback to summary
pack-priv ResolvedPromiseImpl(T value, PromiseFactory factory)

Initialize this resolved Promise.

Parameters
value:T

The value of this resolved Promise.

factory:PromiseFactory

The factory to use for callbacks and scheduled operations.

Method Detail

fallbackToback to summary
public Promise<T> fallbackTo(Promise<? extends T> fallback)

Overrides org.osgi.util.promise.PromiseImpl.fallbackTo.

Implements org.osgi.util.promise.Promise.fallbackTo.

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

Fall back to the value of the specified Promise if this Promise fails.

If this Promise is successfully resolved, the returned Promise must be resolved with the value of this Promise.

If this Promise is resolved with a failure, the successful result of the specified Promise is used to resolve the returned Promise. If the specified Promise is resolved with a failure, the returned Promise must be failed with the failure of this Promise rather than the failure of the specified Promise.

This method may be called at any time including before and after this Promise has been resolved.

Parameters
fallback:Promise<? extends T>

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

The Promise whose value must be used to resolve the returned Promise if this Promise resolves with a failure. Must not be null.

Returns:Promise<T>

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

A Promise that returns the value of this Promise or falls back to the value of the specified Promise.

Annotations
@Override
fallbackToback to summary
public Promise<T> fallbackTo(Promise<? extends T> fallback, Class<?> failureType)

Overrides org.osgi.util.promise.PromiseImpl.fallbackTo.

Implements org.osgi.util.promise.Promise.fallbackTo.

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

Fall back to the value of the specified Promise if this Promise fails and the failure is an instance of a failure type.

If this Promise is successfully resolved, the returned Promise must be resolved with the value of this Promise.

If this Promise is resolved with a failure and the failure is an instance of the specified failure type, the successful result of the specified Promise is used to resolve the returned Promise. If the specified Promise is resolved with a failure, the returned Promise must be failed with the failure of this Promise rather than the failure of the specified Promise.

If this Promise is resolved with a failure and the failure is not an instance of the specified failure type, the returned Promise must be failed with the failure of this Promise.

This method may be called at any time including before and after this Promise has been resolved.

Parameters
fallback:Promise<? extends T>

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

The Promise whose value must be used to resolve the returned Promise if this Promise resolves with a failure and the failure is an instance of the specified failure type. Must not be null.

failureType:Class<?>

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

The type of failure for which this recovery will be used. If the failure is not an instance of the failure type, the specified recovery will not be called and the returned Promise must be failed with the failure of this Promise. Must not be null.

Returns:Promise<T>

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

A Promise that returns the value of this Promise or falls back to the value of the specified Promise if the failure is an instance of the specified failure type.

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()

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
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
onFailureback to summary
public Promise<T> onFailure(Consumer<? super Throwable> failure)

Overrides org.osgi.util.promise.PromiseImpl.onFailure.

Implements org.osgi.util.promise.Promise.onFailure.

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

Register a callback to be called with the failure for this Promise when this Promise is resolved with a failure. The callback will not be called if this Promise is resolved successfully.

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
failure:Consumer<? super Throwable>

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

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

Returns:Promise<T>

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

This Promise.

Annotations
@Override
onFailureback to summary
public <F> Promise<T> onFailure(Consumer<? super F> failure, Class<? extends F> failureType)

Overrides org.osgi.util.promise.PromiseImpl.onFailure.

Implements org.osgi.util.promise.Promise.onFailure.

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

Register a callback to be called with the failure for this Promise when this Promise is resolved with a failure of a failure type. The callback will not be called if this Promise is resolved successfully or if the failure is not an instance of the specified failure type.

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
<F>

Doc from org.osgi.util.promise.Promise.onFailure. The failure type.

failure:Consumer<? super F>

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

The Consumer callback that receives the failure of this Promise if the failure is an instance of the specified failure type. Must not be null.

failureType:Class<? extends F>

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

The type of failure for which this callback will be called. If the failure is not an instance of the specified failure type, the specified callback will not be called. Must not be null.

Returns:Promise<T>

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

This Promise.

Annotations
@Override
recoverback to summary
public Promise<T> recover(Function<Promise<?>, ? extends T> recovery)

Overrides org.osgi.util.promise.PromiseImpl.recover.

Implements org.osgi.util.promise.Promise.recover.

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

Recover from a failure of this Promise with a recovery value.

If this Promise is successfully resolved, the returned Promise must be resolved with the value of this Promise.

If this Promise is resolved with a failure, the specified Function is applied to this Promise to produce a recovery value.

  • If the recovery value is not null, the returned Promise must be resolved with the recovery value.
  • If the recovery value is null, the returned Promise must be failed with the failure of this Promise.
  • If the specified Function throws an exception, the returned Promise must be failed with that exception.

To recover from a failure of this Promise with a recovery value of null, the recoverWith(Function) method must be used. The specified Function for recoverWith(Function) can return Promises.resolved(null) to supply the desired null value.

This method may be called at any time including before and after this Promise has been resolved.

Parameters
recovery:Function<Promise<?>, ? extends T>

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

If this Promise resolves with a failure, the specified Function is called to produce a recovery value to be used to resolve the returned Promise. Must not be null.

Returns:Promise<T>

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

A Promise that resolves with the value of this Promise or recovers from the failure of this Promise.

Annotations
@Override
recoverback to summary
public Promise<T> recover(Function<Promise<?>, ? extends T> recovery, Class<?> failureType)

Overrides org.osgi.util.promise.PromiseImpl.recover.

Implements org.osgi.util.promise.Promise.recover.

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

Recover from a failure of this Promise with a recovery value if the failure is an instance of a failure type.

If this Promise is successfully resolved, the returned Promise must be resolved with the value of this Promise.

If this Promise is resolved with a failure and the failure is not an instance of the specified failure type, the returned Promise must be failed with the failure of this Promise.

If this Promise is resolved with a failure and the failure is an instance of the specified failure type, the specified Function is applied to this Promise to produce a recovery value.

  • If the recovery value is not null, the returned Promise must be resolved with the recovery value.
  • If the recovery value is null, the returned Promise must be failed with the failure of this Promise.
  • If the specified Function throws an exception, the returned Promise must be failed with that exception.

To recover from a failure of this Promise with a recovery value of null, the recoverWith(Function, Class) method must be used. The specified Function for recoverWith(Function, Class) can return Promises.resolved(null) to supply the desired null value.

This method may be called at any time including before and after this Promise has been resolved.

Parameters
recovery:Function<Promise<?>, ? extends T>

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

If this Promise resolves with a failure and the failure is an instance of the specified failure type, the specified Function is called to produce a recovery value to be used to resolve the returned Promise. Must not be null.

failureType:Class<?>

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

The type of failure for which the specified recovery will be used. If the failure is not an instance of the failure type, the specified recovery will not be called and the returned Promise must be failed with the failure of this Promise. Must not be null.

Returns:Promise<T>

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

A Promise that resolves with the value of this Promise or recovers from the failure of this Promise if the failure is an instance of the specified failure type.

Annotations
@Override
recoverWithback to summary
public Promise<T> recoverWith(Function<Promise<?>, Promise<? extends T>> recovery)

Overrides org.osgi.util.promise.PromiseImpl.recoverWith.

Implements org.osgi.util.promise.Promise.recoverWith.

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

Recover from a failure of this Promise with a recovery Promise.

If this Promise is successfully resolved, the returned Promise must be resolved with the value of this Promise.

If this Promise is resolved with a failure, the specified Function is applied to this Promise to produce a recovery Promise.

  • If the recovery Promise is not null, the returned Promise must be resolved with the recovery Promise.
  • If the recovery Promise is null, the returned Promise must be failed with the failure of this Promise.
  • If the specified Function throws an exception, the returned Promise must be failed with that exception.

This method may be called at any time including before and after this Promise has been resolved.

Parameters
recovery:Function<Promise<?>, Promise<? extends T>>

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

If this Promise resolves with a failure, the specified Function is called to produce a recovery Promise to be used to resolve the returned Promise. Must not be null.

Returns:Promise<T>

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

A Promise that resolves with the value of this Promise or recovers from the failure of this Promise.

Annotations
@Override
recoverWithback to summary
public Promise<T> recoverWith(Function<Promise<?>, Promise<? extends T>> recovery, Class<?> failureType)

Overrides org.osgi.util.promise.PromiseImpl.recoverWith.

Implements org.osgi.util.promise.Promise.recoverWith.

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

Recover from a failure of this Promise with a recovery Promise if the failure is an instance of a failure type.

If this Promise is successfully resolved, the returned Promise must be resolved with the value of this Promise.

If this Promise is resolved with a failure and the failure is not an instance of the specified failure type, the returned Promise must be failed with the failure of this Promise.

If this Promise is resolved with a failure and the failure is an instance of the specified failure type, the specified Function is applied to this Promise to produce a recovery Promise.

  • If the recovery Promise is not null, the returned Promise must be resolved with the recovery Promise.
  • If the recovery Promise is null, the returned Promise must be failed with the failure of this Promise.
  • If the specified Function throws an exception, the returned Promise must be failed with that exception.

This method may be called at any time including before and after this Promise has been resolved.

Parameters
recovery:Function<Promise<?>, Promise<? extends T>>

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

If this Promise resolves with a failure and the failure is an instance of the specified failure type, the specified Function is called to produce a recovery Promise to be used to resolve the returned Promise. Must not be null.

failureType:Class<?>

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

The type of failure for which this recovery will be used. If the failure is not an instance of the failure type, the specified recovery will not be called and the returned Promise must be failed with the failure of this Promise. Must not be null.

Returns:Promise<T>

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

A Promise that resolves with the value of this Promise or recovers from the failure of this Promise if the failure is an instance of the specified failure type.

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
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