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/11/03 09:42:29 UTC

[camel] 02/03: CAMEL-15795: camel-core - Reduce tangle from impl engine to model

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

commit 2101aee43b4e46716a760bca11a68a2d70ff79a2
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Tue Nov 3 09:51:20 2020 +0100

    CAMEL-15795: camel-core - Reduce tangle from impl engine to model
---
 .../src/main/java/org/apache/camel/Channel.java    |   7 --
 .../apache/camel/impl/engine/DefaultChannel.java   |  11 --
 .../camel/impl/lw/LightweightCamelContext.java     |   4 -
 .../RandomLoadBalanceJavaDSLBuilderTest.java       | 123 ---------------------
 4 files changed, 145 deletions(-)

diff --git a/core/camel-api/src/main/java/org/apache/camel/Channel.java b/core/camel-api/src/main/java/org/apache/camel/Channel.java
index e2777f8..9778df2 100644
--- a/core/camel-api/src/main/java/org/apache/camel/Channel.java
+++ b/core/camel-api/src/main/java/org/apache/camel/Channel.java
@@ -84,11 +84,4 @@ public interface Channel extends AsyncProcessor, Navigate<Processor> {
      */
     Route getRoute();
 
-    /**
-     * Gets the definition of the next processor
-     *
-     * @return the processor definition
-     */
-    NamedNode getProcessorDefinition();
-
 }
diff --git a/core/camel-base-engine/src/main/java/org/apache/camel/impl/engine/DefaultChannel.java b/core/camel-base-engine/src/main/java/org/apache/camel/impl/engine/DefaultChannel.java
index 776f958..902eec4 100644
--- a/core/camel-base-engine/src/main/java/org/apache/camel/impl/engine/DefaultChannel.java
+++ b/core/camel-base-engine/src/main/java/org/apache/camel/impl/engine/DefaultChannel.java
@@ -62,7 +62,6 @@ public class DefaultChannel extends CamelInternalProcessor implements Channel {
     private Processor nextProcessor;
     // the real output to invoke that has been wrapped
     private Processor output;
-    private NamedNode definition;
     private ManagementInterceptStrategy.InstrumentationProcessor<?> instrumentationProcessor;
     private Route route;
 
@@ -114,15 +113,6 @@ public class DefaultChannel extends CamelInternalProcessor implements Channel {
     }
 
     @Override
-    public NamedNode getProcessorDefinition() {
-        return definition;
-    }
-
-    public void clearModelReferences() {
-        this.definition = null;
-    }
-
-    @Override
     public Route getRoute() {
         return route;
     }
@@ -162,7 +152,6 @@ public class DefaultChannel extends CamelInternalProcessor implements Channel {
             boolean first)
             throws Exception {
         this.route = route;
-        this.definition = definition;
         this.nextProcessor = nextProcessor;
 
         // init CamelContextAware as early as possible on nextProcessor
diff --git a/core/camel-core-engine/src/main/java/org/apache/camel/impl/lw/LightweightCamelContext.java b/core/camel-core-engine/src/main/java/org/apache/camel/impl/lw/LightweightCamelContext.java
index 1453f02..3b0cedb 100644
--- a/core/camel-core-engine/src/main/java/org/apache/camel/impl/lw/LightweightCamelContext.java
+++ b/core/camel-core-engine/src/main/java/org/apache/camel/impl/lw/LightweightCamelContext.java
@@ -53,7 +53,6 @@ import org.apache.camel.ValueHolder;
 import org.apache.camel.builder.AdviceWithRouteBuilder;
 import org.apache.camel.catalog.RuntimeCamelCatalog;
 import org.apache.camel.impl.DefaultCamelContext;
-import org.apache.camel.impl.engine.DefaultChannel;
 import org.apache.camel.impl.engine.DefaultRoute;
 import org.apache.camel.model.DataFormatDefinition;
 import org.apache.camel.model.FaultToleranceConfigurationDefinition;
@@ -1861,9 +1860,6 @@ public class LightweightCamelContext implements ExtendedCamelContext, CatalogCam
 
     private void clearModelReferences(Navigate<Processor> nav) {
         for (Processor processor : nav.next()) {
-            if (processor instanceof DefaultChannel) {
-                ((DefaultChannel) processor).clearModelReferences();
-            }
             if (processor instanceof Navigate) {
                 clearModelReferences((Navigate<Processor>) processor);
             }
diff --git a/core/camel-core/src/test/java/org/apache/camel/processor/RandomLoadBalanceJavaDSLBuilderTest.java b/core/camel-core/src/test/java/org/apache/camel/processor/RandomLoadBalanceJavaDSLBuilderTest.java
deleted file mode 100644
index 0bc0f6b..0000000
--- a/core/camel-core/src/test/java/org/apache/camel/processor/RandomLoadBalanceJavaDSLBuilderTest.java
+++ /dev/null
@@ -1,123 +0,0 @@
-/*
- * 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 java.util.List;
-
-import org.apache.camel.Navigate;
-import org.apache.camel.Processor;
-import org.apache.camel.Route;
-import org.apache.camel.impl.engine.DefaultChannel;
-import org.apache.camel.model.LoadBalanceDefinition;
-import org.apache.camel.model.ProcessorDefinition;
-import org.apache.camel.model.RouteDefinition;
-import org.apache.camel.model.SendDefinition;
-import org.apache.camel.model.loadbalancer.RandomLoadBalancerDefinition;
-import org.junit.jupiter.api.Test;
-
-import static org.junit.jupiter.api.Assertions.assertEquals;
-
-/**
- * A crude unit test to navigate the route and build a Java DSL from the route definition
- */
-public class RandomLoadBalanceJavaDSLBuilderTest extends RandomLoadBalanceTest {
-
-    @Test
-    public void testNavigateRouteAsJavaDSLWithNavigate() throws Exception {
-        // this one navigate using the runtime route using the
-        // Navigate<Processor>
-
-        StringBuilder sb = new StringBuilder();
-
-        Route route = context.getRoutes().get(0);
-
-        // the start of the route
-        sb.append("from(\"" + route.getEndpoint().getEndpointUri() + "\")");
-
-        // navigate the route and add Java DSL to the sb
-        Navigate<Processor> nav = route.navigate();
-        navigateRoute(nav, sb);
-
-        // output the Java DSL
-        assertEquals("from(\"direct://start\").loadBalance().random().to(\"mock://x\").to(\"mock://y\").to(\"mock://z\")",
-                sb.toString());
-    }
-
-    @Test
-    public void testNavigateRouteAsJavaDSL() throws Exception {
-        // this one navigate using the route definition
-
-        StringBuilder sb = new StringBuilder();
-
-        RouteDefinition route = context.getRouteDefinitions().get(0);
-
-        // the start of the route
-        sb.append("from(\"" + route.getInput().getUri() + "\")");
-
-        // navigate the route and add Java DSL to the sb
-        navigateDefinition(route, sb);
-
-        // output the Java DSL
-        assertEquals("from(\"direct://start\").loadBalance().random().to(\"mock://x\").to(\"mock://y\").to(\"mock://z\")",
-                sb.toString());
-    }
-
-    private void navigateRoute(Navigate<Processor> nav, StringBuilder sb) {
-        if (nav instanceof Pipeline) {
-            nav = (Navigate<Processor>) nav.next().get(0);
-        }
-
-        if (!nav.hasNext()) {
-            return;
-        }
-
-        if (nav instanceof DefaultChannel) {
-            DefaultChannel channel = (DefaultChannel) nav;
-            ProcessorDefinition<?> def = (ProcessorDefinition<?>) channel.getProcessorDefinition();
-            navigateDefinition(def, sb);
-        }
-    }
-
-    private void navigateDefinition(ProcessorDefinition<?> def, StringBuilder sb) {
-
-        // must do this ugly cast to avoid compiler error on HP-UX
-        ProcessorDefinition<?> defn = (ProcessorDefinition<?>) def;
-
-        if (defn instanceof LoadBalanceDefinition) {
-            sb.append(".loadBalance()");
-
-            LoadBalanceDefinition lbd = (LoadBalanceDefinition) defn;
-            if (lbd.getLoadBalancerType() instanceof RandomLoadBalancerDefinition) {
-                sb.append(".random()");
-            }
-        }
-
-        if (defn instanceof SendDefinition) {
-            SendDefinition<?> send = (SendDefinition<?>) defn;
-            sb.append(".to(\"" + send.getUri() + "\")");
-        }
-
-        List<ProcessorDefinition<?>> children = defn.getOutputs();
-        if (children == null || children.isEmpty()) {
-            return;
-        }
-
-        for (ProcessorDefinition<?> child : children) {
-            navigateDefinition(child, sb);
-        }
-    }
-}