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 2022/06/04 19:12:31 UTC

[camel] 02/02: CAMEL-18166: camel-main - Make RoutesCollector more flexible for other runtimes to do custom strategy.

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 3b33075f77b9bf16cd519e8477deb0fe8f51c25b
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Sat Jun 4 21:12:17 2022 +0200

    CAMEL-18166: camel-main - Make RoutesCollector more flexible for other runtimes to do custom strategy.
---
 .../apache/camel/main/DefaultRoutesCollector.java  | 30 +++++++++++++++++++---
 1 file changed, 27 insertions(+), 3 deletions(-)

diff --git a/core/camel-main/src/main/java/org/apache/camel/main/DefaultRoutesCollector.java b/core/camel-main/src/main/java/org/apache/camel/main/DefaultRoutesCollector.java
index e1d1c4a3b52..3462c8792cc 100644
--- a/core/camel-main/src/main/java/org/apache/camel/main/DefaultRoutesCollector.java
+++ b/core/camel-main/src/main/java/org/apache/camel/main/DefaultRoutesCollector.java
@@ -21,7 +21,6 @@ import java.lang.reflect.Modifier;
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.List;
-import java.util.Set;
 
 import org.apache.camel.CamelContext;
 import org.apache.camel.ExtendedCamelContext;
@@ -53,7 +52,13 @@ public class DefaultRoutesCollector implements RoutesCollector {
         final List<RoutesBuilder> routes = new ArrayList<>();
         final AntPathMatcher matcher = new AntPathMatcher();
 
-        Set<LambdaRouteBuilder> lrbs = camelContext.getRegistry().findByType(LambdaRouteBuilder.class);
+        Collection<RoutesBuilder> additional
+                = collectAdditionalRoutesFromRegistry(camelContext, excludePattern, includePattern);
+        if (additional != null) {
+            routes.addAll(additional);
+        }
+
+        Collection<LambdaRouteBuilder> lrbs = findByType(camelContext, LambdaRouteBuilder.class);
         for (LambdaRouteBuilder lrb : lrbs) {
             RouteBuilder rb = new RouteBuilder() {
                 @Override
@@ -64,7 +69,7 @@ public class DefaultRoutesCollector implements RoutesCollector {
             routes.add(rb);
         }
 
-        Set<RoutesBuilder> builders = camelContext.getRegistry().findByType(RoutesBuilder.class);
+        Collection<RoutesBuilder> builders = findByType(camelContext, RoutesBuilder.class);
         for (RoutesBuilder routesBuilder : builders) {
             // filter out abstract classes
             boolean abs = Modifier.isAbstract(routesBuilder.getClass().getModifiers());
@@ -195,4 +200,23 @@ public class DefaultRoutesCollector implements RoutesCollector {
 
         return accepted;
     }
+
+    /**
+     * Strategy to allow collecting additional routes from registry.
+     */
+    protected Collection<RoutesBuilder> collectAdditionalRoutesFromRegistry(
+            CamelContext camelContext,
+            String excludePattern,
+            String includePattern) {
+        return null;
+    }
+
+    /**
+     * Strategy to discover a specific route builder type from the registry. This allows Spring Boot or other runtimes
+     * to do custom lookup.
+     */
+    protected <T> Collection<T> findByType(CamelContext camelContext, Class<T> type) {
+        return camelContext.getRegistry().findByType(type);
+    }
+
 }