camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject [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
Date Wed, 11 Nov 2015 07:35:56 GMT
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 <msp+git@molindo.at>
Authored: Tue Nov 3 12:01:14 2015 +0100
Committer: Claus Ibsen <davsclaus@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 {


Mime
View raw message