You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@cocoon.apache.org by re...@apache.org on 2008/06/08 19:26:43 UTC

svn commit: r664529 - in /cocoon/whiteboard/corona/trunk/corona-pipeline/src/main/java/org/apache/cocoon/corona/pipeline: ./ caching/ component/

Author: reinhard
Date: Sun Jun  8 10:26:43 2008
New Revision: 664529

URL: http://svn.apache.org/viewvc?rev=664529&view=rev
Log:
. add getLastModified() method to Pipeline and CacheKey interface in order to make the last modification date externally available
. replace printStackTrace with logging statements

Modified:
    cocoon/whiteboard/corona/trunk/corona-pipeline/src/main/java/org/apache/cocoon/corona/pipeline/AbstractPipeline.java
    cocoon/whiteboard/corona/trunk/corona-pipeline/src/main/java/org/apache/cocoon/corona/pipeline/AsyncCachePipeline.java
    cocoon/whiteboard/corona/trunk/corona-pipeline/src/main/java/org/apache/cocoon/corona/pipeline/CachingPipeline.java
    cocoon/whiteboard/corona/trunk/corona-pipeline/src/main/java/org/apache/cocoon/corona/pipeline/Pipeline.java
    cocoon/whiteboard/corona/trunk/corona-pipeline/src/main/java/org/apache/cocoon/corona/pipeline/caching/CacheKey.java
    cocoon/whiteboard/corona/trunk/corona-pipeline/src/main/java/org/apache/cocoon/corona/pipeline/caching/CompoundCacheKey.java
    cocoon/whiteboard/corona/trunk/corona-pipeline/src/main/java/org/apache/cocoon/corona/pipeline/caching/SimpleCacheKey.java
    cocoon/whiteboard/corona/trunk/corona-pipeline/src/main/java/org/apache/cocoon/corona/pipeline/caching/TimestampCacheKey.java
    cocoon/whiteboard/corona/trunk/corona-pipeline/src/main/java/org/apache/cocoon/corona/pipeline/component/FileGenerator.java
    cocoon/whiteboard/corona/trunk/corona-pipeline/src/main/java/org/apache/cocoon/corona/pipeline/component/FileReaderComponent.java
    cocoon/whiteboard/corona/trunk/corona-pipeline/src/main/java/org/apache/cocoon/corona/pipeline/component/XMLSerializer.java

Modified: cocoon/whiteboard/corona/trunk/corona-pipeline/src/main/java/org/apache/cocoon/corona/pipeline/AbstractPipeline.java
URL: http://svn.apache.org/viewvc/cocoon/whiteboard/corona/trunk/corona-pipeline/src/main/java/org/apache/cocoon/corona/pipeline/AbstractPipeline.java?rev=664529&r1=664528&r2=664529&view=diff
==============================================================================
--- cocoon/whiteboard/corona/trunk/corona-pipeline/src/main/java/org/apache/cocoon/corona/pipeline/AbstractPipeline.java (original)
+++ cocoon/whiteboard/corona/trunk/corona-pipeline/src/main/java/org/apache/cocoon/corona/pipeline/AbstractPipeline.java Sun Jun  8 10:26:43 2008
@@ -171,6 +171,10 @@
         ((Producer) firstComponent).setConsumer((Consumer) secondComponent);
     }
 
+    public long getLastModified() {
+        return -1;
+    }
+
     @Override
     public String toString() {
         return StringRepresentation.buildString(this, "components=" + this.getComponents());

Modified: cocoon/whiteboard/corona/trunk/corona-pipeline/src/main/java/org/apache/cocoon/corona/pipeline/AsyncCachePipeline.java
URL: http://svn.apache.org/viewvc/cocoon/whiteboard/corona/trunk/corona-pipeline/src/main/java/org/apache/cocoon/corona/pipeline/AsyncCachePipeline.java?rev=664529&r1=664528&r2=664529&view=diff
==============================================================================
--- cocoon/whiteboard/corona/trunk/corona-pipeline/src/main/java/org/apache/cocoon/corona/pipeline/AsyncCachePipeline.java (original)
+++ cocoon/whiteboard/corona/trunk/corona-pipeline/src/main/java/org/apache/cocoon/corona/pipeline/AsyncCachePipeline.java Sun Jun  8 10:26:43 2008
@@ -67,10 +67,10 @@
         this.setupComponents(parameters, cachingOutputStream);
 
         // construct the current cache key
-        CacheKey cacheKey = this.constructCacheKey();
+        this.cacheKey = this.constructCacheKey();
 
         // check for a cached value first
-        CacheValue cachedValue = this.getCachedValue(cacheKey);
+        CacheValue cachedValue = this.getCachedValue(this.cacheKey);
         if (cachedValue != null) {
             // cached value found -> write it
             if (this.logger.isDebugEnabled()) {
@@ -78,12 +78,12 @@
             }
             cachedValue.writeTo(outputStream);
 
-            if (!cachedValue.isValid(cacheKey)) {
+            if (!cachedValue.isValid(this.cacheKey)) {
                 if (this.logger.isDebugEnabled()) {
                     this.logger.debug("Cached value is not up to date. Delegating to " + this.cacheRefreshManager);
                 }
                 // the cached value is not valid -> refresh the value
-                this.cacheRefreshManager.refreshCacheValue(cacheKey, this);
+                this.cacheRefreshManager.refreshCacheValue(this.cacheKey, this);
             }
             // stop here
             return;
@@ -92,7 +92,7 @@
         // no cached value (not even an invalid one) was present -> execute the pipeline
         this.invokeStarter();
         // cache the result
-        this.setCachedValue(cacheKey, new CompleteCacheValue(cachingOutputStream.getContent(), cacheKey));
+        this.setCachedValue(this.cacheKey, new CompleteCacheValue(cachingOutputStream.getContent(), this.cacheKey));
     }
 
     public CacheRefreshManager getCacheRefreshManager() {

Modified: cocoon/whiteboard/corona/trunk/corona-pipeline/src/main/java/org/apache/cocoon/corona/pipeline/CachingPipeline.java
URL: http://svn.apache.org/viewvc/cocoon/whiteboard/corona/trunk/corona-pipeline/src/main/java/org/apache/cocoon/corona/pipeline/CachingPipeline.java?rev=664529&r1=664528&r2=664529&view=diff
==============================================================================
--- cocoon/whiteboard/corona/trunk/corona-pipeline/src/main/java/org/apache/cocoon/corona/pipeline/CachingPipeline.java (original)
+++ cocoon/whiteboard/corona/trunk/corona-pipeline/src/main/java/org/apache/cocoon/corona/pipeline/CachingPipeline.java Sun Jun  8 10:26:43 2008
@@ -44,6 +44,8 @@
 
     protected PipelineCache pipelineCache;
 
+    protected CacheKey cacheKey;
+
     @Override
     public void execute(Map<String, Object> parameters, OutputStream outputStream) throws Exception {
         if (this.logger.isDebugEnabled()) {
@@ -56,12 +58,10 @@
         CachingOutputStream cachingOutputStream = new CachingOutputStream(outputStream);
         this.setupComponents(parameters, cachingOutputStream);
 
-        // construct the current cache key
-        CacheKey cacheKey = this.constructCacheKey();
-
+        this.cacheKey = this.constructCacheKey();
         // checked for a cached value first
-        CacheValue cachedValue = this.getCachedValue(cacheKey);
-        if (cachedValue != null && cachedValue.isValid(cacheKey)) {
+        CacheValue cachedValue = this.getCachedValue(this.cacheKey);
+        if (cachedValue != null && cachedValue.isValid(this.cacheKey)) {
             // cached value found
             if (this.logger.isDebugEnabled()) {
                 this.logger.debug("Write cache value to output stream: " + cachedValue);
@@ -75,14 +75,22 @@
         this.invokeStarter();
 
         // cache the result
-        this.setCachedValue(cacheKey, new CompleteCacheValue(cachingOutputStream.getContent(), cacheKey));
+        this.setCachedValue(this.cacheKey, new CompleteCacheValue(cachingOutputStream.getContent(), this.cacheKey));
     }
 
     public void setPipelineCache(PipelineCache pipelineCache) {
         this.pipelineCache = pipelineCache;
     }
 
-    protected CacheKey constructCacheKey() {
+    @Override
+    public long getLastModified() {
+        if (this.cacheKey == null) {
+            return -1;
+        }
+        return this.cacheKey.getLastModifed();
+    }
+
+    public CacheKey constructCacheKey() {
         CompoundCacheKey result = new CompoundCacheKey();
         if (this.logger.isDebugEnabled()) {
             this.logger.debug("Creating " + result + ": ");

Modified: cocoon/whiteboard/corona/trunk/corona-pipeline/src/main/java/org/apache/cocoon/corona/pipeline/Pipeline.java
URL: http://svn.apache.org/viewvc/cocoon/whiteboard/corona/trunk/corona-pipeline/src/main/java/org/apache/cocoon/corona/pipeline/Pipeline.java?rev=664529&r1=664528&r2=664529&view=diff
==============================================================================
--- cocoon/whiteboard/corona/trunk/corona-pipeline/src/main/java/org/apache/cocoon/corona/pipeline/Pipeline.java (original)
+++ cocoon/whiteboard/corona/trunk/corona-pipeline/src/main/java/org/apache/cocoon/corona/pipeline/Pipeline.java Sun Jun  8 10:26:43 2008
@@ -76,4 +76,11 @@
     void execute(Map<String, Object> parameters, OutputStream outputStream) throws Exception;
 
     String getContentType();
+
+    /**
+     * Get the time of the last modification.
+     * 
+     * @return The last modification date
+     */
+    long getLastModified();
 }

Modified: cocoon/whiteboard/corona/trunk/corona-pipeline/src/main/java/org/apache/cocoon/corona/pipeline/caching/CacheKey.java
URL: http://svn.apache.org/viewvc/cocoon/whiteboard/corona/trunk/corona-pipeline/src/main/java/org/apache/cocoon/corona/pipeline/caching/CacheKey.java?rev=664529&r1=664528&r2=664529&view=diff
==============================================================================
--- cocoon/whiteboard/corona/trunk/corona-pipeline/src/main/java/org/apache/cocoon/corona/pipeline/caching/CacheKey.java (original)
+++ cocoon/whiteboard/corona/trunk/corona-pipeline/src/main/java/org/apache/cocoon/corona/pipeline/caching/CacheKey.java Sun Jun  8 10:26:43 2008
@@ -21,4 +21,6 @@
 public interface CacheKey {
 
     boolean isValid(CacheKey cacheKey);
+
+    long getLastModifed();
 }

Modified: cocoon/whiteboard/corona/trunk/corona-pipeline/src/main/java/org/apache/cocoon/corona/pipeline/caching/CompoundCacheKey.java
URL: http://svn.apache.org/viewvc/cocoon/whiteboard/corona/trunk/corona-pipeline/src/main/java/org/apache/cocoon/corona/pipeline/caching/CompoundCacheKey.java?rev=664529&r1=664528&r2=664529&view=diff
==============================================================================
--- cocoon/whiteboard/corona/trunk/corona-pipeline/src/main/java/org/apache/cocoon/corona/pipeline/caching/CompoundCacheKey.java (original)
+++ cocoon/whiteboard/corona/trunk/corona-pipeline/src/main/java/org/apache/cocoon/corona/pipeline/caching/CompoundCacheKey.java Sun Jun  8 10:26:43 2008
@@ -116,6 +116,21 @@
         return true;
     }
 
+    public long getLastModifed() {
+        long lastModified = 0;
+        for (CacheKey eachKey : this.cacheKeys) {
+            long eachLastModified = eachKey.getLastModifed();
+            if (eachLastModified == -1) {
+                return -1;
+            }
+            if (eachLastModified > lastModified) {
+                lastModified = eachLastModified;
+                continue;
+            }
+        }
+        return lastModified;
+    }
+
     @Override
     public String toString() {
         return StringRepresentation.buildString(this, "key=" + this.cacheKeys);

Modified: cocoon/whiteboard/corona/trunk/corona-pipeline/src/main/java/org/apache/cocoon/corona/pipeline/caching/SimpleCacheKey.java
URL: http://svn.apache.org/viewvc/cocoon/whiteboard/corona/trunk/corona-pipeline/src/main/java/org/apache/cocoon/corona/pipeline/caching/SimpleCacheKey.java?rev=664529&r1=664528&r2=664529&view=diff
==============================================================================
--- cocoon/whiteboard/corona/trunk/corona-pipeline/src/main/java/org/apache/cocoon/corona/pipeline/caching/SimpleCacheKey.java (original)
+++ cocoon/whiteboard/corona/trunk/corona-pipeline/src/main/java/org/apache/cocoon/corona/pipeline/caching/SimpleCacheKey.java Sun Jun  8 10:26:43 2008
@@ -36,6 +36,10 @@
         return true;
     }
 
+    public long getLastModifed() {
+        return 0;
+    }
+
     @Override
     public String toString() {
         return StringRepresentation.buildString(this);

Modified: cocoon/whiteboard/corona/trunk/corona-pipeline/src/main/java/org/apache/cocoon/corona/pipeline/caching/TimestampCacheKey.java
URL: http://svn.apache.org/viewvc/cocoon/whiteboard/corona/trunk/corona-pipeline/src/main/java/org/apache/cocoon/corona/pipeline/caching/TimestampCacheKey.java?rev=664529&r1=664528&r2=664529&view=diff
==============================================================================
--- cocoon/whiteboard/corona/trunk/corona-pipeline/src/main/java/org/apache/cocoon/corona/pipeline/caching/TimestampCacheKey.java (original)
+++ cocoon/whiteboard/corona/trunk/corona-pipeline/src/main/java/org/apache/cocoon/corona/pipeline/caching/TimestampCacheKey.java Sun Jun  8 10:26:43 2008
@@ -50,6 +50,10 @@
         return this.timestamp;
     }
 
+    public long getLastModifed() {
+        return this.getTimestamp();
+    }
+
     @Override
     public int hashCode() {
         return this.url.hashCode();

Modified: cocoon/whiteboard/corona/trunk/corona-pipeline/src/main/java/org/apache/cocoon/corona/pipeline/component/FileGenerator.java
URL: http://svn.apache.org/viewvc/cocoon/whiteboard/corona/trunk/corona-pipeline/src/main/java/org/apache/cocoon/corona/pipeline/component/FileGenerator.java?rev=664529&r1=664528&r2=664529&view=diff
==============================================================================
--- cocoon/whiteboard/corona/trunk/corona-pipeline/src/main/java/org/apache/cocoon/corona/pipeline/component/FileGenerator.java (original)
+++ cocoon/whiteboard/corona/trunk/corona-pipeline/src/main/java/org/apache/cocoon/corona/pipeline/component/FileGenerator.java Sun Jun  8 10:26:43 2008
@@ -27,12 +27,16 @@
 import org.apache.cocoon.corona.pipeline.caching.CacheKey;
 import org.apache.cocoon.corona.pipeline.caching.TimestampCacheKey;
 import org.apache.cocoon.corona.pipeline.util.StringRepresentation;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
 import org.xml.sax.InputSource;
 import org.xml.sax.XMLReader;
 import org.xml.sax.helpers.XMLReaderFactory;
 
 public class FileGenerator extends AbstractXMLProducer implements Starter, CachingPipelineComponent {
 
+    private final Log logger = LogFactory.getLog(this.getClass());
+
     private URL source;
 
     public FileGenerator() {
@@ -53,8 +57,7 @@
         try {
             return new TimestampCacheKey(this.source, this.source.openConnection().getLastModified());
         } catch (IOException e) {
-            // TODO Auto-generated catch block
-            e.printStackTrace();
+            this.logger.error("Can't construct cache key. Error while connecting to " + this.source, e);
         }
 
         return null;
@@ -80,12 +83,13 @@
             inputStream = new BufferedInputStream(this.source.openStream());
             xmlReader.parse(new InputSource(inputStream));
         } catch (Exception e) {
+            this.logger.error("Can't parse " + this.source, e);
             throw new RuntimeException(e);
         } finally {
             try {
                 inputStream.close();
             } catch (IOException e) {
-                e.printStackTrace();
+                this.logger.error("Error while closing input stream on " + this.source, e);
             }
         }
     }

Modified: cocoon/whiteboard/corona/trunk/corona-pipeline/src/main/java/org/apache/cocoon/corona/pipeline/component/FileReaderComponent.java
URL: http://svn.apache.org/viewvc/cocoon/whiteboard/corona/trunk/corona-pipeline/src/main/java/org/apache/cocoon/corona/pipeline/component/FileReaderComponent.java?rev=664529&r1=664528&r2=664529&view=diff
==============================================================================
--- cocoon/whiteboard/corona/trunk/corona-pipeline/src/main/java/org/apache/cocoon/corona/pipeline/component/FileReaderComponent.java (original)
+++ cocoon/whiteboard/corona/trunk/corona-pipeline/src/main/java/org/apache/cocoon/corona/pipeline/component/FileReaderComponent.java Sun Jun  8 10:26:43 2008
@@ -27,9 +27,13 @@
 
 import org.apache.cocoon.corona.pipeline.caching.CacheKey;
 import org.apache.cocoon.corona.pipeline.caching.TimestampCacheKey;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
 
 public class FileReaderComponent implements Starter, Finisher, CachingPipelineComponent {
 
+    private final Log logger = LogFactory.getLog(this.getClass());
+
     private String mimeType;
     private OutputStream outputStream;
     private URL source;
@@ -53,8 +57,7 @@
             URLConnection connection = this.source.openConnection();
             return new TimestampCacheKey(this.source, connection.getLastModified());
         } catch (IOException e) {
-            // TODO Auto-generated catch block
-            e.printStackTrace();
+            this.logger.error("Can't construct cache key. Error while connecting to " + this.source, e);
         }
 
         return null;
@@ -86,13 +89,14 @@
             }
 
         } catch (IOException e) {
-            // TODO: a specific exception is in order
-            throw new RuntimeException("FileReader cannot read from '" + this.source + "'", e);
+            String message = "FileReader cannot read from '" + this.source + "'";
+            this.logger.error(message, e);
+            throw new RuntimeException(message, e);
         } finally {
             try {
                 inputStream.close();
             } catch (IOException e) {
-                e.printStackTrace();
+                this.logger.error("Error while closing input stream on " + this.source, e);
             }
         }
     }

Modified: cocoon/whiteboard/corona/trunk/corona-pipeline/src/main/java/org/apache/cocoon/corona/pipeline/component/XMLSerializer.java
URL: http://svn.apache.org/viewvc/cocoon/whiteboard/corona/trunk/corona-pipeline/src/main/java/org/apache/cocoon/corona/pipeline/component/XMLSerializer.java?rev=664529&r1=664528&r2=664529&view=diff
==============================================================================
--- cocoon/whiteboard/corona/trunk/corona-pipeline/src/main/java/org/apache/cocoon/corona/pipeline/component/XMLSerializer.java (original)
+++ cocoon/whiteboard/corona/trunk/corona-pipeline/src/main/java/org/apache/cocoon/corona/pipeline/component/XMLSerializer.java Sun Jun  8 10:26:43 2008
@@ -31,12 +31,15 @@
 import org.apache.cocoon.corona.pipeline.caching.CacheKey;
 import org.apache.cocoon.corona.pipeline.caching.SimpleCacheKey;
 import org.apache.cocoon.corona.pipeline.util.StringRepresentation;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
 import org.xml.sax.Attributes;
 import org.xml.sax.Locator;
 import org.xml.sax.SAXException;
 
 public class XMLSerializer implements XMLConsumer, Finisher, CachingPipelineComponent {
 
+    private final Log logger = LogFactory.getLog(this.getClass());
     private static final SAXTransformerFactory SAX_TRANSFORMER_FACTORY = (SAXTransformerFactory) TransformerFactory
             .newInstance();
 
@@ -120,7 +123,7 @@
             this.transformerHandler.getTransformer().setOutputProperties(this.format);
             this.transformerHandler.setResult(new StreamResult(outputStream));
         } catch (TransformerConfigurationException e) {
-            e.printStackTrace();
+            this.logger.error("Can't configure trax transformer ", e);
         }
     }