Class ListenableFutureUtils
ListenableFuture.- Author:
- Jerry Lee (oldratlee at gmail dot com), HuHao (995483610 at qq dot com), Eric Lin (linqinghua4 at gmail dot com)
-
Method Summary
Modifier and TypeMethodDescriptionstatic <T> Cffu<T> toCffu(ListenableFuture<T> lf, CffuFactory cffuFactory, boolean interruptLfWhenCancellationException) Converts inputListenableFuturetoCffu.static <T> CompletableFuture<T> toCompletableFuture(ListenableFuture<T> lf, Executor executor, boolean interruptLfWhenCancellationException) Converts inputListenableFuturetoCompletableFuture.static <T> ListenableFuture<T> toListenableFuture(Cffu<T> cf) Converts inputCffutoListenableFuture.static <T> ListenableFuture<T> Converts inputCompletableFuturetoListenableFuture.
-
Method Details
-
toCompletableFuture
@Contract(pure=true) public static <T> CompletableFuture<T> toCompletableFuture(ListenableFuture<T> lf, Executor executor, boolean interruptLfWhenCancellationException) Converts inputListenableFuturetoCompletableFuture.Callback from ListenableFuture is executed using the given executor, use
MoreExecutors.directExecutor()if you need skip the execution switch.Cancelling(
Future.cancel(boolean)) the returned CompletableFuture will also cancel underlying ListenableFuture.Use param
interruptLfWhenCancellationExceptionto control whether to cancel ListenableFuture with interruption when CancellationException occurred (including CompletionException/ExecutionException with CancellationException cause, more info seeCompletableFutureUtils.unwrapCfException(Throwable)).It's recommended to avoid using direct write methods(e.g.
CompletableFuture.complete(Object),CompletableFuture.completeExceptionally(Throwable)) of the returned CompletableFuture:- the underlying ListenableFuture can benefit from cancellation propagation.
- the writing of the returned CompletableFuture won't affect the underlying ListenableFuture.
- Parameters:
lf- the underlying ListenableFutureexecutor- the executor to use for ListenableFuture callback executioninterruptLfWhenCancellationException- whether to cancel ListenableFuture with interruption when CancellationException occurred- Returns:
- the CompletableFuture adapter
- See Also:
-
toCffu
@Contract(pure=true) public static <T> Cffu<T> toCffu(ListenableFuture<T> lf, CffuFactory cffuFactory, boolean interruptLfWhenCancellationException) Converts inputListenableFuturetoCffu.Callback from ListenableFuture is executed using cffuFactory's default executor.
More info see
toCompletableFuture(ListenableFuture, Executor, boolean). -
toListenableFuture
@Contract(pure=true) public static <T> ListenableFuture<T> toListenableFuture(CompletableFuture<T> cf) Converts inputCompletableFuturetoListenableFuture. -
toListenableFuture
Converts inputCffutoListenableFuture.
-