findDefaultHost();
Engine engine = (Engine) connector.getService().getContainer();
- engine.addContainerListener(this);
+ addListeners(engine);
Container[] conHosts = engine.findChildren();
for (Container conHost : conHosts) {
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 Listener methods
+ @Override
public void containerEvent(ContainerEvent event) {
if (event.getType() == Container.ADD_CHILD_EVENT) {
Container child = (Container) event.getData();
- child.addLifecycleListener(this);
- child.addContainerListener(this);
- if (child instanceof Host) {
- registerHost((Host) child);
- } else if (child instanceof Context) {
- registerContext((Context) child);
- } else if (child instanceof Wrapper) {
- registerWrapper((Wrapper) child);
+ addListeners(child);
+ // If child is started then it is too late for life-cycle listener
+ // to register the child so register it here
+ if (child.getState().isAvailable()) {
+ if (child instanceof Host) {
+ registerHost((Host) child);
+ } else if (child instanceof Context) {
+ registerContext((Context) child);
+ } else if (child instanceof Wrapper) {
+ registerWrapper((Wrapper) child);
+ }
}
} else if (event.getType() == Container.REMOVE_CHILD_EVENT) {
Container child = (Container) event.getData();
removeListeners(child);
- if (child instanceof Host) {
- unregisterHost((Host) child);
- } else if (child instanceof Context) {
- unregisterContext((Context) child);
- } else if (child instanceof Wrapper) {
- unregisterWrapper((Wrapper) child);
- }
+ // No need to unregister - life-cycle listener will handle this when
+ // the child stops
} else if (event.getType() == Host.ADD_ALIAS_EVENT) {
// Handle dynamically adding host aliases
mapper.addHostAlias(((Host) event.getSource()).getName(),
mapper.setDefaultHostName(defaultHost);
} else {
log.warn(sm.getString("mapperListener.unknownDefaultHost",
- defaultHost));
+ defaultHost, connector));
}
}
String[] aliases = host.findAliases();
mapper.addHost(host.getName(), aliases, host);
- host.addContainerListener(this);
-
for (Container container : host.findChildren()) {
registerContext((Context) container);
}
if(log.isDebugEnabled()) {
- log.debug(sm.getString
- ("mapperListener.registerHost", host.getName(), domain));
+ log.debug(sm.getString("mapperListener.registerHost",
+ host.getName(), domain, connector));
}
}
if(log.isDebugEnabled())
log.debug(sm.getString("mapperListener.unregisterHost", hostname,
- domain));
+ domain, connector));
}
private void unregisterWrapper(Wrapper wrapper) {
String contextName = wrapper.getParent().getName();
+ String wrapperName = wrapper.getName();
+
if ("/".equals(contextName)) {
contextName = "";
}
for (String mapping : mappings) {
mapper.removeWrapper(hostName, contextName, mapping);
}
+
+ if(log.isDebugEnabled()) {
+ log.debug(sm.getString("mapperListener.unregisterWrapper",
+ wrapperName, contextName, connector));
+ }
}
mapper.addContext(host.getName(), host, contextName, context,
welcomeFiles, resources);
- context.addContainerListener(this);
-
for (Container container : context.findChildren()) {
registerWrapper((Wrapper) container);
}
if(log.isDebugEnabled()) {
- log.debug(sm.getString
- ("mapperListener.registerContext", contextName));
+ log.debug(sm.getString("mapperListener.registerContext",
+ contextName, connector));
}
}
String hostName = context.getParent().getName();
if(log.isDebugEnabled())
- log.debug(sm.getString
- ("mapperListener.unregisterContext", contextName));
+ log.debug(sm.getString("mapperListener.unregisterContext",
+ contextName, connector));
mapper.removeContext(hostName, contextName);
}
jspWildCard);
}
- wrapper.addContainerListener(this);
-
if(log.isDebugEnabled()) {
log.debug(sm.getString("mapperListener.registerWrapper",
- wrapperName, contextName));
+ wrapperName, contextName, connector));
}
}
}
}
+
+ /**
+ * Add this mapper to the container and all child containers
+ *
+ * @param container
+ */
+ private void addListeners(Container container) {
+ container.addContainerListener(this);
+ container.addLifecycleListener(this);
+ for (Container child : container.findChildren()) {
+ addListeners(child);
+ }
+ }
+
+
/**
* Remove this mapper from the container and all child containers
*
package org.apache.catalina.mbeans;
+import java.util.ArrayList;
+import java.util.List;
+
import javax.management.InstanceNotFoundException;
import javax.management.MBeanException;
import javax.management.MalformedObjectNameException;
import javax.management.modelmbean.InvalidTargetObjectTypeException;
import org.apache.catalina.Container;
+import org.apache.catalina.ContainerListener;
import org.apache.catalina.LifecycleException;
import org.apache.catalina.LifecycleListener;
import org.apache.catalina.Valve;
}
}
+
+ /**
+ * List the class name of each of the lifecycle listeners added to this
+ * container.
+ */
+ public String[] findLifecycleListenerNames() throws MBeanException {
+ ContainerBase container = null;
+ List<String> result = new ArrayList<String>();
+
+ try {
+ container = (ContainerBase) getManagedResource();
+ } catch (InstanceNotFoundException e) {
+ throw new MBeanException(e);
+ } catch (RuntimeOperationsException e) {
+ throw new MBeanException(e);
+ } catch (InvalidTargetObjectTypeException e) {
+ throw new MBeanException(e);
+ }
+
+ LifecycleListener[] listeners = container.findLifecycleListeners();
+ for(LifecycleListener listener: listeners){
+ result.add(listener.getClass().getName());
+ }
+
+ return result.toArray(new String[result.size()]);
+ }
+
+
+ /**
+ * List the class name of each of the container listeners added to this
+ * container.
+ */
+ public String[] findContainerListenerNames() throws MBeanException {
+ ContainerBase container = null;
+ List<String> result = new ArrayList<String>();
+
+ try {
+ container = (ContainerBase) getManagedResource();
+ } catch (InstanceNotFoundException e) {
+ throw new MBeanException(e);
+ } catch (RuntimeOperationsException e) {
+ throw new MBeanException(e);
+ } catch (InvalidTargetObjectTypeException e) {
+ throw new MBeanException(e);
+ }
+
+ ContainerListener[] listeners = container.findContainerListeners();
+ for(ContainerListener listener: listeners){
+ result.add(listener.getClass().getName());
+ }
+
+ return result.toArray(new String[result.size()]);
+ }
}