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/10/05 01:51:24 UTC
[camel] 02/09: CAMEL-18574: camel-core - Add disabled option to EIPs
This is an automated email from the ASF dual-hosted git repository.
davsclaus pushed a commit to branch disabled
in repository https://gitbox.apache.org/repos/asf/camel.git
commit 21e7e05c40f706c10728ef831912bdbc3e0bbe4c
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Tue Oct 4 16:37:52 2022 -0500
CAMEL-18574: camel-core - Add disabled option to EIPs
---
.../apache/camel/processor/DisabledProcessor.java | 75 ++++++++++++++++++++++
.../org/apache/camel/reifier/DisabledReifier.java | 35 ++++++++++
.../org/apache/camel/reifier/ProcessorReifier.java | 8 +++
3 files changed, 118 insertions(+)
diff --git a/core/camel-core-processor/src/main/java/org/apache/camel/processor/DisabledProcessor.java b/core/camel-core-processor/src/main/java/org/apache/camel/processor/DisabledProcessor.java
new file mode 100644
index 00000000000..3a92b821041
--- /dev/null
+++ b/core/camel-core-processor/src/main/java/org/apache/camel/processor/DisabledProcessor.java
@@ -0,0 +1,75 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.processor;
+
+import org.apache.camel.AsyncCallback;
+import org.apache.camel.Exchange;
+import org.apache.camel.spi.IdAware;
+import org.apache.camel.spi.RouteIdAware;
+import org.apache.camel.support.AsyncProcessorSupport;
+
+/**
+ * A disabled EIP that does not do anything
+ */
+public class DisabledProcessor extends AsyncProcessorSupport implements IdAware, RouteIdAware {
+
+ private String id;
+ private String routeId;
+
+ @Override
+ public boolean process(Exchange exchange, AsyncCallback callback) {
+ // do nothing
+ callback.done(true);
+ return true;
+ }
+
+ @Override
+ public String toString() {
+ return id;
+ }
+
+ @Override
+ public String getId() {
+ return id;
+ }
+
+ @Override
+ public void setId(String id) {
+ this.id = id;
+ }
+
+ @Override
+ public String getRouteId() {
+ return routeId;
+ }
+
+ @Override
+ public void setRouteId(String routeId) {
+ this.routeId = routeId;
+ }
+
+ @Override
+ protected void doStart() throws Exception {
+ // noop
+ }
+
+ @Override
+ protected void doStop() throws Exception {
+ // noop
+ }
+
+}
diff --git a/core/camel-core-reifier/src/main/java/org/apache/camel/reifier/DisabledReifier.java b/core/camel-core-reifier/src/main/java/org/apache/camel/reifier/DisabledReifier.java
new file mode 100644
index 00000000000..e2a89b8d74f
--- /dev/null
+++ b/core/camel-core-reifier/src/main/java/org/apache/camel/reifier/DisabledReifier.java
@@ -0,0 +1,35 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.reifier;
+
+import org.apache.camel.Processor;
+import org.apache.camel.Route;
+import org.apache.camel.model.ProcessDefinition;
+import org.apache.camel.model.ProcessorDefinition;
+
+public class DisabledReifier extends ProcessorReifier<ProcessDefinition> {
+
+ public DisabledReifier(Route route, ProcessorDefinition<?> definition) {
+ super(route, (ProcessDefinition) definition);
+ }
+
+ @Override
+ public Processor createProcessor() {
+ // disabled so return null
+ return null;
+ }
+}
diff --git a/core/camel-core-reifier/src/main/java/org/apache/camel/reifier/ProcessorReifier.java b/core/camel-core-reifier/src/main/java/org/apache/camel/reifier/ProcessorReifier.java
index f375336c62c..c1a8aacd6fd 100644
--- a/core/camel-core-reifier/src/main/java/org/apache/camel/reifier/ProcessorReifier.java
+++ b/core/camel-core-reifier/src/main/java/org/apache/camel/reifier/ProcessorReifier.java
@@ -119,6 +119,7 @@ import org.apache.camel.spi.IdAware;
import org.apache.camel.spi.InterceptStrategy;
import org.apache.camel.spi.ReifierStrategy;
import org.apache.camel.spi.RouteIdAware;
+import org.apache.camel.support.CamelContextHelper;
import org.apache.camel.util.ObjectHelper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -158,6 +159,13 @@ public abstract class ProcessorReifier<T extends ProcessorDefinition<?>> extends
public static ProcessorReifier<? extends ProcessorDefinition<?>> reifier(Route route, ProcessorDefinition<?> definition) {
ProcessorReifier<? extends ProcessorDefinition<?>> answer = null;
+
+ // special if the EIP is disabled
+ Boolean disabled = CamelContextHelper.parseBoolean(route.getCamelContext(), definition.getDisabled());
+ if (disabled != null && disabled) {
+ return new DisabledReifier(route, definition);
+ }
+
if (!PROCESSORS.isEmpty()) {
// custom take precedence
BiFunction<Route, ProcessorDefinition<?>, ProcessorReifier<? extends ProcessorDefinition<?>>> reifier