Interface RequestContextStorage

All Superinterfaces:
Unwrappable
All Known Implementing Classes:
RequestContextStorageWrapper

@UnstableApi public interface RequestContextStorage extends Unwrappable
The storage for storing RequestContext.

If you want to implement your own storage or add some hooks when a RequestContext is pushed and popped, you should use RequestContextStorageProvider. Here's an example that sets MDC before RequestContext is pushed:


 > public class MyStorage implements RequestContextStorageProvider {
 >
 >     @Override
 >     public RequestContextStorage newStorage() {
 >         RequestContextStorage threadLocalStorage = RequestContextStorage.threadLocal();
 >         return new RequestContextStorage() {
 >
 >             @Nullable
 >             @Override
 >             public <T extends RequestContext> T push(RequestContext toPush) {
 >                 setMdc(toPush);
 >                 return threadLocalStorage.push(toPush);
 >             }
 >
 >             @Override
 >             public void pop(RequestContext current, @Nullable RequestContext toRestore) {
 >                 clearMdc();
 >                 if (toRestore != null) {
 >                     setMdc(toRestore);
 >                 }
 >                 threadLocalStorage.pop(current, toRestore);
 >             }
 >             ...
 >          }
 >     }
 > }