SolarMetric Kodo JDO 3.0.3 generated on February 20 2004

kodo.datacache
Class AbstractCacheImpl

java.lang.Object
  |
  +--kodo.datacache.AbstractCacheImpl
All Implemented Interfaces:
com.solarmetric.util.Closeable, Configurable, DataCache, Watchable
Direct Known Subclasses:
CacheImpl, TangosolCache

public abstract class AbstractCacheImpl
extends Object
implements DataCache, Configurable, Watchable

Abstract DataCache implementation that provides various locking, logging, etc. functionality common across cache implementations.


Field Summary
protected  Map cache
          A map in which that this cache implementation stores data.
protected  JDOConfiguration conf
          The configuration set by the system.
protected  org.apache.commons.logging.Log log
          The log to use.
 
Fields inherited from interface kodo.datacache.DataCache
DEFAULT_NAME
 
Constructor Summary
AbstractCacheImpl()
           
 
Method Summary
protected abstract  boolean addExistingUpdates()
          Return true if updates to data already in the cache (either in batchUpdate(java.util.Collection, java.util.Collection, java.util.Collection, java.util.Collection) or the updateValue(kodo.runtime.PCData)) should be put back into the cache.
 boolean addListener(WatchableListener listener)
          Add a listener.
 void batchUpdate(Collection additions, Collection newUpdates, Collection existingUpdates, Collection deletes)
          Perform a batch update of the cache.
 void clear()
          Remove all data from this cache.
 void clearListeners()
          Clear all listeners.
 void close()
          Close this cache, dropping all hard references and releasing any resources that this cache maintains.
 boolean containsKey(Object key)
          Returns true if this cache contains data corresponding to oid; otherwise returns false.
 void endConfiguration()
          Invoked upon completion of bean property configuration for this object.
 PCData get(Object key)
          Return the cached object for the given oid.
 String getCacheStatisticsString()
          Returns a localized string containing the number of hits, the number of misses, and the hit ratio (hits / (hits+misses)).
 int getHitCount()
          Returns the number of cache hits for invocations of the get(java.lang.Object) method.
 Map getMap()
          Returns the underlying Map that this CacheImpl is using.
 int getMissCount()
          Returns the number of cache misses for invocations of the get(java.lang.Object) method.
 String getName()
          Returns a string name that can be used by end-user-visible code to identify this cache.
 boolean getRecordCacheStatistics()
          Returns true if cache statistics recording is currently on; otherwise returns false.
 Collection getStatistics()
          Get statistics exported by this object.
protected  void keyRemoved(Object key, boolean expired)
          Invoked when a key is expired from this cache.
protected abstract  Map newMap()
          Returns a new Map for use as the underlying data cache.
 PCData put(PCData data)
          Set the cached value for the given instance.
 void registerListener(ExpirationListener listen)
          Add a new expiration event listener to this cache.
 PCData remove(Object key)
          Remove the value stored under the given oid.
 void removeAll(Collection keys)
           
 boolean removeListener(ExpirationListener listen)
          Remove an expiration event listener from this cache.
 boolean removeListener(WatchableListener listener)
          Remove a listener.
 void setConfiguration(Configuration config)
          Invoked prior to setting bean properties.
 void setName(String name)
          Sets a string name to be used to identify this cache to end-user needs.
 void setRecordCacheStatistics(boolean record)
          Turns cache statistics recording on or off.
 void startConfiguration()
          Invoked before bean property configuration is begun on this object.
 String toString()
           
 void updateValue(PCData data)
          Determine what to based on addExistingUpdates().
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface kodo.datacache.DataCache
pin, unpin
 

Field Detail

cache

protected Map cache
A map in which that this cache implementation stores data.

conf

protected JDOConfiguration conf
The configuration set by the system.

log

protected org.apache.commons.logging.Log log
The log to use.
Constructor Detail

AbstractCacheImpl

public AbstractCacheImpl()
Method Detail

getMap

public Map getMap()

Returns the underlying Map that this CacheImpl is using. This is not an unmodifiable view on the map, so care should be taken with this reference. Implementations should probably not mess with the contents of the cache, but should only use this reference to obtain cache metrics.


newMap

protected abstract Map newMap()
Returns a new Map for use as the underlying data cache.

keyRemoved

protected void keyRemoved(Object key,
                          boolean expired)
Invoked when a key is expired from this cache. Propagates the expiration event on to all expiration listeners registered with this class.

addExistingUpdates

protected abstract boolean addExistingUpdates()
Return true if updates to data already in the cache (either in batchUpdate(java.util.Collection, java.util.Collection, java.util.Collection, java.util.Collection) or the updateValue(kodo.runtime.PCData)) should be put back into the cache.

batchUpdate

public void batchUpdate(Collection additions,
                        Collection newUpdates,
                        Collection existingUpdates,
                        Collection deletes)
Description copied from interface: DataCache

Perform a batch update of the cache. Add all PCData objects in additions and in newUpdates, make the appropriate modifications to all PCDatas in existingUpdates, and delete all OIDs in deletes.

All changes made to cached data must be cached via this method. It is this method that is responsible for performing any side-effects that should happen on meaningful cache changes.

Implementations should bear in mind that the deletes collection may contain oids that are also in the additions map. This is possible because it is valid for a user to delete an object with a particular oid and then add that object in the same batch.

Specified by:
batchUpdate in interface DataCache
Following copied from interface: kodo.datacache.DataCache
Parameters:
additions - A collection of PCData objects. These represent data that have been newly created, and thus must be added to the cache.
newUpdates - A collection of PCData objects. These represent data that have been modified but were not originally in the cache, and thus must be added to the cache.
existingUpdates - A collection of PCData objects. These represent data that have been modified and were originally loaded from the cache. It is up to the cache implementation to decide if these values must be re-enlisted in the cache. Some caches may return live data from DataCache.get(java.lang.Object) invocations, in which case these values need not be re-enlisted.
deletes - A collection of object IDs that have been deleted and must therefore be dropped from the cache.

get

public PCData get(Object key)
Description copied from interface: DataCache
Return the cached object for the given oid. Modifying the returned object may or may not change the cached value; the DataCache.updateValue(kodo.runtime.PCData) method should be used to re-cache any changed objects.
Specified by:
get in interface DataCache
Following copied from interface: kodo.datacache.DataCache
Returns:
the object matching the given oid, or null if none

put

public PCData put(PCData data)
Description copied from interface: DataCache
Set the cached value for the given instance. This does not result in an update of other caches. Rather, it should only be used for loading clean data into the cache. Meaningful changes to the state of the cache should be made via the DataCache.batchUpdate(java.util.Collection, java.util.Collection, java.util.Collection, java.util.Collection) method.
Specified by:
put in interface DataCache
Following copied from interface: kodo.datacache.DataCache
Returns:
The previously cached value, or null if the value was not previously cached. See Map.put(java.lang.Object, java.lang.Object) for more information.

updateValue

public void updateValue(PCData data)
Determine what to based on addExistingUpdates().
Specified by:
updateValue in interface DataCache

remove

public PCData remove(Object key)
Description copied from interface: DataCache
Remove the value stored under the given oid. This does not result in an update of other caches. Rather, it should only be used for removing data into the cache. Meaningful changes to the state of the cache should be made via the DataCache.batchUpdate(java.util.Collection, java.util.Collection, java.util.Collection, java.util.Collection) method.
Specified by:
remove in interface DataCache
Following copied from interface: kodo.datacache.DataCache
Returns:
The previously cached value, or null if the oid was not previously cached. See Map.remove(java.lang.Object) for more information.

removeAll

public void removeAll(Collection keys)

clear

public void clear()
Description copied from interface: DataCache
Remove all data from this cache. This does not result in an update of other caches. Rather, it should only be used for clearing the cache. Meaningful changes to the state of the cache should be made via the DataCache.batchUpdate(java.util.Collection, java.util.Collection, java.util.Collection, java.util.Collection) method.
Specified by:
clear in interface DataCache

close

public void close()
Description copied from interface: DataCache
Close this cache, dropping all hard references and releasing any resources that this cache maintains.
Specified by:
close in interface DataCache

containsKey

public boolean containsKey(Object key)
Description copied from interface: DataCache
Returns true if this cache contains data corresponding to oid; otherwise returns false.
Specified by:
containsKey in interface DataCache

setName

public void setName(String name)
Description copied from interface: DataCache
Sets a string name to be used to identify this cache to end-user needs.
Specified by:
setName in interface DataCache

getName

public String getName()
Description copied from interface: DataCache
Returns a string name that can be used by end-user-visible code to identify this cache.
Specified by:
getName in interface DataCache

registerListener

public void registerListener(ExpirationListener listen)
Description copied from interface: DataCache
Add a new expiration event listener to this cache.
Specified by:
registerListener in interface DataCache

removeListener

public boolean removeListener(ExpirationListener listen)
Description copied from interface: DataCache
Remove an expiration event listener from this cache.
Specified by:
removeListener in interface DataCache

getHitCount

public int getHitCount()
Returns the number of cache hits for invocations of the get(java.lang.Object) method. This number is cleared when cache statistics recording is first enabled (when setRecordCacheStatistics(boolean) is invoked with true, and recording was previously off) and when #clearCacheStatistics is invoked.

getMissCount

public int getMissCount()
Returns the number of cache misses for invocations of the get(java.lang.Object) method. This number is cleared when cache statistics recording is disabled (when setRecordCacheStatistics(boolean) is invoked with false).

setRecordCacheStatistics

public void setRecordCacheStatistics(boolean record)
Turns cache statistics recording on or off. If cache statistics recording is on and the cache logging category is set to log info messages, then a cache statistics statement (generated by getCacheStatisticsString()) will be logged when closing the cache.

getRecordCacheStatistics

public boolean getRecordCacheStatistics()
Returns true if cache statistics recording is currently on; otherwise returns false.

getCacheStatisticsString

public String getCacheStatisticsString()
Returns a localized string containing the number of hits, the number of misses, and the hit ratio (hits / (hits+misses)).

toString

public String toString()
Overrides:
toString in class Object

setConfiguration

public void setConfiguration(Configuration config)
Description copied from interface: Configurable
Invoked prior to setting bean properties.
Specified by:
setConfiguration in interface Configurable

startConfiguration

public void startConfiguration()
Description copied from interface: Configurable
Invoked before bean property configuration is begun on this object.
Specified by:
startConfiguration in interface Configurable

endConfiguration

public void endConfiguration()
Description copied from interface: Configurable
Invoked upon completion of bean property configuration for this object.
Specified by:
endConfiguration in interface Configurable

getStatistics

public Collection getStatistics()
Get statistics exported by this object. For Watchable interface.
Specified by:
getStatistics in interface Watchable

addListener

public boolean addListener(WatchableListener listener)
Description copied from interface: Watchable
Add a listener.
Specified by:
addListener in interface Watchable

removeListener

public boolean removeListener(WatchableListener listener)
Description copied from interface: Watchable
Remove a listener.
Specified by:
removeListener in interface Watchable

clearListeners

public void clearListeners()
Description copied from interface: Watchable
Clear all listeners.
Specified by:
clearListeners in interface Watchable

SolarMetric Kodo JDO 3.0.3 generated on February 20 2004

Copyright 2001,2002 SolarMetric, Inc. All Rights Reserved.