1 18 package org.apache.activemq.console.filter; 19 20 import org.apache.activemq.command.ActiveMQTopic; 21 import org.apache.activemq.command.ActiveMQQueue; 22 import org.apache.activemq.ActiveMQConnectionFactory; 23 24 import javax.jms.Destination ; 25 import javax.jms.Connection ; 26 import javax.jms.JMSException ; 27 import javax.jms.Session ; 28 import javax.jms.QueueBrowser ; 29 import java.net.URI ; 30 import java.util.Collections ; 31 import java.util.List ; 32 import java.util.Iterator ; 33 34 public class AmqMessagesQueryFilter extends AbstractQueryFilter { 35 36 private URI brokerUrl; 37 private Destination destination; 38 39 44 public AmqMessagesQueryFilter(URI brokerUrl, Destination destination) { 45 super(null); 46 this.brokerUrl = brokerUrl; 47 this.destination = destination; 48 } 49 50 56 public List query(List queries) throws Exception { 57 String selector = ""; 58 59 for (Iterator i=queries.iterator(); i.hasNext();) { 61 selector = selector + "(" + i.next().toString() + ") AND "; 62 } 63 64 if (selector != "") { 66 selector = selector.substring(0, selector.length() - 5); 67 } 68 69 if (destination instanceof ActiveMQQueue) { 70 return queryMessages((ActiveMQQueue)destination, selector); 71 } else { 72 return queryMessages((ActiveMQTopic)destination, selector); 73 } 74 } 75 76 83 protected List queryMessages(ActiveMQQueue queue, String selector) throws Exception { 84 Connection conn = createConnection(getBrokerUrl()); 85 86 Session sess = conn.createSession(false, Session.AUTO_ACKNOWLEDGE); 87 QueueBrowser browser = sess.createBrowser(queue, selector); 88 89 List messages = Collections.list(browser.getEnumeration()); 90 91 conn.close(); 92 93 return messages; 94 } 95 96 103 protected List queryMessages(ActiveMQTopic topic, String selector) throws Exception { 104 return null; 107 } 108 109 115 protected Connection createConnection(URI brokerUrl) throws JMSException { 116 Connection conn = (new ActiveMQConnectionFactory(brokerUrl)).createConnection(); 117 conn.start(); 118 return conn; 119 } 120 121 125 public URI getBrokerUrl() { 126 return brokerUrl; 127 } 128 129 133 public void setBrokerUrl(URI brokerUrl) { 134 this.brokerUrl = brokerUrl; 135 } 136 137 141 public Destination getDestination() { 142 return destination; 143 } 144 145 149 public void setDestination(Destination destination) { 150 this.destination = destination; 151 } 152 153 } 154 | Popular Tags |