camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject svn commit: r1464481 - in /camel/trunk: camel-core/src/main/java/org/apache/camel/management/mbean/ platforms/karaf/commands/src/main/java/org/apache/camel/karaf/commands/ platforms/karaf/commands/src/main/resources/OSGI-INF/blueprint/
Date Thu, 04 Apr 2013 12:00:02 GMT
Author: davsclaus
Date: Thu Apr  4 12:00:02 2013
New Revision: 1464481

URL: http://svn.apache.org/r1464481
Log:
CAMEL-6237: Added camel karaf command for reset route stats.

Added:
    camel/trunk/platforms/karaf/commands/src/main/java/org/apache/camel/karaf/commands/RouteResetStats.java
      - copied, changed from r1464379, camel/trunk/platforms/karaf/commands/src/main/java/org/apache/camel/karaf/commands/RouteStart.java
Modified:
    camel/trunk/camel-core/src/main/java/org/apache/camel/management/mbean/ManagedRoute.java
    camel/trunk/platforms/karaf/commands/src/main/java/org/apache/camel/karaf/commands/RouteProfile.java
    camel/trunk/platforms/karaf/commands/src/main/resources/OSGI-INF/blueprint/camel-commands.xml

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=1464481&r1=1464480&r2=1464481&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 12:00:02 2013
@@ -231,7 +231,7 @@ 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
+                // get all the processor mbeans and sort them accordingly 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>();

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=1464481&r1=1464480&r2=1464481&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 12:00:02 2013
@@ -30,6 +30,7 @@ import org.apache.camel.management.Defau
 import org.apache.camel.spi.ManagementAgent;
 import org.apache.camel.util.ProcessorStatDump;
 import org.apache.camel.util.RouteStatDump;
+import org.apache.camel.util.URISupport;
 import org.apache.felix.gogo.commands.Argument;
 import org.apache.felix.gogo.commands.Command;
 import org.apache.karaf.shell.console.OsgiCommandSupport;
@@ -68,6 +69,7 @@ public class RouteProfile extends OsgiCo
         Unmarshaller unmarshaller = context.createUnmarshaller();
 
         System.out.println(StringEscapeUtils.unescapeJava("\u001B[1m\u001B[33mCamel Route
" + camelRoute.getId() + "\u001B[0m"));
+        System.out.println(StringEscapeUtils.unescapeJava("\tEndpoint uri: " + URISupport.sanitizeUri(camelRoute.getEndpoint().getEndpointUri())));
         System.out.println(StringEscapeUtils.unescapeJava("\tCamel Context: " + camelRoute.getRouteContext().getCamelContext().getName()));
         System.out.println("");
         System.out.println(StringEscapeUtils.unescapeJava("\u001B[1mProfile\u001B[0m"));
@@ -81,7 +83,6 @@ public class RouteProfile extends OsgiCo
                 if (iterator.hasNext()) {
                     ObjectName routeMBean = iterator.next();
 
-                    // TODO: add a row with the route endpoint, so you can see that
                     // TODO: add column with total time (delta for self time)
 
                     String xml = (String) mBeanServer.invoke(routeMBean, "dumpRouteStatsAsXml",
new Object[]{Boolean.FALSE, Boolean.TRUE}, new String[]{"boolean", "boolean"});

Copied: camel/trunk/platforms/karaf/commands/src/main/java/org/apache/camel/karaf/commands/RouteResetStats.java
(from r1464379, camel/trunk/platforms/karaf/commands/src/main/java/org/apache/camel/karaf/commands/RouteStart.java)
URL: http://svn.apache.org/viewvc/camel/trunk/platforms/karaf/commands/src/main/java/org/apache/camel/karaf/commands/RouteResetStats.java?p2=camel/trunk/platforms/karaf/commands/src/main/java/org/apache/camel/karaf/commands/RouteResetStats.java&p1=camel/trunk/platforms/karaf/commands/src/main/java/org/apache/camel/karaf/commands/RouteStart.java&r1=1464379&r2=1464481&rev=1464481&view=diff
==============================================================================
--- camel/trunk/platforms/karaf/commands/src/main/java/org/apache/camel/karaf/commands/RouteStart.java
(original)
+++ camel/trunk/platforms/karaf/commands/src/main/java/org/apache/camel/karaf/commands/RouteResetStats.java
Thu Apr  4 12:00:02 2013
@@ -16,19 +16,58 @@
  */
 package org.apache.camel.karaf.commands;
 
+import java.util.Iterator;
+import java.util.Set;
+import javax.management.MBeanServer;
+import javax.management.ObjectName;
+
 import org.apache.camel.CamelContext;
 import org.apache.camel.Route;
+import org.apache.camel.management.DefaultManagementAgent;
+import org.apache.camel.spi.ManagementAgent;
 import org.apache.felix.gogo.commands.Command;
 
 /**
- * Command to start a route.
+ * Command to reset route stats.
  */
-@Command(scope = "camel", name = "route-start", description = "Start a Camel route or a group
of routes")
-public class RouteStart extends AbstractRouteCommand {
+@Command(scope = "camel", name = "route-reset-stats", description = "Reset performance stats
on a route or group of routes")
+public class RouteResetStats extends AbstractRouteCommand {
 
     @Override
     public void executeOnRoute(CamelContext camelContext, Route camelRoute) throws Exception
{
-        camelContext.startRoute(camelRoute.getId());
+        String id = camelRoute.getId();
+
+        ManagementAgent agent = camelContext.getManagementStrategy().getManagementAgent();
+        if (agent != null) {
+            MBeanServer mBeanServer = agent.getMBeanServer();
+
+            // reset route mbeans
+            ObjectName query = ObjectName.getInstance(DefaultManagementAgent.DEFAULT_DOMAIN
+ ":type=routes,*");
+            Set<ObjectName> set = mBeanServer.queryNames(query, null);
+            Iterator<ObjectName> iterator = set.iterator();
+            while (iterator.hasNext()) {
+                ObjectName routeMBean = iterator.next();
+
+                String camelId = (String) mBeanServer.getAttribute(routeMBean, "CamelId");
+                if (camelId != null && camelId.equals(camelContext.getName())) {
+                    mBeanServer.invoke(routeMBean, "reset", null, null);
+                }
+            }
+
+            // reset processor mbeans that belongs to the given route
+            query = ObjectName.getInstance(DefaultManagementAgent.DEFAULT_DOMAIN + ":type=processors,*");
+            set = mBeanServer.queryNames(query, null);
+            iterator = set.iterator();
+            while (iterator.hasNext()) {
+                ObjectName processorMBean = iterator.next();
+                // must belong to this camel context and match the route id
+                String camelId = (String) mBeanServer.getAttribute(processorMBean, "CamelId");
+                String routeId = (String) mBeanServer.getAttribute(processorMBean, "RouteId");
+                if (camelId != null && camelId.equals(camelContext.getName()) &&
routeId != null && routeId.equals(id)) {
+                    mBeanServer.invoke(processorMBean, "reset", null, null);
+                }
+            }
+        }
     }
 
 }

Modified: camel/trunk/platforms/karaf/commands/src/main/resources/OSGI-INF/blueprint/camel-commands.xml
URL: http://svn.apache.org/viewvc/camel/trunk/platforms/karaf/commands/src/main/resources/OSGI-INF/blueprint/camel-commands.xml?rev=1464481&r1=1464480&r2=1464481&view=diff
==============================================================================
--- camel/trunk/platforms/karaf/commands/src/main/resources/OSGI-INF/blueprint/camel-commands.xml
(original)
+++ camel/trunk/platforms/karaf/commands/src/main/resources/OSGI-INF/blueprint/camel-commands.xml
Thu Apr  4 12:00:02 2013
@@ -77,6 +77,15 @@
                 <null/>
             </completers>
         </command>
+        <command name="camel/route-reset-stats">
+            <action class="org.apache.camel.karaf.commands.RouteResetStats">
+                <property name="camelController" ref="camelController"/>
+            </action>
+            <completers>
+                <ref component-id="routeCompleter"/>
+                <null/>
+            </completers>
+        </command>
         <command name="camel/route-show">
             <action class="org.apache.camel.karaf.commands.RouteShow">
                 <property name="camelController" ref="camelController"/>



Mime
View raw message