public class FutureUtils extends Object
CompletableFuture.| Modifier and Type | Class and Description |
|---|---|
static class |
FutureUtils.ConjunctFuture<T>
A future that is complete once multiple other futures completed.
|
static class |
FutureUtils.RetryException
Exception with which the returned future is completed if the
retry(Supplier, int, Executor)
operation fails. |
| Constructor and Description |
|---|
FutureUtils() |
| Modifier and Type | Method and Description |
|---|---|
static <T> FutureUtils.ConjunctFuture<Collection<T>> |
combineAll(Collection<? extends CompletableFuture<? extends T>> futures)
Creates a future that is complete once multiple other futures completed.
|
static FutureUtils.ConjunctFuture<Void> |
completeAll(Collection<? extends CompletableFuture<?>> futuresToComplete)
Creates a
FutureUtils.ConjunctFuture which is only completed after all given futures have completed. |
static <T> CompletableFuture<T> |
completedExceptionally(Throwable cause)
Returns an exceptionally completed
CompletableFuture. |
static CompletableFuture<Void> |
composeAfterwards(CompletableFuture<?> future,
java.util.function.Supplier<CompletableFuture<?>> composedAction)
Run the given asynchronous action after the completion of the given future.
|
static <T> CompletableFuture<T> |
orTimeout(CompletableFuture<T> future,
long timeout,
TimeUnit timeUnit)
Times the given future out after the timeout.
|
static <T> CompletableFuture<T> |
retry(java.util.function.Supplier<CompletableFuture<T>> operation,
int retries,
Executor executor)
Retry the given operation the given number of times in case of a failure.
|
static <T> CompletableFuture<T> |
retrySuccessfulWithDelay(java.util.function.Supplier<CompletableFuture<T>> operation,
org.apache.flink.api.common.time.Time retryDelay,
org.apache.flink.api.common.time.Deadline deadline,
java.util.function.Predicate<T> acceptancePredicate,
ScheduledExecutor scheduledExecutor)
Retry the given operation with the given delay in between successful completions where the
result does not match a given predicate.
|
static <T> CompletableFuture<T> |
retryWithDelay(java.util.function.Supplier<CompletableFuture<T>> operation,
int retries,
org.apache.flink.api.common.time.Time retryDelay,
java.util.function.Predicate<Throwable> retryPredicate,
ScheduledExecutor scheduledExecutor)
Retry the given operation with the given delay in between failures.
|
static <T> CompletableFuture<T> |
retryWithDelay(java.util.function.Supplier<CompletableFuture<T>> operation,
int retries,
org.apache.flink.api.common.time.Time retryDelay,
ScheduledExecutor scheduledExecutor)
Retry the given operation with the given delay in between failures.
|
static CompletableFuture<Void> |
runAfterwards(CompletableFuture<?> future,
org.apache.flink.util.function.RunnableWithException runnable)
Run the given action after the completion of the given future.
|
static CompletableFuture<Void> |
runAfterwardsAsync(CompletableFuture<?> future,
org.apache.flink.util.function.RunnableWithException runnable)
Run the given action after the completion of the given future.
|
static CompletableFuture<Void> |
runAfterwardsAsync(CompletableFuture<?> future,
org.apache.flink.util.function.RunnableWithException runnable,
Executor executor)
Run the given action after the completion of the given future.
|
static <T> CompletableFuture<T> |
supplyAsync(org.apache.flink.util.function.SupplierWithException<T,?> supplier,
Executor executor)
Returns a future which is completed with the result of the
SupplierWithException. |
static scala.concurrent.duration.FiniteDuration |
toFiniteDuration(org.apache.flink.api.common.time.Time time)
Converts Flink time into a
FiniteDuration. |
static <T,U extends T> |
toJava(scala.concurrent.Future<U> scalaFuture)
Converts a Scala
Future to a CompletableFuture. |
static org.apache.flink.api.common.time.Time |
toTime(scala.concurrent.duration.FiniteDuration finiteDuration)
Converts
FiniteDuration into Flink time. |
static FutureUtils.ConjunctFuture<Void> |
waitForAll(Collection<? extends CompletableFuture<?>> futures)
Creates a future that is complete once all of the given futures have completed.
|
public static <T> CompletableFuture<T> retry(java.util.function.Supplier<CompletableFuture<T>> operation, int retries, Executor executor)
T - type of the resultoperation - to executedretries - if the operation failedexecutor - to use to run the futuresFutureUtils.RetryExceptionpublic static <T> CompletableFuture<T> retryWithDelay(java.util.function.Supplier<CompletableFuture<T>> operation, int retries, org.apache.flink.api.common.time.Time retryDelay, java.util.function.Predicate<Throwable> retryPredicate, ScheduledExecutor scheduledExecutor)
T - type of the resultoperation - to retryretries - number of retriesretryDelay - delay between retriesretryPredicate - Predicate to test whether an exception is retryablescheduledExecutor - executor to be used for the retry operationpublic static <T> CompletableFuture<T> retryWithDelay(java.util.function.Supplier<CompletableFuture<T>> operation, int retries, org.apache.flink.api.common.time.Time retryDelay, ScheduledExecutor scheduledExecutor)
T - type of the resultoperation - to retryretries - number of retriesretryDelay - delay between retriesscheduledExecutor - executor to be used for the retry operationpublic static <T> CompletableFuture<T> retrySuccessfulWithDelay(java.util.function.Supplier<CompletableFuture<T>> operation, org.apache.flink.api.common.time.Time retryDelay, org.apache.flink.api.common.time.Deadline deadline, java.util.function.Predicate<T> acceptancePredicate, ScheduledExecutor scheduledExecutor)
T - type of the resultoperation - to retryretryDelay - delay between retriesdeadline - A deadline that specifies at what point we should stop retryingacceptancePredicate - Predicate to test whether the result is acceptablescheduledExecutor - executor to be used for the retry operationpublic static <T> CompletableFuture<T> orTimeout(CompletableFuture<T> future, long timeout, TimeUnit timeUnit)
T - type of the given futurefuture - to time outtimeout - after which the given future is timed outtimeUnit - time unit of the timeoutpublic static CompletableFuture<Void> runAfterwards(CompletableFuture<?> future, org.apache.flink.util.function.RunnableWithException runnable)
future - to wait for its completionrunnable - action which is triggered after the future's completionpublic static CompletableFuture<Void> runAfterwardsAsync(CompletableFuture<?> future, org.apache.flink.util.function.RunnableWithException runnable)
future - to wait for its completionrunnable - action which is triggered after the future's completionpublic static CompletableFuture<Void> runAfterwardsAsync(CompletableFuture<?> future, org.apache.flink.util.function.RunnableWithException runnable, Executor executor)
future - to wait for its completionrunnable - action which is triggered after the future's completionexecutor - to run the given actionpublic static CompletableFuture<Void> composeAfterwards(CompletableFuture<?> future, java.util.function.Supplier<CompletableFuture<?>> composedAction)
future - to wait for its completioncomposedAction - asynchronous action which is triggered after the future's completionpublic static <T> FutureUtils.ConjunctFuture<Collection<T>> combineAll(Collection<? extends CompletableFuture<? extends T>> futures)
The ConjunctFuture gives access to how many Futures in the conjunction have already
completed successfully, via FutureUtils.ConjunctFuture.getNumFuturesCompleted().
futures - The futures that make up the conjunction. No null entries are allowed.public static FutureUtils.ConjunctFuture<Void> waitForAll(Collection<? extends CompletableFuture<?>> futures)
The ConjunctFuture gives access to how many Futures have already
completed successfully, via FutureUtils.ConjunctFuture.getNumFuturesCompleted().
futures - The futures to wait on. No null entries are allowed.public static FutureUtils.ConjunctFuture<Void> completeAll(Collection<? extends CompletableFuture<?>> futuresToComplete)
FutureUtils.ConjunctFuture which is only completed after all given futures have completed.
Unlike waitForAll(Collection), the resulting future won't be completed directly
if one of the given futures is completed exceptionally. Instead, all occurring exception will be
collected and combined to a single exception. If at least on exception occurs, then the resulting
future will be completed exceptionally.futuresToComplete - futures to completepublic static <T> CompletableFuture<T> completedExceptionally(Throwable cause)
CompletableFuture.T - type of the futurecause - to complete the future withpublic static <T> CompletableFuture<T> supplyAsync(org.apache.flink.util.function.SupplierWithException<T,?> supplier, Executor executor)
SupplierWithException.T - type of the resultsupplier - to provide the future's valueexecutor - to execute the supplierpublic static scala.concurrent.duration.FiniteDuration toFiniteDuration(org.apache.flink.api.common.time.Time time)
FiniteDuration.time - to convert into a FiniteDurationpublic static org.apache.flink.api.common.time.Time toTime(scala.concurrent.duration.FiniteDuration finiteDuration)
FiniteDuration into Flink time.finiteDuration - to convert into Flink timepublic static <T,U extends T> CompletableFuture<T> toJava(scala.concurrent.Future<U> scalaFuture)
Future to a CompletableFuture.T - type of the future valueU - type of the original futurescalaFuture - to convert to a Java 8 CompletableFutureCopyright © 2014–2019 The Apache Software Foundation. All rights reserved.