camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject svn commit: r980881 - in /camel/trunk/camel-core/src: main/java/org/apache/camel/impl/ test/java/org/apache/camel/impl/ test/java/org/apache/camel/management/
Date Fri, 30 Jul 2010 16:21:27 GMT
Author: davsclaus
Date: Fri Jul 30 16:21:26 2010
New Revision: 980881

URL: http://svn.apache.org/viewvc?rev=980881&view=rev
Log:
CAMEL-3008: Routes with noAutoStartup will be warmed up and enlisted in JMX.

Added:
    camel/trunk/camel-core/src/test/java/org/apache/camel/management/ManagedRouteAutoStartupTest.java
      - copied, changed from r980821, camel/trunk/camel-core/src/test/java/org/apache/camel/management/ManagedCamelContextAutoStartupTest.java
Modified:
    camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java
    camel/trunk/camel-core/src/test/java/org/apache/camel/impl/GracefulShutdownNoAutoStartOrderClashTest.java

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java?rev=980881&r1=980880&r2=980881&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java Fri
Jul 30 16:21:26 2010
@@ -40,6 +40,7 @@ import org.apache.camel.Component;
 import org.apache.camel.Consumer;
 import org.apache.camel.ConsumerTemplate;
 import org.apache.camel.Endpoint;
+import org.apache.camel.FailedToCreateRouteException;
 import org.apache.camel.FailedToStartRouteException;
 import org.apache.camel.IsSingleton;
 import org.apache.camel.MultipleConsumersSupport;
@@ -1439,7 +1440,7 @@ public class DefaultCamelContext extends
 
         // figure out the order in which the routes should be started
         for (RouteService routeService : routeServices) {
-            DefaultRouteStartupOrder order = doPrepareRouteToBeStarted(routeService, forceAutoStart);
+            DefaultRouteStartupOrder order = doPrepareRouteToBeStarted(routeService);
             // check for clash before we add it as input
             if (order != null) {
                 if (checkClash && doCheckStartupOrderClash(order, inputs)) {
@@ -1471,32 +1472,18 @@ public class DefaultCamelContext extends
         safelyStartRouteServices(forceAutoStart, checkClash, startConsumer, Arrays.asList(routeServices));
     }
 
-    private DefaultRouteStartupOrder doPrepareRouteToBeStarted(RouteService routeService,
boolean forceAutoStart) throws Exception {
-        DefaultRouteStartupOrder answer = null;
-
-        Boolean autoStart = routeService.getRouteDefinition().isAutoStartup();
-        if (autoStart == null || autoStart || forceAutoStart) {
-            try {
-                // add the inputs from this route service to the list to start afterwards
-                // should be ordered according to the startup number
-                Integer startupOrder = routeService.getRouteDefinition().getStartupOrder();
-                if (startupOrder == null) {
-                    // auto assign a default startup order
-                    startupOrder = defaultRouteStartupOrder++;
-                }
-
-                // create holder object that contains information about this route to be
started
-                Route route = routeService.getRoutes().iterator().next();
-                answer = new DefaultRouteStartupOrder(startupOrder, route, routeService);
-            } catch (Exception e) {
-                throw new FailedToStartRouteException(e);
-            }
-        } else {
-            // should not start on startup
-            LOG.info("Cannot start route " + routeService.getId() + " as it is configured
with auto startup disabled.");
+    private DefaultRouteStartupOrder doPrepareRouteToBeStarted(RouteService routeService)
{
+        // add the inputs from this route service to the list to start afterwards
+        // should be ordered according to the startup number
+        Integer startupOrder = routeService.getRouteDefinition().getStartupOrder();
+        if (startupOrder == null) {
+            // auto assign a default startup order
+            startupOrder = defaultRouteStartupOrder++;
         }
 
-        return answer;
+        // create holder object that contains information about this route to be started
+        Route route = routeService.getRoutes().iterator().next();
+        return new DefaultRouteStartupOrder(startupOrder, route, routeService);
     }
 
     private boolean doCheckStartupOrderClash(DefaultRouteStartupOrder answer, Map<Integer,
DefaultRouteStartupOrder> inputs) throws FailedToStartRouteException {
@@ -1544,10 +1531,16 @@ public class DefaultCamelContext extends
         for (Map.Entry<Integer, DefaultRouteStartupOrder> entry : inputs.entrySet())
{
             Integer order = entry.getKey();
             Route route = entry.getValue().getRoute();
-
-            // start the service
             RouteService routeService = entry.getValue().getRouteService();
 
+            // if we are starting camel, then skip routes which are configured to not be
auto started
+            boolean autoStartup = routeService.getRouteDefinition().isAutoStartup();
+            if (isStarting() && !autoStartup) {
+                LOG.info("Cannot start route " + routeService.getId() + " as its configured
with autoStartup=false");
+                continue;
+            }
+
+            // start the service
             for (Consumer consumer : routeService.getInputs().values()) {
                 Endpoint endpoint = consumer.getEndpoint();
 
@@ -1589,7 +1582,7 @@ public class DefaultCamelContext extends
                 }
             }
 
-            // and start the route service (no need to start children as they are alredy
warmed up)
+            // and start the route service (no need to start children as they are already
warmed up)
             routeService.start(false);
         }
     }

Modified: camel/trunk/camel-core/src/test/java/org/apache/camel/impl/GracefulShutdownNoAutoStartOrderClashTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/impl/GracefulShutdownNoAutoStartOrderClashTest.java?rev=980881&r1=980880&r2=980881&view=diff
==============================================================================
--- camel/trunk/camel-core/src/test/java/org/apache/camel/impl/GracefulShutdownNoAutoStartOrderClashTest.java
(original)
+++ camel/trunk/camel-core/src/test/java/org/apache/camel/impl/GracefulShutdownNoAutoStartOrderClashTest.java
Fri Jul 30 16:21:26 2010
@@ -25,13 +25,21 @@ import org.apache.camel.builder.RouteBui
  */
 public class GracefulShutdownNoAutoStartOrderClashTest extends ContextTestSupport {
 
-    public void testStartupOrderClash() throws Exception {
-        getMockEndpoint("mock:foo").expectedMessageCount(1);
-        template.sendBody("direct:foo", "Hello World");
-        assertMockEndpointsSatisfied();
+    @Override
+    public boolean isUseRouteBuilder() {
+        return false;
+    }
 
+    public void testStartupOrderClash() throws Exception {
+        context.addRoutes(new RouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+                from("direct:foo").routeId("foo").startupOrder(5).to("mock:foo");
+                from("direct:bar").routeId("bar").startupOrder(5).noAutoStartup().to("mock:bar");
+            }
+        });
         try {
-            context.startRoute("bar");
+            context.start();
             fail("Should have thrown an exception");
         } catch (FailedToStartRouteException e) {
             assertEquals("Failed to start route bar because of startupOrder clash. Route
foo already has startupOrder 5 configured"
@@ -39,14 +47,4 @@ public class GracefulShutdownNoAutoStart
         }
     }
 
-    @Override
-    protected RouteBuilder createRouteBuilder() throws Exception {
-        return new RouteBuilder() {
-            @Override
-            public void configure() throws Exception {
-                from("direct:foo").routeId("foo").startupOrder(5).to("mock:foo");
-                from("direct:bar").routeId("bar").startupOrder(5).noAutoStartup().to("mock:bar");
-            }
-        };
-    }
 }

Copied: camel/trunk/camel-core/src/test/java/org/apache/camel/management/ManagedRouteAutoStartupTest.java
(from r980821, camel/trunk/camel-core/src/test/java/org/apache/camel/management/ManagedCamelContextAutoStartupTest.java)
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/management/ManagedRouteAutoStartupTest.java?p2=camel/trunk/camel-core/src/test/java/org/apache/camel/management/ManagedRouteAutoStartupTest.java&p1=camel/trunk/camel-core/src/test/java/org/apache/camel/management/ManagedCamelContextAutoStartupTest.java&r1=980821&r2=980881&rev=980881&view=diff
==============================================================================
--- camel/trunk/camel-core/src/test/java/org/apache/camel/management/ManagedCamelContextAutoStartupTest.java
(original)
+++ camel/trunk/camel-core/src/test/java/org/apache/camel/management/ManagedRouteAutoStartupTest.java
Fri Jul 30 16:21:26 2010
@@ -27,7 +27,7 @@ import org.apache.camel.impl.DefaultCame
 /**
  * @version $Revision$
  */
-public class ManagedCamelContextAutoStartupTest extends ContextTestSupport {
+public class ManagedRouteAutoStartupTest extends ContextTestSupport {
 
     @Override
     protected boolean useJmx() {
@@ -46,20 +46,23 @@ public class ManagedCamelContextAutoStar
         MBeanServer mbeanServer = context.getManagementStrategy().getManagementAgent().getMBeanServer();
 
         ObjectName on = ObjectName.getInstance("org.apache.camel:context=localhost/camel-1,type=context,name=\"camel-1\"");
-        ObjectName onRoute = ObjectName.getInstance("org.apache.camel:context=localhost/camel-1,type=routes,name=\"foo\"");
+        ObjectName onFoo = ObjectName.getInstance("org.apache.camel:context=localhost/camel-1,type=routes,name=\"foo\"");
+        ObjectName onBar = ObjectName.getInstance("org.apache.camel:context=localhost/camel-1,type=routes,name=\"bar\"");
 
         assertTrue("Should be registered", mbeanServer.isRegistered(on));
         String name = (String) mbeanServer.getAttribute(on, "CamelId");
         assertEquals("camel-1", name);
 
-        assertTrue("Should be registered", mbeanServer.isRegistered(onRoute));
-        String state = (String) mbeanServer.getAttribute(onRoute, "State");
+        String state = (String) mbeanServer.getAttribute(onFoo, "State");
         assertEquals("Stopped", state);
 
+        state = (String) mbeanServer.getAttribute(onBar, "State");
+        assertEquals("Started", state);
+
         // start the route
-        mbeanServer.invoke(onRoute, "start", null, null);
+        mbeanServer.invoke(onFoo, "start", null, null);
 
-        state = (String) mbeanServer.getAttribute(onRoute, "State");
+        state = (String) mbeanServer.getAttribute(onFoo, "State");
         assertEquals("Started", state);
 
         Object reply = mbeanServer.invoke(on, "requestBody", new Object[]{"direct:foo", "Hello
World"}, new String[]{"java.lang.String", "java.lang.String"});
@@ -74,9 +77,9 @@ public class ManagedCamelContextAutoStar
         return new RouteBuilder() {
             @Override
             public void configure() throws Exception {
-                context.setAutoStartup(false);
+                from("direct:bar").routeId("bar").to("mock:bar");
 
-                from("direct:foo").routeId("foo").transform(constant("Bye World"));
+                from("direct:foo").routeId("foo").noAutoStartup().transform(constant("Bye
World"));
             }
         };
     }



Mime
View raw message