jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ju...@apache.org
Subject svn commit: r995002 - /jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/session/SessionState.java
Date Wed, 08 Sep 2010 12:07:33 GMT
Author: jukka
Date: Wed Sep  8 12:07:33 2010
New Revision: 995002

URL: http://svn.apache.org/viewvc?rev=995002&view=rev
Log:
JCR-2741: Improved logging for session operations

Add a jcr.operation variable to MDC and clean up the MDC handling code

Modified:
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/session/SessionState.java

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/session/SessionState.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/session/SessionState.java?rev=995002&r1=995001&r2=995002&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/session/SessionState.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/session/SessionState.java
Wed Sep  8 12:07:33 2010
@@ -123,8 +123,9 @@ public class SessionState {
      */
     public <T> T perform(SessionOperation<T> operation)
             throws RepositoryException {
-        String previous = MDC.get("jcr.session");
-        MDC.put("jcr.session", context.toString());
+        LogState state = new LogState(
+                "jcr.session", context.toString(),
+                "jcr.operation", operation.toString());
         try {
             if (log.isDebugEnabled()) {
                 long start = System.nanoTime();
@@ -138,12 +139,37 @@ public class SessionState {
                 return internalPerform(operation);
             }
         } finally {
-            if (previous != null) {
-                MDC.put("jcr.session", previous);
-            } else {
-                MDC.remove("jcr.session");
+            state.reset();
+        }
+    }
+
+    /**
+     * Internal utility class for setting MDC variables during the execution
+     * of a session operation.
+     */
+    private static class LogState {
+
+        private final String[] keyValuePairs;
+
+        public LogState(String... keyValuePairs) {
+            this.keyValuePairs = keyValuePairs;
+            for (int i = 0; i + 1 < keyValuePairs.length; i += 2) {
+                if (MDC.get(keyValuePairs[i]) == null) {
+                    MDC.put(keyValuePairs[i], keyValuePairs[i + 1]);
+                } else {
+                    keyValuePairs[i + 1] = null;
+                }
             }
         }
+
+        public void reset() {
+            for (int i = 0; i + 1 < keyValuePairs.length; i += 2) {
+                if (keyValuePairs[i + 1] != null) {
+                    MDC.remove(keyValuePairs[i]);
+                }
+            }
+        }
+
     }
 
     /**



Mime
View raw message