Class CompositeCacheManager

java.lang.Object
org.apache.commons.jcs3.engine.control.CompositeCacheManager
All Implemented Interfaces:
IRemoteCacheConstants, ICompositeCacheManager, IProvideScheduler, IShutdownObservable

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.

  • Field Details

  • Constructor Details

  • Method Details

    • getInstance

      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

      Get a CacheHub instance which is not configured. If an instance already exists, it will be returned.

      Returns:
      CompositeCacheManager
    • createInstance

      Simple factory method, must override in subclasses so getInstance creates / returns the correct object.

      Returns:
      CompositeCacheManager
    • initialize

      protected void initialize()
      Creates a shutdown hook and starts the scheduler service
    • getElementEventQueue

      Get the element event queue
      Returns:
      the elementEventQueue
    • 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

      Gets the defaultCacheAttributes attribute of the CacheHub object

      Returns:
      The defaultCacheAttributes value
    • getDefaultElementAttributes

      Gets the defaultElementAttributes attribute of the CacheHub object

      Returns:
      The defaultElementAttributes value
    • getCache

      public <K, V> 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, V> CompositeCache<K,V> getCache(String cacheName, ICompositeCacheAttributes cattr)
      Gets the cache attribute of the CacheHub object

      Parameters:
      cacheName -
      cattr -
      Returns:
      CompositeCache
    • getCache

      public <K, V> 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, V> CompositeCache<K,V> getCache(ICompositeCacheAttributes cattr)
      Gets the cache attribute of the CacheHub object

      Parameters:
      cattr -
      Returns:
      CompositeCache
    • getCache

      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
    • newConfigurator

    • 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
    • release

      public void release()
    • getCacheNames

      Returns a list of the current cache names.
      Returns:
      Set
    • getCacheType

      Returns:
      ICacheType.CACHE_HUB
    • registryFacPut

      public void registryFacPut(AuxiliaryCacheFactory auxFac)
      Parameters:
      auxFac -
    • registryFacGet

      Parameters:
      name -
      Returns:
      AuxiliaryCacheFactory
    • registryAttrPut

      Parameters:
      auxAttr -
    • registryAttrGet

      Parameters:
      name -
      Returns:
      AuxiliaryCacheAttributes
    • addCache

      public void addCache(String cacheName, ICache<?,?> cache)
      Add a cache to the map of registered caches
      Parameters:
      cacheName - the region name
      cache - the cache instance
    • addAuxiliaryCache

      public void addAuxiliaryCache(String auxName, String cacheName, AuxiliaryCache<?,?> cache)
      Add a cache to the map of registered auxiliary caches
      Parameters:
      auxName - the auxiliary name
      cacheName - the region name
      cache - the cache instance
    • getAuxiliaryCache

      public <K, V> AuxiliaryCache<K,V> getAuxiliaryCache(String auxName, String cacheName)
      Get a cache from the map of registered auxiliary caches
      Specified by:
      getAuxiliaryCache in interface ICompositeCacheManager
      Parameters:
      auxName - the auxiliary name
      cacheName - the region name
      Returns:
      the cache instance
    • freeAuxiliaryCache

      public void freeAuxiliaryCache(String auxName, String cacheName) throws IOException
      Dispose a cache and remove it from the map of registered auxiliary caches
      Parameters:
      auxName - the auxiliary name
      cacheName - the region name
      Throws:
      IOException - if disposing of the cache fails
    • freeAuxiliaryCache

      public void freeAuxiliaryCache(String key) throws IOException
      Dispose a cache and remove it from the map of registered auxiliary caches
      Parameters:
      key - the key into the map of auxiliaries
      Throws:
      IOException - if disposing of the cache fails
    • 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

      This returns data gathered for all regions and all the auxiliaries they currently uses.

      Returns:
      ICacheStats[]
    • registerShutdownObserver

      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

      Description copied from interface: IShutdownObservable
      Deregister the observer with the observable.
      Specified by:
      deregisterShutdownObserver in interface IShutdownObservable
      Parameters:
      observer -
    • getConfigurationProperties

      This is exposed so other manager can get access to the props.

      Specified by:
      getConfigurationProperties in interface ICompositeCacheManager
      Returns:
      the configurationProperties
    • isInitialized

      public boolean isInitialized()
      Returns:
      the isInitialized
    • isConfigured

      public boolean isConfigured()
      Returns:
      the isConfigured
    • setJmxName

      public void setJmxName(String name)