Class AbstractFactoryOfTheFuture
java.lang.Object
space.arim.omnibus.util.concurrent.impl.AbstractFactoryOfTheFuture
- All Implemented Interfaces:
Executor, FactoryOfTheFuture, SynchronousExecutor
- Direct Known Subclasses:
IndifferentFactoryOfTheFuture
Abstract base class for
Requirements to be implemented by subclasses are
FactoryOfTheFuture using protected method
newIncompleteFuture() to generate futures as determined by subclasses. Requirements to be implemented by subclasses are
newIncompleteFuture() and
FactoryOfTheFuture.executeSync(Runnable). execute(Runnable) may be optionally overridden to change the default executor for
asynchronous work.- Author:
- A248
-
Constructor Summary
Constructors -
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.<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.abstract <U> CentralisedFuture<U> Creates a new, 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).Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface FactoryOfTheFuture
executeSync
-
Constructor Details
-
AbstractFactoryOfTheFuture
public AbstractFactoryOfTheFuture()
-
-
Method Details
-
newIncompleteFuture
Creates a new, incomplete future. The result of this method is used in implementing variousFactoryOfTheFuturespecifications.- Specified by:
newIncompleteFuturein interfaceFactoryOfTheFuture- Type Parameters:
U- the result type of the future- Returns:
- a new incomplete future
-
execute
Description copied from interface:FactoryOfTheFutureExecutes aRunnableasynchronously.- Specified by:
executein interfaceExecutor- Specified by:
executein interfaceFactoryOfTheFuture- Parameters:
command- the command
-
runAsync
Description copied from interface:FactoryOfTheFutureRuns aRunnableasynchronously and returns a future indicating its progress.- Specified by:
runAsyncin interfaceFactoryOfTheFuture- Parameters:
command- the runnable to run- Returns:
- a centralised future representing the runnable's progress
-
runAsync
Description copied from interface:FactoryOfTheFutureRuns aRunnableasynchronously using the providedExecutorand returns a future indicating its progress.- Specified by:
runAsyncin interfaceFactoryOfTheFuture- Parameters:
command- the runnable to runexecutor- the executor on which to run the runnable- Returns:
- a centralised future representing the runnable's progress
-
runSync
Description copied from interface:FactoryOfTheFutureRuns aRunnableon the main thread if a main thread exists, else appropriately, per the specifications ofSynchronousExecutor.executeSync(Runnable).- Specified by:
runSyncin interfaceFactoryOfTheFuture- Parameters:
command- the runnable to run- Returns:
- a centralised future representing the runnable's progress
-
supplyAsync
Description copied from interface:FactoryOfTheFutureSupplies a value asynchronously and returns a future indicating its progress.- Specified by:
supplyAsyncin interfaceFactoryOfTheFuture- Type Parameters:
T- the return type of the supplier- Parameters:
supplier- the supplier to run- Returns:
- a centralised future representing the supplier's progress
-
supplyAsync
Description copied from interface:FactoryOfTheFutureSupplies a value asynchronously using the providedExecutorand returns a future indicating its progress.- Specified by:
supplyAsyncin interfaceFactoryOfTheFuture- 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
-
supplySync
Description copied from interface:FactoryOfTheFutureSupplies a value on the main thread if a main thread exists, else appropriately, per the specifications ofSynchronousExecutor.executeSync(Runnable).- Specified by:
supplySyncin interfaceFactoryOfTheFuture- Type Parameters:
T- the return type of the supplier- Parameters:
supplier- the supplier to run- Returns:
- a centralised future representing the supplier's progress
-
completedFuture
Description copied from interface:FactoryOfTheFutureCreates a precompleted future which has completed normally with the given value.- Specified by:
completedFuturein interfaceFactoryOfTheFuture- 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
Description copied from interface:FactoryOfTheFutureCreates a precompleted stage which has completed normally with the given value.- Specified by:
completedStagein interfaceFactoryOfTheFuture- 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
Description copied from interface:FactoryOfTheFutureCreates a precompleted future which has completed exceptionally with the given exception.- Specified by:
failedFuturein interfaceFactoryOfTheFuture- 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
Description copied from interface:FactoryOfTheFutureCreates a precompleted stage which has completed exceptionally with the given exception.- Specified by:
failedStagein interfaceFactoryOfTheFuture- 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
-
copyFuture
Description copied from interface:FactoryOfTheFutureCopies 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.- Specified by:
copyFuturein interfaceFactoryOfTheFuture- 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
-
copyStage
Description copied from interface:FactoryOfTheFutureCopies 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.- Specified by:
copyStagein interfaceFactoryOfTheFuture- 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
-
allOf
Description copied from interface:FactoryOfTheFutureCreates 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.- Specified by:
allOfin interfaceFactoryOfTheFuture- Parameters:
futures- the futures to combine- Returns:
- a future completed combining the specified futures
-
allOf
Description copied from interface:FactoryOfTheFutureCreates 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.- Specified by:
allOfin interfaceFactoryOfTheFuture- 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
-