From e78fb963c19eaa78108ad2c54798627bb53eca6d Mon Sep 17 00:00:00 2001 From: Robert Gemmell Date: Sun, 9 Aug 2009 21:06:47 +0000 Subject: QPID-2015: Add 2 new methods to the VirtualHostManager to retrieve attribute names/values for every Queue in the vhost in a single call. Remove previous viewQueueNamesDepths() method. Add new ManagedQueue attribute names constants, and a test to ensure any attributes added to the Queue MBeans in future are also added to the constants. git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk@802601 13f79535-47bb-0310-9956-ffa450edef68 --- .../apache/qpid/server/AMQBrokerManagerMBean.java | 67 ++++++++++++++++++---- .../org/apache/qpid/server/queue/AMQQueue.java | 3 + 2 files changed, 58 insertions(+), 12 deletions(-) (limited to 'qpid/java/broker/src') diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/AMQBrokerManagerMBean.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/AMQBrokerManagerMBean.java index 306dce1057..14f64d2879 100644 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/AMQBrokerManagerMBean.java +++ b/qpid/java/broker/src/main/java/org/apache/qpid/server/AMQBrokerManagerMBean.java @@ -39,8 +39,8 @@ package org.apache.qpid.server; import java.io.IOException; import java.util.ArrayList; -import java.util.HashMap; -import java.util.Map; +import java.util.Collections; +import java.util.List; import javax.management.JMException; import javax.management.MBeanException; @@ -50,6 +50,7 @@ import javax.management.ObjectName; import org.apache.qpid.AMQException; import org.apache.qpid.framing.AMQShortString; import org.apache.qpid.management.common.mbeans.ManagedBroker; +import org.apache.qpid.management.common.mbeans.ManagedQueue; import org.apache.qpid.management.common.mbeans.annotations.MBeanConstructor; import org.apache.qpid.management.common.mbeans.annotations.MBeanDescription; import org.apache.qpid.server.exchange.Exchange; @@ -60,6 +61,7 @@ import org.apache.qpid.server.management.AMQManagedObject; import org.apache.qpid.server.management.ManagedObject; import org.apache.qpid.server.queue.AMQQueue; import org.apache.qpid.server.queue.AMQQueueFactory; +import org.apache.qpid.server.queue.AMQQueueMBean; import org.apache.qpid.server.queue.QueueRegistry; import org.apache.qpid.server.store.MessageStore; import org.apache.qpid.server.virtualhost.VirtualHost; @@ -114,26 +116,67 @@ public class AMQBrokerManagerMBean extends AMQManagedObject implements ManagedBr } /** - * Returns a Map keyed by QueueName, detailing its associated QueueDepth in bytes. + * Returns a list containing the names of the attributes available for the Queue mbeans. * @since Qpid JMX API 1.3 * @throws IOException */ - public Map viewQueueNamesDepths() throws IOException + public List retrieveQueueAttributeNames() throws IOException { - Map queueDepthMap = new HashMap(_queueRegistry.getQueues().size()); + List attributeList = new ArrayList(); + for(String attr : ManagedQueue.QUEUE_ATTRIBUTES) + { + attributeList.add(attr); + } - String queueName; - Long queueDepth; + Collections.sort(attributeList); + return attributeList; + } + + /** + * Returns a List of Object Lists containing the requested attribute values (in the same sequence requested) for each queue in the virtualhost. + * If a particular attribute cant be found or raises an mbean/reflection exception whilst being gathered its value is substituted with the String "-". + * @since Qpid JMX API 1.3 + * @throws IOException + */ + public List> retrieveQueueAttributeValues(String[] attributes) throws IOException + { + if(_queueRegistry.getQueues().size() == 0) + { + return new ArrayList>(); + } + + List> queueAttributesList = new ArrayList>(_queueRegistry.getQueues().size()); + + int attributesLength = attributes.length; + for(AMQQueue queue : _queueRegistry.getQueues()) { - queueName = queue.getName().toString(); - queueDepth = queue.getQueueDepth(); + AMQQueueMBean mbean = (AMQQueueMBean) queue.getManagedObject(); - queueDepthMap.put(queueName,queueDepth); + if(mbean == null) + { + continue; + } + + List attributeValues = new ArrayList(attributesLength); + + for(int i=0; i < attributesLength; i++) + { + try + { + attributeValues.add(mbean.getAttribute(attributes[i])); + } + catch (Exception e) + { + attributeValues.add(new String("-")); + } + } + + queueAttributesList.add(attributeValues); } - - return queueDepthMap; + + return queueAttributesList; } /** diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/queue/AMQQueue.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/queue/AMQQueue.java index 4643326df3..2a692344d0 100644 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/queue/AMQQueue.java +++ b/qpid/java/broker/src/main/java/org/apache/qpid/server/queue/AMQQueue.java @@ -23,6 +23,7 @@ package org.apache.qpid.server.queue; import org.apache.commons.configuration.CompositeConfiguration; import org.apache.commons.configuration.Configuration; import org.apache.qpid.server.management.Managable; +import org.apache.qpid.server.management.ManagedObject; import org.apache.qpid.server.store.StoreContext; import org.apache.qpid.server.configuration.QueueConfiguration; import org.apache.qpid.server.exchange.Exchange; @@ -228,4 +229,6 @@ public interface AMQQueue extends Managable, Comparable } void configure(QueueConfiguration config); + + ManagedObject getManagedObject(); } -- cgit v1.2.1