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 f825286  CAMEL-15903: Polished
f825286 is described below

commit f8252862ba4a2d14daa435b7bb3f93d3a025829e
Author: Claus Ibsen <[email protected]>
AuthorDate: Thu Dec 10 10:19:41 2020 +0100

    CAMEL-15903: Polished
---
 .../apache/camel/component/master/MasterComponent.java | 18 ++++++------------
 .../apache/camel/component/master/MasterConsumer.java  | 11 ++++-------
 .../apache/camel/component/master/MasterEndpoint.java  |  3 +--
 3 files changed, 11 insertions(+), 21 deletions(-)

diff --git 
a/components/camel-master/src/main/java/org/apache/camel/component/master/MasterComponent.java
 
b/components/camel-master/src/main/java/org/apache/camel/component/master/MasterComponent.java
index f4b71ba..1e1e7e5 100644
--- 
a/components/camel-master/src/main/java/org/apache/camel/component/master/MasterComponent.java
+++ 
b/components/camel-master/src/main/java/org/apache/camel/component/master/MasterComponent.java
@@ -48,7 +48,6 @@ public class MasterComponent extends DefaultComponent {
 
     public MasterComponent(CamelContext context) {
         super(context);
-
         this.serviceSelector = ClusterServiceSelectors.DEFAULT_SELECTOR;
     }
 
@@ -70,7 +69,7 @@ public class MasterComponent extends DefaultComponent {
         return new MasterEndpoint(
                 uri,
                 this,
-                getClusterService(),
+                service,
                 namespace,
                 delegateUri);
     }
@@ -104,20 +103,15 @@ public class MasterComponent extends DefaultComponent {
         this.serviceSelector = serviceSelector;
     }
 
-    // ********************************
-    // Helpers
-    // ********************************
+    @Override
+    protected void doInit() throws Exception {
+        CamelContext context = getCamelContext();
+        ObjectHelper.notNull(context, "Camel Context");
 
-    private CamelClusterService getClusterService() throws Exception {
         if (service == null) {
-            CamelContext context = getCamelContext();
-
-            ObjectHelper.notNull(context, "Camel Context");
-
             service = ClusterServiceHelper.lookupService(context, 
serviceSelector).orElseThrow(
                     () -> new IllegalStateException("No cluster service 
found"));
         }
-
-        return service;
     }
+
 }
diff --git 
a/components/camel-master/src/main/java/org/apache/camel/component/master/MasterConsumer.java
 
b/components/camel-master/src/main/java/org/apache/camel/component/master/MasterConsumer.java
index 0bc7995..d84b743 100644
--- 
a/components/camel-master/src/main/java/org/apache/camel/component/master/MasterConsumer.java
+++ 
b/components/camel-master/src/main/java/org/apache/camel/component/master/MasterConsumer.java
@@ -46,7 +46,7 @@ public class MasterConsumer extends DefaultConsumer {
     private final Endpoint delegatedEndpoint;
     private final Processor processor;
     private final CamelClusterEventListener.Leadership leadershipListener;
-    private Consumer delegatedConsumer;
+    private volatile Consumer delegatedConsumer;
     private volatile CamelClusterView view;
 
     public MasterConsumer(MasterEndpoint masterEndpoint, Processor processor, 
CamelClusterService clusterService) {
@@ -81,8 +81,7 @@ public class MasterConsumer extends DefaultConsumer {
             view = null;
         }
 
-        ServiceHelper.stopAndShutdownServices(delegatedConsumer);
-        ServiceHelper.stopAndShutdownServices(delegatedEndpoint);
+        ServiceHelper.stopAndShutdownServices(delegatedConsumer, 
delegatedEndpoint);
 
         delegatedConsumer = null;
     }
@@ -126,15 +125,13 @@ public class MasterConsumer extends DefaultConsumer {
             
getEndpoint().getCamelContext().addStartupListener((StartupListener) 
delegatedConsumer);
         }
 
-        ServiceHelper.startService(delegatedEndpoint);
-        ServiceHelper.startService(delegatedConsumer);
+        ServiceHelper.startService(delegatedEndpoint, delegatedConsumer);
 
         LOG.info("Leadership taken. Consumer started: {}", delegatedEndpoint);
     }
 
     private synchronized void onLeadershipLost() throws Exception {
-        ServiceHelper.stopAndShutdownServices(delegatedConsumer);
-        ServiceHelper.stopAndShutdownServices(delegatedEndpoint);
+        ServiceHelper.stopAndShutdownServices(delegatedConsumer, 
delegatedEndpoint);
 
         delegatedConsumer = null;
 
diff --git 
a/components/camel-master/src/main/java/org/apache/camel/component/master/MasterEndpoint.java
 
b/components/camel-master/src/main/java/org/apache/camel/component/master/MasterEndpoint.java
index 3ce7322..4286327 100644
--- 
a/components/camel-master/src/main/java/org/apache/camel/component/master/MasterEndpoint.java
+++ 
b/components/camel-master/src/main/java/org/apache/camel/component/master/MasterEndpoint.java
@@ -34,8 +34,7 @@ import org.apache.camel.support.DefaultEndpoint;
  * Have only a single consumer in a cluster consuming from a given endpoint; 
with automatic failover if the JVM dies.
  */
 @ManagedResource(description = "Managed Master Endpoint")
-@UriEndpoint(
-             firstVersion = "2.20.0",
+@UriEndpoint(firstVersion = "2.20.0",
              scheme = "master",
              syntax = "master:namespace:delegateUri",
              consumerOnly = true,

Reply via email to