https://issues.apache.org/activemq/browse/AMQ-2570 - allow monitoring connections, scheduled messages, etc. for remote brokers

git-svn-id: https://svn.apache.org/repos/asf/activemq/trunk@963970 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Bosanac Dejan 2010-07-14 08:21:53 +00:00
parent 73433372e9
commit 1f355142f4
3 changed files with 39 additions and 12 deletions

View File

@ -23,6 +23,7 @@ import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.Set; import java.util.Set;
import javax.management.ObjectName; import javax.management.ObjectName;
import javax.management.QueryExp;
import javax.management.openmbean.CompositeData; import javax.management.openmbean.CompositeData;
import javax.management.openmbean.TabularData; import javax.management.openmbean.TabularData;
import org.apache.activemq.broker.jmx.BrokerViewMBean; import org.apache.activemq.broker.jmx.BrokerViewMBean;
@ -45,6 +46,8 @@ import org.springframework.util.StringUtils;
*/ */
public abstract class BrokerFacadeSupport implements BrokerFacade { public abstract class BrokerFacadeSupport implements BrokerFacade {
public abstract ManagementContext getManagementContext(); 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<QueueViewMBean> getQueues() throws Exception { public Collection<QueueViewMBean> getQueues() throws Exception {
BrokerViewMBean broker = getBrokerAdmin(); BrokerViewMBean broker = getBrokerAdmin();
@ -94,11 +97,11 @@ public abstract class BrokerFacadeSupport implements BrokerFacade {
} }
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
protected <T> Collection<T> getManagedObjects(ObjectName[] names, Class<T> type) { protected <T> Collection<T> getManagedObjects(ObjectName[] names, Class<T> type) throws Exception {
List<T> answer = new ArrayList<T>(); List<T> answer = new ArrayList<T>();
for (int i = 0; i < names.length; i++) { for (int i = 0; i < names.length; i++) {
ObjectName name = names[i]; ObjectName name = names[i];
T value = (T) getManagementContext().newProxyInstance(name, type, true); T value = (T) newProxyInstance(name, type, true);
if (value != null) { if (value != null) {
answer.add(value); answer.add(value);
} }
@ -110,7 +113,7 @@ public abstract class BrokerFacadeSupport implements BrokerFacade {
public Collection<ConnectionViewMBean> getConnections() throws Exception { public Collection<ConnectionViewMBean> getConnections() throws Exception {
String brokerName = getBrokerName(); String brokerName = getBrokerName();
ObjectName query = new ObjectName("org.apache.activemq:BrokerName=" + brokerName + ",Type=Connection,*"); ObjectName query = new ObjectName("org.apache.activemq:BrokerName=" + brokerName + ",Type=Connection,*");
Set<ObjectName> queryResult = getManagementContext().queryNames(query, null); Set<ObjectName> queryResult = queryNames(query, null);
return getManagedObjects(queryResult.toArray(new ObjectName[queryResult.size()]), ConnectionViewMBean.class); return getManagedObjects(queryResult.toArray(new ObjectName[queryResult.size()]), ConnectionViewMBean.class);
} }
@ -119,7 +122,7 @@ public abstract class BrokerFacadeSupport implements BrokerFacade {
String brokerName = getBrokerName(); String brokerName = getBrokerName();
ObjectName query = new ObjectName("org.apache.activemq:BrokerName=" + brokerName ObjectName query = new ObjectName("org.apache.activemq:BrokerName=" + brokerName
+ ",Type=Connection,ConnectorName=" + connectorName + ",*"); + ",Type=Connection,ConnectorName=" + connectorName + ",*");
Set<ObjectName> queryResult = getManagementContext().queryNames(query, null); Set<ObjectName> queryResult = queryNames(query, null);
Collection<String> result = new ArrayList<String>(queryResult.size()); Collection<String> result = new ArrayList<String>(queryResult.size());
for (ObjectName on : queryResult) { for (ObjectName on : queryResult) {
String name = StringUtils.replace(on.getKeyProperty("Connection"), "_", ":"); String name = StringUtils.replace(on.getKeyProperty("Connection"), "_", ":");
@ -134,11 +137,11 @@ public abstract class BrokerFacadeSupport implements BrokerFacade {
String brokerName = getBrokerName(); String brokerName = getBrokerName();
ObjectName query = new ObjectName("org.apache.activemq:BrokerName=" + brokerName ObjectName query = new ObjectName("org.apache.activemq:BrokerName=" + brokerName
+ ",Type=Connection,*,Connection=" + connectionName); + ",Type=Connection,*,Connection=" + connectionName);
Set<ObjectName> queryResult = getManagementContext().queryNames(query, null); Set<ObjectName> queryResult = queryNames(query, null);
if (queryResult.size() == 0) if (queryResult.size() == 0)
return null; return null;
ObjectName objectName = queryResult.iterator().next(); ObjectName objectName = queryResult.iterator().next();
return (ConnectionViewMBean) getManagementContext().newProxyInstance(objectName, ConnectionViewMBean.class, return (ConnectionViewMBean) newProxyInstance(objectName, ConnectionViewMBean.class,
true); true);
} }
@ -146,7 +149,7 @@ public abstract class BrokerFacadeSupport implements BrokerFacade {
public Collection<String> getConnectors() throws Exception { public Collection<String> getConnectors() throws Exception {
String brokerName = getBrokerName(); String brokerName = getBrokerName();
ObjectName query = new ObjectName("org.apache.activemq:BrokerName=" + brokerName + ",Type=Connector,*"); ObjectName query = new ObjectName("org.apache.activemq:BrokerName=" + brokerName + ",Type=Connector,*");
Set<ObjectName> queryResult = getManagementContext().queryNames(query, null); Set<ObjectName> queryResult = queryNames(query, null);
Collection<String> result = new ArrayList<String>(queryResult.size()); Collection<String> result = new ArrayList<String>(queryResult.size());
for (ObjectName on : queryResult) for (ObjectName on : queryResult)
result.add(on.getKeyProperty("ConnectorName")); result.add(on.getKeyProperty("ConnectorName"));
@ -157,14 +160,14 @@ public abstract class BrokerFacadeSupport implements BrokerFacade {
String brokerName = getBrokerName(); String brokerName = getBrokerName();
ObjectName objectName = new ObjectName("org.apache.activemq:BrokerName=" + brokerName ObjectName objectName = new ObjectName("org.apache.activemq:BrokerName=" + brokerName
+ ",Type=Connector,ConnectorName=" + name); + ",Type=Connector,ConnectorName=" + name);
return (ConnectorViewMBean) getManagementContext().newProxyInstance(objectName, ConnectorViewMBean.class, true); return (ConnectorViewMBean) newProxyInstance(objectName, ConnectorViewMBean.class, true);
} }
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public Collection<NetworkConnectorViewMBean> getNetworkConnectors() throws Exception { public Collection<NetworkConnectorViewMBean> getNetworkConnectors() throws Exception {
String brokerName = getBrokerName(); String brokerName = getBrokerName();
ObjectName query = new ObjectName("org.apache.activemq:BrokerName=" + brokerName + ",Type=NetworkConnector,*"); ObjectName query = new ObjectName("org.apache.activemq:BrokerName=" + brokerName + ",Type=NetworkConnector,*");
Set<ObjectName> queryResult = getManagementContext().queryNames(query, null); Set<ObjectName> queryResult = queryNames(query, null);
return getManagedObjects(queryResult.toArray(new ObjectName[queryResult.size()]), return getManagedObjects(queryResult.toArray(new ObjectName[queryResult.size()]),
NetworkConnectorViewMBean.class); NetworkConnectorViewMBean.class);
} }
@ -175,7 +178,7 @@ public abstract class BrokerFacadeSupport implements BrokerFacade {
queueName = StringUtils.replace(queueName, "\"", "_"); queueName = StringUtils.replace(queueName, "\"", "_");
ObjectName query = new ObjectName("org.apache.activemq:BrokerName=" + brokerName ObjectName query = new ObjectName("org.apache.activemq:BrokerName=" + brokerName
+ ",Type=Subscription,destinationType=Queue,destinationName=" + queueName + ",*"); + ",Type=Subscription,destinationType=Queue,destinationName=" + queueName + ",*");
Set<ObjectName> queryResult = getManagementContext().queryNames(query, null); Set<ObjectName> queryResult = queryNames(query, null);
return getManagedObjects(queryResult.toArray(new ObjectName[queryResult.size()]), SubscriptionViewMBean.class); return getManagedObjects(queryResult.toArray(new ObjectName[queryResult.size()]), SubscriptionViewMBean.class);
} }
@ -185,13 +188,13 @@ public abstract class BrokerFacadeSupport implements BrokerFacade {
String brokerName = getBrokerName(); String brokerName = getBrokerName();
ObjectName query = new ObjectName("org.apache.activemq:BrokerName=" + brokerName ObjectName query = new ObjectName("org.apache.activemq:BrokerName=" + brokerName
+ ",Type=Subscription,clientId=" + connectionName + ",*"); + ",Type=Subscription,clientId=" + connectionName + ",*");
Set<ObjectName> queryResult = getManagementContext().queryNames(query, null); Set<ObjectName> queryResult = queryNames(query, null);
return getManagedObjects(queryResult.toArray(new ObjectName[queryResult.size()]), SubscriptionViewMBean.class); return getManagedObjects(queryResult.toArray(new ObjectName[queryResult.size()]), SubscriptionViewMBean.class);
} }
public JobSchedulerViewMBean getJobScheduler() throws Exception { public JobSchedulerViewMBean getJobScheduler() throws Exception {
ObjectName name = getBrokerAdmin().getJMSJobScheduler(); ObjectName name = getBrokerAdmin().getJMSJobScheduler();
return (JobSchedulerViewMBean) getManagementContext().newProxyInstance(name, JobSchedulerViewMBean.class, true); return (JobSchedulerViewMBean) newProxyInstance(name, JobSchedulerViewMBean.class, true);
} }
public Collection<JobFacade> getScheduledJobs() throws Exception { public Collection<JobFacade> getScheduledJobs() throws Exception {

View File

@ -19,6 +19,9 @@ package org.apache.activemq.web;
import java.util.Iterator; import java.util.Iterator;
import java.util.Set; import java.util.Set;
import javax.management.ObjectName;
import javax.management.QueryExp;
import org.apache.activemq.broker.Broker; import org.apache.activemq.broker.Broker;
import org.apache.activemq.broker.BrokerService; import org.apache.activemq.broker.BrokerService;
import org.apache.activemq.broker.jmx.BrokerView; 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);
}
} }

View File

@ -28,6 +28,7 @@ import javax.management.MBeanServerConnection;
import javax.management.MBeanServerInvocationHandler; import javax.management.MBeanServerInvocationHandler;
import javax.management.MalformedObjectNameException; import javax.management.MalformedObjectNameException;
import javax.management.ObjectName; import javax.management.ObjectName;
import javax.management.QueryExp;
import javax.management.remote.JMXConnector; import javax.management.remote.JMXConnector;
import javax.management.remote.JMXConnectorFactory; import javax.management.remote.JMXConnectorFactory;
import javax.management.remote.JMXServiceURL; import javax.management.remote.JMXServiceURL;
@ -240,4 +241,14 @@ public class RemoteJMXBrokerFacade extends BrokerFacadeSupport {
return answer; 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);
}
} }