ContextManager<java.util.Map<java.lang.String,java.lang.String>>
public class MdcManager extends java.lang.Object implements ContextManager<java.util.Map<java.lang.String,java.lang.String>>
MDC
content from one thread to another.
As MDC
already manages its own threadlocal state,
getting the active context is 100% delegated to the MDC.
This means that closing the resulting context from getActiveContext()
will have no side-effects,
as it is not ours to manage.
Closing a context returned form initializeNewContext(Map)
will reset the MDC
to the values it had before the context was created.
This means that closing nested contexts out-of-order will probably result in an undesirable state.
It is therefore strongly advised to use Java's try-with-resources
mechanism to ensure proper
closing when nesting new MDC contexts.
Constructor | Description |
---|---|
MdcManager() |
Modifier and Type | Method | Description |
---|---|---|
Context<java.util.Map<java.lang.String,java.lang.String>> |
getActiveContext() |
Returns the active MDC values from the current thread.
|
Context<java.util.Map<java.lang.String,java.lang.String>> |
initializeNewContext(java.util.Map<java.lang.String,java.lang.String> mdcValues) |
Initializes a new MDC context populated by the specified values.
|
java.lang.String |
toString() |
public Context<java.util.Map<java.lang.String,java.lang.String>> initializeNewContext(java.util.Map<java.lang.String,java.lang.String> mdcValues)
The given values will become the active MDC values for the current thread.
Closing the resulting context will restore the MDC to the state it had just before this call.
Please be aware that this may overwrite changes made to the MDC from other code.
initializeNewContext
in interface ContextManager<java.util.Map<java.lang.String,java.lang.String>>
mdcValues
- The values to initialize a new context for
(which must be closed by the caller at the end of its lifecycle).public Context<java.util.Map<java.lang.String,java.lang.String>> getActiveContext()
Please note: Because these values are managed by MDC itself and not by us, closing the resulting context has no effect.
getActiveContext
in interface ContextManager<java.util.Map<java.lang.String,java.lang.String>>
public java.lang.String toString()
toString
in class java.lang.Object
Copyright © 2016–2018 Talsma ICT. All rights reserved.