camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject svn commit: r1456490 - in /camel/trunk/camel-core/src: main/java/org/apache/camel/api/management/mbean/ main/java/org/apache/camel/management/mbean/ main/java/org/apache/camel/processor/interceptor/ test/java/org/apache/camel/management/
Date Thu, 14 Mar 2013 15:46:20 GMT
Author: davsclaus
Date: Thu Mar 14 15:46:20 2013
New Revision: 1456490

URL: http://svn.apache.org/r1456490
Log:
CAMEL-6148: BacklogTracer allow to configure a trace pattern to filter what to trace at runtime

Added:
    camel/trunk/camel-core/src/test/java/org/apache/camel/management/BacklogTracerPatternRouteTest.java
    camel/trunk/camel-core/src/test/java/org/apache/camel/management/BacklogTracerPatternTest.java
      - copied, changed from r1456471, camel/trunk/camel-core/src/test/java/org/apache/camel/management/BacklogTracerTest.java
Modified:
    camel/trunk/camel-core/src/main/java/org/apache/camel/api/management/mbean/ManagedTracerBacklogMBean.java
    camel/trunk/camel-core/src/main/java/org/apache/camel/management/mbean/ManagedBacklogTracer.java
    camel/trunk/camel-core/src/main/java/org/apache/camel/processor/interceptor/BacklogTracer.java

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/api/management/mbean/ManagedTracerBacklogMBean.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/api/management/mbean/ManagedTracerBacklogMBean.java?rev=1456490&r1=1456489&r2=1456490&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/api/management/mbean/ManagedTracerBacklogMBean.java
(original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/api/management/mbean/ManagedTracerBacklogMBean.java
Thu Mar 14 15:46:20 2013
@@ -35,6 +35,12 @@ public interface ManagedTracerBacklogMBe
     @ManagedAttribute(description = "Number of traced messages to keep in the backlog (FIFO
queue)")
     void setBacklogSize(int backlogSize);
 
+    @ManagedAttribute(description = "To filter tracing by nodes (pattern)")
+    void setTracePattern(String pattern);
+
+    @ManagedAttribute(description = "To filter tracing by nodes (pattern)")
+    String getTracePattern();
+
     @ManagedAttribute(description = "Number of total traced messages")
     long getTraceCounter();
 

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/management/mbean/ManagedBacklogTracer.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/management/mbean/ManagedBacklogTracer.java?rev=1456490&r1=1456489&r2=1456490&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/management/mbean/ManagedBacklogTracer.java
(original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/management/mbean/ManagedBacklogTracer.java
Thu Mar 14 15:46:20 2013
@@ -70,6 +70,14 @@ public class ManagedBacklogTracer implem
         backlogTracer.setBacklogSize(backlogSize);
     }
 
+    public void setTracePattern(String pattern) {
+        backlogTracer.setTracePattern(pattern);
+    }
+
+    public String getTracePattern() {
+        return backlogTracer.getTracePattern();
+    }
+
     public long getTraceCounter() {
         return backlogTracer.getTraceCounter();
     }

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/processor/interceptor/BacklogTracer.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/processor/interceptor/BacklogTracer.java?rev=1456490&r1=1456489&r2=1456490&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/processor/interceptor/BacklogTracer.java
(original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/processor/interceptor/BacklogTracer.java
Thu Mar 14 15:46:20 2013
@@ -34,6 +34,7 @@ import org.apache.camel.model.RouteDefin
 import org.apache.camel.spi.InterceptStrategy;
 import org.apache.camel.spi.NodeIdFactory;
 import org.apache.camel.support.ServiceSupport;
+import org.apache.camel.util.EndpointHelper;
 
 /**
  * A tracer used for message tracing, storing a copy of the message details in a backlog.
@@ -50,6 +51,9 @@ public class BacklogTracer extends Servi
     private final Queue<DefaultBacklogTracerEventMessage> queue = new ArrayBlockingQueue<DefaultBacklogTracerEventMessage>(1000);
     // how many of the last messages per node to keep in the backlog
     private int backlogSize = 10;
+    // a pattern to filter tracing nodes
+    private String tracePattern;
+    private String[] patterns;
     // remember the processors we are tracing, which we need later
     private final Set<ProcessorDefinition<?>> processors = new HashSet<ProcessorDefinition<?>>();
 
@@ -103,7 +107,31 @@ public class BacklogTracer extends Servi
      * @return <tt>true</tt> to trace, <tt>false</tt> to skip tracing
      */
     public boolean shouldTrace(ProcessorDefinition<?> definition) {
-        return enabled;
+        if (!enabled) {
+            return false;
+        }
+
+        if (patterns != null) {
+            for (String pattern : patterns) {
+                // match either route id, or node id
+                String id = definition.getId();
+                // use matchPattern method from endpoint helper that has a good matcher we
use in Camel
+                if (EndpointHelper.matchPattern(id, pattern)) {
+                    return true;
+                }
+                RouteDefinition route = ProcessorDefinitionHelper.getRoute(definition);
+                if (route != null) {
+                    id = route.getId();
+                    if (EndpointHelper.matchPattern(id, pattern)) {
+                        return true;
+                    }
+                }
+            }
+            // not matched the pattern
+            return false;
+        }
+
+        return true;
     }
 
     public boolean isEnabled() {
@@ -129,6 +157,20 @@ public class BacklogTracer extends Servi
         this.backlogSize = backlogSize;
     }
 
+    public String getTracePattern() {
+        return tracePattern;
+    }
+
+    public void setTracePattern(String tracePattern) {
+        this.tracePattern = tracePattern;
+        if (tracePattern != null) {
+            // the pattern can have multiple nodes separated by comma
+            this.patterns = tracePattern.split(",");
+        } else {
+            this.patterns = null;
+        }
+    }
+
     public long getTraceCounter() {
         return traceCounter.get();
     }

Added: camel/trunk/camel-core/src/test/java/org/apache/camel/management/BacklogTracerPatternRouteTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/management/BacklogTracerPatternRouteTest.java?rev=1456490&view=auto
==============================================================================
--- camel/trunk/camel-core/src/test/java/org/apache/camel/management/BacklogTracerPatternRouteTest.java
(added)
+++ camel/trunk/camel-core/src/test/java/org/apache/camel/management/BacklogTracerPatternRouteTest.java
Thu Mar 14 15:46:20 2013
@@ -0,0 +1,94 @@
+/**
+ * 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.management;
+
+import java.util.List;
+import javax.management.Attribute;
+import javax.management.MBeanServer;
+import javax.management.ObjectName;
+
+import org.apache.camel.api.management.mbean.BacklogTracerEventMessage;
+import org.apache.camel.builder.RouteBuilder;
+
+public class BacklogTracerPatternRouteTest extends ManagementTestSupport {
+
+    @SuppressWarnings("unchecked")
+    public void testBacklogTracerPattern() throws Exception {
+        MBeanServer mbeanServer = getMBeanServer();
+        ObjectName on = new ObjectName("org.apache.camel:context=localhost/camel-1,type=tracer,name=BacklogTracer");
+        assertNotNull(on);
+        mbeanServer.isRegistered(on);
+
+        Boolean enabled = (Boolean) mbeanServer.getAttribute(on, "Enabled");
+        assertEquals("Should not be enabled", Boolean.FALSE, enabled);
+
+        Integer size = (Integer) mbeanServer.getAttribute(on, "BacklogSize");
+        assertEquals("Should be 10", 10, size.intValue());
+
+        // set the pattern to match only coolRoute
+        mbeanServer.setAttribute(on, new Attribute("TracePattern", "coolRoute"));
+
+        // enable it
+        mbeanServer.setAttribute(on, new Attribute("Enabled", Boolean.TRUE));
+
+        getMockEndpoint("mock:foo").expectedMessageCount(2);
+        getMockEndpoint("mock:bar").expectedMessageCount(2);
+
+        template.sendBody("direct:start", "Hello World");
+        template.sendBody("direct:start", "Bye World");
+
+        assertMockEndpointsSatisfied();
+
+        List<BacklogTracerEventMessage> events = (List<BacklogTracerEventMessage>)
mbeanServer.invoke(on, "dumpTracedMessages",
+                new Object[]{"foo"}, new String[]{"java.lang.String"});
+
+        assertNotNull(events);
+        assertEquals(2, events.size());
+
+        // there should also be messages on bar
+        events = (List<BacklogTracerEventMessage>) mbeanServer.invoke(on, "dumpTracedMessages",
+                new Object[]{"bar"}, new String[]{"java.lang.String"});
+        assertNotNull(events);
+        assertEquals(2, events.size());
+
+        // but not on beer
+        events = (List<BacklogTracerEventMessage>) mbeanServer.invoke(on, "dumpTracedMessages",
+                new Object[]{"beer"}, new String[]{"java.lang.String"});
+        assertNotNull(events);
+        assertEquals(0, events.size());
+    }
+
+    @Override
+    protected RouteBuilder createRouteBuilder() throws Exception {
+        return new RouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+                context.setUseBreadcrumb(false);
+
+                from("direct:start").routeId("coolRoute")
+                        .to("direct:beer")
+                        .to("mock:foo").id("foo")
+                        .to("mock:bar").id("bar");
+
+                from("direct:beer").routeId("beerRoute")
+                        .to("mock:beer").id("beer");
+
+            }
+        };
+    }
+
+}

Copied: camel/trunk/camel-core/src/test/java/org/apache/camel/management/BacklogTracerPatternTest.java
(from r1456471, camel/trunk/camel-core/src/test/java/org/apache/camel/management/BacklogTracerTest.java)
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/management/BacklogTracerPatternTest.java?p2=camel/trunk/camel-core/src/test/java/org/apache/camel/management/BacklogTracerPatternTest.java&p1=camel/trunk/camel-core/src/test/java/org/apache/camel/management/BacklogTracerTest.java&r1=1456471&r2=1456490&rev=1456490&view=diff
==============================================================================
--- camel/trunk/camel-core/src/test/java/org/apache/camel/management/BacklogTracerTest.java
(original)
+++ camel/trunk/camel-core/src/test/java/org/apache/camel/management/BacklogTracerPatternTest.java
Thu Mar 14 15:46:20 2013
@@ -21,17 +21,14 @@ import javax.management.Attribute;
 import javax.management.MBeanServer;
 import javax.management.ObjectName;
 
-import org.w3c.dom.Document;
-import org.w3c.dom.NodeList;
-
 import org.apache.camel.Exchange;
 import org.apache.camel.api.management.mbean.BacklogTracerEventMessage;
 import org.apache.camel.builder.RouteBuilder;
 
-public class BacklogTracerTest extends ManagementTestSupport {
+public class BacklogTracerPatternTest extends ManagementTestSupport {
 
     @SuppressWarnings("unchecked")
-    public void testBacklogTracerEventMessage() throws Exception {
+    public void testBacklogTracerPattern() throws Exception {
         MBeanServer mbeanServer = getMBeanServer();
         ObjectName on = new ObjectName("org.apache.camel:context=localhost/camel-1,type=tracer,name=BacklogTracer");
         assertNotNull(on);
@@ -43,6 +40,9 @@ public class BacklogTracerTest extends M
         Integer size = (Integer) mbeanServer.getAttribute(on, "BacklogSize");
         assertEquals("Should be 10", 10, size.intValue());
 
+        // set the pattern to match only foo*
+        mbeanServer.setAttribute(on, new Attribute("TracePattern", "foo*"));
+
         // enable it
         mbeanServer.setAttribute(on, new Attribute("Enabled", Boolean.TRUE));
 
@@ -73,150 +73,13 @@ public class BacklogTracerTest extends M
         assertEquals("    <message exchangeId=\"" + exchanges.get(1).getExchangeId() +
"\">\n"
                 + "      <body type=\"java.lang.String\">Bye World</body>\n"
                 + "    </message>", event2.getMessageAsXml());
-    }
-
-    @SuppressWarnings("unchecked")
-    public void testBacklogTracerEventMessageAsXml() throws Exception {
-        MBeanServer mbeanServer = getMBeanServer();
-        ObjectName on = new ObjectName("org.apache.camel:context=localhost/camel-1,type=tracer,name=BacklogTracer");
-        assertNotNull(on);
-        mbeanServer.isRegistered(on);
-
-        Boolean enabled = (Boolean) mbeanServer.getAttribute(on, "Enabled");
-        assertEquals("Should not be enabled", Boolean.FALSE, enabled);
-
-        Integer size = (Integer) mbeanServer.getAttribute(on, "BacklogSize");
-        assertEquals("Should be 10", 10, size.intValue());
-
-        // enable it
-        mbeanServer.setAttribute(on, new Attribute("Enabled", Boolean.TRUE));
-
-        getMockEndpoint("mock:foo").expectedMessageCount(2);
-        getMockEndpoint("mock:bar").expectedMessageCount(2);
-
-        template.sendBody("direct:start", "Hello World");
-        template.sendBody("direct:start", "Bye World");
 
-        assertMockEndpointsSatisfied();
-
-        String events = (String) mbeanServer.invoke(on, "dumpTracedMessagesAsXml",
-                new Object[]{"foo"}, new String[]{"java.lang.String"});
+        // there should be no messages on bar
 
+        events = (List<BacklogTracerEventMessage>) mbeanServer.invoke(on, "dumpTracedMessages",
+                new Object[]{"bar"}, new String[]{"java.lang.String"});
         assertNotNull(events);
-        log.info(events);
-
-        // should be valid XML
-        Document dom = context.getTypeConverter().convertTo(Document.class, events);
-        assertNotNull(dom);
-
-        NodeList list = dom.getElementsByTagName("backlogTracerEventMessage");
-        assertEquals(2, list.getLength());
-    }
-
-    @SuppressWarnings("unchecked")
-    public void testBacklogTracerEventMessageDumpAll() throws Exception {
-        MBeanServer mbeanServer = getMBeanServer();
-        ObjectName on = new ObjectName("org.apache.camel:context=localhost/camel-1,type=tracer,name=BacklogTracer");
-        assertNotNull(on);
-        mbeanServer.isRegistered(on);
-
-        Boolean enabled = (Boolean) mbeanServer.getAttribute(on, "Enabled");
-        assertEquals("Should not be enabled", Boolean.FALSE, enabled);
-
-        // enable it
-        mbeanServer.setAttribute(on, new Attribute("Enabled", Boolean.TRUE));
-
-        getMockEndpoint("mock:foo").expectedMessageCount(2);
-        getMockEndpoint("mock:bar").expectedMessageCount(2);
-
-        template.sendBody("direct:start", "Hello World");
-        template.sendBody("direct:start", "Bye World");
-
-        assertMockEndpointsSatisfied();
-
-        List<Exchange> fooExchanges = getMockEndpoint("mock:foo").getReceivedExchanges();
-        List<Exchange> barExchanges = getMockEndpoint("mock:bar").getReceivedExchanges();
-
-        List<BacklogTracerEventMessage> events = (List<BacklogTracerEventMessage>)
mbeanServer.invoke(on, "dumpAllTracedMessages", null, null);
-
-        assertNotNull(events);
-        assertEquals(6, events.size());
-
-        BacklogTracerEventMessage event0 = events.get(0);
-        assertEquals("route1", event0.getRouteId());
-        assertEquals(null, event0.getToNode());
-        assertEquals("    <message exchangeId=\"" + fooExchanges.get(0).getExchangeId()
+ "\">\n"
-                + "      <body type=\"java.lang.String\">Hello World</body>\n"
-                + "    </message>", event0.getMessageAsXml());
-
-        BacklogTracerEventMessage event1 = events.get(1);
-        assertEquals("route1", event1.getRouteId());
-        assertEquals("foo", event1.getToNode());
-        assertEquals("    <message exchangeId=\"" + fooExchanges.get(0).getExchangeId()
+ "\">\n"
-                + "      <body type=\"java.lang.String\">Hello World</body>\n"
-                + "    </message>", event1.getMessageAsXml());
-
-        BacklogTracerEventMessage event2 = events.get(2);
-        assertEquals("route1", event2.getRouteId());
-        assertEquals("bar", event2.getToNode());
-        assertEquals("    <message exchangeId=\"" + barExchanges.get(0).getExchangeId()
+ "\">\n"
-                + "      <body type=\"java.lang.String\">Hello World</body>\n"
-                + "    </message>", event2.getMessageAsXml());
-
-        BacklogTracerEventMessage event3 = events.get(3);
-        assertEquals("route1", event3.getRouteId());
-        assertEquals(null, event3.getToNode());
-        assertEquals("    <message exchangeId=\"" + fooExchanges.get(1).getExchangeId()
+ "\">\n"
-                + "      <body type=\"java.lang.String\">Bye World</body>\n"
-                + "    </message>", event3.getMessageAsXml());
-
-        BacklogTracerEventMessage event4 = events.get(4);
-        assertEquals("route1", event4.getRouteId());
-        assertEquals("foo", event4.getToNode());
-        assertEquals("    <message exchangeId=\"" + fooExchanges.get(1).getExchangeId()
+ "\">\n"
-                + "      <body type=\"java.lang.String\">Bye World</body>\n"
-                + "    </message>", event3.getMessageAsXml());
-
-        BacklogTracerEventMessage event5 = events.get(5);
-        assertEquals("route1", event5.getRouteId());
-        assertEquals("bar", event5.getToNode());
-        assertEquals("    <message exchangeId=\"" + barExchanges.get(1).getExchangeId()
+ "\">\n"
-                + "      <body type=\"java.lang.String\">Bye World</body>\n"
-                + "    </message>", event4.getMessageAsXml());
-    }
-
-    @SuppressWarnings("unchecked")
-    public void testBacklogTracerEventMessageDumpAllAsXml() throws Exception {
-        MBeanServer mbeanServer = getMBeanServer();
-        ObjectName on = new ObjectName("org.apache.camel:context=localhost/camel-1,type=tracer,name=BacklogTracer");
-        assertNotNull(on);
-        mbeanServer.isRegistered(on);
-
-        Boolean enabled = (Boolean) mbeanServer.getAttribute(on, "Enabled");
-        assertEquals("Should not be enabled", Boolean.FALSE, enabled);
-
-        // enable it
-        mbeanServer.setAttribute(on, new Attribute("Enabled", Boolean.TRUE));
-
-        getMockEndpoint("mock:foo").expectedMessageCount(2);
-        getMockEndpoint("mock:bar").expectedMessageCount(2);
-
-        template.sendBody("direct:start", "Hello World");
-        template.sendBody("direct:start", "Bye World");
-
-        assertMockEndpointsSatisfied();
-
-        String events = (String) mbeanServer.invoke(on, "dumpAllTracedMessagesAsXml", null,
null);
-
-        assertNotNull(events);
-        log.info(events);
-
-        // should be valid XML
-        Document dom = context.getTypeConverter().convertTo(Document.class, events);
-        assertNotNull(dom);
-
-        NodeList list = dom.getElementsByTagName("backlogTracerEventMessage");
-        assertEquals(6, list.getLength());
+        assertEquals(0, events.size());
     }
 
     @Override



Mime
View raw message