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

pack-priv abstract Class PromiseImpl<T>

extends Object
implements Promise<T>
Class Inheritance
All Implemented Interfaces
org.osgi.util.promise.Promise
Known Direct Subclasses
org.osgi.util.promise.ResolvedPromiseImpl, org.osgi.util.promise.DeferredPromiseImpl, org.osgi.util.promise.FailedPromiseImpl
Type Parameters
<T>
The result type associated with the Promise.
Static Imports
java.util.Objects.requireNonNull

Abstract Promise implementation.

This class is not used directly by clients. Clients should use PromiseFactory to create a Promise.

Author
$Id: eb102637b5ef32c8e2f53444bdacc534854c3b1e $

Nested and Inner Type Summary

Modifier and TypeClass and Description
pack-priv static interface
PromiseImpl.InlineCallback

Marker interface for internal callbacks which do not call user code and should be run on the current thread for an already resolved promise.

private class
PromiseImpl.OnFailure<
The failure type.
F
>

A callback used for the onFailure(Consumer, Class) method.

private class
PromiseImpl.OnSuccess

A callback used for the onSuccess(Consumer) method.

pack-priv static interface
PromiseImpl.Result<R>

A consumer of the result of a Promise.

private class
PromiseImpl.ToCompletionStage

A callback used for the toCompletionStage() method.

Field Summary

Modifier and TypeField and Description
private final ConcurrentLinkedQueue<Runnable>
callbacks

A ConcurrentLinkedQueue to hold the callbacks for this Promise, so no additional synchronization is required to write to or read from the queue.

private final PromiseFactory
factory

The factory to use for callbacks and scheduled operations.

Constructor Summary

AccessConstructor and Description
pack-priv
PromiseImpl(PromiseFactory
The factory to use for callbacks and scheduled operations.
factory
)

Initialize this Promise.

Method Summary

Modifier and TypeMethod and Description
pack-priv <V> DeferredPromiseImpl<V>

Returns:

A new DeferredPromiseImpl.
deferred
()

Return a new DeferredPromiseImpl using the PromiseFactory of this PromiseImpl.

public Promise<T>
delay(long
The time to delay in milliseconds. Zero and negative time is treated as no delay.
millis
)

Implements org.osgi.util.promise.Promise.delay.

Delay after the resolution of this Promise.

pack-priv void
execute(Runnable operation)

Execute a operation on the executor.

pack-priv <V> FailedPromiseImpl<V>

Returns:

A new FailedPromiseImpl.
failed
(Throwable
Failure for the FailedPromiseImpl.
f
)

Return a new FailedPromiseImpl using the PromiseFactory of this PromiseImpl.

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
)

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
)

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 Promise<T>
filter(Predicate<? super T>
The Predicate to evaluate the value of this Promise. Must not be null.
predicate
)

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
)

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

FlatMap the value of this Promise.

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
)

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

Map the value of this Promise.

pack-priv void
notifyCallbacks()

Call any registered callbacks if this Promise is resolved.

public Promise<T>
onFailure(Consumer<? super Throwable>
The Consumer callback that receives the failure of this Promise. Must not be null.
failure
)

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
)

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>
onResolve(Runnable
The callback to be called when this Promise is resolved. Must not be null.
callback
)

Implements org.osgi.util.promise.Promise.onResolve.

Register a callback to be called when this Promise is resolved.

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

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.

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
)

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
)

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
)

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
)

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

Returns:

A new ResolvedPromiseImpl.
resolved
(V
Value for the ResolvedPromiseImpl.
v
)

Return a new ResolvedPromiseImpl using the PromiseFactory of this PromiseImpl.

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

Accept the result of this PromiseImpl.

pack-priv static <R> void
result(Promise<? extends R> promise, PromiseImpl.Result<? super R> consumer)

Accept the result of the specified Promise.

pack-priv ScheduledFuture<?>
schedule(Runnable operation, long delay, TimeUnit unit)

Schedule a operation on the scheduled executor.

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
)

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

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

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
)

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

Chain a new Promise to this Promise with a Success callback.

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

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
)

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

Time out the resolution of this Promise.

public CompletionStage<T>
toCompletionStage()

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

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

pack-priv static void
uncaughtException(Throwable
The uncaught exception.
t
)

Handle an uncaught exception from a Runnable.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait