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

org.infinispan.spring.provider.SpringEmbeddedCacheManagerFactoryBean 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.manager.EmbeddedCacheManager;
import org.infinispan.spring.AbstractEmbeddedCacheManagerFactory;
import org.springframework.beans.factory.DisposableBean;
import org.springframework.beans.factory.FactoryBean;
import org.springframework.beans.factory.InitializingBean;

/**
 * 

* A {@link org.springframework.beans.factory.FactoryBean FactoryBean} for creating an * {@link org.infinispan.spring.provider.SpringEmbeddedCacheManager * SpringEmbeddedCacheManager} instance. The location of the Infinispan configuration * file used to provide the default {@link org.infinispan.configuration.cache.Configuration configuration} for * the EmbeddedCacheManager instance created by this FactoryBean is * {@link #setConfigurationFileLocation(org.springframework.core.io.Resource) configurable}. *

*

* If no configuration file location is set the SpringEmbeddedCacheManager instance * created by this FactoryBean will use Infinispan's default settings. See Infinispan's * documentation for what those default settings * are. *

*

* A user may further customize the SpringEmbeddedCacheManager's configuration using * explicit setters on this FactoryBean. The properties thus defined will be applied * either to the configuration loaded from Infinispan's configuration file in case one has been * specified, or to a configuration initialized with Infinispan's default settings. Either way, the * net effect is that explicitly set configuration properties take precedence over both those loaded * from a configuration file as well as INFINISPAN's default settings. *

*

* In addition to creating an SpringEmbeddedCacheManager this FactoryBean * does also control that SpringEmbeddedCacheManager's * {@link org.infinispan.lifecycle.Lifecycle 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 SpringEmbeddedCacheManager. *

* * @author Olaf Bergner * * @see #setConfigurationFileLocation(org.springframework.core.io.Resource) * @see #destroy() * @see org.infinispan.spring.provider.SpringEmbeddedCacheManager * @see org.infinispan.manager.EmbeddedCacheManager * @see org.infinispan.configuration.cache.Configuration * */ public class SpringEmbeddedCacheManagerFactoryBean extends AbstractEmbeddedCacheManagerFactory implements FactoryBean, InitializingBean, DisposableBean { private SpringEmbeddedCacheManager cacheManager; // ------------------------------------------------------------------------ // org.springframework.beans.factory.InitializingBean // ------------------------------------------------------------------------ /** * @see org.springframework.beans.factory.InitializingBean#afterPropertiesSet() */ @Override public void afterPropertiesSet() throws Exception { logger.info("Initializing SpringEmbeddedCacheManager instance ..."); final EmbeddedCacheManager nativeEmbeddedCacheManager = createBackingEmbeddedCacheManager(); this.cacheManager = new SpringEmbeddedCacheManager(nativeEmbeddedCacheManager); logger.info("Successfully initialized SpringEmbeddedCacheManager instance [" + this.cacheManager + "]"); } // ------------------------------------------------------------------------ // org.springframework.beans.factory.FactoryBean // ------------------------------------------------------------------------ /** * @see org.springframework.beans.factory.FactoryBean#getObject() */ @Override public SpringEmbeddedCacheManager getObject() throws Exception { return this.cacheManager; } /** * @see org.springframework.beans.factory.FactoryBean#getObjectType() */ @Override public Class getObjectType() { return this.cacheManager != null ? this.cacheManager.getClass() : SpringEmbeddedCacheManager.class; } /** * Always returns true. * * @return Always true * * @see org.springframework.beans.factory.FactoryBean#isSingleton() */ @Override public boolean isSingleton() { return true; } // ------------------------------------------------------------------------ // org.springframework.beans.factory.DisposableBean // ------------------------------------------------------------------------ /** * Shuts down the SpringEmbeddedCacheManager instance created by this * FactoryBean. * * @see org.springframework.beans.factory.DisposableBean#destroy() * @see org.infinispan.spring.provider.SpringEmbeddedCacheManager#stop() */ @Override public void destroy() throws Exception { // Probably being paranoid here ... if (this.cacheManager != null) { this.cacheManager.stop(); } } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy