This is an automated email from the ASF dual-hosted git repository.

mattsicker pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/logging-log4j2.git

commit 568b658d572aa40d1c78912658a3e26568221d72
Author: Matt Sicker <[email protected]>
AuthorDate: Sat Nov 5 13:23:22 2022 -0500

    Revert "Flatten ThreadContextMap API"
    
    This reverts commit 37d2d5d834055e5c4c980e52063007a11fafe7f5.
---
 .../log4j/spi/CleanableThreadContextMap.java       | 18 ++++-
 .../logging/log4j/spi/NoOpThreadContextMap.java    | 21 -----
 .../logging/log4j/spi/ObjectThreadContextMap.java  | 36 ++++++++-
 .../apache/logging/log4j/spi/ThreadContextMap.java | 92 +---------------------
 .../logging/log4j/spi/ThreadContextMap2.java       | 32 +++++++-
 .../logging/log4j/perf/nogc/OpenHashStringMap.java | 19 ++---
 6 files changed, 86 insertions(+), 132 deletions(-)

diff --git 
a/log4j-api/src/main/java/org/apache/logging/log4j/spi/CleanableThreadContextMap.java
 
b/log4j-api/src/main/java/org/apache/logging/log4j/spi/CleanableThreadContextMap.java
index c2aeb77807..f32a06e6e0 100644
--- 
a/log4j-api/src/main/java/org/apache/logging/log4j/spi/CleanableThreadContextMap.java
+++ 
b/log4j-api/src/main/java/org/apache/logging/log4j/spi/CleanableThreadContextMap.java
@@ -17,13 +17,23 @@
 package org.apache.logging.log4j.spi;
 
 /**
- * Legacy interface extension for ThreadContextMap. These methods have been 
moved to ThreadContextMap
- * using default interface methods.
+ * Extension service provider interface to implement additional custom MDC 
behavior for
+ * {@link org.apache.logging.log4j.ThreadContext}.
  *
  * @see ThreadContextMap
  * @since 2.8
- * @deprecated use {@link ThreadContextMap} directly
  */
-@Deprecated(since = "3.0.0")
 public interface CleanableThreadContextMap extends ThreadContextMap2 {
+
+    /**
+     * Removes all given context map keys from the current thread's context 
map.
+     *
+     * <p>If the current thread does not have a context map it is
+     * created as a side effect.</p>
+
+     * @param keys The keys.
+     * @since 2.8
+     */
+    void removeAll(final Iterable<String> keys);
+
 }
diff --git 
a/log4j-api/src/main/java/org/apache/logging/log4j/spi/NoOpThreadContextMap.java
 
b/log4j-api/src/main/java/org/apache/logging/log4j/spi/NoOpThreadContextMap.java
index f46ffec06b..2f858fce32 100644
--- 
a/log4j-api/src/main/java/org/apache/logging/log4j/spi/NoOpThreadContextMap.java
+++ 
b/log4j-api/src/main/java/org/apache/logging/log4j/spi/NoOpThreadContextMap.java
@@ -62,25 +62,4 @@ public class NoOpThreadContextMap implements 
ThreadContextMap {
     @Override
     public void remove(final String key) {
     }
-
-    @Override
-    public void putAll(final Map<String, String> map) {
-    }
-
-    @Override
-    public void removeAll(final Iterable<String> keys) {
-    }
-
-    @Override
-    public <V> V getValue(final String key) {
-        return null;
-    }
-
-    @Override
-    public <V> void putValue(final String key, final V value) {
-    }
-
-    @Override
-    public <V> void putAllValues(final Map<String, V> values) {
-    }
 }
diff --git 
a/log4j-api/src/main/java/org/apache/logging/log4j/spi/ObjectThreadContextMap.java
 
b/log4j-api/src/main/java/org/apache/logging/log4j/spi/ObjectThreadContextMap.java
index 2711dd01f8..c4bc014d3a 100644
--- 
a/log4j-api/src/main/java/org/apache/logging/log4j/spi/ObjectThreadContextMap.java
+++ 
b/log4j-api/src/main/java/org/apache/logging/log4j/spi/ObjectThreadContextMap.java
@@ -16,14 +16,42 @@
  */
 package org.apache.logging.log4j.spi;
 
+import java.util.Map;
+
 /**
- * Legacy interface extension for ThreadContextMap. These methods have been 
moved to ThreadContextMap
- * using default interface methods.
+ * Extension service provider interface to allow putting Object values in the
+ * {@link org.apache.logging.log4j.ThreadContext}.
  *
  * @see ThreadContextMap
  * @since 2.8
- * @deprecated use {@link ThreadContextMap} directly
  */
-@Deprecated(since = "3.0.0")
 public interface ObjectThreadContextMap extends CleanableThreadContextMap {
+
+    /**
+     * Returns the Object value for the specified key, or {@code null} if the 
specified key does not exist in this
+     * collection.
+     *
+     * @param key the key whose value to return
+     * @param <V> The type of the returned value.
+     * @return the value for the specified key or {@code null}
+     */
+    <V> V getValue(String key);
+
+    /**
+     * Puts the specified key-value pair into the collection.
+     *
+     * @param key the key to add or remove. Keys may be {@code null}.
+     * @param <V> The type of the stored and returned value.
+     * @param value the value to add. Values may be {@code null}.
+     */
+    <V> void putValue(String key, V value);
+
+    /**
+     * Puts all given key-value pairs into the collection.
+     *
+     * @param values the map of key-value pairs to add
+     * @param <V> The type of the value being added.
+     */
+    <V> void putAllValues(Map<String, V> values);
+
 }
diff --git 
a/log4j-api/src/main/java/org/apache/logging/log4j/spi/ThreadContextMap.java 
b/log4j-api/src/main/java/org/apache/logging/log4j/spi/ThreadContextMap.java
index 95edcdbc86..5040bb928e 100644
--- a/log4j-api/src/main/java/org/apache/logging/log4j/spi/ThreadContextMap.java
+++ b/log4j-api/src/main/java/org/apache/logging/log4j/spi/ThreadContextMap.java
@@ -16,13 +16,10 @@
  */
 package org.apache.logging.log4j.spi;
 
-import org.apache.logging.log4j.ThreadContext;
-import org.apache.logging.log4j.util.SortedArrayStringMap;
-import org.apache.logging.log4j.util.StringMap;
-import org.apache.logging.log4j.util3.Cast;
-
 import java.util.Map;
 
+import org.apache.logging.log4j.ThreadContext;
+
 /**
  * Service provider interface to implement custom MDC behavior for {@link 
org.apache.logging.log4j.ThreadContext}.
  * <p>
@@ -89,89 +86,4 @@ public interface ThreadContextMap {
      * @param key The key to remove.
      */
     void remove(final String key);
-
-    /**
-     * Puts all given context map entries into the current thread's
-     * context map.
-     *
-     * <p>If the current thread does not have a context map it is
-     * created as a side effect.</p>
-     * @param map The map.
-     * @since 3.0.0
-     */
-    default void putAll(Map<String, String> map) {
-        map.forEach(this::put);
-    }
-
-    /**
-     * Removes all given context map keys from the current thread's context 
map.
-     *
-     * <p>If the current thread does not have a context map it is
-     * created as a side effect.</p>
-
-     * @param keys The keys.
-     * @since 3.0.0
-     */
-    default void removeAll(Iterable<String> keys) {
-        keys.forEach(this::remove);
-    }
-
-    /**
-     * Returns the context data for reading. Note that regardless of whether 
the returned context data has been
-     * {@linkplain StringMap#freeze() frozen} (made read-only) or not, callers 
should not attempt to modify
-     * the returned data structure.
-     *
-     * @return the {@code StringMap}
-     * @since 3.0.0
-     */
-    default StringMap getReadOnlyContextData() {
-        final Map<String, String> copy = getCopy();
-        StringMap map = new SortedArrayStringMap(copy.size());
-        copy.forEach(map::putValue);
-        map.freeze();
-        return map;
-    }
-
-    /**
-     * Returns the Object value for the specified key, or {@code null} if the 
specified key does not exist in this
-     * collection.
-     *
-     * @param key the key whose value to return
-     * @param <V> The type of the returned value.
-     * @return the value for the specified key or {@code null}
-     * @since 3.0.0
-     */
-    default <V> V getValue(String key) {
-        return Cast.cast(get(key));
-    }
-
-    /**
-     * Puts the specified key-value pair into the collection.
-     *
-     * @param key the key to add or remove. Keys may be {@code null}.
-     * @param <V> The type of the stored and returned value.
-     * @param value the value to add. Values may be {@code null}.
-     * @since 3.0.0
-     */
-    default <V> void putValue(String key, V value) {
-        put(key, value != null ? value.toString() : null);
-    }
-
-    /**
-     * Puts all given key-value pairs into the collection.
-     *
-     * @param values the map of key-value pairs to add
-     * @param <V> The type of the value being added.
-     * @since 3.0.0
-     */
-    default <V> void putAllValues(Map<String, V> values) {
-        values.forEach(this::putValue);
-    }
-
-    interface Factory {
-        /**
-         * Creates a new ThreadContextMap.
-         */
-        ThreadContextMap createThreadContextMap();
-    }
 }
diff --git 
a/log4j-api/src/main/java/org/apache/logging/log4j/spi/ThreadContextMap2.java 
b/log4j-api/src/main/java/org/apache/logging/log4j/spi/ThreadContextMap2.java
index f3e2481631..b48d5ab90b 100644
--- 
a/log4j-api/src/main/java/org/apache/logging/log4j/spi/ThreadContextMap2.java
+++ 
b/log4j-api/src/main/java/org/apache/logging/log4j/spi/ThreadContextMap2.java
@@ -16,14 +16,38 @@
  */
 package org.apache.logging.log4j.spi;
 
+import java.util.Map;
+
+import org.apache.logging.log4j.util.StringMap;
+
 /**
- * Legacy interface extension for ThreadContextMap. These methods have been 
moved to ThreadContextMap
- * using default interface methods.
+ * Extension service provider interface to implement additional custom MDC 
behavior for
+ * {@link org.apache.logging.log4j.ThreadContext}.
+ *
+ * Consider implementing {@link CleanableThreadContextMap} instead.
  *
  * @see ThreadContextMap
  * @since 2.7
- * @deprecated use {@link ThreadContextMap} directly
  */
-@Deprecated(since = "3.0.0")
 public interface ThreadContextMap2 extends ThreadContextMap {
+
+    /**
+     * Puts all given context map entries into the current thread's
+     * context map.
+     *
+     * <p>If the current thread does not have a context map it is
+     * created as a side effect.</p>
+     * @param map The map.
+     * @since 2.7
+     */
+    void putAll(final Map<String, String> map);
+
+    /**
+     * Returns the context data for reading. Note that regardless of whether 
the returned context data has been
+     * {@linkplain StringMap#freeze() frozen} (made read-only) or not, callers 
should not attempt to modify
+     * the returned data structure.
+     *
+     * @return the {@code StringMap}
+     */
+    StringMap getReadOnlyContextData();
 }
diff --git 
a/log4j-perf/src/main/java/org/apache/logging/log4j/perf/nogc/OpenHashStringMap.java
 
b/log4j-perf/src/main/java/org/apache/logging/log4j/perf/nogc/OpenHashStringMap.java
index 942641506e..f976869278 100644
--- 
a/log4j-perf/src/main/java/org/apache/logging/log4j/perf/nogc/OpenHashStringMap.java
+++ 
b/log4j-perf/src/main/java/org/apache/logging/log4j/perf/nogc/OpenHashStringMap.java
@@ -16,12 +16,6 @@
  */
 package org.apache.logging.log4j.perf.nogc;
 
-import org.apache.logging.log4j.spi.ThreadContextMap;
-import org.apache.logging.log4j.util.BiConsumer;
-import org.apache.logging.log4j.util.ReadOnlyStringMap;
-import org.apache.logging.log4j.util.StringMap;
-import org.apache.logging.log4j.util.TriConsumer;
-
 import java.io.IOException;
 import java.io.ObjectInputStream;
 import java.io.ObjectOutputStream;
@@ -32,6 +26,12 @@ import java.util.HashMap;
 import java.util.Map;
 import java.util.Objects;
 
+import org.apache.logging.log4j.util.ReadOnlyStringMap;
+import org.apache.logging.log4j.util.StringMap;
+import org.apache.logging.log4j.spi.ThreadContextMap;
+import org.apache.logging.log4j.util.BiConsumer;
+import org.apache.logging.log4j.util.TriConsumer;
+
 /**
  * Open hash map-based implementation of the {@code ReadOnlyStringMap} 
interface.
  * Implementation based on <a 
href="http://fastutil.di.unimi.it/";>fastutil</a>'s
@@ -485,8 +485,7 @@ public class OpenHashStringMap<K, V> implements StringMap, 
ThreadContextMap {
     }
 
     /** {@inheritDoc} */
-    @SuppressWarnings({"unchecked", "rawtypes"})
-    public void putAll(final Map map) {
+    public void putAll(final Map<? extends K, ? extends V> map) {
         if (loadFactor <= .5) {
             // The resulting map will be sized for m.size() elements
             ensureCapacity(map.size());
@@ -494,7 +493,9 @@ public class OpenHashStringMap<K, V> implements StringMap, 
ThreadContextMap {
             // The resulting map will be tentatively sized for size() +  
m.size() elements
             tryCapacity(size() + map.size());
         }
-        map.forEach((key, value) -> putObjectValue((K) key, (V) value));
+        for (final Map.Entry<? extends K, ? extends V> entry : map.entrySet()) 
{
+            putObjectValue(entry.getKey(), entry.getValue());
+        }
     }
 
     private V putObjectValue(final K k, final V v) {

Reply via email to