Package org.infinispan.manager.impl
Class AbstractDelegatingEmbeddedCacheManager
- java.lang.Object
-
- org.infinispan.manager.impl.AbstractDelegatingEmbeddedCacheManager
-
- All Implemented Interfaces:
Closeable
,AutoCloseable
,BasicCacheContainer
,Lifecycle
,CacheContainer
,EmbeddedCacheManager
,Listenable
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 Deprecated 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.CompletionStage<Void>
addListenerAsync(Object listener)
Asynchronous version ofListenable.addListener(Object)
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 theEmbeddedCacheManager.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 cache configuration by first reading the template configuration and then applying the override.Configuration
defineConfiguration(String cacheName, Configuration configuration)
Register a cache configuration in the cache manager.ClusterExecutor
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()
Retrieves the default cache associated with this cache container.<K,V>
Cache<K,V>getCache(String cacheName)
Retrieves a cache by name.<K,V>
Cache<K,V>getCache(String cacheName, boolean createIfAbsent)
Similar toEmbeddedCacheManager.getCache(String)
, except if has the option to not create the cache if it is not already running.Configuration
getCacheConfiguration(String name)
Returns the configuration for the given cache.Set<String>
getCacheConfigurationNames()
This method returns a collection of all cache configuration names.GlobalConfiguration
getCacheManagerConfiguration()
Returns global configuration for this CacheManagerCacheManagerInfo
getCacheManagerInfo()
Set<String>
getCacheNames()
This method returns a collection of all cache names.ClassAllowList
getClassAllowList()
ClassAllowList
getClassWhiteList()
String
getClusterName()
Address
getCoordinator()
Configuration
getDefaultCacheConfiguration()
GlobalComponentRegistry
getGlobalComponentRegistry()
Health
getHealth()
Returns an entry point for a Health Check API.Set<Object>
getListeners()
Deprecated.List<Address>
getMembers()
CacheContainerStats
getStats()
Returns statistics for this cache managerComponentStatus
getStatus()
Subject
getSubject()
Transport
getTransport()
boolean
isCoordinator()
boolean
isDefaultRunning()
Tests whether the default cache is running.boolean
isRunning(String cacheName)
Tests whether a 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.CompletionStage<Void>
removeListenerAsync(Object listener)
Asynchronous version ofListenable.removeListener(Object)
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.EmbeddedCacheManager
withSubject(Subject subject)
-
-
-
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
Register a cache configuration in the cache manager. The configuration will be automatically used when creating a cache with the same name, unless it is a template. If it is a template and it contains wildcards (`*` or `?`), it will be automatically used when creating caches that match the template. In order to extend an existing configuration, useConfigurationBuilder.read(org.infinispan.configuration.cache.Configuration)
. The other way to define a cache configuration is declaratively, in the XML file passed in to the cache manager.- Specified by:
defineConfiguration
in interfaceEmbeddedCacheManager
- Parameters:
cacheName
- name of the cache configurationconfiguration
- the cache configuration- Returns:
- the cache configuration
-
defineConfiguration
public Configuration defineConfiguration(String cacheName, String templateCacheName, Configuration configurationOverride)
Description copied from interface:EmbeddedCacheManager
Defines a cache configuration by first reading the template configuration and then applying the override. The configuration will be automatically used when creating a cache with the same name, unless it is a template. If it is a template and it contains wildcards (`*` or `?`), it will be automatically used when creating caches that match the template. The other way to define a cache configuration is declaratively, in the XML file passed in to the cache manager. If templateName is null, this method works exactly likeEmbeddedCacheManager.defineConfiguration(String, Configuration)
.- Specified by:
defineConfiguration
in interfaceEmbeddedCacheManager
- Parameters:
cacheName
- name of cache whose configuration is being definedtemplateCacheName
- configuration to use as a templateconfigurationOverride
- configuration overrides on top of the template- Returns:
- the configuration
-
undefineConfiguration
public void undefineConfiguration(String configurationName)
Description copied from interface:EmbeddedCacheManager
Removes a configuration from the set of defined configurations. 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()
- Specified by:
getDefaultCacheConfiguration
in interfaceEmbeddedCacheManager
- Returns:
- the default cache's configuration, or
null
if there is no default cache.
-
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:BasicCacheContainer
This method returns a collection of all cache names. The configurations may have been defined via XML, in the programmatic configuration, or at runtime. Internal-only caches are not included.- Specified by:
getCacheNames
in interfaceBasicCacheContainer
- Returns:
- an immutable set of cache names registered in this cache manager.
-
getCacheConfigurationNames
public Set<String> getCacheConfigurationNames()
Description copied from interface:EmbeddedCacheManager
This method returns a collection of all cache configuration names. The configurations may have been defined via XML, programmatically viaConfigurationBuilderHolder
, or at runtime viaEmbeddedCacheManager.defineConfiguration(String, Configuration)
. Internal caches defined viaInternalCacheRegistry
are not included.- Specified by:
getCacheConfigurationNames
in interfaceEmbeddedCacheManager
- Returns:
- an immutable set of configuration names registered in 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
.
-
getCacheManagerInfo
public CacheManagerInfo getCacheManagerInfo()
- Specified by:
getCacheManagerInfo
in interfaceEmbeddedCacheManager
- Returns:
- an instance of
CacheManagerInfo
used to get basic info about the cache manager.
-
isRunning
public boolean isRunning(String cacheName)
Description copied from interface:EmbeddedCacheManager
Tests whether a cache is running.- Specified by:
isRunning
in interfaceEmbeddedCacheManager
- Parameters:
cacheName
- name of cache to test.- Returns:
- true if the 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 theEmbeddedCacheManager.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
- Parameters:
cacheName
- cache to check- 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 ClassAllowList getClassWhiteList()
- Specified by:
getClassWhiteList
in interfaceEmbeddedCacheManager
-
getClassAllowList
public ClassAllowList getClassAllowList()
- Specified by:
getClassAllowList
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 the 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
Similar toEmbeddedCacheManager.getCache(String)
, except if has the option to not create the cache if it is not already running.- Specified by:
getCache
in interfaceEmbeddedCacheManager
- Parameters:
cacheName
- name of cache to retrievecreateIfAbsent
- If true, this methods works just likeEmbeddedCacheManager.getCache(String)
. If false, return the already running cache or null.- Returns:
- null if the cache does not exist and createIfAbsent == false, otherwise 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:EmbeddedCacheManager
Retrieves the default cache associated with this cache container.- Specified by:
getCache
in interfaceBasicCacheContainer
- Specified by:
getCache
in interfaceCacheContainer
- Specified by:
getCache
in interfaceEmbeddedCacheManager
- Returns:
- the default cache.
-
getCache
public <K,V> Cache<K,V> getCache(String cacheName)
Description copied from interface:EmbeddedCacheManager
Retrieves a cache by name. If the cache has been previously created with the same name, the running cache instance is returned. Otherwise, this method attempts to create the cache first. When creating a new cache, this method requires a defined configuration that either has exactly the same name, or is a template with wildcards and matches the cache name.- Specified by:
getCache
in interfaceBasicCacheContainer
- Specified by:
getCache
in interfaceCacheContainer
- Specified by:
getCache
in interfaceEmbeddedCacheManager
- Parameters:
cacheName
- name of cache to retrieve- Returns:
- a cache instance identified by cacheName
-
start
public void start()
Description copied from interface:Lifecycle
Invoked on component start
-
stop
public void stop()
Description copied from interface:Lifecycle
Invoked on component stop
-
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
- listener to add, must not be null
-
addListenerAsync
public CompletionStage<Void> addListenerAsync(Object listener)
Description copied from interface:Listenable
Asynchronous version ofListenable.addListener(Object)
- Specified by:
addListenerAsync
in interfaceListenable
- Parameters:
listener
- listener to add, must not be null- Returns:
- CompletionStage that when complete the listener is fully installed
-
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.
-
removeListenerAsync
public CompletionStage<Void> removeListenerAsync(Object listener)
Description copied from interface:Listenable
Asynchronous version ofListenable.removeListener(Object)
- Specified by:
removeListenerAsync
in interfaceListenable
- Parameters:
listener
- listener to remove, must not be null- Returns:
- CompletionStage that when complete the listener is fully removed
-
getListeners
@Deprecated public Set<Object> getListeners()
Deprecated.- 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- 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
-
withSubject
public EmbeddedCacheManager withSubject(Subject subject)
- Specified by:
withSubject
in interfaceEmbeddedCacheManager
-
getSubject
public Subject getSubject()
- Specified by:
getSubject
in interfaceEmbeddedCacheManager
-
-