You are viewing a plain text version of this content. The canonical link for it is here.
Posted to scm@geronimo.apache.org by jg...@apache.org on 2005/12/18 01:20:40 UTC

svn commit: r357408 - in /geronimo/branches/1.0: configs/tomcat/src/plan/ modules/tomcat-builder/src/test/org/apache/geronimo/tomcat/deployment/ modules/tomcat/src/java/org/apache/geronimo/tomcat/ modules/tomcat/src/test/org/apache/geronimo/tomcat/

Author: jgenender
Date: Sat Dec 17 16:20:34 2005
New Revision: 357408

URL: http://svn.apache.org/viewcvs?rev=357408&view=rev
Log:
Fixed race condition in Tomcat by specifying the defaultHost as a GBean in the Engine

Modified:
    geronimo/branches/1.0/configs/tomcat/src/plan/plan.xml
    geronimo/branches/1.0/modules/tomcat-builder/src/test/org/apache/geronimo/tomcat/deployment/TomcatModuleBuilderTest.java
    geronimo/branches/1.0/modules/tomcat/src/java/org/apache/geronimo/tomcat/BaseGBean.java
    geronimo/branches/1.0/modules/tomcat/src/java/org/apache/geronimo/tomcat/EngineGBean.java
    geronimo/branches/1.0/modules/tomcat/src/java/org/apache/geronimo/tomcat/HostGBean.java
    geronimo/branches/1.0/modules/tomcat/src/test/org/apache/geronimo/tomcat/AbstractWebModuleTest.java
    geronimo/branches/1.0/modules/tomcat/src/test/org/apache/geronimo/tomcat/ContainerTest.java

Modified: geronimo/branches/1.0/configs/tomcat/src/plan/plan.xml
URL: http://svn.apache.org/viewcvs/geronimo/branches/1.0/configs/tomcat/src/plan/plan.xml?rev=357408&r1=357407&r2=357408&view=diff
==============================================================================
--- geronimo/branches/1.0/configs/tomcat/src/plan/plan.xml (original)
+++ geronimo/branches/1.0/configs/tomcat/src/plan/plan.xml Sat Dec 17 16:20:34 2005
@@ -118,8 +118,10 @@
         <attribute name="className">org.apache.geronimo.tomcat.TomcatEngine</attribute>
         <attribute name="initParams">
             name=Geronimo
-            defaultHost=${PlanServerHostname}
         </attribute>
+        <reference name="DefaultHost">
+            <name>TomcatHost</name>
+        </reference>
         <references name="Hosts">
             <pattern>
                 <gbean-name>geronimo.server:j2eeType=Host,*</gbean-name>

Modified: geronimo/branches/1.0/modules/tomcat-builder/src/test/org/apache/geronimo/tomcat/deployment/TomcatModuleBuilderTest.java
URL: http://svn.apache.org/viewcvs/geronimo/branches/1.0/modules/tomcat-builder/src/test/org/apache/geronimo/tomcat/deployment/TomcatModuleBuilderTest.java?rev=357408&r1=357407&r2=357408&view=diff
==============================================================================
--- geronimo/branches/1.0/modules/tomcat-builder/src/test/org/apache/geronimo/tomcat/deployment/TomcatModuleBuilderTest.java (original)
+++ geronimo/branches/1.0/modules/tomcat-builder/src/test/org/apache/geronimo/tomcat/deployment/TomcatModuleBuilderTest.java Sat Dec 17 16:20:34 2005
@@ -419,10 +419,10 @@
         // Default Engine
         initParams.clear();
         initParams.put("name", "Geronimo");
-        initParams.put("defaultHost", "localhost");
         engine = new GBeanData(engineName, EngineGBean.GBEAN_INFO);
         engine.setAttribute("className", "org.apache.geronimo.tomcat.TomcatEngine");
         engine.setAttribute("initParams", initParams);
+        engine.setReferencePattern("DefaultHost", hostName);
         engine.setReferencePattern("RealmGBean", realmName);
         engine.setReferencePattern("Hosts", hostName);
         start(engine);

Modified: geronimo/branches/1.0/modules/tomcat/src/java/org/apache/geronimo/tomcat/BaseGBean.java
URL: http://svn.apache.org/viewcvs/geronimo/branches/1.0/modules/tomcat/src/java/org/apache/geronimo/tomcat/BaseGBean.java?rev=357408&r1=357407&r2=357408&view=diff
==============================================================================
--- geronimo/branches/1.0/modules/tomcat/src/java/org/apache/geronimo/tomcat/BaseGBean.java (original)
+++ geronimo/branches/1.0/modules/tomcat/src/java/org/apache/geronimo/tomcat/BaseGBean.java Sat Dec 17 16:20:34 2005
@@ -20,7 +20,7 @@
 import java.util.Map;
 import java.util.Set;
 
-import org.apache.commons.modeler.util.IntrospectionUtils;
+import org.apache.tomcat.util.IntrospectionUtils;
 
 public abstract class BaseGBean {
 

Modified: geronimo/branches/1.0/modules/tomcat/src/java/org/apache/geronimo/tomcat/EngineGBean.java
URL: http://svn.apache.org/viewcvs/geronimo/branches/1.0/modules/tomcat/src/java/org/apache/geronimo/tomcat/EngineGBean.java?rev=357408&r1=357407&r2=357408&view=diff
==============================================================================
--- geronimo/branches/1.0/modules/tomcat/src/java/org/apache/geronimo/tomcat/EngineGBean.java (original)
+++ geronimo/branches/1.0/modules/tomcat/src/java/org/apache/geronimo/tomcat/EngineGBean.java Sat Dec 17 16:20:34 2005
@@ -51,6 +51,7 @@
 
     public EngineGBean(String className,
             Map initParams,
+            HostGBean defaultHost,
             Collection hosts,
             ObjectRetriever realmGBean,
             ValveGBean tomcatValveChain,
@@ -63,23 +64,34 @@
         }
 
         if (initParams == null){
-            throw new IllegalArgumentException("Must have 'name' and 'defaultHost' values in initParams.");
+            throw new IllegalArgumentException("Must have 'name' value in initParams.");
+        }
+        
+        //Be sure the defaulthost has been declared.
+        if (defaultHost == null){
+            throw new IllegalArgumentException("Must have a 'defaultHost' attribute.");
         }
 
         //Be sure the name has been declared.
         if (!initParams.containsKey(NAME)){
             throw new IllegalArgumentException("Must have a 'name' value initParams.");
         }
-
-        //Be sure the defaulthost has been declared.
-        if (!initParams.containsKey(DEFAULTHOST)){
-            throw new IllegalArgumentException("Must have a 'defaultHost' value initParams.");
+        
+        //Deprecate the defaultHost initParam
+        if (initParams.containsKey(DEFAULTHOST)){
+            log.warn("The " + DEFAULTHOST + " initParams value is no longer used and will be ignored.");
+            initParams.remove(DEFAULTHOST);
         }
 
         engine = (Engine)Class.forName(className).newInstance();
 
         //Set the parameters
         setParameters(engine, initParams);
+        
+        //Set the default Host
+        final String defaultHostName = ((Host)defaultHost.getInternalObject()).getName();
+        engine.setDefaultHost(defaultHostName);
+        addHost(defaultHost);
 
         if (realmGBean != null){
             engine.setRealm((Realm)realmGBean.getInternalObject());
@@ -106,20 +118,26 @@
             public void memberAdded(ReferenceCollectionEvent event) {
                 Object o = event.getMember();
                 ObjectRetriever objectRetriever = (ObjectRetriever) o;
-                addHost(objectRetriever);
+                String hostName = ((Host)objectRetriever.getInternalObject()).getName();
+                if (!hostName.equals(defaultHostName))
+                    addHost(objectRetriever);
             }
 
             public void memberRemoved(ReferenceCollectionEvent event) {
                 Object o = event.getMember();
                 ObjectRetriever objectRetriever = (ObjectRetriever) o;
-                removeHost(objectRetriever);
+                String hostName = ((Host)objectRetriever.getInternalObject()).getName();
+                if (!hostName.equals(defaultHostName))
+                    removeHost(objectRetriever);
             }
         });
+        
         Iterator iterator = refs.iterator();
         while (iterator.hasNext()){
             ObjectRetriever objRetriever = (ObjectRetriever)iterator.next();
-            addHost(objRetriever);
-
+            String hostName = ((Host)objRetriever.getInternalObject()).getName();
+            if (!hostName.equals(defaultHostName))
+                addHost(objRetriever);
         }
         
         //Add clustering
@@ -165,6 +183,7 @@
         GBeanInfoBuilder infoFactory = GBeanInfoBuilder.createStatic("TomcatEngine", EngineGBean.class);
         infoFactory.addAttribute("className", String.class, true);
         infoFactory.addAttribute("initParams", Map.class, true);
+        infoFactory.addReference("DefaultHost", HostGBean.class, HostGBean.J2EE_TYPE);
         infoFactory.addReference("Hosts", ObjectRetriever.class, HostGBean.J2EE_TYPE);
         infoFactory.addReference("RealmGBean", ObjectRetriever.class, NameFactory.GERONIMO_SERVICE);
         infoFactory.addReference("TomcatValveChain", ValveGBean.class, ValveGBean.J2EE_TYPE);
@@ -174,6 +193,7 @@
         infoFactory.setConstructor(new String[] { 
                 "className", 
                 "initParams", 
+                "DefaultHost",
                 "Hosts", 
                 "RealmGBean", 
                 "TomcatValveChain",

Modified: geronimo/branches/1.0/modules/tomcat/src/java/org/apache/geronimo/tomcat/HostGBean.java
URL: http://svn.apache.org/viewcvs/geronimo/branches/1.0/modules/tomcat/src/java/org/apache/geronimo/tomcat/HostGBean.java?rev=357408&r1=357407&r2=357408&view=diff
==============================================================================
--- geronimo/branches/1.0/modules/tomcat/src/java/org/apache/geronimo/tomcat/HostGBean.java (original)
+++ geronimo/branches/1.0/modules/tomcat/src/java/org/apache/geronimo/tomcat/HostGBean.java Sat Dec 17 16:20:34 2005
@@ -45,6 +45,10 @@
     private static final String NAME = "name";
     
     private final Host host;
+    
+    public HostGBean(){
+        host = null;
+    }
 
     public HostGBean(String className, 
             Map initParams, 

Modified: geronimo/branches/1.0/modules/tomcat/src/test/org/apache/geronimo/tomcat/AbstractWebModuleTest.java
URL: http://svn.apache.org/viewcvs/geronimo/branches/1.0/modules/tomcat/src/test/org/apache/geronimo/tomcat/AbstractWebModuleTest.java?rev=357408&r1=357407&r2=357408&view=diff
==============================================================================
--- geronimo/branches/1.0/modules/tomcat/src/test/org/apache/geronimo/tomcat/AbstractWebModuleTest.java (original)
+++ geronimo/branches/1.0/modules/tomcat/src/test/org/apache/geronimo/tomcat/AbstractWebModuleTest.java Sat Dec 17 16:20:34 2005
@@ -359,10 +359,10 @@
         //Default Engine
         initParams.clear();
         initParams.put("name", "Geronimo");
-        initParams.put("defaultHost", "localhost");
         engine = new GBeanData(engineName, EngineGBean.GBEAN_INFO);
         engine.setAttribute("className", "org.apache.geronimo.tomcat.TomcatEngine");
         engine.setAttribute("initParams", initParams);
+        engine.setReferencePattern("DefaultHost", hostName);
         if (realmClass != null)
             engine.setReferencePattern("RealmGBean", realmName);
         engine.setReferencePattern("Hosts", hostName);

Modified: geronimo/branches/1.0/modules/tomcat/src/test/org/apache/geronimo/tomcat/ContainerTest.java
URL: http://svn.apache.org/viewcvs/geronimo/branches/1.0/modules/tomcat/src/test/org/apache/geronimo/tomcat/ContainerTest.java?rev=357408&r1=357407&r2=357408&view=diff
==============================================================================
--- geronimo/branches/1.0/modules/tomcat/src/test/org/apache/geronimo/tomcat/ContainerTest.java (original)
+++ geronimo/branches/1.0/modules/tomcat/src/test/org/apache/geronimo/tomcat/ContainerTest.java Sat Dec 17 16:20:34 2005
@@ -277,9 +277,9 @@
 
         initParams.clear();
         initParams.put("name", "Geronimo");
-        initParams.put("defaultHost", "localhost");
         engine = new GBeanData(engineName, EngineGBean.GBEAN_INFO);
         engine.setAttribute("className", "org.apache.geronimo.tomcat.TomcatEngine");
+        engine.setReferencePattern("DefaultHost", hostName);
         engine.setAttribute("initParams", initParams);
         engine.setReferencePattern("Hosts", hostName);
         start(engine);