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 2019/03/29 12:23:06 UTC

[camel] branch master updated: CAMEL-13118: Components should not depend on camel-core but camel-support

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


The following commit(s) were added to refs/heads/master by this push:
     new ab2b3df  CAMEL-13118: Components should not depend on camel-core but camel-support
ab2b3df is described below

commit ab2b3df32b1750122b8499f879ced5538e35761a
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Fri Mar 29 13:13:52 2019 +0100

    CAMEL-13118: Components should not depend on camel-core but camel-support
---
 components/camel-quartz2/pom.xml                   |  4 +---
 .../apache/camel/component/quartz2/CamelJob.java   | 14 ++++++++---
 .../camel/component/quartz2/QuartzEndpoint.java    | 27 ++++++++--------------
 3 files changed, 22 insertions(+), 23 deletions(-)

diff --git a/components/camel-quartz2/pom.xml b/components/camel-quartz2/pom.xml
index 1f3f3c2..20a6aac 100644
--- a/components/camel-quartz2/pom.xml
+++ b/components/camel-quartz2/pom.xml
@@ -33,11 +33,9 @@
     <description>Camel Quartz2 support</description>
 
     <dependencies>
-        <!-- TODO: try to fix this -->
-        <!-- core required: org.apache.camel.processor.loadbalancer -->
         <dependency>
             <groupId>org.apache.camel</groupId>
-            <artifactId>camel-core</artifactId>
+            <artifactId>camel-support</artifactId>
         </dependency>
         <dependency>
             <groupId>org.quartz-scheduler</groupId>
diff --git a/components/camel-quartz2/src/main/java/org/apache/camel/component/quartz2/CamelJob.java b/components/camel-quartz2/src/main/java/org/apache/camel/component/quartz2/CamelJob.java
index 08faa98..2f525d2 100644
--- a/components/camel-quartz2/src/main/java/org/apache/camel/component/quartz2/CamelJob.java
+++ b/components/camel-quartz2/src/main/java/org/apache/camel/component/quartz2/CamelJob.java
@@ -18,6 +18,7 @@ package org.apache.camel.component.quartz2;
 
 import java.util.Collection;
 
+import org.apache.camel.AsyncProcessor;
 import org.apache.camel.CamelContext;
 import org.apache.camel.CamelExchangeException;
 import org.apache.camel.DelegateEndpoint;
@@ -38,7 +39,6 @@ import org.slf4j.LoggerFactory;
 /**
  * This is a Quartz Job that is scheduled by QuartzEndpoint's Consumer and will call it to
  * produce a QuartzMessage sending to a route.
- *
  */
 public class CamelJob implements Job {
     private static final Logger LOG = LoggerFactory.getLogger(CamelJob.class);
@@ -55,7 +55,15 @@ public class CamelJob implements Job {
             QuartzEndpoint endpoint = lookupQuartzEndpoint(camelContext, context);
             exchange = endpoint.createExchange();
             exchange.setIn(new QuartzMessage(exchange, context));
-            endpoint.getConsumerLoadBalancer().process(exchange);
+
+            AsyncProcessor processor = endpoint.getProcessor();
+            try {
+                if (processor != null) {
+                    processor.process(exchange);
+                }
+            } catch (Throwable e) {
+                exchange.setException(e);
+            }
 
             if (exchange.getException() != null) {
                 throw new JobExecutionException(exchange.getException());
@@ -124,7 +132,7 @@ public class CamelJob implements Job {
         // fallback and lookup existing from registry (eg maybe a @Consume POJO with a quartz endpoint, and thus not from a route)
         String endpointUri = quartzContext.getMergedJobDataMap().getString(QuartzConstants.QUARTZ_ENDPOINT_URI);
         
-        QuartzEndpoint result = null;
+        QuartzEndpoint result;
 
         // Even though the same camelContext.getEndpoint call, but if/else display different log.
         if (camelContext.hasEndpoint(endpointUri) != null) {
diff --git a/components/camel-quartz2/src/main/java/org/apache/camel/component/quartz2/QuartzEndpoint.java b/components/camel-quartz2/src/main/java/org/apache/camel/component/quartz2/QuartzEndpoint.java
index e27c620..428b8d8 100644
--- a/components/camel-quartz2/src/main/java/org/apache/camel/component/quartz2/QuartzEndpoint.java
+++ b/components/camel-quartz2/src/main/java/org/apache/camel/component/quartz2/QuartzEndpoint.java
@@ -22,12 +22,11 @@ import java.util.TimeZone;
 import java.util.concurrent.atomic.AtomicBoolean;
 import java.util.concurrent.atomic.AtomicInteger;
 
+import org.apache.camel.AsyncProcessor;
 import org.apache.camel.Consumer;
 import org.apache.camel.Processor;
 import org.apache.camel.Producer;
 import org.apache.camel.Route;
-import org.apache.camel.processor.loadbalancer.LoadBalancer;
-import org.apache.camel.processor.loadbalancer.RoundRobinLoadBalancer;
 import org.apache.camel.spi.Metadata;
 import org.apache.camel.spi.UriEndpoint;
 import org.apache.camel.spi.UriParam;
@@ -58,7 +57,9 @@ import static org.quartz.SimpleScheduleBuilder.simpleSchedule;
 public class QuartzEndpoint extends DefaultEndpoint {
 
     private TriggerKey triggerKey;
-    private LoadBalancer consumerLoadBalancer;
+
+    private volatile AsyncProcessor processor;
+
     // An internal variables to track whether a job has been in scheduler or not, and has it paused or not.
     private final AtomicBoolean jobAdded = new AtomicBoolean(false);
     private final AtomicBoolean jobPaused = new AtomicBoolean(false);
@@ -217,18 +218,6 @@ public class QuartzEndpoint extends DefaultEndpoint {
         this.usingFixedCamelContextName = usingFixedCamelContextName;
     }
 
-    public LoadBalancer getConsumerLoadBalancer() {
-        if (consumerLoadBalancer == null) {
-            consumerLoadBalancer = new RoundRobinLoadBalancer();
-        }
-        return consumerLoadBalancer;
-    }
-
-    public void setConsumerLoadBalancer(LoadBalancer consumerLoadBalancer) {
-        this.consumerLoadBalancer = consumerLoadBalancer;
-    }
-
-
     public Map<String, Object> getTriggerParameters() {
         return triggerParameters;
     }
@@ -616,7 +605,7 @@ public class QuartzEndpoint extends DefaultEndpoint {
     }
 
     public void onConsumerStart(QuartzConsumer quartzConsumer) throws Exception {
-        getConsumerLoadBalancer().addProcessor(quartzConsumer.getAsyncProcessor());
+        this.processor = quartzConsumer.getAsyncProcessor();
         if (!jobAdded.get()) {
             addJobInScheduler();
         } else {
@@ -625,9 +614,13 @@ public class QuartzEndpoint extends DefaultEndpoint {
     }
 
     public void onConsumerStop(QuartzConsumer quartzConsumer) throws Exception {
-        getConsumerLoadBalancer().removeProcessor(quartzConsumer.getAsyncProcessor());
         if (jobAdded.get()) {
             pauseTrigger();
         }
+        this.processor = null;
+    }
+
+    AsyncProcessor getProcessor() {
+        return this.processor;
     }
 }