ghoward     2003/10/01 21:21:17

  Modified:    src/blocks/eventcache/java/org/apache/cocoon/caching/impl
                        DefaultEventRegistryImpl.java
                        EventAwareCacheImpl.java
               src/blocks/eventcache/java/org/apache/cocoon/acting
                        CacheEventAction.java
               src/blocks/eventcache/samples sitemap.xmap event.js
                        eventcache.xsp
               src/blocks/eventcache/java/org/apache/cocoon/caching
                        EventRegistry.java
  Log:
  Fix event cache samples.
  
  Revision  Changes    Path
  1.7       +9 -9      
cocoon-2.1/src/blocks/eventcache/java/org/apache/cocoon/caching/impl/DefaultEventRegistryImpl.java
  
  Index: DefaultEventRegistryImpl.java
  ===================================================================
  RCS file: 
/home/cvs/cocoon-2.1/src/blocks/eventcache/java/org/apache/cocoon/caching/impl/DefaultEventRegistryImpl.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- DefaultEventRegistryImpl.java     24 Sep 2003 21:22:33 -0000      1.6
  +++ DefaultEventRegistryImpl.java     2 Oct 2003 04:21:17 -0000       1.7
  @@ -57,6 +57,7 @@
   import java.io.IOException;
   import java.io.ObjectInputStream;
   import java.io.ObjectOutputStream;
  +import java.io.Serializable;
   import java.util.Collection;
   import java.util.Iterator;
   import java.util.Set;
  @@ -70,7 +71,6 @@
   import org.apache.avalon.framework.thread.ThreadSafe;
   import org.apache.cocoon.Constants;
   import org.apache.cocoon.caching.EventRegistry;
  -import org.apache.cocoon.caching.PipelineCacheKey;
   import org.apache.cocoon.caching.validity.Event;
   import org.apache.commons.collections.MultiHashMap;
   
  @@ -105,7 +105,7 @@
        * @param event The event to 
        * @param key
        */
  -    public void register(Event e, PipelineCacheKey key) {
  +    public void register(Event e, Serializable key) {
           synchronized(this) {
               m_keyMMap.put(key,e);
               m_eventMMap.put(e,key);
  @@ -125,7 +125,7 @@
       /**
        * Retrieve all pipeline keys mapped to this event.
        */
  -    public PipelineCacheKey[] keysForEvent(Event e) {
  +    public Serializable[] keysForEvent(Event e) {
           Collection coll = (Collection)m_eventMMap.get(e);
           if (coll==null || coll.isEmpty()) {
               if (getLogger().isDebugEnabled()) {
  @@ -133,24 +133,24 @@
               }
               return null;
           } else {
  -            return (PipelineCacheKey[])coll.toArray(new 
PipelineCacheKey[coll.size()]);
  +            return (Serializable[])coll.toArray(new 
Serializable[coll.size()]);
           }
       }
   
       /**
        * Return all pipeline keys mapped to any event
        */
  -    public PipelineCacheKey[] allKeys() {
  +    public Serializable[] allKeys() {
           Set keys = this.m_keyMMap.keySet();
  -        return (PipelineCacheKey[])keys.toArray(
  -                        new PipelineCacheKey[keys.size()]);
  +        return (Serializable[])keys.toArray(
  +                        new Serializable[keys.size()]);
       }
   
       /**
        * When a CachedResponse is removed from the Cache, any entries 
        * in the event mapping must be cleaned up.
        */
  -    public void removeKey(PipelineCacheKey key) {
  +    public void removeKey(Serializable key) {
           Collection coll = (Collection)m_keyMMap.get(key);
           if (coll==null || coll.isEmpty()) {
               return;
  
  
  
  1.6       +29 -19    
cocoon-2.1/src/blocks/eventcache/java/org/apache/cocoon/caching/impl/EventAwareCacheImpl.java
  
  Index: EventAwareCacheImpl.java
  ===================================================================
  RCS file: 
/home/cvs/cocoon-2.1/src/blocks/eventcache/java/org/apache/cocoon/caching/impl/EventAwareCacheImpl.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- EventAwareCacheImpl.java  5 Sep 2003 04:02:51 -0000       1.5
  +++ EventAwareCacheImpl.java  2 Oct 2003 04:21:17 -0000       1.6
  @@ -45,6 +45,7 @@
   */
   package org.apache.cocoon.caching.impl;
   
  +import java.io.Serializable;
   import java.util.Iterator;
   
   import org.apache.avalon.framework.activity.Initializable;
  @@ -92,17 +93,26 @@
        * 
        * <code>AggregatedValidity</code> is handled recursively.
         */
  -     public void store(PipelineCacheKey key,
  +     public void store(Serializable key,
                                CachedResponse response)
                                throws ProcessingException {
           SourceValidity[] validities = response.getValidityObjects();
           for (int i=0; i< validities.length;i++) {
               SourceValidity val = validities[i];
  -                     examineValidity(val, key);
  +            examineValidity(val, key);
           }
  -             super.store(key, response);
  +        super.store(key, response);
        }
   
  +    /* (non-Javadoc)
  +     * @see org.apache.cocoon.caching.Cache#store(java.io.Serializable, 
org.apache.cocoon.caching.CachedResponse)
  +     
  +    public void store(Serializable key, CachedResponse response)
  +        throws ProcessingException {
  +        // TODO Auto-generated method stub
  +        super.store(key, response);
  +    }*/
  +
       /**
        * Look up the EventRegistry 
        */
  @@ -129,19 +139,19 @@
        */
       public void processEvent(Event e) {
           if (e == null) return;
  -        PipelineCacheKey[] pcks = m_eventRegistry.keysForEvent(e);
  -        if (pcks == null) return;
  -        for (int i=0;i<pcks.length; i++) {
  -            if (pcks[i] != null) {
  +        Serializable[] keys = m_eventRegistry.keysForEvent(e);
  +        if (keys == null) return;
  +        for (int i=0;i<keys.length; i++) {
  +            if (keys[i] != null) {
                   if (getLogger().isDebugEnabled()) {
  -                    getLogger().debug("Processing cache event, found 
Pipeline key: " + pcks[i].toString());
  +                    getLogger().debug("Processing cache event, found 
Pipeline key: " + keys[i].toString());
                   }
                   /* every pck associated with this event needs to be
                    * removed -- regardless of event mapping. and every 
                    * event mapped to those keys needs to be removed 
                    * recursively.
                    */ 
  -                remove(pcks[i]);
  +                remove(keys[i]);
               }
           }
       }
  @@ -168,14 +178,14 @@
        * removed abnormally or is not configured with persistence.
        */
       public void veryifyEventCache() {
  -        PipelineCacheKey[] pcks = m_eventRegistry.allKeys();
  -        if (pcks == null) return;
  -        for (int i=0; i<pcks.length; i++) {
  -            if (!this.containsKey(pcks[i])) {
  -                m_eventRegistry.removeKey(pcks[i]);
  +        Serializable[] keys = m_eventRegistry.allKeys();
  +        if (keys == null) return;
  +        for (int i=0; i<keys.length; i++) {
  +            if (!this.containsKey(keys[i])) {
  +                m_eventRegistry.removeKey(keys[i]);
                   if (getLogger().isDebugEnabled()) {
                       getLogger().debug("Cache key no longer valid: " + 
  -                            pcks[i]);
  +                            keys[i]);
                   }
               }
           }
  @@ -191,7 +201,7 @@
           m_eventRegistry = null;
        }
   
  -    private void examineValidity(SourceValidity val, PipelineCacheKey key) {
  +    private void examineValidity(SourceValidity val, Serializable key) {
           if (val instanceof AggregatedValidity) {
               handleAggregatedValidity((AggregatedValidity)val, key);
           } else if (val instanceof EventValidity) {
  @@ -201,7 +211,7 @@
   
       private void handleAggregatedValidity(
                                       AggregatedValidity val,
  -                                    PipelineCacheKey key) {
  +                                    Serializable key) {
           // AggregatedValidity must be investigated further.
            Iterator it = val.getValidities().iterator();
            while (it.hasNext()) {
  @@ -211,7 +221,7 @@
            }
       }
   
  -    private void handleEventValidity(EventValidity val, PipelineCacheKey 
key) {
  +    private void handleEventValidity(EventValidity val, Serializable key) {
           if (getLogger().isDebugEnabled()) {
               getLogger().debug("Found EventValidity: " + val.toString());
           }
  
  
  
  1.3       +2 -5      
cocoon-2.1/src/blocks/eventcache/java/org/apache/cocoon/acting/CacheEventAction.java
  
  Index: CacheEventAction.java
  ===================================================================
  RCS file: 
/home/cvs/cocoon-2.1/src/blocks/eventcache/java/org/apache/cocoon/acting/CacheEventAction.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- CacheEventAction.java     4 Aug 2003 03:06:30 -0000       1.2
  +++ CacheEventAction.java     2 Oct 2003 04:21:17 -0000       1.3
  @@ -62,9 +62,6 @@
   import org.apache.cocoon.environment.SourceResolver;
   
   /**
  - * Very experimental start at external cache invalidation.
  - * Warning - API very unstable.  Do not use!  
  - * 
    * Simple action to cause notification of a NamedEvent to an 
EventAwareCacheImpl.
    * The event name is taken from a sitemap parameter named "event".
    * 
  @@ -88,7 +85,7 @@
                       String src,
                       Parameters par
       ) throws Exception {
  -        Cache cache = (Cache)this.manager.lookup(Cache.ROLE);
  +        Cache cache = (Cache)this.manager.lookup(Cache.ROLE + "/EventAware");
           if (cache instanceof EventAwareCacheImpl) {
               String eventName = par.getParameter("event");
               if (getLogger().isDebugEnabled()) {
  
  
  
  1.3       +3 -0      cocoon-2.1/src/blocks/eventcache/samples/sitemap.xmap
  
  Index: sitemap.xmap
  ===================================================================
  RCS file: /home/cvs/cocoon-2.1/src/blocks/eventcache/samples/sitemap.xmap,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- sitemap.xmap      11 Aug 2003 09:50:40 -0000      1.2
  +++ sitemap.xmap      2 Oct 2003 04:21:17 -0000       1.3
  @@ -17,7 +17,9 @@
       <map:actions>
        <map:action name="cacheevent" 
src="org.apache.cocoon.acting.CacheEventAction"/>
       </map:actions>
  +    
       <map:pipes default="caching">
  +       <!-- A pipe must be defined configured to use the EventAware cache. 
-->
         <map:pipe name="event-aware" 
src="org.apache.cocoon.components.pipeline.impl.CachingProcessingPipeline">
           <parameter name="cache-role" 
value="org.apache.cocoon.caching.Cache/EventAware"/>
         </map:pipe>
  @@ -35,6 +37,7 @@
     </map:views>
   
     <map:pipelines>
  +     <!-- Our content must occur in a pipeline configured to use our Event 
Aware cache --> 
       <map:pipeline type="event-aware">
         
         <map:match pattern="flow">
  
  
  
  1.3       +1 -1      cocoon-2.1/src/blocks/eventcache/samples/event.js
  
  Index: event.js
  ===================================================================
  RCS file: /home/cvs/cocoon-2.1/src/blocks/eventcache/samples/event.js,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- event.js  21 Jul 2003 01:54:37 -0000      1.2
  +++ event.js  2 Oct 2003 04:21:17 -0000       1.3
  @@ -1,4 +1,4 @@
  -var role = Packages.org.apache.cocoon.caching.Cache.ROLE;
  +var role = Packages.org.apache.cocoon.caching.Cache.ROLE + "/EventAware";
   
   function cacheEvent() {
        var cache = cocoon.getComponent(role);
  
  
  
  1.2       +5 -4      cocoon-2.1/src/blocks/eventcache/samples/eventcache.xsp
  
  Index: eventcache.xsp
  ===================================================================
  RCS file: /home/cvs/cocoon-2.1/src/blocks/eventcache/samples/eventcache.xsp,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- eventcache.xsp    14 Jul 2003 02:50:45 -0000      1.1
  +++ eventcache.xsp    2 Oct 2003 04:21:17 -0000       1.2
  @@ -3,7 +3,7 @@
   <!--
       XSP event-based cache sample.
   
  -    $Id$
  +    Cvs $Id$
    -->
   
   
  @@ -100,10 +100,10 @@
                </para>
           <para>Test links:
               <ul>
  -                <li><a target="_new" href="?pageKey=one">pageKey=one</a> 
  +                <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 target="_new" href="?pageKey=two">pageKey=two</a>
  +                <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>
  @@ -127,7 +127,8 @@
                                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.</li>
  +                             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 
  
  
  
  1.3       +7 -5      
cocoon-2.1/src/blocks/eventcache/java/org/apache/cocoon/caching/EventRegistry.java
  
  Index: EventRegistry.java
  ===================================================================
  RCS file: 
/home/cvs/cocoon-2.1/src/blocks/eventcache/java/org/apache/cocoon/caching/EventRegistry.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- EventRegistry.java        20 Jul 2003 21:08:06 -0000      1.2
  +++ EventRegistry.java        2 Oct 2003 04:21:17 -0000       1.3
  @@ -50,6 +50,8 @@
   */
   package org.apache.cocoon.caching;
   
  +import java.io.Serializable;
  +
   import org.apache.avalon.framework.component.Component;
   import org.apache.cocoon.caching.validity.Event;
   
  @@ -76,14 +78,14 @@
        * @param event
        * @param key
        */
  -    public void register(Event e, PipelineCacheKey key);
  +    public void register(Event e, Serializable key);
       
       /**
        * Remove all occurances of the specified key from the registry.
        * 
        * @param key - The key to remove.
        */
  -    public void removeKey(PipelineCacheKey key);
  +    public void removeKey(Serializable key);
       
       /**
        * Retrieve an array of all keys mapped to this event.
  @@ -92,7 +94,7 @@
        * @return an array of keys which should not be modified or null if 
        *      no keys are mapped to this event.
        */
  -    public PipelineCacheKey[] keysForEvent(Event e);
  +    public Serializable[] keysForEvent(Event e);
       
       /**
        * Retrieve an array of all keys regardless of event mapping, or null if
  @@ -100,7 +102,7 @@
        * 
        * @return an array of keys which should not be modified
        */
  -    public PipelineCacheKey[] allKeys(); 
  +    public Serializable[] allKeys(); 
       
       /**
        * Clear all event-key mappings from the registry.
  
  
  

Reply via email to