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 2477c66b7bcd124f24d009a2c0df28b388025d39 Author: Claus Ibsen <[email protected]> AuthorDate: Mon Nov 22 16:18:09 2021 +0100 CAMEL-17223: camel-main - durationMaxAction to control whether to shutdown or stop all routes. --- .../camel/impl/engine/AbstractCamelContext.java | 19 ++++++++++++++++--- .../java/org/apache/camel/main/KameletMainTest.java | 3 ++- 2 files changed, 18 insertions(+), 4 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 bc5b795..0eb4402 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 @@ -1199,9 +1199,22 @@ public abstract class AbstractCamelContext extends BaseService } public void stopAllRoutes() throws Exception { - // stop all routes - if (shutdownStrategy != null) { - shutdownStrategy.shutdown(this, getRouteStartupOrder()); + // stop all routes in reverse order that they were started + Comparator<RouteStartupOrder> comparator = Comparator.comparingInt(RouteStartupOrder::getStartupOrder); + if (shutdownStrategy == null || shutdownStrategy.isShutdownRoutesInReverseOrder()) { + comparator = comparator.reversed(); + } + List<RouteStartupOrder> routesOrdered = new ArrayList<>(getRouteStartupOrder()); + routesOrdered.sort(comparator); + for (RouteStartupOrder order : routesOrdered) { + stopRoute(order.getRoute().getRouteId()); + } + // stop remainder routes + for (Route route : getRoutes()) { + boolean stopped = getRouteController().getRouteStatus(route.getRouteId()).isStopped(); + if (!stopped) { + stopRoute(route.getRouteId()); + } } } diff --git a/dsl/camel-kamelet-main/src/test/java/org/apache/camel/main/KameletMainTest.java b/dsl/camel-kamelet-main/src/test/java/org/apache/camel/main/KameletMainTest.java index 82083f8..2442d1d 100644 --- a/dsl/camel-kamelet-main/src/test/java/org/apache/camel/main/KameletMainTest.java +++ b/dsl/camel-kamelet-main/src/test/java/org/apache/camel/main/KameletMainTest.java @@ -36,7 +36,8 @@ public class KameletMainTest { public void testReload() throws Exception { KameletMain main = new KameletMain(); main.setDownload(true); - main.configure().withDurationMaxSeconds(60); + main.configure().withDurationMaxMessages(10); + main.configure().withDurationMaxAction("stop"); main.configure().withRoutesIncludePattern("file:src/test/resources/my-route.yaml"); main.configure().withRoutesReloadEnabled(true); main.configure().withRoutesReloadDirectory("src/test/resources");
