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/12/10 09:07:14 UTC

[camel] branch master updated: CAMEL-15903: camel-master - Log exception if error with leaderhip taken/lost

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 02df9ca  CAMEL-15903: camel-master - Log exception if error with leaderhip taken/lost
02df9ca is described below

commit 02df9ca76ba26284e1c3036f53fdce894d40a3d0
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Thu Dec 10 10:06:41 2020 +0100

    CAMEL-15903: camel-master - Log exception if error with leaderhip taken/lost
---
 .../camel/component/master/MasterConsumer.java     | 24 ++++++++++++----------
 1 file changed, 13 insertions(+), 11 deletions(-)

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 665ce9e..0bc7995 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
@@ -21,7 +21,6 @@ import java.util.Optional;
 import org.apache.camel.Consumer;
 import org.apache.camel.Endpoint;
 import org.apache.camel.Processor;
-import org.apache.camel.RuntimeCamelException;
 import org.apache.camel.StartupListener;
 import org.apache.camel.SuspendableService;
 import org.apache.camel.api.management.ManagedAttribute;
@@ -106,9 +105,7 @@ public class MasterConsumer extends DefaultConsumer {
 
     @ManagedAttribute(description = "Are we the master")
     public boolean isMaster() {
-        return view != null
-                ? view.getLocalMember().isLeader()
-                : false;
+        return view != null && view.getLocalMember().isLeader();
     }
 
     // **************************************
@@ -132,7 +129,7 @@ public class MasterConsumer extends DefaultConsumer {
         ServiceHelper.startService(delegatedEndpoint);
         ServiceHelper.startService(delegatedConsumer);
 
-        LOG.info("Leadership taken: consumer started: {}", delegatedEndpoint);
+        LOG.info("Leadership taken. Consumer started: {}", delegatedEndpoint);
     }
 
     private synchronized void onLeadershipLost() throws Exception {
@@ -141,7 +138,7 @@ public class MasterConsumer extends DefaultConsumer {
 
         delegatedConsumer = null;
 
-        LOG.info("Leadership lost: consumer stopped: {}", delegatedEndpoint);
+        LOG.info("Leadership lost. Consumer stopped: {}", delegatedEndpoint);
     }
 
     // **************************************
@@ -155,14 +152,19 @@ public class MasterConsumer extends DefaultConsumer {
                 return;
             }
 
-            try {
-                if (view.getLocalMember().isLeader()) {
+            if (view.getLocalMember().isLeader()) {
+                try {
                     onLeadershipTaken();
-                } else if (delegatedConsumer != null) {
+                } catch (Exception e) {
+                    getExceptionHandler().handleException("Error starting consumer while taking leadership", e);
+                }
+            } else if (delegatedConsumer != null) {
+                try {
                     onLeadershipLost();
+                } catch (Exception e) {
+                    getExceptionHandler()
+                            .handleException("Error stopping consumer while loosing leadership. This exception is ignored.", e);
                 }
-            } catch (Exception e) {
-                throw RuntimeCamelException.wrapRuntimeCamelException(e);
             }
         }
     }