org.infinispan.spring.provider.SpringEmbeddedCacheManager 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.
package org.infinispan.spring.provider;
import org.infinispan.manager.EmbeddedCacheManager;
import org.springframework.cache.CacheManager;
import org.springframework.util.Assert;
import java.util.Collection;
/**
*
* A {@link org.springframework.cache.CacheManager CacheManager
} implementation that is
* backed by an {@link org.infinispan.manager.EmbeddedCacheManager
* Infinispan EmbeddedCacheManager
} instance.
*
*
* Note that this CacheManager
does support adding new
* {@link org.infinispan.Cache Caches
} at runtime, i.e. Caches
added
* programmatically to the backing EmbeddedCacheManager
after this
* CacheManager
has been constructed will be seen by this CacheManager
.
*
*
* @author Olaf Bergner
* @author Marius Bogoevici
*
*/
public class SpringEmbeddedCacheManager implements CacheManager {
private final EmbeddedCacheManager nativeCacheManager;
/**
* @param nativeCacheManager Underlying cache manager
*/
public SpringEmbeddedCacheManager(final EmbeddedCacheManager nativeCacheManager) {
Assert.notNull(nativeCacheManager,
"A non-null instance of EmbeddedCacheManager needs to be supplied");
this.nativeCacheManager = nativeCacheManager;
}
@Override
public SpringCache getCache(final String name) {
return new SpringCache(this.nativeCacheManager.getCache(name));
}
@Override
public Collection getCacheNames() {
return this.nativeCacheManager.getCacheNames();
}
/**
* Return the {@link org.infinispan.manager.EmbeddedCacheManager
* org.infinispan.manager.EmbeddedCacheManager
} that backs this
* CacheManager
.
*
* @return The {@link org.infinispan.manager.EmbeddedCacheManager
* org.infinispan.manager.EmbeddedCacheManager
} that backs this
* CacheManager
*/
public EmbeddedCacheManager getNativeCacheManager() {
return this.nativeCacheManager;
}
/**
* Stop the {@link EmbeddedCacheManager EmbeddedCacheManager
} this
* CacheManager
delegates to.
*/
public void stop() {
this.nativeCacheManager.stop();
}
}