private void dumpCamelContext(String msg) { LOGGER.debug("\n\n*************** START: " + msg + " *****************"); List<RouteDefinition> routeDefinitions = camelContext.getRouteDefinitions(); if (routeDefinitions != null) { LOGGER.debug("Number of routes = " + routeDefinitions.size()); for (RouteDefinition routeDef : routeDefinitions) { String routeId = routeDef.getId(); LOGGER.debug("route ID = " + routeId); List<FromDefinition> routeInputs = routeDef.getInputs(); if (routeInputs.isEmpty()) { LOGGER.debug("routeInputs are EMPTY"); } else { for (FromDefinition fromDef : routeInputs) { LOGGER.debug("route input's URI = " + fromDef.getUri()); } } ServiceStatus routeStatus = camelContext.getRouteStatus(routeId); if (routeStatus != null) { LOGGER.debug("Route ID " + routeId + " is started = " + routeStatus.isStarted()); } else { LOGGER.debug("routeStatus is NULL for routeId = " + routeId); } } } LOGGER.debug("*************** END: " + msg + " *****************\n\n"); }
private boolean isMyRoute(String routeId) { boolean status = false; if (this.routeCollection != null) { for (RouteDefinition routeDef : this.routeCollection) { if (routeDef.getId().equals(routeId)) { return true; } } } return status; }
private void removeRoutes() { LOGGER.trace("ENTERING: stopRoutes"); List<RouteDefinition> routeDefinitions = camelContext.getRouteDefinitions(); for (RouteDefinition routeDef : routeDefinitions) { try { // Only remove routes that this Content Directory Monitor created // (since same camelContext shared across all ContentDirectoryMonitors // this is necessary) if (isMyRoute(routeDef.getId())) { LOGGER.trace("Stopping route with ID = " + routeDef.getId()); camelContext.stopRoute(routeDef); // DEPRECATED // camelContext.stopRoute(routeDef.getId()); boolean status = camelContext.removeRoute(routeDef.getId()); LOGGER.trace("Status of removing route " + routeDef.getId() + " is " + status); camelContext.removeRouteDefinition(routeDef); } } catch (Exception e) { LOGGER.warn("Unable to stop Camel route with route ID = " + routeDef.getId(), e); } } LOGGER.trace("EXITING: stopRoutes"); }
public void updateRouteFromXml(String xml) throws Exception { // convert to model from xml RouteDefinition def = ModelHelper.createModelFromXml(xml, RouteDefinition.class); if (def == null) { return; } // if the xml does not contain the route-id then we fix this by adding the actual route id // this may be needed if the route-id was auto-generated, as the intend is to update this route // and not add a new route, adding a new route, use the MBean operation on ManagedCamelContext // instead. if (ObjectHelper.isEmpty(def.getId())) { def.setId(getRouteId()); } else if (!def.getId().equals(getRouteId())) { throw new IllegalArgumentException( "Cannot update route from XML as routeIds does not match. routeId: " + getRouteId() + ", routeId from XML: " + def.getId()); } // add will remove existing route first context.addRouteDefinition(def); }
/** * Removes the wrapped processors for the given routes, as they are no longer in use. * * <p>This is needed to avoid accumulating memory, if a lot of routes is being added and removed. * * @param routes the routes */ private void removeWrappedProcessorsForRoutes(Collection<Route> routes) { // loop the routes, and remove the route associated wrapped processors, as they are no longer in // use for (Route route : routes) { String id = route.getId(); Iterator<KeyValueHolder<ProcessorDefinition<?>, InstrumentationProcessor>> it = wrappedProcessors.values().iterator(); while (it.hasNext()) { KeyValueHolder<ProcessorDefinition<?>, InstrumentationProcessor> holder = it.next(); RouteDefinition def = ProcessorDefinitionHelper.getRoute(holder.getKey()); if (def != null && id.equals(def.getId())) { it.remove(); } } } }
private void startRoute(RouteDefinition routeDef) { String routeId = routeDef.getId(); try { if (isMyRoute(routeId)) { ServiceStatus routeStatus = camelContext.getRouteStatus(routeId); // Only start the route if it is not already started if (routeStatus == null || !routeStatus.isStarted()) { LOGGER.trace("Starting route with ID = " + routeId); camelContext.startRoute(routeDef); // DEPRECATED // this method does not reliably start a route that was created, then // app shutdown, and restarted // camelContext.startRoute(routeId); } } } catch (Exception e) { LOGGER.warn("Unable to start Camel route with route ID = " + routeId, e); } }