cziegeler 02/05/06 06:22:32 Modified: src/java/org/apache/cocoon cocoon.roles src/java/org/apache/cocoon/caching CacheableProcessingComponent.java CachedResponse.java SourceCacheValidity.java src/java/org/apache/cocoon/components/pipeline/impl CachingProcessingPipeline.java Added: src/java/org/apache/cocoon/caching Cache.java CacheValidityToSourceValidity.java src/java/org/apache/cocoon/caching/impl CacheImpl.java Log: Starting Cache component Revision Changes Path 1.27 +8 -4 xml-cocoon2/src/java/org/apache/cocoon/cocoon.roles Index: cocoon.roles =================================================================== RCS file: /home/cvs/xml-cocoon2/src/java/org/apache/cocoon/cocoon.roles,v retrieving revision 1.26 retrieving revision 1.27 diff -u -r1.26 -r1.27 --- cocoon.roles 6 May 2002 12:28:50 -0000 1.26 +++ cocoon.roles 6 May 2002 13:22:30 -0000 1.27 @@ -29,10 +29,6 @@ shorthand="xpath-processor" default-class="org.apache.avalon.excalibur.xml.xpath.XPathProcessorImpl"/> - <role name="org.apache.cocoon.components.browser.Browser" - shorthand="browser" - default-class="org.apache.cocoon.components.browser.BrowserImpl"/> - <!-- Stores: --> <role name="org.apache.excalibur.store.Store" @@ -52,6 +48,10 @@ <role name="org.apache.cocoon.Processor" shorthand="processor"/> --> + <role name="org.apache.cocoon.components.browser.Browser" + shorthand="browser" + default-class="org.apache.cocoon.components.browser.BrowserImpl"/> + <role name="org.apache.cocoon.components.deli.Deli" shorthand="deli"/> @@ -134,6 +134,10 @@ <role name="org.apache.cocoon.components.xscript.XScriptManager" shorthand="xscript" default-class="org.apache.cocoon.components.xscript.XScriptManagerImpl"/> + + <role name="org.apache.cocoon.caching.Cache" + shorthand="cache" + default-class="org.apache.cocoon.caching.impl.CacheImpl"/> <role name="org.apache.cocoon.components.pipeline.StreamPipeline" shorthand="stream-pipeline" 1.2 +2 -1 xml-cocoon2/src/java/org/apache/cocoon/caching/CacheableProcessingComponent.java Index: CacheableProcessingComponent.java =================================================================== RCS file: /home/cvs/xml-cocoon2/src/java/org/apache/cocoon/caching/CacheableProcessingComponent.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- CacheableProcessingComponent.java 3 May 2002 11:55:05 -0000 1.1 +++ CacheableProcessingComponent.java 6 May 2002 13:22:31 -0000 1.2 @@ -57,8 +57,9 @@ * * This interface deprecates the org.apache.cocoon.caching.Cacheable interface! * + * @since @next-version@ * @author <a href="mailto:[EMAIL PROTECTED]">Carsten Ziegeler</a> - * @version CVS $Id: CacheableProcessingComponent.java,v 1.1 2002/05/03 11:55:05 cziegeler Exp $ + * @version CVS $Id: CacheableProcessingComponent.java,v 1.2 2002/05/06 13:22:31 cziegeler Exp $ */ public interface CacheableProcessingComponent { 1.2 +2 -1 xml-cocoon2/src/java/org/apache/cocoon/caching/CachedResponse.java Index: CachedResponse.java =================================================================== RCS file: /home/cvs/xml-cocoon2/src/java/org/apache/cocoon/caching/CachedResponse.java,v retrieving revision 1.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- CachedResponse.java 3 May 2002 15:31:28 -0000 1.1 +++ CachedResponse.java 6 May 2002 13:22:31 -0000 1.2 @@ -59,8 +59,9 @@ * This class replaces the <code>CachedEventObject</code> and the * <code>CachedStreamObject</code>. * + * @since @next-version@ * @author <a href="mailto:[EMAIL PROTECTED]">Carsten Ziegeler</a> - * @version CVS $Id: CachedResponse.java,v 1.1 2002/05/03 15:31:28 cziegeler Exp $ + * @version CVS $Id: CachedResponse.java,v 1.2 2002/05/06 13:22:31 cziegeler Exp $ */ public final class CachedResponse implements java.io.Serializable { 1.4 +2 -1 xml-cocoon2/src/java/org/apache/cocoon/caching/SourceCacheValidity.java Index: SourceCacheValidity.java =================================================================== RCS file: /home/cvs/xml-cocoon2/src/java/org/apache/cocoon/caching/SourceCacheValidity.java,v retrieving revision 1.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- SourceCacheValidity.java 21 Apr 2002 17:29:50 -0000 1.3 +++ SourceCacheValidity.java 6 May 2002 13:22:31 -0000 1.4 @@ -56,8 +56,9 @@ * A CacheValidity object wrapping the Avalon Excalibur * <code>SourceValidity</code> object. * + * @since @next-version@ * @author <a href="mailto:[EMAIL PROTECTED]">Carsten Ziegeler</a> - * @version CVS $Id: SourceCacheValidity.java,v 1.3 2002/04/21 17:29:50 vgritsenko Exp $ + * @version CVS $Id: SourceCacheValidity.java,v 1.4 2002/05/06 13:22:31 cziegeler Exp $ */ public final class SourceCacheValidity implements CacheValidity { 1.1 xml-cocoon2/src/java/org/apache/cocoon/caching/Cache.java Index: Cache.java =================================================================== /* ============================================================================ The Apache Software License, Version 1.1 ============================================================================ Copyright (C) 1999-2002 The Apache Software Foundation. All rights reserved. Redistribution and use in source and binary forms, with or without modifica- tion, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 3. The end-user documentation included with the redistribution, if any, must include the following acknowledgment: "This product includes software developed by the Apache Software Foundation (http://www.apache.org/)." Alternately, this acknowledgment may appear in the software itself, if and wherever such third-party acknowledgments normally appear. 4. The names "Apache Cocoon" and "Apache Software Foundation" must not be used to endorse or promote products derived from this software without prior written permission. For written permission, please contact [EMAIL PROTECTED] 5. Products derived from this software may not be called "Apache", nor may "Apache" appear in their name, without prior written permission of the Apache Software Foundation. THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU- DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. This software consists of voluntary contributions made by many individuals on behalf of the Apache Software Foundation and was originally created by Stefano Mazzocchi <[EMAIL PROTECTED]>. For more information on the Apache Software Foundation, please see <http://www.apache.org/>. */ package org.apache.cocoon.caching; import org.apache.avalon.framework.component.Component; import org.apache.cocoon.ProcessingException; import java.util.Map; /** * This is the Cocoon cache. This component is responsible for storing * and retrieving cached responses. It can be used to monitor the cache * or the investigate which responses are cached etc. * This interface will grow! * * @since @next-version@ * @author <a href="mailto:[EMAIL PROTECTED]">Carsten Ziegeler</a> * @version CVS $Id: Cache.java,v 1.1 2002/05/06 13:22:31 cziegeler Exp $ */ public interface Cache extends Component { /** The Avalon Role **/ String ROLE = Cache.class.getName(); /** * Store a cached response * @param objectModel all information about the request * @param key the key used by the caching algorithm to identify the * request * @param response the cached response */ void store(Map objectModel, String key, CachedResponse response) throws ProcessingException; /** * Get a cached response. * If it is not available <code>null</code> is returned. * @param key the key used by the caching algorithm to identify the * request */ CachedResponse get(String key); /** * Remove a cached response. * If it is not available no operation is performed. * @param key the key used by the caching algorithm to identify the * request */ void remove(String key); } 1.1 xml-cocoon2/src/java/org/apache/cocoon/caching/CacheValidityToSourceValidity.java Index: CacheValidityToSourceValidity.java =================================================================== /* ============================================================================ The Apache Software License, Version 1.1 ============================================================================ Copyright (C) 1999-2002 The Apache Software Foundation. All rights reserved. Redistribution and use in source and binary forms, with or without modifica- tion, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 3. The end-user documentation included with the redistribution, if any, must include the following acknowledgment: "This product includes software developed by the Apache Software Foundation (http://www.apache.org/)." Alternately, this acknowledgment may appear in the software itself, if and wherever such third-party acknowledgments normally appear. 4. The names "Apache Cocoon" and "Apache Software Foundation" must not be used to endorse or promote products derived from this software without prior written permission. For written permission, please contact [EMAIL PROTECTED] 5. Products derived from this software may not be called "Apache", nor may "Apache" appear in their name, without prior written permission of the Apache Software Foundation. THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU- DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. This software consists of voluntary contributions made by many individuals on behalf of the Apache Software Foundation and was originally created by Stefano Mazzocchi <[EMAIL PROTECTED]>. For more information on the Apache Software Foundation, please see <http://www.apache.org/>. */ package org.apache.cocoon.caching; import org.apache.excalibur.source.SourceValidity; /** * A CacheValidity object wrapping the Avalon Excalibur * <code>SourceValidity</code> object. * * @author <a href="mailto:[EMAIL PROTECTED]">Carsten Ziegeler</a> * @version CVS $Id: CacheValidityToSourceValidity.java,v 1.1 2002/05/06 13:22:31 cziegeler Exp $ */ public final class CacheValidityToSourceValidity implements SourceValidity { protected CacheValidity cacheValidity; /** * Constructor */ public CacheValidityToSourceValidity(CacheValidity validity) { this.cacheValidity = validity; } /** * Check if the component is still valid. * If <code>false</code> is returned the isValid(SourceValidity) must be * called afterwards! */ public boolean isValid() { return false; } /** * Check if the component is still valid. * This is only true, if the incoming Validity is of the same * type and has the same values. * The invocation order is that the isValid method of the * old Validity object is called with the new one as a parameter */ public boolean isValid( SourceValidity newValidity ) { if (newValidity instanceof CacheValidity) { return this.cacheValidity.isValid((CacheValidity)newValidity); } return false; } public String toString() { return "Cache Validity To Source Validity[" + this.cacheValidity + ']'; } } 1.1 xml-cocoon2/src/java/org/apache/cocoon/caching/impl/CacheImpl.java Index: CacheImpl.java =================================================================== /* ============================================================================ The Apache Software License, Version 1.1 ============================================================================ Copyright (C) 1999-2002 The Apache Software Foundation. All rights reserved. Redistribution and use in source and binary forms, with or without modifica- tion, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 3. The end-user documentation included with the redistribution, if any, must include the following acknowledgment: "This product includes software developed by the Apache Software Foundation (http://www.apache.org/)." Alternately, this acknowledgment may appear in the software itself, if and wherever such third-party acknowledgments normally appear. 4. The names "Apache Cocoon" and "Apache Software Foundation" must not be used to endorse or promote products derived from this software without prior written permission. For written permission, please contact [EMAIL PROTECTED] 5. Products derived from this software may not be called "Apache", nor may "Apache" appear in their name, without prior written permission of the Apache Software Foundation. THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU- DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. This software consists of voluntary contributions made by many individuals on behalf of the Apache Software Foundation and was originally created by Stefano Mazzocchi <[EMAIL PROTECTED]>. For more information on the Apache Software Foundation, please see <http://www.apache.org/>. */ package org.apache.cocoon.caching.impl; import org.apache.avalon.framework.activity.Disposable; import org.apache.avalon.framework.component.Composable; import org.apache.avalon.framework.component.ComponentException; import org.apache.avalon.framework.component.ComponentManager; import org.apache.avalon.framework.logger.AbstractLogEnabled; import org.apache.avalon.framework.thread.ThreadSafe; import org.apache.cocoon.ProcessingException; import org.apache.cocoon.caching.Cache; import org.apache.cocoon.caching.CachedResponse; import org.apache.excalibur.store.Store; import java.io.IOException; import java.util.Map; /** * This is the Cocoon cache. This component is responsible for storing * and retrieving cached responses. It can be used to monitor the cache * or the investigate which responses are cached etc. * This component will grow! * * @since @next-version@ * @author <a href="mailto:[EMAIL PROTECTED]">Carsten Ziegeler</a> * @version CVS $Id: CacheImpl.java,v 1.1 2002/05/06 13:22:31 cziegeler Exp $ */ public class CacheImpl extends AbstractLogEnabled implements Cache, ThreadSafe, Composable, Disposable { /** The store containing the cached responses */ protected Store store; /** The component manager */ protected ComponentManager manager; /** * Composable Interface */ public void compose (ComponentManager manager) throws ComponentException { this.manager = manager; this.store = (Store)this.manager.lookup(Store.TRANSIENT_STORE); } /** * Disposable Interface */ public void dispose() { this.manager.release(this.store); this.store = null; this.manager = null; } /** * Store a cached response * @param objectModel all information about the request * @param key the key used by the caching algorithm to identify the * request * @param response the cached response */ public void store(Map objectModel, String key, CachedResponse response) throws ProcessingException { try { this.store.store(key, response); } catch (IOException ioe) { throw new ProcessingException("Unable to cache response.", ioe); } } /** * Get a cached response. * If it is not available <code>null</code> is returned. * @param key the key used by the caching algorithm to identify the * request */ public CachedResponse get(String key) { return (CachedResponse)this.store.get(key); } /** * Remove a cached response. * If it is not available no operation is performed. * @param key the key used by the caching algorithm to identify the * request */ public void remove(String key) { this.store.remove(key); } } 1.5 +23 -13 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.4 retrieving revision 1.5 diff -u -r1.4 -r1.5 --- CachingProcessingPipeline.java 6 May 2002 12:28:50 -0000 1.4 +++ CachingProcessingPipeline.java 6 May 2002 13:22:31 -0000 1.5 @@ -57,16 +57,17 @@ import org.apache.avalon.framework.parameters.Parameters; import org.apache.cocoon.ConnectionResetException; import org.apache.cocoon.ProcessingException; +import org.apache.cocoon.caching.Cache; import org.apache.cocoon.caching.Cacheable; import org.apache.cocoon.caching.CacheableProcessingComponent; import org.apache.cocoon.caching.CachedResponse; +import org.apache.cocoon.caching.CacheValidityToSourceValidity; import org.apache.cocoon.caching.CachingOutputStream; import org.apache.cocoon.components.pipeline.AbstractProcessingPipeline; import org.apache.cocoon.components.sax.XMLDeserializer; import org.apache.cocoon.components.sax.XMLSerializer; import org.apache.cocoon.components.sax.XMLTeePipe; import org.apache.cocoon.components.saxconnector.SAXConnector; -import org.apache.excalibur.store.Store; import org.apache.cocoon.environment.Environment; import org.apache.cocoon.transformation.Transformer; import org.apache.cocoon.xml.XMLConsumer; @@ -87,14 +88,14 @@ * * * @author <a href="mailto:[EMAIL PROTECTED]">Carsten Ziegeler</a> - * @version CVS $Id: CachingProcessingPipeline.java,v 1.4 2002/05/06 12:28:50 cziegeler Exp $ + * @version CVS $Id: CachingProcessingPipeline.java,v 1.5 2002/05/06 13:22:31 cziegeler Exp $ */ public class CachingProcessingPipeline extends AbstractProcessingPipeline implements Disposable { - /** The store for the cached response (or part of the response) */ - private Store cache; + /** The Cache storing the cached response (or part of the response) */ + private Cache cache; /** The role name of the generator */ private String generatorRole; @@ -120,7 +121,7 @@ public void compose (ComponentManager manager) throws ComponentException { super.compose(manager); - this.cache = (Store)this.manager.lookup(Store.TRANSIENT_STORE); + this.cache = (Cache)this.manager.lookup(Cache.ROLE); } /** @@ -277,7 +278,6 @@ } if (key != 0) { - // CacheValidity validity = ((Cacheable)this.generator).generateValidity(); this.pipelineCacheKey = new StringBuffer(); this.pipelineCacheKey.append("PCK:CCK:1-") .append(this.generatorRole).append('-') @@ -433,7 +433,7 @@ .append(readerKey); // now we have the key to get the cached object - CachedResponse cachedObject = (CachedResponse)this.cache.get(pcKey); + CachedResponse cachedObject = (CachedResponse)this.cache.get(pcKey.toString()); if (cachedObject != null) { if (this.getLogger().isDebugEnabled()) { @@ -450,7 +450,9 @@ if (isCacheableProcessingComponent) { readerValidity = ((CacheableProcessingComponent)this.reader).generateValidity(); } else { - // FIXME: wrap it + readerValidity = new CacheValidityToSourceValidity( + ((Cacheable)this.reader).generateValidity() + ); } valid = cachedValidity.isValid(readerValidity); } @@ -470,7 +472,7 @@ this.getLogger().debug("Cached content is invalid for '" + environment.getURI() + "'."); } // remove invalid cached object - this.cache.remove(pcKey); + this.cache.remove(pcKey.toString()); } } } @@ -485,7 +487,9 @@ if (isCacheableProcessingComponent) { readerValidity = ((CacheableProcessingComponent)this.reader).generateValidity(); } else { - // FIXME: wrap it + readerValidity = new CacheValidityToSourceValidity( + ((Cacheable)this.reader).generateValidity() + ); } } outputStream = new CachingOutputStream(outputStream); @@ -495,9 +499,12 @@ // store the response if (pcKey != null) { - this.cache.store(pcKey, + this.cache.store( + environment.getObjectModel(), + pcKey.toString(), new CachedResponse( new SourceValidity[] {readerValidity}, - ((CachingOutputStream)outputStream).getContent())); + ((CachingOutputStream)outputStream).getContent()) + ); } } } catch ( SocketException se ) { @@ -526,7 +533,10 @@ return true; } - + protected boolean processXMLPipeline(Environment environment) + throws ProcessingException { + return super.processXMLPipeline( environment ); + } /** * Process the request. public boolean process(Environment environment)
---------------------------------------------------------------------- In case of troubles, e-mail: [EMAIL PROTECTED] To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]