Example #1
0
  protected void doStop() throws Exception {

    // if we are stopping CamelContext then we are shutting down
    boolean isShutdownCamelContext = camelContext.isStopping();

    if (isShutdownCamelContext || isRemovingRoutes()) {
      // need to call onRoutesRemove when the CamelContext is shutting down or Route is shutdown
      for (LifecycleStrategy strategy : camelContext.getLifecycleStrategies()) {
        strategy.onRoutesRemove(routes);
      }
    }

    for (Route route : routes) {
      LOG.debug("Stopping services on route: {}", route.getId());

      // gather list of services to stop as we need to start child services as well
      Set<Service> services = gatherChildServices(route, true);

      // stop services
      stopChildService(route, services, isShutdownCamelContext);

      // stop the route itself
      if (isShutdownCamelContext) {
        ServiceHelper.stopAndShutdownServices(route);
      } else {
        ServiceHelper.stopServices(route);
      }

      // invoke callbacks on route policy
      if (route.getRouteContext().getRoutePolicyList() != null) {
        for (RoutePolicy routePolicy : route.getRouteContext().getRoutePolicyList()) {
          routePolicy.onStop(route);
        }
      }
      // fire event
      EventHelper.notifyRouteStopped(camelContext, route);
    }
    if (isRemovingRoutes()) {
      camelContext.removeRouteCollection(routes);
    }
    // need to warm up again
    warmUpDone.set(false);
  }