* @version $Revision$ $Date$
*/
-public interface Container {
+public interface Container extends Lifecycle {
// ----------------------------------------------------- Manifest Constants
* @version $Revision$ $Date$
*/
-public interface Server {
+public interface Server extends Lifecycle {
// ------------------------------------------------------------- Properties
* @version $Revision$ $Date$
*/
-public interface Service {
+public interface Service extends Lifecycle {
// ------------------------------------------------------------- Properties
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);
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);
// 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
// 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();
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);
// 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),
// 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
@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
}
}
- if (started && (service instanceof Lifecycle)) {
+ if (started) {
try {
- ((Lifecycle) service).start();
+ service.start();
} catch (LifecycleException e) {
// Ignore
}
}
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];
// 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();
}
}
// 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
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
}
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
}
// Start our defined Container first
if (container != null) {
synchronized (container) {
- if (container instanceof Lifecycle) {
- ((Lifecycle) container).start();
- }
+ container.start();
}
}
// 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!
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;
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");
RequestUtil.filter(displayPath)));
return;
}
- ((Lifecycle) context).start();
+ context.start();
if (context.getAvailable())
writer.println
(sm.getString("managerServlet.started", displayPath));
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);
addServiced(path);
try {
// Try to stop the context first to be nicer
- ((Lifecycle) context).stop();
+ context.stop();
} catch (Throwable t) {
// Ignore
}
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;
// Start host
try {
- ((Lifecycle) engine.findChild(name)).start();
+ engine.findChild(name).start();
writer.println
(sm.getString("hostManagerServlet.started", name));
} catch (Throwable t) {
// Start host
try {
- ((Lifecycle) engine.findChild(name)).stop();
+ engine.findChild(name).stop();
writer.println
(sm.getString("hostManagerServlet.stopped", name));
} catch (Throwable t) {
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();
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();
}
// 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);
}
}
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);
}
ContextConfig config = new ContextConfig();
config.setCustomAuthenticators(authenticators);
- ((Lifecycle) context).addLifecycleListener(config);
+ context.addLifecycleListener(config);
return (context);
}
// 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
// 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
// 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();
}
}
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
(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);
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);
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);
// 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);
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 <taglib> 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
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
* @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;
getServer();
getConnector();
server.initialize();
- if (server instanceof Lifecycle) {
- ((Lifecycle) server).start();
- } else {
- log.warn(sm.getString("tomcat.startNotLifecycle"));
- }
+ server.start();
}
/**
*/
public void stop() throws LifecycleException {
getServer();
- if (server instanceof Lifecycle) {
- ((Lifecycle) server).stop();
- } else {
- log.warn(sm.getString("tomcat.stopNotLifecycle"));
- }
+ server.stop();
}
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);
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);
// 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");
(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);
started = true;
if (container instanceof Context) {
- ((Lifecycle) container).addLifecycleListener(this);
+ container.addLifecycleListener(this);
}
}
started = false;
if (container instanceof Context) {
- ((Lifecycle) container).removeLifecycleListener(this);
+ container.removeLifecycleListener(this);
}
}
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;
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();