cziegeler    2002/08/13 02:58:31

  Modified:    src/java/org/apache/cocoon/components/pipeline/impl
                        AbstractCachingProcessingPipeline.java
                        CachingPointProcessingPipeline.java
                        CachingProcessingPipeline.java
  Log:
  Applied FIX Cachable Readers bug with caching-point
  PR: 11633
  Submitted by: [EMAIL PROTECTED] (Michael Melhem)
  
  Revision  Changes    Path
  1.4       +147 -17   
xml-cocoon2/src/java/org/apache/cocoon/components/pipeline/impl/AbstractCachingProcessingPipeline.java
  
  Index: AbstractCachingProcessingPipeline.java
  ===================================================================
  RCS file: 
/home/cvs/xml-cocoon2/src/java/org/apache/cocoon/components/pipeline/impl/AbstractCachingProcessingPipeline.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- AbstractCachingProcessingPipeline.java    9 Aug 2002 09:26:19 -0000       1.3
  +++ AbstractCachingProcessingPipeline.java    13 Aug 2002 09:58:30 -0000      1.4
  @@ -1,36 +1,36 @@
   /*
  - 
  +
    ============================================================================
                      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
  @@ -41,12 +41,12 @@
    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.components.pipeline.impl;
   
  @@ -84,7 +84,7 @@
   
   /**
    * This is the base class for all caching pipeline implementations.
  - * 
  + *
    *
    * @since 2.1
    * @author <a href="mailto:[EMAIL PROTECTED]";>Carsten Ziegeler</a>
  @@ -255,7 +255,7 @@
                           this.generator.generate();
                       }
                   }
  -             
  +
                   //
                   // Now that we have processed the pipeline,
                   // we do the actual caching
  @@ -574,15 +574,145 @@
       throws ProcessingException {
           if ( this.pipelineCacheKey == null && this.cachedResponse == null) {
               super.connectPipeline( environment );
  -         return;
  +            return;
           } else if (this.completeResponseIsCached) {
               // do nothing
               return;
           } else {
  -             this.connectCachingPipeline(environment);
  -     }
  +            this.connectCachingPipeline(environment);
  +        }
       }
   
  +    /** Process the pipeline using a reader.
  +     * @throws ProcessingException if an error occurs
  +     */
  +    protected boolean processReader(Environment environment)
  +    throws ProcessingException {
  +        try {
  +            boolean usedCache = false;
  +            OutputStream outputStream = environment.getOutputStream();
  +            SourceValidity readerValidity = null;
  +            PipelineCacheKey pcKey = null;
  +
  +            // test if reader is cacheable
  +            Serializable readerKey = null;
  +            boolean isCacheableProcessingComponent = false;
  +            if (super.reader instanceof CacheableProcessingComponent) {
  +                readerKey = 
((CacheableProcessingComponent)super.reader).generateKey();
  +                isCacheableProcessingComponent = true;
  +            } else if (super.reader instanceof Cacheable) {
  +                readerKey = new Long(((Cacheable)super.reader).generateKey());
  +            }
  +
  +            if ( readerKey != null) {
  +                // response is cacheable, build the key
  +                pcKey = new PipelineCacheKey();
  +                pcKey.addKey(new 
ComponentCacheKey(ComponentCacheKey.ComponentType_Reader,
  +                                                   this.readerRole,
  +                                                   readerKey)
  +                            );
  +
  +                // now we have the key to get the cached object
  +                CachedResponse cachedObject = (CachedResponse)this.cache.get( pcKey 
);
  +
  +                if (cachedObject != null) {
  +                    if (this.getLogger().isDebugEnabled()) {
  +                        this.getLogger().debug("Found cached response for '" + 
environment.getURI() + "'.");
  +                    }
  +                    SourceValidity[] validities = cachedObject.getValidityObjects();
  +                    if (validities == null || validities.length != 1) {
  +                        throw new ProcessingException("Cached response is not 
correct.");
  +                    }
  +                    SourceValidity cachedValidity = validities[0];
  +                    int result = cachedValidity.isValid();
  +                    boolean valid = false;
  +                    if ( result == 0 ) {
  +                        // get reader validity and compare
  +                        if (isCacheableProcessingComponent) {
  +                            readerValidity = 
((CacheableProcessingComponent)super.reader).generateValidity();
  +                        } else {
  +                            CacheValidity cv = 
((Cacheable)super.reader).generateValidity();
  +                            if ( cv != null ) {
  +                                readerValidity = 
CacheValidityToSourceValidity.createValidity( cv );
  +                            }
  +                        }
  +                        if (readerValidity != null) {
  +                            valid = cachedValidity.isValid(readerValidity);
  +                        }
  +                    } else {
  +                        valid = (result > 0);
  +                    }
  +
  +                    if (valid) {
  +                        if (this.getLogger().isDebugEnabled()) {
  +                            this.getLogger().debug("Using valid cached content for 
'" + environment.getURI() + "'.");
  +                        }
  +                        byte[] response = cachedObject.getResponse();
  +                        if (response.length > 0) {
  +                            usedCache = true;
  +                            environment.setContentLength(response.length);
  +                            outputStream.write(response);
  +                        }
  +                    } else {
  +                        if (this.getLogger().isDebugEnabled()) {
  +                            this.getLogger().debug("Cached content is invalid for 
'" + environment.getURI() + "'.");
  +                        }
  +                        // remove invalid cached object
  +                        this.cache.remove(pcKey);
  +                    }
  +                }
  +            }
  +
  +            if (!usedCache) {
  +
  +                if ( pcKey != null ) {
  +                    if (this.getLogger().isDebugEnabled()) {
  +                        this.getLogger().debug("Caching content for further 
requests of '" + environment.getURI() + "'.");
  +                    }
  +                    if (readerValidity == null) {
  +                        if (isCacheableProcessingComponent) {
  +                            readerValidity = 
((CacheableProcessingComponent)super.reader).generateValidity();
  +                        } else {
  +                            CacheValidity cv = 
((Cacheable)super.reader).generateValidity();
  +                            if ( cv != null ) {
  +                                readerValidity = 
CacheValidityToSourceValidity.createValidity( cv );
  +                            }
  +                        }
  +                    }
  +                    if (readerValidity != null) {
  +                        outputStream = new CachingOutputStream(outputStream);
  +                    } else {
  +                        pcKey = null;
  +                    }
  +                }
  +
  +                super.processReader( environment, outputStream );
  +
  +                // store the response
  +                if (pcKey != null) {
  +                    this.cache.store(
  +                        environment.getObjectModel(),
  +                        pcKey,
  +                        new CachedResponse( new SourceValidity[] {readerValidity},
  +                                            
((CachingOutputStream)outputStream).getContent())
  +                    );
  +                }
  +            }
  +        } catch ( SocketException se ) {
  +            if (se.getMessage().indexOf("reset") > 0
  +                    || se.getMessage().indexOf("aborted") > 0) {
  +                throw new ConnectionResetException("Connection reset by peer", se);
  +            } else {
  +                throw new ProcessingException("Failed to execute pipeline.", se);
  +            }
  +        } catch ( ProcessingException e ) {
  +            throw e;
  +        } catch ( Exception e ) {
  +            throw new ProcessingException("Failed to execute pipeline.", e);
  +        }
  +
  +        return true;
  +    }
   
   
       /**
  
  
  
  1.3       +61 -75    
xml-cocoon2/src/java/org/apache/cocoon/components/pipeline/impl/CachingPointProcessingPipeline.java
  
  Index: CachingPointProcessingPipeline.java
  ===================================================================
  RCS file: 
/home/cvs/xml-cocoon2/src/java/org/apache/cocoon/components/pipeline/impl/CachingPointProcessingPipeline.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- CachingPointProcessingPipeline.java       9 Aug 2002 07:47:16 -0000       1.2
  +++ CachingPointProcessingPipeline.java       13 Aug 2002 09:58:30 -0000      1.3
  @@ -1,36 +1,36 @@
   /*
  - 
  +
    ============================================================================
                      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
  @@ -41,12 +41,12 @@
    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.components.pipeline.impl;
   
  @@ -99,7 +99,7 @@
   
      /**
       * The <code>CachingPointProcessingPipeline</code> is configurable.
  -    * The autoCachingPoint algorithm can be switced on/off 
  +    * The autoCachingPoint algorithm can be switced on/off
       * in the sitemap.xmap
       */
       public void configure(Configuration config) throws ConfigurationException {
  @@ -114,7 +114,7 @@
               this.autoCachingPoint=true;
               return;
           }
  -         
  +
           if (this.autoCachingPointSwitch.toLowerCase().equals("on")) {
               this.autoCachingPoint=true;
           }
  @@ -129,21 +129,21 @@
        */
       public void addTransformer (String role, String source, Parameters param)
       throws ProcessingException {
  -     super.addTransformer(role, source, param);
  +    super.addTransformer(role, source, param);
   
           // add caching point flag
           // default value is false
           this.isCachePoint.add(new Boolean(this.nextIsCachePoint));
           this.nextIsCachePoint = false;
   
  -     //REVISIT:      Alter the interface to pass an extra "pipeline-hint" paramater 
 
  -     //              and add pipeline-hint check for manual "caching-point"
  +    //REVISIT:       Alter the interface to pass an extra "pipeline-hint" paramater
  +    //               and add pipeline-hint check for manual "caching-point"
   
       }
   
   
       /**
  -     * Determine if the given branch-point 
  +     * Determine if the given branch-point
        * is a caching-point
        *
        * Please Note: this method is used by auto caching-point
  @@ -152,11 +152,11 @@
       public void informBranchPoint() {
   
           if (this.generator == null)
  -             return;
  +        return;
  +
  +    if (!this.autoCachingPoint)
  +        return;
   
  -     if (!this.autoCachingPoint)
  -             return;
  -       
           this.nextIsCachePoint = true;
            if (this.getLogger().isDebugEnabled()) {
              this.getLogger().debug("Informed Pipeline of branch point");
  @@ -165,7 +165,7 @@
   
       /**
        * Cache longest cachable path plus cache points.
  -     */ 
  +     */
       protected void cacheResults(Environment environment, OutputStream os)  throws 
Exception {
   
           if (this.pipelineCacheKey != null) {
  @@ -180,17 +180,17 @@
                                    this.pipelineCacheKey.copy(),
                                    response);
                   //
  -             // Scan back along the pipelineCacheKey for 
  -             // for any cachepoint(s)
  +        // Scan back along the pipelineCacheKey for
  +        // for any cachepoint(s)
                   //
                   this.pipelineCacheKey.removeUntilCachePoint();
   
  -             //
  -             // adjust the validities object
  -             // to reflect the new length of the pipeline cache key.
  -             //
  -             // REVISIT: Is it enough to simply reduce the length of the validities 
array?
  -             //
  +        //
  +        // adjust the validities object
  +        // to reflect the new length of the pipeline cache key.
  +        //
  +        // REVISIT: Is it enough to simply reduce the length of the validities 
array?
  +        //
                   if (this.pipelineCacheKey.size()>0) {
                       SourceValidity[] copy = new 
SourceValidity[this.pipelineCacheKey.size()];
                       System.arraycopy(this.pipelineValidityObjects, 0,
  @@ -208,15 +208,15 @@
                       this.cache.store(environment.getObjectModel(),
                                        this.pipelineCacheKey.copy(),
                                        response);
  -                 
  +
                       if (this.getLogger().isDebugEnabled()) {
  -                        this.getLogger().debug("Caching results for the following 
key: " 
  -                                                     + this.pipelineCacheKey);
  +                        this.getLogger().debug("Caching results for the following 
key: "
  +                            + this.pipelineCacheKey);
                       }
   
  -                 // 
  -                    // Check for further cachepoints 
  -                 //
  +            //
  +                    // Check for further cachepoints
  +            //
                       pipelineCacheKey.removeUntilCachePoint();
                       if (this.pipelineCacheKey.size()==0)
                           // no cachePoint found in key
  @@ -277,22 +277,22 @@
                       while ( itt.hasNext() ) {
                           next = (XMLConsumer) itt.next();
   
  -                     // if we have cacheable transformers,
  -                     // check the tranformers for cachepoints
  +            // if we have cacheable transformers,
  +            // check the tranformers for cachepoints
                           if (cacheableTransformerCount > 0) {
                               if ( (this.isCachePoint.get(currentTransformerIndex) != 
null)  &&
                                       
((Boolean)this.isCachePoint.get(currentTransformerIndex)).booleanValue()) {
  -                                 
  +
                                   cachePointXMLSerializer = ((XMLSerializer)
  -                                                             this.manager.lookup( 
XMLSerializer.ROLE ));
  +                                this.manager.lookup( XMLSerializer.ROLE ));
                                   next = new XMLTeePipe(next, 
cachePointXMLSerializer);
                                   
this.xmlSerializerArray.add(cachePointXMLSerializer);
                               }
                           }
   
  -                     
  -                     // Serializer is not cachable, 
  -                     // but we  have the longest cachable key. Do default longest 
key caching 
  +
  +                // Serializer is not cachable,
  +            // but we  have the longest cachable key. Do default longest key caching
                           if (localXMLSerializer != null) {
                               if (cacheableTransformerCount == 0) {
                                   next = new XMLTeePipe(next, localXMLSerializer);
  @@ -309,16 +309,16 @@
                       }
                       next = super.lastConsumer;
   
  -                
  -                 // if the serializer is not cachable, but all the transformers 
are: 
  -                 // (this is default longest key caching)
  +
  +            // if the serializer is not cachable, but all the transformers are:
  +            // (this is default longest key caching)
                       if (localXMLSerializer != null) {
                           next = new XMLTeePipe(next, localXMLSerializer);
                           this.xmlSerializerArray.add(localXMLSerializer);
                           localXMLSerializer = null;
                       }
  -                 
  -                 // else if the serializer is cachable and has cocoon views
  +
  +            // else if the serializer is cachable and has cocoon views
                       else if ((currentTransformerIndex == 
this.firstNotCacheableTransformerIndex) &&
                               this.nextIsCachePoint) {
                           cachePointXMLSerializer = 
((XMLSerializer)this.manager.lookup( XMLSerializer.ROLE ));
  @@ -339,11 +339,11 @@
                       Iterator itt = this.transformers.iterator();
                       while ( itt.hasNext() ) {
                           next = (XMLConsumer) itt.next();
  -                     
  +
                           if (cacheableTransformerCount >= 
this.firstProcessedTransformerIndex) {
   
  -                         // if we have cacheable transformers left,
  -                         // then check the tranformers for cachepoints
  +                // if we have cacheable transformers left,
  +                // then check the tranformers for cachepoints
                               if (cacheableTransformerCount < 
this.firstNotCacheableTransformerIndex) {
                                   if ( !(prev instanceof XMLDeserializer) &&
                                           
(this.isCachePoint.get(cacheableTransformerCount) != null)  &&
  @@ -354,8 +354,8 @@
                                   }
                               }
   
  -                         // Serializer is not cachable, 
  -                         // but we  have the longest cachable key. Do default 
longest key caching 
  +                    // Serializer is not cachable,
  +                // but we  have the longest cachable key. Do default longest key 
caching
                               if (localXMLSerializer != null && !(prev instanceof 
XMLDeserializer)
                                       && cacheableTransformerCount == 
this.firstNotCacheableTransformerIndex) {
                                   next = new XMLTeePipe(next, localXMLSerializer);
  @@ -368,16 +368,16 @@
                           cacheableTransformerCount++;
                       }
                       next = super.lastConsumer;
  -                 
  -                 //*all* the transformers are cachable, but the serializer is not!! 
this is longest key
  +
  +            //*all* the transformers are cachable, but the serializer is not!! this 
is longest key
                       if (localXMLSerializer != null && !(prev instanceof 
XMLDeserializer)) {
                           next = new XMLTeePipe(next, localXMLSerializer);
                           this.xmlSerializerArray.add(localXMLSerializer);
                           localXMLSerializer = null;
  -                    
  -                 }
  -                 //  else the serializer is cachable but has views
  -                 else if (this.nextIsCachePoint && !(prev instanceof 
XMLDeserializer) &&
  +
  +            }
  +            //       else the serializer is cachable but has views
  +            else if (this.nextIsCachePoint && !(prev instanceof XMLDeserializer) &&
                               cacheableTransformerCount == 
this.firstNotCacheableTransformerIndex) {
                           cachePointXMLSerializer = 
((XMLSerializer)this.manager.lookup( XMLSerializer.ROLE ));
                           next = new XMLTeePipe(next,  cachePointXMLSerializer);
  @@ -392,20 +392,6 @@
       }
   
   
  -    /** Process the pipeline using a reader.
  -     * @throws ProcessingException if an error occurs
  -     */
  -    protected boolean processReader(Environment environment)
  -    throws ProcessingException {
  -
  -        if (this.getLogger().isDebugEnabled()) {
  -            this.getLogger().debug("Readers not yet supported for CachingPoint 
Pipelines");
  -        }
  -
  -        return true;
  -    }
  -
  -
       /**
        * Recyclable Interface
        */
  @@ -418,7 +404,7 @@
           }
           this.xmlSerializerArray.clear();
           this.nextIsCachePoint = false;
  -     this.autoCachingPointSwitch=null;
  +        this.autoCachingPointSwitch=null;
       }
   
   }
  
  
  
  1.29      +14 -146   
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.28
  retrieving revision 1.29
  diff -u -r1.28 -r1.29
  --- CachingProcessingPipeline.java    15 Jul 2002 08:17:28 -0000      1.28
  +++ CachingProcessingPipeline.java    13 Aug 2002 09:58:30 -0000      1.29
  @@ -1,36 +1,36 @@
   /*
  - 
  +
    ============================================================================
                      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
  @@ -41,12 +41,12 @@
    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.components.pipeline.impl;
   
  @@ -91,8 +91,8 @@
       extends AbstractCachingProcessingPipeline {
   
       /**
  -    * Cache longest cachable key 
  -    */ 
  +    * Cache longest cachable key
  +    */
       protected void cacheResults(Environment environment, OutputStream os)  throws 
Exception {
           if (this.pipelineCacheKey != null) {
               if ( this.cacheCompleteResponse ) {
  @@ -187,138 +187,6 @@
               } catch ( ComponentException e ) {
                   throw new ProcessingException("Could not connect pipeline.", e);
               }
  -    }
  -
  -
  -    /** Process the pipeline using a reader.
  -     * @throws ProcessingException if an error occurs
  -     */
  -    protected boolean processReader(Environment environment)
  -    throws ProcessingException {
  -        try {
  -            boolean usedCache = false;
  -            OutputStream outputStream = environment.getOutputStream();
  -            SourceValidity readerValidity = null;
  -            PipelineCacheKey pcKey = null;
  -
  -            // test if reader is cacheable
  -            Serializable readerKey = null;
  -            boolean isCacheableProcessingComponent = false;
  -            if (super.reader instanceof CacheableProcessingComponent) {
  -                readerKey = 
((CacheableProcessingComponent)super.reader).generateKey();
  -                isCacheableProcessingComponent = true;
  -            } else if (super.reader instanceof Cacheable) {
  -                readerKey = new Long(((Cacheable)super.reader).generateKey());
  -            }
  -
  -            if ( readerKey != null) {
  -                // response is cacheable, build the key
  -                pcKey = new PipelineCacheKey();
  -                pcKey.addKey(new 
ComponentCacheKey(ComponentCacheKey.ComponentType_Reader,
  -                                                   this.readerRole,
  -                                                   readerKey)
  -                            );
  -
  -                // now we have the key to get the cached object
  -                CachedResponse cachedObject = (CachedResponse)this.cache.get( pcKey 
);
  -
  -                if (cachedObject != null) {
  -                    if (this.getLogger().isDebugEnabled()) {
  -                        this.getLogger().debug("Found cached response for '" + 
environment.getURI() + "'.");
  -                    }
  -                    SourceValidity[] validities = cachedObject.getValidityObjects();
  -                    if (validities == null || validities.length != 1) {
  -                        throw new ProcessingException("Cached response is not 
correct.");
  -                    }
  -                    SourceValidity cachedValidity = validities[0];
  -                    int result = cachedValidity.isValid();
  -                    boolean valid = false;
  -                    if ( result == 0 ) {
  -                        // get reader validity and compare
  -                        if (isCacheableProcessingComponent) {
  -                            readerValidity = 
((CacheableProcessingComponent)super.reader).generateValidity();
  -                        } else {
  -                            CacheValidity cv = 
((Cacheable)super.reader).generateValidity();
  -                            if ( cv != null ) {
  -                                readerValidity = 
CacheValidityToSourceValidity.createValidity( cv );
  -                            }
  -                        }
  -                        if (readerValidity != null) {
  -                            valid = cachedValidity.isValid(readerValidity);
  -                        }
  -                    } else {
  -                        valid = (result > 0);
  -                    }
  -
  -                    if (valid) {
  -                        if (this.getLogger().isDebugEnabled()) {
  -                            this.getLogger().debug("Using valid cached content for 
'" + environment.getURI() + "'.");
  -                        }
  -                        byte[] response = cachedObject.getResponse();
  -                        if (response.length > 0) {
  -                            usedCache = true;
  -                            environment.setContentLength(response.length);
  -                            outputStream.write(response);
  -                        }
  -                    } else {
  -                        if (this.getLogger().isDebugEnabled()) {
  -                            this.getLogger().debug("Cached content is invalid for 
'" + environment.getURI() + "'.");
  -                        }
  -                        // remove invalid cached object
  -                        this.cache.remove(pcKey);
  -                    }
  -                }
  -            }
  -
  -            if (!usedCache) {
  -
  -                if ( pcKey != null ) {
  -                    if (this.getLogger().isDebugEnabled()) {
  -                        this.getLogger().debug("Caching content for further 
requests of '" + environment.getURI() + "'.");
  -                    }
  -                    if (readerValidity == null) {
  -                        if (isCacheableProcessingComponent) {
  -                            readerValidity = 
((CacheableProcessingComponent)super.reader).generateValidity();
  -                        } else {
  -                            CacheValidity cv = 
((Cacheable)super.reader).generateValidity();
  -                            if ( cv != null ) {
  -                                readerValidity = 
CacheValidityToSourceValidity.createValidity( cv );
  -                            }
  -                        }
  -                    }
  -                    if (readerValidity != null) {
  -                        outputStream = new CachingOutputStream(outputStream);
  -                    } else {
  -                        pcKey = null;
  -                    }
  -                }
  -
  -                super.processReader( environment, outputStream );
  -
  -                // store the response
  -                if (pcKey != null) {
  -                    this.cache.store(
  -                        environment.getObjectModel(),
  -                        pcKey,
  -                        new CachedResponse( new SourceValidity[] {readerValidity},
  -                                            
((CachingOutputStream)outputStream).getContent())
  -                    );
  -                }
  -            }
  -        } catch ( SocketException se ) {
  -            if (se.getMessage().indexOf("reset") > 0
  -                    || se.getMessage().indexOf("aborted") > 0) {
  -                throw new ConnectionResetException("Connection reset by peer", se);
  -            } else {
  -                throw new ProcessingException("Failed to execute pipeline.", se);
  -            }
  -        } catch ( ProcessingException e ) {
  -            throw e;
  -        } catch ( Exception e ) {
  -            throw new ProcessingException("Failed to execute pipeline.", e);
  -        }
  -
  -        return true;
       }
   
   }
  
  
  

----------------------------------------------------------------------
In case of troubles, e-mail:     [EMAIL PROTECTED]
To unsubscribe, e-mail:          [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to