Package org.apache.logging.log4j.spi
Interface ThreadContextMap
-
- All Known Subinterfaces:
CleanableThreadContextMap
,ObjectThreadContextMap
,ThreadContextMap2
- All Known Implementing Classes:
DefaultThreadContextMap
,NoOpThreadContextMap
public interface ThreadContextMap
Service provider interface to implement custom MDC behavior forThreadContext
.Since 2.8,
ThreadContextMap
implementations that implement theReadOnlyThreadContextMap
interface are accessible to applications via theThreadContext.getThreadContextMap()
method.
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description void
clear()
Clears the context.boolean
containsKey(java.lang.String key)
Determines if the key is in the context.java.lang.String
get(java.lang.String key)
Gets the context identified by thekey
parameter.java.util.Map<java.lang.String,java.lang.String>
getCopy()
Gets a non-null
mutable 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 ornull
if the context map is empty.boolean
isEmpty()
Returns true if the Map is empty.void
put(java.lang.String key, java.lang.String value)
Puts a context value (theo
parameter) as identified with thekey
parameter into the current thread's context map.void
remove(java.lang.String key)
Removes the context identified by thekey
parameter.
-
-
-
Method Detail
-
clear
void clear()
Clears the context.
-
containsKey
boolean containsKey(java.lang.String key)
Determines if the key is in the context.- Parameters:
key
- The key to locate.- Returns:
- True if the key is in the context, false otherwise.
-
get
java.lang.String get(java.lang.String key)
Gets the context identified by thekey
parameter.This method has no side effects.
- Parameters:
key
- The key to locate.- Returns:
- The value associated with the key or null.
-
getCopy
java.util.Map<java.lang.String,java.lang.String> getCopy()
Gets a non-null
mutable copy of current thread's context Map.- Returns:
- a mutable copy of the context.
-
getImmutableMapOrNull
java.util.Map<java.lang.String,java.lang.String> getImmutableMapOrNull()
Returns an immutable view on the context Map ornull
if the context map is empty.- Returns:
- an immutable context Map or
null
.
-
isEmpty
boolean isEmpty()
Returns true if the Map is empty.- Returns:
- true if the Map is empty, false otherwise.
-
put
void put(java.lang.String key, java.lang.String value)
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.
- Parameters:
key
- The key name.value
- The key value.
-
remove
void remove(java.lang.String key)
Removes the context identified by thekey
parameter.- Parameters:
key
- The key to remove.
-
-