Author: davsclaus Date: Wed Oct 24 12:58:51 2012 New Revision: 1401660 URL: http://svn.apache.org/viewvc?rev=1401660&view=rev Log: CAMEL-5739: Camel validates when starting routes that any custom assigned ids on the route models is unique. As this is required to be unique within each CamelContext.
Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java camel/trunk/camel-core/src/main/java/org/apache/camel/model/ProcessorDefinitionHelper.java camel/trunk/camel-core/src/main/java/org/apache/camel/model/RouteDefinitionHelper.java Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java?rev=1401660&r1=1401659&r2=1401660&view=diff ============================================================================== --- camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java (original) +++ camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java Wed Oct 24 12:58:51 2012 @@ -1971,9 +1971,6 @@ public class DefaultCamelContext extends } private boolean doCheckStartupOrderClash(DefaultRouteStartupOrder answer, Map<Integer, DefaultRouteStartupOrder> inputs) throws FailedToStartRouteException { - // TODO: There could potential be routeId clash as well, so we should check for that as well - - // check for clash by startupOrder id DefaultRouteStartupOrder other = inputs.get(answer.getStartupOrder()); if (other != null && answer != other) { Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/model/ProcessorDefinitionHelper.java URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/model/ProcessorDefinitionHelper.java?rev=1401660&r1=1401659&r2=1401660&view=diff ============================================================================== --- camel/trunk/camel-core/src/main/java/org/apache/camel/model/ProcessorDefinitionHelper.java (original) +++ camel/trunk/camel-core/src/main/java/org/apache/camel/model/ProcessorDefinitionHelper.java Wed Oct 24 12:58:51 2012 @@ -137,7 +137,17 @@ public final class ProcessorDefinitionHe } } - public static Set<String> getAllIDs(ProcessorDefinition<?> node, Set<String> set, boolean onlyCustomId, boolean includeAbstract) { + /** + * Traverses the node, including its children (recursive), and gathers all the node ids. + * + * @param node the target node + * @param set set to store ids, if <tt>null</tt> a new set will be created + * @param onlyCustomId whether to only store custom assigned ids (ie. {@link org.apache.camel.model.OptionalIdentifiedDefinition#hasCustomIdAssigned()} + * @param includeAbstract whether to include abstract nodes (ie. {@link org.apache.camel.model.ProcessorDefinition#isAbstract()} + * @return the set with the found ids. + */ + public static Set<String> gatherAllNodeIds(ProcessorDefinition<?> node, Set<String> set, + boolean onlyCustomId, boolean includeAbstract) { if (node == null) { return set; } @@ -163,7 +173,7 @@ public final class ProcessorDefinitionHe if (children != null && !children.isEmpty()) { for (ProcessorDefinition child : children) { // traverse children also - getAllIDs(child, set, onlyCustomId, includeAbstract); + gatherAllNodeIds(child, set, onlyCustomId, includeAbstract); } } Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/model/RouteDefinitionHelper.java URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/model/RouteDefinitionHelper.java?rev=1401660&r1=1401659&r2=1401660&view=diff ============================================================================== --- camel/trunk/camel-core/src/main/java/org/apache/camel/model/RouteDefinitionHelper.java (original) +++ camel/trunk/camel-core/src/main/java/org/apache/camel/model/RouteDefinitionHelper.java Wed Oct 24 12:58:51 2012 @@ -17,13 +17,11 @@ package org.apache.camel.model; import java.util.ArrayList; -import java.util.HashSet; import java.util.LinkedHashSet; import java.util.List; import java.util.Set; import org.apache.camel.CamelContext; -import org.apache.camel.FailedToStartRouteException; import org.apache.camel.builder.ErrorHandlerBuilder; import org.apache.camel.util.CamelContextHelper; import org.apache.camel.util.EndpointHelper; @@ -45,10 +43,10 @@ public final class RouteDefinitionHelper * Validates that the target route has no duplicate id's from any of the existing routes. * * @param target the target route - * @param routes the other routes - * @return <tt>null</tt> if no duplicate id's detected, otherwise the duplicate id is returned. + * @param routes the existing routes + * @return <tt>null</tt> if no duplicate id's detected, otherwise the first found duplicate id is returned. */ - public static String validateUniqueIds(RouteDefinition target, List<RouteDefinition> routes) throws FailedToStartRouteException { + public static String validateUniqueIds(RouteDefinition target, List<RouteDefinition> routes) { Set<String> routesIds = new LinkedHashSet<String>(); // gather all ids for the existing route, but only include custom ids, and no abstract ids // as abstract nodes is cross-cutting functionality such as interceptors etc @@ -57,13 +55,13 @@ public final class RouteDefinitionHelper if (route == target) { continue; } - ProcessorDefinitionHelper.getAllIDs(route, routesIds, true, false); + ProcessorDefinitionHelper.gatherAllNodeIds(route, routesIds, true, false); } // gather all ids for the target route, but only include custom ids, and no abstract ids // as abstract nodes is cross-cutting functionality such as interceptors etc Set<String> targetIds = new LinkedHashSet<String>(); - ProcessorDefinitionHelper.getAllIDs(target, targetIds, true, false); + ProcessorDefinitionHelper.gatherAllNodeIds(target, targetIds, true, false); // now check for clash with the target route for (String id : targetIds) {