activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dej...@apache.org
Subject activemq git commit: https://issues.apache.org/jira/browse/AMQ-5724 - Query command don't filter properly
Date Wed, 15 Apr 2015 11:32:28 GMT
Repository: activemq
Updated Branches:
  refs/heads/master be6617507 -> eece06b32


https://issues.apache.org/jira/browse/AMQ-5724 - Query command don't filter properly


Project: http://git-wip-us.apache.org/repos/asf/activemq/repo
Commit: http://git-wip-us.apache.org/repos/asf/activemq/commit/eece06b3
Tree: http://git-wip-us.apache.org/repos/asf/activemq/tree/eece06b3
Diff: http://git-wip-us.apache.org/repos/asf/activemq/diff/eece06b3

Branch: refs/heads/master
Commit: eece06b326468708aeb8a9703c1e6e9e1fa6822a
Parents: be66175
Author: Dejan Bosanac <dejan@nighttale.net>
Authored: Wed Apr 15 13:30:22 2015 +0200
Committer: Dejan Bosanac <dejan@nighttale.net>
Committed: Wed Apr 15 13:30:31 2015 +0200

----------------------------------------------------------------------
 .../activemq/console/command/QueryCommand.java  | 23 ++++--------
 .../console/filter/PropertiesViewFilter.java    | 12 ++-----
 .../activemq/console/util/JmxMBeansUtil.java    | 37 +++++++++++---------
 3 files changed, 30 insertions(+), 42 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/activemq/blob/eece06b3/activemq-console/src/main/java/org/apache/activemq/console/command/QueryCommand.java
----------------------------------------------------------------------
diff --git a/activemq-console/src/main/java/org/apache/activemq/console/command/QueryCommand.java
b/activemq-console/src/main/java/org/apache/activemq/console/command/QueryCommand.java
index b11ebde..bdb6b88 100644
--- a/activemq-console/src/main/java/org/apache/activemq/console/command/QueryCommand.java
+++ b/activemq-console/src/main/java/org/apache/activemq/console/command/QueryCommand.java
@@ -16,16 +16,10 @@
  */
 package org.apache.activemq.console.command;
 
-import java.util.ArrayList;
-import java.util.Enumeration;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Properties;
-import java.util.Set;
-import java.util.StringTokenizer;
-
 import org.apache.activemq.console.util.JmxMBeansUtil;
 
+import java.util.*;
+
 public class QueryCommand extends AbstractJmxCommand {
     // Predefined type=identifier query
     private static final Properties PREDEFINED_OBJNAME_QUERY = new Properties();
@@ -96,7 +90,7 @@ public class QueryCommand extends AbstractJmxCommand {
 
     private final List<String> queryAddObjects = new ArrayList<String>(10);
     private final List<String> querySubObjects = new ArrayList<String>(10);
-    private final Set queryViews = new HashSet(10);
+    private final Set queryViews = new LinkedHashSet();
 
     @Override
     public String getName() {
@@ -117,16 +111,13 @@ public class QueryCommand extends AbstractJmxCommand {
     protected void runTask(List<String> tokens) throws Exception {
         try {
             // Query for the mbeans to add
-            List addMBeans = JmxMBeansUtil.queryMBeans(createJmxConnection(), queryAddObjects,
queryViews);
-
+            Map<String,List> addMBeans = JmxMBeansUtil.queryMBeansAsMap(createJmxConnection(),
queryAddObjects, queryViews);
             // Query for the mbeans to sub
             if (querySubObjects.size() > 0) {
-                List subMBeans = JmxMBeansUtil.queryMBeans(createJmxConnection(), querySubObjects,
queryViews);
-                addMBeans.removeAll(subMBeans);
+                Map<String,List> subMBeans = JmxMBeansUtil.queryMBeansAsMap(createJmxConnection(),
querySubObjects, queryViews);
+                addMBeans.keySet().removeAll(subMBeans.keySet());
             }
-
-            context.printMBean(JmxMBeansUtil.filterMBeansView(addMBeans, queryViews));
-
+            context.printMBean(JmxMBeansUtil.filterMBeansView(new ArrayList(addMBeans.values()),
queryViews));
         } catch (Exception e) {
             context.printException(new RuntimeException("Failed to execute query task. Reason:
" + e));
             throw new Exception(e);

http://git-wip-us.apache.org/repos/asf/activemq/blob/eece06b3/activemq-console/src/main/java/org/apache/activemq/console/filter/PropertiesViewFilter.java
----------------------------------------------------------------------
diff --git a/activemq-console/src/main/java/org/apache/activemq/console/filter/PropertiesViewFilter.java
b/activemq-console/src/main/java/org/apache/activemq/console/filter/PropertiesViewFilter.java
index c2bedd2..7c117a7 100644
--- a/activemq-console/src/main/java/org/apache/activemq/console/filter/PropertiesViewFilter.java
+++ b/activemq-console/src/main/java/org/apache/activemq/console/filter/PropertiesViewFilter.java
@@ -16,13 +16,7 @@
  */
 package org.apache.activemq.console.filter;
 
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
+import java.util.*;
 
 public class PropertiesViewFilter implements QueryFilter {
     protected QueryFilter next;
@@ -102,10 +96,10 @@ public class PropertiesViewFilter implements QueryFilter {
         Map<Object, Object> newData;
         try {
             // Lets try to use the same class as the original
-            newData = data.getClass().newInstance();
+            newData = new LinkedHashMap(data.getClass().newInstance());
         } catch (Exception e) {
             // Lets use a default HashMap
-            newData = new HashMap<Object, Object>();
+            newData = new LinkedHashMap<Object, Object>();
         }
 
         // Filter the keys to view

http://git-wip-us.apache.org/repos/asf/activemq/blob/eece06b3/activemq-console/src/main/java/org/apache/activemq/console/util/JmxMBeansUtil.java
----------------------------------------------------------------------
diff --git a/activemq-console/src/main/java/org/apache/activemq/console/util/JmxMBeansUtil.java
b/activemq-console/src/main/java/org/apache/activemq/console/util/JmxMBeansUtil.java
index 21ceb9b..baa40be 100644
--- a/activemq-console/src/main/java/org/apache/activemq/console/util/JmxMBeansUtil.java
+++ b/activemq-console/src/main/java/org/apache/activemq/console/util/JmxMBeansUtil.java
@@ -16,25 +16,14 @@
  */
 package org.apache.activemq.console.util;
 
-import java.util.Iterator;
-import java.util.List;
-import java.util.Set;
+import org.apache.activemq.console.filter.*;
 
-import javax.management.ObjectName;
+import javax.management.Attribute;
+import javax.management.AttributeList;
 import javax.management.MBeanServerConnection;
-import javax.management.remote.JMXServiceURL;
-
-import org.apache.activemq.console.filter.GroupPropertiesViewFilter;
-import org.apache.activemq.console.filter.MBeansAttributeQueryFilter;
-import org.apache.activemq.console.filter.MBeansObjectNameQueryFilter;
-import org.apache.activemq.console.filter.MBeansRegExQueryFilter;
-import org.apache.activemq.console.filter.MapTransformFilter;
-import org.apache.activemq.console.filter.MessagesQueryFilter;
-import org.apache.activemq.console.filter.PropertiesViewFilter;
-import org.apache.activemq.console.filter.QueryFilter;
-import org.apache.activemq.console.filter.StubQueryFilter;
-import org.apache.activemq.console.filter.WildcardToMsgSelectorTransformFilter;
-import org.apache.activemq.console.filter.WildcardToRegExTransformFilter;
+import javax.management.ObjectName;
+import java.util.*;
+
 
 public final class JmxMBeansUtil {
 
@@ -68,6 +57,20 @@ public final class JmxMBeansUtil {
         }
     }
 
+    public static Map<String, List> queryMBeansAsMap(MBeanServerConnection jmxConnection,
List queryList, Set attributes) throws Exception {
+        Map answer = new HashMap<String, List>();
+        List<AttributeList> mbeans = queryMBeans(jmxConnection, queryList, attributes);
+        for (AttributeList mbean : mbeans) {
+            for(Attribute attr: mbean.asList()) {
+                if (attr.getName().equals("Name")) {
+                    answer.put(attr.getValue(), mbean);
+                }
+            }
+        }
+        return answer;
+    }
+
+
     public static List queryMBeans(MBeanServerConnection jmxConnection, List queryList, Set
attributes) throws Exception {
         // If there is no query defined get all mbeans
         if (queryList == null || queryList.size() == 0) {


Mime
View raw message