Author: markt Date: Fri Mar 5 14:49:39 2010 New Revision: 919434 URL: http://svn.apache.org/viewvc?rev=919434&view=rev Log: Lifecycle refactoring o.a.c.loader - Note WebappClassloader only has a stubbed Lifecycle implementation
Modified: tomcat/trunk/java/org/apache/catalina/loader/VirtualWebappLoader.java tomcat/trunk/java/org/apache/catalina/loader/WebappClassLoader.java tomcat/trunk/java/org/apache/catalina/loader/WebappLoader.java Modified: tomcat/trunk/java/org/apache/catalina/loader/VirtualWebappLoader.java URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/loader/VirtualWebappLoader.java?rev=919434&r1=919433&r2=919434&view=diff ============================================================================== --- tomcat/trunk/java/org/apache/catalina/loader/VirtualWebappLoader.java (original) +++ tomcat/trunk/java/org/apache/catalina/loader/VirtualWebappLoader.java Fri Mar 5 14:49:39 2010 @@ -20,6 +20,7 @@ import java.util.StringTokenizer; import org.apache.catalina.LifecycleException; +import org.apache.catalina.util.LifecycleBase; /** * Simple webapp classloader that allows a customized classpath to be added @@ -80,8 +81,15 @@ virtualClasspath = path; } + /** + * 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 void start() throws LifecycleException { + protected void startInternal() throws LifecycleException { // just add any jar/directory set in virtual classpath to the // repositories list before calling start on the standard WebappLoader @@ -94,7 +102,7 @@ addRepository(file.toURI().toString()); } - super.start(); + super.startInternal(); } } 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=919434&r1=919433&r2=919434&view=diff ============================================================================== --- tomcat/trunk/java/org/apache/catalina/loader/WebappClassLoader.java (original) +++ tomcat/trunk/java/org/apache/catalina/loader/WebappClassLoader.java Fri Mar 5 14:49:39 2010 @@ -68,6 +68,7 @@ import org.apache.catalina.Lifecycle; import org.apache.catalina.LifecycleException; import org.apache.catalina.LifecycleListener; +import org.apache.catalina.LifecycleState; import org.apache.tomcat.util.res.StringManager; import org.apache.jasper.servlet.JasperLoader; import org.apache.naming.JndiPermission; @@ -107,6 +108,9 @@ * <p> * <strong>IMPLEMENTATION NOTE</strong> - No check for sealing violations or * security is made unless a security manager is present. + * <p> + * TODO: Is there any requirement to provide a proper Lifecycle implementation + * rather than the current stubbed implementation? * * @author Remy Maucherat * @author Craig R. McClanahan @@ -1641,6 +1645,16 @@ /** + * Obtain the current state of the source component. + * + * @return The current state of the source component. + */ + public LifecycleState getState() { + return LifecycleState.NEW; + } + + + /** * Start the class loader. * * @exception LifecycleException if a lifecycle error occurs 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=919434&r1=919433&r2=919434&view=diff ============================================================================== --- tomcat/trunk/java/org/apache/catalina/loader/WebappLoader.java (original) +++ tomcat/trunk/java/org/apache/catalina/loader/WebappLoader.java Fri Mar 5 14:49:39 2010 @@ -51,10 +51,10 @@ 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.core.StandardContext; -import org.apache.catalina.util.LifecycleSupport; +import org.apache.catalina.util.LifecycleBase; import org.apache.tomcat.util.res.StringManager; import org.apache.naming.resources.DirContextURLStreamHandler; import org.apache.naming.resources.DirContextURLStreamHandlerFactory; @@ -80,8 +80,8 @@ * @version $Revision$ $Date$ */ -public class WebappLoader - implements Lifecycle, Loader, PropertyChangeListener, MBeanRegistration { +public class WebappLoader extends LifecycleBase + implements Loader, PropertyChangeListener, MBeanRegistration { // ----------------------------------------------------------- Constructors @@ -145,12 +145,6 @@ /** - * The lifecycle event support for this component. - */ - protected LifecycleSupport lifecycle = new LifecycleSupport(this); - - - /** * The Java class name of the ClassLoader implementation to be used. * This class should extend WebappClassLoader, otherwise, a different * loader implementation must be used. @@ -185,12 +179,6 @@ /** - * Has this component been started? - */ - private boolean started = false; - - - /** * The property change support for this component. */ protected PropertyChangeSupport support = new PropertyChangeSupport(this); @@ -379,7 +367,7 @@ results[repositories.length] = repository; repositories = results; - if (started && (classLoader != null)) { + if (getState().isAvailable() && (classLoader != null)) { classLoader.addRepository(repository); if( loaderRepositories != null ) loaderRepositories.add(repository); setClassPath(); @@ -515,43 +503,6 @@ } - // ------------------------------------------------------ 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); - - } - private boolean initialized=false; public void init() { @@ -595,25 +546,26 @@ } /** - * Start this component, initializing our associated class loader. + * Start associated {...@link ClassLoader} and implement the requirements + * of {...@link LifecycleBase#startInternal()}. * - * @exception LifecycleException if a lifecycle error occurs + * @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 + @Override + protected void startInternal() throws LifecycleException { + if( ! initialized ) init(); - if (started) - throw new LifecycleException - (sm.getString("webappLoader.alreadyStarted")); + if (log.isDebugEnabled()) log.debug(sm.getString("webappLoader.starting")); - lifecycle.fireLifecycleEvent(START_EVENT, null); - started = true; if (container.getResources() == null) { log.info("No resources for " + container); + setState(LifecycleState.STARTING); return; } + // Register a stream handler factory for the JNDI protocol URLStreamHandlerFactory streamHandlerFactory = new DirContextURLStreamHandlerFactory(); @@ -678,24 +630,24 @@ throw new LifecycleException("start: ", t); } + setState(LifecycleState.STARTING); } /** - * Stop this component, finalizing our associated class loader. + * Stop associated {...@link ClassLoader} and implement the requirements + * of {...@link LifecycleBase#stopInternal()}. * - * @exception LifecycleException if a lifecycle error occurs + * @exception LifecycleException if this component detects a fatal error + * that prevents this component from being used */ - public void stop() throws LifecycleException { + @Override + protected void stopInternal() throws LifecycleException { - // Validate and update our current component state - if (!started) - throw new LifecycleException - (sm.getString("webappLoader.notStarted")); if (log.isDebugEnabled()) log.debug(sm.getString("webappLoader.stopping")); - lifecycle.fireLifecycleEvent(STOP_EVENT, null); - started = false; + + setState(LifecycleState.STOPPING); // Remove context attributes as appropriate if (container instanceof Context) { @@ -725,7 +677,6 @@ classLoader = null; destroy(); - } --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org For additional commands, e-mail: dev-h...@tomcat.apache.org