camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject svn commit: r810506 - in /camel/trunk/camel-core/src: main/java/org/apache/camel/impl/ main/java/org/apache/camel/management/ main/java/org/apache/camel/management/mbean/ main/java/org/apache/camel/spi/ test/java/org/apache/camel/impl/ test/java/org/ap...
Date Wed, 02 Sep 2009 13:54:41 GMT
Author: davsclaus
Date: Wed Sep  2 13:54:40 2009
New Revision: 810506

URL: http://svn.apache.org/viewvc?rev=810506&view=rev
Log:
CAMEL-1980: JMX. Route id is now displayed for consumers.

Modified:
    camel/trunk/camel-core/src/main/java/org/apache/camel/impl/RouteService.java
    camel/trunk/camel-core/src/main/java/org/apache/camel/management/DefaultManagementLifecycleStrategy.java
    camel/trunk/camel-core/src/main/java/org/apache/camel/management/mbean/ManagedConsumer.java
    camel/trunk/camel-core/src/main/java/org/apache/camel/management/mbean/ManagedScheduledPollConsumer.java
    camel/trunk/camel-core/src/main/java/org/apache/camel/spi/LifecycleStrategy.java
    camel/trunk/camel-core/src/test/java/org/apache/camel/impl/DummyLifecycleStrategy.java
    camel/trunk/camel-core/src/test/java/org/apache/camel/management/ManagedBrowseableEndpointTest.java
    camel/trunk/camel-core/src/test/java/org/apache/camel/management/ManagedScheduledPollConsumerTest.java
    camel/trunk/camel-core/src/test/java/org/apache/camel/management/ManagedUnregisterConsumerTest.java

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/impl/RouteService.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/RouteService.java?rev=810506&r1=810505&r2=810506&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/impl/RouteService.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/impl/RouteService.java Wed Sep 
2 13:54:40 2009
@@ -21,6 +21,7 @@
 import java.util.List;
 
 import org.apache.camel.CamelContext;
+import org.apache.camel.Consumer;
 import org.apache.camel.Navigate;
 import org.apache.camel.Route;
 import org.apache.camel.Service;
@@ -98,7 +99,8 @@
             for (Service service : services) {
                 doGetChildServies(list, service);
             }
-            startChildService(list);
+
+            startChildService(route, list);
 
             // start the route itself
             ServiceHelper.startService(route);
@@ -125,7 +127,7 @@
             for (Service service : services) {
                 doGetChildServies(list, service);
             }
-            stopChildService(list);
+            stopChildService(route, list);
 
             // stop the route itself
             ServiceHelper.stopService(route);
@@ -137,20 +139,34 @@
         camelContext.removeRouteCollection(routes);
     }
 
-    protected void startChildService(List<Service> services) throws Exception {
+    protected void startChildService(Route route, List<Service> services) throws Exception
{
+        boolean first = true;
         for (Service service : services) {
             for (LifecycleStrategy strategy : camelContext.getLifecycleStrategies()) {
-                strategy.onServiceAdd(camelContext, service);
+                // the first one is the input consumer
+                if (first && service instanceof Consumer) {
+                    strategy.onRouteConsumerAdd(route, (Consumer) service);
+                } else {
+                    strategy.onServiceAdd(camelContext, service);
+                    first = false;
+                }
             }
             ServiceHelper.startService(service);
             addChildService(service);
         }
     }
 
-    protected void stopChildService(List<Service> services) throws Exception {
+    protected void stopChildService(Route route, List<Service> services) throws Exception
{
+        boolean first = true;
         for (Service service : services) {
             for (LifecycleStrategy strategy : camelContext.getLifecycleStrategies()) {
-                strategy.onServiceRemove(camelContext, service);
+                // the first one is the input consumer
+                if (first && service instanceof Consumer) {
+                    strategy.onRouteConsumerRemove(route, (Consumer) service);
+                } else {
+                    strategy.onServiceRemove(camelContext, service);
+                    first = false;
+                }
             }
             ServiceHelper.stopService(service);
             removeChildService(service);

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/management/DefaultManagementLifecycleStrategy.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/management/DefaultManagementLifecycleStrategy.java?rev=810506&r1=810505&r2=810506&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/management/DefaultManagementLifecycleStrategy.java
(original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/management/DefaultManagementLifecycleStrategy.java
Wed Sep  2 13:54:40 2009
@@ -255,7 +255,7 @@
         } else if (service instanceof Producer) {
             return new ManagedProducer(context, (Producer) service);
         } else if (service instanceof ScheduledPollConsumer) {
-                return new ManagedScheduledPollConsumer(context, (ScheduledPollConsumer)
service);
+            return new ManagedScheduledPollConsumer(context, (ScheduledPollConsumer) service);
         } else if (service instanceof Consumer) {
             return new ManagedConsumer(context, (Consumer) service);
         } else if (service instanceof Processor) {
@@ -307,6 +307,48 @@
         return new ManagedProcessor(context, processor, definition);
     }
 
+    public void onRouteConsumerAdd(Route route, Consumer consumer) {
+        // the agent hasn't been started
+        if (!initialized) {
+            return;
+        }
+
+        Object managedObject;
+        if (consumer instanceof ManagementAware) {
+            managedObject = ((ManagementAware) consumer).getManagedObject(consumer);
+        } else if (consumer instanceof ScheduledPollConsumer) {
+            managedObject = new ManagedScheduledPollConsumer(route.getRouteContext().getCamelContext(),
(ScheduledPollConsumer) consumer, route);
+        } else {
+            managedObject = new ManagedConsumer(route.getRouteContext().getCamelContext(),
consumer, route);
+        }
+        try {
+            getStrategy().manageObject(managedObject);
+        } catch (Exception e) {
+            LOG.warn("Could not register consumer MBean.", e);
+        }
+    }
+
+    public void onRouteConsumerRemove(Route route, Consumer consumer) {
+        // the agent hasn't been started
+        if (!initialized) {
+            return;
+        }
+
+        Object managedObject;
+        if (consumer instanceof ManagementAware) {
+            managedObject = ((ManagementAware) consumer).getManagedObject(consumer);
+        } else if (consumer instanceof ScheduledPollConsumer) {
+            managedObject = new ManagedScheduledPollConsumer(route.getRouteContext().getCamelContext(),
(ScheduledPollConsumer) consumer, route);
+        } else {
+            managedObject = new ManagedConsumer(route.getRouteContext().getCamelContext(),
consumer, route);
+        }
+        try {
+            getStrategy().unmanageObject(managedObject);
+        } catch (Exception e) {
+            LOG.warn("Could not register consumer MBean.", e);
+        }
+    }
+
     public void onRoutesAdd(Collection<Route> routes) {
         // the agent hasn't been started
         if (!initialized) {

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/management/mbean/ManagedConsumer.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/management/mbean/ManagedConsumer.java?rev=810506&r1=810505&r2=810506&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/management/mbean/ManagedConsumer.java
(original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/management/mbean/ManagedConsumer.java
Wed Sep  2 13:54:40 2009
@@ -18,6 +18,7 @@
 
 import org.apache.camel.CamelContext;
 import org.apache.camel.Consumer;
+import org.apache.camel.Route;
 import org.springframework.jmx.export.annotation.ManagedAttribute;
 import org.springframework.jmx.export.annotation.ManagedResource;
 
@@ -27,20 +28,38 @@
 @ManagedResource(description = "Managed Consumer")
 public class ManagedConsumer extends ManagedService {
 
-    private Consumer consumer;
+    private final Consumer consumer;
+    private final Route route;
 
     public ManagedConsumer(CamelContext context, Consumer consumer) {
+        this(context, consumer, null);
+    }
+
+    public ManagedConsumer(CamelContext context, Consumer consumer, Route route) {
         super(context, consumer);
         this.consumer = consumer;
+        this.route = route;
     }
 
     public Consumer getConsumer() {
         return consumer;
     }
 
+    public Route getRoute() {
+        return route;
+    }
+
     @ManagedAttribute(description = "Endpoint Uri")
     public String getEndpointUri() {
         return consumer.getEndpoint().getEndpointUri();
     }
 
+    @ManagedAttribute(description = "Route id")
+    public String getRouteId() {
+        if (route != null) {
+            return route.getId();
+        }
+        return null;
+    }
+
 }

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/management/mbean/ManagedScheduledPollConsumer.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/management/mbean/ManagedScheduledPollConsumer.java?rev=810506&r1=810505&r2=810506&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/management/mbean/ManagedScheduledPollConsumer.java
(original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/management/mbean/ManagedScheduledPollConsumer.java
Wed Sep  2 13:54:40 2009
@@ -19,6 +19,7 @@
 import java.util.concurrent.TimeUnit;
 
 import org.apache.camel.CamelContext;
+import org.apache.camel.Route;
 import org.apache.camel.impl.ScheduledPollConsumer;
 import org.springframework.jmx.export.annotation.ManagedAttribute;
 import org.springframework.jmx.export.annotation.ManagedResource;
@@ -36,6 +37,11 @@
         this.consumer = consumer;
     }
 
+    public ManagedScheduledPollConsumer(CamelContext context, ScheduledPollConsumer consumer,
Route route) {
+        super(context, consumer, route);
+        this.consumer = consumer;
+    }
+
     public ScheduledPollConsumer getConsumer() {
         return consumer;
     }

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/spi/LifecycleStrategy.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/spi/LifecycleStrategy.java?rev=810506&r1=810505&r2=810506&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/spi/LifecycleStrategy.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/spi/LifecycleStrategy.java Wed Sep
 2 13:54:40 2009
@@ -20,14 +20,13 @@
 
 import org.apache.camel.CamelContext;
 import org.apache.camel.Component;
+import org.apache.camel.Consumer;
 import org.apache.camel.Endpoint;
 import org.apache.camel.Route;
 import org.apache.camel.Service;
 
 /**
  * Strategy for lifecycle notifications.
- * <p/>
- * <b>Node:</b> Subject to change in Camel 2.1
  */
 public interface LifecycleStrategy {
 
@@ -84,6 +83,16 @@
     void onServiceAdd(CamelContext context, Service service);
 
     /**
+     * Notification on adding a {@link Consumer} as input to a given {@link Route}
+     *
+     * @param route
+     * @param consumer      the consumer
+     */
+    void onRouteConsumerAdd(Route route, Consumer consumer);
+
+    void onRouteConsumerRemove(Route route, Consumer consumer);
+
+    /**
      * Notification on removing a {@link Service}.
      *
      * @param context the camel context

Modified: camel/trunk/camel-core/src/test/java/org/apache/camel/impl/DummyLifecycleStrategy.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/impl/DummyLifecycleStrategy.java?rev=810506&r1=810505&r2=810506&view=diff
==============================================================================
--- camel/trunk/camel-core/src/test/java/org/apache/camel/impl/DummyLifecycleStrategy.java
(original)
+++ camel/trunk/camel-core/src/test/java/org/apache/camel/impl/DummyLifecycleStrategy.java
Wed Sep  2 13:54:40 2009
@@ -22,6 +22,7 @@
 
 import org.apache.camel.CamelContext;
 import org.apache.camel.Component;
+import org.apache.camel.Consumer;
 import org.apache.camel.Endpoint;
 import org.apache.camel.Route;
 import org.apache.camel.Service;
@@ -67,6 +68,14 @@
         events.add("onServiceRemove");
     }
 
+    public void onRouteConsumerAdd(Route route, Consumer consumer) {
+        events.add("onRouteConsumerAdd");
+    }
+
+    public void onRouteConsumerRemove(Route route, Consumer consumer) {
+        events.add("onRouteConsumerRemove");
+    }
+
     public void onRoutesAdd(Collection<Route> routes) {
         events.add("onRoutesAdd");
     }

Modified: camel/trunk/camel-core/src/test/java/org/apache/camel/management/ManagedBrowseableEndpointTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/management/ManagedBrowseableEndpointTest.java?rev=810506&r1=810505&r2=810506&view=diff
==============================================================================
--- camel/trunk/camel-core/src/test/java/org/apache/camel/management/ManagedBrowseableEndpointTest.java
(original)
+++ camel/trunk/camel-core/src/test/java/org/apache/camel/management/ManagedBrowseableEndpointTest.java
Wed Sep  2 13:54:40 2009
@@ -56,11 +56,11 @@
 
         String out = (String) mbeanServer.invoke(name, "browseExchange", new Object[]{0},
new String[]{"java.lang.Integer"});
         assertNotNull(out);
-        assertTrue(out.contains("Hello World") );
+        assertTrue(out.contains("Hello World"));
 
         out = (String) mbeanServer.invoke(name, "browseExchange", new Object[]{1}, new String[]{"java.lang.Integer"});
         assertNotNull(out);
-        assertTrue(out.contains("Bye World") );
+        assertTrue(out.contains("Bye World"));
     }
 
     @Override

Modified: camel/trunk/camel-core/src/test/java/org/apache/camel/management/ManagedScheduledPollConsumerTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/management/ManagedScheduledPollConsumerTest.java?rev=810506&r1=810505&r2=810506&view=diff
==============================================================================
--- camel/trunk/camel-core/src/test/java/org/apache/camel/management/ManagedScheduledPollConsumerTest.java
(original)
+++ camel/trunk/camel-core/src/test/java/org/apache/camel/management/ManagedScheduledPollConsumerTest.java
Wed Sep  2 13:54:40 2009
@@ -55,6 +55,9 @@
         Long delay = (Long) mbeanServer.getAttribute(on, "Delay");
         assertEquals(4000, delay.longValue());
 
+        String routeId = (String) mbeanServer.getAttribute(on, "RouteId");
+        assertEquals("route1", routeId);
+
         // stop it
         mbeanServer.invoke(on, "stop", null, null);
 

Modified: camel/trunk/camel-core/src/test/java/org/apache/camel/management/ManagedUnregisterConsumerTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/management/ManagedUnregisterConsumerTest.java?rev=810506&r1=810505&r2=810506&view=diff
==============================================================================
--- camel/trunk/camel-core/src/test/java/org/apache/camel/management/ManagedUnregisterConsumerTest.java
(original)
+++ camel/trunk/camel-core/src/test/java/org/apache/camel/management/ManagedUnregisterConsumerTest.java
Wed Sep  2 13:54:40 2009
@@ -51,6 +51,9 @@
         String uri = (String) mbeanServer.getAttribute(on, "EndpointUri");
         assertEquals("direct://start", uri);
 
+        String routeId = (String) mbeanServer.getAttribute(on, "RouteId");
+        assertEquals("route1", routeId);
+
         context.stop();
 
         assertFalse("Should no longer be registered", mbeanServer.isRegistered(on));



Mime
View raw message