geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From djen...@apache.org
Subject svn commit: r946044 - in /geronimo/server/trunk/plugins/openejb: ./ geronimo-openejb-builder/src/main/java/org/apache/geronimo/openejb/deployment/ geronimo-openejb-clustering-wadi/src/main/java/org/apache/geronimo/openejb/cluster/stateful/deployment/ g...
Date Wed, 19 May 2010 06:33:30 GMT
Author: djencks
Date: Wed May 19 06:33:29 2010
New Revision: 946044

URL: http://svn.apache.org/viewvc?rev=946044&view=rev
Log:
GERONIMO-4918 port singleton support from 2.2

Removed:
    geronimo/server/trunk/plugins/openejb/geronimo-openejb/src/main/java/org/apache/geronimo/openejb/EjbModuleImplGBean.java
Modified:
    geronimo/server/trunk/plugins/openejb/   (props changed)
    geronimo/server/trunk/plugins/openejb/geronimo-openejb-builder/src/main/java/org/apache/geronimo/openejb/deployment/EjbDeploymentBuilder.java
    geronimo/server/trunk/plugins/openejb/geronimo-openejb-builder/src/main/java/org/apache/geronimo/openejb/deployment/EjbModuleBuilder.java
    geronimo/server/trunk/plugins/openejb/geronimo-openejb-clustering-wadi/src/main/java/org/apache/geronimo/openejb/cluster/stateful/deployment/ClusteredStatefulDeployment.java
    geronimo/server/trunk/plugins/openejb/geronimo-openejb/src/main/java/org/apache/geronimo/openejb/EjbDeployment.java
    geronimo/server/trunk/plugins/openejb/geronimo-openejb/src/main/java/org/apache/geronimo/openejb/EjbDeploymentGBean.java
    geronimo/server/trunk/plugins/openejb/geronimo-openejb/src/main/java/org/apache/geronimo/openejb/EjbModuleImpl.java
    geronimo/server/trunk/plugins/openejb/geronimo-openejb/src/main/java/org/apache/geronimo/openejb/GeronimoThreadContextListener.java
    geronimo/server/trunk/plugins/openejb/geronimo-openejb/src/main/java/org/apache/geronimo/openejb/SingletonContainerGBean.java
    geronimo/server/trunk/plugins/openejb/geronimo-openejb/src/test/java/org/apache/geronimo/openejb/GBeanTest.java

Propchange: geronimo/server/trunk/plugins/openejb/
------------------------------------------------------------------------------
--- svn:mergeinfo (added)
+++ svn:mergeinfo Wed May 19 06:33:29 2010
@@ -0,0 +1,2 @@
+/geronimo/server/branches/2.2/plugins/openejb:830343,830385,830420,830443,830766,831498,831811,832538,885058,941914
+/geronimo/server/trunk/plugins/j2ee/openejb:887507

Modified: geronimo/server/trunk/plugins/openejb/geronimo-openejb-builder/src/main/java/org/apache/geronimo/openejb/deployment/EjbDeploymentBuilder.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/plugins/openejb/geronimo-openejb-builder/src/main/java/org/apache/geronimo/openejb/deployment/EjbDeploymentBuilder.java?rev=946044&r1=946043&r2=946044&view=diff
==============================================================================
--- geronimo/server/trunk/plugins/openejb/geronimo-openejb-builder/src/main/java/org/apache/geronimo/openejb/deployment/EjbDeploymentBuilder.java
(original)
+++ geronimo/server/trunk/plugins/openejb/geronimo-openejb-builder/src/main/java/org/apache/geronimo/openejb/deployment/EjbDeploymentBuilder.java
Wed May 19 06:33:29 2010
@@ -28,6 +28,7 @@ import java.util.HashSet;
 import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
+import java.util.Set;
 import java.util.TreeMap;
 
 import org.apache.geronimo.common.DeploymentException;
@@ -40,6 +41,7 @@ import org.apache.geronimo.j2ee.deployme
 import org.apache.geronimo.j2ee.deployment.annotation.AnnotatedEjbJar;
 import org.apache.geronimo.j2ee.jndi.JndiKey;
 import org.apache.geronimo.j2ee.jndi.JndiScope;
+import org.apache.geronimo.j2ee.j2eeobjectnames.NameFactory;
 import org.apache.geronimo.kernel.GBeanAlreadyExistsException;
 import org.apache.geronimo.naming.deployment.AbstractNamingBuilder;
 import org.apache.geronimo.naming.deployment.GBeanResourceEnvironmentBuilder;
@@ -176,9 +178,22 @@ public class EjbDeploymentBuilder {
         }
     }
 
-    public void addEjbModuleDependency(AbstractName ejbModuleName) {
+    private static Set<AbstractName> getResourceDependencies(EARContext earContext)
{
+        AbstractNameQuery cfNameQuery = new AbstractNameQuery(earContext.getConfigID(), Collections.singletonMap(NameFactory.J2EE_TYPE,
NameFactory.JCA_MANAGED_CONNECTION_FACTORY));
+        AbstractNameQuery aoNameQuery = new AbstractNameQuery(earContext.getConfigID(), Collections.singletonMap(NameFactory.J2EE_TYPE,
NameFactory.JCA_ADMIN_OBJECT));
+        AbstractNameQuery raNameQuery = new AbstractNameQuery(earContext.getConfigID(), Collections.singletonMap(NameFactory.J2EE_TYPE,
NameFactory.JCA_RESOURCE_ADAPTER));
+        Set<AbstractName> dependencies = new HashSet<AbstractName>();
+        dependencies.addAll(earContext.findGBeans(cfNameQuery));
+        dependencies.addAll(earContext.findGBeans(aoNameQuery));
+        dependencies.addAll(earContext.findGBeans(raNameQuery));
+        return dependencies;
+    }
+
+    public void addEjbModuleDependency(GBeanData ejbModule) {
+        Set<AbstractName> resourceDependencies = getResourceDependencies(earContext);
         for (GBeanData gbean : gbeans.values()) {
-            gbean.setReferencePattern("EjbModule", ejbModuleName);
+            ejbModule.addDependency(gbean.getAbstractName());
+            gbean.addDependencies(resourceDependencies);
         }
     }
 

Modified: geronimo/server/trunk/plugins/openejb/geronimo-openejb-builder/src/main/java/org/apache/geronimo/openejb/deployment/EjbModuleBuilder.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/plugins/openejb/geronimo-openejb-builder/src/main/java/org/apache/geronimo/openejb/deployment/EjbModuleBuilder.java?rev=946044&r1=946043&r2=946044&view=diff
==============================================================================
--- geronimo/server/trunk/plugins/openejb/geronimo-openejb-builder/src/main/java/org/apache/geronimo/openejb/deployment/EjbModuleBuilder.java
(original)
+++ geronimo/server/trunk/plugins/openejb/geronimo-openejb-builder/src/main/java/org/apache/geronimo/openejb/deployment/EjbModuleBuilder.java
Wed May 19 06:33:29 2010
@@ -69,14 +69,13 @@ import org.apache.geronimo.kernel.Naming
 import org.apache.geronimo.kernel.classloader.TemporaryClassLoader;
 import org.apache.geronimo.kernel.config.Configuration;
 import org.apache.geronimo.kernel.config.ConfigurationStore;
-import org.apache.xbean.osgi.bundle.util.BundleClassLoader;
 import org.apache.geronimo.kernel.repository.Artifact;
 import org.apache.geronimo.kernel.repository.Environment;
 import org.apache.geronimo.kernel.util.FileUtils;
 import org.apache.geronimo.naming.deployment.ResourceEnvironmentSetter;
 import org.apache.geronimo.openejb.EjbContainer;
 import org.apache.geronimo.openejb.EjbDeployment;
-import org.apache.geronimo.openejb.EjbModuleImplGBean;
+import org.apache.geronimo.openejb.EjbModuleImpl;
 import org.apache.geronimo.openejb.OpenEjbSystem;
 import org.apache.geronimo.openejb.xbeans.ejbjar.OpenejbGeronimoEjbJarType;
 import org.apache.geronimo.persistence.PersistenceUnitGBean;
@@ -125,6 +124,7 @@ import org.apache.openejb.jee.oejb2.Reso
 import org.apache.openejb.loader.SystemInstance;
 import org.apache.openejb.util.LinkResolver;
 import org.apache.openejb.util.UniqueDefaultLinkResolver;
+import org.apache.xbean.osgi.bundle.util.BundleClassLoader;
 import org.apache.xmlbeans.XmlCursor;
 import org.apache.xmlbeans.XmlObject;
 import org.osgi.framework.Bundle;
@@ -802,7 +802,7 @@ public class EjbModuleBuilder implements
             }
         }
         // Add JSR77 EJBModule GBean
-        GBeanData ejbModuleGBeanData = new GBeanData(ejbModule.getModuleName(), EjbModuleImplGBean.class);
+        GBeanData ejbModuleGBeanData = new GBeanData(ejbModule.getModuleName(), EjbModuleImpl.class);
         try {
             ejbModuleGBeanData.setReferencePattern("J2EEServer", earContext.getServerName());
             if (!ejbModule.isStandAlone()) {
@@ -828,7 +828,7 @@ public class EjbModuleBuilder implements
         }
 
         // add a depdendency on the ejb module object
-        ejbDeploymentBuilder.addEjbModuleDependency(ejbModuleGBeanData.getAbstractName());
+        ejbDeploymentBuilder.addEjbModuleDependency(ejbModuleGBeanData);
 
         // add the Jacc permissions to the ear
         ComponentPermissions componentPermissions = ejbDeploymentBuilder.buildComponentPermissions();
@@ -900,6 +900,8 @@ public class EjbModuleBuilder implements
 
             // add a dependency from the module to the ra so we can be assured the mdb
             // container exists when this app is started
+            //TODO we are now useing a sledgehammer in EjbDeploymentBuilder and adding any
possibly relevant
+            // dependency to every ejb gbean.
             ejbModuleGBeanData.addDependency(resourceAdapterAbstractName);
         }
         //check that all the mdbs have resource adapters identified.

Modified: geronimo/server/trunk/plugins/openejb/geronimo-openejb-clustering-wadi/src/main/java/org/apache/geronimo/openejb/cluster/stateful/deployment/ClusteredStatefulDeployment.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/plugins/openejb/geronimo-openejb-clustering-wadi/src/main/java/org/apache/geronimo/openejb/cluster/stateful/deployment/ClusteredStatefulDeployment.java?rev=946044&r1=946043&r2=946044&view=diff
==============================================================================
--- geronimo/server/trunk/plugins/openejb/geronimo-openejb-clustering-wadi/src/main/java/org/apache/geronimo/openejb/cluster/stateful/deployment/ClusteredStatefulDeployment.java
(original)
+++ geronimo/server/trunk/plugins/openejb/geronimo-openejb-clustering-wadi/src/main/java/org/apache/geronimo/openejb/cluster/stateful/deployment/ClusteredStatefulDeployment.java
Wed May 19 06:33:29 2010
@@ -22,12 +22,14 @@ package org.apache.geronimo.openejb.clus
 import java.util.Map;
 import java.util.Set;
 
+import javax.naming.Context;
 import org.apache.geronimo.clustering.SessionManager;
 import org.apache.geronimo.connector.outbound.connectiontracking.TrackedConnectionAssociator;
 import org.apache.geronimo.gbean.GBeanInfo;
 import org.apache.geronimo.gbean.GBeanInfoBuilder;
 import org.apache.geronimo.j2ee.j2eeobjectnames.NameFactory;
 import org.apache.geronimo.kernel.Kernel;
+import org.apache.geronimo.openejb.EjbDeployment;
 import org.apache.geronimo.openejb.EjbDeploymentGBean;
 import org.apache.geronimo.openejb.EjbModuleImpl;
 import org.apache.geronimo.openejb.OpenEjbSystem;
@@ -35,11 +37,12 @@ import org.apache.geronimo.openejb.clust
 import org.apache.geronimo.security.jacc.RunAsSource;
 import org.apache.geronimo.transaction.manager.GeronimoTransactionManager;
 import org.apache.openejb.Container;
+import org.apache.openejb.core.CoreDeploymentInfo;
 
 /**
  * @version $Rev:$ $Date:$
  */
-public class ClusteredStatefulDeployment extends EjbDeploymentGBean {
+public class ClusteredStatefulDeployment extends EjbDeployment {
 
     private final SessionManager sessionManager;
 
@@ -61,15 +64,16 @@ public class ClusteredStatefulDeployment
                                        String defaultRole,
                                        String runAsRole,
                                        RunAsSource runAsSource,
-                                       Map<String, Object> componentContext,
+                                       Context componentContext,
                                        Set<String> unshareableResources,
                                        Set<String> applicationManagedSecurityResources,
                                        TrackedConnectionAssociator trackedConnectionAssociator,
-                                       GeronimoTransactionManager transactionManager,
+//                                       GeronimoTransactionManager transactionManager,
                                        OpenEjbSystem openEjbSystem,
-                                       SessionManager sessionManager,
-                                       EjbModuleImpl ejbModule,
-                                       Kernel kernel) throws Exception {
+                                       SessionManager sessionManager//,
+//                                       EjbModuleImpl ejbModule,
+//                                       Kernel kernel
+    ) throws Exception {
         super(objectName,
                 deploymentId,
                 ejbName,
@@ -88,18 +92,16 @@ public class ClusteredStatefulDeployment
                 unshareableResources,
                 applicationManagedSecurityResources,
                 trackedConnectionAssociator,
-                transactionManager,
-                openEjbSystem,
-                ejbModule,
-                kernel);
+                openEjbSystem);
         if (null == sessionManager) {
             throw new IllegalArgumentException("sessionManager is required");
         }
         this.sessionManager = sessionManager;
     }
 
-    protected void start() throws Exception {
-        super.start();
+    @Override
+    protected EjbDeployment initialize(CoreDeploymentInfo deploymentInfo) {
+        super.initialize(deploymentInfo);
 
         Container container = deploymentInfo.getContainer();
         if (null == container) {
@@ -111,18 +113,22 @@ public class ClusteredStatefulDeployment
         }
         SessionManagerTracker sessionManagerTracker = (SessionManagerTracker) container;
         sessionManagerTracker.addSessionManager(deploymentId, sessionManager);
+
+        return this;
     }
 
-    protected void stop() {
-        if (null != deploymentInfo) {
-            Container container = deploymentInfo.getContainer();
+    @Override
+    protected void destroy() {
+        CoreDeploymentInfo info = deploymentInfo.get();
+        if (null != info) {
+            Container container = info.getContainer();
             if (null != container) {
                 SessionManagerTracker sessionManagerTracker = (SessionManagerTracker) container;
                 sessionManagerTracker.removeSessionManager(deploymentId, sessionManager);
             }
         }
 
-        super.stop();
+        super.destroy();
     }
 
     public static final GBeanInfo GBEAN_INFO;

Modified: geronimo/server/trunk/plugins/openejb/geronimo-openejb/src/main/java/org/apache/geronimo/openejb/EjbDeployment.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/plugins/openejb/geronimo-openejb/src/main/java/org/apache/geronimo/openejb/EjbDeployment.java?rev=946044&r1=946043&r2=946044&view=diff
==============================================================================
--- geronimo/server/trunk/plugins/openejb/geronimo-openejb/src/main/java/org/apache/geronimo/openejb/EjbDeployment.java
(original)
+++ geronimo/server/trunk/plugins/openejb/geronimo-openejb/src/main/java/org/apache/geronimo/openejb/EjbDeployment.java
Wed May 19 06:33:29 2010
@@ -19,11 +19,13 @@ package org.apache.geronimo.openejb;
 
 import java.lang.reflect.Method;
 import java.util.Set;
+import java.util.concurrent.atomic.AtomicReference;
 
 import javax.ejb.EJBHome;
 import javax.ejb.EJBLocalHome;
 import javax.ejb.EJBObject;
 import javax.naming.Context;
+import javax.naming.NamingException;
 import javax.security.auth.Subject;
 import javax.security.auth.login.LoginException;
 
@@ -63,7 +65,7 @@ public class EjbDeployment implements EJ
 
     protected final OpenEjbSystem openEjbSystem;
 
-    protected CoreDeploymentInfo deploymentInfo;
+    protected AtomicReference<CoreDeploymentInfo> deploymentInfo = new AtomicReference<CoreDeploymentInfo>();
 
 //    private Context javaCompSubContext;
 
@@ -115,7 +117,7 @@ public class EjbDeployment implements EJ
     }
 
     public CoreDeploymentInfo getDeploymentInfo() {
-        return deploymentInfo;
+        return deploymentInfo.get();
     }
 
     public String getDeploymentId() {
@@ -183,75 +185,75 @@ public class EjbDeployment implements EJ
     }
 
     public EJBHome getEJBHome() {
-        return deploymentInfo.getEJBHome();
+        return getDeploymentInfo().getEJBHome();
     }
 
     public EJBLocalHome getEJBLocalHome() {
-        return deploymentInfo.getEJBLocalHome();
+        return getDeploymentInfo().getEJBLocalHome();
     }
 
     public Object getBusinessLocalHome() {
-        return deploymentInfo.getBusinessLocalHome();
+        return getDeploymentInfo().getBusinessLocalHome();
     }
 
     public Object getBusinessRemoteHome() {
-        return deploymentInfo.getBusinessRemoteHome();
+        return getDeploymentInfo().getBusinessRemoteHome();
     }
 
     public EJBObject getEjbObject(Object primaryKey) {
-        return (EJBObject) EjbObjectProxyHandler.createProxy(deploymentInfo, primaryKey,
InterfaceType.EJB_HOME);
+        return (EJBObject) EjbObjectProxyHandler.createProxy(getDeploymentInfo(), primaryKey,
InterfaceType.EJB_HOME);
     }
 
     public Class getHomeInterface() {
-        return deploymentInfo.getHomeInterface();
+        return getDeploymentInfo().getHomeInterface();
     }
 
     public Class getRemoteInterface() {
-        return deploymentInfo.getRemoteInterface();
+        return getDeploymentInfo().getRemoteInterface();
     }
 
     public Class getLocalHomeInterface() {
-        return deploymentInfo.getLocalHomeInterface();
+        return getDeploymentInfo().getLocalHomeInterface();
     }
 
     public Class getLocalInterface() {
-        return deploymentInfo.getLocalInterface();
+        return getDeploymentInfo().getLocalInterface();
     }
 
     public Class getBeanClass() {
-        return deploymentInfo.getBeanClass();
+        return getDeploymentInfo().getBeanClass();
     }
 
     public Class getBusinessLocalInterface() {
-        return deploymentInfo.getBusinessLocalInterface();
+        return getDeploymentInfo().getBusinessLocalInterface();
     }
 
     public Class getBusinessRemoteInterface() {
-        return deploymentInfo.getBusinessRemoteInterface();
+        return getDeploymentInfo().getBusinessRemoteInterface();
     }
 
     public Class getMdbInterface() {
-        return deploymentInfo.getMdbInterface();
+        return getDeploymentInfo().getMdbInterface();
     }
 
     public Class getServiceEndpointInterface() {
-        return deploymentInfo.getServiceEndpointInterface();
+        return getDeploymentInfo().getServiceEndpointInterface();
     }
 
     public BeanType getComponentType() {
-        return deploymentInfo.getComponentType();
+        return getDeploymentInfo().getComponentType();
     }
 
     public Container getContainer() {
-        return deploymentInfo.getContainer();
+        return getDeploymentInfo().getContainer();
     }
 
     public boolean isBeanManagedTransaction() {
-        return deploymentInfo.isBeanManagedTransaction();
+        return getDeploymentInfo().isBeanManagedTransaction();
     }
 
     public TransactionType getTransactionType(Method method) {
-          return deploymentInfo.getTransactionType(method);
+          return getDeploymentInfo().getTransactionType(method);
     }
     
     public String getObjectName() {
@@ -270,27 +272,26 @@ public class EjbDeployment implements EJ
         return true;
     }
 
-    protected void start() throws Exception {
-        deploymentInfo = (CoreDeploymentInfo) openEjbSystem.getDeploymentInfo(deploymentId);
-        if (deploymentInfo == null) {
-            throw new IllegalStateException("Ejb does not exist " + deploymentId);
-        }
+    protected EjbDeployment initialize(CoreDeploymentInfo deploymentInfo) {
+//        try {
+//            javaCompSubContext = (Context) deploymentInfo.getJndiEnc().lookup("java:comp");
+//            if (componentContext != null) {
+//                javaCompSubContext.bind("geronimo", componentContext);
+//            }
+            deploymentInfo.set(EjbDeployment.class, this);
+
+            this.deploymentInfo.set(deploymentInfo);
 
-//        javaCompSubContext = (Context) deploymentInfo.getJndiEnc().lookup("java:comp");
-//        if (componentContext != null) {
-//            javaCompSubContext.bind("geronimo", componentContext);
+            return this;
+//        } catch (NamingException e) {
+//            throw new IllegalStateException("Unable to complete EjbDeployment initialization",
e);
 //        }
-        synchronized(deploymentInfo){
-            deploymentInfo.set(EjbDeployment.class, this);
-       	    deploymentInfo.notifyAll();
-        }
     }
 
-    protected void stop() {
-        if (deploymentInfo != null) {
-	    deploymentInfo.setDestroyed(true);
-	    deploymentInfo.set(EjbDeployment.class, null);
-	    deploymentInfo = null;
-	}	
+    protected void destroy() {
+        CoreDeploymentInfo info = deploymentInfo.getAndSet(null);
+        if (info != null) {
+            info.set(EjbDeployment.class, null);
+        }
     }
 }

Modified: geronimo/server/trunk/plugins/openejb/geronimo-openejb/src/main/java/org/apache/geronimo/openejb/EjbDeploymentGBean.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/plugins/openejb/geronimo-openejb/src/main/java/org/apache/geronimo/openejb/EjbDeploymentGBean.java?rev=946044&r1=946043&r2=946044&view=diff
==============================================================================
--- geronimo/server/trunk/plugins/openejb/geronimo-openejb/src/main/java/org/apache/geronimo/openejb/EjbDeploymentGBean.java
(original)
+++ geronimo/server/trunk/plugins/openejb/geronimo-openejb/src/main/java/org/apache/geronimo/openejb/EjbDeploymentGBean.java
Wed May 19 06:33:29 2010
@@ -34,7 +34,7 @@ import org.apache.geronimo.security.Secu
 import org.apache.geronimo.security.jacc.RunAsSource;
 import org.apache.geronimo.transaction.manager.GeronimoTransactionManager;
 
-public class EjbDeploymentGBean extends EjbDeployment implements GBeanLifecycle {
+public class EjbDeploymentGBean extends EjbDeployment {
     public EjbDeploymentGBean(String objectName,
                               String deploymentId,
                               String ejbName,
@@ -87,18 +87,6 @@ public class EjbDeploymentGBean extends 
         return EnterpriseNamingContext.createEnterpriseNamingContext(contexts);
     }
 
-    public void doStart() throws Exception {
-        start();
-    }
-
-    public void doStop() throws Exception {
-        stop();
-    }
-
-    public void doFail() {
-        stop();
-    }
-
     // do not use this gbean info, instead use StatelessDeploymentGBean, StatefulDeploymentGBean,
EntityDeploymentGBean, or MessageDrivenDeploymentGBean
     public static final GBeanInfo GBEAN_INFO;
 

Modified: geronimo/server/trunk/plugins/openejb/geronimo-openejb/src/main/java/org/apache/geronimo/openejb/EjbModuleImpl.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/plugins/openejb/geronimo-openejb/src/main/java/org/apache/geronimo/openejb/EjbModuleImpl.java?rev=946044&r1=946043&r2=946044&view=diff
==============================================================================
--- geronimo/server/trunk/plugins/openejb/geronimo-openejb/src/main/java/org/apache/geronimo/openejb/EjbModuleImpl.java
(original)
+++ geronimo/server/trunk/plugins/openejb/geronimo-openejb/src/main/java/org/apache/geronimo/openejb/EjbModuleImpl.java
Wed May 19 06:33:29 2010
@@ -18,6 +18,7 @@ package org.apache.geronimo.openejb;
 
 import java.util.ArrayList;
 import java.util.Collection;
+import java.util.HashMap;
 import java.util.Hashtable;
 import java.util.List;
 import java.util.Map;
@@ -25,7 +26,16 @@ import java.util.Map;
 import javax.management.ObjectName;
 import javax.naming.Context;
 import javax.naming.NamingException;
-
+import org.apache.geronimo.gbean.GBeanLifecycle;
+import org.apache.geronimo.gbean.ReferenceCollection;
+import org.apache.geronimo.gbean.ReferenceCollectionEvent;
+import org.apache.geronimo.gbean.ReferenceCollectionListener;
+import org.apache.geronimo.gbean.annotation.GBean;
+import org.apache.geronimo.gbean.annotation.ParamAttribute;
+import org.apache.geronimo.gbean.annotation.ParamReference;
+import org.apache.geronimo.gbean.annotation.ParamSpecial;
+import org.apache.geronimo.gbean.annotation.SpecialAttributeType;
+import org.apache.geronimo.j2ee.j2eeobjectnames.NameFactory;
 import org.apache.geronimo.j2ee.jndi.ApplicationJndi;
 import org.apache.geronimo.j2ee.management.impl.InvalidObjectNameException;
 import org.apache.geronimo.kernel.Kernel;
@@ -35,16 +45,20 @@ import org.apache.geronimo.management.EJ
 import org.apache.geronimo.management.J2EEApplication;
 import org.apache.geronimo.management.J2EEServer;
 import org.apache.geronimo.naming.enc.EnterpriseNamingContext;
-import org.apache.openejb.assembler.classic.EjbJarInfo;
-import org.apache.openejb.UndeployException;
 import org.apache.openejb.NoSuchApplicationException;
-import org.slf4j.LoggerFactory;
+import org.apache.openejb.UndeployException;
+import org.apache.openejb.DeploymentInfo;
+import org.apache.openejb.core.CoreDeploymentInfo;
+import org.apache.openejb.assembler.classic.EjbJarInfo;
 import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 /**
  * @version $Revision$ $Date$
  */
-public class EjbModuleImpl implements EJBModule {
+
+@GBean(j2eeType = NameFactory.EJB_MODULE)
+public class EjbModuleImpl implements EJBModule, GBeanLifecycle {
     private static final Logger log = LoggerFactory.getLogger(EjbModuleImpl.class);
     private final J2EEServer server;
     private final J2EEApplication application;
@@ -52,13 +66,23 @@ public class EjbModuleImpl implements EJ
     private final Context moduleContext;
     private final String deploymentDescriptor;
     private final String objectName;
-    private final Collection<? extends EJB> ejbs;
+    private final Map<String, EjbDeployment> ejbs = new HashMap<String, EjbDeployment>();
     private final ClassLoader classLoader;
 
     private final OpenEjbSystem openEjbSystem;
     private final EjbJarInfo ejbJarInfo;
 
-    public EjbModuleImpl(String objectName, J2EEServer server, J2EEApplication application,
ApplicationJndi applicationJndi, Map<String, Object> moduleJndi, String deploymentDescriptor,
Collection<? extends EJB> ejbs, ClassLoader classLoader, Kernel kernel, OpenEjbSystem
openEjbSystem, EjbJarInfo ejbJarInfo) throws NamingException {
+    public EjbModuleImpl(@ParamSpecial(type = SpecialAttributeType.objectName) String objectName,
+                              @ParamReference(name = "J2EEServer", namingType = NameFactory.J2EE_SERVER)
J2EEServer server,
+                              @ParamReference(name = "J2EEApplication", namingType = NameFactory.J2EE_APPLICATION)
J2EEApplication application,
+                              @ParamReference(name = "ApplicationJndi", namingType = "GBEAN")
ApplicationJndi applicationJndi,
+                              @ParamAttribute(name = "moduleJndi") Map<String, Object>
moduleJndi,
+                              @ParamAttribute(name = "deploymentDescriptor") String deploymentDescriptor,
+                              @ParamReference(name = "EJBCollection") Collection<? extends
EjbDeployment> ejbs,
+                              @ParamSpecial(type = SpecialAttributeType.classLoader) ClassLoader
classLoader,
+                              @ParamSpecial(type = SpecialAttributeType.kernel)Kernel kernel,
+                              @ParamReference(name = "OpenEjbSystem") OpenEjbSystem openEjbSystem,
+                              @ParamAttribute(name = "ejbJarInfo") EjbJarInfo ejbJarInfo)
throws NamingException {
         this.objectName = objectName;
         ObjectName myObjectName = ObjectNameUtil.getObjectName(objectName);
         verifyObjectName(myObjectName);
@@ -68,7 +92,21 @@ public class EjbModuleImpl implements EJ
         this.applicationJndi = applicationJndi;
         this.moduleContext = EnterpriseNamingContext.livenReferences(moduleJndi, null, kernel,
classLoader, "module/");
         this.deploymentDescriptor = deploymentDescriptor;
-        this.ejbs = ejbs;
+        ((ReferenceCollection) ejbs).addReferenceCollectionListener(new ReferenceCollectionListener()
{
+
+            public void memberAdded(ReferenceCollectionEvent event) {
+                EjbDeployment ejb = (EjbDeployment) event.getMember();
+                addEjb(ejb);
+            }
+
+            public void memberRemoved(ReferenceCollectionEvent event) {
+                EjbDeployment ejb = (EjbDeployment) event.getMember();
+                removeEjb(ejb);
+            }
+        });
+        for (EjbDeployment ejb : ejbs) {
+            addEjb(ejb);
+        }
 
         this.classLoader = classLoader;
 
@@ -76,6 +114,16 @@ public class EjbModuleImpl implements EJ
         this.ejbJarInfo = ejbJarInfo;
     }
 
+    private void removeEjb(EjbDeployment ejb) {
+        GeronimoThreadContextListener.get().removeEjb(ejb.getDeploymentId());
+        ejbs.remove(ejb.getDeploymentId());
+    }
+
+    private void addEjb(EjbDeployment ejb) {
+        ejbs.put(ejb.getDeploymentId(), ejb);
+        GeronimoThreadContextListener.get().addEjb(ejb);
+    }
+
     public String getObjectName() {
         return objectName;
     }
@@ -118,7 +166,7 @@ public class EjbModuleImpl implements EJ
 
         ArrayList<EJB> copy;
         synchronized (ejbs) {
-            copy = new ArrayList<EJB>(ejbs);
+            copy = new ArrayList<EJB>(ejbs.values());
         }
 
         String[] result = new String[copy.size()];
@@ -136,28 +184,37 @@ public class EjbModuleImpl implements EJ
         return moduleContext;
     }
 
-    protected void start() throws Exception {
+    public void doStart() throws Exception {
         openEjbSystem.createEjbJar(ejbJarInfo, classLoader);
+        for (String deploymentId: ejbs.keySet()) {
+            DeploymentInfo deploymentInfo = openEjbSystem.getDeploymentInfo(deploymentId);
+            GeronimoThreadContextListener.get().getEjbDeployment((CoreDeploymentInfo) deploymentInfo);
+        }
     }
 
-    protected void stop() {
+    public void doStop() {
         try {
             openEjbSystem.removeEjbJar(ejbJarInfo, classLoader);
         } catch (NoSuchApplicationException e) {
             log.error("Module does not exist.", e);
         } catch (UndeployException e) {
             List<Throwable> causes = e.getCauses();
-            log.error(e.getMessage()+": Encountered "+causes.size()+" failures.");
+            log.error(e.getMessage() + ": Encountered " + causes.size() + " failures.");
             for (Throwable throwable : causes) {
                 log.info(throwable.toString(), throwable);
             }
         }
     }
 
+    public void doFail() {
+        doStop();
+    }
+
     /**
      * ObjectName must match this pattern:
      * <p/>
      * domain:j2eeType=EJBModule,name=MyName,J2EEServer=MyServer,J2EEApplication=MyApplication
+     * @param objectName object name to verify
      */
     private void verifyObjectName(ObjectName objectName) {
         if (objectName.isPattern()) {

Modified: geronimo/server/trunk/plugins/openejb/geronimo-openejb/src/main/java/org/apache/geronimo/openejb/GeronimoThreadContextListener.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/plugins/openejb/geronimo-openejb/src/main/java/org/apache/geronimo/openejb/GeronimoThreadContextListener.java?rev=946044&r1=946043&r2=946044&view=diff
==============================================================================
--- geronimo/server/trunk/plugins/openejb/geronimo-openejb/src/main/java/org/apache/geronimo/openejb/GeronimoThreadContextListener.java
(original)
+++ geronimo/server/trunk/plugins/openejb/geronimo-openejb/src/main/java/org/apache/geronimo/openejb/GeronimoThreadContextListener.java
Wed May 19 06:33:29 2010
@@ -34,6 +34,14 @@ import org.apache.openejb.core.CoreDeplo
 import org.apache.openejb.core.ThreadContext;
 import org.apache.openejb.core.ThreadContextListener;
 
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.Future;
+import java.util.concurrent.FutureTask;
+import java.util.concurrent.Callable;
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.atomic.AtomicReference;
+
 /**
  * @version $Rev$ $Date$
  */
@@ -51,26 +59,38 @@ public class GeronimoThreadContextListen
         // do nothing.. the goal here is to kick off the onetime init above
     }
 
+    private final Map<String, Deployment> ejbs = new ConcurrentHashMap<String, Deployment>();
+
     private GeronimoThreadContextListener() {
     }
 
+    public static GeronimoThreadContextListener get() {
+        return instance;
+    }
+
+    public void addEjb(EjbDeployment ejbDeployment) {
+        this.ejbs.put(ejbDeployment.getDeploymentId(), new Deployment(ejbDeployment));
+    }
+
+    public void removeEjb(String id) {
+        this.ejbs.remove(id);
+    }
+
+    EjbDeployment getEjbDeployment(CoreDeploymentInfo deploymentInfo) {
+        Deployment deployment = ejbs.get(deploymentInfo.getDeploymentID());
+
+        if (deployment == null) return null;
+
+        return deployment.get(deploymentInfo);
+    }
+
+
     public void contextEntered(ThreadContext oldContext, ThreadContext newContext) {
         CoreDeploymentInfo deploymentInfo = newContext.getDeploymentInfo();
         if (deploymentInfo == null) return;
-        if (deploymentInfo.get(EjbDeployment.class) == null) {
-	    synchronized (deploymentInfo) {
-                if (deploymentInfo.get(EjbDeployment.class) == null) {
-                    if (!deploymentInfo.isDestroyed()) {
-                        try {
-                            deploymentInfo.wait();
-                        } catch (InterruptedException e) {
-                        log.warn("Wait on deploymentInfo interrupted unexpectedly");
-                        }
-                    }
-                }
-            }
-        } 
-        EjbDeployment ejbDeployment = deploymentInfo.get(EjbDeployment.class);
+
+        EjbDeployment ejbDeployment = getEjbDeployment(deploymentInfo);
+
         if (ejbDeployment == null) return;
 
         // Geronimo call context is used to track old state that must be restored
@@ -156,6 +176,59 @@ public class GeronimoThreadContextListen
         }
     }
 
+    private static final class Deployment {
+        private final EjbDeployment geronimoDeployment;
+        private final AtomicReference<Future<EjbDeployment>> initialized = new
AtomicReference<Future<EjbDeployment>>();
+
+        private Deployment(EjbDeployment geronimoDeployment) {
+            this.geronimoDeployment = geronimoDeployment;
+        }
+
+        public EjbDeployment get(final CoreDeploymentInfo openejbDeployment) {
+            try {
+                // Has the deployment been initialized yet?
+
+                // If there is a Future object in the AtomicReference, then
+                // it's either been initialized or is being initialized now.
+                Future<EjbDeployment> initializedRef = initialized.get();
+                if (initializedRef != null) return initializedRef.get();
+
+                // The deployment has not been initialized nor is being initialized
+
+                // We will construct this FutureTask and compete with the
+                // other threads for the right to initialize the deployment
+                FutureTask<EjbDeployment> initializer = new FutureTask<EjbDeployment>(new
Callable<EjbDeployment>() {
+                    public EjbDeployment call() throws Exception {
+                        return geronimoDeployment.initialize(openejbDeployment);
+                    }
+                });
+
+
+                do {
+                    // If our FutureTask was the one to win the slot
+                    // than we are the ones responsisble for initializing
+                    // the deployment while the others wait.
+                    if (initialized.compareAndSet(null, initializer)) {
+                        initializer.run();
+                    }
+
+                    // If we didn't win the slot and no other FutureTask
+                    // has been set by a different thread, than we need
+                    // to try again.
+                } while ((initializedRef = initialized.get()) == null);
+
+
+                // At this point we can safely return the initialized deployment
+                return initializedRef.get();
+            } catch (InterruptedException e) {
+                Thread.interrupted();
+                throw new IllegalStateException("EjbDeployment.initialize() interrupted",
e);
+            } catch (ExecutionException e) {
+                throw new IllegalStateException("EjbDeployment.initialize() failed", e.getCause());
+            }
+        }
+    }
+    
     private static final class GeronimoCallContext {
         private Context oldJndiContext;
         private ConnectorInstanceContext oldConnectorContext;

Modified: geronimo/server/trunk/plugins/openejb/geronimo-openejb/src/main/java/org/apache/geronimo/openejb/SingletonContainerGBean.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/plugins/openejb/geronimo-openejb/src/main/java/org/apache/geronimo/openejb/SingletonContainerGBean.java?rev=946044&r1=946043&r2=946044&view=diff
==============================================================================
--- geronimo/server/trunk/plugins/openejb/geronimo-openejb/src/main/java/org/apache/geronimo/openejb/SingletonContainerGBean.java
(original)
+++ geronimo/server/trunk/plugins/openejb/geronimo-openejb/src/main/java/org/apache/geronimo/openejb/SingletonContainerGBean.java
Wed May 19 06:33:29 2010
@@ -23,8 +23,10 @@ import org.apache.geronimo.gbean.annotat
 import org.apache.geronimo.gbean.annotation.SpecialAttributeType;
 import org.apache.geronimo.gbean.AbstractName;
 import org.apache.openejb.assembler.classic.SingletonSessionContainerInfo;
+import org.apache.openejb.util.Duration;
 
 import java.util.Properties;
+import java.util.concurrent.TimeUnit;
 
 /**
  * @version $Rev$ $Date$
@@ -41,7 +43,9 @@ public class SingletonContainerGBean ext
             @ParamAttribute(name = "accessTimeout") long accessTimeout,
             @ParamAttribute(name = "properties") Properties properties) {
         super(abstractName, SingletonSessionContainerInfo.class, openEjbSystem, provider,
"SINGLETON", properties);
-        set("AccessTimeout", Long.toString(accessTimeout));
+
+        Duration duration = new Duration(accessTimeout, TimeUnit.SECONDS);
+        set("AccessTimeout", duration.toString());
         this.accessTimeout = accessTimeout;
     }
 

Modified: geronimo/server/trunk/plugins/openejb/geronimo-openejb/src/test/java/org/apache/geronimo/openejb/GBeanTest.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/plugins/openejb/geronimo-openejb/src/test/java/org/apache/geronimo/openejb/GBeanTest.java?rev=946044&r1=946043&r2=946044&view=diff
==============================================================================
--- geronimo/server/trunk/plugins/openejb/geronimo-openejb/src/test/java/org/apache/geronimo/openejb/GBeanTest.java
(original)
+++ geronimo/server/trunk/plugins/openejb/geronimo-openejb/src/test/java/org/apache/geronimo/openejb/GBeanTest.java
Wed May 19 06:33:29 2010
@@ -29,7 +29,7 @@ public class GBeanTest extends TestCase 
     }
 
     public void testEjbModuleImplGBean() {
-        GBeanInfo.getGBeanInfo(EjbModuleImplGBean.class.getName(), new MockBundle(getClass().getClassLoader(),
"test", 0L));
+        GBeanInfo.getGBeanInfo(EjbModuleImpl.class.getName(), new MockBundle(getClass().getClassLoader(),
"test", 0L));
     }
 
     public void testEntityDeploymentGBean() {



Mime
View raw message