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

public Class Deferred<T>

extends Object
Class Inheritance
Annotations
@ProviderType
Type Parameters
<T>
The value type associated with the created Promise.
Static Imports
java.util.Objects.requireNonNull

A Deferred Promise resolution.

Instances of this class can be used to create a Promise that can be resolved in the future. The associated Promise can be successfully resolved with resolve(Object) or resolved with a failure with fail(Throwable). It can also be resolved with the resolution of another promise using resolveWith(Promise).

The associated Promise can be provided to any one, but the Deferred object should be made available only to the party that will responsible for resolving the Promise.

Author
$Id: c45122c8a530b5552fb4892d4cfed906f46c211c $

Field Summary

Modifier and TypeField and Description
private final DeferredPromiseImpl<T>
promise

The Promise associated with this Deferred.

Constructor Summary

AccessConstructor and Description
public
Deferred()

Create a new Deferred.

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

Create a new Deferred with the specified callback and scheduled executors.

Method Summary

Modifier and TypeMethod and Description
public void
fail(Throwable
The failure of the resolved Promise. Must not be null.
failure
)

Fail the Promise associated with this Deferred.

public Promise<T>

Returns:

The Promise associated with this Deferred.
getPromise
()

Returns the Promise associated with this Deferred.

public void
resolve(T
The value of the resolved Promise.
value
)

Successfully resolve the Promise associated with this Deferred.

public Promise<Void>

Returns:

A Promise that is resolved only when the associated Promise is resolved by the specified Promise. The returned Promise must be successfully resolved with the value null, if the associated Promise was resolved by the specified Promise. The returned Promise must be resolved with a failure of IllegalStateException, if the associated Promise was already resolved when the specified Promise was resolved.
resolveWith
(Promise<? extends T>
A Promise whose value or failure must be used to resolve the associated Promise. Must not be null.
with
)

Resolve the Promise associated with this Deferred with the specified Promise.

public Promise<Void>

Returns:

A Promise that is resolved only when the associated Promise is resolved by the specified CompletionStage. The returned Promise must be successfully resolved with the value null, if the associated Promise was resolved by the specified CompletionStage. The returned Promise must be resolved with a failure of IllegalStateException, if the associated Promise was already resolved when the specified CompletionStage was completed.
resolveWith
(CompletionStage<? extends T>
A CompletionStage whose result must be used to resolve the associated Promise. Must not be null.
with
)

Resolve the Promise associated with this Deferred with the specified CompletionStage.

public String

Returns:

A string representation of the associated Promise.
toString
()

Overrides java.lang.Object.toString.

Returns a string representation of the associated Promise.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAllwaitwaitwait

Field Detail

promiseback to summary
private final DeferredPromiseImpl<T> promise

The Promise associated with this Deferred.

Constructor Detail

Deferredback to summary
public Deferred()

Create a new Deferred.

The associated promise will use the default callback executor and default scheduled executor.

See Also
PromiseFactory#deferred()
Deferredback to summary
pack-priv Deferred(PromiseFactory factory)

Create a new Deferred with the specified callback and scheduled executors.

Parameters
factory:PromiseFactory

The factory to use for callbacks and scheduled operations.

Since
1.1

Method Detail

failback to summary
public void fail(Throwable failure)

Fail the Promise associated with this Deferred.

After the associated Promise is resolved with the specified failure, all registered callbacks are called and any chained Promises are resolved. This may occur asynchronously to this method.

Resolving the associated Promise happens-before any registered callback is called. That is, in a registered callback, Promise#isDone() must return true and Promise#getValue() and Promise#getFailure() must not block.

Parameters
failure:Throwable

The failure of the resolved Promise. Must not be null.

Exceptions
IllegalStateException:
If the associated Promise was already resolved.
getPromiseback to summary
public Promise<T> getPromise()

Returns the Promise associated with this Deferred.

All Promise objects created by the associated Promise will use the executors of the associated Promise.

Returns:Promise<T>

The Promise associated with this Deferred.

resolveback to summary
public void resolve(T value)

Successfully resolve the Promise associated with this Deferred.

After the associated Promise is resolved with the specified value, all registered callbacks are called and any chained Promises are resolved. This may occur asynchronously to this method.

Resolving the associated Promise happens-before any registered callback is called. That is, in a registered callback, Promise#isDone() must return true and Promise#getValue() and Promise#getFailure() must not block.

Parameters
value:T

The value of the resolved Promise.

Exceptions
IllegalStateException:
If the associated Promise was already resolved.
resolveWithback to summary
public Promise<Void> resolveWith(Promise<? extends T> with)

Resolve the Promise associated with this Deferred with the specified Promise.

If the specified Promise is successfully resolved, the associated Promise is resolved with the value of the specified Promise. If the specified Promise is resolved with a failure, the associated Promise is resolved with the failure of the specified Promise.

After the associated Promise is resolved with the specified Promise, all registered callbacks are called and any chained Promises are resolved. This may occur asynchronously to this method.

Resolving the associated Promise happens-before any registered callback is called. That is, in a registered callback, Promise#isDone() must return true and Promise#getValue() and Promise#getFailure() must not block.

Parameters
with:Promise<? extends T>

A Promise whose value or failure must be used to resolve the associated Promise. Must not be null.

Returns:Promise<Void>

A Promise that is resolved only when the associated Promise is resolved by the specified Promise. The returned Promise must be successfully resolved with the value null, if the associated Promise was resolved by the specified Promise. The returned Promise must be resolved with a failure of IllegalStateException, if the associated Promise was already resolved when the specified Promise was resolved.

resolveWithback to summary
public Promise<Void> resolveWith(CompletionStage<? extends T> with)

Resolve the Promise associated with this Deferred with the specified CompletionStage.

If the specified CompletionStage is completed normally, the associated Promise is resolved with the value of the specified CompletionStage. If the specified CompletionStage is completed exceptionally, the associated Promise is resolved with the failure of the specified CompletionStage.

After the associated Promise is resolved with the specified CompletionStage, all registered callbacks are called and any chained Promises are resolved. This may occur asynchronously to this method.

Resolving the associated Promise happens-before any registered callback is called. That is, in a registered callback, Promise#isDone() must return true and Promise#getValue() and Promise#getFailure() must not block.

Parameters
with:CompletionStage<? extends T>

A CompletionStage whose result must be used to resolve the associated Promise. Must not be null.

Returns:Promise<Void>

A Promise that is resolved only when the associated Promise is resolved by the specified CompletionStage. The returned Promise must be successfully resolved with the value null, if the associated Promise was resolved by the specified CompletionStage. The returned Promise must be resolved with a failure of IllegalStateException, if the associated Promise was already resolved when the specified CompletionStage was completed.

Since
1.2
toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Returns a string representation of the associated Promise.

Returns:String

A string representation of the associated Promise.

Annotations
@Override
Since
1.1