vgritsenko 02/01/29 07:33:26 Modified: src/java/org/apache/cocoon/generation ServerPagesGenerator.java src/java/org/apache/cocoon/components/language/generator ProgramGeneratorImpl.java Log: XSP Engine Fixes - Dispose everything disposable - Clean up references - Why server pages generator had static reference to the ProgramGenerator? - Check Source last modification date for 0 ("unknown") - Do not ignore ComponentException on Compose - parameterize() instead of configure() Revision Changes Path 1.5 +11 -11 xml-cocoon2/src/java/org/apache/cocoon/generation/ServerPagesGenerator.java Index: ServerPagesGenerator.java =================================================================== RCS file: /home/cvs/xml-cocoon2/src/java/org/apache/cocoon/generation/ServerPagesGenerator.java,v retrieving revision 1.4 retrieving revision 1.5 diff -u -r1.4 -r1.5 --- ServerPagesGenerator.java 26 Jan 2002 02:16:49 -0000 1.4 +++ ServerPagesGenerator.java 29 Jan 2002 15:33:26 -0000 1.5 @@ -59,7 +59,7 @@ * * @author <a href="mailto:[EMAIL PROTECTED]">Ricardo Rocha</a> * @author <a href="mailto:[EMAIL PROTECTED]">Sylvain Wallez</a> - * @version CVS $Revision: 1.4 $ $Date: 2002/01/26 02:16:49 $ + * @version CVS $Revision: 1.5 $ $Date: 2002/01/29 15:33:26 $ */ public class ServerPagesGenerator extends ServletGenerator implements Recyclable, Disposable, Cacheable, Configurable @@ -67,7 +67,7 @@ /** * The sitemap-defined server pages program generator */ - protected static ProgramGenerator programGenerator = null; + protected ProgramGenerator programGenerator = null; protected XSPGenerator generator = null; @@ -86,12 +86,8 @@ super.compose(manager); if (programGenerator == null) { - try { - this.programGenerator = (ProgramGenerator) - manager.lookup(ProgramGenerator.ROLE); - } catch (Exception e) { - getLogger().error("Could not find ProgramGenerator", e); - } + this.programGenerator = + (ProgramGenerator) manager.lookup(ProgramGenerator.ROLE); } } @@ -169,8 +165,9 @@ } try { - generator = (XSPGenerator) - programGenerator.load(this.manager, super.source, this.markupLanguage, this.programmingLanguage, this.resolver); + generator = (XSPGenerator) programGenerator.load( + this.manager, super.source, this.markupLanguage, + this.programmingLanguage, this.resolver); } catch (ProcessingException e) { throw e; } catch (Exception e) { @@ -185,6 +182,7 @@ if (generator instanceof Loggable) { ((Loggable)generator).setLogger(getLogger()); } + generator.setup(this.resolver, this.objectModel, super.source, this.parameters); } @@ -272,7 +270,9 @@ * dispose */ public void dispose() { - if(this.programGenerator != null) manager.release((Component)this.programGenerator); + if(this.programGenerator != null) + manager.release((Component)this.programGenerator); + this.programGenerator = null; } /* Completion pipe */ 1.3 +54 -42 xml-cocoon2/src/java/org/apache/cocoon/components/language/generator/ProgramGeneratorImpl.java Index: ProgramGeneratorImpl.java =================================================================== RCS file: /home/cvs/xml-cocoon2/src/java/org/apache/cocoon/components/language/generator/ProgramGeneratorImpl.java,v retrieving revision 1.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- ProgramGeneratorImpl.java 22 Jan 2002 00:17:11 -0000 1.2 +++ ProgramGeneratorImpl.java 29 Jan 2002 15:33:26 -0000 1.3 @@ -9,16 +9,19 @@ package org.apache.cocoon.components.language.generator; import org.apache.avalon.framework.activity.Disposable; -import org.apache.avalon.framework.component.*; -import org.apache.avalon.framework.configuration.Configurable; -import org.apache.avalon.framework.configuration.Configuration; -import org.apache.avalon.framework.configuration.ConfigurationException; +import org.apache.avalon.framework.component.Composable; +import org.apache.avalon.framework.component.ComponentManager; +import org.apache.avalon.framework.component.ComponentSelector; +import org.apache.avalon.framework.component.ComponentException; import org.apache.avalon.framework.context.Context; import org.apache.avalon.framework.context.ContextException; import org.apache.avalon.framework.context.Contextualizable; import org.apache.avalon.framework.logger.AbstractLoggable; import org.apache.avalon.framework.parameters.Parameters; +import org.apache.avalon.framework.parameters.Parameterizable; +import org.apache.avalon.framework.parameters.ParameterException; import org.apache.avalon.framework.thread.ThreadSafe; + import org.apache.cocoon.Constants; import org.apache.cocoon.ProcessingException; import org.apache.cocoon.components.classloader.ClassLoaderManager; @@ -39,10 +42,11 @@ /** * The default implementation of <code>ProgramGenerator</code> * @author <a href="mailto:[EMAIL PROTECTED]">Ricardo Rocha</a> - * @version CVS $Revision: 1.2 $ $Date: 2002/01/22 00:17:11 $ + * @version CVS $Revision: 1.3 $ $Date: 2002/01/29 15:33:26 $ */ public class ProgramGeneratorImpl extends AbstractLoggable - implements ProgramGenerator, Contextualizable, Composable, Configurable, ThreadSafe, Disposable { + implements ProgramGenerator, Contextualizable, Composable, Parameterizable, + Disposable, ThreadSafe { /** The auto-reloading option */ protected boolean autoReload = false; @@ -57,7 +61,7 @@ protected Store repository; /** The component manager */ - protected ComponentManager manager = null; + protected ComponentManager manager; /** The markup language component selector */ protected ComponentSelector markupSelector; @@ -86,7 +90,7 @@ if (this.contextDir == null) { org.apache.cocoon.environment.Context ctx = (org.apache.cocoon.environment.Context) context.get(Constants.CONTEXT_ENVIRONMENT_CONTEXT); - + // Determine the context directory, preferably as a file // FIXME (SW) - this is purposely redundant with some code in CocoonServlet // to have the same rootPath. How to avoid this ? @@ -96,7 +100,7 @@ this.contextDir = new File(rootPath).toURL().toExternalForm(); } else { String webInf = ctx.getResource("/WEB-INF").toExternalForm(); - this.contextDir = webInf.substring(0,webInf.length() - "WEB-INF".length()); + this.contextDir = webInf.substring(0, webInf.length() - "WEB-INF".length()); } getLogger().debug("Context directory is " + this.contextDir); } catch (MalformedURLException e) { @@ -115,15 +119,11 @@ public void compose(ComponentManager manager) throws ComponentException { if ((this.manager == null) && (manager != null)) { this.manager = manager; - try { - this.cache = (GeneratorSelector) this.manager.lookup(GeneratorSelector.ROLE + "Selector"); - this.repository = (Store) this.manager.lookup(Store.ROLE + "/Filesystem"); - this.markupSelector = (ComponentSelector)this.manager.lookup(MarkupLanguage.ROLE + "Selector"); - this.languageSelector = (ComponentSelector)this.manager.lookup(ProgrammingLanguage.ROLE + "Selector"); - this.classManager = (ClassLoaderManager)this.manager.lookup(ClassLoaderManager.ROLE); - } catch (Exception e) { - getLogger().warn("Could not lookup Component", e); - } + this.cache = (GeneratorSelector) this.manager.lookup(GeneratorSelector.ROLE + "Selector"); + this.repository = (Store) this.manager.lookup(Store.ROLE + "/Filesystem"); + this.markupSelector = (ComponentSelector)this.manager.lookup(MarkupLanguage.ROLE + "Selector"); + this.languageSelector = (ComponentSelector)this.manager.lookup(ProgrammingLanguage.ROLE + "Selector"); + this.classManager = (ClassLoaderManager)this.manager.lookup(ClassLoaderManager.ROLE); } } @@ -132,8 +132,7 @@ * @param conf The configuration information * @exception ConfigurationException Not thrown here */ - public void configure(Configuration conf) throws ConfigurationException { - Parameters params = Parameters.fromConfiguration(conf); + public void parameterize(Parameters params) throws ParameterException { this.autoReload = params.getParameterAsBoolean("auto-reload", autoReload); this.rootPackage = params.getParameter("root-package", "org.apache.cocoon.www"); this.preload = params.getParameterAsBoolean("preload", preload); @@ -169,21 +168,20 @@ contextFilename.append(id); } String normalizedName = IOUtils.normalizedFilename(contextFilename.toString()); - + // Ensure no 2 requests for the same file overlap Class program = null; CompiledComponent programInstance = null; - + // Attempt to load program object from cache try { programInstance = (CompiledComponent) select(normalizedName); } catch (Exception e) { getLogger().debug("The instance was not accessible from the internal cache. Proceeding."); } - + if ((programInstance == null) && this.preload) { String className = normalizedName.replace(File.separatorChar, '.'); - try { program = this.classManager.loadClass(className); this.addCompiledComponent(newManager, normalizedName, program); @@ -192,49 +190,52 @@ getLogger().debug("The class was not preloaded"); } } - + if (programInstance == null) { - programInstance = + programInstance = this.createResource( newManager, fileName, normalizedName, markupLanguageName, programmingLanguageName, resolver ); } - + if (!this.autoReload) { return programInstance; } - + /* * FIXME: It's the program (not the instance) that must * be queried for changes!!! */ - - if (programInstance != null && programInstance.modifiedSince(source.getLastModified())) { + long lastModified = source.getLastModified(); + if (programInstance != null && + (lastModified == 0 || programInstance.modifiedSince(lastModified))) + { // Release the component. release(programInstance); - + // Unload program ProgrammingLanguage programmingLanguage = (ProgrammingLanguage)this.languageSelector.select(programmingLanguageName); programmingLanguage.setLanguageName(programmingLanguageName); programmingLanguage.unload(program, normalizedName, this.workDir); this.cache.removeGenerator(normalizedName); - + // Invalidate previous program/instance pair program = null; programInstance = null; } - + if (programInstance == null) { if (program == null) { programInstance = this.createResource( - newManager, fileName, normalizedName, + newManager, fileName, normalizedName, markupLanguageName, programmingLanguageName, resolver ); - } else + } else { programInstance = (CompiledComponent) select(normalizedName); + } } return programInstance; @@ -312,7 +313,7 @@ throws Exception { Source source = resolver.resolve(fileName); - try { + try { // Input Source InputSource is = source.getInputSource(); // Generate code @@ -331,7 +332,7 @@ Class program = programmingLanguage.load(normalizedName, this.workDir, markupLanguage.getEncoding()); // Store generated program in cache this.addCompiledComponent(newManager, normalizedName, program); - + // FIXME: Do we want this functionality? All analysis says no. if (markupLanguage.getClass().equals(SitemapMarkupLanguage.class)) { try { @@ -341,7 +342,7 @@ this.addCompiledComponent(newManager, "sitemap", program); } } - + return program; } finally { source.recycle(); @@ -369,9 +370,20 @@ * dispose */ public void dispose() { - this.manager.release((Component)this.cache); - this.manager.release((Component)this.repository); - this.manager.release((Component)this.markupSelector); - this.manager.release((Component)this.languageSelector); + this.manager.release(this.cache); + this.cache = null; + this.manager.release(this.repository); + this.repository = null; + this.manager.release(this.markupSelector); + this.markupSelector = null; + this.manager.release(this.languageSelector); + this.languageSelector = null; + this.manager.release(this.classManager); + this.classManager = null; + + this.manager = null; + + this.workDir = null; + this.contextDir = null; } }
---------------------------------------------------------------------- In case of troubles, e-mail: [EMAIL PROTECTED] To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]