org.apache.jcs.engine.control
Class CompositeCacheManager

java.lang.Object
  extended by org.apache.jcs.engine.control.CompositeCacheManager
All Implemented Interfaces:
Serializable, IRemoteCacheConstants, ICompositeCacheManager, IProvideScheduler, IShutdownObservable

public class CompositeCacheManager
extends Object
implements IRemoteCacheConstants, Serializable, ICompositeCacheManager, IShutdownObservable, IProvideScheduler

Manages a composite cache. This provides access to caches and is the primary way to shutdown the caching system as a whole.

The composite cache manager is responsible for creating / configuring cache regions. It serves as a factory for the ComositeCache class. The CompositeCache is the core of JCS, the hub for various auxiliaries.

It is recommended that you use the JCS convenience class for all cache access.

See Also:
Serialized Form

Field Summary
protected  Hashtable<String,AuxiliaryCacheAttributes> auxiliaryAttributeRegistry
          Used to keep track of attributes for auxiliaries.
protected  Hashtable<String,AuxiliaryCacheFactory> auxiliaryFactoryRegistry
          Used to keep track of configured auxiliaries
protected  Hashtable<String,ICache<? extends Serializable,? extends Serializable>> caches
          Caches managed by this cache manager
protected  String defaultAuxValues
          The default auxiliary caches to be used if not preconfigured
protected  ICompositeCacheAttributes defaultCacheAttr
          Default cache attributes for this cache manager
protected  IElementAttributes defaultElementAttr
          Default element attributes for this cache manager
protected static CompositeCacheManager instance
          The Singleton Instance
protected static org.apache.commons.logging.Log log
          The logger
protected  Hashtable<String,ICache<? extends Serializable,? extends Serializable>> systemCaches
          Internal system caches for this cache manager
 
Fields inherited from interface org.apache.jcs.auxiliary.remote.behavior.IRemoteCacheConstants
CACHE_SERVER_ATTRIBUTES_PROPERTY_PREFIX, CACHE_SERVER_PREFIX, CUSTOM_RMI_SOCKET_FACTORY_PROPERTY_PREFIX, PROPERTY_PREFIX, REMOTE_ALLOW_CLUSTER_GET, REMOTE_CACHE_SERVICE_NAME, REMOTE_CACHE_SERVICE_PORT, REMOTE_CACHE_SERVICE_VAL, REMOTE_LOCAL_CLUSTER_CONSISTENCY, SOCKET_TIMEOUT_MILLIS, TOMCAT_ON, TOMCAT_XML
 
Constructor Summary
protected CompositeCacheManager()
          Creates a shutdown hook and starts the scheduler service
 
Method Summary
 void configure()
          Configure with default properties file
 void configure(Properties props)
          Configure from properties object.
 void configure(Properties props, boolean useSystemProperties)
          Configure from properties object, overriding with values from the system properties if instructed.
 void configure(Properties props, boolean useSystemProperties, boolean forceReconfiguration)
          Configure from properties object, overriding with values from the system properties if instructed.
 void configure(String propFile)
          Configure from specific properties file.
protected static CompositeCacheManager createInstance()
          Simple factory method, must override in subclasses so getInstance creates / returns the correct object.
 void deregisterShutdownObserver(IShutdownObserver observer)
          Deregisters the observer with the observable.
 void freeCache(String name)
           
 void freeCache(String name, boolean fromRemote)
           
<K extends Serializable,V extends Serializable>
CompositeCache<K,V>
getCache(ICompositeCacheAttributes cattr)
          Gets the cache attribute of the CacheHub object
<K extends Serializable,V extends Serializable>
CompositeCache<K,V>
getCache(ICompositeCacheAttributes cattr, IElementAttributes attr)
          If the cache has already been created, then the CacheAttributes and the element Attributes will be ignored.
<K extends Serializable,V extends Serializable>
CompositeCache<K,V>
getCache(String cacheName)
          Gets the cache attribute of the CacheHub object
<K extends Serializable,V extends Serializable>
CompositeCache<K,V>
getCache(String cacheName, ICompositeCacheAttributes cattr)
          Gets the cache attribute of the CacheHub object
<K extends Serializable,V extends Serializable>
CompositeCache<K,V>
getCache(String cacheName, ICompositeCacheAttributes cattr, IElementAttributes attr)
          Gets the cache attribute of the CacheHub object
 String[] getCacheNames()
          Returns a list of the current cache names.
 ICacheType.CacheType getCacheType()
           
 Properties getConfigurationProperties()
          This is exposed so other manager can get access to the props.
 ICompositeCacheAttributes getDefaultCacheAttributes()
          Gets the defaultCacheAttributes attribute of the CacheHub object
 ICompositeCacheAttributes getDefaultCattr()
           
 IElementAttributes getDefaultElementAttributes()
          Gets the defaultElementAttributes attribute of the CacheHub object
static CompositeCacheManager getInstance()
          Gets the CacheHub instance.
static CompositeCacheManager getInstance(String propsFilename)
          Initializes the cache manager using the props file for the given name.
 ScheduledExecutorService getScheduledExecutorService()
          Get the scheduler service
 ICacheStats[] getStatistics()
          This returns data gathered for all regions and all the auxiliaries they currently uses.
 String getStats()
          Gets stats for debugging.
static CompositeCacheManager getUnconfiguredInstance()
          Get a CacheHub instance which is not configured.
protected  void incrementClients()
           
 boolean isConfigured()
           
 boolean isShutdown()
           
 void registerShutdownObserver(IShutdownObserver observer)
          Perhaps the composite cache itself should be the observable object.
 void release()
           
 void setConfigurationProperties(Properties props)
          This is exposed so other manager can get access to the props.
 void setDefaultCacheAttributes(ICompositeCacheAttributes icca)
          Sets the defaultCacheAttributes attribute of the CacheHub object
 void setDefaultElementAttributes(IElementAttributes iea)
          Sets the defaultElementAttributes attribute of the CacheHub object
 void shutDown()
          Calls freeCache on all regions
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

log

protected static final org.apache.commons.logging.Log log
The logger


caches

protected Hashtable<String,ICache<? extends Serializable,? extends Serializable>> caches
Caches managed by this cache manager


systemCaches

protected Hashtable<String,ICache<? extends Serializable,? extends Serializable>> systemCaches
Internal system caches for this cache manager


defaultCacheAttr

protected ICompositeCacheAttributes defaultCacheAttr
Default cache attributes for this cache manager


defaultElementAttr

protected IElementAttributes defaultElementAttr
Default element attributes for this cache manager


auxiliaryFactoryRegistry

protected Hashtable<String,AuxiliaryCacheFactory> auxiliaryFactoryRegistry
Used to keep track of configured auxiliaries


auxiliaryAttributeRegistry

protected Hashtable<String,AuxiliaryCacheAttributes> auxiliaryAttributeRegistry
Used to keep track of attributes for auxiliaries.


defaultAuxValues

protected String defaultAuxValues
The default auxiliary caches to be used if not preconfigured


instance

protected static CompositeCacheManager instance
The Singleton Instance

Constructor Detail

CompositeCacheManager

protected CompositeCacheManager()
Creates a shutdown hook and starts the scheduler service

Method Detail

getInstance

public static CompositeCacheManager getInstance()
                                         throws CacheException
Gets the CacheHub instance. For backward compatibility, if this creates the instance it will attempt to configure it with the default configuration. If you want to configure from your own source, use getUnconfiguredInstance()and then call configure()

Returns:
CompositeCacheManager
Throws:
CacheException - if the configuration cannot be loaded

getInstance

public static CompositeCacheManager getInstance(String propsFilename)
                                         throws CacheException
Initializes the cache manager using the props file for the given name.

Parameters:
propsFilename -
Returns:
CompositeCacheManager configured from the give propsFileName
Throws:
CacheException - if the configuration cannot be loaded

getUnconfiguredInstance

public static CompositeCacheManager getUnconfiguredInstance()
Get a CacheHub instance which is not configured. If an instance already exists, it will be returned.

Returns:
CompositeCacheManager

createInstance

protected static CompositeCacheManager createInstance()
Simple factory method, must override in subclasses so getInstance creates / returns the correct object.

Returns:
CompositeCacheManager

getScheduledExecutorService

public ScheduledExecutorService getScheduledExecutorService()
Get the scheduler service

Specified by:
getScheduledExecutorService in interface IProvideScheduler
Returns:
the scheduledExecutor

configure

public void configure()
               throws CacheException
Configure with default properties file

Throws:
CacheException - if the configuration cannot be loaded

configure

public void configure(String propFile)
               throws CacheException
Configure from specific properties file.

Parameters:
propFile - Path within classpath to load configuration from
Throws:
CacheException - if the configuration cannot be loaded

configure

public void configure(Properties props)
Configure from properties object.

This method will call configure, instructing it to use system properties as a default.

Parameters:
props -

configure

public void configure(Properties props,
                      boolean useSystemProperties)
Configure from properties object, overriding with values from the system properties if instructed.

You can override a specific value by passing in a system property:

For example, you could override this value in the cache.ccf file by starting up your program with the argument: -Djcs.auxiliary.LTCP.attributes.TcpListenerPort=1111

Parameters:
props -
useSystemProperties - -- if true, values starting with jcs will be put into the props file prior to configuring the cache.

configure

public void configure(Properties props,
                      boolean useSystemProperties,
                      boolean forceReconfiguration)
Configure from properties object, overriding with values from the system properties if instructed.

You can override a specific value by passing in a system property:

For example, you could override this value in the cache.ccf file by starting up your program with the argument: -Djcs.auxiliary.LTCP.attributes.TcpListenerPort=1111

Parameters:
props -
useSystemProperties - -- if true, values starting with jcs will be put into the props file prior to configuring the cache.
forceReconfiguration - - if the manager is already configured, we will try again. This may not work properly.

getDefaultCacheAttributes

public ICompositeCacheAttributes getDefaultCacheAttributes()
Gets the defaultCacheAttributes attribute of the CacheHub object

Returns:
The defaultCacheAttributes value

setDefaultCacheAttributes

public void setDefaultCacheAttributes(ICompositeCacheAttributes icca)
Sets the defaultCacheAttributes attribute of the CacheHub object

Parameters:
icca - The new defaultCacheAttributes value

setDefaultElementAttributes

public void setDefaultElementAttributes(IElementAttributes iea)
Sets the defaultElementAttributes attribute of the CacheHub object

Parameters:
iea - The new defaultElementAttributes value

getDefaultElementAttributes

public IElementAttributes getDefaultElementAttributes()
Gets the defaultElementAttributes attribute of the CacheHub object

Returns:
The defaultElementAttributes value

getCache

public <K extends Serializable,V extends Serializable> CompositeCache<K,V> getCache(String cacheName)
Gets the cache attribute of the CacheHub object

Specified by:
getCache in interface ICompositeCacheManager
Parameters:
cacheName -
Returns:
CompositeCache -- the cache region controller

getCache

public <K extends Serializable,V extends Serializable> CompositeCache<K,V> getCache(String cacheName,
                                                                                    ICompositeCacheAttributes cattr)
Gets the cache attribute of the CacheHub object

Parameters:
cacheName -
cattr -
Returns:
CompositeCache

getCache

public <K extends Serializable,V extends Serializable> CompositeCache<K,V> getCache(String cacheName,
                                                                                    ICompositeCacheAttributes cattr,
                                                                                    IElementAttributes attr)
Gets the cache attribute of the CacheHub object

Parameters:
cacheName -
cattr -
attr -
Returns:
CompositeCache

getCache

public <K extends Serializable,V extends Serializable> CompositeCache<K,V> getCache(ICompositeCacheAttributes cattr)
Gets the cache attribute of the CacheHub object

Parameters:
cattr -
Returns:
CompositeCache

getCache

public <K extends Serializable,V extends Serializable> CompositeCache<K,V> getCache(ICompositeCacheAttributes cattr,
                                                                                    IElementAttributes attr)
If the cache has already been created, then the CacheAttributes and the element Attributes will be ignored. Currently there is no overriding the CacheAttributes once it is set up. You can change the default ElementAttributes for a region later.

Overriding the default elemental attributes will require changing the way the attributes are assigned to elements. Get cache creates a cache with defaults if none are specified. We might want to create separate method for creating/getting. . .

Parameters:
cattr -
attr -
Returns:
CompositeCache

freeCache

public void freeCache(String name)
Parameters:
name -

freeCache

public void freeCache(String name,
                      boolean fromRemote)
Parameters:
name -
fromRemote -

shutDown

public void shutDown()
Calls freeCache on all regions


incrementClients

protected void incrementClients()

release

public void release()

getCacheNames

public String[] getCacheNames()
Returns a list of the current cache names.

Returns:
String[]

getCacheType

public ICacheType.CacheType getCacheType()
Returns:
ICacheType.CACHE_HUB

getDefaultCattr

public ICompositeCacheAttributes getDefaultCattr()
Returns:
ICompositeCacheAttributes

getStats

public String getStats()
Gets stats for debugging. This calls gets statistics and then puts all the results in a string. This returns data for all regions.

Specified by:
getStats in interface ICompositeCacheManager
Returns:
String

getStatistics

public ICacheStats[] getStatistics()
This returns data gathered for all regions and all the auxiliaries they currently uses.

Returns:
ICacheStats[]

registerShutdownObserver

public void registerShutdownObserver(IShutdownObserver observer)
Perhaps the composite cache itself should be the observable object. It doesn't make much of a difference. There are some problems with region by region shutdown. Some auxiliaries are global. They will need to track when every region has shutdown before doing things like closing the socket with a lateral.

Specified by:
registerShutdownObserver in interface IShutdownObservable
Parameters:
observer -

deregisterShutdownObserver

public void deregisterShutdownObserver(IShutdownObserver observer)
Description copied from interface: IShutdownObservable
Deregisters the observer with the observable.

Specified by:
deregisterShutdownObserver in interface IShutdownObservable
Parameters:
observer -

setConfigurationProperties

public void setConfigurationProperties(Properties props)
This is exposed so other manager can get access to the props.

Parameters:
props -

getConfigurationProperties

public Properties getConfigurationProperties()
This is exposed so other manager can get access to the props.

Specified by:
getConfigurationProperties in interface ICompositeCacheManager
Returns:
the configurationProperties

isShutdown

public boolean isShutdown()
Returns:
the isShutdown

isConfigured

public boolean isConfigured()
Returns:
the isConfigured


Copyright © 2002-2013 The Apache Software Foundation. All Rights Reserved.