You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by nf...@apache.org on 2022/09/14 09:49:34 UTC
[camel] branch CAMEL-11252/retrieve-objects-from-context-with-predicate created (now cb3d1a3f2fa)
This is an automated email from the ASF dual-hosted git repository.
nfilotto pushed a change to branch CAMEL-11252/retrieve-objects-from-context-with-predicate
in repository https://gitbox.apache.org/repos/asf/camel.git
at cb3d1a3f2fa CAMEL-11252: camel-core : allow to retrieve components/endpoints list with a predicate
This branch includes the following new commits:
new cb3d1a3f2fa CAMEL-11252: camel-core : allow to retrieve components/endpoints list with a predicate
The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
[camel] 01/01: CAMEL-11252: camel-core : allow to retrieve components/endpoints list with a predicate
Posted by nf...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
nfilotto pushed a commit to branch CAMEL-11252/retrieve-objects-from-context-with-predicate
in repository https://gitbox.apache.org/repos/asf/camel.git
commit cb3d1a3f2fa68b6a7cc16e9ce4801a1f1f348010
Author: Nicolas Filotto <nf...@talend.com>
AuthorDate: Wed Sep 14 11:49:07 2022 +0200
CAMEL-11252: camel-core : allow to retrieve components/endpoints list with a predicate
---
.../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;