Class GarbageFreeSortedArrayThreadContextMap

    • Field Summary

      Fields 
      Modifier and Type Field Description
      protected static int DEFAULT_INITIAL_CAPACITY
      The default initial capacity.
      static java.lang.String INHERITABLE_MAP
      Property name ("isThreadContextMapInheritable" ) for selecting InheritableThreadLocal (value "true") or plain ThreadLocal (value is not "true") in the implementation.
      private static boolean inheritableMap  
      private static int initialCapacity  
      protected java.lang.ThreadLocal<StringMap> localMap  
      protected static java.lang.String PROPERTY_NAME_INITIAL_CAPACITY
      System property name that can be used to control the data structure's initial capacity.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void clear()
      Clears the context.
      boolean containsKey​(java.lang.String key)
      Determines if the key is in the context.
      protected StringMap createStringMap()
      Returns an implementation of the StringMap used to back this thread context map.
      protected StringMap createStringMap​(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.
      private java.lang.ThreadLocal<StringMap> createThreadLocalMap()  
      boolean equals​(java.lang.Object obj)  
      java.lang.String get​(java.lang.String key)
      Gets the context identified by the key parameter.
      java.util.Map<java.lang.String,​java.lang.String> getCopy()
      Gets a non-null mutable copy of current thread's context Map.
      java.util.Map<java.lang.String,​java.lang.String> getImmutableMapOrNull()
      Returns an immutable view on the context Map or null if the context map is empty.
      StringMap getReadOnlyContextData()
      Returns the context data for reading.
      private StringMap getThreadLocalMap()  
      <V> V getValue​(java.lang.String key)
      Returns the Object value for the specified key, or null if the specified key does not exist in this collection.
      int hashCode()  
      (package private) static void init()
      Initializes static variables based on system properties.
      boolean isEmpty()
      Returns true if the Map is empty.
      void put​(java.lang.String key, java.lang.String value)
      Puts a context value (the o parameter) as identified with the key parameter into the current thread's context map.
      void putAll​(java.util.Map<java.lang.String,​java.lang.String> values)
      Puts all given context map entries into the current thread's context map.
      <V> void putAllValues​(java.util.Map<java.lang.String,​V> values)
      Puts all given key-value pairs into the collection.
      void putValue​(java.lang.String key, java.lang.Object value)
      Puts the specified key-value pair into the collection.
      void remove​(java.lang.String key)
      Removes the context identified by the key parameter.
      void removeAll​(java.lang.Iterable<java.lang.String> keys)
      Removes all given context map keys from the current thread's context map.
      java.lang.String toString()  
      • Methods inherited from class java.lang.Object

        clone, finalize, getClass, notify, notifyAll, wait, wait, wait
    • Field Detail

      • INHERITABLE_MAP

        public static final java.lang.String INHERITABLE_MAP
        Property name ("isThreadContextMapInheritable" ) for selecting InheritableThreadLocal (value "true") or plain ThreadLocal (value is not "true") in the implementation.
        See Also:
        Constant Field Values
      • DEFAULT_INITIAL_CAPACITY

        protected static final int DEFAULT_INITIAL_CAPACITY
        The default initial capacity.
        See Also:
        Constant Field Values
      • PROPERTY_NAME_INITIAL_CAPACITY

        protected static final java.lang.String PROPERTY_NAME_INITIAL_CAPACITY
        System property name that can be used to control the data structure's initial capacity.
        See Also:
        Constant Field Values
      • localMap

        protected final java.lang.ThreadLocal<StringMap> localMap
      • initialCapacity

        private static volatile int initialCapacity
      • inheritableMap

        private static volatile boolean inheritableMap
    • Constructor Detail

      • GarbageFreeSortedArrayThreadContextMap

        public GarbageFreeSortedArrayThreadContextMap()
    • Method Detail

      • init

        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.
      • createThreadLocalMap

        private java.lang.ThreadLocal<StringMap> createThreadLocalMap()
      • createStringMap

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

        Subclasses may override.

        Returns:
        an implementation of the StringMap used to back this thread context map
      • createStringMap

        protected StringMap createStringMap​(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 - the key-value pairs to initialize the returned context data with
        Returns:
        an implementation of the StringMap used to back this thread context map
      • getThreadLocalMap

        private StringMap getThreadLocalMap()
      • put

        public void put​(java.lang.String key,
                        java.lang.String value)
        Description copied from interface: ThreadContextMap
        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.

        Specified by:
        put in interface ThreadContextMap
        Parameters:
        key - The key name.
        value - The key value.
      • putValue

        public void putValue​(java.lang.String key,
                             java.lang.Object value)
        Description copied from interface: ObjectThreadContextMap
        Puts the specified key-value pair into the collection.
        Specified by:
        putValue in interface ObjectThreadContextMap
        Parameters:
        key - the key to add or remove. Keys may be null.
        value - the value to add. Values may be null.
      • putAll

        public void putAll​(java.util.Map<java.lang.String,​java.lang.String> values)
        Description copied from interface: ThreadContextMap2
        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.

        Specified by:
        putAll in interface ThreadContextMap2
        Parameters:
        values - The map.
      • putAllValues

        public <V> void putAllValues​(java.util.Map<java.lang.String,​V> values)
        Description copied from interface: ObjectThreadContextMap
        Puts all given key-value pairs into the collection.
        Specified by:
        putAllValues in interface ObjectThreadContextMap
        Parameters:
        values - the map of key-value pairs to add
      • get

        public java.lang.String get​(java.lang.String key)
        Description copied from interface: ReadOnlyThreadContextMap
        Gets the context identified by the key parameter.

        This method has no side effects.

        Specified by:
        get in interface ReadOnlyThreadContextMap
        Specified by:
        get in interface ThreadContextMap
        Parameters:
        key - The key to locate.
        Returns:
        The value associated with the key or null.
      • getValue

        public <V> V getValue​(java.lang.String key)
        Description copied from interface: ObjectThreadContextMap
        Returns the Object value for the specified key, or null if the specified key does not exist in this collection.
        Specified by:
        getValue in interface ObjectThreadContextMap
        Parameters:
        key - the key whose value to return
        Returns:
        the value for the specified key or null
      • remove

        public void remove​(java.lang.String key)
        Description copied from interface: ThreadContextMap
        Removes the context identified by the key parameter.
        Specified by:
        remove in interface ThreadContextMap
        Parameters:
        key - The key to remove.
      • removeAll

        public void removeAll​(java.lang.Iterable<java.lang.String> keys)
        Description copied from interface: CleanableThreadContextMap
        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.

        Specified by:
        removeAll in interface CleanableThreadContextMap
        Parameters:
        keys - The keys.
      • getReadOnlyContextData

        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.

        Specified by:
        getReadOnlyContextData in interface ReadOnlyThreadContextMap
        Specified by:
        getReadOnlyContextData in interface ThreadContextMap2
        Returns:
        a StringMap containing context data key-value pairs
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class java.lang.Object
      • equals

        public boolean equals​(java.lang.Object obj)
        Overrides:
        equals in class java.lang.Object