Interface ReadOnlyThreadContextMap


public interface ReadOnlyThreadContextMap
Read-only view of the data structure that implements MDC behavior for ThreadContext.

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

Since:
2.8
See Also:
  • Method Details

    • clear

      void clear()
      Clears the context.
    • containsKey

      boolean containsKey(String key)
      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

      String get(String key)
      Gets the context identified by the key parameter.

      This method has no side effects.

      Parameters:
      key - The key to locate.
      Returns:
      The value associated with the key or null.
    • getCopy

      Map<String,String> getCopy()
      Gets a non-null mutable copy of current thread's context Map.
      Returns:
      a mutable copy of the context.
    • getImmutableMapOrNull

      Map<String,String> getImmutableMapOrNull()
      Returns an immutable view on the context Map or null 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 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:
      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.