diff --git a/activemq-web/src/main/java/org/apache/activemq/web/BrokerFacadeSupport.java b/activemq-web/src/main/java/org/apache/activemq/web/BrokerFacadeSupport.java index 1287a69b71..bd791f0779 100644 --- a/activemq-web/src/main/java/org/apache/activemq/web/BrokerFacadeSupport.java +++ b/activemq-web/src/main/java/org/apache/activemq/web/BrokerFacadeSupport.java @@ -23,6 +23,7 @@ import java.util.Iterator; import java.util.List; import java.util.Set; import javax.management.ObjectName; +import javax.management.QueryExp; import javax.management.openmbean.CompositeData; import javax.management.openmbean.TabularData; import org.apache.activemq.broker.jmx.BrokerViewMBean; @@ -45,6 +46,8 @@ import org.springframework.util.StringUtils; */ public abstract class BrokerFacadeSupport implements BrokerFacade { public abstract ManagementContext getManagementContext(); + public abstract Set queryNames(ObjectName name, QueryExp query) throws Exception; + public abstract Object newProxyInstance( ObjectName objectName, Class interfaceClass, boolean notificationBroadcaster) throws Exception; public Collection getQueues() throws Exception { BrokerViewMBean broker = getBrokerAdmin(); @@ -94,11 +97,11 @@ public abstract class BrokerFacadeSupport implements BrokerFacade { } @SuppressWarnings("unchecked") - protected Collection getManagedObjects(ObjectName[] names, Class type) { + protected Collection getManagedObjects(ObjectName[] names, Class type) throws Exception { List answer = new ArrayList(); for (int i = 0; i < names.length; i++) { ObjectName name = names[i]; - T value = (T) getManagementContext().newProxyInstance(name, type, true); + T value = (T) newProxyInstance(name, type, true); if (value != null) { answer.add(value); } @@ -110,7 +113,7 @@ public abstract class BrokerFacadeSupport implements BrokerFacade { public Collection getConnections() throws Exception { String brokerName = getBrokerName(); ObjectName query = new ObjectName("org.apache.activemq:BrokerName=" + brokerName + ",Type=Connection,*"); - Set queryResult = getManagementContext().queryNames(query, null); + Set queryResult = queryNames(query, null); return getManagedObjects(queryResult.toArray(new ObjectName[queryResult.size()]), ConnectionViewMBean.class); } @@ -119,7 +122,7 @@ public abstract class BrokerFacadeSupport implements BrokerFacade { String brokerName = getBrokerName(); ObjectName query = new ObjectName("org.apache.activemq:BrokerName=" + brokerName + ",Type=Connection,ConnectorName=" + connectorName + ",*"); - Set queryResult = getManagementContext().queryNames(query, null); + Set queryResult = queryNames(query, null); Collection result = new ArrayList(queryResult.size()); for (ObjectName on : queryResult) { String name = StringUtils.replace(on.getKeyProperty("Connection"), "_", ":"); @@ -134,11 +137,11 @@ public abstract class BrokerFacadeSupport implements BrokerFacade { String brokerName = getBrokerName(); ObjectName query = new ObjectName("org.apache.activemq:BrokerName=" + brokerName + ",Type=Connection,*,Connection=" + connectionName); - Set queryResult = getManagementContext().queryNames(query, null); + Set queryResult = queryNames(query, null); if (queryResult.size() == 0) return null; ObjectName objectName = queryResult.iterator().next(); - return (ConnectionViewMBean) getManagementContext().newProxyInstance(objectName, ConnectionViewMBean.class, + return (ConnectionViewMBean) newProxyInstance(objectName, ConnectionViewMBean.class, true); } @@ -146,7 +149,7 @@ public abstract class BrokerFacadeSupport implements BrokerFacade { public Collection getConnectors() throws Exception { String brokerName = getBrokerName(); ObjectName query = new ObjectName("org.apache.activemq:BrokerName=" + brokerName + ",Type=Connector,*"); - Set queryResult = getManagementContext().queryNames(query, null); + Set queryResult = queryNames(query, null); Collection result = new ArrayList(queryResult.size()); for (ObjectName on : queryResult) result.add(on.getKeyProperty("ConnectorName")); @@ -157,14 +160,14 @@ public abstract class BrokerFacadeSupport implements BrokerFacade { String brokerName = getBrokerName(); ObjectName objectName = new ObjectName("org.apache.activemq:BrokerName=" + brokerName + ",Type=Connector,ConnectorName=" + name); - return (ConnectorViewMBean) getManagementContext().newProxyInstance(objectName, ConnectorViewMBean.class, true); + return (ConnectorViewMBean) newProxyInstance(objectName, ConnectorViewMBean.class, true); } @SuppressWarnings("unchecked") public Collection getNetworkConnectors() throws Exception { String brokerName = getBrokerName(); ObjectName query = new ObjectName("org.apache.activemq:BrokerName=" + brokerName + ",Type=NetworkConnector,*"); - Set queryResult = getManagementContext().queryNames(query, null); + Set queryResult = queryNames(query, null); return getManagedObjects(queryResult.toArray(new ObjectName[queryResult.size()]), NetworkConnectorViewMBean.class); } @@ -175,7 +178,7 @@ public abstract class BrokerFacadeSupport implements BrokerFacade { queueName = StringUtils.replace(queueName, "\"", "_"); ObjectName query = new ObjectName("org.apache.activemq:BrokerName=" + brokerName + ",Type=Subscription,destinationType=Queue,destinationName=" + queueName + ",*"); - Set queryResult = getManagementContext().queryNames(query, null); + Set queryResult = queryNames(query, null); return getManagedObjects(queryResult.toArray(new ObjectName[queryResult.size()]), SubscriptionViewMBean.class); } @@ -185,13 +188,13 @@ public abstract class BrokerFacadeSupport implements BrokerFacade { String brokerName = getBrokerName(); ObjectName query = new ObjectName("org.apache.activemq:BrokerName=" + brokerName + ",Type=Subscription,clientId=" + connectionName + ",*"); - Set queryResult = getManagementContext().queryNames(query, null); + Set queryResult = queryNames(query, null); return getManagedObjects(queryResult.toArray(new ObjectName[queryResult.size()]), SubscriptionViewMBean.class); } public JobSchedulerViewMBean getJobScheduler() throws Exception { ObjectName name = getBrokerAdmin().getJMSJobScheduler(); - return (JobSchedulerViewMBean) getManagementContext().newProxyInstance(name, JobSchedulerViewMBean.class, true); + return (JobSchedulerViewMBean) newProxyInstance(name, JobSchedulerViewMBean.class, true); } public Collection getScheduledJobs() throws Exception { diff --git a/activemq-web/src/main/java/org/apache/activemq/web/LocalBrokerFacade.java b/activemq-web/src/main/java/org/apache/activemq/web/LocalBrokerFacade.java index 4f8a1c3e1f..4461c675ba 100644 --- a/activemq-web/src/main/java/org/apache/activemq/web/LocalBrokerFacade.java +++ b/activemq-web/src/main/java/org/apache/activemq/web/LocalBrokerFacade.java @@ -19,6 +19,9 @@ package org.apache.activemq.web; import java.util.Iterator; import java.util.Set; +import javax.management.ObjectName; +import javax.management.QueryExp; + import org.apache.activemq.broker.Broker; import org.apache.activemq.broker.BrokerService; import org.apache.activemq.broker.jmx.BrokerView; @@ -74,5 +77,15 @@ public class LocalBrokerFacade extends BrokerFacadeSupport { } } } + + @Override + public Set queryNames(ObjectName name, QueryExp query) throws Exception { + return getManagementContext().queryNames(name, query); + } + + @Override + public Object newProxyInstance(ObjectName objectName, Class interfaceClass, boolean notificationBroadcaster) { + return getManagementContext().newProxyInstance(objectName, interfaceClass, notificationBroadcaster); + } } diff --git a/activemq-web/src/main/java/org/apache/activemq/web/RemoteJMXBrokerFacade.java b/activemq-web/src/main/java/org/apache/activemq/web/RemoteJMXBrokerFacade.java index 09d8c2c051..733a0b3120 100644 --- a/activemq-web/src/main/java/org/apache/activemq/web/RemoteJMXBrokerFacade.java +++ b/activemq-web/src/main/java/org/apache/activemq/web/RemoteJMXBrokerFacade.java @@ -28,6 +28,7 @@ import javax.management.MBeanServerConnection; import javax.management.MBeanServerInvocationHandler; import javax.management.MalformedObjectNameException; import javax.management.ObjectName; +import javax.management.QueryExp; import javax.management.remote.JMXConnector; import javax.management.remote.JMXConnectorFactory; import javax.management.remote.JMXServiceURL; @@ -240,4 +241,14 @@ public class RemoteJMXBrokerFacade extends BrokerFacadeSupport { return answer; } + @Override + public Set queryNames(ObjectName name, QueryExp query) throws Exception { + return getMBeanServerConnection().queryNames(name, query); + } + + @Override + public Object newProxyInstance(ObjectName objectName, Class interfaceClass,boolean notificationBroadcaster) throws Exception { + return MBeanServerInvocationHandler.newProxyInstance(getMBeanServerConnection(), objectName, interfaceClass, notificationBroadcaster); + } + }