Interface ReadOnlyThreadContextMap
ThreadContext
.
ThreadContextMap
implementations that also implement this interface can be accessed
by applications via the ThreadContext.getThreadContextMap()
method.
- Since:
- 2.8
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionvoid
clear()
Clears the context.boolean
containsKey
(String key) Determines if the key is in the context.Gets the context identified by thekey
parameter.getCopy()
Gets a non-null
mutable copy of current thread's context Map.Returns an immutable view on the context Map ornull
if the context map is empty.Returns the context data for reading.boolean
isEmpty()
Returns true if the Map is empty.
-
Method Details
-
clear
void clear()Clears the context. -
containsKey
Determines if the key is in the context.- Parameters:
key
- The key to locate.- Returns:
- True if the key is in the context, false otherwise.
-
get
Gets the context identified by thekey
parameter.This method has no side effects.
- Parameters:
key
- The key to locate.- Returns:
- The value associated with the key or null.
-
getCopy
Gets a non-null
mutable copy of current thread's context Map.- Returns:
- a mutable copy of the context.
-
getImmutableMapOrNull
Returns an immutable view on the context Map ornull
if the context map is empty.- Returns:
- an immutable context Map or
null
.
-
getReadOnlyContextData
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
implementsCopyOnWrite
, then the returnedStringMap
can safely be passed to another thread: future changes in the underlying context data will not be reflected in the returnedStringMap
.Otherwise, if this
ReadOnlyThreadContextMap
does not implementCopyOnWrite
, then it is not safe to pass the returnedStringMap
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:
- a
StringMap
containing context data key-value pairs
-
isEmpty
boolean isEmpty()Returns true if the Map is empty.- Returns:
- true if the Map is empty, false otherwise.
-