[jboss-cvs] JBoss Messaging SVN: r4881 - in trunk: src/main/org/jboss/messaging/core/management/impl and 3 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Wed Aug 27 11:07:23 EDT 2008


Author: jmesnil
Date: 2008-08-27 11:07:23 -0400 (Wed, 27 Aug 2008)
New Revision: 4881

Added:
   trunk/src/main/org/jboss/messaging/core/management/DayCounterInfo.java
   trunk/src/main/org/jboss/messaging/core/management/MessageCounterInfo.java
   trunk/src/main/org/jboss/messaging/core/messagecounter/MessageCounterManager.java
   trunk/src/main/org/jboss/messaging/core/messagecounter/MessageStatistics.java
   trunk/src/main/org/jboss/messaging/core/messagecounter/impl/
   trunk/src/main/org/jboss/messaging/core/messagecounter/impl/MessageCounterManagerImpl.java
Modified:
   trunk/src/main/org/jboss/messaging/core/management/MessagingServerControlMBean.java
   trunk/src/main/org/jboss/messaging/core/management/QueueControlMBean.java
   trunk/src/main/org/jboss/messaging/core/management/impl/ManagementServiceImpl.java
   trunk/src/main/org/jboss/messaging/core/management/impl/MessagingServerControl.java
   trunk/src/main/org/jboss/messaging/core/management/impl/QueueControl.java
   trunk/src/main/org/jboss/messaging/core/messagecounter/MessageCounter.java
   trunk/tests/src/org/jboss/messaging/tests/unit/core/management/impl/ManagementServiceImplTest.java
   trunk/tests/src/org/jboss/messaging/tests/unit/core/management/impl/MessagingServerControlTest.java
   trunk/tests/src/org/jboss/messaging/tests/unit/core/management/impl/QueueControlTest.java
Log:
JBMESSAGING-1410: Reenable message counters
  - added {enable|disable}MessageCounters() operation to MessagingServerControlMBean
  - added operations to list message counters and their history to QueueControlMBean

Added: trunk/src/main/org/jboss/messaging/core/management/DayCounterInfo.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/management/DayCounterInfo.java	                        (rev 0)
+++ trunk/src/main/org/jboss/messaging/core/management/DayCounterInfo.java	2008-08-27 15:07:23 UTC (rev 4881)
@@ -0,0 +1,172 @@
+/*
+ * 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;
+
+import static javax.management.openmbean.SimpleType.INTEGER;
+import static javax.management.openmbean.SimpleType.STRING;
+
+import javax.management.openmbean.CompositeData;
+import javax.management.openmbean.CompositeDataSupport;
+import javax.management.openmbean.CompositeType;
+import javax.management.openmbean.OpenDataException;
+import javax.management.openmbean.OpenType;
+import javax.management.openmbean.TabularData;
+import javax.management.openmbean.TabularDataSupport;
+import javax.management.openmbean.TabularType;
+
+import org.jboss.logging.Logger;
+
+/**
+ * @author <a href="mailto:jmesnil at redhat.com">Jeff Mesnil</a>
+ * 
+ * @version <tt>$Revision$</tt>
+ * 
+ */
+public class DayCounterInfo
+{
+   // Constants -----------------------------------------------------
+
+   private static final Logger log = Logger.getLogger(DayCounterInfo.class);
+
+   public static final CompositeType TYPE;
+   private static final String MESSAGE_TYPE_NAME = "DayCounterInfo";
+   private static final String MESSAGE_TABULAR_TYPE_NAME = "TabularDayCounterInfo";
+   private static final String[] ITEM_NAMES = new String[] { "date", "00",
+         "01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11",
+         "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22",
+         "23", "total" };
+   private static final String[] ITEM_DESCRIPTIONS = new String[] { "Date",
+         "Messages received during the 1st hour",
+         "Messages received during the 2nd hour",
+         "Messages received during the 3rd hour",
+         "Messages received during the 4th hour",
+         "Messages received during the 5th hour",
+         "Messages received during the 6th hour",
+         "Messages received during the 7th hour",
+         "Messages received during the 8th hour",
+         "Messages received during the 9th hour",
+         "Messages received during the 10th hour",
+         "Messages received during the 11th hour",
+         "Messages received during the 12th hour",
+         "Messages received during the 13th hour",
+         "Messages received during the 14th hour",
+         "Messages received during the 15th hour",
+         "Messages received during the 16th hour",
+         "Messages received during the 17th hour",
+         "Messages received during the 18th hour",
+         "Messages received during the 19th hour",
+         "Messages received during the 20th hour",
+         "Messages received during the 21th hour",
+         "Messages received during the 22th hour",
+         "Messages received during the 23th hour",
+         "Messages received during the 24th hour",
+         "Total of messages for the day" };
+   private static final OpenType[] TYPES;
+   private static final TabularType TABULAR_TYPE;
+
+   static
+   {
+      try
+      {
+         TYPES = new OpenType[] { STRING, INTEGER, INTEGER, INTEGER, INTEGER,
+               INTEGER, INTEGER, INTEGER, INTEGER, INTEGER, INTEGER, INTEGER,
+               INTEGER, INTEGER, INTEGER, INTEGER, INTEGER, INTEGER, INTEGER,
+               INTEGER, INTEGER, INTEGER, INTEGER, INTEGER, INTEGER, INTEGER };
+         TYPE = new CompositeType(MESSAGE_TYPE_NAME,
+               "Information for a DayCounterInfo", ITEM_NAMES,
+               ITEM_DESCRIPTIONS, TYPES);
+         TABULAR_TYPE = new TabularType(MESSAGE_TABULAR_TYPE_NAME,
+               "Information for Tabular DayCounterInfo", TYPE,
+               new String[] { "date" });
+      } catch (OpenDataException e)
+      {
+         log.error("Unable to create open types for a DayCounter", e);
+         throw new IllegalStateException(e);
+      }
+   }
+
+   // Attributes ----------------------------------------------------
+
+   private final String date;
+   private final int[] counters;
+
+   // Static --------------------------------------------------------
+
+   public static TabularData toTabularData(final DayCounterInfo[] infos)
+         throws OpenDataException
+   {
+      TabularData data = new TabularDataSupport(TABULAR_TYPE);
+      for (DayCounterInfo info : infos)
+      {
+         data.put(info.toCompositeData());
+      }
+      return data;
+   }
+
+   // Constructors --------------------------------------------------
+
+   public DayCounterInfo(final String date, final int[] counters)
+   {
+      this.date = date;
+      this.counters = counters;
+   }
+
+   // Public --------------------------------------------------------
+
+   public CompositeData toCompositeData()
+   {
+      try
+      {
+         // 1 for the date, 24 for the hours, 1 for the total
+         Object[] objects = new Object[1 + 24 + 1];
+         objects[0] = date;
+         int total = 0;
+         for (int i = 0; i < counters.length; i++)
+         {
+            int value = counters[i];
+            if (value == -1)
+            {
+               objects[1 + i] = 0;
+            } else
+            {
+               objects[1 + i] = value;
+               total += value;
+            }
+         }
+         objects[objects.length - 1] = total;
+         return new CompositeDataSupport(TYPE, ITEM_NAMES, objects);
+      } catch (OpenDataException e)
+      {
+         log.error("Unable to create a CompositeData from a DayCounter", e);
+         return null;
+      }
+   }
+
+   // Package protected ---------------------------------------------
+
+   // Protected -----------------------------------------------------
+
+   // Private -------------------------------------------------------
+
+   // Inner classes -------------------------------------------------
+}

Added: trunk/src/main/org/jboss/messaging/core/management/MessageCounterInfo.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/management/MessageCounterInfo.java	                        (rev 0)
+++ trunk/src/main/org/jboss/messaging/core/management/MessageCounterInfo.java	2008-08-27 15:07:23 UTC (rev 4881)
@@ -0,0 +1,135 @@
+/*
+ * 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;
+
+import static javax.management.openmbean.SimpleType.BOOLEAN;
+import static javax.management.openmbean.SimpleType.INTEGER;
+import static javax.management.openmbean.SimpleType.STRING;
+
+import javax.management.openmbean.CompositeData;
+import javax.management.openmbean.CompositeDataSupport;
+import javax.management.openmbean.CompositeType;
+import javax.management.openmbean.OpenDataException;
+import javax.management.openmbean.OpenType;
+import javax.management.openmbean.TabularType;
+
+import org.jboss.logging.Logger;
+
+/**
+ * @author <a href="mailto:jmesnil at redhat.com">Jeff Mesnil</a>
+ * 
+ * @version <tt>$Revision$</tt>
+ * 
+ */
+public class MessageCounterInfo
+{
+   // Constants -----------------------------------------------------
+
+   private static final Logger log = Logger.getLogger(MessageCounterInfo.class);
+
+   public static final CompositeType TYPE;
+   private static final String MESSAGE_TYPE_NAME = "MessageCounterInfo";
+   private static final String MESSAGE_TABULAR_TYPE_NAME = "TabularMessageCounterInfo";
+   private static final String[] ITEM_NAMES = new String[] { "name",
+         "subscription", "durable", "count", "countDelta", "depth",
+         "depthDelta", "timestamp" };
+   private static final String[] ITEM_DESCRIPTIONS = new String[] {
+         "Name of the Queue", "Name of the subscription",
+         "Is the queue durable?", "Message count", "Message count delta",
+         "Depth", "Depth delta", "Timestamp of the last increment" };
+   private static final OpenType[] TYPES;
+   private static final TabularType TABULAR_TYPE;
+
+   static
+   {
+      try
+      {
+         TYPES = new OpenType[] { STRING, STRING, BOOLEAN, INTEGER, INTEGER,
+               INTEGER, INTEGER, STRING };
+         TYPE = new CompositeType(MESSAGE_TYPE_NAME,
+               "Information for a MessageCounter", ITEM_NAMES,
+               ITEM_DESCRIPTIONS, TYPES);
+         TABULAR_TYPE = new TabularType(MESSAGE_TABULAR_TYPE_NAME,
+               "Information for Tabular MessageCounter", TYPE,
+               new String[] { "name" });
+      } catch (OpenDataException e)
+      {
+         log.error("Unable to create open types for a MessageCounter", e);
+         throw new IllegalStateException(e);
+      }
+   }
+
+   // Attributes ----------------------------------------------------
+
+   private final String name;
+   private final String subscription;
+   private final boolean durable;
+   private final int count;
+   private final int countDelta;
+   private final int depth;
+   private final int depthDelta;
+   private final String timestamp;
+
+   // Static --------------------------------------------------------
+
+   // Constructors --------------------------------------------------
+
+   public MessageCounterInfo(final String name, final String subscription,
+         final boolean durable, final int count, final int countDelta,
+         final int depth, final int depthDelta, final String timestamp)
+   {
+      this.name = name;
+      this.subscription = subscription;
+      this.durable = durable;
+      this.count = count;
+      this.countDelta = countDelta;
+      this.depth = depth;
+      this.depthDelta = depthDelta;
+      this.timestamp = timestamp;
+   }
+
+   // Public --------------------------------------------------------
+
+   public CompositeData toCompositeData()
+   {
+      try
+      {
+
+         return new CompositeDataSupport(TYPE, ITEM_NAMES, new Object[] { name,
+               subscription, durable, count, countDelta, depth, depthDelta,
+               timestamp });
+      } catch (OpenDataException e)
+      {
+         log.error("Unable to create a CompositeData from a MessageCounter", e);
+         return null;
+      }
+   }
+
+   // Package protected ---------------------------------------------
+
+   // Protected -----------------------------------------------------
+
+   // Private -------------------------------------------------------
+
+   // Inner classes -------------------------------------------------
+}

Modified: trunk/src/main/org/jboss/messaging/core/management/MessagingServerControlMBean.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/management/MessagingServerControlMBean.java	2008-08-27 14:10:45 UTC (rev 4880)
+++ trunk/src/main/org/jboss/messaging/core/management/MessagingServerControlMBean.java	2008-08-27 15:07:23 UTC (rev 4881)
@@ -114,4 +114,10 @@
    boolean removeAddress(
          @Parameter(name = "address", desc = "The address to remove") String address)
          throws Exception;
+
+   void enableMessageCounters();
+
+   void disableMessageCounters();
+
+   boolean isEnableMessageCounters();
 }

Modified: trunk/src/main/org/jboss/messaging/core/management/QueueControlMBean.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/management/QueueControlMBean.java	2008-08-27 14:10:45 UTC (rev 4880)
+++ trunk/src/main/org/jboss/messaging/core/management/QueueControlMBean.java	2008-08-27 15:07:23 UTC (rev 4881)
@@ -25,6 +25,7 @@
 import static javax.management.MBeanOperationInfo.ACTION;
 import static javax.management.MBeanOperationInfo.INFO;
 
+import javax.management.openmbean.CompositeData;
 import javax.management.openmbean.TabularData;
 
 /**
@@ -114,4 +115,11 @@
          @Parameter(name = "newPriority", desc = "the new priority (between 0 and 9)") int newPriority)
          throws Exception;
 
+   CompositeData listMessageCounter();
+
+   String listMessageCounterAsHTML();
+
+   TabularData listMessageCounterHistory() throws Exception;
+
+   String listMessageCounterHistoryAsHTML();
 }

Modified: trunk/src/main/org/jboss/messaging/core/management/impl/ManagementServiceImpl.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/management/impl/ManagementServiceImpl.java	2008-08-27 14:10:45 UTC (rev 4880)
+++ trunk/src/main/org/jboss/messaging/core/management/impl/ManagementServiceImpl.java	2008-08-27 15:07:23 UTC (rev 4881)
@@ -35,6 +35,9 @@
 import org.jboss.messaging.core.management.ManagementService;
 import org.jboss.messaging.core.management.MessagingServerControlMBean;
 import org.jboss.messaging.core.management.QueueControlMBean;
+import org.jboss.messaging.core.messagecounter.MessageCounter;
+import org.jboss.messaging.core.messagecounter.MessageCounterManager;
+import org.jboss.messaging.core.messagecounter.impl.MessageCounterManagerImpl;
 import org.jboss.messaging.core.persistence.StorageManager;
 import org.jboss.messaging.core.postoffice.PostOffice;
 import org.jboss.messaging.core.security.Role;
@@ -67,6 +70,7 @@
    private PostOffice postOffice;
    private HierarchicalRepository<Set<Role>> securityRepository;
    private HierarchicalRepository<QueueSettings> queueSettingsRepository;
+   private MessageCounterManager messageCounterManager = new MessageCounterManagerImpl(10000);
 
    // Static --------------------------------------------------------
 
@@ -115,7 +119,7 @@
       this.queueSettingsRepository = queueSettingsRepository;
       MessagingServerControlMBean managedServer = new MessagingServerControl(
             postOffice, storageManager, configuration, securityRepository,
-            queueSettingsRepository, messagingServer);
+            queueSettingsRepository, messagingServer, messageCounterManager);
       ObjectName objectName = getMessagingServerObjectName();
       register(objectName, managedServer);
       registerInJMX(objectName, managedServer);
@@ -152,9 +156,12 @@
    public void registerQueue(final Queue queue, final SimpleString address,
          final StorageManager storageManager) throws Exception
    {
+      MessageCounter counter = new MessageCounter(queue.getName().toString(), null, queue, false, queue.isDurable(),
+            10);
+      messageCounterManager.registerMessageCounter(queue.getName().toString(), counter);
       ObjectName objectName = getQueueObjectName(address, queue.getName());
       QueueControlMBean queueControl = new QueueControl(queue, storageManager,
-            postOffice, queueSettingsRepository);
+            postOffice, queueSettingsRepository, counter);
       register(objectName, queueControl);
       registerInJMX(objectName, queueControl);
       if (log.isDebugEnabled())
@@ -169,6 +176,7 @@
       ObjectName objectName = getQueueObjectName(address, name);
       unregister(objectName);
       unregisterFromJMX(objectName);
+      messageCounterManager.unregisterMessageCounter(name.toString());
    }
 
    // Package protected ---------------------------------------------

Modified: trunk/src/main/org/jboss/messaging/core/management/impl/MessagingServerControl.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/management/impl/MessagingServerControl.java	2008-08-27 14:10:45 UTC (rev 4880)
+++ trunk/src/main/org/jboss/messaging/core/management/impl/MessagingServerControl.java	2008-08-27 15:07:23 UTC (rev 4881)
@@ -40,6 +40,7 @@
 import org.jboss.messaging.core.filter.Filter;
 import org.jboss.messaging.core.filter.impl.FilterImpl;
 import org.jboss.messaging.core.management.MessagingServerControlMBean;
+import org.jboss.messaging.core.messagecounter.MessageCounterManager;
 import org.jboss.messaging.core.persistence.StorageManager;
 import org.jboss.messaging.core.postoffice.Binding;
 import org.jboss.messaging.core.postoffice.PostOffice;
@@ -71,10 +72,13 @@
    private final HierarchicalRepository<Set<Role>> securityRepository;
    private final HierarchicalRepository<QueueSettings> queueSettingsRepository;
    private final MessagingServer server;
+   private final MessageCounterManager messageCounterManager;
 
    private final NotificationBroadcasterSupport broadcaster;
    private AtomicLong notifSeq = new AtomicLong(0);
 
+   private boolean enableMessageCounters;
+
    // Static --------------------------------------------------------
 
    // Constructors --------------------------------------------------
@@ -83,7 +87,7 @@
          StorageManager storageManager, Configuration configuration,
          HierarchicalRepository<Set<Role>> securityRepository,
          HierarchicalRepository<QueueSettings> queueSettingsRepository,
-         MessagingServer messagingServer) throws Exception
+         MessagingServer messagingServer, MessageCounterManager messageCounterManager) throws Exception
    {
       super(MessagingServerControlMBean.class);
       this.postOffice = postOffice;
@@ -92,6 +96,7 @@
       this.securityRepository = securityRepository;
       this.queueSettingsRepository = queueSettingsRepository;
       this.server = messagingServer;
+      this.messageCounterManager = messageCounterManager;
 
       broadcaster = new NotificationBroadcasterSupport();
    }
@@ -371,6 +376,21 @@
       return postOffice.removeDestination(new SimpleString(address), false);
    }
 
+   public void enableMessageCounters()
+   {
+      setEnableMessageCounters(true);
+   }
+
+   public void disableMessageCounters()
+   {
+      setEnableMessageCounters(false);
+   }
+      
+   public boolean isEnableMessageCounters()
+   {
+      return enableMessageCounters;
+   } 
+   
    // NotificationEmitter implementation ----------------------------
 
    public void removeNotificationListener(final NotificationListener listener,
@@ -411,6 +431,36 @@
 
    // Private -------------------------------------------------------
 
+   private synchronized void setEnableMessageCounters(boolean enable) 
+   {
+      if (isStarted())
+      {
+         if (enableMessageCounters && !enable)
+         {
+            stopMessageCounters();
+         }
+         else if (!enableMessageCounters && enable)
+         {
+            startMessageCounters();
+         }        
+      }
+      enableMessageCounters = enable;
+   }
+
+   private void startMessageCounters()
+   {
+      messageCounterManager.start();
+   }
+   
+   private void stopMessageCounters()
+   {
+      messageCounterManager.stop();
+      
+      messageCounterManager.resetAllCounters();
+
+      messageCounterManager.resetAllCounterHistories();
+   }
+   
    private void sendNotification(final NotificationType type,
          final String message)
    {

Modified: trunk/src/main/org/jboss/messaging/core/management/impl/QueueControl.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/management/impl/QueueControl.java	2008-08-27 14:10:45 UTC (rev 4880)
+++ trunk/src/main/org/jboss/messaging/core/management/impl/QueueControl.java	2008-08-27 15:07:23 UTC (rev 4881)
@@ -22,18 +22,27 @@
 
 package org.jboss.messaging.core.management.impl;
 
+import java.text.DateFormat;
+import java.util.Date;
+import java.util.GregorianCalendar;
 import java.util.List;
+import java.util.StringTokenizer;
 
 import javax.management.MBeanInfo;
 import javax.management.NotCompliantMBeanException;
 import javax.management.StandardMBean;
+import javax.management.openmbean.CompositeData;
 import javax.management.openmbean.TabularData;
 
 import org.jboss.messaging.core.exception.MessagingException;
 import org.jboss.messaging.core.filter.Filter;
 import org.jboss.messaging.core.filter.impl.FilterImpl;
+import org.jboss.messaging.core.management.DayCounterInfo;
+import org.jboss.messaging.core.management.MessageCounterInfo;
 import org.jboss.messaging.core.management.MessageInfo;
 import org.jboss.messaging.core.management.QueueControlMBean;
+import org.jboss.messaging.core.messagecounter.MessageCounter;
+import org.jboss.messaging.core.messagecounter.MessageCounter.DayCounter;
 import org.jboss.messaging.core.persistence.StorageManager;
 import org.jboss.messaging.core.postoffice.Binding;
 import org.jboss.messaging.core.postoffice.PostOffice;
@@ -57,10 +66,11 @@
 
    // Attributes ----------------------------------------------------
 
-   public final Queue queue;
+   private final Queue queue;
    private final StorageManager storageManager;
    private final PostOffice postOffice;
    private final HierarchicalRepository<QueueSettings> queueSettingsRepository;
+   private final MessageCounter counter;
 
    // Static --------------------------------------------------------
 
@@ -68,14 +78,15 @@
 
    public QueueControl(final Queue queue, final StorageManager storageManager,
          final PostOffice postOffice,
-         final HierarchicalRepository<QueueSettings> queueSettingsRepository)
-         throws NotCompliantMBeanException
+         final HierarchicalRepository<QueueSettings> queueSettingsRepository,
+         final MessageCounter counter) throws NotCompliantMBeanException
    {
       super(QueueControlMBean.class);
       this.queue = queue;
       this.storageManager = storageManager;
       this.postOffice = postOffice;
       this.queueSettingsRepository = queueSettingsRepository;
+      this.counter = counter;
    }
 
    // Public --------------------------------------------------------
@@ -282,6 +293,52 @@
             storageManager, postOffice, queueSettingsRepository);
    }
 
+   public CompositeData listMessageCounter()
+   {
+      DateFormat dateFormat = DateFormat.getDateTimeInstance(DateFormat.SHORT,
+            DateFormat.MEDIUM);
+      String timestamp = dateFormat.format(new Date(counter.getLastUpdate()));
+      MessageCounterInfo info = new MessageCounterInfo(counter
+            .getDestinationName(), counter.getDestinationSubscription(),
+            counter.getDestinationDurable(), counter.getCount(), counter
+                  .getCountDelta(), counter.getMessageCount(), counter
+                  .getMessageCountDelta(), timestamp);
+      return info.toCompositeData();
+   }
+
+   public String listMessageCounterAsHTML()
+   {
+      return listMessageCounterAsHTML(new MessageCounter[] { counter });
+   }
+
+   public TabularData listMessageCounterHistory() throws Exception
+   {
+      try {
+         List<DayCounter> history = counter.getHistory();
+         DayCounterInfo[] infos = new DayCounterInfo[history.size()];
+         for (int i = 0; i < infos.length; i++)
+         {
+            DayCounter dayCounter = history.get(i);
+            int[] counters = dayCounter.getCounters();
+            GregorianCalendar date = dayCounter.getDate();
+
+            DateFormat dateFormat = DateFormat.getDateInstance(DateFormat.SHORT);
+            String strData = dateFormat.format(date.getTime());
+            infos[i] = new DayCounterInfo(strData, counters);
+         }
+         return DayCounterInfo.toTabularData(infos);
+      } catch (Throwable t)
+      {
+         t.printStackTrace();
+         return null;
+      }
+   }
+   
+   public String listMessageCounterHistoryAsHTML()
+   {
+      return listMessageCounterHistoryAsHTML(new MessageCounter[] { counter });
+   }
+   
    // StandardMBean overrides ---------------------------------------
 
    @Override
@@ -300,5 +357,133 @@
 
    // Private -------------------------------------------------------
 
+   private String listMessageCounterAsHTML(MessageCounter[] counters)
+   {
+      if (counters == null)
+         return null;
+
+      String ret = "<table width=\"100%\" border=\"1\" cellpadding=\"1\" cellspacing=\"1\">"
+            + "<tr>"
+            + "<th>Type</th>"
+            + "<th>Name</th>"
+            + "<th>Subscription</th>"
+            + "<th>Durable</th>"
+            + "<th>Count</th>"
+            + "<th>CountDelta</th>"
+            + "<th>Depth</th>"
+            + "<th>DepthDelta</th>"
+            + "<th>Last Add</th>" + "</tr>";
+
+      for (int i = 0; i < counters.length; i++)
+      {
+         String data = counters[i].getCounterAsString();
+         StringTokenizer token = new StringTokenizer(data, ",");
+         String value;
+
+         ret += "<tr bgcolor=\"#" + ((i % 2) == 0 ? "FFFFFF" : "F0F0F0")
+               + "\">";
+
+         ret += "<td>" + token.nextToken() + "</td>"; // type
+         ret += "<td>" + token.nextToken() + "</td>"; // name
+         ret += "<td>" + token.nextToken() + "</td>"; // subscription
+         ret += "<td>" + token.nextToken() + "</td>"; // durable
+
+         ret += "<td>" + token.nextToken() + "</td>"; // count
+
+         value = token.nextToken(); // countDelta
+
+         if (value.equalsIgnoreCase("0"))
+            value = "-";
+
+         ret += "<td>" + value + "</td>";
+
+         ret += "<td>" + token.nextToken() + "</td>"; // depth
+
+         value = token.nextToken(); // depthDelta
+
+         if (value.equalsIgnoreCase("0"))
+            value = "-";
+
+         ret += "<td>" + value + "</td>";
+
+         ret += "<td>" + token.nextToken() + "</td>"; // date last add
+
+         ret += "</tr>";
+      }
+
+      ret += "</table>";
+
+      return ret;
+   }
+
+   private String listMessageCounterHistoryAsHTML(MessageCounter[] counters)
+   {
+      if (counters == null)
+         return null;
+
+      String ret = "";
+
+      for (int i = 0; i < counters.length; i++)
+      {
+         // destination name
+         ret += (counters[i].getDestinationTopic() ? "Topic '" : "Queue '");
+         ret += counters[i].getDestinationName() + "'";
+
+         if (counters[i].getDestinationSubscription() != null)
+            ret += "Subscription '" + counters[i].getDestinationSubscription()
+                  + "'";
+
+         // table header
+         ret += "<table width=\"100%\" border=\"1\" cellpadding=\"1\" cellspacing=\"1\">"
+               + "<tr>" + "<th>Date</th>";
+
+         for (int j = 0; j < 24; j++)
+            ret += "<th width=\"4%\">" + j + "</th>";
+
+         ret += "<th>Total</th></tr>";
+
+         // get history data as CSV string
+         StringTokenizer tokens = new StringTokenizer(counters[i]
+               .getHistoryAsString(), ",\n");
+
+         // get history day count
+         int days = Integer.parseInt(tokens.nextToken());
+
+         for (int j = 0; j < days; j++)
+         {
+            // next day counter row
+            ret += "<tr bgcolor=\"#" + ((j % 2) == 0 ? "FFFFFF" : "F0F0F0")
+                  + "\">";
+
+            // date
+            ret += "<td>" + tokens.nextToken() + "</td>";
+
+            // 24 hour counters
+            int total = 0;
+
+            for (int k = 0; k < 24; k++)
+            {
+               int value = Integer.parseInt(tokens.nextToken().trim());
+
+               if (value == -1)
+               {
+                  ret += "<td></td>";
+               } else
+               {
+                  ret += "<td>" + value + "</td>";
+
+                  total += value;
+               }
+            }
+
+            ret += "<td>" + total + "</td></tr>";
+         }
+
+         ret += "</table><br><br>";
+      }
+
+      return ret;
+   }
+   
    // Inner classes -------------------------------------------------
 }

Modified: trunk/src/main/org/jboss/messaging/core/messagecounter/MessageCounter.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/messagecounter/MessageCounter.java	2008-08-27 14:10:45 UTC (rev 4880)
+++ trunk/src/main/org/jboss/messaging/core/messagecounter/MessageCounter.java	2008-08-27 15:07:23 UTC (rev 4881)
@@ -1,539 +1,680 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2005-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.messagecounter;
-
-import java.text.DateFormat;
-import java.util.ArrayList;
-import java.util.Calendar;
-import java.util.Date;
-import java.util.GregorianCalendar;
-
-import org.jboss.messaging.core.logging.Logger;
-import org.jboss.messaging.core.server.Queue;
-
-/**
- * This class stores message count informations for a given queue
- * 
- * At intervals this class samples the queue for message count data
- * 
- * Note that the underlying queue *does not* update statistics every time a message
- * is added since that would reall slow things down, instead we *sample* the queues at
- * regular intervals - this means we are less intrusive on the queue
- *
- * @author <a href="mailto:u.schroeter at mobilcom.de">Ulf Schroeter</a>
- * @author <a href="mailto:s.steinbacher at mobilcom.de">Stephan Steinbacher</a>
- * @author <a href="mailto:tim.fox at jboss.com">Tim Fox</a>
- * @version $Revision: 1.8 $
- */
-public class MessageCounter
-{
-   protected static final Logger log = Logger.getLogger(MessageCounter.class);
-
-   // destination related information
-   private String destName;
-   private boolean destDurable;
-
-   // destination queue
-   private Queue destQueue;
-
-   // counter
-   private long timeLastUpdate;
-
-   // per hour day counter history
-   private int messageCount;
-   private int dayCounterMax;
-   private ArrayList<DayCounter> dayCounter;
-
-   /**
-    *    Constructor
-    *
-    * @param name             destination name
-    * @param queue            internal queue object
-    * @param durable          durable subsciption flag
-    * @param daycountmax      max message history day count
-    */
-   public MessageCounter(String name,
-                         Queue queue,
-                         boolean durable,
-                         int daycountmax)
-   {
-      // store destination related information
-      destName = name;
-      destDurable = durable;
-      destQueue = queue;      
-      messageCount = destQueue.getMessageCount();
-      // initialize counter
-      resetCounter();
-
-      // initialize message history
-      dayCounter = new ArrayList<DayCounter>();
-
-      setHistoryLimit(daycountmax);
-   }
-
-   /**
-   * Get string representation
-   */
-   public String toString()
-   {
-      return getCounterAsString();
-   }
-
-   private int lastMessagesAdded;
-   
-   /*
-    * This method is called periodically to update statistics from the queue
-    */
-   public synchronized void sample()
-   {
-      
-      //update timestamp
-      timeLastUpdate = System.currentTimeMillis();
-      
-      // update message history
-      updateHistory(true);
-   }
-
-   /**
-    * Gets the related destination name
-    *
-    * @return String    destination name
-    */
-   public String getDestinationName()
-   {
-      return destName;
-   }
-
-   /**
-    * Gets the related destination durable subscription flag
-    *
-    * @return boolean   true : durable subscription,
-    *                   false: non-durable subscription
-    */
-   public boolean getDestinationDurable()
-   {
-      return destDurable;
-   }
-
-   public int getTotalMessages()
-   {
-      return this.destQueue.getMessagesAdded();
-   }
-
-   public int getCurrentMessageCount()
-   {
-      return this.destQueue.getMessageCount();
-   }
-
-   /**
-    * Gets the current message count of pending messages
-    * within the destination waiting for dispatch
-    *
-    * @return int message queue depth
-    */
-   public int getMessageCount()
-   {
-      return destQueue.getMessagesAdded() - messageCount;
-   }
-
-
-   /**
-    * Gets the timestamp of the last message add
-    *
-    * @return long      system time
-    */
-   public long getLastUpdate()
-   {
-      return timeLastUpdate;
-   }
-
-   /**
-    * Reset message counter values
-    */
-   public void resetCounter()
-   {
-      messageCount = destQueue.getMessageCount();
-      timeLastUpdate = 0;
-   }
-
-   /**
-    * Get message counter data as string in format
-    *
-    *  "Topic/Queue, Name, Subscription, Durable, Count, CountDelta,
-    *  Depth, DepthDelta, Timestamp Last Increment"  
-    *
-    * @return  String   message counter data string
-    */
-   public String getCounterAsString()
-   {
-      StringBuffer ret = new StringBuffer();
-
-      // name 
-      ret.append(destName).append(",");
-
-      // counter values
-      ret.append("total messages received = ").append(getTotalMessages()).append(",").
-              append("current messages in queue = ").append(getCurrentMessageCount()).append(",").
-              append("current message count = ").append(getMessageCount()).append(",");
-
-      // timestamp last counter update
-      if (timeLastUpdate > 0)
-      {
-         DateFormat dateFormat = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.MEDIUM);
-
-         ret.append("last reset at ").append(dateFormat.format(new Date(timeLastUpdate)));
-      }
-      else
-      {
-         ret.append("-");
-      }
-
-      return ret.toString();
-   }
-
-   /**
-    * Get message counter history day count limit
-    *
-    * <0: unlimited, 0: history disabled, >0: day count
-    */
-   public int getHistoryLimit()
-   {
-      return dayCounterMax;
-   }
-
-   /**
-    * Set message counter history day count limit
-    *
-    * <0: unlimited, 0: history disabled, >0: day count
-    */
-   public void setHistoryLimit(int daycountmax)
-   {
-      boolean bInitialize = false;
-
-      // store new maximum day count
-      dayCounterMax = daycountmax;
-
-      // update day counter array
-      synchronized (dayCounter)
-      {
-         if (dayCounterMax > 0)
-         {
-            // limit day history to specified day count
-            int delta = dayCounter.size() - dayCounterMax;
-
-            for (int i = 0; i < delta; i++)
-            {
-               // reduce array size to requested size by dropping
-               // oldest day counters
-               dayCounter.remove(0);
-            }
-
-            // create initial day counter when empty
-            bInitialize = dayCounter.isEmpty();
-         }
-         else if (dayCounterMax == 0)
-         {
-            // disable history
-            dayCounter.clear();
-         }
-         else
-         {
-            // unlimited day history
-
-            // create initial day counter when empty
-            bInitialize = dayCounter.isEmpty();
-         }
-
-         // optionally initialize first day counter entry
-         if (bInitialize)
-         {
-            dayCounter.add(new DayCounter(new GregorianCalendar(), true));
-         }
-      }
-   }
-
-   /**
-    * Update message counter history
-    */
-   private void updateHistory(boolean incrementCounter)
-   {
-      // check history activation
-      if (dayCounter.isEmpty())
-      {
-         return;
-      }
-
-      // calculate day difference between current date and date of last day counter entry
-      synchronized (dayCounter)
-      {
-         DayCounter counterLast = dayCounter.get(dayCounter.size() - 1);
-
-         GregorianCalendar calNow = new GregorianCalendar();
-         GregorianCalendar calLast = counterLast.getDate();
-
-         // clip day time part for day delta calulation
-         calNow.clear(Calendar.AM_PM);
-         calNow.clear(Calendar.HOUR);
-         calNow.clear(Calendar.HOUR_OF_DAY);
-         calNow.clear(Calendar.MINUTE);
-         calNow.clear(Calendar.SECOND);
-         calNow.clear(Calendar.MILLISECOND);
-
-         calLast.clear(Calendar.AM_PM);
-         calLast.clear(Calendar.HOUR);
-         calLast.clear(Calendar.HOUR_OF_DAY);
-         calLast.clear(Calendar.MINUTE);
-         calLast.clear(Calendar.SECOND);
-         calLast.clear(Calendar.MILLISECOND);
-
-         long millisPerDay = 86400000; // 24 * 60 * 60 * 1000
-         long millisDelta = calNow.getTime().getTime() - calLast.getTime().getTime();
-
-         int dayDelta = (int) (millisDelta / millisPerDay);
-
-         if (dayDelta > 0)
-         {
-            // finalize last day counter
-            counterLast.finalizeDayCounter();
-
-            // add new intermediate empty day counter entries
-            DayCounter counterNew;
-
-            for (int i = 1; i < dayDelta; i++)
-            {
-               // increment date
-               calLast.add(Calendar.DAY_OF_YEAR, 1);
-
-               counterNew = new DayCounter(calLast, false);
-               counterNew.finalizeDayCounter();
-
-               dayCounter.add(counterNew);
-            }
-
-            // add new day counter entry for current day
-            counterNew = new DayCounter(calNow, false);
-
-            dayCounter.add(counterNew);
-
-            // ensure history day count limit
-            setHistoryLimit(dayCounterMax);
-         }
-
-         // update last day counter entry
-         counterLast = dayCounter.get(dayCounter.size() - 1);
-         counterLast.updateDayCounter(incrementCounter);
-      }
-   }
-
-   /**
-    * Reset message counter history
-    */
-   public void resetHistory()
-   {
-      int max = dayCounterMax;
-
-      setHistoryLimit(0);
-      setHistoryLimit(max);
-   }
-
-   /**
-    * Get message counter history data as string in format
-    * 
-    * "day count\n  
-    *  Date 1, hour counter 0, hour counter 1, ..., hour counter 23\n
-    *  Date 2, hour counter 0, hour counter 1, ..., hour counter 23\n
-    *  .....
-    *  .....
-    *  Date n, hour counter 0, hour counter 1, ..., hour counter 23\n"
-    *
-    * @return  String   message history data string
-    */
-   public String getHistoryAsString()
-   {
-      String ret = "";
-
-      // ensure history counters are up to date
-      updateHistory(false);
-
-      // compile string       
-      synchronized (dayCounter)
-      {
-         // first line: history day count  
-         ret += dayCounter.size() + "\n";
-
-         // following lines: day counter data
-         for (DayCounter counter : dayCounter)
-         {
-            ret += counter.getDayCounterAsString() + "\n";
-         }
-      }
-
-      return ret;
-   }
-
-   /**
-    * Internal day counter class for one day hour based counter history
-    */
-   private static class DayCounter
-   {
-      static final int HOURS = 24;
-
-      GregorianCalendar date = null;
-      int[] counters = new int[HOURS];
-
-      /**
-       *    Constructor
-       *
-       * @param date          day counter date
-       * @param isStartDay    true  first day counter
-       *                      false follow up day counter
-       */
-      DayCounter(GregorianCalendar date, boolean isStartDay)
-      {
-         // store internal copy of creation date
-         this.date = (GregorianCalendar) date.clone();
-
-         // initialize the array with '0'- values to current hour (if it is not the
-         // first monitored day) and the rest with default values ('-1')
-         int hour = date.get(Calendar.HOUR_OF_DAY);
-
-         for (int i = 0; i < HOURS; i++)
-         {
-            if (i < hour)
-            {
-               if (isStartDay)
-                  counters[i] = -1;
-               else
-                  counters[i] = 0;
-            }
-            else
-            {
-               counters[i] = -1;
-            }
-         }
-
-         // set the array element of the current hour to '0'
-         counters[hour] = 0;
-      }
-
-      /**
-       * Gets copy of day counter date
-       *
-       * @return GregorianCalendar        day counter date
-       */
-      GregorianCalendar getDate()
-      {
-         return (GregorianCalendar) date.clone();
-      }
-
-      /**
-       * Update day counter hour array elements  
-       *
-       * @param incrementCounter      update current hour counter
-       */
-      void updateDayCounter(boolean incrementCounter)
-      {
-         // get the current hour of the day
-         GregorianCalendar cal = new GregorianCalendar();
-
-         int currentIndex = cal.get(Calendar.HOUR_OF_DAY);
-
-         // check if the last array update is more than 1 hour ago, if so fill all
-         // array elements between the last index and the current index with '0' values
-         boolean bUpdate = false;
-
-         for (int i = 0; i <= currentIndex; i++)
-         {
-            if (counters[i] > -1)
-            {
-               // found first initialized hour counter
-               // -> set all following uninitialized
-               //    counter values to 0
-               bUpdate = true;
-            }
-
-            if (bUpdate)
-            {
-               if (counters[i] == -1)
-                  counters[i] = 0;
-            }
-         }
-
-         // optionally increment current counter
-         if (incrementCounter)
-         {
-            counters[currentIndex]++;
-         }
-      }
-
-      /**
-       * Finalize day counter hour array elements  
-       */
-      void finalizeDayCounter()
-      {
-         // a new day has began, so fill all array elements from index to end with
-         // '0' values
-         boolean bFinalize = false;
-
-         for (int i = 0; i < HOURS; i++)
-         {
-            if (counters[i] > -1)
-            {
-               // found first initialized hour counter
-               // -> finalize all following uninitialized
-               //    counter values
-               bFinalize = true;
-            }
-
-            if (bFinalize)
-            {
-               if (counters[i] == -1)
-                  counters[i] = 0;
-            }
-         }
-      }
-
-      /**
-       * Return day counter data as string with format
-       * "Date, hour counter 0, hour counter 1, ..., hour counter 23"
-       * 
-       * @return  String   day counter data
-       */
-      String getDayCounterAsString()
-      {
-         // first element day counter date
-         DateFormat dateFormat = DateFormat.getDateInstance(DateFormat.SHORT);
-
-         String strData = dateFormat.format(date.getTime());
-
-         // append 24 comma separated hour counter values           
-         for (int i = 0; i < HOURS; i++)
-         {
-            strData += "," + counters[i];
-         }
-
-         return strData;
-      }
-   }
-}
-
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2005, JBoss Inc., and individual contributors as indicated
+* 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.messagecounter;
+
+import java.text.DateFormat;
+import java.util.ArrayList;
+import java.util.Calendar;
+import java.util.Date;
+import java.util.GregorianCalendar;
+import java.util.Iterator;
+import java.util.List;
+
+import org.jboss.logging.Logger;
+import org.jboss.messaging.core.server.Queue;
+
+/**
+ * This class stores message count informations for a given queue
+ * 
+ * At intervals this class samples the queue for message count data
+ * 
+ * Note that the underlying queue *does not* update statistics every time a message
+ * is added since that would reall slow things down, instead we *sample* the queues at
+ * regular intervals - this means we are less intrusive on the queue
+ *
+ * @author <a href="mailto:u.schroeter at mobilcom.de">Ulf Schroeter</a>
+ * @author <a href="mailto:s.steinbacher at mobilcom.de">Stephan Steinbacher</a>
+ * @author <a href="mailto:tim.fox at jboss.com">Tim Fox</a>
+ * @version $Revision: 1.8 $
+ */
+public class MessageCounter
+{
+   protected static final Logger log = Logger.getLogger(MessageCounter.class);
+
+   // destination related information
+   private String destName;
+   private String destSubscription;
+   private boolean destTopic;
+   private boolean destDurable;
+
+   // destination queue
+   private Queue destQueue;
+
+   // counter
+   private int countTotal;
+   private int countTotalLast;
+   private int depthLast;
+   private long timeLastUpdate;
+
+   // per hour day counter history
+   private int dayCounterMax;
+   private ArrayList dayCounter;
+   
+   /**
+    * Get a list of message statistics from a list of message counters
+    * 
+    * @param counter the message counters
+    * @return the message statistics
+    * @throws Exception for any error
+    */
+   public static List getMessageStatistics(List counters) throws Exception
+   {
+      List list = new ArrayList(counters.size());
+      
+      Iterator iter = counters.iterator();
+      
+      while (iter.hasNext())
+      {
+         MessageCounter counter = (MessageCounter)iter.next();
+         
+         MessageStatistics stats = new MessageStatistics();
+         stats.setName(counter.getDestinationName());
+         stats.setSubscriptionID(counter.getDestinationSubscription());
+         stats.setTopic(counter.getDestinationTopic());
+         stats.setDurable(counter.getDestinationDurable());
+         stats.setCount(counter.getCount());
+         stats.setCountDelta(counter.getCountDelta());
+         stats.setDepth(counter.getMessageCount());
+         stats.setDepthDelta(counter.getMessageCountDelta());
+         stats.setTimeLastUpdate(counter.getLastUpdate());
+         
+         list.add(stats);
+      }
+      return list;
+   }
+
+   /**
+    *    Constructor
+    *
+    * @param name             destination name
+    * @param subscription     subscription name
+    * @param queue            internal queue object
+    * @param topic            topic destination flag
+    * @param durable          durable subsciption flag
+    * @param daycountmax      max message history day count
+    */
+   public MessageCounter(String name,
+                         String subscription,
+                         Queue queue,
+                         boolean topic,
+                         boolean durable,
+                         int daycountmax)
+   {
+      // store destination related information
+      destName = name;
+      destSubscription = subscription;
+      destTopic = topic;
+      destDurable = durable;
+      destQueue = queue;      
+
+      // initialize counter
+      resetCounter();
+
+      // initialize message history
+      dayCounter = new ArrayList();
+
+      setHistoryLimit(daycountmax);
+   }
+
+   /**
+   * Get string representation
+   */
+   public String toString()
+   {
+      return getCounterAsString();
+   }
+
+   private int lastMessagesAdded;
+   
+   /*
+    * This method is called periodically to update statistics from the queue
+    */
+   public synchronized void onTimer()
+   {
+      int latestMessagesAdded = destQueue.getMessagesAdded();
+      
+      int newMessagesAdded = latestMessagesAdded - lastMessagesAdded;
+      
+      countTotal += newMessagesAdded;
+      
+      lastMessagesAdded = latestMessagesAdded;
+      
+      //update timestamp
+      timeLastUpdate = System.currentTimeMillis();
+      
+      // update message history
+      updateHistory(newMessagesAdded);
+   }
+
+   /**
+    * Gets the related destination name
+    *
+    * @return String    destination name
+    */
+   public String getDestinationName()
+   {
+      return destName;
+   }
+
+   /**
+    * Gets the related destination subscription
+    *
+    * @return String    destination name
+    */
+   public String getDestinationSubscription()
+   {
+      return destSubscription;
+   }
+
+   /**
+    * Gets the related destination topic flag
+    *
+    * @return boolean    true: topic destination, false: queue destination
+    */
+   public boolean getDestinationTopic()
+   {
+      return destTopic;
+   }
+
+   /**
+    * Gets the related destination durable subscription flag
+    *
+    * @return boolean   true : durable subscription,
+    *                   false: non-durable subscription
+    */
+   public boolean getDestinationDurable()
+   {
+      return destDurable;
+   }
+
+   /**
+    * Gets the total message count since startup or
+    * last counter reset
+    *
+    * @return int    message count
+    */
+   public int getCount()
+   {
+      return countTotal;
+   }
+
+   /**
+    * Gets the message count delta since last method call
+    *
+    * @return int    message count delta
+    */
+   public int getCountDelta()
+   {
+      int delta = countTotal - countTotalLast;
+
+      countTotalLast = countTotal;
+
+      return delta;
+   }
+
+   /**
+    * Gets the current message count of pending messages
+    * within the destination waiting for dispatch
+    *
+    * @return int message queue depth
+    */
+   public int getMessageCount()
+   {
+      return destQueue.getMessageCount();
+   }
+
+   /**
+    * Gets the message count delta of pending messages
+    * since last method call. Therefore
+    *
+    * @return int message queue depth delta
+    */
+   public int getMessageCountDelta()
+   {
+      int current = destQueue.getMessageCount();
+      int delta = current - depthLast;
+
+      depthLast = current;
+
+      return delta;
+   }
+
+   /**
+    * Gets the timestamp of the last message add
+    *
+    * @return long      system time
+    */
+   public long getLastUpdate()
+   {
+      return timeLastUpdate;
+   }
+
+   /**
+    * Reset message counter values
+    */
+   public void resetCounter()
+   {
+      countTotal = 0;
+      countTotalLast = 0;
+      depthLast = 0;
+      timeLastUpdate = 0;
+   }
+
+   /**
+    * Get message counter data as string in format
+    *
+    *  "Topic/Queue, Name, Subscription, Durable, Count, CountDelta,
+    *  Depth, DepthDelta, Timestamp Last Increment"  
+    *
+    * @return  String   message counter data string
+    */
+   public String getCounterAsString()
+   {
+      StringBuffer ret = new StringBuffer();
+
+      // Topic/Queue
+      if (destTopic)
+         ret.append("Topic,");
+      else
+         ret.append("Queue,");
+
+      // name 
+      ret.append(destName).append(",");
+
+      // subscription
+      if (destSubscription != null)
+         ret.append(destSubscription).append(",");
+      else
+         ret.append("-,");
+
+      // Durable subscription
+      if (destTopic)
+      {
+         // Topic
+         if (destDurable)
+            ret.append("true,");
+         else
+            ret.append("false,");
+      }
+      else
+      {
+         // Queue
+         ret.append("-,");
+      }
+
+      // counter values
+      ret.append(getCount()).append(",").append(getCountDelta()).append(",").append(getMessageCount()).append(",").append(getMessageCountDelta()).append(",");
+
+      // timestamp last counter update
+      if (timeLastUpdate > 0)
+      {
+         DateFormat dateFormat = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.MEDIUM);
+
+         ret.append(dateFormat.format(new Date(timeLastUpdate)));
+      }
+      else
+      {
+         ret.append("-");
+      }
+
+      return ret.toString();
+   }
+
+   /**
+    * Get message counter history day count limit
+    *
+    * <0: unlimited, 0: history disabled, >0: day count
+    */
+   public int getHistoryLimit()
+   {
+      return dayCounterMax;
+   }
+
+   /**
+    * Set message counter history day count limit
+    *
+    * <0: unlimited, 0: history disabled, >0: day count
+    */
+   public void setHistoryLimit(int daycountmax)
+   {
+      boolean bInitialize = false;
+
+      // store new maximum day count
+      dayCounterMax = daycountmax;
+
+      // update day counter array
+      synchronized (dayCounter)
+      {
+         if (dayCounterMax > 0)
+         {
+            // limit day history to specified day count
+            int delta = dayCounter.size() - dayCounterMax;
+
+            for (int i = 0; i < delta; i++)
+            {
+               // reduce array size to requested size by dropping
+               // oldest day counters
+               dayCounter.remove(0);
+            }
+
+            // create initial day counter when empty
+            bInitialize = dayCounter.isEmpty();
+         }
+         else if (dayCounterMax == 0)
+         {
+            // disable history
+            dayCounter.clear();
+         }
+         else
+         {
+            // unlimited day history
+
+            // create initial day counter when empty
+            bInitialize = dayCounter.isEmpty();
+         }
+
+         // optionally initialize first day counter entry
+         if (bInitialize)
+         {
+            dayCounter.add(new DayCounter(new GregorianCalendar(), true));
+         }
+      }
+   }
+
+   /**
+    * Update message counter history
+    * 
+    * @param newMessages number of new messages to add to the latest day counter
+    */
+   private void updateHistory(int newMessages)
+   {
+      // check history activation
+      if (dayCounter.isEmpty())
+      {
+         return;
+      }
+
+      // calculate day difference between current date and date of last day counter entry
+      synchronized (dayCounter)
+      {
+         DayCounter counterLast = (DayCounter) dayCounter.get(dayCounter.size() - 1);
+
+         GregorianCalendar calNow = new GregorianCalendar();
+         GregorianCalendar calLast = counterLast.getDate();
+
+         // clip day time part for day delta calulation
+         calNow.clear(Calendar.AM_PM);
+         calNow.clear(Calendar.HOUR);
+         calNow.clear(Calendar.HOUR_OF_DAY);
+         calNow.clear(Calendar.MINUTE);
+         calNow.clear(Calendar.SECOND);
+         calNow.clear(Calendar.MILLISECOND);
+
+         calLast.clear(Calendar.AM_PM);
+         calLast.clear(Calendar.HOUR);
+         calLast.clear(Calendar.HOUR_OF_DAY);
+         calLast.clear(Calendar.MINUTE);
+         calLast.clear(Calendar.SECOND);
+         calLast.clear(Calendar.MILLISECOND);
+
+         long millisPerDay = 86400000; // 24 * 60 * 60 * 1000
+         long millisDelta = calNow.getTime().getTime() - calLast.getTime().getTime();
+
+         int dayDelta = (int) (millisDelta / millisPerDay);
+
+         if (dayDelta > 0)
+         {
+            // finalize last day counter
+            counterLast.finalizeDayCounter();
+
+            // add new intermediate empty day counter entries
+            DayCounter counterNew;
+
+            for (int i = 1; i < dayDelta; i++)
+            {
+               // increment date
+               calLast.add(Calendar.DAY_OF_YEAR, 1);
+
+               counterNew = new DayCounter(calLast, false);
+               counterNew.finalizeDayCounter();
+
+               dayCounter.add(counterNew);
+            }
+
+            // add new day counter entry for current day
+            counterNew = new DayCounter(calNow, false);
+
+            dayCounter.add(counterNew);
+
+            // ensure history day count limit
+            setHistoryLimit(dayCounterMax);
+         }
+
+         // update last day counter entry
+         counterLast = (DayCounter) dayCounter.get(dayCounter.size() - 1);
+         counterLast.updateDayCounter(newMessages);
+      }
+   }
+
+   /**
+    * Reset message counter history
+    */
+   public void resetHistory()
+   {
+      int max = dayCounterMax;
+
+      setHistoryLimit(0);
+      setHistoryLimit(max);
+   }
+
+   public List<DayCounter> getHistory()
+   {
+      updateHistory(0);
+      
+      return new ArrayList<DayCounter>(dayCounter);
+   }
+   
+   /**
+    * Get message counter history data as string in format
+    * 
+    * "day count\n  
+    *  Date 1, hour counter 0, hour counter 1, ..., hour counter 23\n
+    *  Date 2, hour counter 0, hour counter 1, ..., hour counter 23\n
+    *  .....
+    *  .....
+    *  Date n, hour counter 0, hour counter 1, ..., hour counter 23\n"
+    *
+    * @return  String   message history data string
+    */
+   public String getHistoryAsString()
+   {
+      String ret = "";
+
+      // ensure history counters are up to date
+      updateHistory(0);
+
+      // compile string       
+      synchronized (dayCounter)
+      {
+         // first line: history day count  
+         ret += dayCounter.size() + "\n";
+
+         // following lines: day counter data
+         for (int i = 0; i < dayCounter.size(); i++)
+         {
+            DayCounter counter = (DayCounter) dayCounter.get(i);
+
+            ret += counter.getDayCounterAsString() + "\n";
+         }
+      }
+
+      return ret;
+   }
+
+   /**
+    * Internal day counter class for one day hour based counter history
+    */
+   public static class DayCounter
+   {
+      static final int HOURS = 24;
+
+      GregorianCalendar date = null;
+      int[] counters = new int[HOURS];
+
+      /**
+       *    Constructor
+       *
+       * @param date          day counter date
+       * @param isStartDay    true  first day counter
+       *                      false follow up day counter
+       */
+      DayCounter(GregorianCalendar date, boolean isStartDay)
+      {
+         // store internal copy of creation date
+         this.date = (GregorianCalendar) date.clone();
+
+         // initialize the array with '0'- values to current hour (if it is not the
+         // first monitored day) and the rest with default values ('-1')
+         int hour = date.get(Calendar.HOUR_OF_DAY);
+
+         for (int i = 0; i < HOURS; i++)
+         {
+            if (i < hour)
+            {
+               if (isStartDay)
+                  counters[i] = -1;
+               else
+                  counters[i] = 0;
+            }
+            else
+            {
+               counters[i] = -1;
+            }
+         }
+
+         // set the array element of the current hour to '0'
+         counters[hour] = 0;
+      }
+
+      /**
+       * Gets copy of day counter date
+       *
+       * @return GregorianCalendar        day counter date
+       */
+      public GregorianCalendar getDate()
+      {
+         return (GregorianCalendar) date.clone();
+      }
+
+      public int[] getCounters()
+      {
+          return counters;
+      }
+      
+      /**
+       * Update day counter hour array elements  
+       *
+       * @param newMessages number of new messages since the counter was last updated.
+       */
+      void updateDayCounter(int newMessages)
+      {
+         // get the current hour of the day
+         GregorianCalendar cal = new GregorianCalendar();
+
+         int currentIndex = cal.get(Calendar.HOUR_OF_DAY);
+
+         // check if the last array update is more than 1 hour ago, if so fill all
+         // array elements between the last index and the current index with '0' values
+         boolean bUpdate = false;
+
+         for (int i = 0; i <= currentIndex; i++)
+         {
+            if (counters[i] > -1)
+            {
+               // found first initialized hour counter
+               // -> set all following uninitialized
+               //    counter values to 0
+               bUpdate = true;
+            }
+
+            if (bUpdate == true)
+            {
+               if (counters[i] == -1)
+                  counters[i] = 0;
+            }
+         }
+
+         // increment current counter with the new messages
+         counters[currentIndex] += newMessages;
+      }
+
+      /**
+       * Finalize day counter hour array elements  
+       */
+      void finalizeDayCounter()
+      {
+         // a new day has began, so fill all array elements from index to end with
+         // '0' values
+         boolean bFinalize = false;
+
+         for (int i = 0; i < HOURS; i++)
+         {
+            if (counters[i] > -1)
+            {
+               // found first initialized hour counter
+               // -> finalize all following uninitialized
+               //    counter values
+               bFinalize = true;
+            }
+
+            if (bFinalize)
+            {
+               if (counters[i] == -1)
+                  counters[i] = 0;
+            }
+         }
+      }
+
+      /**
+       * Return day counter data as string with format
+       * "Date, hour counter 0, hour counter 1, ..., hour counter 23"
+       * 
+       * @return  String   day counter data
+       */
+      String getDayCounterAsString()
+      {
+         // first element day counter date
+         DateFormat dateFormat = DateFormat.getDateInstance(DateFormat.SHORT);
+
+         String strData = dateFormat.format(date.getTime());
+
+         // append 24 comma separated hour counter values           
+         for (int i = 0; i < HOURS; i++)
+         {
+            strData += "," + counters[i];
+         }
+
+         return strData;
+      }
+   }
+}
+

Added: trunk/src/main/org/jboss/messaging/core/messagecounter/MessageCounterManager.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/messagecounter/MessageCounterManager.java	                        (rev 0)
+++ trunk/src/main/org/jboss/messaging/core/messagecounter/MessageCounterManager.java	2008-08-27 15:07:23 UTC (rev 4881)
@@ -0,0 +1,48 @@
+/*
+ * 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.messagecounter;
+
+
+/**
+ * @author <a href="mailto:jmesnil at redhat.com">Jeff Mesnil</a>
+ *
+ * @version <tt>$Revision$</tt>
+ *
+ */
+public interface MessageCounterManager
+{
+
+   public abstract void start();
+
+   public abstract void stop();
+
+   public abstract void registerMessageCounter(String name,
+         MessageCounter counter);
+
+   public abstract MessageCounter unregisterMessageCounter(String name);
+
+   public abstract void resetAllCounters();
+
+   public abstract void resetAllCounterHistories();
+
+}
\ No newline at end of file

Added: trunk/src/main/org/jboss/messaging/core/messagecounter/MessageStatistics.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/messagecounter/MessageStatistics.java	                        (rev 0)
+++ trunk/src/main/org/jboss/messaging/core/messagecounter/MessageStatistics.java	2008-08-27 15:07:23 UTC (rev 4881)
@@ -0,0 +1,338 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2005, JBoss Inc., and individual contributors as indicated
+* 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.messagecounter;
+
+import java.io.Serializable;
+import java.text.DateFormat;
+import java.util.Date;
+
+/**
+ * Message statistics
+ * 
+ * @author <a href="mailto:adrian at jboss.org">Adrian Brock</a>
+ * @version <tt>$Revision: 1.3 $</tt>
+ */
+public class MessageStatistics implements Serializable
+{
+   // Constants -----------------------------------------------------
+
+   /** The serialVersionUID */
+   static final long serialVersionUID = 8056884098781414022L;
+
+   // Attributes ----------------------------------------------------
+
+   /** Whether we are topic */
+   private boolean topic;
+
+   /** Whether we are durable */
+   private boolean durable;
+
+   /** The name */
+   private String name;
+
+   /** The subscription id */
+   private String subscriptionID;
+
+   /** The message count */
+   private int count;
+
+   /** The message count delta */
+   private int countDelta;
+
+   /** The message depth */
+   private int depth;
+
+   /** The message depth delta */
+   private int depthDelta;
+
+   /** The last update */
+   private long timeLastUpdate;
+
+   // Static --------------------------------------------------------
+
+   // Constructors --------------------------------------------------
+
+   /**
+    * Construct a new Message Statistics
+    */
+   public MessageStatistics()
+   {
+   }
+
+   // Public --------------------------------------------------------
+
+   /**
+    * Get the count.
+    * 
+    * @return Returns the count.
+    */
+   public int getCount()
+   {
+      return count;
+   }
+
+   /**
+    * Set the count.
+    * 
+    * @param count The count to set.
+    */
+   public void setCount(int count)
+   {
+      this.count = count;
+   }
+
+   /**
+    * Get the countDelta.
+    * 
+    * @return Returns the countDelta.
+    */
+   public int getCountDelta()
+   {
+      return countDelta;
+   }
+
+   /**
+    * Set the countDelta.
+    * 
+    * @param countDelta The countDelta to set.
+    */
+   public void setCountDelta(int countDelta)
+   {
+      this.countDelta = countDelta;
+   }
+
+   /**
+    * Get the depth.
+    * 
+    * @return Returns the depth.
+    */
+   public int getDepth()
+   {
+      return depth;
+   }
+
+   /**
+    * Set the depth.
+    * 
+    * @param depth The depth to set.
+    */
+   public void setDepth(int depth)
+   {
+      this.depth = depth;
+   }
+
+   /**
+    * Get the depthDelta.
+    * 
+    * @return Returns the depthDelta.
+    */
+   public int getDepthDelta()
+   {
+      return depthDelta;
+   }
+
+   /**
+    * Set the depthDelta.
+    * 
+    * @param depthDelta The depthDelta to set.
+    */
+   public void setDepthDelta(int depthDelta)
+   {
+      this.depthDelta = depthDelta;
+   }
+
+   /**
+    * Get the durable.
+    * 
+    * @return Returns the durable.
+    */
+   public boolean isDurable()
+   {
+      return durable;
+   }
+
+   /**
+    * Set the durable.
+    * 
+    * @param durable The durable to set.
+    */
+   public void setDurable(boolean durable)
+   {
+      this.durable = durable;
+   }
+
+   /**
+    * Get the name.
+    * 
+    * @return Returns the name.
+    */
+   public String getName()
+   {
+      return name;
+   }
+
+   /**
+    * Set the name.
+    * 
+    * @param name The name to set.
+    */
+   public void setName(String name)
+   {
+      this.name = name;
+   }
+
+   /**
+    * Get the subscriptionID.
+    * 
+    * @return Returns the subscriptionID.
+    */
+   public String getSubscriptionID()
+   {
+      return subscriptionID;
+   }
+
+   /**
+    * Set the subscriptionID.
+    * 
+    * @param subscriptionID The subscriptionID to set.
+    */
+   public void setSubscriptionID(String subscriptionID)
+   {
+      this.subscriptionID = subscriptionID;
+   }
+
+   /**
+    * Get the timeLastUpdate.
+    * 
+    * @return Returns the timeLastUpdate.
+    */
+   public long getTimeLastUpdate()
+   {
+      return timeLastUpdate;
+   }
+
+   /**
+    * Set the timeLastUpdate.
+    * 
+    * @param timeLastUpdate The timeLastUpdate to set.
+    */
+   public void setTimeLastUpdate(long timeLastUpdate)
+   {
+      this.timeLastUpdate = timeLastUpdate;
+   }
+
+   /**
+    * Get the topic.
+    * 
+    * @return Returns the topic.
+    */
+   public boolean isTopic()
+   {
+      return topic;
+   }
+
+   /**
+    * Set the topic.
+    * 
+    * @param topic The topic to set.
+    */
+   public void setTopic(boolean topic)
+   {
+      this.topic = topic;
+   }
+
+   /**
+    * Get message data as string in format
+    *
+    *  "Topic/Queue, Name, Subscription, Durable, Count, CountDelta,
+    *  Depth, DepthDelta, Timestamp Last Increment"  
+    *
+    * @return  String data as a string
+    */
+   public String getAsString()
+   {
+      StringBuffer buffer = new StringBuffer(50);
+
+      // Topic/Queue
+      if (topic)
+         buffer.append("Topic,");
+      else
+         buffer.append("Queue,");
+
+      // name 
+      buffer.append(name).append(',');
+
+      // subscription
+      if (subscriptionID != null)
+         buffer.append(subscriptionID).append(',');
+      else
+         buffer.append("-,");
+
+      // Durable subscription
+      if (topic)
+      {
+         // Topic
+         if (durable)
+            buffer.append("DURABLE,");
+         else
+            buffer.append("NONDURABLE,");
+      }
+      else
+      {
+         buffer.append("-,");
+      }
+
+      // counter values
+      buffer.append(count).append(',').append(countDelta).append(',').append(depth).append(',').append(depthDelta)
+            .append(',');
+
+      // timestamp last counter update
+      if (timeLastUpdate > 0)
+      {
+         DateFormat dateFormat = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.MEDIUM);
+
+         buffer.append(dateFormat.format(new Date(timeLastUpdate)));
+      }
+      else
+      {
+         buffer.append('-');
+      }
+
+      return buffer.toString();
+   }
+
+   // Object overrides ----------------------------------------------
+
+   public String toString()
+   {
+      return getAsString();
+   }
+
+   // Package protected ---------------------------------------------
+
+   // Protected -----------------------------------------------------
+
+   // Private -------------------------------------------------------
+
+   // Inner classes -------------------------------------------------
+
+}
\ No newline at end of file

Added: trunk/src/main/org/jboss/messaging/core/messagecounter/impl/MessageCounterManagerImpl.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/messagecounter/impl/MessageCounterManagerImpl.java	                        (rev 0)
+++ trunk/src/main/org/jboss/messaging/core/messagecounter/impl/MessageCounterManagerImpl.java	2008-08-27 15:07:23 UTC (rev 4881)
@@ -0,0 +1,203 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * 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.messagecounter.impl;
+
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.Set;
+import java.util.Timer;
+import java.util.TimerTask;
+
+import org.jboss.logging.Logger;
+import org.jboss.messaging.core.messagecounter.MessageCounter;
+import org.jboss.messaging.core.messagecounter.MessageCounterManager;
+
+/**
+ * 
+ * A MessageCounterManager
+ *
+ * @author <a href="mailto:tim.fox at jboss.com">Tim Fox</a>
+ * @version <tt>$Revision: 3307 $</tt>
+ *
+ * $Id: MessageCounterManager.java 3307 2007-11-09 20:43:00Z timfox $
+ *
+ */
+public class MessageCounterManagerImpl implements MessageCounterManager
+{
+   private static final Logger log = Logger.getLogger(MessageCounterManagerImpl.class);
+   
+   private Map<String, MessageCounter> messageCounters;
+   
+   private boolean started;
+   
+   private Timer timer;
+   
+   private long period;
+   
+   private PingMessageCountersTask task;
+          
+   public MessageCounterManagerImpl(long period)
+   {
+      messageCounters = new HashMap<String, MessageCounter>();
+      
+      this.period = period;
+   }
+
+   public synchronized void start()
+   {
+      if (started)
+      {  
+         return;
+      }
+      
+      // Needs to be daemon
+      timer = new Timer(true);
+      
+      task = new PingMessageCountersTask();
+            
+      timer.schedule(task, 0, period);      
+      
+      started = true;      
+   }
+
+   public synchronized void stop()
+   { 
+      if (!started)
+      {
+         return;
+      }
+      
+      //Wait for timer task to stop
+      
+      task.stop();
+      
+      timer.cancel();
+      
+      timer = null;
+      
+      started = false;
+   }
+   
+   public synchronized void reschedule(long newPeriod)
+   {
+      boolean wasStarted = this.started;
+      
+      if (wasStarted)
+      {
+         stop();
+      }
+      
+      period = newPeriod;
+      
+      if (wasStarted)
+      {
+         start();
+      }
+   }
+   
+   public void registerMessageCounter(String name, MessageCounter counter)
+   {
+      synchronized (messageCounters)
+      {
+         messageCounters.put(name, counter);
+      }
+   }
+   
+   public MessageCounter unregisterMessageCounter(String name)
+   {
+      synchronized (messageCounters)
+      {
+         return (MessageCounter)messageCounters.remove(name);
+      }
+   }
+   
+   public Set<MessageCounter> getMessageCounters()
+   {
+      synchronized (messageCounters)
+      {
+         return new HashSet<MessageCounter>(messageCounters.values());
+      }
+   }
+   
+   public MessageCounter getMessageCounter(String name)
+   {
+      synchronized (messageCounters)
+      {
+         return (MessageCounter)messageCounters.get(name);
+      }
+   }
+   
+   public void resetAllCounters()
+   {
+      synchronized (messageCounters)
+      {
+         Iterator<MessageCounter> iter = messageCounters.values().iterator();
+         
+         while (iter.hasNext())
+         {
+            MessageCounter counter = (MessageCounter)iter.next();
+            
+            counter.resetCounter();
+         }
+      }
+   }
+   
+   public void resetAllCounterHistories()
+   {
+      synchronized (messageCounters)
+      {
+         Iterator<MessageCounter> iter = messageCounters.values().iterator();
+         
+         while (iter.hasNext())
+         {
+            MessageCounter counter = (MessageCounter)iter.next();
+            
+            counter.resetHistory();
+         }
+      }
+   }
+   
+   class PingMessageCountersTask extends TimerTask
+   {
+      public synchronized void run()
+      {
+         synchronized (messageCounters)
+         {
+            Iterator<MessageCounter> iter = messageCounters.values().iterator();
+            
+            while (iter.hasNext())
+            {
+               MessageCounter counter = (MessageCounter)iter.next();
+               
+               counter.onTimer();
+            }
+         }
+      }  
+                        
+      synchronized void stop()
+      {
+         cancel();
+      }
+   }
+}

Modified: trunk/tests/src/org/jboss/messaging/tests/unit/core/management/impl/ManagementServiceImplTest.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/tests/unit/core/management/impl/ManagementServiceImplTest.java	2008-08-27 14:10:45 UTC (rev 4880)
+++ trunk/tests/src/org/jboss/messaging/tests/unit/core/management/impl/ManagementServiceImplTest.java	2008-08-27 15:07:23 UTC (rev 4881)
@@ -221,6 +221,7 @@
       MBeanServer mbeanServer = createMock(MBeanServer.class);
       Queue queue = createMock(Queue.class);
       expect(queue.getName()).andStubReturn(name);
+      expect(queue.isDurable()).andReturn(true);
       StorageManager storageManager = createMock(StorageManager.class);
       expect(mbeanServer.isRegistered(objectName)).andReturn(false);
       expect(
@@ -247,6 +248,7 @@
       MBeanServer mbeanServer = createMock(MBeanServer.class);
       Queue queue = createMock(Queue.class);
       expect(queue.getName()).andStubReturn(name);
+      expect(queue.isDurable()).andReturn(true);
       StorageManager storageManager = createMock(StorageManager.class);
       expect(mbeanServer.isRegistered(objectName)).andReturn(true);
       mbeanServer.unregisterMBean(objectName);

Modified: trunk/tests/src/org/jboss/messaging/tests/unit/core/management/impl/MessagingServerControlTest.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/tests/unit/core/management/impl/MessagingServerControlTest.java	2008-08-27 14:10:45 UTC (rev 4880)
+++ trunk/tests/src/org/jboss/messaging/tests/unit/core/management/impl/MessagingServerControlTest.java	2008-08-27 15:07:23 UTC (rev 4881)
@@ -54,6 +54,7 @@
 import org.jboss.messaging.core.management.impl.ManagementServiceImpl;
 import org.jboss.messaging.core.management.impl.MessagingServerControl;
 import org.jboss.messaging.core.management.impl.MessagingServerControl.NotificationType;
+import org.jboss.messaging.core.messagecounter.MessageCounterManager;
 import org.jboss.messaging.core.persistence.StorageManager;
 import org.jboss.messaging.core.postoffice.Binding;
 import org.jboss.messaging.core.postoffice.PostOffice;
@@ -85,6 +86,7 @@
    private HierarchicalRepository<Set<Role>> securityRepository;
    private HierarchicalRepository<QueueSettings> queueSettingsRepository;
    private MessagingServer server;
+   private MessageCounterManager messageCounterManager;
 
    // Constants -----------------------------------------------------
 
@@ -112,14 +114,12 @@
       boolean started = randomBoolean();
 
       expect(server.isStarted()).andStubReturn(started);
-      replayMocks();
+      replayMockedAttributes();
 
-      MessagingServerControl control = new MessagingServerControl(postOffice,
-            storageManager, configuration, securityRepository,
-            queueSettingsRepository, server);
+      MessagingServerControl control = createControl();
       assertEquals(started, control.isStarted());
 
-      verifyMocks();
+      verifyMockedAttributes();
    }
 
    public void testGetVersion() throws Exception
@@ -129,16 +129,14 @@
       Version version = createMock(Version.class);
       expect(version.getFullVersion()).andReturn(fullVersion);
       expect(server.getVersion()).andStubReturn(version);
-      replayMocks();
+      replayMockedAttributes();
       replay(version);
 
-      MessagingServerControl control = new MessagingServerControl(postOffice,
-            storageManager, configuration, securityRepository,
-            queueSettingsRepository, server);
+      MessagingServerControl control = createControl();
       assertEquals(fullVersion, control.getVersion());
 
       verify(version);
-      verifyMocks();
+      verifyMockedAttributes();
    }
 
    public void testGetBindingsDirectory() throws Exception
@@ -146,14 +144,12 @@
       String dir = randomString();
 
       expect(configuration.getBindingsDirectory()).andReturn(dir);
-      replayMocks();
+      replayMockedAttributes();
 
-      MessagingServerControl control = new MessagingServerControl(postOffice,
-            storageManager, configuration, securityRepository,
-            queueSettingsRepository, server);
+      MessagingServerControl control = createControl();
       assertEquals(dir, control.getBindingsDirectory());
 
-      verifyMocks();
+      verifyMockedAttributes();
    }
 
    public void testGetInterceptorClassNames() throws Exception
@@ -162,14 +158,12 @@
       list.add(randomString());
 
       expect(configuration.getInterceptorClassNames()).andReturn(list);
-      replayMocks();
+      replayMockedAttributes();
 
-      MessagingServerControl control = new MessagingServerControl(postOffice,
-            storageManager, configuration, securityRepository,
-            queueSettingsRepository, server);
+      MessagingServerControl control = createControl();
       assertEquals(list, control.getInterceptorClassNames());
 
-      verifyMocks();
+      verifyMockedAttributes();
    }
 
    public void testGetJournalDirectory() throws Exception
@@ -177,14 +171,12 @@
       String dir = randomString();
 
       expect(configuration.getJournalDirectory()).andReturn(dir);
-      replayMocks();
+      replayMockedAttributes();
 
-      MessagingServerControl control = new MessagingServerControl(postOffice,
-            storageManager, configuration, securityRepository,
-            queueSettingsRepository, server);
+      MessagingServerControl control = createControl();
       assertEquals(dir, control.getJournalDirectory());
 
-      verifyMocks();
+      verifyMockedAttributes();
    }
 
    public void testGetJournalFileSize() throws Exception
@@ -192,14 +184,12 @@
       int size = randomInt();
 
       expect(configuration.getJournalFileSize()).andReturn(size);
-      replayMocks();
+      replayMockedAttributes();
 
-      MessagingServerControl control = new MessagingServerControl(postOffice,
-            storageManager, configuration, securityRepository,
-            queueSettingsRepository, server);
+      MessagingServerControl control = createControl();
       assertEquals(size, control.getJournalFileSize());
 
-      verifyMocks();
+      verifyMockedAttributes();
    }
 
    public void testGetJournalMaxAIO() throws Exception
@@ -207,14 +197,12 @@
       int max = randomInt();
 
       expect(configuration.getJournalMaxAIO()).andReturn(max);
-      replayMocks();
+      replayMockedAttributes();
 
-      MessagingServerControl control = new MessagingServerControl(postOffice,
-            storageManager, configuration, securityRepository,
-            queueSettingsRepository, server);
+      MessagingServerControl control = createControl();
       assertEquals(max, control.getJournalMaxAIO());
 
-      verifyMocks();
+      verifyMockedAttributes();
    }
 
    public void testGetJournalMinFiles() throws Exception
@@ -222,27 +210,23 @@
       int minFiles = randomInt();
 
       expect(configuration.getJournalMinFiles()).andReturn(minFiles);
-      replayMocks();
+      replayMockedAttributes();
 
-      MessagingServerControl control = new MessagingServerControl(postOffice,
-            storageManager, configuration, securityRepository,
-            queueSettingsRepository, server);
+      MessagingServerControl control = createControl();
       assertEquals(minFiles, control.getJournalMinFiles());
 
-      verifyMocks();
+      verifyMockedAttributes();
    }
 
    public void testGetJournalType() throws Exception
    {
       expect(configuration.getJournalType()).andReturn(JournalType.ASYNCIO);
-      replayMocks();
+      replayMockedAttributes();
 
-      MessagingServerControl control = new MessagingServerControl(postOffice,
-            storageManager, configuration, securityRepository,
-            queueSettingsRepository, server);
+      MessagingServerControl control = createControl();
       assertEquals(JournalType.ASYNCIO.toString(), control.getJournalType());
 
-      verifyMocks();
+      verifyMockedAttributes();
    }
 
    public void testGetKeyStorePath() throws Exception
@@ -250,14 +234,12 @@
       String path = randomString();
 
       expect(configuration.getKeyStorePath()).andReturn(path);
-      replayMocks();
+      replayMockedAttributes();
 
-      MessagingServerControl control = new MessagingServerControl(postOffice,
-            storageManager, configuration, securityRepository,
-            queueSettingsRepository, server);
+      MessagingServerControl control = createControl();
       assertEquals(path, control.getKeyStorePath());
 
-      verifyMocks();
+      verifyMockedAttributes();
    }
 
    public void testGetLocation() throws Exception
@@ -265,14 +247,12 @@
       Location location = new LocationImpl(TransportType.TCP, "localhost");
 
       expect(configuration.getLocation()).andReturn(location);
-      replayMocks();
+      replayMockedAttributes();
 
-      MessagingServerControl control = new MessagingServerControl(postOffice,
-            storageManager, configuration, securityRepository,
-            queueSettingsRepository, server);
+      MessagingServerControl control = createControl();
       assertEquals(location.toString(), control.getLocation());
 
-      verifyMocks();
+      verifyMockedAttributes();
    }
 
    public void testGetScheduledThreadPoolMaxSize() throws Exception
@@ -280,14 +260,12 @@
       int size = randomInt();
 
       expect(configuration.getScheduledThreadPoolMaxSize()).andReturn(size);
-      replayMocks();
+      replayMockedAttributes();
 
-      MessagingServerControl control = new MessagingServerControl(postOffice,
-            storageManager, configuration, securityRepository,
-            queueSettingsRepository, server);
+      MessagingServerControl control = createControl();
       assertEquals(size, control.getScheduledThreadPoolMaxSize());
 
-      verifyMocks();
+      verifyMockedAttributes();
    }
 
    public void testGetSecurityInvalidationInterval() throws Exception
@@ -296,14 +274,12 @@
 
       expect(configuration.getSecurityInvalidationInterval()).andReturn(
             interval);
-      replayMocks();
+      replayMockedAttributes();
 
-      MessagingServerControl control = new MessagingServerControl(postOffice,
-            storageManager, configuration, securityRepository,
-            queueSettingsRepository, server);
+      MessagingServerControl control = createControl();
       assertEquals(interval, control.getSecurityInvalidationInterval());
 
-      verifyMocks();
+      verifyMockedAttributes();
    }
 
    public void testGetTrustStorePath() throws Exception
@@ -311,14 +287,12 @@
       String path = randomString();
 
       expect(configuration.getTrustStorePath()).andReturn(path);
-      replayMocks();
+      replayMockedAttributes();
 
-      MessagingServerControl control = new MessagingServerControl(postOffice,
-            storageManager, configuration, securityRepository,
-            queueSettingsRepository, server);
+      MessagingServerControl control = createControl();
       assertEquals(path, control.getTrustStorePath());
 
-      verifyMocks();
+      verifyMockedAttributes();
    }
 
    public void testIsClustered() throws Exception
@@ -326,14 +300,12 @@
       boolean clustered = randomBoolean();
 
       expect(configuration.isClustered()).andReturn(clustered);
-      replayMocks();
+      replayMockedAttributes();
 
-      MessagingServerControl control = new MessagingServerControl(postOffice,
-            storageManager, configuration, securityRepository,
-            queueSettingsRepository, server);
+      MessagingServerControl control = createControl();
       assertEquals(clustered, control.isClustered());
 
-      verifyMocks();
+      verifyMockedAttributes();
    }
 
    public void testIsCreateBindingsDir() throws Exception
@@ -341,14 +313,12 @@
       boolean createBindingsDir = randomBoolean();
 
       expect(configuration.isCreateBindingsDir()).andReturn(createBindingsDir);
-      replayMocks();
+      replayMockedAttributes();
 
-      MessagingServerControl control = new MessagingServerControl(postOffice,
-            storageManager, configuration, securityRepository,
-            queueSettingsRepository, server);
+      MessagingServerControl control = createControl();
       assertEquals(createBindingsDir, control.isCreateBindingsDir());
 
-      verifyMocks();
+      verifyMockedAttributes();
    }
 
    public void testIsCreateJournalDir() throws Exception
@@ -356,14 +326,12 @@
       boolean createJournalDir = randomBoolean();
 
       expect(configuration.isCreateJournalDir()).andReturn(createJournalDir);
-      replayMocks();
+      replayMockedAttributes();
 
-      MessagingServerControl control = new MessagingServerControl(postOffice,
-            storageManager, configuration, securityRepository,
-            queueSettingsRepository, server);
+      MessagingServerControl control = createControl();
       assertEquals(createJournalDir, control.isCreateJournalDir());
 
-      verifyMocks();
+      verifyMockedAttributes();
    }
 
    public void testIsJournalSyncNonTransactional() throws Exception
@@ -372,15 +340,13 @@
 
       expect(configuration.isJournalSyncNonTransactional()).andReturn(
             journalSyncNonTransactional);
-      replayMocks();
+      replayMockedAttributes();
 
-      MessagingServerControl control = new MessagingServerControl(postOffice,
-            storageManager, configuration, securityRepository,
-            queueSettingsRepository, server);
+      MessagingServerControl control = createControl();
       assertEquals(journalSyncNonTransactional, control
             .isJournalSyncNonTransactional());
 
-      verifyMocks();
+      verifyMockedAttributes();
    }
 
    public void testIsJournalSyncTransactional() throws Exception
@@ -389,15 +355,13 @@
 
       expect(configuration.isJournalSyncTransactional()).andReturn(
             journalSyncTransactional);
-      replayMocks();
+      replayMockedAttributes();
 
-      MessagingServerControl control = new MessagingServerControl(postOffice,
-            storageManager, configuration, securityRepository,
-            queueSettingsRepository, server);
+      MessagingServerControl control = createControl();
       assertEquals(journalSyncTransactional, control
             .isJournalSyncTransactional());
 
-      verifyMocks();
+      verifyMockedAttributes();
    }
 
    public void testIsRequireDestinations() throws Exception
@@ -406,14 +370,12 @@
 
       expect(configuration.isRequireDestinations()).andReturn(
             requireDestinations);
-      replayMocks();
+      replayMockedAttributes();
 
-      MessagingServerControl control = new MessagingServerControl(postOffice,
-            storageManager, configuration, securityRepository,
-            queueSettingsRepository, server);
+      MessagingServerControl control = createControl();
       assertEquals(requireDestinations, control.isRequireDestinations());
 
-      verifyMocks();
+      verifyMockedAttributes();
    }
 
    public void testIsSSLEnabled() throws Exception
@@ -421,14 +383,12 @@
       boolean sslEnabled = randomBoolean();
 
       expect(configuration.isSSLEnabled()).andReturn(sslEnabled);
-      replayMocks();
+      replayMockedAttributes();
 
-      MessagingServerControl control = new MessagingServerControl(postOffice,
-            storageManager, configuration, securityRepository,
-            queueSettingsRepository, server);
+      MessagingServerControl control = createControl();
       assertEquals(sslEnabled, control.isSSLEnabled());
 
-      verifyMocks();
+      verifyMockedAttributes();
    }
 
    public void testIsSecurityEnabled() throws Exception
@@ -436,14 +396,12 @@
       boolean securityEnabled = randomBoolean();
 
       expect(configuration.isSecurityEnabled()).andReturn(securityEnabled);
-      replayMocks();
+      replayMockedAttributes();
 
-      MessagingServerControl control = new MessagingServerControl(postOffice,
-            storageManager, configuration, securityRepository,
-            queueSettingsRepository, server);
+      MessagingServerControl control = createControl();
       assertEquals(securityEnabled, control.isSecurityEnabled());
 
-      verifyMocks();
+      verifyMockedAttributes();
    }
 
    public void testAddDestination() throws Exception
@@ -453,11 +411,9 @@
 
       expect(postOffice.addDestination(new SimpleString(address), false))
             .andReturn(added);
-      replayMocks();
+      replayMockedAttributes();
 
-      MessagingServerControl control = new MessagingServerControl(postOffice,
-            storageManager, configuration, securityRepository,
-            queueSettingsRepository, server);
+      MessagingServerControl control = createControl();
       mbeanServer.registerMBean(control, serverON);
 
       final CountDownLatch latch = new CountDownLatch(1);
@@ -471,7 +427,7 @@
             MessagingServerControl.NotificationType.ADDRESS_ADDED, listener,
             latch);
 
-      verifyMocks();
+      verifyMockedAttributes();
 
       mbeanServer.removeNotificationListener(serverON, listener);
    }
@@ -483,11 +439,9 @@
 
       expect(postOffice.removeDestination(new SimpleString(address), false))
             .andReturn(removed);
-      replayMocks();
+      replayMockedAttributes();
 
-      MessagingServerControl control = new MessagingServerControl(postOffice,
-            storageManager, configuration, securityRepository,
-            queueSettingsRepository, server);
+      MessagingServerControl control = createControl();
       mbeanServer.registerMBean(control, serverON);
 
       final CountDownLatch latch = new CountDownLatch(1);
@@ -501,7 +455,7 @@
             MessagingServerControl.NotificationType.ADDRESS_REMOVED, listener,
             latch);
 
-      verifyMocks();
+      verifyMockedAttributes();
 
       mbeanServer.removeNotificationListener(serverON, listener);
    }
@@ -516,15 +470,13 @@
       expect(
             postOffice.addBinding(new SimpleString(address), new SimpleString(
                   name), null, true)).andReturn(newBinding);
-      replayMocks();
+      replayMockedAttributes();
       replay(newBinding);
 
-      MessagingServerControl control = new MessagingServerControl(postOffice,
-            storageManager, configuration, securityRepository,
-            queueSettingsRepository, server);
+      MessagingServerControl control = createControl();
       control.createQueue(address, name);
 
-      verifyMocks();
+      verifyMockedAttributes();
       verify(newBinding);
    }
 
@@ -538,12 +490,10 @@
       expect(
             postOffice.addBinding(new SimpleString(address), new SimpleString(
                   name), null, true)).andReturn(newBinding);
-      replayMocks();
+      replayMockedAttributes();
       replay(newBinding);
 
-      MessagingServerControl control = new MessagingServerControl(postOffice,
-            storageManager, configuration, securityRepository,
-            queueSettingsRepository, server);
+      MessagingServerControl control = createControl();
       mbeanServer.registerMBean(control, serverON);
 
       final CountDownLatch latch = new CountDownLatch(1);
@@ -560,7 +510,7 @@
       mbeanServer.removeNotificationListener(serverON, listener);
 
       verify(newBinding);
-      verifyMocks();
+      verifyMockedAttributes();
    }
 
    public void testCreateQueueWithAllParameters() throws Exception
@@ -576,16 +526,14 @@
             postOffice.addBinding(eq(new SimpleString(address)),
                   eq(new SimpleString(name)), isA(Filter.class), eq(durable)
                   )).andReturn(newBinding);
-      replayMocks();
+      replayMockedAttributes();
       replay(newBinding);
 
-      MessagingServerControl control = new MessagingServerControl(postOffice,
-            storageManager, configuration, securityRepository,
-            queueSettingsRepository, server);
+      MessagingServerControl control = createControl();
       control.createQueue(address, name, filter, durable);
 
       verify(newBinding);
-      verifyMocks();
+      verifyMockedAttributes();
    }
 
    public void testCreateQueueWithEmptyFilter() throws Exception
@@ -601,15 +549,13 @@
             postOffice.addBinding(new SimpleString(address), new SimpleString(
                   name), null, durable)).andReturn(newBinding);
       replay(newBinding);
-      replayMocks();
+      replayMockedAttributes();
 
-      MessagingServerControl control = new MessagingServerControl(postOffice,
-            storageManager, configuration, securityRepository,
-            queueSettingsRepository, server);
+      MessagingServerControl control = createControl();
       control.createQueue(address, name, filter, durable);
 
       verify(newBinding);
-      verifyMocks();
+      verifyMockedAttributes();
    }
 
    public void testCreateQueueWithNullFilter() throws Exception
@@ -625,15 +571,13 @@
             postOffice.addBinding(new SimpleString(address), new SimpleString(
                   name), null, durable)).andReturn(newBinding);
       replay(newBinding);
-      replayMocks();
+      replayMockedAttributes();
 
-      MessagingServerControl control = new MessagingServerControl(postOffice,
-            storageManager, configuration, securityRepository,
-            queueSettingsRepository, server);
+      MessagingServerControl control = createControl();
       control.createQueue(address, name, filter, durable);
 
       verify(newBinding);
-      verifyMocks();
+      verifyMockedAttributes();
    }
 
    public void testDestroyQueueAndReceiveNotification() throws Exception
@@ -648,12 +592,10 @@
       queue.deleteAllReferences(storageManager);
       expect(postOffice.removeBinding(new SimpleString(name))).andReturn(
             binding);
-      replayMocks();
+      replayMockedAttributes();
       replay(binding, queue);
 
-      MessagingServerControl control = new MessagingServerControl(postOffice,
-            storageManager, configuration, securityRepository,
-            queueSettingsRepository, server);
+      MessagingServerControl control = createControl();
       mbeanServer.registerMBean(control, serverON);
 
       final CountDownLatch latch = new CountDownLatch(1);
@@ -668,7 +610,7 @@
             latch);
 
       verify(binding, queue);
-      verifyMocks();
+      verifyMockedAttributes();
 
       mbeanServer.removeNotificationListener(serverON, listener);
    }
@@ -678,14 +620,12 @@
       int count = randomInt();
 
       expect(server.getConnectionCount()).andReturn(count);
-      replayMocks();
+      replayMockedAttributes();
 
-      MessagingServerControl control = new MessagingServerControl(postOffice,
-            storageManager, configuration, securityRepository,
-            queueSettingsRepository, server);
+      MessagingServerControl control = createControl();
       assertEquals(count, control.getConnectionCount());
 
-      verifyMocks();
+      verifyMockedAttributes();
    }
 
    // Package protected ---------------------------------------------
@@ -706,6 +646,7 @@
       securityRepository = createMock(HierarchicalRepository.class);
       queueSettingsRepository = createMock(HierarchicalRepository.class);
       server = createMock(MessagingServer.class);
+      messageCounterManager = createMock(MessageCounterManager.class);
    }
 
    @Override
@@ -725,22 +666,31 @@
       securityRepository = null;
       queueSettingsRepository = null;
       server = null;
+      messageCounterManager = null;
 
       super.tearDown();
    }
 
    // Private -------------------------------------------------------
 
-   private void replayMocks()
+   private MessagingServerControl createControl() throws Exception
    {
+      MessagingServerControl control = new MessagingServerControl(postOffice,
+            storageManager, configuration, securityRepository,
+            queueSettingsRepository, server, messageCounterManager);
+      return control;
+   }
+
+   private void replayMockedAttributes()
+   {
       replay(postOffice, storageManager, configuration, securityRepository,
-            queueSettingsRepository, server);
+            queueSettingsRepository, server, messageCounterManager);
    }
 
-   private void verifyMocks()
+   private void verifyMockedAttributes()
    {
       verify(postOffice, storageManager, configuration, securityRepository,
-            queueSettingsRepository, server);
+            queueSettingsRepository, server, messageCounterManager);
    }
 
    // Inner classes -------------------------------------------------

Modified: trunk/tests/src/org/jboss/messaging/tests/unit/core/management/impl/QueueControlTest.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/tests/unit/core/management/impl/QueueControlTest.java	2008-08-27 14:10:45 UTC (rev 4880)
+++ trunk/tests/src/org/jboss/messaging/tests/unit/core/management/impl/QueueControlTest.java	2008-08-27 15:07:23 UTC (rev 4881)
@@ -48,6 +48,7 @@
 import org.jboss.messaging.core.filter.Filter;
 import org.jboss.messaging.core.management.QueueControlMBean;
 import org.jboss.messaging.core.management.impl.QueueControl;
+import org.jboss.messaging.core.messagecounter.MessageCounter;
 import org.jboss.messaging.core.persistence.StorageManager;
 import org.jboss.messaging.core.postoffice.Binding;
 import org.jboss.messaging.core.postoffice.PostOffice;
@@ -70,6 +71,13 @@
 
    // Attributes ----------------------------------------------------
 
+   private Queue queue;
+   private StorageManager storageManager;
+   private PostOffice postOffice;
+   private HierarchicalRepository<QueueSettings> repository;
+   private MessageCounter messageCounter;
+   private SimpleString queueName;
+
    // Static --------------------------------------------------------
 
    // Constructors --------------------------------------------------
@@ -78,298 +86,206 @@
 
    public void testGetName() throws Exception
    {
-      String name = randomString();
+      expect(queue.getName()).andReturn(queueName);
 
-      Queue queue = createMock(Queue.class);
-      expect(queue.getName()).andReturn(new SimpleString(name));
-      StorageManager storageManager = createMock(StorageManager.class);
-      PostOffice postOffice = createMock(PostOffice.class);
-      HierarchicalRepository<QueueSettings> repository = createMock(HierarchicalRepository.class);
+      replayMockedAttributes();
 
-      replay(queue, storageManager, postOffice, repository);
+      QueueControlMBean control = createControl();
+      assertEquals(queueName.toString(), control.getName());
 
-      QueueControlMBean control = new QueueControl(queue, storageManager,
-            postOffice, repository);
-      assertEquals(name, control.getName());
-
-      verify(queue, storageManager, postOffice, repository);
+      verifyMockedAttributes();
    }
 
    public void testGetFilter() throws Exception
    {
       String filterStr = "color = 'green'";
-      Queue queue = createMock(Queue.class);
       Filter filter = createMock(Filter.class);
       expect(filter.getFilterString()).andReturn(new SimpleString(filterStr));
       expect(queue.getFilter()).andReturn(filter);
-      StorageManager storageManager = createMock(StorageManager.class);
-      PostOffice postOffice = createMock(PostOffice.class);
-      HierarchicalRepository<QueueSettings> repository = createMock(HierarchicalRepository.class);
 
-      replay(queue, storageManager, postOffice, repository, filter);
+      replayMockedAttributes();
+      replay(filter);
 
-      QueueControlMBean control = new QueueControl(queue, storageManager,
-            postOffice, repository);
+      QueueControlMBean control = createControl();
       assertEquals(filterStr, control.getFilter());
 
-      verify(queue, storageManager, postOffice, repository, filter);
+      verifyMockedAttributes();
+      verify(filter);
    }
 
    public void testGetFilterWithNull() throws Exception
    {
-      Queue queue = createMock(Queue.class);
       expect(queue.getFilter()).andReturn(null);
-      StorageManager storageManager = createMock(StorageManager.class);
-      PostOffice postOffice = createMock(PostOffice.class);
-      HierarchicalRepository<QueueSettings> repository = createMock(HierarchicalRepository.class);
 
-      replay(queue, storageManager, postOffice, repository);
+      replayMockedAttributes();
 
-      QueueControlMBean control = new QueueControl(queue, storageManager,
-            postOffice, repository);
+      QueueControlMBean control = createControl();
       assertNull(control.getFilter());
 
-      verify(queue, storageManager, postOffice, repository);
+      verifyMockedAttributes();
    }
 
    public void testIsClustered() throws Exception
    {
       boolean clustered = randomBoolean();
-
-      Queue queue = createMock(Queue.class);
       expect(queue.isClustered()).andReturn(clustered);
-      StorageManager storageManager = createMock(StorageManager.class);
-      PostOffice postOffice = createMock(PostOffice.class);
-      HierarchicalRepository<QueueSettings> repository = createMock(HierarchicalRepository.class);
 
-      replay(queue, storageManager, postOffice, repository);
+      replayMockedAttributes();
 
-      QueueControlMBean control = new QueueControl(queue, storageManager,
-            postOffice, repository);
+      QueueControlMBean control = createControl();
       assertEquals(clustered, control.isClustered());
 
-      verify(queue, storageManager, postOffice, repository);
+      verifyMockedAttributes();
    }
 
    public void testIsDurable() throws Exception
    {
       boolean durable = randomBoolean();
-
-      Queue queue = createMock(Queue.class);
       expect(queue.isDurable()).andReturn(durable);
-      StorageManager storageManager = createMock(StorageManager.class);
-      PostOffice postOffice = createMock(PostOffice.class);
-      HierarchicalRepository<QueueSettings> repository = createMock(HierarchicalRepository.class);
 
-      replay(queue, storageManager, postOffice, repository);
+      replayMockedAttributes();
 
-      QueueControlMBean control = new QueueControl(queue, storageManager,
-            postOffice, repository);
+      QueueControlMBean control = createControl();
       assertEquals(durable, control.isDurable());
 
-      verify(queue, storageManager, postOffice, repository);
+      verifyMockedAttributes();
    }
 
    public void testIsTemporary() throws Exception
    {
       boolean temp = randomBoolean();
-
-      Queue queue = createMock(Queue.class);
       expect(queue.isDurable()).andReturn(temp);
-      StorageManager storageManager = createMock(StorageManager.class);
-      PostOffice postOffice = createMock(PostOffice.class);
-      HierarchicalRepository<QueueSettings> repository = createMock(HierarchicalRepository.class);
 
-      replay(queue, storageManager, postOffice, repository);
+      replayMockedAttributes();
 
-      QueueControlMBean control = new QueueControl(queue, storageManager,
-            postOffice, repository);
+      QueueControlMBean control = createControl();
       assertEquals(temp, control.isTemporary());
 
       verify(queue, storageManager, postOffice, repository);
    }
-   
+
    public void testIsBackup() throws Exception
    {
       boolean backup = randomBoolean();
-
-      Queue queue = createMock(Queue.class);
       expect(queue.isBackup()).andReturn(backup);
-      StorageManager storageManager = createMock(StorageManager.class);
-      PostOffice postOffice = createMock(PostOffice.class);
-      HierarchicalRepository<QueueSettings> repository = createMock(HierarchicalRepository.class);
 
-      replay(queue, storageManager, postOffice, repository);
+      replayMockedAttributes();
 
-      QueueControlMBean control = new QueueControl(queue, storageManager,
-            postOffice, repository);
+      QueueControlMBean control = createControl();
       assertEquals(backup, control.isBackup());
 
-      verify(queue, storageManager, postOffice, repository);
+      verifyMockedAttributes();
    }
 
    public void testGetMessageCount() throws Exception
    {
       int count = randomInt();
-
-      Queue queue = createMock(Queue.class);
       expect(queue.getMessageCount()).andReturn(count);
-      StorageManager storageManager = createMock(StorageManager.class);
-      PostOffice postOffice = createMock(PostOffice.class);
-      HierarchicalRepository<QueueSettings> repository = createMock(HierarchicalRepository.class);
 
-      replay(queue, storageManager, postOffice, repository);
+      replayMockedAttributes();
 
-      QueueControlMBean control = new QueueControl(queue, storageManager,
-            postOffice, repository);
+      QueueControlMBean control = createControl();
       assertEquals(count, control.getMessageCount());
 
-      verify(queue, storageManager, postOffice, repository);
+      verifyMockedAttributes();
    }
 
    public void testGetMessagesAdded() throws Exception
    {
       int count = randomInt();
-
-      Queue queue = createMock(Queue.class);
       expect(queue.getMessagesAdded()).andReturn(count);
-      StorageManager storageManager = createMock(StorageManager.class);
-      PostOffice postOffice = createMock(PostOffice.class);
-      HierarchicalRepository<QueueSettings> repository = createMock(HierarchicalRepository.class);
 
-      replay(queue, storageManager, postOffice, repository);
+      replayMockedAttributes();
 
-      QueueControlMBean control = new QueueControl(queue, storageManager,
-            postOffice, repository);
+      QueueControlMBean control = createControl();
       assertEquals(count, control.getMessagesAdded());
 
-      verify(queue, storageManager, postOffice, repository);
+      verifyMockedAttributes();
    }
 
    public void testGetMaxSizeBytes() throws Exception
    {
       int size = randomInt();
-
-      Queue queue = createMock(Queue.class);
       expect(queue.getMaxSizeBytes()).andReturn(size);
-      StorageManager storageManager = createMock(StorageManager.class);
-      PostOffice postOffice = createMock(PostOffice.class);
-      HierarchicalRepository<QueueSettings> repository = createMock(HierarchicalRepository.class);
 
-      replay(queue, storageManager, postOffice, repository);
+      replayMockedAttributes();
 
-      QueueControlMBean control = new QueueControl(queue, storageManager,
-            postOffice, repository);
+      QueueControlMBean control = createControl();
       assertEquals(size, control.getMaxSizeBytes());
 
-      verify(queue, storageManager, postOffice, repository);
+      verifyMockedAttributes();
    }
 
    public void testGetSizeBytes() throws Exception
    {
       int size = randomInt();
-
-      Queue queue = createMock(Queue.class);
       expect(queue.getSizeBytes()).andReturn(size);
-      StorageManager storageManager = createMock(StorageManager.class);
-      PostOffice postOffice = createMock(PostOffice.class);
-      HierarchicalRepository<QueueSettings> repository = createMock(HierarchicalRepository.class);
 
-      replay(queue, storageManager, postOffice, repository);
+      replayMockedAttributes();
 
-      QueueControlMBean control = new QueueControl(queue, storageManager,
-            postOffice, repository);
+      QueueControlMBean control = createControl();
       assertEquals(size, control.getSizeBytes());
 
-      verify(queue, storageManager, postOffice, repository);
+      verifyMockedAttributes();
    }
 
    public void testGetScheduledCount() throws Exception
    {
       int count = randomInt();
-
-      Queue queue = createMock(Queue.class);
       expect(queue.getScheduledCount()).andReturn(count);
-      StorageManager storageManager = createMock(StorageManager.class);
-      PostOffice postOffice = createMock(PostOffice.class);
-      HierarchicalRepository<QueueSettings> repository = createMock(HierarchicalRepository.class);
 
-      replay(queue, storageManager, postOffice, repository);
+      replayMockedAttributes();
 
-      QueueControlMBean control = new QueueControl(queue, storageManager,
-            postOffice, repository);
+      QueueControlMBean control = createControl();
       assertEquals(count, control.getScheduledCount());
 
-      verify(queue, storageManager, postOffice, repository);
+      verifyMockedAttributes();
    }
 
    public void testGetConsumerCount() throws Exception
    {
       int count = randomInt();
-
-      Queue queue = createMock(Queue.class);
       expect(queue.getConsumerCount()).andReturn(count);
-      StorageManager storageManager = createMock(StorageManager.class);
-      PostOffice postOffice = createMock(PostOffice.class);
-      HierarchicalRepository<QueueSettings> repository = createMock(HierarchicalRepository.class);
 
-      replay(queue, storageManager, postOffice, repository);
+      replayMockedAttributes();
 
-      QueueControlMBean control = new QueueControl(queue, storageManager,
-            postOffice, repository);
+      QueueControlMBean control = createControl();
       assertEquals(count, control.getConsumerCount());
 
-      verify(queue, storageManager, postOffice, repository);
+      verifyMockedAttributes();
    }
 
    public void testGetDeliveringCount() throws Exception
    {
       int count = randomInt();
-
-      Queue queue = createMock(Queue.class);
       expect(queue.getDeliveringCount()).andReturn(count);
-      StorageManager storageManager = createMock(StorageManager.class);
-      PostOffice postOffice = createMock(PostOffice.class);
-      HierarchicalRepository<QueueSettings> repository = createMock(HierarchicalRepository.class);
 
-      replay(queue, storageManager, postOffice, repository);
+      replayMockedAttributes();
 
-      QueueControlMBean control = new QueueControl(queue, storageManager,
-            postOffice, repository);
+      QueueControlMBean control = createControl();
       assertEquals(count, control.getDeliveringCount());
 
-      verify(queue, storageManager, postOffice, repository);
+      verifyMockedAttributes();
    }
 
    public void testGetPersistenceID() throws Exception
    {
       long id = randomLong();
-
-      Queue queue = createMock(Queue.class);
       expect(queue.getPersistenceID()).andReturn(id);
-      StorageManager storageManager = createMock(StorageManager.class);
-      PostOffice postOffice = createMock(PostOffice.class);
-      HierarchicalRepository<QueueSettings> repository = createMock(HierarchicalRepository.class);
 
-      replay(queue, storageManager, postOffice, repository);
+      replayMockedAttributes();
 
-      QueueControlMBean control = new QueueControl(queue, storageManager,
-            postOffice, repository);
+      QueueControlMBean control = createControl();
       assertEquals(id, control.getPersistenceID());
 
-      verify(queue, storageManager, postOffice, repository);
+      verifyMockedAttributes();
    }
 
    public void testGetDLQ() throws Exception
    {
-      String queueName = randomString();
       final String dlqName = randomString();
 
-      Queue queue = createMock(Queue.class);
-      expect(queue.getName()).andReturn(new SimpleString(queueName));
-      StorageManager storageManager = createMock(StorageManager.class);
-      PostOffice postOffice = createMock(PostOffice.class);
-      HierarchicalRepository<QueueSettings> repository = createMock(HierarchicalRepository.class);
+      expect(queue.getName()).andReturn(queueName);
       QueueSettings queueSettings = new QueueSettings()
       {
          @Override
@@ -378,27 +294,22 @@
             return new SimpleString(dlqName);
          }
       };
-      expect(repository.getMatch(queueName)).andReturn(queueSettings);
+      expect(repository.getMatch(queueName.toString()))
+            .andReturn(queueSettings);
 
-      replay(queue, storageManager, postOffice, repository);
+      replayMockedAttributes();
 
-      QueueControlMBean control = new QueueControl(queue, storageManager,
-            postOffice, repository);
+      QueueControlMBean control = createControl();
       assertEquals(dlqName, control.getDLQ());
 
-      verify(queue, storageManager, postOffice, repository);
+      verifyMockedAttributes();
    }
 
    public void testGetExpiryQueue() throws Exception
    {
-      String queueName = randomString();
       final String expiryQueueName = randomString();
 
-      Queue queue = createMock(Queue.class);
-      expect(queue.getName()).andReturn(new SimpleString(queueName));
-      StorageManager storageManager = createMock(StorageManager.class);
-      PostOffice postOffice = createMock(PostOffice.class);
-      HierarchicalRepository<QueueSettings> repository = createMock(HierarchicalRepository.class);
+      expect(queue.getName()).andReturn(queueName);
       QueueSettings queueSettings = new QueueSettings()
       {
          @Override
@@ -407,47 +318,37 @@
             return new SimpleString(expiryQueueName);
          }
       };
-      expect(repository.getMatch(queueName)).andReturn(queueSettings);
+      expect(repository.getMatch(queueName.toString()))
+            .andReturn(queueSettings);
 
-      replay(queue, storageManager, postOffice, repository);
+      replayMockedAttributes();
 
-      QueueControlMBean control = new QueueControl(queue, storageManager,
-            postOffice, repository);
+      QueueControlMBean control = createControl();
       assertEquals(expiryQueueName, control.getExpiryQueue());
 
-      verify(queue, storageManager, postOffice, repository);
+      verifyMockedAttributes();
    }
 
    public void testRemoveAllMessages() throws Exception
    {
-      Queue queue = createMock(Queue.class);
-      StorageManager storageManager = createMock(StorageManager.class);
       queue.deleteAllReferences(storageManager);
-      PostOffice postOffice = createMock(PostOffice.class);
-      HierarchicalRepository<QueueSettings> repository = createMock(HierarchicalRepository.class);
 
-      replay(queue, storageManager, postOffice, repository);
+      replayMockedAttributes();
 
-      QueueControlMBean control = new QueueControl(queue, storageManager,
-            postOffice, repository);
+      QueueControlMBean control = createControl();
       control.removeAllMessages();
 
-      verify(queue, storageManager, postOffice, repository);
+      verifyMockedAttributes();
    }
 
    public void testRemoveAllMessagesThrowsException() throws Exception
    {
-      Queue queue = createMock(Queue.class);
-      StorageManager storageManager = createMock(StorageManager.class);
       queue.deleteAllReferences(storageManager);
       expectLastCall().andThrow(new MessagingException());
-      PostOffice postOffice = createMock(PostOffice.class);
-      HierarchicalRepository<QueueSettings> repository = createMock(HierarchicalRepository.class);
 
-      replay(queue, storageManager, postOffice, repository);
+      replayMockedAttributes();
 
-      QueueControlMBean control = new QueueControl(queue, storageManager,
-            postOffice, repository);
+      QueueControlMBean control = createControl();
       try
       {
          control.removeAllMessages();
@@ -457,45 +358,33 @@
 
       }
 
-      verify(queue, storageManager, postOffice, repository);
+      verifyMockedAttributes();
    }
 
    public void testRemoveMessage() throws Exception
    {
       long messageID = randomLong();
       boolean deleted = randomBoolean();
-
-      Queue queue = createMock(Queue.class);
-      StorageManager storageManager = createMock(StorageManager.class);
       expect(queue.deleteReference(messageID, storageManager)).andReturn(
             deleted);
-      PostOffice postOffice = createMock(PostOffice.class);
-      HierarchicalRepository<QueueSettings> repository = createMock(HierarchicalRepository.class);
 
-      replay(queue, storageManager, postOffice, repository);
+      replayMockedAttributes();
 
-      QueueControlMBean control = new QueueControl(queue, storageManager,
-            postOffice, repository);
+      QueueControlMBean control = createControl();
       assertEquals(deleted, control.removeMessage(messageID));
 
-      verify(queue, storageManager, postOffice, repository);
+      verifyMockedAttributes();
    }
 
    public void testRemoveMessageThrowsException() throws Exception
    {
       long messageID = randomLong();
-
-      Queue queue = createMock(Queue.class);
-      StorageManager storageManager = createMock(StorageManager.class);
       expect(queue.deleteReference(messageID, storageManager)).andThrow(
             new MessagingException());
-      PostOffice postOffice = createMock(PostOffice.class);
-      HierarchicalRepository<QueueSettings> repository = createMock(HierarchicalRepository.class);
 
-      replay(queue, storageManager, postOffice, repository);
+      replayMockedAttributes();
 
-      QueueControlMBean control = new QueueControl(queue, storageManager,
-            postOffice, repository);
+      QueueControlMBean control = createControl();
       try
       {
          control.removeMessage(messageID);
@@ -505,7 +394,7 @@
 
       }
 
-      verify(queue, storageManager, postOffice, repository);
+      verifyMockedAttributes();
    }
 
    public void testListMessages() throws Exception
@@ -527,16 +416,12 @@
       expect(message.getPropertyNames()).andReturn(new HashSet<SimpleString>());
       expect(ref.getMessage()).andReturn(message);
       refs.add(ref);
-      Queue queue = createMock(Queue.class);
-      StorageManager storageManager = createMock(StorageManager.class);
       expect(queue.list(isA(Filter.class))).andReturn(refs);
-      PostOffice postOffice = createMock(PostOffice.class);
-      HierarchicalRepository<QueueSettings> repository = createMock(HierarchicalRepository.class);
 
-      replay(queue, storageManager, postOffice, repository, ref, message);
+      replayMockedAttributes();
+      replay(ref, message);
 
-      QueueControlMBean control = new QueueControl(queue, storageManager,
-            postOffice, repository);
+      QueueControlMBean control = createControl();
       TabularData data = control.listMessages(filterStr);
       assertEquals(1, data.size());
       CompositeData info = data.get(new Object[] { message.getMessageID() });
@@ -551,48 +436,37 @@
       assertEquals(message.isExpired(), info.get("expired"));
       assertEquals(message.getExpiration(), info.get("expiration"));
 
-      verify(queue, storageManager, postOffice, repository, ref, message);
+      verifyMockedAttributes();
+      verify(ref, message);
    }
 
    public void testExpireMessageWithMessageID() throws Exception
    {
       long messageID = randomLong();
-
-      Queue queue = createMock(Queue.class);
-      StorageManager storageManager = createMock(StorageManager.class);
-      PostOffice postOffice = createMock(PostOffice.class);
-      HierarchicalRepository<QueueSettings> repository = createMock(HierarchicalRepository.class);
       expect(
             queue.expireMessage(messageID, storageManager, postOffice,
                   repository)).andReturn(true);
 
-      replay(queue, storageManager, postOffice, repository);
+      replayMockedAttributes();
 
-      QueueControlMBean control = new QueueControl(queue, storageManager,
-            postOffice, repository);
+      QueueControlMBean control = createControl();
       assertTrue(control.expireMessage(messageID));
 
-      verify(queue, storageManager, postOffice, repository);
+      verifyMockedAttributes();
    }
 
    public void testExpireMessageWithNoMatch() throws Exception
    {
       long messageID = randomLong();
-
-      Queue queue = createMock(Queue.class);
-      StorageManager storageManager = createMock(StorageManager.class);
-      PostOffice postOffice = createMock(PostOffice.class);
-      HierarchicalRepository<QueueSettings> repository = createMock(HierarchicalRepository.class);
       expect(
             queue.expireMessage(messageID, storageManager, postOffice,
                   repository)).andReturn(false);
-      replay(queue, storageManager, postOffice, repository);
+      replayMockedAttributes();
 
-      QueueControlMBean control = new QueueControl(queue, storageManager,
-            postOffice, repository);
+      QueueControlMBean control = createControl();
       assertFalse(control.expireMessage(messageID));
 
-      verify(queue, storageManager, postOffice, repository);
+      verifyMockedAttributes();
    }
 
    public void testExpireMessagesWithFilter() throws Exception
@@ -611,11 +485,7 @@
       expect(ref_2.getMessage()).andReturn(message_2);
       refs.add(ref_1);
       refs.add(ref_2);
-      Queue queue = createMock(Queue.class);
-      StorageManager storageManager = createMock(StorageManager.class);
       expect(queue.list(isA(Filter.class))).andReturn(refs);
-      PostOffice postOffice = createMock(PostOffice.class);
-      HierarchicalRepository<QueueSettings> repository = createMock(HierarchicalRepository.class);
       expect(
             queue.expireMessage(messageID_1, storageManager, postOffice,
                   repository)).andReturn(true);
@@ -623,55 +493,45 @@
             queue.expireMessage(messageID_2, storageManager, postOffice,
                   repository)).andReturn(true);
 
-      replay(queue, storageManager, postOffice, repository, ref_1, ref_2,
-            message_1, message_2);
+      replayMockedAttributes();
+      replay(ref_1, ref_2, message_1, message_2);
 
-      QueueControlMBean control = new QueueControl(queue, storageManager,
-            postOffice, repository);
+      QueueControlMBean control = createControl();
       assertEquals(2, control.expireMessages("foo = true"));
 
-      verify(queue, storageManager, postOffice, repository, ref_1, ref_2,
-            message_1, message_2);
+      verifyMockedAttributes();
+      verify(ref_1, ref_2, message_1, message_2);
    }
 
    public void testMoveMessage() throws Exception
    {
       long messageID = randomLong();
       SimpleString otherQueueName = randomSimpleString();
-      Queue queue = createMock(Queue.class);
       Binding otherBinding = createMock(Binding.class);
-      StorageManager storageManager = createMock(StorageManager.class);
-      PostOffice postOffice = createMock(PostOffice.class);
       expect(postOffice.getBinding(otherQueueName)).andReturn(otherBinding);
-      HierarchicalRepository<QueueSettings> repository = createMock(HierarchicalRepository.class);
       expect(
             queue.moveMessage(messageID, otherBinding, storageManager,
                   postOffice)).andReturn(true);
 
-      replay(queue, storageManager, postOffice, repository, otherBinding);
+      replayMockedAttributes();
+      replay(otherBinding);
 
-      QueueControlMBean control = new QueueControl(queue, storageManager,
-            postOffice, repository);
+      QueueControlMBean control = createControl();
       assertTrue(control.moveMessage(messageID, otherQueueName.toString()));
 
-      verify(queue, storageManager, postOffice, repository, otherBinding);
+      verifyMockedAttributes();
+      verify(otherBinding);
    }
 
    public void testMoveMessageWithNoQueue() throws Exception
    {
       long messageID = randomLong();
       SimpleString otherQueueName = randomSimpleString();
-
-      Queue queue = createMock(Queue.class);
-      StorageManager storageManager = createMock(StorageManager.class);
-      PostOffice postOffice = createMock(PostOffice.class);
       expect(postOffice.getBinding(otherQueueName)).andReturn(null);
-      HierarchicalRepository<QueueSettings> repository = createMock(HierarchicalRepository.class);
 
-      replay(queue, storageManager, postOffice, repository);
+      replayMockedAttributes();
 
-      QueueControl control = new QueueControl(queue, storageManager,
-            postOffice, repository);
+      QueueControl control = createControl();
       try
       {
          control.moveMessage(messageID, otherQueueName.toString());
@@ -680,28 +540,27 @@
       {
 
       }
-      verify(queue, storageManager, postOffice, repository);
+      verifyMockedAttributes();
    }
 
    public void testMoveMessageWithNoMessageID() throws Exception
    {
       long messageID = randomLong();
       SimpleString otherQueueName = randomSimpleString();
-      Queue queue = createMock(Queue.class);
       Binding otherBinding = createMock(Binding.class);
-      StorageManager storageManager = createMock(StorageManager.class);
-      PostOffice postOffice = createMock(PostOffice.class);
       expect(postOffice.getBinding(otherQueueName)).andReturn(otherBinding);
-      HierarchicalRepository<QueueSettings> repository = createMock(HierarchicalRepository.class);
-      expect(queue.moveMessage(messageID, otherBinding, storageManager, postOffice)).andReturn(false);
-      
-      replay(queue, storageManager, postOffice, repository, otherBinding);
+      expect(
+            queue.moveMessage(messageID, otherBinding, storageManager,
+                  postOffice)).andReturn(false);
 
-      QueueControl control = new QueueControl(queue, storageManager,
-            postOffice, repository);
+      replayMockedAttributes();
+      replay(otherBinding);
+
+      QueueControl control = createControl();
       assertFalse(control.moveMessage(messageID, otherQueueName.toString()));
 
-      verify(queue, storageManager, postOffice, repository, otherBinding);
+      verifyMockedAttributes();
+      verify(otherBinding);
    }
 
    public void testChangeMessagePriority() throws Exception
@@ -711,34 +570,28 @@
       List<MessageReference> refs = new ArrayList<MessageReference>();
       MessageReference ref = createMock(MessageReference.class);
       refs.add(ref);
-      StorageManager storageManager = createMock(StorageManager.class);
-      PostOffice postOffice = createMock(PostOffice.class);
-      HierarchicalRepository<QueueSettings> repository = createMock(HierarchicalRepository.class);
-      Queue queue = createMock(Queue.class);
-      expect(queue.changeMessagePriority(messageID, newPriority, storageManager, postOffice, repository)).andReturn(true);
+      expect(
+            queue.changeMessagePriority(messageID, newPriority, storageManager,
+                  postOffice, repository)).andReturn(true);
 
-      replay(queue, storageManager, postOffice, repository, ref);
+      replayMockedAttributes();
+      replay(ref);
 
-      QueueControl control = new QueueControl(queue, storageManager,
-            postOffice, repository);
+      QueueControl control = createControl();
       assertTrue(control.changeMessagePriority(messageID, newPriority));
 
-      verify(queue, storageManager, postOffice, repository, ref);
+      verifyMockedAttributes();
+      verify(ref);
    }
 
    public void testChangeMessagePriorityWithInvalidPriorityValues()
          throws Exception
    {
       long messageID = randomLong();
-      Queue queue = createMock(Queue.class);
-      StorageManager storageManager = createMock(StorageManager.class);
-      PostOffice postOffice = createMock(PostOffice.class);
-      HierarchicalRepository<QueueSettings> repository = createMock(HierarchicalRepository.class);
 
-      replay(queue, storageManager, postOffice, repository);
+      replayMockedAttributes();
 
-      QueueControl control = new QueueControl(queue, storageManager,
-            postOffice, repository);
+      QueueControl control = createControl();
 
       try
       {
@@ -756,75 +609,102 @@
       {
       }
 
-      verify(queue, storageManager, postOffice, repository);
+      verifyMockedAttributes();
    }
 
    public void testChangeMessagePriorityWithNoMessageID() throws Exception
    {
       long messageID = randomLong();
       byte newPriority = 5;
-      Queue queue = createMock(Queue.class);
-      StorageManager storageManager = createMock(StorageManager.class);
-      PostOffice postOffice = createMock(PostOffice.class);
-      HierarchicalRepository<QueueSettings> repository = createMock(HierarchicalRepository.class);
-      expect(queue.changeMessagePriority(messageID, newPriority, storageManager, postOffice, repository)).andReturn(false);
-      
-      replay(queue, storageManager, postOffice, repository);
+      expect(
+            queue.changeMessagePriority(messageID, newPriority, storageManager,
+                  postOffice, repository)).andReturn(false);
 
-      QueueControl control = new QueueControl(queue, storageManager,
-            postOffice, repository);
+      replayMockedAttributes();
+
+      QueueControl control = createControl();
       assertFalse(control.changeMessagePriority(messageID, newPriority));
 
-      verify(queue, storageManager, postOffice, repository);
+      verifyMockedAttributes();
    }
 
    public void testSendMessageToDLQ() throws Exception
    {
       long messageID = randomLong();
-
-      Queue queue = createMock(Queue.class);
-      StorageManager storageManager = createMock(StorageManager.class);
-      PostOffice postOffice = createMock(PostOffice.class);
-      HierarchicalRepository<QueueSettings> repository = createMock(HierarchicalRepository.class);
       expect(
             queue.sendMessageToDLQ(messageID, storageManager, postOffice,
                   repository)).andReturn(true);
 
-      replay(queue, storageManager, postOffice, repository);
+      replayMockedAttributes();
 
-      QueueControlMBean control = new QueueControl(queue, storageManager,
-            postOffice, repository);
+      QueueControlMBean control = createControl();
       assertTrue(control.sendMessageToDLQ(messageID));
 
-      verify(queue, storageManager, postOffice, repository);
+      verifyMockedAttributes();
    }
 
    public void testSendMessageToDLQWithNoMessageID() throws Exception
    {
       long messageID = randomLong();
-
-      Queue queue = createMock(Queue.class);
-      StorageManager storageManager = createMock(StorageManager.class);
-      PostOffice postOffice = createMock(PostOffice.class);
-      HierarchicalRepository<QueueSettings> repository = createMock(HierarchicalRepository.class);
       expect(
             queue.sendMessageToDLQ(messageID, storageManager, postOffice,
                   repository)).andReturn(false);
 
-      replay(queue, storageManager, postOffice, repository);
+      replayMockedAttributes();
 
-      QueueControlMBean control = new QueueControl(queue, storageManager,
-            postOffice, repository);
+      QueueControlMBean control = createControl();
       assertFalse(control.sendMessageToDLQ(messageID));
 
-      verify(queue, storageManager, postOffice, repository);
+      verifyMockedAttributes();
    }
 
    // Package protected ---------------------------------------------
 
    // Protected -----------------------------------------------------
 
+   @Override
+   protected void setUp() throws Exception
+   {
+      super.setUp();
+
+      queueName = randomSimpleString();
+      queue = createMock(Queue.class);
+      storageManager = createMock(StorageManager.class);
+      postOffice = createMock(PostOffice.class);
+      repository = createMock(HierarchicalRepository.class);
+      messageCounter = new MessageCounter(queueName.toString(), null, queue,
+            false, false, 10);
+   }
+
+   @Override
+   protected void tearDown() throws Exception
+   {
+      queue = null;
+      storageManager = null;
+      postOffice = null;
+      repository = null;
+      messageCounter = null;
+
+      super.tearDown();
+   }
+
    // Private -------------------------------------------------------
 
+   private void replayMockedAttributes()
+   {
+      replay(queue, storageManager, postOffice, repository);
+   }
+
+   private void verifyMockedAttributes()
+   {
+      verify(queue, storageManager, postOffice, repository);
+   }
+
+   private QueueControl createControl() throws Exception
+   {
+      return new QueueControl(queue, storageManager, postOffice, repository,
+            messageCounter);
+   }
+
    // Inner classes -------------------------------------------------
 }




More information about the jboss-cvs-commits mailing list