[logback-dev] [GIT] Logback: the generic, reliable, fast and flexible logging framework. branch, master, updated. v_0.9.25-8-g13500de
added by portage for gitosis-gentoo
git-noreply at pixie.qos.ch
Mon Oct 18 22:58:59 CEST 2010
This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "Logback: the generic, reliable, fast and flexible logging framework.".
The branch, master has been updated
via 13500debebed9bb352c9216ab295ec21a8cbe59a (commit)
from 93995946b59b3ed1622d92c06b39c21942d98c58 (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
http://git.qos.ch/gitweb/?p=logback.git;a=commit;h=13500debebed9bb352c9216ab295ec21a8cbe59a
http://github.com/ceki/logback/commit/13500debebed9bb352c9216ab295ec21a8cbe59a
commit 13500debebed9bb352c9216ab295ec21a8cbe59a
Author: Ceki Gulcu <ceki at qos.ch>
Date: Mon Oct 18 22:56:41 2010 +0200
Solve LBCLASSIC-183. Use InheritableThreadLocal instead of
CopyOnInheritThreadLocal. This is sage given the implementaiton of the
LogbackMDCAdapter.put method.
diff --git a/logback-classic/src/main/java/ch/qos/logback/classic/util/LogbackMDCAdapter.java b/logback-classic/src/main/java/ch/qos/logback/classic/util/LogbackMDCAdapter.java
index 2c4f807..83129b9 100644
--- a/logback-classic/src/main/java/ch/qos/logback/classic/util/LogbackMDCAdapter.java
+++ b/logback-classic/src/main/java/ch/qos/logback/classic/util/LogbackMDCAdapter.java
@@ -24,23 +24,25 @@ import org.slf4j.spi.MDCAdapter;
* distinguishing interleaved log output from different sources. Log output is
* typically interleaved when a server handles multiple clients
* near-simultaneously.
- * <p>
+ * <p/>
* <b><em>The MDC is managed on a per thread basis</em></b>. A child thread
* automatically inherits a <em>copy</em> of the mapped diagnostic context of
* its parent.
- * <p>
- *
+ * <p/>
+ * <p/>
* For more information about MDC, please refer to the online manual at
* http://logback.qos.ch/manual/mdc.html
- *
+ *
* @author Ceki Gülcü
*/
public class LogbackMDCAdapter implements MDCAdapter {
- // final CopyOnInheritThreadLocal copyOnInheritThreadLocal = new
- // CopyOnInheritThreadLocal();
- final CopyOnInheritThreadLocal copyOnInheritThreadLocal = new CopyOnInheritThreadLocal();
+ // We no longer use CopyOnInheritThreadLocal in order to solve LBCLASSIC-183
+ // Initially the contents of the thread local in parent and child threads
+ // reference the same map. However, as soon as a thread invokes the put()
+ // method, the maps diverge as they should.
+ final InheritableThreadLocal<HashMap<String, String>> copyOnInheritThreadLocal = new InheritableThreadLocal<HashMap<String, String>>();
public LogbackMDCAdapter() {
}
@@ -49,19 +51,18 @@ public class LogbackMDCAdapter implements MDCAdapter {
* Put a context value (the <code>val</code> parameter) as identified with the
* <code>key</code> parameter into the current thread's context map. Note that
* contrary to log4j, the <code>val</code> parameter can be null.
- *
- * <p>
+ * <p/>
+ * <p/>
* If the current thread does not have a context map it is created as a side
* effect of this call.
- *
- * <p>
+ * <p/>
+ * <p/>
* Each time a value is added, a new instance of the map is created. This is
* to be certain that the serialization process will operate on the updated
* map and not send a reference to the old map, thus not allowing the remote
* logback component to see the latest changes.
- *
- * @throws IllegalArgumentException
- * in case the "key" parameter is null
+ *
+ * @throws IllegalArgumentException in case the "key" parameter is null
*/
public void put(String key, String val) throws IllegalArgumentException {
if (key == null) {
@@ -81,8 +82,8 @@ public class LogbackMDCAdapter implements MDCAdapter {
/**
* Get the context identified by the <code>key</code> parameter.
- *
- * <p>
+ * <p/>
+ * <p/>
* This method has no side effects.
*/
public String get(String key) {
@@ -97,15 +98,15 @@ public class LogbackMDCAdapter implements MDCAdapter {
/**
* Remove the the context identified by the <code>key</code> parameter.
- *
- * <p>
+ * <p/>
+ * <p/>
* Each time a value is removed, a new instance of the map is created. This is
* to be certain that the serialization process will operate on the updated
* map and not send a reference to the old map, thus not allowing the remote
* logback component to see the latest changes.
*/
public void remove(String key) {
- if(key == null) {
+ if (key == null) {
return;
}
HashMap<String, String> oldMap = copyOnInheritThreadLocal.get();
diff --git a/logback-classic/src/test/java/ch/qos/logback/classic/util/LogbackMDCAdapterTest.java b/logback-classic/src/test/java/ch/qos/logback/classic/util/LogbackMDCAdapterTest.java
index a88d9d0..8edb657 100644
--- a/logback-classic/src/test/java/ch/qos/logback/classic/util/LogbackMDCAdapterTest.java
+++ b/logback-classic/src/test/java/ch/qos/logback/classic/util/LogbackMDCAdapterTest.java
@@ -28,31 +28,32 @@ import ch.qos.logback.core.testUtil.RandomUtil;
public class LogbackMDCAdapterTest {
final static String A_SUFFIX = "A_SUFFIX";
+ final static String B_SUFFIX = "B_SUFFIX";
int diff = RandomUtil.getPositiveInt();
/**
- * Test that CopyOnInheritThreadLocal does not barf when the
+ * Test that CopyOnInheritThreadLocal does not barf when the
* MDC hashmap is null
- *
+ *
* @throws InterruptedException
*/
@Test
- public void lbclassic77() throws InterruptedException {
+ public void lbclassic77Test() throws InterruptedException {
LogbackMDCAdapter lma = new LogbackMDCAdapter();
HashMap<String, String> parentHM = getHashMapFromMDCAdapter(lma);
assertNull(parentHM);
-
+
ChildThreadForMDCAdapter childThread = new ChildThreadForMDCAdapter(lma);
childThread.start();
childThread.join();
assertTrue(childThread.successul);
assertNull(childThread.childHM);
}
-
+
@Test
- public void removeForNullKey() {
+ public void removeForNullKeyTest() {
LogbackMDCAdapter lma = new LogbackMDCAdapter();
lma.remove(null);
}
@@ -62,7 +63,7 @@ public class LogbackMDCAdapterTest {
LogbackMDCAdapter lma = new LogbackMDCAdapter();
lma.remove("abcdlw0");
}
-
+
class ChildThreadForMDCAdapter extends Thread {
LogbackMDCAdapter logbackMDCAdapter;
@@ -72,7 +73,7 @@ public class LogbackMDCAdapterTest {
ChildThreadForMDCAdapter(LogbackMDCAdapter logbackMDCAdapter) {
this.logbackMDCAdapter = logbackMDCAdapter;
}
-
+
@Override
public void run() {
childHM = getHashMapFromMDCAdapter(logbackMDCAdapter);
@@ -82,30 +83,43 @@ public class LogbackMDCAdapterTest {
}
// =================================================
+
/**
* Test that LogbackMDCAdapter copies its hashmap when a child
* thread inherits it.
- *
+ *
* @throws InterruptedException
*/
@Test
- public void copyOnInheritence() throws InterruptedException {
+ public void copyOnInheritenceTest() throws InterruptedException {
String mdcKey = "x" + diff;
String otherMDCKey = "o" + diff;
MDC.put(mdcKey, mdcKey + A_SUFFIX);
- HashMap<String, String> parentHM = getHashMapFromMDC();
ChildThreadForMDC childThread = new ChildThreadForMDC(mdcKey, otherMDCKey);
childThread.start();
+ MDC.put(mdcKey, mdcKey + B_SUFFIX);
childThread.join();
assertNull(MDC.get(otherMDCKey));
assertTrue(childThread.successul);
+
+ HashMap<String, String> parentHM = getHashMapFromMDC();
assertTrue(parentHM != childThread.childHM);
+
+ HashMap<String, String> parentHMWitness = new HashMap<String, String>();
+ parentHMWitness.put(mdcKey, mdcKey + B_SUFFIX);
+ assertEquals(parentHMWitness, parentHM);
+
+ HashMap<String, String> childHMWitness = new HashMap<String, String>();
+ childHMWitness.put(mdcKey, mdcKey + A_SUFFIX);
+ childHMWitness.put(otherMDCKey, otherMDCKey + A_SUFFIX);
+ assertEquals(childHMWitness, childThread.childHM);
+
}
-
+
class ChildThreadForMDC extends Thread {
String mdcKey;
@@ -120,24 +134,23 @@ public class LogbackMDCAdapterTest {
@Override
public void run() {
- childHM = getHashMapFromMDC();
-
MDC.put(otherMDCKey, otherMDCKey + A_SUFFIX);
assertNotNull(MDC.get(mdcKey));
assertEquals(mdcKey + A_SUFFIX, MDC.get(mdcKey));
assertEquals(otherMDCKey + A_SUFFIX, MDC.get(otherMDCKey));
successul = true;
+ childHM = getHashMapFromMDC();
}
}
HashMap<String, String> getHashMapFromMDCAdapter(LogbackMDCAdapter lma) {
- CopyOnInheritThreadLocal copyOnInheritThreadLocal = lma.copyOnInheritThreadLocal;
+ InheritableThreadLocal<HashMap<String, String>> copyOnInheritThreadLocal = lma.copyOnInheritThreadLocal;
return copyOnInheritThreadLocal.get();
}
HashMap<String, String> getHashMapFromMDC() {
LogbackMDCAdapter lma = (LogbackMDCAdapter) MDC.getMDCAdapter();
- CopyOnInheritThreadLocal copyOnInheritThreadLocal = lma.copyOnInheritThreadLocal;
+ InheritableThreadLocal<HashMap<String, String>> copyOnInheritThreadLocal = lma.copyOnInheritThreadLocal;
return copyOnInheritThreadLocal.get();
}
}
-----------------------------------------------------------------------
Summary of changes:
.../logback/classic/util/LogbackMDCAdapter.java | 39 +++++++++--------
.../classic/util/LogbackMDCAdapterTest.java | 45 +++++++++++++-------
2 files changed, 49 insertions(+), 35 deletions(-)
hooks/post-receive
--
Logback: the generic, reliable, fast and flexible logging framework.
More information about the logback-dev
mailing list