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

org.infinispan.spring.support.InfinispanDefaultCacheFactoryBean 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.support;

import org.infinispan.Cache;
import org.infinispan.manager.CacheContainer;
import org.infinispan.util.logging.Log;
import org.infinispan.util.logging.LogFactory;
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 a * native default Infinispan {@link org.infinispan.Cache org.infinispan.Cache} * , delegating to a {@link #setInfinispanCacheContainer(CacheContainer) configurable} * {@link org.infinispan.manager.CacheContainer org.infinispan.manager.CacheContainer}. * A default Cache is a Cache that uses its CacheContainer's * default settings. This is contrary to a named Cache where select settings * from a CacheContainer's default configuration may be overridden with settings * specific to that Cache. *

*

* In addition to creating a Cache this FactoryBean does also control that * Cache's {@link org.infinispan.commons.api.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 a Cache. *

* * @author Olaf Bergner * */ public class InfinispanDefaultCacheFactoryBean implements FactoryBean>, InitializingBean, DisposableBean { protected final Log logger = LogFactory.getLog(getClass()); private CacheContainer infinispanCacheContainer; private Cache infinispanCache; /** *

* Sets the {@link org.infinispan.manager.CacheContainer * org.infinispan.manager.CacheContainer} to be used for creating our * {@link org.infinispan.Cache Cache} instance. Note that this is a * mandatory property. *

* * @param infinispanCacheContainer * The {@link org.infinispan.manager.CacheContainer * org.infinispan.manager.CacheContainer} to be used for creating our * {@link org.infinispan.Cache Cache} instance */ public void setInfinispanCacheContainer(final CacheContainer infinispanCacheContainer) { this.infinispanCacheContainer = infinispanCacheContainer; } /** * @see org.springframework.beans.factory.InitializingBean#afterPropertiesSet() */ @Override public void afterPropertiesSet() throws Exception { if (this.infinispanCacheContainer == null) { throw new IllegalStateException("No Infinispan CacheContainer has been set"); } this.logger.info("Initializing named Infinispan cache ..."); this.infinispanCache = this.infinispanCacheContainer.getCache(); this.logger.info("New Infinispan cache [" + this.infinispanCache + "] initialized"); } /** * @see org.springframework.beans.factory.FactoryBean#getObject() */ @Override public Cache getObject() throws Exception { return this.infinispanCache; } /** * @see org.springframework.beans.factory.FactoryBean#getObjectType() */ @Override public Class getObjectType() { return this.infinispanCache != null ? this.infinispanCache.getClass() : Cache.class; } /** * Always returns true. * * @return Always true * * @see org.springframework.beans.factory.FactoryBean#isSingleton() */ @Override public boolean isSingleton() { return true; } /** * Shuts down the org.infinispan.Cache created by this FactoryBean. * * @see org.springframework.beans.factory.DisposableBean#destroy() * @see org.infinispan.Cache#stop() */ @Override public void destroy() throws Exception { // Probably being paranoid here ... if (this.infinispanCache != null) { this.infinispanCache.stop(); } } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy