You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@cocoon.apache.org by gh...@apache.org on 2003/07/13 06:40:52 UTC
cvs commit: cocoon-2.1/src/scratchpad/src/org/apache/cocoon/caching EventRegistry.java
ghoward 2003/07/12 21:40:52
Modified: src/scratchpad/src/org/apache/cocoon/caching/impl
EventAwareCacheImpl.java
src/scratchpad/src/org/apache/cocoon/caching/validity
Event.java
Added: src/scratchpad/src/org/apache/cocoon/caching/impl
DefaultEventRegistryImpl.java
EventRegistryDataWrapper.java
src/scratchpad/src/org/apache/cocoon/caching
EventRegistry.java
Log:
refactoring - a little more mature now.
Revision Changes Path
1.2 +114 -126 cocoon-2.1/src/scratchpad/src/org/apache/cocoon/caching/impl/EventAwareCacheImpl.java
Index: EventAwareCacheImpl.java
===================================================================
RCS file: /home/cvs/cocoon-2.1/src/scratchpad/src/org/apache/cocoon/caching/impl/EventAwareCacheImpl.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- EventAwareCacheImpl.java 1 Jul 2003 04:38:48 -0000 1.1
+++ EventAwareCacheImpl.java 13 Jul 2003 04:40:51 -0000 1.2
@@ -45,70 +45,59 @@
*/
package org.apache.cocoon.caching.impl;
-import java.util.Collection;
import java.util.Iterator;
import java.util.Map;
+import org.apache.avalon.framework.activity.Initializable;
import org.apache.avalon.framework.component.ComponentException;
import org.apache.avalon.framework.component.ComponentManager;
import org.apache.cocoon.ProcessingException;
import org.apache.cocoon.caching.CachedResponse;
+import org.apache.cocoon.caching.EventRegistry;
import org.apache.cocoon.caching.PipelineCacheKey;
import org.apache.cocoon.caching.validity.Event;
import org.apache.cocoon.caching.validity.EventValidity;
-import org.apache.commons.collections.MultiHashMap;
import org.apache.excalibur.source.SourceValidity;
import org.apache.excalibur.source.impl.validity.AggregatedValidity;
/**
* Very experimental start at external cache invalidation.
* Warning - API very unstable. Do not use!
+ * (But it's getting closer!)
*
* This implementation holds all mappings between Events and PipelineCacheKeys
* in two MultiHashMap to facilitate efficient lookup by either as Key.
*
- * TODO: Implement Persistence.
* TODO: Test performance.
+ * TODO: Handle MultiThreading
*
* @author Geoff Howard (ghoward@apache.org)
* @version $Id$
*/
-public class EventAwareCacheImpl extends CacheImpl {
+public class EventAwareCacheImpl
+ extends CacheImpl
+ implements Initializable {
+ private ComponentManager m_manager;
+
+ private EventRegistry m_eventRegistry;
/**
- * Clears the entire Cache, including all held event-pipeline key
+ * Clears the entire Cache, including all registered event-pipeline key
* mappings..
- *
- * @see org.apache.cocoon.caching.Cache#clear()
*/
public void clear() {
super.clear();
- m_keyMMap.clear();
- m_eventMMap.clear();
- }
-
- /**
- * Compose
- *
- * TODO: the Maps should not be initialized here (and should not be hardcoded size)
- * TODO: Attempt to recover/deserialize persisted event listing. (but not here)
- *
- * @see org.apache.avalon.framework.component.Composable#compose(org.apache.avalon.framework.component.ComponentManager)
- */
- public void compose(ComponentManager manager) throws ComponentException {
- super.compose(manager);
- this.m_eventMMap = new MultiHashMap(100); // TODO: don't hardcode initial size
- this.m_keyMMap = new MultiHashMap(100); // TODO: don't hardcode initial size
+ m_eventRegistry.clear();
}
-
-
/**
- * When a new Pipeline key is stored, it needs to be registered in
- * the local Event-PipelineKey mapping.
+ * When a new Pipeline key is stored, it needs to be have its
+ * <code>SourceValidity</code> objects examined. For every
+ * <code>EventValidity</code> found, its <code>Event</code> will be
+ * registered with this key in the <code>EventRegistry</code>.
*
- * @see org.apache.cocoon.caching.Cache#store(java.util.Map, org.apache.cocoon.caching.PipelineCacheKey, org.apache.cocoon.caching.CachedResponse)
+ * <code>AggregatedValidity</code> is handled recursively.
*/
public void store(Map objectModel,
PipelineCacheKey key,
@@ -116,125 +105,124 @@
throws ProcessingException {
SourceValidity[] validities = response.getValidityObjects();
for (int i=0; i< validities.length;i++) {
- if (validities[i] instanceof AggregatedValidity) {
- // AggregatedValidity must be investigated further.
- Iterator it = ((AggregatedValidity)validities[i]).getValidities().iterator();
- SourceValidity sv = null;
- while (it.hasNext()) {
- sv = (SourceValidity)it.next();
- if (sv instanceof EventValidity) {
- if (getLogger().isDebugEnabled()) {
- getLogger().debug("Found EventValidity in AggregatedValidity: " + sv.toString());
- }
- registerEvent( ((EventValidity)sv).getEvent(),key);
- }
- }
- } else if (validities[i] instanceof EventValidity) {
- // Found a plain EventValidity.
- if (getLogger().isDebugEnabled()) {
- getLogger().debug("Found EventValidity: " + validities[i].toString());
- }
- registerEvent( ((EventValidity)validities[i]).getEvent(),key);
- }
-
+ SourceValidity val = validities[i];
+ examineValidity(val, key);
}
super.store(objectModel, key, response);
}
+ /**
+ * Look up the EventRegistry
+ */
+ public void compose(ComponentManager manager) throws ComponentException {
+ this.m_manager = manager;
+ super.compose(manager);
+ this.m_eventRegistry = (EventRegistry)manager.lookup(EventRegistry.ROLE);
+ }
+
/**
- * When a CachedResponse is removed from the Cache, any entries in the event mapping
- * must be cleaned up.
- *
- * @see org.apache.cocoon.caching.Cache#remove(org.apache.cocoon.caching.PipelineCacheKey)
+ * Un-register this key in the EventRegistry in addition to
+ * removing it from the Store
*/
public void remove(PipelineCacheKey key) {
super.remove(key);
- Collection coll = (Collection)m_keyMMap.get(key);
- if (coll==null || coll.isEmpty()) {
- return;
- } else {
- // get the iterator over all matching PCK keyed
- // entries in the key-indexed MMap.
- Iterator it = coll.iterator();
-
- while (it.hasNext()) {
- // remove all entries in the event-indexed map where this PCK key
- // is the value.
- Object o = it.next();
- if (o != null) {
- if (getLogger().isDebugEnabled()) {
- getLogger().debug("Removing from event mapping: " + o.toString());
- }
- m_eventMMap.remove((Event)o,key);
- }
- }
- }
- // remove all entries in the key-indexed map where this PCK key
- // is the key -- confused yet?
- m_keyMMap.remove(key);
+ m_eventRegistry.removeKey(key);
}
+ /**
+ * Receive notification about the occurrence of an Event.
+ * If this event has registered pipeline keys, remove them
+ * from the Store and unregister them
+ * @param e The Event to be processed.
+ */
public void processEvent(Event e) {
- Collection coll = (Collection)m_eventMMap.get(e);
- if (coll==null || coll.isEmpty()) {
- if (getLogger().isDebugEnabled()) {
- getLogger().debug("The event map returned empty");
+ PipelineCacheKey[] pcks = m_eventRegistry.keysForEvent(e);
+ for (int i=0;i<pcks.length; i++) {
+ if (pcks[i] != null) {
+ if (getLogger().isDebugEnabled()) {
+ getLogger().debug("Processing cache event, found Pipeline key: " + pcks[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]);
}
- // return silently with no action
- return;
+ }
+ }
+
+ /**
+ * Get the EventRegistry ready, and make sure it does not contain
+ * orphaned Event/PipelineKey mappings.
+ */
+ public void initialize() throws Exception {
+ if (!m_eventRegistry.init()) {
+ // Is this OK in initialize? I think it depends
+ // on the Store(s) being initialized first.
+ super.clear();
} else {
- /* get the array of all matching event keyed entries
- * in the event-indexed MMap. Using an iterator gives
- * a concurrent modification exception.
- */
- Object[] obs = coll.toArray();
- for (int i=0;i<obs.length; i++) {
- if (obs[i] != null) {
- PipelineCacheKey pck = (PipelineCacheKey)obs[i];
- if (getLogger().isDebugEnabled()) {
- getLogger().debug("Processing cache event, found Pipeline key: " + pck.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.
- *
- * TODO: what happens in this recursive removal? is
- * it a deadlock danger, or NPE danger??
- */
- remove(pck);
+ // Not sure if we want this overhead here, but where else?
+ veryifyEventCache();
+ }
+ }
+
+ /**
+ * Ensure that all PipelineCacheKeys registered to events still
+ * point to valid cache entries. Having an isTotallyEmpty() on
+ * Store might make this less necessary, as the most likely time
+ * to discover orphaned entries is at startup. This is because
+ * stray events could hang around indefinitely if the cache is
+ * removed abnormally or is not configured with persistence.
+ */
+ public void veryifyEventCache() {
+ PipelineCacheKey[] pcks = m_eventRegistry.allKeys();
+ for (int i=0; i<pcks.length; i++) {
+ if (!this.containsKey(pcks[i])) {
+ m_eventRegistry.removeKey(pcks[i]);
+ if (getLogger().isDebugEnabled()) {
+ getLogger().debug("Cache key no longer valid: " +
+ pcks[i]);
}
}
}
- // This may be unnecessary because the pck removal is done recursively.
- m_eventMMap.remove(e);
}
/**
- * Registers (stores) a two-way mapping between this Event and this
- * PipelineCacheKey for later retrieval on receipt of an event.
- *
- * @param event
- * @param key
+ * Release resources
*/
- private void registerEvent(Event e, PipelineCacheKey key) {
- m_keyMMap.put(key,e);
- m_eventMMap.put(e,key);
- }
-
- private MultiHashMap m_keyMMap;
- private MultiHashMap m_eventMMap;
-
- /** Release all held components.
- *
- * TODO: is this the place to persist the event mappings?
- *
- * @see org.apache.avalon.framework.activity.Disposable#dispose()
- */
public void dispose() {
- // TODO need to store event listing persistently - serialize?
- // for now: TODO: uncache all events.
+ m_manager.release(m_eventRegistry);
super.dispose();
+ m_manager = null;
+ m_eventRegistry = null;
}
+
+ private void examineValidity(SourceValidity val, PipelineCacheKey key) {
+ if (val instanceof AggregatedValidity) {
+ handleAggregatedValidity((AggregatedValidity)val, key);
+ } else if (val instanceof EventValidity) {
+ handleEventValidity((EventValidity)val, key);
+ }
+ }
+
+ private void handleAggregatedValidity(
+ AggregatedValidity val,
+ PipelineCacheKey key) {
+ // AggregatedValidity must be investigated further.
+ Iterator it = val.getValidities().iterator();
+ while (it.hasNext()) {
+ SourceValidity thisVal = (SourceValidity)it.next();
+ // Allow recursion
+ examineValidity(thisVal, key);
+ }
+ }
+
+ private void handleEventValidity(EventValidity val, PipelineCacheKey key) {
+ if (getLogger().isDebugEnabled()) {
+ getLogger().debug("Found EventValidity: " + val.toString());
+ }
+ m_eventRegistry.register(val.getEvent(),key);
+ }
}
1.1 cocoon-2.1/src/scratchpad/src/org/apache/cocoon/caching/impl/DefaultEventRegistryImpl.java
Index: DefaultEventRegistryImpl.java
===================================================================
/*
============================================================================
The Apache Software License, Version 1.1
============================================================================
Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved.
Redistribution and use in source and binary forms, with or without modifica-
tion, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
3. The end-user documentation included with the redistribution, if any, must
include the following acknowledgment: "This product includes software
developed by the Apache Software Foundation (http://www.apache.org/)."
Alternately, this acknowledgment may appear in the software itself, if
and wherever such third-party acknowledgments normally appear.
4. The names "Apache Cocoon" and "Apache Software Foundation" must not be
used to endorse or promote products derived from this software without
prior written permission. For written permission, please contact
apache@apache.org.
5. Products derived from this software may not be called "Apache", nor may
"Apache" appear in their name, without prior written permission of the
Apache Software Foundation.
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-
DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
This software consists of voluntary contributions made by many individuals
on behalf of the Apache Software Foundation and was originally created by
Stefano Mazzocchi <st...@apache.org>. For more information on the Apache
Software Foundation, please see <http://www.apache.org/>.
*/
package org.apache.cocoon.caching.impl;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.util.Collection;
import java.util.Iterator;
import java.util.Set;
import org.apache.avalon.framework.activity.Disposable;
import org.apache.avalon.framework.context.Context;
import org.apache.avalon.framework.context.ContextException;
import org.apache.avalon.framework.context.Contextualizable;
import org.apache.avalon.framework.logger.AbstractLogEnabled;
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;
/**
* This implementation of <code>EventRegistry</code> stores the event-key
* mappings in a simple pair of <code>MultiMap</code>s. It handles
* persistence by serializing an <code>EventRegistryDataWrapper</code> to
* disk.
*
* @since 2.1
* @author <a href="mailto:ghoward@apache.org">Geoff Howard</a>
* @version CVS $Id: DefaultEventRegistryImpl.java,v 1.1 2003/07/13 04:40:51 ghoward Exp $
*/
public class DefaultEventRegistryImpl
extends AbstractLogEnabled
implements EventRegistry,
ThreadSafe,
Disposable,
Contextualizable {
private File m_persistentFile;
private static final String PERSISTENT_FILE = "ev_cache.ser";
private File m_workDir;
private MultiHashMap m_keyMMap;
private MultiHashMap m_eventMMap;
/**
* Registers (stores) a two-way mapping between this Event and this
* PipelineCacheKey for later retrieval.
*
* @param event The event to
* @param key
*/
public void register(Event e, PipelineCacheKey key) {
m_keyMMap.put(key,e);
m_eventMMap.put(e,key);
}
/**
* Retrieve all pipeline keys mapped to this event.
*/
public PipelineCacheKey[] keysForEvent(Event e) {
Collection coll = (Collection)m_eventMMap.get(e);
if (coll==null || coll.isEmpty()) {
if (getLogger().isDebugEnabled()) {
getLogger().debug("The event map returned empty");
}
return null;
} else {
return (PipelineCacheKey[])coll.toArray(new PipelineCacheKey[coll.size()]);
}
}
/**
* When a CachedResponse is removed from the Cache, any entries
* in the event mapping must be cleaned up.
*/
public void removeKey(PipelineCacheKey key) {
Collection coll = (Collection)m_keyMMap.get(key);
if (coll==null || coll.isEmpty()) {
return;
} else {
// get the iterator over all matching PCK keyed
// entries in the key-indexed MMap.
Iterator it = coll.iterator();
while (it.hasNext()) {
/* remove all entries in the event-indexed map where this
* PCK key is the value.
*/
Object o = it.next();
if (o != null) {
if (getLogger().isDebugEnabled()) {
getLogger().debug("Removing from event mapping: " + o.toString());
}
m_eventMMap.remove((Event)o,key);
}
}
}
// remove all entries in the key-indexed map where this PCK key
// is the key -- confused yet?
m_keyMMap.remove(key);
}
/**
* Return the keys held as an array
*/
public PipelineCacheKey[] allKeys() {
Set keys = this.m_keyMMap.keySet();
return (PipelineCacheKey[])keys.toArray(
new PipelineCacheKey[keys.size()]);
}
/**
* Remove all registered data.
*/
public void clear() {
m_keyMMap.clear();
m_eventMMap.clear();
}
/**
* We must persist the data at container shutdown. If the serialization
* fails, an error is logged but not thrown. The missing/invalid state is
* handled at startup.
*/
public void dispose() {
ObjectOutputStream oos = null;
try {
oos = new ObjectOutputStream(
new FileOutputStream(this.m_persistentFile));
EventRegistryDataWrapper ecdw = new EventRegistryDataWrapper();
ecdw.setupMaps(this.m_keyMMap, this.m_eventMMap);
oos.writeObject(ecdw);
oos.flush();
} catch (FileNotFoundException e) {
getLogger().error("Unable to persist EventRegistry", e);
} catch (IOException e) {
getLogger().error("Unable to persist EventRegistry", e);
} finally {
try {
if (oos != null) oos.close();
} catch (IOException e) {}
}
m_keyMMap.clear();
m_keyMMap = null;
m_eventMMap.clear();
m_eventMMap = null;
}
/**
* Set up the persistence file.
*/
public void contextualize(Context context) throws ContextException {
org.apache.cocoon.environment.Context ctx =
(org.apache.cocoon.environment.Context) context.get(
Constants.CONTEXT_ENVIRONMENT_CONTEXT);
// set up file
m_persistentFile = new File(
ctx.getRealPath("/WEB-INF"),
DefaultEventRegistryImpl.PERSISTENT_FILE);
if (m_persistentFile == null) {
throw new ContextException("Could not obtain persistent file. " +
"The cache event registry cannot be " +
"used inside an unexpanded WAR file.");
}
}
/**
* Recover state by de-serializing the data wrapper. If this fails
* a new empty mapping is initialized and the Cache is signalled of
* the failure so it can clean up.
*
* @return true if de-serializing was successful, false otherwise.
*/
public boolean init() {
return recover();
}
private boolean recover() {
if (this.m_persistentFile.exists()) {
ObjectInputStream ois = null;
EventRegistryDataWrapper ecdw = null;
try {
ois = new ObjectInputStream(
new FileInputStream(this.m_persistentFile));
ecdw = (EventRegistryDataWrapper)ois.readObject();
} catch (FileNotFoundException e) {
getLogger().error("Unable to retrieve EventRegistry", e);
createBlankCache();
return false;
} catch (IOException e) {
getLogger().error("Unable to retrieve EventRegistry", e);
createBlankCache();
return false;
} catch (ClassNotFoundException e) {
getLogger().error("Unable to retrieve EventRegistry", e);
createBlankCache();
return false;
} finally {
try {
if (ois != null) ois.close();
} catch (IOException e) {
// ignore
}
}
this.m_eventMMap = ecdw.get_eventMap();
this.m_keyMMap = ecdw.get_keyMap();
} else {
getLogger().warn(this.m_persistentFile + " does not exist - Unable to " +
"retrieve EventRegistry.");
createBlankCache();
return false;
}
return true;
}
// TODO: don't hardcode initial size
private void createBlankCache() {
this.m_eventMMap = new MultiHashMap(100);
this.m_keyMMap = new MultiHashMap(100);
}
}
1.1 cocoon-2.1/src/scratchpad/src/org/apache/cocoon/caching/impl/EventRegistryDataWrapper.java
Index: EventRegistryDataWrapper.java
===================================================================
/*
============================================================================
The Apache Software License, Version 1.1
============================================================================
Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved.
Redistribution and use in source and binary forms, with or without modifica-
tion, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
3. The end-user documentation included with the redistribution, if any, must
include the following acknowledgment: "This product includes software
developed by the Apache Software Foundation (http://www.apache.org/)."
Alternately, this acknowledgment may appear in the software itself, if
and wherever such third-party acknowledgments normally appear.
4. The names "Apache Cocoon" and "Apache Software Foundation" must not be
used to endorse or promote products derived from this software without
prior written permission. For written permission, please contact
apache@apache.org.
5. Products derived from this software may not be called "Apache", nor may
"Apache" appear in their name, without prior written permission of the
Apache Software Foundation.
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-
DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
This software consists of voluntary contributions made by many individuals
on behalf of the Apache Software Foundation and was originally created by
Stefano Mazzocchi <st...@apache.org>. For more information on the Apache
Software Foundation, please see <http://www.apache.org/>.
*/
package org.apache.cocoon.caching.impl;
import java.io.Serializable;
import org.apache.commons.collections.MultiHashMap;
/**
* A light object for persisting the state of an EventRegistry implementation
* based on two MultiHashMaps.
*
* @author ghoward@apache.org
* @version CVS $Id: EventRegistryDataWrapper.java,v 1.1 2003/07/13 04:40:51 ghoward Exp $
*/
public class EventRegistryDataWrapper implements Serializable {
private MultiHashMap m_keyMMap;
private MultiHashMap m_eventMMap;
public EventRegistryDataWrapper() {
this.m_keyMMap = null;
this.m_eventMMap = null;
}
public void setupMaps(MultiHashMap keyMap, MultiHashMap eventMap) {
this.m_keyMMap = keyMap;
this.m_eventMMap = eventMap;
}
public MultiHashMap get_eventMap() {
return m_eventMMap;
}
public MultiHashMap get_keyMap() {
return m_keyMMap;
}
}
1.4 +4 -2 cocoon-2.1/src/scratchpad/src/org/apache/cocoon/caching/validity/Event.java
Index: Event.java
===================================================================
RCS file: /home/cvs/cocoon-2.1/src/scratchpad/src/org/apache/cocoon/caching/validity/Event.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- Event.java 1 Jul 2003 03:54:13 -0000 1.3
+++ Event.java 13 Jul 2003 04:40:51 -0000 1.4
@@ -45,6 +45,8 @@
*/
package org.apache.cocoon.caching.validity;
+import java.io.Serializable;
+
/**
* Very experimental start at external cache invalidation.
* Warning - API very unstable. Do not use! In fact, if this
@@ -56,7 +58,7 @@
* @author Geoff Howard (ghoward@apache.org)
* @version $Id$
*/
-public abstract class Event {
+public abstract class Event implements Serializable {
/**
* Used by EventValidity for equals(Object o) which
1.1 cocoon-2.1/src/scratchpad/src/org/apache/cocoon/caching/EventRegistry.java
Index: EventRegistry.java
===================================================================
/*
============================================================================
The Apache Software License, Version 1.1
============================================================================
Copyright (C) 1999-2003 The Apache Software Foundation. All rights reserved.
Redistribution and use in source and binary forms, with or without modifica-
tion, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
3. The end-user documentation included with the redistribution, if any, must
include the following acknowledgment: "This product includes software
developed by the Apache Software Foundation (http://www.apache.org/)."
Alternately, this acknowledgment may appear in the software itself, if
and wherever such third-party acknowledgments normally appear.
4. The names "Apache Cocoon" and "Apache Software Foundation" must not be
used to endorse or promote products derived from this software without
prior written permission. For written permission, please contact
apache@apache.org.
5. Products derived from this software may not be called "Apache", nor may
"Apache" appear in their name, without prior written permission of the
Apache Software Foundation.
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-
DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
This software consists of voluntary contributions made by many individuals
on behalf of the Apache Software Foundation and was originally created by
Stefano Mazzocchi <st...@apache.org>. For more information on the Apache
Software Foundation, please see <http://www.apache.org/>.
*/
package org.apache.cocoon.caching;
import org.apache.avalon.framework.component.Component;
import org.apache.cocoon.caching.validity.Event;
/**
* The <code>EventRegistry</code> is responsible for the two-way many-to-many
* mapping between cache <code>Event</code>s and
* <code>PipelineCacheKey</code>s necessary to allow for efficient
* event-based cache invalidation.
*
* @since 2.1
* @author <a href="mailto:ghoward@apache.org">Geoff Howard</a>
* @version CVS $Id: EventRegistry.java,v 1.1 2003/07/13 04:40:52 ghoward Exp $
*/
public interface EventRegistry extends Component {
/**
* The Avalon ROLE for this component
*/
String ROLE = EventRegistry.class.getName();
/**
* Map an event to a key
*
* @param event
* @param key
*/
public void register(Event e, PipelineCacheKey key);
/**
* Remove all occurances of the specified key from the registry.
*
* @param key - The key to remove.
*/
public void removeKey(PipelineCacheKey key);
/**
* Retrieve an array of all keys mapped to this event.
*
* @param event
* @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);
/**
* Retrieve an array of all keys regardless of event mapping, or null if
* no keys are registered..
*
* @return an array of keys which should not be modified
*/
public PipelineCacheKey[] allKeys();
/**
* Clear all event-key mappings from the registry.
*/
public void clear();
/**
* Request that the registry get ready for normal operation. Depending
* on the implementation, the component may need this opportunity to
* retrieve persisted data.
*
* If recovering persisted data was not successful, the component must
* signal that the Cache may contain orphaned EventValidity objects by
* returning false. The Cache should then ensure that all pipelines
* associated with EventValidities are either removed or re-associated
* (if possible).
*
* @return true if the Component recovered its state successfully,
* false otherwise.
*/
public boolean init();
}