From: markt Date: Wed, 17 Feb 2010 09:20:59 +0000 (+0000) Subject: Add Lifecycle to Container, Server and Service X-Git-Url: https://git.internetallee.de/?a=commitdiff_plain;h=a713fd590f318db7c2ccf3d19676905adcadd88d;p=tomcat7.0 Add Lifecycle to Container, Server and Service Remove casts instanceof tests and any other code this makes unnecessary git-svn-id: https://svn.apache.org/repos/asf/tomcat/trunk@910877 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/java/org/apache/catalina/Container.java b/java/org/apache/catalina/Container.java index b566ff6b2..c7cfa17c7 100644 --- a/java/org/apache/catalina/Container.java +++ b/java/org/apache/catalina/Container.java @@ -81,7 +81,7 @@ import org.apache.juli.logging.Log; * @version $Revision$ $Date$ */ -public interface Container { +public interface Container extends Lifecycle { // ----------------------------------------------------- Manifest Constants diff --git a/java/org/apache/catalina/Server.java b/java/org/apache/catalina/Server.java index 917526d26..092d5b278 100644 --- a/java/org/apache/catalina/Server.java +++ b/java/org/apache/catalina/Server.java @@ -45,7 +45,7 @@ import org.apache.catalina.deploy.NamingResources; * @version $Revision$ $Date$ */ -public interface Server { +public interface Server extends Lifecycle { // ------------------------------------------------------------- Properties diff --git a/java/org/apache/catalina/Service.java b/java/org/apache/catalina/Service.java index 455514bd4..fb759fd36 100644 --- a/java/org/apache/catalina/Service.java +++ b/java/org/apache/catalina/Service.java @@ -34,7 +34,7 @@ import org.apache.catalina.connector.Connector; * @version $Revision$ $Date$ */ -public interface Service { +public interface Service extends Lifecycle { // ------------------------------------------------------------- Properties diff --git a/java/org/apache/catalina/core/ContainerBase.java b/java/org/apache/catalina/core/ContainerBase.java index 3a5b0b292..7a65d0967 100644 --- a/java/org/apache/catalina/core/ContainerBase.java +++ b/java/org/apache/catalina/core/ContainerBase.java @@ -787,10 +787,10 @@ public abstract class ContainerBase children.put(child.getName(), child); // Start child - if (started && startChildren && (child instanceof Lifecycle)) { + if (started && startChildren) { boolean success = false; try { - ((Lifecycle) child).start(); + child.start(); success = true; } catch (LifecycleException e) { log.error("ContainerBase.addChild: start: ", e); @@ -919,14 +919,14 @@ public abstract class ContainerBase children.remove(child.getName()); } - if (started && (child instanceof Lifecycle)) { + if (started) { try { if( child instanceof ContainerBase ) { if( ((ContainerBase)child).started ) { - ((Lifecycle) child).stop(); + child.stop(); } } else { - ((Lifecycle) child).stop(); + child.stop(); } } catch (LifecycleException e) { log.error("ContainerBase.removeChild: stop: ", e); @@ -1043,8 +1043,7 @@ public abstract class ContainerBase // Start our child containers, if any Container children[] = findChildren(); for (int i = 0; i < children.length; i++) { - if (children[i] instanceof Lifecycle) - ((Lifecycle) children[i]).start(); + children[i].start(); } // Start the Valves in our pipeline (including the basic), if any @@ -1096,8 +1095,7 @@ public abstract class ContainerBase // Stop our child containers, if any Container children[] = findChildren(); for (int i = 0; i < children.length; i++) { - if (children[i] instanceof Lifecycle) - ((Lifecycle) children[i]).stop(); + children[i].stop(); } // Remove children - so next start can work children = findChildren(); diff --git a/java/org/apache/catalina/core/StandardContext.java b/java/org/apache/catalina/core/StandardContext.java index 34636d422..50ee84a4e 100644 --- a/java/org/apache/catalina/core/StandardContext.java +++ b/java/org/apache/catalina/core/StandardContext.java @@ -2835,9 +2835,8 @@ public class StandardContext try { Class clazz = Class.forName(wrapperLifecycles[i]); LifecycleListener listener = - (LifecycleListener) clazz.newInstance(); - if (wrapper instanceof Lifecycle) - ((Lifecycle) wrapper).addLifecycleListener(listener); + (LifecycleListener) clazz.newInstance(); + wrapper.addLifecycleListener(listener); } catch (Throwable t) { log.error("createWrapper", t); return (null); @@ -4491,8 +4490,7 @@ public class StandardContext // Start our child containers, if any Container children[] = findChildren(); for (int i = 0; i < children.length; i++) { - if (children[i] instanceof Lifecycle) - ((Lifecycle) children[i]).start(); + children[i].start(); } // Start the Valves in our pipeline (including the basic), @@ -4752,8 +4750,7 @@ public class StandardContext // Stop our child containers, if any Container[] children = findChildren(); for (int i = 0; i < children.length; i++) { - if (children[i] instanceof Lifecycle) - ((Lifecycle) children[i]).stop(); + children[i].stop(); } // Stop our filters diff --git a/java/org/apache/catalina/core/StandardHost.java b/java/org/apache/catalina/core/StandardHost.java index 1c48bcd93..e3af7fc1d 100644 --- a/java/org/apache/catalina/core/StandardHost.java +++ b/java/org/apache/catalina/core/StandardHost.java @@ -578,10 +578,7 @@ public class StandardHost @Override public void addChild(Container child) { - if (child instanceof Lifecycle) { - ((Lifecycle) child).addLifecycleListener( - new MemoryLeakTrackingListener()); - } + child.addLifecycleListener(new MemoryLeakTrackingListener()); if (!(child instanceof Context)) throw new IllegalArgumentException diff --git a/java/org/apache/catalina/core/StandardServer.java b/java/org/apache/catalina/core/StandardServer.java index 85bb84b09..fe7fed48d 100644 --- a/java/org/apache/catalina/core/StandardServer.java +++ b/java/org/apache/catalina/core/StandardServer.java @@ -342,9 +342,9 @@ public final class StandardServer } } - if (started && (service instanceof Lifecycle)) { + if (started) { try { - ((Lifecycle) service).start(); + service.start(); } catch (LifecycleException e) { // Ignore } @@ -525,12 +525,10 @@ public final class StandardServer } if (j < 0) return; - if (services[j] instanceof Lifecycle) { - try { - ((Lifecycle) services[j]).stop(); - } catch (LifecycleException e) { - // Ignore - } + try { + services[j].stop(); + } catch (LifecycleException e) { + // Ignore } int k = 0; Service results[] = new Service[services.length - 1]; @@ -723,8 +721,7 @@ public final class StandardServer // Start our defined Services synchronized (services) { for (int i = 0; i < services.length; i++) { - if (services[i] instanceof Lifecycle) - ((Lifecycle) services[i]).start(); + services[i].start(); } } @@ -757,8 +754,7 @@ public final class StandardServer // Stop our defined Services for (int i = 0; i < services.length; i++) { - if (services[i] instanceof Lifecycle) - ((Lifecycle) services[i]).stop(); + services[i].stop(); } // Notify our interested LifecycleListeners diff --git a/java/org/apache/catalina/core/StandardService.java b/java/org/apache/catalina/core/StandardService.java index 0655842df..102712b66 100644 --- a/java/org/apache/catalina/core/StandardService.java +++ b/java/org/apache/catalina/core/StandardService.java @@ -152,10 +152,9 @@ public class StandardService this.container = container; if ((this.container != null) && (this.container instanceof Engine)) ((Engine) this.container).setService(this); - if (started && (this.container != null) && - (this.container instanceof Lifecycle)) { + if (started && (this.container != null)) { try { - ((Lifecycle) this.container).start(); + this.container.start(); } catch (LifecycleException e) { // Ignore } @@ -164,10 +163,9 @@ public class StandardService for (int i = 0; i < connectors.length; i++) connectors[i].setContainer(this.container); } - if (started && (oldContainer != null) && - (oldContainer instanceof Lifecycle)) { + if (started && (oldContainer != null)) { try { - ((Lifecycle) oldContainer).stop(); + oldContainer.stop(); } catch (LifecycleException e) { // Ignore } @@ -515,9 +513,7 @@ public class StandardService // Start our defined Container first if (container != null) { synchronized (container) { - if (container instanceof Lifecycle) { - ((Lifecycle) container).start(); - } + container.start(); } } @@ -582,9 +578,7 @@ public class StandardService // Stop our defined Container second if (container != null) { synchronized (container) { - if (container instanceof Lifecycle) { - ((Lifecycle) container).stop(); - } + container.stop(); } } // FIXME pero -- Why container stop first? KeepAlive connections can send request! diff --git a/java/org/apache/catalina/ha/deploy/FarmWarDeployer.java b/java/org/apache/catalina/ha/deploy/FarmWarDeployer.java index fbf22e32c..4aa31af80 100644 --- a/java/org/apache/catalina/ha/deploy/FarmWarDeployer.java +++ b/java/org/apache/catalina/ha/deploy/FarmWarDeployer.java @@ -28,7 +28,6 @@ import org.apache.catalina.Container; import org.apache.catalina.Context; import org.apache.catalina.Engine; import org.apache.catalina.Host; -import org.apache.catalina.Lifecycle; import org.apache.catalina.LifecycleException; import org.apache.catalina.ha.CatalinaCluster; import org.apache.catalina.ha.ClusterDeployer; @@ -559,7 +558,7 @@ public class FarmWarDeployer extends ClusterListener implements ClusterDeployer, if (context != null) { if(log.isDebugEnabled()) log.debug("Undeploy local context " +path ); - ((Lifecycle) context).stop(); + context.stop(); File war = new File(getAppBase(), getDocBase(path) + ".war"); File dir = new File(getAppBase(), getDocBase(path)); File xml = new File(configBase, getConfigFile(path) + ".xml"); diff --git a/java/org/apache/catalina/manager/ManagerServlet.java b/java/org/apache/catalina/manager/ManagerServlet.java index 1146ee70a..1d88aa65e 100644 --- a/java/org/apache/catalina/manager/ManagerServlet.java +++ b/java/org/apache/catalina/manager/ManagerServlet.java @@ -1245,7 +1245,7 @@ public class ManagerServlet RequestUtil.filter(displayPath))); return; } - ((Lifecycle) context).start(); + context.start(); if (context.getAvailable()) writer.println (sm.getString("managerServlet.started", displayPath)); @@ -1296,7 +1296,7 @@ public class ManagerServlet writer.println(sm.getString("managerServlet.noSelf")); return; } - ((Lifecycle) context).stop(); + context.stop(); writer.println(sm.getString("managerServlet.stopped", displayPath)); } catch (Throwable t) { log("ManagerServlet.stop[" + displayPath + "]", t); @@ -1347,7 +1347,7 @@ public class ManagerServlet addServiced(path); try { // Try to stop the context first to be nicer - ((Lifecycle) context).stop(); + context.stop(); } catch (Throwable t) { // Ignore } diff --git a/java/org/apache/catalina/manager/host/HostManagerServlet.java b/java/org/apache/catalina/manager/host/HostManagerServlet.java index 1d633dd22..65dfa2709 100644 --- a/java/org/apache/catalina/manager/host/HostManagerServlet.java +++ b/java/org/apache/catalina/manager/host/HostManagerServlet.java @@ -39,7 +39,6 @@ import org.apache.catalina.ContainerServlet; import org.apache.catalina.Context; import org.apache.catalina.Engine; import org.apache.catalina.Host; -import org.apache.catalina.Lifecycle; import org.apache.catalina.Wrapper; import org.apache.catalina.core.StandardHost; import org.apache.catalina.startup.HostConfig; @@ -581,7 +580,7 @@ public class HostManagerServlet // Start host try { - ((Lifecycle) engine.findChild(name)).start(); + engine.findChild(name).start(); writer.println (sm.getString("hostManagerServlet.started", name)); } catch (Throwable t) { @@ -631,7 +630,7 @@ public class HostManagerServlet // Start host try { - ((Lifecycle) engine.findChild(name)).stop(); + engine.findChild(name).stop(); writer.println (sm.getString("hostManagerServlet.stopped", name)); } catch (Throwable t) { diff --git a/java/org/apache/catalina/startup/Catalina.java b/java/org/apache/catalina/startup/Catalina.java index 762d761e3..a7c722a8c 100644 --- a/java/org/apache/catalina/startup/Catalina.java +++ b/java/org/apache/catalina/startup/Catalina.java @@ -498,16 +498,14 @@ public class Catalina extends Embedded { initStreams(); // Start the new server - if (getServer() instanceof Lifecycle) { - try { - getServer().initialize(); - } catch (LifecycleException e) { - if (Boolean.getBoolean("org.apache.catalina.startup.EXIT_ON_INIT_FAILURE")) - throw new java.lang.Error(e); - else - log.error("Catalina.start", e); - - } + try { + getServer().initialize(); + } catch (LifecycleException e) { + if (Boolean.getBoolean("org.apache.catalina.startup.EXIT_ON_INIT_FAILURE")) + throw new java.lang.Error(e); + else + log.error("Catalina.start", e); + } long t2 = System.nanoTime(); @@ -557,12 +555,10 @@ public class Catalina extends Embedded { long t1 = System.nanoTime(); // Start the new server - if (getServer() instanceof Lifecycle) { - try { - ((Lifecycle) getServer()).start(); - } catch (LifecycleException e) { - log.error("Catalina.start: ", e); - } + try { + getServer().start(); + } catch (LifecycleException e) { + log.error("Catalina.start: ", e); } long t2 = System.nanoTime(); @@ -608,12 +604,10 @@ public class Catalina extends Embedded { } // Shut down the server - if (getServer() instanceof Lifecycle) { - try { - ((Lifecycle) getServer()).stop(); - } catch (LifecycleException e) { - log.error("Catalina.stop", e); - } + try { + getServer().stop(); + } catch (LifecycleException e) { + log.error("Catalina.stop", e); } } diff --git a/java/org/apache/catalina/startup/Embedded.java b/java/org/apache/catalina/startup/Embedded.java index 3b857bbd9..c7c031704 100644 --- a/java/org/apache/catalina/startup/Embedded.java +++ b/java/org/apache/catalina/startup/Embedded.java @@ -347,9 +347,9 @@ public class Embedded extends StandardService { engines = results; // Start this Engine if necessary - if (started && (engine instanceof Lifecycle)) { + if (started) { try { - ((Lifecycle) engine).start(); + engine.start(); } catch (LifecycleException e) { log.error("Engine.start", e); } @@ -484,7 +484,7 @@ public class Embedded extends StandardService { ContextConfig config = new ContextConfig(); config.setCustomAuthenticators(authenticators); - ((Lifecycle) context).addLifecycleListener(config); + context.addLifecycleListener(config); return (context); @@ -666,14 +666,12 @@ public class Embedded extends StandardService { } // Stop this Engine if necessary - if (engine instanceof Lifecycle) { - if( log.isDebugEnabled() ) - log.debug(" Stopping this Engine"); - try { - ((Lifecycle) engine).stop(); - } catch (LifecycleException e) { - log.error("Engine.stop", e); - } + if( log.isDebugEnabled() ) + log.debug(" Stopping this Engine"); + try { + engine.stop(); + } catch (LifecycleException e) { + log.error("Engine.stop", e); } // Remove this Engine from our set of defined Engines @@ -827,8 +825,7 @@ public class Embedded extends StandardService { // Start our defined Engines first for (int i = 0; i < engines.length; i++) { - if (engines[i] instanceof Lifecycle) - ((Lifecycle) engines[i]).start(); + engines[i].start(); } // Start our defined Connectors second @@ -868,8 +865,7 @@ public class Embedded extends StandardService { // Stop our defined Engines second for (int i = 0; i < engines.length; i++) { - if (engines[i] instanceof Lifecycle) - ((Lifecycle) engines[i]).stop(); + engines[i].stop(); } } diff --git a/java/org/apache/catalina/startup/HostConfig.java b/java/org/apache/catalina/startup/HostConfig.java index eb8432ae7..115ec8c59 100644 --- a/java/org/apache/catalina/startup/HostConfig.java +++ b/java/org/apache/catalina/startup/HostConfig.java @@ -608,12 +608,12 @@ public class HostConfig digester.reset(); } } - if (context instanceof Lifecycle) { - Class clazz = Class.forName(host.getConfigClass()); - LifecycleListener listener = - (LifecycleListener) clazz.newInstance(); - ((Lifecycle) context).addLifecycleListener(listener); - } + + Class clazz = Class.forName(host.getConfigClass()); + LifecycleListener listener = + (LifecycleListener) clazz.newInstance(); + context.addLifecycleListener(listener); + context.setConfigFile(contextXml.getAbsolutePath()); context.setPath(contextPath); // Add the associated docBase to the redeployed list if it's a WAR @@ -901,12 +901,11 @@ public class HostConfig (xml.getAbsolutePath(), new Long(xml.lastModified())); } - if (context instanceof Lifecycle) { - Class clazz = Class.forName(host.getConfigClass()); - LifecycleListener listener = - (LifecycleListener) clazz.newInstance(); - ((Lifecycle) context).addLifecycleListener(listener); - } + Class clazz = Class.forName(host.getConfigClass()); + LifecycleListener listener = + (LifecycleListener) clazz.newInstance(); + context.addLifecycleListener(listener); + context.setPath(contextPath); context.setDocBase(file); host.addChild(context); @@ -1036,12 +1035,11 @@ public class HostConfig context = (Context) Class.forName(contextClass).newInstance(); } - if (context instanceof Lifecycle) { - Class clazz = Class.forName(host.getConfigClass()); - LifecycleListener listener = - (LifecycleListener) clazz.newInstance(); - ((Lifecycle) context).addLifecycleListener(listener); - } + Class clazz = Class.forName(host.getConfigClass()); + LifecycleListener listener = + (LifecycleListener) clazz.newInstance(); + context.addLifecycleListener(listener); + context.setPath(contextPath); context.setDocBase(file); host.addChild(context); @@ -1240,7 +1238,7 @@ public class HostConfig log.info(sm.getString("hostConfig.reload", app.name)); Container context = host.findChild(app.name); try { - ((Lifecycle) context).stop(); + context.stop(); } catch (Exception e) { log.warn(sm.getString ("hostConfig.context.restart", app.name), e); @@ -1248,7 +1246,7 @@ public class HostConfig // If the context was not started (for example an error // in web.xml) we'll still get to try to start try { - ((Lifecycle) context).start(); + context.start(); } catch (Exception e) { log.warn(sm.getString ("hostConfig.context.restart", app.name), e); diff --git a/java/org/apache/catalina/startup/LocalStrings.properties b/java/org/apache/catalina/startup/LocalStrings.properties index da0620f05..c5db47595 100644 --- a/java/org/apache/catalina/startup/LocalStrings.properties +++ b/java/org/apache/catalina/startup/LocalStrings.properties @@ -108,11 +108,6 @@ tldConfig.webxmlAdd=Adding path [{0}] for URI [{1}] tldConfig.webxmlFail=Failed to process TLD with path [{1}] and URI [{0}] tldConfig.webxmlSkip=Path [{1}] skipped since URI [{0}] is a duplicate tldConfig.webxmlStart=Scanning elements in web.xml -tomcat.addContextNotLifecycle=Tomcat.addContext() was called but the Context implementation does not implement Lifecycle. The functionality provided by the FixContextListener must be provided by other means. -tomcat.addWebappNotLifecycle=Tomcat.addWebapp() was called but the Context implementation does not implement Lifecycle. The functionality provided by the DefaultWebXmlListener and ContextConfig must be provided by other means. -tomcat.namingNotLifecycle=Tomcat.enableNaming() was called but the Server implementation does not implement Lifecycle. The functionality provided by the NamingContextListener must be provided by other means. -tomcat.startNotLifecycle=Tomcat.start() was called but the Server implementation does not implement Lifecycle. The Server must be started by other means. -tomcat.stopNotLifecycle=Tomcat.stop() was called but the Server implementation does not implement Lifecycle. The Server must be stopped by other means. userConfig.database=Exception loading user database userConfig.deploy=Deploying web application for user {0} userConfig.deploying=Deploying user web applications diff --git a/java/org/apache/catalina/startup/Tomcat.java b/java/org/apache/catalina/startup/Tomcat.java index e7e6491c3..b07b60453 100644 --- a/java/org/apache/catalina/startup/Tomcat.java +++ b/java/org/apache/catalina/startup/Tomcat.java @@ -52,9 +52,6 @@ import org.apache.catalina.core.StandardWrapper; import org.apache.catalina.realm.GenericPrincipal; import org.apache.catalina.realm.RealmBase; import org.apache.catalina.session.StandardManager; -import org.apache.juli.logging.Log; -import org.apache.juli.logging.LogFactory; -import org.apache.tomcat.util.res.StringManager; // TODO: lazy init for the temp dir - only when a JSP is compiled or // get temp dir is called we need to create it. This will avoid the @@ -91,9 +88,6 @@ import org.apache.tomcat.util.res.StringManager; * @author Costin Manolache */ public class Tomcat { - private static final Log log = LogFactory.getLog(Tomcat.class); - private static final StringManager sm = StringManager.getManager(Constants.Package); - // Single engine, service, server, connector - few cases need more, // they can use server.xml protected Server server; @@ -295,11 +289,7 @@ public class Tomcat { getServer(); getConnector(); server.initialize(); - if (server instanceof Lifecycle) { - ((Lifecycle) server).start(); - } else { - log.warn(sm.getString("tomcat.startNotLifecycle")); - } + server.start(); } /** @@ -310,11 +300,7 @@ public class Tomcat { */ public void stop() throws LifecycleException { getServer(); - if (server instanceof Lifecycle) { - ((Lifecycle) server).stop(); - } else { - log.warn(sm.getString("tomcat.stopNotLifecycle")); - } + server.stop(); } @@ -454,11 +440,7 @@ public class Tomcat { Context ctx = new StandardContext(); ctx.setPath( contextPath ); ctx.setDocBase(dir); - if (ctx instanceof Lifecycle) { - ((Lifecycle) ctx).addLifecycleListener(new FixContextListener()); - } else { - log.warn(sm.getString("tomcat.addContextNotLifecycle")); - } + ctx.addLifecycleListener(new FixContextListener()); if (host == null) { getHost().addChild(ctx); @@ -478,17 +460,14 @@ public class Tomcat { initSimpleAuth(); } ctx.setRealm(defaultRealm); - if (ctx instanceof Lifecycle) { - ((Lifecycle) ctx).addLifecycleListener(new DefaultWebXmlListener()); - - ContextConfig ctxCfg = new ContextConfig(); - ((Lifecycle) ctx).addLifecycleListener(ctxCfg); - - // prevent it from looking ( if it finds one - it'll have dup error ) - ctxCfg.setDefaultWebXml("org/apache/catalin/startup/NO_DEFAULT_XML"); - } else { - log.warn(sm.getString("tomcat.addWebappNotLifecycle")); - } + + ctx.addLifecycleListener(new DefaultWebXmlListener()); + + ContextConfig ctxCfg = new ContextConfig(); + ctx.addLifecycleListener(ctxCfg); + + // prevent it from looking ( if it finds one - it'll have dup error ) + ctxCfg.setDefaultWebXml("org/apache/catalin/startup/NO_DEFAULT_XML"); if (host == null) { getHost().addChild(ctx); @@ -609,12 +588,7 @@ public class Tomcat { // Make sure getServer() has been called as that is where naming is // disabled getServer(); - if (server instanceof Lifecycle) { - ((Lifecycle) server).addLifecycleListener( - new NamingContextListener()); - } else { - log.warn(sm.getString("tomcat.namingNotLifecycle")); - } + server.addLifecycleListener(new NamingContextListener()); System.setProperty("catalina.useNaming", "true"); diff --git a/java/org/apache/catalina/startup/UserConfig.java b/java/org/apache/catalina/startup/UserConfig.java index 5e302e08b..bde24c81d 100644 --- a/java/org/apache/catalina/startup/UserConfig.java +++ b/java/org/apache/catalina/startup/UserConfig.java @@ -298,12 +298,10 @@ public final class UserConfig (Context) clazz.newInstance(); context.setPath(contextPath); context.setDocBase(app.toString()); - if (context instanceof Lifecycle) { - clazz = Class.forName(configClass); - LifecycleListener listener = - (LifecycleListener) clazz.newInstance(); - ((Lifecycle) context).addLifecycleListener(listener); - } + clazz = Class.forName(configClass); + LifecycleListener listener = + (LifecycleListener) clazz.newInstance(); + context.addLifecycleListener(listener); host.addChild(context); } catch (Exception e) { host.getLogger().error(sm.getString("userConfig.error", user), e); diff --git a/java/org/apache/catalina/valves/CometConnectionManagerValve.java b/java/org/apache/catalina/valves/CometConnectionManagerValve.java index 67905ba14..0ce5e9590 100644 --- a/java/org/apache/catalina/valves/CometConnectionManagerValve.java +++ b/java/org/apache/catalina/valves/CometConnectionManagerValve.java @@ -166,7 +166,7 @@ public class CometConnectionManagerValve started = true; if (container instanceof Context) { - ((Lifecycle) container).addLifecycleListener(this); + container.addLifecycleListener(this); } } @@ -190,7 +190,7 @@ public class CometConnectionManagerValve started = false; if (container instanceof Context) { - ((Lifecycle) container).removeLifecycleListener(this); + container.removeLifecycleListener(this); } } diff --git a/test/org/apache/catalina/loader/TestWebappClassLoaderMemoryLeak.java b/test/org/apache/catalina/loader/TestWebappClassLoaderMemoryLeak.java index 5bf75b1b0..4605c22c9 100644 --- a/test/org/apache/catalina/loader/TestWebappClassLoaderMemoryLeak.java +++ b/test/org/apache/catalina/loader/TestWebappClassLoaderMemoryLeak.java @@ -10,7 +10,6 @@ import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.apache.catalina.Context; -import org.apache.catalina.Lifecycle; import org.apache.catalina.startup.Tomcat; import org.apache.catalina.startup.TomcatBaseTest; @@ -32,11 +31,7 @@ public class TestWebappClassLoaderMemoryLeak extends TomcatBaseTest { getUrl("http://localhost:" + getPort() + "/"); // Stop the context - if (ctx instanceof Lifecycle) { - ((Lifecycle) ctx).stop(); - } else { - fail("Test requires context implements Lifecycle"); - } + ctx.stop(); // If the thread still exists, we have a thread/memory leak Thread[] threads = getThreads();