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/09/14 15:15:37 UTC

[camel] branch main updated: CAMEL-11252: camel-core : allow to retrieve components/endpoints list with a predicate (#8370)

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


The following commit(s) were added to refs/heads/main by this push:
     new 8018f28bd2d CAMEL-11252: camel-core : allow to retrieve components/endpoints list with a predicate (#8370)
8018f28bd2d is described below

commit 8018f28bd2d1f6672ce852407a34d9f9ae2649f2
Author: Nicolas Filotto <es...@users.noreply.github.com>
AuthorDate: Wed Sep 14 17:15:30 2022 +0200

    CAMEL-11252: camel-core : allow to retrieve components/endpoints list with a predicate (#8370)
---
 .../apache/camel/support/CamelContextHelper.java   | 31 ++++++++++++++++++++++
 1 file changed, 31 insertions(+)

diff --git a/core/camel-support/src/main/java/org/apache/camel/support/CamelContextHelper.java b/core/camel-support/src/main/java/org/apache/camel/support/CamelContextHelper.java
index 3a11ca4b1b7..3ea7a2ce2d7 100644
--- a/core/camel-support/src/main/java/org/apache/camel/support/CamelContextHelper.java
+++ b/core/camel-support/src/main/java/org/apache/camel/support/CamelContextHelper.java
@@ -17,11 +17,15 @@
 package org.apache.camel.support;
 
 import java.time.Duration;
+import java.util.List;
 import java.util.Map;
 import java.util.Objects;
 import java.util.Properties;
+import java.util.function.Predicate;
+import java.util.stream.Collectors;
 
 import org.apache.camel.CamelContext;
+import org.apache.camel.Component;
 import org.apache.camel.Endpoint;
 import org.apache.camel.Exchange;
 import org.apache.camel.ExtendedCamelContext;
@@ -647,6 +651,33 @@ public final class CamelContextHelper {
         return configuration;
     }
 
+    /**
+     * Gets the components from the given {@code CamelContext} that match with the given predicate.
+     *
+     * @param  camelContext the camel context
+     * @param  predicate    the predicate to evaluate to know whether a given component should be returned or not.
+     * @return              the existing components that match the predicate.
+     */
+    public static List<Component> getComponents(CamelContext camelContext, Predicate<Component> predicate) {
+        return camelContext.getComponentNames().stream()
+                .map(camelContext::getComponent)
+                .filter(predicate)
+                .collect(Collectors.toList());
+    }
+
+    /**
+     * Gets the endpoints from the given {@code CamelContext} that match with the given predicate
+     *
+     * @param  camelContext the camel context
+     * @param  predicate    the predicate to evaluate to know whether a given endpoint should be returned or not.
+     * @return              the existing endpoints that match the predicate.
+     */
+    public static List<Endpoint> getEndpoints(CamelContext camelContext, Predicate<Endpoint> predicate) {
+        return camelContext.getEndpoints().stream()
+                .filter(predicate)
+                .collect(Collectors.toList());
+    }
+
     private static void validateRestConfigurationComponent(String component, String configurationComponent) {
         if (ObjectHelper.isEmpty(component) || ObjectHelper.isEmpty(configurationComponent)) {
             return;