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/06 01:25:33 UTC

logging-log4j2 git commit: LOG4J2-1648 SPI interface for putting Object values in the ThreadContextMap (no end-user visible API yet)

Repository: logging-log4j2
Updated Branches:
  refs/heads/master 769612070 -> e0058d672


LOG4J2-1648 SPI interface for putting Object values in the ThreadContextMap (no end-user visible API yet)


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

Branch: refs/heads/master
Commit: e0058d672121a10a3deb88709fda708e51eddcf4
Parents: 7696120
Author: rpopma <rp...@apache.org>
Authored: Sun Nov 6 10:25:23 2016 +0900
Committer: rpopma <rp...@apache.org>
Committed: Sun Nov 6 10:25:23 2016 +0900

----------------------------------------------------------------------
 .../CopyOnWriteSortedArrayThreadContextMap.java | 14 ++++++-
 .../GarbageFreeSortedArrayThreadContextMap.java | 14 ++++++-
 .../log4j/spi/ObjectThreadContextMap.java       | 44 ++++++++++++++++++++
 3 files changed, 68 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/e0058d67/log4j-api/src/main/java/org/apache/logging/log4j/spi/CopyOnWriteSortedArrayThreadContextMap.java
----------------------------------------------------------------------
diff --git a/log4j-api/src/main/java/org/apache/logging/log4j/spi/CopyOnWriteSortedArrayThreadContextMap.java b/log4j-api/src/main/java/org/apache/logging/log4j/spi/CopyOnWriteSortedArrayThreadContextMap.java
index d346d0e..3b91dbb 100644
--- a/log4j-api/src/main/java/org/apache/logging/log4j/spi/CopyOnWriteSortedArrayThreadContextMap.java
+++ b/log4j-api/src/main/java/org/apache/logging/log4j/spi/CopyOnWriteSortedArrayThreadContextMap.java
@@ -34,7 +34,7 @@ import org.apache.logging.log4j.util.PropertiesUtil;
  *
  * @since 2.7
  */
-class CopyOnWriteSortedArrayThreadContextMap implements ReadOnlyThreadContextMap, ThreadContextMap2, CopyOnWrite {
+class CopyOnWriteSortedArrayThreadContextMap implements ReadOnlyThreadContextMap, ObjectThreadContextMap, CopyOnWrite {
 
     /**
      * Property name ({@value} ) for selecting {@code InheritableThreadLocal} (value "true") or plain
@@ -107,6 +107,11 @@ class CopyOnWriteSortedArrayThreadContextMap implements ReadOnlyThreadContextMap
 
     @Override
     public void put(final String key, final String value) {
+        putValue(key, value);
+    }
+
+    @Override
+    public void putValue(final String key, final Object value) {
         StringMap map = localMap.get();
         map = map == null ? createStringMap() : createStringMap(map);
         map.putValue(key, value);
@@ -130,8 +135,13 @@ class CopyOnWriteSortedArrayThreadContextMap implements ReadOnlyThreadContextMap
 
     @Override
     public String get(final String key) {
+        return (String) getValue(key);
+    }
+
+    @Override
+    public Object getValue(final String key) {
         final StringMap map = localMap.get();
-        return map == null ? null : (String) map.getValue(key);
+        return map == null ? null : map.getValue(key);
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/e0058d67/log4j-api/src/main/java/org/apache/logging/log4j/spi/GarbageFreeSortedArrayThreadContextMap.java
----------------------------------------------------------------------
diff --git a/log4j-api/src/main/java/org/apache/logging/log4j/spi/GarbageFreeSortedArrayThreadContextMap.java b/log4j-api/src/main/java/org/apache/logging/log4j/spi/GarbageFreeSortedArrayThreadContextMap.java
index d0ee369..7113d9f 100644
--- a/log4j-api/src/main/java/org/apache/logging/log4j/spi/GarbageFreeSortedArrayThreadContextMap.java
+++ b/log4j-api/src/main/java/org/apache/logging/log4j/spi/GarbageFreeSortedArrayThreadContextMap.java
@@ -34,7 +34,7 @@ import org.apache.logging.log4j.util.SortedArrayStringMap;
  * </p>
  * @since 2.7
  */
-class GarbageFreeSortedArrayThreadContextMap implements ReadOnlyThreadContextMap, ThreadContextMap2  {
+class GarbageFreeSortedArrayThreadContextMap implements ReadOnlyThreadContextMap, ObjectThreadContextMap  {
 
     /**
      * Property name ({@value} ) for selecting {@code InheritableThreadLocal} (value "true") or plain
@@ -115,6 +115,11 @@ class GarbageFreeSortedArrayThreadContextMap implements ReadOnlyThreadContextMap
     }
 
     @Override
+    public void putValue(final String key, final Object value) {
+        getThreadLocalMap().putValue(key, value);
+    }
+
+    @Override
     public void putAll(final Map<String, String> values) {
         if (values == null || values.isEmpty()) {
             return;
@@ -127,8 +132,13 @@ class GarbageFreeSortedArrayThreadContextMap implements ReadOnlyThreadContextMap
 
     @Override
     public String get(final String key) {
+        return (String) getValue(key);
+    }
+
+    @Override
+    public Object getValue(final String key) {
         final StringMap map = localMap.get();
-        return map == null ? null : (String) map.getValue(key);
+        return map == null ? null : map.getValue(key);
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/e0058d67/log4j-api/src/main/java/org/apache/logging/log4j/spi/ObjectThreadContextMap.java
----------------------------------------------------------------------
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
new file mode 100644
index 0000000..a3e3715
--- /dev/null
+++ b/log4j-api/src/main/java/org/apache/logging/log4j/spi/ObjectThreadContextMap.java
@@ -0,0 +1,44 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache license, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the license for the specific language governing permissions and
+ * limitations under the license.
+ */
+package org.apache.logging.log4j.spi;
+
+/**
+ * Extension service provider interface to allow putting Object values in the
+ * {@link org.apache.logging.log4j.ThreadContext}.
+ *
+ * @see ThreadContextMap2
+ * @since 2.8
+ */
+public interface ObjectThreadContextMap extends ThreadContextMap2 {
+
+    /**
+     * 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
+     * @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 value the value to add. Values may be {@code null}.
+     */
+    <V> void putValue(String key, V value);
+}