geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From djen...@apache.org
Subject svn commit: r267422 - /geronimo/trunk/modules/tomcat/src/java/org/apache/geronimo/tomcat/EngineGBean.java
Date Sat, 03 Sep 2005 05:19:08 GMT
Author: djencks
Date: Fri Sep  2 22:19:05 2005
New Revision: 267422

URL: http://svn.apache.org/viewcvs?rev=267422&view=rev
Log:
Reference collections need listeners to register the members that join later

Modified:
    geronimo/trunk/modules/tomcat/src/java/org/apache/geronimo/tomcat/EngineGBean.java

Modified: geronimo/trunk/modules/tomcat/src/java/org/apache/geronimo/tomcat/EngineGBean.java
URL: http://svn.apache.org/viewcvs/geronimo/trunk/modules/tomcat/src/java/org/apache/geronimo/tomcat/EngineGBean.java?rev=267422&r1=267421&r2=267422&view=diff
==============================================================================
--- geronimo/trunk/modules/tomcat/src/java/org/apache/geronimo/tomcat/EngineGBean.java (original)
+++ geronimo/trunk/modules/tomcat/src/java/org/apache/geronimo/tomcat/EngineGBean.java Fri
Sep  2 22:19:05 2005
@@ -31,27 +31,29 @@
 import org.apache.geronimo.gbean.GBeanInfoBuilder;
 import org.apache.geronimo.gbean.GBeanLifecycle;
 import org.apache.geronimo.gbean.ReferenceCollection;
+import org.apache.geronimo.gbean.ReferenceCollectionListener;
+import org.apache.geronimo.gbean.ReferenceCollectionEvent;
 import org.apache.geronimo.j2ee.j2eeobjectnames.NameFactory;
 
 /**
  * @version $Rev$ $Date$
  */
 public class EngineGBean extends BaseGBean implements GBeanLifecycle, ObjectRetriever {
-    
+
     private static final Log log = LogFactory.getLog(EngineGBean.class);
 
     private static final String NAME = "name";
     private static final String DEFAULTHOST = "defaultHost";
-    
+
     private final Engine engine;
 
-    public EngineGBean(String className, 
-            Map initParams, 
+    public EngineGBean(String className,
+            Map initParams,
             Collection hosts,
-            ObjectRetriever realmGBean,            
+            ObjectRetriever realmGBean,
             ValveGBean tomcatValveChain) throws Exception {
         super(); // TODO: make it an attribute
-        
+
         if (className == null){
             className = "org.apache.geronimo.tomcat.TomcatEngine";
         }
@@ -59,7 +61,7 @@
         if (initParams == null){
             throw new IllegalArgumentException("Must have 'name' and 'defaultHost' values
in initParams.");
         }
-        
+
         //Be sure the name has been declared.
         if (!initParams.containsKey(NAME)){
             throw new IllegalArgumentException("Must have a 'name' value initParams.");
@@ -69,16 +71,16 @@
         if (!initParams.containsKey(DEFAULTHOST)){
             throw new IllegalArgumentException("Must have a 'defaultHost' value initParams.");
         }
-        
+
         engine = (Engine)Class.forName(className).newInstance();
 
         //Set the parameters
         setParameters(engine, initParams);
-        
+
         if (realmGBean != null){
             engine.setRealm((Realm)realmGBean.getInternalObject());
         }
-        
+
         //Add the valve list
         if (engine instanceof StandardEngine){
             if (tomcatValveChain != null){
@@ -89,20 +91,44 @@
                 }
             }
         }
-        
+
         //Add the hosts
         ReferenceCollection refs = (ReferenceCollection)hosts;
+        refs.addReferenceCollectionListener(new ReferenceCollectionListener() {
+
+            public void memberAdded(ReferenceCollectionEvent event) {
+                Object o = event.getMember();
+                ObjectRetriever objectRetriever = (ObjectRetriever) o;
+                addHost(objectRetriever);
+            }
+
+            public void memberRemoved(ReferenceCollectionEvent event) {
+                Object o = event.getMember();
+                ObjectRetriever objectRetriever = (ObjectRetriever) o;
+                removeHost(objectRetriever);
+            }
+        });
         Iterator iterator = refs.iterator();
         while (iterator.hasNext()){
             ObjectRetriever objRetriever = (ObjectRetriever)iterator.next();
-            Host host = (Host)objRetriever.getInternalObject();
-            
-            //If we didn't set a realm, then use the default
-            if (host.getRealm() == null)
-                host.setRealm(engine.getRealm());
+            addHost(objRetriever);
+
+        }
+    }
+
+    private void removeHost(ObjectRetriever objRetriever) {
+        Host host = (Host)objRetriever.getInternalObject();
+        engine.removeChild(host);
+    }
+
+    private void addHost(ObjectRetriever objRetriever) {
+        Host host = (Host)objRetriever.getInternalObject();
 
-            engine.addChild(host);
+        //If we didn't set a realm, then use the default
+        if (host.getRealm() == null) {
+            host.setRealm(engine.getRealm());
         }
+        engine.addChild(host);
     }
 
     public Object getInternalObject() {



Mime
View raw message