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 inputListenableFuture
toCffu
.static <T> CompletableFuture
<T> toCompletableFuture
(ListenableFuture<T> lf, Executor executor, boolean interruptLfWhenCancellationException) Converts inputListenableFuture
toCompletableFuture
.static <T> ListenableFuture
<T> toListenableFuture
(Cffu<T> cf) Converts inputCffu
toListenableFuture
.static <T> ListenableFuture
<T> Converts inputCompletableFuture
toListenableFuture
.
-
Method Details
-
toCompletableFuture
@Contract(pure=true) public static <T> CompletableFuture<T> toCompletableFuture(ListenableFuture<T> lf, Executor executor, boolean interruptLfWhenCancellationException) Converts inputListenableFuture
toCompletableFuture
.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
interruptLfWhenCancellationException
to 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 inputListenableFuture
toCffu
.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 inputCompletableFuture
toListenableFuture
. -
toListenableFuture
Converts inputCffu
toListenableFuture
.
-