org.apache.cocoon.caching.impl
Class AbstractDoubleMapEventRegistry

java.lang.Object
  extended by org.apache.avalon.framework.logger.AbstractLogEnabled
      extended by org.apache.cocoon.caching.impl.AbstractDoubleMapEventRegistry
All Implemented Interfaces:
Disposable, Initializable, Component, LogEnabled, ThreadSafe, EventRegistry
Direct Known Subclasses:
DefaultEventRegistryImpl, StoreEventRegistryImpl

public abstract class AbstractDoubleMapEventRegistry
extends AbstractLogEnabled
implements Initializable, EventRegistry, Disposable, ThreadSafe

This abstract base implementation of EventRegistry stores the event-key mappings in a simple pair of MultiMaps. 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
Version:
$Id: AbstractDoubleMapEventRegistry.html 1304258 2012-03-23 10:09:27Z ilgrosso $

Field Summary
 
Fields inherited from interface org.apache.cocoon.caching.EventRegistry
ROLE
 
Constructor Summary
AbstractDoubleMapEventRegistry()
           
 
Method Summary
 Serializable[] allKeys()
          Return all pipeline keys mapped to any event
 void clear()
          Remove all registered data.
protected  void createBlankCache()
           
protected  void createMultiMaps()
           
 void dispose()
          Delegate persistence to subclasses then clean up resources.
 void initialize()
          Recover state by de-serializing the data wrapper.
 Serializable[] keysForEvent(Event e)
          Retrieve all pipeline keys mapped to this event.
protected abstract  void persist(EventRegistryDataWrapper wrapper)
          An EventRegistry must persist its data.
protected abstract  boolean recover()
          An EventRegistry must recover its persisted data.
 void register(Event e, Serializable key)
          Registers (stores) a two-way mapping between this Event and this PipelineCacheKey for later retrieval.
 void removeKey(Serializable key)
          When a CachedResponse is removed from the Cache, any entries in the event mapping must be cleaned up.
protected  void unwrapRegistry(EventRegistryDataWrapper ecdw)
           
 boolean wasRecoverySuccessful()
          Returns whether the registry was successful in retrieving its persisted state during startup.
protected  EventRegistryDataWrapper wrapRegistry()
           
 
Methods inherited from class org.apache.avalon.framework.logger.AbstractLogEnabled
enableLogging, getLogger, setupLogger, setupLogger, setupLogger
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AbstractDoubleMapEventRegistry

public AbstractDoubleMapEventRegistry()
Method Detail

register

public void register(Event e,
                     Serializable key)
Registers (stores) a two-way mapping between this Event and this PipelineCacheKey for later retrieval.

Specified by:
register in interface EventRegistry
Parameters:
e - The event to
key - key

clear

public void clear()
Remove all registered data.

Specified by:
clear in interface EventRegistry

keysForEvent

public Serializable[] keysForEvent(Event e)
Retrieve all pipeline keys mapped to this event.

Specified by:
keysForEvent in interface EventRegistry
Parameters:
e - event
Returns:
an array of keys which should not be modified or null if no keys are mapped to this event.

allKeys

public Serializable[] allKeys()
Return all pipeline keys mapped to any event

Specified by:
allKeys in interface EventRegistry
Returns:
an array of keys which should not be modified

removeKey

public void removeKey(Serializable key)
When a CachedResponse is removed from the Cache, any entries in the event mapping must be cleaned up.

Specified by:
removeKey in interface EventRegistry
Parameters:
key - - The key to remove.

initialize

public void initialize()
                throws Exception
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.

Specified by:
initialize in interface Initializable
Throws:
Exception

dispose

public void dispose()
Delegate persistence to subclasses then clean up resources.

Specified by:
dispose in interface Disposable

wasRecoverySuccessful

public boolean wasRecoverySuccessful()
Description copied from interface: EventRegistry
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 returning false. The Cache should then ensure that all pipelines associated with EventValidities are either removed or re-associated (if possible).

Specified by:
wasRecoverySuccessful in interface EventRegistry
Returns:
true if persistent state existed and was recovered successfully.

wrapRegistry

protected EventRegistryDataWrapper wrapRegistry()

unwrapRegistry

protected void unwrapRegistry(EventRegistryDataWrapper ecdw)

createBlankCache

protected final void createBlankCache()

createMultiMaps

protected void createMultiMaps()

recover

protected abstract boolean recover()
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.

Returns:
boolean to signal success or failure of recovery.

persist

protected abstract void persist(EventRegistryDataWrapper wrapper)
An EventRegistry must persist its data.



Copyright © 1999-2010 The Apache Software Foundation. All Rights Reserved.