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 nativeFactoryBean
named
Infinispan
, delegating to aorg.infinispan.Cache
configurable
. If no cache name is explicitly set, thisorg.infinispan.manager.EmbeddedCacheManager
FactoryBean
's
will be used instead.beanName
Beyond merely creating named
Cache
instances, thisFactoryBean
offers 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 whatmodes
Configuration
to start before further customizing it as described above:-
NONE
: Configuration starts with a newConfiguration
instance. Note that this mode may only be used if no named configuration having the same name as theCache
to be created already exists. It is therefore illegal to use this mode to create aCache
named, say, "cacheName" if the configuration file used to configure theEmbeddedCacheManager
contains a configuration section named "cacheName". -
DEFAULT
: Configuration starts with theEmbeddedCacheManager
's defaultConfiguration
instance, 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 theCache
to be created already exists. It is therefore illegal to use this mode to create aCache
named, say, "cacheName" if the configuration file used to configure theEmbeddedCacheManager
contains a configuration section named "cacheName". -
CUSTOM
: This is where a user will provide a custom-builtConfigurationBuilder
object which will be used to configure aCache
instance. If asetCacheName(String)
has already been called, then that name will be used. -
NAMED
: Configuration starts with theEmbeddedCacheManager
'sConfiguration
instance having the same name as theCache
to be created. For aCache
named, 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
Cache
thisFactoryBean
does also control thatCache
'lifecycle
by shutting it down when the enclosing Spring application context is closed. It is therefore advisable to always use thisFactoryBean
when 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 void
addCustomConfiguration(ConfigurationBuilder builder)
API to introduce a customisedConfigurationBuilder
that will override the default configurations which are already available on this class.void
afterPropertiesSet()
void
destroy()
Shuts down theorg.infinispan.Cache
created by thisFactoryBean
.Cache<K,V>
getObject()
java.lang.Class<? extends Cache>
getObjectType()
boolean
isSingleton()
Always returnstrue
.void
setBeanName(java.lang.String name)
void
setCacheName(java.lang.String cacheName)
Sets thename
of the
to be created.org.infinispan.Cache
void
setConfigurationTemplateMode(java.lang.String configurationTemplateMode)
void
setInfinispanEmbeddedCacheManager(EmbeddedCacheManager infinispanEmbeddedCacheManager)
Sets the
to be used for creating ourorg.infinispan.manager.EmbeddedCacheManager
instance.Cache
-
-
-
Method Detail
-
afterPropertiesSet
public void afterPropertiesSet() throws java.lang.Exception
- Specified by:
afterPropertiesSet
in 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:
getObject
in interfaceorg.springframework.beans.factory.FactoryBean<K>
- Throws:
java.lang.Exception
- See Also:
FactoryBean.getObject()
-
getObjectType
public java.lang.Class<? extends Cache> getObjectType()
- Specified by:
getObjectType
in interfaceorg.springframework.beans.factory.FactoryBean<K>
- See Also:
FactoryBean.getObjectType()
-
isSingleton
public boolean isSingleton()
Always returnstrue
.- Specified by:
isSingleton
in interfaceorg.springframework.beans.factory.FactoryBean<K>
- Returns:
- Always
true
- See Also:
FactoryBean.isSingleton()
-
setBeanName
public void setBeanName(java.lang.String name)
- Specified by:
setBeanName
in interfaceorg.springframework.beans.factory.BeanNameAware
- See Also:
BeanNameAware.setBeanName(String)
-
destroy
public void destroy() throws java.lang.Exception
Shuts down theorg.infinispan.Cache
created by thisFactoryBean
.- Specified by:
destroy
in 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
name
of the
to be created. If no explicitorg.infinispan.Cache
cacheName
is set, thisFactoryBean
will use its
as thebeanName
cacheName
.- Parameters:
cacheName
- Thename
of the
to be createdorg.infinispan.Cache
-
setInfinispanEmbeddedCacheManager
public void setInfinispanEmbeddedCacheManager(EmbeddedCacheManager infinispanEmbeddedCacheManager)
Sets the
to be used for creating ourorg.infinispan.manager.EmbeddedCacheManager
instance. Note that this is a mandatory property.Cache
- Parameters:
infinispanEmbeddedCacheManager
- The
to be used for creating ourorg.infinispan.manager.EmbeddedCacheManager
instanceCache
-
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 customisedConfigurationBuilder
that 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
-
-
-