org.ehcache.core
Class EhcacheManager

java.lang.Object
  extended by org.ehcache.core.EhcacheManager
All Implemented Interfaces:
CacheManager, InternalCacheManager, PersistentCacheManager

public class EhcacheManager
extends java.lang.Object
implements PersistentCacheManager, InternalCacheManager

Implementation class for the CacheManager and PersistentCacheManager

Ehcache users should not have to depend on this type but rely exclusively on the api types in package org.ehcache.


Field Summary
protected  ServiceLocator serviceLocator
           
 
Constructor Summary
EhcacheManager(Configuration config)
           
EhcacheManager(Configuration config, java.util.Collection<Service> services)
           
EhcacheManager(Configuration config, java.util.Collection<Service> services, boolean useLoaderInAtomics)
           
 
Method Summary
 void close()
          Releases all data held in Cache instances managed by this CacheManager, as well as all Service this instance provides to managed Cache instances.
protected  void closeEhcache(java.lang.String alias, InternalCache<?,?> ehcache)
          Perform cache closure actions specific to a cache manager implementation.
<K,V> Cache<K,V>
createCache(java.lang.String alias, CacheConfiguration<K,V> config)
          Creates a Cache in this CacheManager according to the specified CacheConfiguration.
 void deregisterListener(CacheManagerListener listener)
           
 void destroyCache(java.lang.String alias)
          Destroys all data persistent data associated with the aliased Cache instance managed by this CacheManager
<K,V> Cache<K,V>
getCache(java.lang.String alias, java.lang.Class<K> keyType, java.lang.Class<V> valueType)
          Retrieves the Cache associated with the given alias, if one is known.
protected  org.slf4j.Logger getLogger()
          Gets the class-identified Logger instance.
 RuntimeConfiguration getRuntimeConfiguration()
          Returns the current RuntimeConfiguration used by this CacheManager
 Status getStatus()
          Returns the current Status for this CacheManager
protected
<K,V> Store<K,V>
getStore(java.lang.String alias, CacheConfiguration<K,V> config, java.lang.Class<K> keyType, java.lang.Class<V> valueType, java.util.Collection<ServiceConfiguration<?>> serviceConfigs, java.util.List<LifeCycled> lifeCycledList)
          Instantiates a Store used for the cache data.
 void init()
          Attempts at having this CacheManager go to Status.AVAILABLE, starting all Service instances managed by this CacheManager, as well as all Cache pre registered with it.
 void registerListener(CacheManagerListener listener)
           
protected  void removeAndCloseWithoutNotice(java.lang.String alias)
          Removes and closes a cache without performing CacheManagerListener.cacheRemoved(String, Cache) notifications.
 void removeCache(java.lang.String alias)
          Removes the Cache associated with the alias provided, if oe is known.
 Maintainable toMaintenance()
          Lets you manipulate the persistent data structures for this PersistentCacheManager
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

serviceLocator

protected final ServiceLocator serviceLocator
Constructor Detail

EhcacheManager

public EhcacheManager(Configuration config)

EhcacheManager

public EhcacheManager(Configuration config,
                      java.util.Collection<Service> services)

EhcacheManager

public EhcacheManager(Configuration config,
                      java.util.Collection<Service> services,
                      boolean useLoaderInAtomics)
Method Detail

getLogger

protected org.slf4j.Logger getLogger()
Gets the class-identified Logger instance.

Returns:
the Logger to use

getCache

public <K,V> Cache<K,V> getCache(java.lang.String alias,
                                 java.lang.Class<K> keyType,
                                 java.lang.Class<V> valueType)
Description copied from interface: CacheManager
Retrieves the Cache associated with the given alias, if one is known.

Specified by:
getCache in interface CacheManager
Type Parameters:
K - the type of the keys used to access data within this cache
V - the type of the values held within this cache
Parameters:
alias - the alias under which to look the Cache up
keyType - the Cache key class
valueType - the Cache value class
Returns:
the Cache associated with the given alias, null if no association exists

removeCache

public void removeCache(java.lang.String alias)
Description copied from interface: CacheManager
Removes the Cache associated with the alias provided, if oe is known.

When the cache is removed, it will release all resources it used.

Specified by:
removeCache in interface CacheManager
Parameters:
alias - the alias for which to remove the Cache

closeEhcache

protected void closeEhcache(java.lang.String alias,
                            InternalCache<?,?> ehcache)
Perform cache closure actions specific to a cache manager implementation. This method is called after the InternalCache instance is closed.

Parameters:
alias - the cache alias
ehcache - the InternalCache instance for the cache to close

createCache

public <K,V> Cache<K,V> createCache(java.lang.String alias,
                                    CacheConfiguration<K,V> config)
                       throws java.lang.IllegalArgumentException
Description copied from interface: CacheManager
Creates a Cache in this CacheManager according to the specified CacheConfiguration.

Specified by:
createCache in interface CacheManager
Type Parameters:
K - the type of the keys used to access data within this cache
V - the type of the values held within this cache
Parameters:
alias - the alias under which the cache will be created
config - the configuration of the cache to create
Returns:
the created and initialized Cache
Throws:
java.lang.IllegalArgumentException - If there is already a cache registered with the given alias.

getStore

protected <K,V> Store<K,V> getStore(java.lang.String alias,
                                    CacheConfiguration<K,V> config,
                                    java.lang.Class<K> keyType,
                                    java.lang.Class<V> valueType,
                                    java.util.Collection<ServiceConfiguration<?>> serviceConfigs,
                                    java.util.List<LifeCycled> lifeCycledList)
Instantiates a Store used for the cache data.

Type Parameters:
K - the cache key type
V - the cache value type
Parameters:
alias - the alias assigned to the cache
config - the configuration used for the cache
keyType - the cache key type
valueType - the cache value type
serviceConfigs - the List of ServiceConfiguration instances available to the cache; this list may be augmented by the implementation of this method
lifeCycledList - the List of LifeCycled instances used to manage components of the cache; this list may be augmented by the implementation of this method
Returns:
the Store instance used to create the cache

registerListener

public void registerListener(CacheManagerListener listener)
Specified by:
registerListener in interface InternalCacheManager

deregisterListener

public void deregisterListener(CacheManagerListener listener)
Specified by:
deregisterListener in interface InternalCacheManager

init

public void init()
Attempts at having this CacheManager go to Status.AVAILABLE, starting all Service instances managed by this CacheManager, as well as all Cache pre registered with it.

Should this throw, while the CacheManager isn't yet Status.AVAILABLE, it will go back to Status.UNINITIALIZED properly (i.e. closing all services it already started, but which in turn may fail too).

Specified by:
init in interface CacheManager

getStatus

public Status getStatus()
Description copied from interface: CacheManager
Returns the current Status for this CacheManager

Specified by:
getStatus in interface CacheManager
Returns:
the current Status

close

public void close()
Description copied from interface: CacheManager
Releases all data held in Cache instances managed by this CacheManager, as well as all Service this instance provides to managed Cache instances.

Should this throw, while the CacheManager isn't yet Status.UNINITIALIZED, it will keep on trying to go to Status.UNINITIALIZED properly (i.e. closing all other services it didn't yet stop).

Specified by:
close in interface CacheManager

getRuntimeConfiguration

public RuntimeConfiguration getRuntimeConfiguration()
Description copied from interface: CacheManager
Returns the current RuntimeConfiguration used by this CacheManager

Specified by:
getRuntimeConfiguration in interface CacheManager
Returns:
the configuration instance backing this CacheManager up

removeAndCloseWithoutNotice

protected void removeAndCloseWithoutNotice(java.lang.String alias)
Removes and closes a cache without performing CacheManagerListener.cacheRemoved(String, Cache) notifications.

Parameters:
alias - the alias of the cache to remove

destroyCache

public void destroyCache(java.lang.String alias)
                  throws CachePersistenceException
Description copied from interface: PersistentCacheManager
Destroys all data persistent data associated with the aliased Cache instance managed by this CacheManager

Specified by:
destroyCache in interface PersistentCacheManager
Parameters:
alias - the Cache's alias to destroy all persistent data from
Throws:
CachePersistenceException - When something goes wrong destroying the persistent data

toMaintenance

public Maintainable toMaintenance()
Description copied from interface: PersistentCacheManager
Lets you manipulate the persistent data structures for this PersistentCacheManager

Specified by:
toMaintenance in interface PersistentCacheManager
Returns:
a Maintainable for this PersistentCacheManager