cziegeler 02/05/28 01:55:54
Modified: src/java/org/apache/cocoon/components/pipeline/impl
CachingProcessingPipeline.java
Log:
Finished? caching pipeline (and correct cvs message, too)
Revision Changes Path
1.16 +23 -15
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.15
retrieving revision 1.16
diff -u -r1.15 -r1.16
--- CachingProcessingPipeline.java 28 May 2002 08:42:12 -0000 1.15
+++ CachingProcessingPipeline.java 28 May 2002 08:55:54 -0000 1.16
@@ -92,7 +92,7 @@
*
* @since @next-version@
* @author <a href="mailto:[EMAIL PROTECTED]">Carsten Ziegeler</a>
- * @version CVS $Id: CachingProcessingPipeline.java,v 1.15 2002/05/28 08:42:12
cziegeler Exp $
+ * @version CVS $Id: CachingProcessingPipeline.java,v 1.16 2002/05/28 08:55:54
cziegeler Exp $
*/
public class CachingProcessingPipeline
extends AbstractProcessingPipeline
@@ -113,8 +113,6 @@
/** The role name of the reader */
protected String readerRole;
- /** The index indicating to the first transformer which is not cacheable */
- protected int firstNotCacheableTransformerIndex;
/** The deserializer */
protected XMLDeserializer xmlDeserializer;
/** Complete response is cached */
@@ -122,15 +120,17 @@
/** The serializer */
protected XMLSerializer xmlSerializer;
- /** The cached validity objects */
- protected SourceValidity[] cachedValidityObjects;
/** The cached byte stream */
protected byte[] cachedResponse;
+ /** The index indicating the first transformer getting input from the cache */
+ protected int firstProcessedTransformerIndex;
/** The key to store the generated response */
protected PipelineCacheKey pipelineCacheKey;
/** The validity objects of the generated response */
protected SourceValidity[] pipelineValidityObjects;
+ /** The index indicating to the first transformer which is not cacheable */
+ protected int firstNotCacheableTransformerIndex;
/**
@@ -183,7 +183,7 @@
*/
protected boolean processXMLPipeline(Environment environment)
throws ProcessingException {
- if (this.pipelineCacheKey == null) {
+ if (this.pipelineCacheKey == null && this.cachedResponse == null) {
return super.processXMLPipeline( environment );
} else if (this.cachedResponse != null && this.completeResponseIsCached) {
try {
@@ -200,6 +200,8 @@
throw new ProcessingException("Failed to execute reader
pipeline.", se);
}
} catch ( Exception e ) {
+ if (e instanceof ProcessingException)
+ throw (ProcessingException)e;
throw new ProcessingException("Error executing reader pipeline.",e);
}
} else {
@@ -235,13 +237,13 @@
}
if (this.xmlSerializer != null) {
if ( this.completeResponseIsCached ) {
- CachedResponse response = new
CachedResponse(this.cachedValidityObjects,
+ CachedResponse response = new
CachedResponse(this.pipelineValidityObjects,
((CachingOutputStream)os).getContent());
this.cache.store(environment.getObjectModel(),
this.pipelineCacheKey,
response);
} else {
- CachedResponse response = new
CachedResponse(this.cachedValidityObjects,
+ CachedResponse response = new
CachedResponse(this.pipelineValidityObjects,
(byte[])this.xmlSerializer.getSAXFragment());
this.cache.store(environment.getObjectModel(),
this.pipelineCacheKey,
@@ -283,6 +285,7 @@
boolean[] transformerIsCacheableProcessingComponent = new
boolean[this.transformers.size()];
this.firstNotCacheableTransformerIndex = 0;
+ this.firstProcessedTransformerIndex = 0;
this.completeResponseIsCached = false;
// first step is to generate the key:
@@ -356,8 +359,10 @@
// first non cacheable
if (processingPipelineKey != null) {
cachedPipelineKey = processingPipelineKey.copy();
+ this.firstProcessedTransformerIndex =
this.firstNotCacheableTransformerIndex;
}
boolean finished = false;
+ SourceValidity[] cachedValidityObjects = null;
while (cachedPipelineKey != null && !finished) {
finished = true;
CachedResponse response = this.cache.get( cachedPipelineKey );
@@ -380,7 +385,7 @@
} else {
validity = new
CacheValidityToSourceValidity(((Cacheable)super.generator).generateValidity());
}
- } else if (i <= firstNotCacheableTransformerIndex + 1) {
+ } else if (i <= this.firstProcessedTransformerIndex + 1) {
// test transformer
final Transformer trans =
(Transformer)super.transformers.get(i-1);
@@ -412,7 +417,7 @@
if ( responseIsValid ) {
// we are valid, ok that's it
- this.cachedValidityObjects = validities;
+ cachedValidityObjects = validities;
} else {
// we are not valid!
this.completeResponseIsCached = false;
@@ -441,6 +446,7 @@
// try a shorter key
if (i > 0) {
cachedPipelineKey.removeLastKey();
+ this.firstProcessedTransformerIndex--;
} else {
cachedPipelineKey = null;
}
@@ -458,7 +464,7 @@
if (cachedPipelineKey != null) {
start = cachedPipelineKey.size();
for(int i=0; i<start;i++) {
- this.pipelineValidityObjects[i] =
this.cachedValidityObjects[i];
+ this.pipelineValidityObjects[i] = cachedValidityObjects[i];
}
}
for(int i=start; i < this.pipelineValidityObjects.length; i++) {
@@ -498,7 +504,7 @@
*/
protected void connectPipeline(Environment environment)
throws ProcessingException {
- if ( this.pipelineCacheKey == null ) {
+ if ( this.pipelineCacheKey == null && this.cachedResponse == null) {
super.connectPipeline( environment );
} else if (this.completeResponseIsCached) {
// do nothing
@@ -542,7 +548,7 @@
Iterator itt = this.transformers.iterator();
while ( itt.hasNext() ) {
next = (XMLConsumer) itt.next();
- if (cacheableTransformerCount >=
this.firstNotCacheableTransformerIndex) {
+ if (cacheableTransformerCount >=
this.firstProcessedTransformerIndex) {
this.connect(environment, prev, next);
prev = (XMLProducer)next;
}
@@ -697,7 +703,10 @@
* Otherwise return <code>null</code>
*/
public SourceValidity[] getValiditiesForEventPipeline() {
- // FIXME (CZ) - Implement this
+ if (!this.completeResponseIsCached
+ && this.firstNotCacheableTransformerIndex == super.transformers.size())
{
+ return this.pipelineValidityObjects;
+ }
return null;
}
@@ -721,7 +730,6 @@
this.pipelineCacheKey = null;
this.pipelineValidityObjects = null;
this.cachedResponse = null;
- this.cachedValidityObjects = null;
}
/**
----------------------------------------------------------------------
In case of troubles, e-mail: [EMAIL PROTECTED]
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]