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/03/16 15:18:05 UTC
camel git commit: Make it easier to stop route async from route policy
Repository: camel
Updated Branches:
refs/heads/master bc05a54d5 -> 0d096d77f
Make it easier to stop route async from route policy
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/0d096d77
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/0d096d77
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/0d096d77
Branch: refs/heads/master
Commit: 0d096d77fb919916d42a21a4258dc36e0e472249
Parents: bc05a54
Author: Claus Ibsen <da...@apache.org>
Authored: Thu Mar 16 16:12:45 2017 +0100
Committer: Claus Ibsen <da...@apache.org>
Committed: Thu Mar 16 16:17:59 2017 +0100
----------------------------------------------------------------------
.../camel/support/RoutePolicySupport.java | 27 +++++++++++++++++++-
1 file changed, 26 insertions(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/0d096d77/camel-core/src/main/java/org/apache/camel/support/RoutePolicySupport.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/support/RoutePolicySupport.java b/camel-core/src/main/java/org/apache/camel/support/RoutePolicySupport.java
index 575d009..42e9edf 100644
--- a/camel-core/src/main/java/org/apache/camel/support/RoutePolicySupport.java
+++ b/camel-core/src/main/java/org/apache/camel/support/RoutePolicySupport.java
@@ -107,14 +107,39 @@ public abstract class RoutePolicySupport extends ServiceSupport implements Route
route.getRouteContext().getCamelContext().suspendRoute(route.getId(), timeout, timeUnit);
}
+ /**
+ * @see #stopRouteAsync(Route)
+ */
public void stopRoute(Route route) throws Exception {
route.getRouteContext().getCamelContext().stopRoute(route.getId());
}
+ /**
+ * @see #stopRouteAsync(Route)
+ */
public void stopRoute(Route route, long timeout, TimeUnit timeUnit) throws Exception {
route.getRouteContext().getCamelContext().stopRoute(route.getId(), timeout, timeUnit);
}
-
+
+ /**
+ * Allows to stop a route asynchronously using a separate background thread which can allow any current in-flight exchange
+ * to complete while the route is being shutdown.
+ * You may attempt to stop a route from processing an exchange which would be in-flight and therefore attempting to stop
+ * the route will defer due there is an inflight exchange in-progress. By stopping the route independently using a separate
+ * thread ensures the exchange can continue process and complete and the route can be stopped.
+ */
+ public void stopRouteAsync(final Route route) {
+ String threadId = route.getRouteContext().getCamelContext().getExecutorServiceManager().resolveThreadName("StopRouteAsync");
+ Runnable task = () -> {
+ try {
+ route.getRouteContext().getCamelContext().stopRoute(route.getId());
+ } catch (Exception e) {
+ handleException(e);
+ }
+ };
+ new Thread(task, threadId).start();
+ }
+
/**
* Handles the given exception using the {@link #getExceptionHandler()}
*