Package org.infinispan.manager.impl
Class AbstractDelegatingEmbeddedCacheManager
- java.lang.Object
-
- org.infinispan.manager.impl.AbstractDelegatingEmbeddedCacheManager
-
- All Implemented Interfaces:
Closeable
,AutoCloseable
,org.infinispan.commons.api.BasicCacheContainer
,org.infinispan.commons.api.Lifecycle
,CacheContainer
,EmbeddedCacheManager
,Listenable
- Direct Known Subclasses:
AbstractDelegatingEmbeddedCacheManager
public class AbstractDelegatingEmbeddedCacheManager extends Object implements EmbeddedCacheManager
This is a convenient base class for implementing a cache manager delegate. The only constructor takes aEmbeddedCacheManager
argument, to which each method call is delegated. One can extend this class and only override the method sub-set it is interested in.- Author:
- Dan Berindei <dan@infinispan.org>
- See Also:
AbstractDelegatingCache
,AbstractDelegatingAdvancedCache
-
-
Field Summary
Fields Modifier and Type Field Description protected EmbeddedCacheManager
cm
-
Constructor Summary
Constructors Constructor Description AbstractDelegatingEmbeddedCacheManager(EmbeddedCacheManager cm)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addCacheDependency(String from, String to)
Add a dependency between two caches.void
addListener(Object listener)
Adds a listener to the component.EmbeddedCacheManagerAdmin
administration()
Provides anEmbeddedCacheManagerAdmin
whose methods affect the entire cluster as opposed to a single node.boolean
cacheExists(String cacheName)
A cache is considered to exist if it has been created and started via one of theCacheContainer.getCache()
methods and has not yet been removed viaEmbeddedCacheManager.removeCache(String)
.void
close()
<K,V>
Cache<K,V>createCache(String name, Configuration configuration)
Creates a cache on the local node using the supplied configuration.Configuration
defineConfiguration(String cacheName, String templateCacheName, Configuration configurationOverride)
Defines a named cache's configuration using by first reading the template configuration and then applying the override afterwards to generate a configuration.Configuration
defineConfiguration(String cacheName, Configuration configuration)
Defines a named cache's configuration by using the provided configurationClusterExecutor
executor()
Providess the cache manager based executor.Address
getAddress()
Warning: the address may benull
before the first clustered cache starts and after all the clustered caches have been stopped.<K,V>
Cache<K,V>getCache()
This method overrides the underlyingCacheContainer.getCache()
, to return aCache
instead of aBasicCache
<K,V>
Cache<K,V>getCache(String cacheName)
This method overrides the underlyingCacheContainer.getCache(String)
, to return aCache
instead of aBasicCache
<K,V>
Cache<K,V>getCache(String cacheName, boolean createIfAbsent)
Retrieves a named cache from the system in the same way thatCacheContainer.getCache(String)
does except that if offers the possibility for the named cache not to be retrieved if it has not yet been started, or if it's been removed after being started.<K,V>
Cache<K,V>getCache(String cacheName, String configurationName)
Retrieves a named cache from the system in the same way thatCacheContainer.getCache(String)
does except that if offers the possibility to specify a specific configuration template.<K,V>
Cache<K,V>getCache(String cacheName, String configurationTemplate, boolean createIfAbsent)
Retrieves a named cache from the system in the same way thatCacheContainer.getCache(String)
does except that if offers the possibility to specify a specific configuration template.Configuration
getCacheConfiguration(String name)
Returns the configuration for the given cache.Set<String>
getCacheConfigurationNames()
This method returns a collection of cache configuration names which contains the cache configurations that have been defined via XML or programmatically, and the cache configurations that have been defined at runtime via this cache manager instance.GlobalConfiguration
getCacheManagerConfiguration()
Returns global configuration for this CacheManagerSet<String>
getCacheNames()
This method returns a collection of caches names which contains the caches that have been defined via XML or programmatically, and the caches that have been created at runtime via this cache manager instance.org.infinispan.commons.configuration.ClassWhiteList
getClassWhiteList()
String
getClusterName()
Address
getCoordinator()
Configuration
getDefaultCacheConfiguration()
Returns default configuration for this CacheManagerGlobalComponentRegistry
getGlobalComponentRegistry()
Health
getHealth()
Returns an entry point for a Health Check API.Set<Object>
getListeners()
List<Address>
getMembers()
CacheContainerStats
getStats()
Returns statistics for this cache manager since 7.1ComponentStatus
getStatus()
Transport
getTransport()
boolean
isCoordinator()
boolean
isDefaultRunning()
Tests whether the default cache is running.boolean
isRunning(String cacheName)
Tests whether a named cache is running.void
removeCache(String cacheName)
Removes a cache with the given name from the system.void
removeListener(Object listener)
Removes a listener from the component.void
start()
Invoked on component startEmbeddedCacheManager
startCaches(String... cacheNames)
Starts a set of caches in parallel.void
stop()
Invoked on component stopvoid
undefineConfiguration(String configurationName)
Removes a configuration from the set of defined configurations.
-
-
-
Field Detail
-
cm
protected EmbeddedCacheManager cm
-
-
Constructor Detail
-
AbstractDelegatingEmbeddedCacheManager
public AbstractDelegatingEmbeddedCacheManager(EmbeddedCacheManager cm)
-
-
Method Detail
-
defineConfiguration
public Configuration defineConfiguration(String cacheName, Configuration configuration)
Description copied from interface:EmbeddedCacheManager
Defines a named cache's configuration by using the provided configuration Unlike previous versions of Infinispan, this method does not build on an existing configuration (default or named). If you want this behavior, then useConfigurationBuilder.read(org.infinispan.configuration.cache.Configuration)
. The other way to define named cache's configuration is declaratively, in the XML file passed in to the cache manager. If this cache was already configured either declaritively or programmatically this method will throw aCacheConfigurationException
.- Specified by:
defineConfiguration
in interfaceEmbeddedCacheManager
- Parameters:
cacheName
- name of cache whose configuration is being definedconfiguration
- configuration overrides to use- Returns:
- a cloned configuration instance
-
defineConfiguration
public Configuration defineConfiguration(String cacheName, String templateCacheName, Configuration configurationOverride)
Description copied from interface:EmbeddedCacheManager
Defines a named cache's configuration using by first reading the template configuration and then applying the override afterwards to generate a configuration. The other way to define named cache's configuration is declaratively, in the XML file passed in to the cache manager. If templateName is null or there isn't any named cache with that name, this methods works exactly likeEmbeddedCacheManager.defineConfiguration(String, Configuration)
. If this cache was already configured either declaratively or programmatically this method will throw aCacheConfigurationException
.- Specified by:
defineConfiguration
in interfaceEmbeddedCacheManager
- Parameters:
cacheName
- name of cache whose configuration is being definedtemplateCacheName
- name of cache to use as a template before overrides are applied to itconfigurationOverride
- configuration overrides to use- Returns:
- a cloned configuration instance
-
undefineConfiguration
public void undefineConfiguration(String configurationName)
Description copied from interface:EmbeddedCacheManager
Removes a configuration from the set of defined configurations. If the configuration is currently in use by one of the caches, anIllegalStateException
is thrown. If the named configuration does not exist, nothing happens- Specified by:
undefineConfiguration
in interfaceEmbeddedCacheManager
- Parameters:
configurationName
- the named configuration
-
getClusterName
public String getClusterName()
- Specified by:
getClusterName
in interfaceEmbeddedCacheManager
- Returns:
- the name of the cluster. Null if running in local mode.
-
getMembers
public List<Address> getMembers()
- Specified by:
getMembers
in interfaceEmbeddedCacheManager
- Returns:
- the addresses of all the members in the cluster, or
null
if not connected
-
getAddress
public Address getAddress()
Description copied from interface:EmbeddedCacheManager
Warning: the address may benull
before the first clustered cache starts and after all the clustered caches have been stopped.- Specified by:
getAddress
in interfaceEmbeddedCacheManager
- Returns:
- the address of the local node, or
null
if not connected
-
getCoordinator
public Address getCoordinator()
- Specified by:
getCoordinator
in interfaceEmbeddedCacheManager
- Returns:
- the address of the cluster's coordinator, or
null
if not connected
-
isCoordinator
public boolean isCoordinator()
- Specified by:
isCoordinator
in interfaceEmbeddedCacheManager
- Returns:
- whether the local node is the cluster's coordinator, or
null
if not connected
-
getStatus
public ComponentStatus getStatus()
- Specified by:
getStatus
in interfaceEmbeddedCacheManager
- Returns:
- the status of the cache manager
-
getDefaultCacheConfiguration
public Configuration getDefaultCacheConfiguration()
Description copied from interface:EmbeddedCacheManager
Returns default configuration for this CacheManager- Specified by:
getDefaultCacheConfiguration
in interfaceEmbeddedCacheManager
- Returns:
- the default configuration associated with this CacheManager
-
getCacheManagerConfiguration
public GlobalConfiguration getCacheManagerConfiguration()
Description copied from interface:EmbeddedCacheManager
Returns global configuration for this CacheManager- Specified by:
getCacheManagerConfiguration
in interfaceEmbeddedCacheManager
- Returns:
- the global configuration object associated to this CacheManager
-
getCacheConfiguration
public Configuration getCacheConfiguration(String name)
Description copied from interface:EmbeddedCacheManager
Returns the configuration for the given cache.- Specified by:
getCacheConfiguration
in interfaceEmbeddedCacheManager
- Returns:
- the configuration for the given cache or null if no such cache is defined
-
getCacheNames
public Set<String> getCacheNames()
Description copied from interface:org.infinispan.commons.api.BasicCacheContainer
This method returns a collection of caches names which contains the caches that have been defined via XML or programmatically, and the caches that have been created at runtime via this cache manager instance. If no named caches are registered or no caches have been created, this method returns an empty set. The list of caches does not include internal-only cachesInternalCacheRegistry
- Specified by:
getCacheNames
in interfaceorg.infinispan.commons.api.BasicCacheContainer
- Returns:
- an immutable set of caches registered or created with this cache manager.
-
getCacheConfigurationNames
public Set<String> getCacheConfigurationNames()
Description copied from interface:EmbeddedCacheManager
This method returns a collection of cache configuration names which contains the cache configurations that have been defined via XML or programmatically, and the cache configurations that have been defined at runtime via this cache manager instance. If no cache configurations are registered or no caches have been created, this method returns an empty set. The default cache is never included in this set of cache names, as well a caches for internal-only useInternalCacheRegistry
- Specified by:
getCacheConfigurationNames
in interfaceEmbeddedCacheManager
- Returns:
- an immutable set of non-default named caches registered or created with this cache manager.
-
executor
public ClusterExecutor executor()
Description copied from interface:EmbeddedCacheManager
Providess the cache manager based executor. This can be used to execute a given operation upon the cluster or a single node if desired. If this manager is not clustered this will execute locally only.Note that not all
EmbeddedCacheManager
implementations may implement this. Those that don't will throw aUnsupportedOperationException
upon invocation.- Specified by:
executor
in interfaceEmbeddedCacheManager
- Returns:
-
getHealth
public Health getHealth()
Description copied from interface:EmbeddedCacheManager
Returns an entry point for a Health Check API.- Specified by:
getHealth
in interfaceEmbeddedCacheManager
- Returns:
- Health API for this
EmbeddedCacheManager
.
-
isRunning
public boolean isRunning(String cacheName)
Description copied from interface:EmbeddedCacheManager
Tests whether a named cache is running.- Specified by:
isRunning
in interfaceEmbeddedCacheManager
- Parameters:
cacheName
- name of cache to test.- Returns:
- true if the named cache exists and is running; false otherwise.
-
isDefaultRunning
public boolean isDefaultRunning()
Description copied from interface:EmbeddedCacheManager
Tests whether the default cache is running.- Specified by:
isDefaultRunning
in interfaceEmbeddedCacheManager
- Returns:
- true if the default cache is running; false otherwise.
-
cacheExists
public boolean cacheExists(String cacheName)
Description copied from interface:EmbeddedCacheManager
A cache is considered to exist if it has been created and started via one of theCacheContainer.getCache()
methods and has not yet been removed viaEmbeddedCacheManager.removeCache(String)
. In environments when caches are continuously created and removed, this method offers the possibility to find out whether a cache has either, not been started, or if it was started, whether it's been removed already or not.- Specified by:
cacheExists
in interfaceEmbeddedCacheManager
- Returns:
- true if the cache with the given name has not yet been started, or if it was started, whether it's been removed or not.
-
administration
public EmbeddedCacheManagerAdmin administration()
Description copied from interface:EmbeddedCacheManager
Provides anEmbeddedCacheManagerAdmin
whose methods affect the entire cluster as opposed to a single node.- Specified by:
administration
in interfaceCacheContainer
- Specified by:
administration
in interfaceEmbeddedCacheManager
- Returns:
- a cluster-aware
EmbeddedCacheManagerAdmin
-
getClassWhiteList
public org.infinispan.commons.configuration.ClassWhiteList getClassWhiteList()
- Specified by:
getClassWhiteList
in interfaceEmbeddedCacheManager
-
createCache
public <K,V> Cache<K,V> createCache(String name, Configuration configuration)
Description copied from interface:EmbeddedCacheManager
Creates a cache on the local node using the supplied configuration. The cache may be clustered, but this method (or an equivalent combination ofEmbeddedCacheManager.defineConfiguration(String, Configuration)
andEmbeddedCacheManager.getCache(String, boolean)
) needs to be invoked on all nodes.- Specified by:
createCache
in interfaceEmbeddedCacheManager
- Type Parameters:
K
- the generic type of the keyV
- the generic type of the value- Parameters:
name
- the name of the cacheconfiguration
- the configuration to use.- Returns:
- the cache
-
getCache
public <K,V> Cache<K,V> getCache(String cacheName, boolean createIfAbsent)
Description copied from interface:EmbeddedCacheManager
Retrieves a named cache from the system in the same way thatCacheContainer.getCache(String)
does except that if offers the possibility for the named cache not to be retrieved if it has not yet been started, or if it's been removed after being started. If a non-template configuration exists with the same name, it will be used to configure the cache.- Specified by:
getCache
in interfaceEmbeddedCacheManager
- Parameters:
cacheName
- name of cache to retrievecreateIfAbsent
- if false, the named cache will not be retrieved if it hasn't been retrieved previously or if it's been removed. If true, this methods works just likeCacheContainer.getCache(String)
- Returns:
- null if no named cache exists as per rules set above, otherwise returns a cache instance identified by cacheName
-
getCache
public <K,V> Cache<K,V> getCache(String cacheName, String configurationName)
Description copied from interface:EmbeddedCacheManager
Retrieves a named cache from the system in the same way thatCacheContainer.getCache(String)
does except that if offers the possibility to specify a specific configuration template. Multiple caches can be created using the same configuration.- Specified by:
getCache
in interfaceEmbeddedCacheManager
- Parameters:
cacheName
- name of cache to retrieveconfigurationName
- name of the configuration template to use- Returns:
- null if no configuration exists as per rules set above, otherwise returns a cache instance identified by cacheName
-
getCache
public <K,V> Cache<K,V> getCache(String cacheName, String configurationTemplate, boolean createIfAbsent)
Description copied from interface:EmbeddedCacheManager
Retrieves a named cache from the system in the same way thatCacheContainer.getCache(String)
does except that if offers the possibility to specify a specific configuration template. Multiple caches can be created using the same configuration. Tihs method also offers the possibility for the named cache not to be retrieved if it has not yet been started, or if it's been removed after being started.- Specified by:
getCache
in interfaceEmbeddedCacheManager
- Parameters:
cacheName
- name of cache to retrieveconfigurationTemplate
- name of the configuration template to usecreateIfAbsent
- if false, the named cache will not be retrieved if it hasn't been retrieved previously or if it's been removed. If true, this methods works just likeEmbeddedCacheManager.getCache(String, String)
- Returns:
- null if no configuration exists as per rules set above, otherwise returns a cache instance identified by cacheName
-
startCaches
public EmbeddedCacheManager startCaches(String... cacheNames)
Description copied from interface:EmbeddedCacheManager
Starts a set of caches in parallel. Infinispan supports both symmetric and asymmetric clusters; that is, multiple nodes having the same or different sets of caches running, respectively. Calling this method on application/application server startup with all your cache names will ensure that the cluster is symmetric.- Specified by:
startCaches
in interfaceEmbeddedCacheManager
- Parameters:
cacheNames
- the names of the caches to start
-
removeCache
public void removeCache(String cacheName)
Description copied from interface:EmbeddedCacheManager
Removes a cache with the given name from the system. This is a cluster wide operation that results not only in stopping the cache with the given name in all nodes in the cluster, but also deletes its contents both in memory and in any backing cache store.- Specified by:
removeCache
in interfaceEmbeddedCacheManager
- Parameters:
cacheName
- name of cache to remove
-
getTransport
public Transport getTransport()
- Specified by:
getTransport
in interfaceEmbeddedCacheManager
-
getCache
public <K,V> Cache<K,V> getCache()
Description copied from interface:CacheContainer
This method overrides the underlyingCacheContainer.getCache()
, to return aCache
instead of aBasicCache
- Specified by:
getCache
in interfaceorg.infinispan.commons.api.BasicCacheContainer
- Specified by:
getCache
in interfaceCacheContainer
- Returns:
- the default cache.
-
getCache
public <K,V> Cache<K,V> getCache(String cacheName)
Description copied from interface:CacheContainer
This method overrides the underlyingCacheContainer.getCache(String)
, to return aCache
instead of aBasicCache
- Specified by:
getCache
in interfaceorg.infinispan.commons.api.BasicCacheContainer
- Specified by:
getCache
in interfaceCacheContainer
- Parameters:
cacheName
- name of cache to retrieve- Returns:
- a cache instance identified by cacheName
-
start
public void start()
Description copied from interface:org.infinispan.commons.api.Lifecycle
Invoked on component start- Specified by:
start
in interfaceorg.infinispan.commons.api.Lifecycle
-
stop
public void stop()
Description copied from interface:org.infinispan.commons.api.Lifecycle
Invoked on component stop- Specified by:
stop
in interfaceorg.infinispan.commons.api.Lifecycle
-
getGlobalComponentRegistry
public GlobalComponentRegistry getGlobalComponentRegistry()
- Specified by:
getGlobalComponentRegistry
in interfaceEmbeddedCacheManager
-
addCacheDependency
public void addCacheDependency(String from, String to)
Description copied from interface:EmbeddedCacheManager
Add a dependency between two caches. The cache manager will make sure that a cache is stopped before any of its dependencies- Specified by:
addCacheDependency
in interfaceEmbeddedCacheManager
- Parameters:
from
- cache nameto
- cache name
-
addListener
public void addListener(Object listener)
Description copied from interface:Listenable
Adds a listener to the component. Typically, listeners would need to be annotated withListener
and further to that, contain methods annotated appropriately, otherwise the listener will not be registered. See theListener
annotation for more information.- Specified by:
addListener
in interfaceListenable
- Parameters:
listener
- must not be null.
-
removeListener
public void removeListener(Object listener)
Description copied from interface:Listenable
Removes a listener from the component.- Specified by:
removeListener
in interfaceListenable
- Parameters:
listener
- listener to remove. Must not be null.
-
getListeners
public Set<Object> getListeners()
- Specified by:
getListeners
in interfaceListenable
- Returns:
- a set of all listeners registered on this component.
-
getStats
public CacheContainerStats getStats()
Description copied from interface:EmbeddedCacheManager
Returns statistics for this cache manager since 7.1- Specified by:
getStats
in interfaceEmbeddedCacheManager
- Returns:
- statistics for this cache manager
-
close
public void close() throws IOException
- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Throws:
IOException
-
-