Package org.infinispan.util.concurrent
Class CompletableFutures
- java.lang.Object
-
- org.infinispan.util.concurrent.CompletableFutures
-
public class CompletableFutures extends java.lang.Object
Utility methods connectingCompletableFuture
futures.- Since:
- 8.0
- Author:
- Dan Berindei
-
-
Field Summary
Fields Modifier and Type Field Description static java.util.concurrent.CompletableFuture[]
EMPTY_ARRAY
-
Constructor Summary
Constructors Constructor Description CompletableFutures()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static java.util.concurrent.CompletionException
asCompletionException(java.lang.Throwable t)
static boolean
await(java.util.concurrent.CompletableFuture<?> future, long time, java.util.concurrent.TimeUnit unit)
It waits until theCompletableFuture
is completed.static <T> T
await(java.util.concurrent.CompletableFuture<T> future)
Wait for a long time until theCompletableFuture
is completed.static java.util.concurrent.CompletionStage<java.lang.Boolean>
booleanStage(boolean trueOrFalse)
static <K,V>
java.util.concurrent.CompletableFuture<java.util.Map<K,V>>completedEmptyMap()
static <T> java.util.concurrent.CompletableFuture<T>
completedExceptionFuture(java.lang.Throwable ex)
static java.util.concurrent.CompletableFuture<java.lang.Boolean>
completedFalse()
static <T> java.util.concurrent.CompletableFuture<T>
completedNull()
static java.util.concurrent.CompletableFuture<java.lang.Boolean>
completedTrue()
static <T> java.util.function.Function<T,java.util.concurrent.CompletionStage<java.lang.Boolean>>
composeFalse()
static <T,R>
java.util.function.Function<T,java.util.concurrent.CompletionStage<R>>composeNull()
static <T> java.util.function.Function<T,java.util.concurrent.CompletionStage<java.lang.Boolean>>
composeTrue()
static java.lang.Throwable
extractException(java.lang.Throwable t)
static void
rethrowException(java.lang.Throwable t)
static <T> java.util.concurrent.CompletableFuture<java.util.List<T>>
sequence(java.util.List<java.util.concurrent.CompletableFuture<T>> futures)
static <T,R>
java.util.function.Function<T,R>toNullFunction()
static boolean
uncheckedAwait(java.util.concurrent.CompletableFuture<?> future, long time, java.util.concurrent.TimeUnit unit)
Same asawait(CompletableFuture, long, TimeUnit)
but wraps checked exceptions inCacheException
static <T> T
uncheckedAwait(java.util.concurrent.CompletableFuture<T> future)
Same asawait(CompletableFuture)
but wraps checked exceptions inCacheException
-
-
-
Method Detail
-
completedEmptyMap
public static <K,V> java.util.concurrent.CompletableFuture<java.util.Map<K,V>> completedEmptyMap()
-
completedNull
public static <T> java.util.concurrent.CompletableFuture<T> completedNull()
-
completedTrue
public static java.util.concurrent.CompletableFuture<java.lang.Boolean> completedTrue()
-
completedFalse
public static java.util.concurrent.CompletableFuture<java.lang.Boolean> completedFalse()
-
composeTrue
public static <T> java.util.function.Function<T,java.util.concurrent.CompletionStage<java.lang.Boolean>> composeTrue()
-
composeFalse
public static <T> java.util.function.Function<T,java.util.concurrent.CompletionStage<java.lang.Boolean>> composeFalse()
-
composeNull
public static <T,R> java.util.function.Function<T,java.util.concurrent.CompletionStage<R>> composeNull()
-
booleanStage
public static java.util.concurrent.CompletionStage<java.lang.Boolean> booleanStage(boolean trueOrFalse)
-
sequence
public static <T> java.util.concurrent.CompletableFuture<java.util.List<T>> sequence(java.util.List<java.util.concurrent.CompletableFuture<T>> futures)
-
completedExceptionFuture
public static <T> java.util.concurrent.CompletableFuture<T> completedExceptionFuture(java.lang.Throwable ex)
-
await
public static boolean await(java.util.concurrent.CompletableFuture<?> future, long time, java.util.concurrent.TimeUnit unit) throws java.lang.InterruptedException
It waits until theCompletableFuture
is completed.It ignore if the
CompletableFuture
is completed normally or exceptionally.- Parameters:
future
- theCompletableFuture
to test.time
- the timeout.unit
- the timeout unit.- Returns:
true
if completed,false
if timed out.- Throws:
java.lang.InterruptedException
- if interrupted while waiting.java.lang.NullPointerException
- iffuture
orunit
isnull
.
-
uncheckedAwait
public static boolean uncheckedAwait(java.util.concurrent.CompletableFuture<?> future, long time, java.util.concurrent.TimeUnit unit)
Same asawait(CompletableFuture, long, TimeUnit)
but wraps checked exceptions inCacheException
- Parameters:
future
- theCompletableFuture
to test.time
- the timeout.unit
- the timeout unit.- Returns:
true
if completed,false
if timed out.- Throws:
java.lang.NullPointerException
- iffuture
orunit
isnull
.
-
await
public static <T> T await(java.util.concurrent.CompletableFuture<T> future) throws java.util.concurrent.ExecutionException, java.lang.InterruptedException
Wait for a long time until theCompletableFuture
is completed.- Type Parameters:
T
- the return type.- Parameters:
future
- theCompletableFuture
.- Returns:
- the result value.
- Throws:
java.util.concurrent.ExecutionException
- if theCompletableFuture
completed exceptionally.java.lang.InterruptedException
- if the current thread was interrupted while waiting.
-
uncheckedAwait
public static <T> T uncheckedAwait(java.util.concurrent.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 java.util.concurrent.CompletionException asCompletionException(java.lang.Throwable t)
-
rethrowException
public static void rethrowException(java.lang.Throwable t)
-
extractException
public static java.lang.Throwable extractException(java.lang.Throwable t)
-
toNullFunction
public static <T,R> java.util.function.Function<T,R> toNullFunction()
-
-