Instances of this class can be used to create Deferred and Promise objects which use the executors used to construct this object for any callback or scheduled operation execution.
| Modifier and Type | Class and Description |
|---|---|
| private static class | PromiseFactory.
A callback used to resolve the specified Promise when the specified list
of Promises are resolved for the |
| private static class | PromiseFactory.
Default executors for Promises. |
| private static class | PromiseFactory.
An Executor implementation which executes the task immediately on the
thread calling the |
| public static enum | PromiseFactory.
Defines the options for a Promise factory. |
| Modifier and Type | Field and Description |
|---|---|
| private final boolean | |
| private final Executor | callbackExecutor
The executor to use for callbacks. |
| pack-priv static final PromiseFactory | defaultFactory
The default factory which uses the default callback executor and default scheduled executor. |
| private final ScheduledExecutorService | scheduledExecutor
The executor to use for scheduled operations. |
| Access | Constructor and Description |
|---|---|
| public | PromiseFactory(Executor
The executor to use for callbacks. callbackExecutor)null
can be specified for the default callback executor.Create a new PromiseFactory with the specified callback executor. |
| public | PromiseFactory(Executor
The executor to use for callbacks. callbackExecutor, ScheduledExecutorService null
can be specified for the default callback executor.The scheduled executor for use for scheduled
operations. scheduledExecutor)null can be specified for the default
scheduled executor.Create a new PromiseFactory with the specified callback executor and specified scheduled executor. |
| public | PromiseFactory(Executor
The executor to use for callbacks. callbackExecutor, ScheduledExecutorService null
can be specified for the default callback executor.The scheduled executor for use for scheduled
operations. scheduledExecutor, PromiseFactory.null can be specified for the default
scheduled executor.Options for PromiseFactory. optionsCreate a new PromiseFactory with the specified callback executor, specified scheduled executor, and specified options. |
| Modifier and Type | Method and Description |
|---|---|
| public < The value type of the List value associated with the returned
Promise. T, The value type of the specified Promises. S extends T> Promise | Returns: A Promise that must be successfully resolved with a List of the values in the order of the specified Promises if all the specified Promises are successfully resolved. The List in the returned Promise is the property of the caller and is modifiable. The returned Promise must be resolved with a failure ofFailedPromisesException if any of the specified Promises
are resolved with a failure. The failure
FailedPromisesException must contain all of the specified
Promises which resolved with a failure.The Promises which must be resolved before the returned
Promise must be resolved. Must not be promises)null and all of
the elements in the collection must not be null.Returns a new Promise that is a latch on the resolution of the specified Promises. |
| pack-priv boolean | |
| private static <E, C extends Collection | |
| private static PromiseFactory. | |
| public < The value type associated with the returned Deferred. T> Deferred | |
| public Executor | Returns: The executor to use for callbacks. This will be the default callback executor ifnull was specified for the callback
executor when this PromiseFactory was created.Returns the executor to use for callbacks. |
| public < The value type associated with the returned Promise. T> Promise | |
| public static Executor | Returns: An Executor implementation that executes tasks immediately on the thread calling theExecutor.execute method.Returns an Executor implementation that executes tasks immediately on the
thread calling the |
| public < The value type associated with the returned Promise. T> Promise | Returns: A new Promise that has been resolved with the specified value.The value of the resolved Promise. value)Returns a new Promise that has been resolved with the specified value. |
| public < The value type associated with the returned Promise. T> Promise | Returns: A new Promise that will be resolved with the result of the specified CompletionStage.A CompletionStage whose result will be used to resolve the
returned Promise. Must not be with)null.Returns a new Promise that will be resolved with the result of the specified CompletionStage. |
| public < The value type associated with the returned Promise. T> Promise | Returns: A new Promise that is resolved with the specified Promise.A Promise whose value or failure must be used to resolve the
returned Promise. Must not be with)null.Returns a new Promise that will be resolved with the specified Promise. |
| public ScheduledExecutorService | Returns: The scheduled executor to use for scheduled operations. This will be the default scheduled executor ifnull was specified
for the scheduled executor when this PromiseFactory was created.Returns the scheduled executor to use for scheduled operations. |
| public < The value type associated with the returned Promise. T> Promise | |
| public < The value type of the List value result of the collected
T, all(Collection) Promise.The value type of the input Promises. S extends T> Collector | Returns: ACollector which accumulates the results of all the
input Promises into a new all(Collection) Promise.Returns a |
| allowCurrentThread | back to summary |
|---|---|
| private final boolean allowCurrentThread | |
| callbackExecutor | back to summary |
|---|---|
| private final Executor callbackExecutor The executor to use for callbacks. If | |
| defaultFactory | back to summary |
|---|---|
| pack-priv static final PromiseFactory defaultFactory The default factory which uses the default callback executor and default scheduled executor. | |
| scheduledExecutor | back to summary |
|---|---|
| private final ScheduledExecutorService scheduledExecutor The executor to use for scheduled operations. If | |
| PromiseFactory | back to summary |
|---|---|
| public PromiseFactory(Executor callbackExecutor) Create a new PromiseFactory with the specified callback executor. The default scheduled executor and default options will be used.
| |
| PromiseFactory | back to summary |
|---|---|
| public PromiseFactory(Executor callbackExecutor, ScheduledExecutorService scheduledExecutor) Create a new PromiseFactory with the specified callback executor and specified scheduled executor. The default options will be used.
| |
| PromiseFactory | back to summary |
|---|---|
| public PromiseFactory(Executor callbackExecutor, ScheduledExecutorService scheduledExecutor, PromiseFactory. Create a new PromiseFactory with the specified callback executor, specified scheduled executor, and specified options.
| |
| all | back to summary |
|---|---|
| public <T, S extends T> Promise Returns a new Promise that is a latch on the resolution of the specified Promises. The returned Promise uses the callback executor and scheduled executor of this PromiseFactory object. The returned Promise acts as a gate and must be resolved after all of the specified Promises are resolved.
| |
| allowCurrentThread | back to summary |
|---|---|
| pack-priv boolean allowCurrentThread() | |
| combiner | back to summary |
|---|---|
| private static <E, C extends Collection | |
| defaultOptions | back to summary |
|---|---|
| private static PromiseFactory. | |
| deferred | back to summary |
|---|---|
| public <T> Deferred Create a new Deferred with the callback executor and scheduled executor of this PromiseFactory object.
Use this method instead of | |
| executor | back to summary |
|---|---|
| public Executor executor() Returns the executor to use for callbacks.
| |
| failed | back to summary |
|---|---|
| public <T> Promise Returns a new Promise that has been resolved with the specified failure. The returned Promise uses the callback executor and scheduled executor of this PromiseFactory object.
Use this method instead of | |
| inlineExecutor | back to summary |
|---|---|
| public static Executor inlineExecutor() Returns an Executor implementation that executes tasks immediately on the
thread calling the
| |
| resolved | back to summary |
|---|---|
| public <T> Promise Returns a new Promise that has been resolved with the specified value. The returned Promise uses the callback executor and scheduled executor of this PromiseFactory object.
Use this method instead of
| |
| resolvedWith | back to summary |
|---|---|
| public <T> Promise Returns a new Promise that will be resolved with the result of the specified CompletionStage. The returned Promise uses the callback executor and scheduled executor of this PromiseFactory object. If the specified CompletionStage is completed normally, the returned Promise is resolved with the value of the specified CompletionStage. If the specified CompletionStage is completed exceptionally, the returned Promise is resolved with the exception of the specified CompletionStage.
After the returned Promise is resolved with the specified
CompletionStage, all registered
Resolving the returned Promise happens-before any registered
callback is called. That is, in a registered callback,
| |
| resolvedWith | back to summary |
|---|---|
| public <T> Promise Returns a new Promise that will be resolved with the specified Promise. The returned Promise uses the callback executor and scheduled executor of this PromiseFactory object. If the specified Promise is successfully resolved, the returned Promise is resolved with the value of the specified Promise. If the specified Promise is resolved with a failure, the returned Promise is resolved with the failure of the specified Promise.
After the returned Promise is resolved with the specified Promise, all
registered
Resolving the returned Promise happens-before any registered
callback is called. That is, in a registered callback,
| |
| scheduledExecutor | back to summary |
|---|---|
| public ScheduledExecutorService scheduledExecutor() Returns the scheduled executor to use for scheduled operations.
| |
| submit | back to summary |
|---|---|
| public <T> Promise Returns a new Promise that will hold the result of the specified task. The returned Promise uses the callback executor and scheduled executor of this PromiseFactory object.
The specified task will be executed on the | |
| toPromise | back to summary |
|---|---|
| public <T, S extends T> Collector Returns a
| |
PromiseFactory#all(Collection)
method.
| Modifier and Type | Field and Description |
|---|---|
| private final DeferredPromiseImpl | |
| private final AtomicInteger | |
| private final List |
| Access | Constructor and Description |
|---|---|
| pack-priv |
| Modifier and Type | Method and Description |
|---|---|
| public void |
| chained | back to summary |
|---|---|
| private final DeferredPromiseImpl<List<T>> chained | |
| promiseCount | back to summary |
|---|---|
| private final AtomicInteger promiseCount | |
| promises | back to summary |
|---|---|
| private final List<Promise<S>> promises | |
| All | back to summary |
|---|---|
| pack-priv All(DeferredPromiseImpl<List<T>> chained, List<Promise<S>> promises) | |
| run | back to summary |
|---|---|
| public void run() Implements java. Doc from java. Runs this operation.
| |
| Modifier and Type | Class and Description |
|---|---|
| private static class | PromiseFactory.
ScheduledThreadPoolExecutor for scheduled execution. |
| Modifier and Type | Field and Description |
|---|---|
| private static final ThreadPoolExecutor | |
| private static final PromiseFactory. | |
| private final ThreadFactory | |
| private static final PromiseFactory. | |
| private final AtomicBoolean |
| Access | Constructor and Description |
|---|---|
| private |
| Modifier and Type | Method and Description |
|---|---|
| pack-priv static Executor | |
| public Thread | newThread(Runnable
a runnable to be executed by new thread instance r)Implements java. Executor threads should not prevent VM from exiting. |
| public void | rejectedExecution(Runnable
the runnable task requested to be executed callback, ThreadPoolExecutor the executor attempting to execute this task executor)Implements java. Call the callback using the caller's thread because the thread pool rejected the execution. |
| public void | |
| pack-priv static ScheduledExecutorService |
| callbackExecutor | back to summary |
|---|---|
| private static final ThreadPoolExecutor callbackExecutor | |
| callbacks | back to summary |
|---|---|
| private static final PromiseFactory. | |
| delegateThreadFactory | back to summary |
|---|---|
| private final ThreadFactory delegateThreadFactory | |
| scheduledExecutor | back to summary |
|---|---|
| private static final PromiseFactory. | |
| shutdownHookInstalled | back to summary |
|---|---|
| private final AtomicBoolean shutdownHookInstalled | |
| DefaultExecutors | back to summary |
|---|---|
| private DefaultExecutors() | |
| callbackExecutor | back to summary |
|---|---|
| pack-priv static Executor callbackExecutor() | |
| newThread | back to summary |
|---|---|
| public Thread newThread(Runnable r) Implements java. Executor threads should not prevent VM from exiting.
| |
| rejectedExecution | back to summary |
|---|---|
| public void rejectedExecution(Runnable callback, ThreadPoolExecutor executor) Implements java. Call the callback using the caller's thread because the thread pool rejected the execution.
| |
| run | back to summary |
|---|---|
| public void run() Implements java. Shutdown hook
| |
| scheduledExecutor | back to summary |
|---|---|
| pack-priv static ScheduledExecutorService scheduledExecutor() | |
| Access | Constructor and Description |
|---|---|
| pack-priv |
| Modifier and Type | Method and Description |
|---|---|
| protected void | afterExecute(Runnable
the runnable that has completed r, Throwable the exception that caused termination, or null if
execution completed normally t)Overrides java. Handle uncaught exceptions |
| ScheduledExecutor | back to summary |
|---|---|
| pack-priv ScheduledExecutor(int corePoolSize, ThreadFactory threadFactory) | |
| afterExecute | back to summary |
|---|---|
| protected void afterExecute(Runnable r, Throwable t) Overrides java. Handle uncaught exceptions
| |
Executor.execute method.
| Access | Constructor and Description |
|---|---|
| pack-priv |
| Modifier and Type | Method and Description |
|---|---|
| public void | execute(Runnable
the runnable task callback)Implements java. Executes the given command at some time in the future. |
| InlineExecutor | back to summary |
|---|---|
| pack-priv InlineExecutor() | |
| execute | back to summary |
|---|---|
| public void execute(Runnable callback) Implements java. Doc from java. Executes the given command at some time in the future. The command
may execute in a new thread, in a pooled thread, or in the calling
thread, at the discretion of the | |
The default options are no options unless the boolean system property
org.osgi.util.promise.allowCurrentThread is set to false.
When this is the case, the option Option#CALLBACKS_EXECUTOR_THREAD
is a default option.
| Modifier and Type | Field and Description |
|---|---|
| public static final PromiseFactory. | CALLBACKS_EXECUTOR_THREAD
Run callbacks on an executor thread. |
| Access | Constructor and Description |
|---|---|
| private |
| Modifier and Type | Method and Description |
|---|---|
| public static PromiseFactory. | |
| public static PromiseFactory. |
| CALLBACKS_EXECUTOR_THREAD | back to summary |
|---|---|
| public static final PromiseFactory. Run callbacks on an executor thread. If this option is not set, callbacks added to a resolved Promise may be immediately called on the caller's thread to avoid a thread context switch. | |
| Option | back to summary |
|---|---|
| private Option() | |
| valueOf | back to summary |
|---|---|
| public static PromiseFactory. | |
| values | back to summary |
|---|---|
| public static PromiseFactory. | |