Package org.apache.logging.log4j.spi
Class DefaultThreadContextMap
- java.lang.Object
-
- org.apache.logging.log4j.spi.DefaultThreadContextMap
-
- All Implemented Interfaces:
java.io.Serializable,ThreadContextMap,org.apache.logging.log4j.util.ReadOnlyStringMap
public class DefaultThreadContextMap extends java.lang.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:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.StringINHERITABLE_MAPProperty name ("isThreadContextMapInheritable" ) for selectingInheritableThreadLocal(value "true") or plainThreadLocal(value is not "true") in the implementation.
-
Constructor Summary
Constructors Constructor Description DefaultThreadContextMap()DefaultThreadContextMap(boolean useMap)
-
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.booleanequals(java.lang.Object obj)<V> voidforEach(org.apache.logging.log4j.util.BiConsumer<java.lang.String,? super V> action)<V,S>
voidforEach(org.apache.logging.log4j.util.TriConsumer<java.lang.String,? super V,S> action, S state)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.<V> VgetValue(java.lang.String key)inthashCode()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)voidremove(java.lang.String key)Removes the context identified by thekeyparameter.voidremoveAll(java.lang.Iterable<java.lang.String> keys)intsize()java.util.Map<java.lang.String,java.lang.String>toMap()java.lang.StringtoString()
-
-
-
Field Detail
-
INHERITABLE_MAP
public static final java.lang.String INHERITABLE_MAP
Property name ("isThreadContextMapInheritable" ) for selectingInheritableThreadLocal(value "true") or plainThreadLocal(value is not "true") in the implementation.- See Also:
- Constant Field Values
-
-
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)
-
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)
-
clear
public void clear()
Description copied from interface:ThreadContextMapClears the context.- Specified by:
clearin interfaceThreadContextMap
-
toMap
public java.util.Map<java.lang.String,java.lang.String> toMap()
- Specified by:
toMapin interfaceorg.apache.logging.log4j.util.ReadOnlyStringMap
-
containsKey
public boolean containsKey(java.lang.String key)
Description copied from interface:ThreadContextMapDetermines if the key is in the context.- Specified by:
containsKeyin interfaceorg.apache.logging.log4j.util.ReadOnlyStringMap- Specified by:
containsKeyin interfaceThreadContextMap- Parameters:
key- The key to locate.- Returns:
- True if the key is in the context, false otherwise.
-
forEach
public <V> void forEach(org.apache.logging.log4j.util.BiConsumer<java.lang.String,? super V> action)
- Specified by:
forEachin interfaceorg.apache.logging.log4j.util.ReadOnlyStringMap
-
forEach
public <V,S> void forEach(org.apache.logging.log4j.util.TriConsumer<java.lang.String,? super V,S> action, S state)- Specified by:
forEachin interfaceorg.apache.logging.log4j.util.ReadOnlyStringMap
-
getValue
public <V> V getValue(java.lang.String key)
- Specified by:
getValuein interfaceorg.apache.logging.log4j.util.ReadOnlyStringMap
-
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 interfaceorg.apache.logging.log4j.util.ReadOnlyStringMap- Specified by:
isEmptyin interfaceThreadContextMap- Returns:
- true if the Map is empty, false otherwise.
-
size
public int size()
- Specified by:
sizein interfaceorg.apache.logging.log4j.util.ReadOnlyStringMap
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
hashCode
public int hashCode()
- Overrides:
hashCodein classjava.lang.Object
-
equals
public boolean equals(java.lang.Object obj)
- Overrides:
equalsin classjava.lang.Object
-
-