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 2015/11/11 08:35:53 UTC
[2/6] camel git commit: CAMEL-8460: Better logic for trigger when to
start Camel on the refresh event. This fixes #668
CAMEL-8460: Better logic for trigger when to start Camel on the refresh event. This fixes #668
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/0589a149
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/0589a149
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/0589a149
Branch: refs/heads/master
Commit: 0589a149001a4bfc33d02aadab75d8d6481d5d1f
Parents: 66b6edc
Author: Claus Ibsen <da...@apache.org>
Authored: Wed Nov 11 08:37:24 2015 +0100
Committer: Claus Ibsen <da...@apache.org>
Committed: Wed Nov 11 08:38:26 2015 +0100
----------------------------------------------------------------------
.../camel/spring/boot/RoutesCollector.java | 44 +++++++++++---------
1 file changed, 25 insertions(+), 19 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/0589a149/components/camel-spring-boot/src/main/java/org/apache/camel/spring/boot/RoutesCollector.java
----------------------------------------------------------------------
diff --git a/components/camel-spring-boot/src/main/java/org/apache/camel/spring/boot/RoutesCollector.java b/components/camel-spring-boot/src/main/java/org/apache/camel/spring/boot/RoutesCollector.java
index cf6ea40..c13e214 100644
--- a/components/camel-spring-boot/src/main/java/org/apache/camel/spring/boot/RoutesCollector.java
+++ b/components/camel-spring-boot/src/main/java/org/apache/camel/spring/boot/RoutesCollector.java
@@ -49,7 +49,7 @@ public class RoutesCollector implements ApplicationListener<ContextRefreshedEven
// Constructors
public RoutesCollector(ApplicationContext applicationContext, List<CamelContextConfiguration> camelContextConfigurations) {
- this.applicationContext = applicationContext;
+ this.applicationContext = applicationContext;
this.camelContextConfigurations = new ArrayList<CamelContextConfiguration>(camelContextConfigurations);
}
@@ -61,30 +61,36 @@ public class RoutesCollector implements ApplicationListener<ContextRefreshedEven
// only listen to context refreshs of "my" applicationContext
if (this.applicationContext.equals(applicationContext)) {
CamelContext camelContext = contextRefreshedEvent.getApplicationContext().getBean(CamelContext.class);
- LOG.debug("Post-processing CamelContext bean: {}", camelContext.getName());
- for (RoutesBuilder routesBuilder : applicationContext.getBeansOfType(RoutesBuilder.class).values()) {
- try {
- LOG.debug("Injecting following route into the CamelContext: {}", routesBuilder);
- camelContext.addRoutes(routesBuilder);
- } catch (Exception e) {
- throw new CamelSpringBootInitializationException(e);
+
+ // only add and start Camel if its stopped (initial state)
+ if (camelContext.getStatus().isStopped()) {
+ LOG.debug("Post-processing CamelContext bean: {}", camelContext.getName());
+ for (RoutesBuilder routesBuilder : applicationContext.getBeansOfType(RoutesBuilder.class).values()) {
+ try {
+ LOG.debug("Injecting following route into the CamelContext: {}", routesBuilder);
+ camelContext.addRoutes(routesBuilder);
+ } catch (Exception e) {
+ throw new CamelSpringBootInitializationException(e);
+ }
}
- }
- try {
- loadXmlRoutes(applicationContext, camelContext);
+ try {
+ loadXmlRoutes(applicationContext, camelContext);
- for (CamelContextConfiguration camelContextConfiguration : camelContextConfigurations) {
- LOG.debug("CamelContextConfiguration found. Invoking: {}", camelContextConfiguration);
- camelContextConfiguration.beforeApplicationStart(camelContext);
- }
+ for (CamelContextConfiguration camelContextConfiguration : camelContextConfigurations) {
+ LOG.debug("CamelContextConfiguration found. Invoking: {}", camelContextConfiguration);
+ camelContextConfiguration.beforeApplicationStart(camelContext);
+ }
- camelContext.start();
- } catch (Exception e) {
- throw new CamelSpringBootInitializationException(e);
+ camelContext.start();
+ } catch (Exception e) {
+ throw new CamelSpringBootInitializationException(e);
+ }
+ } else {
+ LOG.debug("Camel already started, not adding routes.");
}
} else {
- LOG.debug("Camel already started, not adding routes.");
+ LOG.debug("Ignore ContextRefreshedEvent: {}", contextRefreshedEvent);
}
}