tuscany-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From antel...@apache.org
Subject svn commit: r1159380 - /tuscany/sca-java-2.x/trunk/modules/core-spi/src/main/java/org/apache/tuscany/sca/context/ThreadMessageContext.java
Date Thu, 18 Aug 2011 19:50:52 GMT
Author: antelder
Date: Thu Aug 18 19:50:52 2011
New Revision: 1159380

URL: http://svn.apache.org/viewvc?rev=1159380&view=rev
Log:
TUSCANY-3906: Apply patch from Eric Larsen for an enhancement to ThreadMessageContext enabling
external tooling to retrieve the previous message context in a given invocation chain.

Modified:
    tuscany/sca-java-2.x/trunk/modules/core-spi/src/main/java/org/apache/tuscany/sca/context/ThreadMessageContext.java

Modified: tuscany/sca-java-2.x/trunk/modules/core-spi/src/main/java/org/apache/tuscany/sca/context/ThreadMessageContext.java
URL: http://svn.apache.org/viewvc/tuscany/sca-java-2.x/trunk/modules/core-spi/src/main/java/org/apache/tuscany/sca/context/ThreadMessageContext.java?rev=1159380&r1=1159379&r2=1159380&view=diff
==============================================================================
--- tuscany/sca-java-2.x/trunk/modules/core-spi/src/main/java/org/apache/tuscany/sca/context/ThreadMessageContext.java
(original)
+++ tuscany/sca-java-2.x/trunk/modules/core-spi/src/main/java/org/apache/tuscany/sca/context/ThreadMessageContext.java
Thu Aug 18 19:50:52 2011
@@ -28,13 +28,31 @@ import org.apache.tuscany.sca.invocation
 public final class ThreadMessageContext {
 
     private static final ThreadLocal<Message> CONTEXT = new ThreadLocal<Message>();
+    
+    private static final ThreadLocal<Message> PREVIOUS_CONTEXT = new ThreadLocal<Message>();
 
     private ThreadMessageContext() {
     }
 
+    /**
+     * Set the WorkContext for the current thread.
+     * The current work context is returned and must be restored after the invocation is
complete.
+     * Typical usage would be:
+     * <pre>
+     *   WorkContext old = PojoWorkContextTunnel.setThreadWorkContext(newContext);
+     *   try {
+     *      ... invoke user code ...
+     *   } finally {
+     *     PojoWorkContextTunnel.setThreadWorkContext(old);
+     *   }
+     * </pre>
+     * @param context
+     * @return the current work context for the thread; this must be restored after the invocation
is made
+     */
     public static Message setMessageContext(Message context) {
         Message old = CONTEXT.get();
         CONTEXT.set(context);
+        PREVIOUS_CONTEXT.set(old);
         return old;
     }
 
@@ -46,6 +64,10 @@ public final class ThreadMessageContext 
     public static Message getMessageContext() {
         return CONTEXT.get();
     }
+    
+    public static Message getPreviousMessageContext() {
+        return PREVIOUS_CONTEXT.get();
+    }
 
     /**
      * Removes and state from the current thread to ensure that
@@ -54,4 +76,8 @@ public final class ThreadMessageContext 
     public static void removeMessageContext() {
         CONTEXT.remove();
     }
+
+    public static void removePreviousMessageContext() {
+        PREVIOUS_CONTEXT.remove();
+    }
 }



Mime
View raw message