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 18:16:30 UTC

[camel] branch master updated: Fixed so camel marks starting routes more eager as recent refactorings with reifiers may create endpoints sooner.

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 fadfaef  Fixed so camel marks starting routes more eager as recent refactorings with reifiers may create endpoints sooner.
fadfaef is described below

commit fadfaef7a2d1c30f4d1733c6e136827d2763bbac
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Sun Mar 15 18:01:13 2020 +0100

    Fixed so camel marks starting routes more eager as recent refactorings with reifiers may create endpoints sooner.
---
 .../camel/impl/engine/AbstractDynamicRegistry.java | 11 ++++--
 .../org/apache/camel/impl/DefaultCamelContext.java | 44 +++++++++++++---------
 2 files changed, 34 insertions(+), 21 deletions(-)

diff --git a/core/camel-base/src/main/java/org/apache/camel/impl/engine/AbstractDynamicRegistry.java b/core/camel-base/src/main/java/org/apache/camel/impl/engine/AbstractDynamicRegistry.java
index 36b0b90..a62ab9b 100644
--- a/core/camel-base/src/main/java/org/apache/camel/impl/engine/AbstractDynamicRegistry.java
+++ b/core/camel-base/src/main/java/org/apache/camel/impl/engine/AbstractDynamicRegistry.java
@@ -27,6 +27,7 @@ import java.util.concurrent.ConcurrentHashMap;
 import org.apache.camel.CamelContext;
 import org.apache.camel.ExtendedCamelContext;
 import org.apache.camel.StaticService;
+import org.apache.camel.spi.RouteController;
 import org.apache.camel.support.LRUCache;
 import org.apache.camel.support.LRUCacheFactory;
 import org.apache.camel.support.service.ServiceHelper;
@@ -37,13 +38,15 @@ import org.apache.camel.support.service.ServiceHelper;
  */
 public class AbstractDynamicRegistry<K, V> extends AbstractMap<K, V>  implements StaticService {
 
-    protected final CamelContext context;
+    protected final ExtendedCamelContext context;
+    protected final RouteController routeController;
     protected final int maxCacheSize;
     protected final Map<K, V> dynamicMap;
     protected final Map<K, V> staticMap;
 
     public AbstractDynamicRegistry(CamelContext context, int maxCacheSize) {
-        this.context = context;
+        this.context = (ExtendedCamelContext) context;
+        this.routeController = context.getRouteController();
         this.maxCacheSize = maxCacheSize;
         // do not stop on eviction, as the transformer may still be in use
         this.dynamicMap = LRUCacheFactory.newLRUCache(this.maxCacheSize, this.maxCacheSize, false);
@@ -64,7 +67,7 @@ public class AbstractDynamicRegistry<K, V> extends AbstractMap<K, V>  implements
         V answer = staticMap.get(o);
         if (answer == null) {
             answer = dynamicMap.get(o);
-            if (answer != null && (context.adapt(ExtendedCamelContext.class).isSetupRoutes() || context.getRouteController().isStartingRoutes())) {
+            if (answer != null && (context.isSetupRoutes() || routeController.isStartingRoutes())) {
                 dynamicMap.remove(o);
                 staticMap.put((K) o, answer);
             }
@@ -90,7 +93,7 @@ public class AbstractDynamicRegistry<K, V> extends AbstractMap<K, V>  implements
         }
 
         // we want transformers to be static if they are part of setting up or starting routes
-        if (context.adapt(ExtendedCamelContext.class).isSetupRoutes() || context.getRouteController().isStartingRoutes()) {
+        if (context.isSetupRoutes() || routeController.isStartingRoutes()) {
             answer = staticMap.put(key, transformer);
         } else {
             answer = dynamicMap.put(key, transformer);
diff --git a/core/camel-core-engine/src/main/java/org/apache/camel/impl/DefaultCamelContext.java b/core/camel-core-engine/src/main/java/org/apache/camel/impl/DefaultCamelContext.java
index 17b9531..ba3fe6b 100644
--- a/core/camel-core-engine/src/main/java/org/apache/camel/impl/DefaultCamelContext.java
+++ b/core/camel-core-engine/src/main/java/org/apache/camel/impl/DefaultCamelContext.java
@@ -329,25 +329,35 @@ public class DefaultCamelContext extends SimpleCamelContext implements ModelCame
     }
 
     public void startRouteDefinitions(List<RouteDefinition> routeDefinitions) throws Exception {
-        RouteDefinitionHelper.forceAssignIds(getCamelContextReference(), routeDefinitions);
-        for (RouteDefinition routeDefinition : routeDefinitions) {
-            // assign ids to the routes and validate that the id's is all unique
-            String duplicate = RouteDefinitionHelper.validateUniqueIds(routeDefinition, routeDefinitions);
-            if (duplicate != null) {
-                throw new FailedToStartRouteException(routeDefinition.getId(), "duplicate id detected: " + duplicate + ". Please correct ids to be unique among all your routes.");
-            }
+        // indicate we are staring the route using this thread so
+        // we are able to query this if needed
+        boolean alreadyStartingRoutes = isStartingRoutes();
+        if (!alreadyStartingRoutes) {
+            setStartingRoutes(true);
+        }
+        try {
+            RouteDefinitionHelper.forceAssignIds(getCamelContextReference(), routeDefinitions);
+            for (RouteDefinition routeDefinition : routeDefinitions) {
+                // assign ids to the routes and validate that the id's is all unique
+                String duplicate = RouteDefinitionHelper.validateUniqueIds(routeDefinition, routeDefinitions);
+                if (duplicate != null) {
+                    throw new FailedToStartRouteException(routeDefinition.getId(), "duplicate id detected: " + duplicate + ". Please correct ids to be unique among all your routes.");
+                }
 
-            // must ensure route is prepared, before we can start it
-            if (!routeDefinition.isPrepared()) {
-                RouteDefinitionHelper.prepareRoute(getCamelContextReference(), routeDefinition);
-                routeDefinition.markPrepared();
-            }
+                // must ensure route is prepared, before we can start it
+                if (!routeDefinition.isPrepared()) {
+                    RouteDefinitionHelper.prepareRoute(getCamelContextReference(), routeDefinition);
+                    routeDefinition.markPrepared();
+                }
 
-            // indicate we are staring the route using this thread so
-            // we are able to query this if needed
-            Route route = new RouteReifier(getCamelContextReference(), routeDefinition).createRoute();
-            RouteService routeService = new RouteService(route);
-            startRouteService(routeService, true);
+                Route route = new RouteReifier(getCamelContextReference(), routeDefinition).createRoute();
+                RouteService routeService = new RouteService(route);
+                startRouteService(routeService, true);
+            }
+        } finally {
+            if (!alreadyStartingRoutes) {
+                setStartingRoutes(false);
+            }
         }
     }