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

org.infinispan.spring.embedded.provider.SpringEmbeddedCacheManager Maven / Gradle / Ivy

There is a newer version: 15.1.0.Dev03
Show newest version
package org.infinispan.spring.embedded.provider;

import java.util.Collection;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;

import org.infinispan.Cache;
import org.infinispan.manager.EmbeddedCacheManager;
import org.infinispan.spring.common.provider.SpringCache;
import org.springframework.cache.CacheManager;
import org.springframework.util.Assert;

/**
 * 

* A {@link CacheManager CacheManager} implementation that is * backed by an {@link 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; private final ConcurrentMap springCaches = new ConcurrentHashMap<>(); /** * @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 springCaches.computeIfAbsent(name, n -> { final Cache nativeCache = this.nativeCacheManager.getCache(n); return new SpringCache(nativeCache); }); } @Override public Collection getCacheNames() { return this.nativeCacheManager.getCacheNames(); } /** * Return the {@link EmbeddedCacheManager * org.infinispan.manager.EmbeddedCacheManager} that backs this * CacheManager. * * @return The {@link 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(); this.springCaches.clear(); } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy