-
Notifications
You must be signed in to change notification settings - Fork 128
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use the thread-local ThreadContext in order to be able to define whic…
…h contexts get propagated Fixes #626
- Loading branch information
Showing
4 changed files
with
86 additions
and
9 deletions.
There are no files selected for viewing
8 changes: 1 addition & 7 deletions
8
...gation/src/main/java/io/smallrye/mutiny/context/DefaultContextPropagationInterceptor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,14 @@ | ||
package io.smallrye.mutiny.context; | ||
|
||
import org.eclipse.microprofile.context.spi.ContextManagerProvider; | ||
|
||
import io.smallrye.context.SmallRyeThreadContext; | ||
|
||
/** | ||
* Provides context propagation by intercepting the user callbacks. | ||
*/ | ||
public class DefaultContextPropagationInterceptor extends BaseContextPropagationInterceptor { | ||
|
||
static final SmallRyeThreadContext THREAD_CONTEXT = (SmallRyeThreadContext) ContextManagerProvider.instance() | ||
.getContextManager() | ||
.newThreadContextBuilder().build(); | ||
|
||
@Override | ||
protected SmallRyeThreadContext getThreadContext() { | ||
return THREAD_CONTEXT; | ||
return SmallRyeThreadContext.getCurrentThreadContextOrPropagatedContexts(); | ||
} | ||
} |
13 changes: 11 additions & 2 deletions
13
...t-propagation/src/main/java/io/smallrye/mutiny/context/MutinyContextManagerExtension.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,26 @@ | ||
package io.smallrye.mutiny.context; | ||
|
||
import java.util.concurrent.CompletableFuture; | ||
import java.util.function.UnaryOperator; | ||
|
||
import org.eclipse.microprofile.context.ThreadContext; | ||
import org.eclipse.microprofile.context.spi.ContextManager; | ||
import org.eclipse.microprofile.context.spi.ContextManagerExtension; | ||
|
||
import io.smallrye.context.SmallRyeThreadContext; | ||
import io.smallrye.mutiny.infrastructure.Infrastructure; | ||
|
||
public class MutinyContextManagerExtension implements ContextManagerExtension { | ||
|
||
@Override | ||
public void setup(ContextManager manager) { | ||
ThreadContext threadContext = manager.newThreadContextBuilder().build(); | ||
Infrastructure.setCompletableFutureWrapper(threadContext::withContextCapture); | ||
Infrastructure.setCompletableFutureWrapper(new UnaryOperator<CompletableFuture<?>>() { | ||
@Override | ||
public CompletableFuture<?> apply(CompletableFuture<?> t) { | ||
ThreadContext threadContext = SmallRyeThreadContext.getCurrentThreadContextOrPropagatedContexts(); | ||
return threadContext.withContextCapture(t); | ||
} | ||
}); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters