ContainerListener != LifecycleListener. Use the correct one.
authormarkt <markt@13f79535-47bb-0310-9956-ffa450edef68>
Tue, 11 May 2010 10:18:55 +0000 (10:18 +0000)
committermarkt <markt@13f79535-47bb-0310-9956-ffa450edef68>
Tue, 11 May 2010 10:18:55 +0000 (10:18 +0000)
git-svn-id: https://svn.apache.org/repos/asf/tomcat/trunk@943073 13f79535-47bb-0310-9956-ffa450edef68

java/org/apache/catalina/connector/LocalStrings.properties
java/org/apache/catalina/connector/MapperListener.java
java/org/apache/catalina/core/mbeans-descriptors.xml

index 7957c8a..dd9af68 100644 (file)
@@ -82,6 +82,6 @@ mapperListener.unregisterContext=Unregister Context {0}
 mapperListener.registerWrapper=Register Wrapper {0} in Context {1}
 mapperListener.addMBeanListenerFail=Failed to add MBean notification listener for connector [{0}] in domain [{1}]. Adding Hosts, Contexts and Wrappers will not be visible to the connector.
 mapperListener.removeMBeanListenerFail=Failed to remove MBean notification listener for connector [{0}] in domain [{1}]. This may result in a memory leak.
-mapperLister.containerListenerFail=Failed to call method [{0}] on object [{1}]. Changes in the object state may not be correctly reflected in the mapper for connector [{2}] in domain [{3}].
+mapperLister.lifecycleListenerFail=Failed to call method [{0}] on object [{1}]. Changes in the object state may not be correctly reflected in the mapper for connector [{2}] in domain [{3}].
 
 inputBuffer.streamClosed=Stream closed
index f1acc43..fd21b99 100644 (file)
@@ -34,6 +34,8 @@ import org.apache.catalina.Context;
 import org.apache.catalina.Engine;
 import org.apache.catalina.Host;
 import org.apache.catalina.Lifecycle;
+import org.apache.catalina.LifecycleEvent;
+import org.apache.catalina.LifecycleListener;
 import org.apache.catalina.LifecycleState;
 import org.apache.catalina.Wrapper;
 import org.apache.juli.logging.Log;
@@ -53,8 +55,7 @@ import org.apache.tomcat.util.res.StringManager;
  * @author Costin Manolache
  */
 public class MapperListener
-    implements NotificationListener, ContainerListener
- {
+        implements NotificationListener, ContainerListener, LifecycleListener {
 
 
     private static final Log log = LogFactory.getLog(MapperListener.class);
@@ -206,10 +207,10 @@ public class MapperListener
         String methodName = null;
         if (notification.getType().equals
                 (MBeanServerNotification.REGISTRATION_NOTIFICATION)) {
-            methodName = "addContainerListener";
+            methodName = "addLifecycleListener";
         } else if (notification.getType().equals
                 (MBeanServerNotification.UNREGISTRATION_NOTIFICATION)) {
-            methodName = "removeContainerListener";
+            methodName = "removeLifecycleListener";
         } else {
             return;
         }
@@ -231,18 +232,18 @@ public class MapperListener
                 try {
                     mBeanServer.invoke(objectName, methodName,
                             new Object[] {this},
-                            new String[] {"org.apache.catalinaContainerListener"});
+                            new String[] {"org.apache.catalina.LifecycleListener"});
                 } catch (ReflectionException e) {
                     log.error(sm.getString(
-                            "mapperLister.containerListenerFail", methodName,
+                            "mapperLister.lifecycleListenerFail", methodName,
                             objectName, connector, domain), e);
                 } catch (MBeanException e) {
                     log.error(sm.getString(
-                            "mapperLister.containerListenerFail", methodName,
+                            "mapperLister.lifecycleListenerFail", methodName,
                             objectName, connector, domain), e);
                 } catch (InstanceNotFoundException e) {
                     log.error(sm.getString(
-                            "mapperLister.containerListenerFail", methodName,
+                            "mapperLister.lifecycleListenerFail", methodName,
                             objectName, connector, domain), e);
                 }
             }
@@ -254,25 +255,7 @@ public class MapperListener
 
     public void containerEvent(ContainerEvent event) {
 
-        if (event.getType() == Lifecycle.AFTER_START_EVENT) {
-            Object obj = event.getSource();
-            if (obj instanceof Wrapper) {
-                registerWrapper((Wrapper) obj);
-            } else if (obj instanceof Context) {
-                registerContext((Context) obj);
-            } else if (obj instanceof Host) {
-                registerHost((Host) obj);
-            }
-        } else if (event.getType() == Lifecycle.AFTER_STOP_EVENT) {
-            Object obj = event.getSource();
-            if (obj instanceof Wrapper) {
-                unregisterWrapper((Wrapper) obj);
-            } else if (obj instanceof Context) {
-                unregisterContext((Context) obj);
-            } else if (obj instanceof Host) {
-                unregisterHost((Host) obj);
-            }
-        } else if (event.getType() == Host.ADD_ALIAS_EVENT) {
+        if (event.getType() == Host.ADD_ALIAS_EVENT) {
             mapper.addHostAlias(((Host) event.getSource()).getName(),
                     event.getData().toString());
         } else if (event.getType() == Host.REMOVE_ALIAS_EVENT) {
@@ -441,4 +424,28 @@ public class MapperListener
                     wrapperName, contextName));
         }
     }
+
+
+    @Override
+    public void lifecycleEvent(LifecycleEvent event) {
+        if (event.getType() == Lifecycle.AFTER_START_EVENT) {
+            Object obj = event.getSource();
+            if (obj instanceof Wrapper) {
+                registerWrapper((Wrapper) obj);
+            } else if (obj instanceof Context) {
+                registerContext((Context) obj);
+            } else if (obj instanceof Host) {
+                registerHost((Host) obj);
+            }
+        } else if (event.getType() == Lifecycle.AFTER_STOP_EVENT) {
+            Object obj = event.getSource();
+            if (obj instanceof Wrapper) {
+                unregisterWrapper((Wrapper) obj);
+            } else if (obj instanceof Context) {
+                unregisterContext((Context) obj);
+            } else if (obj instanceof Host) {
+                unregisterHost((Host) obj);
+            }
+        }
+    }
 }
index e260185..79dba71 100644 (file)
                returnType="org.apache.catalina.Wrapper">
     </operation>
     
+        <operation name="addLifecycleListener"
+               description="Add a lifecycle listener to this Context"
+               impact="ACTION"
+               returnType="void">
+      <parameter name="listener"
+                 description="New lifecycle listener to be added"
+                 type="org.apache.catalina.LifecycleListener"/>
+    </operation>
+    
+    <operation name="removeLifecycleListener"
+               description="Remove a lifecycle listener from this Context"
+               impact="ACTION"
+               returnType="void">
+      <parameter name="listener"
+                 description="New lifecycle listener to be removed"
+                 type="org.apache.catalina.LifecycleListener"/>
+    </operation>
   </mbean>
   
   <mbean name="StandardWrapperValve"