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 2017/02/19 11:47:57 UTC
[1/2] camel git commit: camel-hazelcast should use Camels thread pool
for its background task.
Repository: camel
Updated Branches:
refs/heads/master 34e2c13b7 -> 72025be03
camel-hazelcast should use Camels thread pool for its background task.
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/1494988e
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/1494988e
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/1494988e
Branch: refs/heads/master
Commit: 1494988ef3f66f1bc7b459266e384b44066de61e
Parents: 34e2c13
Author: Claus Ibsen <da...@apache.org>
Authored: Sun Feb 19 12:46:10 2017 +0100
Committer: Claus Ibsen <da...@apache.org>
Committed: Sun Feb 19 12:46:10 2017 +0100
----------------------------------------------------------------------
.../hazelcast/policy/HazelcastRoutePolicy.java | 35 +++++++++++---------
1 file changed, 20 insertions(+), 15 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/1494988e/components/camel-hazelcast/src/main/java/org/apache/camel/component/hazelcast/policy/HazelcastRoutePolicy.java
----------------------------------------------------------------------
diff --git a/components/camel-hazelcast/src/main/java/org/apache/camel/component/hazelcast/policy/HazelcastRoutePolicy.java b/components/camel-hazelcast/src/main/java/org/apache/camel/component/hazelcast/policy/HazelcastRoutePolicy.java
index 45bb421..1b514b2 100644
--- a/components/camel-hazelcast/src/main/java/org/apache/camel/component/hazelcast/policy/HazelcastRoutePolicy.java
+++ b/components/camel-hazelcast/src/main/java/org/apache/camel/component/hazelcast/policy/HazelcastRoutePolicy.java
@@ -19,30 +19,31 @@ package org.apache.camel.component.hazelcast.policy;
import java.util.HashSet;
import java.util.Set;
import java.util.concurrent.ExecutorService;
-import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicBoolean;
import com.hazelcast.core.HazelcastInstance;
import com.hazelcast.core.IMap;
+import org.apache.camel.CamelContext;
+import org.apache.camel.CamelContextAware;
import org.apache.camel.NonManagedService;
import org.apache.camel.Route;
import org.apache.camel.component.hazelcast.HazelcastUtil;
import org.apache.camel.support.RoutePolicySupport;
-import org.apache.camel.util.ObjectHelper;
import org.apache.camel.util.StringHelper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-public class HazelcastRoutePolicy extends RoutePolicySupport implements NonManagedService {
+public class HazelcastRoutePolicy extends RoutePolicySupport implements CamelContextAware, NonManagedService {
private static final Logger LOGGER = LoggerFactory.getLogger(HazelcastRoutePolicy.class);
private final boolean managedInstance;
private final AtomicBoolean leader;
private final Set<Route> suspendedRoutes;
- private final ExecutorService executorService;
+ private CamelContext camelContext;
+ private ExecutorService executorService;
private HazelcastInstance instance;
private String lockMapName;
private String lockKey;
@@ -74,12 +75,16 @@ public class HazelcastRoutePolicy extends RoutePolicySupport implements NonManag
this.locks = null;
this.future = null;
this.shouldStopConsumer = true;
+ }
- this.executorService = Executors.newSingleThreadExecutor(r -> {
- Thread thread = new Thread(r, "Camel RoutePolicy");
- thread.setDaemon(true);
- return thread;
- });
+ @Override
+ public CamelContext getCamelContext() {
+ return camelContext;
+ }
+
+ @Override
+ public void setCamelContext(CamelContext camelContext) {
+ this.camelContext = camelContext;
}
@Override
@@ -106,6 +111,8 @@ public class HazelcastRoutePolicy extends RoutePolicySupport implements NonManag
StringHelper.notEmpty(lockKey, "lockKey", this);
StringHelper.notEmpty(lockValue, "lockValue", this);
+ executorService = getCamelContext().getExecutorServiceManager().newSingleThreadExecutor(this, "HazelcastRoutePolicy");
+
locks = instance.getMap(lockMapName);
future = executorService.submit(this::acquireLeadership);
@@ -123,6 +130,8 @@ public class HazelcastRoutePolicy extends RoutePolicySupport implements NonManag
instance.shutdown();
}
+ getCamelContext().getExecutorServiceManager().shutdownGraceful(executorService);
+
super.doStop();
}
// *************************************************************************
@@ -269,13 +278,9 @@ public class HazelcastRoutePolicy extends RoutePolicySupport implements NonManag
);
}
} catch (InterruptedException e) {
- if (isRunAllowed()) {
- LOGGER.warn("Interrupted Exception caught", e);
- } else {
- LOGGER.debug("Interrupted Exception caught", e);
- }
+ // ignore
} catch (Exception e) {
- LOGGER.warn("Exception caught", e);
+ getExceptionHandler().handleException(e);
} finally {
if (locked) {
locks.remove(lockKey);
[2/2] camel git commit: CAMEL-10860: camel-hazelcast - route policy
should have a better try lock default value
Posted by da...@apache.org.
CAMEL-10860: camel-hazelcast - route policy should have a better try lock default value
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/72025be0
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/72025be0
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/72025be0
Branch: refs/heads/master
Commit: 72025be030b0d0e74daa9603361ffd0da672007b
Parents: 1494988
Author: Claus Ibsen <da...@apache.org>
Authored: Sun Feb 19 12:47:16 2017 +0100
Committer: Claus Ibsen <da...@apache.org>
Committed: Sun Feb 19 12:47:16 2017 +0100
----------------------------------------------------------------------
.../camel/component/hazelcast/policy/HazelcastRoutePolicy.java | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/72025be0/components/camel-hazelcast/src/main/java/org/apache/camel/component/hazelcast/policy/HazelcastRoutePolicy.java
----------------------------------------------------------------------
diff --git a/components/camel-hazelcast/src/main/java/org/apache/camel/component/hazelcast/policy/HazelcastRoutePolicy.java b/components/camel-hazelcast/src/main/java/org/apache/camel/component/hazelcast/policy/HazelcastRoutePolicy.java
index 1b514b2..94d332f 100644
--- a/components/camel-hazelcast/src/main/java/org/apache/camel/component/hazelcast/policy/HazelcastRoutePolicy.java
+++ b/components/camel-hazelcast/src/main/java/org/apache/camel/component/hazelcast/policy/HazelcastRoutePolicy.java
@@ -70,7 +70,7 @@ public class HazelcastRoutePolicy extends RoutePolicySupport implements CamelCon
this.lockMapName = null;
this.lockKey = null;
this.lockValue = null;
- this.tryLockTimeout = Long.MAX_VALUE;
+ this.tryLockTimeout = 10 * 1000;
this.tryLockTimeoutUnit = TimeUnit.MILLISECONDS;
this.locks = null;
this.future = null;