This is an automated email from the ASF dual-hosted git repository.
davsclaus pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel.git
The following commit(s) were added to refs/heads/main by this push:
new cce03bcf407 CAMEL-19162: camel-ehcache - Should ignore exception when
shutting down cache manager, which prevents from the component to be restarted
again.
cce03bcf407 is described below
commit cce03bcf4072e50877afc7183b8702d74f019ef0
Author: Claus Ibsen <[email protected]>
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 feac7f3c9f4..a70d6de9c95 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;
/**
* Perform caching operations using <a
href="http://www.ehcache.org">Ehcache</a>.
@@ -68,18 +69,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")