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 <T> CompletableFuture<T> |
completedExceptionally(Throwable cause)
Returns an exceptionally completed
CompletableFuture . |
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> |
retrySuccesfulWithDelay(java.util.function.Supplier<CompletableFuture<T>> operation,
Time retryDelay,
scala.concurrent.duration.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,
Time retryDelay,
ScheduledExecutor scheduledExecutor)
Retry the given operation with the given delay in between failures.
|
static scala.concurrent.duration.FiniteDuration |
toFiniteDuration(Time time)
Converts Flink time into a
FiniteDuration . |
static <T> CompletableFuture<T> |
toJava(scala.concurrent.Future<T> scalaFuture)
Converts a Scala
Future to a CompletableFuture . |
static 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.RetryException
public static <T> CompletableFuture<T> retryWithDelay(java.util.function.Supplier<CompletableFuture<T>> operation, int retries, 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> retrySuccesfulWithDelay(java.util.function.Supplier<CompletableFuture<T>> operation, Time retryDelay, scala.concurrent.duration.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> 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 <T> CompletableFuture<T> completedExceptionally(Throwable cause)
CompletableFuture
.T
- type of the futurecause
- to complete the future withpublic static scala.concurrent.duration.FiniteDuration toFiniteDuration(Time time)
FiniteDuration
.time
- to convert into a FiniteDurationpublic static Time toTime(scala.concurrent.duration.FiniteDuration finiteDuration)
FiniteDuration
into Flink time.finiteDuration
- to convert into Flink timepublic static <T> CompletableFuture<T> toJava(scala.concurrent.Future<T> scalaFuture)
Future
to a CompletableFuture
.T
- type of the future valuescalaFuture
- to convert to a Java 8 CompletableFuturepublic 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 timeoutCopyright © 2014–2018 The Apache Software Foundation. All rights reserved.