Class NameableCompletableFuture<T>
- java.lang.Object
-
- com.lightbend.cinnamon.java.future.NameableCompletionStage<T>
-
- com.lightbend.cinnamon.java.future.NameableCompletableFuture<T>
-
- All Implemented Interfaces:
java.util.concurrent.CompletionStage<T>
public class NameableCompletableFuture<T> extends NameableCompletionStage<T>
Naming API for CompletableFuture (Java 11).Note: NameableCompletableFuture wrapper is NOT a CompletableFuture, but extends NameableCompletionStage for fluent naming API. Use
getUnderlying
ortoCompletableFuture
to get a CompletableFuture again.
-
-
Constructor Summary
Constructors Constructor Description NameableCompletableFuture(java.util.concurrent.CompletableFuture<T> underlying)
Create a new CompletableFuture with nameable methods.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static <U> java.util.concurrent.CompletableFuture<U>
completedFutureNamed(java.lang.String name, U value)
Named version ofCompletableFuture.completedFuture(value)
.static <U> java.util.concurrent.CompletionStage<U>
completedStageNamed(java.lang.String name, U value)
Named version ofCompletableFuture.completedStage(value)
.NameableCompletableFuture<T>
copy()
Original version ofCompletableFuture.copy
, but returns a NameableCompletableFuture where subsequent method calls can use named variations.NameableCompletableFuture<T>
copyNamed(java.lang.String name)
Named version ofCompletableFuture.copy
.static java.lang.String
currentName()
Get the current CompletableFuture / completion name.static <T> java.util.concurrent.CompletableFuture<T>
disableContext(java.util.concurrent.CompletableFuture<T> future)
Disable any Cinnamon attached context on the givenCompletableFuture
.static <U> java.util.concurrent.CompletableFuture<U>
failedFutureNamed(java.lang.String name, java.lang.Throwable ex)
Named version ofCompletableFuture.failedFuture(ex)
.static <U> java.util.concurrent.CompletionStage<U>
failedStageNamed(java.lang.String name, java.lang.Throwable ex)
Named version ofCompletableFuture.failedStage(ex)
.java.util.concurrent.CompletableFuture<T>
getUnderlying()
Return the underlying CompletableFuture wrapped by this NameableCompletableFuture.NameableCompletionStage<T>
minimalCompletionStage()
Original version ofCompletableFuture.minimalCompletionStage
, but returns a NameableCompletionStage where subsequent method calls can use named variations.NameableCompletionStage<T>
minimalCompletionStageNamed(java.lang.String name)
Named version ofCompletableFuture.minimalCompletionStage
.static <U> NameableCompletableFuture<U>
nameable(java.util.concurrent.CompletableFuture<U> future)
Create a NameableCompletableFuture wrapper with nameable methods.<U> NameableCompletableFuture<U>
newIncompleteFuture()
Original version ofCompletableFuture.newIncompleteFuture
, but returns a NameableCompletableFuture where subsequent method calls can use named variations.<U> NameableCompletableFuture<U>
newIncompleteFutureNamed(java.lang.String name)
Named version ofCompletableFuture.newIncompleteFuture
.static <U> java.util.concurrent.CompletableFuture<U>
newNamed(java.lang.String name)
Named version ofnew CompletableFuture<T>
.static java.util.concurrent.CompletableFuture<java.lang.Void>
runAsyncNamed(java.lang.String name, java.lang.Runnable runnable)
Named version ofCompletableFuture.runAsync(runnable)
.static java.util.concurrent.CompletableFuture<java.lang.Void>
runAsyncNamed(java.lang.String name, java.lang.Runnable runnable, java.util.concurrent.Executor executor)
Named version ofCompletableFuture.runAsync(runnable, executor)
.static <U> java.util.concurrent.CompletableFuture<U>
supplyAsyncNamed(java.lang.String name, java.util.function.Supplier<U> supplier)
Named version ofCompletableFuture.supplyAsync(supplier)
.static <U> java.util.concurrent.CompletableFuture<U>
supplyAsyncNamed(java.lang.String name, java.util.function.Supplier<U> supplier, java.util.concurrent.Executor executor)
Named version ofCompletableFuture.supplyAsync(supplier, executor)
.static <F> F
withName(java.lang.String name, java.util.function.Supplier<F> f)
Add a name around CompletableFuture creation or completion callbacks.-
Methods inherited from class com.lightbend.cinnamon.java.future.NameableCompletionStage
acceptEither, acceptEitherAsync, acceptEitherAsync, acceptEitherAsyncNamed, acceptEitherAsyncNamed, acceptEitherNamed, applyToEither, applyToEitherAsync, applyToEitherAsync, applyToEitherAsyncNamed, applyToEitherAsyncNamed, applyToEitherNamed, disableContext, exceptionally, exceptionallyNamed, handle, handleAsync, handleAsync, handleAsyncNamed, handleAsyncNamed, handleNamed, nameable, runAfterBoth, runAfterBothAsync, runAfterBothAsync, runAfterBothAsyncNamed, runAfterBothAsyncNamed, runAfterBothNamed, runAfterEither, runAfterEitherAsync, runAfterEitherAsync, runAfterEitherAsyncNamed, runAfterEitherAsyncNamed, runAfterEitherNamed, thenAccept, thenAcceptAsync, thenAcceptAsync, thenAcceptAsyncNamed, thenAcceptAsyncNamed, thenAcceptBoth, thenAcceptBothAsync, thenAcceptBothAsync, thenAcceptBothAsyncNamed, thenAcceptBothAsyncNamed, thenAcceptBothNamed, thenAcceptNamed, thenApply, thenApplyAsync, thenApplyAsync, thenApplyAsyncNamed, thenApplyAsyncNamed, thenApplyNamed, thenCombine, thenCombineAsync, thenCombineAsync, thenCombineAsyncNamed, thenCombineAsyncNamed, thenCombineNamed, thenCompose, thenComposeAsync, thenComposeAsync, thenComposeAsyncNamed, thenComposeAsyncNamed, thenComposeNamed, thenRun, thenRunAsync, thenRunAsync, thenRunAsyncNamed, thenRunAsyncNamed, thenRunNamed, toCompletableFuture, toCompletableFutureNamed, whenComplete, whenCompleteAsync, whenCompleteAsync, whenCompleteAsyncNamed, whenCompleteAsyncNamed, whenCompleteNamed
-
-
-
-
Constructor Detail
-
NameableCompletableFuture
public NameableCompletableFuture(java.util.concurrent.CompletableFuture<T> underlying)
Create a new CompletableFuture with nameable methods.- Parameters:
underlying
- the CompletableFuture to wrap with nameable methods
-
-
Method Detail
-
currentName
public static java.lang.String currentName()
Get the current CompletableFuture / completion name.- Returns:
- the current name (thread locally)
-
withName
public static <F> F withName(java.lang.String name, java.util.function.Supplier<F> f)
Add a name around CompletableFuture creation or completion callbacks.- Type Parameters:
F
- the return type of the supplied block- Parameters:
name
- the name for the CompletableFuture and/or completion callbackf
- the supplied block to name (with newly created CompletableFutures)- Returns:
- the result of the supplied block
-
newNamed
public static <U> java.util.concurrent.CompletableFuture<U> newNamed(java.lang.String name)
Named version ofnew CompletableFuture<T>
.- Type Parameters:
U
- the CompletableFuture's type- Parameters:
name
- the name for the CompletableFuture- Returns:
- the named CompletableFuture
-
supplyAsyncNamed
public static <U> java.util.concurrent.CompletableFuture<U> supplyAsyncNamed(java.lang.String name, java.util.function.Supplier<U> supplier)
Named version ofCompletableFuture.supplyAsync(supplier)
.- Type Parameters:
U
- the function's return type- Parameters:
name
- the name for the CompletableFuturesupplier
- the supplier forCompletableFuture.supplyAsync
- Returns:
- the named CompletableFuture
-
supplyAsyncNamed
public static <U> java.util.concurrent.CompletableFuture<U> supplyAsyncNamed(java.lang.String name, java.util.function.Supplier<U> supplier, java.util.concurrent.Executor executor)
Named version ofCompletableFuture.supplyAsync(supplier, executor)
.- Type Parameters:
U
- the function's return type- Parameters:
name
- the name for the CompletableFuturesupplier
- the supplier forCompletableFuture.supplyAsync
executor
- the executor to use for asynchronous execution- Returns:
- the named CompletableFuture
-
runAsyncNamed
public static java.util.concurrent.CompletableFuture<java.lang.Void> runAsyncNamed(java.lang.String name, java.lang.Runnable runnable)
Named version ofCompletableFuture.runAsync(runnable)
.- Parameters:
name
- the name for the CompletableFuturerunnable
- the runnable forCompletableFuture.runAsync
- Returns:
- the named CompletableFuture
-
runAsyncNamed
public static java.util.concurrent.CompletableFuture<java.lang.Void> runAsyncNamed(java.lang.String name, java.lang.Runnable runnable, java.util.concurrent.Executor executor)
Named version ofCompletableFuture.runAsync(runnable, executor)
.- Parameters:
name
- the name for the CompletableFuturerunnable
- the runnable forCompletableFuture.runAsync
executor
- the executor to use for asynchronous execution- Returns:
- the named CompletableFuture
-
completedFutureNamed
public static <U> java.util.concurrent.CompletableFuture<U> completedFutureNamed(java.lang.String name, U value)
Named version ofCompletableFuture.completedFuture(value)
.- Type Parameters:
U
- the type of the value- Parameters:
name
- the name for the CompletableFuturevalue
- the value forCompletableFuture.completedFuture
- Returns:
- the named and completed CompletableFuture
-
getUnderlying
public java.util.concurrent.CompletableFuture<T> getUnderlying()
Return the underlying CompletableFuture wrapped by this NameableCompletableFuture.- Overrides:
getUnderlying
in classNameableCompletionStage<T>
- Returns:
- the underlying CompletableFuture
-
nameable
public static <U> NameableCompletableFuture<U> nameable(java.util.concurrent.CompletableFuture<U> future)
Create a NameableCompletableFuture wrapper with nameable methods.- Type Parameters:
U
- the underlying CompletableFuture's type- Parameters:
future
- the CompletableFuture to extend with named variations- Returns:
- a NameableCompletableFuture with nameable completion methods
-
newIncompleteFuture
public <U> NameableCompletableFuture<U> newIncompleteFuture()
Original version ofCompletableFuture.newIncompleteFuture
, but returns a NameableCompletableFuture where subsequent method calls can use named variations.- Type Parameters:
U
- the type of the value- Returns:
- the new (unnamed) incomplete CompletableFuture
-
newIncompleteFutureNamed
public <U> NameableCompletableFuture<U> newIncompleteFutureNamed(java.lang.String name)
Named version ofCompletableFuture.newIncompleteFuture
.- Type Parameters:
U
- the type of the value- Returns:
- the new (named) incomplete CompletableFuture
-
copy
public NameableCompletableFuture<T> copy()
Original version ofCompletableFuture.copy
, but returns a NameableCompletableFuture where subsequent method calls can use named variations.- Returns:
- the new (unnamed) copied CompletableFuture
-
copyNamed
public NameableCompletableFuture<T> copyNamed(java.lang.String name)
Named version ofCompletableFuture.copy
.- Returns:
- the new (named) copied CompletableFuture
-
minimalCompletionStage
public NameableCompletionStage<T> minimalCompletionStage()
Original version ofCompletableFuture.minimalCompletionStage
, but returns a NameableCompletionStage where subsequent method calls can use named variations.- Returns:
- the new (unnamed) copied CompletableFuture
-
minimalCompletionStageNamed
public NameableCompletionStage<T> minimalCompletionStageNamed(java.lang.String name)
Named version ofCompletableFuture.minimalCompletionStage
.- Returns:
- the new (named) copied CompletableFuture
-
completedStageNamed
public static <U> java.util.concurrent.CompletionStage<U> completedStageNamed(java.lang.String name, U value)
Named version ofCompletableFuture.completedStage(value)
.- Type Parameters:
U
- the type of the value- Parameters:
name
- the name for the CompletionStagevalue
- the value forCompletableFuture.completedStage
- Returns:
- the named and completed CompletionStage
-
failedFutureNamed
public static <U> java.util.concurrent.CompletableFuture<U> failedFutureNamed(java.lang.String name, java.lang.Throwable ex)
Named version ofCompletableFuture.failedFuture(ex)
.- Type Parameters:
U
- the type of the value- Parameters:
name
- the name for the CompletableFutureex
- the exception forCompletableFuture.failedFuture
- Returns:
- the named and exceptionally completed CompletableFuture
-
failedStageNamed
public static <U> java.util.concurrent.CompletionStage<U> failedStageNamed(java.lang.String name, java.lang.Throwable ex)
Named version ofCompletableFuture.failedStage(ex)
.- Type Parameters:
U
- the type of the value- Parameters:
name
- the name for the CompletionStageex
- the exception forCompletableFuture.failedStage
- Returns:
- the named and exceptionally completed CompletionStage
-
disableContext
public static <T> java.util.concurrent.CompletableFuture<T> disableContext(java.util.concurrent.CompletableFuture<T> future)
Disable any Cinnamon attached context on the givenCompletableFuture
.Can be used if the CompletableFuture will be cached.
- Type Parameters:
T
- the type of the value- Parameters:
future
- the CompletableFuture to disable contexts for- Returns:
- the original CompletableFuture with context disabled
-
-