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 2020/03/15 09:03:21 UTC

[camel] branch master updated: CAMEL-14719: camel-core - Camel context started events should be emitted after its status is started. Also fix clustered route policy to only start routes after camel has been started up.

This is an automated email from the ASF dual-hosted git repository.

davsclaus pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel.git


The following commit(s) were added to refs/heads/master by this push:
     new 677e434  CAMEL-14719: camel-core - Camel context started events should be emitted after its status is started. Also fix clustered route policy to only start routes after camel has been started up.
677e434 is described below

commit 677e434e2de3b3cf349476fbfa93c29075429867
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Sun Mar 15 10:01:54 2020 +0100

    CAMEL-14719: camel-core - Camel context started events should be emitted after its status is started. Also fix clustered route policy to only start routes after camel has been started up.
---
 .../ConsulClusteredRoutePolicyFactoryTest.java     |  4 ++-
 .../camel/impl/engine/AbstractCamelContext.java    | 35 ++++++++++++----------
 .../apache/camel/cluster/ClusteredRoutePolicy.java |  9 ++++--
 3 files changed, 30 insertions(+), 18 deletions(-)

diff --git a/components/camel-consul/src/test/java/org/apache/camel/component/consul/cluster/ConsulClusteredRoutePolicyFactoryTest.java b/components/camel-consul/src/test/java/org/apache/camel/component/consul/cluster/ConsulClusteredRoutePolicyFactoryTest.java
index e549ff4..2a22429 100644
--- a/components/camel-consul/src/test/java/org/apache/camel/component/consul/cluster/ConsulClusteredRoutePolicyFactoryTest.java
+++ b/components/camel-consul/src/test/java/org/apache/camel/component/consul/cluster/ConsulClusteredRoutePolicyFactoryTest.java
@@ -98,11 +98,13 @@ public class ConsulClusteredRoutePolicyFactoryTest {
             // Start the context after some random time so the startup order
             // changes for each test.
             Thread.sleep(ThreadLocalRandom.current().nextInt(500));
+            LOGGER.info("Starting CamelContext on node: {}", id);
             context.start();
+            LOGGER.info("Started CamelContext on node: {}", id);
 
             contextLatch.await();
 
-            LOGGER.debug("Shutting down node {}", id);
+            LOGGER.info("Shutting down node {}", id);
             RESULTS.add(id);
 
             context.stop();
diff --git a/core/camel-base/src/main/java/org/apache/camel/impl/engine/AbstractCamelContext.java b/core/camel-base/src/main/java/org/apache/camel/impl/engine/AbstractCamelContext.java
index c8acf1b..82f9b0b 100644
--- a/core/camel-base/src/main/java/org/apache/camel/impl/engine/AbstractCamelContext.java
+++ b/core/camel-base/src/main/java/org/apache/camel/impl/engine/AbstractCamelContext.java
@@ -2483,6 +2483,26 @@ public abstract class AbstractCamelContext extends BaseService
     }
 
     @Override
+    public void start() {
+        super.start();
+
+        // okay the routes has been started so emit event that CamelContext
+        // has started (here at the end)
+        EventHelper.notifyCamelContextStarted(this);
+
+        // now call the startup listeners where the routes has been started
+        for (StartupListener startup : startupListeners) {
+            if (startup instanceof ExtendedStartupListener) {
+                try {
+                    ((ExtendedStartupListener)startup).onCamelContextFullyStarted(this, isStarted());
+                } catch (Exception e) {
+                    throw RuntimeCamelException.wrapRuntimeException(e);
+                }
+            }
+        }
+    }
+
+    @Override
     protected synchronized void doStart() throws Exception {
         try {
             doStartContext();
@@ -2576,21 +2596,6 @@ public abstract class AbstractCamelContext extends BaseService
             }
             LOG.info("Apache Camel {} (CamelContext: {}) started in {}", getVersion(), getName(), TimeUtils.printDuration(stopWatch.taken()));
         }
-
-        // okay the routes has been started so emit event that CamelContext
-        // has started (here at the end)
-        EventHelper.notifyCamelContextStarted(this);
-
-        // now call the startup listeners where the routes has been started
-        for (StartupListener startup : startupListeners) {
-            if (startup instanceof ExtendedStartupListener) {
-                try {
-                    ((ExtendedStartupListener)startup).onCamelContextFullyStarted(this, isStarted());
-                } catch (Exception e) {
-                    throw RuntimeCamelException.wrapRuntimeException(e);
-                }
-            }
-        }
     }
 
     protected void doStartCamel() throws Exception {
diff --git a/core/camel-core-engine/src/main/java/org/apache/camel/cluster/ClusteredRoutePolicy.java b/core/camel-core-engine/src/main/java/org/apache/camel/cluster/ClusteredRoutePolicy.java
index c4e976a..10d7cd8 100644
--- a/core/camel-core-engine/src/main/java/org/apache/camel/cluster/ClusteredRoutePolicy.java
+++ b/core/camel-core-engine/src/main/java/org/apache/camel/cluster/ClusteredRoutePolicy.java
@@ -27,9 +27,9 @@ import java.util.stream.Collectors;
 
 import org.apache.camel.CamelContext;
 import org.apache.camel.CamelContextAware;
+import org.apache.camel.ExtendedStartupListener;
 import org.apache.camel.Route;
 import org.apache.camel.ServiceStatus;
-import org.apache.camel.StartupListener;
 import org.apache.camel.api.management.ManagedAttribute;
 import org.apache.camel.api.management.ManagedResource;
 import org.apache.camel.spi.CamelEvent;
@@ -297,7 +297,7 @@ public final class ClusteredRoutePolicy extends RoutePolicySupport implements Ca
         }
     }
 
-    private class CamelContextStartupListener extends EventNotifierSupport implements StartupListener {
+    private class CamelContextStartupListener extends EventNotifierSupport implements ExtendedStartupListener {
         @Override
         public void notify(CamelEvent event) throws Exception {
             onCamelContextStarted();
@@ -310,6 +310,11 @@ public final class ClusteredRoutePolicy extends RoutePolicySupport implements Ca
 
         @Override
         public void onCamelContextStarted(CamelContext context, boolean alreadyStarted) throws Exception {
+            // noop
+        }
+
+        @Override
+        public void onCamelContextFullyStarted(CamelContext context, boolean alreadyStarted) throws Exception {
             if (alreadyStarted) {
                 // Invoke it only if the context was already started as this
                 // method is not invoked at last event as documented but after