Updated Branches:
  refs/heads/master fea576f9e -> 6adb14060

CAMEL-6377: Optimized routing engine to reduce stack frames in use during 
routing.


Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/6adb1406
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/6adb1406
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/6adb1406

Branch: refs/heads/master
Commit: 6adb140603159068e4dfa31b7fb89b8486efdffa
Parents: c5530ac
Author: Claus Ibsen <[email protected]>
Authored: Thu May 30 14:34:00 2013 +0200
Committer: Claus Ibsen <[email protected]>
Committed: Thu May 30 14:36:18 2013 +0200

----------------------------------------------------------------------
 .../camel/impl/CamelPostProcessorHelper.java       |    2 +-
 .../org/apache/camel/impl/DefaultRouteContext.java |   12 +-
 .../DefaultManagementLifecycleStrategy.java        |    2 +-
 .../apache/camel/model/AggregateDefinition.java    |    2 +-
 .../apache/camel/model/MulticastDefinition.java    |    2 +-
 .../apache/camel/model/OnCompletionDefinition.java |    2 +-
 .../apache/camel/model/ResequenceDefinition.java   |    4 +-
 .../org/apache/camel/model/SplitDefinition.java    |    2 +-
 .../org/apache/camel/model/WireTapDefinition.java  |    2 +-
 .../camel/processor/CamelInternalProcessor.java    |  111 ++++++++++----
 .../processor/CamelInternalProcessorAdvice.java    |   49 +++++++
 .../processor/CamelInternalProcessorTask.java      |   49 -------
 .../apache/camel/processor/MulticastProcessor.java |    4 +-
 .../org/apache/camel/processor/RecipientList.java  |    2 +-
 .../apache/camel/processor/UnitOfWorkProducer.java |    2 +-
 .../processor/interceptor/DefaultChannel.java      |    4 +-
 16 files changed, 149 insertions(+), 102 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/6adb1406/camel-core/src/main/java/org/apache/camel/impl/CamelPostProcessorHelper.java
----------------------------------------------------------------------
diff --git 
a/camel-core/src/main/java/org/apache/camel/impl/CamelPostProcessorHelper.java 
b/camel-core/src/main/java/org/apache/camel/impl/CamelPostProcessorHelper.java
index a8dc64b..6ddeb13 100644
--- 
a/camel-core/src/main/java/org/apache/camel/impl/CamelPostProcessorHelper.java
+++ 
b/camel-core/src/main/java/org/apache/camel/impl/CamelPostProcessorHelper.java
@@ -130,7 +130,7 @@ public class CamelPostProcessorHelper implements 
CamelContextAware {
         BeanProcessor answer = new BeanProcessor(pojo, info);
         // must ensure the consumer is being executed in an unit of work so 
synchronization callbacks etc is invoked
         CamelInternalProcessor internal = new CamelInternalProcessor(answer);
-        internal.addTask(new 
CamelInternalProcessor.UnitOfWorkProcessorTask(null));
+        internal.addAdvice(new 
CamelInternalProcessor.UnitOfWorkProcessorAdvice(null));
         return internal;
     }
 

http://git-wip-us.apache.org/repos/asf/camel/blob/6adb1406/camel-core/src/main/java/org/apache/camel/impl/DefaultRouteContext.java
----------------------------------------------------------------------
diff --git 
a/camel-core/src/main/java/org/apache/camel/impl/DefaultRouteContext.java 
b/camel-core/src/main/java/org/apache/camel/impl/DefaultRouteContext.java
index ea32aeb..40b5415 100644
--- a/camel-core/src/main/java/org/apache/camel/impl/DefaultRouteContext.java
+++ b/camel-core/src/main/java/org/apache/camel/impl/DefaultRouteContext.java
@@ -152,10 +152,10 @@ public class DefaultRouteContext implements RouteContext {
 
             // and wrap it in a unit of work so the UoW is on the top, so the 
entire route will be in the same UoW
             CamelInternalProcessor internal = new 
CamelInternalProcessor(target);
-            internal.addTask(new 
CamelInternalProcessor.UnitOfWorkProcessorTask(routeId));
+            internal.addAdvice(new 
CamelInternalProcessor.UnitOfWorkProcessorAdvice(routeId));
 
             // and then in route context so we can keep track which route this 
is at runtime
-            internal.addTask(new 
CamelInternalProcessor.RouteContextTask(this));
+            internal.addAdvice(new 
CamelInternalProcessor.RouteContextAdvice(this));
 
             // and then optionally add route policy processor if a custom 
policy is set
             List<RoutePolicy> routePolicyList = getRoutePolicyList();
@@ -172,14 +172,14 @@ public class DefaultRouteContext implements RouteContext {
                     }
                 }
 
-                internal.addTask(new 
CamelInternalProcessor.RoutePolicyTask(routePolicyList));
+                internal.addAdvice(new 
CamelInternalProcessor.RoutePolicyAdvice(routePolicyList));
             }
 
             // wrap in route inflight processor to track number of inflight 
exchanges for the route
-            internal.addTask(new 
CamelInternalProcessor.RouteInflightRepositoryTask(camelContext.getInflightRepository(),
 routeId));
+            internal.addAdvice(new 
CamelInternalProcessor.RouteInflightRepositoryAdvice(camelContext.getInflightRepository(),
 routeId));
 
             // wrap in JMX instrumentation processor that is used for 
performance stats
-            internal.addTask(new 
CamelInternalProcessor.InstrumentationTask("route"));
+            internal.addAdvice(new 
CamelInternalProcessor.InstrumentationAdvice("route"));
 
             // and create the route that wraps the UoW
             Route edcr = new EventDrivenConsumerRoute(this, getEndpoint(), 
internal);
@@ -190,7 +190,7 @@ public class DefaultRouteContext implements RouteContext {
             }
 
             // after the route is created then set the route on the policy 
processor so we get hold of it
-            CamelInternalProcessor.RoutePolicyTask task = 
internal.getTask(CamelInternalProcessor.RoutePolicyTask.class);
+            CamelInternalProcessor.RoutePolicyAdvice task = 
internal.getAdvice(CamelInternalProcessor.RoutePolicyAdvice.class);
             if (task != null) {
                 task.setRoute(edcr);
             }

http://git-wip-us.apache.org/repos/asf/camel/blob/6adb1406/camel-core/src/main/java/org/apache/camel/management/DefaultManagementLifecycleStrategy.java
----------------------------------------------------------------------
diff --git 
a/camel-core/src/main/java/org/apache/camel/management/DefaultManagementLifecycleStrategy.java
 
b/camel-core/src/main/java/org/apache/camel/management/DefaultManagementLifecycleStrategy.java
index 31d14b6..9b63390 100644
--- 
a/camel-core/src/main/java/org/apache/camel/management/DefaultManagementLifecycleStrategy.java
+++ 
b/camel-core/src/main/java/org/apache/camel/management/DefaultManagementLifecycleStrategy.java
@@ -533,7 +533,7 @@ public class DefaultManagementLifecycleStrategy extends 
ServiceSupport implement
                     CamelInternalProcessor internal = (CamelInternalProcessor) 
processor;
                     ManagedRoute routeMBean = (ManagedRoute) mr;
 
-                    CamelInternalProcessor.InstrumentationTask task = 
internal.getTask(CamelInternalProcessor.InstrumentationTask.class);
+                    CamelInternalProcessor.InstrumentationAdvice task = 
internal.getAdvice(CamelInternalProcessor.InstrumentationAdvice.class);
                     if (task != null) {
                         // we need to wrap the counter with the camel context 
so we get stats updated on the context as well
                         if (camelContextMBean != null) {

http://git-wip-us.apache.org/repos/asf/camel/blob/6adb1406/camel-core/src/main/java/org/apache/camel/model/AggregateDefinition.java
----------------------------------------------------------------------
diff --git 
a/camel-core/src/main/java/org/apache/camel/model/AggregateDefinition.java 
b/camel-core/src/main/java/org/apache/camel/model/AggregateDefinition.java
index d6fb50e..a0dc593 100644
--- a/camel-core/src/main/java/org/apache/camel/model/AggregateDefinition.java
+++ b/camel-core/src/main/java/org/apache/camel/model/AggregateDefinition.java
@@ -163,7 +163,7 @@ public class AggregateDefinition extends 
ProcessorDefinition<AggregateDefinition
 
         // wrap the aggregate route in a unit of work processor
         CamelInternalProcessor internal = new 
CamelInternalProcessor(childProcessor);
-        internal.addTask(new 
CamelInternalProcessor.UnitOfWorkProcessorTask(routeId));
+        internal.addAdvice(new 
CamelInternalProcessor.UnitOfWorkProcessorAdvice(routeId));
 
         Expression correlation = 
getExpression().createExpression(routeContext);
         AggregationStrategy strategy = createAggregationStrategy(routeContext);

http://git-wip-us.apache.org/repos/asf/camel/blob/6adb1406/camel-core/src/main/java/org/apache/camel/model/MulticastDefinition.java
----------------------------------------------------------------------
diff --git 
a/camel-core/src/main/java/org/apache/camel/model/MulticastDefinition.java 
b/camel-core/src/main/java/org/apache/camel/model/MulticastDefinition.java
index 834eb96..b0e65a2 100644
--- a/camel-core/src/main/java/org/apache/camel/model/MulticastDefinition.java
+++ b/camel-core/src/main/java/org/apache/camel/model/MulticastDefinition.java
@@ -231,7 +231,7 @@ public class MulticastDefinition extends 
OutputDefinition<MulticastDefinition> i
         if (isShareUnitOfWork()) {
             // wrap answer in a sub unit of work, since we share the unit of 
work
             CamelInternalProcessor internalProcessor = new 
CamelInternalProcessor(answer);
-            internalProcessor.addTask(new 
CamelInternalProcessor.SubUnitOfWorkProcessorTask());
+            internalProcessor.addAdvice(new 
CamelInternalProcessor.SubUnitOfWorkProcessorAdvice());
             return internalProcessor;
         }
         return answer;

http://git-wip-us.apache.org/repos/asf/camel/blob/6adb1406/camel-core/src/main/java/org/apache/camel/model/OnCompletionDefinition.java
----------------------------------------------------------------------
diff --git 
a/camel-core/src/main/java/org/apache/camel/model/OnCompletionDefinition.java 
b/camel-core/src/main/java/org/apache/camel/model/OnCompletionDefinition.java
index 2558ad1..e67f780 100644
--- 
a/camel-core/src/main/java/org/apache/camel/model/OnCompletionDefinition.java
+++ 
b/camel-core/src/main/java/org/apache/camel/model/OnCompletionDefinition.java
@@ -122,7 +122,7 @@ public class OnCompletionDefinition extends 
ProcessorDefinition<OnCompletionDefi
 
         // wrap the on completion route in a unit of work processor
         CamelInternalProcessor internal = new 
CamelInternalProcessor(childProcessor);
-        internal.addTask(new 
CamelInternalProcessor.UnitOfWorkProcessorTask(routeId));
+        internal.addAdvice(new 
CamelInternalProcessor.UnitOfWorkProcessorAdvice(routeId));
 
         onCompletions.put(routeId, internal);
 

http://git-wip-us.apache.org/repos/asf/camel/blob/6adb1406/camel-core/src/main/java/org/apache/camel/model/ResequenceDefinition.java
----------------------------------------------------------------------
diff --git 
a/camel-core/src/main/java/org/apache/camel/model/ResequenceDefinition.java 
b/camel-core/src/main/java/org/apache/camel/model/ResequenceDefinition.java
index c208086..adcf2f4 100644
--- a/camel-core/src/main/java/org/apache/camel/model/ResequenceDefinition.java
+++ b/camel-core/src/main/java/org/apache/camel/model/ResequenceDefinition.java
@@ -349,7 +349,7 @@ public class ResequenceDefinition extends 
ProcessorDefinition<ResequenceDefiniti
         // and wrap in unit of work
         String routeId = 
routeContext.getRoute().idOrCreate(routeContext.getCamelContext().getNodeIdFactory());
         CamelInternalProcessor internal = new 
CamelInternalProcessor(processor);
-        internal.addTask(new 
CamelInternalProcessor.UnitOfWorkProcessorTask(routeId));
+        internal.addAdvice(new 
CamelInternalProcessor.UnitOfWorkProcessorAdvice(routeId));
 
         ObjectHelper.notNull(config, "config", this);
         ObjectHelper.notNull(expression, "expression", this);
@@ -380,7 +380,7 @@ public class ResequenceDefinition extends 
ProcessorDefinition<ResequenceDefiniti
         // and wrap in unit of work
         String routeId = 
routeContext.getRoute().idOrCreate(routeContext.getCamelContext().getNodeIdFactory());
         CamelInternalProcessor internal = new 
CamelInternalProcessor(processor);
-        internal.addTask(new 
CamelInternalProcessor.UnitOfWorkProcessorTask(routeId));
+        internal.addAdvice(new 
CamelInternalProcessor.UnitOfWorkProcessorAdvice(routeId));
 
         ObjectHelper.notNull(config, "config", this);
         ObjectHelper.notNull(expression, "expression", this);

http://git-wip-us.apache.org/repos/asf/camel/blob/6adb1406/camel-core/src/main/java/org/apache/camel/model/SplitDefinition.java
----------------------------------------------------------------------
diff --git 
a/camel-core/src/main/java/org/apache/camel/model/SplitDefinition.java 
b/camel-core/src/main/java/org/apache/camel/model/SplitDefinition.java
index 71eaa89..f6ea616 100644
--- a/camel-core/src/main/java/org/apache/camel/model/SplitDefinition.java
+++ b/camel-core/src/main/java/org/apache/camel/model/SplitDefinition.java
@@ -114,7 +114,7 @@ public class SplitDefinition extends ExpressionNode 
implements ExecutorServiceAw
         if (isShareUnitOfWork()) {
             // wrap answer in a sub unit of work, since we share the unit of 
work
             CamelInternalProcessor internalProcessor = new 
CamelInternalProcessor(answer);
-            internalProcessor.addTask(new 
CamelInternalProcessor.SubUnitOfWorkProcessorTask());
+            internalProcessor.addAdvice(new 
CamelInternalProcessor.SubUnitOfWorkProcessorAdvice());
             return internalProcessor;
         }
         return answer;

http://git-wip-us.apache.org/repos/asf/camel/blob/6adb1406/camel-core/src/main/java/org/apache/camel/model/WireTapDefinition.java
----------------------------------------------------------------------
diff --git 
a/camel-core/src/main/java/org/apache/camel/model/WireTapDefinition.java 
b/camel-core/src/main/java/org/apache/camel/model/WireTapDefinition.java
index 25c8c4d..f66f54d 100644
--- a/camel-core/src/main/java/org/apache/camel/model/WireTapDefinition.java
+++ b/camel-core/src/main/java/org/apache/camel/model/WireTapDefinition.java
@@ -96,7 +96,7 @@ public class WireTapDefinition<Type extends 
ProcessorDefinition<Type>> extends N
         // and wrap in unit of work
         String routeId = 
routeContext.getRoute().idOrCreate(routeContext.getCamelContext().getNodeIdFactory());
         CamelInternalProcessor internal = new CamelInternalProcessor(target);
-        internal.addTask(new 
CamelInternalProcessor.UnitOfWorkProcessorTask(routeId));
+        internal.addAdvice(new 
CamelInternalProcessor.UnitOfWorkProcessorAdvice(routeId));
 
         WireTapProcessor answer = new WireTapProcessor(endpoint, internal, 
getPattern(), threadPool, shutdownThreadPool);
         answer.setCopy(isCopy());

http://git-wip-us.apache.org/repos/asf/camel/blob/6adb1406/camel-core/src/main/java/org/apache/camel/processor/CamelInternalProcessor.java
----------------------------------------------------------------------
diff --git 
a/camel-core/src/main/java/org/apache/camel/processor/CamelInternalProcessor.java
 
b/camel-core/src/main/java/org/apache/camel/processor/CamelInternalProcessor.java
index d2eff83..217c8d7 100644
--- 
a/camel-core/src/main/java/org/apache/camel/processor/CamelInternalProcessor.java
+++ 
b/camel-core/src/main/java/org/apache/camel/processor/CamelInternalProcessor.java
@@ -58,9 +58,9 @@ import org.slf4j.LoggerFactory;
  * </ul>
  * ... and more.
  * <p/>
- * This implementation executes this cross cutting functionality as a {@link 
CamelInternalProcessorTask} task
- * by executing the {@link 
CamelInternalProcessorTask#before(org.apache.camel.Exchange)} and
- * {@link CamelInternalProcessorTask#after(org.apache.camel.Exchange, Object)} 
callbacks in correct order during routing.
+ * This implementation executes this cross cutting functionality as a {@link 
CamelInternalProcessorAdvice} advice (before and after advice)
+ * by executing the {@link 
CamelInternalProcessorAdvice#before(org.apache.camel.Exchange)} and
+ * {@link CamelInternalProcessorAdvice#after(org.apache.camel.Exchange, 
Object)} callbacks in correct order during routing.
  * This reduces number of stack frames needed during routing, and reduce the 
number of lines in stacktraces, as well
  * makes debugging the routing engine easier for end users.
  * <p/>
@@ -71,7 +71,7 @@ import org.slf4j.LoggerFactory;
 public class CamelInternalProcessor extends DelegateAsyncProcessor {
 
     private static final Logger LOG = 
LoggerFactory.getLogger(CamelInternalProcessor.class);
-    private final List<CamelInternalProcessorTask> tasks = new 
ArrayList<CamelInternalProcessorTask>();
+    private final List<CamelInternalProcessorAdvice> advices = new 
ArrayList<CamelInternalProcessorAdvice>();
 
     public CamelInternalProcessor() {
     }
@@ -80,12 +80,23 @@ public class CamelInternalProcessor extends 
DelegateAsyncProcessor {
         super(processor);
     }
 
-    public void addTask(CamelInternalProcessorTask task) {
-        tasks.add(task);
+    /**
+     * Adds an {@link CamelInternalProcessorAdvice} advice to the list of 
advices to execute by this internal processor.
+     *
+     * @param advice  the advice to add
+     */
+    public void addAdvice(CamelInternalProcessorAdvice advice) {
+        advices.add(advice);
     }
 
-    public <T> T getTask(Class<T> type) {
-        for (CamelInternalProcessorTask task : tasks) {
+    /**
+     * Gets the advice with the given type.
+     *
+     * @param type  the type of the advice
+     * @return the advice if exists, or <tt>null</tt> if no advices has been 
added with the given type.
+     */
+    public <T> T getAdvice(Class<T> type) {
+        for (CamelInternalProcessorAdvice task : advices) {
             if (type.isInstance(task)) {
                 return type.cast(task);
             }
@@ -116,8 +127,8 @@ public class CamelInternalProcessor extends 
DelegateAsyncProcessor {
             return true;
         }
 
-        final List<Object> states = new ArrayList<Object>(tasks.size());
-        for (CamelInternalProcessorTask task : tasks) {
+        final List<Object> states = new ArrayList<Object>(advices.size());
+        for (CamelInternalProcessorAdvice task : advices) {
             try {
                 Object state = task.before(exchange);
                 states.add(state);
@@ -128,7 +139,7 @@ public class CamelInternalProcessor extends 
DelegateAsyncProcessor {
             }
         }
 
-        // create internal callback which will execute the tasks in reverse 
order when done
+        // create internal callback which will execute the advices in reverse 
order when done
         callback = new InternalCallback(states, exchange, callback);
 
         // UNIT_OF_WORK_PROCESS_SYNC is @deprecated and we should remove it 
from Camel 3.0
@@ -194,6 +205,9 @@ public class CamelInternalProcessor extends 
DelegateAsyncProcessor {
         return processor != null ? processor.toString() : super.toString();
     }
 
+    /**
+     * Internal callback that executes the after advices.
+     */
     private final class InternalCallback implements AsyncCallback {
 
         private final List<Object> states;
@@ -213,14 +227,14 @@ public class CamelInternalProcessor extends 
DelegateAsyncProcessor {
 
             // we should call after in reverse order
             try {
-                for (int i = tasks.size() - 1; i >= 0; i--) {
-                    CamelInternalProcessorTask task = tasks.get(i);
+                for (int i = advices.size() - 1; i >= 0; i--) {
+                    CamelInternalProcessorAdvice task = advices.get(i);
                     Object state = states.get(i);
                     try {
                         task.after(exchange, state);
                     } catch (Exception e) {
                         exchange.setException(e);
-                        // allow all tasks to complete even if there was an 
exception
+                        // allow all advices to complete even if there was an 
exception
                     }
                 }
             } finally {
@@ -263,12 +277,20 @@ public class CamelInternalProcessor extends 
DelegateAsyncProcessor {
         return true;
     }
 
-    public static class InstrumentationTask implements 
CamelInternalProcessorTask<StopWatch> {
+    /**
+     * Advice for JMX instrumentation of the process being invoked.
+     * <p/>
+     * This advice keeps track of JMX metrics for performance statistics.
+     * <p/>
+     * The current implementation of this advice is only used for route level 
statistics. For processor levels
+     * they are still wrapped in the route processor chains.
+     */
+    public static class InstrumentationAdvice implements 
CamelInternalProcessorAdvice<StopWatch> {
 
         private PerformanceCounter counter;
         private String type;
 
-        public InstrumentationTask(String type) {
+        public InstrumentationAdvice(String type) {
             this.type = type;
         }
 
@@ -322,11 +344,14 @@ public class CamelInternalProcessor extends 
DelegateAsyncProcessor {
         }
     }
 
-    public static class RouteContextTask implements 
CamelInternalProcessorTask<UnitOfWork> {
+    /**
+     * Advice to inject the current {@link RouteContext} into the {@link 
UnitOfWork} on the {@link Exchange}
+     */
+    public static class RouteContextAdvice implements 
CamelInternalProcessorAdvice<UnitOfWork> {
 
         private final RouteContext routeContext;
 
-        public RouteContextTask(RouteContext routeContext) {
+        public RouteContextAdvice(RouteContext routeContext) {
             this.routeContext = routeContext;
         }
 
@@ -348,12 +373,15 @@ public class CamelInternalProcessor extends 
DelegateAsyncProcessor {
         }
     }
 
-    public static class RouteInflightRepositoryTask implements 
CamelInternalProcessorTask {
+    /**
+     * Advice to keep the {@link InflightRepository} up to date.
+     */
+    public static class RouteInflightRepositoryAdvice implements 
CamelInternalProcessorAdvice {
 
         private final InflightRepository inflightRepository;
         private final String id;
 
-        public RouteInflightRepositoryTask(InflightRepository 
inflightRepository, String id) {
+        public RouteInflightRepositoryAdvice(InflightRepository 
inflightRepository, String id) {
             this.inflightRepository = inflightRepository;
             this.id = id;
         }
@@ -370,12 +398,15 @@ public class CamelInternalProcessor extends 
DelegateAsyncProcessor {
         }
     }
 
-    public static class RoutePolicyTask implements CamelInternalProcessorTask {
+    /**
+     * Advice to execute any {@link RoutePolicy} a route may have been 
configured with.
+     */
+    public static class RoutePolicyAdvice implements 
CamelInternalProcessorAdvice {
 
         private final List<RoutePolicy> routePolicies;
         private Route route;
 
-        public RoutePolicyTask(List<RoutePolicy> routePolicies) {
+        public RoutePolicyAdvice(List<RoutePolicy> routePolicies) {
             this.routePolicies = routePolicies;
         }
 
@@ -442,7 +473,10 @@ public class CamelInternalProcessor extends 
DelegateAsyncProcessor {
         }
     }
 
-    public static final class BacklogTracerTask implements 
CamelInternalProcessorTask {
+    /**
+     * Advice to execute the {@link BacklogTracer} if enabled.
+     */
+    public static final class BacklogTracerAdvice implements 
CamelInternalProcessorAdvice {
 
         private final Queue<DefaultBacklogTracerEventMessage> queue;
         private final BacklogTracer backlogTracer;
@@ -450,8 +484,8 @@ public class CamelInternalProcessor extends 
DelegateAsyncProcessor {
         private final ProcessorDefinition<?> routeDefinition;
         private final boolean first;
 
-        public BacklogTracerTask(Queue<DefaultBacklogTracerEventMessage> 
queue, BacklogTracer backlogTracer,
-                                 ProcessorDefinition<?> processorDefinition, 
ProcessorDefinition<?> routeDefinition, boolean first) {
+        public BacklogTracerAdvice(Queue<DefaultBacklogTracerEventMessage> 
queue, BacklogTracer backlogTracer,
+                                   ProcessorDefinition<?> processorDefinition, 
ProcessorDefinition<?> routeDefinition, boolean first) {
             this.queue = queue;
             this.backlogTracer = backlogTracer;
             this.processorDefinition = processorDefinition;
@@ -498,14 +532,17 @@ public class CamelInternalProcessor extends 
DelegateAsyncProcessor {
         }
     }
 
-    public static final class BacklogDebuggerTask implements 
CamelInternalProcessorTask<StopWatch> {
+    /**
+     * Advice to execute the {@link 
org.apache.camel.processor.interceptor.BacklogDebugger} if enabled.
+     */
+    public static final class BacklogDebuggerAdvice implements 
CamelInternalProcessorAdvice<StopWatch> {
 
         private final BacklogDebugger backlogDebugger;
         private final Processor target;
         private final ProcessorDefinition<?> definition;
         private final String nodeId;
 
-        public BacklogDebuggerTask(BacklogDebugger backlogDebugger, Processor 
target, ProcessorDefinition<?> definition) {
+        public BacklogDebuggerAdvice(BacklogDebugger backlogDebugger, 
Processor target, ProcessorDefinition<?> definition) {
             this.backlogDebugger = backlogDebugger;
             this.target = target;
             this.definition = definition;
@@ -531,11 +568,15 @@ public class CamelInternalProcessor extends 
DelegateAsyncProcessor {
         }
     }
 
-    public static class UnitOfWorkProcessorTask implements 
CamelInternalProcessorTask<UnitOfWork> {
+    /**
+     * Advice to inject new {@link UnitOfWork} to the {@link Exchange} if 
needed, and as well to ensure
+     * the {@link UnitOfWork} is done and stopped.
+     */
+    public static class UnitOfWorkProcessorAdvice implements 
CamelInternalProcessorAdvice<UnitOfWork> {
 
         private final String routeId;
 
-        public UnitOfWorkProcessorTask(String routeId) {
+        public UnitOfWorkProcessorAdvice(String routeId) {
             this.routeId = routeId;
         }
 
@@ -601,11 +642,14 @@ public class CamelInternalProcessor extends 
DelegateAsyncProcessor {
 
     }
 
-    public static class ChildUnitOfWorkProcessorTask extends 
UnitOfWorkProcessorTask {
+    /**
+     * Advice when an EIP uses the <tt>shareUnitOfWork</tt> functionality.
+     */
+    public static class ChildUnitOfWorkProcessorAdvice extends 
UnitOfWorkProcessorAdvice {
 
         private final UnitOfWork parent;
 
-        public ChildUnitOfWorkProcessorTask(String routeId, UnitOfWork parent) 
{
+        public ChildUnitOfWorkProcessorAdvice(String routeId, UnitOfWork 
parent) {
             super(routeId);
             this.parent = parent;
         }
@@ -618,7 +662,10 @@ public class CamelInternalProcessor extends 
DelegateAsyncProcessor {
 
     }
 
-    public static class SubUnitOfWorkProcessorTask implements 
CamelInternalProcessorTask<UnitOfWork> {
+    /**
+     * Advice when an EIP uses the <tt>shareUnitOfWork</tt> functionality.
+     */
+    public static class SubUnitOfWorkProcessorAdvice implements 
CamelInternalProcessorAdvice<UnitOfWork> {
 
         @Override
         public UnitOfWork before(Exchange exchange) throws Exception {

http://git-wip-us.apache.org/repos/asf/camel/blob/6adb1406/camel-core/src/main/java/org/apache/camel/processor/CamelInternalProcessorAdvice.java
----------------------------------------------------------------------
diff --git 
a/camel-core/src/main/java/org/apache/camel/processor/CamelInternalProcessorAdvice.java
 
b/camel-core/src/main/java/org/apache/camel/processor/CamelInternalProcessorAdvice.java
new file mode 100644
index 0000000..a6c589a
--- /dev/null
+++ 
b/camel-core/src/main/java/org/apache/camel/processor/CamelInternalProcessorAdvice.java
@@ -0,0 +1,49 @@
+/**
+ * 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.processor;
+
+import org.apache.camel.Exchange;
+
+/**
+ * An advice (before and after) to execute cross cutting functionality in the 
Camel routing engine.
+ * <p/>
+ * The Camel routing engine will execute the {@link 
#before(org.apache.camel.Exchange)} and
+ * {@link #after(org.apache.camel.Exchange, Object)} methods during routing in 
correct order.
+ *
+ * @param <T>
+ * @see CamelInternalProcessor
+ */
+public interface CamelInternalProcessorAdvice<T> {
+
+    /**
+     * Callback executed before processing a step in the route.
+     *
+     * @param exchange  the current exchange
+     * @return any state to keep and provide as data to the {@link 
#after(org.apache.camel.Exchange, Object)} method, or use <tt>null</tt> for no 
state.
+     * @throws Exception is thrown if error during the call.
+     */
+    T before(Exchange exchange) throws Exception;
+
+    /**
+     * Callback executed after processing a step in the route.
+     *
+     * @param exchange  the current exchange
+     * @param data      the state, if any, returned in the {@link 
#before(org.apache.camel.Exchange)} method.
+     * @throws Exception is thrown if error during the call.
+     */
+    void after(Exchange exchange, T data) throws Exception;
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/6adb1406/camel-core/src/main/java/org/apache/camel/processor/CamelInternalProcessorTask.java
----------------------------------------------------------------------
diff --git 
a/camel-core/src/main/java/org/apache/camel/processor/CamelInternalProcessorTask.java
 
b/camel-core/src/main/java/org/apache/camel/processor/CamelInternalProcessorTask.java
deleted file mode 100644
index 1df3db9..0000000
--- 
a/camel-core/src/main/java/org/apache/camel/processor/CamelInternalProcessorTask.java
+++ /dev/null
@@ -1,49 +0,0 @@
-/**
- * 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.processor;
-
-import org.apache.camel.Exchange;
-
-/**
- * A task to execute cross cutting functionality in the Camel routing engine.
- * <p/>
- * The Camel routing engine will execute the {@link 
#before(org.apache.camel.Exchange)} and
- * {@link #after(org.apache.camel.Exchange, Object)} methods during routing in 
correct order.
- *
- * @param <T>
- * @see CamelInternalProcessor
- */
-public interface CamelInternalProcessorTask<T> {
-
-    /**
-     * Callback executed before processing a step in the route.
-     *
-     * @param exchange  the current exchange
-     * @return any state to keep and provide as data to the {@link 
#after(org.apache.camel.Exchange, Object)} method, or use <tt>null</tt> for no 
state.
-     * @throws Exception is thrown if error during the call.
-     */
-    T before(Exchange exchange) throws Exception;
-
-    /**
-     * Callback executed after processing a step in the route.
-     *
-     * @param exchange  the current exchange
-     * @param data      the state, if any, returned in the {@link 
#before(org.apache.camel.Exchange)} method.
-     * @throws Exception is thrown if error during the call.
-     */
-    void after(Exchange exchange, T data) throws Exception;
-}

http://git-wip-us.apache.org/repos/asf/camel/blob/6adb1406/camel-core/src/main/java/org/apache/camel/processor/MulticastProcessor.java
----------------------------------------------------------------------
diff --git 
a/camel-core/src/main/java/org/apache/camel/processor/MulticastProcessor.java 
b/camel-core/src/main/java/org/apache/camel/processor/MulticastProcessor.java
index 6549402..ca23be1 100644
--- 
a/camel-core/src/main/java/org/apache/camel/processor/MulticastProcessor.java
+++ 
b/camel-core/src/main/java/org/apache/camel/processor/MulticastProcessor.java
@@ -908,9 +908,9 @@ public class MulticastProcessor extends ServiceSupport 
implements AsyncProcessor
 
         UnitOfWork parent = exchange.getProperty(Exchange.PARENT_UNIT_OF_WORK, 
UnitOfWork.class);
         if (parent != null) {
-            internal.addTask(new 
CamelInternalProcessor.ChildUnitOfWorkProcessorTask(routeId, parent));
+            internal.addAdvice(new 
CamelInternalProcessor.ChildUnitOfWorkProcessorAdvice(routeId, parent));
         } else {
-            internal.addTask(new 
CamelInternalProcessor.UnitOfWorkProcessorTask(routeId));
+            internal.addAdvice(new 
CamelInternalProcessor.UnitOfWorkProcessorAdvice(routeId));
         }
         return internal;
     }

http://git-wip-us.apache.org/repos/asf/camel/blob/6adb1406/camel-core/src/main/java/org/apache/camel/processor/RecipientList.java
----------------------------------------------------------------------
diff --git 
a/camel-core/src/main/java/org/apache/camel/processor/RecipientList.java 
b/camel-core/src/main/java/org/apache/camel/processor/RecipientList.java
index e4008d6..4b700a9 100644
--- a/camel-core/src/main/java/org/apache/camel/processor/RecipientList.java
+++ b/camel-core/src/main/java/org/apache/camel/processor/RecipientList.java
@@ -145,7 +145,7 @@ public class RecipientList extends ServiceSupport 
implements AsyncProcessor {
         if (isShareUnitOfWork()) {
             // wrap answer in a sub unit of work, since we share the unit of 
work
             CamelInternalProcessor internalProcessor = new 
CamelInternalProcessor(rlp);
-            internalProcessor.addTask(new 
CamelInternalProcessor.SubUnitOfWorkProcessorTask());
+            internalProcessor.addAdvice(new 
CamelInternalProcessor.SubUnitOfWorkProcessorAdvice());
             target = internalProcessor;
         }
 

http://git-wip-us.apache.org/repos/asf/camel/blob/6adb1406/camel-core/src/main/java/org/apache/camel/processor/UnitOfWorkProducer.java
----------------------------------------------------------------------
diff --git 
a/camel-core/src/main/java/org/apache/camel/processor/UnitOfWorkProducer.java 
b/camel-core/src/main/java/org/apache/camel/processor/UnitOfWorkProducer.java
index 03af6c3..5537bf7 100644
--- 
a/camel-core/src/main/java/org/apache/camel/processor/UnitOfWorkProducer.java
+++ 
b/camel-core/src/main/java/org/apache/camel/processor/UnitOfWorkProducer.java
@@ -48,7 +48,7 @@ public final class UnitOfWorkProducer implements Producer {
         this.producer = producer;
         // wrap in unit of work
         CamelInternalProcessor internal = new CamelInternalProcessor(producer);
-        internal.addTask(new 
CamelInternalProcessor.UnitOfWorkProcessorTask(null));
+        internal.addAdvice(new 
CamelInternalProcessor.UnitOfWorkProcessorAdvice(null));
         this.processor = internal;
     }
 

http://git-wip-us.apache.org/repos/asf/camel/blob/6adb1406/camel-core/src/main/java/org/apache/camel/processor/interceptor/DefaultChannel.java
----------------------------------------------------------------------
diff --git 
a/camel-core/src/main/java/org/apache/camel/processor/interceptor/DefaultChannel.java
 
b/camel-core/src/main/java/org/apache/camel/processor/interceptor/DefaultChannel.java
index fa6656b..725a3bd 100644
--- 
a/camel-core/src/main/java/org/apache/camel/processor/interceptor/DefaultChannel.java
+++ 
b/camel-core/src/main/java/org/apache/camel/processor/interceptor/DefaultChannel.java
@@ -210,13 +210,13 @@ public class DefaultChannel extends 
CamelInternalProcessor implements ModelChann
                 first = route.getOutputs().get(0) == definition;
             }
 
-            addTask(new 
CamelInternalProcessor.BacklogTracerTask(backlogTracer.getQueue(), 
backlogTracer, targetOutputDef, route, first));
+            addAdvice(new BacklogTracerAdvice(backlogTracer.getQueue(), 
backlogTracer, targetOutputDef, route, first));
 
             // add debugger as well so we have both tracing and debugging out 
of the box
             InterceptStrategy debugger = getOrCreateBacklogDebugger();
             if (debugger instanceof BacklogDebugger) {
                 BacklogDebugger backlogDebugger = (BacklogDebugger) debugger;
-                addTask(new 
CamelInternalProcessor.BacklogDebuggerTask(backlogDebugger, target, 
targetOutputDef));
+                addAdvice(new BacklogDebuggerAdvice(backlogDebugger, target, 
targetOutputDef));
             }
         }
 

Reply via email to