From a6553354714965741a66df3f1be72d18d2f085bb Mon Sep 17 00:00:00 2001 From: James Strachan Date: Thu, 21 Aug 2008 21:13:39 +0000 Subject: [PATCH] further enhancement for AMQ-1904 to add helper method to extract the Map of all user properties git-svn-id: https://svn.apache.org/repos/asf/activemq/trunk@687864 13f79535-47bb-0310-9956-ffa450edef68 --- .../broker/jmx/CompositeDataHelper.java | 24 +++++++++++++++++++ .../apache/activemq/broker/jmx/MBeanTest.java | 5 ++++ 2 files changed, 29 insertions(+) diff --git a/activemq-core/src/main/java/org/apache/activemq/broker/jmx/CompositeDataHelper.java b/activemq-core/src/main/java/org/apache/activemq/broker/jmx/CompositeDataHelper.java index 33821b2c83..ec27ae2f3f 100644 --- a/activemq-core/src/main/java/org/apache/activemq/broker/jmx/CompositeDataHelper.java +++ b/activemq-core/src/main/java/org/apache/activemq/broker/jmx/CompositeDataHelper.java @@ -34,6 +34,11 @@ public class CompositeDataHelper { */ public static Map getTabularMap(CompositeData cdata, String fieldName) { Map map = new HashMap(); + appendTabularMap(map, cdata, fieldName); + return map; + } + + public static void appendTabularMap(Map map, CompositeData cdata, String fieldName) { Object tabularObject = cdata.get(fieldName); if (tabularObject instanceof TabularData) { TabularData tabularData = (TabularData) tabularObject; @@ -44,6 +49,25 @@ public class CompositeDataHelper { map.put(key, value); } } + } + + /** + * Returns a map of all the user properties in the given message {@link javax.management.openmbean.CompositeData} + * object + * + * @param cdata + * @return + */ + public static Map getMessageUserProperties(CompositeData cdata) { + Map map = new HashMap(); + appendTabularMap(map, cdata, CompositeDataConstants.STRING_PROPERTIES); + appendTabularMap(map, cdata, CompositeDataConstants.BOOLEAN_PROPERTIES); + appendTabularMap(map, cdata, CompositeDataConstants.BYTE_PROPERTIES); + appendTabularMap(map, cdata, CompositeDataConstants.SHORT_PROPERTIES); + appendTabularMap(map, cdata, CompositeDataConstants.INT_PROPERTIES); + appendTabularMap(map, cdata, CompositeDataConstants.LONG_PROPERTIES); + appendTabularMap(map, cdata, CompositeDataConstants.FLOAT_PROPERTIES); + appendTabularMap(map, cdata, CompositeDataConstants.DOUBLE_PROPERTIES); return map; } } diff --git a/activemq-core/src/test/java/org/apache/activemq/broker/jmx/MBeanTest.java b/activemq-core/src/test/java/org/apache/activemq/broker/jmx/MBeanTest.java index c5198953ca..fcad449b48 100644 --- a/activemq-core/src/test/java/org/apache/activemq/broker/jmx/MBeanTest.java +++ b/activemq-core/src/test/java/org/apache/activemq/broker/jmx/MBeanTest.java @@ -188,6 +188,11 @@ public class MBeanTest extends EmbeddedBrokerTestSupport { assertEquals("stringProperties size()", 1, stringProperties.size()); assertEquals("stringProperties.MyHeader", "StringHeader" + i, stringProperties.get("MyStringHeader")); + Map properties = CompositeDataHelper.getMessageUserProperties(cdata); + assertEquals("properties size()", 2, properties.size()); + assertEquals("properties.MyHeader", i, properties.get("MyHeader")); + assertEquals("properties.MyHeader", "StringHeader" + i, properties.get("MyStringHeader")); + assertComplexData(cdata, "JMSXGroupSeq", 1234); assertComplexData(cdata, "JMSXGroupID", "MyGroupID"); assertComplexData(cdata, "Text", "message:" + i);