camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject svn commit: r884845 - in /camel/trunk/camel-core/src: main/java/org/apache/camel/management/mbean/ main/java/org/apache/camel/model/ main/java/org/apache/camel/processor/interceptor/ test/java/org/apache/camel/management/ test/java/org/apache/camel/pro...
Date Fri, 27 Nov 2009 12:05:45 GMT
Author: davsclaus
Date: Fri Nov 27 12:05:44 2009
New Revision: 884845

URL: http://svn.apache.org/viewvc?rev=884845&view=rev
Log:
CAMEL-2233: Tracer now show route id by default.

Modified:
    camel/trunk/camel-core/src/main/java/org/apache/camel/management/mbean/ManagedTracer.java
    camel/trunk/camel-core/src/main/java/org/apache/camel/model/ProcessorDefinition.java
    camel/trunk/camel-core/src/main/java/org/apache/camel/model/ProcessorDefinitionHelper.java
    camel/trunk/camel-core/src/main/java/org/apache/camel/processor/interceptor/DefaultTraceFormatter.java
    camel/trunk/camel-core/src/main/java/org/apache/camel/processor/interceptor/TraceFormatter.java
    camel/trunk/camel-core/src/test/java/org/apache/camel/management/ManagedTracerOptionsTest.java
    camel/trunk/camel-core/src/test/java/org/apache/camel/processor/TraceInterceptorTest.java
    camel/trunk/camel-core/src/test/java/org/apache/camel/processor/interceptor/DefaultTraceFormatterTest.java

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/management/mbean/ManagedTracer.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/management/mbean/ManagedTracer.java?rev=884845&r1=884844&r2=884845&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/management/mbean/ManagedTracer.java
(original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/management/mbean/ManagedTracer.java
Fri Nov 27 12:05:44 2009
@@ -331,6 +331,22 @@
         tracer.getDefaultTraceFormatter().setShowException(showException);
     }
 
+    @ManagedAttribute(description = "Formatter show route id")
+    public boolean getFormatterShowRouteId() {
+        if (tracer.getDefaultTraceFormatter() == null) {
+            return false;
+        }
+        return tracer.getDefaultTraceFormatter().isShowRouteId();
+    }
+
+    @ManagedAttribute(description = "Formatter show route id")
+    public void setFormatterShowRouteId(boolean showRouteId) {
+        if (tracer.getDefaultTraceFormatter() == null) {
+            return;
+        }
+        tracer.getDefaultTraceFormatter().setShowRouteId(showRouteId);
+    }
+
     @ManagedAttribute(description = "Formatter breadcrumb length")
     public int getFormatterBreadCrumbLength() {
         if (tracer.getDefaultTraceFormatter() == null) {
@@ -394,5 +410,5 @@
         }
         tracer.getDefaultTraceFormatter().setMaxChars(maxChars);
     }
-    
+
 }

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=884845&r1=884844&r2=884845&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 Fri
Nov 27 12:05:44 2009
@@ -722,14 +722,12 @@
     @SuppressWarnings("unchecked")
     public Type routeId(String id) {
         ProcessorDefinition def = this;
-        // drill to the top
-        while (def.getParent() != null) {
-            def = def.getParent();
-        }
-        if (def instanceof RouteDefinition) {
-            RouteDefinition route = (RouteDefinition) def;
+
+        RouteDefinition route = ProcessorDefinitionHelper.getRoute(def);
+        if (route != null) {
             route.setId(id);
         }
+
         return (Type) this;
     }
 

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/model/ProcessorDefinitionHelper.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/model/ProcessorDefinitionHelper.java?rev=884845&r1=884844&r2=884845&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/model/ProcessorDefinitionHelper.java
(original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/model/ProcessorDefinitionHelper.java
Fri Nov 27 12:05:44 2009
@@ -81,6 +81,32 @@
         return node.getParent().getOutputs().get(0).equals(node);
     }
 
+    /**
+     * Gets the route definition the given node belongs to.
+     *
+     * @param node the node
+     * @return the route, or <tt>null</tt> if not possible to find
+     */
+    public static RouteDefinition getRoute(ProcessorDefinition<?> node) {
+        if (node == null) {
+            return null;
+        }
+
+        ProcessorDefinition def = node;
+        // drill to the top
+        while (def != null && def.getParent() != null) {
+            def = def.getParent();
+        }
+
+        if (def instanceof RouteDefinition) {
+            return (RouteDefinition) def;
+        } else {
+            // not found
+            return null;
+        }
+
+    }
+
     @SuppressWarnings("unchecked")
     private static <T> void doFindType(List<ProcessorDefinition> outputs, Class<T>
type, List<T> found) {
         if (outputs == null || outputs.isEmpty()) {

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/processor/interceptor/DefaultTraceFormatter.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/processor/interceptor/DefaultTraceFormatter.java?rev=884845&r1=884844&r2=884845&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/processor/interceptor/DefaultTraceFormatter.java
(original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/processor/interceptor/DefaultTraceFormatter.java
Fri Nov 27 12:05:44 2009
@@ -20,6 +20,8 @@
 import org.apache.camel.Message;
 import org.apache.camel.RouteNode;
 import org.apache.camel.model.ProcessorDefinition;
+import org.apache.camel.model.ProcessorDefinitionHelper;
+import org.apache.camel.model.RouteDefinition;
 import org.apache.camel.spi.TracedRouteNodes;
 import org.apache.camel.util.MessageHelper;
 
@@ -42,6 +44,7 @@
     private boolean showOutBody;
     private boolean showOutBodyType;
     private boolean showException = true;
+    private boolean showRouteId = true;
     private int maxChars;
 
     public Object format(final TraceInterceptor interceptor, final ProcessorDefinition<?>
node, final Exchange exchange) {
@@ -84,14 +87,17 @@
             sb.append(", Exception:").append(exchange.getException());
         }
 
+        // replace ugly <<<, with <<<
+        String s = sb.toString();
+        s = s.replaceFirst("<<<,", "<<<");
+
         if (maxChars > 0) {
-            String s = sb.toString();
             if (s.length() > maxChars) {
                 s = s.substring(0, maxChars) + "...";
             }
             return s;
         } else {
-            return sb.toString();
+            return s;
         }
     }
 
@@ -191,6 +197,14 @@
         this.showException = showException;
     }
 
+    public boolean isShowRouteId() {
+        return showRouteId;
+    }
+
+    public void setShowRouteId(boolean showRouteId) {
+        this.showRouteId = showRouteId;
+    }
+
     public int getBreadCrumbLength() {
         return breadCrumbLength;
     }
@@ -225,6 +239,17 @@
 
     // Implementation methods
     //-------------------------------------------------------------------------
+
+    protected String extractRoute(ProcessorDefinition<?> node) {
+        RouteDefinition route = ProcessorDefinitionHelper.getRoute(node);
+        if (route != null) {
+            return route.getId();
+        } else {
+            return null;
+        }
+    }
+
+
     protected Object getBreadCrumbID(Exchange exchange) {
         return exchange.getExchangeId();
     }
@@ -264,10 +289,11 @@
             }
         }
 
-        // compute from and to
+        // compute from, to and route
         String from = "";
         String to = "";
-        if (showNode) {
+        String route = "";
+        if (showNode || showRouteId) {
             TracedRouteNodes traced = exchange.getUnitOfWork().getTracedRouteNodes();
 
             RouteNode traceFrom = traced.getSecondLastNode();
@@ -280,12 +306,23 @@
             RouteNode traceTo = traced.getLastNode();
             if (traceTo != null) {
                 to = getNodeMessage(traceTo, exchange);
+                // if its an abstract dummy holder then get the 2nd last so we can get the
real node that has
+                // information which route it belongs to
+                if (traceTo.isAbstract()) {
+                    traceTo = traced.getSecondLastNode();
+                }
+                route = extractRoute(traceTo.getProcessorDefinition());
             }
         }
 
         // assemble result with and without the to/from
         if (showNode) {
-            result = id.trim() + " >>> " + from + " --> " + to.trim();
+            if (showRouteId && route != null) {
+                result = id.trim() + " >>> (" + route + ") " + from + " --> "
+ to.trim() + " <<< ";
+            } else {
+                result = id.trim() + " >>> " + from + " --> " + to.trim() + "
<<< ";
+            }
+
             if (interceptor.shouldTraceOutExchanges() && exchange.hasOut()) {
                 result += " (OUT) ";
             }

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/processor/interceptor/TraceFormatter.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/processor/interceptor/TraceFormatter.java?rev=884845&r1=884844&r2=884845&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/processor/interceptor/TraceFormatter.java
(original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/processor/interceptor/TraceFormatter.java
Fri Nov 27 12:05:44 2009
@@ -28,7 +28,7 @@
      * Formats a log message at given point of interception.
      * 
      * @param interceptor    the tracing interceptor
-     * @param node           the node where the interception occured
+     * @param node           the node where the interception occurred
      * @param exchange       the current exchange
      * @return the log message
      */

Modified: camel/trunk/camel-core/src/test/java/org/apache/camel/management/ManagedTracerOptionsTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/management/ManagedTracerOptionsTest.java?rev=884845&r1=884844&r2=884845&view=diff
==============================================================================
--- camel/trunk/camel-core/src/test/java/org/apache/camel/management/ManagedTracerOptionsTest.java
(original)
+++ camel/trunk/camel-core/src/test/java/org/apache/camel/management/ManagedTracerOptionsTest.java
Fri Nov 27 12:05:44 2009
@@ -138,6 +138,10 @@
         Boolean fsn = (Boolean) mbeanServer.getAttribute(on, "FormatterShowNode");
         assertEquals(true, fsn.booleanValue());
 
+        mbeanServer.setAttribute(on, new Attribute("FormatterShowRouteId", Boolean.FALSE));
+        Boolean fsr = (Boolean) mbeanServer.getAttribute(on, "FormatterShowRouteId");
+        assertEquals(false, fsr.booleanValue());
+
         mbeanServer.setAttribute(on, new Attribute("FormatterShowExchangePattern", Boolean.TRUE));
         Boolean fsep = (Boolean) mbeanServer.getAttribute(on, "FormatterShowExchangePattern");
         assertEquals(true, fsep.booleanValue());

Modified: camel/trunk/camel-core/src/test/java/org/apache/camel/processor/TraceInterceptorTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/TraceInterceptorTest.java?rev=884845&r1=884844&r2=884845&view=diff
==============================================================================
--- camel/trunk/camel-core/src/test/java/org/apache/camel/processor/TraceInterceptorTest.java
(original)
+++ camel/trunk/camel-core/src/test/java/org/apache/camel/processor/TraceInterceptorTest.java
Fri Nov 27 12:05:44 2009
@@ -38,7 +38,7 @@
                 // enable tracing
                 getContext().setTracing(true);
 
-                from("direct:start").
+                from("direct:start").routeId("foo").
                         process(new Processor() {
                             public void process(Exchange exchange) throws Exception {
                                 // do nothing
@@ -49,8 +49,10 @@
                                 return "MyProcessor";
                             }
                         }).
-                        to("mock:a").
-                        to("mock:b");
+                        to("mock:foo").
+                        to("direct:bar");
+
+                from("direct:bar").routeId("bar").to("mock:bar");
             }
         };
     }

Modified: camel/trunk/camel-core/src/test/java/org/apache/camel/processor/interceptor/DefaultTraceFormatterTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/test/java/org/apache/camel/processor/interceptor/DefaultTraceFormatterTest.java?rev=884845&r1=884844&r2=884845&view=diff
==============================================================================
--- camel/trunk/camel-core/src/test/java/org/apache/camel/processor/interceptor/DefaultTraceFormatterTest.java
(original)
+++ camel/trunk/camel-core/src/test/java/org/apache/camel/processor/interceptor/DefaultTraceFormatterTest.java
Fri Nov 27 12:05:44 2009
@@ -152,6 +152,9 @@
         formatter.setShowShortExchangeId(true);
         assertEquals(true, formatter.isShowShortExchangeId());
 
+        formatter.setShowRouteId(false);
+        assertEquals(false, formatter.isShowRouteId());
+
         return formatter;
     }
 



Mime
View raw message