/** * Shutdown all the consumers immediately. * * @param routes the routes to shutdown */ protected void shutdownRoutesNow(List<RouteStartupOrder> routes) { for (RouteStartupOrder order : routes) { // set the route to shutdown as fast as possible by stopping after // it has completed its current task ShutdownRunningTask current = order.getRoute().getRouteContext().getShutdownRunningTask(); if (current != ShutdownRunningTask.CompleteCurrentTaskOnly) { LOG.debug("Changing shutdownRunningTask from {} to " + ShutdownRunningTask.CompleteCurrentTaskOnly + " on route {} to shutdown faster", current, order.getRoute().getId()); order.getRoute().getRouteContext().setShutdownRunningTask(ShutdownRunningTask.CompleteCurrentTaskOnly); } for (Consumer consumer : order.getInputs()) { shutdownNow(consumer); } } }
/** * Calculates the total number of inflight exchanges for the given route * * @param order the route * @return number of inflight exchanges */ protected static int getPendingInflightExchanges(RouteStartupOrder order) { int inflight = 0; // the consumer is the 1st service so we always get the consumer // the child services are EIPs in the routes which may also have pending // inflight exchanges (such as the aggregator) for (Service service : order.getServices()) { Set<Service> children = ServiceHelper.getChildServices(service); for (Service child : children) { if (child instanceof ShutdownAware) { inflight += ((ShutdownAware) child).getPendingExchangesSize(); } } } return inflight; }
public synchronized boolean stopRoute(String routeId, long timeout, TimeUnit timeUnit, boolean abortAfterTimeout) throws Exception { RouteService routeService = routeServices.get(routeId); if (routeService != null) { RouteStartupOrder route = new DefaultRouteStartupOrder(1, routeService.getRoutes().iterator().next(), routeService); boolean completed = getShutdownStrategy().shutdown(this, route, timeout, timeUnit, abortAfterTimeout); if (completed) { // must stop route service as well stopRouteService(routeService, false); } else { // shutdown was aborted, make sure route is re-started properly startRouteService(routeService, false); } return completed; } return false; }
public synchronized void suspendRoute(String routeId) throws Exception { if (!routeSupportsSuspension(routeId)) { // stop if we suspend is not supported stopRoute(routeId); return; } RouteService routeService = routeServices.get(routeId); if (routeService != null) { List<RouteStartupOrder> routes = new ArrayList<RouteStartupOrder>(1); Route route = routeService.getRoutes().iterator().next(); RouteStartupOrder order = new DefaultRouteStartupOrder(1, route, routeService); routes.add(order); getShutdownStrategy().suspend(this, routes); // must suspend route service as well suspendRouteService(routeService); // must suspend the route as well if (route instanceof SuspendableService) { ((SuspendableService) route).suspend(); } } }
public synchronized void suspendRoute(String routeId, long timeout, TimeUnit timeUnit) throws Exception { if (!routeSupportsSuspension(routeId)) { stopRoute(routeId, timeout, timeUnit); return; } RouteService routeService = routeServices.get(routeId); if (routeService != null) { List<RouteStartupOrder> routes = new ArrayList<RouteStartupOrder>(1); Route route = routeService.getRoutes().iterator().next(); RouteStartupOrder order = new DefaultRouteStartupOrder(1, route, routeService); routes.add(order); getShutdownStrategy().suspend(this, routes, timeout, timeUnit); // must suspend route service as well suspendRouteService(routeService); // must suspend the route as well if (route instanceof SuspendableService) { ((SuspendableService) route).suspend(); } } }
public void testRouteStartupOrder() throws Exception { MockEndpoint mock = getMockEndpoint("mock:result"); mock.expectedMessageCount(1); template.sendBody("direct:start", "Hello World"); assertMockEndpointsSatisfied(); // assert correct order DefaultCamelContext dcc = (DefaultCamelContext) context; List<RouteStartupOrder> order = dcc.getRouteStartupOrder(); assertEquals(2, order.size()); assertEquals("direct://start", order.get(0).getRoute().getEndpoint().getEndpointUri()); assertEquals("seda://foo", order.get(1).getRoute().getEndpoint().getEndpointUri()); }
public void testRouteShutdownNotReverseOrder() throws Exception { // flip to not reverse context.getShutdownStrategy().setShutdownRoutesInReverseOrder(false); MockEndpoint mock = getMockEndpoint("mock:result"); mock.expectedMessageCount(1); template.sendBody("direct:bar", "Hello World"); assertMockEndpointsSatisfied(); // assert correct startup order DefaultCamelContext dcc = (DefaultCamelContext) context; List<RouteStartupOrder> order = dcc.getRouteStartupOrder(); assertEquals(2, order.size()); assertEquals("direct://bar", order.get(0).getRoute().getEndpoint().getEndpointUri()); assertEquals("direct://foo", order.get(1).getRoute().getEndpoint().getEndpointUri()); // assert correct shutdown order context.stop(); }
public void testRouteStartupOrder() throws Exception { MockEndpoint mock = getMockEndpoint("mock:result"); mock.expectedMessageCount(1); template.sendBody("direct:start", "Hello World"); assertMockEndpointsSatisfied(); // assert correct order DefaultCamelContext dcc = (DefaultCamelContext) context; List<RouteStartupOrder> order = dcc.getRouteStartupOrder(); assertEquals(5, order.size()); assertEquals("seda://foo", order.get(0).getRoute().getEndpoint().getEndpointUri()); assertEquals("direct://start", order.get(1).getRoute().getEndpoint().getEndpointUri()); assertEquals("seda://bar", order.get(2).getRoute().getEndpoint().getEndpointUri()); assertEquals("direct://bar", order.get(3).getRoute().getEndpoint().getEndpointUri()); // the one with no startup order should be last assertEquals("direct://default", order.get(4).getRoute().getEndpoint().getEndpointUri()); }
public void testRouteShutdownReverseOrder() throws Exception { MockEndpoint mock = getMockEndpoint("mock:result"); mock.expectedMessageCount(1); template.sendBody("direct:bar", "Hello World"); assertMockEndpointsSatisfied(); // assert correct startup order DefaultCamelContext dcc = (DefaultCamelContext) context; List<RouteStartupOrder> order = dcc.getRouteStartupOrder(); assertEquals(2, order.size()); assertEquals("direct://bar", order.get(0).getRoute().getEndpoint().getEndpointUri()); assertEquals("direct://foo", order.get(1).getRoute().getEndpoint().getEndpointUri()); // assert correct shutdown order context.stop(); }
public void testRouteStartupOrderSuspendResumeNoAutoStartup() throws Exception { MockEndpoint mock = getMockEndpoint("mock:result"); mock.expectedMessageCount(1); template.sendBody("direct:start", "Hello World"); assertMockEndpointsSatisfied(); context.suspend(); context.resume(); // route C should still be stopped after we have resumed assertEquals(true, context.getRouteStatus("C").isStopped()); // assert correct order DefaultCamelContext dcc = (DefaultCamelContext) context; List<RouteStartupOrder> order = dcc.getRouteStartupOrder(); assertEquals(3, order.size()); assertEquals("direct://foo", order.get(0).getRoute().getEndpoint().getEndpointUri()); assertEquals("direct://start", order.get(1).getRoute().getEndpoint().getEndpointUri()); assertEquals("direct://bar", order.get(2).getRoute().getEndpoint().getEndpointUri()); }
public void testRouteStartupOrder() throws Exception { MockEndpoint mock = getMockEndpoint("mock:result"); mock.expectedMessageCount(1); template.sendBody("direct:bar", "Hello World"); assertMockEndpointsSatisfied(); // assert correct order DefaultCamelContext dcc = (DefaultCamelContext) context; List<RouteStartupOrder> order = dcc.getRouteStartupOrder(); assertEquals(2, order.size()); assertEquals("direct://bar", order.get(0).getRoute().getEndpoint().getEndpointUri()); assertEquals("direct://foo", order.get(1).getRoute().getEndpoint().getEndpointUri()); }
public void testRouteServiceStartupOrder() throws Exception { MockEndpoint mock = getMockEndpoint("mock:result"); mock.expectedMessageCount(1); template.sendBody("direct:start", "Hello World"); assertMockEndpointsSatisfied(); // assert correct order DefaultCamelContext dcc = (DefaultCamelContext) context; List<RouteStartupOrder> order = dcc.getRouteStartupOrder(); assertEquals(4, order.size()); assertEquals("seda://foo", order.get(0).getRoute().getEndpoint().getEndpointUri()); assertEquals("direct://start", order.get(1).getRoute().getEndpoint().getEndpointUri()); assertEquals("seda://bar", order.get(2).getRoute().getEndpoint().getEndpointUri()); assertEquals("direct://bar", order.get(3).getRoute().getEndpoint().getEndpointUri()); // assert route service was started in order as well assertEquals("2143", startOrder); }
public void testRouteStartupOrder() throws Exception { MockEndpoint mock = getMockEndpoint("mock:result"); mock.expectedMessageCount(1); template.sendBody("direct:start", "Hello World"); assertMockEndpointsSatisfied(); // assert correct order DefaultCamelContext dcc = (DefaultCamelContext) context; List<RouteStartupOrder> order = dcc.getRouteStartupOrder(); assertEquals(4, order.size()); assertEquals("seda://foo", order.get(0).getRoute().getEndpoint().getEndpointUri()); assertEquals("direct://start", order.get(1).getRoute().getEndpoint().getEndpointUri()); assertEquals("seda://bar", order.get(2).getRoute().getEndpoint().getEndpointUri()); assertEquals("direct://bar", order.get(3).getRoute().getEndpoint().getEndpointUri()); }
public void testRouteStartupOrder() throws Exception { MockEndpoint mock = getMockEndpoint("mock:result"); mock.expectedMessageCount(1); template.sendBody("direct:bar", "Hello World"); assertMockEndpointsSatisfied(); // assert correct order DefaultCamelContext dcc = (DefaultCamelContext) context; List<RouteStartupOrder> order = dcc.getRouteStartupOrder(); assertEquals(2, order.size()); assertEquals("direct://bar", order.get(1).getRoute().getEndpoint().getEndpointUri()); assertEquals("direct://foo", order.get(0).getRoute().getEndpoint().getEndpointUri()); }
public void testRouteStartupOrderSuspendResume() throws Exception { MockEndpoint mock = getMockEndpoint("mock:result"); mock.expectedMessageCount(1); template.sendBody("direct:start", "Hello World"); assertMockEndpointsSatisfied(); context.suspend(); context.resume(); // assert correct order DefaultCamelContext dcc = (DefaultCamelContext) context; List<RouteStartupOrder> order = dcc.getRouteStartupOrder(); assertEquals(4, order.size()); assertEquals("direct://foo", order.get(0).getRoute().getEndpoint().getEndpointUri()); assertEquals("direct://start", order.get(1).getRoute().getEndpoint().getEndpointUri()); assertEquals("direct://baz", order.get(2).getRoute().getEndpoint().getEndpointUri()); assertEquals("direct://bar", order.get(3).getRoute().getEndpoint().getEndpointUri()); }
@Test public void testJmsDirectStartupOrderIssue() throws Exception { // send messages to queue so there is messages on the queue before we start the route template.sendBody("activemq:queue:foo", "Hello World"); template.sendBody("activemq:queue:foo", "Hello Camel"); template.sendBody("activemq:queue:foo", "Bye World"); template.sendBody("activemq:queue:foo", "Bye Camel"); context.startRoute("amq"); getMockEndpoint("mock:result").expectedMessageCount(4); assertMockEndpointsSatisfied(); DefaultCamelContext dcc = (DefaultCamelContext) context; List<RouteStartupOrder> order = dcc.getRouteStartupOrder(); assertEquals(2, order.size()); assertEquals(1, order.get(0).getStartupOrder()); assertEquals("direct", order.get(0).getRoute().getId()); assertEquals(100, order.get(1).getStartupOrder()); assertEquals("amq", order.get(1).getRoute().getId()); }
/** * Gets the route startup order for the given route id * * @param camelContext the camel context * @param routeId the id of the route * @return the startup order, or <tt>0</tt> if not possible to determine */ public static int getRouteStartupOrder(CamelContext camelContext, String routeId) { for (RouteStartupOrder order : camelContext.getRouteStartupOrder()) { if (order.getRoute().getId().equals(routeId)) { return order.getStartupOrder(); } } return 0; }
ShutdownTask(CamelContext context, List<RouteStartupOrder> routes, long timeout, TimeUnit timeUnit, boolean suspendOnly, boolean abortAfterTimeout, AtomicBoolean timeoutOccurred) { this.context = context; this.routes = routes; this.suspendOnly = suspendOnly; this.abortAfterTimeout = abortAfterTimeout; this.timeout = timeout; this.timeUnit = timeUnit; this.timeoutOccurred = timeoutOccurred; }
public synchronized void stopRoute(String routeId) throws Exception { RouteService routeService = routeServices.get(routeId); if (routeService != null) { List<RouteStartupOrder> routes = new ArrayList<RouteStartupOrder>(1); RouteStartupOrder order = new DefaultRouteStartupOrder(1, routeService.getRoutes().iterator().next(), routeService); routes.add(order); getShutdownStrategy().shutdown(this, routes); // must stop route service as well stopRouteService(routeService, false); } }
public synchronized void stopRoute(String routeId, long timeout, TimeUnit timeUnit) throws Exception { RouteService routeService = routeServices.get(routeId); if (routeService != null) { List<RouteStartupOrder> routes = new ArrayList<RouteStartupOrder>(1); RouteStartupOrder order = new DefaultRouteStartupOrder(1, routeService.getRoutes().iterator().next(), routeService); routes.add(order); getShutdownStrategy().shutdown(this, routes, timeout, timeUnit); // must stop route service as well stopRouteService(routeService, false); } }
public synchronized void shutdownRoute(String routeId) throws Exception { RouteService routeService = routeServices.get(routeId); if (routeService != null) { List<RouteStartupOrder> routes = new ArrayList<RouteStartupOrder>(1); RouteStartupOrder order = new DefaultRouteStartupOrder(1, routeService.getRoutes().iterator().next(), routeService); routes.add(order); getShutdownStrategy().shutdown(this, routes); // must stop route service as well (and remove the routes from management) stopRouteService(routeService, true); } }
public synchronized void shutdownRoute(String routeId, long timeout, TimeUnit timeUnit) throws Exception { RouteService routeService = routeServices.get(routeId); if (routeService != null) { List<RouteStartupOrder> routes = new ArrayList<RouteStartupOrder>(1); RouteStartupOrder order = new DefaultRouteStartupOrder(1, routeService.getRoutes().iterator().next(), routeService); routes.add(order); getShutdownStrategy().shutdown(this, routes, timeout, timeUnit); // must stop route service as well (and remove the routes from management) stopRouteService(routeService, true); } }
public void testRouteStartupOrderSuspendResumeStartC() throws Exception { MockEndpoint mock = getMockEndpoint("mock:result"); mock.expectedMessageCount(1); template.sendBody("direct:start", "Hello World"); assertMockEndpointsSatisfied(); // start C context.startRoute("C"); context.suspend(); context.resume(); // route C should be started assertEquals(true, context.getRouteStatus("C").isStarted()); // assert correct order DefaultCamelContext dcc = (DefaultCamelContext) context; List<RouteStartupOrder> order = dcc.getRouteStartupOrder(); assertEquals(4, order.size()); assertEquals("direct://foo", order.get(0).getRoute().getEndpoint().getEndpointUri()); assertEquals("direct://start", order.get(1).getRoute().getEndpoint().getEndpointUri()); assertEquals("direct://bar", order.get(2).getRoute().getEndpoint().getEndpointUri()); // however its started manually so its started after the auto started assertEquals("direct://baz", order.get(3).getRoute().getEndpoint().getEndpointUri()); }
public void shutdown(CamelContext context, List<RouteStartupOrder> routes) throws Exception { shutdown(context, routes, getTimeout(), getTimeUnit()); }
@Override public void shutdownForced(CamelContext context, List<RouteStartupOrder> routes) throws Exception { doShutdown(context, routes, getTimeout(), getTimeUnit(), false, false, true); }
public void suspend(CamelContext context, List<RouteStartupOrder> routes) throws Exception { doShutdown(context, routes, getTimeout(), getTimeUnit(), true, false, false); }
public void shutdown(CamelContext context, List<RouteStartupOrder> routes, long timeout, TimeUnit timeUnit) throws Exception { doShutdown(context, routes, timeout, timeUnit, false, false, false); }
public boolean shutdown(CamelContext context, RouteStartupOrder route, long timeout, TimeUnit timeUnit, boolean abortAfterTimeout) throws Exception { List<RouteStartupOrder> routes = new ArrayList<RouteStartupOrder>(1); routes.add(route); return doShutdown(context, routes, timeout, timeUnit, false, abortAfterTimeout, false); }
public void suspend(CamelContext context, List<RouteStartupOrder> routes, long timeout, TimeUnit timeUnit) throws Exception { doShutdown(context, routes, timeout, timeUnit, true, false, false); }
public List<RouteStartupOrder> getRouteStartupOrder() { return routeStartupOrder; }
@Override public List<RouteStartupOrder> getRouteStartupOrder() { return context.getRouteStartupOrder(); }
/** * Returns the order in which the route inputs was started. * <p/> * The order may not be according to the startupOrder defined on the route. * For example a route could be started manually later, or new routes added at runtime. * * @return a list in the order how routes was started */ List<RouteStartupOrder> getRouteStartupOrder();