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 2023/03/24 21:48:43 UTC
[camel] branch camel-3.14.x updated: CAMEL-19162: camel-ehcache - Should ignore exception when shutting down cache manager, which prevents from the component to be restarted again.
This is an automated email from the ASF dual-hosted git repository.
davsclaus pushed a commit to branch camel-3.14.x
in repository https://gitbox.apache.org/repos/asf/camel.git
The following commit(s) were added to refs/heads/camel-3.14.x by this push:
new d0b1af7f2a0 CAMEL-19162: camel-ehcache - Should ignore exception when shutting down cache manager, which prevents from the component to be restarted again.
d0b1af7f2a0 is described below
commit d0b1af7f2a0c8405c633e18df040d55427f5ee43
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Fri Mar 24 22:43:15 2023 +0100
CAMEL-19162: camel-ehcache - Should ignore exception when shutting down cache manager, which prevents from the component to be restarted again.
---
.../camel/component/ehcache/EhcacheEndpoint.java | 14 ++++++++----
.../camel/component/ehcache/EhcacheManager.java | 25 ++++++++++++++++------
2 files changed, 28 insertions(+), 11 deletions(-)
diff --git a/components/camel-ehcache/src/main/java/org/apache/camel/component/ehcache/EhcacheEndpoint.java b/components/camel-ehcache/src/main/java/org/apache/camel/component/ehcache/EhcacheEndpoint.java
index 51a6b520015..547676044fc 100644
--- a/components/camel-ehcache/src/main/java/org/apache/camel/component/ehcache/EhcacheEndpoint.java
+++ b/components/camel-ehcache/src/main/java/org/apache/camel/component/ehcache/EhcacheEndpoint.java
@@ -25,6 +25,7 @@ import org.apache.camel.spi.UriEndpoint;
import org.apache.camel.spi.UriParam;
import org.apache.camel.spi.UriPath;
import org.apache.camel.support.DefaultEndpoint;
+import org.apache.camel.support.service.ServiceHelper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -73,18 +74,23 @@ public class EhcacheEndpoint extends DefaultEndpoint {
if (cacheManager == null) {
cacheManager = getComponent().createCacheManager(configuration);
}
- cacheManager.start();
- super.doStart();
+ ServiceHelper.startService(cacheManager);
+ cacheManager.incRef();
}
@Override
protected void doStop() throws Exception {
- super.doStop();
+ ServiceHelper.stopService(cacheManager);
if (cacheManager != null) {
- cacheManager.stop();
+ cacheManager.decRef();
}
}
+ @Override
+ protected void doShutdown() throws Exception {
+ ServiceHelper.stopAndShutdownService(cacheManager);
+ }
+
EhcacheManager getManager() {
return cacheManager;
}
diff --git a/components/camel-ehcache/src/main/java/org/apache/camel/component/ehcache/EhcacheManager.java b/components/camel-ehcache/src/main/java/org/apache/camel/component/ehcache/EhcacheManager.java
index d1b4e19b375..ff200ab38c0 100644
--- a/components/camel-ehcache/src/main/java/org/apache/camel/component/ehcache/EhcacheManager.java
+++ b/components/camel-ehcache/src/main/java/org/apache/camel/component/ehcache/EhcacheManager.java
@@ -20,7 +20,7 @@ import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
import org.apache.camel.RuntimeCamelException;
-import org.apache.camel.Service;
+import org.apache.camel.support.service.ServiceSupport;
import org.apache.camel.util.ObjectHelper;
import org.apache.camel.util.ReferenceCount;
import org.ehcache.Cache;
@@ -33,7 +33,7 @@ import org.ehcache.spi.service.ServiceConfiguration;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-public class EhcacheManager implements Service {
+public class EhcacheManager extends ServiceSupport {
private static final Logger LOGGER = LoggerFactory.getLogger(EhcacheManager.class);
private final EhcacheConfiguration configuration;
@@ -52,15 +52,26 @@ public class EhcacheManager implements Service {
});
}
- @Override
- public synchronized void start() {
+ protected void incRef() {
refCount.retain();
}
- @Override
- public synchronized void stop() {
+ protected void decRef() {
refCount.release();
- userCaches.values().forEach(UserManagedCache::close);
+ }
+
+ @Override
+ protected void doShutdown() throws Exception {
+ if (userCaches != null && !userCaches.isEmpty()) {
+ for (UserManagedCache cache : userCaches.values()) {
+ try {
+ cache.close();
+ } catch (Exception e) {
+ // ignore
+ }
+ }
+ userCaches.clear();
+ }
}
@SuppressWarnings("unchecked")