Author: davsclaus
Date: Thu Jul 30 13:21:27 2009
New Revision: 799257

URL: http://svn.apache.org/viewvc?rev=799257&view=rev
Log:
CAMEL-1866: Introduced NodeIdFactory to aid tooling. Also expose CamelContext 
in InterceptStrategy as its nice to have it there as well.

Added:
    
camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultNodeIdFactory.java
   (with props)
    
camel/trunk/camel-core/src/main/java/org/apache/camel/spi/NodeIdFactory.java   
(with props)
    
camel/trunk/camel-core/src/test/java/org/apache/camel/impl/CustomIdFactoryTest.java
   (with props)
Modified:
    camel/trunk/camel-core/src/main/java/org/apache/camel/CamelContext.java
    
camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java
    
camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultRouteContext.java
    camel/trunk/camel-core/src/main/java/org/apache/camel/impl/RouteService.java
    
camel/trunk/camel-core/src/main/java/org/apache/camel/management/CamelNamingStrategy.java
    
camel/trunk/camel-core/src/main/java/org/apache/camel/management/InstrumentationInterceptStrategy.java
    
camel/trunk/camel-core/src/main/java/org/apache/camel/management/InstrumentationLifecycleStrategy.java
    
camel/trunk/camel-core/src/main/java/org/apache/camel/model/InterceptDefinition.java
    
camel/trunk/camel-core/src/main/java/org/apache/camel/model/OptionalIdentifiedDefinition.java
    
camel/trunk/camel-core/src/main/java/org/apache/camel/model/ProcessorDefinition.java
    
camel/trunk/camel-core/src/main/java/org/apache/camel/processor/DefaultChannel.java
    
camel/trunk/camel-core/src/main/java/org/apache/camel/processor/interceptor/Delayer.java
    
camel/trunk/camel-core/src/main/java/org/apache/camel/processor/interceptor/HandleFault.java
    
camel/trunk/camel-core/src/main/java/org/apache/camel/processor/interceptor/StreamCaching.java
    
camel/trunk/camel-core/src/main/java/org/apache/camel/processor/interceptor/Tracer.java
    
camel/trunk/camel-core/src/main/java/org/apache/camel/spi/InterceptStrategy.java
    
camel/trunk/camel-core/src/test/java/org/apache/camel/issues/TwoTimerWithJMXIssue.java
    
camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/interceptor/ContainerWideInterceptor.java
    
camel/trunk/components/camel-web/src/main/java/org/apache/camel/web/resources/RouteResource.java

Modified: 
camel/trunk/camel-core/src/main/java/org/apache/camel/CamelContext.java
URL: 
http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/CamelContext.java?rev=799257&r1=799256&r2=799257&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/CamelContext.java 
(original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/CamelContext.java Thu 
Jul 30 13:21:27 2009
@@ -25,6 +25,7 @@
 import org.apache.camel.model.DataFormatDefinition;
 import org.apache.camel.model.RouteDefinition;
 import org.apache.camel.spi.ClassResolver;
+import org.apache.camel.spi.NodeIdFactory;
 import org.apache.camel.spi.EndpointStrategy;
 import org.apache.camel.spi.FactoryFinder;
 import org.apache.camel.spi.FactoryFinderResolver;
@@ -455,4 +456,18 @@
      */
     ServicePool<Endpoint, Producer> getProducerServicePool();
 
+    /**
+     * Uses a custom node id factory when generating auto assigned ids to the 
nodes in the route definitions
+     *
+     * @param factory  custom factory to use
+     */
+    void setNodeIdFactory(NodeIdFactory factory);
+
+    /**
+     * Gets the node id factory
+     *
+     * @return  the node id factory
+     */
+    NodeIdFactory getNodeIdFactory();
+
 }

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=799257&r1=799256&r2=799257&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
 Thu Jul 30 13:21:27 2009
@@ -62,6 +62,7 @@
 import org.apache.camel.spi.Language;
 import org.apache.camel.spi.LanguageResolver;
 import org.apache.camel.spi.LifecycleStrategy;
+import org.apache.camel.spi.NodeIdFactory;
 import org.apache.camel.spi.PackageScanClassResolver;
 import org.apache.camel.spi.Registry;
 import org.apache.camel.spi.RouteContext;
@@ -119,6 +120,7 @@
     // we use a capacity of 100 per endpoint, so for the same endpoint we have 
at most 100 producers in the pool
     // so if we have 6 endpoints in the pool, we have 6 x 100 producers in 
total
     private ServicePool<Endpoint, Producer> producerServicePool = new 
DefaultProducerServicePool(100);
+    private NodeIdFactory nodeIdFactory = new DefaultNodeIdFactory();
 
     public DefaultCamelContext() {
         super();
@@ -512,7 +514,7 @@
         Iterator<RouteDefinition> iter = routeDefinitions.iterator();
         while (iter.hasNext()) {
             RouteDefinition route = iter.next();
-            if (route.idOrCreate().equals(key)) {
+            if (route.idOrCreate(nodeIdFactory).equals(key)) {
                 iter.remove();
                 answer = true;
             }
@@ -528,13 +530,13 @@
     }
 
     public void removeRouteDefinition(RouteDefinition routeDefinition) throws 
Exception {
-        String key = routeDefinition.idOrCreate();
+        String key = routeDefinition.idOrCreate(nodeIdFactory);
         stopRoute(key);
         removeRouteDefinition(key);
     }
 
     public ServiceStatus getRouteStatus(RouteDefinition route) {
-        return getRouteStatus(route.idOrCreate());
+        return getRouteStatus(route.idOrCreate(nodeIdFactory));
     }
 
     /**
@@ -557,7 +559,7 @@
 
 
     public void stopRoute(RouteDefinition route) throws Exception {
-        stopRoute(route.idOrCreate());
+        stopRoute(route.idOrCreate(nodeIdFactory));
     }
 
     /**
@@ -1082,6 +1084,14 @@
         }
     }
 
+    public NodeIdFactory getNodeIdFactory() {
+        return nodeIdFactory;
+    }
+
+    public void setNodeIdFactory(NodeIdFactory idFactory) {
+        this.nodeIdFactory = idFactory;
+    }
+
     protected synchronized String getEndpointKey(String uri, Endpoint 
endpoint) {
         if (endpoint.isSingleton()) {
             return uri;

Added: 
camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultNodeIdFactory.java
URL: 
http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultNodeIdFactory.java?rev=799257&view=auto
==============================================================================
--- 
camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultNodeIdFactory.java
 (added)
+++ 
camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultNodeIdFactory.java
 Thu Jul 30 13:21:27 2009
@@ -0,0 +1,52 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.impl;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.concurrent.atomic.AtomicInteger;
+
+import org.apache.camel.model.OptionalIdentifiedDefinition;
+import org.apache.camel.spi.NodeIdFactory;
+
+/**
+ * Default id factory.
+ *
+ * @version $Revision$
+ */
+public class DefaultNodeIdFactory implements NodeIdFactory {
+
+    protected static Map<String, AtomicInteger> nodeCounters = new 
HashMap<String, AtomicInteger>();
+
+    public String createId(OptionalIdentifiedDefinition definition) {
+        String key = definition.getShortName();
+        return key + getNodeCounter(key).incrementAndGet();
+    }
+
+    /**
+     * Returns the counter for the given node key, lazily creating one if 
necessary
+     */
+    protected static synchronized AtomicInteger getNodeCounter(String key) {
+        AtomicInteger answer = nodeCounters.get(key);
+        if (answer == null) {
+            answer = new AtomicInteger(0);
+            nodeCounters.put(key, answer);
+        }
+        return answer;
+    }
+
+}

Propchange: 
camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultNodeIdFactory.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultNodeIdFactory.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Modified: 
camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultRouteContext.java
URL: 
http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultRouteContext.java?rev=799257&r1=799256&r2=799257&view=diff
==============================================================================
--- 
camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultRouteContext.java
 (original)
+++ 
camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultRouteContext.java
 Thu Jul 30 13:21:27 2009
@@ -139,7 +139,7 @@
 
             // and create the route that wraps the UoW
             Route edcr = new EventDrivenConsumerRoute(getEndpoint(), 
unitOfWorkProcessor);
-            edcr.getProperties().put(Route.ID_PROPERTY, route.idOrCreate());
+            edcr.getProperties().put(Route.ID_PROPERTY, 
route.idOrCreate(getCamelContext().getNodeIdFactory()));
             edcr.getProperties().put(Route.PARENT_PROPERTY, 
Integer.toHexString(route.hashCode()));
             if (route.getGroup() != null) {
                 edcr.getProperties().put(Route.GROUP_PROPERTY, 
route.getGroup());

Modified: 
camel/trunk/camel-core/src/main/java/org/apache/camel/impl/RouteService.java
URL: 
http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/RouteService.java?rev=799257&r1=799256&r2=799257&view=diff
==============================================================================
--- 
camel/trunk/camel-core/src/main/java/org/apache/camel/impl/RouteService.java 
(original)
+++ 
camel/trunk/camel-core/src/main/java/org/apache/camel/impl/RouteService.java 
Thu Jul 30 13:21:27 2009
@@ -45,7 +45,7 @@
         this.routeDefinition = routeDefinition;
         this.routeContexts = routeContexts;
         this.routes = routes;
-        this.id = routeDefinition.idOrCreate();
+        this.id = routeDefinition.idOrCreate(camelContext.getNodeIdFactory());
     }
 
     public String getId() {

Modified: 
camel/trunk/camel-core/src/main/java/org/apache/camel/management/CamelNamingStrategy.java
URL: 
http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/management/CamelNamingStrategy.java?rev=799257&r1=799256&r2=799257&view=diff
==============================================================================
--- 
camel/trunk/camel-core/src/main/java/org/apache/camel/management/CamelNamingStrategy.java
 (original)
+++ 
camel/trunk/camel-core/src/main/java/org/apache/camel/management/CamelNamingStrategy.java
 Thu Jul 30 13:21:27 2009
@@ -159,7 +159,7 @@
             cid = null;
         }
         //String id = VALUE_UNKNOWN.equals(cid) ? 
ObjectName.quote(getEndpointId(ep) : "[" + cid + "]" + 
ObjectName.quote(getEndpointId(ep);
-        String nodeId = processor.idOrCreate();
+        String nodeId = 
processor.idOrCreate(routeContext.getCamelContext().getNodeIdFactory());
 
         StringBuffer buffer = new StringBuffer();
         buffer.append(domainName).append(":");

Modified: 
camel/trunk/camel-core/src/main/java/org/apache/camel/management/InstrumentationInterceptStrategy.java
URL: 
http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/management/InstrumentationInterceptStrategy.java?rev=799257&r1=799256&r2=799257&view=diff
==============================================================================
--- 
camel/trunk/camel-core/src/main/java/org/apache/camel/management/InstrumentationInterceptStrategy.java
 (original)
+++ 
camel/trunk/camel-core/src/main/java/org/apache/camel/management/InstrumentationInterceptStrategy.java
 Thu Jul 30 13:21:27 2009
@@ -18,6 +18,7 @@
 
 import java.util.Map;
 
+import org.apache.camel.CamelContext;
 import org.apache.camel.Processor;
 import org.apache.camel.model.ProcessorDefinition;
 import org.apache.camel.spi.InterceptStrategy;
@@ -40,20 +41,21 @@
         this.registeredCounters = registeredCounters;
     }
 
-    public Processor wrapProcessorInInterceptors(ProcessorDefinition 
processorDefinition, Processor target, Processor nextTarget) throws Exception {
+    public Processor wrapProcessorInInterceptors(CamelContext context, 
ProcessorDefinition definition,
+                                                 Processor target, Processor 
nextTarget) throws Exception {
         // dont double wrap it
         if (target instanceof InstrumentationProcessor) {
             return target;
         }
 
         // only wrap a performance counter if we have it registered in JMX by 
the jmx agent
-        PerformanceCounter counter = 
registeredCounters.get(processorDefinition);
+        PerformanceCounter counter = registeredCounters.get(definition);
         if (counter != null) {
             InstrumentationProcessor wrapper = new 
InstrumentationProcessor(counter);
             wrapper.setProcessor(target);
-            wrapper.setType(processorDefinition.getShortName());
+            wrapper.setType(definition.getShortName());
             // remove to not double wrap it
-            registeredCounters.remove(processorDefinition);
+            registeredCounters.remove(definition);
             return wrapper;
         }
 

Modified: 
camel/trunk/camel-core/src/main/java/org/apache/camel/management/InstrumentationLifecycleStrategy.java
URL: 
http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/management/InstrumentationLifecycleStrategy.java?rev=799257&r1=799256&r2=799257&view=diff
==============================================================================
--- 
camel/trunk/camel-core/src/main/java/org/apache/camel/management/InstrumentationLifecycleStrategy.java
 (original)
+++ 
camel/trunk/camel-core/src/main/java/org/apache/camel/management/InstrumentationLifecycleStrategy.java
 Thu Jul 30 13:21:27 2009
@@ -270,13 +270,14 @@
         // add an intercept strategy that counts when the route sends to any 
of its outputs
         if (out != null) {
             out.addInterceptStrategy(new InterceptStrategy() {
-                public Processor 
wrapProcessorInInterceptors(ProcessorDefinition processorDefinition, Processor 
target, Processor nextTarget) throws Exception {
+                public Processor wrapProcessorInInterceptors(CamelContext 
context, ProcessorDefinition definition,
+                                                             Processor target, 
Processor nextTarget) throws Exception {
                     if (registeredRoutes.containsKey(endpoint)) {
                         // do not double wrap
                         return target;
                     }
                     InstrumentationProcessor wrapper = new 
InstrumentationProcessor(null);
-                    wrapper.setType(processorDefinition.getShortName());
+                    wrapper.setType(definition.getShortName());
                     wrapper.setProcessor(target);
 
                     // register our wrapper

Modified: 
camel/trunk/camel-core/src/main/java/org/apache/camel/model/InterceptDefinition.java
URL: 
http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/model/InterceptDefinition.java?rev=799257&r1=799256&r2=799257&view=diff
==============================================================================
--- 
camel/trunk/camel-core/src/main/java/org/apache/camel/model/InterceptDefinition.java
 (original)
+++ 
camel/trunk/camel-core/src/main/java/org/apache/camel/model/InterceptDefinition.java
 Thu Jul 30 13:21:27 2009
@@ -23,6 +23,7 @@
 import javax.xml.bind.annotation.XmlRootElement;
 import javax.xml.bind.annotation.XmlTransient;
 
+import org.apache.camel.CamelContext;
 import org.apache.camel.Predicate;
 import org.apache.camel.Processor;
 import org.apache.camel.processor.Pipeline;
@@ -73,7 +74,8 @@
         routeContext.getInterceptStrategies().add(new InterceptStrategy() {
             private Processor interceptedTarget;
 
-            public Processor wrapProcessorInInterceptors(ProcessorDefinition 
processorDefinition, Processor target, Processor nextTarget) throws Exception {
+            public Processor wrapProcessorInInterceptors(CamelContext context, 
ProcessorDefinition definition,
+                                                         Processor target, 
Processor nextTarget) throws Exception {
                 // prefer next target over taget as next target is the real 
target
                 interceptedTarget = nextTarget != null ? nextTarget : target;
 

Modified: 
camel/trunk/camel-core/src/main/java/org/apache/camel/model/OptionalIdentifiedDefinition.java
URL: 
http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/model/OptionalIdentifiedDefinition.java?rev=799257&r1=799256&r2=799257&view=diff
==============================================================================
--- 
camel/trunk/camel-core/src/main/java/org/apache/camel/model/OptionalIdentifiedDefinition.java
 (original)
+++ 
camel/trunk/camel-core/src/main/java/org/apache/camel/model/OptionalIdentifiedDefinition.java
 Thu Jul 30 13:21:27 2009
@@ -16,10 +16,6 @@
  */
 package org.apache.camel.model;
 
-import java.util.HashMap;
-import java.util.Map;
-import java.util.concurrent.atomic.AtomicInteger;
-
 import javax.xml.bind.annotation.XmlAccessType;
 import javax.xml.bind.annotation.XmlAccessorType;
 import javax.xml.bind.annotation.XmlAttribute;
@@ -30,7 +26,7 @@
 import javax.xml.bind.annotation.adapters.CollapsedStringAdapter;
 import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
 
-import org.apache.camel.CamelContext;
+import org.apache.camel.spi.NodeIdFactory;
 
 /**
  * Allows an element to have an optional ID specified
@@ -40,8 +36,6 @@
 @XmlType(name = "optionalIdentifiedDefinition")
 @XmlAccessorType(XmlAccessType.FIELD)
 public abstract class OptionalIdentifiedDefinition<T extends 
OptionalIdentifiedDefinition> {
-    @XmlTransient
-    protected static Map<String, AtomicInteger> nodeCounters = new 
HashMap<String, AtomicInteger>();
     @XmlAttribute(required = false)
     @XmlJavaTypeAdapter(CollapsedStringAdapter.class)
     @XmlID
@@ -51,7 +45,6 @@
     @XmlElement(required = false)
     private DescriptionDefinition description;
 
-
     /**
      * Gets the value of the id property.
      */
@@ -130,9 +123,9 @@
     /**
      * Gets the node id, creating one if not already set.
      */
-    public String idOrCreate() {
+    public String idOrCreate(NodeIdFactory factory) {
         if (id == null) {
-            id = createId();
+            id = factory.createId(this);
         }
         return getId();
     }
@@ -147,23 +140,4 @@
     // Implementation methods
     // 
-------------------------------------------------------------------------
 
-    /**
-     * A helper method to create a new id for this node
-     */
-    protected String createId() {
-        String key = getShortName();
-        return key + getNodeCounter(key).incrementAndGet();
-    }
-
-    /**
-     * Returns the counter for the given node key, lazily creating one if 
necessary
-     */
-    protected static synchronized AtomicInteger getNodeCounter(String key) {
-        AtomicInteger answer = nodeCounters.get(key);
-        if (answer == null) {
-            answer = new AtomicInteger(0);
-            nodeCounters.put(key, answer);
-        }
-        return answer;
-    }
 }
\ No newline at end of file

Modified: 
camel/trunk/camel-core/src/main/java/org/apache/camel/model/ProcessorDefinition.java
URL: 
http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/model/ProcessorDefinition.java?rev=799257&r1=799256&r2=799257&view=diff
==============================================================================
--- 
camel/trunk/camel-core/src/main/java/org/apache/camel/model/ProcessorDefinition.java
 (original)
+++ 
camel/trunk/camel-core/src/main/java/org/apache/camel/model/ProcessorDefinition.java
 Thu Jul 30 13:21:27 2009
@@ -2198,5 +2198,4 @@
         return "";
     }
 
-
 }

Modified: 
camel/trunk/camel-core/src/main/java/org/apache/camel/processor/DefaultChannel.java
URL: 
http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/processor/DefaultChannel.java?rev=799257&r1=799256&r2=799257&view=diff
==============================================================================
--- 
camel/trunk/camel-core/src/main/java/org/apache/camel/processor/DefaultChannel.java
 (original)
+++ 
camel/trunk/camel-core/src/main/java/org/apache/camel/processor/DefaultChannel.java
 Thu Jul 30 13:21:27 2009
@@ -135,7 +135,7 @@
         Processor target = nextProcessor;
         for (InterceptStrategy strategy : interceptors) {
             Processor next = target == nextProcessor ? null : nextProcessor;
-            target = strategy.wrapProcessorInInterceptors(outputDefinition, 
target, next);
+            target = 
strategy.wrapProcessorInInterceptors(routeContext.getCamelContext(), 
outputDefinition, target, next);
         }
 
         // sets the delegate to our wrapped output

Modified: 
camel/trunk/camel-core/src/main/java/org/apache/camel/processor/interceptor/Delayer.java
URL: 
http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/processor/interceptor/Delayer.java?rev=799257&r1=799256&r2=799257&view=diff
==============================================================================
--- 
camel/trunk/camel-core/src/main/java/org/apache/camel/processor/interceptor/Delayer.java
 (original)
+++ 
camel/trunk/camel-core/src/main/java/org/apache/camel/processor/interceptor/Delayer.java
 Thu Jul 30 13:21:27 2009
@@ -54,8 +54,9 @@
         return null;
     }
 
-    public Processor wrapProcessorInInterceptors(ProcessorDefinition 
processorDefinition, Processor target, Processor nextTarget) throws Exception {
-        return new DelayInterceptor(processorDefinition, target, this);
+    public Processor wrapProcessorInInterceptors(CamelContext context, 
ProcessorDefinition definition,
+                                                 Processor target, Processor 
nextTarget) throws Exception {
+        return new DelayInterceptor(definition, target, this);
     }
 
     public boolean isEnabled() {

Modified: 
camel/trunk/camel-core/src/main/java/org/apache/camel/processor/interceptor/HandleFault.java
URL: 
http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/processor/interceptor/HandleFault.java?rev=799257&r1=799256&r2=799257&view=diff
==============================================================================
--- 
camel/trunk/camel-core/src/main/java/org/apache/camel/processor/interceptor/HandleFault.java
 (original)
+++ 
camel/trunk/camel-core/src/main/java/org/apache/camel/processor/interceptor/HandleFault.java
 Thu Jul 30 13:21:27 2009
@@ -28,8 +28,8 @@
  */
 public final class HandleFault implements InterceptStrategy {
 
-    @SuppressWarnings("unchecked")
-    public Processor wrapProcessorInInterceptors(ProcessorDefinition 
processorDefinition, Processor target, Processor nextTarget) throws Exception {
+    public Processor wrapProcessorInInterceptors(CamelContext context, 
ProcessorDefinition definition,
+                                                 Processor target, Processor 
nextTarget) throws Exception {
         return new HandleFaultInterceptor(target);
     }
 

Modified: 
camel/trunk/camel-core/src/main/java/org/apache/camel/processor/interceptor/StreamCaching.java
URL: 
http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/processor/interceptor/StreamCaching.java?rev=799257&r1=799256&r2=799257&view=diff
==============================================================================
--- 
camel/trunk/camel-core/src/main/java/org/apache/camel/processor/interceptor/StreamCaching.java
 (original)
+++ 
camel/trunk/camel-core/src/main/java/org/apache/camel/processor/interceptor/StreamCaching.java
 Thu Jul 30 13:21:27 2009
@@ -28,8 +28,8 @@
  */
 public final class StreamCaching implements InterceptStrategy {
     
-    @SuppressWarnings("unchecked")
-    public Processor wrapProcessorInInterceptors(ProcessorDefinition 
processorDefinition, Processor target, Processor nextTarget) throws Exception {
+    public Processor wrapProcessorInInterceptors(CamelContext context, 
ProcessorDefinition definition,
+                                                 Processor target, Processor 
nextTarget) throws Exception {
         return new StreamCachingInterceptor(target);
     }
     

Modified: 
camel/trunk/camel-core/src/main/java/org/apache/camel/processor/interceptor/Tracer.java
URL: 
http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/processor/interceptor/Tracer.java?rev=799257&r1=799256&r2=799257&view=diff
==============================================================================
--- 
camel/trunk/camel-core/src/main/java/org/apache/camel/processor/interceptor/Tracer.java
 (original)
+++ 
camel/trunk/camel-core/src/main/java/org/apache/camel/processor/interceptor/Tracer.java
 Thu Jul 30 13:21:27 2009
@@ -18,11 +18,11 @@
 
 import java.util.List;
 
+import org.apache.camel.CamelContext;
 import org.apache.camel.Endpoint;
 import org.apache.camel.LoggingLevel;
 import org.apache.camel.Predicate;
 import org.apache.camel.Processor;
-import org.apache.camel.CamelContext;
 import org.apache.camel.model.ProcessorDefinition;
 import org.apache.camel.spi.InterceptStrategy;
 
@@ -77,11 +77,12 @@
         return null;
     }
 
-    public Processor wrapProcessorInInterceptors(ProcessorDefinition 
processorDefinition, Processor target, Processor nextTarget) throws Exception {
+    public Processor wrapProcessorInInterceptors(CamelContext context, 
ProcessorDefinition definition,
+                                                 Processor target, Processor 
nextTarget) throws Exception {
         // Force the creation of an id, otherwise the id is not available when 
the trace formatter is
         // outputting trace information
-        String id = processorDefinition.idOrCreate();
-        return new TraceInterceptor(processorDefinition, target, formatter, 
this);
+        definition.idOrCreate(context.getNodeIdFactory());
+        return new TraceInterceptor(definition, target, formatter, this);
     }
 
     public TraceFormatter getFormatter() {

Modified: 
camel/trunk/camel-core/src/main/java/org/apache/camel/spi/InterceptStrategy.java
URL: 
http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/spi/InterceptStrategy.java?rev=799257&r1=799256&r2=799257&view=diff
==============================================================================
--- 
camel/trunk/camel-core/src/main/java/org/apache/camel/spi/InterceptStrategy.java
 (original)
+++ 
camel/trunk/camel-core/src/main/java/org/apache/camel/spi/InterceptStrategy.java
 Thu Jul 30 13:21:27 2009
@@ -16,6 +16,7 @@
  */
 package org.apache.camel.spi;
 
+import org.apache.camel.CamelContext;
 import org.apache.camel.Processor;
 import org.apache.camel.model.ProcessorDefinition;
 
@@ -34,12 +35,13 @@
      * to give the implementor an opportunity to wrap the target processor
      * in a route.
      *
-     * @param processorDefinition the object that invokes this method
+     * @param context       Camel context
+     * @param definition    the model this interceptor represents
      * @param target        the processor to be wrapped
      * @param nextTarget    the next processor to be routed to
      * @return processor wrapped with an interceptor or not wrapped
      * @throws Exception can be thrown
      */
-    Processor wrapProcessorInInterceptors(ProcessorDefinition 
processorDefinition,
+    Processor wrapProcessorInInterceptors(CamelContext context, 
ProcessorDefinition definition,
                                           Processor target, Processor 
nextTarget) throws Exception;
 }

Added: 
camel/trunk/camel-core/src/main/java/org/apache/camel/spi/NodeIdFactory.java
URL: 
http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/spi/NodeIdFactory.java?rev=799257&view=auto
==============================================================================
--- 
camel/trunk/camel-core/src/main/java/org/apache/camel/spi/NodeIdFactory.java 
(added)
+++ 
camel/trunk/camel-core/src/main/java/org/apache/camel/spi/NodeIdFactory.java 
Thu Jul 30 13:21:27 2009
@@ -0,0 +1,35 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.spi;
+
+import org.apache.camel.model.OptionalIdentifiedDefinition;
+
+/**
+ * Factory to generate unique ids for model nodes.
+ *
+ * @version $Revision$
+ */
+public interface NodeIdFactory {
+
+    /**
+     * Creates an id for the given model definiton.
+     *
+     * @param definition model definition
+     * @return the id created
+     */
+    String createId(OptionalIdentifiedDefinition definition);
+}

Propchange: 
camel/trunk/camel-core/src/main/java/org/apache/camel/spi/NodeIdFactory.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
camel/trunk/camel-core/src/main/java/org/apache/camel/spi/NodeIdFactory.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Added: 
camel/trunk/camel-core/src/test/java/org/apache/camel/impl/CustomIdFactoryTest.java
URL: 
http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/impl/CustomIdFactoryTest.java?rev=799257&view=auto
==============================================================================
--- 
camel/trunk/camel-core/src/test/java/org/apache/camel/impl/CustomIdFactoryTest.java
 (added)
+++ 
camel/trunk/camel-core/src/test/java/org/apache/camel/impl/CustomIdFactoryTest.java
 Thu Jul 30 13:21:27 2009
@@ -0,0 +1,132 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.impl;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.ContextTestSupport;
+import org.apache.camel.Exchange;
+import org.apache.camel.Processor;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.model.OptionalIdentifiedDefinition;
+import org.apache.camel.model.ProcessorDefinition;
+import org.apache.camel.processor.DelegateProcessor;
+import org.apache.camel.spi.InterceptStrategy;
+import org.apache.camel.spi.NodeIdFactory;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+/**
+ * Demonstrates how you can use a custom id factory to assign ids to Camel 
Java routes
+ * and then attach your own debugger and be able to use the custom ids to know 
at what
+ * point you are debugging
+ *
+ * @version $Revision$
+ */
+public class CustomIdFactoryTest extends ContextTestSupport {
+
+    private static final Log LOG = 
LogFactory.getLog(CustomIdFactoryTest.class);
+
+    private static int counter;
+    private static String ids;
+
+    @Override
+    protected void setUp() throws Exception {
+        ids = "";
+        counter = 0;
+        super.setUp();
+    }
+
+    @Override
+    protected RouteBuilder createRouteBuilder() throws Exception {
+        return new RouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+                // use our own id factory so we can generate the keys we like 
to use
+                context.setNodeIdFactory(new NodeIdFactory() {
+                    public String createId(OptionalIdentifiedDefinition 
definition) {
+                        return "#" + definition.getShortName() + ++counter + 
"#";
+                    }
+                });
+
+                // add our debugger so we can debug camel routes when we send 
in messages
+                context.addInterceptStrategy(new MyDebuggerCheckingId());
+
+                // a little content based router so we got 2 paths to route at 
runtime
+                from("direct:start")
+                    .choice()
+                        .when(body().contains("Hello"))
+                            .to("mock:hello")
+                        .otherwise()
+                            .to("mock:other")
+                    .end();
+            }
+        };
+    }
+
+    /**
+     * Test path 1
+     */
+    public void testHello() throws Exception {
+        assertEquals("#route1#", context.getRouteDefinitions().get(0).getId());
+
+        getMockEndpoint("mock:hello").expectedMessageCount(1);
+        template.sendBody("direct:start", "Hello World");
+        assertMockEndpointsSatisfied();
+
+        // this should take the when path
+        assertEquals("#choice2##when3#", ids);
+    }
+
+    /**
+     * Test path 2
+     */
+    public void testOther() throws Exception {
+        assertEquals("#route1#", context.getRouteDefinitions().get(0).getId());
+
+        getMockEndpoint("mock:other").expectedMessageCount(1);
+        template.sendBody("direct:start", "Bye World");
+        assertMockEndpointsSatisfied();
+
+        // this should take the otherwise path
+        assertEquals("#choice2##otherwise4#", ids);
+    }
+
+    private class MyDebuggerCheckingId implements InterceptStrategy {
+
+        public Processor wrapProcessorInInterceptors(final CamelContext 
context, final ProcessorDefinition definition,
+                                                     Processor target, 
Processor nextTarget) throws Exception {
+
+            // MUST DO THIS
+            // force id creation as sub nodes have lazy assigned ids
+            definition.idOrCreate(context.getNodeIdFactory());
+
+            return new DelegateProcessor(target) {
+                @Override
+                protected void processNext(Exchange exchange) throws Exception 
{
+                    LOG.debug("Debugging at: " + definition.toString() + " 
with id: " + definition.getId() + " with exchange: " + exchange);
+
+                    // record the path taken at runtime
+                    ids += definition.getId();
+
+                    // continue to the real target by invoking super
+                    super.processNext(exchange);
+                }
+            };
+        }
+
+    }
+}

Propchange: 
camel/trunk/camel-core/src/test/java/org/apache/camel/impl/CustomIdFactoryTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
camel/trunk/camel-core/src/test/java/org/apache/camel/impl/CustomIdFactoryTest.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Modified: 
camel/trunk/camel-core/src/test/java/org/apache/camel/issues/TwoTimerWithJMXIssue.java
URL: 
http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/issues/TwoTimerWithJMXIssue.java?rev=799257&r1=799256&r2=799257&view=diff
==============================================================================
--- 
camel/trunk/camel-core/src/test/java/org/apache/camel/issues/TwoTimerWithJMXIssue.java
 (original)
+++ 
camel/trunk/camel-core/src/test/java/org/apache/camel/issues/TwoTimerWithJMXIssue.java
 Thu Jul 30 13:21:27 2009
@@ -16,6 +16,7 @@
  */
 package org.apache.camel.issues;
 
+import org.apache.camel.CamelContext;
 import org.apache.camel.ContextTestSupport;
 import org.apache.camel.Processor;
 import org.apache.camel.builder.RouteBuilder;
@@ -53,12 +54,14 @@
     }
 
     private class MyTracer implements InterceptStrategy {
-        public Processor wrapProcessorInInterceptors(ProcessorDefinition 
processorDefinition, Processor target, Processor nextTarget)
+
+        public Processor wrapProcessorInInterceptors(CamelContext context, 
ProcessorDefinition definition, Processor target, Processor nextTarget)
             throws Exception {
             assertNotNull(target);
             counter++;
             return target;
         }
+
     }
 
 }

Modified: 
camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/interceptor/ContainerWideInterceptor.java
URL: 
http://svn.apache.org/viewvc/camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/interceptor/ContainerWideInterceptor.java?rev=799257&r1=799256&r2=799257&view=diff
==============================================================================
--- 
camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/interceptor/ContainerWideInterceptor.java
 (original)
+++ 
camel/trunk/components/camel-spring/src/test/java/org/apache/camel/spring/interceptor/ContainerWideInterceptor.java
 Thu Jul 30 13:21:27 2009
@@ -16,6 +16,7 @@
  */
 package org.apache.camel.spring.interceptor;
 
+import org.apache.camel.CamelContext;
 import org.apache.camel.Exchange;
 import org.apache.camel.Processor;
 import org.apache.camel.model.ProcessorDefinition;
@@ -32,7 +33,7 @@
     private static final transient Log LOG = 
LogFactory.getLog(ContainerWideInterceptor.class);
     private static int count;
 
-    public Processor wrapProcessorInInterceptors(final ProcessorDefinition 
processorDefinition,
+    public Processor wrapProcessorInInterceptors(final CamelContext context, 
final ProcessorDefinition definition,
                                                  final Processor target, final 
Processor nextTarget) throws Exception {
 
         // as this is based on an unit test we are a bit lazy and just create 
an inlined processor

Modified: 
camel/trunk/components/camel-web/src/main/java/org/apache/camel/web/resources/RouteResource.java
URL: 
http://svn.apache.org/viewvc/camel/trunk/components/camel-web/src/main/java/org/apache/camel/web/resources/RouteResource.java?rev=799257&r1=799256&r2=799257&view=diff
==============================================================================
--- 
camel/trunk/components/camel-web/src/main/java/org/apache/camel/web/resources/RouteResource.java
 (original)
+++ 
camel/trunk/components/camel-web/src/main/java/org/apache/camel/web/resources/RouteResource.java
 Thu Jul 30 13:21:27 2009
@@ -79,7 +79,7 @@
     public RouteResource(RoutesResource routesResource, RouteDefinition route) 
{
         super(routesResource.getContextResource());
         this.route = route;
-        this.id = route.idOrCreate();
+        this.id = route.idOrCreate(route.getCamelContext().getNodeIdFactory());
     }
 
     /**


Reply via email to