-
- 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.Since 3.0.0,
ThreadContextMap
combines all its extension interfaces into default methods on this interface.
-
-
Method Summary
All Methods Instance Methods Abstract Methods Default 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.default StringMap
getReadOnlyContextData()
Returns the context data for reading.default <V> V
getValue(String key)
Returns the Object value for the specified key, ornull
if the specified key does not exist in this collection.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.default void
putAll(Map<String,String> map)
Puts all given context map entries into the current thread's context map.default <V> void
putAllValues(Map<String,V> values)
Puts all given key-value pairs into the collection.default <V> void
putValue(String key, V value)
Puts the specified key-value pair into the collection.void
remove(String key)
Removes the context identified by thekey
parameter.default void
removeAll(Iterable<String> keys)
Removes all given context map keys from the current thread's context map.
-
-
-
Method Detail
-
clear
void clear()
Clears the context.
-
containsKey
boolean containsKey(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
String get(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
Map<String,String> getCopy()
Gets a non-null
mutable copy of current thread's context Map.- Returns:
- a mutable copy of the context.
-
getImmutableMapOrNull
Map<String,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(String key, 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(String key)
Removes the context identified by thekey
parameter.- Parameters:
key
- The key to remove.
-
putAll
default void putAll(Map<String,String> map)
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.
- Parameters:
map
- The map.- Since:
- 3.0.0
-
getReadOnlyContextData
default StringMap getReadOnlyContextData()
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.- Returns:
- the
StringMap
- Since:
- 3.0.0
-
removeAll
default void removeAll(Iterable<String> keys)
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.
- Parameters:
keys
- The keys.- Since:
- 3.0.0
-
getValue
default <V> V getValue(String key)
Returns the Object value for the specified key, ornull
if the specified key does not exist in this collection.- Type Parameters:
V
- The type of the returned value.- Parameters:
key
- the key whose value to return- Returns:
- the value for the specified key or
null
- Since:
- 3.0.0
-
putValue
default <V> void putValue(String key, V value)
Puts the specified key-value pair into the collection.- Type Parameters:
V
- The type of the stored and returned value.- Parameters:
key
- the key to add or remove. Keys may benull
.value
- the value to add. Values may benull
.- Since:
- 3.0.0
-
-