cziegeler 01/04/17 03:33:21
Modified: src/org/apache/cocoon Tag: xml-cocoon2 Roles.java
cocoon.roles
src/org/apache/cocoon/caching Tag: xml-cocoon2
Cacheable.java ComponentCacheKey.java
EventCache.java EventMemoryCache.java
PipelineCacheKey.java
src/org/apache/cocoon/components/pipeline Tag: xml-cocoon2
CachingEventPipeline.java
NonCachingStreamPipeline.java
src/org/apache/cocoon/serialization Tag: xml-cocoon2
FOPSerializer.java
Added: src/org/apache/cocoon/caching Tag: xml-cocoon2
CachedEventObject.java CachedStreamObject.java
CachingOutputStream.java NOPCacheValidity.java
StreamCache.java StreamMemoryCache.java
src/org/apache/cocoon/components/pipeline Tag: xml-cocoon2
AbstractStreamPipeline.java
CacheableEventPipeline.java
CachingStreamPipeline.java
Removed: src/org/apache/cocoon/caching Tag: xml-cocoon2
CachedObject.java
Log:
The second step of the caching: cacheable stream pipelines and FOP as a
cacheable example
Revision Changes Path
No revision
No revision
1.1.2.13 +2 -1 xml-cocoon/src/org/apache/cocoon/Attic/Roles.java
Index: Roles.java
===================================================================
RCS file: /home/cvs/xml-cocoon/src/org/apache/cocoon/Attic/Roles.java,v
retrieving revision 1.1.2.12
retrieving revision 1.1.2.13
diff -u -r1.1.2.12 -r1.1.2.13
--- Roles.java 2001/04/13 17:39:51 1.1.2.12
+++ Roles.java 2001/04/17 10:32:38 1.1.2.13
@@ -12,7 +12,7 @@
* Created this interface to specify the Avalon role names.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Berin Loritsch</a>
- * @version CVS $Revision: 1.1.2.12 $ $Date: 2001/04/13 17:39:51 $
+ * @version CVS $Revision: 1.1.2.13 $ $Date: 2001/04/17 10:32:38 $
*/
public interface Roles {
@@ -48,5 +48,6 @@
String XML_SERIALIZER = "org.apache.cocoon.components.sax.XMLSerializer";
String XML_DESERIALIZER =
"org.apache.cocoon.components.sax.XMLDeserializer";
String EVENT_CACHE = "org.apache.cocoon.caching.EventCache";
+ String STREAM_CACHE = "org.apache.cocoon.caching.StreamCache";
}
1.1.2.4 +4 -0 xml-cocoon/src/org/apache/cocoon/Attic/cocoon.roles
Index: cocoon.roles
===================================================================
RCS file: /home/cvs/xml-cocoon/src/org/apache/cocoon/Attic/cocoon.roles,v
retrieving revision 1.1.2.3
retrieving revision 1.1.2.4
diff -u -r1.1.2.3 -r1.1.2.4
--- cocoon.roles 2001/04/13 17:39:51 1.1.2.3
+++ cocoon.roles 2001/04/17 10:32:40 1.1.2.4
@@ -110,4 +110,8 @@
shorthand="event-cache"
default-class="org.apache.cocoon.caching.EventMemoryCache"/>
+<role name="org.apache.cocoon.caching.StreamCache"
+ shorthand="stream-cache"
+ default-class="org.apache.cocoon.caching.StreamMemoryCache"/>
+
</role-list>
No revision
No revision
1.1.2.2 +4 -1
xml-cocoon/src/org/apache/cocoon/caching/Attic/Cacheable.java
Index: Cacheable.java
===================================================================
RCS file:
/home/cvs/xml-cocoon/src/org/apache/cocoon/caching/Attic/Cacheable.java,v
retrieving revision 1.1.2.1
retrieving revision 1.1.2.2
diff -u -r1.1.2.1 -r1.1.2.2
--- Cacheable.java 2001/04/11 10:52:11 1.1.2.1
+++ Cacheable.java 2001/04/17 10:32:46 1.1.2.2
@@ -12,13 +12,14 @@
*
*
* @author <a href="mailto:[EMAIL PROTECTED]">Carsten Ziegeler</a>
- * @version CVS $Revision: 1.1.2.1 $ $Date: 2001/04/11 10:52:11 $
+ * @version CVS $Revision: 1.1.2.2 $ $Date: 2001/04/17 10:32:46 $
*/
public interface Cacheable {
/**
* Generate the unique key.
* This key must be unique inside the space of this component.
+ * This method must be invoked before the generateValidity() method.
*
* @return The generated key or <code>0</code> if the component
* is currently not cacheable.
@@ -27,6 +28,8 @@
/**
* Generate the validity object.
+ * Before this method can be invoked the generateKey() method
+ * must be invoked.
*
* @return The generated validity object or <code>null</code> if the
* component is currently not cacheable.
1.1.2.2 +1 -1
xml-cocoon/src/org/apache/cocoon/caching/Attic/ComponentCacheKey.java
Index: ComponentCacheKey.java
===================================================================
RCS file:
/home/cvs/xml-cocoon/src/org/apache/cocoon/caching/Attic/ComponentCacheKey.java,v
retrieving revision 1.1.2.1
retrieving revision 1.1.2.2
diff -u -r1.1.2.1 -r1.1.2.2
--- ComponentCacheKey.java 2001/04/11 10:52:16 1.1.2.1
+++ ComponentCacheKey.java 2001/04/17 10:32:52 1.1.2.2
@@ -16,7 +16,7 @@
* is unique inside the component space.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Carsten Ziegeler</a>
- * @version CVS $Revision: 1.1.2.1 $ $Date: 2001/04/11 10:52:16 $
+ * @version CVS $Revision: 1.1.2.2 $ $Date: 2001/04/17 10:32:52 $
*/
public final class ComponentCacheKey {
1.1.2.2 +2 -2
xml-cocoon/src/org/apache/cocoon/caching/Attic/EventCache.java
Index: EventCache.java
===================================================================
RCS file:
/home/cvs/xml-cocoon/src/org/apache/cocoon/caching/Attic/EventCache.java,v
retrieving revision 1.1.2.1
retrieving revision 1.1.2.2
diff -u -r1.1.2.1 -r1.1.2.2
--- EventCache.java 2001/04/11 10:52:19 1.1.2.1
+++ EventCache.java 2001/04/17 10:32:53 1.1.2.2
@@ -11,10 +11,10 @@
/**
* This is the EventCache. It stores cached <code>EventPipelines</code>.
- * The objects stored in this cache are <code>CachedObjects</code>.
+ * The objects stored in this cache are <code>CachedEventObjects</code>.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Carsten Ziegeler</a>
- * @version CVS $Revision: 1.1.2.1 $ $Date: 2001/04/11 10:52:19 $
+ * @version CVS $Revision: 1.1.2.2 $ $Date: 2001/04/17 10:32:53 $
*/
public interface EventCache
extends Store {
1.1.2.2 +2 -2
xml-cocoon/src/org/apache/cocoon/caching/Attic/EventMemoryCache.java
Index: EventMemoryCache.java
===================================================================
RCS file:
/home/cvs/xml-cocoon/src/org/apache/cocoon/caching/Attic/EventMemoryCache.java,v
retrieving revision 1.1.2.1
retrieving revision 1.1.2.2
diff -u -r1.1.2.1 -r1.1.2.2
--- EventMemoryCache.java 2001/04/11 10:52:21 1.1.2.1
+++ EventMemoryCache.java 2001/04/17 10:32:54 1.1.2.2
@@ -10,11 +10,11 @@
import org.apache.cocoon.components.store.MemoryStore;
/**
- * An implementation for the EventCache which simply uses stores the
+ * An implementation for the EventCache which simply stores the
* cached objects in the memory.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Carsten Ziegeler</a>
- * @version CVS $Revision: 1.1.2.1 $ $Date: 2001/04/11 10:52:21 $
+ * @version CVS $Revision: 1.1.2.2 $ $Date: 2001/04/17 10:32:54 $
*/
public final class EventMemoryCache
extends MemoryStore
1.1.2.2 +9 -1
xml-cocoon/src/org/apache/cocoon/caching/Attic/PipelineCacheKey.java
Index: PipelineCacheKey.java
===================================================================
RCS file:
/home/cvs/xml-cocoon/src/org/apache/cocoon/caching/Attic/PipelineCacheKey.java,v
retrieving revision 1.1.2.1
retrieving revision 1.1.2.2
diff -u -r1.1.2.1 -r1.1.2.2
--- PipelineCacheKey.java 2001/04/11 10:52:23 1.1.2.1
+++ PipelineCacheKey.java 2001/04/17 10:32:57 1.1.2.2
@@ -15,7 +15,7 @@
* or more <code>ComponentCacheKey</code> objects.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Carsten Ziegeler</a>
- * @version CVS $Revision: 1.1.2.1 $ $Date: 2001/04/11 10:52:23 $
+ * @version CVS $Revision: 1.1.2.2 $ $Date: 2001/04/17 10:32:57 $
*/
public final class PipelineCacheKey {
@@ -23,6 +23,14 @@
private String toStringValue = "PCK:";
public void addKey(ComponentCacheKey key) {
+ if (this.list == null) {
+ this.list = new ArrayList();
+ }
+ this.list.add(key);
+ toStringValue = toStringValue + key.toString();
+ }
+
+ public void addKey(PipelineCacheKey key) {
if (this.list == null) {
this.list = new ArrayList();
}
No revision
No revision
1.1.2.1 +56 -0
xml-cocoon/src/org/apache/cocoon/caching/Attic/CachedEventObject.java
1.1.2.1 +56 -0
xml-cocoon/src/org/apache/cocoon/caching/Attic/CachedStreamObject.java
1.1.2.1 +59 -0
xml-cocoon/src/org/apache/cocoon/caching/Attic/CachingOutputStream.java
1.1.2.1 +28 -0
xml-cocoon/src/org/apache/cocoon/caching/Attic/NOPCacheValidity.java
1.1.2.1 +22 -0
xml-cocoon/src/org/apache/cocoon/caching/Attic/StreamCache.java
1.1.2.1 +23 -0
xml-cocoon/src/org/apache/cocoon/caching/Attic/StreamMemoryCache.java
No revision
No revision
1.1.2.5 +190 -110
xml-cocoon/src/org/apache/cocoon/components/pipeline/Attic/CachingEventPipeline.java
Index: CachingEventPipeline.java
===================================================================
RCS file:
/home/cvs/xml-cocoon/src/org/apache/cocoon/components/pipeline/Attic/CachingEventPipeline.java,v
retrieving revision 1.1.2.4
retrieving revision 1.1.2.5
diff -u -r1.1.2.4 -r1.1.2.5
--- CachingEventPipeline.java 2001/04/13 16:02:22 1.1.2.4
+++ CachingEventPipeline.java 2001/04/17 10:33:12 1.1.2.5
@@ -41,7 +41,7 @@
import org.apache.cocoon.caching.ComponentCacheKey;
import org.apache.cocoon.caching.PipelineCacheKey;
import org.apache.cocoon.caching.Cacheable;
-import org.apache.cocoon.caching.CachedObject;
+import org.apache.cocoon.caching.CachedEventObject;
import org.apache.cocoon.caching.CacheValidity;
import org.apache.cocoon.sitemap.ErrorNotifier;
@@ -51,148 +51,151 @@
/**
* The CachingEventPipeline
*
+ * If all components of this event pipeline are cacheable then the whole
+ * pipeline is also cacheable. If in this case the CacheableEventPipeline
interface
+ * is invoked (e.g. by the CachingStreamPipeline) the CachingEventPipeline
+ * does not cache! (If it would cache, the response would be cached twice!)
+ *
* @author <a href="mailto:[EMAIL PROTECTED]">Carsten Ziegeler</a>
- * @version CVS $Revision: 1.1.2.4 $ $Date: 2001/04/13 16:02:22 $
+ * @version CVS $Revision: 1.1.2.5 $ $Date: 2001/04/17 10:33:12 $
*/
-public class CachingEventPipeline extends AbstractEventPipeline implements
Disposable {
+public final class CachingEventPipeline
+extends AbstractEventPipeline
+implements Disposable, CacheableEventPipeline {
/** The store for the cached sax events */
- private EventCache saxStore;
+ private EventCache eventCache;
private XMLProducer producer;
private String generatorRole;
private ArrayList transformerRoles = new ArrayList();
private ArrayList notCacheableTransformers = new ArrayList();
+ private Map validityObjects;
+ private PipelineCacheKey pipelineCacheKey;
+ private boolean setupFinished = false;
+ /** Indicates if the whole pipeline is cacheable */
+ private boolean cacheable = false;
+ private int firstNotCacheableTransformerIndex;
public void compose (ComponentManager manager)
throws ComponentManagerException {
super.compose(manager);
- this.saxStore = (EventCache)this.manager.lookup(Roles.EVENT_CACHE);
+ this.eventCache = (EventCache)this.manager.lookup(Roles.EVENT_CACHE);
}
+ /**
+ * Set the generator.
+ */
public void setGenerator (String role, String source, Parameters param)
throws Exception {
super.setGenerator(role, source, param);
this.generatorRole = role;
}
+ /**
+ * Add a transformer.
+ */
public void addTransformer (String role, String source, Parameters param)
throws Exception {
super.addTransformer(role, source, param);
this.transformerRoles.add(role);
}
- public boolean process(Environment environment) throws Exception {
- if (this.checkPipeline() == false) {
- throw new ProcessingException("Attempted to process incomplete
pipeline.");
+ /**
+ * Generate the unique key.
+ * This key is the <code>PipelineCacheKey</code> for the whole
+ * EventPipeline.
+ *
+ * @param environment The current environment of the request.
+ * @return The generated key or <code>null</code> if the pipeline
+ * is currently not cacheable as a whole.
+ */
+ public PipelineCacheKey generateKey(Environment environment)
+ throws Exception {
+ this.setup(environment);
+ return (this.cacheable == true ? this.pipelineCacheKey : null);
+ }
+
+ /**
+ * Generate the validity object.
+ * Before this method can be invoked the generateKey() method
+ * must be invoked.
+ *
+ * @param environment The current environment of the request.
+ * @return The generated validity objects for the whole pipeline
+ * or <code>null</code> if the pipeline is currently
+ * not cacheable.
+ */
+ public Map generateValidity(Environment environment)
+ throws Exception {
+ // if we are cacheable and this method is called
+ // reset the pipeline cache key to avoid duplicate caching
+ if (this.cacheable == true) {
+ this.pipelineCacheKey = null;
+ return this.validityObjects;
}
+ return null;
+ }
+
+ public boolean process(Environment environment) throws Exception {
+ this.setup(environment);
- Map validityObjects = null;
- PipelineCacheKey pipelineCacheKey = null;
+ // we cache if the pipelinecachekey is available
XMLSerializer xmlSerializer = null;
try {
- // set up all sitemap components
- this.setupPipeline(environment);
-
- // 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);
- validityObjects = new HashMap();
- validityObjects.put(cck, validity);
- pipelineCacheKey = new PipelineCacheKey();
- pipelineCacheKey.addKey(cck);
-
- // now testing transformers
- Transformer trans;
- ComponentCacheKey transCacheKey;
- int transformerIndex = 0;
- int transformerSize = this.transformers.size();
- long transKey;
- CacheValidity transValidity;
- boolean testTrans = true;
-
- while (transformerIndex < transformerSize
- && testTrans == true) {
- trans =
(Transformer)this.transformers.get(transformerIndex);
- 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(transformerIndex),
- transKey);
- pipelineCacheKey.addKey(transCacheKey);
- validityObjects.put(transCacheKey,
transValidity);
- } else {
- testTrans = false;
- }
- } else {
- testTrans = false;
- }
- if (testTrans == true) transformerIndex++;
+ if (this.pipelineCacheKey != null) {
+ // now we have the key to get the cached object
+ CachedEventObject cachedObject =
(CachedEventObject)this.eventCache.get(this.pipelineCacheKey);
+
+ if (cachedObject != null) {
+ getLogger().debug("Found cached content.");
+ Iterator validityIterator =
validityObjects.keySet().iterator();
+ ComponentCacheKey validityKey;
+ boolean valid = true;
+ while (validityIterator.hasNext() == true && valid ==
true) {
+ validityKey =
(ComponentCacheKey)validityIterator.next();
+ valid = cachedObject.isValid(validityKey,
(CacheValidity)validityObjects.get(validityKey));
}
+ if (valid == true) {
- // now we have the key to get the cached object
- CachedObject cachedObject =
(CachedObject)saxStore.get(pipelineCacheKey);
- if (cachedObject != null) {
- getLogger().debug("Found cached content.");
- Iterator validityIterator =
validityObjects.keySet().iterator();
- ComponentCacheKey validityKey;
- boolean valid = true;
- while (validityIterator.hasNext() == true && valid
== true) {
- validityKey =
(ComponentCacheKey)validityIterator.next();
- valid = cachedObject.isValid(validityKey,
(CacheValidity)validityObjects.get(validityKey));
+ getLogger().debug("Using valid cached content.");
+ // 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++;
}
- if (valid == true) {
- getLogger().debug("Using valid cached content.");
- // get all transformers which are not cacheable
- while (transformerIndex < transformerSize) {
-
this.notCacheableTransformers.add(this.transformers.get(transformerIndex));
- transformerIndex++;
- }
-
- XMLDeserializer deserializer = null;
- try {
- deserializer =
(XMLDeserializer)this.manager.lookup(Roles.XML_DESERIALIZER);
- // connect the pipeline:
- this.producer = deserializer;
- this.connectPipeline(environment,
-
notCacheableTransformers,
- null);
- // execute the pipeline:
-
deserializer.deserialize(cachedObject.getSAXFragment());
- } catch ( Exception e ) {
- throw new ProcessingException(
- "Failed to execute pipeline.",
- e
- );
- } finally {
- if (deserializer != null)
-
this.manager.release((Component)deserializer);
- }
- } else {
- getLogger().debug("Cached content is invalid.");
- // remove invalid cached object
- saxStore.remove(pipelineCacheKey);
- cachedObject = null;
+ XMLDeserializer deserializer = null;
+ try {
+ deserializer =
(XMLDeserializer)this.manager.lookup(Roles.XML_DESERIALIZER);
+ // connect the pipeline:
+ this.producer = deserializer;
+ this.connectPipeline(environment,
+ notCacheableTransformers,
+ null);
+ // execute the pipeline:
+
deserializer.deserialize(cachedObject.getSAXFragment());
+ } catch ( Exception e ) {
+ throw new ProcessingException(
+ "Failed to execute pipeline.",
+ e
+ );
+ } finally {
+ if (deserializer != null)
+
this.manager.release((Component)deserializer);
}
+ } else {
+ getLogger().debug("Cached content is invalid.");
+ // remove invalid cached object
+ this.eventCache.remove(this.pipelineCacheKey);
+ cachedObject = null;
}
- if (cachedObject == null) {
- getLogger().debug("Caching content for further
request.");
- xmlSerializer =
(XMLSerializer)this.manager.lookup(Roles.XML_SERIALIZER);
- }
+ }
+ if (cachedObject == null) {
+ getLogger().debug("Caching content for further
requests.");
+ xmlSerializer =
(XMLSerializer)this.manager.lookup(Roles.XML_SERIALIZER);
}
}
@@ -207,8 +210,8 @@
this.generator.generate();
// did we have cacheable components?
if (xmlSerializer != null) {
- this.saxStore.store(pipelineCacheKey,
- new CachedObject(validityObjects,
+ this.eventCache.store(this.pipelineCacheKey,
+ new CachedEventObject(this.validityObjects,
xmlSerializer.getSAXFragment()));
}
} catch ( Exception e ) {
@@ -225,6 +228,79 @@
return true;
}
+ /**
+ * Setup the evenet pipeline.
+ * The components of the pipeline are checked if they are
+ * Cacheable.
+ */
+ private void setup(Environment environment) throws Exception {
+ if (this.setupFinished == true) {
+ return;
+ }
+ if (this.checkPipeline() == false) {
+ throw new ProcessingException("Attempted to process incomplete
pipeline.");
+ }
+
+ // set up all sitemap components
+ this.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 == true) {
+ 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 == true)
+ this.firstNotCacheableTransformerIndex++;
+ }
+ // all transformers are cacheable => pipeline is cacheable
+ if (this.firstNotCacheableTransformerIndex ==
transformerSize)
+ this.cacheable = true;
+ }
+ }
+ this.setupFinished = true;
+ }
+
/** Connect the pipeline.
*/
private void connectPipeline(Environment environment,
@@ -295,15 +371,19 @@
getLogger().debug("Recycling of CachingEventPipeline");
super.recycle();
-
+
this.producer = null;
this.generatorRole = null;
this.transformerRoles.clear();
this.notCacheableTransformers.clear();
+ this.validityObjects = null;
+ this.pipelineCacheKey = null;
+ this.setupFinished = false;
+ this.cacheable = false;
}
public void dispose() {
- if(this.saxStore != null)
- this.manager.release((Component)this.saxStore);
+ if(this.eventCache != null)
+ this.manager.release((Component)this.eventCache);
}
}
1.1.2.5 +7 -232
xml-cocoon/src/org/apache/cocoon/components/pipeline/Attic/NonCachingStreamPipeline.java
Index: NonCachingStreamPipeline.java
===================================================================
RCS file:
/home/cvs/xml-cocoon/src/org/apache/cocoon/components/pipeline/Attic/NonCachingStreamPipeline.java,v
retrieving revision 1.1.2.4
retrieving revision 1.1.2.5
diff -u -r1.1.2.4 -r1.1.2.5
--- NonCachingStreamPipeline.java 2001/04/13 16:02:22 1.1.2.4
+++ NonCachingStreamPipeline.java 2001/04/17 10:33:15 1.1.2.5
@@ -8,27 +8,9 @@
package org.apache.cocoon.components.pipeline;
import java.io.IOException;
-import java.io.OutputStream;
-import org.apache.avalon.Component;
-import org.apache.avalon.ComponentManager;
-import org.apache.avalon.ComponentManagerException;
-import org.apache.avalon.ComponentSelector;
-import org.apache.avalon.Composer;
-import org.apache.avalon.Disposable;
-import org.apache.avalon.configuration.Parameters;
-import org.apache.avalon.AbstractLoggable;
-
import org.apache.cocoon.ProcessingException;
import org.apache.cocoon.environment.Environment;
-import org.apache.cocoon.reading.Reader;
-import org.apache.cocoon.serialization.Serializer;
-import org.apache.cocoon.sitemap.SitemapComponentSelector;
-import org.apache.cocoon.xml.XMLProducer;
-import org.apache.cocoon.xml.XMLConsumer;
-import org.apache.cocoon.Roles;
-
-import org.xml.sax.EntityResolver;
/** A <CODE>ResourcePipeline</CODE> either
* <UL>
@@ -38,238 +20,31 @@
* resource
* </UL>
* @author <a href="mailto:[EMAIL PROTECTED]">Giacomo Pati</a>
- * @version CVS $Revision: 1.1.2.4 $ $Date: 2001/04/13 16:02:22 $
+ * @version CVS $Revision: 1.1.2.5 $ $Date: 2001/04/17 10:33:15 $
*/
-public class NonCachingStreamPipeline extends AbstractLoggable implements
StreamPipeline, Disposable {
- private EventPipeline eventPipeline;
- private Reader reader;
- private Parameters readerParam;
- private String readerSource;
- private String readerMimeType;
- private String sitemapReaderMimeType;
- private Serializer serializer;
- private Parameters serializerParam;
- private String serializerSource;
- private String serializerMimeType;
- private String sitemapSerializerMimeType;
- private SitemapComponentSelector readerSelector;
- private SitemapComponentSelector serializerSelector;
-
- /** the component manager */
- private ComponentManager manager;
-
- /**
- * Pass the <code>ComponentManager</code> to the <code>composer</code>.
- * The <code>Composer</code> implementation should use the specified
- * <code>ComponentManager</code> to acquire the components it needs for
- * execution.
- *
- * @param manager The <code>ComponentManager</code> which this
- * <code>Composer</code> uses.
- * @throws ComponentManagerException */
- public void compose (ComponentManager manager) throws
ComponentManagerException {
- this.manager = manager;
- readerSelector = (SitemapComponentSelector)
this.manager.lookup(Roles.READERS);
- serializerSelector = (SitemapComponentSelector)
this.manager.lookup(Roles.SERIALIZERS);
- }
-
- public void setEventPipeline (EventPipeline eventPipeline) throws
Exception {
- if (this.eventPipeline != null) {
- throw new ProcessingException ("EventPipeline already set. You
can only select one EventPipeline ");
- }
- this.eventPipeline = eventPipeline;
- }
-
- public void setGenerator (String role, String source, Parameters param,
Exception e) throws Exception {
- this.eventPipeline.setGenerator (role, source, param);
- }
-
- public void setGenerator (String role, String source, Parameters param)
throws Exception {
- this.eventPipeline.setGenerator (role, source, param);
- }
-
- public EventPipeline getEventPipeline () {
- return this.eventPipeline;
- }
-
- public void setReader (String role, String source, Parameters param)
- throws Exception {
- this.setReader (role, source, param, null);
- }
-
- public void setReader (String role, String source, Parameters param,
String mimeType)
- throws Exception {
- if (this.reader != null) {
- throw new ProcessingException ("Reader already set. You can only
select one Reader (" + role + ")");
- }
- this.reader = (Reader)readerSelector.select(role);
- this.readerSource = source;
- this.readerParam = param;
- this.readerMimeType = mimeType;
- this.sitemapReaderMimeType = readerSelector.getMimeTypeForRole(role);
- }
-
- public void setSerializer (String role, String source, Parameters param)
- throws Exception {
- this.setSerializer (role, source, param, null);
- }
-
- public void setSerializer (String role, String source, Parameters param,
String mimeType)
- throws Exception {
- if (this.serializer != null) {
- throw new ProcessingException ("Serializer already set. You can
only select one Serializer (" + role + ")");
- }
- this.serializer = (Serializer)serializerSelector.select(role);
- this.serializerSource = source;
- this.serializerParam = param;
- this.serializerMimeType = mimeType;
- this.sitemapSerializerMimeType =
serializerSelector.getMimeTypeForRole(role);
- }
-
- public void addTransformer (String role, String source, Parameters
param) throws Exception {
- this.eventPipeline.addTransformer (role, source, param);
- }
-
- public boolean process(Environment environment)
- throws ProcessingException {
- if ( this.reader != null ) {
- return processReader(environment);
- } else {
- if ( !checkPipeline() ) {
- throw new ProcessingException("Attempted to process
incomplete pipeline.");
- }
-
- setupPipeline(environment);
- connectPipeline();
-
- // execute the pipeline:
- try {
- this.eventPipeline.process(environment);
- } catch ( Exception e ) {
- throw new ProcessingException(
- "Failed to execute pipeline.",
- e
- );
- }
+public final class NonCachingStreamPipeline extends AbstractStreamPipeline {
- return true;
- }
- }
-
- /** Process the pipeline using a reader.
- * @throws ProcessingException if
- */
- private boolean processReader(Environment environment)
- throws ProcessingException {
- String mimeType;
- try {
- this.reader.setup((EntityResolver)
environment,environment.getObjectModel(),readerSource,readerParam);
- mimeType = this.reader.getMimeType();
- if ( mimeType != null ) {
- environment.setContentType(mimeType);
- } else if ( readerMimeType != null ) {
- environment.setContentType(this.readerMimeType);
- } else {
- environment.setContentType(this.sitemapReaderMimeType);
- }
- this.reader.setOutputStream(environment.getOutputStream());
- this.reader.generate();
- } catch ( Exception e ) {
- throw new ProcessingException("Error reading resource",e);
- }
- return true;
- }
-
- /** Sanity check the non-reader pipeline.
- * @return true if the pipeline is 'sane', false otherwise.
- */
- private boolean checkPipeline() {
- if ( this.eventPipeline == null ) {
- return false;
- }
-
- if ( this.serializer == null ) {
- return false;
- }
-
- return true;
- }
-
/** Setup pipeline components.
*/
- private void setupPipeline(Environment environment)
+ protected void setupPipeline(Environment environment)
throws ProcessingException {
try {
this.serializer.setOutputStream(environment.getOutputStream());
- String mimeType = this.serializer.getMimeType();
- if (mimeType != null) {
- // we have a mimeType freom the component itself
- environment.setContentType (mimeType);
- } else if (serializerMimeType != null) {
- // there was a mimeType specified in the sitemap pipeline
- environment.setContentType (serializerMimeType);
- } else {
- // use the mimeType specified in the sitemap component
declaration
- environment.setContentType (this.sitemapSerializerMimeType);
- }
} catch (IOException e) {
throw new ProcessingException(
"Could not setup resource pipeline.",
e
);
}
-
-
+ super.setupPipeline(environment);
}
- /** Connect the pipeline.
+ /**
+ * Recycle this component
*/
- private void connectPipeline() throws ProcessingException {
- XMLProducer prev = (XMLProducer) this.eventPipeline;
- XMLConsumer next;
-
- // connect serializer.
- prev.setConsumer(this.serializer);
- }
-
- public void dispose() {
- if(readerSelector != null)
- manager.release((Component)readerSelector);
- if(serializerSelector != null)
- manager.release((Component)serializerSelector);
- }
-
public void recycle() {
getLogger().debug("Recycling of NonCachingStreamPipeline");
-
- try {
- // release reader.
- if ( this.readerSelector != null) {
- if ( this.reader != null ) {
- readerSelector.release(this.reader);
- }
- }
- this.reader = null;
-
- // release eventPipeline
- this.eventPipeline = null;
- // release serializer
- if ( this.serializerSelector != null ) {
- if ( this.serializer != null ) {
- serializerSelector.release(this.serializer);
- }
- }
- this.serializer = null;
- } catch ( Exception e ) {
- getLogger().warn(
- "Failed to release components from
NonCachingStreamPipeline.",
- e
- );
- } finally {
- this.reader = null;
- this.eventPipeline = null;
- this.serializer = null;
- }
+ super.recycle();
}
}
No revision
No revision
1.1.2.1 +265 -0
xml-cocoon/src/org/apache/cocoon/components/pipeline/Attic/AbstractStreamPipeline.java
1.1.2.1 +46 -0
xml-cocoon/src/org/apache/cocoon/components/pipeline/Attic/CacheableEventPipeline.java
1.1.2.1 +192 -0
xml-cocoon/src/org/apache/cocoon/components/pipeline/Attic/CachingStreamPipeline.java
No revision
No revision
1.1.2.15 +33 -3
xml-cocoon/src/org/apache/cocoon/serialization/Attic/FOPSerializer.java
Index: FOPSerializer.java
===================================================================
RCS file:
/home/cvs/xml-cocoon/src/org/apache/cocoon/serialization/Attic/FOPSerializer.java,v
retrieving revision 1.1.2.14
retrieving revision 1.1.2.15
diff -u -r1.1.2.14 -r1.1.2.15
--- FOPSerializer.java 2001/03/21 09:58:10 1.1.2.14
+++ FOPSerializer.java 2001/04/17 10:33:19 1.1.2.15
@@ -20,6 +20,10 @@
import org.apache.fop.messaging.MessageHandler;
import org.apache.fop.messaging.MessageEvent;
+import org.apache.cocoon.caching.Cacheable;
+import org.apache.cocoon.caching.CacheValidity;
+import org.apache.cocoon.caching.NOPCacheValidity;
+
import org.xml.sax.ContentHandler;
import org.xml.sax.SAXException;
@@ -29,10 +33,12 @@
* @author <a href="mailto:[EMAIL PROTECTED]">Giacomo Pati</a>
* (PWR Organisation & Entwicklung)
* @author <a href="mailto:[EMAIL PROTECTED]">Stefano Mazzocchi</a>
- * @version CVS $Revision: 1.1.2.14 $ $Date: 2001/03/21 09:58:10 $
+ * @author <a href="mailto:[EMAIL PROTECTED]">Carsten Ziegeler</a>
+ * @version CVS $Revision: 1.1.2.15 $ $Date: 2001/04/17 10:33:19 $
*
*/
-public class FOPSerializer extends AbstractSerializer implements
MessageListener, Recyclable {
+public class FOPSerializer extends AbstractSerializer
+implements MessageListener, Recyclable, Cacheable {
/**
* The FOP driver
@@ -92,8 +98,32 @@
// XXX (SM)
// we should consume the events in some meaningful way
// for example formatting them on the metapipeline
+ }
+
+ /**
+ * Generate the unique key.
+ * This key must be unique inside the space of this component.
+ * This method must be invoked before the generateValidity() method.
+ *
+ * @return The generated key or <code>0</code> if the component
+ * is currently not cacheable.
+ */
+ public long generateKey() {
+ return 1;
}
-
+
+ /**
+ * Generate the validity object.
+ * Before this method can be invoked the generateKey() method
+ * must be invoked.
+ *
+ * @return The generated validity object or <code>null</code> if the
+ * component is currently not cacheable.
+ */
+ public CacheValidity generateValidity() {
+ return new NOPCacheValidity();
+ }
+
/**
* Recycle the component and remove it from the MessageList
*/
----------------------------------------------------------------------
In case of troubles, e-mail: [EMAIL PROTECTED]
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]