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:02 UTC

[camel] 02/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 7313fc5ad8f0d3edd4f44967935de3aa4cfa506e
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Mon Nov 22 15:37:12 2021 +0100

    CAMEL-17223: camel-main - durationMaxAction to control whether to shutdown or stop all routes.
---
 .../src/main/java/org/apache/camel/spi/RouteController.java        | 7 +++++++
 .../java/org/apache/camel/impl/engine/AbstractCamelContext.java    | 4 ++++
 .../java/org/apache/camel/impl/engine/InternalRouteController.java | 5 +++++
 .../org/apache/camel/impl/lw/LightweightRuntimeCamelContext.java   | 5 +++++
 .../main/java/org/apache/camel/main/MainDurationEventNotifier.java | 7 +++++--
 5 files changed, 26 insertions(+), 2 deletions(-)

diff --git a/core/camel-api/src/main/java/org/apache/camel/spi/RouteController.java b/core/camel-api/src/main/java/org/apache/camel/spi/RouteController.java
index b22812f..9af937b 100644
--- a/core/camel-api/src/main/java/org/apache/camel/spi/RouteController.java
+++ b/core/camel-api/src/main/java/org/apache/camel/spi/RouteController.java
@@ -77,6 +77,13 @@ public interface RouteController extends CamelContextAware, StaticService {
     void startAllRoutes() throws Exception;
 
     /**
+     * Stops all the routes
+     *
+     * @throws Exception is thrown if a route could not be stopped for whatever reason
+     */
+    void stopAllRoutes() throws Exception;
+
+    /**
      * Indicates whether current thread is starting route(s).
      * <p/>
      * This can be useful to know by {@link LifecycleStrategy} or the likes, in case they need to react differently.
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 5845fd9..db84220 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
@@ -1198,6 +1198,10 @@ public abstract class AbstractCamelContext extends BaseService
         internalRouteStartupManager.doStartOrResumeRoutes(routeServices, true, true, false, false);
     }
 
+    public void stopAllRoutes() throws Exception {
+        // TODO: implement me
+    }
+
     public synchronized void startRoute(String routeId) throws Exception {
         DefaultRouteError.reset(this, routeId);
 
diff --git a/core/camel-base-engine/src/main/java/org/apache/camel/impl/engine/InternalRouteController.java b/core/camel-base-engine/src/main/java/org/apache/camel/impl/engine/InternalRouteController.java
index f7f7cc8..d2219f1 100644
--- a/core/camel-base-engine/src/main/java/org/apache/camel/impl/engine/InternalRouteController.java
+++ b/core/camel-base-engine/src/main/java/org/apache/camel/impl/engine/InternalRouteController.java
@@ -73,6 +73,11 @@ class InternalRouteController implements RouteController {
     }
 
     @Override
+    public void stopAllRoutes() throws Exception {
+        abstractCamelContext.stopAllRoutes();
+    }
+
+    @Override
     public boolean isStartingRoutes() {
         return abstractCamelContext.isStartingRoutes();
     }
diff --git a/core/camel-core-engine/src/main/java/org/apache/camel/impl/lw/LightweightRuntimeCamelContext.java b/core/camel-core-engine/src/main/java/org/apache/camel/impl/lw/LightweightRuntimeCamelContext.java
index eb12bf4..d9f7f3b 100644
--- a/core/camel-core-engine/src/main/java/org/apache/camel/impl/lw/LightweightRuntimeCamelContext.java
+++ b/core/camel-core-engine/src/main/java/org/apache/camel/impl/lw/LightweightRuntimeCamelContext.java
@@ -1994,6 +1994,11 @@ public class LightweightRuntimeCamelContext implements ExtendedCamelContext, Cat
             }
 
             @Override
+            public void stopAllRoutes() throws Exception {
+                throw new UnsupportedOperationException();
+            }
+
+            @Override
             public boolean isStartingRoutes() {
                 return false;
             }
diff --git a/core/camel-main/src/main/java/org/apache/camel/main/MainDurationEventNotifier.java b/core/camel-main/src/main/java/org/apache/camel/main/MainDurationEventNotifier.java
index 586ad25..66a7432 100644
--- a/core/camel-main/src/main/java/org/apache/camel/main/MainDurationEventNotifier.java
+++ b/core/camel-main/src/main/java/org/apache/camel/main/MainDurationEventNotifier.java
@@ -160,8 +160,11 @@ public class MainDurationEventNotifier extends EventNotifierSupport {
             return;
         }
 
-        // TODO: stop all routes via shutdown strategy
-        LOG.warn("Stopping all routes!!!");
+        try {
+            camelContext.getRouteController().stopAllRoutes();
+        } catch (Exception e) {
+            LOG.warn("Error during stopping all routes. This exception is ignored.", e);
+        }
     }
 
     private void shutdownTask() {