org.opendoors.cache.immutable
Class ChangeControl

java.lang.Object
  extended byorg.opendoors.cache.immutable.ChangeControl
All Implemented Interfaces:
java.util.Observer

public class ChangeControl
extends java.lang.Object
implements java.util.Observer

Default behavior for managing the mutable and immutable cache as implemented by CacheImpl.

Advanced implementations of the Immutable/Mutable strategy may elect to subclass this class and provide fine grained change control for a specific type of cache.

For example a cluster of file caches would possibly require a change control manager which would sweep from time to time a disk volume and matching files in the cache which were out of date would be replaced in the cache. This kind of functionality can be performed as well by a cache manager wrapping itself around the cache interface.

This class delegates observability of the cache to an instance of PostponeObservable. In this manner, updates to the immutable cache are postponed until a sufficient period of idle activity has elapsed before changes are propagate to the immutable image.

See Also:
PostponeObservable, Cache, UpdateableCache

Field Summary
protected  java.lang.Object actionMutex
          The synch mutex.
protected  CacheImpl cache
          The actual cache under management.
protected  PostponeObservable observable
          The thread delegate for managing changes.
 
Constructor Summary
ChangeControl()
          The default constructor which does nothing.
 
Method Summary
protected  java.lang.Object setCacheImpl(CacheImpl cache, int refreshRate)
          Sets up the cache for change control: the cache, the refresh rate and returns the mutex.
 void update(java.util.Observable o, java.lang.Object arg)
          Call back for changes pending to be implemented.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

cache

protected CacheImpl cache
The actual cache under management.


observable

protected PostponeObservable observable
The thread delegate for managing changes. By default, 5 seconds of inactivity must occur before pending updates are propagated and the immutable cache is upgraded.


actionMutex

protected java.lang.Object actionMutex
The synch mutex.

Constructor Detail

ChangeControl

public ChangeControl()
The default constructor which does nothing.

Method Detail

setCacheImpl

protected java.lang.Object setCacheImpl(CacheImpl cache,
                                        int refreshRate)
Sets up the cache for change control: the cache, the refresh rate and returns the mutex.

Parameters:
cache - The cache to manage.
refreshRate - How often in millis to refresh the cache.
Returns:
The mutex synchronizing updates.

update

public void update(java.util.Observable o,
                   java.lang.Object arg)
Call back for changes pending to be implemented.

Cache has been idle for at least n seconds.

This routine implements the generational update such that the immutable becomes identical now to the most current image in the mutable instance.

Specified by:
update in interface java.util.Observer