Top Description Fields Constructors Methods
org.apache.logging.log4j.spi

pack-priv Class GarbageFreeSortedArrayThreadContextMap

extends Object
implements ReadOnlyThreadContextMap, ObjectThreadContextMap
Class Inheritance
All Implemented Interfaces
org.apache.logging.log4j.spi.ObjectThreadContextMap, org.apache.logging.log4j.spi.CleanableThreadContextMap, org.apache.logging.log4j.spi.ThreadContextMap2, org.apache.logging.log4j.spi.ThreadContextMap, org.apache.logging.log4j.spi.ReadOnlyThreadContextMap
Imports
java.util.Collections, .HashMap, .Map, .Objects, org.apache.logging.log4j.util.PropertiesUtil, .ReadOnlyStringMap, .SortedArrayStringMap, .StringMap

SortedArrayStringMap-based implementation of the ThreadContextMap interface that attempts not to create temporary objects. Adding and removing key-value pairs will not create temporary objects.

This implementation does not make a copy of its contents on every operation, so this data structure cannot be passed to log events. Instead, client code needs to copy the contents when interacting with another thread.

Since
2.7

Field Summary

Modifier and TypeField and Description
protected static final int
DEFAULT_INITIAL_CAPACITY

The default initial capacity.

public static final String
INHERITABLE_MAP

Property name ( ) for selecting InheritableThreadLocal (value "true") or plain ThreadLocal (value is not "true") in the implementation.

private static volatile boolean
private static volatile int
protected final ThreadLocal<StringMap>
protected static final String
PROPERTY_NAME_INITIAL_CAPACITY

System property name that can be used to control the data structure's initial capacity.

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public void
public boolean
protected StringMap

Returns:

an implementation of the StringMap used to back this thread context map
createStringMap
()

Returns an implementation of the StringMap used to back this thread context map.

protected StringMap

Returns:

an implementation of the StringMap used to back this thread context map
createStringMap
(final ReadOnlyStringMap
the key-value pairs to initialize the returned context data with
original
)

Returns an implementation of the StringMap used to back this thread context map, pre-populated with the contents of the specified context data.

private ThreadLocal<StringMap>
public boolean
equals(final Object
the reference object with which to compare.
obj
)

Overrides java.lang.Object.equals.

Indicates whether some other object is "equal to" this one.

public String
get(final String
The key to locate.
key
)

Implements org.apache.logging.log4j.spi.ReadOnlyThreadContextMap.get, org.apache.logging.log4j.spi.ThreadContextMap.get.

Gets the context identified by the key parameter.

public Map<String, String>
public Map<String, String>
public StringMap
private StringMap
public <V> V
getValue(final String
the key whose value to return
key
)

Implements org.apache.logging.log4j.spi.ObjectThreadContextMap.getValue.

Returns the Object value for the specified key, or null if the specified key does not exist in this collection.

public int
hashCode()

Overrides java.lang.Object.hashCode.

Returns a hash code value for this object.

pack-priv static void
init()

Initializes static variables based on system properties.

public boolean
public void
put(final String
The key name.
key
,
final String
The key value.
value
)

Implements org.apache.logging.log4j.spi.ThreadContextMap.put.

Puts a context value (the o parameter) as identified with the key parameter into the current thread's context map.

public void
putAll(final Map<String, String>
The map.
values
)

Implements org.apache.logging.log4j.spi.ThreadContextMap2.putAll.

Puts all given context map entries into the current thread's context map.

public <V> void
putAllValues(final Map<String, V>
the map of key-value pairs to add
values
)

Implements org.apache.logging.log4j.spi.ObjectThreadContextMap.putAllValues.

Puts all given key-value pairs into the collection.

public void
putValue(final String
the key to add or remove. Keys may be null.
key
,
final Object
the value to add. Values may be null.
value
)

Implements org.apache.logging.log4j.spi.ObjectThreadContextMap.putValue.

Puts the specified key-value pair into the collection.

public void
remove(final String
The key to remove.
key
)

Implements org.apache.logging.log4j.spi.ThreadContextMap.remove.

Removes the context identified by the key parameter.

public void
removeAll(final Iterable<String>
The keys.
keys
)

Implements org.apache.logging.log4j.spi.CleanableThreadContextMap.removeAll.

Removes all given context map keys from the current thread's context map.

public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.

Inherited from java.lang.Object:
clonefinalizegetClassnotifynotifyAllwaitwaitwait

Field Detail

DEFAULT_INITIAL_CAPACITYback to summary
protected static final int DEFAULT_INITIAL_CAPACITY

The default initial capacity.

INHERITABLE_MAPback to summary
public static final String INHERITABLE_MAP

Property name ( ) for selecting InheritableThreadLocal (value "true") or plain ThreadLocal (value is not "true") in the implementation.

inheritableMapback to summary
private static volatile boolean inheritableMap
initialCapacityback to summary
private static volatile int initialCapacity
localMapback to summary
protected final ThreadLocal<StringMap> localMap
PROPERTY_NAME_INITIAL_CAPACITYback to summary
protected static final String PROPERTY_NAME_INITIAL_CAPACITY

System property name that can be used to control the data structure's initial capacity.

Constructor Detail

GarbageFreeSortedArrayThreadContextMapback to summary
public GarbageFreeSortedArrayThreadContextMap()

Method Detail

clearback to summary
public void clear()

Implements org.apache.logging.log4j.spi.ReadOnlyThreadContextMap.clear, org.apache.logging.log4j.spi.ThreadContextMap.clear.

Doc from org.apache.logging.log4j.spi.ReadOnlyThreadContextMap.clear.

Clears the context.

Annotations
@Override
containsKeyback to summary
public boolean containsKey(final String key)

Implements org.apache.logging.log4j.spi.ReadOnlyThreadContextMap.containsKey, org.apache.logging.log4j.spi.ThreadContextMap.containsKey.

Doc from org.apache.logging.log4j.spi.ReadOnlyThreadContextMap.containsKey.

Determines if the key is in the context.

Parameters
key:String

The key to locate.

Returns:boolean

True if the key is in the context, false otherwise.

Annotations
@Override
createStringMapback to summary
protected StringMap createStringMap()

Returns an implementation of the StringMap used to back this thread context map.

Subclasses may override.

Returns:StringMap

an implementation of the StringMap used to back this thread context map

createStringMapback to summary
protected StringMap createStringMap(final ReadOnlyStringMap original)

Returns an implementation of the StringMap used to back this thread context map, pre-populated with the contents of the specified context data.

Subclasses may override.

Parameters
original:ReadOnlyStringMap

the key-value pairs to initialize the returned context data with

Returns:StringMap

an implementation of the StringMap used to back this thread context map

createThreadLocalMapback to summary
private ThreadLocal<StringMap> createThreadLocalMap()
equalsback to summary
public boolean equals(final Object obj)

Overrides java.lang.Object.equals.

Doc from java.lang.Object.equals.

Indicates whether some other object is "equal to" this one.

The equals method implements an equivalence relation on non-null object references:

  • It is reflexive: for any non-null reference value x, x.equals(x) should return true.
  • It is symmetric: for any non-null reference values x and y, x.equals(y) should return true if and only if y.equals(x) returns true.
  • It is transitive: for any non-null reference values x, y, and z, if x.equals(y) returns true and y.equals(z) returns true, then x.equals(z) should return true.
  • It is consistent: for any non-null reference values x and y, multiple invocations of x.equals(y) consistently return true or consistently return false, provided no information used in equals comparisons on the objects is modified.
  • For any non-null reference value x, x.equals(null) should return false.

An equivalence relation partitions the elements it operates on into equivalence classes; all the members of an equivalence class are equal to each other. Members of an equivalence class are substitutable for each other, at least for some purposes.

Parameters
obj:Object

the reference object with which to compare.

Returns:boolean

true if this object is the same as the obj argument; false otherwise.

Annotations
@Override
getback to summary
public String get(final String key)

Implements org.apache.logging.log4j.spi.ReadOnlyThreadContextMap.get, org.apache.logging.log4j.spi.ThreadContextMap.get.

Doc from org.apache.logging.log4j.spi.ReadOnlyThreadContextMap.get.

Gets the context identified by the key parameter.

This method has no side effects.

Parameters
key:String

The key to locate.

Returns:String

The value associated with the key or null.

Annotations
@Override
getCopyback to summary
public Map<String, String> getCopy()

Implements org.apache.logging.log4j.spi.ReadOnlyThreadContextMap.getCopy, org.apache.logging.log4j.spi.ThreadContextMap.getCopy.

Doc from org.apache.logging.log4j.spi.ReadOnlyThreadContextMap.getCopy.

Gets a non-null mutable copy of current thread's context Map.

Returns:Map<String, String>

a mutable copy of the context.

Annotations
@Override
getImmutableMapOrNullback to summary
public Map<String, String> getImmutableMapOrNull()

Implements org.apache.logging.log4j.spi.ReadOnlyThreadContextMap.getImmutableMapOrNull, org.apache.logging.log4j.spi.ThreadContextMap.getImmutableMapOrNull.

Doc from org.apache.logging.log4j.spi.ReadOnlyThreadContextMap.getImmutableMapOrNull.

Returns an immutable view on the context Map or null if the context map is empty.

Returns:Map<String, String>

an immutable context Map or null.

Annotations
@Override
getReadOnlyContextDataback to summary
public StringMap getReadOnlyContextData()

Implements org.apache.logging.log4j.spi.ReadOnlyThreadContextMap.getReadOnlyContextData, org.apache.logging.log4j.spi.ThreadContextMap2.getReadOnlyContextData.

Doc from org.apache.logging.log4j.spi.ReadOnlyThreadContextMap.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.

Thread safety note:

If this ReadOnlyThreadContextMap implements CopyOnWrite, then the returned StringMap can safely be passed to another thread: future changes in the underlying context data will not be reflected in the returned StringMap.

Otherwise, if this ReadOnlyThreadContextMap does not implement CopyOnWrite, then it is not safe to pass the returned StringMap to another thread because changes in the underlying context may be reflected in the returned object. It is the responsibility of the caller to make a copy to pass to another thread.

Returns:StringMap

a StringMap containing context data key-value pairs

Annotations
@Override
getThreadLocalMapback to summary
private StringMap getThreadLocalMap()
getValueback to summary
public <V> V getValue(final String key)

Implements org.apache.logging.log4j.spi.ObjectThreadContextMap.getValue.

Doc from org.apache.logging.log4j.spi.ObjectThreadContextMap.getValue.

Returns the Object value for the specified key, or null if the specified key does not exist in this collection.

Parameters
key:String

the key whose value to return

Returns:V

the value for the specified key or null

Annotations
@Override
hashCodeback to summary
public int hashCode()

Overrides java.lang.Object.hashCode.

Doc from java.lang.Object.hashCode.

Returns a hash code value for this object. This method is supported for the benefit of hash tables such as those provided by java.util.HashMap.

The general contract of hashCode is:

  • Whenever it is invoked on the same object more than once during an execution of a Java application, the hashCode method must consistently return the same integer, provided no information used in equals comparisons on the object is modified. This integer need not remain consistent from one execution of an application to another execution of the same application.
  • If two objects are equal according to the equals method, then calling the hashCode method on each of the two objects must produce the same integer result.
  • It is not required that if two objects are unequal according to the equals method, then calling the hashCode method on each of the two objects must produce distinct integer results. However, the programmer should be aware that producing distinct integer results for unequal objects may improve the performance of hash tables.
Returns:int

a hash code value for this object

Annotations
@Override
initback to summary
pack-priv static void init()

Initializes static variables based on system properties. Normally called when this class is initialized by the VM and when Log4j is reconfigured.

isEmptyback to summary
public boolean isEmpty()

Implements org.apache.logging.log4j.spi.ReadOnlyThreadContextMap.isEmpty, org.apache.logging.log4j.spi.ThreadContextMap.isEmpty.

Doc from org.apache.logging.log4j.spi.ReadOnlyThreadContextMap.isEmpty.

Returns true if the Map is empty.

Returns:boolean

true if the Map is empty, false otherwise.

Annotations
@Override
putback to summary
public void put(final String key, final String value)

Implements org.apache.logging.log4j.spi.ThreadContextMap.put.

Doc from org.apache.logging.log4j.spi.ThreadContextMap.put.

Puts 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.

Parameters
key:String

The key name.

value:String

The key value.

Annotations
@Override
putAllback to summary
public void putAll(final Map<String, String> values)

Implements org.apache.logging.log4j.spi.ThreadContextMap2.putAll.

Doc from org.apache.logging.log4j.spi.ThreadContextMap2.putAll.

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
values:Map<String, String>

The map.

Annotations
@Override
putAllValuesback to summary
public <V> void putAllValues(final Map<String, V> values)

Implements org.apache.logging.log4j.spi.ObjectThreadContextMap.putAllValues.

Doc from org.apache.logging.log4j.spi.ObjectThreadContextMap.putAllValues.

Puts all given key-value pairs into the collection.

Parameters
values:Map<String, V>

the map of key-value pairs to add

Annotations
@Override
putValueback to summary
public void putValue(final String key, final Object value)

Implements org.apache.logging.log4j.spi.ObjectThreadContextMap.putValue.

Doc from org.apache.logging.log4j.spi.ObjectThreadContextMap.putValue.

Puts the specified key-value pair into the collection.

Parameters
key:String

the key to add or remove. Keys may be null.

value:Object

the value to add. Values may be null.

Annotations
@Override
removeback to summary
public void remove(final String key)

Implements org.apache.logging.log4j.spi.ThreadContextMap.remove.

Doc from org.apache.logging.log4j.spi.ThreadContextMap.remove.

Removes the context identified by the key parameter.

Parameters
key:String

The key to remove.

Annotations
@Override
removeAllback to summary
public void removeAll(final Iterable<String> keys)

Implements org.apache.logging.log4j.spi.CleanableThreadContextMap.removeAll.

Doc from org.apache.logging.log4j.spi.CleanableThreadContextMap.removeAll.

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:Iterable<String>

The keys.

Annotations
@Override
toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object. Satisfying this method's contract implies a non-null result must be returned.

Returns:String

a string representation of the object

Annotations
@Override