Author: rmannibucau Date: Thu Feb 26 08:39:35 2015 New Revision: 1662382 URL: http://svn.apache.org/r1662382 Log: ensuring to close created cache manager/provider in extras cdi extension
Modified: commons/proper/jcs/trunk/commons-jcs-jcache-extras/pom.xml commons/proper/jcs/trunk/commons-jcs-jcache-extras/src/main/java/org/apache/commons/jcs/jcache/extras/cdi/ExtraJCacheExtension.java Modified: commons/proper/jcs/trunk/commons-jcs-jcache-extras/pom.xml URL: http://svn.apache.org/viewvc/commons/proper/jcs/trunk/commons-jcs-jcache-extras/pom.xml?rev=1662382&r1=1662381&r2=1662382&view=diff ============================================================================== --- commons/proper/jcs/trunk/commons-jcs-jcache-extras/pom.xml (original) +++ commons/proper/jcs/trunk/commons-jcs-jcache-extras/pom.xml Thu Feb 26 08:39:35 2015 @@ -48,6 +48,10 @@ </dependency> <dependency> <groupId>org.apache.geronimo.specs</groupId> + <artifactId>geronimo-annotation_1.2_spec</artifactId> + </dependency> + <dependency> + <groupId>org.apache.geronimo.specs</groupId> <artifactId>geronimo-servlet_3.0_spec</artifactId> <version>1.0</version> <scope>provided</scope> Modified: commons/proper/jcs/trunk/commons-jcs-jcache-extras/src/main/java/org/apache/commons/jcs/jcache/extras/cdi/ExtraJCacheExtension.java URL: http://svn.apache.org/viewvc/commons/proper/jcs/trunk/commons-jcs-jcache-extras/src/main/java/org/apache/commons/jcs/jcache/extras/cdi/ExtraJCacheExtension.java?rev=1662382&r1=1662381&r2=1662382&view=diff ============================================================================== --- commons/proper/jcs/trunk/commons-jcs-jcache-extras/src/main/java/org/apache/commons/jcs/jcache/extras/cdi/ExtraJCacheExtension.java (original) +++ commons/proper/jcs/trunk/commons-jcs-jcache-extras/src/main/java/org/apache/commons/jcs/jcache/extras/cdi/ExtraJCacheExtension.java Thu Feb 26 08:39:35 2015 @@ -24,6 +24,7 @@ import javax.cache.spi.CachingProvider; import javax.enterprise.event.Observes; import javax.enterprise.inject.spi.AfterBeanDiscovery; import javax.enterprise.inject.spi.Bean; +import javax.enterprise.inject.spi.BeforeShutdown; import javax.enterprise.inject.spi.Extension; import javax.enterprise.inject.spi.ProcessBean; import java.util.Properties; @@ -35,6 +36,8 @@ public class ExtraJCacheExtension implem private boolean cacheManagerFound = false; private boolean cacheProviderFound = false; + private CacheManager cacheManager; + private CachingProvider cachingProvider; public <A> void processBean(final @Observes ProcessBean<A> processBeanEvent) { @@ -75,10 +78,10 @@ public class ExtraJCacheExtension implem return; } - final CachingProvider cachingProvider = Caching.getCachingProvider(); + cachingProvider = Caching.getCachingProvider(); if (!cacheManagerFound) { - final CacheManager cacheManager = cachingProvider.getCacheManager( + cacheManager = cachingProvider.getCacheManager( cachingProvider.getDefaultURI(), cachingProvider.getDefaultClassLoader(), new Properties()); @@ -89,4 +92,16 @@ public class ExtraJCacheExtension implem afterBeanDiscovery.addBean(new CacheProviderBean(cachingProvider)); } } + + public void destroyIfCreated(final @Observes BeforeShutdown beforeShutdown) + { + if (cacheManager != null) + { + cacheManager.close(); + } + if (cachingProvider != null) + { + cachingProvider.close(); + } + } }