Return-Path: X-Original-To: apmail-activemq-commits-archive@www.apache.org Delivered-To: apmail-activemq-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id EEB441092A for ; Mon, 28 Oct 2013 16:11:28 +0000 (UTC) Received: (qmail 77836 invoked by uid 500); 28 Oct 2013 16:01:45 -0000 Delivered-To: apmail-activemq-commits-archive@activemq.apache.org Received: (qmail 77700 invoked by uid 500); 28 Oct 2013 16:01:41 -0000 Mailing-List: contact commits-help@activemq.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@activemq.apache.org Delivered-To: mailing list commits@activemq.apache.org Received: (qmail 77616 invoked by uid 99); 28 Oct 2013 16:01:39 -0000 Received: from tyr.zones.apache.org (HELO tyr.zones.apache.org) (140.211.11.114) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 28 Oct 2013 16:01:39 +0000 Received: by tyr.zones.apache.org (Postfix, from userid 65534) id 49C7A8864AC; Mon, 28 Oct 2013 16:01:39 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: davsclaus@apache.org To: commits@activemq.apache.org Message-Id: <69aa7e40e4aa4a74b07ccb815609259c@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: git commit: AMQ-4829: Fixed activemq:dstat command and also sort the listing A..Z by default. Date: Mon, 28 Oct 2013 16:01:39 +0000 (UTC) Updated Branches: refs/heads/trunk da45d994a -> dc290ecb4 AMQ-4829: Fixed activemq:dstat command and also sort the listing A..Z by default. Project: http://git-wip-us.apache.org/repos/asf/activemq/repo Commit: http://git-wip-us.apache.org/repos/asf/activemq/commit/dc290ecb Tree: http://git-wip-us.apache.org/repos/asf/activemq/tree/dc290ecb Diff: http://git-wip-us.apache.org/repos/asf/activemq/diff/dc290ecb Branch: refs/heads/trunk Commit: dc290ecb457d74cadf7286083e955cfe4b29bf94 Parents: da45d99 Author: Claus Ibsen Authored: Mon Oct 28 17:02:17 2013 +0100 Committer: Claus Ibsen Committed: Mon Oct 28 17:02:17 2013 +0100 ---------------------------------------------------------------------- .../activemq/console/command/DstatCommand.java | 58 +++++++++++++++++--- 1 file changed, 50 insertions(+), 8 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/activemq/blob/dc290ecb/activemq-console/src/main/java/org/apache/activemq/console/command/DstatCommand.java ---------------------------------------------------------------------- diff --git a/activemq-console/src/main/java/org/apache/activemq/console/command/DstatCommand.java b/activemq-console/src/main/java/org/apache/activemq/console/command/DstatCommand.java index a64e190..a6d6356 100644 --- a/activemq-console/src/main/java/org/apache/activemq/console/command/DstatCommand.java +++ b/activemq-console/src/main/java/org/apache/activemq/console/command/DstatCommand.java @@ -16,14 +16,17 @@ */ package org.apache.activemq.console.command; +import java.util.Collections; +import java.util.Comparator; import java.util.List; import java.util.Locale; - import javax.management.MBeanServerInvocationHandler; import javax.management.ObjectInstance; import javax.management.ObjectName; +import org.apache.activemq.broker.jmx.QueueView; import org.apache.activemq.broker.jmx.QueueViewMBean; +import org.apache.activemq.broker.jmx.TopicView; import org.apache.activemq.broker.jmx.TopicViewMBean; import org.apache.activemq.console.util.JmxMBeansUtil; @@ -75,24 +78,33 @@ public class DstatCommand extends AbstractJmxCommand { // Iterate through the queue names } catch (Exception e) { - context.printException(new RuntimeException("Failed to execute dstat task. Reason: " + e)); + context.printException(new RuntimeException("Failed to execute dstat task. Reason: " + e.getMessage(), e)); throw new Exception(e); } } + @SuppressWarnings("unchecked") private void displayAllDestinations() throws Exception { String query = JmxMBeansUtil.createQueryString(queryString, "*"); - List queueList = JmxMBeansUtil.queryMBeans(createJmxConnection(), query); + List queueList = JmxMBeansUtil.queryMBeans(createJmxConnection(), query); final String header = "%-50s %10s %10s %10s %10s %10s %10s"; final String tableRow = "%-50s %10d %10d %10d %10d %10d %10d"; + // sort list so the names is A..Z + Collections.sort(queueList, new ObjectInstanceComparator()); + context.print(String.format(Locale.US, header, "Name", "Queue Size", "Producer #", "Consumer #", "Enqueue #", "Dequeue #", "Memory %")); // Iterate through the queue result for (Object view : queueList) { - ObjectName queueName = ((ObjectInstance)view).getObjectName(); + ObjectInstance obj = (ObjectInstance) view; + if (!filterMBeans(obj)) { + continue; + } + ObjectName queueName = obj.getObjectName(); + QueueViewMBean queueView = MBeanServerInvocationHandler. newProxyInstance(createJmxConnection(), queueName, QueueViewMBean.class, true); @@ -107,19 +119,27 @@ public class DstatCommand extends AbstractJmxCommand { } } + @SuppressWarnings("unchecked") private void displayQueueStats() throws Exception { String query = JmxMBeansUtil.createQueryString(queryString, "Queue"); - List queueList = JmxMBeansUtil.queryMBeans(createJmxConnection(), query); + List queueList = JmxMBeansUtil.queryMBeans(createJmxConnection(), query); final String header = "%-50s %10s %10s %10s %10s %10s %10s"; final String tableRow = "%-50s %10d %10d %10d %10d %10d %10d"; context.print(String.format(Locale.US, header, "Name", "Queue Size", "Producer #", "Consumer #", "Enqueue #", "Dequeue #", "Memory %")); + Collections.sort(queueList, new ObjectInstanceComparator()); + // Iterate through the queue result for (Object view : queueList) { - ObjectName queueName = ((ObjectInstance)view).getObjectName(); + ObjectInstance obj = (ObjectInstance) view; + if (!filterMBeans(obj)) { + continue; + } + ObjectName queueName = obj.getObjectName(); + QueueViewMBean queueView = MBeanServerInvocationHandler. newProxyInstance(createJmxConnection(), queueName, QueueViewMBean.class, true); @@ -134,19 +154,28 @@ public class DstatCommand extends AbstractJmxCommand { } } + @SuppressWarnings("unchecked") private void displayTopicStats() throws Exception { String query = JmxMBeansUtil.createQueryString(queryString, "Topic"); - List topicsList = JmxMBeansUtil.queryMBeans(createJmxConnection(), query); + List topicsList = JmxMBeansUtil.queryMBeans(createJmxConnection(), query); final String header = "%-50s %10s %10s %10s %10s %10s %10s"; final String tableRow = "%-50s %10d %10d %10d %10d %10d %10d"; + // sort list so the names is A..Z + Collections.sort(topicsList, new ObjectInstanceComparator()); + context.print(String.format(Locale.US, header, "Name", "Queue Size", "Producer #", "Consumer #", "Enqueue #", "Dequeue #", "Memory %")); // Iterate through the topics result for (Object view : topicsList) { - ObjectName topicName = ((ObjectInstance)view).getObjectName(); + ObjectInstance obj = (ObjectInstance) view; + if (!filterMBeans(obj)) { + continue; + } + ObjectName topicName = obj.getObjectName(); + TopicViewMBean topicView = MBeanServerInvocationHandler. newProxyInstance(createJmxConnection(), topicName, TopicViewMBean.class, true); @@ -179,4 +208,17 @@ public class DstatCommand extends AbstractJmxCommand { context.printHelp(helpFile); } + protected boolean filterMBeans(ObjectInstance obj) { + String className = obj.getClassName(); + return className.equals(QueueView.class.getName()) || className.equals(TopicView.class.getName()); + } + + private static class ObjectInstanceComparator implements Comparator { + + @Override + public int compare(ObjectInstance o1, ObjectInstance o2) { + return o1.getObjectName().compareTo(o2.getObjectName()); + } + } + } \ No newline at end of file