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:52 UTC

[1/6] camel git commit: adapted the changes of CAMEL-8460 to only refresh routes on ContextRefreshEvents from "own" applicationContext. Previously route refreshs were initiated only if the parent applicationContext of the event's context was null. This d

Repository: camel
Updated Branches:
  refs/heads/camel-2.15.x 27a9b3953 -> 5d266ce2c
  refs/heads/camel-2.16.x 7f961480a -> c73de90d2
  refs/heads/master ba84da4ab -> 0589a1490


adapted the changes of CAMEL-8460 to only refresh routes on ContextRefreshEvents from "own" applicationContext. Previously route refreshs were initiated only if the parent applicationContext of the event's context was null. This doesn't work when Spring instantiates the Camel's application context as child of another applicationContext. This e.g. happens as soon as you're using spring-cloud-config


Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/66b6edcf
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/66b6edcf
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/66b6edcf

Branch: refs/heads/master
Commit: 66b6edcf2706eb9b4911967c33a8d6a9c4528747
Parents: ba84da4
Author: msparer <ms...@molindo.at>
Authored: Tue Nov 3 12:01:14 2015 +0100
Committer: Claus Ibsen <da...@apache.org>
Committed: Wed Nov 11 08:35:32 2015 +0100

----------------------------------------------------------------------
 .../camel/spring/boot/CamelAutoConfiguration.java       |  2 +-
 .../org/apache/camel/spring/boot/RoutesCollector.java   | 12 +++++++-----
 2 files changed, 8 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/66b6edcf/components/camel-spring-boot/src/main/java/org/apache/camel/spring/boot/CamelAutoConfiguration.java
----------------------------------------------------------------------
diff --git a/components/camel-spring-boot/src/main/java/org/apache/camel/spring/boot/CamelAutoConfiguration.java b/components/camel-spring-boot/src/main/java/org/apache/camel/spring/boot/CamelAutoConfiguration.java
index 9034f09..e1bd003 100644
--- a/components/camel-spring-boot/src/main/java/org/apache/camel/spring/boot/CamelAutoConfiguration.java
+++ b/components/camel-spring-boot/src/main/java/org/apache/camel/spring/boot/CamelAutoConfiguration.java
@@ -69,7 +69,7 @@ public class CamelAutoConfiguration {
     @ConditionalOnMissingBean(RoutesCollector.class)
     RoutesCollector routesCollector(ApplicationContext applicationContext) {
         Collection<CamelContextConfiguration> configurations = applicationContext.getBeansOfType(CamelContextConfiguration.class).values();
-        return new RoutesCollector(new ArrayList<CamelContextConfiguration>(configurations));
+        return new RoutesCollector(applicationContext, new ArrayList<CamelContextConfiguration>(configurations));
     }
 
     /**

http://git-wip-us.apache.org/repos/asf/camel/blob/66b6edcf/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 33d479b..cf6ea40 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
@@ -22,7 +22,6 @@ import java.util.List;
 
 import org.apache.camel.CamelContext;
 import org.apache.camel.RoutesBuilder;
-import org.apache.camel.ServiceStatus;
 import org.apache.camel.model.RoutesDefinition;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -42,12 +41,15 @@ public class RoutesCollector implements ApplicationListener<ContextRefreshedEven
     private static final Logger LOG = LoggerFactory.getLogger(RoutesCollector.class);
 
     // Collaborators
+    
+    private final ApplicationContext applicationContext;
 
     private final List<CamelContextConfiguration> camelContextConfigurations;
 
     // Constructors
 
-    public RoutesCollector(List<CamelContextConfiguration> camelContextConfigurations) {
+    public RoutesCollector(ApplicationContext applicationContext, List<CamelContextConfiguration> camelContextConfigurations) {
+    	this.applicationContext = applicationContext;
         this.camelContextConfigurations = new ArrayList<CamelContextConfiguration>(camelContextConfigurations);
     }
 
@@ -56,9 +58,9 @@ public class RoutesCollector implements ApplicationListener<ContextRefreshedEven
     @Override
     public void onApplicationEvent(ContextRefreshedEvent contextRefreshedEvent) {
         ApplicationContext applicationContext = contextRefreshedEvent.getApplicationContext();
-        CamelContext camelContext = contextRefreshedEvent.getApplicationContext().getBean(CamelContext.class);
-        // if we have not yet started
-        if (camelContext.getStatus() == ServiceStatus.Stopped) {
+        // 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 {


[5/6] camel git commit: adapted the changes of CAMEL-8460 to only refresh routes on ContextRefreshEvents from "own" applicationContext. Previously route refreshs were initiated only if the parent applicationContext of the event's context was null. This d

Posted by da...@apache.org.
adapted the changes of CAMEL-8460 to only refresh routes on ContextRefreshEvents from "own" applicationContext. Previously route refreshs were initiated only if the parent applicationContext of the event's context was null. This doesn't work when Spring instantiates the Camel's application context as child of another applicationContext. This e.g. happens as soon as you're using spring-cloud-config


Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/b652b86c
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/b652b86c
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/b652b86c

Branch: refs/heads/camel-2.15.x
Commit: b652b86c6a7758907b76ccb422d20bb6d92cc38e
Parents: 27a9b39
Author: msparer <ms...@molindo.at>
Authored: Tue Nov 3 12:01:14 2015 +0100
Committer: Claus Ibsen <da...@apache.org>
Committed: Wed Nov 11 08:39:10 2015 +0100

----------------------------------------------------------------------
 .../camel/spring/boot/CamelAutoConfiguration.java       |  2 +-
 .../org/apache/camel/spring/boot/RoutesCollector.java   | 12 +++++++-----
 2 files changed, 8 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/b652b86c/components/camel-spring-boot/src/main/java/org/apache/camel/spring/boot/CamelAutoConfiguration.java
----------------------------------------------------------------------
diff --git a/components/camel-spring-boot/src/main/java/org/apache/camel/spring/boot/CamelAutoConfiguration.java b/components/camel-spring-boot/src/main/java/org/apache/camel/spring/boot/CamelAutoConfiguration.java
index 0f444ac..dc9abc8 100644
--- a/components/camel-spring-boot/src/main/java/org/apache/camel/spring/boot/CamelAutoConfiguration.java
+++ b/components/camel-spring-boot/src/main/java/org/apache/camel/spring/boot/CamelAutoConfiguration.java
@@ -68,7 +68,7 @@ public class CamelAutoConfiguration {
     @ConditionalOnMissingBean(RoutesCollector.class)
     RoutesCollector routesCollector(ApplicationContext applicationContext) {
         Collection<CamelContextConfiguration> configurations = applicationContext.getBeansOfType(CamelContextConfiguration.class).values();
-        return new RoutesCollector(new ArrayList<CamelContextConfiguration>(configurations));
+        return new RoutesCollector(applicationContext, new ArrayList<CamelContextConfiguration>(configurations));
     }
 
     /**

http://git-wip-us.apache.org/repos/asf/camel/blob/b652b86c/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 51cc984..793b1e4 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
@@ -22,7 +22,6 @@ import java.util.List;
 
 import org.apache.camel.CamelContext;
 import org.apache.camel.RoutesBuilder;
-import org.apache.camel.ServiceStatus;
 import org.apache.camel.model.RoutesDefinition;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -38,12 +37,15 @@ public class RoutesCollector implements ApplicationListener<ContextRefreshedEven
     private static final Logger LOG = LoggerFactory.getLogger(RoutesCollector.class);
 
     // Collaborators
+    
+    private final ApplicationContext applicationContext;
 
     private final List<CamelContextConfiguration> camelContextConfigurations;
 
     // Constructors
 
-    public RoutesCollector(List<CamelContextConfiguration> camelContextConfigurations) {
+    public RoutesCollector(ApplicationContext applicationContext, List<CamelContextConfiguration> camelContextConfigurations) {
+    	this.applicationContext = applicationContext;
         this.camelContextConfigurations = new ArrayList<CamelContextConfiguration>(camelContextConfigurations);
     }
 
@@ -52,9 +54,9 @@ public class RoutesCollector implements ApplicationListener<ContextRefreshedEven
     @Override
     public void onApplicationEvent(ContextRefreshedEvent contextRefreshedEvent) {
         ApplicationContext applicationContext = contextRefreshedEvent.getApplicationContext();
-        CamelContext camelContext = contextRefreshedEvent.getApplicationContext().getBean(CamelContext.class);
-        // if we have not yet started
-        if (camelContext.getStatus() == ServiceStatus.Stopped) {
+        // 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 {


[6/6] camel git commit: CAMEL-8460: Better logic for trigger when to start Camel on the refresh event. This fixes #668

Posted by da...@apache.org.
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/5d266ce2
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/5d266ce2
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/5d266ce2

Branch: refs/heads/camel-2.15.x
Commit: 5d266ce2c026a5301a2e4e2500358934b74b2c47
Parents: b652b86
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:39:17 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/5d266ce2/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 793b1e4..1a4ffda 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
@@ -45,7 +45,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);
     }
 
@@ -57,30 +57,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);
         }
     }
 


[4/6] camel git commit: CAMEL-8460: Better logic for trigger when to start Camel on the refresh event. This fixes #668

Posted by da...@apache.org.
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/c73de90d
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/c73de90d
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/c73de90d

Branch: refs/heads/camel-2.16.x
Commit: c73de90d2bd02545507cbb5baa9e6f481ae8315d
Parents: c0e144f
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:59 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/c73de90d/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);
         }
     }
 


[3/6] camel git commit: adapted the changes of CAMEL-8460 to only refresh routes on ContextRefreshEvents from "own" applicationContext. Previously route refreshs were initiated only if the parent applicationContext of the event's context was null. This d

Posted by da...@apache.org.
adapted the changes of CAMEL-8460 to only refresh routes on ContextRefreshEvents from "own" applicationContext. Previously route refreshs were initiated only if the parent applicationContext of the event's context was null. This doesn't work when Spring instantiates the Camel's application context as child of another applicationContext. This e.g. happens as soon as you're using spring-cloud-config


Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/c0e144f9
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/c0e144f9
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/c0e144f9

Branch: refs/heads/camel-2.16.x
Commit: c0e144f993ddba8101bec83b28d53d861d1ca4cd
Parents: 7f96148
Author: msparer <ms...@molindo.at>
Authored: Tue Nov 3 12:01:14 2015 +0100
Committer: Claus Ibsen <da...@apache.org>
Committed: Wed Nov 11 08:38:53 2015 +0100

----------------------------------------------------------------------
 .../camel/spring/boot/CamelAutoConfiguration.java       |  2 +-
 .../org/apache/camel/spring/boot/RoutesCollector.java   | 12 +++++++-----
 2 files changed, 8 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/c0e144f9/components/camel-spring-boot/src/main/java/org/apache/camel/spring/boot/CamelAutoConfiguration.java
----------------------------------------------------------------------
diff --git a/components/camel-spring-boot/src/main/java/org/apache/camel/spring/boot/CamelAutoConfiguration.java b/components/camel-spring-boot/src/main/java/org/apache/camel/spring/boot/CamelAutoConfiguration.java
index 9034f09..e1bd003 100644
--- a/components/camel-spring-boot/src/main/java/org/apache/camel/spring/boot/CamelAutoConfiguration.java
+++ b/components/camel-spring-boot/src/main/java/org/apache/camel/spring/boot/CamelAutoConfiguration.java
@@ -69,7 +69,7 @@ public class CamelAutoConfiguration {
     @ConditionalOnMissingBean(RoutesCollector.class)
     RoutesCollector routesCollector(ApplicationContext applicationContext) {
         Collection<CamelContextConfiguration> configurations = applicationContext.getBeansOfType(CamelContextConfiguration.class).values();
-        return new RoutesCollector(new ArrayList<CamelContextConfiguration>(configurations));
+        return new RoutesCollector(applicationContext, new ArrayList<CamelContextConfiguration>(configurations));
     }
 
     /**

http://git-wip-us.apache.org/repos/asf/camel/blob/c0e144f9/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 33d479b..cf6ea40 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
@@ -22,7 +22,6 @@ import java.util.List;
 
 import org.apache.camel.CamelContext;
 import org.apache.camel.RoutesBuilder;
-import org.apache.camel.ServiceStatus;
 import org.apache.camel.model.RoutesDefinition;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -42,12 +41,15 @@ public class RoutesCollector implements ApplicationListener<ContextRefreshedEven
     private static final Logger LOG = LoggerFactory.getLogger(RoutesCollector.class);
 
     // Collaborators
+    
+    private final ApplicationContext applicationContext;
 
     private final List<CamelContextConfiguration> camelContextConfigurations;
 
     // Constructors
 
-    public RoutesCollector(List<CamelContextConfiguration> camelContextConfigurations) {
+    public RoutesCollector(ApplicationContext applicationContext, List<CamelContextConfiguration> camelContextConfigurations) {
+    	this.applicationContext = applicationContext;
         this.camelContextConfigurations = new ArrayList<CamelContextConfiguration>(camelContextConfigurations);
     }
 
@@ -56,9 +58,9 @@ public class RoutesCollector implements ApplicationListener<ContextRefreshedEven
     @Override
     public void onApplicationEvent(ContextRefreshedEvent contextRefreshedEvent) {
         ApplicationContext applicationContext = contextRefreshedEvent.getApplicationContext();
-        CamelContext camelContext = contextRefreshedEvent.getApplicationContext().getBean(CamelContext.class);
-        // if we have not yet started
-        if (camelContext.getStatus() == ServiceStatus.Stopped) {
+        // 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 {


[2/6] camel git commit: CAMEL-8460: Better logic for trigger when to start Camel on the refresh event. This fixes #668

Posted by da...@apache.org.
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);
         }
     }