ghoward 2004/02/28 13:51:14
Modified: src/blocks/eventcache/java/org/apache/cocoon/caching/impl
StoreEventRegistryImpl.java
DefaultEventRegistryImpl.java
src/blocks/eventcache/conf eventregistry.xconf
src/blocks/eventcache/java/org/apache/cocoon/caching
EventRegistry.java
Added: src/blocks/eventcache/java/org/apache/cocoon/caching/impl
AbstractDoubleMapEventRegistry.java
Log:
Messy commit because of line endings and tabs :(
- refactor EventRegistry hierarchy "Default" and "Store" both
inherit now from new AbstractDoubleMapEventReg...
- StoreEventRegistryImpl is now default (and now the name for
Default begs to be changed - that'll happen next)
Revision Changes Path
1.5 +87 -97
cocoon-2.1/src/blocks/eventcache/java/org/apache/cocoon/caching/impl/StoreEventRegistryImpl.java
Index: StoreEventRegistryImpl.java
===================================================================
RCS file:
/home/cvs/cocoon-2.1/src/blocks/eventcache/java/org/apache/cocoon/caching/impl/StoreEventRegistryImpl.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- StoreEventRegistryImpl.java 27 Feb 2004 17:27:04 -0000 1.4
+++ StoreEventRegistryImpl.java 28 Feb 2004 21:51:14 -0000 1.5
@@ -1,53 +1,48 @@
/*
-
- ============================================================================
- 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
- [EMAIL PROTECTED]
-
- 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 <[EMAIL PROTECTED]>. For more information on the Apache
- Software Foundation, please see <http://www.apache.org/>.
-
-*/
+ *
+ *
============================================================================
+ * 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
+ * [EMAIL PROTECTED]
+ * 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 <[EMAIL PROTECTED]> . For more information on the Apache
+ * Software Foundation, please see <http://www.apache.org/> .
+ *
+ */
package org.apache.cocoon.caching.impl;
import java.io.IOException;
@@ -58,64 +53,59 @@
import org.apache.excalibur.store.Store;
/**
- * This implementation of <code>EventRegistry</code> extends <code>
- * DefaultEventRegistry</code> to handle persistence by storing its
- * <code>EventRegistryDataWrapper</code> in the <code>PersistentStore</code>
- * defined in cocoon.xconf.
+ * This implementation of <code>EventRegistry</code> stores its
<code>EventRegistryDataWrapper</code>
+ * in the <code>PersistentStore</code> defined in cocoon.xconf.
*
* @since 2.1
* @author <a href="mailto:[EMAIL PROTECTED]">Geoff Howard</a>
- * @version CVS $Id$
+ * @version CVS $Id: StoreEventRegistryImpl.java,v 1.4 2004/02/27 17:27:04
+ * unico Exp $
*/
-public class StoreEventRegistryImpl
- extends DefaultEventRegistryImpl implements Serviceable {
- private static final String EVENTREGISTRYKEY = "EVENTREGWRAPPER";
- private ServiceManager m_manager;
- private Store m_persistentStore;
-
- /**
- * Completely override dispose from superclass to persist the
- * data wrapper in the Store instead of a serialized file on disk.
- */
- public void dispose() {
- EventRegistryDataWrapper ecdw = wrapRegistry();
- try {
- m_persistentStore.store(EVENTREGISTRYKEY,ecdw);
- } catch (IOException e) {
- getLogger().warn("Unable to persist Event Registry");
- }
- this.m_manager.release(this.m_persistentStore);
- m_manager = null;
- m_persistentStore = null;
- }
-
-
+public class StoreEventRegistryImpl
+ extends AbstractDoubleMapEventRegistry
+ implements Serviceable {
+ private static final String EVENTREGISTRYKEY = "EVENTREGWRAPPER";
+ private ServiceManager m_manager;
+ private Store m_persistentStore;
+
+ protected void persist(EventRegistryDataWrapper wrapper) {
+ EventRegistryDataWrapper ecdw = wrapRegistry();
+ try {
+ m_persistentStore.store(EVENTREGISTRYKEY, ecdw);
+ } catch (IOException e) {
+ getLogger().warn("Unable to persist Event Registry");
+ }
+ this.m_manager.release(this.m_persistentStore);
+ m_manager = null;
+ m_persistentStore = null;
+ }
- /**
+ /**
* Obtain a reference to the Store
*/
- public void service(ServiceManager manager) throws ServiceException {
- this.m_manager = manager;
- this.m_persistentStore =
(Store)manager.lookup(Store.PERSISTENT_STORE);
- }
+ public void service(ServiceManager manager) throws ServiceException {
+ this.m_manager = manager;
+ this.m_persistentStore = (Store)
manager.lookup(Store.PERSISTENT_STORE);
+ }
- /**
+ /**
* Recover the datawrapper from the Store.
*/
- protected boolean recover() {
- Object o = m_persistentStore.get(EVENTREGISTRYKEY);
- m_persistentStore.remove(EVENTREGISTRYKEY);
- if (o != null && o instanceof EventRegistryDataWrapper) {
- if (getLogger().isInfoEnabled()) {
- getLogger().info("Retrieving EventRegistry from
PersistentStore.");
- }
- unwrapRegistry((EventRegistryDataWrapper)o);
- return true;
- } else {
- getLogger().warn("Unable to recover Event Registry.");
+ protected boolean recover() {
+ Object o = m_persistentStore.get(EVENTREGISTRYKEY);
+ m_persistentStore.remove(EVENTREGISTRYKEY);
+ if (o != null && o instanceof EventRegistryDataWrapper) {
+ if (getLogger().isInfoEnabled()) {
+ getLogger().info(
+ "Retrieving EventRegistry from PersistentStore.");
+ }
+ unwrapRegistry((EventRegistryDataWrapper) o);
+ return true;
+ } else {
+ getLogger().warn("Unable to recover Event Registry.");
super.createBlankCache();
- return false;
- }
- }
+ return false;
+ }
+ }
}
1.11 +14 -162
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.10
retrieving revision 1.11
diff -u -r1.10 -r1.11
--- DefaultEventRegistryImpl.java 27 Feb 2004 17:27:04 -0000 1.10
+++ DefaultEventRegistryImpl.java 28 Feb 2004 21:51:14 -0000 1.11
@@ -57,26 +57,15 @@
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;
-import org.apache.avalon.framework.activity.Disposable;
-import org.apache.avalon.framework.activity.Initializable;
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.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
+ * This implementation of <code>EventRegistry</code> handles
* persistence by serializing an <code>EventRegistryDataWrapper</code> to
* disk.
*
@@ -85,103 +74,17 @@
* @version CVS $Id$
*/
public class DefaultEventRegistryImpl
- extends AbstractLogEnabled
+ extends AbstractDoubleMapEventRegistry
implements EventRegistry,
- Initializable,
- ThreadSafe,
- Disposable,
- Contextualizable {
+ Contextualizable {
- private boolean m_init_success = false;
- private File m_persistentFile;
- private static final String PERSISTENT_FILE = "ev_cache.ser";
- private MultiHashMap m_keyMMap;
- private MultiHashMap m_eventMMap;
-
- /**
- * Registers (stores) a two-way mapping between this Event and this
- * PipelineCacheKey for later retrieval.
- *
- * @param e The event to
- * @param key key
- */
- public void register(Event e, Serializable key) {
- synchronized(this) {
- m_keyMMap.put(key,e);
- m_eventMMap.put(e,key);
- }
- }
-
- /**
- * Remove all registered data.
- */
- public void clear() {
- synchronized(this) {
- m_keyMMap.clear();
- m_eventMMap.clear();
- }
- }
-
- /**
- * Retrieve all pipeline keys mapped to this event.
- */
- public Serializable[] 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 (Serializable[])coll.toArray(new
Serializable[coll.size()]);
- }
- }
-
- /**
- * Return all pipeline keys mapped to any event
- */
- public Serializable[] allKeys() {
- Set keys = this.m_keyMMap.keySet();
- 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(Serializable key) {
- Collection coll = (Collection)m_keyMMap.get(key);
- if (coll==null || coll.isEmpty()) {
- return;
- }
- // get the iterator over all matching PCK keyed
- // entries in the key-indexed MMap.
- synchronized(this) {
- 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(o,key);
- }
- }
-
- // remove all entries in the key-indexed map where this PCK key
- // is the key -- confused yet?
- m_keyMMap.remove(key);
- }
- }
+ private File m_persistentFile;
+ private static final String PERSISTENT_FILE = "ev_cache.ser";
/**
* Set up the persistence file.
*/
- public void contextualize(Context context) throws ContextException {
+ public void contextualize(Context context) throws ContextException {
org.apache.cocoon.environment.Context ctx =
(org.apache.cocoon.environment.Context) context.get(
Constants.CONTEXT_ENVIRONMENT_CONTEXT);
@@ -194,49 +97,19 @@
"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();
- }*/
-
- /**
- * 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.
- */
- public void initialize() throws Exception {
- if (recover()) {
- m_init_success = true;
- }
- }
-
- /**
- * @return true if persistent state existed and was recovered
successfully.
- */
- public boolean wasRecoverySuccessful() {
- return m_init_success;
}
-
+
/**
- * Clean up resources at container shutdown. An EventRegistry must
persist
- * its data. If the serialization fails, an error is logged but not
thrown
- * because missing/invalid state is handled at startup.
+ * Persist by simple object serialization. If the serialization fails,
an
+ * error is logged but not thrown because missing/invalid state is
handled
+ * at startup.
*/
- public void dispose() {
+ protected void persist(EventRegistryDataWrapper registryWrapper) {
ObjectOutputStream oos = null;
try {
oos = new ObjectOutputStream(
- new
FileOutputStream(this.m_persistentFile));
- EventRegistryDataWrapper ecdw = wrapRegistry();
- oos.writeObject(ecdw);
+ new
FileOutputStream(this.m_persistentFile));
+ oos.writeObject(registryWrapper);
oos.flush();
} catch (FileNotFoundException e) {
getLogger().error("Unable to persist EventRegistry", e);
@@ -247,18 +120,8 @@
if (oos != null) oos.close();
} catch (IOException e) {}
}
- m_keyMMap.clear();
- m_keyMMap = null;
- m_eventMMap.clear();
- m_eventMMap = null;
}
- protected EventRegistryDataWrapper wrapRegistry() {
- EventRegistryDataWrapper ecdw = new EventRegistryDataWrapper();
- ecdw.setupMaps(this.m_keyMMap, this.m_eventMMap);
- return ecdw;
- }
-
/*
* I don't think this needs to get synchronized because it should
* only be called during initialize, which should only be called
@@ -299,17 +162,6 @@
return false;
}
return true;
- }
-
- protected void unwrapRegistry(EventRegistryDataWrapper ecdw) {
- this.m_eventMMap = ecdw.get_eventMap();
- this.m_keyMMap = ecdw.get_keyMap();
- }
-
- // TODO: don't hardcode initial size
- protected final void createBlankCache() {
- this.m_eventMMap = new MultiHashMap(100);
- this.m_keyMMap = new MultiHashMap(100);
}
}
1.1
cocoon-2.1/src/blocks/eventcache/java/org/apache/cocoon/caching/impl/AbstractDoubleMapEventRegistry.java
Index: AbstractDoubleMapEventRegistry.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
[EMAIL PROTECTED]
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 <[EMAIL PROTECTED]>. 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 java.util.Collection;
import java.util.Iterator;
import java.util.Set;
import org.apache.avalon.framework.activity.Disposable;
import org.apache.avalon.framework.activity.Initializable;
import org.apache.avalon.framework.logger.AbstractLogEnabled;
import org.apache.avalon.framework.thread.ThreadSafe;
import org.apache.cocoon.caching.EventRegistry;
import org.apache.cocoon.caching.validity.Event;
import org.apache.commons.collections.MultiHashMap;
/**
* This abstract base implementation of <code>EventRegistry</code> stores
* the event-key mappings in a simple pair of <code>MultiMap</code>s. It
* leaves all persistence to its concrete subclasses. To protect against
* future confusing inheritance trees, all internal implementation of the
* event-key mapping mechanism is hidden from its subclasses. If future
* EventRegistry implementations desire to use a different event-key mapping
* strategy but share persistence code, this package should probably be
* refactored to employ composition rather than inheritance. For now,
* simplicity favors inheritance.
*
* @since 2.1
* @author <a href="mailto:[EMAIL PROTECTED]">Geoff Howard</a>
* @version CVS $Id: AbstractDoubleMapEventRegistry.java,v 1.1 2004/02/28
21:51:14 ghoward Exp $
*/
public abstract class AbstractDoubleMapEventRegistry
extends AbstractLogEnabled
implements Initializable, EventRegistry, Disposable, ThreadSafe {
private boolean m_init_success = false;
private MultiHashMap m_keyMMap;
private MultiHashMap m_eventMMap;
/**
* Registers (stores) a two-way mapping between this Event and this
* PipelineCacheKey for later retrieval.
*
* @param e The event to
* @param key key
*/
public void register(Event e, Serializable key) {
synchronized(this) {
m_keyMMap.put(key,e);
m_eventMMap.put(e,key);
}
}
/**
* Remove all registered data.
*/
public void clear() {
synchronized(this) {
m_keyMMap.clear();
m_eventMMap.clear();
}
}
/**
* Retrieve all pipeline keys mapped to this event.
*/
public Serializable[] 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 (Serializable[])coll.toArray(new
Serializable[coll.size()]);
}
}
/**
* Return all pipeline keys mapped to any event
*/
public Serializable[] allKeys() {
Set keys = this.m_keyMMap.keySet();
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(Serializable key) {
Collection coll = (Collection)m_keyMMap.get(key);
if (coll==null || coll.isEmpty()) {
return;
}
// get the iterator over all matching PCK keyed
// entries in the key-indexed MMap.
synchronized(this) {
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(o,key);
}
}
// remove all entries in the key-indexed map where this PCK key
// is the key -- confused yet?
m_keyMMap.remove(key);
}
}
/**
* 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.
*/
public void initialize() throws Exception {
if (recover()) {
m_init_success = true;
}
}
/**
* Delegate persistence to subclasses then clean up resources.
*/
public void dispose() {
EventRegistryDataWrapper ecdw = wrapRegistry();
persist(ecdw);
m_keyMMap.clear();
m_keyMMap = null;
m_eventMMap.clear();
m_eventMMap = null;
}
/**
* @return true if persistent state existed and was recovered
successfully.
*/
public boolean wasRecoverySuccessful() {
return m_init_success;
}
protected EventRegistryDataWrapper wrapRegistry() {
EventRegistryDataWrapper ecdw = new EventRegistryDataWrapper();
ecdw.setupMaps(this.m_keyMMap, this.m_eventMMap);
return ecdw;
}
protected void unwrapRegistry(EventRegistryDataWrapper ecdw) {
this.m_eventMMap = ecdw.get_eventMap();
this.m_keyMMap = ecdw.get_keyMap();
}
protected final void createBlankCache() {
// TODO: don't hardcode initial size
this.m_eventMMap = new MultiHashMap(100);
this.m_keyMMap = new MultiHashMap(100);
}
/**
* An EventRegistry must recover its persisted data. Failed
* recovery must be signaled so that the Cache will know not to
* serve potentially stale content. Of course, at first start up
* failed recovery is a normal state.
*
* @return boolean to signal success or failure of recovery.
*/
protected abstract boolean recover();
/**
* An EventRegistry must persist its data.
*/
protected abstract void persist(EventRegistryDataWrapper wrapper);
}
1.5 +4 -2 cocoon-2.1/src/blocks/eventcache/conf/eventregistry.xconf
Index: eventregistry.xconf
===================================================================
RCS file:
/home/cvs/cocoon-2.1/src/blocks/eventcache/conf/eventregistry.xconf,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- eventregistry.xconf 17 Feb 2004 00:15:19 -0000 1.4
+++ eventregistry.xconf 28 Feb 2004 21:51:14 -0000 1.5
@@ -1,9 +1,11 @@
<?xml version="1.0"?>
<xconf xpath="/cocoon"
- unless="[EMAIL
PROTECTED]'org.apache.cocoon.caching.impl.DefaultEventRegistryImpl']">
+ remove="/cocoon/[EMAIL
PROTECTED]'org.apache.cocoon.caching.EventRegistry']">
<!-- The event registry which maps Cache events to Pipeline keys -->
+ <!--component role="org.apache.cocoon.caching.EventRegistry"
+
class="org.apache.cocoon.caching.impl.DefaultEventRegistryImpl"/-->
<component role="org.apache.cocoon.caching.EventRegistry"
-
class="org.apache.cocoon.caching.impl.DefaultEventRegistryImpl"/>
+ class="org.apache.cocoon.caching.impl.StoreEventRegistryImpl"/>
</xconf>
1.5 +9 -1
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.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- EventRegistry.java 15 Nov 2003 04:21:28 -0000 1.4
+++ EventRegistry.java 28 Feb 2004 21:51:14 -0000 1.5
@@ -60,6 +60,14 @@
* mapping between cache <code>Event</code>s and
* <code>PipelineCacheKey</code>s necessary to allow for efficient
* event-based cache invalidation.
+ *
+ * Because persistence and recovery between application shutdown and startup
are
+ * internal concerns they are not defined here even though it is expected
that most
+ * real-world implementers of this interface would require these features.
+ * On the other hand, EventRegistry must help the Cache to ensure that
outdated
+ * content is never served, even if that means discarding potentially valid
cached
+ * entries. For this reason, wasRecoverySuccessful() is defined here as
part of
+ * the public contract with the Cache.
*
* @since 2.1
* @author <a href="mailto:[EMAIL PROTECTED]">Geoff Howard</a>