Class InfinispanNamedEmbeddedCacheFactoryBean<K,V>
- java.lang.Object
-
- org.infinispan.spring.embedded.support.InfinispanNamedEmbeddedCacheFactoryBean<K,V>
-
- All Implemented Interfaces:
org.springframework.beans.factory.Aware,org.springframework.beans.factory.BeanNameAware,org.springframework.beans.factory.DisposableBean,org.springframework.beans.factory.FactoryBean<Cache<K,V>>,org.springframework.beans.factory.InitializingBean
public class InfinispanNamedEmbeddedCacheFactoryBean<K,V> extends java.lang.Object implements org.springframework.beans.factory.FactoryBean<Cache<K,V>>, org.springframework.beans.factory.BeanNameAware, org.springframework.beans.factory.InitializingBean, org.springframework.beans.factory.DisposableBean
A
for creating a nativeFactoryBeannamedInfinispan, delegating to aorg.infinispan.Cacheconfigurable. If no cache name is explicitly set, thisorg.infinispan.manager.EmbeddedCacheManagerFactoryBean'swill be used instead.beanNameBeyond merely creating named
Cacheinstances, thisFactoryBeanoffers great flexibility in configuring thoseCaches. It has setters for all non-global configuration settings, i.e. all settings that are specific to a singleCache. The configuration settings thus defined override those settings obtained from theEmbeddedCacheManager.There are different configuration
that control with whatmodesConfigurationto start before further customizing it as described above:-
NONE: Configuration starts with a newConfigurationinstance. Note that this mode may only be used if no named configuration having the same name as theCacheto be created already exists. It is therefore illegal to use this mode to create aCachenamed, say, "cacheName" if the configuration file used to configure theEmbeddedCacheManagercontains a configuration section named "cacheName". -
DEFAULT: Configuration starts with theEmbeddedCacheManager's defaultConfigurationinstance, i.e. the configuration settings defined in its configuration file's default section. Note that this mode may only be used if no named configuration having the same name as theCacheto be created already exists. It is therefore illegal to use this mode to create aCachenamed, say, "cacheName" if the configuration file used to configure theEmbeddedCacheManagercontains a configuration section named "cacheName". -
CUSTOM: This is where a user will provide a custom-builtConfigurationBuilderobject which will be used to configure aCacheinstance. If asetCacheName(String)has already been called, then that name will be used. -
NAMED: Configuration starts with theEmbeddedCacheManager'sConfigurationinstance having the same name as theCacheto be created. For aCachenamed, say, "cacheName" this is the configuration section named "cacheName" as defined in theEmbeddedCacheManager's configuration file. Note that this mode is only useful if such a named configuration section does indeed exist. Otherwise, it is equivalent to usingDEFAULT.
In addition to creating a named
CachethisFactoryBeandoes also control thatCache'lifecycleby shutting it down when the enclosing Spring application context is closed. It is therefore advisable to always use thisFactoryBeanwhen creating a namedCache.- Author:
- Olaf Bergner, Marius Bogoevici
-
-
Constructor Summary
Constructors Constructor Description InfinispanNamedEmbeddedCacheFactoryBean()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddCustomConfiguration(ConfigurationBuilder builder)API to introduce a customisedConfigurationBuilderthat will override the default configurations which are already available on this class.voidafterPropertiesSet()voiddestroy()Shuts down theorg.infinispan.Cachecreated by thisFactoryBean.Cache<K,V>getObject()java.lang.Class<? extends Cache>getObjectType()booleanisSingleton()Always returnstrue.voidsetBeanName(java.lang.String name)voidsetCacheName(java.lang.String cacheName)Sets thenameof theto be created.org.infinispan.CachevoidsetConfigurationTemplateMode(java.lang.String configurationTemplateMode)voidsetInfinispanEmbeddedCacheManager(EmbeddedCacheManager infinispanEmbeddedCacheManager)Sets theto be used for creating ourorg.infinispan.manager.EmbeddedCacheManagerinstance.Cache
-
-
-
Method Detail
-
afterPropertiesSet
public void afterPropertiesSet() throws java.lang.Exception- Specified by:
afterPropertiesSetin interfaceorg.springframework.beans.factory.InitializingBean- Throws:
java.lang.Exception- See Also:
InitializingBean.afterPropertiesSet()
-
getObject
public Cache<K,V> getObject() throws java.lang.Exception
- Specified by:
getObjectin interfaceorg.springframework.beans.factory.FactoryBean<K>- Throws:
java.lang.Exception- See Also:
FactoryBean.getObject()
-
getObjectType
public java.lang.Class<? extends Cache> getObjectType()
- Specified by:
getObjectTypein interfaceorg.springframework.beans.factory.FactoryBean<K>- See Also:
FactoryBean.getObjectType()
-
isSingleton
public boolean isSingleton()
Always returnstrue.- Specified by:
isSingletonin interfaceorg.springframework.beans.factory.FactoryBean<K>- Returns:
- Always
true - See Also:
FactoryBean.isSingleton()
-
setBeanName
public void setBeanName(java.lang.String name)
- Specified by:
setBeanNamein interfaceorg.springframework.beans.factory.BeanNameAware- See Also:
BeanNameAware.setBeanName(String)
-
destroy
public void destroy() throws java.lang.ExceptionShuts down theorg.infinispan.Cachecreated by thisFactoryBean.- Specified by:
destroyin interfaceorg.springframework.beans.factory.DisposableBean- Throws:
java.lang.Exception- See Also:
DisposableBean.destroy(),Cache.stop()
-
setCacheName
public void setCacheName(java.lang.String cacheName)
Sets the
nameof theto be created. If no explicitorg.infinispan.CachecacheNameis set, thisFactoryBeanwill use itsas thebeanNamecacheName.- Parameters:
cacheName- Thenameof theto be createdorg.infinispan.Cache
-
setInfinispanEmbeddedCacheManager
public void setInfinispanEmbeddedCacheManager(EmbeddedCacheManager infinispanEmbeddedCacheManager)
Sets the
to be used for creating ourorg.infinispan.manager.EmbeddedCacheManagerinstance. Note that this is a mandatory property.Cache- Parameters:
infinispanEmbeddedCacheManager- Theto be used for creating ourorg.infinispan.manager.EmbeddedCacheManagerinstanceCache
-
setConfigurationTemplateMode
public void setConfigurationTemplateMode(java.lang.String configurationTemplateMode) throws java.lang.IllegalArgumentException- Parameters:
configurationTemplateMode-- Throws:
java.lang.IllegalArgumentException
-
addCustomConfiguration
public void addCustomConfiguration(ConfigurationBuilder builder)
API to introduce a customisedConfigurationBuilderthat will override the default configurations which are already available on this class. This can only be used ifsetConfigurationTemplateMode(String)has been set toCUSTOM.- Parameters:
builder-
-
-