Skip to main content

[glassfish~svn:62942] Porting changes from 4.0 branch to trunk. QL and ejb dev tests passed.

  • From: mk111283@...
  • To: commits@...
  • Subject: [glassfish~svn:62942] Porting changes from 4.0 branch to trunk. QL and ejb dev tests passed.
  • Date: Fri, 8 Nov 2013 23:15:20 +0000

Project:    glassfish
Repository: svn
Revision:   62942
Author:     mk111283
Date:       2013-11-08 23:15:15 UTC
Link:       

Log Message:
------------
Porting changes from 4.0 branch to trunk. QL and ejb dev tests passed.


Revisions:
----------
62942


Modified Paths:
---------------
trunk/main/nucleus/common/glassfish-api/src/main/java/org/glassfish/api/invocation/ComponentInvocation.java
trunk/main/appserver/concurrent/concurrent-impl/src/main/java/org/glassfish/concurrent/runtime/ContextSetupProviderImpl.java
trunk/main/appserver/ejb/ejb-container/src/main/java/com/sun/ejb/containers/EjbAsyncInvocationManager.java
trunk/main/appserver/ejb/ejb-container/src/main/java/com/sun/ejb/containers/AbstractSingletonContainer.java
trunk/main/appserver/ejb/ejb-container/src/main/java/com/sun/ejb/EjbInvocation.java


Diffs:
------
Index: 
trunk/main/nucleus/common/glassfish-api/src/main/java/org/glassfish/api/invocation/ComponentInvocation.java
===================================================================
--- 
trunk/main/nucleus/common/glassfish-api/src/main/java/org/glassfish/api/invocation/ComponentInvocation.java
 (revision 62941)
+++ 
trunk/main/nucleus/common/glassfish-api/src/main/java/org/glassfish/api/invocation/ComponentInvocation.java
 (revision 62942)
@@ -244,6 +244,16 @@
         registry.put(key, payLoad);
     }
 
+    //In most of the cases we don't want registry entries from being reused 
in the cloned
+    //  invocation, in which case, this method must be called. I am not sure 
if async
+    //  ejb invocation must call this (It never did and someone in ejb team 
must investigate
+    //  if clearRegistry() must be called from EjbAsyncInvocationManager)
+    public void clearRegistry() {
+        if (registry != null) {
+            registry.clear();
+        }
+    }
+
     public boolean isPreInvokeDone() {
         return preInvokeDoneStatus;
     }
Index: 
trunk/main/appserver/concurrent/concurrent-impl/src/main/java/org/glassfish/concurrent/runtime/ContextSetupProviderImpl.java
===================================================================
--- 
trunk/main/appserver/concurrent/concurrent-impl/src/main/java/org/glassfish/concurrent/runtime/ContextSetupProviderImpl.java
        (revision 62941)
+++ 
trunk/main/appserver/concurrent/concurrent-impl/src/main/java/org/glassfish/concurrent/runtime/ContextSetupProviderImpl.java
        (revision 62942)
@@ -215,16 +215,21 @@
     }
 
     private ComponentInvocation 
createComponentInvocation(ComponentInvocation currInv) {
-        ComponentInvocation newInv = new ComponentInvocation(
-                currInv.getComponentId(),
-                
ComponentInvocation.ComponentInvocationType.SERVLET_INVOCATION,
-                currInv.getContainer(),
-                currInv.getAppName(),
-                currInv.getModuleName()
-        );
+//        ComponentInvocation newInv = new ComponentInvocation(
+//                currInv.getComponentId(),
+//                
ComponentInvocation.ComponentInvocationType.SERVLET_INVOCATION,
+//                currInv.getContainer(),
+//                currInv.getAppName(),
+//                currInv.getModuleName()
+//        );
+        ComponentInvocation newInv = currInv.clone();
+        newInv.setResourceTableKey(null);
         newInv.instance = currInv.getInstance();
-        if (naming) {
-            newInv.setJNDIEnvironment(currInv.getJNDIEnvironment());
+//        if (naming) {
+//            newInv.setJNDIEnvironment(currInv.getJNDIEnvironment());
+//        }
+        if (!naming) {
+            newInv.setJNDIEnvironment(null);
         }
         return newInv;
     }
Index: 
trunk/main/appserver/ejb/ejb-container/src/main/java/com/sun/ejb/containers/EjbAsyncInvocationManager.java
===================================================================
--- 
trunk/main/appserver/ejb/ejb-container/src/main/java/com/sun/ejb/containers/EjbAsyncInvocationManager.java
  (revision 62941)
+++ 
trunk/main/appserver/ejb/ejb-container/src/main/java/com/sun/ejb/containers/EjbAsyncInvocationManager.java
  (revision 62942)
@@ -117,6 +117,21 @@
         //so that the inv is *NOT* shared between the
         //current thread and the executor service thread
         EjbInvocation asyncInv = inv.clone();
+
+        //EjbInvocation.clone clears the txOpsManager field so 
getTransactionOperationsManager()
+        // returns null *after* EjbInvocation.clone(). However, in this 
case, we do want the original
+        // TransactionOperationsManager so we explicitly set it after 
calling clone.
+        //
+        //Note: EjbInvocation implements TransactionOperationsManager so we 
can use asyncInv to
+        //  be the TransactionOperationsManager for the new cloned invocation
+        asyncInv.setTransactionOperationsManager(asyncInv);
+
+        //In most of the cases we don't want registry entries from being 
reused in the cloned
+        //  invocation, in which case, this method must be called. I am not 
sure if async
+        //  ejb invocation must call this (It never did and someone in ejb 
team must investigate
+        //  if clearRegistry() must be called from here)
+
+
         inv.clearYetToSubmitStatus();
         asyncInv.clearYetToSubmitStatus();
 
Index: 
trunk/main/appserver/ejb/ejb-container/src/main/java/com/sun/ejb/containers/AbstractSingletonContainer.java
===================================================================
--- 
trunk/main/appserver/ejb/ejb-container/src/main/java/com/sun/ejb/containers/AbstractSingletonContainer.java
 (revision 62941)
+++ 
trunk/main/appserver/ejb/ejb-container/src/main/java/com/sun/ejb/containers/AbstractSingletonContainer.java
 (revision 62942)
@@ -42,10 +42,7 @@
 
 import java.lang.reflect.Method;
 import java.rmi.RemoteException;
-import java.util.concurrent.ConcurrentHashMap;
-import java.util.ArrayList;
 import java.util.HashMap;
-import java.util.List;
 import java.util.Map;
 import java.util.Set;
 import java.util.concurrent.atomic.AtomicBoolean;
@@ -55,9 +52,6 @@
 import javax.ejb.NoSuchEJBException;
 import javax.ejb.NoSuchObjectLocalException;
 import javax.ejb.RemoveException;
-import javax.transaction.Synchronization;
-import javax.transaction.Transaction;
-import javax.transaction.TransactionManager;
 
 import com.sun.ejb.ComponentContext;
 import com.sun.ejb.Container;
@@ -73,7 +67,6 @@
 import com.sun.enterprise.security.SecurityManager;
 import com.sun.enterprise.util.Utility;
 import org.glassfish.api.invocation.ComponentInvocation;
-import org.glassfish.api.invocation.ResourceHandler;
 import org.glassfish.ejb.deployment.descriptor.EjbDescriptor;
 import org.glassfish.ejb.startup.SingletonLifeCycleManager;
 
@@ -186,7 +179,7 @@
         // concurrent invocations.  Instead, set the resource
         // handler on the invocation to provide a different
         // resource List for each Singleton invocation. 
-        
inv.setResourceHandler(ResourceHandlerImpl.getResourceHandler(transactionManager));
+        
inv.setResourceHandler(SimpleEjbResourceHandlerImpl.getResourceHandler(transactionManager));
     }
 
     protected void initializeHome()
@@ -289,10 +282,6 @@
     public EJBLocalObjectImpl createEJBLocalBusinessObjectImpl(boolean 
localBeanView)
         throws CreateException
     {  
-           ejbProbeNotifier.ejbBeanCreatedEvent(getContainerId(),
-                containerInfo.appName, containerInfo.modName,
-                containerInfo.ejbName);
-
         // No access checks needed because this is called as a result
         // of an internal creation, not a user-visible create method.
         return (localBeanView)
@@ -726,73 +715,7 @@
         return 1;
     }
 
-    private static class ResourceHandlerImpl implements ResourceHandler, 
Synchronization {
-        private static Map<Transaction, ResourceHandlerImpl> 
_resourceHandlers = 
-                new ConcurrentHashMap<Transaction, ResourceHandlerImpl>();
+    //The inner class ResourceHandlerImpl has been moved into its own (top 
level) class called
+    // SimpleEjbResourceHandlerImpl because it is now used by 
EjbInvocation.clone() method also.
+}
 
-        private List l = null;
-        private Transaction tx = null;
-        private TransactionManager tm = null;
-
-        private ResourceHandlerImpl(TransactionManager tm) { 
-            this.tm = tm;
-            checkTransaction();
-        }
-
-        public static ResourceHandler getResourceHandler(TransactionManager 
tm) {
-            ResourceHandlerImpl rh = null;
-            try {
-                Transaction tx = tm.getTransaction();
-                if (tx != null) {
-                    rh = _resourceHandlers.get(tx);
-                }
-            } catch (Exception e) {
-                _logger.log(Level.WARNING, "Exception during Singleton 
ResourceHandler processing", e);
-            }
-
-            if (rh == null) {
-                rh = new ResourceHandlerImpl(tm);
-            }
-
-            return rh;
-        }
-
-        public List getResourceList() {
-            if (tx == null) {
-                checkTransaction();
-            }
-
-            if( l == null ) {
-                l = new ArrayList();
-            }
-            return l;
-        }
-
-        public void beforeCompletion() {
-            // do nothing
-        }
-
-        public void afterCompletion(int status) {
-            if (tx != null) {
-                _resourceHandlers.remove(tx);
-                tx = null;
-            }
-        }
-
-        private void checkTransaction() {
-            try {
-                tx = tm.getTransaction();
-                if (tx != null) {
-                    tx.registerSynchronization(this);
-                    _resourceHandlers.put(tx, this);
-                }
-            } catch (Exception e) {
-                tx = null;
-                _logger.log(Level.WARNING, "Exception during Singleton 
ResourceHandler processing", e);
-            }
-        }
-
-    }
-
-} 
-
Index: 
trunk/main/appserver/ejb/ejb-container/src/main/java/com/sun/ejb/EjbInvocation.java
===================================================================
--- 
trunk/main/appserver/ejb/ejb-container/src/main/java/com/sun/ejb/EjbInvocation.java
 (revision 62941)
+++ 
trunk/main/appserver/ejb/ejb-container/src/main/java/com/sun/ejb/EjbInvocation.java
 (revision 62942)
@@ -43,11 +43,8 @@
 //XXX: import javax.xml.rpc.handler.MessageContext;
 /* HARRY : JACC Changes */
 
-import com.sun.ejb.containers.BaseContainer;
+import com.sun.ejb.containers.*;
 import com.sun.enterprise.deployment.MethodDescriptor;
-import com.sun.ejb.containers.EJBLocalRemoteObject;
-import com.sun.ejb.containers.EjbFutureTask;
-import com.sun.ejb.containers.EJBContextImpl;
 import org.glassfish.api.invocation.ComponentInvocation;
 import org.glassfish.api.invocation.ResourceHandler;
 import com.sun.enterprise.transaction.spi.TransactionOperationsManager;
@@ -65,9 +62,8 @@
 import java.lang.reflect.Method;
 import java.rmi.UnmarshalException;
 import java.util.HashMap;
-import java.util.HashSet;
 import java.util.Map;
-import java.util.Set;
+
 import com.sun.ejb.containers.interceptors.InterceptorManager;
 import com.sun.enterprise.deployment.EjbBundleDescriptor;
 
@@ -87,6 +83,8 @@
   
 
     public ComponentContext context;
+
+    private TransactionOperationsManager transactionOperationsManager;
     
     EjbInvocation(String compEnvId, Container container) {
         super.componentId = compEnvId;
@@ -96,6 +94,11 @@
         EjbBundleDescriptor ejbBundleDesc = 
container.getEjbDescriptor().getEjbBundleDescriptor();
         moduleName = ejbBundleDesc.getModuleName();
         appName = ejbBundleDesc.getApplication().getAppName();
+
+        //By default we enable TransactionOperationsManager checks. But 
EjbInvocation.clone()
+        //  clears transactionOperationsManager so that, be default, cloned 
invocations
+        //  doesn't enforce Transaction Operations checks.
+        transactionOperationsManager = this;
     }
 
     /**
@@ -335,7 +338,24 @@
         newInv.clientTx = null;
         newInv.preInvokeTxStatus = null;
         newInv.originalContextClassLoader = null;
-        
+
+        //The cloned invocation contains a ResourceHandler that points to 
the same
+        //  resource list as the original invocation. If any one of these 
resource lists
+        //  are modified, then we may get a ConcurrentModification exception.
+        //
+        //To avoid this, we will create a new ResourceHandler for the cloned 
invocation. I
+        //  have simply reused SimpleEjbResourceHandlerImpl that was used in 
async Ejb invocation.
+        
newInv.setResourceHandler(SimpleEjbResourceHandlerImpl.createResourceHandler(EjbContainerUtilImpl.getInstance().getTransactionManager()));
+
+        //The cloned invocation is most likely to be used for running a 
batch task.
+        //  In this case, we don't want TransactionOperationsManager 
restricting the Batch runtime
+        //  from performing a java:comp/UserTransaction lookup. So, we 
explicitly set a null
+        //  TransactionOperationsManager in this case.
+        newInv.setTransactionOperationsManager(null);
+
+        //We also don't want any JPA EMs registry entries from being shared.
+        newInv.clearRegistry();
+
         return newInv;
     }
 
@@ -413,9 +433,15 @@
 
     @Override
     public Object getTransactionOperationsManager() {
-        return this;
+        return transactionOperationsManager;
     }
 
+    public void setTransactionOperationsManager(TransactionOperationsManager 
transactionOperationsManager) {
+        //Note: clone() clears transactionOperationsManager so that, be 
default, cloned invocations
+        //  doesn't enforce Transaction Operations checks.
+        this.transactionOperationsManager = transactionOperationsManager;
+    }
+
     //Implementation of TransactionOperationsManager methods
     
     /**





[glassfish~svn:62942] Porting changes from 4.0 branch to trunk. QL and ejb dev tests passed.

mk111283 11/08/2013
 
 
Close
loading
Please Confirm
Close