You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by tv...@apache.org on 2020/04/13 12:52:01 UTC
[commons-jcs] 01/03: JCS-199 Properly shut down auxiliaries
This is an automated email from the ASF dual-hosted git repository.
tv pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-jcs.git
commit 1477f3f503ea2b2471683c3067916a4484539606
Author: Thomas Vandahl <tv...@apache.org>
AuthorDate: Mon Apr 13 14:50:48 2020 +0200
JCS-199 Properly shut down auxiliaries
---
.../jcs/engine/control/CompositeCacheManager.java | 42 ++++++++++++++++++++++
1 file changed, 42 insertions(+)
diff --git a/commons-jcs-core/src/main/java/org/apache/commons/jcs/engine/control/CompositeCacheManager.java b/commons-jcs-core/src/main/java/org/apache/commons/jcs/engine/control/CompositeCacheManager.java
index 85712ff..b13b66d 100644
--- a/commons-jcs-core/src/main/java/org/apache/commons/jcs/engine/control/CompositeCacheManager.java
+++ b/commons-jcs-core/src/main/java/org/apache/commons/jcs/engine/control/CompositeCacheManager.java
@@ -631,6 +631,19 @@ public class CompositeCacheManager
// do the traditional shutdown of the regions.
getCacheNames().forEach(this::freeCache);
+ // shut down auxiliaries
+ for (String key : auxiliaryCaches.keySet())
+ {
+ try
+ {
+ freeAuxiliaryCache(key);
+ }
+ catch (IOException e)
+ {
+ log.warn("Auxiliary cache {0} failed to shut down", key, e);
+ }
+ }
+
// shut down factories
auxiliaryFactoryRegistry.values().forEach(AuxiliaryCacheFactory::dispose);
@@ -779,6 +792,35 @@ public class CompositeCacheManager
}
/**
+ * Dispose a cache and remove it from the map of registered auxiliary caches
+ *
+ * @param auxName the auxiliary name
+ * @param cacheName the region name
+ * @throws IOException if disposing of the cache fails
+ */
+ public void freeAuxiliaryCache(String auxName, String cacheName) throws IOException
+ {
+ String key = String.format("aux.%s.region.%s", auxName, cacheName);
+ freeAuxiliaryCache(key);
+ }
+
+ /**
+ * Dispose a cache and remove it from the map of registered auxiliary caches
+ *
+ * @param key the key into the map of auxiliaries
+ * @throws IOException if disposing of the cache fails
+ */
+ public void freeAuxiliaryCache(String key) throws IOException
+ {
+ AuxiliaryCache<?, ?> aux = auxiliaryCaches.remove( key );
+
+ if ( aux != null )
+ {
+ aux.dispose();
+ }
+ }
+
+ /**
* Gets stats for debugging. This calls gets statistics and then puts all the results in a
* string. This returns data for all regions.
* <p>