cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cziege...@apache.org
Subject cvs commit: xml-cocoon2/src/java/org/apache/cocoon/components/pipeline/impl CachingProcessingPipeline.java
Date Tue, 28 May 2002 08:42:12 GMT
cziegeler    02/05/28 01:42:12

  Modified:    src/java/org/apache/cocoon/caching PipelineCacheKey.java
               src/java/org/apache/cocoon/components/pipeline/impl
                        CachingProcessingPipeline.java
  Log:
  Changed key from String to long
  
  Revision  Changes    Path
  1.9       +20 -4     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.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- PipelineCacheKey.java	28 May 2002 08:25:00 -0000	1.8
  +++ PipelineCacheKey.java	28 May 2002 08:42:12 -0000	1.9
  @@ -58,7 +58,7 @@
    * or more {@link ComponentCacheKey}s.
    *
    * @author <a href="mailto:cziegeler@apache.org">Carsten Ziegeler</a>
  - * @version CVS $Id: PipelineCacheKey.java,v 1.8 2002/05/28 08:25:00 cziegeler Exp $
  + * @version CVS $Id: PipelineCacheKey.java,v 1.9 2002/05/28 08:42:12 cziegeler Exp $
    */
   public final class PipelineCacheKey
       implements java.io.Serializable {
  @@ -73,17 +73,30 @@
           this.keys = new ArrayList(4);
       }
   
  -    private StringBuffer value;
  -    private String toStringValue;
  -
  +    /**
  +     * Add a key
  +     */
       public void addKey(ComponentCacheKey key) {
           this.keys.add(key);
       }
   
  +    /**
  +     * Remove the last key
  +     */
       public void removeLastKey() {
           this.keys.remove(this.keys.size()-1);
       }
   
  +    /**
  +     * Return the number of keys
  +     */
  +    public int size() {
  +        return this.keys.size();
  +    }
  +
  +    /**
  +     * Compare
  +     */
       public boolean equals(Object object) {
           if (object instanceof PipelineCacheKey) {
               PipelineCacheKey pck = (PipelineCacheKey)object;
  @@ -101,6 +114,9 @@
           return false;
       }
   
  +    /**
  +     * Generate a hash code
  +     */
       public int hashCode() {
           // FIXME (CZ) we need a good one here...
           return this.keys.hashCode();
  
  
  
  1.15      +59 -9     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.14
  retrieving revision 1.15
  diff -u -r1.14 -r1.15
  --- CachingProcessingPipeline.java	28 May 2002 08:25:00 -0000	1.14
  +++ CachingProcessingPipeline.java	28 May 2002 08:42:12 -0000	1.15
  @@ -92,7 +92,7 @@
    *
    * @since @next-version@
    * @author <a href="mailto:cziegeler@apache.org">Carsten Ziegeler</a>
  - * @version CVS $Id: CachingProcessingPipeline.java,v 1.14 2002/05/28 08:25:00 cziegeler
Exp $
  + * @version CVS $Id: CachingProcessingPipeline.java,v 1.15 2002/05/28 08:42:12 cziegeler
Exp $
    */
   public class CachingProcessingPipeline
   extends AbstractProcessingPipeline
  @@ -113,8 +113,6 @@
       /** The role name of the reader */
       protected String readerRole;
   
  -    /** The key to store the cached response */
  -    protected PipelineCacheKey   pipelineCacheKey;
       /** The index indicating to the first transformer which is not cacheable */
       protected int firstNotCacheableTransformerIndex;
       /** The deserializer */
  @@ -129,6 +127,12 @@
       /** The cached byte stream */
       protected byte[]           cachedResponse;
   
  +    /** The key to store the generated response */
  +    protected PipelineCacheKey   pipelineCacheKey;
  +    /** The validity objects of the generated response */
  +    protected SourceValidity[]   pipelineValidityObjects;
  +
  +
       /**
        * Composable Interface
        */
  @@ -405,18 +409,19 @@
                       }
                       if ( isValid ) i++;
                   }
  -                // FIXME
  +
                   if ( responseIsValid ) {
                       // we are valid, ok that's it
                       this.cachedValidityObjects = validities;
                   } else {
  +                    // we are not valid!
  +                    this.completeResponseIsCached = false;
                       finished = false;
                       this.cachedResponse = null;
   
                       if (!responseIsUsable) {
  -                        // FIXME (CZ) : check this
  -                        // we can try a shorter key now...
  -                        // but we don't invalidate the current entry!
  +                        // we could compare, because we got no
  +                        // validity object, so shorten pipeline key
                           if (i > 0) {
                               int deleteCount = validities.length - i;
                               if (i > 0 && i <= firstNotCacheableTransformerIndex
+ 1) {
  @@ -430,10 +435,10 @@
                               processingPipelineKey = null;
                           }
                       } else {
  -                        // invalidate entry
  +                        // the entry is invalid, remove it
                           this.cache.remove( cachedPipelineKey );
  -                        // FIXME(CZ) let's get the rest of the validities now
                       }
  +                    // try a shorter key
                       if (i > 0) {
                           cachedPipelineKey.removeLastKey();
                       } else {
  @@ -442,6 +447,50 @@
                   }
               }
           }
  +
  +        // now generate validity objects for the new response
  +        if (processingPipelineKey != null) {
  +            if (cachedPipelineKey == null ||
  +                cachedPipelineKey.size() < processingPipelineKey.size()) {
  +                this.pipelineCacheKey = processingPipelineKey;
  +                this.pipelineValidityObjects = new SourceValidity[processingPipelineKey.size()];
  +                int start = 0;
  +                if (cachedPipelineKey != null) {
  +                    start = cachedPipelineKey.size();
  +                    for(int i=0; i<start;i++) {
  +                        this.pipelineValidityObjects[i] = this.cachedValidityObjects[i];
  +                    }
  +                }
  +                for(int i=start; i < this.pipelineValidityObjects.length; i++) {
  +                    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 <= firstNotCacheableTransformerIndex + 1) {
  +                        // 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 {
  +                        // test serializer
  +                        if (serializerIsCacheableProcessingComponent) {
  +                            validity = ((CacheableProcessingComponent)super.serializer).generateValidity();
  +                        } else {
  +                            validity = new CacheValidityToSourceValidity(((Cacheable)super.serializer).generateValidity());
  +                        }
  +                    }
  +                    this.pipelineValidityObjects[i] = validity;
  +                }
  +            }
  +        }
       }
   
       /**
  @@ -670,6 +719,7 @@
           this.readerRole = null;
   
           this.pipelineCacheKey = null;
  +        this.pipelineValidityObjects = null;
           this.cachedResponse = null;
           this.cachedValidityObjects = null;
       }
  
  
  

----------------------------------------------------------------------
In case of troubles, e-mail:     webmaster@xml.apache.org
To unsubscribe, e-mail:          cocoon-cvs-unsubscribe@xml.apache.org
For additional commands, e-mail: cocoon-cvs-help@xml.apache.org


Mime
View raw message