Repository: camel Updated Branches: refs/heads/master c3a7a5644 -> 1502688d2
CAMEL-9917: Route stopped events are sent in inconsistent order Project: http://git-wip-us.apache.org/repos/asf/camel/repo Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/1502688d Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/1502688d Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/1502688d Branch: refs/heads/master Commit: 1502688d25d7f4747b93702f803204c4b9ad07ff Parents: c3a7a56 Author: Antonin Stefanutti <anto...@stefanutti.fr> Authored: Wed Apr 27 16:42:04 2016 +0200 Committer: Antonin Stefanutti <anto...@stefanutti.fr> Committed: Wed Apr 27 16:42:04 2016 +0200 ---------------------------------------------------------------------- .../java/org/apache/camel/impl/DefaultCamelContext.java | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/camel/blob/1502688d/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java ---------------------------------------------------------------------- diff --git a/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java b/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java index 1f6ac66..d5c6d3f 100644 --- a/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java +++ b/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java @@ -23,6 +23,7 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; import java.util.Collections; +import java.util.Comparator; import java.util.Date; import java.util.HashMap; import java.util.Iterator; @@ -40,6 +41,7 @@ import java.util.concurrent.ScheduledExecutorService; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicInteger; +import java.util.stream.Collectors; import javax.management.MalformedObjectNameException; import javax.management.ObjectName; @@ -3109,13 +3111,17 @@ public class DefaultCamelContext extends ServiceSupport implements ModelCamelCon } catch (Throwable e) { log.warn("Error occurred while shutting down routes. This exception will be ignored.", e); } - getRouteStartupOrder().clear(); // shutdown await manager to trigger interrupt of blocked threads to attempt to free these threads graceful shutdownServices(asyncProcessorAwaitManager); - shutdownServices(routeServices.values()); + shutdownServices(getRouteStartupOrder().stream() + .sorted(Comparator.comparing(RouteStartupOrder::getStartupOrder).reversed()) + .map(DefaultRouteStartupOrder.class::cast) + .map(DefaultRouteStartupOrder::getRouteService) + .collect(Collectors.toList()), false); // do not clear route services or startup listeners as we can start Camel again and get the route back as before + getRouteStartupOrder().clear(); // but clear any suspend routes suspendedRouteServices.clear();