public class CacheManager
extends java.lang.Object
Ehcache
s that maintain all aspects of their lifecycle.
CacheManager may be either be a singleton if created with factory methods, or multiple instances may exist, in which case resources
required by each must be unique.
A CacheManager holds references to Caches and Ehcaches and manages their creation and lifecycle.Modifier and Type | Class and Description |
---|---|
(package private) class |
CacheManager.CacheRejoinAction
Class which handles rejoin events and notifies Caches implementations about them.
|
Modifier and Type | Field and Description |
---|---|
static java.util.List<CacheManager> |
ALL_CACHE_MANAGERS
Keeps track of all known CacheManagers.
|
private static java.util.Map<java.lang.String,CacheManager> |
CACHE_MANAGERS_MAP |
private static java.util.IdentityHashMap<CacheManager,java.lang.String> |
CACHE_MANAGERS_REVERSE_MAP |
protected CacheManagerEventListenerRegistry |
cacheManagerEventListenerRegistry
The listener registry
|
protected java.util.Map<java.lang.String,CacheManagerPeerListener> |
cacheManagerPeerListeners
The map of listeners
|
protected java.util.Map<java.lang.String,CacheManagerPeerProvider> |
cacheManagerPeerProviders
The map of providers
|
private FailSafeTimer |
cacheManagerTimer |
private CacheManager.CacheRejoinAction |
cacheRejoinAction |
static java.lang.String |
DEFAULT_NAME
Default name if not specified in the configuration/
|
private Ehcache |
defaultCache
Default cache cache.
|
private static long |
DELAY_UPDATE_CHECK
delay period before doing update check
|
private DiskStorePathManager |
diskStorePathManager
The path for the directory in which disk caches are created.
|
private java.util.concurrent.ConcurrentMap<java.lang.String,Ehcache> |
ehcaches
Ehcaches managed by this manager.
|
static java.lang.String |
ENABLE_SHUTDOWN_HOOK_PROPERTY
System property to enable creation of a shutdown hook for CacheManager.
|
private static long |
EVERY_WEEK
Update check interval - one week in milliseconds
|
private FeaturesManager |
featuresManager |
private static long |
LOCAL_TX_RECOVERY_THREAD_JOIN_TIMEOUT |
private java.lang.Thread |
localTransactionsRecoveryThread |
private static org.slf4j.Logger |
LOG |
private static java.lang.String |
MANAGEMENT_SERVER_CLASS_NAME |
private static MBeanRegistrationProviderFactory |
MBEAN_REGISTRATION_PROVIDER_FACTORY
The factory to use for creating MBeanRegistrationProvider's
|
private MBeanRegistrationProvider |
mbeanRegistrationProvider |
private static java.lang.String |
NO_DEFAULT_CACHE_ERROR_MSG |
private NonstopExecutorServiceFactory |
nonstopExecutorServiceFactory |
static double |
ON_HEAP_THRESHOLD
Threshold, in percent of the available heap, above which the CacheManager will warn if the configured memory
|
private Pool |
onDiskPool |
private Pool |
onHeapPool |
private java.lang.String |
registeredMgmtSvrBind |
private Configuration.RuntimeCfg |
runtimeCfg |
protected java.lang.Thread |
shutdownHook
The shutdown hook thread for CacheManager.
|
private static CacheManager |
singleton
The Singleton Instance.
|
private java.util.concurrent.ConcurrentMap<java.lang.String,SoftLockManager> |
softLockManagers |
protected Status |
status
Status of the Cache Manager
|
private TerracottaClient |
terracottaClient |
private TransactionController |
transactionController |
private DelegatingTransactionIDFactory |
transactionIDFactory |
private TransactionManagerLookup |
transactionManagerLookup |
Constructor and Description |
---|
CacheManager()
Constructor.
|
CacheManager(Configuration configuration)
An constructor for CacheManager, which takes a configuration object, rather than one created by parsing
an ehcache.xml file.
|
CacheManager(java.io.InputStream configurationInputStream)
An ordinary constructor for CacheManager.
|
CacheManager(java.lang.String configurationFileName)
An ordinary constructor for CacheManager.
|
CacheManager(java.net.URL configurationURL)
An ordinary constructor for CacheManager.
|
Modifier and Type | Method and Description |
---|---|
void |
addCache(Cache cache)
Adds a
Cache to the CacheManager. |
void |
addCache(Ehcache cache)
Adds an
Ehcache to the CacheManager. |
void |
addCache(java.lang.String cacheName)
Adds a
Ehcache based on the defaultCache with the given name. |
Ehcache |
addCacheIfAbsent(Ehcache cache)
Only adds the cache to the CacheManager should not one with the same name already be present
|
Ehcache |
addCacheIfAbsent(java.lang.String cacheName)
Only creates and adds the cache to the CacheManager should not one with the same name already be present
|
private Ehcache |
addCacheNoCheck(Ehcache cache,
boolean strict) |
private void |
addConfiguredCaches(ConfigurationHelper configurationHelper) |
void |
addDecoratedCache(Ehcache decoratedCache)
Adds a decorated
Ehcache to the CacheManager. |
void |
addDecoratedCacheIfAbsent(Ehcache decoratedCache)
Same as
addDecoratedCache(Ehcache) but does not throw exception if another cache with same name already exists. |
private void |
addOrReplaceDecoratedCache(Ehcache underlyingCache,
Ehcache decoratedCache) |
private void |
addShutdownHookIfRequired()
Some caches might be persistent, so we want to add a shutdown hook if that is the
case, so that the data and index can be written to disk.
|
private void |
assertNoCacheManagerExistsWithSameName(Configuration configuration) |
boolean |
cacheExists(java.lang.String cacheName)
Checks whether a cache of type ehcache exists.
|
private void |
checkForUpdateIfNeeded(boolean updateCheckNeeded) |
protected void |
checkStatus()
Checks the state of the CacheManager for legal operation
|
void |
clearAll()
Clears the contents of all caches in the CacheManager, but without
removing any caches.
|
void |
clearAllStartingWith(java.lang.String prefix)
Clears the contents of all caches in the CacheManager with a name starting with the prefix,
but without removing them.
|
private Ehcache |
cloneDefaultCache(java.lang.String cacheName) |
private void |
clusterRejoinComplete()
This method is called when the Terracotta Cluster is rejoined.
|
private void |
clusterRejoinStarted() |
private void |
configure(ConfigurationHelper configurationHelper) |
static CacheManager |
create()
A factory method to create a singleton CacheManager with default config, or return it if it exists.
|
static CacheManager |
create(Configuration config)
A factory method to create a singleton CacheManager from a net.sf.ehcache.config.Configuration.
|
static CacheManager |
create(java.io.InputStream inputStream)
A factory method to create a singleton CacheManager from a java.io.InputStream.
|
static CacheManager |
create(java.lang.String configurationFileName)
A factory method to create a singleton CacheManager with a specified configuration.
|
static CacheManager |
create(java.net.URL configurationFileURL)
A factory method to create a singleton CacheManager from an URL.
|
private java.util.List<Ehcache> |
createDefaultCacheDecorators(Ehcache underlyingCache) |
(package private) SizeOfEngine |
createSizeOfEngine(Cache cache)
Creates a SizeOfEngine for a cache.
|
(package private) SoftLockManager |
createSoftLockManager(Ehcache cache)
Create a soft lock manager for a specific cache
|
CacheEventListener |
createTerracottaEventReplicator(Ehcache cache)
Create/access the appropriate clustered cache event replicator for the given cache
|
Store |
createTerracottaStore(Ehcache cache)
Create/access the appropriate terracotta clustered store for the given cache
|
WriteBehind |
createTerracottaWriteBehind(Ehcache cache)
Create/access the appropriate clustered write behind queue for the given cache
|
private void |
detectAndFixCacheManagerPeerListenerConflict(ConfigurationHelper configurationHelper) |
private void |
doInit(Configuration configuration) |
java.lang.String |
getActiveConfigurationText()
Returns the active configuration text for this
CacheManager |
java.lang.String |
getActiveConfigurationText(java.lang.String cacheName)
Returns the active configuration text for the input cacheName
|
Cache |
getCache(java.lang.String name)
Returns a concrete implementation of Cache, it it is available in the CacheManager.
|
static CacheManager |
getCacheManager(java.lang.String name)
Checks if a cacheManager already exists for a given name and gets it.
|
CacheManagerEventListener |
getCacheManagerEventListener()
Returns the composite listener.
|
CacheManagerEventListenerRegistry |
getCacheManagerEventListenerRegistry()
Gets the CacheManagerEventListenerRegistry.
|
CacheManagerPeerProvider |
getCacheManagerPeerProvider(java.lang.String scheme)
Gets the
CacheManagerPeerProvider , matching the given scheme
For distributed caches, the peer provider finds other cache managers and their caches in the same cluster |
java.util.Map<java.lang.String,CacheManagerPeerProvider> |
getCacheManagerPeerProviders() |
java.lang.String[] |
getCacheNames()
Returns a list of the current cache names.
|
CacheManagerPeerListener |
getCachePeerListener(java.lang.String scheme)
When CacheManage is configured as part of a cluster, a CacheManagerPeerListener will
be registered in it.
|
(package private) CacheManager.CacheRejoinAction |
getCacheRejoinAction()
Get the CacheRejoinAction
|
private static java.lang.String |
getClientUUID(ClusteredInstanceFactory clusteredInstanceFactory) |
CacheCluster |
getCluster(ClusterScheme scheme)
Returns access to information about the cache cluster.
|
protected ClusteredInstanceFactory |
getClusteredInstanceFactory(Ehcache cache)
Return the clustered instance factory for a cache of this cache manager.
|
java.lang.String |
getClusterUUID()
Returns unique cluster-wide id for this cache-manager.
|
Configuration |
getConfiguration()
Get the CacheManager configuration
|
DiskStorePathManager |
getDiskStorePathManager()
Returns the disk store path manager.
|
Ehcache |
getEhcache(java.lang.String name)
Gets an Ehcache
|
FeaturesManager |
getFeaturesManager()
Get the features manager.
|
static CacheManager |
getInstance()
A factory method to create a singleton CacheManager with default config, or return it if it exists.
|
java.lang.String |
getName()
Gets the name of the CacheManager.
|
private NonstopActiveDelegateHolder |
getNonstopActiveDelegateHolder(Ehcache cache) |
protected NonstopExecutorService |
getNonstopExecutorService()
Return the
NonstopExecutorService associated with this cacheManager |
Pool |
getOnDiskPool()
Return this cache manager's shared on-disk pool
|
Pool |
getOnHeapPool()
Return this cache manager's shared on-heap pool
|
TransactionIDFactory |
getOrCreateTransactionIDFactory()
Get or create a TransactionIDFactory
|
java.lang.String |
getOriginalConfigurationText()
Returns the original configuration text for this
CacheManager |
java.lang.String |
getOriginalConfigurationText(java.lang.String cacheName)
Returns the original configuration text for the input cacheName
|
Status |
getStatus()
Gets the status attribute of the Ehcache
|
FailSafeTimer |
getTimer()
Returns a
FailSafeTimer associated with this CacheManager |
TransactionController |
getTransactionController()
Get the TransactionController
|
protected void |
init(Configuration initialConfiguration,
java.lang.String configurationFileName,
java.net.URL configurationURL,
java.io.InputStream configurationInputStream)
initialises the CacheManager
|
(package private) void |
initializeEhcache(Ehcache cache,
boolean registerCacheConfig)
Initialize the given
Ehcache without adding it to the CacheManager . |
private void |
internalAddDecoratedCache(Ehcache decoratedCache,
boolean strict) |
boolean |
isNamed()
Indicate whether the CacheManager is named or not.
|
static CacheManager |
newInstance()
A factory method to create a CacheManager with default config, or return it if it exists.
|
static CacheManager |
newInstance(Configuration config)
A factory method to create a CacheManager from a net.sf.ehcache.config.Configuration.
|
private static CacheManager |
newInstance(Configuration configuration,
java.lang.String msg)
Returns a new cacheManager or returns already created one.
|
static CacheManager |
newInstance(java.io.InputStream inputStream)
A factory method to create a CacheManager from a java.io.InputStream.
|
static CacheManager |
newInstance(java.lang.String configurationFileName)
A factory method to create a CacheManager with a specified configuration.
|
static CacheManager |
newInstance(java.net.URL configurationFileURL)
A factory method to create a CacheManager from an URL.
|
private Configuration |
parseConfiguration(java.lang.String configurationFileName,
java.net.URL configurationURL,
java.io.InputStream configurationInputStream)
Loads configuration, either from the supplied
ConfigurationHelper or by creating a new Configuration instance
from the configuration file referred to by file, inputstream or URL. |
private void |
reinitialisationCheck() |
void |
removalAll()
Removes all caches using
removeCache(String) for each cache. |
void |
removeCache(java.lang.String cacheName)
Remove a cache from the CacheManager.
|
private void |
removeShutdownHook()
Remove the shutdown hook to prevent leaving orphaned CacheManagers around.
|
void |
replaceCacheWithDecoratedCache(Ehcache ehcache,
Ehcache decoratedCache)
Replaces in the map of Caches managed by this CacheManager an Ehcache with a decorated version of the same
Ehcache.
|
private FeaturesManager |
retrieveFeaturesManager() |
void |
setCacheManagerEventListener(CacheManagerEventListener cacheManagerEventListener)
Same as getCacheManagerEventListenerRegistry().registerListener(cacheManagerEventListener);
Left for backward compatiblity
|
void |
setName(java.lang.String name)
Sets the name of the CacheManager.
|
void |
shutdown()
Shuts down the CacheManager.
|
java.lang.String |
toString() |
public static final java.lang.String DEFAULT_NAME
public static final double ON_HEAP_THRESHOLD
public static final java.util.List<CacheManager> ALL_CACHE_MANAGERS
public static final java.lang.String ENABLE_SHUTDOWN_HOOK_PROPERTY
private static final org.slf4j.Logger LOG
private static final long EVERY_WEEK
private static final long DELAY_UPDATE_CHECK
private static volatile CacheManager singleton
private static final MBeanRegistrationProviderFactory MBEAN_REGISTRATION_PROVIDER_FACTORY
private static final java.lang.String NO_DEFAULT_CACHE_ERROR_MSG
private static final java.util.Map<java.lang.String,CacheManager> CACHE_MANAGERS_MAP
private static final java.util.IdentityHashMap<CacheManager,java.lang.String> CACHE_MANAGERS_REVERSE_MAP
private static final java.lang.String MANAGEMENT_SERVER_CLASS_NAME
private static final long LOCAL_TX_RECOVERY_THREAD_JOIN_TIMEOUT
protected volatile Status status
protected final java.util.Map<java.lang.String,CacheManagerPeerProvider> cacheManagerPeerProviders
protected final java.util.Map<java.lang.String,CacheManagerPeerListener> cacheManagerPeerListeners
protected final CacheManagerEventListenerRegistry cacheManagerEventListenerRegistry
protected java.lang.Thread shutdownHook
private final java.util.concurrent.ConcurrentMap<java.lang.String,Ehcache> ehcaches
private Ehcache defaultCache
private DiskStorePathManager diskStorePathManager
private volatile FeaturesManager featuresManager
private MBeanRegistrationProvider mbeanRegistrationProvider
private FailSafeTimer cacheManagerTimer
private volatile TerracottaClient terracottaClient
private volatile TransactionManagerLookup transactionManagerLookup
private volatile TransactionController transactionController
private volatile java.lang.Thread localTransactionsRecoveryThread
private final java.util.concurrent.ConcurrentMap<java.lang.String,SoftLockManager> softLockManagers
private volatile Pool onHeapPool
private volatile Pool onDiskPool
private final NonstopExecutorServiceFactory nonstopExecutorServiceFactory
private volatile Configuration.RuntimeCfg runtimeCfg
private final CacheManager.CacheRejoinAction cacheRejoinAction
private volatile DelegatingTransactionIDFactory transactionIDFactory
private java.lang.String registeredMgmtSvrBind
public CacheManager(Configuration configuration) throws CacheException
create()
methods are called, a new singleton instance will be created, separate from any instances
created in this method.
Since 2.5, every newly created CacheManager is registered with its name (uses a default name if unnamed), and trying to create multiple
CacheManager with same names (or multiple unnamed CacheManagers) is not allowed and throws an exception.
It is recommended to use one of the newInstance()
methods to instantiate new CacheManagers as those methods return the same instance
of CacheManager for same names (or unnamed). Shutting down the CacheManager will deregister it and new ones can be created again.configuration
- CacheException
public CacheManager(java.lang.String configurationFileName) throws CacheException
create()
methods are called, a new singleton will be created,
separate from any instances created in this method.
Since 2.5, every newly created CacheManager is registered with its name (uses a default name if unnamed), and trying to create multiple
CacheManager with same names (or multiple unnamed CacheManagers) is not allowed and throws an exception. Using any of the newInstance()
methods also registers the CacheManager with its name.
It is recommended to use one of the newInstance()
methods to instantiate new CacheManagers as those methods return the same instance
of CacheManager for same names (or unnamed). Shutting down the CacheManager will deregister it and new ones can be created again.configurationFileName
- an xml configuration file available through a file name. The configuration File
is created
using new File(configurationFileName)
CacheException
newInstance(String)
public CacheManager(java.net.URL configurationURL) throws CacheException
create()
methods are called, a new singleton will be created,
separate from any instances created in this method.
Since 2.5, every newly created CacheManager is registered with its name (uses a default name if unnamed), and trying to create multiple
CacheManager with same names (or multiple unnamed CacheManagers) is not allowed and throws an exception. Using any of the newInstance()
methods also registers the CacheManager with its name.
It is recommended to use one of the newInstance()
methods to instantiate new CacheManagers as those methods return the same instance
of CacheManager for same names (or unnamed). Shutting down the CacheManager will deregister it and new ones can be created again.
This method can be used to specify a configuration resource in the classpath other than the default of \"/ehcache.xml\":
URL url = this.getClass().getResource("/ehcache-2.xml");Note that
Class.getResource(String)
will look for resources in the same package unless a leading "/" is used, in which case it will
look in the root of the classpath.
You can also load a resource using other class loaders. e.g. Thread.getContextClassLoader()
configurationURL
- an xml configuration available through a URL.CacheException
newInstance(java.net.URL)
public CacheManager(java.io.InputStream configurationInputStream) throws CacheException
create()
methods are called, a new singleton will be created,
separate from any instances created in this method.
Since 2.5, every newly created CacheManager is registered with its name (uses a default name if unnamed), and trying to create multiple
CacheManager with same names (or multiple unnamed CacheManagers) is not allowed and throws an exception. Using any of the newInstance()
methods also registers the CacheManager with its name.
It is recommended to use one of the newInstance()
methods to instantiate new CacheManagers as those methods return the same instance
of CacheManager for same names (or unnamed). Shutting down the CacheManager will deregister it and new ones can be created again.configurationInputStream
- an xml configuration file available through an inputstreamCacheException
newInstance(java.io.InputStream)
public CacheManager() throws CacheException
newInstance()
methods also registers the CacheManager with its name.
It is recommended to use one of the newInstance()
methods to instantiate new CacheManagers as those methods return the same instance
of CacheManager for same names (or unnamed). Shutting down the CacheManager will deregister it and new ones can be created again.CacheException
protected void init(Configuration initialConfiguration, java.lang.String configurationFileName, java.net.URL configurationURL, java.io.InputStream configurationInputStream)
private void doInit(Configuration configuration)
private void assertNoCacheManagerExistsWithSameName(Configuration configuration)
public Pool getOnHeapPool()
public Pool getOnDiskPool()
public java.lang.String getClusterUUID()
private static java.lang.String getClientUUID(ClusteredInstanceFactory clusteredInstanceFactory)
public Store createTerracottaStore(Ehcache cache)
cache
- The cache for which the Store should be createdpublic WriteBehind createTerracottaWriteBehind(Ehcache cache)
cache
- The cache for which the write behind queue should be createdpublic CacheEventListener createTerracottaEventReplicator(Ehcache cache)
cache
- The cache for which the clustered event replicator should be createdprivate NonstopActiveDelegateHolder getNonstopActiveDelegateHolder(Ehcache cache)
protected ClusteredInstanceFactory getClusteredInstanceFactory(Ehcache cache)
cache
- the cache the clustered instance factory has to be returned forprivate void checkForUpdateIfNeeded(boolean updateCheckNeeded)
private Configuration parseConfiguration(java.lang.String configurationFileName, java.net.URL configurationURL, java.io.InputStream configurationInputStream) throws CacheException
ConfigurationHelper
or by creating a new Configuration instance
from the configuration file referred to by file, inputstream or URL.
Should only be called once.configurationFileName
- the file name to parse, or nullconfigurationURL
- the URL to pass, or nullconfigurationInputStream
- , the InputStream to parse, or nullCacheException
- if the configuration cannot be parsedprivate void configure(ConfigurationHelper configurationHelper)
private void detectAndFixCacheManagerPeerListenerConflict(ConfigurationHelper configurationHelper)
private void addConfiguredCaches(ConfigurationHelper configurationHelper)
private void addOrReplaceDecoratedCache(Ehcache underlyingCache, Ehcache decoratedCache)
private void reinitialisationCheck() throws java.lang.IllegalStateException
java.lang.IllegalStateException
public static CacheManager create() throws CacheException
Ehcache
s created and required stores initialized. When the CacheManager
is no longer
required, call shutdown to free resources.CacheException
- if the CacheManager cannot be createdpublic static CacheManager newInstance() throws CacheException
Ehcache
s created and required stores initialized. When the CacheManager
is no longer
required, call shutdown to free resources.CacheException
- if the CacheManager cannot be createdpublic static CacheManager getInstance() throws CacheException
create()
Same as create()
CacheException
- if the CacheManager cannot be createdpublic static CacheManager create(java.lang.String configurationFileName) throws CacheException
configurationFileName
- an xml file compliant with the ehcache.xsd schema
The configuration will be read, Ehcache
s created and required stores initialized. When the CacheManager
is
no longer required, call shutdown to free resources.CacheException
public static CacheManager newInstance(java.lang.String configurationFileName) throws CacheException
If the specified configuration has different names for the CacheManager, it will return a new one for each unique name or return already created one.
configurationFileName
- an xml file compliant with the ehcache.xsd schema
The configuration will be read, Ehcache
s created and required stores initialized. When the CacheManager
is
no longer required, call shutdown to free resources.CacheException
public static CacheManager create(java.net.URL configurationFileURL) throws CacheException
URL url = this.getClass().getResource("/ehcache-2.xml");Note that
Class.getResource(String)
will look for resources in the same package unless a leading "/" is used, in which case it will
look in the root of the classpath.
You can also load a resource using other class loaders. e.g. Thread.getContextClassLoader()
configurationFileURL
- an URL to an xml file compliant with the ehcache.xsd schema
The configuration will be read, Ehcache
s created and required stores initialized. When the CacheManager
is
no longer required, call shutdown to free resources.CacheException
public static CacheManager newInstance(java.net.URL configurationFileURL) throws CacheException
URL url = this.getClass().getResource("/ehcache-2.xml");Note that
Class.getResource(String)
will look for resources in the same package unless a leading "/" is used, in which case it will
look in the root of the classpath.
You can also load a resource using other class loaders. e.g. Thread.getContextClassLoader()
If the specified configuration has different names for the CacheManager, it will return a new one for each unique name or return already created one.configurationFileURL
- an URL to an xml file compliant with the ehcache.xsd schema
The configuration will be read, Ehcache
s created and required stores initialized. When the CacheManager
is
no longer required, call shutdown to free resources.CacheException
public static CacheManager create(java.io.InputStream inputStream) throws CacheException
inputStream
- InputStream of xml compliant with the ehcache.xsd schema
The configuration will be read, Ehcache
s created and required stores initialized. When the CacheManager
is
no longer required, call shutdown to free resources.CacheException
public static CacheManager newInstance(java.io.InputStream inputStream) throws CacheException
inputStream
- InputStream of xml compliant with the ehcache.xsd schema
The configuration will be read, Ehcache
s created and required stores initialized. When the CacheManager
is
no longer required, call shutdown to free resources.CacheException
public static CacheManager create(Configuration config) throws CacheException
config
- CacheException
public static CacheManager newInstance(Configuration config)
config
- private static CacheManager newInstance(Configuration configuration, java.lang.String msg) throws CacheException
fileName
- name of the file to read the config frommsg
- Message printed when creating new cacheManagerCacheException
public static CacheManager getCacheManager(java.lang.String name)
name
- the cacheManager name.name
is null,
returns the default unnamed cacheManager if it has been created
already otherwise returns nullpublic Cache getCache(java.lang.String name) throws java.lang.IllegalStateException, java.lang.ClassCastException
Ehcache
decorator is present in the CacheManager, its not necessary that a
Cache
instance is also present for the same name. Decorators can have different names other than the name of the cache its
decorating.java.lang.IllegalStateException
- if the cache is not Status.STATUS_ALIVE
java.lang.ClassCastException
getEhcache(String)
public Ehcache getEhcache(java.lang.String name) throws java.lang.IllegalStateException
java.lang.IllegalStateException
- if the cache is not Status.STATUS_ALIVE
private void addShutdownHookIfRequired()
private void removeShutdownHook()
shutdown()
AFTER the status has been set to shutdown.public void addCache(java.lang.String cacheName) throws java.lang.IllegalStateException, ObjectExistsException, CacheException
Ehcache
based on the defaultCache with the given name.
Memory and Disk stores will be configured for it and it will be added to the map of caches.
Also notifies the CacheManagerEventListener after the cache was initialised and added.
It will be created with the defaultCache attributes specified in ehcache.xmlcacheName
- the name for the cacheObjectExistsException
- if the cache already existsCacheException
- if there was an error creating the cache.java.lang.IllegalStateException
public void addCache(Cache cache) throws java.lang.IllegalStateException, ObjectExistsException, CacheException
Cache
to the CacheManager.
Memory and Disk stores will be configured for it and it will be added to the map of caches. Also notifies the
CacheManagerEventListener after the cache was initialised and added.cache
- java.lang.IllegalStateException
- if the cache is not Status.STATUS_UNINITIALISED
before this method is called.ObjectExistsException
- if the cache already exists in the CacheManagerCacheException
- if there was an error adding the cache to the CacheManagerpublic void addCache(Ehcache cache) throws java.lang.IllegalStateException, ObjectExistsException, CacheException
Ehcache
to the CacheManager.
Memory and Disk stores will be configured for it and it will be added to the map of caches. Also notifies the
CacheManagerEventListener after the cache was initialised and added.cache
- java.lang.IllegalStateException
- if the cache is not Status.STATUS_UNINITIALISED
before this method is called.ObjectExistsException
- if the cache already exists in the CacheManagerCacheException
- if there was an error adding the cache to the CacheManagerpublic void addDecoratedCache(Ehcache decoratedCache) throws ObjectExistsException
Ehcache
to the CacheManager. This method neither creates the memory/disk store
nor initializes the cache. It only adds the cache reference to the map of caches held by this
cacheManager.
It is generally required that a decorated cache, once constructed, is made available to other execution threads. The simplest way of
doing this is to either add it to the cacheManager with a different name or substitute the original cache with the decorated one.
This method adds the decorated cache assuming it has a different name. If another cache (decorated or not) with the same name already
exists, it will throw ObjectExistsException
. For replacing existing cache with another decorated cache having same name,
please use replaceCacheWithDecoratedCache(Ehcache, Ehcache)
Note that any overridden Ehcache methods by the decorator will take on new behaviours without casting. Casting is only required for
new methods that the decorator introduces. For more information see the well known Gang of Four Decorator pattern.decoratedCache
- ObjectExistsException
- if another cache with the same name already exists.public void addDecoratedCacheIfAbsent(Ehcache decoratedCache) throws ObjectExistsException
addDecoratedCache(Ehcache)
but does not throw exception if another cache with same name already exists.decoratedCache
- ObjectExistsException
private void internalAddDecoratedCache(Ehcache decoratedCache, boolean strict)
void initializeEhcache(Ehcache cache, boolean registerCacheConfig)
Ehcache
without adding it to the CacheManager
.cache
- registerCacheConfig
- private Ehcache addCacheNoCheck(Ehcache cache, boolean strict) throws java.lang.IllegalStateException, ObjectExistsException, CacheException
java.lang.IllegalStateException
ObjectExistsException
CacheException
public boolean cacheExists(java.lang.String cacheName) throws java.lang.IllegalStateException
cacheName
- the cache name to check forjava.lang.IllegalStateException
- if the cache is not Status.STATUS_ALIVE
public void removalAll()
removeCache(String)
for each cache.public void removeCache(java.lang.String cacheName) throws java.lang.IllegalStateException
cacheName
- the cache namejava.lang.IllegalStateException
- if the cache is not Status.STATUS_ALIVE
public void shutdown()
public java.lang.String[] getCacheNames() throws java.lang.IllegalStateException
String
sjava.lang.IllegalStateException
- if the cache is not Status.STATUS_ALIVE
protected void checkStatus()
public Status getStatus()
public void clearAll() throws CacheException
Ehcache.removeAll()
mehod on each cache is called.CacheException
public void clearAllStartingWith(java.lang.String prefix) throws CacheException
Ehcache.removeAll()
method on each cache is called.prefix
- The prefix the cache name should start withCacheException
public CacheManagerPeerProvider getCacheManagerPeerProvider(java.lang.String scheme)
CacheManagerPeerProvider
, matching the given scheme
For distributed caches, the peer provider finds other cache managers and their caches in the same clusterscheme
- the replication scheme to use. Schemes shipped with ehcache are RMI, JGROUPS, JMSpublic java.util.Map<java.lang.String,CacheManagerPeerProvider> getCacheManagerPeerProviders()
CacheManagerPeerProvider
s keyed by scheme.public CacheManagerPeerListener getCachePeerListener(java.lang.String scheme)
scheme
- the replication scheme to use. Schemes shipped with ehcache are RMI, JGROUPS, JMSpublic CacheManagerEventListener getCacheManagerEventListener()
public void setCacheManagerEventListener(CacheManagerEventListener cacheManagerEventListener)
cacheManagerEventListener
- the listener to set.public CacheManagerEventListenerRegistry getCacheManagerEventListenerRegistry()
public void replaceCacheWithDecoratedCache(Ehcache ehcache, Ehcache decoratedCache) throws CacheException
BlockingCache
- A cache that blocks other threads from getting a null element until
the first thread has placed a value in it.
SelfPopulatingCache
- A BlockingCache that has the additional property of knowing how
to load its own entries.
ehcache
- decoratedCache
- An implementation of Ehcache that wraps the original cache.CacheException
- if the two caches do not equal each other.public java.lang.String getName()
which uses either the name or Object.toString()
public boolean isNamed()
public void setName(java.lang.String name)
name
- a name with characters legal in a JMX ObjectNamepublic java.lang.String toString()
toString
in class java.lang.Object
public DiskStorePathManager getDiskStorePathManager()
public FailSafeTimer getTimer()
FailSafeTimer
associated with this CacheManager
FailSafeTimer
associated with this cache managerpublic CacheCluster getCluster(ClusterScheme scheme) throws ClusterSchemeNotAvailableException
scheme
- The clustering scheme to retrieve information about (such as "Terracotta")ClusterSchemeNotAvailableException
- If the CacheCluster specified by scheme is not available.ClusterScheme
public java.lang.String getOriginalConfigurationText()
CacheManager
CacheManager
public java.lang.String getActiveConfigurationText()
CacheManager
CacheManager
public java.lang.String getOriginalConfigurationText(java.lang.String cacheName) throws CacheException
cacheName
- CacheException
- if the cache with cacheName
does not exist in the original configpublic java.lang.String getActiveConfigurationText(java.lang.String cacheName) throws CacheException
cacheName
- CacheException
- if the cache with cacheName
does not existpublic Configuration getConfiguration()
public Ehcache addCacheIfAbsent(Ehcache cache)
cache
- The Ehcache to be addedpublic Ehcache addCacheIfAbsent(java.lang.String cacheName)
cacheName
- the name of the Cache to be createdprivate Ehcache cloneDefaultCache(java.lang.String cacheName)
private java.util.List<Ehcache> createDefaultCacheDecorators(Ehcache underlyingCache)
public TransactionController getTransactionController()
public TransactionIDFactory getOrCreateTransactionIDFactory()
SoftLockManager createSoftLockManager(Ehcache cache)
cache
- the cache to create the soft lock manager forprivate void clusterRejoinStarted()
private void clusterRejoinComplete()
SizeOfEngine createSizeOfEngine(Cache cache)
cache
- The cache to be sized by the engineprotected NonstopExecutorService getNonstopExecutorService()
NonstopExecutorService
associated with this cacheManagerNonstopExecutorService
associated with this cacheManagerCacheManager.CacheRejoinAction getCacheRejoinAction()
public FeaturesManager getFeaturesManager()
private FeaturesManager retrieveFeaturesManager()