From ee548920a7e9d93726d0996809bf1b75dad3d71c Mon Sep 17 00:00:00 2001 From: markt Date: Tue, 18 May 2010 15:58:58 +0000 Subject: [PATCH] Only register the MapperListener once per component and remove it as soon as it is no longer required. git-svn-id: https://svn.apache.org/repos/asf/tomcat/trunk@945722 13f79535-47bb-0310-9956-ffa450edef68 --- .../apache/catalina/connector/MapperListener.java | 38 ++++++++++------------ 1 file changed, 17 insertions(+), 21 deletions(-) diff --git a/java/org/apache/catalina/connector/MapperListener.java b/java/org/apache/catalina/connector/MapperListener.java index 5822a1b2f..5395ca29c 100644 --- a/java/org/apache/catalina/connector/MapperListener.java +++ b/java/org/apache/catalina/connector/MapperListener.java @@ -110,25 +110,8 @@ public class MapperListener implements ContainerListener, LifecycleListener { Host host = (Host) conHost; if (!LifecycleState.NEW.equals(host.getState())) { host.addLifecycleListener(this); + // Registering the host will register the context and wrappers registerHost(host); - - Container[] conContexts = host.findChildren(); - for (Container conContext : conContexts) { - Context context = (Context) conContext; - if (!LifecycleState.NEW.equals(context.getState())) { - context.addLifecycleListener(this); - registerContext(context); - - Container[] conWrappers = context.findChildren(); - for (Container conWrapper : conWrappers) { - Wrapper wrapper = (Wrapper) conWrapper; - if (!LifecycleState.NEW.equals(wrapper.getState())) { - wrapper.addLifecycleListener(this); - registerWrapper(wrapper); - } - } - } - } } } } @@ -308,7 +291,7 @@ public class MapperListener implements ContainerListener, LifecycleListener { */ private void unregisterHost(Host host) { - host.removeContainerListener(this); + removeListeners(host); String hostname = host.getName(); @@ -325,7 +308,7 @@ public class MapperListener implements ContainerListener, LifecycleListener { */ private void unregisterWrapper(Wrapper wrapper) { - wrapper.removeContainerListener(this); + removeListeners(wrapper); String contextName = wrapper.getParent().getName(); if ("/".equals(contextName)) { @@ -381,7 +364,7 @@ public class MapperListener implements ContainerListener, LifecycleListener { return; } - context.removeContainerListener(this); + removeListeners(context); String contextName = context.getName(); if ("/".equals(contextName)) { @@ -448,4 +431,17 @@ public class MapperListener implements ContainerListener, LifecycleListener { } } } + + /** + * Remove this mapper from the container and all child containers + * + * @param container + */ + private void removeListeners(Container container) { + container.removeContainerListener(this); + container.removeLifecycleListener(this); + for (Container child : container.findChildren()) { + removeListeners(child); + } + } } -- 2.11.0