org.apache.logging.log4j.spi
Class DefaultThreadContextMap

java.lang.Object
  extended by org.apache.logging.log4j.spi.DefaultThreadContextMap
All Implemented Interfaces:
ThreadContextMap

public class DefaultThreadContextMap
extends Object
implements ThreadContextMap

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.


Field Summary
static String INHERITABLE_MAP
          Property name ("isThreadContextMapInheritable") for selecting InheritableThreadLocal (value "true") or plain ThreadLocal (value is not "true") in the implementation.
 
Constructor Summary
DefaultThreadContextMap(boolean useMap)
           
 
Method Summary
 void clear()
          Clear the context.
 boolean containsKey(String key)
          Determine if the key is in the context.
 boolean equals(Object obj)
           
 String get(String key)
          Get the context identified by the key parameter.
 Map<String,String> getCopy()
          Returns a non-null mutable copy of the ThreadContext Map.
 Map<String,String> getImmutableMapOrNull()
          Returns either null or an immutable view of the context Map.
 int hashCode()
           
 boolean isEmpty()
          Returns true if the Map is empty.
 void put(String key, String value)
          Put a context value (the o parameter) as identified with the key parameter into the current thread's context map.
 void remove(String key)
          Remove the the context identified by the key parameter.
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

INHERITABLE_MAP

public static final String INHERITABLE_MAP
Property name ("isThreadContextMapInheritable") for selecting InheritableThreadLocal (value "true") or plain ThreadLocal (value is not "true") in the implementation.

See Also:
Constant Field Values
Constructor Detail

DefaultThreadContextMap

public DefaultThreadContextMap(boolean useMap)
Method Detail

put

public void put(String key,
                String value)
Put a context value (the 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.

Specified by:
put in interface ThreadContextMap
Parameters:
key - The key name.
value - The key value.

get

public String get(String key)
Get the context identified by the key parameter.

This method has no side effects.

Specified by:
get in interface ThreadContextMap
Parameters:
key - The key to locate.
Returns:
The value associated with the key or null.

remove

public void remove(String key)
Remove the the context identified by the key parameter.

Specified by:
remove in interface ThreadContextMap
Parameters:
key - The key to remove.

clear

public void clear()
Clear the context.

Specified by:
clear in interface ThreadContextMap

containsKey

public boolean containsKey(String key)
Determine if the key is in the context.

Specified by:
containsKey in interface ThreadContextMap
Parameters:
key - The key to locate.
Returns:
True if the key is in the context, false otherwise.

getCopy

public Map<String,String> getCopy()
Returns a non-null mutable copy of the ThreadContext Map.

Specified by:
getCopy in interface ThreadContextMap
Returns:
a non-null mutable copy of the context.

getImmutableMapOrNull

public Map<String,String> getImmutableMapOrNull()
Returns either null or an immutable view of the context Map.

Specified by:
getImmutableMapOrNull in interface ThreadContextMap
Returns:
the Context Map.

isEmpty

public boolean isEmpty()
Returns true if the Map is empty.

Specified by:
isEmpty in interface ThreadContextMap
Returns:
true if the Map is empty, false otherwise.

toString

public String toString()
Overrides:
toString in class Object

hashCode

public int hashCode()
Overrides:
hashCode in class Object

equals

public boolean equals(Object obj)
Overrides:
equals in class Object


Copyright © 1999-2014 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.