Package org.apache.logging.log4j.spi
Class DefaultThreadContextMap
java.lang.Object
org.apache.logging.log4j.spi.DefaultThreadContextMap
- All Implemented Interfaces:
Serializable
,ThreadContextMap
,org.apache.logging.log4j.util.ReadOnlyStringMap
public class DefaultThreadContextMap
extends Object
implements ThreadContextMap, org.apache.logging.log4j.util.ReadOnlyStringMap
The actual ThreadContext Map. A new ThreadContext Map is created each time it is updated and the Map stored is always
immutable. This means the Map can be passed to other threads without concern that it will be updated. Since it is
expected that the Map will be passed to many more log events than the number of keys it contains the performance
should be much better than if the Map was copied for each event.
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final String
Property name ("isThreadContextMapInheritable" ) for selectingInheritableThreadLocal
(value "true") or plainThreadLocal
(value is not "true") in the implementation. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
clear()
Clears the context.boolean
containsKey
(String key) Determines if the key is in the context.boolean
<V> void
<V,
S> void Gets the context identified by thekey
parameter.getCopy()
Gets a non-null
mutable copy of current thread's context Map.Returns an immutable view on the context Map ornull
if the context map is empty.<V> V
int
hashCode()
boolean
isEmpty()
Returns true if the Map is empty.void
Puts a context value (theo
parameter) as identified with thekey
parameter into the current thread's context map.void
void
Removes the context identified by thekey
parameter.void
int
size()
toMap()
toString()
-
Field Details
-
INHERITABLE_MAP
Property name ("isThreadContextMapInheritable" ) for selectingInheritableThreadLocal
(value "true") or plainThreadLocal
(value is not "true") in the implementation.- See Also:
-
-
Constructor Details
-
DefaultThreadContextMap
public DefaultThreadContextMap() -
DefaultThreadContextMap
public DefaultThreadContextMap(boolean useMap)
-
-
Method Details
-
put
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
-
get
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
Description copied from interface:ThreadContextMap
Removes the context identified by thekey
parameter.- Specified by:
remove
in interfaceThreadContextMap
- Parameters:
key
- The key to remove.
-
removeAll
-
clear
public void clear()Description copied from interface:ThreadContextMap
Clears the context.- Specified by:
clear
in interfaceThreadContextMap
-
toMap
- Specified by:
toMap
in interfaceorg.apache.logging.log4j.util.ReadOnlyStringMap
-
containsKey
Description copied from interface:ThreadContextMap
Determines if the key is in the context.- Specified by:
containsKey
in interfaceorg.apache.logging.log4j.util.ReadOnlyStringMap
- Specified by:
containsKey
in interfaceThreadContextMap
- Parameters:
key
- The key to locate.- Returns:
- True if the key is in the context, false otherwise.
-
forEach
- Specified by:
forEach
in interfaceorg.apache.logging.log4j.util.ReadOnlyStringMap
-
forEach
public <V,S> void forEach(org.apache.logging.log4j.util.TriConsumer<String, ? super V, S> action, S state) - Specified by:
forEach
in interfaceorg.apache.logging.log4j.util.ReadOnlyStringMap
-
getValue
- Specified by:
getValue
in interfaceorg.apache.logging.log4j.util.ReadOnlyStringMap
-
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
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 interfaceorg.apache.logging.log4j.util.ReadOnlyStringMap
- Specified by:
isEmpty
in interfaceThreadContextMap
- Returns:
- true if the Map is empty, false otherwise.
-
size
public int size()- Specified by:
size
in interfaceorg.apache.logging.log4j.util.ReadOnlyStringMap
-
toString
-
hashCode
public int hashCode() -
equals
-