camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject svn commit: r1464379 - in /camel/trunk: camel-core/src/main/java/org/apache/camel/api/management/mbean/ camel-core/src/main/java/org/apache/camel/management/ camel-core/src/main/java/org/apache/camel/management/mbean/ camel-core/src/main/java/org/apach...
Date Thu, 04 Apr 2013 09:12:36 GMT
Author: davsclaus
Date: Thu Apr  4 09:12:35 2013
New Revision: 1464379

URL: http://svn.apache.org/r1464379
Log:
CAMEL-6239: Added index to processor defs so we know the order they were created / positioned
in routes etc. Exposes that for JMX so karaf camel command can leverage that.

Modified:
    camel/trunk/camel-core/src/main/java/org/apache/camel/api/management/mbean/ManagedProcessorMBean.java
    camel/trunk/camel-core/src/main/java/org/apache/camel/management/DefaultManagementLifecycleStrategy.java
    camel/trunk/camel-core/src/main/java/org/apache/camel/management/mbean/ManagedPerformanceCounter.java
    camel/trunk/camel-core/src/main/java/org/apache/camel/management/mbean/ManagedProcessor.java
    camel/trunk/camel-core/src/main/java/org/apache/camel/management/mbean/ManagedRoute.java
    camel/trunk/camel-core/src/main/java/org/apache/camel/model/ProcessorDefinition.java
    camel/trunk/camel-core/src/main/java/org/apache/camel/util/ProcessorStatDump.java
    camel/trunk/platforms/karaf/commands/src/main/java/org/apache/camel/karaf/commands/RouteProfile.java

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/api/management/mbean/ManagedProcessorMBean.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/api/management/mbean/ManagedProcessorMBean.java?rev=1464379&r1=1464378&r2=1464379&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/api/management/mbean/ManagedProcessorMBean.java
(original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/api/management/mbean/ManagedProcessorMBean.java
Thu Apr  4 09:12:35 2013
@@ -33,6 +33,9 @@ public interface ManagedProcessorMBean e
     @ManagedAttribute(description = "Processor ID")
     String getProcessorId();
 
+    @ManagedAttribute(description = "Processor Index")
+    Integer getIndex();
+
     @ManagedOperation(description = "Start Processor")
     void start() throws Exception;
 

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/management/DefaultManagementLifecycleStrategy.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/management/DefaultManagementLifecycleStrategy.java?rev=1464379&r1=1464378&r2=1464379&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/management/DefaultManagementLifecycleStrategy.java
(original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/management/DefaultManagementLifecycleStrategy.java
Thu Apr  4 09:12:35 2013
@@ -25,6 +25,7 @@ import java.util.List;
 import java.util.Map;
 import java.util.Set;
 import java.util.concurrent.ThreadPoolExecutor;
+import java.util.concurrent.atomic.AtomicLong;
 import javax.management.JMException;
 import javax.management.MalformedObjectNameException;
 import javax.management.ObjectName;
@@ -100,6 +101,8 @@ import org.slf4j.LoggerFactory;
 public class DefaultManagementLifecycleStrategy extends ServiceSupport implements LifecycleStrategy,
CamelContextAware {
 
     private static final Logger LOG = LoggerFactory.getLogger(DefaultManagementLifecycleStrategy.class);
+    // unique counter we use when registering a new mbean which allows to know the order
they were registered
+    private final AtomicLong counter = new AtomicLong();
     // the wrapped processors is for performance counters, which are in use for the created
routes
     // when a route is removed, we should remove the associated processors from this map
     private final Map<Processor, KeyValueHolder<ProcessorDefinition<?>, InstrumentationProcessor>>
wrappedProcessors =

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/management/mbean/ManagedPerformanceCounter.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/management/mbean/ManagedPerformanceCounter.java?rev=1464379&r1=1464378&r2=1464379&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/management/mbean/ManagedPerformanceCounter.java
(original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/management/mbean/ManagedPerformanceCounter.java
Thu Apr  4 09:12:35 2013
@@ -26,7 +26,7 @@ import org.apache.camel.api.management.m
 import org.apache.camel.spi.ManagementStrategy;
 import org.apache.camel.util.ExchangeHelper;
 
-@ManagedResource(description = "PerformanceCounter")
+@ManagedResource(description = "Managed PerformanceCounter")
 public abstract class ManagedPerformanceCounter extends ManagedCounter implements PerformanceCounter,
ManagedPerformanceCounterMBean {
 
     public static final String TIMESTAMP_FORMAT = "yyyy-MM-dd'T'HH:mm:ss.SSSZ";

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/management/mbean/ManagedProcessor.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/management/mbean/ManagedProcessor.java?rev=1464379&r1=1464378&r2=1464379&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/management/mbean/ManagedProcessor.java
(original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/management/mbean/ManagedProcessor.java
Thu Apr  4 09:12:35 2013
@@ -62,6 +62,14 @@ public class ManagedProcessor extends Ma
         return definition;
     }
 
+    public String getId() {
+        return id;
+    }
+
+    public Integer getIndex() {
+        return definition.getIndex();
+    }
+
     public Route getRoute() {
         return route;
     }

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/management/mbean/ManagedRoute.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/management/mbean/ManagedRoute.java?rev=1464379&r1=1464378&r2=1464379&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/management/mbean/ManagedRoute.java
(original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/management/mbean/ManagedRoute.java
Thu Apr  4 09:12:35 2013
@@ -16,6 +16,9 @@
  */
 package org.apache.camel.management.mbean;
 
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Comparator;
 import java.util.List;
 import java.util.Set;
 import java.util.concurrent.TimeUnit;
@@ -228,13 +231,21 @@ public class ManagedRoute extends Manage
             sb.append("  <processorStats>\n");
             MBeanServer server = getContext().getManagementStrategy().getManagementAgent().getMBeanServer();
             if (server != null) {
+                // get all the processor mbeans and sort them accordinly to their index
                 ObjectName query = ObjectName.getInstance("org.apache.camel:context=*/" +
getContext().getManagementName() + ",type=processors,*");
                 Set<ObjectName> names = server.queryNames(query, null);
+                List<ManagedProcessorMBean> mps = new ArrayList<ManagedProcessorMBean>();
                 for (ObjectName on : names) {
                     ManagedProcessorMBean processor = MBeanServerInvocationHandler.newProxyInstance(server,
on, ManagedProcessorMBean.class, true);
+                    mps.add(processor);
+                }
+                Collections.sort(mps, new OrderProcessorMBeans());
+
+                // and now add the sorted list of processors to the xml output
+                for (ManagedProcessorMBean processor : mps) {
                     // the processor must belong to this route
                     if (getRouteId().equals(processor.getRouteId())) {
-                        sb.append("    <processorStat").append(String.format(" id=\"%s\"",
processor.getProcessorId()));
+                        sb.append("    <processorStat").append(String.format(" id=\"%s\"
index=\"%s\"", processor.getProcessorId(), processor.getIndex()));
                         // use substring as we only want the attributes
                         sb.append(" ").append(processor.dumpStatsAsXml(fullStats).substring(7)).append("\n");
                     }
@@ -256,4 +267,16 @@ public class ManagedRoute extends Manage
     public int hashCode() {
         return route.hashCode();
     }
+
+    /**
+     * Used for sorting the processor mbeans accordingly to their index.
+     */
+    private final static class OrderProcessorMBeans implements Comparator<ManagedProcessorMBean>
{
+
+        @Override
+        public int compare(ManagedProcessorMBean o1, ManagedProcessorMBean o2) {
+            return o1.getIndex().compareTo(o2.getIndex());
+        }
+    }
+
 }

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=1464379&r1=1464378&r2=1464379&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 Thu
Apr  4 09:12:35 2013
@@ -27,6 +27,7 @@ import java.util.List;
 import java.util.Map;
 import java.util.concurrent.ExecutorService;
 import java.util.concurrent.TimeUnit;
+import java.util.concurrent.atomic.AtomicInteger;
 import javax.xml.bind.annotation.XmlAccessType;
 import javax.xml.bind.annotation.XmlAccessorType;
 import javax.xml.bind.annotation.XmlAnyAttribute;
@@ -86,6 +87,25 @@ public abstract class ProcessorDefinitio
 
     // use xs:any to support optional property placeholders
     private Map<QName, Object> otherAttributes;
+    private static final AtomicInteger COUNTER = new AtomicInteger();
+    private final int index;
+
+    protected ProcessorDefinition() {
+        // every time we create a definition we should inc the COUNTER counter
+        index = COUNTER.getAndIncrement();
+    }
+
+    /**
+     * Gets the unique index number for when this {@link ProcessorDefinition} was created
by its constructor.
+     * <p/>
+     * This can be used to know the order in which the definition was created when assembled
as a route.
+     *
+     * @return the current COUNTER value
+     */
+    @XmlTransient // do not expose this in the XML DSL
+    public int getIndex() {
+        return index;
+    }
 
     // else to use an optional attribute in JAXB2
     public abstract List<ProcessorDefinition<?>> getOutputs();

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/util/ProcessorStatDump.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/util/ProcessorStatDump.java?rev=1464379&r1=1464378&r2=1464379&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/util/ProcessorStatDump.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/util/ProcessorStatDump.java Thu
Apr  4 09:12:35 2013
@@ -32,6 +32,9 @@ public final class ProcessorStatDump {
     private String id;
 
     @XmlAttribute
+    private Integer index;
+
+    @XmlAttribute
     private Long exchangesCompleted;
 
     @XmlAttribute
@@ -90,6 +93,14 @@ public final class ProcessorStatDump {
         this.id = id;
     }
 
+    public Integer getIndex() {
+        return index;
+    }
+
+    public void setIndex(Integer index) {
+        this.index = index;
+    }
+
     public Long getExchangesCompleted() {
         return exchangesCompleted;
     }

Modified: camel/trunk/platforms/karaf/commands/src/main/java/org/apache/camel/karaf/commands/RouteProfile.java
URL: http://svn.apache.org/viewvc/camel/trunk/platforms/karaf/commands/src/main/java/org/apache/camel/karaf/commands/RouteProfile.java?rev=1464379&r1=1464378&r2=1464379&view=diff
==============================================================================
--- camel/trunk/platforms/karaf/commands/src/main/java/org/apache/camel/karaf/commands/RouteProfile.java
(original)
+++ camel/trunk/platforms/karaf/commands/src/main/java/org/apache/camel/karaf/commands/RouteProfile.java
Thu Apr  4 09:12:35 2013
@@ -83,7 +83,6 @@ public class RouteProfile extends OsgiCo
 
                     // TODO: add a row with the route endpoint, so you can see that
                     // TODO: add column with total time (delta for self time)
-                    // TODO: ensure the jmx mbeans for processors is sorted correctly
 
                     String xml = (String) mBeanServer.invoke(routeMBean, "dumpRouteStatsAsXml",
new Object[]{Boolean.FALSE, Boolean.TRUE}, new String[]{"boolean", "boolean"});
                     RouteStatDump route = (RouteStatDump) unmarshaller.unmarshal(new StringReader(xml));
@@ -93,8 +92,7 @@ public class RouteProfile extends OsgiCo
                             route.getMeanProcessingTime(), route.getMinProcessingTime(),
route.getMaxProcessingTime(), route.getTotalProcessingTime(), 0));
 
                     // output in reverse order which prints the route as we want
-                    for (int i = route.getProcessorStats().size() - 1; i >= 0; i--) {
-                        ProcessorStatDump ps = route.getProcessorStats().get(i);
+                    for (ProcessorStatDump ps : route.getProcessorStats()) {
                         // the self time is the total time of the processor itself
                         long selfTime = ps.getTotalProcessingTime();
                         // indent route id with 2 spaces



Mime
View raw message