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 | 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 | Description |
|---|---|---|
ContextAwareCompletableFuture<java.lang.Void> |
acceptEither(java.util.concurrent.CompletionStage<? extends T> other,
java.util.function.Consumer<? super T> action) |
|
ContextAwareCompletableFuture<java.lang.Void> |
acceptEitherAsync(java.util.concurrent.CompletionStage<? extends T> other,
java.util.function.Consumer<? super T> action) |
|
ContextAwareCompletableFuture<java.lang.Void> |
acceptEitherAsync(java.util.concurrent.CompletionStage<? extends T> other,
java.util.function.Consumer<? super T> action,
java.util.concurrent.Executor executor) |
|
<U> ContextAwareCompletableFuture<U> |
applyToEither(java.util.concurrent.CompletionStage<? extends T> other,
java.util.function.Function<? super T,U> fn) |
|
<U> ContextAwareCompletableFuture<U> |
applyToEitherAsync(java.util.concurrent.CompletionStage<? extends T> other,
java.util.function.Function<? super T,U> fn) |
|
<U> ContextAwareCompletableFuture<U> |
applyToEitherAsync(java.util.concurrent.CompletionStage<? extends T> other,
java.util.function.Function<? super T,U> fn,
java.util.concurrent.Executor executor) |
|
ContextAwareCompletableFuture<T> |
exceptionally(java.util.function.Function<java.lang.Throwable,? extends T> fn) |
|
<U> ContextAwareCompletableFuture<U> |
handle(java.util.function.BiFunction<? super T,java.lang.Throwable,? extends U> fn) |
|
<U> ContextAwareCompletableFuture<U> |
handleAsync(java.util.function.BiFunction<? super T,java.lang.Throwable,? extends U> fn) |
|
<U> ContextAwareCompletableFuture<U> |
handleAsync(java.util.function.BiFunction<? super T,java.lang.Throwable,? extends U> fn,
java.util.concurrent.Executor executor) |
|
ContextAwareCompletableFuture<java.lang.Void> |
runAfterBoth(java.util.concurrent.CompletionStage<?> other,
java.lang.Runnable action) |
|
ContextAwareCompletableFuture<java.lang.Void> |
runAfterBothAsync(java.util.concurrent.CompletionStage<?> other,
java.lang.Runnable action) |
|
ContextAwareCompletableFuture<java.lang.Void> |
runAfterBothAsync(java.util.concurrent.CompletionStage<?> other,
java.lang.Runnable action,
java.util.concurrent.Executor executor) |
|
ContextAwareCompletableFuture<java.lang.Void> |
runAfterEither(java.util.concurrent.CompletionStage<?> other,
java.lang.Runnable action) |
|
ContextAwareCompletableFuture<java.lang.Void> |
runAfterEitherAsync(java.util.concurrent.CompletionStage<?> other,
java.lang.Runnable action) |
|
ContextAwareCompletableFuture<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. |
ContextAwareCompletableFuture<T> |
takeNewSnapshot() |
Returns a context-aware CompletableFuture that takes a new snapshot after each completion stage.
|
ContextAwareCompletableFuture<T> |
takeNewSnapshot(boolean takeSnapshot) |
Returns a context-aware CompletableFuture that may take a new snapshot after each completion stage.
|
ContextAwareCompletableFuture<java.lang.Void> |
thenAccept(java.util.function.Consumer<? super T> action) |
|
ContextAwareCompletableFuture<java.lang.Void> |
thenAcceptAsync(java.util.function.Consumer<? super T> action) |
|
ContextAwareCompletableFuture<java.lang.Void> |
thenAcceptAsync(java.util.function.Consumer<? super T> action,
java.util.concurrent.Executor executor) |
|
<U> ContextAwareCompletableFuture<java.lang.Void> |
thenAcceptBoth(java.util.concurrent.CompletionStage<? extends U> other,
java.util.function.BiConsumer<? super T,? super U> action) |
|
<U> ContextAwareCompletableFuture<java.lang.Void> |
thenAcceptBothAsync(java.util.concurrent.CompletionStage<? extends U> other,
java.util.function.BiConsumer<? super T,? super U> action) |
|
<U> ContextAwareCompletableFuture<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> ContextAwareCompletableFuture<U> |
thenApply(java.util.function.Function<? super T,? extends U> fn) |
|
<U> ContextAwareCompletableFuture<U> |
thenApplyAsync(java.util.function.Function<? super T,? extends U> fn) |
|
<U> ContextAwareCompletableFuture<U> |
thenApplyAsync(java.util.function.Function<? super T,? extends U> fn,
java.util.concurrent.Executor executor) |
|
<U,V> ContextAwareCompletableFuture<V> |
thenCombine(java.util.concurrent.CompletionStage<? extends U> other,
java.util.function.BiFunction<? super T,? super U,? extends V> fn) |
|
<U,V> ContextAwareCompletableFuture<V> |
thenCombineAsync(java.util.concurrent.CompletionStage<? extends U> other,
java.util.function.BiFunction<? super T,? super U,? extends V> fn) |
|
<U,V> ContextAwareCompletableFuture<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> ContextAwareCompletableFuture<U> |
thenCompose(java.util.function.Function<? super T,? extends java.util.concurrent.CompletionStage<U>> fn) |
|
<U> ContextAwareCompletableFuture<U> |
thenComposeAsync(java.util.function.Function<? super T,? extends java.util.concurrent.CompletionStage<U>> fn) |
|
<U> ContextAwareCompletableFuture<U> |
thenComposeAsync(java.util.function.Function<? super T,? extends java.util.concurrent.CompletionStage<U>> fn,
java.util.concurrent.Executor executor) |
|
ContextAwareCompletableFuture<java.lang.Void> |
thenRun(java.lang.Runnable action) |
|
java.util.concurrent.CompletableFuture<java.lang.Void> |
thenRunAsync(java.lang.Runnable action) |
|
ContextAwareCompletableFuture<java.lang.Void> |
thenRunAsync(java.lang.Runnable action,
java.util.concurrent.Executor executor) |
|
ContextAwareCompletableFuture<T> |
whenComplete(java.util.function.BiConsumer<? super T,? super java.lang.Throwable> action) |
|
ContextAwareCompletableFuture<T> |
whenCompleteAsync(java.util.function.BiConsumer<? super T,? super java.lang.Throwable> action) |
|
ContextAwareCompletableFuture<T> |
whenCompleteAsync(java.util.function.BiConsumer<? super T,? super java.lang.Throwable> action,
java.util.concurrent.Executor executor) |
allOf, anyOf, cancel, complete, completeAsync, completeAsync, completedFuture, completedStage, completeExceptionally, completeOnTimeout, copy, defaultExecutor, delayedExecutor, delayedExecutor, failedFuture, failedStage, get, get, getNow, getNumberOfDependents, isCancelled, isCompletedExceptionally, isDone, join, minimalCompletionStage, newIncompleteFuture, obtrudeException, obtrudeValue, orTimeout, toCompletableFuture, toStringpublic 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.
Optional, the completable future will take a new snaphot if null is provided.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 to be performed asynchronously returning the result of the 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 executionsnapshot - the context snapshot to apply to the runnable actionCompletableFuture.runAsync(Runnable, Executor)public ContextAwareCompletableFuture<T> takeNewSnapshot()
This means that after each then..., run..., apply... method,
after calling the function, a new context snapshot is taken for follow-up calls.
Only use this when chaining completable futures where the completion stages may update contextual values.
Warning: This may result in unnecessary context snapshots being taken.
CompletionStagepublic ContextAwareCompletableFuture<T> takeNewSnapshot(boolean takeSnapshot)
This means that after each then..., run..., apply... method,
after calling the function, a new context snapshot is taken for follow-up calls.
Only set this to true when chaining completable futures where the completion stages
may update contextual values.
Warning: This may result in unnecessary context snapshots being taken.
takeSnapshot - whether or not new context snapshots must be taken after each completion stage.takeSnapshot is true.CompletionStagepublic <U> ContextAwareCompletableFuture<U> thenApply(java.util.function.Function<? super T,? extends U> fn)
thenApply in class java.util.concurrent.CompletableFuture<T>public <U> ContextAwareCompletableFuture<U> thenApplyAsync(java.util.function.Function<? super T,? extends U> fn)
thenApplyAsync in class java.util.concurrent.CompletableFuture<T>public <U> ContextAwareCompletableFuture<U> thenApplyAsync(java.util.function.Function<? super T,? extends U> fn, java.util.concurrent.Executor executor)
thenApplyAsync in class java.util.concurrent.CompletableFuture<T>public ContextAwareCompletableFuture<java.lang.Void> thenAccept(java.util.function.Consumer<? super T> action)
thenAccept in class java.util.concurrent.CompletableFuture<T>public ContextAwareCompletableFuture<java.lang.Void> thenAcceptAsync(java.util.function.Consumer<? super T> action)
thenAcceptAsync in class java.util.concurrent.CompletableFuture<T>public ContextAwareCompletableFuture<java.lang.Void> thenAcceptAsync(java.util.function.Consumer<? super T> action, java.util.concurrent.Executor executor)
thenAcceptAsync in class java.util.concurrent.CompletableFuture<T>public ContextAwareCompletableFuture<java.lang.Void> thenRun(java.lang.Runnable action)
thenRun in class java.util.concurrent.CompletableFuture<T>public java.util.concurrent.CompletableFuture<java.lang.Void> thenRunAsync(java.lang.Runnable action)
thenRunAsync in class java.util.concurrent.CompletableFuture<T>public ContextAwareCompletableFuture<java.lang.Void> thenRunAsync(java.lang.Runnable action, java.util.concurrent.Executor executor)
thenRunAsync in class java.util.concurrent.CompletableFuture<T>public <U,V> ContextAwareCompletableFuture<V> thenCombine(java.util.concurrent.CompletionStage<? extends U> other, java.util.function.BiFunction<? super T,? super U,? extends V> fn)
thenCombine in class java.util.concurrent.CompletableFuture<T>public <U,V> ContextAwareCompletableFuture<V> thenCombineAsync(java.util.concurrent.CompletionStage<? extends U> other, java.util.function.BiFunction<? super T,? super U,? extends V> fn)
thenCombineAsync in class java.util.concurrent.CompletableFuture<T>public <U,V> ContextAwareCompletableFuture<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)
thenCombineAsync in class java.util.concurrent.CompletableFuture<T>public <U> ContextAwareCompletableFuture<java.lang.Void> thenAcceptBoth(java.util.concurrent.CompletionStage<? extends U> other, java.util.function.BiConsumer<? super T,? super U> action)
thenAcceptBoth in class java.util.concurrent.CompletableFuture<T>public <U> ContextAwareCompletableFuture<java.lang.Void> thenAcceptBothAsync(java.util.concurrent.CompletionStage<? extends U> other, java.util.function.BiConsumer<? super T,? super U> action)
thenAcceptBothAsync in class java.util.concurrent.CompletableFuture<T>public <U> ContextAwareCompletableFuture<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)
thenAcceptBothAsync in class java.util.concurrent.CompletableFuture<T>public ContextAwareCompletableFuture<java.lang.Void> runAfterBoth(java.util.concurrent.CompletionStage<?> other, java.lang.Runnable action)
runAfterBoth in class java.util.concurrent.CompletableFuture<T>public ContextAwareCompletableFuture<java.lang.Void> runAfterBothAsync(java.util.concurrent.CompletionStage<?> other, java.lang.Runnable action)
runAfterBothAsync in class java.util.concurrent.CompletableFuture<T>public ContextAwareCompletableFuture<java.lang.Void> runAfterBothAsync(java.util.concurrent.CompletionStage<?> other, java.lang.Runnable action, java.util.concurrent.Executor executor)
runAfterBothAsync in class java.util.concurrent.CompletableFuture<T>public <U> ContextAwareCompletableFuture<U> applyToEither(java.util.concurrent.CompletionStage<? extends T> other, java.util.function.Function<? super T,U> fn)
applyToEither in class java.util.concurrent.CompletableFuture<T>public <U> ContextAwareCompletableFuture<U> applyToEitherAsync(java.util.concurrent.CompletionStage<? extends T> other, java.util.function.Function<? super T,U> fn)
applyToEitherAsync in class java.util.concurrent.CompletableFuture<T>public <U> ContextAwareCompletableFuture<U> applyToEitherAsync(java.util.concurrent.CompletionStage<? extends T> other, java.util.function.Function<? super T,U> fn, java.util.concurrent.Executor executor)
applyToEitherAsync in class java.util.concurrent.CompletableFuture<T>public ContextAwareCompletableFuture<java.lang.Void> acceptEither(java.util.concurrent.CompletionStage<? extends T> other, java.util.function.Consumer<? super T> action)
acceptEither in class java.util.concurrent.CompletableFuture<T>public ContextAwareCompletableFuture<java.lang.Void> acceptEitherAsync(java.util.concurrent.CompletionStage<? extends T> other, java.util.function.Consumer<? super T> action)
acceptEitherAsync in class java.util.concurrent.CompletableFuture<T>public ContextAwareCompletableFuture<java.lang.Void> acceptEitherAsync(java.util.concurrent.CompletionStage<? extends T> other, java.util.function.Consumer<? super T> action, java.util.concurrent.Executor executor)
acceptEitherAsync in class java.util.concurrent.CompletableFuture<T>public ContextAwareCompletableFuture<java.lang.Void> runAfterEither(java.util.concurrent.CompletionStage<?> other, java.lang.Runnable action)
runAfterEither in class java.util.concurrent.CompletableFuture<T>public ContextAwareCompletableFuture<java.lang.Void> runAfterEitherAsync(java.util.concurrent.CompletionStage<?> other, java.lang.Runnable action)
runAfterEitherAsync in class java.util.concurrent.CompletableFuture<T>public ContextAwareCompletableFuture<java.lang.Void> runAfterEitherAsync(java.util.concurrent.CompletionStage<?> other, java.lang.Runnable action, java.util.concurrent.Executor executor)
runAfterEitherAsync in class java.util.concurrent.CompletableFuture<T>public <U> ContextAwareCompletableFuture<U> thenCompose(java.util.function.Function<? super T,? extends java.util.concurrent.CompletionStage<U>> fn)
thenCompose in class java.util.concurrent.CompletableFuture<T>public <U> ContextAwareCompletableFuture<U> thenComposeAsync(java.util.function.Function<? super T,? extends java.util.concurrent.CompletionStage<U>> fn)
thenComposeAsync in class java.util.concurrent.CompletableFuture<T>public <U> ContextAwareCompletableFuture<U> thenComposeAsync(java.util.function.Function<? super T,? extends java.util.concurrent.CompletionStage<U>> fn, java.util.concurrent.Executor executor)
thenComposeAsync in class java.util.concurrent.CompletableFuture<T>public ContextAwareCompletableFuture<T> whenComplete(java.util.function.BiConsumer<? super T,? super java.lang.Throwable> action)
whenComplete in class java.util.concurrent.CompletableFuture<T>public ContextAwareCompletableFuture<T> whenCompleteAsync(java.util.function.BiConsumer<? super T,? super java.lang.Throwable> action)
whenCompleteAsync in class java.util.concurrent.CompletableFuture<T>public ContextAwareCompletableFuture<T> whenCompleteAsync(java.util.function.BiConsumer<? super T,? super java.lang.Throwable> action, java.util.concurrent.Executor executor)
whenCompleteAsync in class java.util.concurrent.CompletableFuture<T>public <U> ContextAwareCompletableFuture<U> handle(java.util.function.BiFunction<? super T,java.lang.Throwable,? extends U> fn)
handle in class java.util.concurrent.CompletableFuture<T>public <U> ContextAwareCompletableFuture<U> handleAsync(java.util.function.BiFunction<? super T,java.lang.Throwable,? extends U> fn)
handleAsync in class java.util.concurrent.CompletableFuture<T>public <U> ContextAwareCompletableFuture<U> handleAsync(java.util.function.BiFunction<? super T,java.lang.Throwable,? extends U> fn, java.util.concurrent.Executor executor)
handleAsync in class java.util.concurrent.CompletableFuture<T>public ContextAwareCompletableFuture<T> exceptionally(java.util.function.Function<java.lang.Throwable,? extends T> fn)
exceptionally in class java.util.concurrent.CompletableFuture<T>Copyright © 2016–2019 Talsma ICT. All rights reserved.