tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ma...@apache.org
Subject svn commit: r940008 - in /tomcat/trunk/java/org/apache/catalina: ./ connector/ core/ ha/context/ ha/session/ ha/tcp/ loader/ realm/ session/ startup/ util/ valves/
Date Sat, 01 May 2010 13:31:47 GMT
Author: markt
Date: Sat May  1 13:31:46 2010
New Revision: 940008

URL: http://svn.apache.org/viewvc?rev=940008&view=rev
Log:
Add init() and destroy() to the Lifecycle interface
Note that this commit breaks the shutdown hook. I'll fix that in a following commit.

Modified:
    tomcat/trunk/java/org/apache/catalina/Context.java
    tomcat/trunk/java/org/apache/catalina/Lifecycle.java
    tomcat/trunk/java/org/apache/catalina/LifecycleState.java
    tomcat/trunk/java/org/apache/catalina/Server.java
    tomcat/trunk/java/org/apache/catalina/Service.java
    tomcat/trunk/java/org/apache/catalina/connector/Connector.java
    tomcat/trunk/java/org/apache/catalina/connector/LocalStrings.properties
    tomcat/trunk/java/org/apache/catalina/connector/LocalStrings_es.properties
    tomcat/trunk/java/org/apache/catalina/connector/LocalStrings_fr.properties
    tomcat/trunk/java/org/apache/catalina/connector/LocalStrings_ja.properties
    tomcat/trunk/java/org/apache/catalina/core/ApplicationServletRegistration.java
    tomcat/trunk/java/org/apache/catalina/core/ContainerBase.java
    tomcat/trunk/java/org/apache/catalina/core/LocalStrings.properties
    tomcat/trunk/java/org/apache/catalina/core/LocalStrings_es.properties
    tomcat/trunk/java/org/apache/catalina/core/LocalStrings_fr.properties
    tomcat/trunk/java/org/apache/catalina/core/LocalStrings_ja.properties
    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/StandardPipeline.java
    tomcat/trunk/java/org/apache/catalina/core/StandardServer.java
    tomcat/trunk/java/org/apache/catalina/core/StandardService.java
    tomcat/trunk/java/org/apache/catalina/core/StandardThreadExecutor.java
    tomcat/trunk/java/org/apache/catalina/ha/context/ReplicatedContext.java
    tomcat/trunk/java/org/apache/catalina/ha/session/BackupManager.java
    tomcat/trunk/java/org/apache/catalina/ha/session/DeltaManager.java
    tomcat/trunk/java/org/apache/catalina/ha/tcp/SimpleTcpCluster.java
    tomcat/trunk/java/org/apache/catalina/loader/WebappClassLoader.java
    tomcat/trunk/java/org/apache/catalina/loader/WebappLoader.java
    tomcat/trunk/java/org/apache/catalina/realm/RealmBase.java
    tomcat/trunk/java/org/apache/catalina/session/ManagerBase.java
    tomcat/trunk/java/org/apache/catalina/session/PersistentManagerBase.java
    tomcat/trunk/java/org/apache/catalina/session/StandardManager.java
    tomcat/trunk/java/org/apache/catalina/session/StoreBase.java
    tomcat/trunk/java/org/apache/catalina/startup/Catalina.java
    tomcat/trunk/java/org/apache/catalina/startup/Embedded.java
    tomcat/trunk/java/org/apache/catalina/startup/Tomcat.java
    tomcat/trunk/java/org/apache/catalina/util/LifecycleBase.java
    tomcat/trunk/java/org/apache/catalina/valves/ValveBase.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=940008&r1=940007&r2=940008&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/Context.java (original)
+++ tomcat/trunk/java/org/apache/catalina/Context.java Sat May  1 13:31:46 2010
@@ -603,11 +603,6 @@ public interface Context extends Contain
      */
     public boolean getLogEffectiveWebXml();
     
-    /**
-     * Has this context been initialized?
-     */
-    public boolean isInitialized();
-
     // --------------------------------------------------------- Public Methods
 
 

Modified: tomcat/trunk/java/org/apache/catalina/Lifecycle.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/Lifecycle.java?rev=940008&r1=940007&r2=940008&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/Lifecycle.java (original)
+++ tomcat/trunk/java/org/apache/catalina/Lifecycle.java Sat May  1 13:31:46 2010
@@ -27,30 +27,37 @@ package org.apache.catalina;
  * <br>
  * The valid state transitions for components that support Lifecycle are:
  * <pre>
- *                            --------------------<--------------------------
- *                            |                                             |
- *               start()      |        auto          auto         stop()    |       
- * NEW ------------->--- STARTING_PREP -->- STARTING -->- STARTED -->---    |
- *  |                                                        |         |    |
- *  |                                            auto        |         |    |
- *  |stop()       ---------<----- MUST_STOP --<---------------         |    |
- *  |             |                                                    |    |
- *  |             ---------------------------<--------------------------    ^
- *  |             |                                                         |
- *  |             |        auto          auto                start()        |
- *  |        STOPPING_PREP -->- STOPPING -->- STOPPED -------------->--------
- *  |             ^                              ^
- *  |             |stop()                        |
- *  |             |                              |
- *  |          FAILED                            |
- *  |                                            |
- *  --->------------------------------>-----------
+ *                                  --------------------<-----------------------
+ *                                  |                                          |
+ *    init()           start()      |        auto          auto         stop() |
+ * NEW ->-- INITIALIZED -->-- STARTING_PREP -->- STARTING -->- STARTED -->---  |
+ * | |                              ^                             |         |  |
+ * | |        start()               |                             |         |  |
+ * | ----------->--------------------                             |         |  |
+ * |                                                              |         |  |
+ * |                   auto                    auto               |         |  |
+ * |stop()       ---------<----- MUST_STOP ---------------------<--         |  |
+ * |             |                                                          |  |
+ * |             ---------------------------<--------------------------------  ^
+ * |             |                                                             |
+ * |             |         auto            auto                 start()        |
+ * |        STOPPING_PREP --->-- STOPPING --->-- STOPPED ---------->------------
+ * |             ^                                |   ^
+ * |             |stop()                          |   |
+ * |             |                       destroy()|   |
+ * |             |    destroy()                   |   |
+ * |          FAILED ---->------ DESTROYED ----<---   |
+ * |                                                  |
+ * --->------------------------------>-----------------
  *   
  * Any state can transition to FAILED.
  * 
  * Calling start() while a component is in states STARTING_PREP, STARTING or
  * STARTED has no effect.
  * 
+ * Calling start() while a component is in state NEW will cause init() to be
+ * called immediately the start() method is entered.
+ * 
  * Calling stop() while a component is in states STOPPING_PREP, STOPPING or
  * STOPPED has no effect.
  * 
@@ -60,7 +67,12 @@ package org.apache.catalina;
  * try to stop all sub-components - even those it didn't start.
  * 
  * MUST_STOP is used to indicate that the {@link #stop()} should be called on
- * the component as soon as {@link #start()} exits.
+ * the component as soon as {@link #start()} exits. It is typically used when a
+ * component has failed to start.
+ * 
+ * MUST_DESTROY is used to indicate that the {@link #stop()} should be called on
+ * the component as soon as {@link #stop()} exits. It is typically used when a
+ * component is not designed to be restarted.
  * 
  * Attempting any other transition will throw {@link LifecycleException}.
  * 
@@ -179,6 +191,20 @@ public interface Lifecycle {
 
 
     /**
+     * Prepare the component for starting. This method should perform any
+     * initialization required post object creation. The following
+     * {@link LifecycleEvent}s will be fired in the following order:
+     * <ol>
+     *   <li>INIT_EVENT: On the successful completion of component
+     *                   initialization.</li>
+     * </ol>
+     * 
+     * @exception LifecycleException if this component detects a fatal error
+     *  that prevents this component from being used
+     */
+    public void init() throws LifecycleException;
+
+    /**
      * Prepare for the beginning of active use of the public methods of this
      * component.  This method should be called before any of the public
      * methods of this component are utilized. The following
@@ -227,6 +253,19 @@ public interface Lifecycle {
      */
     public void stop() throws LifecycleException;
 
+    /**
+     * Prepare to discard the object. The following {@link LifecycleEvent}s will
+     * be fired in the following order:
+     * <ol>
+     *   <li>DESTROY_EVENT: On the successful completion of component
+     *                      destruction.</li>
+     * </ol>
+     * 
+     * @exception LifecycleException if this component detects a fatal error
+     *  that prevents this component from being used
+     */
+    public void destroy() throws LifecycleException;
+
 
     /**
      * Obtain the current state of the source component.

Modified: tomcat/trunk/java/org/apache/catalina/LifecycleState.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/LifecycleState.java?rev=940008&r1=940007&r2=940008&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/LifecycleState.java (original)
+++ tomcat/trunk/java/org/apache/catalina/LifecycleState.java Sat May  1 13:31:46 2010
@@ -23,14 +23,17 @@ package org.apache.catalina;
  */
 public enum LifecycleState {
     NEW(false, null),
+    INITIALIZED(false, Lifecycle.INIT_EVENT),
     STARTING_PREP(false, Lifecycle.BEFORE_START_EVENT),
     STARTING(true, Lifecycle.START_EVENT),
     STARTED(true, Lifecycle.AFTER_START_EVENT),
     STOPPING_PREP(true, Lifecycle.BEFORE_STOP_EVENT),
     STOPPING(false, Lifecycle.STOP_EVENT),
     STOPPED(false, Lifecycle.AFTER_STOP_EVENT),
+    DESTROYED(false, Lifecycle.DESTROY_EVENT),
     FAILED(false, null),
-    MUST_STOP(true, null);
+    MUST_STOP(true, null),
+    MUST_DESTROY(true, null);
     
     private final boolean available;
     private final String lifecycleEvent;

Modified: tomcat/trunk/java/org/apache/catalina/Server.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/Server.java?rev=940008&r1=940007&r2=940008&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/Server.java (original)
+++ tomcat/trunk/java/org/apache/catalina/Server.java Sat May  1 13:31:46 2010
@@ -155,13 +155,4 @@ public interface Server extends Lifecycl
      * @param service The Service to be removed
      */
     public void removeService(Service service);
-
-    /**
-     * Invoke a pre-startup initialization. This is used to allow connectors
-     * to bind to restricted ports under Unix operating environments.
-     *
-     * @exception LifecycleException If this server was already initialized.
-     */
-    public void initialize()
-    throws LifecycleException;
 }

Modified: tomcat/trunk/java/org/apache/catalina/Service.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/Service.java?rev=940008&r1=940007&r2=940008&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/Service.java (original)
+++ tomcat/trunk/java/org/apache/catalina/Service.java Sat May  1 13:31:46 2010
@@ -110,14 +110,6 @@ public interface Service extends Lifecyc
     public void removeConnector(Connector connector);
 
     /**
-     * Invoke a pre-startup initialization. This is used to allow connectors
-     * to bind to restricted ports under Unix operating environments.
-     *
-     * @exception LifecycleException If this server was already initialized.
-     */
-    public void initialize() throws LifecycleException;
-
-    /**
      * Adds a named executor to the service
      * @param ex Executor
      */

Modified: tomcat/trunk/java/org/apache/catalina/connector/Connector.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/connector/Connector.java?rev=940008&r1=940007&r2=940008&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/connector/Connector.java (original)
+++ tomcat/trunk/java/org/apache/catalina/connector/Connector.java Sat May  1 13:31:46 2010
@@ -189,12 +189,6 @@ public class Connector extends Lifecycle
 
 
     /**
-     * Has this component been initialized yet?
-     */
-    protected boolean initialized = false;
-
-
-    /**
      * The shutdown signal to our background thread
      */
     protected boolean stopped = false;
@@ -857,51 +851,6 @@ public class Connector extends Lifecycle
         return _oname;
     }
 
-    /**
-     * Initialize this connector (create ServerSocket here!)
-     */
-    public void initialize()
-        throws LifecycleException
-    {
-        if (initialized) {
-            if(log.isInfoEnabled())
-                log.info(sm.getString("coyoteConnector.alreadyInitialized"));
-           return;
-        }
-
-        this.initialized = true;
-
-        if (oname == null) {
-            try {
-                // we are loaded directly, via API - and no name was given to us
-                // Engine name is used as domain name for MBeans
-                oname = createObjectName(container.getName(), "Connector");
-                Registry.getRegistry(null, null)
-                    .registerComponent(this, oname, null);
-                controller=oname;
-            } catch (Exception e) {
-                log.error( "Error registering connector ", e);
-            }
-            if(log.isDebugEnabled())
-                log.debug("Creating name for connector " + oname);
-        }
-
-        // Initializa adapter
-        adapter = new CoyoteAdapter(this);
-        protocolHandler.setAdapter(adapter);
-
-        IntrospectionUtils.setProperty(protocolHandler, "jkHome",
-                                       System.getProperty("catalina.base"));
-
-        try {
-            protocolHandler.init();
-        } catch (Exception e) {
-            throw new LifecycleException
-                (sm.getString
-                 ("coyoteConnector.protocolHandlerInitializationFailed", e));
-        }
-    }
-
 
     /**
      * Pause the connector.
@@ -938,8 +887,6 @@ public class Connector extends Lifecycle
      */
     @Override
     protected void startInternal() throws LifecycleException {
-        if( !initialized )
-            initialize();
 
         setState(LifecycleState.STARTING);
 
@@ -1109,9 +1056,6 @@ public class Connector extends Lifecycle
                       log.debug("Found engine " + obj + " " + obj.getClass());
                 container=(Container)obj;
 
-                // Internal initialize - we now have the Engine
-                initialize();
-
                 if(log.isDebugEnabled())
                     log.debug("Initialized");
                 // As a side effect we'll get the container field set
@@ -1123,19 +1067,47 @@ public class Connector extends Lifecycle
         }
     }
 
-    public void init() throws Exception {
+    @Override
+    protected void initInternal() throws LifecycleException {
 
-        if( this.getService() != null ) {
-            if(log.isDebugEnabled())
-                 log.debug( "Already configured" );
-            return;
-        }
         if( container==null ) {
             findContainer();
         }
+        
+        if (oname == null) {
+            try {
+                // we are loaded directly, via API - and no name was given to us
+                // Engine name is used as domain name for MBeans
+                oname = createObjectName(container.getName(), "Connector");
+                Registry.getRegistry(null, null)
+                    .registerComponent(this, oname, null);
+                controller=oname;
+            } catch (Exception e) {
+                log.error( "Error registering connector ", e);
+            }
+            if(log.isDebugEnabled())
+                log.debug("Creating name for connector " + oname);
+        }
+
+        // Initializa adapter
+        adapter = new CoyoteAdapter(this);
+        protocolHandler.setAdapter(adapter);
+
+        IntrospectionUtils.setProperty(protocolHandler, "jkHome",
+                                       System.getProperty("catalina.base"));
+
+        try {
+            protocolHandler.init();
+        } catch (Exception e) {
+            throw new LifecycleException
+                (sm.getString
+                 ("coyoteConnector.protocolHandlerInitializationFailed", e));
+        }
+
     }
 
-    public void destroy() throws Exception {
+    @Override
+    protected void destroyInternal() {
         if( oname!=null && controller==oname ) {
             if(log.isDebugEnabled())
                  log.debug("Unregister itself " + oname );

Modified: tomcat/trunk/java/org/apache/catalina/connector/LocalStrings.properties
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/connector/LocalStrings.properties?rev=940008&r1=940007&r2=940008&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/connector/LocalStrings.properties (original)
+++ tomcat/trunk/java/org/apache/catalina/connector/LocalStrings.properties Sat May  1 13:31:46 2010
@@ -17,7 +17,6 @@
 #
 # CoyoteConnector
 #
-coyoteConnector.alreadyInitialized=The connector has already been initialized
 coyoteConnector.cannotRegisterProtocol=Cannot register MBean for the Protocol
 coyoteConnector.protocolHandlerDestroyFailed=Protocol handler destroy failed: {0}
 coyoteConnector.protocolHandlerInitializationFailed=Protocol handler initialization failed: {0}

Modified: tomcat/trunk/java/org/apache/catalina/connector/LocalStrings_es.properties
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/connector/LocalStrings_es.properties?rev=940008&r1=940007&r2=940008&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/connector/LocalStrings_es.properties (original)
+++ tomcat/trunk/java/org/apache/catalina/connector/LocalStrings_es.properties Sat May  1 13:31:46 2010
@@ -14,7 +14,6 @@
 # limitations under the License.
 #
 # CoyoteConnector
-coyoteConnector.alreadyInitialized = Ya ha sido inicializado el conector
 coyoteConnector.cannotRegisterProtocol = No puedo registrar MBean para el Protocolo
 coyoteConnector.protocolHandlerDestroyFailed = Fall\u00F3 la destrucci\u00F3n del manejador de protocolo\: {0}
 coyoteConnector.protocolHandlerInitializationFailed = Fall\u00F3 la inicializaci\u00F3n del manejador de protocolo\: {0}

Modified: tomcat/trunk/java/org/apache/catalina/connector/LocalStrings_fr.properties
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/connector/LocalStrings_fr.properties?rev=940008&r1=940007&r2=940008&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/connector/LocalStrings_fr.properties (original)
+++ tomcat/trunk/java/org/apache/catalina/connector/LocalStrings_fr.properties Sat May  1 13:31:46 2010
@@ -18,7 +18,6 @@
 # CoyoteConnector
 #
 
-coyoteConnector.alreadyInitialized=Le connecteur a d\u00e9j\u00e0 \u00e9t\u00e9 initialis\u00e9
 coyoteConnector.cannotRegisterProtocol=Impossible d''enregistrer le MBean pour le Protocol
 coyoteConnector.protocolHandlerDestroyFailed=La destruction du gestionnaire de protocole a \u00e9chou\u00e9: {0}
 coyoteConnector.protocolHandlerInitializationFailed=L''initialisation du gestionnaire de protocole a \u00e9chou\u00e9: {0}

Modified: tomcat/trunk/java/org/apache/catalina/connector/LocalStrings_ja.properties
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/connector/LocalStrings_ja.properties?rev=940008&r1=940007&r2=940008&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/connector/LocalStrings_ja.properties (original)
+++ tomcat/trunk/java/org/apache/catalina/connector/LocalStrings_ja.properties Sat May  1 13:31:46 2010
@@ -18,7 +18,6 @@
 # CoyoteConnector
 #
 
-coyoteConnector.alreadyInitialized=\u30b3\u30cd\u30af\u30bf\u306f\u65e2\u306b\u521d\u671f\u5316\u3055\u308c\u3066\u3044\u307e\u3059
 coyoteConnector.cannotRegisterProtocol=\u305d\u306e\u30d7\u30ed\u30c8\u30b3\u30eb\u306bMBean\u3092\u767b\u9332\u3067\u304d\u307e\u305b\u3093
 coyoteConnector.protocolHandlerDestroyFailed=\u30d7\u30ed\u30c8\u30b3\u30eb\u30cf\u30f3\u30c9\u30e9\u306e\u5ec3\u68c4\u306b\u5931\u6557\u3057\u307e\u3057\u305f: {0}
 coyoteConnector.protocolHandlerInitializationFailed=\u30d7\u30ed\u30c8\u30b3\u30eb\u30cf\u30f3\u30c9\u30e9\u306e\u521d\u671f\u5316\u306b\u5931\u6557\u3057\u307e\u3057\u305f: {0}

Modified: tomcat/trunk/java/org/apache/catalina/core/ApplicationServletRegistration.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/core/ApplicationServletRegistration.java?rev=940008&r1=940007&r2=940008&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/core/ApplicationServletRegistration.java (original)
+++ tomcat/trunk/java/org/apache/catalina/core/ApplicationServletRegistration.java Sat May  1 13:31:46 2010
@@ -28,6 +28,7 @@ import javax.servlet.ServletRegistration
 import javax.servlet.ServletSecurityElement;
 
 import org.apache.catalina.Context;
+import org.apache.catalina.LifecycleState;
 import org.apache.catalina.Wrapper;
 import org.apache.catalina.deploy.SecurityCollection;
 import org.apache.catalina.deploy.SecurityConstraint;
@@ -151,7 +152,7 @@ public class ApplicationServletRegistrat
                     getName(), context.getPath()));
         }
         
-        if (context.isInitialized()) {
+        if (!context.getState().equals(LifecycleState.STARTING_PREP)) {
             throw new IllegalStateException(sm.getString(
                     "applicationServletRegistration.setServletSecurity.ise",
                     getName(), context.getPath()));

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=940008&r1=940007&r2=940008&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/core/ContainerBase.java (original)
+++ tomcat/trunk/java/org/apache/catalina/core/ContainerBase.java Sat May  1 13:31:46 2010
@@ -29,10 +29,13 @@ import java.util.HashMap;
 import java.util.Hashtable;
 import java.util.Iterator;
 
+import javax.management.InstanceNotFoundException;
+import javax.management.MBeanException;
 import javax.management.MBeanRegistration;
 import javax.management.MBeanServer;
 import javax.management.MalformedObjectNameException;
 import javax.management.ObjectName;
+import javax.management.ReflectionException;
 import javax.naming.directory.DirContext;
 import javax.servlet.ServletException;
 
@@ -248,11 +251,6 @@ public abstract class ContainerBase exte
 
 
     /**
-     * Has this component been initialized?
-     */
-    protected boolean initialized=false;
-
-    /**
      * Will children be started automatically when they are added.
      */
     protected boolean startChildren = true;
@@ -1061,32 +1059,40 @@ public abstract class ContainerBase exte
      * 
      * @throws Exception
      */ 
-    public void init() throws Exception {
-
-        if( this.getParent() == null ) {
-            // "Life" update
-            ObjectName parentName=getParentName();
+    @Override
+    protected void initInternal() throws LifecycleException{
 
-            //log.info("Register " + parentName );
-            if( parentName != null && 
-                    mserver.isRegistered(parentName)) 
-            {
-                mserver.invoke(parentName, "addChild", new Object[] { this },
-                        new String[] {"org.apache.catalina.Container"});
+        try {
+            if( this.getParent() == null ) {
+                // "Life" update
+                ObjectName parentName;
+                    parentName = getParentName();
+    
+                //log.info("Register " + parentName );
+                if( parentName != null && 
+                        mserver.isRegistered(parentName)) 
+                {
+                    mserver.invoke(parentName, "addChild", new Object[] { this },
+                            new String[] {"org.apache.catalina.Container"});
+                }
             }
+        } catch (MalformedObjectNameException e) {
+            throw new LifecycleException(e);
+        } catch (InstanceNotFoundException e) {
+            throw new LifecycleException(e);
+        } catch (ReflectionException e) {
+            throw new LifecycleException(e);
+        } catch (MBeanException e) {
+            throw new LifecycleException(e);
         }
-        initialized=true;
     }
     
     public ObjectName getParentName() throws MalformedObjectNameException {
         return null;
     }
     
-    public void destroy() throws Exception {
-        if (getState().isAvailable()) {
-            stop();
-        }
-        initialized=false;
+    @Override
+    protected void destroyInternal() throws LifecycleException {
 
         // unregister this component
         if ( oname != null ) {
@@ -1106,12 +1112,6 @@ public abstract class ContainerBase exte
             parent.removeChild(this);
         }
 
-        // Stop our child containers, if any
-        Container children[] = findChildren();
-        for (int i = 0; i < children.length; i++) {
-            removeChild(children[i]);
-        }
-                
     }
 
     // ------------------------------------------------------- Pipeline Methods

Modified: tomcat/trunk/java/org/apache/catalina/core/LocalStrings.properties
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/core/LocalStrings.properties?rev=940008&r1=940007&r2=940008&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/core/LocalStrings.properties (original)
+++ tomcat/trunk/java/org/apache/catalina/core/LocalStrings.properties Sat May  1 13:31:46 2010
@@ -188,10 +188,8 @@ standardHost.warRequired=URL to web appl
 standardHost.warURL=Invalid URL for web application archive: {0}
 standardHost.validationEnabled=XML validation enabled
 standardHost.validationDisabled=XML validation disabled
-standardServer.initialize.initialized=This server has already been initialized
 standardServer.shutdownViaPort=A valid shutdown command was received via the shutdown port. Stopping the Server instance.
 standardService.connector.failed=Failed to start connector [{0}]
-standardService.initialize.initialized=This service has already been initialized
 standardService.initialize.failed=Service initializing at {0} failed
 standardService.register.failed=Error registering Service at domain {0}
 standardService.start.name=Starting service {0}

Modified: tomcat/trunk/java/org/apache/catalina/core/LocalStrings_es.properties
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/core/LocalStrings_es.properties?rev=940008&r1=940007&r2=940008&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/core/LocalStrings_es.properties (original)
+++ tomcat/trunk/java/org/apache/catalina/core/LocalStrings_es.properties Sat May  1 13:31:46 2010
@@ -162,8 +162,6 @@ standardHost.warRequired = Es necesario 
 standardHost.warURL = URL inv\u00E1lida para archivo de aplicaci\u00F3n web\: {0}
 standardHost.validationEnabled = Activada la validaci\u00F3n XML
 standardHost.validationDisabled = Desactivada la validaci\u00F3n XML
-standardServer.initialize.initialized = Ya se ha inicializado este servidor
-standardService.initialize.initialized = Ya ha sido inicializado este servicio
 standardService.initialize.failed = Servicio inicializando en {0} fall\u00F3
 standardService.register.failed = Error registrando servicio en dominio {0}
 standardService.start.name = Arrancando servicio {0}

Modified: tomcat/trunk/java/org/apache/catalina/core/LocalStrings_fr.properties
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/core/LocalStrings_fr.properties?rev=940008&r1=940007&r2=940008&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/core/LocalStrings_fr.properties (original)
+++ tomcat/trunk/java/org/apache/catalina/core/LocalStrings_fr.properties Sat May  1 13:31:46 2010
@@ -135,8 +135,6 @@ standardHost.stop=Arr\u00eat de l''appli
 standardHost.unfoundContext=Impossible de trouver un contexte pour l''URI {0} demand\u00e9e
 standardHost.warRequired=Une URL vers l''archive d''application web (war) est n\u00e9cessaire
 standardHost.warURL=URL vers l''archive d''application web (war) invalide: {0}
-standardServer.initialize.initialized=Ce serveur a d\u00e9j\u00e0 \u00e9t\u00e9 initialis\u00e9
-standardService.initialize.initialized=Ce service a d\u00e9j\u00e0 \u00e9t\u00e9 initialis\u00e9
 standardService.start.name=D\u00e9marrage du service {0}
 standardService.stop.name=Arr\u00eat du service {0}
 standardWrapper.allocate=Erreur d''allocation \u00e0 une instance de servlet

Modified: tomcat/trunk/java/org/apache/catalina/core/LocalStrings_ja.properties
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/core/LocalStrings_ja.properties?rev=940008&r1=940007&r2=940008&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/core/LocalStrings_ja.properties (original)
+++ tomcat/trunk/java/org/apache/catalina/core/LocalStrings_ja.properties Sat May  1 13:31:46 2010
@@ -142,8 +142,6 @@ standardHost.warRequired=Web\u30a2\u30d7
 standardHost.warURL=Web\u30a2\u30d7\u30ea\u30b1\u30fc\u30b7\u30e7\u30f3\u30a2\u30fc\u30ab\u30a4\u30d6\u306b\u5bfe\u3059\u308b\u7121\u52b9\u306aURL\u3067\u3059: {0}
 standardHost.validationEnabled=XML\u691c\u8a3c\u306f\u6709\u52b9\u3067\u3059
 standardHost.validationDisabled=XML\u691c\u8a3c\u306f\u7121\u52b9\u3067\u3059
-standardServer.initialize.initialized=\u3053\u306e\u30b5\u30fc\u30d0\u306f\u65e2\u306b\u521d\u671f\u5316\u3055\u308c\u3066\u3044\u307e\u3059
-standardService.initialize.initialized=\u3053\u306e\u30b5\u30fc\u30d3\u30b9\u306f\u65e2\u306b\u521d\u671f\u5316\u3055\u308c\u3066\u3044\u307e\u3059
 standardService.start.name=\u30b5\u30fc\u30d3\u30b9 {0} \u3092\u8d77\u52d5\u3057\u307e\u3059
 standardService.stop.name=\u30b5\u30fc\u30d3\u30b9 {0} \u3092\u505c\u6b62\u3057\u307e\u3059
 standardWrapper.allocate=\u30b5\u30fc\u30d6\u30ec\u30c3\u30c8\u30a4\u30f3\u30b9\u30bf\u30f3\u30b9\u3092\u5272\u308a\u5f53\u3066\u4e2d\u306e\u30a8\u30e9\u30fc\u3067\u3059

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=940008&r1=940007&r2=940008&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/core/StandardContext.java (original)
+++ tomcat/trunk/java/org/apache/catalina/core/StandardContext.java Sat May  1 13:31:46 2010
@@ -2348,13 +2348,6 @@ public class StandardContext
     }
 
 
-    /**
-     * Has this context been initialized?
-     */
-    public boolean isInitialized() {
-        return initialized;
-    }
-
     // -------------------------------------------------------- Context Methods
 
 
@@ -4532,13 +4525,6 @@ public class StandardContext
     @Override
     protected synchronized void startInternal() throws LifecycleException {
 
-        if( !initialized ) { 
-            try {
-                init();
-            } catch( Exception ex ) {
-                throw new LifecycleException("Error initializaing ", ex);
-            }
-        }
         if(log.isDebugEnabled())
             log.debug("Starting " + ("".equals(getName()) ? "ROOT" : getName()));
 
@@ -5027,7 +5013,7 @@ public class StandardContext
      * 
      */ 
     @Override
-    public void destroy() throws Exception {
+    protected void destroyInternal() throws LifecycleException {
         if( oname != null ) { 
             // Send j2ee.object.deleted notification 
             Notification notification = 
@@ -5035,7 +5021,7 @@ public class StandardContext
                                 sequenceNumber++);
             broadcaster.sendNotification(notification);
         } 
-        super.destroy();
+        super.destroyInternal();
 
         // Notify our interested LifecycleListeners
         fireLifecycleEvent(DESTROY_EVENT, null);
@@ -5659,10 +5645,15 @@ public class StandardContext
     }
 
     @Override
-    public void init() throws Exception {
+    protected void initInternal() throws LifecycleException {
 
         if( this.getParent() == null ) {
-            ObjectName parentName=getParentName();
+            ObjectName parentName;
+            try {
+                parentName = getParentName();
+            } catch (MalformedObjectNameException e1) {
+                throw new LifecycleException(e1);
+            }
             
             if( ! mserver.isRegistered(parentName)) {
                 if(log.isDebugEnabled())
@@ -5670,8 +5661,12 @@ public class StandardContext
                 StandardHost host=new StandardHost();
                 host.setName(hostName);
                 host.setAutoDeploy(false);
-                Registry.getRegistry(null, null)
-                    .registerComponent(host, parentName, null);
+                try {
+                    Registry.getRegistry(null, null)
+                        .registerComponent(host, parentName, null);
+                } catch (Exception e) {
+                    throw new LifecycleException(e);
+                }
                 // We could do it the hard way...
                 //mserver.invoke(parentName, "init", new Object[] {}, new String[] {} );
                 // or same thing easier:
@@ -5695,7 +5690,7 @@ public class StandardContext
                 }
             } catch (Exception e) {
                 log.warn("Error creating ContextConfig for " + parentName, e);
-                throw e;
+                throw new LifecycleException(e);
             }
             this.addLifecycleListener(config);
 
@@ -5706,19 +5701,14 @@ public class StandardContext
                 mserver.invoke(parentName, "addChild", new Object[] { this },
                         new String[] {"org.apache.catalina.Container"});
             } catch (Exception e) {
-                destroy();
-                throw e;
-            }
-            // It's possible that addChild may have started us
-            if( initialized ) {
-                return;
+                throw new LifecycleException(e);
             }
         }
         if (processTlds) {
             this.addLifecycleListener(new TldConfig());
         }
 
-        super.init();
+        super.initInternal();
         
         // Notify our interested LifecycleListeners
         fireLifecycleEvent(INIT_EVENT, 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=940008&r1=940007&r2=940008&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/core/StandardEngine.java (original)
+++ tomcat/trunk/java/org/apache/catalina/core/StandardEngine.java Sat May  1 13:31:46 2010
@@ -295,12 +295,8 @@ public class StandardEngine
     }
 
 
-    private boolean initialized=false;
-    
     @Override
-    public void init() {
-        if( initialized ) return;
-        initialized=true;
+    protected void initInternal() {
 
         if( oname==null ) {
             // not registered in JMX yet - standalone mode
@@ -360,7 +356,7 @@ public class StandardEngine
             try {
                 service=new StandardService();
                 service.setContainer( this );
-                service.initialize();
+                service.init();
             } catch( Throwable t ) {
                 log.error(t);
             }
@@ -369,9 +365,7 @@ public class StandardEngine
     }
     
     @Override
-    public void destroy() throws LifecycleException {
-        if( ! initialized ) return;
-        initialized=false;
+    protected void destroyInternal() throws LifecycleException {
         
         // if we created it, make sure it's also destroyed
         // this call implizit this.stop()
@@ -402,6 +396,7 @@ public class StandardEngine
         // registry - and stop using the static.
         Registry.getRegistry(null, null).resetMetadata();
         
+        super.destroyInternal();
     }
     
     /**
@@ -414,10 +409,6 @@ public class StandardEngine
     @Override
     protected synchronized void startInternal() throws LifecycleException {
         
-        if( !initialized ) {
-            init();
-        }
-
         // Look for a realm - that may have been configured earlier. 
         // If the realm is added after context - it'll set itself.
         if( realm == null ) {

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=940008&r1=940007&r2=940008&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/core/StandardHost.java (original)
+++ tomcat/trunk/java/org/apache/catalina/core/StandardHost.java Sat May  1 13:31:46 2010
@@ -803,9 +803,6 @@ public class StandardHost
     @Override
     protected synchronized void startInternal() throws LifecycleException {
         
-        if( ! initialized )
-            init();
-
         // Look for a realm - that may have been configured earlier. 
         // If the realm is added after context - it'll set itself.
         if( realm == null ) {
@@ -885,12 +882,8 @@ public class StandardHost
         }
     }
 
-    private boolean initialized=false;
-    
     @Override
-    public void init() {
-        if( initialized ) return;
-        initialized=true;
+    protected void initInternal() {
         
         // already registered.
         if( getParent() == null ) {
@@ -932,10 +925,10 @@ public class StandardHost
     }
 
     @Override
-    public void destroy() throws Exception {
+    public void destroyInternal() throws LifecycleException {
         // destroy our child containers, if any
         Container children[] = findChildren();
-        super.destroy();
+        super.destroyInternal();
         for (int i = 0; i < children.length; i++) {
             if(children[i] instanceof StandardContext)
                 ((StandardContext)children[i]).destroy();

Modified: tomcat/trunk/java/org/apache/catalina/core/StandardPipeline.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/core/StandardPipeline.java?rev=940008&r1=940007&r2=940008&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/core/StandardPipeline.java (original)
+++ tomcat/trunk/java/org/apache/catalina/core/StandardPipeline.java Sat May  1 13:31:46 2010
@@ -157,6 +157,12 @@ public class StandardPipeline extends Li
     }
 
 
+    @Override
+    protected void initInternal() {
+        // NOOP
+    }
+
+    
     /**
      * Start {@link Valve}s) in this pipeline and implement the requirements
      * of {@link LifecycleBase#startInternal()}.
@@ -209,6 +215,12 @@ public class StandardPipeline extends Li
     }
 
     
+    @Override
+    protected void destroyInternal() {
+        // NOOP
+    }
+
+    
     /**
      * Return a String representation of this component.
      */

Modified: tomcat/trunk/java/org/apache/catalina/core/StandardServer.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/core/StandardServer.java?rev=940008&r1=940007&r2=940008&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/core/StandardServer.java (original)
+++ tomcat/trunk/java/org/apache/catalina/core/StandardServer.java Sat May  1 13:31:46 2010
@@ -151,12 +151,6 @@ public final class StandardServer extend
 
 
     /**
-     * Has this component been initialized?
-     */
-    private boolean initialized = false;
-
-
-    /**
      * The property change support for this component.
      */
     protected PropertyChangeSupport support = new PropertyChangeSupport(this);
@@ -321,14 +315,6 @@ public final class StandardServer extend
             results[services.length] = service;
             services = results;
 
-            if (initialized) {
-                try {
-                    service.initialize();
-                } catch (LifecycleException e) {
-                    log.error(e);
-                }
-            }
-
             if (getState().isAvailable()) {
                 try {
                     service.start();
@@ -689,23 +675,12 @@ public final class StandardServer extend
 
     }
 
-    public void init() throws Exception {
-        initialize();
-    }
-    
     /**
      * Invoke a pre-startup initialization. This is used to allow connectors
      * to bind to restricted ports under Unix operating environments.
      */
-    public void initialize()
-        throws LifecycleException 
-    {
-        if (initialized) {
-                log.info(sm.getString("standardServer.initialize.initialized"));
-            return;
-        }
-        fireLifecycleEvent(INIT_EVENT, null);
-        initialized = true;
+    @Override
+    protected void initInternal() throws LifecycleException {
 
         if( oname==null ) {
             try {
@@ -729,10 +704,14 @@ public final class StandardServer extend
 
         // Initialize our defined Services
         for (int i = 0; i < services.length; i++) {
-            services[i].initialize();
+            services[i].init();
         }
     }
     
+    protected void destroyInternal() {
+        // NOOP
+    }
+
     protected String type;
     protected String domain;
     protected String suffix;

Modified: tomcat/trunk/java/org/apache/catalina/core/StandardService.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/core/StandardService.java?rev=940008&r1=940007&r2=940008&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/core/StandardService.java (original)
+++ tomcat/trunk/java/org/apache/catalina/core/StandardService.java Sat May  1 13:31:46 2010
@@ -106,12 +106,6 @@ public class StandardService extends Lif
     protected Container container = null;
 
 
-    /**
-     * Has this component been initialized?
-     */
-    protected boolean initialized = false;
-
-
     // ------------------------------------------------------------- Properties
 
 
@@ -247,14 +241,6 @@ public class StandardService extends Lif
             results[connectors.length] = connector;
             connectors = results;
 
-            if (initialized) {
-                try {
-                    connector.initialize();
-                } catch (LifecycleException e) {
-                    log.error("Connector.initialize", e);
-                }
-            }
-
             if (getState().isAvailable()) {
                 try {
                     ((Lifecycle) connector).start();
@@ -443,9 +429,6 @@ public class StandardService extends Lif
     @Override
     protected void startInternal() throws LifecycleException {
 
-        if( ! initialized )
-            init(); 
-
         if(log.isInfoEnabled())
             log.info(sm.getString("standardService.start.name", this.name));
         setState(LifecycleState.STARTING);
@@ -544,22 +527,20 @@ public class StandardService extends Lif
      * Invoke a pre-startup initialization. This is used to allow connectors
      * to bind to restricted ports under Unix operating environments.
      */
-    public void initialize()
-            throws LifecycleException
-    {
-        // Service shouldn't be used with embedded, so it doesn't matter
-        if (initialized) {
-            if(log.isInfoEnabled())
-                log.info(sm.getString("standardService.initialize.initialized"));
-            return;
-        }
-        initialized = true;
+    @Override
+    protected void initInternal() throws LifecycleException {
 
         if( oname==null ) {
             try {
                 // Hack - Server should be deprecated...
                 Container engine=this.getContainer();
-                domain=engine.getName();
+                
+                if (engine == null) {
+                    // TODO - Get this form elsewhere
+                    domain = "Catalina";
+                } else {
+                    domain = engine.getName();
+                }
                 oname=new ObjectName(domain + ":type=Service,serviceName="+name);
                 this.controller=oname;
                 Registry.getRegistry(null, null)
@@ -590,7 +571,7 @@ public class StandardService extends Lif
         synchronized (connectors) {
                 for (int i = 0; i < connectors.length; i++) {
                     try {
-                        connectors[i].initialize();
+                        connectors[i].init();
                     } catch (Exception e) {
                         log.error(sm.getString(
                                 "standardService.connector.failed",
@@ -600,19 +581,11 @@ public class StandardService extends Lif
         }
     }
     
-    public void destroy() throws LifecycleException {
-        if(getState().isAvailable()) stop();
+    @Override
+    protected void destroyInternal() {
         // FIXME unregister should be here probably -- stop doing that ?
     }
 
-    public void init() {
-        try {
-            initialize();
-        } catch( Throwable t ) {
-            log.error(sm.getString("standardService.initialize.failed",domain),t);
-        }
-    }
-
     protected String type;
     protected String domain;
     protected String suffix;

Modified: tomcat/trunk/java/org/apache/catalina/core/StandardThreadExecutor.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/core/StandardThreadExecutor.java?rev=940008&r1=940007&r2=940008&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/core/StandardThreadExecutor.java (original)
+++ tomcat/trunk/java/org/apache/catalina/core/StandardThreadExecutor.java Sat May  1 13:31:46 2010
@@ -93,6 +93,12 @@ public class StandardThreadExecutor exte
     
     // ---------------------------------------------- Public Methods
     
+    @Override
+    protected void initInternal() {
+        // NOOP
+    }
+
+    
     /**
      * Start the component and implement the requirements
      * of {@link LifecycleBase#startInternal()}.
@@ -130,6 +136,13 @@ public class StandardThreadExecutor exte
         executor = null;
         taskqueue = null;
     }
+
+    
+    @Override
+    protected void destroyInternal() {
+        // NOOP
+    }
+
     
     public void execute(Runnable command, long timeout, TimeUnit unit) {
         if ( executor != 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=940008&r1=940007&r2=940008&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/ha/context/ReplicatedContext.java (original)
+++ tomcat/trunk/java/org/apache/catalina/ha/context/ReplicatedContext.java Sat May  1 13:31:46 2010
@@ -54,14 +54,6 @@ public class ReplicatedContext extends S
     @Override
     protected synchronized void startInternal() throws LifecycleException {
 
-        if( !initialized ) { 
-            try {
-                init();
-            } catch( Exception ex ) {
-                throw new LifecycleException("Error initializaing ", ex);
-            }
-        }
-
         try {
             CatalinaCluster catclust = (CatalinaCluster)this.getCluster();
             if (this.context == null) this.context = new ReplApplContext(this);

Modified: tomcat/trunk/java/org/apache/catalina/ha/session/BackupManager.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/ha/session/BackupManager.java?rev=940008&r1=940007&r2=940008&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/ha/session/BackupManager.java (original)
+++ tomcat/trunk/java/org/apache/catalina/ha/session/BackupManager.java Sat May  1 13:31:46 2010
@@ -200,8 +200,6 @@ public class BackupManager extends Stand
     @Override
     protected synchronized void startInternal() throws LifecycleException {
         
-        if (!initialized) init();
-
         // Force initialization of the random number generator
         generateSessionId();
 
@@ -256,9 +254,7 @@ public class BackupManager extends Stand
         cluster.removeManager(this);
         this.random = null;
 
-        if( initialized ) {
-            destroy();
-        }
+        setState(LifecycleState.MUST_DESTROY);
     }
 
     @Override

Modified: tomcat/trunk/java/org/apache/catalina/ha/session/DeltaManager.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/ha/session/DeltaManager.java?rev=940008&r1=940007&r2=940008&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/ha/session/DeltaManager.java (original)
+++ tomcat/trunk/java/org/apache/catalina/ha/session/DeltaManager.java Sat May  1 13:31:46 2010
@@ -761,7 +761,6 @@ public class DeltaManager extends Cluste
      */
     @Override
     protected synchronized void startInternal() throws LifecycleException {
-        if (!initialized) init();
 
         // Force initialization of the random number generator
         generateSessionId();
@@ -988,9 +987,8 @@ public class DeltaManager extends Cluste
         this.random = null;
         getCluster().removeManager(this);
         replicationValve = null;
-        if (initialized) {
-            destroy();
-        }
+        
+        setState(LifecycleState.MUST_DESTROY);
     }
 
     // ----------------------------------------- PropertyChangeListener Methods

Modified: tomcat/trunk/java/org/apache/catalina/ha/tcp/SimpleTcpCluster.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/ha/tcp/SimpleTcpCluster.java?rev=940008&r1=940007&r2=940008&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/ha/tcp/SimpleTcpCluster.java (original)
+++ tomcat/trunk/java/org/apache/catalina/ha/tcp/SimpleTcpCluster.java Sat May  1 13:31:46 2010
@@ -613,6 +613,12 @@ public class SimpleTcpCluster extends Li
 
     // ------------------------------------------------------ public
 
+    @Override
+    protected void initInternal() {
+        // NOOP
+    }
+    
+    
     /**
      * Start Cluster and implement the requirements
      * of {@link LifecycleBase#startInternal()}.
@@ -732,6 +738,12 @@ public class SimpleTcpCluster extends Li
     }
 
     
+    @Override
+    protected void destroyInternal() {
+        // NOOP
+    }
+
+    
     /**
      * Return a String rendering of this object.
      */

Modified: tomcat/trunk/java/org/apache/catalina/loader/WebappClassLoader.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/loader/WebappClassLoader.java?rev=940008&r1=940007&r2=940008&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/loader/WebappClassLoader.java (original)
+++ tomcat/trunk/java/org/apache/catalina/loader/WebappClassLoader.java Sat May  1 13:31:46 2010
@@ -1757,6 +1757,12 @@ public class WebappClassLoader
     }
 
 
+    @Override
+    public void init() {
+        // NOOP
+    }
+
+    
     /**
      * Start the class loader.
      *
@@ -1837,6 +1843,12 @@ public class WebappClassLoader
     }
 
 
+    @Override
+    public void destroy() {
+        // NOOP
+    }
+    
+
     /**
      * Used to periodically signal to the classloader to release 
      * JAR resources.

Modified: tomcat/trunk/java/org/apache/catalina/loader/WebappLoader.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/loader/WebappLoader.java?rev=940008&r1=940007&r2=940008&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/loader/WebappLoader.java (original)
+++ tomcat/trunk/java/org/apache/catalina/loader/WebappLoader.java Sat May  1 13:31:46 2010
@@ -526,10 +526,8 @@ public class WebappLoader extends Lifecy
     }
 
 
-    private boolean initialized=false;
-
-    public void init() {
-        initialized=true;
+    @Override
+    protected void initInternal() {
 
         if( oname==null ) {
             // not registered yet - standalone or API
@@ -558,14 +556,13 @@ public class WebappLoader extends Lifecy
         }
     }
 
-    public void destroy() {
+    @Override
+    protected void destroyInternal() {
         if( controller==oname ) {
             // Self-registration, undo it
             Registry.getRegistry(null, null).unregisterComponent(oname);
             oname = null;
         }
-        initialized = false;
-
     }
 
     /**
@@ -578,8 +575,6 @@ public class WebappLoader extends Lifecy
     @Override
     protected void startInternal() throws LifecycleException {
 
-        if( ! initialized ) init();
-
         if (log.isDebugEnabled())
             log.debug(sm.getString("webappLoader.starting"));
 
@@ -702,7 +697,7 @@ public class WebappLoader extends Lifecy
 
         classLoader = null;
 
-        destroy();
+        setState(LifecycleState.MUST_DESTROY);
     }
 
 

Modified: tomcat/trunk/java/org/apache/catalina/realm/RealmBase.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/realm/RealmBase.java?rev=940008&r1=940007&r2=940008&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/realm/RealmBase.java (original)
+++ tomcat/trunk/java/org/apache/catalina/realm/RealmBase.java Sat May  1 13:31:46 2010
@@ -968,10 +968,6 @@ public abstract class RealmBase extends 
     @Override
     protected void startInternal() throws LifecycleException {
 
-        if( !initialized ) {
-            init();
-        }
-
         // Create a MessageDigest instance for credentials, if desired
         if (digest != null) {
             try {
@@ -1002,7 +998,7 @@ public abstract class RealmBase extends 
         // Clean up allocated resources
         md = null;
         
-        destroy();
+        setState(LifecycleState.MUST_DESTROY);
     }
     
     
@@ -1018,7 +1014,8 @@ public abstract class RealmBase extends 
     }
     
     
-    public void destroy() {
+    @Override
+    protected void destroyInternal() {
     
         // unregister this realm
         if ( oname!=null ) {   
@@ -1305,17 +1302,14 @@ public abstract class RealmBase extends 
         // NOOP in base class
     }
 
-    protected boolean initialized=false;
-    
-    public void init() {
-        if( initialized && container != null ) return;
+    @Override
+    protected void initInternal() {
 
         // We want logger as soon as possible
         if (container != null) {
             this.containerLog = container.getLogger();
         }
         
-        initialized=true;
         if( container== null ) {
             ObjectName parent=null;
             // Register with the parent

Modified: tomcat/trunk/java/org/apache/catalina/session/ManagerBase.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/session/ManagerBase.java?rev=940008&r1=940007&r2=940008&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/session/ManagerBase.java (original)
+++ tomcat/trunk/java/org/apache/catalina/session/ManagerBase.java Sat May  1 13:31:46 2010
@@ -191,8 +191,6 @@ public abstract class ManagerBase extend
     // number of duplicated session ids - anything >0 means we have problems
     protected int duplicates=0;
 
-    protected boolean initialized=false;
-    
     /**
      * Processing time during session expiration.
      */
@@ -712,7 +710,8 @@ public abstract class ManagerBase extend
 
     }
 
-    public void destroy() {
+    @Override
+    protected void destroyInternal() {
         if( oname != null )
             Registry.getRegistry(null, null).unregisterComponent(oname);
         if (randomIS!=null) {
@@ -724,13 +723,11 @@ public abstract class ManagerBase extend
             randomIS=null;
         }
 
-        initialized=false;
         oname = null;
     }
     
-    public void init() {
-        if( initialized ) return;
-        initialized=true;        
+    @Override
+    protected void initInternal() {
         
         if( oname==null ) {
             try {

Modified: tomcat/trunk/java/org/apache/catalina/session/PersistentManagerBase.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/session/PersistentManagerBase.java?rev=940008&r1=940007&r2=940008&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/session/PersistentManagerBase.java (original)
+++ tomcat/trunk/java/org/apache/catalina/session/PersistentManagerBase.java Sat May  1 13:31:46 2010
@@ -909,9 +909,6 @@ public abstract class PersistentManagerB
     @Override
     protected synchronized void startInternal() throws LifecycleException {
 
-        if( ! initialized )
-            init();
-        
         // Force initialization of the random number generator
         if (log.isDebugEnabled())
             log.debug("Force random number initialization starting");
@@ -962,8 +959,7 @@ public abstract class PersistentManagerB
         // Require a new random number generator if we are restarted
         this.random = null;
 
-        if( initialized )
-            destroy();
+        setState(LifecycleState.MUST_DESTROY);
 
     }
 

Modified: tomcat/trunk/java/org/apache/catalina/session/StandardManager.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/session/StandardManager.java?rev=940008&r1=940007&r2=940008&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/session/StandardManager.java (original)
+++ tomcat/trunk/java/org/apache/catalina/session/StandardManager.java Sat May  1 13:31:46 2010
@@ -570,9 +570,6 @@ public class StandardManager extends Man
     @Override
     protected synchronized void startInternal() throws LifecycleException {
 
-        if( ! initialized )
-            init();
-
         // Force initialization of the random number generator
         if (log.isDebugEnabled())
             log.debug("Force random number initialization starting");
@@ -633,9 +630,7 @@ public class StandardManager extends Man
         // Require a new random number generator if we are restarted
         this.random = null;
 
-        if( initialized ) {
-            destroy();
-        }
+        setState(LifecycleState.MUST_DESTROY);
     }
 
 

Modified: tomcat/trunk/java/org/apache/catalina/session/StoreBase.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/session/StoreBase.java?rev=940008&r1=940007&r2=940008&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/session/StoreBase.java (original)
+++ tomcat/trunk/java/org/apache/catalina/session/StoreBase.java Sat May  1 13:31:46 2010
@@ -182,6 +182,12 @@ public abstract class StoreBase extends 
     }
 
 
+    @Override
+    protected void initInternal() {
+        // NOOP
+    }
+    
+    
     /**
      * Start this component and implement the requirements
      * of {@link LifecycleBase#startInternal()}.
@@ -210,6 +216,12 @@ public abstract class StoreBase extends 
     }
     
     
+    @Override
+    protected void destroyInternal() {
+        // NOOP
+    }
+    
+    
     /**
      * Return a String rendering of this object.
      */

Modified: tomcat/trunk/java/org/apache/catalina/startup/Catalina.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/startup/Catalina.java?rev=940008&r1=940007&r2=940008&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/startup/Catalina.java (original)
+++ tomcat/trunk/java/org/apache/catalina/startup/Catalina.java Sat May  1 13:31:46 2010
@@ -501,7 +501,7 @@ public class Catalina extends Embedded {
 
         // Start the new server
         try {
-            getServer().initialize();
+            getServer().init();
         } catch (LifecycleException e) {
             if (Boolean.getBoolean("org.apache.catalina.startup.EXIT_ON_INIT_FAILURE"))
                 throw new java.lang.Error(e);
@@ -535,8 +535,8 @@ public class Catalina extends Embedded {
     }
 
     @Override
-    public void destroy() {
-
+    protected void destroyInternal() {
+        // NOOP
     }
 
     /**

Modified: tomcat/trunk/java/org/apache/catalina/startup/Embedded.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/startup/Embedded.java?rev=940008&r1=940007&r2=940008&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/startup/Embedded.java (original)
+++ tomcat/trunk/java/org/apache/catalina/startup/Embedded.java Sat May  1 13:31:46 2010
@@ -813,7 +813,6 @@ public class Embedded  extends StandardS
 
         setState(LifecycleState.STARTING);
         lifecycle.fireLifecycleEvent(START_EVENT, null);
-        initialized = true;
 
         // Start our defined Engines first
         for (int i = 0; i < engines.length; i++) {
@@ -822,7 +821,6 @@ public class Embedded  extends StandardS
 
         // Start our defined Connectors second
         for (int i = 0; i < connectors.length; i++) {
-            connectors[i].initialize();
             ((Lifecycle) connectors[i]).start();
         }
 

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=940008&r1=940007&r2=940008&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/startup/Tomcat.java (original)
+++ tomcat/trunk/java/org/apache/catalina/startup/Tomcat.java Sat May  1 13:31:46 2010
@@ -288,7 +288,6 @@ public class Tomcat {
     public void start() throws LifecycleException {
         getServer();
         getConnector();
-        server.initialize();
         server.start();
     }
 

Modified: tomcat/trunk/java/org/apache/catalina/util/LifecycleBase.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/util/LifecycleBase.java?rev=940008&r1=940007&r2=940008&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/util/LifecycleBase.java (original)
+++ tomcat/trunk/java/org/apache/catalina/util/LifecycleBase.java Sat May  1 13:31:46 2010
@@ -90,40 +90,51 @@ public abstract class LifecycleBase impl
     }
 
     
+    public synchronized final void init() throws LifecycleException {
+        if (!state.equals(LifecycleState.NEW)) {
+            invalidTransition(Lifecycle.INIT_EVENT);
+        }
+
+        // TODO - Check for JMX support and register if required
+        
+        initInternal();
+        
+        setState(LifecycleState.INITIALIZED);
+    }
+    
+    
+    protected abstract void initInternal() throws LifecycleException;
+    
     /**
      * {@inheritDoc}
      */
     @Override
-    public final void start() throws LifecycleException {
+    public synchronized final void start() throws LifecycleException {
         
-        synchronized (this) {
-            if (LifecycleState.STARTING_PREP.equals(state) ||
-                    LifecycleState.STARTING.equals(state) ||
-                    LifecycleState.STARTED.equals(state)) {
-                
-                if (log.isDebugEnabled()) {
-                    Exception e = new LifecycleException();
-                    log.debug(sm.getString("lifecycleBase.alreadyStarted",
-                            toString()), e);
-                } else if (log.isInfoEnabled()) {
-                    log.info(sm.getString("lifecycleBase.alreadyStarted",
-                            toString()));
-                }
-                
-                return;
-            }
+        if (LifecycleState.STARTING_PREP.equals(state) ||
+                LifecycleState.STARTING.equals(state) ||
+                LifecycleState.STARTED.equals(state)) {
             
-            if (!state.equals(LifecycleState.NEW) &&
-                    !state.equals(LifecycleState.STOPPED)) {
-                invalidTransition(Lifecycle.BEFORE_START_EVENT);
+            if (log.isDebugEnabled()) {
+                Exception e = new LifecycleException();
+                log.debug(sm.getString("lifecycleBase.alreadyStarted",
+                        toString()), e);
+            } else if (log.isInfoEnabled()) {
+                log.info(sm.getString("lifecycleBase.alreadyStarted",
+                        toString()));
             }
-
-            // Set state and fire event separately rather than via setState()
-            // so event fires outside of sync boundary
-            state = LifecycleState.STARTING_PREP;
+            
+            return;
         }
         
-        lifecycle.fireLifecycleEvent(Lifecycle.BEFORE_START_EVENT, null);
+        if (state.equals(LifecycleState.NEW)) {
+            init();
+        } else if (!state.equals(LifecycleState.INITIALIZED) &&
+                !state.equals(LifecycleState.STOPPED)) {
+            invalidTransition(Lifecycle.BEFORE_START_EVENT);
+        }
+
+        setState(LifecycleState.STARTING_PREP);
 
         startInternal();
 
@@ -166,52 +177,53 @@ public abstract class LifecycleBase impl
      * {@inheritDoc}
      */
     @Override
-    public final void stop() throws LifecycleException {
+    public synchronized final void stop() throws LifecycleException {
 
-        synchronized (this) {
-            if (LifecycleState.STOPPING_PREP.equals(state) ||
-                    LifecycleState.STOPPING.equals(state) ||
-                    LifecycleState.STOPPED.equals(state)) {
-    
-                if (log.isDebugEnabled()) {
-                    Exception e = new LifecycleException();
-                    log.debug(sm.getString("lifecycleBase.alreadyStopped",
-                            toString()), e);
-                } else if (log.isInfoEnabled()) {
-                    log.info(sm.getString("lifecycleBase.alreadyStopped",
-                            toString()));
-                }
-                
-                return;
+        if (LifecycleState.STOPPING_PREP.equals(state) ||
+                LifecycleState.STOPPING.equals(state) ||
+                LifecycleState.STOPPED.equals(state)) {
+
+            if (log.isDebugEnabled()) {
+                Exception e = new LifecycleException();
+                log.debug(sm.getString("lifecycleBase.alreadyStopped",
+                        toString()), e);
+            } else if (log.isInfoEnabled()) {
+                log.info(sm.getString("lifecycleBase.alreadyStopped",
+                        toString()));
             }
             
-            if (state.equals(LifecycleState.NEW)) {
-                state = LifecycleState.STOPPED;
-                return;
-            }
+            return;
+        }
+        
+        if (state.equals(LifecycleState.NEW)) {
+            state = LifecycleState.STOPPED;
+            return;
+        }
 
-            if (!state.equals(LifecycleState.STARTED) &&
-                    !state.equals(LifecycleState.FAILED) &&
-                    !state.equals(LifecycleState.MUST_STOP)) {
-                invalidTransition(Lifecycle.BEFORE_STOP_EVENT);
-            }
-            
-            // Set state and fire event separately rather than via setState()
-            // so event fires outside of sync boundary
-            state = LifecycleState.STOPPING_PREP;
+        if (!state.equals(LifecycleState.STARTED) &&
+                !state.equals(LifecycleState.FAILED) &&
+                !state.equals(LifecycleState.MUST_STOP)) {
+            invalidTransition(Lifecycle.BEFORE_STOP_EVENT);
         }
         
-        lifecycle.fireLifecycleEvent(Lifecycle.BEFORE_STOP_EVENT, null);
+        setState(LifecycleState.STOPPING_PREP);
 
         stopInternal();
 
-        // Shouldn't be necessary but acts as a check that sub-classes are doing
-        // what they are supposed to.
-        if (!state.equals(LifecycleState.STOPPING)) {
-            invalidTransition(Lifecycle.AFTER_STOP_EVENT);
-        }
+        if (state.equals(LifecycleState.MUST_DESTROY)) {
+            // Complete stop process first
+            setState(LifecycleState.STOPPED);
 
-        setState(LifecycleState.STOPPED);
+            destroy();
+        } else {
+            // Shouldn't be necessary but acts as a check that sub-classes are doing
+            // what they are supposed to.
+            if (!state.equals(LifecycleState.STOPPING)) {
+                invalidTransition(Lifecycle.AFTER_STOP_EVENT);
+            }
+
+            setState(LifecycleState.STOPPED);
+        }
     }
 
 
@@ -229,6 +241,22 @@ public abstract class LifecycleBase impl
     protected abstract void stopInternal() throws LifecycleException;
 
 
+    public synchronized final void destroy() throws LifecycleException {
+        if (!state.equals(LifecycleState.STOPPED) &&
+                !state.equals(LifecycleState.FAILED)) {
+            invalidTransition(Lifecycle.DESTROY_EVENT);
+        }
+
+        // TODO - Check for JMX support and de-register if required
+        
+        destroyInternal();
+        
+        setState(LifecycleState.DESTROYED);
+    }
+    
+    
+    protected abstract void destroyInternal() throws LifecycleException;
+    
     /**
      * {@inheritDoc}
      */
@@ -244,7 +272,7 @@ public abstract class LifecycleBase impl
      * 
      * @param state The new state for this component
      */
-    protected void setState(LifecycleState state) {
+    protected synchronized void setState(LifecycleState state) {
         setState(state, null);
     }
     

Modified: tomcat/trunk/java/org/apache/catalina/valves/ValveBase.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/valves/ValveBase.java?rev=940008&r1=940007&r2=940008&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/valves/ValveBase.java (original)
+++ tomcat/trunk/java/org/apache/catalina/valves/ValveBase.java Sat May  1 13:31:46 2010
@@ -227,6 +227,10 @@ public abstract class ValveBase extends 
     }
 
 
+    protected void initInternal() {
+        // NOOP
+    }
+
     /**
      * Start this component and implement the requirements
      * of {@link LifecycleBase#startInternal()}.
@@ -255,6 +259,12 @@ public abstract class ValveBase extends 
     }
     
     
+    @Override
+    protected void destroyInternal() {
+        // NOOP
+    }
+
+
     /**
      * Return a String rendering of this object.
      */



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org


Mime
View raw message