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 TypeMethodDescriptionvoidclear()Clears the context.booleancontainsKey(String key) Determines if the key is in the context.Gets the context identified by thekeyparameter.getCopy()Gets a non-nullmutable copy of current thread's context Map.Returns an immutable view on the context Map ornullif the context map is empty.Returns the context data for reading.booleanisEmpty()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 thekeyparameter.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-nullmutable copy of current thread's context Map.- Returns:
- a mutable copy of the context.
-
getImmutableMapOrNull
Returns an immutable view on the context Map ornullif 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
ReadOnlyThreadContextMapimplementsCopyOnWrite, then the returnedStringMapcan safely be passed to another thread: future changes in the underlying context data will not be reflected in the returnedStringMap.Otherwise, if this
ReadOnlyThreadContextMapdoes not implementCopyOnWrite, then it is not safe to pass the returnedStringMapto 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
StringMapcontaining context data key-value pairs
-
isEmpty
boolean isEmpty()Returns true if the Map is empty.- Returns:
- true if the Map is empty, false otherwise.
-