From: markt Date: Tue, 11 May 2010 10:18:55 +0000 (+0000) Subject: ContainerListener != LifecycleListener. Use the correct one. X-Git-Url: https://git.internetallee.de/?a=commitdiff_plain;h=16e3b4c7e4b7dc03d3a9759324195bd4eef1b800;p=tomcat7.0 ContainerListener != LifecycleListener. Use the correct one. git-svn-id: https://svn.apache.org/repos/asf/tomcat/trunk@943073 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/java/org/apache/catalina/connector/LocalStrings.properties b/java/org/apache/catalina/connector/LocalStrings.properties index 7957c8a4d..dd9af68a1 100644 --- a/java/org/apache/catalina/connector/LocalStrings.properties +++ b/java/org/apache/catalina/connector/LocalStrings.properties @@ -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 diff --git a/java/org/apache/catalina/connector/MapperListener.java b/java/org/apache/catalina/connector/MapperListener.java index f1acc437f..fd21b994a 100644 --- a/java/org/apache/catalina/connector/MapperListener.java +++ b/java/org/apache/catalina/connector/MapperListener.java @@ -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); + } + } + } } diff --git a/java/org/apache/catalina/core/mbeans-descriptors.xml b/java/org/apache/catalina/core/mbeans-descriptors.xml index e26018591..79dba71d7 100644 --- a/java/org/apache/catalina/core/mbeans-descriptors.xml +++ b/java/org/apache/catalina/core/mbeans-descriptors.xml @@ -1021,6 +1021,23 @@ returnType="org.apache.catalina.Wrapper"> + + + + + + +