You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2016/04/10 16:20:58 UTC

[2/2] camel git commit: CAMEL-7174: CacheManager should only be shutdown when last endpoint is stopped. Thanks to metatech for the patch.

CAMEL-7174: CacheManager should only be shutdown when last endpoint is stopped. Thanks to metatech for the patch.


Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/241c98b6
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/241c98b6
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/241c98b6

Branch: refs/heads/master
Commit: 241c98b66583de92a3c85b6bbe9290903fdf7dc6
Parents: d0d809d
Author: Claus Ibsen <da...@apache.org>
Authored: Sun Apr 10 16:20:39 2016 +0200
Committer: Claus Ibsen <da...@apache.org>
Committed: Sun Apr 10 16:20:39 2016 +0200

----------------------------------------------------------------------
 .../camel/component/cache/CacheManagerFactory.java   | 15 +++++++++++----
 1 file changed, 11 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/241c98b6/components/camel-cache/src/main/java/org/apache/camel/component/cache/CacheManagerFactory.java
----------------------------------------------------------------------
diff --git a/components/camel-cache/src/main/java/org/apache/camel/component/cache/CacheManagerFactory.java b/components/camel-cache/src/main/java/org/apache/camel/component/cache/CacheManagerFactory.java
index 1a69a7c..5ab229b 100755
--- a/components/camel-cache/src/main/java/org/apache/camel/component/cache/CacheManagerFactory.java
+++ b/components/camel-cache/src/main/java/org/apache/camel/component/cache/CacheManagerFactory.java
@@ -63,11 +63,18 @@ public abstract class CacheManagerFactory extends ServiceSupport {
     }
 
     @Override
-    protected void doStop() throws Exception {
-        // shutdown cache manager when stopping
+    protected synchronized void doStop() throws Exception {
+        // only shutdown cache manager if no longer in use
+        // (it may be reused when running in app servers like Karaf)
         if (cacheManager != null) {
-            cacheManager.shutdown();
-            cacheManager = null;
+            int size = cacheManager.getCacheNames().length;
+            if (size <= 0) {
+                LOG.info("Shutting down CacheManager as its no longer in use");
+                cacheManager.shutdown();
+                cacheManager = null;
+            } else {
+                LOG.info("Cannot stop CacheManager as its still in use by {} clients", size);
+            }
         }
     }
 }