cziegeler    02/05/02 07:48:53

  Modified:    src/java/org/apache/cocoon/components/pipeline
                        AbstractProcessingPipeline.java
  Added:       src/java/org/apache/cocoon/components/pipeline/impl
                        CachingProcessingPipeline.java
                        NonCachingProcessingPipeline.java
  Removed:     src/java/org/apache/cocoon/components/pipeline
                        CachingProcessingPipeline.java
                        NonCachingProcessingPipeline.java
  Log:
  Moved impl
  
  Revision  Changes    Path
  1.3       +1 -18     
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.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- AbstractProcessingPipeline.java   2 May 2002 14:20:46 -0000       1.2
  +++ AbstractProcessingPipeline.java   2 May 2002 14:48:53 -0000       1.3
  @@ -77,25 +77,8 @@
   /**
    * This is the base for all implementations of a <code>ProcessingPipeline</code>.
    *
  - * A <code>ProcessingPipeline<code> produces the response for a given request.
  - * It is assembled according to the commands in the sitemap and can either
  - * <ul>
  - *  <li>collect a <code>Reader</code> and let it produce a character stream</li>
  - *  <li>or connect a <code>Generator</code> with zero or more
  - *      <code>Transformer</code>s and a <code>Serializer</code> and let them
  - *      produce the byte stream. This pipeline uses SAX events for
  - *      communication.
  - *  </li>
  - * </ul>
  - *
  - * <p>
  - * A <code>ProcessingPipeline</code> is <code>Recomposable</code> since the
  - * <code>ComponentManager</code> used to get the generato, transformers etc.
  - * depends on the pipeline assembly engine where they are defined (i.e. a given
  - * sitemap file).
  - *
    * @author <a href="mailto:[EMAIL PROTECTED]";>Carsten Ziegeler</a>
  - * @version CVS $Id: AbstractProcessingPipeline.java,v 1.2 2002/05/02 14:20:46 
cziegeler Exp $
  + * @version CVS $Id: AbstractProcessingPipeline.java,v 1.3 2002/05/02 14:48:53 
cziegeler Exp $
    */
   public abstract class AbstractProcessingPipeline
     extends AbstractLoggable
  
  
  
  1.1                  
xml-cocoon2/src/java/org/apache/cocoon/components/pipeline/impl/CachingProcessingPipeline.java
  
  Index: CachingProcessingPipeline.java
  ===================================================================
  /*
  
   ============================================================================
                     The Apache Software License, Version 1.1
   ============================================================================
  
   Copyright (C) 1999-2002 The Apache Software Foundation. All rights reserved.
  
   Redistribution and use in source and binary forms, with or without modifica-
   tion, are permitted provided that the following conditions are met:
  
   1. Redistributions of  source code must  retain the above copyright  notice,
      this list of conditions and the following disclaimer.
  
   2. Redistributions in binary form must reproduce the above copyright notice,
      this list of conditions and the following disclaimer in the documentation
      and/or other materials provided with the distribution.
  
   3. The end-user documentation included with the redistribution, if any, must
      include  the following  acknowledgment:  "This product includes  software
      developed  by the  Apache Software Foundation  (http://www.apache.org/)."
      Alternately, this  acknowledgment may  appear in the software itself,  if
      and wherever such third-party acknowledgments normally appear.
  
   4. The names "Apache Cocoon" and  "Apache Software Foundation" must  not  be
      used to  endorse or promote  products derived from  this software without
      prior written permission. For written permission, please contact
      [EMAIL PROTECTED]
  
   5. Products  derived from this software may not  be called "Apache", nor may
      "Apache" appear  in their name,  without prior written permission  of the
      Apache Software Foundation.
  
   THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
   INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
   FITNESS  FOR A PARTICULAR  PURPOSE ARE  DISCLAIMED.  IN NO  EVENT SHALL  THE
   APACHE SOFTWARE  FOUNDATION  OR ITS CONTRIBUTORS  BE LIABLE FOR  ANY DIRECT,
   INDIRECT, INCIDENTAL, SPECIAL,  EXEMPLARY, OR CONSEQUENTIAL  DAMAGES (INCLU-
   DING, BUT NOT LIMITED TO, PROCUREMENT  OF SUBSTITUTE GOODS OR SERVICES; LOSS
   OF USE, DATA, OR  PROFITS; OR BUSINESS  INTERRUPTION)  HOWEVER CAUSED AND ON
   ANY  THEORY OF LIABILITY,  WHETHER  IN CONTRACT,  STRICT LIABILITY,  OR TORT
   (INCLUDING  NEGLIGENCE OR  OTHERWISE) ARISING IN  ANY WAY OUT OF THE  USE OF
   THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  
   This software  consists of voluntary contributions made  by many individuals
   on  behalf of the Apache Software  Foundation and was  originally created by
   Stefano Mazzocchi  <[EMAIL PROTECTED]>. For more  information on the Apache
   Software Foundation, please see <http://www.apache.org/>.
  
  */
  package org.apache.cocoon.components.pipeline.impl;
  
  import org.apache.avalon.excalibur.pool.Recyclable;
  import org.apache.avalon.framework.activity.Disposable;
  import org.apache.avalon.framework.component.ComponentException;
  import org.apache.avalon.framework.component.ComponentManager;
  import org.apache.avalon.framework.parameters.Parameters;
  import org.apache.cocoon.ProcessingException;
  import org.apache.cocoon.caching.*;
  import org.apache.cocoon.components.pipeline.AbstractProcessingPipeline;
  import org.apache.cocoon.components.sax.XMLDeserializer;
  import org.apache.cocoon.components.sax.XMLSerializer;
  import org.apache.cocoon.components.sax.XMLTeePipe;
  import org.apache.cocoon.components.saxconnector.SAXConnector;
  import org.apache.cocoon.components.store.Store;
  import org.apache.cocoon.environment.Environment;
  import org.apache.cocoon.transformation.Transformer;
  import org.apache.cocoon.xml.XMLConsumer;
  import org.apache.cocoon.xml.XMLProducer;
  import org.xml.sax.SAXException;
  
  import java.io.IOException;
  import java.util.ArrayList;
  import java.util.HashMap;
  import java.util.Iterator;
  import java.util.Map;
  
  /**
   * The CachingProcessingPipeline
   *
   *
   * @author <a href="mailto:[EMAIL PROTECTED]";>Carsten Ziegeler</a>
   * @version CVS $Id: CachingProcessingPipeline.java,v 1.1 2002/05/02 14:48:53 
cziegeler Exp $
   */
  public class CachingProcessingPipeline
  extends AbstractProcessingPipeline
  implements Disposable {
  
      /** The store for the cached response (or part of the response) */
      private Store  cache;
  
      /** The role name of the generator */
      private String generatorRole;
  
      /** The role names of the transfomrers */
      private ArrayList transformerRoles = new ArrayList();
  
      /** The role name of the serializer */
      private String serializerRole;
  
      /** The role name of the reader */
      private String readerRole;
  
      private ArrayList notCacheableTransformers = new ArrayList();
      private Map validityObjects;
      private PipelineCacheKey pipelineCacheKey;
  
      private int firstNotCacheableTransformerIndex;
  
      /**
       * Composable Interface
       */
      public void compose (ComponentManager manager)
      throws ComponentException {
          super.compose(manager);
          this.cache = (Store)this.manager.lookup(Store.TRANSIENT_CACHE);
      }
  
      /**
       * Set the generator.
       */
      public void setGenerator (String role, String source, Parameters param)
      throws ProcessingException {
          super.setGenerator(role, source, param);
          this.generatorRole = role;
      }
  
      /**
       * Add a transformer.
       */
      public void addTransformer (String role, String source, Parameters param)
      throws ProcessingException {
          super.addTransformer(role, source, param);
          this.transformerRoles.add(role);
      }
  
      /**
       * Set the serializer.
       */
      public void setSerializer (String role, String source, Parameters param, String 
mimeType)
      throws ProcessingException {
          super.setSerializer(role, source, param, mimeType);
          this.serializerRole = role;
      }
  
      /**
       * Set the Reader.
       */
      public void setReader (String role, String source, Parameters param, String 
mimeType)
      throws ProcessingException {
          super.setReader(role, source, param, mimeType);
          this.readerRole = role;
      }
  
      /**
       * 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 (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);
                          }
                      } else {
                          getLogger().debug("Cached content is invalid for '" + 
environment.getURI() + "'.");
                          // remove invalid cached object
                          this.eventCache.remove(this.pipelineCacheKey);
                          cachedObject = null;
                      }
                  }
                  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()));
                  }
              }
          } finally {
              this.manager.release(xmlSerializer);
          }
          return true;
      }
       */
  
      /**
       * Setup the evenet pipeline.
       * The components of the pipeline are checked if they are
       * Cacheable.
       */
      protected void setupPipeline(Environment environment)
      throws ProcessingException {
          super.setupPipeline( environment );
  
          this.firstNotCacheableTransformerIndex = 0;
  
          // is the generator cacheable?
          if (this.generator instanceof Cacheable) {
              long key = ((Cacheable)this.generator).generateKey();
              CacheValidity validity = ((Cacheable)this.generator).generateValidity();
  
              // final check, the current generator might not be cacheable
              if (key != 0 && validity != null) {
                  ComponentCacheKey cck = new ComponentCacheKey(
                             ComponentCacheKey.ComponentType_Generator,
                             this.generatorRole,
                             key);
                  this.validityObjects = new HashMap();
                  this.validityObjects.put(cck, validity);
                  this.pipelineCacheKey = new PipelineCacheKey();
                  this.pipelineCacheKey.addKey(cck);
  
                  // now testing transformers
                  Transformer trans;
                  ComponentCacheKey transCacheKey;
                  int transformerSize = this.transformers.size();
                  long transKey;
                  CacheValidity transValidity;
                  boolean testTrans = true;
  
                  while (this.firstNotCacheableTransformerIndex < transformerSize
                             && testTrans) {
                      trans = 
(Transformer)this.transformers.get(this.firstNotCacheableTransformerIndex);
                      if (trans instanceof Cacheable) {
                          transKey = ((Cacheable)trans).generateKey();
                          transValidity = ((Cacheable)trans).generateValidity();
                          if (transKey != 0 && transValidity != null) {
                              transCacheKey = new ComponentCacheKey(
                                   ComponentCacheKey.ComponentType_Transformer,
                                   
(String)this.transformerRoles.get(this.firstNotCacheableTransformerIndex),
                                   transKey);
                              this.pipelineCacheKey.addKey(transCacheKey);
                              this.validityObjects.put(transCacheKey, transValidity);
                          } else {
                              testTrans = false;
                          }
                      } else {
                          testTrans = false;
                      }
                      if (testTrans) {
                          this.firstNotCacheableTransformerIndex++;
                      }
                  }
                  // all transformers are cacheable => pipeline is cacheable
                  if (this.firstNotCacheableTransformerIndex == transformerSize) {
                      // FIXME - WE ARE CACHEABLE
                  }
              }
          }
      }
  
      /** Connect the pipeline.
      private void connectPipeline(Environment   environment,
                                   ArrayList     usedTransformers,
                                   XMLSerializer xmlSerializer)
      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--;
                      }
                  }
                  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
              );
          }
  
      }
       */
  
      /** Process the pipeline using a reader.
       * @throws ProcessingException if
      protected boolean processReader(Environment environment)
      throws ProcessingException {
  
          try
          {
              
this.reader.setup(environment,environment.getObjectModel(),readerSource,readerParam);
              String mimeType = this.reader.getMimeType();
  
              mimeType = this.reader.getMimeType();
              if ( mimeType != null ) {
                  environment.setContentType(mimeType);
              } else if ( readerMimeType != null ) {
                  environment.setContentType(this.readerMimeType);
              } else {
                  environment.setContentType(this.sitemapReaderMimeType);
              }
  
              // has the read resource been modified?
              long lastModified = this.reader.getLastModified();
              if (lastModified != 0
                  && !environment.isResponseModified(lastModified)) {
  
                  // environment supports this, so we are finished
                  environment.setResponseIsNotModified();
                  return true;
              }
          } catch (SAXException e){
              getLogger().debug("SAXException in ProcessReader", e);
  
              throw new ProcessingException(
                  "Failed to execute pipeline.",
                  e
              );
          } catch (IOException e){
              getLogger().debug("IOException in ProcessReader", e);
  
              throw new ProcessingException(
                  "Failed to execute pipeline.",
                  e
              );
          }
  
          try {
              boolean usedCache = false;
              OutputStream outputStream;
              PipelineCacheKey pcKey = null;
              Map validityObjects = new HashMap();
  
              outputStream = environment.getOutputStream();
  
              // test if serializer and event pipeline are cacheable
              long readerKey = 0;
              CacheValidity readerValidity = null;
              if (this.reader instanceof Cacheable
                  && (readerKey = ((Cacheable)this.reader).generateKey()) != 0
                  && (readerValidity = ((Cacheable)this.reader).generateValidity()) != 
null ){
  
                  // response is cacheable, build the key
                  ComponentCacheKey ccKey;
                  pcKey = new PipelineCacheKey();
                  ccKey = new ComponentCacheKey(ComponentCacheKey.ComponentType_Reader,
                                                  this.readerRole,
                                                  readerKey);
                  validityObjects.put(ccKey, readerValidity);
                  pcKey.addKey(ccKey);
  
                  // 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[] response = cachedObject.getResponse();
                          if(response.length > 0) {
                              usedCache = true;
                              environment.setContentLength(response.length);
                              outputStream.write(response);
                          }
                      }
  
                      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);
                  }
              }
  
              if (!usedCache) {
  
                  if (this.reader.shouldSetContentLength()) {
                      ByteArrayOutputStream os = new ByteArrayOutputStream();
                      this.reader.setOutputStream(os);
                      this.reader.generate();
                      byte[] data = os.toByteArray();
                      environment.setContentLength(data.length);
                      outputStream.write(data);
                  } else {
                      this.reader.setOutputStream(outputStream);
                      this.reader.generate();
                  }
  
                  // store the response
                  if (pcKey != null) {
                      this.streamCache.store(pcKey,
                          new CachedStreamObject(validityObjects,
                                ((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 {
                  getLogger().debug("SocketException in ProcessReader", 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
              );
          }
  
          return true;
      }
       */
  
     /**
       * 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.generatorRole = null;
          this.transformerRoles.clear();
          this.serializerRole = null;
          this.readerRole = null;
  
          this.notCacheableTransformers.clear();
          this.validityObjects = null;
          this.pipelineCacheKey = null;
      }
  
      /**
       * Disposable Interface
       */
      public void dispose() {
          this.manager.release(this.cache);
      }
  }
  
  
  
  1.1                  
xml-cocoon2/src/java/org/apache/cocoon/components/pipeline/impl/NonCachingProcessingPipeline.java
  
  Index: NonCachingProcessingPipeline.java
  ===================================================================
  /*
  
   ============================================================================
                     The Apache Software License, Version 1.1
   ============================================================================
  
   Copyright (C) 1999-2002 The Apache Software Foundation. All rights reserved.
  
   Redistribution and use in source and binary forms, with or without modifica-
   tion, are permitted provided that the following conditions are met:
  
   1. Redistributions of  source code must  retain the above copyright  notice,
      this list of conditions and the following disclaimer.
  
   2. Redistributions in binary form must reproduce the above copyright notice,
      this list of conditions and the following disclaimer in the documentation
      and/or other materials provided with the distribution.
  
   3. The end-user documentation included with the redistribution, if any, must
      include  the following  acknowledgment:  "This product includes  software
      developed  by the  Apache Software Foundation  (http://www.apache.org/)."
      Alternately, this  acknowledgment may  appear in the software itself,  if
      and wherever such third-party acknowledgments normally appear.
  
   4. The names "Apache Cocoon" and  "Apache Software Foundation" must  not  be
      used to  endorse or promote  products derived from  this software without
      prior written permission. For written permission, please contact
      [EMAIL PROTECTED]
  
   5. Products  derived from this software may not  be called "Apache", nor may
      "Apache" appear  in their name,  without prior written permission  of the
      Apache Software Foundation.
  
   THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
   INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
   FITNESS  FOR A PARTICULAR  PURPOSE ARE  DISCLAIMED.  IN NO  EVENT SHALL  THE
   APACHE SOFTWARE  FOUNDATION  OR ITS CONTRIBUTORS  BE LIABLE FOR  ANY DIRECT,
   INDIRECT, INCIDENTAL, SPECIAL,  EXEMPLARY, OR CONSEQUENTIAL  DAMAGES (INCLU-
   DING, BUT NOT LIMITED TO, PROCUREMENT  OF SUBSTITUTE GOODS OR SERVICES; LOSS
   OF USE, DATA, OR  PROFITS; OR BUSINESS  INTERRUPTION)  HOWEVER CAUSED AND ON
   ANY  THEORY OF LIABILITY,  WHETHER  IN CONTRACT,  STRICT LIABILITY,  OR TORT
   (INCLUDING  NEGLIGENCE OR  OTHERWISE) ARISING IN  ANY WAY OUT OF THE  USE OF
   THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  
   This software  consists of voluntary contributions made  by many individuals
   on  behalf of the Apache Software  Foundation and was  originally created by
   Stefano Mazzocchi  <[EMAIL PROTECTED]>. For more  information on the Apache
   Software Foundation, please see <http://www.apache.org/>.
  
  */
  package org.apache.cocoon.components.pipeline.impl;
  
  import org.apache.cocoon.components.pipeline.AbstractProcessingPipeline;
  
  /**
   * Thi is the implementation of the non caching processing pipeline
   *
   * @author <a href="mailto:[EMAIL PROTECTED]";>Carsten Ziegeler</a>
   * @version CVS $Id: NonCachingProcessingPipeline.java,v 1.1 2002/05/02 14:48:53 
cziegeler Exp $
   */
  public class NonCachingProcessingPipeline
         extends AbstractProcessingPipeline {
  }
  
  
  

----------------------------------------------------------------------
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