camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject svn commit: r815376 - in /camel/trunk: camel-core/src/main/java/org/apache/camel/ camel-core/src/main/java/org/apache/camel/impl/ camel-core/src/main/java/org/apache/camel/model/ camel-core/src/test/java/org/apache/camel/processor/ components/camel-spr...
Date Tue, 15 Sep 2009 15:55:06 GMT
Author: davsclaus
Date: Tue Sep 15 15:55:05 2009
New Revision: 815376

URL: http://svn.apache.org/viewvc?rev=815376&view=rev
Log:
CAMEL-1473: Routes can be set to not auto start.

Added:
    camel/trunk/camel-core/src/test/java/org/apache/camel/processor/RouteNoAutoStartupTest.java
  (with props)
    camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/processor/SpringRouteNoAutoStartupTest.java
      - copied, changed from r815301, camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/processor/SpringAggregatorTest.java
    camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/RouteNoAutoStartupTest.xml
      - copied, changed from r815301, camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/aopafter.xml
Modified:
    camel/trunk/camel-core/src/main/java/org/apache/camel/RuntimeConfiguration.java
    camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java
    camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultRouteContext.java
    camel/trunk/camel-core/src/main/java/org/apache/camel/model/RouteDefinition.java

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/RuntimeConfiguration.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/RuntimeConfiguration.java?rev=815376&r1=815375&r2=815376&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/RuntimeConfiguration.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/RuntimeConfiguration.java Tue Sep
15 15:55:05 2009
@@ -89,4 +89,22 @@
      */
     Long getDelayer();
 
+    /**
+     * Sets whether it should automatic start when Camel starts.
+     * <p/>
+     * Currently only routes can be disabled, as {@link CamelContext} itself are always started}
+     * <br/>
+     * Default is true to always startup.
+     *
+     * @param autoStartup  whether to auto startup.
+     */
+    void setAutoStartup(Boolean autoStartup);
+
+    /**
+     * Gets whether it should automatic start when Camel starts.
+     *
+     * @return true if should auto start
+     */
+    boolean isAutoStartup();
+
 }

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=815376&r1=815375&r2=815376&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 Tue
Sep 15 15:55:05 2009
@@ -838,7 +838,13 @@
         // starting routes is done after, not during context startup
         synchronized (this) {
             for (RouteService routeService : routeServices.values()) {
-                routeService.start();
+                Boolean autoStart = routeService.getRouteDefinition().isAutoStartup();
+                if (autoStart == null || autoStart) {
+                    routeService.start();
+                } else {
+                    // should not start on startup
+                    LOG.info("Cannot start route " + routeService.getId() + " as it is configured
with auto startup disabled.");
+                }
             }
         }
         if (LOG.isDebugEnabled()) {
@@ -1005,9 +1011,7 @@
         ServiceStatus status = getRouteStatus(key);
 
         if (status != null && status.isStarted()) {
-            // already started, then stop it
             LOG.debug("Route " + key + " is already started");
-            return;
         } else {
             routeServices.put(key, routeService);
             if (shouldStartRoutes()) {
@@ -1216,6 +1220,15 @@
         this.inflightRepository = repository;
     }
 
+    public void setAutoStartup(Boolean autoStartup) {
+        // noop as Camel always starts up
+    }
+
+    public boolean isAutoStartup() {
+        // Camel always starts up
+        return true;
+    }
+
     protected String getEndpointKey(String uri, Endpoint endpoint) {
         if (endpoint.isSingleton()) {
             return uri;

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultRouteContext.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultRouteContext.java?rev=815376&r1=815375&r2=815376&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultRouteContext.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultRouteContext.java Tue
Sep 15 15:55:05 2009
@@ -55,6 +55,7 @@
     private Boolean stramCache;
     private Boolean handleFault;
     private Long delay;
+    private Boolean autoStartup = Boolean.TRUE;
 
     public DefaultRouteContext(RouteDefinition route, FromDefinition from, Collection<Route>
routes) {
         this.route = route;
@@ -241,6 +242,18 @@
         }
     }
 
+    public void setAutoStartup(Boolean autoStartup) {
+        this.autoStartup = autoStartup;
+    }
+
+    public boolean isAutoStartup() {
+        if (autoStartup != null) {
+            return autoStartup;
+        }
+        // default to true
+        return true;
+    }
+
     public DataFormatDefinition getDataFormat(String ref) {
         Map<String, DataFormatDefinition> dataFormats = getCamelContext().getDataFormats();
         if (dataFormats != null) {

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/model/RouteDefinition.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/model/RouteDefinition.java?rev=815376&r1=815375&r2=815376&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/model/RouteDefinition.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/model/RouteDefinition.java Tue Sep
15 15:55:05 2009
@@ -60,6 +60,7 @@
     private Boolean trace;
     private Boolean handleFault;
     private Long delayer;
+    private Boolean autoStartup = Boolean.TRUE;
 
     public RouteDefinition() {
     }
@@ -285,6 +286,14 @@
         return this;
     }
 
+    /**
+     * Disables this route from being auto started when Camel starts.
+     */
+    public RouteDefinition noAutoStartup() {
+        setAutoStartup(Boolean.FALSE);
+        return this;
+    }
+
     // Properties
     // -----------------------------------------------------------------------
 
@@ -372,10 +381,19 @@
         this.delayer = delayer;
     }
 
+    public Boolean isAutoStartup() {
+        return autoStartup;
+    }
+
+    @XmlAttribute
+    public void setAutoStartup(Boolean autoStartup) {
+        this.autoStartup = autoStartup;
+    }
+
     /**
      * Sets the bean ref name of the error handler builder to use on this route
      */
-    @XmlAttribute(required = false)
+    @XmlAttribute
     public void setErrorHandlerRef(String errorHandlerRef) {
         this.errorHandlerRef = errorHandlerRef;
         // we use an specific error handler ref (from Spring DSL) then wrap that
@@ -458,6 +476,11 @@
             }
         }
 
+        // configure auto startup
+        if (autoStartup != null) {
+            routeContext.setAutoStartup(isAutoStartup());
+        }
+
         // should inherit the intercept strategies we have defined
         routeContext.setInterceptStrategies(this.getInterceptStrategies());
         // force endpoint resolution

Added: camel/trunk/camel-core/src/test/java/org/apache/camel/processor/RouteNoAutoStartupTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/RouteNoAutoStartupTest.java?rev=815376&view=auto
==============================================================================
--- camel/trunk/camel-core/src/test/java/org/apache/camel/processor/RouteNoAutoStartupTest.java
(added)
+++ camel/trunk/camel-core/src/test/java/org/apache/camel/processor/RouteNoAutoStartupTest.java
Tue Sep 15 15:55:05 2009
@@ -0,0 +1,68 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.processor;
+
+import org.apache.camel.ContextTestSupport;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+
+/**
+ * @version $Revision$
+ */
+public class RouteNoAutoStartupTest extends ContextTestSupport {
+
+    public void testRouteNotAutoStarted() throws Exception {
+        MockEndpoint mock = getMockEndpoint("mock:result");
+        mock.expectedMessageCount(0);
+
+        template.sendBody("direct:start", "Hello World");
+
+        Thread.sleep(1000);
+
+        assertMockEndpointsSatisfied();
+    }
+
+    public void testRouteNotAutoStartedThenStarted() throws Exception {
+        MockEndpoint mock = getMockEndpoint("mock:result");
+        mock.expectedMessageCount(0);
+
+        template.sendBody("direct:start", "Hello World");
+
+        Thread.sleep(1000);
+
+        assertMockEndpointsSatisfied();
+
+        mock.reset();
+        mock.expectedMessageCount(1);
+
+        context.startRoute("myRoute");
+
+        assertMockEndpointsSatisfied();
+    }
+
+    @Override
+    protected RouteBuilder createRouteBuilder() throws Exception {
+        return new RouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+                from("direct:start").to("seda:foo");
+
+                from("seda:foo").noAutoStartup().id("myRoute").to("mock:result");
+            }
+        };
+    }
+}

Propchange: camel/trunk/camel-core/src/test/java/org/apache/camel/processor/RouteNoAutoStartupTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: camel/trunk/camel-core/src/test/java/org/apache/camel/processor/RouteNoAutoStartupTest.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Copied: camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/processor/SpringRouteNoAutoStartupTest.java
(from r815301, camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/processor/SpringAggregatorTest.java)
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/processor/SpringRouteNoAutoStartupTest.java?p2=camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/processor/SpringRouteNoAutoStartupTest.java&p1=camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/processor/SpringAggregatorTest.java&r1=815301&r2=815376&rev=815376&view=diff
==============================================================================
--- camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/processor/SpringAggregatorTest.java
(original)
+++ camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/processor/SpringRouteNoAutoStartupTest.java
Tue Sep 15 15:55:05 2009
@@ -17,14 +17,15 @@
 package org.apache.camel.spring.processor;
 
 import org.apache.camel.CamelContext;
-import org.apache.camel.processor.AggregatorTest;
+import org.apache.camel.processor.RouteNoAutoStartupTest;
 import static org.apache.camel.spring.processor.SpringTestHelper.createSpringCamelContext;
 
 /**
  * @version $Revision$
  */
-public class SpringAggregatorTest extends AggregatorTest {
+public class SpringRouteNoAutoStartupTest extends RouteNoAutoStartupTest {
+
     protected CamelContext createCamelContext() throws Exception {
-        return createSpringCamelContext(this, "org/apache/camel/spring/processor/aggregator.xml");
+        return createSpringCamelContext(this, "org/apache/camel/spring/processor/RouteNoAutoStartupTest.xml");
     }
 }
\ No newline at end of file

Copied: camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/RouteNoAutoStartupTest.xml
(from r815301, camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/aopafter.xml)
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/RouteNoAutoStartupTest.xml?p2=camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/RouteNoAutoStartupTest.xml&p1=camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/aopafter.xml&r1=815301&r2=815376&rev=815376&view=diff
==============================================================================
--- camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/aopafter.xml
(original)
+++ camel/trunk/components/camel-spring/src/test/resources/org/apache/camel/spring/processor/RouteNoAutoStartupTest.xml
Tue Sep 15 15:55:05 2009
@@ -22,16 +22,18 @@
        http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd
     ">
 
-    <!-- START SNIPPET: e1 -->
     <camelContext id="camel" xmlns="http://camel.apache.org/schema/spring">
         <route>
             <from uri="direct:start"/>
-            <aop afterUri="mock:after">
-                <transform><constant>Bye World</constant></transform>
-                <to uri="mock:result"/>
-            </aop>
+            <to uri="seda:foo"/>
         </route>
+
+        <!-- START SNIPPET: e1 -->
+        <route autoStartup="false" id="myRoute">
+            <from uri="seda:foo"/>
+            <to uri="mock:result"/>
+        </route>
+        <!-- END SNIPPET: e1 -->
     </camelContext>
-    <!-- END SNIPPET: e1 -->
 
 </beans>



Mime
View raw message