You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by he...@apache.org on 2015/03/23 11:04:37 UTC

camel git commit: [CAMEL-8532] Spring Boot applications should block the main thread of the execution.

Repository: camel
Updated Branches:
  refs/heads/master 0f1d5c757 -> 472903bf2


[CAMEL-8532] Spring Boot applications should block the main thread of the execution.


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

Branch: refs/heads/master
Commit: 472903bf2dc069b7cd47dcdbfa957603092c282e
Parents: 0f1d5c7
Author: Henryk Konsek <he...@gmail.com>
Authored: Mon Mar 23 11:04:30 2015 +0100
Committer: Henryk Konsek <he...@gmail.com>
Committed: Mon Mar 23 11:04:30 2015 +0100

----------------------------------------------------------------------
 .../spring/boot/CamelAutoConfiguration.java     |  5 ++
 .../CamelSpringBootApplicationController.java   | 54 ++++++++++++++++++++
 .../apache/camel/spring/boot/FatJarRouter.java  |  6 ++-
 .../StandaloneFatJarRouterTest.java             |  7 ++-
 4 files changed, 70 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/472903bf/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 5fdac34..0f444ac 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
@@ -60,6 +60,11 @@ public class CamelAutoConfiguration {
     }
 
     @Bean
+    CamelSpringBootApplicationController applicationController(ApplicationContext applicationContext, CamelContext camelContext) {
+        return new CamelSpringBootApplicationController(applicationContext, camelContext);
+    }
+
+    @Bean
     @ConditionalOnMissingBean(RoutesCollector.class)
     RoutesCollector routesCollector(ApplicationContext applicationContext) {
         Collection<CamelContextConfiguration> configurations = applicationContext.getBeansOfType(CamelContextConfiguration.class).values();

http://git-wip-us.apache.org/repos/asf/camel/blob/472903bf/components/camel-spring-boot/src/main/java/org/apache/camel/spring/boot/CamelSpringBootApplicationController.java
----------------------------------------------------------------------
diff --git a/components/camel-spring-boot/src/main/java/org/apache/camel/spring/boot/CamelSpringBootApplicationController.java b/components/camel-spring-boot/src/main/java/org/apache/camel/spring/boot/CamelSpringBootApplicationController.java
new file mode 100644
index 0000000..7ff3714
--- /dev/null
+++ b/components/camel-spring-boot/src/main/java/org/apache/camel/spring/boot/CamelSpringBootApplicationController.java
@@ -0,0 +1,54 @@
+/**
+ * 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.spring.boot;
+
+import java.util.Collections;
+import java.util.Map;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.ProducerTemplate;
+import org.apache.camel.main.MainSupport;
+import org.springframework.context.ApplicationContext;
+
+public class CamelSpringBootApplicationController {
+
+    private final MainSupport mainSupport;
+
+    public CamelSpringBootApplicationController(final ApplicationContext applicationContext, final CamelContext camelContext) {
+        this.mainSupport = new MainSupport() {
+            @Override
+            protected ProducerTemplate findOrCreateCamelTemplate() {
+                return applicationContext.getBean(ProducerTemplate.class);
+            }
+
+            @Override
+            protected Map<String, CamelContext> getCamelContextMap() {
+                return Collections.singletonMap("camelContext", camelContext);
+            }
+        };
+    }
+
+    public void blockMainThread() {
+        try {
+            mainSupport.enableHangupSupport();
+            mainSupport.run();
+        } catch (Exception e) {
+            throw new RuntimeException(e);
+        }
+    }
+
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/camel/blob/472903bf/components/camel-spring-boot/src/main/java/org/apache/camel/spring/boot/FatJarRouter.java
----------------------------------------------------------------------
diff --git a/components/camel-spring-boot/src/main/java/org/apache/camel/spring/boot/FatJarRouter.java b/components/camel-spring-boot/src/main/java/org/apache/camel/spring/boot/FatJarRouter.java
index d712bb0..94458ef 100644
--- a/components/camel-spring-boot/src/main/java/org/apache/camel/spring/boot/FatJarRouter.java
+++ b/components/camel-spring-boot/src/main/java/org/apache/camel/spring/boot/FatJarRouter.java
@@ -18,11 +18,15 @@ package org.apache.camel.spring.boot;
 
 import org.apache.camel.builder.RouteBuilder;
 import org.springframework.boot.SpringApplication;
+import org.springframework.context.ApplicationContext;
 
 public class FatJarRouter extends RouteBuilder {
 
     public static void main(String... args) {
-        new SpringApplication(FatJarRouter.class).run(args);
+        ApplicationContext applicationContext = new SpringApplication(FatJarRouter.class).run(args);
+        CamelSpringBootApplicationController applicationController =
+                applicationContext.getBean(CamelSpringBootApplicationController.class);
+        applicationController.blockMainThread();
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/camel/blob/472903bf/components/camel-spring-boot/src/test/java/org/apache/camel/spring/boot/fatjarroutertests/StandaloneFatJarRouterTest.java
----------------------------------------------------------------------
diff --git a/components/camel-spring-boot/src/test/java/org/apache/camel/spring/boot/fatjarroutertests/StandaloneFatJarRouterTest.java b/components/camel-spring-boot/src/test/java/org/apache/camel/spring/boot/fatjarroutertests/StandaloneFatJarRouterTest.java
index af8916b..2d194a7 100644
--- a/components/camel-spring-boot/src/test/java/org/apache/camel/spring/boot/fatjarroutertests/StandaloneFatJarRouterTest.java
+++ b/components/camel-spring-boot/src/test/java/org/apache/camel/spring/boot/fatjarroutertests/StandaloneFatJarRouterTest.java
@@ -37,7 +37,12 @@ public class StandaloneFatJarRouterTest extends Assert {
         // Given
         final int port = SocketUtils.findAvailableTcpPort();
         final URL httpEndpoint = new URL("http://localhost:" + port);
-        TestFatJarRouter.main("--spring.main.sources=org.apache.camel.spring.boot.fatjarroutertests.TestFatJarRouter", "--http.port=" + port);
+        new Thread() {
+            @Override
+            public void run() {
+                TestFatJarRouter.main("--spring.main.sources=org.apache.camel.spring.boot.fatjarroutertests.TestFatJarRouter", "--http.port=" + port);
+            }
+        }.start();
         await().atMost(1, MINUTES).until(new Callable<Boolean>() {
             @Override
             public Boolean call() throws Exception {