Class 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 FactoryBean for creating a native named Infinispan org.infinispan.Cache, delegating to a configurable org.infinispan.manager.EmbeddedCacheManager. If no cache name is explicitly set, this FactoryBean's beanName will be used instead.

    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 modes that control with what 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.

    Author:
    Olaf Bergner, Marius Bogoevici
    • Constructor Detail

      • InfinispanNamedEmbeddedCacheFactoryBean

        public InfinispanNamedEmbeddedCacheFactoryBean()
    • Method Detail

      • afterPropertiesSet

        public void afterPropertiesSet()
                                throws java.lang.Exception
        Specified by:
        afterPropertiesSet in interface org.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 interface org.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 interface org.springframework.beans.factory.FactoryBean<K>
        See Also:
        FactoryBean.getObjectType()
      • isSingleton

        public boolean isSingleton()
        Always returns true.
        Specified by:
        isSingleton in interface org.springframework.beans.factory.FactoryBean<K>
        Returns:
        Always true
        See Also:
        FactoryBean.isSingleton()
      • setBeanName

        public void setBeanName​(java.lang.String name)
        Specified by:
        setBeanName in interface org.springframework.beans.factory.BeanNameAware
        See Also:
        BeanNameAware.setBeanName(java.lang.String)
      • destroy

        public void destroy()
                     throws java.lang.Exception
        Shuts down the org.infinispan.Cache created by this FactoryBean.
        Specified by:
        destroy in interface org.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 org.infinispan.Cache to be created. If no explicit cacheName is set, this FactoryBean will use its beanName as the cacheName.

        Parameters:
        cacheName - The name of the org.infinispan.Cache to be created
      • setConfigurationTemplateMode

        public void setConfigurationTemplateMode​(java.lang.String configurationTemplateMode)
                                          throws java.lang.IllegalArgumentException
        Parameters:
        configurationTemplateMode -
        Throws:
        java.lang.IllegalArgumentException