All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.infinispan.spring.provider.SpringRemoteCacheManagerFactoryBean Maven / Gradle / Ivy

Go to download

The Infinispan Spring Integration project provides Spring integration for Infinispan, a high performance distributed cache. Its primary features are * An implementation of org.springframework.cache.CacheManager, Spring's central caching abstraction, backed by Infinispan's EmbeddedCacheManager. To be used if your Spring-powered application and Infinispan are colocated, i.e. running within the same VM. * An implementation of org.springframework.cache.CacheManager backed by Infinispan's RemoteCacheManager. To bes used if your Spring-powered application accesses Infinispan remotely, i.e. over the network. * An implementation of org.springframework.cache.CacheManager backed by a CacheContainer reference. To be used if your Spring- powered application needs access to a CacheContainer defined outside the application (e.g. retrieved from JNDI) * Spring namespace support allowing shortcut definitions for all the components above In addition, Infinispan Spring Integration offers various FactoryBeans for facilitating creation of Infinispan core classes - Cache, CacheManager, ... - within a Spring context.

There is a newer version: 8.1.0.Alpha2
Show newest version
package org.infinispan.spring.provider;

import org.infinispan.client.hotrod.RemoteCacheManager;
import org.infinispan.spring.AbstractRemoteCacheManagerFactory;
import org.springframework.beans.factory.DisposableBean;
import org.springframework.beans.factory.FactoryBean;
import org.springframework.beans.factory.InitializingBean;

import java.util.Properties;

/**
 * 

* A {@link org.springframework.beans.factory.FactoryBean FactoryBean} for creating an * {@link org.infinispan.spring.provider.SpringRemoteCacheManager * SpringRemoteCacheManager} instance. *

* Configuration
*

* A SpringRemoteCacheManager is configured through a {@link java.util.Properties * Properties} object. For an exhaustive list of valid properties to be used see * RemoteCacheManager's {@link org.infinispan.client.hotrod.RemoteCacheManager * javadocs}. This FactoryBean provides means to either * {@link #setConfigurationProperties(Properties) inject} a user-defined Properties * instance or to * {@link #setConfigurationPropertiesFileLocation(org.springframework.core.io.Resource) set} the * location of a properties file to load those properties from. Note that it is illegal to * use both mechanisms simultaneously. *

*

* Alternatively or in combination with * {@link #setConfigurationPropertiesFileLocation(org.springframework.core.io.Resource) setting} the * location of a Properties file to load the configuration from, this * FactoryBean provides (typed) setters for all configuration settings. Settings thus * defined take precedence over those defined in the injected Properties instance. This * flexibility enables users to use e.g. a company-wide Properties file containing * default settings while simultaneously overriding select settings whenever special requirements * warrant this.
* Note that it is illegal to use setters in conjunction with * {@link #setConfigurationProperties(Properties) injecting} a Properties instance. *

*

* In addition to creating a SpringRemoteCacheManager this FactoryBean * does also control that SpringRemoteCacheManager's lifecycle by shutting it down when * the enclosing Spring application context is closed. It is therefore advisable to always * use this FactoryBean when creating an SpringRemoteCacheManager. *

* * @author Olaf Bergner * * @see org.infinispan.client.hotrod.RemoteCacheManager * @see #destroy() */ public class SpringRemoteCacheManagerFactoryBean extends AbstractRemoteCacheManagerFactory implements FactoryBean, InitializingBean, DisposableBean { private SpringRemoteCacheManager springRemoteCacheManager; // ------------------------------------------------------------------------ // org.springframework.beans.factory.InitializingBean // ------------------------------------------------------------------------ /** * @see org.springframework.beans.factory.InitializingBean#afterPropertiesSet() */ @Override public void afterPropertiesSet() throws Exception { assertCorrectlyConfigured(); this.logger.info("Creating new instance of RemoteCacheManager ..."); final Properties configurationPropertiesToUse = configurationProperties(); final RemoteCacheManager nativeRemoteCacheManager = new RemoteCacheManager( configurationPropertiesToUse, this.startAutomatically); this.springRemoteCacheManager = new SpringRemoteCacheManager(nativeRemoteCacheManager); this.logger.info("Finished creating new instance of RemoteCacheManager"); } // ------------------------------------------------------------------------ // org.springframework.beans.factory.FactoryBean // ------------------------------------------------------------------------ /** * @see org.springframework.beans.factory.FactoryBean#getObject() */ @Override public SpringRemoteCacheManager getObject() throws Exception { return this.springRemoteCacheManager; } /** * @see org.springframework.beans.factory.FactoryBean#getObjectType() */ @Override public Class getObjectType() { return this.springRemoteCacheManager != null ? this.springRemoteCacheManager.getClass() : SpringRemoteCacheManager.class; } /** * Always return true. * * @see org.springframework.beans.factory.FactoryBean#isSingleton() */ @Override public boolean isSingleton() { return true; } // ------------------------------------------------------------------------ // org.springframework.beans.factory.DisposableBean // ------------------------------------------------------------------------ /** * {@link org.infinispan.client.hotrod.RemoteCacheManager#stop() stop} the * RemoteCacheManager created by this factory. * * @see org.springframework.beans.factory.DisposableBean#destroy() */ @Override public void destroy() throws Exception { // Being paranoid if (this.springRemoteCacheManager != null) { this.springRemoteCacheManager.stop(); } } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy