1 18 package org.apache.activemq.console.util; 19 20 import org.apache.activemq.console.filter.*; 21 22 import javax.management.remote.JMXServiceURL ; 23 import javax.management.ObjectName ; 24 import java.util.Set ; 25 import java.util.List ; 26 import java.util.Iterator ; 27 28 public class JmxMBeansUtil { 29 30 public static List getAllBrokers(JMXServiceURL jmxUrl) throws Exception { 31 return (new MBeansObjectNameQueryFilter(jmxUrl)).query("Type=Broker"); 32 } 33 34 public static List getBrokersByName(JMXServiceURL jmxUrl, String brokerName) throws Exception { 35 return (new MBeansObjectNameQueryFilter(jmxUrl)).query("Type=Broker,BrokerName=" + brokerName); 36 } 37 38 public static List getAllBrokers(JMXServiceURL jmxUrl, Set attributes) throws Exception { 39 return (new MBeansAttributeQueryFilter(jmxUrl, attributes, new MBeansObjectNameQueryFilter(jmxUrl))).query("Type=Broker"); 40 } 41 42 public static List getBrokersByName(JMXServiceURL jmxUrl, String brokerName, Set attributes) throws Exception { 43 return (new MBeansAttributeQueryFilter(jmxUrl, attributes, new MBeansObjectNameQueryFilter(jmxUrl))).query("Type=Broker,BrokerName=" + brokerName); 44 } 45 46 public static List queryMBeans(JMXServiceURL jmxUrl, List queryList) throws Exception { 47 if (queryList==null || queryList.size()==0) { 49 return createMBeansObjectNameQuery(jmxUrl).query(""); 50 51 } else { 53 return createMBeansObjectNameQuery(jmxUrl).query(queryList); 54 } 55 } 56 57 public static List queryMBeans(JMXServiceURL jmxUrl, List queryList, Set attributes) throws Exception { 58 if (queryList==null || queryList.size()==0) { 60 return createMBeansAttributeQuery(jmxUrl, attributes).query(""); 61 62 } else { 64 return createMBeansAttributeQuery(jmxUrl, attributes).query(queryList); 65 } 66 } 67 68 public static List queryMBeans(JMXServiceURL jmxUrl, String queryString) throws Exception { 69 return createMBeansObjectNameQuery(jmxUrl).query(queryString); 70 } 71 72 public static List queryMBeans(JMXServiceURL jmxUrl, String queryString, Set attributes) throws Exception { 73 return createMBeansAttributeQuery(jmxUrl, attributes).query(queryString); 74 } 75 76 public static List filterMBeansView(List mbeans, Set viewFilter) throws Exception { 77 return (new PropertiesViewFilter(viewFilter, new MapTransformFilter(new StubQueryFilter(mbeans))).query("")); 78 } 79 80 public static String createQueryString(String query, String param) { 81 return query.replaceAll("%1", param); 82 } 83 84 public static String createQueryString(String query, List params) { 85 86 int count = 1; 87 for (Iterator i=params.iterator();i.hasNext();) { 88 query.replaceAll("%" + count++, i.next().toString()); 89 } 90 91 return query; 92 } 93 94 public static QueryFilter createMBeansObjectNameQuery(JMXServiceURL jmxUrl) { 95 return new WildcardToRegExTransformFilter( new MBeansRegExQueryFilter( new MBeansObjectNameQueryFilter(jmxUrl) ) 99 ); 100 } 101 102 public static QueryFilter createMBeansAttributeQuery(JMXServiceURL jmxUrl, Set attributes) { 103 return new WildcardToRegExTransformFilter( new MBeansRegExQueryFilter( new MBeansAttributeQueryFilter(jmxUrl, attributes, new MBeansObjectNameQueryFilter(jmxUrl) ) 108 ) 109 ); 110 } 111 112 public static QueryFilter createMessageQueryFilter(JMXServiceURL jmxUrl, ObjectName destName) { 113 return new WildcardToMsgSelectorTransformFilter( 114 new MessagesQueryFilter(jmxUrl, destName) 115 ); 116 } 117 118 public static List filterMessagesView(List messages, Set groupViews, Set attributeViews) throws Exception { 119 return (new PropertiesViewFilter(attributeViews, 120 new GroupPropertiesViewFilter(groupViews, 121 new MapTransformFilter( 122 new StubQueryFilter(messages) 123 ) 124 ) 125 )).query(""); 126 } 127 } 128 | Popular Tags |