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 Wed, 22 May 2013 09:02:52 GMT
Updated Branches:
  refs/heads/master 84feec1ba -> 839ec5698


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/839ec569
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/839ec569
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/839ec569

Branch: refs/heads/master
Commit: 839ec569849b6521fb929570ebf8343b0b9c8f5a
Parents: 84feec1
Author: Claus Ibsen <davsclaus@apache.org>
Authored: Wed May 22 11:02:36 2013 +0200
Committer: Claus Ibsen <davsclaus@apache.org>
Committed: Wed May 22 11:02:44 2013 +0200

----------------------------------------------------------------------
 .../mbean/ManagedBacklogDebuggerMBean.java         |    9 +++
 .../management/mbean/ManagedBacklogDebugger.java   |   12 ++++
 .../camel/model/ProcessorDefinitionHelper.java     |   11 ++++
 .../processor/interceptor/BacklogDebugger.java     |   41 ++++++++++++++-
 4 files changed, 72 insertions(+), 1 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/839ec569/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 a454d09..3709011 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
@@ -44,4 +44,13 @@ public interface ManagedBacklogDebuggerMBean {
     @ManagedOperation(description = "Return the node ids which is currently suspended")
     Set<String> getSuspendedBreakpointNodeIds();
 
+    @ManagedOperation(description = "Dumps the messages in xml format from the suspended
breakpoint at the given node")
+    String dumpTracedMessagesAsXml(String nodeId);
+
+    @ManagedAttribute(description = "Number of total debugged messages")
+    public long getDebugCounter();
+
+    @ManagedOperation(description = "Resets the debug counter")
+    public void resetDebugCounter();
+
 }

http://git-wip-us.apache.org/repos/asf/camel/blob/839ec569/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 b07dcf4..f6fac11 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
@@ -75,4 +75,16 @@ public class ManagedBacklogDebugger implements ManagedBacklogDebuggerMBean
{
         return backlogDebugger.getSuspendedBreakpointNodeIds();
     }
 
+    public String dumpTracedMessagesAsXml(String nodeId) {
+        return backlogDebugger.dumpTracedMessagesAsXml(nodeId);
+    }
+
+    public long getDebugCounter() {
+        return backlogDebugger.getDebugCounter();
+    }
+
+    public void resetDebugCounter() {
+        backlogDebugger.resetDebugCounter();
+    }
+
 }

http://git-wip-us.apache.org/repos/asf/camel/blob/839ec569/camel-core/src/main/java/org/apache/camel/model/ProcessorDefinitionHelper.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/model/ProcessorDefinitionHelper.java
b/camel-core/src/main/java/org/apache/camel/model/ProcessorDefinitionHelper.java
index 2d153c2..6395ec6 100644
--- a/camel-core/src/main/java/org/apache/camel/model/ProcessorDefinitionHelper.java
+++ b/camel-core/src/main/java/org/apache/camel/model/ProcessorDefinitionHelper.java
@@ -138,6 +138,17 @@ public final class ProcessorDefinitionHelper {
     }
 
     /**
+     * Gets the route id the given node belongs to.
+     *
+     * @param node the node
+     * @return the route id, or <tt>null</tt> if not possible to find
+     */
+    public static String getRouteId(ProcessorDefinition<?> node) {
+        RouteDefinition route = getRoute(node);
+        return route != null ? route.getId() : null;
+    }
+
+    /**
      * Traverses the node, including its children (recursive), and gathers all the node ids.
      *
      * @param node  the target node

http://git-wip-us.apache.org/repos/asf/camel/blob/839ec569/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 0dd8013..557d992 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
@@ -16,6 +16,7 @@
  */
 package org.apache.camel.processor.interceptor;
 
+import java.util.Date;
 import java.util.EventObject;
 import java.util.HashMap;
 import java.util.LinkedHashSet;
@@ -24,17 +25,21 @@ import java.util.Map;
 import java.util.Set;
 import java.util.concurrent.CountDownLatch;
 import java.util.concurrent.atomic.AtomicBoolean;
+import java.util.concurrent.atomic.AtomicLong;
 
 import org.apache.camel.CamelContext;
 import org.apache.camel.Exchange;
 import org.apache.camel.Processor;
+import org.apache.camel.api.management.mbean.BacklogTracerEventMessage;
 import org.apache.camel.impl.BreakpointSupport;
 import org.apache.camel.impl.DefaultDebugger;
 import org.apache.camel.model.ProcessorDefinition;
+import org.apache.camel.model.ProcessorDefinitionHelper;
 import org.apache.camel.spi.Condition;
 import org.apache.camel.spi.Debugger;
 import org.apache.camel.spi.InterceptStrategy;
 import org.apache.camel.support.ServiceSupport;
+import org.apache.camel.util.MessageHelper;
 import org.apache.camel.util.ObjectHelper;
 import org.apache.camel.util.ServiceHelper;
 import org.slf4j.Logger;
@@ -49,9 +54,11 @@ public class BacklogDebugger extends ServiceSupport implements InterceptStrategy
     private static final Logger LOG = LoggerFactory.getLogger(BacklogDebugger.class);
 
     private final AtomicBoolean enabled = new AtomicBoolean();
+    private final AtomicLong debugCounter = new AtomicLong(0);
     private final Debugger debugger;
     private final Map<String, NodeBreakpoint> breakpoints = new HashMap<String,
NodeBreakpoint>();
     private final Map<String, CountDownLatch> suspendedBreakpoints = new HashMap<String,
CountDownLatch>();
+    private final Map<String, BacklogTracerEventMessage> suspendedBreakpointMessages
= new HashMap<String, BacklogTracerEventMessage>();
 
     public BacklogDebugger() {
         this.debugger = new DefaultDebugger();
@@ -106,6 +113,7 @@ public class BacklogDebugger extends ServiceSupport implements InterceptStrategy
             latch.countDown();
         }
         suspendedBreakpoints.clear();
+        suspendedBreakpointMessages.clear();
     }
 
     public boolean isEnabled() {
@@ -126,6 +134,7 @@ public class BacklogDebugger extends ServiceSupport implements InterceptStrategy
 
     public void removeBreakpoint(String nodeId) {
         // when removing a break point then ensure latches is cleared and counted down so
we wont have hanging threads
+        suspendedBreakpointMessages.remove(nodeId);
         CountDownLatch latch = suspendedBreakpoints.remove(nodeId);
         NodeBreakpoint breakpoint = breakpoints.remove(nodeId);
         if (breakpoint != null) {
@@ -137,6 +146,8 @@ public class BacklogDebugger extends ServiceSupport implements InterceptStrategy
     }
 
     public void continueBreakpoint(String nodeId) {
+        // remember to remove the dumped message as its no longer in need
+        suspendedBreakpointMessages.remove(nodeId);
         CountDownLatch latch = suspendedBreakpoints.remove(nodeId);
         if (latch != null) {
             latch.countDown();
@@ -147,6 +158,23 @@ public class BacklogDebugger extends ServiceSupport implements InterceptStrategy
         return new LinkedHashSet<String>(suspendedBreakpoints.keySet());
     }
 
+    public String dumpTracedMessagesAsXml(String nodeId) {
+        BacklogTracerEventMessage msg = suspendedBreakpointMessages.get(nodeId);
+        if (msg != null) {
+            return msg.toXml(4);
+        } else {
+            return null;
+        }
+    }
+
+    public long getDebugCounter() {
+        return debugCounter.get();
+    }
+
+    public void resetDebugCounter() {
+        debugCounter.set(0);
+    }
+
     public boolean beforeProcess(Exchange exchange, Processor processor, ProcessorDefinition<?>
definition) {
         return debugger.beforeProcess(exchange, processor, definition);
     }
@@ -171,12 +199,23 @@ public class BacklogDebugger extends ServiceSupport implements InterceptStrategy
 
         private final String nodeId;
 
-        public NodeBreakpoint(String nodeId) {
+        private NodeBreakpoint(String nodeId) {
             this.nodeId = nodeId;
         }
 
         @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 = nodeId;
+            String routeId = ProcessorDefinitionHelper.getRouteId(definition);
+            String exchangeId = exchange.getExchangeId();
+            String messageAsXml = MessageHelper.dumpAsXml(exchange.getIn(), true, 4, false,
false, 1000);
+            long uid = debugCounter.incrementAndGet();
+
+            BacklogTracerEventMessage msg = new DefaultBacklogTracerEventMessage(uid, timestamp,
routeId, toNode, exchangeId, messageAsXml);
+            suspendedBreakpointMessages.put(nodeId, msg);
+
             // mark as suspend
             final CountDownLatch latch = new CountDownLatch(1);
             suspendedBreakpoints.put(nodeId, latch);


Mime
View raw message