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 2017/03/02 14:35:56 UTC
[2/2] camel git commit: CAMEL-10596: Allow camel spring-boot to auto
terminate JVM after processing N messages.
CAMEL-10596: Allow camel spring-boot to auto terminate JVM after processing N messages.
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/29bb84d4
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/29bb84d4
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/29bb84d4
Branch: refs/heads/master
Commit: 29bb84d4227e276fe3b0c17b106a74e161f21268
Parents: eed1d27
Author: Claus Ibsen <da...@apache.org>
Authored: Thu Mar 2 15:35:45 2017 +0100
Committer: Claus Ibsen <da...@apache.org>
Committed: Thu Mar 2 15:35:45 2017 +0100
----------------------------------------------------------------------
.../camel/spring/boot/RoutesCollector.java | 25 ++++++++++++++++++++
1 file changed, 25 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/29bb84d4/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 1baf92c..aa25164 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
@@ -20,6 +20,9 @@ import java.io.FileNotFoundException;
import java.lang.reflect.Modifier;
import java.util.ArrayList;
import java.util.List;
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.ScheduledExecutorService;
+import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicBoolean;
import org.apache.camel.CamelContext;
@@ -121,6 +124,12 @@ public class RoutesCollector implements ApplicationListener<ContextRefreshedEven
camelContext.getManagementStrategy().addEventNotifier(notifier);
}
+ if (configurationProperties.getMainRunControllerMaxDurationSeconds() > 0) {
+ LOG.info("CamelMainRunController will terminate after {} seconds", configurationProperties.getMainRunControllerMaxDurationSeconds());
+ terminateMainControllerAfter(camelContext, configurationProperties.getMainRunControllerMaxDurationSeconds(),
+ controller.getCompleted(), controller.getLatch());
+ }
+
// controller will start Camel
LOG.info("Starting CamelMainRunController to ensure the main thread keeps running");
controller.start();
@@ -190,4 +199,20 @@ public class RoutesCollector implements ApplicationListener<ContextRefreshedEven
}
}
+ private void terminateMainControllerAfter(final CamelContext camelContext, int seconds, final AtomicBoolean completed, final CountDownLatch latch) {
+ ScheduledExecutorService executorService = camelContext.getExecutorServiceManager().newSingleThreadScheduledExecutor(this, "CamelMainRunControllerTerminateTaks");
+ Runnable task = () -> {
+ LOG.info("CamelMainRunController max seconds triggering shutdown of the JVM.");
+ try {
+ camelContext.stop();
+ } catch (Throwable e) {
+ LOG.warn("Error during stopping CamelContext", e);
+ } finally {
+ completed.set(true);
+ latch.countDown();
+ }
+ };
+ executorService.schedule(task, seconds, TimeUnit.SECONDS);
+ }
+
}