use of org.apache.camel.builder.ErrorHandlerBuilderSupport in project camel by apache.
the class DefaultCamelContext method removeRoute.
public synchronized boolean removeRoute(String routeId) throws Exception {
// remove the route from ErrorHandlerBuilder if possible
if (getErrorHandlerBuilder() instanceof ErrorHandlerBuilderSupport) {
ErrorHandlerBuilderSupport builder = (ErrorHandlerBuilderSupport) getErrorHandlerBuilder();
builder.removeOnExceptionList(routeId);
}
// gather a map of all the endpoints in use by the routes, so we can known if a given endpoints is in use
// by one or more routes, when we remove the route
Map<String, Set<Endpoint>> endpointsInUse = new HashMap<String, Set<Endpoint>>();
for (Map.Entry<String, RouteService> entry : routeServices.entrySet()) {
endpointsInUse.put(entry.getKey(), entry.getValue().gatherEndpoints());
}
RouteService routeService = routeServices.get(routeId);
if (routeService != null) {
if (getRouteStatus(routeId).isStopped()) {
routeService.setRemovingRoutes(true);
shutdownRouteService(routeService);
removeRouteDefinition(routeId);
routeServices.remove(routeId);
// remove route from startup order as well, as it was removed
Iterator<RouteStartupOrder> it = routeStartupOrder.iterator();
while (it.hasNext()) {
RouteStartupOrder order = it.next();
if (order.getRoute().getId().equals(routeId)) {
it.remove();
}
}
// from the route which we have removed, then remove all its private endpoints
// (eg the endpoints which are not in use by other routes)
Set<Endpoint> toRemove = new LinkedHashSet<Endpoint>();
for (Endpoint endpoint : endpointsInUse.get(routeId)) {
// how many times is the endpoint in use
int count = 0;
for (Set<Endpoint> endpoints : endpointsInUse.values()) {
if (endpoints.contains(endpoint)) {
count++;
}
}
// notice we will count ourselves so if there is only 1 then its safe to remove
if (count <= 1) {
toRemove.add(endpoint);
}
}
for (Endpoint endpoint : toRemove) {
log.debug("Removing: {} which was only in use by route: {}", endpoint, routeId);
removeEndpoint(endpoint);
}
return true;
} else {
return false;
}
}
return false;
}
Aggregations