public class DefaultThreadContextMap extends Object implements ThreadContextMap, ReadOnlyStringMap
Modifier and Type | Field and Description |
---|---|
static String |
INHERITABLE_MAP
Property name ("isThreadContextMapInheritable" ) for selecting
InheritableThreadLocal (value "true") or plain
ThreadLocal (value is not "true") in the implementation. |
Constructor and Description |
---|
DefaultThreadContextMap() |
DefaultThreadContextMap(boolean useMap) |
Modifier and Type | Method and Description |
---|---|
void |
clear()
Clears the context.
|
boolean |
containsKey(String key)
Determines if the key is in the context.
|
boolean |
equals(Object obj) |
<V> void |
forEach(BiConsumer<String,? super V> action)
Performs the given action for each key-value pair in this data structure
until all entries have been processed or the action throws an exception.
|
<V,S> void |
forEach(TriConsumer<String,? super V,S> action,
S state)
Performs the given action for each key-value pair in this data structure
until all entries have been processed or the action throws an exception.
|
String |
get(String key)
Gets the context identified by the
key 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 or
null if the context map is empty. |
<V> V |
getValue(String key)
Returns the value for the specified key, or
null if the specified key does not exist in this collection. |
int |
hashCode() |
boolean |
isEmpty()
Returns true if the Map is empty.
|
void |
put(String key,
String value)
Puts a context value (the
o parameter) as identified
with the key parameter into the current thread's
context map. |
void |
putAll(Map<String,String> m) |
void |
remove(String key)
Removes the context identified by the
key
parameter. |
void |
removeAll(Iterable<String> keys) |
int |
size()
Returns the number of key-value pairs in this collection.
|
Map<String,String> |
toMap()
Returns a non-
null mutable Map<String, String> containing a snapshot of this data structure. |
String |
toString() |
public static final String INHERITABLE_MAP
InheritableThreadLocal
(value "true") or plain
ThreadLocal
(value is not "true") in the implementation.public DefaultThreadContextMap()
public DefaultThreadContextMap(boolean useMap)
public void put(String key, String value)
ThreadContextMap
o
parameter) as identified
with the key
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.
put
in interface ThreadContextMap
key
- The key name.value
- The key value.public String get(String key)
ThreadContextMap
key
parameter.
This method has no side effects.
get
in interface ThreadContextMap
key
- The key to locate.public void remove(String key)
ThreadContextMap
key
parameter.remove
in interface ThreadContextMap
key
- The key to remove.public void clear()
ThreadContextMap
clear
in interface ThreadContextMap
public Map<String,String> toMap()
ReadOnlyStringMap
null
mutable Map<String, String>
containing a snapshot of this data structure.toMap
in interface ReadOnlyStringMap
Map<String, String>
form.public boolean containsKey(String key)
ThreadContextMap
containsKey
in interface ThreadContextMap
containsKey
in interface ReadOnlyStringMap
key
- The key to locate.public <V> void forEach(BiConsumer<String,? super V> action)
ReadOnlyStringMap
Some implementations may not support structural modifications (adding new elements or removing elements) while
iterating over the contents. In such implementations, attempts to add or remove elements from the
BiConsumer
's BiConsumer.accept(Object, Object)
accept} method may cause a
ConcurrentModificationException
to be thrown.
forEach
in interface ReadOnlyStringMap
V
- type of the value.action
- The action to be performed for each key-value pair in this collection.public <V,S> void forEach(TriConsumer<String,? super V,S> action, S state)
ReadOnlyStringMap
The third parameter lets callers pass in a stateful object to be modified with the key-value pairs, so the TriConsumer implementation itself can be stateless and potentially reusable.
Some implementations may not support structural modifications (adding new elements or removing elements) while
iterating over the contents. In such implementations, attempts to add or remove elements from the
TriConsumer
's accept
method may cause a
ConcurrentModificationException
to be thrown.
forEach
in interface ReadOnlyStringMap
V
- type of the value.S
- type of the third parameter.action
- The action to be performed for each key-value pair in this collection.state
- the object to be passed as the third parameter to each invocation on the specified
triconsumer.public <V> V getValue(String key)
ReadOnlyStringMap
null
if the specified key does not exist in this collection.getValue
in interface ReadOnlyStringMap
key
- the key whose value to return.null
.public Map<String,String> getCopy()
ThreadContextMap
null
mutable copy of current thread's context Map.getCopy
in interface ThreadContextMap
public Map<String,String> getImmutableMapOrNull()
ThreadContextMap
null
if the context map is empty.getImmutableMapOrNull
in interface ThreadContextMap
null
.public boolean isEmpty()
ThreadContextMap
isEmpty
in interface ThreadContextMap
isEmpty
in interface ReadOnlyStringMap
public int size()
ReadOnlyStringMap
size
in interface ReadOnlyStringMap
Copyright © 1999-1969 The Apache Software Foundation. All Rights Reserved.
Apache Logging, Apache Log4j, Log4j, Apache, the Apache feather logo, the Apache Logging project logo, and the Apache Log4j logo are trademarks of The Apache Software Foundation.