Context.
If you want to implement your own storage or add some hooks when a Context is attached
and restored, you should use ContextStorageProvider. Here's an example that sets MDC
before Context is attached:
> public class MyStorage implements ContextStorageProvider {
>
> @Override
> public ContextStorage get() {
> ContextStorage threadLocalStorage = ContextStorage.defaultStorage();
> return new RequestContextStorage() {
> @Override
> public Scope T attach(Context toAttach) {
> Context current = current();
> setMdc(toAttach);
> Scope scope = threadLocalStorage.attach(toAttach);
> return () -> {
> clearMdc();
> setMdc(current);
> scope.close();
> }
> }
>
> @Override
> public Context current() {
> return threadLocalStorage.current();
> }
> }
> }
> }
| Modifier and Type | Method and Description |
|---|---|
| public static void | addWrapper(Function<? super ContextStorage, ? extends ContextStorage> wrapper)
Adds the |
| public Scope | |
| public Context | |
| public static ContextStorage | |
| public static ContextStorage | |
| public default Context |
| addWrapper | back to summary |
|---|---|
| public static void addWrapper(Function<? super ContextStorage, ? extends ContextStorage> wrapper) Adds the | |
| attach | back to summary |
|---|---|
| public Scope attach(Context toAttach) Sets the specified | |
| current | back to summary |
|---|---|
| public Context current() Returns the current
| |
| defaultStorage | back to summary |
|---|---|
| public static ContextStorage defaultStorage() Returns the default | |
| get | back to summary |
|---|---|
| public static ContextStorage get() Returns the | |
| root | back to summary |
|---|---|
| public default Context root() Returns the root The default implementation returns the root | |