}
}
@Override
public DestinationStatistics getDestinationStatistics(PortletRequest portletRequest, JMSDestinationInfo destinationInfo) throws JMSException {
DestinationStatistics stat = new DestinationStatistics();
try {
BrokerInfo brokerInfo = getBrokerInfo(portletRequest, destinationInfo);
if (brokerInfo == null || !isInLocalMBeanServer(brokerInfo)) {
return stat;
}
MBeanServer server = getMBeanServer();
ObjectName objName = createDestinationObjectName(brokerInfo.getBrokerName(), destinationInfo.getType().name(), destinationInfo.getPhysicalName());
DestinationViewMBean proxy;
if (destinationInfo.getType().equals(DestinationType.Queue)) {
if (!server.isRegistered(objName)) {
// mbean is not yet registered.Adding the destination to activemq broker.
ObjectName brokerObj = createBrokerObjectName(brokerInfo.getBrokerName());
Set set = server.queryMBeans(brokerObj, null);
Iterator it = set.iterator();
if (it.hasNext()) {
ObjectInstance instance = (ObjectInstance) it.next();
brokerObj = instance.getObjectName();
}
BrokerViewMBean brokerMBean = (BrokerViewMBean) MBeanServerInvocationHandler.newProxyInstance(server, brokerObj, BrokerViewMBean.class, true);
brokerMBean.addQueue(destinationInfo.getPhysicalName());
}
proxy = (DestinationViewMBean) MBeanServerInvocationHandler.newProxyInstance(server, objName, QueueViewMBean.class, true);
} else {
if (!server.isRegistered(objName)) {
// mbean is not yet registered.Adding the destination to activemq broker.
ObjectName brokerObj = createBrokerObjectName(brokerInfo.getBrokerName());
Set set = server.queryMBeans(brokerObj, null);
Iterator it = set.iterator();
if (it.hasNext()) {
ObjectInstance instance = (ObjectInstance) it.next();
brokerObj = instance.getObjectName();
}
BrokerViewMBean brokerMBean = (BrokerViewMBean) MBeanServerInvocationHandler.newProxyInstance(server, brokerObj, BrokerViewMBean.class, true);
brokerMBean.addTopic(destinationInfo.getPhysicalName());
}
proxy = (DestinationViewMBean) MBeanServerInvocationHandler.newProxyInstance(server, objName, TopicViewMBean.class, true);
}
stat.setConsumerCount(proxy.getConsumerCount());
stat.setEnqueueCount(proxy.getEnqueueCount());
stat.setDequeueCount(proxy.getDequeueCount());
stat.setQueueSize(proxy.getQueueSize());
} catch (Exception ex) {
logger.warn("Failed to get ActiveMQ stats", ex);
}
return stat;
}