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 2014/02/05 11:09:32 UTC
[3/4] git commit: github pull request #90 - Provide access to the
shutdown task Future in order to have more control over it. Thanks to Antoine
for the patch. Revised patch slightly.
github pull request #90 - Provide access to the shutdown task Future in order to have more control over it. Thanks to Antoine for the patch. Revised patch slightly.
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/adec300e
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/adec300e
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/adec300e
Branch: refs/heads/camel-2.12.x
Commit: adec300ec22a9bcdb0e5a51700002563e990e810
Parents: 26327ac
Author: Claus Ibsen <da...@apache.org>
Authored: Tue Feb 4 17:53:47 2014 +0100
Committer: Claus Ibsen <da...@apache.org>
Committed: Wed Feb 5 11:10:15 2014 +0100
----------------------------------------------------------------------
.../camel/impl/DefaultShutdownStrategy.java | 19 +++++++++++++------
1 file changed, 13 insertions(+), 6 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/adec300e/camel-core/src/main/java/org/apache/camel/impl/DefaultShutdownStrategy.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/impl/DefaultShutdownStrategy.java b/camel-core/src/main/java/org/apache/camel/impl/DefaultShutdownStrategy.java
index 64d1c6c..72145a8 100644
--- a/camel-core/src/main/java/org/apache/camel/impl/DefaultShutdownStrategy.java
+++ b/camel-core/src/main/java/org/apache/camel/impl/DefaultShutdownStrategy.java
@@ -71,7 +71,7 @@ import org.slf4j.LoggerFactory;
* The idea by the <tt>forced</tt> shutdown strategy, is to stop continue processing messages.
* And force routes and its services to shutdown now. There is a risk when shutting down now,
* that some resources is not properly shutdown, which can cause side effects. The timeout value
- * is by default 300 seconds, but can be customized.
+ * is by default 300 seconds, but can be customized.
* <p/>
* As this strategy will politely wait until all exchanges has been completed it can potential wait
* for a long time, and hence why a timeout value can be set. When the timeout triggers you can also
@@ -99,7 +99,7 @@ import org.slf4j.LoggerFactory;
* to be logged. The option {@link #setSuppressLoggingOnTimeout(boolean)} can be used to suppress these
* logs, so they are logged at TRACE level instead.
*
- * @version
+ * @version
*/
public class DefaultShutdownStrategy extends ServiceSupport implements ShutdownStrategy, CamelContextAware {
private static final Logger LOG = LoggerFactory.getLogger(DefaultShutdownStrategy.class);
@@ -113,6 +113,7 @@ public class DefaultShutdownStrategy extends ServiceSupport implements ShutdownS
private boolean suppressLoggingOnTimeout;
private volatile boolean forceShutdown;
private final AtomicBoolean timeoutOccurred = new AtomicBoolean();
+ private volatile Future<?> currentShutdownTaskFuture;
public DefaultShutdownStrategy() {
}
@@ -173,15 +174,15 @@ public class DefaultShutdownStrategy extends ServiceSupport implements ShutdownS
// use another thread to perform the shutdowns so we can support timeout
timeoutOccurred.set(false);
- Future<?> future = getExecutorService().submit(new ShutdownTask(context, routesOrdered, timeout, timeUnit, suspendOnly, abortAfterTimeout, timeoutOccurred));
+ currentShutdownTaskFuture = getExecutorService().submit(new ShutdownTask(context, routesOrdered, timeout, timeUnit, suspendOnly, abortAfterTimeout, timeoutOccurred));
try {
- future.get(timeout, timeUnit);
+ currentShutdownTaskFuture.get(timeout, timeUnit);
} catch (TimeoutException e) {
// we hit a timeout, so set the flag
timeoutOccurred.set(true);
// timeout then cancel the task
- future.cancel(true);
+ currentShutdownTaskFuture.cancel(true);
// signal we are forcing shutdown now, since timeout occurred
this.forceShutdown = forceShutdown;
@@ -209,6 +210,8 @@ public class DefaultShutdownStrategy extends ServiceSupport implements ShutdownS
} catch (ExecutionException e) {
// unwrap execution exception
throw ObjectHelper.wrapRuntimeCamelException(e.getCause());
+ } finally {
+ currentShutdownTaskFuture = null;
}
// convert to seconds as its easier to read than a big milli seconds number
@@ -279,6 +282,10 @@ public class DefaultShutdownStrategy extends ServiceSupport implements ShutdownS
this.camelContext = camelContext;
}
+ public Future<?> getCurrentShutdownTaskFuture() {
+ return currentShutdownTaskFuture;
+ }
+
/**
* Shutdown all the consumers immediately.
*
@@ -386,7 +393,7 @@ public class DefaultShutdownStrategy extends ServiceSupport implements ShutdownS
/**
* Prepares the services for shutdown, by invoking the {@link ShutdownPrepared#prepareShutdown(boolean)} method
* on the service if it implement this interface.
- *
+ *
* @param service the service
* @param forced whether to force shutdown
* @param includeChildren whether to prepare the child of the service as well