Author: markt
Date: Sun Mar 7 21:30:32 2010
New Revision: 920122
URL: http://svn.apache.org/viewvc?rev=920122&view=rev
Log:
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
Modified:
tomcat/trunk/java/org/apache/catalina/Context.java
tomcat/trunk/java/org/apache/catalina/Lifecycle.java
tomcat/trunk/java/org/apache/catalina/core/ContainerBase.java
tomcat/trunk/java/org/apache/catalina/core/StandardContext.java
tomcat/trunk/java/org/apache/catalina/core/StandardEngine.java
tomcat/trunk/java/org/apache/catalina/core/StandardHost.java
tomcat/trunk/java/org/apache/catalina/core/StandardWrapper.java
tomcat/trunk/java/org/apache/catalina/ha/context/ReplicatedContext.java
tomcat/trunk/java/org/apache/catalina/startup/ContextConfig.java
tomcat/trunk/java/org/apache/catalina/startup/TldConfig.java
tomcat/trunk/java/org/apache/catalina/startup/Tomcat.java
Modified: tomcat/trunk/java/org/apache/catalina/Context.java
URL:
http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/Context.java?rev=920122&r1=920121&r2=920122&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/Context.java (original)
+++ tomcat/trunk/java/org/apache/catalina/Context.java Sun Mar 7 21:30:32 2010
@@ -119,14 +119,6 @@
/**
- * 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();
Modified: tomcat/trunk/java/org/apache/catalina/Lifecycle.java
URL:
http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/Lifecycle.java?rev=920122&r1=920121&r2=920122&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/Lifecycle.java (original)
+++ tomcat/trunk/java/org/apache/catalina/Lifecycle.java Sun Mar 7 21:30:32
2010
@@ -127,6 +127,15 @@
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 @@
*
* @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();
}
Modified: tomcat/trunk/java/org/apache/catalina/core/ContainerBase.java
URL:
http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/core/ContainerBase.java?rev=920122&r1=920121&r2=920122&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/core/ContainerBase.java (original)
+++ tomcat/trunk/java/org/apache/catalina/core/ContainerBase.java Sun Mar 7
21:30:32 2010
@@ -44,7 +44,7 @@
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.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 @@
* @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 @@
/**
- * The lifecycle event support for this component.
- */
- protected LifecycleSupport lifecycle = new LifecycleSupport(this);
-
-
- /**
* The container event listeners for this Container.
*/
protected ArrayList<ContainerListener> listeners = new
ArrayList<ContainerListener>();
@@ -254,10 +248,8 @@
/**
- * Has this component been started?
+ * Has this component been initialized?
*/
- protected boolean started = false;
-
protected boolean initialized=false;
/**
@@ -352,7 +344,7 @@
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 @@
// 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 @@
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 @@
// 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 @@
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 @@
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 @@
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 @@
// 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 @@
children.put(child.getName(), child);
// Start child
- if (started && startChildren) {
+ if (getState().isAvailable() && startChildren) {
boolean success = false;
try {
child.start();
@@ -919,13 +911,9 @@
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 @@
}
- // ------------------------------------------------------ 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 @@
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 @@
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 void destroy() throws Exception {
- if( started ) {
+ if (getState().isAvailable()) {
stop();
}
initialized=false;
@@ -1224,7 +1147,7 @@
*/
public void backgroundProcess() {
- if (!started)
+ if (!getState().isAvailable())
return;
if (cluster != null) {
@@ -1264,7 +1187,7 @@
}
current = current.getNext();
}
- lifecycle.fireLifecycleEvent(Lifecycle.PERIODIC_EVENT, null);
+ fireLifecycleEvent(Lifecycle.PERIODIC_EVENT, null);
}
Modified: tomcat/trunk/java/org/apache/catalina/core/StandardContext.java
URL:
http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/core/StandardContext.java?rev=920122&r1=920121&r2=920122&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/core/StandardContext.java (original)
+++ tomcat/trunk/java/org/apache/catalina/core/StandardContext.java Sun Mar 7
21:30:32 2010
@@ -69,6 +69,7 @@
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.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 @@
/**
- * 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 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 @@
@Override
public synchronized void setResources(DirContext resources) {
- if (started) {
+ if (getState().isAvailable()) {
throw new IllegalStateException
(sm.getString("standardContext.resources.started"));
}
@@ -2129,7 +2111,7 @@
this.workDir = workDir;
- if (started) {
+ if (getState().isAvailable()) {
postWorkDirectory();
}
}
@@ -3331,7 +3313,7 @@
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 @@
/**
- * 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 @@
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 @@
if (ok) {
- started = true;
-
// Start our subordinate components, if any
if ((loader != null) && (loader instanceof Lifecycle))
((Lifecycle) loader).start();
@@ -4500,7 +4473,7 @@
}
// Notify our interested LifecycleListeners
- lifecycle.fireLifecycleEvent(START_EVENT, null);
+ fireLifecycleEvent(Lifecycle.CONFIGURE_EVENT, null);
// Acquire clustered manager
Manager contextManager = null;
@@ -4585,11 +4558,6 @@
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 @@
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 @@
}
// Reinitializing if something went wrong
- if (!ok && started) {
- stop();
+ if (!ok) {
+ setState(LifecycleState.FAILED);
+ } else {
+ setState(LifecycleState.STARTING);
}
-
- //cacheContext();
}
private Map<String, Map<String, String>> buildInjectionMap(NamingResources
namingResources) {
@@ -4714,23 +4675,15 @@
}
/**
- * 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 @@
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 @@
// 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 @@
//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 @@
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 @@
@Override
public void preDeregister() throws Exception {
- if( started ) {
+ if (getState().isAvailable()) {
try {
stop();
} catch( Exception ex ) {
@@ -5542,7 +5488,7 @@
super.init();
// Notify our interested LifecycleListeners
- lifecycle.fireLifecycleEvent(INIT_EVENT, null);
+ fireLifecycleEvent(INIT_EVENT, null);
// Send j2ee.state.starting notification
if (this.getObjectName() != null) {
Modified: tomcat/trunk/java/org/apache/catalina/core/StandardEngine.java
URL:
http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/core/StandardEngine.java?rev=920122&r1=920121&r2=920122&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/core/StandardEngine.java (original)
+++ tomcat/trunk/java/org/apache/catalina/core/StandardEngine.java Sun Mar 7
21:30:32 2010
@@ -33,6 +33,7 @@
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 @@
}
/**
- * 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 @@
}
// 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);
Modified: tomcat/trunk/java/org/apache/catalina/core/StandardHost.java
URL:
http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/core/StandardHost.java?rev=920122&r1=920121&r2=920122&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/core/StandardHost.java (original)
+++ tomcat/trunk/java/org/apache/catalina/core/StandardHost.java Sun Mar 7
21:30:32 2010
@@ -37,6 +37,7 @@
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 @@
}
/**
- * 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 @@
else
log.debug(sm.getString("standardHost.validationDisabled"));
}
- super.start();
-
+
+ super.startInternal();
}
Modified: tomcat/trunk/java/org/apache/catalina/core/StandardWrapper.java
URL:
http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/core/StandardWrapper.java?rev=920122&r1=920121&r2=920122&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/core/StandardWrapper.java (original)
+++ tomcat/trunk/java/org/apache/catalina/core/StandardWrapper.java Sun Mar 7
21:30:32 2010
@@ -57,6 +57,7 @@
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 void backgroundProcess() {
super.backgroundProcess();
- if (!started)
+ if (!getState().isAvailable())
return;
if (getServlet() != null && (getServlet() instanceof
PeriodicEventListener)) {
@@ -1613,13 +1614,14 @@
/**
- * 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 @@
}
// Start up this component
- super.start();
+ super.startInternal();
if( oname != null )
registerJMX((StandardContext)getParent());
@@ -1652,13 +1654,14 @@
/**
- * 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 @@
}
// Shut down this component
- super.stop();
+ super.stopInternal();
// Send j2ee.state.stoppped notification
if (this.getObjectName() != null) {
Modified:
tomcat/trunk/java/org/apache/catalina/ha/context/ReplicatedContext.java
URL:
http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/ha/context/ReplicatedContext.java?rev=920122&r1=920121&r2=920122&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/ha/context/ReplicatedContext.java
(original)
+++ tomcat/trunk/java/org/apache/catalina/ha/context/ReplicatedContext.java Sun
Mar 7 21:30:32 2010
@@ -26,11 +26,10 @@
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 @@
* @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 @@
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 @@
((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<String,Object> 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 @@
@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);
Modified: tomcat/trunk/java/org/apache/catalina/startup/ContextConfig.java
URL:
http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/startup/ContextConfig.java?rev=920122&r1=920121&r2=920122&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/startup/ContextConfig.java (original)
+++ tomcat/trunk/java/org/apache/catalina/startup/ContextConfig.java Sun Mar 7
21:30:32 2010
@@ -284,8 +284,8 @@
}
// 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 @@
/**
- * 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())
Modified: tomcat/trunk/java/org/apache/catalina/startup/TldConfig.java
URL:
http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/startup/TldConfig.java?rev=920122&r1=920121&r2=920122&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/startup/TldConfig.java (original)
+++ tomcat/trunk/java/org/apache/catalina/startup/TldConfig.java Sun Mar 7
21:30:32 2010
@@ -569,7 +569,7 @@
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) {
Modified: tomcat/trunk/java/org/apache/catalina/startup/Tomcat.java
URL:
http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/startup/Tomcat.java?rev=920122&r1=920121&r2=920122&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/startup/Tomcat.java (original)
+++ tomcat/trunk/java/org/apache/catalina/startup/Tomcat.java Sun Mar 7
21:30:32 2010
@@ -676,7 +676,7 @@
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) {
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]