Package rocks.xmpp.util.concurrent
Class CompletionStages
- java.lang.Object
-
- rocks.xmpp.util.concurrent.CompletionStages
-
public final class CompletionStages extends Object
Utility class for creating different kinds ofCompletionStage
.
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static <T> CompletionStage<List<T>>
allOf(Collection<? extends CompletionStage<List<T>>> stages)
Returns a completion stage, which is complete when all the completion stages are complete.static <T> CompletionStage<T>
timeoutAfter(long delay, TimeUnit unit)
Creates a completion stage, which times out after the specified time, i.e. it completes exceptionally with aTimeoutException
.static <T> CompletionStage<T>
timeoutAfter(long delay, TimeUnit unit, Supplier<Throwable> throwableSupplier)
Creates a completion stage, which times out after the specified time, i.e. it completes exceptionally with the supplied exception.static <T> CompletionStage<T>
withFallback(CompletionStage<T> stage, BiFunction<CompletionStage<T>,Throwable,? extends CompletionStage<T>> fallback)
Creates a new completion stage which uses a fallback stage in case the primary stage completes exceptionally.
-
-
-
Method Detail
-
withFallback
public static <T> CompletionStage<T> withFallback(CompletionStage<T> stage, BiFunction<CompletionStage<T>,Throwable,? extends CompletionStage<T>> fallback)
Creates a new completion stage which uses a fallback stage in case the primary stage completes exceptionally.- Type Parameters:
T
- The type.- Parameters:
stage
- The primary stage.fallback
- A function, which returns a fallback stage, in case the primary one fails exceptionally.- Returns:
- The completion stage with a fallback.
-
allOf
public static <T> CompletionStage<List<T>> allOf(Collection<? extends CompletionStage<List<T>>> stages)
Returns a completion stage, which is complete when all the completion stages are complete. The lists of each stage are flat mapped into one list, so that the returned stage has one accumulated list.- Type Parameters:
T
- The type.- Parameters:
stages
- The stages.- Returns:
- The future.
-
timeoutAfter
public static <T> CompletionStage<T> timeoutAfter(long delay, TimeUnit unit)
Creates a completion stage, which times out after the specified time, i.e. it completes exceptionally with aTimeoutException
.- Type Parameters:
T
- The type.- Parameters:
delay
- The delay.unit
- The time unit.- Returns:
- The stage.
-
timeoutAfter
public static <T> CompletionStage<T> timeoutAfter(long delay, TimeUnit unit, Supplier<Throwable> throwableSupplier)
Creates a completion stage, which times out after the specified time, i.e. it completes exceptionally with the supplied exception.- Type Parameters:
T
- The type.- Parameters:
delay
- The delay.unit
- The time unit.throwableSupplier
- The supplier for an exception which occurs on timeout.- Returns:
- The stage.
-
-