net.sf.ehcache
Class CacheManager

java.lang.Object
  extended bynet.sf.ehcache.CacheManager
All Implemented Interfaces:
java.io.Serializable

public class CacheManager
extends java.lang.Object
implements java.io.Serializable

Manages all aspects of EHCache

Version:
$Id: CacheManager.java,v 1.13 2003/12/24 00:17:26 gregluck Exp $
Author:
Greg Luck
See Also:
Serialized Form

Field Summary
static int STATUS_ALIVE
          Store alive status.
static int STATUS_SHUTDOWN
          Store disposed status.
static int STATUS_UNINITIALISED
          Store alive status.
 
Method Summary
 void addCache(Cache cache)
          Use this to add a Cache.
 void addCache(java.lang.String cacheName)
          Use this to add a Cache.
 boolean cacheExists(java.lang.String cacheName)
          Checks whether a cache exists.
static CacheManager create()
          A factory method to create a CacheManager with default config.
static CacheManager create(java.lang.String configurationFileName)
          A factory method to create a CacheManager with a specified configuration.
static CacheManager create(java.net.URL configurationFileURL)
          A factory method to create a CacheManager from an URL.
 Cache getCache(java.lang.String name)
          Gets a Cache
 java.lang.String[] getCacheNames()
          Returns a list of the current cache names.
(package private)  Configuration getConfiguration()
          Returns configuration to classes in this package.
static CacheManager getInstance()
          A factory method to get an instance ofCacheManager.
 int getStatus()
          Gets the status of the CacheManager.
 void removeCache(java.lang.String cacheName)
          Remove a cache from the CacheManager
 void shutdown()
          Each call to create() must ultimately be matched by a call to this method.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

STATUS_UNINITIALISED

public static final int STATUS_UNINITIALISED
Store alive status.

See Also:
Constant Field Values

STATUS_ALIVE

public static final int STATUS_ALIVE
Store alive status.

See Also:
Constant Field Values

STATUS_SHUTDOWN

public static final int STATUS_SHUTDOWN
Store disposed status.

See Also:
Constant Field Values
Method Detail

create

public static CacheManager create()
                           throws CacheException
A factory method to create a CacheManager with default config.

The configuration will be read, Caches created and required stores initialized. When the CacheManager is no longer required, call shutdown to free resources.

Throws:
CacheException

getInstance

public static CacheManager getInstance()
                                throws CacheException
A factory method to get an instance ofCacheManager.

This has the same effect as create()

Throws:
CacheException

create

public static CacheManager create(java.lang.String configurationFileName)
                           throws CacheException
A factory method to create a CacheManager with a specified configuration.

Parameters:
configurationFileName - an xml file compliant with the ehcache.xsd schema

The configuration will be read, Caches created and required stores initialized. When the CacheManager is no longer required, call shutdown to free resources.

Throws:
CacheException

create

public static CacheManager create(java.net.URL configurationFileURL)
                           throws CacheException
A factory method to create a CacheManager from an URL.

This method makes it possible to specify ehcache.xml, or a differently named config file in the classpath. e.g. this.getClass().getResource(...)

Parameters:
configurationFileURL - an URL to an xml file compliant with the ehcache.xsd schema

The configuration will be read, Caches created and required stores initialized. When the CacheManager is no longer required, call shutdown to free resources.

Throws:
CacheException

getCache

public Cache getCache(java.lang.String name)
               throws java.lang.IllegalStateException
Gets a Cache

Throws:
java.lang.IllegalStateException - if the cache is not STATUS_ALIVE

addCache

public void addCache(java.lang.String cacheName)
              throws java.lang.IllegalStateException,
                     ObjectExistsException,
                     CacheException
Use this to add a Cache. Memory and Disk stores will be configured for it and it will be added to the map of caches. It will be created with the defaultCache attributes specified in ehcache.xml

Parameters:
cacheName - the name for the cache
Throws:
ObjectExistsException - if the cache already exists
CacheException - if there was an error creating the cache.
java.lang.IllegalStateException

addCache

public void addCache(Cache cache)
              throws java.lang.IllegalStateException,
                     ObjectExistsException,
                     CacheException
Use this to add a Cache. Memory and Disk stores will be configured for it and it will be added to the map of caches.

Parameters:
cache -
Throws:
java.lang.IllegalStateException - if the cache is not STATUS_ALIVE
ObjectExistsException - if the cache already exists
CacheException - if there was an error creating the cache.

cacheExists

public boolean cacheExists(java.lang.String cacheName)
                    throws java.lang.IllegalStateException
Checks whether a cache exists.

Parameters:
cacheName - the cache name to check for
Returns:
true if it exists
Throws:
java.lang.IllegalStateException - if the cache is not STATUS_ALIVE

removeCache

public void removeCache(java.lang.String cacheName)
                 throws java.lang.IllegalStateException
Remove a cache from the CacheManager

Parameters:
cacheName - the cache name
Throws:
java.lang.IllegalStateException - if the cache is not STATUS_ALIVE

shutdown

public void shutdown()
Each call to create() must ultimately be matched by a call to this method. A count of instance calls is kept and understood to be the number of clients accessing this CacheManager.

This is the contract with CacheManager clients.


getCacheNames

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

Returns:
an array of Strings
Throws:
java.lang.IllegalStateException - if the cache is not STATUS_ALIVE

getConfiguration

Configuration getConfiguration()
                         throws java.lang.IllegalStateException
Returns configuration to classes in this package. Used for testing.

Throws:
java.lang.IllegalStateException - if the cache is not STATUS_ALIVE

getStatus

public int getStatus()
Gets the status of the CacheManager.

Returns:
one of: STATUS_UNINITIALISED, STATUS_ALIVE, STATUS_SHUTDOWN