Author: cziegeler Date: Wed Feb 23 04:31:40 2005 New Revision: 155004 URL: http://svn.apache.org/viewcvs?view=rev&rev=155004 Log: Fixing roles file and rewrote event cache sample from xsp to java, so no dependency to xsp anymore
Added: cocoon/trunk/src/blocks/eventcache/java/org/apache/cocoon/samples/ cocoon/trunk/src/blocks/eventcache/java/org/apache/cocoon/samples/EventAwareGenerator.java (with props) cocoon/trunk/src/blocks/eventcache/samples/eventcache.xml (with props) Removed: cocoon/trunk/src/blocks/eventcache/samples/eventcache.xsp Modified: cocoon/trunk/blocks.properties cocoon/trunk/gump.xml cocoon/trunk/src/blocks/eventcache/samples/sitemap.xmap cocoon/trunk/src/java/org/apache/cocoon/cocoon.roles Modified: cocoon/trunk/blocks.properties URL: http://svn.apache.org/viewcvs/cocoon/trunk/blocks.properties?view=diff&r1=155003&r2=155004 ============================================================================== --- cocoon/trunk/blocks.properties (original) +++ cocoon/trunk/blocks.properties Wed Feb 23 04:31:40 2005 @@ -84,7 +84,7 @@ #-----[dependency]: "xmldb" depends on "databases". #include.block.xmldb=false #-----[dependency]: "xsp" depends on "databases", "session-fw". -#-----[dependency]: "xsp" is needed by "eventcache", "lucene", "python", "scratchpad". +#-----[dependency]: "xsp" is needed by "lucene", "python", "scratchpad". #include.block.xsp=false # Unstable blocks -------------------------------------------------------------- @@ -106,7 +106,7 @@ #-----[dependency]: "cron" is needed by "portal", "scratchpad". #include.block.cron=false #include.block.deli=false -#-----[dependency]: "eventcache" depends on "jms", "xsp" (for samples). +#-----[dependency]: "eventcache" depends on "jms". #-----[dependency]: "eventcache" is needed by "repository". #include.block.eventcache=false #-----[dependency]: "faces" depends on "portal", "taglib". Modified: cocoon/trunk/gump.xml URL: http://svn.apache.org/viewcvs/cocoon/trunk/gump.xml?view=diff&r1=155003&r2=155004 ============================================================================== --- cocoon/trunk/gump.xml (original) +++ cocoon/trunk/gump.xml Wed Feb 23 04:31:40 2005 @@ -940,7 +940,6 @@ <depend project="cocoon" inherit="all"/> <depend project="cocoon-block-jms"/> <depend project="jms"/> - <depend project="cocoon-block-xsp" type="samples"/> <depend project="jms"/> <work nested="build/cocoon-@@DATE@@/blocks/eventcache/dest"/> Added: cocoon/trunk/src/blocks/eventcache/java/org/apache/cocoon/samples/EventAwareGenerator.java URL: http://svn.apache.org/viewcvs/cocoon/trunk/src/blocks/eventcache/java/org/apache/cocoon/samples/EventAwareGenerator.java?view=auto&rev=155004 ============================================================================== --- cocoon/trunk/src/blocks/eventcache/java/org/apache/cocoon/samples/EventAwareGenerator.java (added) +++ cocoon/trunk/src/blocks/eventcache/java/org/apache/cocoon/samples/EventAwareGenerator.java Wed Feb 23 04:31:40 2005 @@ -0,0 +1,91 @@ +/* + * Copyright 2005 The Apache Software Foundation. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.cocoon.samples; + +import java.io.IOException; +import java.io.Serializable; + +import org.apache.cocoon.ProcessingException; +import org.apache.cocoon.caching.validity.EventValidity; +import org.apache.cocoon.caching.validity.NamedEvent; +import org.apache.cocoon.environment.ObjectModelHelper; +import org.apache.cocoon.environment.Request; +import org.apache.cocoon.generation.JXTemplateGenerator; +import org.apache.excalibur.source.SourceValidity; +import org.xml.sax.SAXException; + +/** + * This is a sample generator to demonstrate the event aware caching. + * We simply extend the JXTG. + * @version $Id:$ + */ +public class EventAwareGenerator extends JXTemplateGenerator { + + /** + * Generate the unique key for the cache. + * + * This key must be unique inside the space of this XSP page, it is used + * to find the page contents in the cache (if getValidity says that the + * contents are still valid). + * + * This method will be invoked before the getValidity() method. + * + * @return The generated key or null if the component + * is currently not cacheable. + */ + public Serializable getKey() { + final Request request = ObjectModelHelper.getRequest(this.objectModel); + // for our test, pages having the same value of "pageKey" will share + // the same cache location + String key = request.getParameter("pageKey") ; + return ((key==null||"".equals(key)) ? "one" : key); + } + + /** + * Generate the validity object, tells the cache how long to + * keep contents having this key around. In this case, it will + * be until an Event is retrieved matching the NamedEvent created below. + * + * Before this method can be invoked the getKey() method + * will be invoked. + * + * @return The generated validity object or null if the + * component is currently not cacheable. + */ + public SourceValidity getValidity() { + final Request request = ObjectModelHelper.getRequest(this.objectModel); + String key = request.getParameter("pageKey") ; + return new EventValidity( + new NamedEvent( + (key==null||"".equals(key)) ? "one" : key)); + } + + + /* (non-Javadoc) + * @see org.apache.cocoon.generation.Generator#generate() + */ + public void generate() + throws IOException, SAXException, ProcessingException { + super.generate(); + // slowdown page generation. + long DELAY_SECS = this.parameters.getParameterAsLong("DELAY_SECS", 2); + try { + Thread.sleep(DELAY_SECS * 1000L); + } catch (InterruptedException ie) { + // Not much that can be done... + } + } +} Propchange: cocoon/trunk/src/blocks/eventcache/java/org/apache/cocoon/samples/EventAwareGenerator.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: cocoon/trunk/src/blocks/eventcache/java/org/apache/cocoon/samples/EventAwareGenerator.java ------------------------------------------------------------------------------ svn:keywords = Id Added: cocoon/trunk/src/blocks/eventcache/samples/eventcache.xml URL: http://svn.apache.org/viewcvs/cocoon/trunk/src/blocks/eventcache/samples/eventcache.xml?view=auto&rev=155004 ============================================================================== --- cocoon/trunk/src/blocks/eventcache/samples/eventcache.xml (added) +++ cocoon/trunk/src/blocks/eventcache/samples/eventcache.xml Wed Feb 23 04:31:40 2005 @@ -0,0 +1,104 @@ +<?xml version="1.0"?> +<!-- + Copyright 1999-2005 The Apache Software Foundation + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +--> + +<!--+ + | event-based cache sample. + | + | @version $Id:$ + +--> +<page> + <title>Demonstrating Event-Aware Caching</title> + <content> + <para> + This page is a sample for event aware caching. We subclassed the + JXTG template generate for this sample. If you don't already + understand at least the basics of caching in Cocoon, you should + probably start there, not here. Read the text below, and the + sitemap and source for more details. + </para> + <para> + I pause for ${cocoon.parameters.DELAY_SECS} seconds during generation, so + that you can tell if I'm being served from the cache or not. + <br/> + What you see here was generated on <b>${cocoon.parameters.DATE}</b>. + </para> + + <para> + I'm cached for each unique value of request parameter 'pageKey'. Other + parameters do not matter. + <br/> + Here the value is: + <b>${cocoon.parameters.KEY}</b>. + <br/> + If this is not the same as the 'pageKey' parameter in the page URL, we have a problem. + </para> + + <para> + Unlike other cacheable pages in Cocoon, I can be un-cached by events external + to Cocoon - for instance, when a database table or row is updated. + <br/> + My cache entry will be invalidated (actually, removed) when an event named + <i>${cocoon.parameters.KEY}</i> occurs. This can be manually + simulated by clicking one of the "uncache" links below. + </para> + <para>Test links: + <ul> + <li><a href="?pageKey=one">pageKey=one</a> + (<a href="action?pageKey=one&event=one">uncache with action</a>) + (<a href="flow?pageKey=one&event=one">uncache with flow</a>)</li> + <li><a href="?pageKey=two">pageKey=two</a> + (<a href="action?pageKey=two&event=two">uncache with action</a>) + (<a href="flow?pageKey=two&event=two">uncache with flow</a>)</li> + </ul> + Note: the random numbers you see included in the url after an uncache link + serve two purposes in the example, making it easier to see the effect of the + cache invalidation. They prevent browser caching and they demonstrate that + only our designated key matters in the retrieval from cache. + </para> + <para> + This event based cache system consists essentially of three parts: + <ul> + <li>A new type of SourceValidity, EventValidity, which contains information + on the Event which will invalidate this cached content. Until this event is + received, EventValidities will usually always return valid, though they don't + have to.</li> + <li>An extension to Cocoon's Cache implementation. Cocoon's Cache is really just + a thin wrapper around Avalon-Excalibur's Store project. The EventAwareCacheImpl + does two things. It examines each pipeline on its way into the cache to + determine if any of its SourceValidities are instances of EventValidity. If so, + it notifies an event registry as described next. The second critical function of + the EventAware cache implementation is that it allows other components to + contact it and notify it of an Event. The Cache then looks up the keys + mapped to that event in the event registry and cleans out the cache and + registry accordingly. <i>See the sitemap of this sample for an example of + configuring a pipeline to use this implementation.</i></li> + <li>The EventRegistry is responsible for mapping Events to cache keys, and + providing information about that mapping to systems that need it, usually just + the EventAwareCache. Another crucial responsibility of the EventRegistry is to + persist its data across container shutdown and startup. The default implementation + does by serializing an object to disk (currently in WEB-INF). If recovering this + fails, the EventAwareCache is notified, and it is expected to ensure there are no + orphaned EventValidities (currently by clearing the entire cache). + </li> + </ul> + Note that though this example extends the jxtg in combination with actions or flow, + any pipeline component can be + made to use EventValidity, and any code with access to the ServiceManager can + translate real-world events to Events and notify the Cache of them. + </para> + </content> +</page> Propchange: cocoon/trunk/src/blocks/eventcache/samples/eventcache.xml ------------------------------------------------------------------------------ svn:eol-style = native Propchange: cocoon/trunk/src/blocks/eventcache/samples/eventcache.xml ------------------------------------------------------------------------------ svn:keywords = Id Modified: cocoon/trunk/src/blocks/eventcache/samples/sitemap.xmap URL: http://svn.apache.org/viewcvs/cocoon/trunk/src/blocks/eventcache/samples/sitemap.xmap?view=diff&r1=155003&r2=155004 ============================================================================== --- cocoon/trunk/src/blocks/eventcache/samples/sitemap.xmap (original) +++ cocoon/trunk/src/blocks/eventcache/samples/sitemap.xmap Wed Feb 23 04:31:40 2005 @@ -1,6 +1,6 @@ <?xml version="1.0"?> <!-- - Copyright 1999-2004 The Apache Software Foundation + Copyright 1999-2005 The Apache Software Foundation Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -18,11 +18,14 @@ <!--+ | Event Cache Sample | - | CVS $Id: sitemap.xmap,v 1.7 2004/03/11 16:25:47 stephan Exp $ + | CVS $Id$ +--> <map:sitemap xmlns:map="http://apache.org/cocoon/sitemap/1.0"> <map:components> + <map:generators> + <map:generator name="sample" src="org.apache.cocoon.samples.EventAwareGenerator"/> + </map:generators> <map:actions> <map:action name="cacheevent" src="org.apache.cocoon.acting.CacheEventAction"/> </map:actions> @@ -50,23 +53,27 @@ <map:pipeline type="event-aware"> <map:match pattern="flow"> - <map:call function="cacheEvent"/> + <map:call function="cacheEvent"/> </map:match> - <map:match pattern="action"> - <map:act type="cacheevent"> - <map:parameter name="event" value="{request-param:event}"/> + <map:match pattern="action"> + <map:act type="cacheevent"> + <map:parameter name="event" value="{request-param:event}"/> </map:act> - <map:redirect-to uri="demo?pageKey={request-param:pageKey}&rand={random:x}"/> - </map:match> + <map:redirect-to uri="demo?pageKey={request-param:pageKey}&rand={random:x}"/> + </map:match> <map:match pattern="*"> - <map:generate type="serverpages" src="eventcache.xsp"/> - <map:transform src="context://samples/stylesheets/dynamic-page2html.xsl"> - <map:parameter name="servletPath" value="{request:servletPath}"/> - <map:parameter name="sitemapURI" value="{request:sitemapURI}"/> - <map:parameter name="contextPath" value="{request:contextPath}"/> - <map:parameter name="file" value="eventcache.xsp"/> - <map:parameter name="remove" value="{0}"/> - </map:transform> + <map:generate type="sample" src="eventcache.xml"> + <map:parameter name="DELAY_SECS" value="2"/> + <map:parameter name="DATE" value="{date:date}"/> + <map:parameter name="KEY" value="{request-param:pageKey}"/> + </map:generate> + <map:transform src="context://samples/stylesheets/dynamic-page2html.xsl"> + <map:parameter name="servletPath" value="{request:servletPath}"/> + <map:parameter name="sitemapURI" value="{request:sitemapURI}"/> + <map:parameter name="contextPath" value="{request:contextPath}"/> + <map:parameter name="file" value="eventcache.xsp"/> + <map:parameter name="remove" value="{0}"/> + </map:transform> <map:serialize/> </map:match> </map:pipeline> Modified: cocoon/trunk/src/java/org/apache/cocoon/cocoon.roles URL: http://svn.apache.org/viewcvs/cocoon/trunk/src/java/org/apache/cocoon/cocoon.roles?view=diff&r1=155003&r2=155004 ============================================================================== --- cocoon/trunk/src/java/org/apache/cocoon/cocoon.roles (original) +++ cocoon/trunk/src/java/org/apache/cocoon/cocoon.roles Wed Feb 23 04:31:40 2005 @@ -155,141 +155,6 @@ <role name="org.apache.cocoon.components.notification.NotifyingBuilder" shorthand="notifying-builder" default-class="org.apache.cocoon.components.notification.DefaultNotifyingBuilder" - - default-class CDATA #IMPLIED -> -<!ATTLIST hint shorthand CDATA #REQUIRED - class CDATA #REQUIRED -> -]> - -<role-list> - - <role name="org.apache.excalibur.source.SourceFactorySelector" - shorthand="source-factories" - default-class="org.apache.cocoon.core.container.DefaultServiceSelector"> - </role> - - <role name="org.apache.excalibur.source.SourceResolver" - shorthand="source-resolver" - default-class="org.apache.cocoon.components.source.CocoonSourceResolver"/> - - <!-- The entity resolver used by most parsers --> - <role name="org.apache.excalibur.xml.EntityResolver" - shorthand="entity-resolver" - default-class="org.apache.cocoon.components.resolver.DefaultResolver"/> - - <!-- Parser: - - Starting with Cocoon 2.1 we have a bunch of different parser: - - a SAX parser (producing SAX events) - - a DOM parser (producint a document) - - an HTML parser (producing SAX events from an HTML document) - ... - --> - - <!-- This is the usual SAX parser --> - <role name="org.apache.excalibur.xml.sax.SAXParser" - shorthand="xml-parser" - default-class="org.apache.excalibur.xml.impl.JaxpParser"/> - - <!-- This is the usual DOM parser --> - <role name="org.apache.excalibur.xml.dom.DOMParser" - shorthand="dom-parser" - default-class="org.apache.excalibur.xml.impl.JaxpParser"/> - - <!-- A Dom Serializer --> - <role default-class="org.apache.excalibur.xml.dom.DefaultDOMSerializer" name="org.apache.excalibur.xml.dom.DOMSerializer" shorthand="dom-serializer"/> - - <!-- XSLT: --> - <role name="org.apache.excalibur.xml.xslt.XSLTProcessor" - shorthand="xslt-processor" - default-class="org.apache.excalibur.xml.xslt.XSLTProcessorImpl"/> - - <role name="org.apache.excalibur.xml.xpath.XPathProcessor" - shorthand="xpath-processor" - default-class="org.apache.excalibur.xml.xpath.XPathProcessorImpl"/> - - <!-- Stores: --> - <role name="org.apache.excalibur.store.Store" - shorthand="store" - default-class="org.apache.cocoon.components.store.impl.EHDefaultStore"/> - - <role name="org.apache.excalibur.store.Store/TransientStore" - shorthand="transient-store" - default-class="org.apache.cocoon.components.store.impl.DefaultTransientStore"/> - -<!-- - The persistent store is only an auxiliary store that shouldn't be - used by Cocoon users. It should only be used - if required - by - the Store. If we use JCS, we don't need a persistent store. - <role name="org.apache.excalibur.store.Store/PersistentStore" - shorthand="persistent-store" - default-class="org.apache.cocoon.components.store.impl.DefaultPersistentStore"/> ---> - <!-- Normally uses the org.apache.excalibur.store.impl.StoreJanitorImpl as - the default-class but as that uses its own Thread spawning there is - the org.apache.cocoon.components.store.impl.CocoonStoreJanitor class - to use a daemon thread from the org.apache.cocoon.components.thread.RunnableManager - component - NOT: As soon as our patch has been accepted by the Excalibur community and an - excalibur-store has been release we can switch back to the original - org.apache.excalibur.store.impl.StoreJanitorImpl class - --> - <role name="org.apache.excalibur.store.StoreJanitor" - shorthand="store-janitor" - default-class="org.apache.cocoon.components.store.impl.CocoonStoreJanitor"/> - - <!--========================================================================= - Sitemap engine - =========================================================================--> - - <!-- the sitemap engine --> - <role name="org.apache.cocoon.Processor" - shorthand="sitemap" - default-class="org.apache.cocoon.components.treeprocessor.TreeProcessor"/> - - <!-- the tree builder for the sitemap language (additional implementations can be added here - or in cocoon.xconf for other implementations) --> - <role name="org.apache.cocoon.components.treeprocessor.TreeBuilder/sitemap-1.0" - default-class="org.apache.cocoon.components.treeprocessor.sitemap.SitemapLanguage"/> - - <!-- the various elements of map:components --> - <role name="org.apache.cocoon.components.pipeline.ProcessingPipelineSelector" - shorthand="pipes" - default-class="org.apache.cocoon.components.treeprocessor.sitemap.ComponentsSelector"/> - - <role name="org.apache.cocoon.acting.ActionSelector" - shorthand="actions" - default-class="org.apache.cocoon.components.treeprocessor.sitemap.ComponentsSelector"/> - - <role name="org.apache.cocoon.selection.SelectorSelector" - shorthand="selectors" - default-class="org.apache.cocoon.components.treeprocessor.sitemap.ComponentsSelector"/> - - <role name="org.apache.cocoon.matching.MatcherSelector" - shorthand="matchers" - default-class="org.apache.cocoon.components.treeprocessor.sitemap.ComponentsSelector"/> - - <role name="org.apache.cocoon.generation.GeneratorSelector" - shorthand="generators" - default-class="org.apache.cocoon.components.treeprocessor.sitemap.ComponentsSelector"/> - - <role name="org.apache.cocoon.transformation.TransformerSelector" - shorthand="transformers" - default-class="org.apache.cocoon.components.treeprocessor.sitemap.ComponentsSelector"/> - - <role name="org.apache.cocoon.serialization.SerializerSelector" - shorthand="serializers" - default-class="org.apache.cocoon.components.treeprocessor.sitemap.ComponentsSelector"/> - - <role name="org.apache.cocoon.reading.ReaderSelector" - shorthand="readers" - default-class="org.apache.cocoon.components.treeprocessor.sitemap.ComponentsSelector"/> - - <role name="org.apache.cocoon.components.notification.NotifyingBuilder" - shorthand="notifying-builder" - default-class="org.apache.cocoon.components.notification.DefaultNotifyingBuilder" model="non-thread-safe-pooled"/> <!-- system-defined sitemap components -->