[jboss-cvs] JBoss Messaging SVN: r4693 - in branches/Branch_JBMESSAGING-1303: src/main/org/jboss/messaging/core/management/impl and 1 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Fri Jul 18 11:02:10 EDT 2008


Author: jmesnil
Date: 2008-07-18 11:02:09 -0400 (Fri, 18 Jul 2008)
New Revision: 4693

Removed:
   branches/Branch_JBMESSAGING-1303/src/main/org/jboss/messaging/core/management/NotificationType.java
Modified:
   branches/Branch_JBMESSAGING-1303/src/main/org/jboss/messaging/core/management/MessageInfo.java
   branches/Branch_JBMESSAGING-1303/src/main/org/jboss/messaging/core/management/impl/QueueControl.java
   branches/Branch_JBMESSAGING-1303/tests/src/org/jboss/messaging/tests/unit/core/management/MessageInfoTest.java
Log:
JBMESSAGING-1303: Revisit management interfaces
* added properties information to MessageInfo

Modified: branches/Branch_JBMESSAGING-1303/src/main/org/jboss/messaging/core/management/MessageInfo.java
===================================================================
--- branches/Branch_JBMESSAGING-1303/src/main/org/jboss/messaging/core/management/MessageInfo.java	2008-07-18 13:20:56 UTC (rev 4692)
+++ branches/Branch_JBMESSAGING-1303/src/main/org/jboss/messaging/core/management/MessageInfo.java	2008-07-18 15:02:09 UTC (rev 4693)
@@ -28,6 +28,10 @@
 import static javax.management.openmbean.SimpleType.LONG;
 import static javax.management.openmbean.SimpleType.STRING;
 
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Map.Entry;
+
 import javax.management.openmbean.CompositeData;
 import javax.management.openmbean.CompositeDataSupport;
 import javax.management.openmbean.CompositeType;
@@ -50,29 +54,33 @@
    public static final CompositeType TYPE;
    private static final String MESSAGE_TYPE_NAME = "MessageInfo";
    private static final String MESSAGE_TABULAR_TYPE_NAME = "MessageTabularInfo";
-   private static final TabularType TABULAR_TYPE;
    private static final String[] ITEM_NAMES = new String[] { "id",
          "destination", "durable", "timestamp", "type", "size", "priority",
-         "expired", "expiration" };
+         "expired", "expiration", "properties" };
    private static final String[] ITEM_DESCRIPTIONS = new String[] {
          "Message ID", "destination of the message", "Is the message durable?",
          "Timestamp of the message", "Type of the message",
          "Size of the encoded messag", "Priority of the message",
-         "Is the message expired?", "Expiration of the message" };
-   private static final OpenType[] ITEM_TYPES = new OpenType[] { LONG, STRING,
-         BOOLEAN, LONG, BYTE, INTEGER, BYTE, BOOLEAN, LONG };
+         "Is the message expired?", "Expiration of the message",
+         "Properties of the message" };
+   private static final OpenType[] TYPES;
+   private static final TabularType TABULAR_TYPE;
 
    static
    {
       try
       {
+         TYPES = new OpenType[] { LONG, STRING, BOOLEAN, LONG, BYTE, INTEGER,
+               BYTE, BOOLEAN, LONG, PropertiesInfo.TABULAR_TYPE };
          TYPE = new CompositeType(MESSAGE_TYPE_NAME,
                "Information for a Message", ITEM_NAMES, ITEM_DESCRIPTIONS,
-               ITEM_TYPES);
+               TYPES);
          TABULAR_TYPE = new TabularType(MESSAGE_TABULAR_TYPE_NAME,
-               "Table of MessageInfo", TYPE, new String[] { "id" });
+               "Information for tabular MessageInfo", TYPE,
+               new String[] { "id" });
       } catch (OpenDataException e)
       {
+         e.printStackTrace();
          throw new IllegalStateException(e);
       }
    }
@@ -88,10 +96,12 @@
    private final byte priority;
    private final boolean expired;
    private final long expiration;
+   private PropertiesInfo properties;
 
    // Static --------------------------------------------------------
 
    public static TabularData toTabularData(MessageInfo[] infos)
+         throws OpenDataException
    {
       TabularData data = new TabularDataSupport(TABULAR_TYPE);
       for (MessageInfo messageInfo : infos)
@@ -116,6 +126,7 @@
       this.priority = priority;
       this.expired = expired;
       this.expiration = expiration;
+      this.properties = new PropertiesInfo();
    }
 
    // Public --------------------------------------------------------
@@ -165,13 +176,24 @@
       return expiration;
    }
 
+   public void putProperty(String key, String value)
+   {
+      properties.put(key, value);
+   }
+
+   public Map<String, String> getProperties()
+   {
+      return properties.entries();
+   }
+
    public CompositeData toCompositeData()
    {
       try
       {
+
          return new CompositeDataSupport(TYPE, ITEM_NAMES, new Object[] { id,
                destination, durable, timestamp, type, size, priority, expired,
-               expiration });
+               expiration, properties.toTabularData() });
       } catch (OpenDataException e)
       {
          e.printStackTrace();
@@ -186,4 +208,64 @@
    // Private -------------------------------------------------------
 
    // Inner classes -------------------------------------------------
+
+   private static class PropertiesInfo
+   {
+      public static final TabularType TABULAR_TYPE;
+      private static CompositeType ROW_TYPE;
+
+      private final Map<String, String> properties = new HashMap<String, String>();
+
+      static
+      {
+         try
+         {
+            ROW_TYPE = new CompositeType("Property", "Property", new String[] {
+                  "key", "value" }, new String[] { "Key of the property",
+                  "Value of the property" }, new OpenType[] { STRING, STRING });
+            TABULAR_TYPE = new TabularType("PropertyInfo",
+                  "Properties of the message", ROW_TYPE, new String[] { "key" });
+         } catch (OpenDataException e)
+         {
+            e.printStackTrace();
+            throw new IllegalStateException(e);
+         }
+      }
+
+      PropertiesInfo()
+      {
+      }
+
+      /**
+       * @return
+       */
+      public Map<String, String> entries()
+      {
+         return properties;
+      }
+
+      void put(String key, String value)
+      {
+         properties.put(key, value);
+      }
+
+      TabularData toTabularData()
+      {
+         try
+         {
+            TabularDataSupport data = new TabularDataSupport(TABULAR_TYPE);
+            for (Entry<String, String> entry : properties.entrySet())
+            {
+               data.put(new CompositeDataSupport(ROW_TYPE, new String[] {
+                     "key", "value" }, new Object[] { entry.getKey(),
+                     entry.getValue() }));
+            }
+            return data;
+         } catch (OpenDataException e)
+         {
+            e.printStackTrace();
+            return null;
+         }
+      }
+   }
 }

Deleted: branches/Branch_JBMESSAGING-1303/src/main/org/jboss/messaging/core/management/NotificationType.java
===================================================================
--- branches/Branch_JBMESSAGING-1303/src/main/org/jboss/messaging/core/management/NotificationType.java	2008-07-18 13:20:56 UTC (rev 4692)
+++ branches/Branch_JBMESSAGING-1303/src/main/org/jboss/messaging/core/management/NotificationType.java	2008-07-18 15:02:09 UTC (rev 4693)
@@ -1,34 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2008, Red Hat Middleware LLC, and individual contributors
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
- */
-
-package org.jboss.messaging.core.management;
-
-/**
- * @author <a href="mailto:jmesnil at redhat.com">Jeff Mesnil</a>
- * 
- * @version <tt>$Revision$</tt>
- * 
- */
-public enum NotificationType
-{
-   QUEUE_CREATED, QUEUE_DESTROYED;
-}

Modified: branches/Branch_JBMESSAGING-1303/src/main/org/jboss/messaging/core/management/impl/QueueControl.java
===================================================================
--- branches/Branch_JBMESSAGING-1303/src/main/org/jboss/messaging/core/management/impl/QueueControl.java	2008-07-18 13:20:56 UTC (rev 4692)
+++ branches/Branch_JBMESSAGING-1303/src/main/org/jboss/messaging/core/management/impl/QueueControl.java	2008-07-18 15:02:09 UTC (rev 4693)
@@ -130,6 +130,12 @@
                   .getTimestamp(), message.getType(), message.getEncodeSize(),
                   message.getPriority(), message.isExpired(), message
                         .getExpiration());
+            for (SimpleString key : message.getPropertyNames())
+            {
+               Object value = message.getProperty(key);
+               String valueStr = value == null ? null : value.toString();
+               info.putProperty(key.toString(), valueStr);
+            }
             infos[i] = info;
          }
          return MessageInfo.toTabularData(infos);

Modified: branches/Branch_JBMESSAGING-1303/tests/src/org/jboss/messaging/tests/unit/core/management/MessageInfoTest.java
===================================================================
--- branches/Branch_JBMESSAGING-1303/tests/src/org/jboss/messaging/tests/unit/core/management/MessageInfoTest.java	2008-07-18 13:20:56 UTC (rev 4692)
+++ branches/Branch_JBMESSAGING-1303/tests/src/org/jboss/messaging/tests/unit/core/management/MessageInfoTest.java	2008-07-18 15:02:09 UTC (rev 4693)
@@ -28,6 +28,8 @@
 import static org.jboss.messaging.tests.util.RandomUtil.randomLong;
 import static org.jboss.messaging.tests.util.RandomUtil.randomString;
 
+import java.util.Collection;
+
 import javax.management.openmbean.CompositeData;
 import javax.management.openmbean.TabularData;
 
@@ -62,6 +64,18 @@
       assertEquals(expected.getPriority(), actual.get("priority"));
       assertEquals(expected.isExpired(), actual.get("expired"));
       assertEquals(expected.getExpiration(), actual.get("expiration"));
+      
+      TabularData propsDatas = (TabularData) actual.get("properties");
+      Collection<CompositeData> props = propsDatas.values();
+      assertEquals(expected.getProperties().size(), props.size());
+      for (CompositeData prop : props)
+      {
+         String actualKey = (String) prop.get("key");
+         String actualValue = (String) prop.get("value");
+         
+         assertTrue(expected.getProperties().containsKey(actualKey));
+         assertEquals(expected.getProperties().get(actualKey), actualValue);
+      }
    }
 
    // Constructors --------------------------------------------------
@@ -83,9 +97,12 @@
       MessageInfo info_1 = new MessageInfo(randomLong(), randomString(),
             randomBoolean(), randomLong(), randomByte(), randomInt(),
             randomByte(), randomBoolean(), randomLong());
+      info_1.putProperty(randomString(), randomString());
+      info_1.putProperty(randomString(), randomString());
       MessageInfo info_2 = new MessageInfo(randomLong(), randomString(),
             randomBoolean(), randomLong(), randomByte(), randomInt(),
             randomByte(), randomBoolean(), randomLong());
+      info_2.putProperty(randomString(), randomString());
       MessageInfo[] messages = new MessageInfo[] { info_1, info_2 };
 
       TabularData data = MessageInfo.toTabularData(messages);




More information about the jboss-cvs-commits mailing list