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 2014/08/18 09:50:50 UTC
[5/6] git commit: CAMEL-7714: AdviceWith - Does not honor autoStartup
option
CAMEL-7714: AdviceWith - Does not honor autoStartup option
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/3cf66ca5
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/3cf66ca5
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/3cf66ca5
Branch: refs/heads/camel-2.13.x
Commit: 3cf66ca51cb4d5e01820b2e0bb445572798cf127
Parents: 5a13af1
Author: Claus Ibsen <da...@apache.org>
Authored: Mon Aug 18 09:20:28 2014 +0200
Committer: Claus Ibsen <da...@apache.org>
Committed: Mon Aug 18 09:50:21 2014 +0200
----------------------------------------------------------------------
.../java/org/apache/camel/CamelContext.java | 7 ++
.../org/apache/camel/RuntimeConfiguration.java | 3 +-
.../mbean/ManagedCamelContextMBean.java | 3 +
.../apache/camel/impl/DefaultCamelContext.java | 8 ++-
.../management/mbean/ManagedCamelContext.java | 4 ++
.../DefaultCamelContextAutoStartupTest.java | 8 +--
.../interceptor/AdviceWithAutoStartupTest.java | 68 ++++++++++++++++++++
7 files changed, 94 insertions(+), 7 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/3cf66ca5/camel-core/src/main/java/org/apache/camel/CamelContext.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/CamelContext.java b/camel-core/src/main/java/org/apache/camel/CamelContext.java
index 8e32849..15c5436 100644
--- a/camel-core/src/main/java/org/apache/camel/CamelContext.java
+++ b/camel-core/src/main/java/org/apache/camel/CamelContext.java
@@ -492,6 +492,13 @@ public interface CamelContext extends SuspendableService, RuntimeConfiguration {
void startRoute(RouteDefinition route) throws Exception;
/**
+ * Starts all the routes which currently is not started.
+ *
+ * @throws Exception is thrown if a route could not be started for whatever reason
+ */
+ void startAllRoutes() throws Exception;
+
+ /**
* Starts the given route if it has been previously stopped
*
* @param routeId the route id
http://git-wip-us.apache.org/repos/asf/camel/blob/3cf66ca5/camel-core/src/main/java/org/apache/camel/RuntimeConfiguration.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/RuntimeConfiguration.java b/camel-core/src/main/java/org/apache/camel/RuntimeConfiguration.java
index 0bcaff1..e1e0e2e 100644
--- a/camel-core/src/main/java/org/apache/camel/RuntimeConfiguration.java
+++ b/camel-core/src/main/java/org/apache/camel/RuntimeConfiguration.java
@@ -104,7 +104,8 @@ public interface RuntimeConfiguration {
* <br/>
* <b>Note:</b> When setting auto startup <tt>false</tt> on {@link CamelContext} then that takes precedence
* and <i>no</i> routes is started. You would need to start {@link CamelContext} explicit using
- * the {@link org.apache.camel.CamelContext#start()} method, to start the context and the routes.
+ * the {@link org.apache.camel.CamelContext#start()} method, to start the context, and then
+ * you would need to start the routes manually using {@link CamelContext#startRoute(String)}.
* <p/>
* Default is <tt>true</tt> to always start up.
*
http://git-wip-us.apache.org/repos/asf/camel/blob/3cf66ca5/camel-core/src/main/java/org/apache/camel/api/management/mbean/ManagedCamelContextMBean.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/api/management/mbean/ManagedCamelContextMBean.java b/camel-core/src/main/java/org/apache/camel/api/management/mbean/ManagedCamelContextMBean.java
index 46c611f..e316bf7 100644
--- a/camel-core/src/main/java/org/apache/camel/api/management/mbean/ManagedCamelContextMBean.java
+++ b/camel-core/src/main/java/org/apache/camel/api/management/mbean/ManagedCamelContextMBean.java
@@ -143,6 +143,9 @@ public interface ManagedCamelContextMBean extends ManagedPerformanceCounterMBean
@ManagedOperation(description = "Resume Camel")
void resume() throws Exception;
+ @ManagedOperation(description = "Starts all the routes which currently is not started")
+ void startAllRoutes() throws Exception;
+
@ManagedOperation(description = "Send body (in only)")
void sendBody(String endpointUri, Object body) throws Exception;
http://git-wip-us.apache.org/repos/asf/camel/blob/3cf66ca5/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java b/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java
index 9f39968..e38bc71 100644
--- a/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java
+++ b/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java
@@ -796,6 +796,10 @@ public class DefaultCamelContext extends ServiceSupport implements ModelCamelCon
stopRoute(route.idOrCreate(nodeIdFactory));
}
+ public void startAllRoutes() throws Exception {
+ doStartOrResumeRoutes(routeServices, true, true, false, false);
+ }
+
public synchronized void startRoute(String routeId) throws Exception {
RouteService routeService = routeServices.get(routeId);
if (routeService != null) {
@@ -2091,7 +2095,7 @@ public class DefaultCamelContext extends ServiceSupport implements ModelCamelCon
// this method will log the routes being started
safelyStartRouteServices(true, true, true, false, addingRoutes, routeService);
// start route services if it was configured to auto startup and we are not adding routes
- boolean autoStartup = routeService.getRouteDefinition().isAutoStartup(this);
+ boolean autoStartup = routeService.getRouteDefinition().isAutoStartup(this) && this.isAutoStartup();
if (!addingRoutes || autoStartup) {
// start the route since auto start is enabled or we are starting a route (not adding new routes)
routeService.start();
@@ -2281,7 +2285,7 @@ public class DefaultCamelContext extends ServiceSupport implements ModelCamelCon
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(this);
+ boolean autoStartup = routeService.getRouteDefinition().isAutoStartup(this) && this.isAutoStartup();
if (addingRoute && !autoStartup) {
log.info("Skipping starting of route " + routeService.getId() + " as its configured with autoStartup=false");
continue;
http://git-wip-us.apache.org/repos/asf/camel/blob/3cf66ca5/camel-core/src/main/java/org/apache/camel/management/mbean/ManagedCamelContext.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/management/mbean/ManagedCamelContext.java b/camel-core/src/main/java/org/apache/camel/management/mbean/ManagedCamelContext.java
index bfcba21..3ba8890 100644
--- a/camel-core/src/main/java/org/apache/camel/management/mbean/ManagedCamelContext.java
+++ b/camel-core/src/main/java/org/apache/camel/management/mbean/ManagedCamelContext.java
@@ -246,6 +246,10 @@ public class ManagedCamelContext extends ManagedPerformanceCounter implements Ti
}
}
+ public void startAllRoutes() throws Exception {
+ context.startAllRoutes();
+ }
+
public void sendBody(String endpointUri, Object body) throws Exception {
ProducerTemplate template = context.createProducerTemplate();
try {
http://git-wip-us.apache.org/repos/asf/camel/blob/3cf66ca5/camel-core/src/test/java/org/apache/camel/impl/DefaultCamelContextAutoStartupTest.java
----------------------------------------------------------------------
diff --git a/camel-core/src/test/java/org/apache/camel/impl/DefaultCamelContextAutoStartupTest.java b/camel-core/src/test/java/org/apache/camel/impl/DefaultCamelContextAutoStartupTest.java
index a1a4893..b4f5b6d 100644
--- a/camel-core/src/test/java/org/apache/camel/impl/DefaultCamelContextAutoStartupTest.java
+++ b/camel-core/src/test/java/org/apache/camel/impl/DefaultCamelContextAutoStartupTest.java
@@ -44,8 +44,8 @@ public class DefaultCamelContextAutoStartupTest extends TestSupport {
assertEquals(1, camel.getRoutes().size());
assertEquals(true, camel.getRouteStatus("foo").isStopped());
- // now start camel again, to get it to start the routes
- camel.start();
+ // now start all routes
+ camel.startAllRoutes();
assertEquals(true, camel.getRouteStatus("foo").isStarted());
@@ -140,8 +140,8 @@ public class DefaultCamelContextAutoStartupTest extends TestSupport {
assertEquals(true, camel.getRouteStatus("foo").isStopped());
assertEquals(false, camel.getRouteStatus("foo").isStarted());
- // now start camel again, to get it to start the routes
- camel.start();
+ // now start all the routes
+ camel.startAllRoutes();
assertEquals(true, camel.getRouteStatus("foo").isStarted());
http://git-wip-us.apache.org/repos/asf/camel/blob/3cf66ca5/camel-core/src/test/java/org/apache/camel/processor/interceptor/AdviceWithAutoStartupTest.java
----------------------------------------------------------------------
diff --git a/camel-core/src/test/java/org/apache/camel/processor/interceptor/AdviceWithAutoStartupTest.java b/camel-core/src/test/java/org/apache/camel/processor/interceptor/AdviceWithAutoStartupTest.java
new file mode 100644
index 0000000..0cfb242
--- /dev/null
+++ b/camel-core/src/test/java/org/apache/camel/processor/interceptor/AdviceWithAutoStartupTest.java
@@ -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.interceptor;
+
+import org.apache.camel.ContextTestSupport;
+import org.apache.camel.builder.AdviceWithRouteBuilder;
+import org.apache.camel.builder.RouteBuilder;
+
+/**
+ * @version
+ */
+public class AdviceWithAutoStartupTest extends ContextTestSupport {
+
+ public void testAdvised() throws Exception {
+ assertFalse(context.getRouteStatus("foo").isStarted());
+ assertFalse(context.getRouteStatus("bar").isStarted());
+
+ context.getRouteDefinition("bar").adviceWith(context, new AdviceWithRouteBuilder() {
+ @Override
+ public void configure() throws Exception {
+ replaceFromWith("seda:newBar");
+ }
+ });
+
+ assertFalse(context.getRouteStatus("foo").isStarted());
+ assertFalse(context.getRouteStatus("bar").isStarted());
+
+ context.startRoute("foo");
+ context.startRoute("bar");
+
+ assertTrue(context.getRouteStatus("foo").isStarted());
+ assertTrue(context.getRouteStatus("bar").isStarted());
+
+ getMockEndpoint("mock:newBar").expectedMessageCount(1);
+
+ template.sendBody("direct:start", "Hello World");
+
+ assertMockEndpointsSatisfied();
+ }
+
+ @Override
+ protected RouteBuilder createRouteBuilder() throws Exception {
+ return new RouteBuilder() {
+ @Override
+ public void configure() throws Exception {
+ context.setAutoStartup(false);
+
+ from("direct:start").routeId("foo").to("seda:newBar");
+
+ from("seda:bar").routeId("bar").to("mock:newBar");
+ }
+ };
+ }
+}
\ No newline at end of file