cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cziege...@apache.org
Subject svn commit: r155005 - in cocoon/branches/BRANCH_2_1_X: ./ src/blocks/eventcache/java/org/apache/cocoon/samples/ src/blocks/eventcache/samples/
Date Wed, 23 Feb 2005 13:02:13 GMT
Author: cziegeler
Date: Wed Feb 23 05:02:09 2005
New Revision: 155005

URL: http://svn.apache.org/viewcvs?view=rev&rev=155005
Log:
rewrote event cache sample from xsp to java, so no dependency to xsp anymore

Added:
    cocoon/branches/BRANCH_2_1_X/src/blocks/eventcache/java/org/apache/cocoon/samples/
    cocoon/branches/BRANCH_2_1_X/src/blocks/eventcache/java/org/apache/cocoon/samples/EventAwareGenerator.java
  (with props)
    cocoon/branches/BRANCH_2_1_X/src/blocks/eventcache/samples/eventcache.xml   (with props)
Removed:
    cocoon/branches/BRANCH_2_1_X/src/blocks/eventcache/samples/eventcache.xsp
Modified:
    cocoon/branches/BRANCH_2_1_X/blocks.properties
    cocoon/branches/BRANCH_2_1_X/gump.xml
    cocoon/branches/BRANCH_2_1_X/src/blocks/eventcache/samples/sitemap.xmap

Modified: cocoon/branches/BRANCH_2_1_X/blocks.properties
URL: http://svn.apache.org/viewcvs/cocoon/branches/BRANCH_2_1_X/blocks.properties?view=diff&r1=155004&r2=155005
==============================================================================
--- cocoon/branches/BRANCH_2_1_X/blocks.properties (original)
+++ cocoon/branches/BRANCH_2_1_X/blocks.properties Wed Feb 23 05:02:09 2005
@@ -50,7 +50,6 @@
 #-----[dependency]: "batik" is needed by "fop", "scratchpad", "tour".
 #include.block.batik=false
 #include.block.bsf=false
-#-----[dependency]: "chaperon" depends on "xsp" (for samples).
 #include.block.chaperon=false
 #-----[dependency]: "databases" depends on "xsp".
 #-----[dependency]: "databases" is needed by "hsqldb", "jms", "ojb", "petstore", "repository",
"xmldb".
@@ -61,7 +60,6 @@
 #-----[dependency]: "hsqldb" depends on "databases".
 #-----[dependency]: "hsqldb" is needed by "jms", "ojb", "petstore".
 #include.block.hsqldb=false
-#-----[dependency]: "html" is needed by "portal".
 #include.block.html=false
 #include.block.itext=false
 #include.block.jfor=false
@@ -73,7 +71,7 @@
 #include.block.naming=false
 #include.block.paranoid=false
 #include.block.poi=false
-#-----[dependency]: "portal" depends on "authentication-fw", "html", "session-fw", "forms",
"cron".
+#-----[dependency]: "portal" depends on "authentication-fw", "cron", "forms", "session-fw".
 #-----[dependency]: "portal" is needed by "faces".
 #include.block.portal=false
 #include.block.profiler=false
@@ -87,7 +85,7 @@
 #include.block.web3=false
 #-----[dependency]: "xmldb" depends on "databases".
 #include.block.xmldb=false
-#-----[dependency]: "xsp" is needed by "chaperon", "databases", "eventcache", "forms", "linkrewriter",
"lucene", "python", "scratchpad", "session-fw", "woody".
+#-----[dependency]: "xsp" is needed by "databases", "forms", "linkrewriter", "lucene", "python",
"scratchpad", "session-fw", "woody".
 #include.block.xsp=false
 
 # Unstable blocks --------------------------------------------------------------
@@ -106,16 +104,16 @@
 #include.block.asciiart=false
 #-----[dependency]: "axis" is needed by "scratchpad".
 #include.block.axis=false
-#-----[dependency]: "cron" is needed by "scratchpad", "portal".
+#-----[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", "scratchpad".
 #include.block.eventcache=false
 #-----[dependency]: "faces" depends on "portal", "taglib".
 #include.block.faces=false
 #-----[dependency]: "forms" depends on "xsp" (for samples).
-#-----[dependency]: "forms" is needed by "apples", "javaflow", "lucene", "ojb", "petstore",
"tour", "portal".
+#-----[dependency]: "forms" is needed by "apples", "javaflow", "lucene", "ojb", "petstore",
"portal", "tour".
 #include.block.forms=false
 #-----[dependency]: "javaflow" depends on "forms", "ojb".
 #include.block.javaflow=false

Modified: cocoon/branches/BRANCH_2_1_X/gump.xml
URL: http://svn.apache.org/viewcvs/cocoon/branches/BRANCH_2_1_X/gump.xml?view=diff&r1=155004&r2=155005
==============================================================================
--- cocoon/branches/BRANCH_2_1_X/gump.xml (original)
+++ cocoon/branches/BRANCH_2_1_X/gump.xml Wed Feb 23 05:02:09 2005
@@ -1056,7 +1056,6 @@
     <depend project="cocoon" inherit="all"/>
     <depend project="cocoon-block-jms"/>
     <depend project="jms"/>
-    <depend project="cocoon-block-xsp" type="samples"/>
     
     <work nested="build/cocoon-@@DATE@@/blocks/eventcache/dest"/>
     <work nested="build/cocoon-@@DATE@@/blocks/eventcache/test"/>

Added: cocoon/branches/BRANCH_2_1_X/src/blocks/eventcache/java/org/apache/cocoon/samples/EventAwareGenerator.java
URL: http://svn.apache.org/viewcvs/cocoon/branches/BRANCH_2_1_X/src/blocks/eventcache/java/org/apache/cocoon/samples/EventAwareGenerator.java?view=auto&rev=155005
==============================================================================
--- cocoon/branches/BRANCH_2_1_X/src/blocks/eventcache/java/org/apache/cocoon/samples/EventAwareGenerator.java
(added)
+++ cocoon/branches/BRANCH_2_1_X/src/blocks/eventcache/java/org/apache/cocoon/samples/EventAwareGenerator.java
Wed Feb 23 05:02:09 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/branches/BRANCH_2_1_X/src/blocks/eventcache/java/org/apache/cocoon/samples/EventAwareGenerator.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cocoon/branches/BRANCH_2_1_X/src/blocks/eventcache/java/org/apache/cocoon/samples/EventAwareGenerator.java
------------------------------------------------------------------------------
    svn:keywords = Id

Added: cocoon/branches/BRANCH_2_1_X/src/blocks/eventcache/samples/eventcache.xml
URL: http://svn.apache.org/viewcvs/cocoon/branches/BRANCH_2_1_X/src/blocks/eventcache/samples/eventcache.xml?view=auto&rev=155005
==============================================================================
--- cocoon/branches/BRANCH_2_1_X/src/blocks/eventcache/samples/eventcache.xml (added)
+++ cocoon/branches/BRANCH_2_1_X/src/blocks/eventcache/samples/eventcache.xml Wed Feb 23 05:02:09
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&amp;event=one">uncache with action</a>)

+                    (<a href="flow?pageKey=one&amp;event=one">uncache with flow</a>)</li>
+                <li><a href="?pageKey=two">pageKey=two</a>
+                    (<a href="action?pageKey=two&amp;event=two">uncache with action</a>)

+                    (<a href="flow?pageKey=two&amp;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/branches/BRANCH_2_1_X/src/blocks/eventcache/samples/eventcache.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cocoon/branches/BRANCH_2_1_X/src/blocks/eventcache/samples/eventcache.xml
------------------------------------------------------------------------------
    svn:keywords = Id

Modified: cocoon/branches/BRANCH_2_1_X/src/blocks/eventcache/samples/sitemap.xmap
URL: http://svn.apache.org/viewcvs/cocoon/branches/BRANCH_2_1_X/src/blocks/eventcache/samples/sitemap.xmap?view=diff&r1=155004&r2=155005
==============================================================================
--- cocoon/branches/BRANCH_2_1_X/src/blocks/eventcache/samples/sitemap.xmap (original)
+++ cocoon/branches/BRANCH_2_1_X/src/blocks/eventcache/samples/sitemap.xmap Wed Feb 23 05:02:09
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}&amp;rand={random:x}"/>
-	  </map:match>
+        <map:redirect-to uri="demo?pageKey={request-param:pageKey}&amp;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>



Mime
View raw message