tomee-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From xuhaih...@apache.org
Subject svn commit: r990059 - in /openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core: ./ entity/ interceptor/ managed/ mdb/ singleton/ stateful/ stateless/
Date Fri, 27 Aug 2010 07:14:26 GMT
Author: xuhaihong
Date: Fri Aug 27 07:14:25 2010
New Revision: 990059

URL: http://svn.apache.org/viewvc?rev=990059&view=rev
Log:
OpenEJB-1196 javax.ejb.EJBContext.getContextData(), use threadlocal to share the context data
from InvocationContext

Modified:
    openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/BaseContext.java
    openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/ThreadContext.java
    openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/entity/EntityContext.java
    openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/interceptor/InterceptorStack.java
    openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/managed/ManagedContext.java
    openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/mdb/MdbContext.java
    openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/singleton/SingletonContext.java
    openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/stateful/StatefulContext.java
    openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/stateless/StatelessContext.java

Modified: openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/BaseContext.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/BaseContext.java?rev=990059&r1=990058&r2=990059&view=diff
==============================================================================
--- openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/BaseContext.java
(original)
+++ openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/BaseContext.java
Fri Aug 27 07:14:25 2010
@@ -29,6 +29,7 @@ import javax.ejb.EJBContext;
 import javax.ejb.EJBHome;
 import javax.ejb.EJBLocalHome;
 import javax.ejb.TimerService;
+import javax.interceptor.InvocationContext;
 import javax.naming.Context;
 import javax.naming.NamingException;
 import javax.transaction.HeuristicMixedException;
@@ -51,7 +52,7 @@ import java.util.Properties;
 public abstract class BaseContext implements EJBContext, Serializable {
 
     public static enum Call {
-        getEJBObject, getEJBLocalObject, isCallerInRole, setRollbackOnly, getCallerPrincipal,
getRollbackOnly, getTimerService, getUserTransaction, getBusinessObject, timerMethod, getInvokedBusinessInterface,
UserTransactionMethod, getMessageContext, getPrimaryKey
+        getEJBObject, getEJBLocalObject, isCallerInRole, setRollbackOnly, getCallerPrincipal,
getRollbackOnly, getTimerService, getUserTransaction, getBusinessObject, timerMethod, getInvokedBusinessInterface,
UserTransactionMethod, getMessageContext, getPrimaryKey, getContextData
 
     }
 
@@ -74,8 +75,10 @@ public abstract class BaseContext implem
     }
 
     public Map<String, Object> getContextData() {
-        throw new UnsupportedOperationException("not yet implemented");
+        check(Call.getContextData);
+        return ThreadContext.getThreadContext().get(InvocationContext.class).getContextData();
     }
+
     public EJBHome getEJBHome() {
         ThreadContext threadContext = ThreadContext.getThreadContext();
         DeploymentInfo di = threadContext.getDeploymentInfo();

Modified: openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/ThreadContext.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/ThreadContext.java?rev=990059&r1=990058&r2=990059&view=diff
==============================================================================
--- openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/ThreadContext.java
(original)
+++ openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/ThreadContext.java
Fri Aug 27 07:14:25 2010
@@ -19,10 +19,11 @@ package org.apache.openejb.core;
 import java.util.HashMap;
 import java.util.List;
 import java.util.concurrent.CopyOnWriteArrayList;
+import java.util.concurrent.atomic.AtomicBoolean;
 
+import org.apache.openejb.core.transaction.TransactionPolicy;
 import org.apache.openejb.util.LogCategory;
 import org.apache.openejb.util.Logger;
-import org.apache.openejb.core.transaction.TransactionPolicy;
 
 public class ThreadContext {
     private static final Logger log = Logger.getInstance(LogCategory.OPENEJB, "org.apache.openejb.util.resources");
@@ -164,7 +165,7 @@ public class ThreadContext {
     public BaseContext.State[] setCurrentAllowedStates(BaseContext.State[] newAllowedStates)
{
         return null;
     }
-    
+
     @SuppressWarnings({"unchecked"})
     public <T> T get(Class<T> type) {
         return (T)data.get(type);
@@ -175,6 +176,11 @@ public class ThreadContext {
         return (T) data.put(type, value);
     }
 
+    @SuppressWarnings({ "unchecked" })
+    public <T> T remove(Class<T> type) {
+        return (T) data.remove(type);
+    }
+
     public boolean isDiscardInstance() {
         return discardInstance;
     }

Modified: openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/entity/EntityContext.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/entity/EntityContext.java?rev=990059&r1=990058&r2=990059&view=diff
==============================================================================
--- openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/entity/EntityContext.java
(original)
+++ openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/entity/EntityContext.java
Fri Aug 27 07:14:25 2010
@@ -89,6 +89,7 @@ public class EntityContext extends BaseC
         final Operation operation = ThreadContext.getThreadContext().getCurrentOperation();
         switch (call) {
             case getUserTransaction:
+            case getContextData:
                 throw illegal(call, operation);
             case getPrimaryKey:
             case getEJBLocalObject:

Modified: openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/interceptor/InterceptorStack.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/interceptor/InterceptorStack.java?rev=990059&r1=990058&r2=990059&view=diff
==============================================================================
--- openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/interceptor/InterceptorStack.java
(original)
+++ openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/interceptor/InterceptorStack.java
Fri Aug 27 07:14:25 2010
@@ -66,6 +66,7 @@ public class InterceptorStack {
                 interceptors.add(interceptor);
             }
         }
+
     }
 
     private static final ThreadLocal<Stack> stack = new ThreadLocal<Stack>();
@@ -118,20 +119,35 @@ public class InterceptorStack {
     }
 
     public Object invoke(Object... parameters) throws Exception {
-        InvocationContext invocationContext = createInvocationContext(parameters);
-        Object value = invocationContext.proceed();
-        return value;
+        try {
+            InvocationContext invocationContext = createInvocationContext(parameters);
+            ThreadContext.getThreadContext().set(InvocationContext.class, invocationContext);
+            Object value = invocationContext.proceed();
+            return value;
+        } finally {
+            ThreadContext.getThreadContext().remove(InvocationContext.class);
+        }
     }
 
     public Object invoke(javax.xml.ws.handler.MessageContext messageContext, Object... parameters)
throws Exception {
-        InvocationContext invocationContext = new JaxWsInvocationContext(operation, interceptors,
beanInstance, targetMethod, messageContext, parameters);
-        Object value = invocationContext.proceed();
-        return value;
+        try {
+            InvocationContext invocationContext = new JaxWsInvocationContext(operation, interceptors,
beanInstance, targetMethod, messageContext, parameters);
+            ThreadContext.getThreadContext().set(InvocationContext.class, invocationContext);
+            Object value = invocationContext.proceed();
+            return value;
+        } finally {
+            ThreadContext.getThreadContext().remove(InvocationContext.class);
+        }
     }
 
     public Object invoke(javax.xml.rpc.handler.MessageContext messageContext, Object... parameters)
throws Exception {
-        InvocationContext invocationContext = new JaxRpcInvocationContext(operation, interceptors,
beanInstance, targetMethod, messageContext, parameters);
-        Object value = invocationContext.proceed();
-        return value;
+        try {
+            InvocationContext invocationContext = new JaxRpcInvocationContext(operation,
interceptors, beanInstance, targetMethod, messageContext, parameters);
+            ThreadContext.getThreadContext().set(InvocationContext.class, invocationContext);
+            Object value = invocationContext.proceed();
+            return value;
+        } finally {
+            ThreadContext.getThreadContext().remove(InvocationContext.class);
+        }
     }
 }

Modified: openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/managed/ManagedContext.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/managed/ManagedContext.java?rev=990059&r1=990058&r2=990059&view=diff
==============================================================================
--- openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/managed/ManagedContext.java
(original)
+++ openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/managed/ManagedContext.java
Fri Aug 27 07:14:25 2010
@@ -45,6 +45,7 @@ public class ManagedContext extends Base
             case getEJBLocalObject:
             case getEJBObject:
             case getBusinessObject:
+            case getContextData:
                 switch (operation) {
                     case INJECTION:
                         throw illegal(call, operation);

Modified: openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/mdb/MdbContext.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/mdb/MdbContext.java?rev=990059&r1=990058&r2=990059&view=diff
==============================================================================
--- openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/mdb/MdbContext.java
(original)
+++ openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/mdb/MdbContext.java
Fri Aug 27 07:14:25 2010
@@ -51,6 +51,7 @@ public class MdbContext extends BaseCont
         switch (call) {
             case getUserTransaction:
             case getTimerService:
+            case getContextData:
                 switch (operation) {
                     case INJECTION:
                         throw illegal(call, operation);

Modified: openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/singleton/SingletonContext.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/singleton/SingletonContext.java?rev=990059&r1=990058&r2=990059&view=diff
==============================================================================
--- openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/singleton/SingletonContext.java
(original)
+++ openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/singleton/SingletonContext.java
Fri Aug 27 07:14:25 2010
@@ -42,6 +42,7 @@ public class SingletonContext extends Ba
             case getBusinessObject:
             case getUserTransaction:
             case getTimerService:
+            case getContextData:
                 switch (operation) {
                     case INJECTION:
                         throw illegal(call, operation);

Modified: openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/stateful/StatefulContext.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/stateful/StatefulContext.java?rev=990059&r1=990058&r2=990059&view=diff
==============================================================================
--- openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/stateful/StatefulContext.java
(original)
+++ openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/stateful/StatefulContext.java
Fri Aug 27 07:14:25 2010
@@ -45,6 +45,7 @@ public class StatefulContext extends Bas
             case getEJBLocalObject:
             case getEJBObject:
             case getBusinessObject:
+            case getContextData:
                 switch (operation) {
                     case INJECTION:
                         throw illegal(call, operation);

Modified: openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/stateless/StatelessContext.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/stateless/StatelessContext.java?rev=990059&r1=990058&r2=990059&view=diff
==============================================================================
--- openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/stateless/StatelessContext.java
(original)
+++ openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/core/stateless/StatelessContext.java
Fri Aug 27 07:14:25 2010
@@ -46,6 +46,7 @@ public class StatelessContext extends Ba
             case getBusinessObject:
             case getUserTransaction:
             case getTimerService:
+            case getContextData:
                 switch (operation) {
                     case INJECTION:
                         throw illegal(call, operation);



Mime
View raw message