Interface FactoryOfTheFuture
- All Superinterfaces:
Executor, SynchronousExecutor
- All Known Implementing Classes:
AbstractFactoryOfTheFuture, IndifferentFactoryOfTheFuture
Concurrent executor and producer of
CentralisedFuture. Intended
to manage both asynchronous execution and synchronisation to the main thread.- Author:
- A248
-
Method Summary
Modifier and TypeMethodDescription<T> CentralisedFuture<?> allOf(Collection<? extends CentralisedFuture<T>> futures) Creates a future which completes when all of the specified futures complete.allOf(CentralisedFuture<?>... futures) Creates a future which completes when all of the specified futures complete.<T> CentralisedFuture<T> completedFuture(T value) Creates a precompleted future which has completed normally with the given value.<T> ReactionStage<T> completedStage(T value) Creates a precompleted stage which has completed normally with the given value.<T> CentralisedFuture<T> copyFuture(CompletableFuture<T> completableFuture) Copies aCompletableFutureto aCentralisedFuture.<T> ReactionStage<T> copyStage(CompletionStage<T> completionStage) Copies aCompletionStageto aReactionStage.voidExecutes aRunnableasynchronously.voidexecuteSync(Runnable command) Runs the Runnable on the main thread, if the application has a main thread, else executes it in a thread pool suitable for computational work such asForkJoinPool.commonPool()<T> CentralisedFuture<T> Creates a precompleted future which has completed exceptionally with the given exception.<T> ReactionStage<T> failedStage(Throwable ex) Creates a precompleted stage which has completed exceptionally with the given exception.<T> CentralisedFuture<T> Creates an incomplete future.Runs aRunnableasynchronously and returns a future indicating its progress.Runs aRunnableon the main thread if a main thread exists, else appropriately, per the specifications ofSynchronousExecutor.executeSync(Runnable).<T> CentralisedFuture<T> supplyAsync(Supplier<T> supplier) Supplies a value asynchronously and returns a future indicating its progress.<T> CentralisedFuture<T> supplyAsync(Supplier<T> supplier, Executor executor) Supplies a value asynchronously using the providedExecutorand returns a future indicating its progress.<T> CentralisedFuture<T> supplySync(Supplier<T> supplier) Supplies a value on the main thread if a main thread exists, else appropriately, per the specifications ofSynchronousExecutor.executeSync(Runnable).
-
Method Details
-
execute
-
executeSync
Runs the Runnable on the main thread, if the application has a main thread, else executes it in a thread pool suitable for computational work such asForkJoinPool.commonPool()- Specified by:
executeSyncin interfaceSynchronousExecutor- Parameters:
command- the runnable to run synchronously with the main thread
-
runAsync
Runs aRunnableasynchronously and returns a future indicating its progress.- Parameters:
command- the runnable to run- Returns:
- a centralised future representing the runnable's progress
- Throws:
NullPointerException- ifcommandis null
-
runAsync
Runs aRunnableasynchronously using the providedExecutorand returns a future indicating its progress.- Parameters:
command- the runnable to runexecutor- the executor on which to run the runnable- Returns:
- a centralised future representing the runnable's progress
- Throws:
NullPointerException- ifcommandorexecutoris null
-
runSync
Runs aRunnableon the main thread if a main thread exists, else appropriately, per the specifications ofSynchronousExecutor.executeSync(Runnable).- Parameters:
command- the runnable to run- Returns:
- a centralised future representing the runnable's progress
- Throws:
NullPointerException- ifcommandis null
-
supplyAsync
Supplies a value asynchronously and returns a future indicating its progress.- Type Parameters:
T- the return type of the supplier- Parameters:
supplier- the supplier to run- Returns:
- a centralised future representing the supplier's progress
- Throws:
NullPointerException- ifsupplieris null
-
supplyAsync
Supplies a value asynchronously using the providedExecutorand returns a future indicating its progress.- Type Parameters:
T- the return type of the supplier- Parameters:
supplier- the supplier to runexecutor- the executor on which to run the supplier- Returns:
- a centralised future representing the supplier's progress
- Throws:
NullPointerException- ifsupplierorexecutoris null
-
supplySync
Supplies a value on the main thread if a main thread exists, else appropriately, per the specifications ofSynchronousExecutor.executeSync(Runnable).- Type Parameters:
T- the return type of the supplier- Parameters:
supplier- the supplier to run- Returns:
- a centralised future representing the supplier's progress
- Throws:
NullPointerException- ifsupplieris null
-
completedFuture
Creates a precompleted future which has completed normally with the given value.- Type Parameters:
T- the result type of the future- Parameters:
value- the value with which to complete the future- Returns:
- a future completed normally with the given value
-
completedStage
Creates a precompleted stage which has completed normally with the given value.- Type Parameters:
T- the result type of the stage- Parameters:
value- the value with which to complete the stage- Returns:
- a stage completed normally with the given value
-
failedFuture
Creates a precompleted future which has completed exceptionally with the given exception.- Type Parameters:
T- the result type of the future- Parameters:
ex- the exception with which to complete the future- Returns:
- a future completeld exceptionally with the given exception
-
failedStage
Creates a precompleted stage which has completed exceptionally with the given exception.- Type Parameters:
T- the result type of the stage- Parameters:
ex- the exception with which to complete the stage- Returns:
- a stage completeld exceptionally with the given exception
-
newIncompleteFuture
Creates an incomplete future.- Type Parameters:
T- the result type of the future- Returns:
- an incomplete future
-
copyFuture
Copies aCompletableFutureto aCentralisedFuture.
When the completable future completes, if it does so normally, the centralised future is also completed normally with the same result. Else, if the former completes exceptionally, the latter is also completed exceptionally with the same exception.- Type Parameters:
T- the result type of the future- Parameters:
completableFuture- the completable future- Returns:
- a centralised future completed in the same way as the original completable future
- Throws:
NullPointerException- ifcompletableFutureis null
-
copyStage
Copies aCompletionStageto aReactionStage.
When the completable future completes, if it does so normally, the reaction stage is also completed normally with the same result. Else, if the former completes exceptionally, the latter is also completed exceptionally with the same exception.- Type Parameters:
T- the result type of the stage- Parameters:
completionStage- the completion stage- Returns:
- a reaction stage completed in the same way as the original completion stage
- Throws:
NullPointerException- ifcompletionStageis null
-
allOf
Creates a future which completes when all of the specified futures complete. If all do so normally, the combined future completes normally, else exceptionally with the exception.
If no futures are provided, returns an already completed future.
Note that the completed value of the combined future, if it completes normally, is not meaningful.- Parameters:
futures- the futures to combine- Returns:
- a future completed combining the specified futures
- Throws:
NullPointerException- iffuturesor an element in it is null
-
allOf
Creates a future which completes when all of the specified futures complete. If all do so normally, the combined future completes normally, else exceptionally with the exception.
If no futures are provided, returns an already completed future.
Note that the completed value of the combined future, if it completes normally, is not meaningful.- Type Parameters:
T- the type of object yielded by the futures- Parameters:
futures- the futures to combine- Returns:
- a future completed combining the specified futures
- Throws:
NullPointerException- iffuturesor an element in it is null
-