ghoward 2003/07/20 14:08:06
Modified: src/blocks/eventcache/java/org/apache/cocoon/caching/impl DefaultEventRegistryImpl.java EventAwareCacheImpl.java src/blocks/eventcache/java/org/apache/cocoon/caching EventRegistry.java Log: recover IoC now that I know the avalon contract a little better Revision Changes Path 1.3 +25 -3 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.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- DefaultEventRegistryImpl.java 15 Jul 2003 02:02:02 -0000 1.2 +++ DefaultEventRegistryImpl.java 20 Jul 2003 21:08:06 -0000 1.3 @@ -62,6 +62,7 @@ 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; @@ -86,10 +87,12 @@ public class DefaultEventRegistryImpl extends AbstractLogEnabled implements EventRegistry, + Initializable, ThreadSafe, Disposable, Contextualizable { + private boolean m_init_success = false; private File m_persistentFile; private static final String PERSISTENT_FILE = "ev_cache.ser"; private File m_workDir; @@ -199,9 +202,27 @@ * * @return true if de-serializing was successful, false otherwise. */ - public boolean init() { + /*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 @@ -281,4 +302,5 @@ this.m_eventMMap = new MultiHashMap(100); this.m_keyMMap = new MultiHashMap(100); } + } 1.3 +2 -4 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.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- EventAwareCacheImpl.java 15 Jul 2003 02:02:02 -0000 1.2 +++ EventAwareCacheImpl.java 20 Jul 2003 21:08:06 -0000 1.3 @@ -160,9 +160,7 @@ * 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. + if (!m_eventRegistry.wasRecoverySuccessful()) { super.clear(); } else { // Not sure if we want this overhead here, but where else? 1.2 +4 -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.1 retrieving revision 1.2 diff -u -r1.1 -r1.2 --- EventRegistry.java 14 Jul 2003 02:50:45 -0000 1.1 +++ EventRegistry.java 20 Jul 2003 21:08:06 -0000 1.2 @@ -108,9 +108,8 @@ 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. + * Returns whether the registry was successful in retrieving its + * persisted state during startup. * * If recovering persisted data was not successful, the component must * signal that the Cache may contain orphaned EventValidity objects by @@ -121,5 +120,5 @@ * @return true if the Component recovered its state successfully, * false otherwise. */ - public boolean init(); + public boolean wasRecoverySuccessful(); }