You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@activemq.apache.org by ta...@apache.org on 2014/08/07 00:00:57 UTC
git commit: AMQ-4829: Fixed activemq:dstat command and also sort the
listing A..Z by default.
Repository: activemq
Updated Branches:
refs/heads/activemq-5.9 6902eaefc -> 679ab8cb0
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/679ab8cb
Tree: http://git-wip-us.apache.org/repos/asf/activemq/tree/679ab8cb
Diff: http://git-wip-us.apache.org/repos/asf/activemq/diff/679ab8cb
Branch: refs/heads/activemq-5.9
Commit: 679ab8cb0c9c4a4c331f77eaca6f9665b2838bf3
Parents: 6902eae
Author: Claus Ibsen <cl...@gmail.com>
Authored: Mon Oct 28 17:02:17 2013 +0100
Committer: Timothy Bish <ta...@gmail.com>
Committed: Wed Aug 6 17:58:06 2014 -0400
----------------------------------------------------------------------
.../activemq/console/command/DstatCommand.java | 58 +++++++++++++++++---
1 file changed, 50 insertions(+), 8 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/activemq/blob/679ab8cb/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<ObjectInstance> {
+
+ @Override
+ public int compare(ObjectInstance o1, ObjectInstance o2) {
+ return o1.getObjectName().compareTo(o2.getObjectName());
+ }
+ }
+
}
\ No newline at end of file