本文整理匯總了Java中javax.cache.CacheManager.close方法的典型用法代碼示例。如果您正苦於以下問題:Java CacheManager.close方法的具體用法?Java CacheManager.close怎麽用?Java CacheManager.close使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類javax.cache.CacheManager
的用法示例。
在下文中一共展示了CacheManager.close方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: close
import javax.cache.CacheManager; //導入方法依賴的package包/類
@Override
public void close()
{
Iterator<Map.Entry<Pair<URI, ClassLoader>, CacheManager>> i = cacheManagers.entrySet().iterator();
while (i.hasNext())
{
Map.Entry<Pair<URI, ClassLoader>, CacheManager> entry = i.next();
CacheManager cm = entry.getValue();
if (cm != null && !cm.isClosed())
{
cm.close();
}
i.remove();
}
}
示例2: testCacheManagerWithCustomClassLoader
import javax.cache.CacheManager; //導入方法依賴的package包/類
@Test
public void testCacheManagerWithCustomClassLoader()
throws Exception
{
CacheManager cacheManager1 = cachingProvider.getCacheManager();
CacheManager cacheManager2 = cachingProvider.getCacheManager(null, ClassLoader.getSystemClassLoader());
assertNotNull(cacheManager1);
assertNotNull(cacheManager2);
assertNotEquals(cacheManager1, cacheManager2);
cacheManager1.close();
cacheManager2.close();
assertTrue(cacheManager1.isClosed());
assertTrue(cacheManager2.isClosed());
}
示例3: testCacheManagerWithCustomProperties
import javax.cache.CacheManager; //導入方法依賴的package包/類
@Test
public void testCacheManagerWithCustomProperties()
throws Exception
{
Properties properties = new Properties();
properties.setProperty("concurrencyLevel", "1");
properties.setProperty("initialCapacity", "16");
CacheManager cacheManager1 = cachingProvider.getCacheManager();
CacheManager cacheManager2 = cachingProvider.getCacheManager(null, null, properties);
assertNotNull(cacheManager1);
assertNotNull(cacheManager2);
// properties do not form part of the identity of the CacheManager
assertEquals(cacheManager1, cacheManager2);
cacheManager1.close();
cacheManager2.close();
assertTrue(cacheManager1.isClosed());
assertTrue(cacheManager2.isClosed());
}
示例4: testCacheManagerWithCustomClassLoaderAndProperties
import javax.cache.CacheManager; //導入方法依賴的package包/類
@Test
public void testCacheManagerWithCustomClassLoaderAndProperties()
throws Exception
{
Properties properties = new Properties();
properties.setProperty("concurrencyLevel", "1");
properties.setProperty("initialCapacity", "16");
CacheManager cacheManager1 = cachingProvider.getCacheManager();
CacheManager cacheManager2 =
cachingProvider.getCacheManager(null, ClassLoader.getSystemClassLoader(), properties);
assertNotNull(cacheManager1);
assertNotNull(cacheManager2);
assertNotEquals(cacheManager1, cacheManager2);
cacheManager1.close();
cacheManager2.close();
assertTrue(cacheManager1.isClosed());
assertTrue(cacheManager2.isClosed());
}
示例5: close
import javax.cache.CacheManager; //導入方法依賴的package包/類
@Override
public void close(ClassLoader classLoader)
{
// System.out.println("CacheManager.close() cl=" + classLoader);
synchronized (cacheManagersLock)
{
for( Iterator<CacheManager> it = cacheManagers.iterator(); it.hasNext(); )
{
CacheManager cacheManager = it.next();
if (cacheManager.getClassLoader().equals(classLoader))
{
cacheManager.close();
// Hint: It may have happened, that cacheManager.close() already removed itrslef cacheManagers.
// In that case the next line is a NOP. It is important though, that the underlying Set is a Concurrent Set.
it.remove();
}
}
}
}
示例6: close
import javax.cache.CacheManager; //導入方法依賴的package包/類
/**
* {@inheritDoc}
*/
@Override
public synchronized void close(URI uri, ClassLoader classLoader) {
URI managerURI = uri == null ? getDefaultURI() : uri;
ClassLoader managerClassLoader = classLoader == null ? getDefaultClassLoader() : classLoader;
HashMap<URI, BlazingCacheManager> cacheManagersByURI = cacheManagersByClassLoader.get(managerClassLoader);
if (cacheManagersByURI != null) {
CacheManager cacheManager = cacheManagersByURI.remove(managerURI);
if (cacheManager != null) {
cacheManager.close();
}
if (cacheManagersByURI.size() == 0) {
cacheManagersByClassLoader.remove(managerClassLoader);
}
}
}
示例7: testReuseCacheManagerGetCache
import javax.cache.CacheManager; //導入方法依賴的package包/類
@Test
public void testReuseCacheManagerGetCache() throws Exception {
CachingProvider provider = Caching.getCachingProvider();
URI uri = provider.getDefaultURI();
CacheManager cacheManager = provider.getCacheManager(uri, provider.getDefaultClassLoader());
assertFalse(cacheManager.isClosed());
cacheManager.close();
assertTrue(cacheManager.isClosed());
try {
cacheManager.getCache("nonExistent", null, null);
fail();
} catch (IllegalStateException e) {
//expected
}
CacheManager otherCacheManager = provider.getCacheManager(uri, provider.getDefaultClassLoader());
assertFalse(otherCacheManager.isClosed());
assertNotSame(cacheManager, otherCacheManager);
}
示例8: close
import javax.cache.CacheManager; //導入方法依賴的package包/類
@Override
public void close(ClassLoader classLoader) {
Map<URI, CacheManager> uri2manager = managers.remove(classLoader);
if (uri2manager != null) {
for (CacheManager manager : uri2manager.values()) {
manager.close();
}
}
}
示例9: testCacheManager
import javax.cache.CacheManager; //導入方法依賴的package包/類
@Test
public void testCacheManager()
throws Exception
{
CacheManager cacheManager = cachingProvider.getCacheManager();
assertEquals(cacheManager, cachingProvider.getCacheManager());
cacheManager.close();
assertTrue(cacheManager.isClosed());
}
示例10: testCacheManagerWithDefaultProperties
import javax.cache.CacheManager; //導入方法依賴的package包/類
@Test
public void testCacheManagerWithDefaultProperties()
throws Exception
{
CacheManager cacheManager = cachingProvider.getCacheManager();
assertNotNull(cacheManager);
MutableConfiguration<Long, String> configuration =
new MutableConfiguration<Long, String>().setStoreByValue(false);
Cache<Long, String> cache = cacheManager.createCache("maximumSizeCacheTest", configuration);
long maximumSize = Long.valueOf(cacheManager.getProperties().getProperty("maximumSize"));
assertNotEquals(0, maximumSize);
for (long l = 1; l <= (maximumSize * 10); l++)
{
cache.put(l, "VALUE-" + l);
if ((l % maximumSize) == 0)
{
assertTrue(cache.unwrap(GuavaCache.class).size() <= maximumSize);
}
}
assertTrue(cache.unwrap(GuavaCache.class).size() <= maximumSize);
cacheManager.close();
}
示例11: testClosedCacheManager
import javax.cache.CacheManager; //導入方法依賴的package包/類
@Test(expected = IllegalStateException.class)
public void testClosedCacheManager()
throws Exception
{
CacheManager cacheManager = cachingProvider.getCacheManager();
assertNotNull(cacheManager);
cacheManager.close();
cacheManager.getCacheNames();
}
示例12: testReuseCacheManager
import javax.cache.CacheManager; //導入方法依賴的package包/類
@Test // org.jsr107.tck.CacheManagerTest.testReuseCacheManager
public void testReuseCacheManager()
throws Exception
{
CachingProvider provider = Caching.getCachingProvider();
URI uri = provider.getDefaultURI();
CacheManager cacheManager = provider.getCacheManager(uri, provider.getDefaultClassLoader());
assertFalse(cacheManager.isClosed());
cacheManager.close();
assertTrue(cacheManager.isClosed());
try
{
cacheManager.createCache("Dog", null);
fail();
}
catch (IllegalStateException e)
{
//expected
}
CacheManager otherCacheManager = provider.getCacheManager(uri, provider.getDefaultClassLoader());
assertFalse(otherCacheManager.isClosed());
assertNotSame(cacheManager, otherCacheManager);
}
示例13: main
import javax.cache.CacheManager; //導入方法依賴的package包/類
public static void main(String[] args) {
// Construct a simple local cache manager with default configuration
CachingProvider jcacheProvider = Caching.getCachingProvider();
CacheManager cacheManager = jcacheProvider.getCacheManager();
MutableConfiguration<String, String> configuration = new MutableConfiguration<>();
configuration.setTypes(String.class, String.class);
// create a cache using the supplied configuration
Cache<String, String> cache = cacheManager.createCache("myCache", configuration);
// Store a value
cache.put("key", "value");
// Retrieve the value and print it out
System.out.printf("key = %s\n", cache.get("key"));
// Stop the cache manager and release all resources
cacheManager.close();
}
示例14: removeCache_Stopped
import javax.cache.CacheManager; //導入方法依賴的package包/類
@Test
public void removeCache_Stopped() {
CacheManager cacheManager = getCacheManager();
cacheManager.close();
try {
cacheManager.destroyCache("c1");
fail();
} catch (IllegalStateException e) {
//ok
}
}
示例15: close_cachesClosed
import javax.cache.CacheManager; //導入方法依賴的package包/類
@Test
public void close_cachesClosed() {
CacheManager cacheManager = getCacheManager();
cacheManager.createCache("c1", new MutableConfiguration());
Cache cache1 = cacheManager.getCache("c1");
cacheManager.createCache("c2", new MutableConfiguration());
Cache cache2 = cacheManager.getCache("c2");
cacheManager.close();
ensureClosed(cache1);
ensureClosed(cache2);
}