public class InfinispanNamedEmbeddedCacheFactoryBean<K,V> extends 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
native FactoryBean
named
Infinispan
, delegating to a
org.infinispan.Cache
configurable
. If no cache name is explicitly set,
this org.infinispan.manager.EmbeddedCacheManager
FactoryBean
's
will be used
instead.
beanName
Beyond merely creating named Cache
instances, this FactoryBean
offers
great flexibility in configuring those Caches
. It has setters for all non-global
configuration settings, i.e. all settings that are specific to a single Cache
. The
configuration settings thus defined override those settings obtained from the
EmbeddedCacheManager
.
There are different configuration
that control with what modes
Configuration
to start before further
customizing it as described above:
NONE
: Configuration starts with a new Configuration
instance.
Note that this mode may only be used if no named configuration having the same name as the Cache
to be created already exists. It is therefore illegal to use this mode to create a Cache
named, say,
"cacheName" if the configuration file used to configure the
EmbeddedCacheManager
contains a configuration section named
"cacheName".DEFAULT
: Configuration starts with the EmbeddedCacheManager
's
default Configuration
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 the Cache
to be created already exists. It is therefore illegal to use
this mode to create a Cache
named, say, "cacheName" if the configuration file used
to configure the EmbeddedCacheManager
contains a configuration section named
"cacheName".CUSTOM
: This is where a user will provide a custom-built ConfigurationBuilder
object which will be used to configure a Cache
instance. If a setCacheName(String)
has
already been called, then that name will be used.
NAMED
: Configuration starts with the EmbeddedCacheManager
's
Configuration
instance having the same name as the Cache
to be
created. For a Cache
named, say, "cacheName" this is the configuration
section named "cacheName" as defined in the EmbeddedCacheManager
's
configuration file. Note that this mode is only useful if such a named configuration section does indeed exist.
Otherwise, it is equivalent to using
DEFAULT
.
In addition to creating a named Cache
this FactoryBean
does also
control that Cache
' lifecycle
by shutting
it down when the enclosing Spring application context is closed. It is therefore advisable to
always use this FactoryBean
when creating a named Cache
.
Constructor and Description |
---|
InfinispanNamedEmbeddedCacheFactoryBean() |
Modifier and Type | Method and Description |
---|---|
void |
addCustomConfiguration(ConfigurationBuilder builder)
API to introduce a customised
ConfigurationBuilder that will override the default configurations
which are already available on this class. |
void |
afterPropertiesSet() |
void |
destroy()
Shuts down the
org.infinispan.Cache created by this FactoryBean . |
Cache<K,V> |
getObject() |
Class<? extends Cache> |
getObjectType() |
boolean |
isSingleton()
Always returns
true . |
void |
setBeanName(String name) |
void |
setCacheName(String cacheName)
Sets the
name of the to be created. |
void |
setConfigurationTemplateMode(String configurationTemplateMode) |
void |
setInfinispanEmbeddedCacheManager(EmbeddedCacheManager infinispanEmbeddedCacheManager)
Sets the
to be used for creating our
instance. |
public InfinispanNamedEmbeddedCacheFactoryBean()
public void afterPropertiesSet() throws Exception
afterPropertiesSet
in interface org.springframework.beans.factory.InitializingBean
Exception
InitializingBean.afterPropertiesSet()
public boolean isSingleton()
true
.public void setBeanName(String name)
setBeanName
in interface org.springframework.beans.factory.BeanNameAware
BeanNameAware.setBeanName(java.lang.String)
public void destroy() throws Exception
org.infinispan.Cache
created by this FactoryBean
.destroy
in interface org.springframework.beans.factory.DisposableBean
Exception
DisposableBean.destroy()
,
Lifecycle.stop()
public void setCacheName(String cacheName)
Sets the name
of the
to be created. If no explicit org.infinispan.Cache
cacheName
is
set, this FactoryBean
will use its
as the beanName
cacheName
.
cacheName
- The name
of the org.infinispan.Cache
to be createdpublic void setInfinispanEmbeddedCacheManager(EmbeddedCacheManager infinispanEmbeddedCacheManager)
Sets the
to be used for creating our
org.infinispan.manager.EmbeddedCacheManager
instance. Note that this is a
mandatory property.
Cache
infinispanEmbeddedCacheManager
- The org.infinispan.manager.EmbeddedCacheManager
to be used for creating
our Cache
instancepublic void setConfigurationTemplateMode(String configurationTemplateMode) throws IllegalArgumentException
configurationTemplateMode
- IllegalArgumentException
public void addCustomConfiguration(ConfigurationBuilder builder)
ConfigurationBuilder
that will override the default configurations
which are already available on this class. This can only be used if setConfigurationTemplateMode(String)
has been set to CUSTOM
.builder
- Copyright © 2014 JBoss, a division of Red Hat. All Rights Reserved.