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 java.lang.Object implements CleanableThreadContextMap
Bind the ThreadContextMap to the SLF4J MDC.
-
-
Field Summary
Fields Modifier and Type Field Description private static StringMapEMPTY_CONTEXT_DATA
-
Constructor Summary
Constructors Constructor Description MDCContextMap()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclear()Clears the context.booleancontainsKey(java.lang.String key)Determines if the key is in the context.java.lang.Stringget(java.lang.String key)Gets the context identified by thekeyparameter.java.util.Map<java.lang.String,java.lang.String>getCopy()Gets a non-nullmutable copy of current thread's context Map.java.util.Map<java.lang.String,java.lang.String>getImmutableMapOrNull()Returns an immutable view on the context Map ornullif the context map is empty.StringMapgetReadOnlyContextData()Returns the context data for reading.booleanisEmpty()Returns true if the Map is empty.voidput(java.lang.String key, java.lang.String value)Puts a context value (theoparameter) as identified with thekeyparameter into the current thread's context map.voidputAll(java.util.Map<java.lang.String,java.lang.String> m)Puts all given context map entries into the current thread's context map.voidremove(java.lang.String key)Removes the context identified by thekeyparameter.voidremoveAll(java.lang.Iterable<java.lang.String> keys)Removes all given context map keys from the current thread's context map.
-
-
-
Field Detail
-
EMPTY_CONTEXT_DATA
private static final StringMap EMPTY_CONTEXT_DATA
-
-
Method Detail
-
put
public void put(java.lang.String key, java.lang.String value)Description copied from interface:ThreadContextMapPuts a context value (theoparameter) as identified with thekeyparameter 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:
putin interfaceThreadContextMap- Parameters:
key- The key name.value- The key value.
-
putAll
public void putAll(java.util.Map<java.lang.String,java.lang.String> m)
Description copied from interface:ThreadContextMap2Puts 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:
putAllin interfaceThreadContextMap2- Parameters:
m- The map.
-
get
public java.lang.String get(java.lang.String key)
Description copied from interface:ThreadContextMapGets the context identified by thekeyparameter.This method has no side effects.
- Specified by:
getin interfaceThreadContextMap- Parameters:
key- The key to locate.- Returns:
- The value associated with the key or null.
-
remove
public void remove(java.lang.String key)
Description copied from interface:ThreadContextMapRemoves the context identified by thekeyparameter.- Specified by:
removein interfaceThreadContextMap- Parameters:
key- The key to remove.
-
removeAll
public void removeAll(java.lang.Iterable<java.lang.String> keys)
Description copied from interface:CleanableThreadContextMapRemoves 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:
removeAllin interfaceCleanableThreadContextMap- Parameters:
keys- The keys.
-
clear
public void clear()
Description copied from interface:ThreadContextMapClears the context.- Specified by:
clearin interfaceThreadContextMap
-
containsKey
public boolean containsKey(java.lang.String key)
Description copied from interface:ThreadContextMapDetermines if the key is in the context.- Specified by:
containsKeyin interfaceThreadContextMap- Parameters:
key- The key to locate.- Returns:
- True if the key is in the context, false otherwise.
-
getCopy
public java.util.Map<java.lang.String,java.lang.String> getCopy()
Description copied from interface:ThreadContextMapGets a non-nullmutable copy of current thread's context Map.- Specified by:
getCopyin interfaceThreadContextMap- Returns:
- a mutable copy of the context.
-
getImmutableMapOrNull
public java.util.Map<java.lang.String,java.lang.String> getImmutableMapOrNull()
Description copied from interface:ThreadContextMapReturns an immutable view on the context Map ornullif the context map is empty.- Specified by:
getImmutableMapOrNullin interfaceThreadContextMap- Returns:
- an immutable context Map or
null.
-
isEmpty
public boolean isEmpty()
Description copied from interface:ThreadContextMapReturns true if the Map is empty.- Specified by:
isEmptyin interfaceThreadContextMap- Returns:
- true if the Map is empty, false otherwise.
-
getReadOnlyContextData
public StringMap getReadOnlyContextData()
Description copied from interface:ThreadContextMap2Returns 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:
getReadOnlyContextDatain interfaceThreadContextMap2- Returns:
- the
StringMap
-
-