/** * {@inheritDoc} */ @Override public void close() { cache.close(); if (!getRuntimeConfiguration().getResourcePools().getPoolForResource(ResourceType.Core.DISK).isPersistent()) { try { diskPersistenceService.destroy(id); } catch (CachePersistenceException e) { logger.debug("Unable to clear persistence space for user managed cache {}", id, e); } } }
/** * Closes and removes a cache, by alias, from this cache manager. * * @param alias the alias of the cache to remove * @param removeFromConfig if {@code true}, the cache configuration is altered to remove the cache */ private void removeCache(final String alias, final boolean removeFromConfig) { statusTransitioner.checkAvailable(); final CacheHolder cacheHolder = caches.remove(alias); if(cacheHolder != null) { final InternalCache<?, ?> ehcache = cacheHolder.retrieve(cacheHolder.keyType, cacheHolder.valueType); if (ehcache != null) { if (removeFromConfig) { configuration.removeCacheConfiguration(alias); } if (!statusTransitioner.isTransitioning()) { for (CacheManagerListener listener : listeners) { listener.cacheRemoved(alias, ehcache); } } ehcache.close(); closeEhcache(alias, ehcache); } LOGGER.info("Cache '{}' removed from {}.", alias, simpleName); } }
private void assertCacheDelegatesLifecycleCallsToStore(InternalCache cache) throws Exception { final LifeCycled mock = mock(LifeCycled.class); cache.addHook(mock); cache.init(); verify(mock).init(); cache.close(); verify(mock).close(); }
@Test public void testDelegatesLifecycleCallsToStore() throws Exception { InternalCache ehcache = getCache(mock(Store.class)); final LifeCycled mock = mock(LifeCycled.class); ehcache.addHook(mock); ehcache.init(); verify(mock).init(); ehcache.close(); verify(mock).close(); }
@Test public void testFailingTransitionGoesToLowestStatus() throws Exception { final LifeCycled mock = mock(LifeCycled.class); InternalCache ehcache = getCache(mock(Store.class)); doThrow(new Exception()).when(mock).init(); ehcache.addHook(mock); try { ehcache.init(); fail(); } catch (StateTransitionException e) { assertThat(ehcache.getStatus(), is(Status.UNINITIALIZED)); } reset(mock); ehcache.init(); assertThat(ehcache.getStatus(), is(Status.AVAILABLE)); ehcache.close(); }
@Test public void testTransistionsState() { Store<Object, Object> store = mock(Store.class); InternalCache ehcache = getCache(store); assertThat(ehcache.getStatus(), CoreMatchers.is(Status.UNINITIALIZED)); ehcache.init(); assertThat(ehcache.getStatus(), is(Status.AVAILABLE)); ehcache.close(); assertThat(ehcache.getStatus(), is(Status.UNINITIALIZED)); }
private void assertFailingTransitionGoesToLowestStatus(InternalCache cache) throws Exception { final LifeCycled mock = mock(LifeCycled.class); cache.addHook(mock); doThrow(new Exception()).when(mock).init(); try { cache.init(); fail(); } catch (StateTransitionException e) { assertThat(cache.getStatus(), CoreMatchers.is(Status.UNINITIALIZED)); } reset(mock); cache.init(); assertThat(cache.getStatus(), is(Status.AVAILABLE)); doThrow(new Exception()).when(mock).close(); try { cache.close(); fail(); } catch (StateTransitionException e) { assertThat(cache.getStatus(), is(Status.UNINITIALIZED)); } }
@Test public void testInvokesHooks() { Store store = mock(Store.class); InternalCache ehcache = getCache(store); final LifeCycled hook = mock(LifeCycled.class); ehcache.addHook(hook); ehcache.init(); try { verify(hook).init(); } catch (Exception e) { fail(); } reset(hook); try { if (ehcache instanceof Ehcache) { ((Ehcache)ehcache).removeHook(hook); } else { ((Ehcache)ehcache).removeHook(hook); } fail(); } catch (IllegalStateException e) { // expected } ehcache.close(); try { verify(hook).close(); } catch (Exception e) { fail(); } }
ehcache.close(); try { iterator.hasNext();
/** * {@inheritDoc} */ @Override public void close() { cache.close(); if (!getRuntimeConfiguration().getResourcePools().getPoolForResource(ResourceType.Core.DISK).isPersistent()) { try { diskPersistenceService.destroy(id); } catch (CachePersistenceException e) { logger.debug("Unable to clear persistence space for user managed cache {}", id, e); } } }
/** * Closes and removes a cache, by alias, from this cache manager. * * @param alias the alias of the cache to remove * @param removeFromConfig if {@code true}, the cache configuration is altered to remove the cache */ private void removeCache(final String alias, final boolean removeFromConfig) { statusTransitioner.checkAvailable(); final CacheHolder cacheHolder = caches.remove(alias); if(cacheHolder != null) { final InternalCache<?, ?> ehcache = cacheHolder.retrieve(cacheHolder.keyType, cacheHolder.valueType); if (ehcache != null) { if (removeFromConfig) { configuration.removeCacheConfiguration(alias); } if (!statusTransitioner.isTransitioning()) { for (CacheManagerListener listener : listeners) { listener.cacheRemoved(alias, ehcache); } } ehcache.close(); closeEhcache(alias, ehcache); } LOGGER.info("Cache '{}' removed from {}.", alias, simpleName); } }