Class CompletionStages
java.lang.Object
org.infinispan.commons.util.concurrent.CompletionStages
Utility methods for handling
CompletionStage
instances.- Since:
- 10.0
- Author:
- wburns
-
Field Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic AggregateCompletionStage
<Void> Returns a CompletionStage that also can be composed of many other CompletionStages.static <R> AggregateCompletionStage
<R> aggregateCompletionStage
(R valueToReturn) Same asaggregateCompletionStage()
except that when this stage completes normally it will return the value provided.static CompletionStage
<Void> allOf
(CompletionStage<?>... stages) Returns a CompletionStage that completes when all of the provided stages complete, either normally or via exception.static CompletionStage
<Void> allOf
(CompletionStage<Void> first, CompletionStage<Void> second) Returns a CompletableStage that completes when both of the provides CompletionStages complete.static <T> T
await
(CompletionStage<T> stage) static <T,
U> CompletionStage <U> handleAndCompose
(CompletionStage<T> stage, BiFunction<T, Throwable, CompletionStage<U>> handleFunction) ExtendCompletionStage.thenCompose(Function)
to also handle exceptions.static <T,
U> CompletionStage <U> handleAndComposeAsync
(CompletionStage<T> stage, BiFunction<T, Throwable, CompletionStage<U>> handleFunction, Executor executor) static CompletionStage
<Void> ignoreValue
(CompletionStage<?> stage) static boolean
isCompletedSuccessfully
(CompletionStage<?> stage) Returns if the providedCompletionStage
has already completed normally, that is not due to an exception.static <R> R
join
(CompletionStage<R> stage) Returns the result value when complete, or throws an (unchecked) exception if completed exceptionally.static AggregateCompletionStage
<Boolean> static <I> CompletionStage
<Void> performConcurrently
(Iterable<I> iterable, int parallelism, io.reactivex.rxjava3.core.Scheduler scheduler, Function<? super I, CompletionStage<?>> function) static <I> CompletionStage
<Void> performSequentially
(Iterator<I> iterator, Function<? super I, CompletionStage<Void>> function) static <I,
T, A, R>
CompletionStage<R> performSequentially
(Iterator<I> iterator, Function<? super I, CompletionStage<T>> function, Collector<T, A, R> collector) static CompletionStage
<Void> schedule
(Runnable command, ScheduledExecutorService executor, long delay, TimeUnit timeUnit) static <T> CompletionStage
<T> schedule
(Callable<T> command, ScheduledExecutorService executor, long delay, TimeUnit timeUnit) static <T> CompletionStage
<T> scheduleNonBlocking
(Callable<? extends CompletionStage<T>> command, ScheduledExecutorService executor, long delay, TimeUnit timeUnit)
-
Field Details
-
NO_OP_RUNNABLE
-
-
Method Details
-
aggregateCompletionStage
Returns a CompletionStage that also can be composed of many other CompletionStages. A stage can compose another stage in it by invoking theAggregateCompletionStage.dependsOn(CompletionStage)
method passing in the CompletionStage. After all stages this composition stage depend upon have been added, theAggregateCompletionStage.freeze()
should be invoked so that the AggregateCompletionStage can finally complete when all of the stages it depends upon complete.If any stage this depends upon fails the returned stage will contain the Throwable from one of the stages.
- Returns:
- composed completion stage
-
aggregateCompletionStage
Same asaggregateCompletionStage()
except that when this stage completes normally it will return the value provided.- Type Parameters:
R
- the type of the value- Parameters:
valueToReturn
- value to return to future stage compositions- Returns:
- composed completion stage that returns the value upon normal completion
-
orBooleanAggregateCompletionStage
-
isCompletedSuccessfully
Returns if the providedCompletionStage
has already completed normally, that is not due to an exception.- Parameters:
stage
- stage to check- Returns:
- if the stage is completed normally
-
join
Returns the result value when complete, or throws an (unchecked) exception if completed exceptionally. To better conform with the use of common functional forms, if a computation involved in the completion of this CompletionStage threw an exception, this method throws an (unchecked) CompletionException with the underlying exception as its cause.- Type Parameters:
R
- the type in the stage- Parameters:
stage
- stage to wait on- Returns:
- the result value
- Throws:
CompletionException
- if this stage completed exceptionally or a completion computation threw an exception
-
allOf
public static CompletionStage<Void> allOf(CompletionStage<Void> first, CompletionStage<Void> second) Returns a CompletableStage that completes when both of the provides CompletionStages complete. This method may choose to return either of the argument if the other is complete or a new instance completely.- Parameters:
first
- the first CompletionStagesecond
- the second CompletionStage- Returns:
- a CompletionStage that is complete when both of the given CompletionStages complete
-
allOf
Returns a CompletionStage that completes when all of the provided stages complete, either normally or via exception. If one or more states complete exceptionally the returned CompletionStage will complete with the exception of one of these. If no CompletionStages are provided, returns a CompletionStage completed with the value null.- Parameters:
stages
- the CompletionStages- Returns:
- a CompletionStage that is completed when all of the given CompletionStages complete
-
handleAndCompose
public static <T,U> CompletionStage<U> handleAndCompose(CompletionStage<T> stage, BiFunction<T, Throwable, CompletionStage<U>> handleFunction) ExtendCompletionStage.thenCompose(Function)
to also handle exceptions. -
handleAndComposeAsync
public static <T,U> CompletionStage<U> handleAndComposeAsync(CompletionStage<T> stage, BiFunction<T, Throwable, CompletionStage<U>> handleFunction, Executor executor) -
schedule
public static CompletionStage<Void> schedule(Runnable command, ScheduledExecutorService executor, long delay, TimeUnit timeUnit) -
schedule
public static <T> CompletionStage<T> schedule(Callable<T> command, ScheduledExecutorService executor, long delay, TimeUnit timeUnit) -
scheduleNonBlocking
public static <T> CompletionStage<T> scheduleNonBlocking(Callable<? extends CompletionStage<T>> command, ScheduledExecutorService executor, long delay, TimeUnit timeUnit) -
ignoreValue
-
await
-
performConcurrently
public static <I> CompletionStage<Void> performConcurrently(Iterable<I> iterable, int parallelism, io.reactivex.rxjava3.core.Scheduler scheduler, Function<? super I, CompletionStage<?>> function) -
performSequentially
public static <I> CompletionStage<Void> performSequentially(Iterator<I> iterator, Function<? super I, CompletionStage<Void>> function) -
performSequentially
public static <I,T, CompletionStage<R> performSequentiallyA, R> (Iterator<I> iterator, Function<? super I, CompletionStage<T>> function, Collector<T, A, R> collector)
-