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 2017/02/19 16:56:38 UTC

[2/3] camel git commit: camel-consul - route policy should have JMX api

camel-consul - route policy should have JMX api


Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/593dffec
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/593dffec
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/593dffec

Branch: refs/heads/master
Commit: 593dffecd7bad47739a7cbd319d14bb3e911038a
Parents: 53f6494
Author: Claus Ibsen <da...@apache.org>
Authored: Sun Feb 19 17:49:43 2017 +0100
Committer: Claus Ibsen <da...@apache.org>
Committed: Sun Feb 19 17:49:43 2017 +0100

----------------------------------------------------------------------
 .../consul/policy/ConsulRoutePolicy.java        | 38 ++++++++++++++++++--
 1 file changed, 36 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/593dffec/components/camel-consul/src/main/java/org/apache/camel/component/consul/policy/ConsulRoutePolicy.java
----------------------------------------------------------------------
diff --git a/components/camel-consul/src/main/java/org/apache/camel/component/consul/policy/ConsulRoutePolicy.java b/components/camel-consul/src/main/java/org/apache/camel/component/consul/policy/ConsulRoutePolicy.java
index 8723992..f0d3083 100644
--- a/components/camel-consul/src/main/java/org/apache/camel/component/consul/policy/ConsulRoutePolicy.java
+++ b/components/camel-consul/src/main/java/org/apache/camel/component/consul/policy/ConsulRoutePolicy.java
@@ -34,14 +34,16 @@ import com.orbitz.consul.model.session.ImmutableSession;
 import com.orbitz.consul.option.QueryOptions;
 import org.apache.camel.CamelContext;
 import org.apache.camel.CamelContextAware;
-import org.apache.camel.NonManagedService;
 import org.apache.camel.Route;
+import org.apache.camel.api.management.ManagedAttribute;
+import org.apache.camel.api.management.ManagedResource;
 import org.apache.camel.support.RoutePolicySupport;
 import org.apache.camel.util.ObjectHelper;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-public class ConsulRoutePolicy extends RoutePolicySupport implements NonManagedService, CamelContextAware {
+@ManagedResource(description = "Route policy using Consul as clustered lock")
+public class ConsulRoutePolicy extends RoutePolicySupport implements CamelContextAware {
     private static final Logger LOGGER = LoggerFactory.getLogger(ConsulRoutePolicy.class);
 
     private final Object lock;
@@ -52,6 +54,7 @@ public class ConsulRoutePolicy extends RoutePolicySupport implements NonManagedS
     private final Set<Route> suspendedRoutes;
     private final AtomicReference<BigInteger> index;
 
+    private Route route;
     private CamelContext camelContext;
     private String serviceName;
     private String servicePath;
@@ -94,6 +97,12 @@ public class ConsulRoutePolicy extends RoutePolicySupport implements NonManagedS
     }
 
     @Override
+    public void onInit(Route route) {
+        super.onInit(route);
+        this.route = route;
+    }
+
+    @Override
     public void onStart(Route route)  {
         if (!leader.get() && shouldStopConsumer) {
             stopConsumer(route);
@@ -213,10 +222,27 @@ public class ConsulRoutePolicy extends RoutePolicySupport implements NonManagedS
     // Getter/Setters
     // *************************************************************************
 
+    @ManagedAttribute(description = "The route id")
+    public String getRouteId() {
+        if (route != null) {
+            return route.getId();
+        }
+        return null;
+    }
+
+    @ManagedAttribute(description = "The consumer endpoint", mask = true)
+    public String getEndpointUrl() {
+        if (route != null && route.getConsumer() != null && route.getConsumer().getEndpoint() != null) {
+            return route.getConsumer().getEndpoint().toString();
+        }
+        return null;
+    }
+
     public Consul getConsul() {
         return consul;
     }
 
+    @ManagedAttribute(description = "The consul service name")
     public String getServiceName() {
         return serviceName;
     }
@@ -226,6 +252,7 @@ public class ConsulRoutePolicy extends RoutePolicySupport implements NonManagedS
         this.servicePath = String.format("/service/%s/leader", serviceName);
     }
 
+    @ManagedAttribute(description = "The time to live")
     public int getTtl() {
         return ttl;
     }
@@ -234,6 +261,7 @@ public class ConsulRoutePolicy extends RoutePolicySupport implements NonManagedS
         this.ttl = ttl > 10 ? ttl : 10;
     }
 
+    @ManagedAttribute(description = "The lock delay")
     public int getLockDelay() {
         return lockDelay;
     }
@@ -242,6 +270,7 @@ public class ConsulRoutePolicy extends RoutePolicySupport implements NonManagedS
         this.lockDelay = lockDelay > 10 ? lockDelay : 10;
     }
 
+    @ManagedAttribute(description = "Whether to stop consumer when starting up and failed to become master")
     public boolean isShouldStopConsumer() {
         return shouldStopConsumer;
     }
@@ -250,6 +279,11 @@ public class ConsulRoutePolicy extends RoutePolicySupport implements NonManagedS
         this.shouldStopConsumer = shouldStopConsumer;
     }
 
+    @ManagedAttribute(description = "Is this route the master or a slave")
+    public boolean isLeader() {
+        return leader.get();
+    }
+
     // *************************************************************************
     // Watch
     // *************************************************************************