Class CffuFactory
CffuFactory is equivalent to CompletableFuture,
contains the static (factory) methods of CompletableFuture.
The methods that equivalent to the instance methods of CompletableFuture is in Cffu class.
Use builder(Executor) to config and build CffuFactory.
About factory methods convention of CffuFactory:
- factory methods return
Cffuinstead ofCompletableFuture. - only provide varargs methods for multiple Cffu/CF input arguments;
if you have
Listinput, use variant methods inCffuFactory.IterableOps.
- Author:
- Jerry Lee (oldratlee at gmail dot com), HuHao (995483610 at qq dot com)
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionfinal classTheIterable-based variants (includingCollection,List, etc.) of same-named varargs methods fromCffuFactory.final classThe methods for parallel data processing.final classThe tuple-based variants of methods fromCffuFactoryfor processing and composing multiple asynchronous actions and CompletableFutures in a type-safe manner. -
Method Summary
Modifier and TypeMethodDescriptionallFailFastOf(CompletionStage<?>... cfs) Returns a new Cffu that is completed normally when all the given stages complete normally; If any of the given stages complete exceptionally, then the returned Cffu also does so, WITHOUT waiting other incomplete given stages, with a CompletionException holding this exception as its cause.allOf(CompletionStage<?>... cfs) Returns a new Cffu that is completed when all the given stages complete; If any of the given stages complete exceptionally, then the returned Cffu also does so, with a CompletionException holding this exception as its cause.allResultsFailFastOf(CompletionStage<? extends T>... cfs) Returns a new Cffu that is completed normally with a list containing the successful results of all given stages when all the given stages complete normally; If any of the given stages complete exceptionally, then the returned Cffu also does so, WITHOUT waiting other incomplete given stages, with a CompletionException holding this exception as its cause.allResultsOf(CompletionStage<? extends T>... cfs) Returns a new Cffu that is completed normally with a list containing the successful results of all given stages when all the given stages complete; If any of the given stages complete exceptionally, then the returned Cffu also does so, with a CompletionException holding this exception as its cause.allSuccessResultsOf(T valueIfFailed, CompletionStage<? extends T>... cfs) Returns a new Cffu that is completed normally with a list containing the successful results of all given stages when all the given stages complete; The list of results is in the same order as the input list, and if any of given stages complete exceptionally, their corresponding position will containvalueIfFailed(which is indistinguishable from the stage having a successful value ofvalueIfFailed).final <T> Cffu<T> anyOf(CompletionStage<? extends T>... cfs) Returns a new Cffu that is completed when any of the given stages complete, with the same result.final <T> Cffu<T> anySuccessOf(CompletionStage<? extends T>... cfs) Returns a new Cffu that completed normally when any of the given stages complete normally, with the same result; Otherwise, when all the given stages complete exceptionally, the returned Cffu also does so, with a CompletionException holding an exception from any of the given stages as its cause.static CffuFactoryBuilderReturns aCffuFactoryBuilderwithdefaultExecutorsetting.<T> Cffu<T> completedFuture(T value) Returns a new Cffu that is already completed with the given value.completedMCffu(T value) Returns a new MCffu that is already completed with the given value.<T> CompletionStage<T> completedStage(T value) Returns a new CompletionStage that is already completed with the given value and supports only those methods in interfaceCompletionStage.concurrencyLimitExecutor(int maxConcurrency) Returns a new Executor that submits a task to the default executor and limits the number of concurrent tasks.concurrencyLimitExecutor(int maxConcurrency, Executor executor) Returns a new Executor that submits a task to the given base executor and limits the number of concurrent tasks.Returns the default Executor used for async methods that do not specify an Executor.delayedExecutor(long delay, TimeUnit unit) Returns a new Executor that submits a task to the default executor after the given delay (or no delay if non-positive).delayedExecutor(long delay, TimeUnit unit, Executor executor) Returns a new Executor that submits a task to the given base executor after the given delay (or no delay if non-positive).<T> Cffu<T> Returns a new Cffu that is already completed exceptionally with the given exception.failedMCffu(Throwable ex) Returns a new MCffu that is already completed exceptionally with the given exception.<T> CompletionStage<T> failedStage(Throwable ex) Returns a new CompletionStage that is already completed exceptionally with the given exception and supports only those methods in interfaceCompletionStage.booleanReturnsforbidObtrudeMethodsor not.<T> Cffu<T> fromSyncCall(Callable<? extends T> callable) Returns a new Cffu that encapsulates the execution of synchronous logic.Returns aCffuFactory.IterableOpsinstance to access theIterable-based variants (includingCollection,List, etc.) of same-named varargs methods fromCffuFactory.mCffuFromSyncCall(Callable<? extends T> callable) Returns a new MCffu that encapsulates the execution of synchronous logic.mostSuccessResultsOf(T valueIfNotSuccess, long timeout, TimeUnit unit, CompletionStage<? extends T>... cfs) Returns a new Cffu that is completed normally with a list containing the successful results of the given stages before the given timeout, i.e.mRunAnyAsync(Runnable... actions) Shortcut to methodanyOf, wraps input actions to Cffu byrunAsync(Runnable).mRunAnyAsync(Executor executor, Runnable... actions) Shortcut to methodanyOf, wraps input actions to Cffu byrunAsync(Runnable, Executor).mRunAnySuccessAsync(Runnable... actions) Shortcut to methodanySuccessOf, wraps input actions to Cffu byrunAsync(Runnable).mRunAnySuccessAsync(Executor executor, Runnable... actions) Shortcut to methodanySuccessOf, wraps input actions to Cffu byrunAsync(Runnable, Executor).Shortcut to methodallOf, wraps input actions to Cffu byrunAsync(Runnable).Shortcut to methodallOf, wraps input actions to Cffu byrunAsync(Runnable, Executor).voidmRunAsyncAndForget(Runnable... actions) Runs all input actions async and forget (returnvoid).voidmRunAsyncAndForget(Executor executor, Runnable... actions) Runs all input actions async and forget (returnvoid).mRunFailFastAsync(Runnable... actions) Shortcut to methodallFailFastOf, wraps input actions to Cffu byrunAsync(Runnable).mRunFailFastAsync(Executor executor, Runnable... actions) Shortcut to methodallFailFastOf, wraps input actions to Cffu byrunAsync(Runnable, Executor).mSupplyAllSuccessAsync(E valueIfFailed, Supplier<? extends E>... suppliers) Shortcut to methodallSuccessResultsOf, wraps input suppliers to Cffu bysupplyAsync(Supplier).mSupplyAllSuccessAsync(Executor executor, E valueIfFailed, Supplier<? extends E>... suppliers) Shortcut to methodallSuccessResultsOf, wraps input suppliers to Cffu bysupplyAsync(Supplier, Executor).final <T> Cffu<T> mSupplyAnyAsync(Executor executor, Supplier<? extends T>... suppliers) Shortcut to methodanySuccessOf, wraps input suppliers to Cffu bysupplyAsync(Supplier, Executor).final <T> Cffu<T> mSupplyAnyAsync(Supplier<? extends T>... suppliers) Shortcut to methodanyOf, wraps input suppliers to Cffu bysupplyAsync(Supplier).final <T> Cffu<T> mSupplyAnySuccessAsync(Executor executor, Supplier<? extends T>... suppliers) Shortcut to methodanySuccessOf, wraps input suppliers to Cffu bysupplyAsync(Supplier, Executor).final <T> Cffu<T> mSupplyAnySuccessAsync(Supplier<? extends T>... suppliers) Shortcut to methodanySuccessOf, wraps input suppliers to Cffu bysupplyAsync(Supplier).mSupplyAsync(Executor executor, Supplier<? extends E>... suppliers) Shortcut to methodallResultsOf, wraps input suppliers to Cffu bysupplyAsync(Supplier, Executor).mSupplyAsync(Supplier<? extends E>... suppliers) Shortcut to methodallResultsOf, wraps input suppliers to Cffu bysupplyAsync(Supplier).mSupplyFailFastAsync(Executor executor, Supplier<? extends E>... suppliers) Shortcut to methodallResultsFailFastOf, wraps input suppliers to Cffu bysupplyAsync(Supplier, Executor).mSupplyFailFastAsync(Supplier<? extends E>... suppliers) Shortcut to methodallResultsFailFastOf, wraps input suppliers to Cffu bysupplyAsync(Supplier).mSupplyMostSuccessAsync(E valueIfNotSuccess, long timeout, TimeUnit unit, Supplier<? extends E>... suppliers) Shortcut to methodmostSuccessResultsOf, wraps input suppliers to Cffu bysupplyAsync(Supplier).mSupplyMostSuccessAsync(Executor executor, E valueIfNotSuccess, long timeout, TimeUnit unit, Supplier<? extends E>... suppliers) Shortcut to methodmostSuccessResultsOf, wraps input suppliers to Cffu bysupplyAsync(Supplier).<T> Cffu<T> Returns a new incomplete Cffu.Returns a new incomplete MCffu.parOps()Returns aCffuFactory.ParOpsinstance to access the methods for parallel data processing.Returns a new Cffu that is asynchronously completed by a task running in thedefaultExecutor()after it runs the given action.Returns a new Cffu that is asynchronously completed by a task running in the given executor after it runs the given action.Returns anExecutorthat submits a task to the default executor and runs each task executed sequentially, such that no two tasks are running concurrently.sequentialExecutor(Executor executor) Returns anExecutorthat submits a task to the given base executor and runs each task executed sequentially, such that no two tasks are running concurrently.<T> Cffu<T> supplyAsync(Supplier<T> supplier) Returns a new Cffu that is asynchronously completed by a task running in thedefaultExecutor()with the value obtained by calling the given Supplier.<T> Cffu<T> supplyAsync(Supplier<T> supplier, Executor executor) Returns a new Cffu that is asynchronously completed by a task running in the given executor with the value obtained by calling the given Supplier.<T> Cffu<T> toCffu(CompletionStage<T> stage) Returns a Cffu that maintains the same completion properties as the given stage, configured with thisCffuFactory.toMCffu(CompletionStage<T> stage) Returns a MCffu that maintains the same completion properties as the given stage, configured with thisCffuFactory.tupleOps()Returns aCffuFactory.TupleOpsinstance to access the tuple-based variants of methods fromCffuFactoryfor processing and composing multiple asynchronous actions and CompletableFutures in a type-safe manner.withDefaultExecutor(Executor defaultExecutor) Returns a new CffuFactory from this CffuFactory with the defaultExecutor.
-
Method Details
-
builder
Returns aCffuFactoryBuilderwithdefaultExecutorsetting.- See Also:
-
withDefaultExecutor
Returns a new CffuFactory from this CffuFactory with the defaultExecutor. -
supplyAsync
@CheckReturnValue(explanation="should use the returned Cffu; otherwise, prefer method `mRunAsyncAndForget`") public <T> Cffu<T> supplyAsync(Supplier<T> supplier) Returns a new Cffu that is asynchronously completed by a task running in thedefaultExecutor()with the value obtained by calling the given Supplier.- Type Parameters:
T- the function's return type- Parameters:
supplier- a function returning the value to be used to complete the returned Cffu
-
supplyAsync
@CheckReturnValue(explanation="should use the returned Cffu; otherwise, prefer method `mRunAsyncAndForget`") public <T> Cffu<T> supplyAsync(Supplier<T> supplier, Executor executor) Returns a new Cffu that is asynchronously completed by a task running in the given executor with the value obtained by calling the given Supplier.- Type Parameters:
T- the function's return type- Parameters:
supplier- a function returning the value to be used to complete the returned Cffuexecutor- the executor to use for asynchronous execution
-
runAsync
@CheckReturnValue(explanation="should use the returned Cffu; otherwise, prefer method `mRunAsyncAndForget`") public Cffu<Void> runAsync(Runnable action) Returns a new Cffu that is asynchronously completed by a task running in thedefaultExecutor()after it runs the given action.- Parameters:
action- the action to run before completing the returned Cffu
-
runAsync
@CheckReturnValue(explanation="should use the returned Cffu; otherwise, prefer method `mRunAsyncAndForget`") public Cffu<Void> runAsync(Runnable action, Executor executor) Returns a new Cffu that is asynchronously completed by a task running in the given executor after it runs the given action.- Parameters:
action- the action to run before completing the returned Cffuexecutor- the executor to use for asynchronous execution
-
mSupplyFailFastAsync
@CheckReturnValue(explanation="should use the returned Cffu; otherwise, use method `mRunAsyncAndForget`") @SafeVarargs public final <E> MCffu<E,List<E>> mSupplyFailFastAsync(Supplier<? extends E>... suppliers) Shortcut to methodallResultsFailFastOf, wraps input suppliers to Cffu bysupplyAsync(Supplier).See the
allResultsFailFastOfdocumentation for the rules of result computation. -
mSupplyFailFastAsync
@CheckReturnValue(explanation="should use the returned Cffu; otherwise, use method `mRunAsyncAndForget`") @SafeVarargs public final <E> MCffu<E,List<E>> mSupplyFailFastAsync(Executor executor, Supplier<? extends E>... suppliers) Shortcut to methodallResultsFailFastOf, wraps input suppliers to Cffu bysupplyAsync(Supplier, Executor).See the
allResultsFailFastOfdocumentation for the rules of result computation. -
mSupplyAllSuccessAsync
@CheckReturnValue(explanation="should use the returned Cffu; otherwise, use method `mRunAsyncAndForget`") @SafeVarargs public final <E> MCffu<E,List<E>> mSupplyAllSuccessAsync(@Nullable E valueIfFailed, Supplier<? extends E>... suppliers) Shortcut to methodallSuccessResultsOf, wraps input suppliers to Cffu bysupplyAsync(Supplier).See the
allSuccessResultsOfdocumentation for the rules of result computation. -
mSupplyAllSuccessAsync
@CheckReturnValue(explanation="should use the returned Cffu; otherwise, use method `mRunAsyncAndForget`") @SafeVarargs public final <E> MCffu<E,List<E>> mSupplyAllSuccessAsync(Executor executor, @Nullable E valueIfFailed, Supplier<? extends E>... suppliers) Shortcut to methodallSuccessResultsOf, wraps input suppliers to Cffu bysupplyAsync(Supplier, Executor).See the
allSuccessResultsOfdocumentation for the rules of result computation. -
mSupplyMostSuccessAsync
@CheckReturnValue(explanation="should use the returned Cffu; otherwise, use method `mRunAsyncAndForget`") @SafeVarargs public final <E> MCffu<E,List<E>> mSupplyMostSuccessAsync(@Nullable E valueIfNotSuccess, long timeout, TimeUnit unit, Supplier<? extends E>... suppliers) Shortcut to methodmostSuccessResultsOf, wraps input suppliers to Cffu bysupplyAsync(Supplier).See the
mostSuccessResultsOfdocumentation for the rules of result computation. -
mSupplyMostSuccessAsync
@CheckReturnValue(explanation="should use the returned Cffu; otherwise, use method `mRunAsyncAndForget`") @SafeVarargs public final <E> MCffu<E,List<E>> mSupplyMostSuccessAsync(Executor executor, @Nullable E valueIfNotSuccess, long timeout, TimeUnit unit, Supplier<? extends E>... suppliers) Shortcut to methodmostSuccessResultsOf, wraps input suppliers to Cffu bysupplyAsync(Supplier).See the
mostSuccessResultsOfdocumentation for the rules of result computation. -
mSupplyAsync
@CheckReturnValue(explanation="should use the returned Cffu; otherwise, use method `mRunAsyncAndForget`") @SafeVarargs public final <E> MCffu<E,List<E>> mSupplyAsync(Supplier<? extends E>... suppliers) Shortcut to methodallResultsOf, wraps input suppliers to Cffu bysupplyAsync(Supplier).See the
allResultsOfdocumentation for the rules of result computation. -
mSupplyAsync
@CheckReturnValue(explanation="should use the returned Cffu; otherwise, use method `mRunAsyncAndForget`") @SafeVarargs public final <E> MCffu<E,List<E>> mSupplyAsync(Executor executor, Supplier<? extends E>... suppliers) Shortcut to methodallResultsOf, wraps input suppliers to Cffu bysupplyAsync(Supplier, Executor).See the
allResultsOfdocumentation for the rules of result computation. -
mSupplyAnySuccessAsync
@CheckReturnValue(explanation="should use the returned Cffu; otherwise, use method `mRunAsyncAndForget`") @SafeVarargs public final <T> Cffu<T> mSupplyAnySuccessAsync(Supplier<? extends T>... suppliers) Shortcut to methodanySuccessOf, wraps input suppliers to Cffu bysupplyAsync(Supplier).See the
anySuccessOfdocumentation for the rules of result computation. -
mSupplyAnySuccessAsync
@CheckReturnValue(explanation="should use the returned Cffu; otherwise, use method `mRunAsyncAndForget`") @SafeVarargs public final <T> Cffu<T> mSupplyAnySuccessAsync(Executor executor, Supplier<? extends T>... suppliers) Shortcut to methodanySuccessOf, wraps input suppliers to Cffu bysupplyAsync(Supplier, Executor).See the
anySuccessOfdocumentation for the rules of result computation. -
mSupplyAnyAsync
@CheckReturnValue(explanation="should use the returned Cffu; otherwise, use method `mRunAsyncAndForget`") @SafeVarargs public final <T> Cffu<T> mSupplyAnyAsync(Supplier<? extends T>... suppliers) Shortcut to methodanyOf, wraps input suppliers to Cffu bysupplyAsync(Supplier).See the
anySuccessOfdocumentation for the rules of result computation. -
mSupplyAnyAsync
@CheckReturnValue(explanation="should use the returned Cffu; otherwise, use method `mRunAsyncAndForget`") @SafeVarargs public final <T> Cffu<T> mSupplyAnyAsync(Executor executor, Supplier<? extends T>... suppliers) Shortcut to methodanySuccessOf, wraps input suppliers to Cffu bysupplyAsync(Supplier, Executor).See the
anyOfdocumentation for the rules of result computation. -
mRunFailFastAsync
@CheckReturnValue(explanation="should use the returned Cffu; otherwise, use method `mRunAsyncAndForget`") public Cffu<Void> mRunFailFastAsync(Runnable... actions) Shortcut to methodallFailFastOf, wraps input actions to Cffu byrunAsync(Runnable).See the
allFailFastOfdocumentation for the rules of result computation. -
mRunFailFastAsync
@CheckReturnValue(explanation="should use the returned Cffu; otherwise, use method `mRunAsyncAndForget`") public Cffu<Void> mRunFailFastAsync(Executor executor, Runnable... actions) Shortcut to methodallFailFastOf, wraps input actions to Cffu byrunAsync(Runnable, Executor).See the
allFailFastOfdocumentation for the rules of result computation. -
mRunAsync
@CheckReturnValue(explanation="should use the returned Cffu; otherwise, use method `mRunAsyncAndForget`") public Cffu<Void> mRunAsync(Runnable... actions) Shortcut to methodallOf, wraps input actions to Cffu byrunAsync(Runnable).See the
allOfdocumentation for the rules of result computation. -
mRunAsync
@CheckReturnValue(explanation="should use the returned Cffu; otherwise, use method `mRunAsyncAndForget`") public Cffu<Void> mRunAsync(Executor executor, Runnable... actions) Shortcut to methodallOf, wraps input actions to Cffu byrunAsync(Runnable, Executor).See the
allOfdocumentation for the rules of result computation. -
mRunAnySuccessAsync
@CheckReturnValue(explanation="should use the returned Cffu; otherwise, use method `mRunAsyncAndForget`") public Cffu<Void> mRunAnySuccessAsync(Runnable... actions) Shortcut to methodanySuccessOf, wraps input actions to Cffu byrunAsync(Runnable).See the
anySuccessOfdocumentation for the rules of result computation. -
mRunAnySuccessAsync
@CheckReturnValue(explanation="should use the returned Cffu; otherwise, use method `mRunAsyncAndForget`") public Cffu<Void> mRunAnySuccessAsync(Executor executor, Runnable... actions) Shortcut to methodanySuccessOf, wraps input actions to Cffu byrunAsync(Runnable, Executor).See the
anySuccessOfdocumentation for the rules of result computation. -
mRunAnyAsync
@CheckReturnValue(explanation="should use the returned Cffu; otherwise, use method `mRunAsyncAndForget`") public Cffu<Void> mRunAnyAsync(Runnable... actions) Shortcut to methodanyOf, wraps input actions to Cffu byrunAsync(Runnable).See the
anyOfdocumentation for the rules of result computation. -
mRunAnyAsync
@CheckReturnValue(explanation="should use the returned Cffu; otherwise, use method `mRunAsyncAndForget`") public Cffu<Void> mRunAnyAsync(Executor executor, Runnable... actions) Shortcut to methodanyOf, wraps input actions to Cffu byrunAsync(Runnable, Executor).See the
anyOfdocumentation for the rules of result computation. -
mRunAsyncAndForget
Runs all input actions async and forget (returnvoid). This method explicitly indicates that the caller will not care about any exceptions from actions and will not wait for the computations to complete ("fire-and-forget").- Since:
- 2.1.0
-
mRunAsyncAndForget
Runs all input actions async and forget (returnvoid). This method explicitly indicates that the caller will not care about any exceptions from actions and will not wait for the computations to complete ("fire-and-forget").- Since:
- 2.1.0
-
allResultsFailFastOf
@Contract(pure=true) @SafeVarargs public final <T> MCffu<T,List<T>> allResultsFailFastOf(CompletionStage<? extends T>... cfs) Returns a new Cffu that is completed normally with a list containing the successful results of all given stages when all the given stages complete normally; If any of the given stages complete exceptionally, then the returned Cffu also does so, WITHOUT waiting other incomplete given stages, with a CompletionException holding this exception as its cause. If no stages are provided, returns a Cffu completed with the value empty list.The list of results is in the same order as the input list.
This method is the same as
allResultsOfmethod except for the fail-fast behavior.- Throws:
NullPointerException- if the cfs param or any of its elements arenull- See Also:
-
allSuccessResultsOf
@Contract(pure=true) @SafeVarargs public final <T> MCffu<T,List<T>> allSuccessResultsOf(@Nullable T valueIfFailed, CompletionStage<? extends T>... cfs) Returns a new Cffu that is completed normally with a list containing the successful results of all given stages when all the given stages complete; The list of results is in the same order as the input list, and if any of given stages complete exceptionally, their corresponding position will containvalueIfFailed(which is indistinguishable from the stage having a successful value ofvalueIfFailed). If no stages are provided, returns a Cffu completed with the value empty list.The list of results is in the same order as the input list.
This method differs from
allResultsFailFastOfmethod in that it's tolerant of failed stages for any of the items, representing them asvalueIfFailedin the result list.- Parameters:
valueIfFailed- the value used as the result if the input stage completed exceptionally- Throws:
NullPointerException- if the cfs param or any of its elements isnull- See Also:
-
mostSuccessResultsOf
@Contract(pure=true) @SafeVarargs public final <T> MCffu<T,List<T>> mostSuccessResultsOf(@Nullable T valueIfNotSuccess, long timeout, TimeUnit unit, CompletionStage<? extends T>... cfs) Returns a new Cffu that is completed normally with a list containing the successful results of the given stages before the given timeout, i.e. as many results as possible in the given time; The list of results is in the same order as the input list, and if any of given stages complete exceptionally or are incomplete, their corresponding positions will containvalueIfNotSuccess(which is indistinguishable from the stage having a successful value ofvalueIfNotSuccess). If no stages are provided, returns a Cffu completed with the value empty list.The list of results is in the same order as the input list.
This method differs from
allResultsFailFastOfmethod in that it's tolerant of failed or incomplete stages for any of the items, representing them asvalueIfNotSuccessin the result list.- Parameters:
valueIfNotSuccess- the value used as the result if the input stage not completed normallytimeout- how long to wait in units ofunitunit- aTimeUnitdetermining how to interpret thetimeoutparameter- Throws:
NullPointerException- if the cfs param or any of its elements arenull- See Also:
-
allResultsOf
@Contract(pure=true) @SafeVarargs public final <T> MCffu<T,List<T>> allResultsOf(CompletionStage<? extends T>... cfs) Returns a new Cffu that is completed normally with a list containing the successful results of all given stages when all the given stages complete; If any of the given stages complete exceptionally, then the returned Cffu also does so, with a CompletionException holding this exception as its cause. If no stages are provided, returns a Cffu completed with the value empty list.The list of results is in the same order as the input list.
Comparing the waiting-all-complete behavior of this method, the fail-fast behavior of
allResultsFailFastOfmethod is more responsive to user and generally more desired in the application.This method is the same as
allOfmethod, except that the returned Cffu contains the results of the given stages.- Throws:
NullPointerException- if the cfs param or any of its elements arenull
-
allFailFastOf
Returns a new Cffu that is completed normally when all the given stages complete normally; If any of the given stages complete exceptionally, then the returned Cffu also does so, WITHOUT waiting other incomplete given stages, with a CompletionException holding this exception as its cause. If no stages are provided, returns a Cffu completed with the valuenull.The successful results, if any, of the given stages are not reflected in the returned Cffu (
Cffu<Void>), but may be obtained by inspecting them individually; Or using the below methods reflected results in the returned Cffu which are more convenient, safer and best-practice of concurrency:allResultsFailFastOf,allTupleFailFastOfallSuccessResultsOf,allSuccessTupleOfmostSuccessResultsOf,mostSuccessTupleOfallResultsOf,allTupleOf
This method is the same as
allOfmethod except for the fail-fast behavior.- Throws:
NullPointerException- if the cfs param or any of its elements arenull- See Also:
-
allOf
@CheckReturnValue(explanation="should use the returned Cffu; forget to call its `join()` method?") @Contract(pure=true) public Cffu<Void> allOf(CompletionStage<?>... cfs) Returns a new Cffu that is completed when all the given stages complete; If any of the given stages complete exceptionally, then the returned Cffu also does so, with a CompletionException holding this exception as its cause. If no stages are provided, returns a Cffu completed with the valuenull.The successful results, if any, of the given stages are not reflected in the returned Cffu (
Cffu<Void>), but may be obtained by inspecting them individually; Or using the below methods reflected results in the returned Cffu which are more convenient, safer and best-practice of concurrency:allResultsOf,allTupleOfallResultsFailFastOf,allTupleFailFastOfallSuccessResultsOf,allSuccessTupleOfmostSuccessResultsOf,mostSuccessTupleOf
Among the applications of this method is to await completion of a set of independent stages before continuing a program, as in:
cffuFactory.allOf(c1, c2, c3).join();.- Throws:
NullPointerException- if the cfs param or any of its elements arenull- See Also:
-
anySuccessOf
Returns a new Cffu that completed normally when any of the given stages complete normally, with the same result; Otherwise, when all the given stages complete exceptionally, the returned Cffu also does so, with a CompletionException holding an exception from any of the given stages as its cause. If no stages are provided, returns a new Cffu that is already completed exceptionally with aNoCfsProvidedException.This method differs from
anyOfmethod in that this method is any-success instead of the any-complete behavior of methodanyOf.- Throws:
NullPointerException- if the cfs param or any of its elements arenull
-
anyOf
@Contract(pure=true) @SafeVarargs public final <T> Cffu<T> anyOf(CompletionStage<? extends T>... cfs) Returns a new Cffu that is completed when any of the given stages complete, with the same result. Otherwise, if it completed exceptionally, the returned Cffu also does so, with a CompletionException holding this exception as its cause. If no stages are provided, returns an incomplete Cffu.Comparing the any-complete behavior of this method, the any-success behavior of method
anySuccessOfis more responsive to user and generally more desired in the application.- Throws:
NullPointerException- if the cfs param or any of its elements arenull
-
completedFuture
Returns a new Cffu that is already completed with the given value.- Type Parameters:
T- The result type returned future- Parameters:
value- the value- Returns:
- the completed Cffu
- See Also:
-
failedFuture
Returns a new Cffu that is already completed exceptionally with the given exception.- Type Parameters:
T- The result type returned future- Parameters:
ex- the exception- Returns:
- the exceptionally completed Cffu
- See Also:
-
completedMCffu
@Contract(pure=true) public <E,T extends Iterable<? extends E>> MCffu<E,T> completedMCffu(@Nullable T value) Returns a new MCffu that is already completed with the given value.- Type Parameters:
E- the data element type of result collectionT- The result collection type returned future- Parameters:
value- the value- Returns:
- the completed MCffu
- See Also:
-
failedMCffu
@Contract(pure=true) public <E,T extends Iterable<? extends E>> MCffu<E,T> failedMCffu(Throwable ex) Returns a new MCffu that is already completed exceptionally with the given exception.- Type Parameters:
E- the data element type of result collectionT- The result collection type returned future- Parameters:
ex- the exception- Returns:
- the exceptionally completed MCffu
- See Also:
-
completedStage
Returns a new CompletionStage that is already completed with the given value and supports only those methods in interfaceCompletionStage.CAUTION: if run on old Java 8 (which does not support *minimal* CompletionStage), this method just returns a *normal* Cffu instance which is NOT a *minimal* CompletionStage.
- Type Parameters:
T- The result type returned future- Parameters:
value- the value- Returns:
- the completed CompletionStage
-
failedStage
Returns a new CompletionStage that is already completed exceptionally with the given exception and supports only those methods in interfaceCompletionStage.CAUTION: if run on old Java 8 (which does not support *minimal* CompletionStage), this method just returns a *normal* Cffu instance which is NOT a *minimal* CompletionStage.
- Type Parameters:
T- The result type returned future- Parameters:
ex- the exception- Returns:
- the exceptionally completed CompletionStage
-
fromSyncCall
@CheckReturnValue(explanation="should use the returned Cffu; otherwise, run directly instead of wrapping") public <T> Cffu<T> fromSyncCall(Callable<? extends T> callable) Returns a new Cffu that encapsulates the execution of synchronous logic. By wrapping synchronous code in a Cffu, exceptions can be handled consistently within the Cffu pipeline, eliminating the need to manage separate exceptional paths both inside and outside the flow.- Throws:
NullPointerException- if argumentcallableisnull- See Also:
-
mCffuFromSyncCall
@CheckReturnValue(explanation="should use the returned MCffu; otherwise, run directly instead of wrapping") public <E,T extends Iterable<? extends E>> MCffu<E,T> mCffuFromSyncCall(Callable<? extends T> callable) Returns a new MCffu that encapsulates the execution of synchronous logic. By wrapping synchronous code in a MCffu, exceptions can be handled consistently within the MCffu pipeline, eliminating the need to manage separate exceptional paths both inside and outside the flow.- Throws:
NullPointerException- if argumentcallableisnull- See Also:
-
toCffu
Returns a Cffu that maintains the same completion properties as the given stage, configured with thisCffuFactory. If the given stage is already a Cffu and uses thisCffuFactory, this method may return the given stage.- Throws:
NullPointerException- if the given stage is null- See Also:
-
toMCffu
@Contract(pure=true) public <E,T extends Iterable<? extends E>> MCffu<E,T> toMCffu(CompletionStage<T> stage) Returns a MCffu that maintains the same completion properties as the given stage, configured with thisCffuFactory. If the given stage is already a MCffu and uses thisCffuFactory, this method may return the given stage.This method is similar as
toCffu(CompletionStage)but return type MCffu instead of Cffu.- Throws:
NullPointerException- if the given stage is null- See Also:
-
newIncompleteCffu
Returns a new incomplete Cffu.In general, you won't use this method in application code, prefer other factory methods.
- See Also:
-
newIncompleteMCffu
Returns a new incomplete MCffu.In general, you won't use this method in application code, prefer other factory methods.
- See Also:
-
delayedExecutor
Returns a new Executor that submits a task to the default executor after the given delay (or no delay if non-positive). Each delay commences upon invocation of the returned executor'sexecutemethod.- Parameters:
delay- how long to delay, in units ofunitunit- aTimeUnitdetermining how to interpret thedelayparameter- Returns:
- the new delayed executor
-
delayedExecutor
Returns a new Executor that submits a task to the given base executor after the given delay (or no delay if non-positive). Each delay commences upon invocation of the returned executor'sexecutemethod.- Parameters:
delay- how long to delay, in units ofunitunit- aTimeUnitdetermining how to interpret thedelayparameterexecutor- the base executor- Returns:
- the new delayed executor
-
concurrencyLimitExecutor
Returns a new Executor that submits a task to the default executor and limits the number of concurrent tasks.- Parameters:
maxConcurrency- the maximum number of tasks that can run concurrently- Returns:
- the new concurrency limit executor
- Since:
- 2.1.0
-
concurrencyLimitExecutor
@Contract(pure=true) public Executor concurrencyLimitExecutor(int maxConcurrency, Executor executor) Returns a new Executor that submits a task to the given base executor and limits the number of concurrent tasks.- Parameters:
maxConcurrency- the maximum number of tasks that can run concurrentlyexecutor- the base executor- Returns:
- the new concurrency limit executor
- Since:
- 2.1.0
-
sequentialExecutor
Returns anExecutorthat submits a task to the default executor and runs each task executed sequentially, such that no two tasks are running concurrently.NOTE: Calling this method
cffuFactory.sequentialExecutor()is the same ascffuFactory.concurrencyLimitExecutor(1).- Returns:
- the new sequential executor
- Since:
- 2.1.0
- See Also:
-
sequentialExecutor
Returns anExecutorthat submits a task to the given base executor and runs each task executed sequentially, such that no two tasks are running concurrently.NOTE: Calling this method
cffuFactory.sequentialExecutor(executor)is the same ascffuFactory.concurrencyLimitExecutor(1, executor).- Returns:
- the new sequential executor
- Since:
- 2.1.0
- See Also:
-
defaultExecutor
Returns the default Executor used for async methods that do not specify an Executor. Configured bybuilder(Executor).- Returns:
- the default executor
- See Also:
-
forbidObtrudeMethods
ReturnsforbidObtrudeMethodsor not.- See Also:
-
iterableOps
Returns aCffuFactory.IterableOpsinstance to access theIterable-based variants (includingCollection,List, etc.) of same-named varargs methods fromCffuFactory. These methods handle multiple actions and Futures with the same type, aka. homogeneous.- See Also:
-
parOps
Returns aCffuFactory.ParOpsinstance to access the methods for parallel data processing.- See Also:
-
tupleOps
Returns aCffuFactory.TupleOpsinstance to access the tuple-based variants of methods fromCffuFactoryfor processing and composing multiple asynchronous actions and CompletableFutures in a type-safe manner.- See Also:
-