1 18 package org.apache.activemq.console.filter; 19 20 import javax.management.remote.JMXConnector ; 21 import javax.management.remote.JMXServiceURL ; 22 import javax.management.remote.JMXConnectorFactory ; 23 import javax.management.MBeanServerConnection ; 24 import javax.management.ObjectName ; 25 import javax.management.openmbean.CompositeData ; 26 import java.net.MalformedURLException ; 27 import java.util.List ; 28 import java.util.Iterator ; 29 import java.util.Arrays ; 30 import java.io.IOException ; 31 32 public class MessagesQueryFilter extends AbstractQueryFilter { 33 34 private JMXServiceURL jmxServiceUrl; 35 private ObjectName destName; 36 37 42 public MessagesQueryFilter(JMXServiceURL jmxServiceUrl, ObjectName destName) { 43 super(null); 44 this.jmxServiceUrl = jmxServiceUrl; 45 this.destName = destName; 46 } 47 48 54 public List query(List queries) throws Exception { 55 String selector = ""; 56 57 for (Iterator i=queries.iterator(); i.hasNext();) { 59 selector = selector + "(" + i.next().toString() + ") AND "; 60 } 61 62 if (selector != "") { 64 selector = selector.substring(0, selector.length() - 5); 65 } 66 67 return queryMessages(selector); 68 } 69 70 76 protected List queryMessages(String selector) throws Exception { 77 JMXConnector connector = createJmxConnector(); 78 MBeanServerConnection server = connector.getMBeanServerConnection(); 79 CompositeData [] messages = (CompositeData [])server.invoke(destName, "browse", new Object [] {}, new String [] {}); 80 connector.close(); 81 82 return Arrays.asList(messages); 83 } 84 85 89 public JMXServiceURL getJmxServiceUrl() { 90 return jmxServiceUrl; 91 } 92 93 97 public void setJmxServiceUrl(JMXServiceURL jmxServiceUrl) { 98 this.jmxServiceUrl = jmxServiceUrl; 99 } 100 101 105 public void setJmxServiceUrl(String jmxServiceUrl) throws MalformedURLException { 106 setJmxServiceUrl(new JMXServiceURL (jmxServiceUrl)); 107 } 108 109 114 protected JMXConnector createJmxConnector() throws IOException { 115 return JMXConnectorFactory.connect(getJmxServiceUrl()); 116 } 117 } 118 | Popular Tags |