public final class FutureUtils
extends java.lang.Object
| Modifier and Type | Method and Description |
|---|---|
static <T> java.util.concurrent.CompletableFuture<java.util.List<T>> |
collect(java.util.List<java.util.concurrent.CompletableFuture<T>> futureList) |
static <T> void |
complete(java.util.concurrent.CompletableFuture<T> result,
T value) |
static <T> void |
completeExceptionally(java.util.concurrent.CompletableFuture<T> result,
java.lang.Throwable cause) |
static <T> java.util.concurrent.CompletableFuture<T> |
createFuture() |
static <T> java.util.concurrent.CompletableFuture<T> |
ensure(java.util.concurrent.CompletableFuture<T> future,
java.lang.Runnable ensureBlock) |
static <T> java.util.concurrent.CompletableFuture<T> |
exception(java.lang.Throwable cause) |
static <T> java.util.concurrent.CompletableFuture<java.lang.Void> |
ignore(java.util.concurrent.CompletableFuture<T> future)
Ignore exception from the future.
|
static <T> java.util.concurrent.CompletableFuture<java.lang.Void> |
ignore(java.util.concurrent.CompletableFuture<T> future,
java.lang.String errorMsg)
Ignore exception from the future and log errorMsg on exceptions.
|
static <T,R> java.util.concurrent.CompletableFuture<java.util.List<R>> |
processList(java.util.List<T> collection,
java.util.function.Function<T,java.util.concurrent.CompletableFuture<R>> processFunc,
java.util.concurrent.ExecutorService callbackExecutor)
Process the list of items one by one using the process function processFunc.
|
static <T> void |
proxyTo(java.util.concurrent.CompletableFuture<T> src,
java.util.concurrent.CompletableFuture<T> target) |
static <T> java.util.concurrent.CompletableFuture<T> |
rescue(java.util.concurrent.CompletableFuture<T> future,
java.util.function.Function<java.lang.Throwable,java.util.concurrent.CompletableFuture<T>> rescueFuc) |
static <T> T |
result(java.util.concurrent.CompletableFuture<T> future) |
static <T,ExceptionT extends java.lang.Throwable> |
result(java.util.concurrent.CompletableFuture<T> future,
java.util.function.Function<java.lang.Throwable,ExceptionT> exceptionHandler) |
static <T,ExceptionT extends java.lang.Throwable> |
result(java.util.concurrent.CompletableFuture<T> future,
java.util.function.Function<java.lang.Throwable,ExceptionT> exceptionHandler,
long timeout,
java.util.concurrent.TimeUnit timeUnit) |
static <T> T |
result(java.util.concurrent.CompletableFuture<T> future,
long timeout,
java.util.concurrent.TimeUnit timeUnit) |
static <T> java.util.concurrent.CompletableFuture<T> |
stats(java.util.concurrent.CompletableFuture<T> result,
org.apache.bookkeeper.stats.OpStatsLogger opStatsLogger,
com.google.common.base.Stopwatch stopwatch)
Add a event listener over result for collecting the operation stats.
|
static <T> java.util.concurrent.CompletableFuture<T> |
value(T value) |
static java.util.concurrent.CompletableFuture<java.lang.Void> |
Void() |
static <T> java.util.concurrent.CompletableFuture<T> |
whenCompleteAsync(java.util.concurrent.CompletableFuture<T> future,
java.util.function.BiConsumer<? super T,? super java.lang.Throwable> action,
OrderedScheduler scheduler,
java.lang.Object scheduleKey)
Completing the
future in the thread in the scheduler identified by
the scheduleKey. |
static <T> java.util.concurrent.CompletableFuture<T> |
within(java.util.concurrent.CompletableFuture<T> promise,
long timeout,
java.util.concurrent.TimeUnit unit,
java.lang.Throwable cause,
OrderedScheduler scheduler,
java.lang.Object key)
Raise an exception to the promise within a given timeout period.
|
public static java.util.concurrent.CompletableFuture<java.lang.Void> Void()
public static <T> T result(java.util.concurrent.CompletableFuture<T> future)
throws java.lang.Exception
java.lang.Exceptionpublic static <T> T result(java.util.concurrent.CompletableFuture<T> future,
long timeout,
java.util.concurrent.TimeUnit timeUnit)
throws java.lang.Exception
java.lang.Exceptionpublic static <T,ExceptionT extends java.lang.Throwable> T result(java.util.concurrent.CompletableFuture<T> future,
java.util.function.Function<java.lang.Throwable,ExceptionT> exceptionHandler)
throws ExceptionT extends java.lang.Throwable
ExceptionT extends java.lang.Throwablepublic static <T,ExceptionT extends java.lang.Throwable> T result(java.util.concurrent.CompletableFuture<T> future,
java.util.function.Function<java.lang.Throwable,ExceptionT> exceptionHandler,
long timeout,
java.util.concurrent.TimeUnit timeUnit)
throws ExceptionT extends java.lang.Throwable,
java.util.concurrent.TimeoutException
ExceptionT extends java.lang.Throwablejava.util.concurrent.TimeoutExceptionpublic static <T> java.util.concurrent.CompletableFuture<T> createFuture()
public static <T> java.util.concurrent.CompletableFuture<T> value(T value)
public static <T> java.util.concurrent.CompletableFuture<T> exception(java.lang.Throwable cause)
public static <T> void complete(java.util.concurrent.CompletableFuture<T> result,
T value)
public static <T> void completeExceptionally(java.util.concurrent.CompletableFuture<T> result,
java.lang.Throwable cause)
public static <T> java.util.concurrent.CompletableFuture<T> whenCompleteAsync(java.util.concurrent.CompletableFuture<T> future,
java.util.function.BiConsumer<? super T,? super java.lang.Throwable> action,
OrderedScheduler scheduler,
java.lang.Object scheduleKey)
future in the thread in the scheduler identified by
the scheduleKey.T - future - future to completeaction - action to execute when completescheduler - scheduler to execute the action.scheduleKey - key to choose the thread to execute the actionpublic static <T> java.util.concurrent.CompletableFuture<java.util.List<T>> collect(java.util.List<java.util.concurrent.CompletableFuture<T>> futureList)
public static <T> void proxyTo(java.util.concurrent.CompletableFuture<T> src,
java.util.concurrent.CompletableFuture<T> target)
public static <T,R> java.util.concurrent.CompletableFuture<java.util.List<R>> processList(java.util.List<T> collection,
java.util.function.Function<T,java.util.concurrent.CompletableFuture<R>> processFunc,
@Nullable
java.util.concurrent.ExecutorService callbackExecutor)
collection - list of itemsprocessFunc - process functioncallbackExecutor - executor to process the itempublic static <T> java.util.concurrent.CompletableFuture<T> within(java.util.concurrent.CompletableFuture<T> promise,
long timeout,
java.util.concurrent.TimeUnit unit,
java.lang.Throwable cause,
OrderedScheduler scheduler,
java.lang.Object key)
promise - promise to raise exceptiontimeout - timeout periodunit - timeout period unitcause - cause to raisescheduler - scheduler to execute raising exceptionkey - the submit key used by the schedulerpublic static <T> java.util.concurrent.CompletableFuture<java.lang.Void> ignore(java.util.concurrent.CompletableFuture<T> future)
future - the original futurepublic static <T> java.util.concurrent.CompletableFuture<java.lang.Void> ignore(java.util.concurrent.CompletableFuture<T> future,
java.lang.String errorMsg)
future - the original futureerrorMsg - the error message to log on exceptionspublic static <T> java.util.concurrent.CompletableFuture<T> ensure(java.util.concurrent.CompletableFuture<T> future,
java.lang.Runnable ensureBlock)
public static <T> java.util.concurrent.CompletableFuture<T> rescue(java.util.concurrent.CompletableFuture<T> future,
java.util.function.Function<java.lang.Throwable,java.util.concurrent.CompletableFuture<T>> rescueFuc)
public static <T> java.util.concurrent.CompletableFuture<T> stats(java.util.concurrent.CompletableFuture<T> result,
org.apache.bookkeeper.stats.OpStatsLogger opStatsLogger,
com.google.common.base.Stopwatch stopwatch)
T - result - result to listen onopStatsLogger - stats logger to record operations statsstopwatch - stop watch to time operationCopyright © 2011–2023 The Apache Software Foundation. All rights reserved.