cziegeler 02/05/29 01:20:26 Modified: . todo.xml src/documentation cocoon.xconf sitemap.xmap src/java/org/apache/cocoon/caching PipelineCacheKey.java src/java/org/apache/cocoon/components/pipeline AbstractProcessingPipeline.java src/java/org/apache/cocoon/components/pipeline/impl CachingProcessingPipeline.java src/java/org/apache/cocoon/components/treeprocessor/sitemap PipelineNode.java src/java/org/apache/cocoon/sitemap ContentAggregator.java src/webapp sitemap.xmap Log: Some Fixes: - Changed sitemap for documentation build to use processing pipelines - Fixed NPE in content aggregator - Fixed hashCode calculation (Reported by Volker Schmitt [[EMAIL PROTECTED]] - Moved configuration of Expires into the ProcessingPipeline Revision Changes Path 1.34 +19 -1 xml-cocoon2/todo.xml Index: todo.xml =================================================================== RCS file: /home/cvs/xml-cocoon2/todo.xml,v retrieving revision 1.33 retrieving revision 1.34 diff -u -r1.33 -r1.34 --- todo.xml 9 May 2002 05:38:24 -0000 1.33 +++ todo.xml 29 May 2002 08:20:25 -0000 1.34 @@ -3,7 +3,7 @@ <!DOCTYPE todo PUBLIC "-//APACHE//DTD Todo V1.0//EN" "src/documentation/xdocs/dtd/todo-v10.dtd"> <!-- - $Id: todo.xml,v 1.33 2002/05/09 05:38:24 crossley Exp $ + $Id: todo.xml,v 1.34 2002/05/29 08:20:25 cziegeler Exp $ --> @@ -29,6 +29,24 @@ </devs> <actions priority="high"> + <action context="code" assigned-to="open"> + Rewrite the FilesystemStore. The current implementations relies on + a correct implementation of the toString() method of the used + keys. A correct version should rely on hashCode() and equals(). + (This is actually an Avalon action as the code is in Excalibur) + </action> + + <action context="code" assigned-to="open"> + Correct the release of internal ProcessingPipelines. If an + error/exception occurs, the ProcessingPipeline might not be + released correctly. + </action> + + <action context="code" assigned-to="open"> + Implement the smart-caching for the processing pipeline and + iron out bugs. + </action> + <action context="docs" assigned-to="open"> Attend to any high+ issues in the <link href="plan/todo-doc.html">Documentation To Do List</link> 1.14 +0 -10 xml-cocoon2/src/documentation/cocoon.xconf Index: cocoon.xconf =================================================================== RCS file: /home/cvs/xml-cocoon2/src/documentation/cocoon.xconf,v retrieving revision 1.13 retrieving revision 1.14 diff -u -r1.13 -r1.14 --- cocoon.xconf 6 May 2002 12:28:49 -0000 1.13 +++ cocoon.xconf 29 May 2002 08:20:25 -0000 1.14 @@ -91,16 +91,6 @@ <classloader class="org.apache.cocoon.components.classloader.ClassLoaderManagerImpl" logger="core.classloader"/> - <!-- Stream Pipeline --> - <stream-pipeline class="org.apache.cocoon.components.pipeline.CachingStreamPipeline" - logger="core.stream-pipeline" - pool-max="32" pool-min="8" pool-grow="4"/> - - <!-- Event Pipeline --> - <event-pipeline class="org.apache.cocoon.components.pipeline.CachingEventPipeline" - logger="core.event-pipeline" - pool-max="32" pool-min="8" pool-grow="4"/> - <!-- Entity resolution catalogs --> <entity-resolver class="org.apache.cocoon.components.resolver.ResolverImpl" logger="core.resolver"> 1.12 +7 -0 xml-cocoon2/src/documentation/sitemap.xmap Index: sitemap.xmap =================================================================== RCS file: /home/cvs/xml-cocoon2/src/documentation/sitemap.xmap,v retrieving revision 1.11 retrieving revision 1.12 diff -u -r1.11 -r1.12 --- sitemap.xmap 22 May 2002 13:02:05 -0000 1.11 +++ sitemap.xmap 29 May 2002 08:20:25 -0000 1.12 @@ -38,6 +38,13 @@ <map:matchers default="wildcard"> <map:matcher name="wildcard" src="org.apache.cocoon.matching.WildcardURIMatcher"/> </map:matchers> + + <map:pipelines default="noncaching"> + <map:pipeline name="noncaching" src="org.apache.cocoon.components.pipeline.impl.NonCachingProcessingPipeline" + logger="core.processing-pipeline" pool-max="32" pool-min="8" pool-grow="4"/> + </map:pipelines> + + </map:components> <!-- =========================== Views =================================== --> 1.14 +2 -2 xml-cocoon2/src/java/org/apache/cocoon/caching/PipelineCacheKey.java Index: PipelineCacheKey.java =================================================================== RCS file: /home/cvs/xml-cocoon2/src/java/org/apache/cocoon/caching/PipelineCacheKey.java,v retrieving revision 1.13 retrieving revision 1.14 diff -u -r1.13 -r1.14 --- PipelineCacheKey.java 28 May 2002 13:16:31 -0000 1.13 +++ PipelineCacheKey.java 29 May 2002 08:20:25 -0000 1.14 @@ -58,7 +58,7 @@ * or more {@link ComponentCacheKey}s. * * @author <a href="mailto:[EMAIL PROTECTED]">Carsten Ziegeler</a> - * @version CVS $Id: PipelineCacheKey.java,v 1.13 2002/05/28 13:16:31 cziegeler Exp $ + * @version CVS $Id: PipelineCacheKey.java,v 1.14 2002/05/29 08:20:25 cziegeler Exp $ */ public final class PipelineCacheKey implements java.io.Serializable { @@ -128,7 +128,7 @@ // FIXME - this is not very safe if (this.hashCode == 0) { for(int i=0; i < this.keys.size(); i++) { - this.hashCode = this.keys.get(i).hashCode(); + this.hashCode += this.keys.get(i).hashCode(); } if (this.keys.size() % 2 == 0) this.hashCode++; } 1.14 +113 -5 xml-cocoon2/src/java/org/apache/cocoon/components/pipeline/AbstractProcessingPipeline.java Index: AbstractProcessingPipeline.java =================================================================== RCS file: /home/cvs/xml-cocoon2/src/java/org/apache/cocoon/components/pipeline/AbstractProcessingPipeline.java,v retrieving revision 1.13 retrieving revision 1.14 diff -u -r1.13 -r1.14 --- AbstractProcessingPipeline.java 28 May 2002 14:03:18 -0000 1.13 +++ AbstractProcessingPipeline.java 29 May 2002 08:20:26 -0000 1.14 @@ -58,11 +58,14 @@ import org.apache.avalon.framework.component.ComponentSelector; import org.apache.avalon.framework.logger.AbstractLogEnabled; import org.apache.avalon.framework.parameters.Parameters; +import org.apache.avalon.framework.parameters.Parameterizable; import org.apache.cocoon.ConnectionResetException; import org.apache.cocoon.ProcessingException; import org.apache.cocoon.components.pipeline.OutputComponentSelector; import org.apache.cocoon.components.saxconnector.SAXConnector; import org.apache.cocoon.environment.Environment; +import org.apache.cocoon.environment.ObjectModelHelper; +import org.apache.cocoon.environment.Response; import org.apache.cocoon.generation.Generator; import org.apache.cocoon.reading.Reader; import org.apache.cocoon.serialization.Serializer; @@ -74,19 +77,18 @@ import java.io.IOException; import java.io.OutputStream; import java.net.SocketException; -import java.util.ArrayList; -import java.util.Iterator; +import java.util.*; /** * This is the base for all implementations of a <code>ProcessingPipeline</code>. * * @since @next-version@ * @author <a href="mailto:[EMAIL PROTECTED]">Carsten Ziegeler</a> - * @version CVS $Id: AbstractProcessingPipeline.java,v 1.13 2002/05/28 14:03:18 cziegeler Exp $ + * @version CVS $Id: AbstractProcessingPipeline.java,v 1.14 2002/05/29 08:20:26 cziegeler Exp $ */ public abstract class AbstractProcessingPipeline extends AbstractLogEnabled - implements ProcessingPipeline, Recyclable { + implements ProcessingPipeline, Parameterizable, Recyclable { // Generator stuff protected Generator generator; @@ -133,9 +135,18 @@ /** the component manager set with compose() and recompose() */ protected ComponentManager newManager; + /** The configuration */ + protected Parameters configuration; + /** The parameters */ protected Parameters parameters; + /** Expires value */ + protected long expires; + + /** Configured Expires value */ + protected long configuredExpires; + /** * Composable Interface */ @@ -156,10 +167,26 @@ } /** + * Parameterizable Interface - Configuration + */ + public void parameterize(Parameters params) { + this.configuration = params; + final String expiresValue = params.getParameter("expires", null); + if (expiresValue != null) { + this.configuredExpires = this.parseExpires(expiresValue); + } + } + + /** * Setup this component */ public void setup(Parameters params) { - this.parameters = params; + final String expiresValue = params.getParameter("expires", null); + if (expiresValue != null) { + this.expires = this.parseExpires(expiresValue); + } else { + this.expires = this.configuredExpires; + } } /** @@ -438,6 +465,14 @@ if ( !checkPipeline() ) { throw new ProcessingException("Attempted to process incomplete pipeline."); } + + // See if we need to set an "Expires:" header + if (this.expires != 0) { + Response res = ObjectModelHelper.getResponse(environment.getObjectModel()); + res.setDateHeader("Expires", expires); + environment.getObjectModel().put(ObjectModelHelper.EXPIRES_OBJECT, + new Long(expires)); + } if ( this.reader != null ) { this.setupReader( environment ); if (this.checkLastModified( environment )) { @@ -634,4 +669,77 @@ public SourceValidity[] getValiditiesForEventPipeline() { return null; } + + /** + * Parse the expires parameter + */ + private long parseExpires(String expire) { + StringTokenizer tokens = new StringTokenizer(expire); + + // get <base> + String current = tokens.nextToken(); + if (current.equals("modification")) { + + this.getLogger().warn("the \"modification\" keyword is not yet" + + + " implemented. Assuming \"now\" as the base attribute"); + current = "now"; + } + + if (!current.equals("now") && !current.equals("access")) { + this.getLogger().error("bad <base> attribute, Expires header will not be set"); + return -1; + } + long number = 0; + long modifier = 0; + long expires = 0; + + while (tokens.hasMoreTokens()) { + current = tokens.nextToken(); + + // get rid of the optional <plus> keyword + if (current.equals("plus")) + current = tokens.nextToken(); + + // We're expecting a sequence of <number> and <modification> here + // get <number> first + try { + number = Long.parseLong(current); + } catch (NumberFormatException nfe) { + this.getLogger().error("state violation: a number was expected here"); + return -1; + } + + // now get <modifier> + try { + current = tokens.nextToken(); + } catch (NoSuchElementException nsee) { + this.getLogger().error("state violation: expecting a modifier" + + " but no one found: Expires header will not be set"); + } + if (current.equals("years")) + modifier = 365L * 24L * 60L * 60L * 1000L; + else if (current.equals("months")) + modifier = 30L * 24L * 60L * 60L * 1000L; + else if (current.equals("weeks")) + modifier = 7L * 24L * 60L * 60L * 1000L; + else if (current.equals("days")) + modifier = 24L * 60L * 60L * 1000L; + else if (current.equals("hours")) + modifier = 60L * 60L * 1000L; + else if (current.equals("minutes")) + modifier = 60L * 1000L; + else if (current.equals("seconds")) + modifier = 1000L; + else { + this.getLogger().error("bad modifier (" + current + + "): ignoring expires configuration"); + return -1; + } + expires += number * modifier; + } + + return System.currentTimeMillis() + expires; + } + } 1.20 +49 -34 xml-cocoon2/src/java/org/apache/cocoon/components/pipeline/impl/CachingProcessingPipeline.java Index: CachingProcessingPipeline.java =================================================================== RCS file: /home/cvs/xml-cocoon2/src/java/org/apache/cocoon/components/pipeline/impl/CachingProcessingPipeline.java,v retrieving revision 1.19 retrieving revision 1.20 diff -u -r1.19 -r1.20 --- CachingProcessingPipeline.java 28 May 2002 11:33:57 -0000 1.19 +++ CachingProcessingPipeline.java 29 May 2002 08:20:26 -0000 1.20 @@ -92,7 +92,7 @@ * * @since @next-version@ * @author <a href="mailto:[EMAIL PROTECTED]">Carsten Ziegeler</a> - * @version CVS $Id: CachingProcessingPipeline.java,v 1.19 2002/05/28 11:33:57 cziegeler Exp $ + * @version CVS $Id: CachingProcessingPipeline.java,v 1.20 2002/05/29 08:20:26 cziegeler Exp $ */ public class CachingProcessingPipeline extends AbstractProcessingPipeline @@ -133,6 +133,8 @@ protected int firstNotCacheableTransformerIndex; /** Cache complete response */ protected boolean cacheCompleteResponse; + /** Smart caching ? */ + protected boolean doSmartCaching; /** * Composable Interface @@ -144,6 +146,16 @@ } /** + * Setup this component + */ + public void setup(Parameters params) { + super.setup(params); + this.doSmartCaching = params.getParameterAsBoolean("smart-caching", + this.configuration.getParameterAsBoolean("smart-caching", true)); + // FIXME (CZ) - Implement smart caching + } + + /** * Set the generator. */ public void setGenerator (String role, String source, Parameters param) @@ -382,46 +394,49 @@ SourceValidity[] validities = response.getValidityObjects(); int i = 0; while (responseIsValid && i < validities.length) { - boolean isValid = validities[i].isValid(); - if ( !isValid ) { - final SourceValidity validity; - if (i == 0) { - // test generator - if (generatorIsCacheableProcessingComponent) { - validity = ((CacheableProcessingComponent)super.generator).generateValidity(); + boolean isValid = false; + // FIXME (CZ) WORKAROUND validities[i] should never be null + if (validities[i] != null) { + isValid = validities[i].isValid(); + if ( !isValid ) { + final SourceValidity validity; + if (i == 0) { + // test generator + if (generatorIsCacheableProcessingComponent) { + validity = ((CacheableProcessingComponent)super.generator).generateValidity(); + } else { + validity = new CacheValidityToSourceValidity(((Cacheable)super.generator).generateValidity()); + } + } else if (i <= this.firstProcessedTransformerIndex) { + // test transformer + final Transformer trans = + (Transformer)super.transformers.get(i-1); + if (transformerIsCacheableProcessingComponent[i-1]) { + validity = ((CacheableProcessingComponent)trans).generateValidity(); + } else { + validity = new CacheValidityToSourceValidity(((Cacheable)trans).generateValidity()); + } } else { - validity = new CacheValidityToSourceValidity(((Cacheable)super.generator).generateValidity()); + // test serializer + if (serializerIsCacheableProcessingComponent) { + validity = ((CacheableProcessingComponent)super.serializer).generateValidity(); + } else { + validity = new CacheValidityToSourceValidity(((Cacheable)super.serializer).generateValidity()); + } } - } else if (i <= this.firstProcessedTransformerIndex) { - // test transformer - final Transformer trans = - (Transformer)super.transformers.get(i-1); - if (transformerIsCacheableProcessingComponent[i-1]) { - validity = ((CacheableProcessingComponent)trans).generateValidity(); - } else { - validity = new CacheValidityToSourceValidity(((Cacheable)trans).generateValidity()); + if (validity != null) { + isValid = validities[i].isValid( validity ); } - } else { - // test serializer - if (serializerIsCacheableProcessingComponent) { - validity = ((CacheableProcessingComponent)super.serializer).generateValidity(); - } else { - validity = new CacheValidityToSourceValidity(((Cacheable)super.serializer).generateValidity()); + if ( !isValid ) { + responseIsValid = false; + // update validity + validities[i] = validity; + if (validity == null) responseIsUsable = false; } } - if (validity != null) { - isValid = validities[i].isValid( validity ); - } - if ( !isValid ) { - responseIsValid = false; - // update validity - validities[i] = validity; - if (validity == null) responseIsUsable = false; - } + if ( isValid ) i++; } - if ( isValid ) i++; } - if ( responseIsValid ) { // we are valid, ok that's it cachedValidityObjects = validities; 1.7 +1 -84 xml-cocoon2/src/java/org/apache/cocoon/components/treeprocessor/sitemap/PipelineNode.java Index: PipelineNode.java =================================================================== RCS file: /home/cvs/xml-cocoon2/src/java/org/apache/cocoon/components/treeprocessor/sitemap/PipelineNode.java,v retrieving revision 1.6 retrieving revision 1.7 diff -u -r1.6 -r1.7 --- PipelineNode.java 27 May 2002 12:43:22 -0000 1.6 +++ PipelineNode.java 29 May 2002 08:20:26 -0000 1.7 @@ -61,8 +61,6 @@ import org.apache.cocoon.ResourceNotFoundException; import org.apache.cocoon.environment.Environment; -import org.apache.cocoon.environment.ObjectModelHelper; -import org.apache.cocoon.environment.Response; import org.apache.cocoon.components.notification.Notifying; import org.apache.cocoon.components.notification.NotifyingBuilder; import org.apache.cocoon.components.treeprocessor.AbstractParentProcessingNode; @@ -79,7 +77,7 @@ * @author <a href="mailto:[EMAIL PROTECTED]">Sylvain Wallez</a> * @author <a href="mailto:[EMAIL PROTECTED]">Gianugo Rabellino</a> * @author <a href="mailto:[EMAIL PROTECTED]">Carsten Ziegeler</a> - * @version CVS $Id: PipelineNode.java,v 1.6 2002/05/27 12:43:22 cziegeler Exp $ + * @version CVS $Id: PipelineNode.java,v 1.7 2002/05/29 08:20:26 cziegeler Exp $ */ public class PipelineNode extends AbstractParentProcessingNode @@ -101,8 +99,6 @@ /** Is it the last <pipeline> in the enclosing <pipelines> ? */ private boolean isLast = false; - private String expires; - /** The component name of the processing pipeline */ protected String processingPipeline; @@ -114,7 +110,6 @@ * and optional parameters for the processing pipeline */ public PipelineNode(Configuration config) { - this.expires = config.getAttribute("expires", null); this.processingPipeline = config.getAttribute("type", null); } @@ -160,16 +155,6 @@ context.inform(this.processingPipeline, this.parameters); try { - // See if we need to set an "Expires:" header - if (expires != null) { - Response res = ObjectModelHelper.getResponse( - env.getObjectModel()); - long expiration = this.parseExpires(expires); - res.setDateHeader("Expires", expiration); - env.getObjectModel().put(ObjectModelHelper.EXPIRES_OBJECT, - new Long(expiration)); - } - if (invokeNodes(children, env, context)) { return true; } else if (this.isLast) { @@ -243,72 +228,4 @@ } } - private long parseExpires(String expire) throws Exception { - StringTokenizer tokens = new StringTokenizer(expire); - - // get <base> - String current = tokens.nextToken(); - if (current.equals("modification")) { - - this.getLogger().warn("the \"modification\" keyword is not yet" + - - " implemented. Assuming \"now\" as the base attribute"); - current = "now"; - } - - if (!current.equals("now") && !current.equals("access")) { - this.getLogger().error("bad <base> attribute, Expires header will not be set"); - return -1; - } - long number = 0; - long modifier = 0; - long expires = 0; - - while (tokens.hasMoreTokens()) { - current = tokens.nextToken(); - - // get rid of the optional <plus> keyword - if (current.equals("plus")) - current = tokens.nextToken(); - - // We're expecting a sequence of <number> and <modification> here - // get <number> first - try { - number = Long.parseLong(current); - } catch (NumberFormatException nfe) { - this.getLogger().error("state violation: a number was expected here"); - return -1; - } - - // now get <modifier> - try { - current = tokens.nextToken(); - } catch (NoSuchElementException nsee) { - this.getLogger().error("state violation: expecting a modifier" + - " but no one found: Expires header will not be set"); - } - if (current.equals("years")) - modifier = 365L * 24L * 60L * 60L * 1000L; - else if (current.equals("months")) - modifier = 30L * 24L * 60L * 60L * 1000L; - else if (current.equals("weeks")) - modifier = 7L * 24L * 60L * 60L * 1000L; - else if (current.equals("days")) - modifier = 24L * 60L * 60L * 1000L; - else if (current.equals("hours")) - modifier = 60L * 60L * 1000L; - else if (current.equals("minutes")) - modifier = 60L * 1000L; - else if (current.equals("seconds")) - modifier = 1000L; - else { - this.getLogger().error("bad modifier (" + current + - "): ignoring expires configuration"); - return -1; - } - expires += number * modifier; - } - - return System.currentTimeMillis() + expires; - } } 1.6 +2 -1 xml-cocoon2/src/java/org/apache/cocoon/sitemap/ContentAggregator.java Index: ContentAggregator.java =================================================================== RCS file: /home/cvs/xml-cocoon2/src/java/org/apache/cocoon/sitemap/ContentAggregator.java,v retrieving revision 1.5 retrieving revision 1.6 diff -u -r1.5 -r1.6 --- ContentAggregator.java 28 May 2002 13:08:13 -0000 1.5 +++ ContentAggregator.java 29 May 2002 08:20:26 -0000 1.6 @@ -78,7 +78,7 @@ * * @author <a href="mailto:[EMAIL PROTECTED]">Giacomo Pati</a> * @author <a href="mailto:[EMAIL PROTECTED]">Carsten Ziegeler</a> - * @version CVS $Id: ContentAggregator.java,v 1.5 2002/05/28 13:08:13 cziegeler Exp $ + * @version CVS $Id: ContentAggregator.java,v 1.6 2002/05/29 08:20:26 cziegeler Exp $ */ public class ContentAggregator extends ContentHandlerWrapper @@ -301,6 +301,7 @@ */ public void setup(SourceResolver resolver, Map objectModel, String src, Parameters par) throws ProcessingException, SAXException, IOException { + this.resolver = resolver; // get the Source for each part try { for(int i=0; i<this.parts.size();i++) { 1.59 +1 -2 xml-cocoon2/src/webapp/sitemap.xmap Index: sitemap.xmap =================================================================== RCS file: /home/cvs/xml-cocoon2/src/webapp/sitemap.xmap,v retrieving revision 1.58 retrieving revision 1.59 diff -u -r1.58 -r1.59 --- sitemap.xmap 28 May 2002 09:09:33 -0000 1.58 +++ sitemap.xmap 29 May 2002 08:20:26 -0000 1.59 @@ -315,8 +315,7 @@ <!-- The different pipeline implementations --> - <map:pipelines default="noncaching"> - <!-- ATTENTION: The caching pipeline is currently not working, use at your own risk! --> + <map:pipelines default="caching"> <map:pipeline name="caching" src="org.apache.cocoon.components.pipeline.impl.CachingProcessingPipeline"/> <map:pipeline name="noncaching" src="org.apache.cocoon.components.pipeline.impl.NonCachingProcessingPipeline"/> <!-- The following two can be used for profiling:
---------------------------------------------------------------------- In case of troubles, e-mail: [EMAIL PROTECTED] To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]