camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject git commit: CAMEL-6384: Added BacklogDebugger MBean for live debugging of Camel routes. Work in progress.
Date Thu, 23 May 2013 06:10:04 GMT
Updated Branches:
  refs/heads/master 1310e930b -> d6661e14e


CAMEL-6384: Added BacklogDebugger MBean for live debugging of Camel routes. Work in progress.


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

Branch: refs/heads/master
Commit: d6661e14e1112926b5f6f3dbe62d6a4cbabe5f3b
Parents: 1310e93
Author: Claus Ibsen <davsclaus@apache.org>
Authored: Thu May 23 08:09:47 2013 +0200
Committer: Claus Ibsen <davsclaus@apache.org>
Committed: Thu May 23 08:09:47 2013 +0200

----------------------------------------------------------------------
 .../mbean/ManagedBacklogDebuggerMBean.java         |    7 +-
 .../management/mbean/ManagedBacklogDebugger.java   |   13 ++-
 .../processor/interceptor/BacklogDebugger.java     |   60 +++++++++------
 3 files changed, 51 insertions(+), 29 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/d6661e14/camel-core/src/main/java/org/apache/camel/api/management/mbean/ManagedBacklogDebuggerMBean.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/api/management/mbean/ManagedBacklogDebuggerMBean.java
b/camel-core/src/main/java/org/apache/camel/api/management/mbean/ManagedBacklogDebuggerMBean.java
index 5e0370e..1b2f4da 100644
--- a/camel-core/src/main/java/org/apache/camel/api/management/mbean/ManagedBacklogDebuggerMBean.java
+++ b/camel-core/src/main/java/org/apache/camel/api/management/mbean/ManagedBacklogDebuggerMBean.java
@@ -39,7 +39,10 @@ public interface ManagedBacklogDebuggerMBean {
     void disableDebugger();
 
     @ManagedOperation(description = "Add a breakpoint at the given node id")
-    void addBreakpoint(String nodeId, boolean internal);
+    void addBreakpoint(String nodeId);
+
+    @ManagedOperation(description = "Add a conditional breakpoint at the given node id (condition
is Simple language)")
+    void addConditionalBreakpoint(String nodeId, String simplePredicate);
 
     @ManagedOperation(description = "Remote the breakpoint from the given node id")
     void removeBreakpoint(String nodeId);
@@ -60,7 +63,7 @@ public interface ManagedBacklogDebuggerMBean {
     void step();
 
     @ManagedOperation(description = "Return the node ids which has breakpoints")
-    Set<String> getBreakpoints(boolean includeInternal);
+    Set<String> getBreakpoints();
 
     @ManagedOperation(description = "Return the node ids which is currently suspended")
     Set<String> getSuspendedBreakpointNodeIds();

http://git-wip-us.apache.org/repos/asf/camel/blob/d6661e14/camel-core/src/main/java/org/apache/camel/management/mbean/ManagedBacklogDebugger.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/management/mbean/ManagedBacklogDebugger.java
b/camel-core/src/main/java/org/apache/camel/management/mbean/ManagedBacklogDebugger.java
index 3b6282d..9838448 100644
--- a/camel-core/src/main/java/org/apache/camel/management/mbean/ManagedBacklogDebugger.java
+++ b/camel-core/src/main/java/org/apache/camel/management/mbean/ManagedBacklogDebugger.java
@@ -19,6 +19,7 @@ package org.apache.camel.management.mbean;
 import java.util.Set;
 
 import org.apache.camel.CamelContext;
+import org.apache.camel.api.management.ManagedOperation;
 import org.apache.camel.api.management.ManagedResource;
 import org.apache.camel.api.management.mbean.ManagedBacklogDebuggerMBean;
 import org.apache.camel.processor.interceptor.BacklogDebugger;
@@ -67,16 +68,20 @@ public class ManagedBacklogDebugger implements ManagedBacklogDebuggerMBean
{
         backlogDebugger.disableDebugger();
     }
 
-    public void addBreakpoint(String nodeId, boolean internal) {
-        backlogDebugger.addBreakpoint(nodeId, internal);
+    public void addBreakpoint(String nodeId) {
+        backlogDebugger.addBreakpoint(nodeId);
+    }
+
+    public void addConditionalBreakpoint(String nodeId, String simplePredicate) {
+        backlogDebugger.addConditionalBreakpoint(nodeId, simplePredicate);
     }
 
     public void removeBreakpoint(String nodeId) {
         backlogDebugger.removeBreakpoint(nodeId);
     }
 
-    public Set<String> getBreakpoints(boolean includeInternal) {
-        return backlogDebugger.getBreakpoints(includeInternal);
+    public Set<String> getBreakpoints() {
+        return backlogDebugger.getBreakpoints();
     }
 
     public void resumeBreakpoint(String nodeId) {

http://git-wip-us.apache.org/repos/asf/camel/blob/d6661e14/camel-core/src/main/java/org/apache/camel/processor/interceptor/BacklogDebugger.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/processor/interceptor/BacklogDebugger.java
b/camel-core/src/main/java/org/apache/camel/processor/interceptor/BacklogDebugger.java
index 7966a63..b62f334 100644
--- a/camel-core/src/main/java/org/apache/camel/processor/interceptor/BacklogDebugger.java
+++ b/camel-core/src/main/java/org/apache/camel/processor/interceptor/BacklogDebugger.java
@@ -29,7 +29,9 @@ import java.util.concurrent.atomic.AtomicLong;
 
 import org.apache.camel.CamelContext;
 import org.apache.camel.Exchange;
+import org.apache.camel.Expression;
 import org.apache.camel.LoggingLevel;
+import org.apache.camel.Predicate;
 import org.apache.camel.Processor;
 import org.apache.camel.api.management.mbean.BacklogTracerEventMessage;
 import org.apache.camel.impl.BreakpointSupport;
@@ -148,16 +150,30 @@ public class BacklogDebugger extends ServiceSupport implements InterceptStrategy
         return singleStepExchangeId != null;
     }
 
-    public void addBreakpoint(String nodeId, boolean internal) {
-        if (internal) {
-            logger.log("Adding internal breakpoint " + nodeId);
-        } else {
+    public void addBreakpoint(String nodeId) {
+        NodeBreakpoint breakpoint = breakpoints.get(nodeId);
+        if (breakpoint == null) {
             logger.log("Adding breakpoint " + nodeId);
+            breakpoint = new NodeBreakpoint(nodeId, null);
+            breakpoints.put(nodeId, breakpoint);
+            debugger.addBreakpoint(breakpoint);
+        } else {
+            breakpoint.setCondition(null);
         }
-        if (!breakpoints.containsKey(nodeId)) {
-            NodeBreakpoint breakpoint = new NodeBreakpoint(nodeId, internal);
+    }
+
+    public void addConditionalBreakpoint(String nodeId, String simplePredicate) {
+        Predicate condition = camelContext.resolveLanguage("simple").createPredicate(simplePredicate);
+        NodeBreakpoint breakpoint = breakpoints.get(nodeId);
+        if (breakpoint == null) {
+            logger.log("Adding conditional breakpoint " + nodeId + " [" + simplePredicate
+ "]");
+            breakpoint = new NodeBreakpoint(nodeId, condition);
             breakpoints.put(nodeId, breakpoint);
             debugger.addBreakpoint(breakpoint);
+        } else {
+            logger.log("Updating conditional breakpoint " + nodeId + " [" + simplePredicate
+ "]");
+            // update condition
+            breakpoint.setCondition(condition);
         }
     }
 
@@ -175,14 +191,8 @@ public class BacklogDebugger extends ServiceSupport implements InterceptStrategy
         }
     }
 
-    public Set<String> getBreakpoints(boolean includeInternal) {
-        Set<String> answer = new LinkedHashSet<String>();
-        for (NodeBreakpoint breakpoint : breakpoints.values()) {
-            if (!breakpoint.isInternal() || includeInternal) {
-                answer.add(breakpoint.getNodeId());
-            }
-        }
-        return answer;
+    public Set<String> getBreakpoints() {
+        return new LinkedHashSet<String>(breakpoints.keySet());
     }
 
     public void resumeBreakpoint(String nodeId) {
@@ -308,26 +318,26 @@ public class BacklogDebugger extends ServiceSupport implements InterceptStrategy
     private final class NodeBreakpoint extends BreakpointSupport implements Condition {
 
         private final String nodeId;
-        private final boolean internal;
+        private Predicate condition;
 
-        private NodeBreakpoint(String nodeId, boolean internal) {
+        private NodeBreakpoint(String nodeId, Predicate condition) {
             this.nodeId = nodeId;
-            this.internal = internal;
+            this.condition = condition;
         }
 
         public String getNodeId() {
             return nodeId;
         }
 
-        public boolean isInternal() {
-            return internal;
+        public void setCondition(Predicate predicate) {
+            this.condition = predicate;
         }
 
         @Override
         public void beforeProcess(Exchange exchange, Processor processor, ProcessorDefinition<?>
definition) {
             // store a copy of the message so we can see that from the debugger
             Date timestamp = new Date();
-            String toNode = definition.getId();
+            String toNode = nodeId;
             String routeId = ProcessorDefinitionHelper.getRouteId(definition);
             String exchangeId = exchange.getExchangeId();
             String messageAsXml = MessageHelper.dumpAsXml(exchange.getIn(), true, 4, false,
false, 1000);
@@ -341,11 +351,11 @@ public class BacklogDebugger extends ServiceSupport implements InterceptStrategy
             suspendedBreakpoints.put(nodeId, latch);
 
             // now wait until we should continue
-            logger.log("NodeBreakpoint at node " + toNode + " is waiting to continue for
exchangeId: " + exchange.getExchangeId());
+            logger.log("NodeBreakpoint at node " + nodeId + " is waiting to continue for
exchangeId: " + exchange.getExchangeId());
             try {
                 // TODO: have a fallback timeout so we wont wait forever
                 latch.await();
-                logger.log("NodeBreakpoint at node " + toNode + " is continued exchangeId:
" + exchange.getExchangeId());
+                logger.log("NodeBreakpoint at node " + nodeId + " is continued exchangeId:
" + exchange.getExchangeId());
             } catch (InterruptedException e) {
                 // ignore
             }
@@ -354,7 +364,11 @@ public class BacklogDebugger extends ServiceSupport implements InterceptStrategy
 
         @Override
         public boolean matchProcess(Exchange exchange, Processor processor, ProcessorDefinition<?>
definition) {
-            return nodeId.equals(definition.getId());
+            boolean match = nodeId.equals(definition.getId());
+            if (match && condition != null) {
+                return condition.matches(exchange);
+            }
+            return match;
         }
 
         @Override


Mime
View raw message