1 18 package org.apache.activemq.console.filter; 19 20 import javax.management.remote.JMXServiceURL ; 21 import javax.management.remote.JMXConnector ; 22 import javax.management.remote.JMXConnectorFactory ; 23 import javax.management.ObjectName ; 24 import javax.management.MalformedObjectNameException ; 25 import javax.management.MBeanServerConnection ; 26 import javax.management.QueryExp ; 27 import java.util.Iterator ; 28 import java.util.List ; 29 import java.util.ArrayList ; 30 import java.net.MalformedURLException ; 31 import java.io.IOException ; 32 33 public class MBeansObjectNameQueryFilter extends AbstractQueryFilter { 34 35 public static final String DEFAULT_JMX_DOMAIN = "org.apache.activemq"; 36 public static final String QUERY_EXP_PREFIX = "MBeans.QueryExp."; 37 38 private JMXServiceURL jmxServiceUrl; 39 40 45 public MBeansObjectNameQueryFilter(String jmxUrl) throws MalformedURLException { 46 this(new JMXServiceURL (jmxUrl)); 47 } 48 49 53 public MBeansObjectNameQueryFilter(JMXServiceURL jmxUrl) { 54 super(null); 55 this.jmxServiceUrl = jmxUrl; 56 } 57 58 65 public List query(List queries) throws MalformedObjectNameException , IOException { 66 67 if (queries == null || queries.isEmpty()) { 69 return queryMBeans(new ObjectName (DEFAULT_JMX_DOMAIN + ":*"), null); 70 } 71 72 String objNameQuery = ""; 74 String queryExp = ""; 75 for (Iterator i=queries.iterator(); i.hasNext();) { 76 String key = (String )i.next(); 77 String val = ""; 78 int pos = key.indexOf("="); 79 if (pos >= 0) { 80 val = key.substring(pos + 1); 81 key = key.substring(0, pos); 82 } 83 84 if (val.startsWith(QUERY_EXP_PREFIX)) { 85 } else if (key != "" && val != "") { 87 objNameQuery = objNameQuery + key + "=" + val + ","; 88 } 89 } 90 91 objNameQuery = objNameQuery + "*"; 93 94 return queryMBeans(new ObjectName (DEFAULT_JMX_DOMAIN + ":" + objNameQuery), queryExp); 95 } 96 97 105 protected List queryMBeans(ObjectName objName, String queryExpStr) throws IOException { 106 JMXConnector jmxConn = createJmxConnector(); 107 MBeanServerConnection server = jmxConn.getMBeanServerConnection(); 108 109 QueryExp queryExp = createQueryExp(queryExpStr); 110 111 List mbeans = new ArrayList (server.queryMBeans(objName, queryExp)); 113 114 jmxConn.close(); 115 116 return mbeans; 117 } 118 119 123 public JMXServiceURL getJmxServiceUrl() { 124 return jmxServiceUrl; 125 } 126 127 131 public void setJmxServiceUrl(JMXServiceURL jmxServiceUrl) { 132 this.jmxServiceUrl = jmxServiceUrl; 133 } 134 135 139 public void setJmxServiceUrl(String jmxServiceUrl) throws MalformedURLException { 140 setJmxServiceUrl(new JMXServiceURL (jmxServiceUrl)); 141 } 142 143 148 protected JMXConnector createJmxConnector() throws IOException { 149 return JMXConnectorFactory.connect(getJmxServiceUrl()); 150 } 151 152 158 protected QueryExp createQueryExp(String queryExpStr) { 159 return null; 161 } 162 } 163 | Popular Tags |