8 Jun 2008 19:26
svn commit: r664529 - in /cocoon/whiteboard/corona/trunk/corona-pipeline/src/main/java/org/apache/cocoon/corona/pipeline: ./ caching/ component/
<reinhard <at> apache.org>
2008-06-08 17:26:43 GMT
2008-06-08 17:26:43 GMT
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 <at> <at> -171,6 +171,10 <at> <at> ((Producer) firstComponent).setConsumer((Consumer) secondComponent); } + public long getLastModified() { + return -1; + } + <at> 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 <at> <at> -67,10 +67,10 <at> <at> 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()) { <at> <at> -78,12 +78,12 <at> <at> } 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; <at> <at> -92,7 +92,7 <at> <at> // 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 <at> <at> -44,6 +44,8 <at> <at> protected PipelineCache pipelineCache; + protected CacheKey cacheKey; + <at> Override public void execute(Map<String, Object> parameters, OutputStream outputStream) throws Exception { if (this.logger.isDebugEnabled()) { <at> <at> -56,12 +58,10 <at> <at> 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); <at> <at> -75,14 +75,22 <at> <at> 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() { + <at> 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 <at> <at> -76,4 +76,11 <at> <at> void execute(Map<String, Object> parameters, OutputStream outputStream) throws Exception; String getContentType(); + + /** + * Get the time of the last modification. + * + * <at> 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 <at> <at> -21,4 +21,6 <at> <at> 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 <at> <at> -116,6 +116,21 <at> <at> 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; + } + <at> 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 <at> <at> -36,6 +36,10 <at> <at> return true; } + public long getLastModifed() { + return 0; + } + <at> 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 <at> <at> -50,6 +50,10 <at> <at> return this.timestamp; } + public long getLastModifed() { + return this.getTimestamp(); + } + <at> 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 <at> <at> -27,12 +27,16 <at> <at> 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() { <at> <at> -53,8 +57,7 <at> <at> 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; <at> <at> -80,12 +83,13 <at> <at> 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 <at> <at> -27,9 +27,13 <at> <at> 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; <at> <at> -53,8 +57,7 <at> <at> 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; <at> <at> -86,13 +89,14 <at> <at> } } 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 <at> <at> -31,12 +31,15 <at> <at> 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(); <at> <at> -120,7 +123,7 <at> <at> 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); } }
RSS Feed