|
ehcache | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectnet.sf.ehcache.CacheManager
public class CacheManager
A container for Ehcache
s that maintain all aspects of their lifecycle.
Field Summary | |
---|---|
static java.util.List<CacheManager> |
ALL_CACHE_MANAGERS
Keeps track of all known CacheManagers. |
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 |
protected java.util.Map |
caches
Caches managed by this manager. |
protected java.util.Map |
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. |
protected java.lang.String |
name
A name for this CacheManager to distinguish it from others. |
protected java.lang.Thread |
shutdownHook
The shutdown hook thread for CacheManager. |
protected Status |
status
Status of the Cache Manager |
Constructor Summary | |
---|---|
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. |
Method Summary | |
---|---|
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. |
boolean |
cacheExists(java.lang.String cacheName)
Checks whether a cache of type ehcache exists. |
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. |
static CacheManager |
create()
A factory method to create a singleton CacheManager with default config, or return it if it exists. |
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. |
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 |
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. |
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.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. |
CacheCluster |
getCluster(ClusterScheme scheme)
Returns access to information about the cache cluster. |
java.lang.String |
getClusterUUID()
Returns unique cluster-wide id for this cache-manager. |
java.lang.String |
getDiskStorePath()
Returns the disk store path. |
Ehcache |
getEhcache(java.lang.String name)
Gets an Ehcache |
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. |
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 |
int |
hashCode()
|
protected void |
init(Configuration configuration,
java.lang.String configurationFileName,
java.net.URL configurationURL,
java.io.InputStream configurationInputStream)
initialises the CacheManager |
boolean |
isNamed()
Indicate whether the CacheManager is named or not. |
void |
removalAll()
Removes all caches using removeCache(java.lang.String) for each cache. |
void |
removeCache(java.lang.String cacheName)
Remove a cache from the CacheManager. |
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. |
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()
|
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
public static final java.util.List<CacheManager> ALL_CACHE_MANAGERS
public static final java.lang.String ENABLE_SHUTDOWN_HOOK_PROPERTY
protected final java.util.Map ehcaches
protected final java.util.Map caches
protected java.lang.String name
protected Status status
protected java.util.Map<java.lang.String,CacheManagerPeerProvider> cacheManagerPeerProviders
protected java.util.Map<java.lang.String,CacheManagerPeerListener> cacheManagerPeerListeners
protected CacheManagerEventListenerRegistry cacheManagerEventListenerRegistry
protected java.lang.Thread shutdownHook
Constructor Detail |
---|
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.
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.
configurationFileName
- an xml configuration file available through a file name. The configuration File
is created
using new File(configurationFileName)
CacheException
create(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.
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(java.lang.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
create(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.
configurationInputStream
- an xml configuration file available through an inputstream
CacheException
create(java.io.InputStream)
public CacheManager() throws CacheException
CacheException
Method Detail |
---|
protected void init(Configuration configuration, java.lang.String configurationFileName, java.net.URL configurationURL, java.io.InputStream configurationInputStream)
public java.lang.String getClusterUUID()
public Store createTerracottaStore(Ehcache cache)
cache
- The cache for which the Store should be created
public WriteBehind createTerracottaWriteBehind(Ehcache cache)
cache
- The cache for which the write behind queue should be created
public CacheEventListener createTerracottaEventReplicator(Ehcache cache)
cache
- The cache for which the clustered event replicator should be created
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 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 create(java.net.URL configurationFileURL) throws CacheException
URL url = this.getClass().getResource("/ehcache-2.xml");Note that
Class.getResource(java.lang.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 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 Cache getCache(java.lang.String name) throws java.lang.IllegalStateException, java.lang.ClassCastException
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
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.xml
cacheName
- the name for the cache
ObjectExistsException
- if the cache already exists
CacheException
- 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 CacheManager
CacheException
- 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 CacheManager
CacheException
- if there was an error adding the cache to the CacheManagerpublic boolean cacheExists(java.lang.String cacheName) throws java.lang.IllegalStateException
cacheName
- the cache name to check for
java.lang.IllegalStateException
- if the cache is not Status.STATUS_ALIVE
public void removalAll()
removeCache(java.lang.String)
for each cache.
public void removeCache(java.lang.String cacheName) throws java.lang.IllegalStateException
cacheName
- the cache name
java.lang.IllegalStateException
- if the cache is not Status.STATUS_ALIVE
public void shutdown()
public java.lang.String[] getCacheNames() throws java.lang.IllegalStateException
String
s
java.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 with
CacheException
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 cluster
scheme
- the replication scheme to use. Schemes shipped with ehcache are RMI, JGROUPS, JMS
public CacheManagerPeerListener getCachePeerListener(java.lang.String scheme)
scheme
- the replication scheme to use. Schemes shipped with ehcache are RMI, JGROUPS, JMS
public 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 java.lang.String getDiskStorePath()
public FailSafeTimer getTimer()
FailSafeTimer
associated with this CacheManager
FailSafeTimer
associated with this cache managerpublic CacheCluster getCluster(ClusterScheme scheme)
scheme
- The clustering scheme to retrieve information about (such as "Terracotta")
ClusterScheme
public java.lang.String getOriginalConfigurationText()
CacheManager
CacheManager
public java.lang.String getActiveConfigurationText()
CacheManager
CacheManager
public java.lang.String getOriginalConfigurationText(java.lang.String cacheName)
cacheName
-
public java.lang.String getActiveConfigurationText(java.lang.String cacheName)
cacheName
-
public int hashCode()
hashCode
in class java.lang.Object
|
ehcache | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |