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

public Interface ReadOnlyThreadContextMap

Known Direct Implementers
org.apache.logging.log4j.spi.CopyOnWriteSortedArrayThreadContextMap, org.apache.logging.log4j.spi.GarbageFreeSortedArrayThreadContextMap
Imports
java.util.Map, org.apache.logging.log4j.ThreadContext, org.apache.logging.log4j.util.StringMap

Read-only view of the data structure that implements MDC behavior for org.apache.logging.log4j.ThreadContext.

ThreadContextMap implementations that also implement this interface can be accessed by applications via the ThreadContext#getThreadContextMap() method.

Since
2.8
See Also
ThreadContext#getThreadContextMap()

Method Summary

Modifier and TypeMethod and Description
public void
clear()

Clears the context.

public boolean

Returns:

True if the key is in the context, false otherwise.
containsKey
(final String
The key to locate.
key
)

Determines if the key is in the context.

public String

Returns:

The value associated with the key or null.
get
(final String
The key to locate.
key
)

Gets the context identified by the key parameter.

public Map<String, String>

Returns:

a mutable copy of the context.
getCopy
()

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

public Map<String, String>

Returns:

an immutable context Map or null.
getImmutableMapOrNull
()

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

public StringMap

Returns:

a StringMap containing context data key-value pairs
getReadOnlyContextData
()

Returns the context data for reading.

public boolean

Returns:

true if the Map is empty, false otherwise.
isEmpty
()

Returns true if the Map is empty.

Method Detail

clearback to summary
public void clear()

Clears the context.

containsKeyback to summary
public boolean containsKey(final String key)

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.

getback to summary
public String get(final String key)

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.

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

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

Returns:Map<String, String>

a mutable copy of the context.

getImmutableMapOrNullback to summary
public Map<String, String> 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.

getReadOnlyContextDataback to summary
public StringMap 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

isEmptyback to summary
public boolean isEmpty()

Returns true if the Map is empty.

Returns:boolean

true if the Map is empty, false otherwise.