com.opensymphony.oscache.base
Class AbstractCacheAdministrator

java.lang.Object
  extended bycom.opensymphony.oscache.base.AbstractCacheAdministrator
All Implemented Interfaces:
java.io.Serializable
Direct Known Subclasses:
GeneralCacheAdministrator, ServletCacheAdministrator

public abstract class AbstractCacheAdministrator
extends java.lang.Object
implements java.io.Serializable

An AbstractCacheAdministrator defines an abstract cache administrator, implementing all the basic operations related to the configuration of a cache, including assigning any configured event handlers to cache objects.

Extend this class to implement a custom cache administrator.

Version:
$Revision: 1.5 $
Author:
a href="mailto:mike@atlassian.com">Mike Cannon-Brookes, Francois Beauregard, Alain Bergevin, Fabian Crabus, Chris Miller
See Also:
Serialized Form

Field Summary
protected  java.lang.String algorithmClass
          The algorithm class being used, as specified by the CACHE_ALGORITHM_KEY configuration property.
protected static java.lang.String CACHE_ALGORITHM_KEY
          A String cache configuration property that specifies the classname of an alternate caching algorithm.
protected static java.lang.String CACHE_BLOCKING_KEY
          The configuration key that specifies whether we should block waiting for new content to be generated, or just serve the old content instead.
protected static java.lang.String CACHE_CAPACITY_KEY
          An integer cache configuration property that specifies the maximum number of objects to hold in the cache.
protected static java.lang.String CACHE_DISK_UNLIMITED_KEY
          A boolean cache configuration property that indicates whether the persistent cache should be unlimited in size, or should be restricted to the same size as the in-memory cache.
protected static java.lang.String CACHE_ENTRY_EVENT_LISTENERS
          A String cache configuration property that holds a comma-delimited list of classnames.
protected static java.lang.String CACHE_MEMORY_KEY
          A boolean cache configuration property that indicates whether the cache should cache objects in memory.
protected  int cacheCapacity
          The cache capacity (number of entries), as specified by the CACHE_CAPACITY_KEY configuration property.
protected  Config config
           
protected  javax.swing.event.EventListenerList listenerList
          Holds a list of all the registered event listeners.
protected static java.lang.String PERSISTENCE_CLASS
          A String cache configuration property that specifies the classname that will be used to provide cache persistence.
 
Constructor Summary
protected AbstractCacheAdministrator()
          Create the AbstractCacheAdministrator.
protected AbstractCacheAdministrator(java.util.Properties p)
          Create the AbstractCacheAdministrator.
 
Method Summary
protected  Cache configureStandardListeners(Cache cache)
          Applies all of the recognised listener classes to the supplied cache object.
protected  void finalizeListeners(Cache cache)
          Finalizes all the listeners that are associated with the given cache object.
protected  CacheEventListener[] getCacheEventListeners()
          Retrieves an array containing instances all of the CacheEventListener classes that are specified in the OSCache configuration file.
 java.lang.String getProperty(java.lang.String key)
          Retrieves the value of one of the configuration properties.
 boolean isBlocking()
          Indicates whether the cache will block waiting for new content to be built, or serve stale content instead of waiting.
 boolean isMemoryCaching()
          Whether entries are cached in memory or not.
 boolean isUnlimitedDiskCache()
          Indicates whether the unlimited disk cache is enabled or not.
 void setAlgorithmClass(java.lang.String newAlgorithmClass)
          Sets the algorithm to use for the cache.
protected  void setCacheCapacity(int newCacheCapacity)
          Sets the cache capacity (number of items).
protected  Cache setPersistenceListener(Cache cache)
          If there is a PersistenceListener in the configuration it will be instantiated and applied to the given cache object.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

CACHE_MEMORY_KEY

protected static final java.lang.String CACHE_MEMORY_KEY
A boolean cache configuration property that indicates whether the cache should cache objects in memory. Set this property to false to disable in-memory caching.

See Also:
Constant Field Values

CACHE_CAPACITY_KEY

protected static final java.lang.String CACHE_CAPACITY_KEY
An integer cache configuration property that specifies the maximum number of objects to hold in the cache. Setting this to a negative value will disable the capacity functionality - there will be no limit to the number of objects that are held in cache.

See Also:
Constant Field Values

CACHE_ALGORITHM_KEY

protected static final java.lang.String CACHE_ALGORITHM_KEY
A String cache configuration property that specifies the classname of an alternate caching algorithm. This class must extend AbstractConcurrentReadCache By default caches will use LRUCache as the default algorithm if the cache capacity is set to a postive value, or UnlimitedCache if the capacity is negative (ie, disabled).

See Also:
Constant Field Values

CACHE_DISK_UNLIMITED_KEY

protected static final java.lang.String CACHE_DISK_UNLIMITED_KEY
A boolean cache configuration property that indicates whether the persistent cache should be unlimited in size, or should be restricted to the same size as the in-memory cache. Set this property to true to allow the persistent cache to grow without bound.

See Also:
Constant Field Values

CACHE_BLOCKING_KEY

protected static final java.lang.String CACHE_BLOCKING_KEY
The configuration key that specifies whether we should block waiting for new content to be generated, or just serve the old content instead. The default behaviour is to serve the old content since that provides the best performance (at the cost of serving slightly stale data).

See Also:
Constant Field Values

PERSISTENCE_CLASS

protected static final java.lang.String PERSISTENCE_CLASS
A String cache configuration property that specifies the classname that will be used to provide cache persistence. This class must extend PersistenceListener.

See Also:
Constant Field Values

CACHE_ENTRY_EVENT_LISTENERS

protected static final java.lang.String CACHE_ENTRY_EVENT_LISTENERS
A String cache configuration property that holds a comma-delimited list of classnames. These classes specify the event handlers that are to be applied to the cache.

See Also:
Constant Field Values

config

protected Config config

listenerList

protected javax.swing.event.EventListenerList listenerList
Holds a list of all the registered event listeners. Event listeners are specified using the CACHE_ENTRY_EVENT_LISTENERS configuration key.


algorithmClass

protected java.lang.String algorithmClass
The algorithm class being used, as specified by the CACHE_ALGORITHM_KEY configuration property.


cacheCapacity

protected int cacheCapacity
The cache capacity (number of entries), as specified by the CACHE_CAPACITY_KEY configuration property.

Constructor Detail

AbstractCacheAdministrator

protected AbstractCacheAdministrator()
Create the AbstractCacheAdministrator. This will initialize all values and load the properties from oscache.properties.


AbstractCacheAdministrator

protected AbstractCacheAdministrator(java.util.Properties p)
Create the AbstractCacheAdministrator.

Parameters:
p - the configuration properties for this cache.
Method Detail

setAlgorithmClass

public void setAlgorithmClass(java.lang.String newAlgorithmClass)
Sets the algorithm to use for the cache.

Parameters:
newAlgorithmClass - The class to use (eg. "com.opensymphony.oscache.base.algorithm.LRUCache")
See Also:
LRUCache, FIFOCache, UnlimitedCache

isBlocking

public boolean isBlocking()
Indicates whether the cache will block waiting for new content to be built, or serve stale content instead of waiting. Regardless of this setting, the cache will always block if new content is being created, ie, there's no stale content in the cache that can be served.


setCacheCapacity

protected void setCacheCapacity(int newCacheCapacity)
Sets the cache capacity (number of items). Administrator implementations should override this method to ensure that their Cache objects are updated correctly (by calling AbstractConcurrentReadCache.setMaxEntries(int)}}.

Parameters:
newCacheCapacity - The new capacity

isMemoryCaching

public boolean isMemoryCaching()
Whether entries are cached in memory or not. Default is true. Set by the cache.memory property.

Returns:
Status whether or not memory caching is used.

getProperty

public java.lang.String getProperty(java.lang.String key)
Retrieves the value of one of the configuration properties.

Parameters:
key - The key assigned to the property
Returns:
Property value, or null if the property could not be found.

isUnlimitedDiskCache

public boolean isUnlimitedDiskCache()
Indicates whether the unlimited disk cache is enabled or not.


getCacheEventListeners

protected CacheEventListener[] getCacheEventListeners()
Retrieves an array containing instances all of the CacheEventListener classes that are specified in the OSCache configuration file.


setPersistenceListener

protected Cache setPersistenceListener(Cache cache)
If there is a PersistenceListener in the configuration it will be instantiated and applied to the given cache object. If the PersistenceListener cannot be found or instantiated, an error will be logged but the cache will not have a persistence listener applied to it and no exception will be thrown.

A cache can only have one PersistenceListener.

Parameters:
cache - the cache to apply the PersistenceListener to.
Returns:
the same cache object that was passed in.

configureStandardListeners

protected Cache configureStandardListeners(Cache cache)
Applies all of the recognised listener classes to the supplied cache object. Recognised classes are CacheEntryEventListener and CacheMapAccessEventListener.

Parameters:
cache - The cache to apply the configuration to.
Returns:
cache The configured cache object.

finalizeListeners

protected void finalizeListeners(Cache cache)
Finalizes all the listeners that are associated with the given cache object. Any FinalizationExceptions that are thrown by the listeners will be caught and logged.


See www.opensymphony.com for more information.