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 for
ThreadContext.
Since 2.8, ThreadContextMap implementations that implement the ReadOnlyThreadContextMap interface
are accessible to applications via the ThreadContext.getThreadContextMap() method.
-
Method Summary
Modifier and TypeMethodDescriptionvoidclear()Clears the context.booleancontainsKey(String key) Determines if the key is in the context.Gets the context identified by thekeyparameter.getCopy()Gets a non-nullmutable copy of current thread's context Map.Returns an immutable view on the context Map ornullif the context map is empty.booleanisEmpty()Returns true if the Map is empty.voidPuts a context value (theoparameter) as identified with thekeyparameter into the current thread's context map.voidRemoves the context identified by thekeyparameter.
-
Method Details
-
clear
void clear()Clears the context. -
containsKey
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
Gets the context identified by thekeyparameter.This method has no side effects.
- Parameters:
key- The key to locate.- Returns:
- The value associated with the key or null.
-
getCopy
Gets a non-nullmutable copy of current thread's context Map.- Returns:
- a mutable copy of the context.
-
getImmutableMapOrNull
Returns an immutable view on the context Map ornullif 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
Puts 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.
- Parameters:
key- The key name.value- The key value.
-
remove
Removes the context identified by thekeyparameter.- Parameters:
key- The key to remove.
-