From: markt Date: Sun, 7 Mar 2010 21:30:32 +0000 (+0000) Subject: Lifecycle refactoring - ContainerBase X-Git-Url: https://git.internetallee.de/?a=commitdiff_plain;h=908fea20b9760b0911ad961af96ea53c6918d989;p=tomcat7.0 Lifecycle refactoring - ContainerBase Adds a new CONFIGURE event to allow Context to fire the START event at the right time Context fires START a little later ReplicatedContext takes advantage of LifecycleBase ensuring start() is only called once git-svn-id: https://svn.apache.org/repos/asf/tomcat/trunk@920122 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/java/org/apache/catalina/Context.java b/java/org/apache/catalina/Context.java index d2c3ce4e3..595ed5eb5 100644 --- a/java/org/apache/catalina/Context.java +++ b/java/org/apache/catalina/Context.java @@ -119,14 +119,6 @@ public interface Context extends Container { /** - * Set the application available flag for this Context. - * - * @param available The new application available flag - */ - public void setAvailable(boolean available); - - - /** * Return the Locale to character set mapper for this Context. */ public CharsetMapper getCharsetMapper(); diff --git a/java/org/apache/catalina/Lifecycle.java b/java/org/apache/catalina/Lifecycle.java index fc108c2ac..d92cfb416 100644 --- a/java/org/apache/catalina/Lifecycle.java +++ b/java/org/apache/catalina/Lifecycle.java @@ -127,6 +127,15 @@ public interface Lifecycle { public static final String PERIODIC_EVENT = "periodic"; + /** + * The LifecycleEvent type for the "configure" event. Use by those + * components that use a separate component to perform configuration and + * need to signal when configuration should be performed - usually after + * {@link #BEFORE_START_EVENT} and before {@link #START_EVENT}. + */ + public static final String CONFIGURE_EVENT = "configure"; + + // --------------------------------------------------------- Public Methods @@ -208,7 +217,5 @@ public interface Lifecycle { * * @return The current state of the source component. */ - // TODO Remove this comment once all components that implement Lifecycle - // have had this method added - //public LifecycleState getState(); + public LifecycleState getState(); } diff --git a/java/org/apache/catalina/core/ContainerBase.java b/java/org/apache/catalina/core/ContainerBase.java index a433c0f51..ae8fa9e8a 100644 --- a/java/org/apache/catalina/core/ContainerBase.java +++ b/java/org/apache/catalina/core/ContainerBase.java @@ -44,7 +44,7 @@ import org.apache.catalina.ContainerListener; import org.apache.catalina.Globals; import org.apache.catalina.Lifecycle; import org.apache.catalina.LifecycleException; -import org.apache.catalina.LifecycleListener; +import org.apache.catalina.LifecycleState; import org.apache.catalina.Loader; import org.apache.catalina.Manager; import org.apache.catalina.Pipeline; @@ -52,7 +52,7 @@ import org.apache.catalina.Realm; import org.apache.catalina.Valve; import org.apache.catalina.connector.Request; import org.apache.catalina.connector.Response; -import org.apache.catalina.util.LifecycleSupport; +import org.apache.catalina.util.LifecycleBase; import org.apache.tomcat.util.res.StringManager; import org.apache.juli.logging.Log; import org.apache.juli.logging.LogFactory; @@ -122,7 +122,7 @@ import org.apache.tomcat.util.modeler.Registry; * @author Craig R. McClanahan */ -public abstract class ContainerBase +public abstract class ContainerBase extends LifecycleBase implements Container, MBeanRegistration { private static final org.apache.juli.logging.Log log= @@ -168,12 +168,6 @@ public abstract class ContainerBase /** - * The lifecycle event support for this component. - */ - protected LifecycleSupport lifecycle = new LifecycleSupport(this); - - - /** * The container event listeners for this Container. */ protected ArrayList listeners = new ArrayList(); @@ -254,10 +248,8 @@ public abstract class ContainerBase /** - * Has this component been started? + * Has this component been initialized? */ - protected boolean started = false; - protected boolean initialized=false; /** @@ -352,7 +344,7 @@ public abstract class ContainerBase this.loader = loader; // Stop the old component if necessary - if (started && (oldLoader != null) && + if (getState().isAvailable() && (oldLoader != null) && (oldLoader instanceof Lifecycle)) { try { ((Lifecycle) oldLoader).stop(); @@ -364,7 +356,7 @@ public abstract class ContainerBase // Start the new component if necessary if (loader != null) loader.setContainer(this); - if (started && (loader != null) && + if (getState().isAvailable() && (loader != null) && (loader instanceof Lifecycle)) { try { ((Lifecycle) loader).start(); @@ -422,7 +414,7 @@ public abstract class ContainerBase this.manager = manager; // Stop the old component if necessary - if (started && (oldManager != null) && + if (getState().isAvailable() && (oldManager != null) && (oldManager instanceof Lifecycle)) { try { ((Lifecycle) oldManager).stop(); @@ -434,7 +426,7 @@ public abstract class ContainerBase // Start the new component if necessary if (manager != null) manager.setContainer(this); - if (started && (manager != null) && + if (getState().isAvailable() && (manager != null) && (manager instanceof Lifecycle)) { try { ((Lifecycle) manager).start(); @@ -486,7 +478,7 @@ public abstract class ContainerBase this.cluster = cluster; // Stop the old component if necessary - if (started && (oldCluster != null) && + if (getState().isAvailable() && (oldCluster != null) && (oldCluster instanceof Lifecycle)) { try { ((Lifecycle) oldCluster).stop(); @@ -499,7 +491,7 @@ public abstract class ContainerBase if (cluster != null) cluster.setContainer(this); - if (started && (cluster != null) && + if (getState().isAvailable() && (cluster != null) && (cluster instanceof Lifecycle)) { try { ((Lifecycle) cluster).start(); @@ -675,7 +667,7 @@ public abstract class ContainerBase this.realm = realm; // Stop the old component if necessary - if (started && (oldRealm != null) && + if (getState().isAvailable() && (oldRealm != null) && (oldRealm instanceof Lifecycle)) { try { ((Lifecycle) oldRealm).stop(); @@ -687,7 +679,7 @@ public abstract class ContainerBase // Start the new component if necessary if (realm != null) realm.setContainer(this); - if (started && (realm != null) && + if (getState().isAvailable() && (realm != null) && (realm instanceof Lifecycle)) { try { ((Lifecycle) realm).start(); @@ -787,7 +779,7 @@ public abstract class ContainerBase children.put(child.getName(), child); // Start child - if (started && startChildren) { + if (getState().isAvailable() && startChildren) { boolean success = false; try { child.start(); @@ -919,13 +911,9 @@ public abstract class ContainerBase children.remove(child.getName()); } - if (started) { + if (getState().isAvailable()) { try { - if( child instanceof ContainerBase ) { - if( ((ContainerBase)child).started ) { - child.stop(); - } - } else { + if (child.getState().isAvailable()) { child.stop(); } } catch (LifecycleException e) { @@ -966,63 +954,15 @@ public abstract class ContainerBase } - // ------------------------------------------------------ Lifecycle Methods - - - /** - * Add a lifecycle event listener to this component. - * - * @param listener The listener to add - */ - public void addLifecycleListener(LifecycleListener listener) { - - lifecycle.addLifecycleListener(listener); - - } - - - /** - * Get the lifecycle listeners associated with this lifecycle. If this - * Lifecycle has no listeners registered, a zero-length array is returned. - */ - public LifecycleListener[] findLifecycleListeners() { - - return lifecycle.findLifecycleListeners(); - - } - - - /** - * Remove a lifecycle event listener from this component. - * - * @param listener The listener to remove - */ - public void removeLifecycleListener(LifecycleListener listener) { - - lifecycle.removeLifecycleListener(listener); - - } - - /** - * Prepare for active use of the public methods of this Component. + * Start this component and implement the requirements + * of {@link LifecycleBase#startInternal()}. * * @exception LifecycleException if this component detects a fatal error - * that prevents it from being started + * that prevents this component from being used */ - public synchronized void start() throws LifecycleException { - - // Validate and update our current component state - if (started) { - if(log.isInfoEnabled()) - log.info(sm.getString("containerBase.alreadyStarted", logName())); - return; - } - - // Notify our interested LifecycleListeners - lifecycle.fireLifecycleEvent(BEFORE_START_EVENT, null); - - started = true; + @Override + protected synchronized void startInternal() throws LifecycleException { // Start our subordinate components, if any if ((loader != null) && (loader instanceof Lifecycle)) @@ -1050,42 +990,29 @@ public abstract class ContainerBase if (pipeline instanceof Lifecycle) ((Lifecycle) pipeline).start(); - // Notify our interested LifecycleListeners - lifecycle.fireLifecycleEvent(START_EVENT, null); + + setState(LifecycleState.STARTING); // Start our thread threadStart(); - // Notify our interested LifecycleListeners - lifecycle.fireLifecycleEvent(AFTER_START_EVENT, null); - } /** - * Gracefully shut down active use of the public methods of this Component. + * Stop this component and implement the requirements + * of {@link LifecycleBase#stopInternal()}. * * @exception LifecycleException if this component detects a fatal error - * that needs to be reported + * that prevents this component from being used */ - public synchronized void stop() throws LifecycleException { - - // Validate and update our current component state - if (!started) { - if(log.isInfoEnabled()) - log.info(sm.getString("containerBase.notStarted", logName())); - return; - } - - // Notify our interested LifecycleListeners - lifecycle.fireLifecycleEvent(BEFORE_STOP_EVENT, null); + @Override + protected synchronized void stopInternal() throws LifecycleException { // Stop our thread threadStop(); - // Notify our interested LifecycleListeners - lifecycle.fireLifecycleEvent(STOP_EVENT, null); - started = false; + setState(LifecycleState.STOPPING); // Stop the Valves in our pipeline (including the basic), if any if (pipeline instanceof Lifecycle) { @@ -1122,10 +1049,6 @@ public abstract class ContainerBase if ((loader != null) && (loader instanceof Lifecycle)) { ((Lifecycle) loader).stop(); } - - // Notify our interested LifecycleListeners - lifecycle.fireLifecycleEvent(AFTER_STOP_EVENT, null); - } /** Init method, part of the MBean lifecycle. @@ -1160,7 +1083,7 @@ public abstract class ContainerBase } public void destroy() throws Exception { - if( started ) { + if (getState().isAvailable()) { stop(); } initialized=false; @@ -1224,7 +1147,7 @@ public abstract class ContainerBase */ public void backgroundProcess() { - if (!started) + if (!getState().isAvailable()) return; if (cluster != null) { @@ -1264,7 +1187,7 @@ public abstract class ContainerBase } current = current.getNext(); } - lifecycle.fireLifecycleEvent(Lifecycle.PERIODIC_EVENT, null); + fireLifecycleEvent(Lifecycle.PERIODIC_EVENT, null); } diff --git a/java/org/apache/catalina/core/StandardContext.java b/java/org/apache/catalina/core/StandardContext.java index 50ee84a4e..f5fa07f10 100644 --- a/java/org/apache/catalina/core/StandardContext.java +++ b/java/org/apache/catalina/core/StandardContext.java @@ -69,6 +69,7 @@ import org.apache.catalina.InstanceListener; import org.apache.catalina.Lifecycle; import org.apache.catalina.LifecycleException; import org.apache.catalina.LifecycleListener; +import org.apache.catalina.LifecycleState; import org.apache.catalina.Loader; import org.apache.catalina.Manager; import org.apache.catalina.Pipeline; @@ -92,6 +93,7 @@ import org.apache.catalina.startup.ContextConfig; import org.apache.catalina.startup.TldConfig; import org.apache.catalina.util.CharsetMapper; import org.apache.catalina.util.ExtensionValidator; +import org.apache.catalina.util.LifecycleBase; import org.apache.catalina.util.RequestUtil; import org.apache.catalina.util.URLEncoder; import org.apache.juli.logging.Log; @@ -235,11 +237,6 @@ public class StandardContext /** - * The application available flag for this Context. - */ - private boolean available = false; - - /** * The broadcaster that sends j2ee notifications. */ private NotificationBroadcasterSupport broadcaster = null; @@ -1133,23 +1130,8 @@ public class StandardContext */ public boolean getAvailable() { - return (this.available); - - } - - - /** - * Set the application available flag for this Context. - * - * @param available The new application available flag - */ - public void setAvailable(boolean available) { - - boolean oldAvailable = this.available; - this.available = available; - support.firePropertyChange("available", - oldAvailable, - this.available); + // TODO Remove this method entirely + return getState().isAvailable(); } @@ -2020,7 +2002,7 @@ public class StandardContext @Override public synchronized void setResources(DirContext resources) { - if (started) { + if (getState().isAvailable()) { throw new IllegalStateException (sm.getString("standardContext.resources.started")); } @@ -2129,7 +2111,7 @@ public class StandardContext this.workDir = workDir; - if (started) { + if (getState().isAvailable()) { postWorkDirectory(); } } @@ -3331,7 +3313,7 @@ public class StandardContext public synchronized void reload() { // Validate our current component state - if (!started) + if (!getState().isAvailable()) throw new IllegalStateException (sm.getString("containerBase.notStarted", logName())); @@ -4325,18 +4307,15 @@ public class StandardContext /** - * Start this Context component. + * Start this component and implement the requirements + * of {@link LifecycleBase#startInternal()}. * - * @exception LifecycleException if a startup error occurs + * @exception LifecycleException if this component detects a fatal error + * that prevents this component from being used */ @Override - public synchronized void start() throws LifecycleException { - //if (lazy ) return; - if (started) { - if(log.isInfoEnabled()) - log.info(sm.getString("containerBase.alreadyStarted", logName())); - return; - } + protected synchronized void startInternal() throws LifecycleException { + if( !initialized ) { try { init(); @@ -4357,10 +4336,6 @@ public class StandardContext Registry.getRegistry(null, null).unregisterComponent(oname); } - // Notify our interested LifecycleListeners - lifecycle.fireLifecycleEvent(BEFORE_START_EVENT, null); - - setAvailable(false); setConfigured(false); boolean ok = true; @@ -4461,8 +4436,6 @@ public class StandardContext if (ok) { - started = true; - // Start our subordinate components, if any if ((loader != null) && (loader instanceof Lifecycle)) ((Lifecycle) loader).start(); @@ -4500,7 +4473,7 @@ public class StandardContext } // Notify our interested LifecycleListeners - lifecycle.fireLifecycleEvent(START_EVENT, null); + fireLifecycleEvent(Lifecycle.CONFIGURE_EVENT, null); // Acquire clustered manager Manager contextManager = null; @@ -4585,11 +4558,6 @@ public class StandardContext postWelcomeFiles(); } - if (ok) { - // Notify our interested LifecycleListeners - lifecycle.fireLifecycleEvent(AFTER_START_EVENT, null); - } - // Configure and call application event listeners if (ok) { if (!listenerStart()) { @@ -4633,15 +4601,8 @@ public class StandardContext if (ok) { if (log.isDebugEnabled()) log.debug("Starting completed"); - setAvailable(true); } else { log.error(sm.getString("standardContext.startFailed", getName())); - try { - stop(); - } catch (Throwable t) { - log.error(sm.getString("standardContext.startCleanup"), t); - } - setAvailable(false); } // JMX registration @@ -4664,11 +4625,11 @@ public class StandardContext } // Reinitializing if something went wrong - if (!ok && started) { - stop(); + if (!ok) { + setState(LifecycleState.FAILED); + } else { + setState(LifecycleState.STARTING); } - - //cacheContext(); } private Map> buildInjectionMap(NamingResources namingResources) { @@ -4714,23 +4675,15 @@ public class StandardContext } /** - * Stop this Context component. + * Stop this component and implement the requirements + * of {@link LifecycleBase#stopInternal()}. * - * @exception LifecycleException if a shutdown error occurs + * @exception LifecycleException if this component detects a fatal error + * that prevents this component from being used */ @Override - public synchronized void stop() throws LifecycleException { - - // Validate and update our current component state - if (!started) { - if(log.isInfoEnabled()) - log.info(sm.getString("containerBase.notStarted", logName())); - return; - } + protected synchronized void stopInternal() throws LifecycleException { - // Notify our interested LifecycleListeners - lifecycle.fireLifecycleEvent(BEFORE_STOP_EVENT, null); - // Send j2ee.state.stopping notification if (this.getObjectName() != null) { Notification notification = @@ -4739,8 +4692,7 @@ public class StandardContext broadcaster.sendNotification(notification); } - // Mark this application as unavailable while we shut down - setAvailable(false); + setState(LifecycleState.STOPPING); // Binding thread ClassLoader oldCCL = bindThread(); @@ -4772,9 +4724,6 @@ public class StandardContext // Normal container shutdown processing if (log.isDebugEnabled()) log.debug("Processing standard container shutdown"); - // Notify our interested LifecycleListeners - lifecycle.fireLifecycleEvent(STOP_EVENT, null); - started = false; // Stop the Valves in our pipeline (including the basic), if any if (pipeline instanceof Lifecycle) { @@ -4829,9 +4778,6 @@ public class StandardContext //reset the instance manager instanceManager = null; - // Notify our interested LifecycleListeners - lifecycle.fireLifecycleEvent(AFTER_STOP_EVENT, null); - if (log.isDebugEnabled()) log.debug("Stopping complete"); @@ -4861,7 +4807,7 @@ public class StandardContext super.destroy(); // Notify our interested LifecycleListeners - lifecycle.fireLifecycleEvent(DESTROY_EVENT, null); + fireLifecycleEvent(DESTROY_EVENT, null); synchronized (instanceListenersLock) { instanceListeners = new String[0]; @@ -5470,7 +5416,7 @@ public class StandardContext @Override public void preDeregister() throws Exception { - if( started ) { + if (getState().isAvailable()) { try { stop(); } catch( Exception ex ) { @@ -5542,7 +5488,7 @@ public class StandardContext super.init(); // Notify our interested LifecycleListeners - lifecycle.fireLifecycleEvent(INIT_EVENT, null); + fireLifecycleEvent(INIT_EVENT, null); // Send j2ee.state.starting notification if (this.getObjectName() != null) { diff --git a/java/org/apache/catalina/core/StandardEngine.java b/java/org/apache/catalina/core/StandardEngine.java index 194785c59..d1d5172da 100644 --- a/java/org/apache/catalina/core/StandardEngine.java +++ b/java/org/apache/catalina/core/StandardEngine.java @@ -33,6 +33,7 @@ import org.apache.catalina.LifecycleException; import org.apache.catalina.Realm; import org.apache.catalina.Service; import org.apache.catalina.realm.JAASRealm; +import org.apache.catalina.util.LifecycleBase; import org.apache.catalina.util.ServerInfo; import org.apache.juli.logging.Log; import org.apache.juli.logging.LogFactory; @@ -404,15 +405,15 @@ public class StandardEngine } /** - * Start this Engine component. + * Start this component and implement the requirements + * of {@link LifecycleBase#startInternal()}. * - * @exception LifecycleException if a startup error occurs + * @exception LifecycleException if this component detects a fatal error + * that prevents this component from being used */ @Override - public void start() throws LifecycleException { - if( started ) { - return; - } + protected synchronized void startInternal() throws LifecycleException { + if( !initialized ) { init(); } @@ -448,13 +449,22 @@ public class StandardEngine } // Standard container startup - super.start(); - + super.startInternal(); } + + /** + * Stop this component and implement the requirements + * of {@link LifecycleBase#stopInternal()}. + * + * @exception LifecycleException if this component detects a fatal error + * that prevents this component from being used + */ @Override - public void stop() throws LifecycleException { - super.stop(); + protected synchronized void stopInternal() throws LifecycleException { + + super.stopInternal(); + if( mbeans != null ) { try { Registry.getRegistry(null, null).invoke(mbeans, "stop", false); diff --git a/java/org/apache/catalina/core/StandardHost.java b/java/org/apache/catalina/core/StandardHost.java index e3af7fc1d..5526e2c31 100644 --- a/java/org/apache/catalina/core/StandardHost.java +++ b/java/org/apache/catalina/core/StandardHost.java @@ -37,6 +37,7 @@ import org.apache.catalina.LifecycleListener; import org.apache.catalina.Valve; import org.apache.catalina.loader.WebappClassLoader; import org.apache.catalina.startup.HostConfig; +import org.apache.catalina.util.LifecycleBase; import org.apache.catalina.valves.ValveBase; import org.apache.tomcat.util.modeler.Registry; @@ -764,16 +765,15 @@ public class StandardHost } /** - * Start this host. + * Start this component and implement the requirements + * of {@link LifecycleBase#startInternal()}. * * @exception LifecycleException if this component detects a fatal error - * that prevents it from being started + * that prevents this component from being used */ @Override - public synchronized void start() throws LifecycleException { - if( started ) { - return; - } + protected synchronized void startInternal() throws LifecycleException { + if( ! initialized ) init(); @@ -824,8 +824,8 @@ public class StandardHost else log.debug(sm.getString("standardHost.validationDisabled")); } - super.start(); - + + super.startInternal(); } diff --git a/java/org/apache/catalina/core/StandardWrapper.java b/java/org/apache/catalina/core/StandardWrapper.java index fb509ac77..7a59ab9db 100644 --- a/java/org/apache/catalina/core/StandardWrapper.java +++ b/java/org/apache/catalina/core/StandardWrapper.java @@ -57,6 +57,7 @@ import org.apache.catalina.Wrapper; import org.apache.catalina.security.SecurityUtil; import org.apache.catalina.util.Enumerator; import org.apache.catalina.util.InstanceSupport; +import org.apache.catalina.util.LifecycleBase; import org.apache.tomcat.InstanceManager; import org.apache.tomcat.PeriodicEventListener; import org.apache.tomcat.util.log.SystemLogHandler; @@ -675,7 +676,7 @@ public class StandardWrapper public void backgroundProcess() { super.backgroundProcess(); - if (!started) + if (!getState().isAvailable()) return; if (getServlet() != null && (getServlet() instanceof PeriodicEventListener)) { @@ -1613,13 +1614,14 @@ public class StandardWrapper /** - * Start this component, pre-loading the servlet if the load-on-startup - * value is set appropriately. + * Start this component and implement the requirements + * of {@link LifecycleBase#startInternal()}. * - * @exception LifecycleException if a fatal error occurs during startup + * @exception LifecycleException if this component detects a fatal error + * that prevents this component from being used */ @Override - public void start() throws LifecycleException { + protected synchronized void startInternal() throws LifecycleException { // Send j2ee.state.starting notification if (this.getObjectName() != null) { @@ -1630,7 +1632,7 @@ public class StandardWrapper } // Start up this component - super.start(); + super.startInternal(); if( oname != null ) registerJMX((StandardContext)getParent()); @@ -1652,13 +1654,14 @@ public class StandardWrapper /** - * Stop this component, gracefully shutting down the servlet if it has - * been initialized. + * Stop this component and implement the requirements + * of {@link LifecycleBase#stopInternal()}. * - * @exception LifecycleException if a fatal error occurs during shutdown + * @exception LifecycleException if this component detects a fatal error + * that prevents this component from being used */ @Override - public void stop() throws LifecycleException { + protected synchronized void stopInternal() throws LifecycleException { setAvailable(Long.MAX_VALUE); @@ -1679,7 +1682,7 @@ public class StandardWrapper } // Shut down this component - super.stop(); + super.stopInternal(); // Send j2ee.state.stoppped notification if (this.getObjectName() != null) { diff --git a/java/org/apache/catalina/ha/context/ReplicatedContext.java b/java/org/apache/catalina/ha/context/ReplicatedContext.java index d5f54b0b1..0bd53e71c 100644 --- a/java/org/apache/catalina/ha/context/ReplicatedContext.java +++ b/java/org/apache/catalina/ha/context/ReplicatedContext.java @@ -26,11 +26,10 @@ import org.apache.catalina.core.ApplicationContext; import org.apache.catalina.Globals; import javax.servlet.ServletContext; import java.util.AbstractMap; -import org.apache.catalina.LifecycleEvent; -import org.apache.catalina.LifecycleListener; import java.util.Enumeration; import java.util.concurrent.ConcurrentHashMap; import org.apache.catalina.util.Enumerator; +import org.apache.catalina.util.LifecycleBase; import org.apache.catalina.tribes.tipis.AbstractReplicatedMap.MapOwner; import org.apache.juli.logging.Log; @@ -40,20 +39,21 @@ import org.apache.juli.logging.LogFactory; * @author Filip Hanik * @version 1.0 */ -public class ReplicatedContext extends StandardContext implements LifecycleListener,MapOwner { +public class ReplicatedContext extends StandardContext implements MapOwner { private int mapSendOptions = Channel.SEND_OPTIONS_DEFAULT; private static final Log log = LogFactory.getLog( ReplicatedContext.class ); - protected boolean startComplete = false; protected static long DEFAULT_REPL_TIMEOUT = 15000;//15 seconds - public void lifecycleEvent(LifecycleEvent event) { - if (AFTER_START_EVENT.equals(event.getType())) - startComplete = true; - } - + /** + * Start this component and implement the requirements + * of {@link LifecycleBase#startInternal()}. + * + * @exception LifecycleException if this component detects a fatal error + * that prevents this component from being used + */ @Override - public synchronized void start() throws LifecycleException { - if ( this.started ) return; + protected synchronized void startInternal() throws LifecycleException { + if( !initialized ) { try { init(); @@ -61,7 +61,7 @@ public class ReplicatedContext extends StandardContext implements LifecycleListe throw new LifecycleException("Error initializaing ", ex); } } - super.addLifecycleListener(this); + try { CatalinaCluster catclust = (CatalinaCluster)this.getCluster(); if (this.context == null) this.context = new ReplApplContext(this); @@ -72,33 +72,30 @@ public class ReplicatedContext extends StandardContext implements LifecycleListe ((ReplApplContext)this.context).setAttributeMap(map); if (getAltDDName() != null) context.setAttribute(Globals.ALT_DD_ATTR, getAltDDName()); } - super.start(); + super.startInternal(); } catch ( Exception x ) { log.error("Unable to start ReplicatedContext",x); throw new LifecycleException("Failed to start ReplicatedContext",x); } } + /** + * Stop this component and implement the requirements + * of {@link LifecycleBase#stopInternal()}. + * + * @exception LifecycleException if this component detects a fatal error + * that prevents this component from being used + */ @Override - public synchronized void stop() throws LifecycleException - { - if ( !this.started ) return; + protected synchronized void stopInternal() throws LifecycleException { + + super.stopInternal(); + AbstractMap map = ((ReplApplContext)this.context).getAttributeMap(); if ( map!=null && map instanceof ReplicatedMap) { ((ReplicatedMap)map).breakdown(); } - try { - super.lifecycle.removeLifecycleListener(this); - } catch ( Exception x ){ - log.error("Unable to stop ReplicatedContext",x); - throw new LifecycleException("Failed to stop ReplicatedContext",x); - } finally { - this.startComplete = false; - super.stop(); - } - - } @@ -169,7 +166,7 @@ public class ReplicatedContext extends StandardContext implements LifecycleListe @Override public void setAttribute(String name, Object value) { - if ( (!getParent().startComplete) || "org.apache.jasper.runtime.JspApplicationContextImpl".equals(name) ){ + if ( (!getParent().getState().isAvailable()) || "org.apache.jasper.runtime.JspApplicationContextImpl".equals(name) ){ tomcatAttributes.put(name,value); } else super.setAttribute(name,value); diff --git a/java/org/apache/catalina/startup/ContextConfig.java b/java/org/apache/catalina/startup/ContextConfig.java index 3d03ea45b..cae33a7cd 100644 --- a/java/org/apache/catalina/startup/ContextConfig.java +++ b/java/org/apache/catalina/startup/ContextConfig.java @@ -284,8 +284,8 @@ public class ContextConfig } // Process the event that has occurred - if (event.getType().equals(Lifecycle.START_EVENT)) { - start(); + if (event.getType().equals(Lifecycle.CONFIGURE_EVENT)) { + configure(); } else if (event.getType().equals(Lifecycle.BEFORE_START_EVENT)) { beforeStart(); } else if (event.getType().equals(Lifecycle.AFTER_START_EVENT)) { @@ -821,9 +821,9 @@ public class ContextConfig /** - * Process a "start" event for this Context. + * Process a "contextConfig" event for this Context. */ - protected synchronized void start() { + protected synchronized void configure() { // Called from StandardContext.start() if (log.isDebugEnabled()) diff --git a/java/org/apache/catalina/startup/TldConfig.java b/java/org/apache/catalina/startup/TldConfig.java index e8f5169a5..a5a4e9d37 100644 --- a/java/org/apache/catalina/startup/TldConfig.java +++ b/java/org/apache/catalina/startup/TldConfig.java @@ -569,7 +569,7 @@ public final class TldConfig implements LifecycleListener { if (event.getType().equals(Lifecycle.INIT_EVENT)) { init(); - } else if (event.getType().equals(Lifecycle.START_EVENT)) { + } else if (event.getType().equals(Lifecycle.CONFIGURE_EVENT)) { try { execute(); } catch (Exception e) { diff --git a/java/org/apache/catalina/startup/Tomcat.java b/java/org/apache/catalina/startup/Tomcat.java index b07b60453..b5e223c2e 100644 --- a/java/org/apache/catalina/startup/Tomcat.java +++ b/java/org/apache/catalina/startup/Tomcat.java @@ -676,7 +676,7 @@ public class Tomcat { public void lifecycleEvent(LifecycleEvent event) { try { Context context = (Context) event.getLifecycle(); - if (event.getType().equals(Lifecycle.START_EVENT)) { + if (event.getType().equals(Lifecycle.CONFIGURE_EVENT)) { context.setConfigured(true); } } catch (ClassCastException e) {