public class ContextAwareCompletableFuture<T>
extends java.util.concurrent.CompletableFuture<T>
CompletableFuture that was introduced in java version 8.
The class is a 'normal' Completable Future, but every successive call made on the result will be made within the
context during creation of this ContextAwareCompletableFuture.
| Constructor and Description |
|---|
ContextAwareCompletableFuture()
Creates a new
ContextSnapshot and remembers that in this completable future, running all
completion methods within this snapshot. |
ContextAwareCompletableFuture(ContextSnapshot snapshot)
Creates a new
CompletableFuture where all completion methods are run within the specified
snapshot context. |
| Modifier and Type | Method and Description |
|---|---|
java.util.concurrent.CompletableFuture<java.lang.Void> |
acceptEither(java.util.concurrent.CompletionStage<? extends T> other,
java.util.function.Consumer<? super T> action) |
java.util.concurrent.CompletableFuture<java.lang.Void> |
acceptEitherAsync(java.util.concurrent.CompletionStage<? extends T> other,
java.util.function.Consumer<? super T> action) |
java.util.concurrent.CompletableFuture<java.lang.Void> |
acceptEitherAsync(java.util.concurrent.CompletionStage<? extends T> other,
java.util.function.Consumer<? super T> action,
java.util.concurrent.Executor executor) |
<U> java.util.concurrent.CompletableFuture<U> |
applyToEither(java.util.concurrent.CompletionStage<? extends T> other,
java.util.function.Function<? super T,U> fn) |
<U> java.util.concurrent.CompletableFuture<U> |
applyToEitherAsync(java.util.concurrent.CompletionStage<? extends T> other,
java.util.function.Function<? super T,U> fn) |
<U> java.util.concurrent.CompletableFuture<U> |
applyToEitherAsync(java.util.concurrent.CompletionStage<? extends T> other,
java.util.function.Function<? super T,U> fn,
java.util.concurrent.Executor executor) |
java.util.concurrent.CompletableFuture<T> |
exceptionally(java.util.function.Function<java.lang.Throwable,? extends T> fn) |
<U> java.util.concurrent.CompletableFuture<U> |
handle(java.util.function.BiFunction<? super T,java.lang.Throwable,? extends U> fn) |
<U> java.util.concurrent.CompletableFuture<U> |
handleAsync(java.util.function.BiFunction<? super T,java.lang.Throwable,? extends U> fn) |
<U> java.util.concurrent.CompletableFuture<U> |
handleAsync(java.util.function.BiFunction<? super T,java.lang.Throwable,? extends U> fn,
java.util.concurrent.Executor executor) |
java.util.concurrent.CompletableFuture<java.lang.Void> |
runAfterBoth(java.util.concurrent.CompletionStage<?> other,
java.lang.Runnable action) |
java.util.concurrent.CompletableFuture<java.lang.Void> |
runAfterBothAsync(java.util.concurrent.CompletionStage<?> other,
java.lang.Runnable action) |
java.util.concurrent.CompletableFuture<java.lang.Void> |
runAfterBothAsync(java.util.concurrent.CompletionStage<?> other,
java.lang.Runnable action,
java.util.concurrent.Executor executor) |
java.util.concurrent.CompletableFuture<java.lang.Void> |
runAfterEither(java.util.concurrent.CompletionStage<?> other,
java.lang.Runnable action) |
java.util.concurrent.CompletableFuture<java.lang.Void> |
runAfterEitherAsync(java.util.concurrent.CompletionStage<?> other,
java.lang.Runnable action) |
java.util.concurrent.CompletableFuture<java.lang.Void> |
runAfterEitherAsync(java.util.concurrent.CompletionStage<?> other,
java.lang.Runnable action,
java.util.concurrent.Executor executor) |
static ContextAwareCompletableFuture<java.lang.Void> |
runAsync(java.lang.Runnable runnable)
Runs the
runnable task in the common ForkJoinPool
within the current context and also applies that context to all successive
calls to the CompletableFuture. |
static ContextAwareCompletableFuture<java.lang.Void> |
runAsync(java.lang.Runnable runnable,
java.util.concurrent.Executor executor)
Runs the
runnable task in the specified executor
within the current context and also applies that context to all successive
calls to the CompletableFuture. |
static ContextAwareCompletableFuture<java.lang.Void> |
runAsync(java.lang.Runnable runnable,
java.util.concurrent.Executor executor,
ContextSnapshot snapshot)
Runs the
runnable task in the specified executor
within the specified context snapshot and also applies that context
to all successive calls to the CompletableFuture. |
static <U> ContextAwareCompletableFuture<U> |
supplyAsync(java.util.function.Supplier<U> supplier)
Runs the
supplier task in the common ForkJoinPool
within the current context and also applies that context to all successive
calls to the CompletableFuture. |
static <U> ContextAwareCompletableFuture<U> |
supplyAsync(java.util.function.Supplier<U> supplier,
java.util.concurrent.Executor executor)
Runs the
supplier task in the specified executor
within the current context and also applies that context to all successive
calls to the CompletableFuture. |
static <U> ContextAwareCompletableFuture<U> |
supplyAsync(java.util.function.Supplier<U> supplier,
java.util.concurrent.Executor executor,
ContextSnapshot snapshot)
Runs the
supplier task in the specified executor
within the specified context snapshot and also applies that context
to all successive calls to the CompletableFuture. |
java.util.concurrent.CompletableFuture<java.lang.Void> |
thenAccept(java.util.function.Consumer<? super T> action) |
java.util.concurrent.CompletableFuture<java.lang.Void> |
thenAcceptAsync(java.util.function.Consumer<? super T> action) |
java.util.concurrent.CompletableFuture<java.lang.Void> |
thenAcceptAsync(java.util.function.Consumer<? super T> action,
java.util.concurrent.Executor executor) |
<U> java.util.concurrent.CompletableFuture<java.lang.Void> |
thenAcceptBoth(java.util.concurrent.CompletionStage<? extends U> other,
java.util.function.BiConsumer<? super T,? super U> action) |
<U> java.util.concurrent.CompletableFuture<java.lang.Void> |
thenAcceptBothAsync(java.util.concurrent.CompletionStage<? extends U> other,
java.util.function.BiConsumer<? super T,? super U> action) |
<U> java.util.concurrent.CompletableFuture<java.lang.Void> |
thenAcceptBothAsync(java.util.concurrent.CompletionStage<? extends U> other,
java.util.function.BiConsumer<? super T,? super U> action,
java.util.concurrent.Executor executor) |
<U> java.util.concurrent.CompletableFuture<U> |
thenApply(java.util.function.Function<? super T,? extends U> fn) |
<U> java.util.concurrent.CompletableFuture<U> |
thenApplyAsync(java.util.function.Function<? super T,? extends U> fn) |
<U> java.util.concurrent.CompletableFuture<U> |
thenApplyAsync(java.util.function.Function<? super T,? extends U> fn,
java.util.concurrent.Executor executor) |
<U,V> java.util.concurrent.CompletableFuture<V> |
thenCombine(java.util.concurrent.CompletionStage<? extends U> other,
java.util.function.BiFunction<? super T,? super U,? extends V> fn) |
<U,V> java.util.concurrent.CompletableFuture<V> |
thenCombineAsync(java.util.concurrent.CompletionStage<? extends U> other,
java.util.function.BiFunction<? super T,? super U,? extends V> fn) |
<U,V> java.util.concurrent.CompletableFuture<V> |
thenCombineAsync(java.util.concurrent.CompletionStage<? extends U> other,
java.util.function.BiFunction<? super T,? super U,? extends V> fn,
java.util.concurrent.Executor executor) |
<U> java.util.concurrent.CompletableFuture<U> |
thenCompose(java.util.function.Function<? super T,? extends java.util.concurrent.CompletionStage<U>> fn) |
<U> java.util.concurrent.CompletableFuture<U> |
thenComposeAsync(java.util.function.Function<? super T,? extends java.util.concurrent.CompletionStage<U>> fn) |
<U> java.util.concurrent.CompletableFuture<U> |
thenComposeAsync(java.util.function.Function<? super T,? extends java.util.concurrent.CompletionStage<U>> fn,
java.util.concurrent.Executor executor) |
java.util.concurrent.CompletableFuture<java.lang.Void> |
thenRun(java.lang.Runnable action) |
java.util.concurrent.CompletableFuture<java.lang.Void> |
thenRunAsync(java.lang.Runnable action) |
java.util.concurrent.CompletableFuture<java.lang.Void> |
thenRunAsync(java.lang.Runnable action,
java.util.concurrent.Executor executor) |
java.util.concurrent.CompletableFuture<T> |
whenComplete(java.util.function.BiConsumer<? super T,? super java.lang.Throwable> action) |
java.util.concurrent.CompletableFuture<T> |
whenCompleteAsync(java.util.function.BiConsumer<? super T,? super java.lang.Throwable> action) |
java.util.concurrent.CompletableFuture<T> |
whenCompleteAsync(java.util.function.BiConsumer<? super T,? super java.lang.Throwable> action,
java.util.concurrent.Executor executor) |
protected <RESULT> java.util.concurrent.CompletableFuture<RESULT> |
wrapResult(java.util.concurrent.CompletableFuture<RESULT> result)
Wraps the resulting completable future from any folowup calls in this class.
|
public ContextAwareCompletableFuture()
ContextSnapshot and remembers that in this completable future, running all
completion methods within this snapshot.ContextManagers.createContextSnapshot()public ContextAwareCompletableFuture(ContextSnapshot snapshot)
CompletableFuture where all completion methods are run within the specified
snapshot context.snapshot - The snapshot to run completion methods in (or specify null to take a
new snapshot upon creation of this completable future).ContextManagers.createContextSnapshot()public static <U> ContextAwareCompletableFuture<U> supplyAsync(java.util.function.Supplier<U> supplier)
supplier task in the common ForkJoinPool
within the current context and also applies that context to all successive
calls to the CompletableFuture.U - the function's return typesupplier - a function returning the value to be used to complete the returned CompletableFutureCompletableFuture.supplyAsync(Supplier),
supplyAsync(Supplier, Executor, ContextSnapshot)public static <U> ContextAwareCompletableFuture<U> supplyAsync(java.util.function.Supplier<U> supplier, java.util.concurrent.Executor executor)
supplier task in the specified executor
within the current context and also applies that context to all successive
calls to the CompletableFuture.U - the function's return typesupplier - a function returning the value to be used to complete the returned CompletableFutureexecutor - the executor to use for asynchronous executionCompletableFuture.supplyAsync(Supplier, Executor),
supplyAsync(Supplier, Executor, ContextSnapshot)public static <U> ContextAwareCompletableFuture<U> supplyAsync(java.util.function.Supplier<U> supplier, java.util.concurrent.Executor executor, ContextSnapshot snapshot)
supplier task in the specified executor
within the specified context snapshot and also applies that context
to all successive calls to the CompletableFuture.
This method is lenient to null values for executor and snapshot:
If executor == null the common ForkJoinPool is used as
specified by CompletableFuture.supplyAsync(Supplier).
If snapshot == null a new context snapshot is
created for all successive calls to the CompletableFuture and the Supplier
(if not already a SupplierWithContext).
U - the function's return typesupplier - a function returning the value to be used to complete the returned CompletableFutureexecutor - the executor to use for asynchronous executionsnapshot - a snapshot of the context to be propagated in the supplier function
and all successive calls of this completable futureCompletableFuture.supplyAsync(Supplier, Executor)public static ContextAwareCompletableFuture<java.lang.Void> runAsync(java.lang.Runnable runnable)
runnable task in the common ForkJoinPool
within the current context and also applies that context to all successive
calls to the CompletableFuture.runnable - the action to run before completing the returned CompletableFutureCompletableFuture.runAsync(Runnable),
runAsync(Runnable, Executor, ContextSnapshot)public static ContextAwareCompletableFuture<java.lang.Void> runAsync(java.lang.Runnable runnable, java.util.concurrent.Executor executor)
runnable task in the specified executor
within the current context and also applies that context to all successive
calls to the CompletableFuture.runnable - the action to run before completing the returned CompletableFutureexecutor - the executor to use for asynchronous executionCompletableFuture.runAsync(Runnable, Executor),
runAsync(Runnable, Executor, ContextSnapshot)public static ContextAwareCompletableFuture<java.lang.Void> runAsync(java.lang.Runnable runnable, java.util.concurrent.Executor executor, ContextSnapshot snapshot)
runnable task in the specified executor
within the specified context snapshot and also applies that context
to all successive calls to the CompletableFuture.
This method is lenient to null values for executor and snapshot:
If executor == null the common ForkJoinPool is used as
specified by CompletableFuture.supplyAsync(Supplier).
If snapshot == null a new context snapshot is
created for all successive calls to the CompletableFuture and the Supplier
(if not already a SupplierWithContext).
runnable - the action to run before completing the returned CompletableFutureexecutor - the executor to use for asynchronous executionCompletableFuture.runAsync(Runnable, Executor)protected <RESULT> java.util.concurrent.CompletableFuture<RESULT> wrapResult(java.util.concurrent.CompletableFuture<RESULT> result)
RESULT - The result type of the completable future.result - The original result after the contextualized followup call.public <U> java.util.concurrent.CompletableFuture<U> thenApply(java.util.function.Function<? super T,? extends U> fn)
public <U> java.util.concurrent.CompletableFuture<U> thenApplyAsync(java.util.function.Function<? super T,? extends U> fn)
public <U> java.util.concurrent.CompletableFuture<U> thenApplyAsync(java.util.function.Function<? super T,? extends U> fn, java.util.concurrent.Executor executor)
public java.util.concurrent.CompletableFuture<java.lang.Void> thenAccept(java.util.function.Consumer<? super T> action)
public java.util.concurrent.CompletableFuture<java.lang.Void> thenAcceptAsync(java.util.function.Consumer<? super T> action)
public java.util.concurrent.CompletableFuture<java.lang.Void> thenAcceptAsync(java.util.function.Consumer<? super T> action, java.util.concurrent.Executor executor)
public java.util.concurrent.CompletableFuture<java.lang.Void> thenRun(java.lang.Runnable action)
public java.util.concurrent.CompletableFuture<java.lang.Void> thenRunAsync(java.lang.Runnable action)
public java.util.concurrent.CompletableFuture<java.lang.Void> thenRunAsync(java.lang.Runnable action,
java.util.concurrent.Executor executor)
public <U,V> java.util.concurrent.CompletableFuture<V> thenCombine(java.util.concurrent.CompletionStage<? extends U> other,
java.util.function.BiFunction<? super T,? super U,? extends V> fn)
public <U,V> java.util.concurrent.CompletableFuture<V> thenCombineAsync(java.util.concurrent.CompletionStage<? extends U> other,
java.util.function.BiFunction<? super T,? super U,? extends V> fn)
public <U,V> java.util.concurrent.CompletableFuture<V> thenCombineAsync(java.util.concurrent.CompletionStage<? extends U> other,
java.util.function.BiFunction<? super T,? super U,? extends V> fn,
java.util.concurrent.Executor executor)
public <U> java.util.concurrent.CompletableFuture<java.lang.Void> thenAcceptBoth(java.util.concurrent.CompletionStage<? extends U> other,
java.util.function.BiConsumer<? super T,? super U> action)
public <U> java.util.concurrent.CompletableFuture<java.lang.Void> thenAcceptBothAsync(java.util.concurrent.CompletionStage<? extends U> other,
java.util.function.BiConsumer<? super T,? super U> action)
public <U> java.util.concurrent.CompletableFuture<java.lang.Void> thenAcceptBothAsync(java.util.concurrent.CompletionStage<? extends U> other,
java.util.function.BiConsumer<? super T,? super U> action,
java.util.concurrent.Executor executor)
public java.util.concurrent.CompletableFuture<java.lang.Void> runAfterBoth(java.util.concurrent.CompletionStage<?> other,
java.lang.Runnable action)
public java.util.concurrent.CompletableFuture<java.lang.Void> runAfterBothAsync(java.util.concurrent.CompletionStage<?> other,
java.lang.Runnable action)
public java.util.concurrent.CompletableFuture<java.lang.Void> runAfterBothAsync(java.util.concurrent.CompletionStage<?> other,
java.lang.Runnable action,
java.util.concurrent.Executor executor)
public <U> java.util.concurrent.CompletableFuture<U> applyToEither(java.util.concurrent.CompletionStage<? extends T> other, java.util.function.Function<? super T,U> fn)
public <U> java.util.concurrent.CompletableFuture<U> applyToEitherAsync(java.util.concurrent.CompletionStage<? extends T> other, java.util.function.Function<? super T,U> fn)
public <U> java.util.concurrent.CompletableFuture<U> applyToEitherAsync(java.util.concurrent.CompletionStage<? extends T> other, java.util.function.Function<? super T,U> fn, java.util.concurrent.Executor executor)
public java.util.concurrent.CompletableFuture<java.lang.Void> acceptEither(java.util.concurrent.CompletionStage<? extends T> other, java.util.function.Consumer<? super T> action)
public java.util.concurrent.CompletableFuture<java.lang.Void> acceptEitherAsync(java.util.concurrent.CompletionStage<? extends T> other, java.util.function.Consumer<? super T> action)
public java.util.concurrent.CompletableFuture<java.lang.Void> acceptEitherAsync(java.util.concurrent.CompletionStage<? extends T> other, java.util.function.Consumer<? super T> action, java.util.concurrent.Executor executor)
public java.util.concurrent.CompletableFuture<java.lang.Void> runAfterEither(java.util.concurrent.CompletionStage<?> other,
java.lang.Runnable action)
public java.util.concurrent.CompletableFuture<java.lang.Void> runAfterEitherAsync(java.util.concurrent.CompletionStage<?> other,
java.lang.Runnable action)
public java.util.concurrent.CompletableFuture<java.lang.Void> runAfterEitherAsync(java.util.concurrent.CompletionStage<?> other,
java.lang.Runnable action,
java.util.concurrent.Executor executor)
public <U> java.util.concurrent.CompletableFuture<U> thenCompose(java.util.function.Function<? super T,? extends java.util.concurrent.CompletionStage<U>> fn)
public <U> java.util.concurrent.CompletableFuture<U> thenComposeAsync(java.util.function.Function<? super T,? extends java.util.concurrent.CompletionStage<U>> fn)
public <U> java.util.concurrent.CompletableFuture<U> thenComposeAsync(java.util.function.Function<? super T,? extends java.util.concurrent.CompletionStage<U>> fn, java.util.concurrent.Executor executor)
public java.util.concurrent.CompletableFuture<T> whenComplete(java.util.function.BiConsumer<? super T,? super java.lang.Throwable> action)
public java.util.concurrent.CompletableFuture<T> whenCompleteAsync(java.util.function.BiConsumer<? super T,? super java.lang.Throwable> action)
public java.util.concurrent.CompletableFuture<T> whenCompleteAsync(java.util.function.BiConsumer<? super T,? super java.lang.Throwable> action, java.util.concurrent.Executor executor)
public <U> java.util.concurrent.CompletableFuture<U> handle(java.util.function.BiFunction<? super T,java.lang.Throwable,? extends U> fn)
public <U> java.util.concurrent.CompletableFuture<U> handleAsync(java.util.function.BiFunction<? super T,java.lang.Throwable,? extends U> fn)
public <U> java.util.concurrent.CompletableFuture<U> handleAsync(java.util.function.BiFunction<? super T,java.lang.Throwable,? extends U> fn, java.util.concurrent.Executor executor)
Copyright © 2016–2018 Talsma ICT. All rights reserved.