qpid-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rob...@apache.org
Subject svn commit: r802601 - in /qpid/trunk/qpid/java: broker/src/main/java/org/apache/qpid/server/ broker/src/main/java/org/apache/qpid/server/queue/ management/common/src/main/java/org/apache/qpid/management/common/mbeans/ management/common/src/test/ manage...
Date Sun, 09 Aug 2009 21:06:48 GMT
Author: robbie
Date: Sun Aug  9 21:06:47 2009
New Revision: 802601

URL: http://svn.apache.org/viewvc?rev=802601&view=rev
Log:
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.

Added:
    qpid/trunk/qpid/java/management/common/src/test/
    qpid/trunk/qpid/java/management/common/src/test/java/
    qpid/trunk/qpid/java/management/common/src/test/java/org/
    qpid/trunk/qpid/java/management/common/src/test/java/org/apache/
    qpid/trunk/qpid/java/management/common/src/test/java/org/apache/qpid/
    qpid/trunk/qpid/java/management/common/src/test/java/org/apache/qpid/management/
    qpid/trunk/qpid/java/management/common/src/test/java/org/apache/qpid/management/common/
    qpid/trunk/qpid/java/management/common/src/test/java/org/apache/qpid/management/common/mbeans/
    qpid/trunk/qpid/java/management/common/src/test/java/org/apache/qpid/management/common/mbeans/ManagedQueueTest.java
Modified:
    qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/AMQBrokerManagerMBean.java
    qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/queue/AMQQueue.java
    qpid/trunk/qpid/java/management/common/src/main/java/org/apache/qpid/management/common/mbeans/ManagedBroker.java
    qpid/trunk/qpid/java/management/common/src/main/java/org/apache/qpid/management/common/mbeans/ManagedQueue.java

Modified: qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/AMQBrokerManagerMBean.java
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/AMQBrokerManagerMBean.java?rev=802601&r1=802600&r2=802601&view=diff
==============================================================================
--- qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/AMQBrokerManagerMBean.java
(original)
+++ qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/AMQBrokerManagerMBean.java
Sun Aug  9 21:06:47 2009
@@ -39,8 +39,8 @@
 
 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 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.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 @@
     }
     
     /**
-     * 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<String,Long> viewQueueNamesDepths() throws IOException
+    public List<String> retrieveQueueAttributeNames() throws IOException
     {
-        Map<String,Long> queueDepthMap = new HashMap<String,Long>(_queueRegistry.getQueues().size());
+        List<String> attributeList = new ArrayList<String>();
+        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<List<Object>> retrieveQueueAttributeValues(String[] attributes)
throws IOException
+    {
+        if(_queueRegistry.getQueues().size() == 0)
+        {
+            return new ArrayList<List<Object>>();
+        }
+        
+        List<List<Object>> queueAttributesList = new ArrayList<List<Object>>(_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<Object> attributeValues = new ArrayList<Object>(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;
     }
     
     /**

Modified: qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/queue/AMQQueue.java
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/queue/AMQQueue.java?rev=802601&r1=802600&r2=802601&view=diff
==============================================================================
--- qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/queue/AMQQueue.java (original)
+++ qpid/trunk/qpid/java/broker/src/main/java/org/apache/qpid/server/queue/AMQQueue.java Sun
Aug  9 21:06:47 2009
@@ -23,6 +23,7 @@
 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 @@
     }
 
     void configure(QueueConfiguration config);
+    
+    ManagedObject getManagedObject();
 }

Modified: qpid/trunk/qpid/java/management/common/src/main/java/org/apache/qpid/management/common/mbeans/ManagedBroker.java
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/management/common/src/main/java/org/apache/qpid/management/common/mbeans/ManagedBroker.java?rev=802601&r1=802600&r2=802601&view=diff
==============================================================================
--- qpid/trunk/qpid/java/management/common/src/main/java/org/apache/qpid/management/common/mbeans/ManagedBroker.java
(original)
+++ qpid/trunk/qpid/java/management/common/src/main/java/org/apache/qpid/management/common/mbeans/ManagedBroker.java
Sun Aug  9 21:06:47 2009
@@ -22,12 +22,10 @@
 package org.apache.qpid.management.common.mbeans;
 
 import java.io.IOException;
-import java.util.Map;
+import java.util.List;
 
 import javax.management.JMException;
 import javax.management.MBeanOperationInfo;
-import javax.management.openmbean.OpenDataException;
-import javax.management.openmbean.TabularData;
 
 import org.apache.qpid.management.common.mbeans.annotations.MBeanAttribute;
 import org.apache.qpid.management.common.mbeans.annotations.MBeanOperation;
@@ -55,13 +53,23 @@
     String[] getExchangeTypes() throws IOException;
     
     /**
-     * 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
      */
-    @MBeanOperation(name = "viewQueueNamesDepths", description = "View the queue names and
depths in this virtualhost", 
-                    impact = MBeanOperationInfo.INFO)
-    Map<String,Long> viewQueueNamesDepths() throws IOException;
+    @MBeanOperation(name = "retrieveQueueAttributeNames", description = "Retrieve the attribute
names for queues in this virtualhost", 
+            impact = MBeanOperationInfo.INFO)
+    List<String> retrieveQueueAttributeNames() throws IOException;
+    
+    /**
+     * 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
+     */
+    @MBeanOperation(name = "retrieveQueueAttributeValues", description = "Retrieve the indicated
attributes for queues in this virtualhost", 
+            impact = MBeanOperationInfo.INFO)
+    List<List<Object>> retrieveQueueAttributeValues(@MBeanOperationParameter(name="attributes",
description="Attributes to retrieve") String[] attributes) throws IOException;
     
     /**
      * Creates a new Exchange.

Modified: qpid/trunk/qpid/java/management/common/src/main/java/org/apache/qpid/management/common/mbeans/ManagedQueue.java
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/management/common/src/main/java/org/apache/qpid/management/common/mbeans/ManagedQueue.java?rev=802601&r1=802600&r2=802601&view=diff
==============================================================================
--- qpid/trunk/qpid/java/management/common/src/main/java/org/apache/qpid/management/common/mbeans/ManagedQueue.java
(original)
+++ qpid/trunk/qpid/java/management/common/src/main/java/org/apache/qpid/management/common/mbeans/ManagedQueue.java
Sun Aug  9 21:06:47 2009
@@ -54,6 +54,37 @@
     String[] VIEW_MSG_CONTENT_COMPOSITE_ITEM_NAMES = { "AMQ MessageId", "MimeType", "Encoding",
"Content" };
     String[] VIEW_MSG_CONTENT_COMPOSITE_ITEM_DESCRIPTIONS = { "AMQ MessageId", "MimeType",
"Encoding", "Content" };
     
+    //Individual attribute name constants
+    String ATTR_NAME = "Name";
+    String ATTR_OWNER = "Owner";
+    String ATTR_MAX_MSG_AGE = "MaximumMessageAge";
+    String ATTR_MAX_MSG_COUNT = "MaximumMessageCount";
+    String ATTR_MAX_QUEUE_DEPTH = "MaximumQueueDepth";
+    String ATTR_MAX_MSG_SIZE = "MaximumMessageSize";
+    String ATTR_DURABLE = "Durable";
+    String ATTR_AUTODELETE = "AutoDelete";
+    String ATTR_CONSUMER_COUNT = "ConsumerCount";
+    String ATTR_ACTIVE_CONSUMER_COUNT = "ActiveConsumerCount";
+    String ATTR_MSG_COUNT = "MessageCount";
+    String ATTR_QUEUE_DEPTH = "QueueDepth";
+    String ATTR_RCVD_MSG_COUNT = "ReceivedMessageCount";
+    
+    //All attribute names constant
+    String[] QUEUE_ATTRIBUTES = new String[]{
+            ATTR_NAME,
+            ATTR_OWNER,
+            ATTR_MAX_MSG_AGE,
+            ATTR_MAX_MSG_COUNT,
+            ATTR_MAX_QUEUE_DEPTH,
+            ATTR_MAX_MSG_SIZE,
+            ATTR_DURABLE,
+            ATTR_AUTODELETE,
+            ATTR_CONSUMER_COUNT,
+            ATTR_ACTIVE_CONSUMER_COUNT,
+            ATTR_MSG_COUNT,
+            ATTR_QUEUE_DEPTH,
+            ATTR_RCVD_MSG_COUNT
+    };
     
     /**
      * Returns the Name of the ManagedQueue.

Added: qpid/trunk/qpid/java/management/common/src/test/java/org/apache/qpid/management/common/mbeans/ManagedQueueTest.java
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/management/common/src/test/java/org/apache/qpid/management/common/mbeans/ManagedQueueTest.java?rev=802601&view=auto
==============================================================================
--- qpid/trunk/qpid/java/management/common/src/test/java/org/apache/qpid/management/common/mbeans/ManagedQueueTest.java
(added)
+++ qpid/trunk/qpid/java/management/common/src/test/java/org/apache/qpid/management/common/mbeans/ManagedQueueTest.java
Sun Aug  9 21:06:47 2009
@@ -0,0 +1,84 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+package org.apache.qpid.management.common.mbeans;
+
+import java.lang.reflect.InvocationHandler;
+import java.lang.reflect.Method;
+import java.lang.reflect.Proxy;
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.management.MBeanAttributeInfo;
+import javax.management.NotCompliantMBeanException;
+import javax.management.StandardMBean;
+
+import junit.framework.TestCase;
+
+public class ManagedQueueTest extends TestCase
+{
+    public void testAttributesContants()
+    {
+        //Construct a test MBeanInfo that matches what we would get from a real 
+        //MBean using the ManagedQueue management interface. Use this to test
+        //that all attributes have a listing in the attribute array constant.
+
+        StubInvocationHandler stubIH = new StubInvocationHandler();
+        Class<ManagedQueue> mq = ManagedQueue.class;
+        
+        ManagedQueue impl = mq.cast(Proxy.newProxyInstance(mq.getClassLoader(), new Class<?>[]
{mq}, stubIH));
+        try
+        {
+            StandardMBean mbean = new StandardMBean(impl, ManagedQueue.class);
+            
+            List<String> attributeList = new ArrayList<String>();
+            for(String attr : ManagedQueue.QUEUE_ATTRIBUTES)
+            {
+                attributeList.add(attr);
+            }
+            
+            //retrieve the attributes from the constructed MBeanInfo
+            MBeanAttributeInfo[] attributes = mbean.getMBeanInfo().getAttributes();
+
+            for(MBeanAttributeInfo info : attributes)
+            {
+                if(!attributeList.contains(info.getName()))
+                {
+                    fail(mq.getSimpleName() + " attributes constant array does not include
the attribute: " + info.getName());
+                }
+            }
+        }
+        catch (NotCompliantMBeanException e)
+        {
+            fail("Unable to create the test proxy mbean to generate the MBeanInfo");
+        }
+
+    }
+    
+    private static class StubInvocationHandler implements InvocationHandler
+    {
+        //invocation handler used to present a stub implementation when generating the StandardMBean
+        public Object invoke(Object proxy, Method method, Object[] args)
+        {
+            return null;
+        }
+    }
+
+}



---------------------------------------------------------------------
Apache Qpid - AMQP Messaging Implementation
Project:      http://qpid.apache.org
Use/Interact: mailto:commits-subscribe@qpid.apache.org


Mime
View raw message