SolarMetric Kodo JDO 2.5.0 Reverse Schema Tool

com.solarmetric.rd.kodo.runtime.datacache.plugins
Class LocalCache

java.lang.Object
  |
  +--com.solarmetric.rd.kodo.runtime.datacache.plugins.LocalCache
All Implemented Interfaces:
Configurable, DataCache
Direct Known Subclasses:
DistributedCache

public class LocalCache
extends java.lang.Object
implements DataCache, Configurable

A single-PersistenceManagerFactory cache. This cache can be used to share data among PersistenceManagers created from a single PersistenceManagerFactory. Batch updates are performed atomically.


Field Summary
protected  com.solarmetric.rd.kodo.util.CacheMap cache
           
 
Constructor Summary
LocalCache()
           
 
Method Summary
 void batchUpdate(java.util.Map additions, java.util.Map updates, java.util.Collection deletes, java.lang.Object origin)
          Perform a batch update of the cache.
 void clear()
          Remove all data from this cache.
 void close()
          Close this cache, dropping all hard references and releasing any resources that this cache maintains.
 void endConfiguration()
          Invoked upon completion of configuration of this object
 java.lang.Object get(java.lang.Object key)
          Return the cached object for the given key.
 com.solarmetric.rd.kodo.util.CacheMap getCacheMap()
          Returns the underlying CacheMap that this LocalCache is using.
 int getCacheSize()
          Returns the maximum number of unpinned objects to keep hard references to.
protected  com.solarmetric.rd.kodo.util.CacheMap newCacheMap()
          Returns a new CacheMap for use as the underlying data cache.
 boolean pin(java.lang.Object key)
          Pin the value stored under key into the cache.
 java.lang.Object put(java.lang.Object key, java.lang.Object value)
          Set the cached value for the given key.
 java.lang.Object remove(java.lang.Object key)
          Remove the value stored under the given key.
 void removeAll(java.util.Collection keys)
           
 void setCacheSize(int size)
          Sets the maximum number of unpinned objects to keep hard references to.
 void startConfiguration()
          Invoked before configuration is begun on this object
 boolean unpin(java.lang.Object key)
          Unpin the value stored under key into the cache.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

cache

protected com.solarmetric.rd.kodo.util.CacheMap cache
Constructor Detail

LocalCache

public LocalCache()
Method Detail

getCacheMap

public com.solarmetric.rd.kodo.util.CacheMap getCacheMap()
Returns the underlying CacheMap that this LocalCache 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.


setCacheSize

public void setCacheSize(int size)
Sets the maximum number of unpinned objects to keep hard references to. If the map contains more unpinned objects than size, then this method will result in the cache flushing old values.


getCacheSize

public int getCacheSize()
Returns the maximum number of unpinned objects to keep hard references to.


newCacheMap

protected com.solarmetric.rd.kodo.util.CacheMap newCacheMap()
Returns a new CacheMap for use as the underlying data cache. This implementation returns a CacheMap. To implement a more sophisticated caching strategy, override this method to return a subclass of CacheMap.


batchUpdate

public void batchUpdate(java.util.Map additions,
                        java.util.Map updates,
                        java.util.Collection deletes,
                        java.lang.Object origin)
Description copied from interface: DataCache

Perform a batch update of the cache. Add all key-value pairs in additions, make the appropriate modifications to all key-value pairs in updates, and delete all keys in deletes. Processing the updates map might involve adding or removing objects to the cache or modifying data already in the cache.

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
Parameters:
origin - the object that initiated this cache update. This can be useful for implementations in which many sources share a single cache, which in turn communicates back to the sources on cache updates.

get

public java.lang.Object get(java.lang.Object key)
Description copied from interface: DataCache
Return the cached object for the given key. Modifying the returned object may or may not change the cached value; the DataCache.put(java.lang.Object, java.lang.Object) method should be used to re-cache any changed objects.

Specified by:
get in interface DataCache
Returns:
the object matching the given key, or null if none

put

public java.lang.Object put(java.lang.Object key,
                            java.lang.Object value)
Description copied from interface: DataCache
Set the cached value for the given key. 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.Map, java.util.Map, java.util.Collection, java.lang.Object) method.

Specified by:
put in interface DataCache
Returns:
The previously cached value, or null if the key was not previously cached. See Map.put(java.lang.Object, java.lang.Object) for more information.

remove

public java.lang.Object remove(java.lang.Object key)
Description copied from interface: DataCache
Remove the value stored under the given key. 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 batchUpdate method.

Specified by:
remove in interface DataCache
Returns:
The previously cached value, or null if the key was not previously cached. See Map.remove(java.lang.Object) for more information.

removeAll

public void removeAll(java.util.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 batchUpdate method.

Specified by:
clear in interface DataCache

pin

public boolean pin(java.lang.Object key)
Description copied from interface: DataCache
Pin the value stored under key into the cache. This method guarantees that key's value will not be dropped by the caching algorithm. This method does not affect the behavior of remove.

Specified by:
pin in interface DataCache
Returns:
true if key's value was pinned into the cache; false if the key is not in the cache.

unpin

public boolean unpin(java.lang.Object key)
Description copied from interface: DataCache
Unpin the value stored under key into the cache. This method reverses a previous invocation of DataCache.pin(java.lang.Object). This method does not remove anything from the cache; it merely makes key's value a candidate for flushing from the cache.

Specified by:
unpin in interface DataCache
Returns:
true if key's value was unpinned from the cache; false if the key is not in the cache.

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

startConfiguration

public void startConfiguration()
Description copied from interface: Configurable
Invoked before 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 configuration of this object

Specified by:
endConfiguration in interface Configurable

SolarMetric Kodo JDO 2.5.0 Reverse Schema Tool

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