Class CompletableFutures
- java.lang.Object
-
- org.infinispan.commons.util.concurrent.CompletableFutures
-
public final class CompletableFutures extends Object
Utility methods connectingCompletableFuturefutures.- Since:
- 8.0
- Author:
- Dan Berindei
-
-
Field Summary
Fields Modifier and Type Field Description static CompletableFuture[]EMPTY_ARRAY
-
Method Summary
-
-
-
Field Detail
-
EMPTY_ARRAY
public static final CompletableFuture[] EMPTY_ARRAY
-
-
Method Detail
-
completedEmptyMap
public static <K,V> CompletableFuture<Map<K,V>> completedEmptyMap()
-
completedNull
public static <T> CompletableFuture<T> completedNull()
-
completedTrue
public static CompletableFuture<Boolean> completedTrue()
-
completedFalse
public static CompletableFuture<Boolean> completedFalse()
-
booleanStage
public static CompletionStage<Boolean> booleanStage(boolean trueOrFalse)
-
sequence
public static <T> CompletableFuture<List<T>> sequence(List<CompletableFuture<T>> futures)
-
completedExceptionFuture
public static <T> CompletableFuture<T> completedExceptionFuture(Throwable ex)
-
await
public static boolean await(CompletableFuture<?> future, long time, TimeUnit unit) throws InterruptedException
It waits until theCompletableFutureis completed.It ignore if the
CompletableFutureis completed normally or exceptionally.- Parameters:
future- theCompletableFutureto test.time- the timeout.unit- the timeout unit.- Returns:
trueif completed,falseif timed out.- Throws:
InterruptedException- if interrupted while waiting.NullPointerException- iffutureorunitisnull.
-
uncheckedAwait
public static boolean uncheckedAwait(CompletableFuture<?> future, long time, TimeUnit unit)
Same asawait(CompletableFuture, long, TimeUnit)but wraps checked exceptions inCacheException- Parameters:
future- theCompletableFutureto test.time- the timeout.unit- the timeout unit.- Returns:
trueif completed,falseif timed out.- Throws:
NullPointerException- iffutureorunitisnull.
-
await
public static <T> T await(CompletableFuture<T> future) throws ExecutionException, InterruptedException
Wait for a long time until theCompletableFutureis completed.- Type Parameters:
T- the return type.- Parameters:
future- theCompletableFuture.- Returns:
- the result value.
- Throws:
ExecutionException- if theCompletableFuturecompleted exceptionally.InterruptedException- if the current thread was interrupted while waiting.
-
uncheckedAwait
public static <T> T uncheckedAwait(CompletableFuture<T> future)
Same asawait(CompletableFuture)but wraps checked exceptions inCacheException- Type Parameters:
T- the return type.- Parameters:
future- theCompletableFuture.- Returns:
- the result value.
-
asCompletionException
public static CompletionException asCompletionException(Throwable t)
-
rethrowExceptionIfPresent
public static void rethrowExceptionIfPresent(Throwable t)
-
toNullFunction
public static <T,R> Function<T,R> toNullFunction()
-
identity
public static <T> Function<T,T> identity()
-
-