You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@logging.apache.org by rp...@apache.org on 2016/11/03 14:55:04 UTC

[05/10] logging-log4j2 git commit: LOG4J2-1660 make method #getThreadContextMap public, change return type to ReadOnlyThreadContextMap, javadoc

LOG4J2-1660 make method #getThreadContextMap public, change return type to ReadOnlyThreadContextMap, javadoc


Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo
Commit: http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit/50392786
Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/50392786
Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/50392786

Branch: refs/heads/master
Commit: 50392786b8153782af7b15646d9108e52b86e38c
Parents: 86e6565
Author: rpopma <rp...@apache.org>
Authored: Thu Nov 3 23:43:54 2016 +0900
Committer: rpopma <rp...@apache.org>
Committed: Thu Nov 3 23:43:54 2016 +0900

----------------------------------------------------------------------
 .../org/apache/logging/log4j/ThreadContext.java | 30 ++++++++++++++------
 1 file changed, 22 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/50392786/log4j-api/src/main/java/org/apache/logging/log4j/ThreadContext.java
----------------------------------------------------------------------
diff --git a/log4j-api/src/main/java/org/apache/logging/log4j/ThreadContext.java b/log4j-api/src/main/java/org/apache/logging/log4j/ThreadContext.java
index f282397..5242993 100644
--- a/log4j-api/src/main/java/org/apache/logging/log4j/ThreadContext.java
+++ b/log4j-api/src/main/java/org/apache/logging/log4j/ThreadContext.java
@@ -30,6 +30,7 @@ import org.apache.logging.log4j.message.ParameterizedMessage;
 import org.apache.logging.log4j.spi.DefaultThreadContextMap;
 import org.apache.logging.log4j.spi.DefaultThreadContextStack;
 import org.apache.logging.log4j.spi.NoOpThreadContextMap;
+import org.apache.logging.log4j.spi.ReadOnlyThreadContextMap;
 import org.apache.logging.log4j.spi.ThreadContextMap;
 import org.apache.logging.log4j.spi.ThreadContextMap2;
 import org.apache.logging.log4j.spi.ThreadContextMapFactory;
@@ -195,6 +196,8 @@ public final class ThreadContext {
     private static boolean useStack;
     private static ThreadContextMap contextMap;
     private static ThreadContextStack contextStack;
+    private static ReadOnlyThreadContextMap readOnlyContextMap;
+
     private static final Logger LOGGER = StatusLogger.getLogger();
 
     static {
@@ -221,6 +224,9 @@ public final class ThreadContext {
         } else {
             contextMap = ThreadContextMapFactory.createThreadContextMap();
         }
+        if (contextMap instanceof ReadOnlyThreadContextMap) {
+            readOnlyContextMap = (ReadOnlyThreadContextMap) contextMap;
+        }
     }
 
     /**
@@ -327,15 +333,23 @@ public final class ThreadContext {
     }
 
     /**
-     * Returns the internal data structure used to store thread context key-value pairs.
-     * <p><em>
-     * This data structure is not intended to be used directly by applications. This method is package protected for
-     * internal log4j2 usage.
-     * </em></p>
-     * @return the internal data structure used to store thread context key-value pairs
+     * Returns a read-only view of the internal data structure used to store thread context key-value pairs,
+     * or {@code null} if the internal data structure does not implement the
+     * {@code ReadOnlyThreadContextMap} interface.
+     * <p>
+     * The {@link DefaultThreadContextMap} implementation does not implement {@code ReadOnlyThreadContextMap}, so by
+     * default this method returns {@code null}.
+     * </p>
+     *
+     * @return the internal data structure used to store thread context key-value pairs or {@code null}
+     * @see ThreadContextMapFactory
+     * @see DefaultThreadContextMap
+     * @see org.apache.logging.log4j.spi.CopyOnWriteSortedArrayThreadContextMap
+     * @see org.apache.logging.log4j.spi.GarbageFreeSortedArrayThreadContextMap
+     * @since 2.8
      */
-    static ThreadContextMap getThreadContextMap() {
-        return contextMap;
+    public static ReadOnlyThreadContextMap getThreadContextMap() {
+        return readOnlyContextMap;
     }
 
     /**