import org.apache.catalina.Context;
import org.apache.catalina.LifecycleException;
-import org.apache.catalina.LifecycleListener;
+import org.apache.catalina.LifecycleState;
import org.apache.catalina.Server;
import org.apache.catalina.Service;
import org.apache.catalina.deploy.NamingResources;
-import org.apache.catalina.util.LifecycleSupport;
+import org.apache.catalina.util.LifecycleBase;
import org.apache.tomcat.util.res.StringManager;
import org.apache.catalina.util.ServerInfo;
import org.apache.juli.logging.Log;
* @author Craig R. McClanahan
* @version $Revision$ $Date$
*/
-public final class StandardServer implements Server, MBeanRegistration {
+public final class StandardServer extends LifecycleBase
+ implements Server, MBeanRegistration {
private static final Log log = LogFactory.getLog(StandardServer.class);
/**
- * The lifecycle event support for this component.
- */
- private LifecycleSupport lifecycle = new LifecycleSupport(this);
-
-
- /**
* The naming context listener for this web application.
*/
private NamingContextListener namingContextListener = null;
/**
- * Has this component been started?
- */
- private boolean started = false;
-
-
- /**
* Has this component been initialized?
*/
private boolean initialized = false;
}
}
- if (started) {
+ if (getState().isAvailable()) {
try {
service.start();
} catch (LifecycleException e) {
}
- // ------------------------------------------------------ Lifecycle Methods
-
-
/**
- * Add a LifecycleEvent 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 LifecycleEvent listener from this component.
- *
- * @param listener The listener to remove
- */
- public void removeLifecycleListener(LifecycleListener listener) {
-
- lifecycle.removeLifecycleListener(listener);
-
- }
-
-
- /**
- * 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. It should also send a
- * LifecycleEvent of type START_EVENT to any registered listeners.
+ * Start nested components ({@link Service}s) and implement the requirements
+ * of {@link LifecycleBase#startInternal()}.
*
* @exception LifecycleException if this component detects a fatal error
* that prevents this component from being used
*/
- public void start() throws LifecycleException {
-
- // Validate and update our current component state
- if (started) {
- log.debug(sm.getString("standardServer.start.started"));
- return;
- }
-
- // Notify our interested LifecycleListeners
- lifecycle.fireLifecycleEvent(BEFORE_START_EVENT, null);
+ protected void startInternal() throws LifecycleException {
- lifecycle.fireLifecycleEvent(START_EVENT, null);
- started = true;
+ setState(LifecycleState.STARTING);
// Start our defined Services
synchronized (services) {
services[i].start();
}
}
-
- // Notify our interested LifecycleListeners
- lifecycle.fireLifecycleEvent(AFTER_START_EVENT, null);
-
}
/**
- * Gracefully terminate the active use of the public methods of this
- * component. This method should be the last one called on a given
- * instance of this component. It should also send a LifecycleEvent
- * of type STOP_EVENT to any registered listeners.
+ * Stop nested components ({@link Service}s) and implement the requirements
+ * of {@link LifecycleBase#stopInternal()}.
*
* @exception LifecycleException if this component detects a fatal error
* that needs to be reported
*/
- public void stop() throws LifecycleException {
-
- // Validate and update our current component state
- if (!started)
- return;
+ protected void stopInternal() throws LifecycleException {
- // Notify our interested LifecycleListeners
- lifecycle.fireLifecycleEvent(BEFORE_STOP_EVENT, null);
-
- lifecycle.fireLifecycleEvent(STOP_EVENT, null);
- started = false;
+ setState(LifecycleState.STOPPING);
// Stop our defined Services
for (int i = 0; i < services.length; i++) {
services[i].stop();
}
- // Notify our interested LifecycleListeners
- lifecycle.fireLifecycleEvent(AFTER_STOP_EVENT, null);
-
if (port == -1)
stopAwait();
log.info(sm.getString("standardServer.initialize.initialized"));
return;
}
- lifecycle.fireLifecycleEvent(INIT_EVENT, null);
+ fireLifecycleEvent(INIT_EVENT, null);
initialized = true;
if( oname==null ) {