Author: jbellis
Date: Tue Aug 11 20:40:10 2009
New Revision: 803285

URL: http://svn.apache.org/viewvc?rev=803285&view=rev
Log:
expose threadpool's pendingtasks via nodeprobe.  patch by Sammy Yu; reviewed by 
jbellis for CASSANDRA-360

Modified:
    incubator/cassandra/trunk/src/java/org/apache/cassandra/tools/NodeProbe.java

Modified: 
incubator/cassandra/trunk/src/java/org/apache/cassandra/tools/NodeProbe.java
URL: 
http://svn.apache.org/viewvc/incubator/cassandra/trunk/src/java/org/apache/cassandra/tools/NodeProbe.java?rev=803285&r1=803284&r2=803285&view=diff
==============================================================================
--- 
incubator/cassandra/trunk/src/java/org/apache/cassandra/tools/NodeProbe.java 
(original)
+++ 
incubator/cassandra/trunk/src/java/org/apache/cassandra/tools/NodeProbe.java 
Tue Aug 11 20:40:10 2009
@@ -39,6 +39,7 @@
 import javax.management.remote.JMXConnectorFactory;
 import javax.management.remote.JMXServiceURL;
 
+import org.apache.cassandra.concurrent.DebuggableThreadPoolExecutorMBean;
 import org.apache.cassandra.db.ColumnFamilyStoreMBean;
 import org.apache.cassandra.dht.Range;
 import org.apache.cassandra.net.EndPoint;
@@ -453,6 +454,37 @@
     }
 
     /**
+     * Print out the size of the queues in the thread pools
+     *
+     * @param outs Output stream to generate the output on.
+     */
+    public void printThreadPoolStats(PrintStream outs)
+    {
+        ObjectName query;
+        try
+        {
+            query = new ObjectName("org.apache.cassandra.concurrent:type=*");
+            Set<ObjectName> result = mbeanServerConn.queryNames(query, null);
+            for (ObjectName objectName : result)
+            {
+                String poolName = objectName.getKeyProperty("type");
+                DebuggableThreadPoolExecutorMBean threadPoolProxy = 
JMX.newMBeanProxy(mbeanServerConn,
+                                                                               
       objectName,
+                                                                               
       DebuggableThreadPoolExecutorMBean.class);
+                outs.println(poolName + ", pending tasks=" + 
threadPoolProxy.getPendingTasks());
+            }
+        }
+        catch (MalformedObjectNameException e)
+        {
+            throw new RuntimeException("Invalid ObjectName? Please report this 
as a bug.", e);
+        }
+        catch (IOException e)
+        {
+            throw new RuntimeException("Could not retrieve list of stat 
mbeans.", e);
+        }
+    }
+
+    /**
      * Retrieve any non-option arguments passed on the command line.
      * 
      * @return non-option command args
@@ -481,7 +513,7 @@
     {
         HelpFormatter hf = new HelpFormatter();
         String header = String.format(
-                "%nAvailable commands: ring, cluster, info, cleanup, compact, 
cfstats, snapshot [name], clearsnapshot, bootstrap");
+                "%nAvailable commands: ring, cluster, info, cleanup, compact, 
cfstats, snapshot [name], clearsnapshot, bootstrap, tpstats");
         String usage = String.format("java %s -host <arg> <command>%n", 
NodeProbe.class.getName());
         hf.printHelp(usage, "", options, header);
     }
@@ -569,6 +601,10 @@
                 System.exit(1);                
             }
         }
+        else if (cmdName.equals("tpstats"))
+        {
+            probe.printThreadPoolStats(System.out);
+        }
         else
         {
             System.err.println("Unrecognized command: " + cmdName + ".");


Reply via email to