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 NewAbstractCachingProcessingPipeline.java
Date Fri, 10 Jan 2003 10:44:43 GMT
cziegeler    2003/01/10 02:44:43

  Modified:    src/java/org/apache/cocoon/components/pipeline
                        ProcessingPipeline.java
                        AbstractProcessingPipeline.java
               src/java/org/apache/cocoon/components/pipeline/impl
                        NewAbstractCachingProcessingPipeline.java
  Log:
  This should work real soon now
  
  Revision  Changes    Path
  1.14      +5 -1      xml-cocoon2/src/java/org/apache/cocoon/components/pipeline/ProcessingPipeline.java
  
  Index: ProcessingPipeline.java
  ===================================================================
  RCS file: /home/cvs/xml-cocoon2/src/java/org/apache/cocoon/components/pipeline/ProcessingPipeline.java,v
  retrieving revision 1.13
  retrieving revision 1.14
  diff -u -r1.13 -r1.14
  --- ProcessingPipeline.java	9 Jan 2003 11:27:59 -0000	1.13
  +++ ProcessingPipeline.java	10 Jan 2003 10:44:43 -0000	1.14
  @@ -182,4 +182,8 @@
        * Otherwise return <code>null</code>
        */
       SourceValidity[] getValiditiesForEventPipeline();
  +
  +    boolean isInternalPipelineCacheable();
  +    
  +    SourceValidity getValidityForInternalPipeline(int index);
   }
  
  
  
  1.28      +9 -1      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.27
  retrieving revision 1.28
  diff -u -r1.27 -r1.28
  --- AbstractProcessingPipeline.java	9 Jan 2003 11:31:09 -0000	1.27
  +++ AbstractProcessingPipeline.java	10 Jan 2003 10:44:43 -0000	1.28
  @@ -756,4 +756,12 @@
           return System.currentTimeMillis() + expires;
       }
   
  +    public boolean isInternalPipelineCacheable() {
  +        return false;
  +    }
  +    
  +    public SourceValidity getValidityForInternalPipeline(int index) {
  +        return null;
  +    }
  +
   }
  
  
  
  1.2       +106 -95   xml-cocoon2/src/java/org/apache/cocoon/components/pipeline/impl/NewAbstractCachingProcessingPipeline.java
  
  Index: NewAbstractCachingProcessingPipeline.java
  ===================================================================
  RCS file: /home/cvs/xml-cocoon2/src/java/org/apache/cocoon/components/pipeline/impl/NewAbstractCachingProcessingPipeline.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- NewAbstractCachingProcessingPipeline.java	10 Jan 2003 07:42:11 -0000	1.1
  +++ NewAbstractCachingProcessingPipeline.java	10 Jan 2003 10:44:43 -0000	1.2
  @@ -115,8 +115,9 @@
       protected PipelineCacheKey fromCacheKey;
       /** This key indicates the response that will get into the cache */
       protected PipelineCacheKey toCacheKey;
  -    /** The validity objects of the generated response */
  -    protected SourceValidity[]   toCacheValidityObjects;
  +    /** The source validities used for caching */
  +    protected SourceValidity[] toCacheSourceValidities;
  +    
       /** The index indicating to the first transformer which is not cacheable */
       protected int firstNotCacheableTransformerIndex;
       /** Cache complete response */
  @@ -128,7 +129,9 @@
   
       /** Smart caching ? */
       protected boolean doSmartCaching;
  -
  +    /** Default setting for smart caching */
  +    protected boolean configuredDoSmartCaching;
  +    
       /**
        * Abstract methods defined in subclasses
        */
  @@ -146,12 +149,20 @@
       }
   
       /**
  +     * Parameterizable Interface - Configuration
  +     */
  +    public void parameterize(Parameters params) {
  +        super.parameterize(params);
  +        this.configuredDoSmartCaching = params.getParameterAsBoolean("smart-caching", true);
  +    }
  +    
  +    /**
        * Setup this component
        */
       public void setup(Parameters params) {
           super.setup(params);
           this.doSmartCaching = params.getParameterAsBoolean("smart-caching",
  -                              this.configuration.getParameterAsBoolean("smart-caching",
true));
  +                                                           this.configuredDoSmartCaching);
       }
   
       /**
  @@ -383,7 +394,7 @@
        */
       protected void validatePipeline(Environment environment)
       throws ProcessingException {
  -        this.cacheCompleteResponse = this.completeResponseIsCached;
  +        this.completeResponseIsCached = this.cacheCompleteResponse;
           this.fromCacheKey = this.toCacheKey.copy();        
           this.firstProcessedTransformerIndex = this.firstNotCacheableTransformerIndex;
   
  @@ -392,7 +403,7 @@
           while (this.fromCacheKey != null && !finished) {
               
               finished = true;
  -            CachedResponse response = this.cache.get( this.fromCacheKey );
  +            final CachedResponse response = this.cache.get( this.fromCacheKey );
   
               // now test validity
               if (response != null) {
  @@ -405,42 +416,21 @@
   
                   boolean responseIsValid = true;
                   boolean responseIsUsable = true;
  -                
  -                this.toCacheValidityObjects = response.getValidityObjects();
  +                SourceValidity[] fromCacheValidityObjects = response.getValidityObjects();
  +
                   int i = 0;
  -                while (responseIsValid && i < this.toCacheValidityObjects.length)
{
  +                while (responseIsValid && i < fromCacheValidityObjects.length)
{
                       boolean isValid = false;
                       // BH check if validities[i] is null, may happen
                       // if exception was thrown due to malformed content
  -                    SourceValidity validity = this.toCacheValidityObjects[i];
  +                    SourceValidity validity = fromCacheValidityObjects[i];
                       int valid = validity != null ? validity.isValid() : -1;
                       if ( valid == 0) { // don't know if valid, make second test
  -                        if (i == 0) {
  -                            // test generator
  -                            if (this.generatorIsCacheableProcessingComponent) {
  -                                validity = ((CacheableProcessingComponent)super.generator).generateValidity();
  -                            } else {
  -                                validity = CacheValidityToSourceValidity.createValidity(((Cacheable)super.generator).generateValidity());
  -                            }
  -                        } else if (i <= this.firstProcessedTransformerIndex) {
  -                            // test transformer
  -                            final Transformer trans =
  -                                (Transformer)super.transformers.get(i-1);
  -                            if (this.transformerIsCacheableProcessingComponent[i-1]) {
  -                                validity = ((CacheableProcessingComponent)trans).generateValidity();
  -                            } else {
  -                                validity = CacheValidityToSourceValidity.createValidity(((Cacheable)trans).generateValidity());
  -                            }
  -                        } else {
  -                            // test serializer
  -                            if (this.serializerIsCacheableProcessingComponent) {
  -                                validity = ((CacheableProcessingComponent)super.serializer).generateValidity();
  -                            } else {
  -                                validity = CacheValidityToSourceValidity.createValidity(((Cacheable)super.serializer).generateValidity());
  -                            }
  -                        }
  +                       
  +                        validity = this.getValidityForInternalPipeline(i);
  +
                           if (validity != null) {
  -                            isValid = this.toCacheValidityObjects[i].isValid( validity
);
  +                            isValid = fromCacheValidityObjects[i].isValid( validity );
                           }
                       } else {
                           isValid = (valid == 1);
  @@ -448,10 +438,9 @@
                       if ( !isValid ) {
                           responseIsValid = false;
                           // update validity
  -                        this.toCacheValidityObjects[i] = validity;
                           if (validity == null)
                               responseIsUsable = false;
  -                    } else {
  +                    } else {                        
                           i++;
                       }
                   }
  @@ -466,6 +455,17 @@
                           this.getLogger().debug("Cached content is invalid for '" + environment.getURI()
+ "'.");
                       }
                       // we are not valid!
  +
  +                    // try a shorter key
  +                    if (i > 0) {
  +                        this.fromCacheKey.removeLastKey();
  +                        if (!this.completeResponseIsCached) {
  +                            this.firstProcessedTransformerIndex--;
  +                        }
  +                    } else {
  +                        this.fromCacheKey = null;
  +                    }
  +
                       this.completeResponseIsCached = false;
                       finished = false;
   
  @@ -473,7 +473,7 @@
                           // we could not compare, because we got no
                           // validity object, so shorten pipeline key
                           if (i > 0) {
  -                            int deleteCount = this.toCacheValidityObjects.length - i;
  +                            int deleteCount = fromCacheValidityObjects.length - i;
                               if (i > 0 && i <= firstNotCacheableTransformerIndex
+ 1) {
                                   this.firstNotCacheableTransformerIndex = i-1;
                               }
  @@ -489,13 +489,6 @@
                           // the entry is invalid, remove it
                           this.cache.remove( this.fromCacheKey );
                       }
  -                    // try a shorter key
  -                    if (i > 0) {
  -                        this.fromCacheKey.removeLastKey();
  -                        this.firstProcessedTransformerIndex--;
  -                    } else {
  -                        this.fromCacheKey = null;
  -                    }
                   }
               } else {
                   
  @@ -506,6 +499,7 @@
                           "' using key: " +  this.fromCacheKey
                       );
                   }
  +
                   if (!this.doSmartCaching) {
                       // try a shorter key
                       if (this.fromCacheKey.size() > 1) {
  @@ -516,15 +510,12 @@
                           finished = false;
                       } else {
                           this.fromCacheKey = null;
  -                        finished = true;
                       }
  -                    this.completeResponseIsCached = false;
                   } else {
                       // stop on longest key for smart caching
  -                    finished = true;
  -                    this.completeResponseIsCached = false;
                       this.fromCacheKey = null;
                   }
  +                this.completeResponseIsCached = false;
               }
           }
   
  @@ -555,61 +546,36 @@
               if (this.fromCacheKey == null 
                   || this.fromCacheKey.size() < this.toCacheKey.size()) {
                   
  -                this.toCacheValidityObjects = new SourceValidity[this.toCacheKey.size()];
  -                int start = 0;
  -                if (this.fromCacheKey != null) {
  -                    start = this.fromCacheKey.size();
  -                    for(int i=0; i<start;i++) {
  -                        // THIS CAN BE NULL, RIGHT??
  -                        //this.pipelineValidityObjects[i] = cachedValidityObjects[i];
  -                    }
  -                }
  -                int len = this.toCacheValidityObjects.length;
  -                int i = start;
  +                this.toCacheSourceValidities = new SourceValidity[this.toCacheKey.size()];
  +                int len = this.toCacheSourceValidities.length;
  +                int i = 0;
                   while (i < len) {
  -                    final SourceValidity validity;
  -                    if (i == 0) {
  -                        // test generator
  -                        if (generatorIsCacheableProcessingComponent) {
  -                            validity = ((CacheableProcessingComponent)super.generator).generateValidity();
  -                        } else {
  -                            validity = CacheValidityToSourceValidity.createValidity(((Cacheable)super.generator).generateValidity());
  -                        }
  -                    } else if (i <= firstNotCacheableTransformerIndex) {
  -                        // test transformer
  -                        final Transformer trans =
  -                            (Transformer)super.transformers.get(i-1);
  -                        if (transformerIsCacheableProcessingComponent[i-1]) {
  -                            validity = ((CacheableProcessingComponent)trans).generateValidity();
  -                        } else {
  -                            validity = CacheValidityToSourceValidity.createValidity(((Cacheable)trans).generateValidity());
  -                        }
  -                    } else {
  -                        // test serializer
  -                        if (serializerIsCacheableProcessingComponent) {
  -                            validity = ((CacheableProcessingComponent)super.serializer).generateValidity();
  -                        } else {
  -                            validity = CacheValidityToSourceValidity.createValidity(((Cacheable)super.serializer).generateValidity());
  -                        }
  -                    }
  +                    final SourceValidity validity = this.getValidityForInternalPipeline(i);
  +
                       if (validity == null) {
                           if (i > 0 && i > this.fromCacheKey.size()) {
                               // shorten key
  -                            for(int m=i; m < this.toCacheValidityObjects.length; m++)
{
  +                            for(int m=i; m < this.toCacheSourceValidities.length; m++)
{
                                   this.toCacheKey.removeLastKey();
  +                                if (!this.cacheCompleteResponse) {
  +                                    this.firstNotCacheableTransformerIndex--;
  +                                }
  +                                this.cacheCompleteResponse = false;
                               }
                               SourceValidity[] copy = new SourceValidity[i];
  -                            System.arraycopy(this.toCacheValidityObjects, 0,
  +                            System.arraycopy(this.toCacheSourceValidities, 0,
                                                copy, 0, copy.length);
  -                            this.toCacheValidityObjects = copy;
  -                            len = this.toCacheValidityObjects.length;
  +                            this.toCacheSourceValidities = copy;
  +                            len = this.toCacheSourceValidities.length;
                           } else {
  +                            // caching is not possible!
                               this.toCacheKey = null;
  -                            this.toCacheValidityObjects = null;
  +                            this.toCacheSourceValidities = null;
  +                            this.cacheCompleteResponse = false;
                               len = 0;
                           }
                       } else {
  -                        this.toCacheValidityObjects[i] = validity;
  +                        this.toCacheSourceValidities[i] = validity;
                       }
                       i++;
                   }
  @@ -796,12 +762,56 @@
       public SourceValidity[] getValiditiesForEventPipeline() {
           if (!this.completeResponseIsCached
                   && this.firstNotCacheableTransformerIndex == super.transformers.size())
{
  -            return this.toCacheValidityObjects;
  +            return null;
           }
           return null;
       }
   
       /**
  +     * 
  +     * @see org.apache.cocoon.components.pipeline.ProcessingPipeline#isInternalPipelineCacheable()
  +     */
  +    public boolean isInternalPipelineCacheable() {
  +        if (!this.completeResponseIsCached
  +             && this.firstNotCacheableTransformerIndex == super.transformers.size())
{
  +            return true;
  +        }
  +        return false;
  +    }
  +    
  +    /**
  +     * 
  +     * @see org.apache.cocoon.components.pipeline.ProcessingPipeline#getValidityForInternalPipeline(int)
  +     */
  +    public SourceValidity getValidityForInternalPipeline(int index) {
  +        final SourceValidity validity;
  +        if (index == 0) {
  +            // test generator
  +            if (this.generatorIsCacheableProcessingComponent) {
  +                validity = ((CacheableProcessingComponent)super.generator).generateValidity();
  +            } else {
  +                validity = CacheValidityToSourceValidity.createValidity(((Cacheable)super.generator).generateValidity());
  +            }
  +        } else if (index <= firstNotCacheableTransformerIndex) {
  +            // test transformer
  +            final Transformer trans = (Transformer)super.transformers.get(index-1);
  +            if (this.transformerIsCacheableProcessingComponent[index-1]) {
  +                validity = ((CacheableProcessingComponent)trans).generateValidity();
  +            } else {
  +                validity = CacheValidityToSourceValidity.createValidity(((Cacheable)trans).generateValidity());
  +            }
  +        } else {
  +            // test serializer
  +            if (this.serializerIsCacheableProcessingComponent) {
  +                validity = ((CacheableProcessingComponent)super.serializer).generateValidity();
  +            } else {
  +                validity = CacheValidityToSourceValidity.createValidity(((Cacheable)super.serializer).generateValidity());
  +            }
  +        }
  +        return validity;
  +    }
  +    
  +    /**
        * Recyclable Interface
        */
       public void recycle() {
  @@ -819,7 +829,6 @@
           this.readerRole = null;
   
           this.toCacheKey = null;
  -        this.toCacheValidityObjects = null;
           this.cachedResponse = null;
           
           this.transformerIsCacheableProcessingComponent = null;
  @@ -830,7 +839,9 @@
        * Disposable Interface
        */
       public void dispose() {
  -        this.manager.release(this.cache);
  +        if ( null != this.manager ) {
  +            this.manager.release(this.cache);
  +        }
           this.cache = null;
           this.manager = 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