Return-Path: Delivered-To: apmail-cocoon-cvs-archive@www.apache.org Received: (qmail 49793 invoked from network); 23 Feb 2005 13:02:17 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur-2.apache.org with SMTP; 23 Feb 2005 13:02:17 -0000 Received: (qmail 45798 invoked by uid 500); 23 Feb 2005 13:02:16 -0000 Delivered-To: apmail-cocoon-cvs-archive@cocoon.apache.org Received: (qmail 45744 invoked by uid 500); 23 Feb 2005 13:02:15 -0000 Mailing-List: contact cvs-help@cocoon.apache.org; run by ezmlm Precedence: bulk Reply-To: dev@cocoon.apache.org list-help: list-unsubscribe: List-Post: Delivered-To: mailing list cvs@cocoon.apache.org Received: (qmail 45730 invoked by uid 99); 23 Feb 2005 13:02:15 -0000 X-ASF-Spam-Status: No, hits=-9.8 required=10.0 tests=ALL_TRUSTED,NO_REAL_NAME X-Spam-Check-By: apache.org Received: from minotaur.apache.org (HELO minotaur.apache.org) (209.237.227.194) by apache.org (qpsmtpd/0.28) with SMTP; Wed, 23 Feb 2005 05:02:15 -0800 Received: (qmail 49691 invoked by uid 65534); 23 Feb 2005 13:02:13 -0000 Message-ID: <20050223130213.49689.qmail@minotaur.apache.org> Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Mailer: svnmailer-1.0.0-dev Date: Wed, 23 Feb 2005 13:02:13 -0000 Subject: svn commit: r155005 - in cocoon/branches/BRANCH_2_1_X: ./ src/blocks/eventcache/java/org/apache/cocoon/samples/ src/blocks/eventcache/samples/ To: cvs@cocoon.apache.org From: cziegeler@apache.org X-Virus-Checked: Checked X-Spam-Rating: minotaur-2.apache.org 1.6.2 0/1000/N Author: cziegeler Date: Wed Feb 23 05:02:09 2005 New Revision: 155005 URL: http://svn.apache.org/viewcvs?view=3Drev&rev=3D155005 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/coco= on/samples/ cocoon/branches/BRANCH_2_1_X/src/blocks/eventcache/java/org/apache/coco= on/samples/EventAwareGenerator.java (with props) cocoon/branches/BRANCH_2_1_X/src/blocks/eventcache/samples/eventcache.x= ml (with props) Removed: cocoon/branches/BRANCH_2_1_X/src/blocks/eventcache/samples/eventcache.x= sp 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.prop= erties?view=3Ddiff&r1=3D155004&r2=3D155005 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D --- 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=3Dfalse #include.block.bsf=3Dfalse -#-----[dependency]: "chaperon" depends on "xsp" (for samples). #include.block.chaperon=3Dfalse #-----[dependency]: "databases" depends on "xsp". #-----[dependency]: "databases" is needed by "hsqldb", "jms", "ojb", "pets= tore", "repository", "xmldb". @@ -61,7 +60,6 @@ #-----[dependency]: "hsqldb" depends on "databases". #-----[dependency]: "hsqldb" is needed by "jms", "ojb", "petstore". #include.block.hsqldb=3Dfalse -#-----[dependency]: "html" is needed by "portal". #include.block.html=3Dfalse #include.block.itext=3Dfalse #include.block.jfor=3Dfalse @@ -73,7 +71,7 @@ #include.block.naming=3Dfalse #include.block.paranoid=3Dfalse #include.block.poi=3Dfalse -#-----[dependency]: "portal" depends on "authentication-fw", "html", "sess= ion-fw", "forms", "cron". +#-----[dependency]: "portal" depends on "authentication-fw", "cron", "form= s", "session-fw". #-----[dependency]: "portal" is needed by "faces". #include.block.portal=3Dfalse #include.block.profiler=3Dfalse @@ -87,7 +85,7 @@ #include.block.web3=3Dfalse #-----[dependency]: "xmldb" depends on "databases". #include.block.xmldb=3Dfalse -#-----[dependency]: "xsp" is needed by "chaperon", "databases", "eventcach= e", "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=3Dfalse =20 # Unstable blocks --------------------------------------------------------= ------ @@ -106,16 +104,16 @@ #include.block.asciiart=3Dfalse #-----[dependency]: "axis" is needed by "scratchpad". #include.block.axis=3Dfalse -#-----[dependency]: "cron" is needed by "scratchpad", "portal". +#-----[dependency]: "cron" is needed by "portal", "scratchpad". #include.block.cron=3Dfalse #include.block.deli=3Dfalse -#-----[dependency]: "eventcache" depends on "jms", "xsp" (for samples). +#-----[dependency]: "eventcache" depends on "jms". #-----[dependency]: "eventcache" is needed by "repository", "scratchpad". #include.block.eventcache=3Dfalse #-----[dependency]: "faces" depends on "portal", "taglib". #include.block.faces=3Dfalse #-----[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=3Dfalse #-----[dependency]: "javaflow" depends on "forms", "ojb". #include.block.javaflow=3Dfalse Modified: cocoon/branches/BRANCH_2_1_X/gump.xml URL: http://svn.apache.org/viewcvs/cocoon/branches/BRANCH_2_1_X/gump.xml?vi= ew=3Ddiff&r1=3D155004&r2=3D155005 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D --- 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 @@ - =20 Added: cocoon/branches/BRANCH_2_1_X/src/blocks/eventcache/java/org/apache/c= ocoon/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=3Da= uto&rev=3D155005 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D --- cocoon/branches/BRANCH_2_1_X/src/blocks/eventcache/java/org/apache/coco= on/samples/EventAwareGenerator.java (added) +++ cocoon/branches/BRANCH_2_1_X/src/blocks/eventcache/java/org/apache/coco= on/samples/EventAwareGenerator.java Wed Feb 23 05:02:09 2005 @@ -0,0 +1,91 @@ +/* + * Copyright 2005 The Apache Software Foundation. + *=20 + * 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 + *=20 + * http://www.apache.org/licenses/LICENSE-2.0 + *=20 + * 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 us= ed + * 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 =3D ObjectModelHelper.getRequest(this.object= Model); + // for our test, pages having the same value of "pageKey" will sha= re + // the same cache location + String key =3D request.getParameter("pageKey") ; + return ((key=3D=3Dnull||"".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=20 + * be until an Event is retrieved matching the NamedEvent created belo= w=2E + * + * 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 =3D ObjectModelHelper.getRequest(this.object= Model); + String key =3D request.getParameter("pageKey") ; + return new EventValidity( + new NamedEvent( + (key=3D=3Dnull||"".equals(key)) ? "one" : key)); + } + + + /* (non-Javadoc) + * @see org.apache.cocoon.generation.Generator#generate() + */ + public void generate()=20 + throws IOException, SAXException, ProcessingException { + super.generate(); + // slowdown page generation. + long DELAY_SECS =3D 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/apa= che/cocoon/samples/EventAwareGenerator.java ---------------------------------------------------------------------------= --- svn:eol-style =3D native Propchange: cocoon/branches/BRANCH_2_1_X/src/blocks/eventcache/java/org/apa= che/cocoon/samples/EventAwareGenerator.java ---------------------------------------------------------------------------= --- svn:keywords =3D Id Added: cocoon/branches/BRANCH_2_1_X/src/blocks/eventcache/samples/eventcach= e=2Exml URL: http://svn.apache.org/viewcvs/cocoon/branches/BRANCH_2_1_X/src/blocks/= eventcache/samples/eventcache.xml?view=3Dauto&rev=3D155005 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D --- cocoon/branches/BRANCH_2_1_X/src/blocks/eventcache/samples/eventcache.x= ml (added) +++ cocoon/branches/BRANCH_2_1_X/src/blocks/eventcache/samples/eventcache.x= ml Wed Feb 23 05:02:09 2005 @@ -0,0 +1,104 @@ + + + + + + Demonstrating Event-Aware Caching + + + This page is a sample for event aware caching. We subclassed t= he + JXTG template generate for this sample. If you don't already=20 + understand at least the basics of caching in Cocoon, you shoul= d=20 + probably start there, not here. Read the text below, and the=20 + sitemap and source for more details. + + + I pause for ${cocoon.parameters.DELAY_SECS} seconds during gen= eration, so=20 + that you can tell if I'm being served from the cache or not. +
+ What you see here was generated on ${cocoon.parameters.DATE= }. +
+ + + I'm cached for each unique value of request parameter 'pageKey= '=2E Other=20 + parameters do not matter. +
+ Here the value is: + ${cocoon.parameters.KEY}. =20 +
+ If this is not the same as the 'pageKey' parameter in the page= URL, we have a problem. +
+ + + Unlike other cacheable pages in Cocoon, I can be un-cached by = events external=20 + to Cocoon - for instance, when a database table or row is upda= ted. +
+ My cache entry will be invalidated (actually, removed) when an= event named=20 + ${cocoon.parameters.KEY} occurs. This can be manually=20 + simulated by clicking one of the "uncache" links below. +
+ Test links: + + Note: the random numbers you see included in the url after an = uncache link=20 + serve two purposes in the example, making it easier to see the= effect of the=20 + cache invalidation. They prevent browser caching and they dem= onstrate that=20 + only our designated key matters in the retrieval from cache. =20 + + + This event based cache system consists essentially of three pa= rts: +
    +
  • A new type of SourceValidity, EventValidity, which con= tains information=20 + on the Event which will invalidate this cached content. U= ntil this event is=20 + received, EventValidities will usually always return valid= , though they don't=20 + have to.
  • +
  • An extension to Cocoon's Cache implementation. Cocoon= 's Cache is really just=20 + a thin wrapper around Avalon-Excalibur's Store project. T= he EventAwareCacheImpl=20 + does two things. It examines each pipeline on its way int= o the cache to=20 + determine if any of its SourceValidities are instances of = EventValidity. If so,=20 + it notifies an event registry as described next. The seco= nd critical function of=20 + the EventAware cache implementation is that it allows othe= r components to=20 + contact it and notify it of an Event. The Cache then look= s up the keys=20 + mapped to that event in the event registry and cleans out = the cache and=20 + registry accordingly. See the sitemap of this sample f= or an example of=20 + configuring a pipeline to use this implementation.
  • +
  • The EventRegistry is responsible for mapping Events to= cache keys, and=20 + providing information about that mapping to systems that n= eed it, usually just=20 + the EventAwareCache. Another crucial responsibility of th= e EventRegistry is to=20 + persist its data across container shutdown and startup. T= he default implementation=20 + does by serializing an object to disk (currently in WEB-IN= F). If recovering this=20 + fails, the EventAwareCache is notified, and it is expected= to ensure there are no=20 + orphaned EventValidities (currently by clearing the entire= cache). +
  • +
+ Note that though this example extends the jxtg in combination = with actions or flow,=20 + any pipeline component can be=20 + made to use EventValidity, and any code with access to the Ser= viceManager can=20 + translate real-world events to Events and notify the Cache of = them. =20 +
+
+
Propchange: cocoon/branches/BRANCH_2_1_X/src/blocks/eventcache/samples/even= tcache.xml ---------------------------------------------------------------------------= --- svn:eol-style =3D native Propchange: cocoon/branches/BRANCH_2_1_X/src/blocks/eventcache/samples/even= tcache.xml ---------------------------------------------------------------------------= --- svn:keywords =3D Id Modified: cocoon/branches/BRANCH_2_1_X/src/blocks/eventcache/samples/sitema= p=2Exmap URL: http://svn.apache.org/viewcvs/cocoon/branches/BRANCH_2_1_X/src/blocks/= eventcache/samples/sitemap.xmap?view=3Ddiff&r1=3D155004&r2=3D155005 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D --- 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 @@ =20 + + + @@ -50,23 +53,27 @@ =20 - + - - - + + + - - + + - - - - - - - - + + + + + + + + + + + +