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 2021/11/23 09:24:08 UTC
[camel] 08/08: CAMEL-17223: camel-main - durationMaxAction to control whether to shutdown or stop all routes.
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
commit ec85b2c6db656a75bd91d6e9210875a94709129d
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Tue Nov 23 09:52:38 2021 +0100
CAMEL-17223: camel-main - durationMaxAction to control whether to shutdown or stop all routes.
---
.../org/apache/camel/impl/engine/AbstractCamelContext.java | 8 ++++++--
.../src/main/java/org/apache/camel/main/MainSupport.java | 14 +++++++++++++-
2 files changed, 19 insertions(+), 3 deletions(-)
diff --git a/core/camel-base-engine/src/main/java/org/apache/camel/impl/engine/AbstractCamelContext.java b/core/camel-base-engine/src/main/java/org/apache/camel/impl/engine/AbstractCamelContext.java
index 0eb4402..30dbe16 100644
--- a/core/camel-base-engine/src/main/java/org/apache/camel/impl/engine/AbstractCamelContext.java
+++ b/core/camel-base-engine/src/main/java/org/apache/camel/impl/engine/AbstractCamelContext.java
@@ -1207,9 +1207,13 @@ public abstract class AbstractCamelContext extends BaseService
List<RouteStartupOrder> routesOrdered = new ArrayList<>(getRouteStartupOrder());
routesOrdered.sort(comparator);
for (RouteStartupOrder order : routesOrdered) {
- stopRoute(order.getRoute().getRouteId());
+ Route route = order.getRoute();
+ boolean stopped = getRouteController().getRouteStatus(route.getRouteId()).isStopped();
+ if (!stopped) {
+ stopRoute(route.getRouteId());
+ }
}
- // stop remainder routes
+ // stop any remainder routes
for (Route route : getRoutes()) {
boolean stopped = getRouteController().getRouteStatus(route.getRouteId()).isStopped();
if (!stopped) {
diff --git a/core/camel-main/src/main/java/org/apache/camel/main/MainSupport.java b/core/camel-main/src/main/java/org/apache/camel/main/MainSupport.java
index 4d40a91..1b925d8 100644
--- a/core/camel-main/src/main/java/org/apache/camel/main/MainSupport.java
+++ b/core/camel-main/src/main/java/org/apache/camel/main/MainSupport.java
@@ -46,6 +46,7 @@ public abstract class MainSupport extends BaseMainSupport {
private int durationMaxMessages;
private long durationMaxSeconds;
private int durationHitExitCode;
+ private String durationMaxAction = "shutdown";
protected MainSupport(Class<?>... configurationClasses) {
this();
@@ -108,6 +109,7 @@ public abstract class MainSupport extends BaseMainSupport {
durationMaxMessages = mainConfigurationProperties.getDurationMaxMessages();
durationMaxSeconds = mainConfigurationProperties.getDurationMaxSeconds();
durationHitExitCode = mainConfigurationProperties.getDurationHitExitCode();
+ durationMaxAction = mainConfigurationProperties.getDurationMaxAction();
// register main as bootstrap
CamelContext context = getCamelContext();
@@ -304,8 +306,18 @@ public abstract class MainSupport extends BaseMainSupport {
LOG.info("Waiting until complete: Duration max {} seconds", sec);
boolean zero = shutdownStrategy.await(sec, TimeUnit.SECONDS);
if (!zero) {
- LOG.info("Duration max seconds triggering shutdown of the JVM");
+ if ("stop".equalsIgnoreCase(durationMaxAction)) {
+ LOG.info("Duration max seconds triggering stopping all routes");
+ try {
+ camelContext.getRouteController().stopAllRoutes();
+ } catch (Exception e) {
+ LOG.warn("Error during stopping all routes. This exception is ignored.", e);
+ }
+ // we are just stopping routes (not terminating JVM) so continue
+ continue;
+ }
}
+ LOG.info("Duration max seconds triggering shutdown of the JVM");
exitCode.compareAndSet(UNINITIALIZED_EXIT_CODE, exit);
shutdownStrategy.shutdown();
} else if (idle > 0 || max > 0) {