Class ContextAwareCompletableFuture<T>
- java.lang.Object
-
- java.util.concurrent.CompletableFuture<T>
-
- nl.talsmasoftware.context.futures.ContextAwareCompletableFuture<T>
-
- All Implemented Interfaces:
CompletionStage<T>,Future<T>
public class ContextAwareCompletableFuture<T> extends CompletableFuture<T>
This class extends the standardCompletableFuturethat 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 creationof thisContextAwareCompletableFuture.- Author:
- Sjoerd Talsma
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class java.util.concurrent.CompletableFuture
CompletableFuture.AsynchronousCompletionTask
-
-
Constructor Summary
Constructors Constructor Description ContextAwareCompletableFuture()Creates a newContextSnapshotand remembers that in this completable future, running all completion methods within this snapshot.ContextAwareCompletableFuture(ContextSnapshot snapshot)Creates a newCompletableFuturewhere all completion methods are run within the specified snapshot context.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description ContextAwareCompletableFuture<Void>acceptEither(CompletionStage<? extends T> other, Consumer<? super T> action)ContextAwareCompletableFuture<Void>acceptEitherAsync(CompletionStage<? extends T> other, Consumer<? super T> action)ContextAwareCompletableFuture<Void>acceptEitherAsync(CompletionStage<? extends T> other, Consumer<? super T> action, Executor executor)static ContextAwareCompletableFuture<Void>allOf(CompletableFuture<?>... cfs)Returns a new CompletableFuture that is completed when all of the given CompletableFutures complete.static ContextAwareCompletableFuture<Void>allOf(ContextSnapshot snapshot, CompletableFuture<?>... cfs)Returns a new CompletableFuture that is completed when all of the given CompletableFutures complete.static ContextAwareCompletableFuture<Object>anyOf(CompletableFuture<?>... cfs)Returns a new CompletableFuture that is completed when any of the given CompletableFutures complete, with the same result.static ContextAwareCompletableFuture<Object>anyOf(ContextSnapshot snapshot, CompletableFuture<?>... cfs)Returns a new CompletableFuture that is completed when any of the given CompletableFutures complete, with the same result.<U> ContextAwareCompletableFuture<U>applyToEither(CompletionStage<? extends T> other, Function<? super T,U> fn)<U> ContextAwareCompletableFuture<U>applyToEitherAsync(CompletionStage<? extends T> other, Function<? super T,U> fn)<U> ContextAwareCompletableFuture<U>applyToEitherAsync(CompletionStage<? extends T> other, Function<? super T,U> fn, Executor executor)static <U> ContextAwareCompletableFuture<U>completedFuture(U value)Creates a newContextAwareCompletableFuturefrom the already-completed value.static <U> ContextAwareCompletableFuture<U>completedFuture(U value, ContextSnapshot snapshot)Creates a newContextAwareCompletableFuturefrom the already-completed value.static <U> CompletionStage<U>completedStage(U value)Creates a newCompletionStagefrom the already-completed value.ContextAwareCompletableFuture<T>exceptionally(Function<Throwable,? extends T> fn)static <U> ContextAwareCompletableFuture<U>failedFuture(Throwable ex)Creates a newContextAwareCompletableFuturethat is already completed exceptionally with the given exception.static <U> ContextAwareCompletableFuture<U>failedFuture(Throwable ex, ContextSnapshot snapshot)Creates a newContextAwareCompletableFuturethat is already completed exceptionally with the given exception.static <U> CompletionStage<U>failedStage(Throwable ex)Creates a newCompletionStagethat is already completed exceptionally with the given exception.<U> ContextAwareCompletableFuture<U>handle(BiFunction<? super T,Throwable,? extends U> fn)<U> ContextAwareCompletableFuture<U>handleAsync(BiFunction<? super T,Throwable,? extends U> fn)<U> ContextAwareCompletableFuture<U>handleAsync(BiFunction<? super T,Throwable,? extends U> fn, Executor executor)ContextAwareCompletableFuture<Void>runAfterBoth(CompletionStage<?> other, Runnable action)ContextAwareCompletableFuture<Void>runAfterBothAsync(CompletionStage<?> other, Runnable action)ContextAwareCompletableFuture<Void>runAfterBothAsync(CompletionStage<?> other, Runnable action, Executor executor)ContextAwareCompletableFuture<Void>runAfterEither(CompletionStage<?> other, Runnable action)ContextAwareCompletableFuture<Void>runAfterEitherAsync(CompletionStage<?> other, Runnable action)ContextAwareCompletableFuture<Void>runAfterEitherAsync(CompletionStage<?> other, Runnable action, Executor executor)static ContextAwareCompletableFuture<Void>runAsync(Runnable runnable)Runs therunnabletask in the commonForkJoinPoolwithin the current context and also applies that context to all successive calls to theCompletableFuture.static ContextAwareCompletableFuture<Void>runAsync(Runnable runnable, Executor executor)Runs therunnabletask in the specifiedexecutorwithin the current context and also applies that context to all successive calls to theCompletableFuture.static ContextAwareCompletableFuture<Void>runAsync(Runnable runnable, Executor executor, ContextSnapshot snapshot)Runs therunnabletask in the specifiedexecutorwithin the specifiedcontext snapshotand also applies that context to all successive calls to theCompletableFuture.static ContextAwareCompletableFuture<Void>runAsync(Runnable runnable, Executor executor, ContextSnapshot snapshot, boolean takeNewSnapshot)Runs therunnabletask in the specifiedexecutorwithin the specifiedcontext snapshotand also applies that context to all successive calls to theCompletableFuture.static <U> ContextAwareCompletableFuture<U>supplyAsync(Supplier<U> supplier)Runs thesuppliertask in the commonForkJoinPoolwithin the current context and also applies that context to all successive calls to theCompletableFuture.static <U> ContextAwareCompletableFuture<U>supplyAsync(Supplier<U> supplier, Executor executor)Runs thesuppliertask in the specifiedexecutorwithin the current context and also applies that context to all successive calls to theCompletableFuture.static <U> ContextAwareCompletableFuture<U>supplyAsync(Supplier<U> supplier, Executor executor, ContextSnapshot snapshot)Runs thesuppliertask in the specifiedexecutorwithin the specifiedcontext snapshotand also applies that context to all successive calls to theCompletableFuture.static <U> ContextAwareCompletableFuture<U>supplyAsync(Supplier<U> supplier, Executor executor, ContextSnapshot snapshot, boolean takeNewSnapshot)Runs thesuppliertask in the specifiedexecutorwithin the specifiedcontext snapshotand also applies that context to all successive calls to theCompletableFuture.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<Void>thenAccept(Consumer<? super T> action)ContextAwareCompletableFuture<Void>thenAcceptAsync(Consumer<? super T> action)ContextAwareCompletableFuture<Void>thenAcceptAsync(Consumer<? super T> action, Executor executor)<U> ContextAwareCompletableFuture<Void>thenAcceptBoth(CompletionStage<? extends U> other, BiConsumer<? super T,? super U> action)<U> ContextAwareCompletableFuture<Void>thenAcceptBothAsync(CompletionStage<? extends U> other, BiConsumer<? super T,? super U> action)<U> ContextAwareCompletableFuture<Void>thenAcceptBothAsync(CompletionStage<? extends U> other, BiConsumer<? super T,? super U> action, Executor executor)<U> ContextAwareCompletableFuture<U>thenApply(Function<? super T,? extends U> fn)<U> ContextAwareCompletableFuture<U>thenApplyAsync(Function<? super T,? extends U> fn)<U> ContextAwareCompletableFuture<U>thenApplyAsync(Function<? super T,? extends U> fn, Executor executor)<U,V>
ContextAwareCompletableFuture<V>thenCombine(CompletionStage<? extends U> other, BiFunction<? super T,? super U,? extends V> fn)<U,V>
ContextAwareCompletableFuture<V>thenCombineAsync(CompletionStage<? extends U> other, BiFunction<? super T,? super U,? extends V> fn)<U,V>
ContextAwareCompletableFuture<V>thenCombineAsync(CompletionStage<? extends U> other, BiFunction<? super T,? super U,? extends V> fn, Executor executor)<U> ContextAwareCompletableFuture<U>thenCompose(Function<? super T,? extends CompletionStage<U>> fn)<U> ContextAwareCompletableFuture<U>thenComposeAsync(Function<? super T,? extends CompletionStage<U>> fn)<U> ContextAwareCompletableFuture<U>thenComposeAsync(Function<? super T,? extends CompletionStage<U>> fn, Executor executor)ContextAwareCompletableFuture<Void>thenRun(Runnable action)CompletableFuture<Void>thenRunAsync(Runnable action)ContextAwareCompletableFuture<Void>thenRunAsync(Runnable action, Executor executor)ContextAwareCompletableFuture<T>whenComplete(BiConsumer<? super T,? super Throwable> action)ContextAwareCompletableFuture<T>whenCompleteAsync(BiConsumer<? super T,? super Throwable> action)ContextAwareCompletableFuture<T>whenCompleteAsync(BiConsumer<? super T,? super Throwable> action, Executor executor)-
Methods inherited from class java.util.concurrent.CompletableFuture
cancel, complete, completeAsync, completeAsync, completeExceptionally, completeOnTimeout, copy, defaultExecutor, delayedExecutor, delayedExecutor, get, get, getNow, getNumberOfDependents, isCancelled, isCompletedExceptionally, isDone, join, minimalCompletionStage, newIncompleteFuture, obtrudeException, obtrudeValue, orTimeout, toCompletableFuture, toString
-
-
-
-
Constructor Detail
-
ContextAwareCompletableFuture
public ContextAwareCompletableFuture()
Creates a newContextSnapshotand remembers that in this completable future, running all completion methods within this snapshot.- See Also:
ContextManagers.createContextSnapshot()
-
ContextAwareCompletableFuture
public ContextAwareCompletableFuture(ContextSnapshot snapshot)
Creates a newCompletableFuturewhere all completion methods are run within the specified snapshot context.- Parameters:
snapshot- the snapshot to run completion methods in. Optional, the completable future will take a new snaphot ifnullis provided.- See Also:
ContextManagers.createContextSnapshot()
-
-
Method Detail
-
supplyAsync
public static <U> ContextAwareCompletableFuture<U> supplyAsync(Supplier<U> supplier)
Runs thesuppliertask in the commonForkJoinPoolwithin the current context and also applies that context to all successive calls to theCompletableFuture.- Type Parameters:
U- the function's return type- Parameters:
supplier- a function to be performed asynchronously returning the result of the CompletableFuture- Returns:
- The new CompletableFuture that propagates a snapshot of the current context
- See Also:
CompletableFuture.supplyAsync(Supplier),supplyAsync(Supplier, Executor, ContextSnapshot, boolean)
-
supplyAsync
public static <U> ContextAwareCompletableFuture<U> supplyAsync(Supplier<U> supplier, Executor executor)
Runs thesuppliertask in the specifiedexecutorwithin the current context and also applies that context to all successive calls to theCompletableFuture.- Type Parameters:
U- the function's return type- Parameters:
supplier- a function returning the value to be used to complete the returned CompletableFutureexecutor- the executor to use for asynchronous execution- Returns:
- The new CompletableFuture that propagates a snapshot of the current context
- See Also:
CompletableFuture.supplyAsync(Supplier, Executor),supplyAsync(Supplier, Executor, ContextSnapshot, boolean)
-
supplyAsync
public static <U> ContextAwareCompletableFuture<U> supplyAsync(Supplier<U> supplier, Executor executor, ContextSnapshot snapshot)
Runs thesuppliertask in the specifiedexecutorwithin the specifiedcontext snapshotand also applies that context to all successive calls to theCompletableFuture.This method is lenient to
nullvalues forexecutorandsnapshot:
Ifexecutor == nullthe commonForkJoinPoolis used as specified byCompletableFuture.supplyAsync(Supplier).
Ifsnapshot == nullanew context snapshotis created for theSupplier(if not already aSupplierWithContext).- Type Parameters:
U- the function's return type- Parameters:
supplier- 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 future- Returns:
- The new CompletableFuture that propagates the specified context snapshot
- See Also:
CompletableFuture.supplyAsync(Supplier, Executor),supplyAsync(Supplier, Executor, ContextSnapshot, boolean)
-
supplyAsync
public static <U> ContextAwareCompletableFuture<U> supplyAsync(Supplier<U> supplier, Executor executor, ContextSnapshot snapshot, boolean takeNewSnapshot)
Runs thesuppliertask in the specifiedexecutorwithin the specifiedcontext snapshotand also applies that context to all successive calls to theCompletableFuture.This method is lenient to
nullvalues forexecutorandsnapshot:
Ifexecutor == nullthe commonForkJoinPoolis used as specified byCompletableFuture.supplyAsync(Supplier).
Ifsnapshot == nullanew context snapshotis created for theSupplier(if not already aSupplierWithContext).- Type Parameters:
U- the function's return type- Parameters:
supplier- 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 futuretakeNewSnapshot- whether or not a new ContextSnapshot should be taken after the supplier function is done. Iffalse, the snapshot from the caller propagate to all following completion stages. Iftrue, a new snapshot is taken after each completion stage to propagate into the next.- Returns:
- The new CompletableFuture that propagates the specified context snapshot
- Since:
- 1.0.4
- See Also:
CompletableFuture.supplyAsync(Supplier, Executor)
-
runAsync
public static ContextAwareCompletableFuture<Void> runAsync(Runnable runnable)
Runs therunnabletask in the commonForkJoinPoolwithin the current context and also applies that context to all successive calls to theCompletableFuture.- Parameters:
runnable- the action to run before completing the returned CompletableFuture- Returns:
- The new CompletableFuture that propagates a snapshot of the current context
- See Also:
CompletableFuture.runAsync(Runnable),runAsync(Runnable, Executor, ContextSnapshot, boolean)
-
runAsync
public static ContextAwareCompletableFuture<Void> runAsync(Runnable runnable, Executor executor)
Runs therunnabletask in the specifiedexecutorwithin the current context and also applies that context to all successive calls to theCompletableFuture.- Parameters:
runnable- the action to run before completing the returned CompletableFutureexecutor- the executor to use for asynchronous execution- Returns:
- The new CompletableFuture that propagates a snapshot of the current context
- See Also:
CompletableFuture.runAsync(Runnable, Executor),runAsync(Runnable, Executor, ContextSnapshot, boolean)
-
runAsync
public static ContextAwareCompletableFuture<Void> runAsync(Runnable runnable, Executor executor, ContextSnapshot snapshot)
Runs therunnabletask in the specifiedexecutorwithin the specifiedcontext snapshotand also applies that context to all successive calls to theCompletableFuture.This method is lenient to
nullvalues forexecutorandsnapshot:
Ifexecutor == nullthe commonForkJoinPoolis used as specified byCompletableFuture.supplyAsync(Supplier).
Ifsnapshot == nullanew context snapshotis created for theSupplier(if not already aSupplierWithContext).- Parameters:
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 action- Returns:
- The new CompletableFuture that propagates a snapshot of the current context
- See Also:
CompletableFuture.runAsync(Runnable, Executor),runAsync(Runnable, Executor, ContextSnapshot, boolean)
-
runAsync
public static ContextAwareCompletableFuture<Void> runAsync(Runnable runnable, Executor executor, ContextSnapshot snapshot, boolean takeNewSnapshot)
Runs therunnabletask in the specifiedexecutorwithin the specifiedcontext snapshotand also applies that context to all successive calls to theCompletableFuture.This method is lenient to
nullvalues forexecutorandsnapshot:
Ifexecutor == nullthe commonForkJoinPoolis used as specified byCompletableFuture.supplyAsync(Supplier).
Ifsnapshot == nullanew context snapshotis created for theSupplier(if not already aSupplierWithContext).- Parameters:
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 actiontakeNewSnapshot- whether or not a new ContextSnapshot should be taken after the supplier function is done. Iffalse, the snapshot from the caller propagate to all following completion stages. Iftrue, a new snapshot is taken after each completion stage to propagate into the next.- Returns:
- The new CompletableFuture that propagates a snapshot of the current context
- Since:
- 1.0.4
- See Also:
CompletableFuture.runAsync(Runnable, Executor)
-
completedFuture
public static <U> ContextAwareCompletableFuture<U> completedFuture(U value)
Creates a newContextAwareCompletableFuturefrom the already-completed value. A new ContextSnapshot is taken and applied to all following completion stages.- Type Parameters:
U- the type of the value- Parameters:
value- the value to return from the already-completed future.- Returns:
- New
ContextAwareCompletableFuturereturning the completed value and containing a newContextSnapshot. - Since:
- 1.0.5
- See Also:
completedFuture(Object, ContextSnapshot)
-
completedFuture
public static <U> ContextAwareCompletableFuture<U> completedFuture(U value, ContextSnapshot snapshot)
Creates a newContextAwareCompletableFuturefrom the already-completed value. A new ContextSnapshot is taken and applied to all following completion stages.- Type Parameters:
U- the type of the value- Parameters:
value- the value to return from the already-completed future.snapshot- the context snapshot to apply to following completion stages (optional, specifynullto take a new snapshot)- Returns:
- New
ContextAwareCompletableFuturereturning the completed value and containing the specifiedContextSnapshot. - Since:
- 1.0.5
-
completedStage
public static <U> CompletionStage<U> completedStage(U value)
Creates a newCompletionStagefrom the already-completed value. A new ContextSnapshot is taken and applied to all following completion stages.- Type Parameters:
U- the type of the value- Parameters:
value- the value to return from the already-completed stage.- Returns:
- New
CompletionStagereturning the completed value and containing a newContextSnapshot. - Since:
- 1.0.5
- See Also:
completedFuture(Object, ContextSnapshot)
-
failedFuture
public static <U> ContextAwareCompletableFuture<U> failedFuture(Throwable ex)
Creates a newContextAwareCompletableFuturethat is already completed exceptionally with the given exception. A new ContextSnapshot is taken and applied to all following completion stages.- Type Parameters:
U- the type of the value- Parameters:
ex- the exception- Returns:
- New
ContextAwareCompletableFuturethrowing the exception and containing a newContextSnapshot. - Since:
- 1.0.5
- See Also:
failedFuture(Throwable, ContextSnapshot)
-
failedFuture
public static <U> ContextAwareCompletableFuture<U> failedFuture(Throwable ex, ContextSnapshot snapshot)
Creates a newContextAwareCompletableFuturethat is already completed exceptionally with the given exception. The specifiedsnapshotis applied to all following completion stages.- Type Parameters:
U- the type of the value- Parameters:
ex- the exceptionsnapshot- the context snapshot to apply to following completion stages (optional, specifynullto take a new snapshot)- Returns:
- New
ContextAwareCompletableFuturethrowing the exception and containing the specifiedsnapshot. - Since:
- 1.0.5
-
failedStage
public static <U> CompletionStage<U> failedStage(Throwable ex)
Creates a newCompletionStagethat is already completed exceptionally with the given exception. A new ContextSnapshot is taken and applied to all following completion stages.- Type Parameters:
U- the type of the value- Parameters:
ex- the exception- Returns:
- New
CompletionStagethrowing the exception and containing a newContextSnapshot. - Since:
- 1.0.5
- See Also:
failedFuture(Throwable, ContextSnapshot)
-
allOf
public static ContextAwareCompletableFuture<Void> allOf(CompletableFuture<?>... cfs)
Returns a new CompletableFuture that is completed when all of the given CompletableFutures complete. If any of the given CompletableFutures complete exceptionally, then the returned CompletableFuture also does so, with a CompletionException holding this exception as its cause. Otherwise, the results, if any, of the given CompletableFutures are not reflected in the returned CompletableFuture, but may be obtained by inspecting them individually. If no CompletableFutures are provided, returns a CompletableFuture completed with the valuenull.Among the applications of this method is to await completion of a set of independent CompletableFutures before continuing a program, as in:
CompletableFuture.allOf(c1, c2, c3).join();.A new ContextSnapshot is taken and applied to all following completion stages.
- Parameters:
cfs- the CompletableFutures- Returns:
- A new
ContextAwareCompletableFuturethat is completed when all of the given CompletableFutures complete - Throws:
NullPointerException- if the array or any of its elements arenull- Since:
- 1.0.5
-
allOf
public static ContextAwareCompletableFuture<Void> allOf(ContextSnapshot snapshot, CompletableFuture<?>... cfs)
Returns a new CompletableFuture that is completed when all of the given CompletableFutures complete. If any of the given CompletableFutures complete exceptionally, then the returned CompletableFuture also does so, with a CompletionException holding this exception as its cause. Otherwise, the results, if any, of the given CompletableFutures are not reflected in the returned CompletableFuture, but may be obtained by inspecting them individually. If no CompletableFutures are provided, returns a CompletableFuture completed with the valuenull.Among the applications of this method is to await completion of a set of independent CompletableFutures before continuing a program, as in:
CompletableFuture.allOf(c1, c2, c3).join();.The specified ContextSnapshot is applied to all following completion stages.
- Parameters:
snapshot- the context snapshot to apply to following completion stages (optional, specifynullto take a new snapshot)cfs- the CompletableFutures- Returns:
- A new
ContextAwareCompletableFuturethat is completed when all of the given CompletableFutures complete - Throws:
NullPointerException- if the array or any of its elements arenull- Since:
- 1.0.5
-
anyOf
public static ContextAwareCompletableFuture<Object> anyOf(CompletableFuture<?>... cfs)
Returns a new CompletableFuture that is completed when any of the given CompletableFutures complete, with the same result. Otherwise, if it completed exceptionally, the returned CompletableFuture also does so, with a CompletionException holding this exception as its cause. If no CompletableFutures are provided, returns an incomplete CompletableFuture.A new ContextSnapshot is taken and applied to all following completion stages.
- Parameters:
cfs- the CompletableFutures- Returns:
- a new CompletableFuture that is completed with the result or exception of any of the given CompletableFutures when one completes
- Throws:
NullPointerException- if the array or any of its elements arenull- Since:
- 1.0.5
-
anyOf
public static ContextAwareCompletableFuture<Object> anyOf(ContextSnapshot snapshot, CompletableFuture<?>... cfs)
Returns a new CompletableFuture that is completed when any of the given CompletableFutures complete, with the same result. Otherwise, if it completed exceptionally, the returned CompletableFuture also does so, with a CompletionException holding this exception as its cause. If no CompletableFutures are provided, returns an incomplete CompletableFuture.The specified ContextSnapshot is applied to all following completion stages.
- Parameters:
snapshot- the context snapshot to apply to following completion stages (optional, specifynullto take a new snapshot)cfs- the CompletableFutures- Returns:
- a new CompletableFuture that is completed with the result or exception of any of the given CompletableFutures when one completes
- Throws:
NullPointerException- if the array or any of its elements arenull- Since:
- 1.0.5
-
takeNewSnapshot
public ContextAwareCompletableFuture<T> takeNewSnapshot()
Returns a context-aware CompletableFuture that takes a new snapshot after each completion stage.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.- Returns:
- A new context-aware completable future where context changes also propagate accross completion stages.
- See Also:
CompletionStage
-
takeNewSnapshot
public ContextAwareCompletableFuture<T> takeNewSnapshot(boolean takeSnapshot)
Returns a context-aware CompletableFuture that may take a new snapshot after each completion stage.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
truewhen chaining completable futures where the completion stages may update contextual values.
Warning: This may result in unnecessary context snapshots being taken.- Parameters:
takeSnapshot- whether or not new context snapshots must be taken after each completion stage.- Returns:
- A context-aware completable future where context changes also propagate accross completion stages
if
takeSnapshotistrue. - See Also:
CompletionStage
-
thenApply
public <U> ContextAwareCompletableFuture<U> thenApply(Function<? super T,? extends U> fn)
- Specified by:
thenApplyin interfaceCompletionStage<T>- Overrides:
thenApplyin classCompletableFuture<T>
-
thenApplyAsync
public <U> ContextAwareCompletableFuture<U> thenApplyAsync(Function<? super T,? extends U> fn)
- Specified by:
thenApplyAsyncin interfaceCompletionStage<T>- Overrides:
thenApplyAsyncin classCompletableFuture<T>
-
thenApplyAsync
public <U> ContextAwareCompletableFuture<U> thenApplyAsync(Function<? super T,? extends U> fn, Executor executor)
- Specified by:
thenApplyAsyncin interfaceCompletionStage<T>- Overrides:
thenApplyAsyncin classCompletableFuture<T>
-
thenAccept
public ContextAwareCompletableFuture<Void> thenAccept(Consumer<? super T> action)
- Specified by:
thenAcceptin interfaceCompletionStage<T>- Overrides:
thenAcceptin classCompletableFuture<T>
-
thenAcceptAsync
public ContextAwareCompletableFuture<Void> thenAcceptAsync(Consumer<? super T> action)
- Specified by:
thenAcceptAsyncin interfaceCompletionStage<T>- Overrides:
thenAcceptAsyncin classCompletableFuture<T>
-
thenAcceptAsync
public ContextAwareCompletableFuture<Void> thenAcceptAsync(Consumer<? super T> action, Executor executor)
- Specified by:
thenAcceptAsyncin interfaceCompletionStage<T>- Overrides:
thenAcceptAsyncin classCompletableFuture<T>
-
thenRun
public ContextAwareCompletableFuture<Void> thenRun(Runnable action)
- Specified by:
thenRunin interfaceCompletionStage<T>- Overrides:
thenRunin classCompletableFuture<T>
-
thenRunAsync
public CompletableFuture<Void> thenRunAsync(Runnable action)
- Specified by:
thenRunAsyncin interfaceCompletionStage<T>- Overrides:
thenRunAsyncin classCompletableFuture<T>
-
thenRunAsync
public ContextAwareCompletableFuture<Void> thenRunAsync(Runnable action, Executor executor)
- Specified by:
thenRunAsyncin interfaceCompletionStage<T>- Overrides:
thenRunAsyncin classCompletableFuture<T>
-
thenCombine
public <U,V> ContextAwareCompletableFuture<V> thenCombine(CompletionStage<? extends U> other, BiFunction<? super T,? super U,? extends V> fn)
- Specified by:
thenCombinein interfaceCompletionStage<T>- Overrides:
thenCombinein classCompletableFuture<T>
-
thenCombineAsync
public <U,V> ContextAwareCompletableFuture<V> thenCombineAsync(CompletionStage<? extends U> other, BiFunction<? super T,? super U,? extends V> fn)
- Specified by:
thenCombineAsyncin interfaceCompletionStage<T>- Overrides:
thenCombineAsyncin classCompletableFuture<T>
-
thenCombineAsync
public <U,V> ContextAwareCompletableFuture<V> thenCombineAsync(CompletionStage<? extends U> other, BiFunction<? super T,? super U,? extends V> fn, Executor executor)
- Specified by:
thenCombineAsyncin interfaceCompletionStage<T>- Overrides:
thenCombineAsyncin classCompletableFuture<T>
-
thenAcceptBoth
public <U> ContextAwareCompletableFuture<Void> thenAcceptBoth(CompletionStage<? extends U> other, BiConsumer<? super T,? super U> action)
- Specified by:
thenAcceptBothin interfaceCompletionStage<T>- Overrides:
thenAcceptBothin classCompletableFuture<T>
-
thenAcceptBothAsync
public <U> ContextAwareCompletableFuture<Void> thenAcceptBothAsync(CompletionStage<? extends U> other, BiConsumer<? super T,? super U> action)
- Specified by:
thenAcceptBothAsyncin interfaceCompletionStage<T>- Overrides:
thenAcceptBothAsyncin classCompletableFuture<T>
-
thenAcceptBothAsync
public <U> ContextAwareCompletableFuture<Void> thenAcceptBothAsync(CompletionStage<? extends U> other, BiConsumer<? super T,? super U> action, Executor executor)
- Specified by:
thenAcceptBothAsyncin interfaceCompletionStage<T>- Overrides:
thenAcceptBothAsyncin classCompletableFuture<T>
-
runAfterBoth
public ContextAwareCompletableFuture<Void> runAfterBoth(CompletionStage<?> other, Runnable action)
- Specified by:
runAfterBothin interfaceCompletionStage<T>- Overrides:
runAfterBothin classCompletableFuture<T>
-
runAfterBothAsync
public ContextAwareCompletableFuture<Void> runAfterBothAsync(CompletionStage<?> other, Runnable action)
- Specified by:
runAfterBothAsyncin interfaceCompletionStage<T>- Overrides:
runAfterBothAsyncin classCompletableFuture<T>
-
runAfterBothAsync
public ContextAwareCompletableFuture<Void> runAfterBothAsync(CompletionStage<?> other, Runnable action, Executor executor)
- Specified by:
runAfterBothAsyncin interfaceCompletionStage<T>- Overrides:
runAfterBothAsyncin classCompletableFuture<T>
-
applyToEither
public <U> ContextAwareCompletableFuture<U> applyToEither(CompletionStage<? extends T> other, Function<? super T,U> fn)
- Specified by:
applyToEitherin interfaceCompletionStage<T>- Overrides:
applyToEitherin classCompletableFuture<T>
-
applyToEitherAsync
public <U> ContextAwareCompletableFuture<U> applyToEitherAsync(CompletionStage<? extends T> other, Function<? super T,U> fn)
- Specified by:
applyToEitherAsyncin interfaceCompletionStage<T>- Overrides:
applyToEitherAsyncin classCompletableFuture<T>
-
applyToEitherAsync
public <U> ContextAwareCompletableFuture<U> applyToEitherAsync(CompletionStage<? extends T> other, Function<? super T,U> fn, Executor executor)
- Specified by:
applyToEitherAsyncin interfaceCompletionStage<T>- Overrides:
applyToEitherAsyncin classCompletableFuture<T>
-
acceptEither
public ContextAwareCompletableFuture<Void> acceptEither(CompletionStage<? extends T> other, Consumer<? super T> action)
- Specified by:
acceptEitherin interfaceCompletionStage<T>- Overrides:
acceptEitherin classCompletableFuture<T>
-
acceptEitherAsync
public ContextAwareCompletableFuture<Void> acceptEitherAsync(CompletionStage<? extends T> other, Consumer<? super T> action)
- Specified by:
acceptEitherAsyncin interfaceCompletionStage<T>- Overrides:
acceptEitherAsyncin classCompletableFuture<T>
-
acceptEitherAsync
public ContextAwareCompletableFuture<Void> acceptEitherAsync(CompletionStage<? extends T> other, Consumer<? super T> action, Executor executor)
- Specified by:
acceptEitherAsyncin interfaceCompletionStage<T>- Overrides:
acceptEitherAsyncin classCompletableFuture<T>
-
runAfterEither
public ContextAwareCompletableFuture<Void> runAfterEither(CompletionStage<?> other, Runnable action)
- Specified by:
runAfterEitherin interfaceCompletionStage<T>- Overrides:
runAfterEitherin classCompletableFuture<T>
-
runAfterEitherAsync
public ContextAwareCompletableFuture<Void> runAfterEitherAsync(CompletionStage<?> other, Runnable action)
- Specified by:
runAfterEitherAsyncin interfaceCompletionStage<T>- Overrides:
runAfterEitherAsyncin classCompletableFuture<T>
-
runAfterEitherAsync
public ContextAwareCompletableFuture<Void> runAfterEitherAsync(CompletionStage<?> other, Runnable action, Executor executor)
- Specified by:
runAfterEitherAsyncin interfaceCompletionStage<T>- Overrides:
runAfterEitherAsyncin classCompletableFuture<T>
-
thenCompose
public <U> ContextAwareCompletableFuture<U> thenCompose(Function<? super T,? extends CompletionStage<U>> fn)
- Specified by:
thenComposein interfaceCompletionStage<T>- Overrides:
thenComposein classCompletableFuture<T>
-
thenComposeAsync
public <U> ContextAwareCompletableFuture<U> thenComposeAsync(Function<? super T,? extends CompletionStage<U>> fn)
- Specified by:
thenComposeAsyncin interfaceCompletionStage<T>- Overrides:
thenComposeAsyncin classCompletableFuture<T>
-
thenComposeAsync
public <U> ContextAwareCompletableFuture<U> thenComposeAsync(Function<? super T,? extends CompletionStage<U>> fn, Executor executor)
- Specified by:
thenComposeAsyncin interfaceCompletionStage<T>- Overrides:
thenComposeAsyncin classCompletableFuture<T>
-
whenComplete
public ContextAwareCompletableFuture<T> whenComplete(BiConsumer<? super T,? super Throwable> action)
- Specified by:
whenCompletein interfaceCompletionStage<T>- Overrides:
whenCompletein classCompletableFuture<T>
-
whenCompleteAsync
public ContextAwareCompletableFuture<T> whenCompleteAsync(BiConsumer<? super T,? super Throwable> action)
- Specified by:
whenCompleteAsyncin interfaceCompletionStage<T>- Overrides:
whenCompleteAsyncin classCompletableFuture<T>
-
whenCompleteAsync
public ContextAwareCompletableFuture<T> whenCompleteAsync(BiConsumer<? super T,? super Throwable> action, Executor executor)
- Specified by:
whenCompleteAsyncin interfaceCompletionStage<T>- Overrides:
whenCompleteAsyncin classCompletableFuture<T>
-
handle
public <U> ContextAwareCompletableFuture<U> handle(BiFunction<? super T,Throwable,? extends U> fn)
- Specified by:
handlein interfaceCompletionStage<T>- Overrides:
handlein classCompletableFuture<T>
-
handleAsync
public <U> ContextAwareCompletableFuture<U> handleAsync(BiFunction<? super T,Throwable,? extends U> fn)
- Specified by:
handleAsyncin interfaceCompletionStage<T>- Overrides:
handleAsyncin classCompletableFuture<T>
-
handleAsync
public <U> ContextAwareCompletableFuture<U> handleAsync(BiFunction<? super T,Throwable,? extends U> fn, Executor executor)
- Specified by:
handleAsyncin interfaceCompletionStage<T>- Overrides:
handleAsyncin classCompletableFuture<T>
-
exceptionally
public ContextAwareCompletableFuture<T> exceptionally(Function<Throwable,? extends T> fn)
- Specified by:
exceptionallyin interfaceCompletionStage<T>- Overrides:
exceptionallyin classCompletableFuture<T>
-
-