MicroProfile® Context Propagation 1.2 Release Review

Type
Release
State
Successful
End Date of the Review Period

Reviews run for a minimum of one week. The outcome of the review is decided on this date. This is the last day to make comments or ask questions about this review.

Project
Release

Context Propagation 1.2

Description

MicroProfile Context Propagation 1.2 provides APIs for obtaining CompletableFutures that are backed by managed threads (threads that are managed by the container), with the ability to capture context from the thread that creates the CompletableFuture and apply it when running the CompletionStage action.  This enables CompletionStage actions to rely on having predictable thread context and enables users of these CompletionStages to guard against unintentional donation of thread context.

Example of ManagedExecutor, which contextualizes all dependent stages:

ManagedExecutor executor = ManagedExecutor.builder()
.propagated(ThreadContext.CDI, ThreadContext.APPLICATION)
.build();
...
CompletableFuture<Integer> stage = executor
.supplyAsync(supplier1)
.thenApplyAsync(function1)
.thenApply(function2);

Example of ThreadContext for granular contextualization of a single stage:

ThreadContext threadContext = ThreadContext.builder()
.propagated(ThreadContext.APPLICATION)
.cleared(ThreadContext.SECURITY, ThreadContext.TRANSACTION)
.unchanged(ThreadContext.ALL_REMAINING)
.build();
...
Function<Integer, Double> getItemCost = threadContext.contextualFunction(id -> {
// java:comp, java:module, java:app lookups require the application's context
DataSource ds = InitialContext.doLookup("java:app/env/jdbc/ds1");
...
});
unmanagedStage4 = unmanagedStage1.thenApply(getProductId)
.thenApply(getItemCost)
.thenApply(addToTotal);

Conforms To UI/UX Guidelines
Not verified