Package org.apache.logging.slf4j
Class MDCContextMap
- java.lang.Object
-
- org.apache.logging.slf4j.MDCContextMap
-
- All Implemented Interfaces:
CleanableThreadContextMap
,ThreadContextMap
,ThreadContextMap2
public class MDCContextMap extends Object implements CleanableThreadContextMap
Bind the ThreadContextMap to the SLF4J MDC.
-
-
Constructor Summary
Constructors Constructor Description MDCContextMap()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
clear()
Clears the context.boolean
containsKey(String key)
Determines if the key is in the context.String
get(String key)
Gets the context identified by thekey
parameter.Map<String,String>
getCopy()
Gets a non-null
mutable copy of current thread's context Map.Map<String,String>
getImmutableMapOrNull()
Returns an immutable view on the context Map ornull
if the context map is empty.StringMap
getReadOnlyContextData()
Returns the context data for reading.boolean
isEmpty()
Returns true if the Map is empty.void
put(String key, String value)
Puts a context value (theo
parameter) as identified with thekey
parameter into the current thread's context map.void
putAll(Map<String,String> m)
Puts all given context map entries into the current thread's context map.void
remove(String key)
Removes the the context identified by thekey
parameter.void
removeAll(Iterable<String> keys)
Removes all given context map keys from the current thread's context map.
-
-
-
Method Detail
-
put
public void put(String key, String value)
Description copied from interface:ThreadContextMap
Puts a context value (theo
parameter) as identified with thekey
parameter into the current thread's context map.If the current thread does not have a context map it is created as a side effect.
- Specified by:
put
in interfaceThreadContextMap
- Parameters:
key
- The key name.value
- The key value.
-
putAll
public void putAll(Map<String,String> m)
Description copied from interface:ThreadContextMap2
Puts all given context map entries into the current thread's context map.If the current thread does not have a context map it is created as a side effect.
- Specified by:
putAll
in interfaceThreadContextMap2
- Parameters:
m
- The map.
-
get
public String get(String key)
Description copied from interface:ThreadContextMap
Gets the context identified by thekey
parameter.This method has no side effects.
- Specified by:
get
in interfaceThreadContextMap
- Parameters:
key
- The key to locate.- Returns:
- The value associated with the key or null.
-
remove
public void remove(String key)
Description copied from interface:ThreadContextMap
Removes the the context identified by thekey
parameter.- Specified by:
remove
in interfaceThreadContextMap
- Parameters:
key
- The key to remove.
-
removeAll
public void removeAll(Iterable<String> keys)
Description copied from interface:CleanableThreadContextMap
Removes all given context map keys from the current thread's context map.If the current thread does not have a context map it is created as a side effect.
- Specified by:
removeAll
in interfaceCleanableThreadContextMap
- Parameters:
keys
- The keys.
-
clear
public void clear()
Description copied from interface:ThreadContextMap
Clears the context.- Specified by:
clear
in interfaceThreadContextMap
-
containsKey
public boolean containsKey(String key)
Description copied from interface:ThreadContextMap
Determines if the key is in the context.- Specified by:
containsKey
in interfaceThreadContextMap
- Parameters:
key
- The key to locate.- Returns:
- True if the key is in the context, false otherwise.
-
getCopy
public Map<String,String> getCopy()
Description copied from interface:ThreadContextMap
Gets a non-null
mutable copy of current thread's context Map.- Specified by:
getCopy
in interfaceThreadContextMap
- Returns:
- a mutable copy of the context.
-
getImmutableMapOrNull
public Map<String,String> getImmutableMapOrNull()
Description copied from interface:ThreadContextMap
Returns an immutable view on the context Map ornull
if the context map is empty.- Specified by:
getImmutableMapOrNull
in interfaceThreadContextMap
- Returns:
- an immutable context Map or
null
.
-
isEmpty
public boolean isEmpty()
Description copied from interface:ThreadContextMap
Returns true if the Map is empty.- Specified by:
isEmpty
in interfaceThreadContextMap
- Returns:
- true if the Map is empty, false otherwise.
-
getReadOnlyContextData
public StringMap getReadOnlyContextData()
Description copied from interface:ThreadContextMap2
Returns the context data for reading. Note that regardless of whether the returned context data has been frozen (made read-only) or not, callers should not attempt to modify the returned data structure.- Specified by:
getReadOnlyContextData
in interfaceThreadContextMap2
- Returns:
- the
StringMap
-
-