1 18 package org.apache.activemq.web; 19 20 import org.apache.activemq.broker.jmx.BrokerViewMBean; 21 import org.apache.activemq.broker.jmx.DurableSubscriptionViewMBean; 22 import org.apache.activemq.broker.jmx.ManagementContext; 23 import org.apache.activemq.broker.jmx.TopicViewMBean; 24 import org.apache.activemq.broker.jmx.QueueViewMBean; 25 import org.apache.activemq.broker.jmx.DestinationViewMBean; 26 27 import javax.management.MBeanServer ; 28 import javax.management.MBeanServerInvocationHandler ; 29 import javax.management.ObjectName ; 30 import java.util.ArrayList ; 31 import java.util.Collection ; 32 import java.util.Collections ; 33 import java.util.List ; 34 import java.util.Iterator ; 35 36 41 public abstract class BrokerFacadeSupport implements BrokerFacade { 42 public abstract ManagementContext getManagementContext(); 43 44 public Collection getQueues() throws Exception { 45 BrokerViewMBean broker = getBrokerAdmin(); 46 if (broker == null) { 47 return Collections.EMPTY_LIST; 48 } 49 ObjectName [] queues = broker.getQueues(); 50 return getManagedObjects(queues, QueueViewMBean.class); 51 } 52 53 public Collection getTopics() throws Exception { 54 BrokerViewMBean broker = getBrokerAdmin(); 55 if (broker == null) { 56 return Collections.EMPTY_LIST; 57 } 58 ObjectName [] queues = broker.getTopics(); 59 return getManagedObjects(queues, TopicViewMBean.class); 60 } 61 62 public Collection getDurableTopicSubscribers() throws Exception { 63 BrokerViewMBean broker = getBrokerAdmin(); 64 if (broker == null) { 65 return Collections.EMPTY_LIST; 66 } 67 ObjectName [] queues = broker.getDurableTopicSubscribers(); 68 return getManagedObjects(queues, DurableSubscriptionViewMBean.class); 69 } 70 71 public QueueViewMBean getQueue(String name) throws Exception { 72 return (QueueViewMBean) getDestinationByName(getQueues(), name); 73 } 74 75 public TopicViewMBean getTopic(String name) throws Exception { 76 return (TopicViewMBean) getDestinationByName(getTopics(), name); 77 } 78 79 protected DestinationViewMBean getDestinationByName(Collection collection, String name) { 80 Iterator iter = collection.iterator(); 81 while (iter.hasNext()) { 82 DestinationViewMBean destinationViewMBean = (DestinationViewMBean) iter.next(); 83 if (name.equals(destinationViewMBean.getName())) { 84 return destinationViewMBean; 85 } 86 } 87 return null; 88 } 89 90 protected Collection getManagedObjects(ObjectName [] names, Class type) { 91 List answer = new ArrayList (); 92 MBeanServer mbeanServer = getManagementContext().getMBeanServer(); 93 if (mbeanServer != null) { 94 for (int i = 0; i < names.length; i++) { 95 ObjectName name = names[i]; 96 Object value = MBeanServerInvocationHandler.newProxyInstance(mbeanServer, name, type, true); 97 if (value != null) { 98 answer.add(value); 99 } 100 } 101 } 102 return answer; 103 } 104 } 105 | Popular Tags |