cziegeler 02/05/03 07:47:33
Modified: src/java/org/apache/cocoon/components/pipeline
AbstractProcessingPipeline.java
src/java/org/apache/cocoon/components/pipeline/impl
CachingProcessingPipeline.java
Log:
Some minor updates on the xml processing pipeline
Revision Changes Path
1.6 +53 -17
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.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- AbstractProcessingPipeline.java 3 May 2002 11:55:05 -0000 1.5
+++ AbstractProcessingPipeline.java 3 May 2002 14:47:33 -0000 1.6
@@ -57,6 +57,7 @@
import org.apache.avalon.framework.component.ComponentSelector;
import org.apache.avalon.framework.logger.AbstractLogEnabled;
import org.apache.avalon.framework.parameters.Parameters;
+import org.apache.cocoon.ConnectionResetException;
import org.apache.cocoon.ProcessingException;
import org.apache.cocoon.components.pipeline.OutputComponentSelector;
import org.apache.cocoon.components.saxconnector.SAXConnector;
@@ -70,6 +71,8 @@
import org.xml.sax.SAXException;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
+import java.io.OutputStream;
+import java.net.SocketException;
import java.util.ArrayList;
import java.util.Iterator;
@@ -77,7 +80,7 @@
* This is the base for all implementations of a <code>ProcessingPipeline</code>.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Carsten Ziegeler</a>
- * @version CVS $Id: AbstractProcessingPipeline.java,v 1.5 2002/05/03 11:55:05
cziegeler Exp $
+ * @version CVS $Id: AbstractProcessingPipeline.java,v 1.6 2002/05/03 14:47:33
cziegeler Exp $
*/
public abstract class AbstractProcessingPipeline
extends AbstractLogEnabled
@@ -430,7 +433,15 @@
throw new ProcessingException("Attempted to process incomplete
pipeline.");
}
if ( this.reader != null ) {
- return this.processReader(environment);
+ this.setupReader( environment );
+ if (this.checkLastModified( environment )) {
+ return true;
+ }
+ try {
+ return this.processReader(environment,
environment.getOutputStream());
+ } catch (IOException ioe) {
+ throw new ProcessingException("Processing of reader pipeline
failed.", ioe);
+ }
} else {
this.setupPipeline(environment);
this.connectPipeline(environment);
@@ -474,13 +485,12 @@
}
/**
- * Process the pipeline using a reader.
- * @throws ProcessingException if
+ * Setup the reader
*/
- protected boolean processReader(Environment environment)
+ protected void setupReader(Environment environment)
throws ProcessingException {
- String mimeType;
try {
+ String mimeType;
this.reader.setup(environment,environment.getObjectModel(),readerSource,readerParam);
mimeType = this.reader.getMimeType();
if ( mimeType != null ) {
@@ -490,31 +500,57 @@
} else {
environment.setContentType(this.sitemapReaderMimeType);
}
- // has the read resource been modified?
- long lastModified = this.reader.getLastModified();
- if (lastModified != 0
- && !environment.isResponseModified(lastModified)) {
+ } catch (SAXException e){
+ throw new ProcessingException("Failed to execute reader pipeline.", e);
+ } catch (IOException e){
+ throw new ProcessingException("Failed to execute reader pipeline.", e);
+ }
+ }
- // environment supports this, so we are finished
- environment.setResponseIsNotModified();
- return true;
- }
+ protected boolean checkLastModified(Environment environment)
+ throws ProcessingException {
+ // 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;
+ }
+ return false;
+ }
+ /**
+ * Process the pipeline using a reader.
+ * @throws ProcessingException if
+ */
+ protected boolean processReader(Environment environment,
+ OutputStream outputStream)
+ throws ProcessingException {
+ try {
if (this.reader.shouldSetContentLength()) {
ByteArrayOutputStream os = new ByteArrayOutputStream();
this.reader.setOutputStream(os);
this.reader.generate();
byte[] data = os.toByteArray();
environment.setContentLength(data.length);
- environment.getOutputStream().write(data);
+ outputStream.write(data);
} else {
- this.reader.setOutputStream(environment.getOutputStream());
+ this.reader.setOutputStream(outputStream);
this.reader.generate();
}
+ } 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("Error reading resource",e);
+ throw new ProcessingException("Error executing reader pipeline.",e);
}
return true;
}
1.2 +96 -122
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.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- CachingProcessingPipeline.java 2 May 2002 14:48:53 -0000 1.1
+++ CachingProcessingPipeline.java 3 May 2002 14:47:33 -0000 1.2
@@ -55,6 +55,7 @@
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.ConnectionResetException;
import org.apache.cocoon.ProcessingException;
import org.apache.cocoon.caching.*;
import org.apache.cocoon.components.pipeline.AbstractProcessingPipeline;
@@ -70,6 +71,8 @@
import org.xml.sax.SAXException;
import java.io.IOException;
+import java.io.OutputStream;
+import java.net.SocketException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
@@ -80,7 +83,7 @@
*
*
* @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 $
+ * @version CVS $Id: CachingProcessingPipeline.java,v 1.2 2002/05/03 14:47:33
cziegeler Exp $
*/
public class CachingProcessingPipeline
extends AbstractProcessingPipeline
@@ -103,7 +106,7 @@
private ArrayList notCacheableTransformers = new ArrayList();
private Map validityObjects;
- private PipelineCacheKey pipelineCacheKey;
+ private StringBuffer pipelineCacheKey;
private int firstNotCacheableTransformerIndex;
@@ -255,55 +258,69 @@
this.firstNotCacheableTransformerIndex = 0;
+ // first step is to generate the key:
+ // All pipeline components starting with the generator
+ // are tested if they are either a CacheableProcessingComponent
+ // or Cacheable (obsolete). The returned keys are chained together
+ // to build a unique key of the request
+
// 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(
+ long key = 0;
+ if (this.generator instanceof CacheableProcessingComponent) {
+ key = ((CacheableProcessingComponent)this.generator).generateKey();
+ } else if (this.generator instanceof Cacheable) {
+ key = ((Cacheable)this.generator).generateKey();
+ }
+
+ if (key != 0) {
+ // CacheValidity validity =
((Cacheable)this.generator).generateValidity();
+ 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++;
- }
+ this.pipelineCacheKey = new StringBuffer();
+ this.pipelineCacheKey.append("PCK:CCK:1-")
+ .append(this.generatorRole).append('-')
+ .append(key);
+
+ // now testing transformers
+ Transformer trans;
+ final int transformerSize = this.transformers.size();
+ boolean testTrans = true;
+
+ while (this.firstNotCacheableTransformerIndex < transformerSize
+ && testTrans) {
+ trans =
(Transformer)this.transformers.get(this.firstNotCacheableTransformerIndex);
+ key = 0;
+ if (trans instanceof CacheableProcessingComponent) {
+ key = ((CacheableProcessingComponent)trans).generateKey();
+ } else if (trans instanceof Cacheable) {
+ key = ((Cacheable)trans).generateKey();
+ }
+ if (key != 0) {
+ this.pipelineCacheKey.append("CCK:2-")
+
.append((String)this.transformerRoles.get(this.firstNotCacheableTransformerIndex))
+ .append('-')
+ .append(key);
+ this.firstNotCacheableTransformerIndex++;
+ } else {
+ testTrans = false;
}
- // all transformers are cacheable => pipeline is cacheable
- if (this.firstNotCacheableTransformerIndex == transformerSize) {
+ }
+ // all transformers are cacheable => pipeline is cacheable
+ if (this.firstNotCacheableTransformerIndex == transformerSize
+ && this.serializer == this.lastConsumer) {
+
+ if (this.serializer instanceof CacheableProcessingComponent) {
+ key =
((CacheableProcessingComponent)this.serializer).generateKey();
+ } else if (this.serializer instanceof Cacheable) {
+ key = ((Cacheable)this.serializer).generateKey();
+ }
+ if (key != 0) {
+ this.pipelineCacheKey.append("CCK:3-")
+ .append(this.serializerRole)
+ .append('-')
+ .append(key);
// FIXME - WE ARE CACHEABLE
}
}
@@ -388,80 +405,43 @@
*/
/** Process the pipeline using a reader.
- * @throws ProcessingException if
+ * @throws ProcessingException if an error occurs
+ */
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;
+ OutputStream outputStream = environment.getOutputStream();;
Map validityObjects = new HashMap();
- outputStream = environment.getOutputStream();
-
- // test if serializer and event pipeline are cacheable
+ // test if reader is cacheable
long readerKey = 0;
- CacheValidity readerValidity = null;
- if (this.reader instanceof Cacheable
- && (readerKey = ((Cacheable)this.reader).generateKey()) != 0
- && (readerValidity = ((Cacheable)this.reader).generateValidity())
!= null ){
+ boolean isCacheable = false;
+ boolean isCacheableProcessingComponent = false;
+ if (this.reader instanceof CacheableProcessingComponent) {
+ readerKey =
((CacheableProcessingComponent)this.reader).generateKey();
+ } else if (this.reader instanceof Cacheable) {
+ readerKey = ((Cacheable)this.reader).generateKey();
+ }
+ if ( readerKey != 0) {
// 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);
+ StringBuffer pcKey = new StringBuffer();
+ pcKey.append("PCK:CCK:4-").append(this.readerRole)
+ .append('-')
+ .append(readerKey);
// now we have the key to get the cached object
- CachedStreamObject cachedObject =
(CachedStreamObject)this.streamCache.get(pcKey);
+ CachedStreamObject cachedObject =
(CachedStreamObject)this.cache.get(pcKey);
if (cachedObject != null) {
- getLogger().debug("Found cached response for '" +
environment.getURI() + "'.");
-
- Iterator validityIterator = validityObjects.keySet().iterator();
+ if (this.getLogger().isDebugEnabled()) {
+ this.getLogger().debug("Found cached response for '" +
environment.getURI() + "'.");
+ }
+ }
+ }
+ /* Iterator validityIterator =
validityObjects.keySet().iterator();
ComponentCacheKey validityKey;
boolean valid = true;
while (validityIterator.hasNext() && valid) {
@@ -497,28 +477,20 @@
getLogger().debug("Caching content for further requests of '" +
environment.getURI() + "'.");
outputStream = new CachingOutputStream(outputStream);
}
- }
+ validityObjects.put(ccKey, readerValidity);
+ }
+*/
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();
- }
+ super.processReader( environment, outputStream );
// store the response
- if (pcKey != null) {
- this.streamCache.store(pcKey,
+ /* if (pcKey != null) {
+ this.cache.store(pcKey,
new CachedStreamObject(validityObjects,
((CachingOutputStream)outputStream).getContent()));
- }
+ }*/
}
} catch ( SocketException se ) {
if (se.getMessage().indexOf("reset") > 0
@@ -545,7 +517,7 @@
return true;
}
- */
+
/**
* Process the request.
@@ -705,5 +677,7 @@
*/
public void dispose() {
this.manager.release(this.cache);
+ this.cache = null;
+ this.manager = null;
}
}
----------------------------------------------------------------------
In case of troubles, e-mail: [EMAIL PROTECTED]
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]