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 Mon, 27 May 2002 09:57:19 GMT
cziegeler    02/05/27 02:57:19

  Modified:    src/java/org/apache/cocoon/caching Cache.java
               src/java/org/apache/cocoon/caching/impl CacheImpl.java
               src/java/org/apache/cocoon/components/pipeline
                        AbstractProcessingPipeline.java
               src/java/org/apache/cocoon/components/pipeline/impl
                        CachingProcessingPipeline.java
  Log:
  Minor update of the caching algorithm
  
  Revision  Changes    Path
  1.2       +4 -4      xml-cocoon2/src/java/org/apache/cocoon/caching/Cache.java
  
  Index: Cache.java
  ===================================================================
  RCS file: /home/cvs/xml-cocoon2/src/java/org/apache/cocoon/caching/Cache.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- Cache.java	6 May 2002 13:22:31 -0000	1.1
  +++ Cache.java	27 May 2002 09:57:18 -0000	1.2
  @@ -62,7 +62,7 @@
    *
    * @since @next-version@
    * @author <a href="mailto:cziegeler@apache.org">Carsten Ziegeler</a>
  - * @version CVS $Id: Cache.java,v 1.1 2002/05/06 13:22:31 cziegeler Exp $
  + * @version CVS $Id: Cache.java,v 1.2 2002/05/27 09:57:18 cziegeler Exp $
    */
   public interface Cache
   extends Component {
  @@ -78,7 +78,7 @@
        * @param response    the cached response
        */
       void store(Map            objectModel,
  -               String         key,
  +               Object         key,
                  CachedResponse response)
       throws ProcessingException;
   
  @@ -88,7 +88,7 @@
        * @param key         the key used by the caching algorithm to identify the
        *                    request
        */
  -    CachedResponse get(String key);
  +    CachedResponse get(Object key);
   
       /**
        * Remove a cached response.
  @@ -96,5 +96,5 @@
        * @param key         the key used by the caching algorithm to identify the
        *                    request
        */
  -    void remove(String key);
  +    void remove(Object key);
   }
  
  
  
  1.2       +4 -4      xml-cocoon2/src/java/org/apache/cocoon/caching/impl/CacheImpl.java
  
  Index: CacheImpl.java
  ===================================================================
  RCS file: /home/cvs/xml-cocoon2/src/java/org/apache/cocoon/caching/impl/CacheImpl.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- CacheImpl.java	6 May 2002 13:22:31 -0000	1.1
  +++ CacheImpl.java	27 May 2002 09:57:18 -0000	1.2
  @@ -71,7 +71,7 @@
    *
    * @since @next-version@
    * @author <a href="mailto:cziegeler@apache.org">Carsten Ziegeler</a>
  - * @version CVS $Id: CacheImpl.java,v 1.1 2002/05/06 13:22:31 cziegeler Exp $
  + * @version CVS $Id: CacheImpl.java,v 1.2 2002/05/27 09:57:18 cziegeler Exp $
    */
   public class CacheImpl
   extends AbstractLogEnabled
  @@ -109,7 +109,7 @@
        * @param response    the cached response
        */
       public void store(Map            objectModel,
  -                      String         key,
  +                      Object         key,
                         CachedResponse response)
       throws ProcessingException {
           try {
  @@ -125,7 +125,7 @@
        * @param key         the key used by the caching algorithm to identify the
        *                    request
        */
  -    public CachedResponse get(String key) {
  +    public CachedResponse get(Object key) {
           return (CachedResponse)this.store.get(key);
       }
   
  @@ -135,7 +135,7 @@
        * @param key         the key used by the caching algorithm to identify the
        *                    request
        */
  -    public void remove(String key) {
  +    public void remove(Object key) {
           this.store.remove(key);
       }
   
  
  
  
  1.9       +32 -47    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.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- AbstractProcessingPipeline.java	21 May 2002 10:16:20 -0000	1.8
  +++ AbstractProcessingPipeline.java	27 May 2002 09:57:19 -0000	1.9
  @@ -81,7 +81,7 @@
    *
    * @since @next-version@
    * @author <a href="mailto:cziegeler@apache.org">Carsten Ziegeler</a>
  - * @version CVS $Id: AbstractProcessingPipeline.java,v 1.8 2002/05/21 10:16:20 cziegeler
Exp $
  + * @version CVS $Id: AbstractProcessingPipeline.java,v 1.9 2002/05/27 09:57:19 cziegeler
Exp $
    */
   public abstract class AbstractProcessingPipeline
     extends AbstractLogEnabled
  @@ -360,60 +360,49 @@
       }
   
       /**
  -     * Connect the XML pipeline.
  +     * Connect the next component
        */
  -    protected void connectPipeline(Environment environment)
  +    protected void connect(Environment environment,
  +                           XMLProducer producer,
  +                           XMLConsumer consumer)
       throws ProcessingException {
  -        XMLProducer prev = (XMLProducer)this.generator;
  -        XMLConsumer next;
  -
           try {
  -            Iterator itt = this.transformers.iterator();
  -            while ( itt.hasNext() ) {
  -                if (this.configuredSAXConnector) {
  -                    // connect SAXConnector
  -                    SAXConnector connect = (SAXConnector) this.manager.lookup(SAXConnector.ROLE);
  -                    connect.setup(environment,environment.getObjectModel(), null, null);
  -                    this.connectors.add(connect);
  -                    next = connect;
  -                    prev.setConsumer(next);
  -                    prev = connect;
  -                }
  -                // Connect next component.
  -                Transformer trans = (Transformer) itt.next();
  -                next = trans;
  -                prev.setConsumer(next);
  -                prev = trans;
  -            }
  -
  +            XMLProducer next = producer;
               if (this.configuredSAXConnector) {
  -                // insert SAXConnector
  +                // connect SAXConnector
                   SAXConnector connect = (SAXConnector) this.manager.lookup(SAXConnector.ROLE);
  -                connect.setup(environment,environment.getObjectModel(), null, null);
                   this.connectors.add(connect);
  +                connect.setup(environment, environment.getObjectModel(), null, null);
  +                next.setConsumer( connect );
                   next = connect;
  -                prev.setConsumer(next);
  -                prev = connect;
               }
  -            // insert the serializer
  -            prev.setConsumer(this.lastConsumer);
  +            // Connect next component.
  +            next.setConsumer(consumer);
           } catch ( IOException e ) {
  -            throw new ProcessingException(
  -                "Could not connect pipeline.",
  -                e
  -            );
  +            throw new ProcessingException("Could not connect pipeline.", e);
           } catch ( SAXException e ) {
  -            throw new ProcessingException(
  -                "Could not connect pipeline.",
  -                e
  -            );
  +            throw new ProcessingException("Could not connect pipeline.", e);
           } catch ( ComponentException e ) {
  -            throw new ProcessingException(
  -                "Could not connect pipeline.",
  -                e
  -            );
  +            throw new ProcessingException("Could not connect pipeline.", e);
  +        }
  +    }
  +
  +    /**
  +     * Connect the XML pipeline.
  +     */
  +    protected void connectPipeline(Environment environment)
  +    throws ProcessingException {
  +        XMLProducer prev = (XMLProducer)this.generator;
  +
  +        Iterator itt = this.transformers.iterator();
  +        while ( itt.hasNext() ) {
  +            Transformer trans = (Transformer) itt.next();
  +            this.connect( environment, prev, trans );
  +            prev = trans;
           }
   
  +        // insert the serializer
  +        this.connect( environment, prev, this.lastConsumer);
       }
   
       /**
  @@ -475,11 +464,7 @@
           } catch ( ProcessingException e ) {
               throw e;
           } catch ( Exception e ) {
  -            getLogger().debug("Exception in process", e);
  -            throw new ProcessingException(
  -                "Failed to execute pipeline.",
  -                e
  -            );
  +            throw new ProcessingException("Failed to execute pipeline.", e);
           }
           return true;
       }
  
  
  
  1.10      +160 -316  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.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- CachingProcessingPipeline.java	24 May 2002 08:52:33 -0000	1.9
  +++ CachingProcessingPipeline.java	27 May 2002 09:57:19 -0000	1.10
  @@ -75,7 +75,7 @@
   import org.apache.cocoon.xml.XMLProducer;
   import org.apache.excalibur.source.SourceValidity;
   import org.xml.sax.SAXException;
  -
  +import java.io.ByteArrayOutputStream;
   import java.io.IOException;
   import java.io.OutputStream;
   import java.net.SocketException;
  @@ -89,32 +89,42 @@
    *
    * @since @next-version@
    * @author <a href="mailto:cziegeler@apache.org">Carsten Ziegeler</a>
  - * @version CVS $Id: CachingProcessingPipeline.java,v 1.9 2002/05/24 08:52:33 cziegeler
Exp $
  + * @version CVS $Id: CachingProcessingPipeline.java,v 1.10 2002/05/27 09:57:19 cziegeler
Exp $
    */
   public class CachingProcessingPipeline
   extends AbstractProcessingPipeline
   implements Disposable {
   
       /** The Cache storing the cached response (or part of the response) */
  -    private Cache  cache;
  +    protected Cache  cache;
   
       /** The role name of the generator */
  -    private String generatorRole;
  +    protected String generatorRole;
   
       /** The role names of the transfomrers */
  -    private ArrayList transformerRoles = new ArrayList();
  +    protected ArrayList transformerRoles = new ArrayList();
   
       /** The role name of the serializer */
  -    private String serializerRole;
  +    protected String serializerRole;
   
       /** The role name of the reader */
  -    private String readerRole;
  +    protected String readerRole;
   
  -    private ArrayList notCacheableTransformers = new ArrayList();
  -    private Map validityObjects;
  -    private StringBuffer pipelineCacheKey;
  +    /** A cached response which is used as input for the pipeline */
  +    protected CachedResponse cachedResponse;
  +    /** The key to store the cached response */
  +    protected StringBuffer   pipelineCacheKey;
  +    /** The index indicating to the first transformer which is not cacheable */
  +    protected int firstNotCacheableTransformerIndex;
  +    /** The deserializer */
  +    protected XMLDeserializer xmlDeserializer;
  +    /** Complete response is cached */
  +    protected boolean completeResponseIsCached;
  +    /** The serializer */
  +    protected XMLSerializer xmlSerializer;
   
  -    private int firstNotCacheableTransformerIndex;
  +    /** The validity objects */
  +    protected SourceValidity[] validityObjects;
   
       /**
        * Composable Interface
  @@ -163,95 +173,78 @@
   
       /**
        * Process the given <code>Environment</code>, producing the output.
  +     */
       protected boolean processXMLPipeline(Environment environment)
       throws ProcessingException {
  -
  -        // we cache if the pipelinecachekey is available
  -        XMLSerializer xmlSerializer = null;
  -
  -        try {
  -            if (this.pipelineCacheKey != null) {
  -                // now we have the key to get the cached object
  -                CachedEventObject cachedObject = (CachedEventObject)this.cache.get(this.pipelineCacheKey);
  -
  -                if (cachedObject != null) {
  -                    getLogger().debug("Found cached content for '" + environment.getURI()
+ "'.");
  -                    Iterator validityIterator = validityObjects.keySet().iterator();
  -                    ComponentCacheKey validityKey;
  -                    boolean valid = true;
  -                    while (validityIterator.hasNext() && valid) {
  -                        validityKey = (ComponentCacheKey)validityIterator.next();
  -                        valid = cachedObject.isValid(validityKey, (CacheValidity)validityObjects.get(validityKey));
  -                        if (getLogger().isDebugEnabled()) {
  -                            CacheValidity cachedValidity = cachedObject.getCacheValidity(validityKey);
  -                            getLogger().debug("Compared cached validity '" + cachedValidity
+
  -                                "' with new validity '" + validityObjects.get(validityKey)
+
  -                                "' : " + (valid ? "valid" : "changed"));
  -                        }
  +        if (this.pipelineCacheKey == null) {
  +            return super.processXMLPipeline( environment );
  +        } else if (this.completeResponseIsCached) {
  +            try {
  +                final OutputStream outputStream = environment.getOutputStream();
  +                byte[] response = this.cachedResponse.getResponse();
  +                if (response.length > 0) {
  +                    environment.setContentLength(response.length);
  +                    outputStream.write(response);
  +                }
  +            } 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 reader pipeline.",
se);
  +                }
  +            } catch ( Exception e ) {
  +                throw new ProcessingException("Error executing reader pipeline.",e);
  +            }
  +        } else {
  +            try {
  +                if (this.serializer.shouldSetContentLength()) {
  +                    // set the output stream
  +                    ByteArrayOutputStream os = new ByteArrayOutputStream();
  +                    this.serializer.setOutputStream(os);
  +
  +                    // execute the pipeline:
  +                    if ( this.xmlDeserializer != null ) {
  +                        this.xmlDeserializer.deserialize(this.cachedResponse.getResponse());
  +                    } else {
  +                        this.generator.generate();
                       }
  -                    if (valid) {
  -                        getLogger().debug("Using valid cached content for '" + environment.getURI()
+ "'.");
  -                        // get all transformers which are not cacheable
  -                        int transformerSize = this.transformers.size();
  -                        while (this.firstNotCacheableTransformerIndex < transformerSize)
{
  -                            this.notCacheableTransformers.add(this.transformers.get(this.firstNotCacheableTransformerIndex));
  -                            this.firstNotCacheableTransformerIndex++;
  -                        }
  -
  -                        XMLDeserializer deserializer = null;
  -                        try {
  -                            deserializer = (XMLDeserializer)this.manager.lookup(XMLDeserializer.ROLE);
  -                            // connect the pipeline:
  -                            this.producer = deserializer;
  -                            this.connectPipeline(environment,
  -                                                 notCacheableTransformers,
  -                                                 null);
  -                            // execute the pipeline:
  -                            deserializer.deserialize(cachedObject.getSAXFragment());
  -                        } catch ( ProcessingException e ) {
  -                            throw e;
  -                        } catch ( Exception e ) {
  -                            throw new ProcessingException(
  -                                 "Failed to execute pipeline.",
  -                                  e
  -                            );
  -                        } finally {
  -                            this.manager.release(deserializer);
  -                        }
  +                    byte[] data = os.toByteArray();
  +                    environment.setContentLength(data.length);
  +                    environment.getOutputStream().write(data);
  +                } else {
  +                    // set the output stream
  +                    this.serializer.setOutputStream(environment.getOutputStream());
  +                    // execute the pipeline:
  +                    if ( this.xmlDeserializer != null ) {
  +                        this.xmlDeserializer.deserialize(this.cachedResponse.getResponse());
                       } else {
  -                        getLogger().debug("Cached content is invalid for '" + environment.getURI()
+ "'.");
  -                        // remove invalid cached object
  -                        this.eventCache.remove(this.pipelineCacheKey);
  -                        cachedObject = null;
  +                        this.generator.generate();
                       }
                   }
  -                if (cachedObject == null) {
  -                    getLogger().debug("Caching content for further requests of '" + environment.getURI()
+ "'.");
  -                    xmlSerializer = (XMLSerializer)this.manager.lookup(XMLSerializer.ROLE);
  -                }
  -            }
  -
  -            if (this.producer == null) {
  -                // the content was not cached/or is invalid
  -                this.producer = this.generator;
  -                this.connectPipeline(environment,
  -                                     this.transformers,
  -                                     xmlSerializer);
  -                // execute the pipeline:
  -                this.generator.generate();
  -                // did we have cacheable components?
  -                if (xmlSerializer != null) {
  -                    this.eventCache.store(this.pipelineCacheKey,
  -                        new CachedEventObject(this.validityObjects,
  -                        xmlSerializer.getSAXFragment()));
  +                if (this.xmlSerializer != null) {
  +                    CachedResponse response = new CachedResponse(this.validityObjects,
  +                                 (byte[])this.xmlSerializer.getSAXFragment());
  +                    this.cache.store(environment.getObjectModel(),
  +                                     this.pipelineCacheKey,
  +                                     response);
  +                }
  +            } 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 reader pipeline.",
se);
                   }
  +            } catch ( ProcessingException e ) {
  +                throw e;
  +            } catch ( Exception e ) {
  +                throw new ProcessingException("Failed to execute pipeline.", e);
               }
  -        } finally {
  -            this.manager.release(xmlSerializer);
  +            return true;
           }
           return true;
       }
  -     */
   
       /**
        * Setup the evenet pipeline.
  @@ -263,6 +256,7 @@
           super.setupPipeline( environment );
   
           this.firstNotCacheableTransformerIndex = 0;
  +        this.completeResponseIsCached = false;
   
           // first step is to generate the key:
           // All pipeline components starting with the generator
  @@ -329,7 +323,7 @@
                                            .append(this.serializerRole)
                                            .append('-')
                                            .append(key);
  -                    // FIXME - WE ARE CACHEABLE
  +                    this.completeResponseIsCached = true;
                   }
               }
           }
  @@ -387,7 +381,10 @@
                   // FIXME
                   if ( responseIsValid ) {
                       // we are valid, ok that's it
  +                    this.cachedResponse = response;
  +                    this.validityObjects = validities;
                   } else {
  +                    this.cachedResponse = null;
                       // we are not valid!
                       this.cache.remove(this.pipelineCacheKey.toString());
                       if (!responseIsUsable) {
  @@ -477,82 +474,74 @@
           }*/
       }
   
  -    /** Connect the pipeline.
  -    private void connectPipeline(Environment   environment,
  -                                 ArrayList     usedTransformers,
  -                                 XMLSerializer xmlSerializer)
  +    /**
  +     * Connect the pipeline.
  +     */
  +    protected void connectPipeline(Environment   environment)
       throws ProcessingException {
  -        XMLProducer prev = this.producer;
  -        XMLConsumer next;
  -
  -        boolean configuredSAXConnector = this.manager.hasComponent(SAXConnector.ROLE);
  -
  -        try {
  -            int cacheableTransformerCount = this.firstNotCacheableTransformerIndex;
  -
  -            Iterator itt = usedTransformers.iterator();
  -            while ( itt.hasNext() ) {
  -                if (configuredSAXConnector) {
  -                    // connect SAXConnector
  -                    SAXConnector connect = (SAXConnector) this.manager.lookup(SAXConnector.ROLE);
  -                    connect.setup(environment,environment.getObjectModel(),null,null);
  -                    this.connectors.add(connect);
  -                    next = connect;
  -                    prev.setConsumer(next);
  -                    prev = connect;
  -                }
  -
  -                // Connect next component.
  -                next = (XMLConsumer) itt.next();
  -                if (xmlSerializer != null) {
  -                    if (cacheableTransformerCount == 0) {
  -                        next = new XMLTeePipe(next, xmlSerializer);
  -                        xmlSerializer = null;
  -                    } else {
  -                        cacheableTransformerCount--;
  +        if ( this.pipelineCacheKey == null ) {
  +            super.connectPipeline( environment );
  +        } else if (this.completeResponseIsCached) {
  +            // do nothing
  +            return;
  +        } else {
  +            try {
  +                this.xmlSerializer = (XMLSerializer)this.manager.lookup( XMLSerializer.ROLE
);
  +                XMLSerializer localXMLSerializer = this.xmlSerializer;
  +                if ( this.cachedResponse == null ) {
  +                    XMLProducer prev = super.generator;
  +                    XMLConsumer next;
  +
  +                    int cacheableTransformerCount = this.firstNotCacheableTransformerIndex;
  +
  +                    Iterator itt = this.transformers.iterator();
  +                    while ( itt.hasNext() ) {
  +                        next = (XMLConsumer) itt.next();
  +                        if (localXMLSerializer != null) {
  +                            if (cacheableTransformerCount == 0) {
  +                                next = new XMLTeePipe(next, localXMLSerializer);
  +                                localXMLSerializer = null;
  +                            } else {
  +                                cacheableTransformerCount--;
  +                            }
  +                        }
  +                        this.connect(environment, prev, next);
  +                        prev = (XMLProducer) next;
                       }
  +                    next = super.lastConsumer;
  +                    if (localXMLSerializer != null) {
  +                        next = new XMLTeePipe(next, localXMLSerializer);
  +                        localXMLSerializer = null;
  +                    }
  +                    this.connect(environment, prev, next);
  +                } else {
  +                    this.xmlDeserializer = (XMLDeserializer)this.manager.lookup(XMLDeserializer.ROLE);
  +                    // connect the pipeline:
  +                    XMLProducer prev = xmlDeserializer;
  +                    XMLConsumer next;
  +                    int cacheableTransformerCount = 0;
  +                    Iterator itt = this.transformers.iterator();
  +                    while ( itt.hasNext() ) {
  +                        next = (XMLConsumer) itt.next();
  +                        if (cacheableTransformerCount >= this.firstNotCacheableTransformerIndex)
{
  +                            this.connect(environment, prev, next);
  +                            prev = (XMLProducer)next;
  +                        }
  +                    }
  +                    next = super.lastConsumer;
  +                    if (localXMLSerializer != null) {
  +                        next = new XMLTeePipe(next, localXMLSerializer);
  +                        localXMLSerializer = null;
  +                    }
  +                    this.connect(environment, prev, next);
                   }
  -                prev.setConsumer(next);
  -                prev = (XMLProducer) next;
  -            }
   
  -            if (configuredSAXConnector) {
  -                // insert SAXConnector
  -                SAXConnector connect = (SAXConnector) this.manager.lookup(SAXConnector.ROLE);
  -                connect.setup(environment,environment.getObjectModel(),null,null);
  -                this.connectors.add(connect);
  -                next = connect;
  -                prev.setConsumer(next);
  -                prev = connect;
  -            }
  -
  -            // insert this consumer
  -            next = super.xmlConsumer;
  -            if (xmlSerializer != null) {
  -                next = new XMLTeePipe(next, xmlSerializer);
  -                xmlSerializer = null;
  -            }
  -            prev.setConsumer(next);
  -
  -        } catch ( IOException e ) {
  -            throw new ProcessingException(
  -                "Could not connect pipeline.",
  -                e
  -            );
  -        } catch ( SAXException e ) {
  -            throw new ProcessingException(
  -                "Could not connect pipeline.",
  -                e
  -            );
  -        } catch ( ComponentException e ) {
  -            throw new ProcessingException(
  -                "Could not connect pipeline.",
  -                e
  -            );
  +            } catch ( ComponentException e ) {
  +                throw new ProcessingException("Could not connect pipeline.", e);
  +            }
           }
  -
       }
  -     */
  +
   
       /** Process the pipeline using a reader.
        * @throws ProcessingException if an error occurs
  @@ -561,7 +550,7 @@
       throws ProcessingException {
           try {
               boolean usedCache = false;
  -            OutputStream outputStream = environment.getOutputStream();;
  +            OutputStream outputStream = environment.getOutputStream();
               SourceValidity readerValidity = null;
               StringBuffer pcKey = null;
   
  @@ -670,182 +659,37 @@
                   || se.getMessage().indexOf("aborted") > 0) {
                   throw new ConnectionResetException("Connection reset by peer", se);
               } else {
  -                getLogger().debug("SocketException in ProcessReader", se);
  -
  -                throw new ProcessingException(
  -                    "Failed to execute pipeline.",
  -                    se
  -                );
  +                throw new ProcessingException("Failed to execute pipeline.", se);
               }
           } catch ( ProcessingException e ) {
               throw e;
           } catch ( Exception e ) {
  -            getLogger().debug("Exception in ProcessReader", e);
  -
  -            throw new ProcessingException(
  -                "Failed to execute pipeline.",
  -                e
  -            );
  +            throw new ProcessingException("Failed to execute pipeline.", e);
           }
   
           return true;
       }
   
  -    protected boolean processXMLPipeline(Environment environment)
  -    throws ProcessingException {
  -        return super.processXMLPipeline( environment );
  -    }
  -   /**
  -     * Process the request.
  -    public boolean process(Environment environment)
  -    throws ProcessingException {
  -        if ( super.reader != null ) {
  -            return super.process(environment);
  -        } else {
  -            if ( !this.checkPipeline() ) {
  -                throw new ProcessingException("Attempted to process incomplete pipeline.");
  -            }
  -
  -            try {
  -
  -                boolean usedCache = false;
  -                OutputStream outputStream;
  -                PipelineCacheKey pcKey = null;
  -                Map validityObjects = null;
  -
  -                outputStream = environment.getOutputStream();
  -
  -                this.setupPipeline(environment);
  -                this.connectPipeline();
  -
  -                // test if serializer and event pipeline are cacheable
  -                long serializerKey = 0;
  -                PipelineCacheKey eventPipelineKey = null;
  -                CacheValidity serializerValidity = null;
  -                Map eventPipelineValidity = null;
  -                if (this.eventPipeline instanceof CacheableEventPipeline) {
  -                    if (this.serializer instanceof Cacheable
  -                        && (serializerKey = ((Cacheable)this.serializer).generateKey())
!= 0
  -                        && (serializerValidity = ((Cacheable)this.serializer).generateValidity())
!= null
  -                        && (eventPipelineKey = ((CacheableEventPipeline)this.eventPipeline).generateKey(environment))
!= null
  -                        && (eventPipelineValidity = ((CacheableEventPipeline)this.eventPipeline).generateValidity(environment))
!= null) {
  -
  -                        // tell the event pipeline that it must not cache
  -                        ((CacheableEventPipeline)this.eventPipeline).setStreamPipelineCaches(true);
  -
  -                        // response is cacheable, build the key
  -                        validityObjects = eventPipelineValidity;
  -                        ComponentCacheKey ccKey;
  -                        pcKey = new PipelineCacheKey();
  -                        ccKey = new ComponentCacheKey(ComponentCacheKey.ComponentType_Serializer,
  -                                                    this.serializerRole,
  -                                                    serializerKey);
  -                        validityObjects.put(ccKey, serializerValidity);
  -                        pcKey.addKey(ccKey);
  -                        pcKey.addKey(eventPipelineKey);
  -
  -                        // now we have the key to get the cached object
  -                        CachedStreamObject cachedObject = (CachedStreamObject)this.streamCache.get(pcKey);
  -
  -                        if (cachedObject != null) {
  -                            getLogger().debug("Found cached response for '" + environment.getURI()
+ "'.");
  -
  -                            Iterator validityIterator = validityObjects.keySet().iterator();
  -                            ComponentCacheKey validityKey;
  -                            boolean valid = true;
  -                            while (validityIterator.hasNext() && valid) {
  -                                validityKey = (ComponentCacheKey)validityIterator.next();
  -                                valid = cachedObject.isValid(validityKey, (CacheValidity)validityObjects.get(validityKey));
  -                                if (getLogger().isDebugEnabled()) {
  -                                    CacheValidity cachedValidity = cachedObject.getCacheValidity(validityKey);
  -                                    getLogger().debug("Compared cached validity '" + cachedValidity
+
  -                                        "' with new validity '" + validityObjects.get(validityKey)
+
  -                                        "' : " + (valid ? "valid" : "changed"));
  -                                }
  -                            }
  -                            if (valid) {
  -                                getLogger().debug("Using valid cached content for '" +
environment.getURI() + "'.");
  -                                byte[] bytes = cachedObject.getResponse();
  -                                if(bytes.length > 0) {
  -                                    usedCache = true;
  -                                    environment.setContentLength(bytes.length);
  -                                    outputStream.write(bytes);
  -                                }
  -                            }
  -
  -                            if (!usedCache) {
  -                                getLogger().debug("Cached content is invalid for '" + environment.getURI()
+ "'.");
  -
  -                                // remove invalid cached object
  -                                this.streamCache.remove(pcKey);
  -                                cachedObject = null;
  -                            }
  -                        }
  -                        if (cachedObject == null) {
  -                            getLogger().debug("Caching content for further requests of
'" + environment.getURI() + "'.");
  -                            outputStream = new CachingOutputStream(outputStream);
  -                        }
  -                    } else {
  -                        ((CacheableEventPipeline)this.eventPipeline).setStreamPipelineCaches(false);
  -                    }
  -                }
  -
  -                if (!usedCache) {
  -                    if (this.serializer.shouldSetContentLength()) {
  -                        // set the output stream
  -                        ByteArrayOutputStream os = new ByteArrayOutputStream();
  -                        this.serializer.setOutputStream(os);
  -
  -                        // execute the pipeline:
  -                        this.eventPipeline.process(environment);
  -                        byte[] data = os.toByteArray();
  -                        environment.setContentLength(data.length);
  -                        outputStream.write(data);
  -                   } else {
  -                        // set the output stream
  -                        this.serializer.setOutputStream(outputStream);
  -
  -                        // execute the pipeline:
  -                        this.eventPipeline.process(environment);
  -                    }
  -
  -                    // store the response
  -                    if (pcKey != null) {
  -                        byte[] bytes = ((CachingOutputStream)outputStream).getContent();
  -                        this.streamCache.store(pcKey,
  -                            new CachedStreamObject(validityObjects, bytes));
  -                    }
  -                }
  -
  -            } catch ( ProcessingException e ) {
  -                throw e;
  -            } catch ( Exception e ) {
  -                getLogger().debug("Exception in process", e);
  -                throw new ProcessingException(
  -                    "Failed to execute pipeline.",
  -                    e
  -                );
  -            }
  -
  -            return true;
  -        }
  -    }
  -     */
  -
       /**
        * Recyclable Interface
        */
       public void recycle() {
           super.recycle();
   
  +        this.manager.release( this.xmlDeserializer );
  +        this.xmlDeserializer = null;
  +
  +        this.manager.release( this.xmlSerializer );
  +        this.xmlSerializer = null;
  +
           this.generatorRole = null;
           this.transformerRoles.clear();
           this.serializerRole = null;
           this.readerRole = null;
   
  -        this.notCacheableTransformers.clear();
  -        this.validityObjects = null;
           this.pipelineCacheKey = null;
  +        this.cachedResponse = null;
  +        this.validityObjects = 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