[jboss-cvs] JBoss Messaging SVN: r5279 - in trunk/src/main/org/jboss/messaging: core/messagecounter and 2 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Wed Nov 5 11:52:19 EST 2008
Author: jmesnil
Date: 2008-11-05 11:52:19 -0500 (Wed, 05 Nov 2008)
New Revision: 5279
Modified:
trunk/src/main/org/jboss/messaging/core/management/impl/QueueControl.java
trunk/src/main/org/jboss/messaging/core/messagecounter/MessageCounter.java
trunk/src/main/org/jboss/messaging/core/messagecounter/impl/MessageCounterHelper.java
trunk/src/main/org/jboss/messaging/jms/server/management/impl/JMSQueueControl.java
Log:
refactoring to clean MessageCounter code
in MessageCounterHelper, the HTML representation of the MessageCounter is now built directly from the object and not anymore from its stringified-then-tokenized representation
Modified: trunk/src/main/org/jboss/messaging/core/management/impl/QueueControl.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/management/impl/QueueControl.java 2008-11-05 14:26:09 UTC (rev 5278)
+++ trunk/src/main/org/jboss/messaging/core/management/impl/QueueControl.java 2008-11-05 16:52:19 UTC (rev 5279)
@@ -319,7 +319,7 @@
String timestamp = dateFormat.format(new Date(counter.getLastUpdate()));
MessageCounterInfo info = new MessageCounterInfo(counter
.getDestinationName(), counter.getDestinationSubscription(),
- counter.getDestinationDurable(), counter.getCount(), counter
+ counter.isDestinationDurable(), counter.getCount(), counter
.getCountDelta(), counter.getMessageCount(), counter
.getMessageCountDelta(), timestamp);
return info.toCompositeData();
Modified: trunk/src/main/org/jboss/messaging/core/messagecounter/MessageCounter.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/messagecounter/MessageCounter.java 2008-11-05 14:26:09 UTC (rev 5278)
+++ trunk/src/main/org/jboss/messaging/core/messagecounter/MessageCounter.java 2008-11-05 16:52:19 UTC (rev 5279)
@@ -24,7 +24,6 @@
import java.text.DateFormat;
import java.util.ArrayList;
import java.util.Calendar;
-import java.util.Date;
import java.util.GregorianCalendar;
import java.util.List;
@@ -47,12 +46,17 @@
*/
public class MessageCounter
{
- protected static final Logger log = Logger.getLogger(MessageCounter.class);
+ // Constants -----------------------------------------------------
+ // Attributes ----------------------------------------------------
+
// destination related information
private String destName;
+
private String destSubscription;
+
private boolean destTopic;
+
private boolean destDurable;
// destination queue
@@ -60,14 +64,24 @@
// counter
private int countTotal;
+
private int countTotalLast;
+
private int depthLast;
+
private long timeLastUpdate;
// per hour day counter history
private int dayCounterMax;
- private ArrayList dayCounter;
+ private List<DayCounter> dayCounters;
+
+ private int lastMessagesAdded;
+
+ // Static --------------------------------------------------------
+
+ // Constructors --------------------------------------------------
+
/**
* Constructor
*
@@ -78,96 +92,62 @@
* @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)
+ 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;
+ destQueue = queue;
// initialize counter
resetCounter();
// initialize message history
- dayCounter = new ArrayList();
+ dayCounters = new ArrayList<DayCounter>();
setHistoryLimit(daycountmax);
}
- /**
- * Get string representation
- */
- public String toString()
- {
- return getCounterAsString();
- }
+ // Public --------------------------------------------------------
- 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
+
+ // 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()
+ public boolean isDestinationTopic()
{
return destTopic;
}
- /**
- * Gets the related destination durable subscription flag
- *
- * @return boolean true : durable subscription,
- * false: non-durable subscription
- */
- public boolean getDestinationDurable()
+ public boolean isDestinationDurable()
{
return destDurable;
}
@@ -175,8 +155,6 @@
/**
* Gets the total message count since startup or
* last counter reset
- *
- * @return int message count
*/
public int getCount()
{
@@ -185,8 +163,6 @@
/**
* Gets the message count delta since last method call
- *
- * @return int message count delta
*/
public int getCountDelta()
{
@@ -200,8 +176,6 @@
/**
* Gets the current message count of pending messages
* within the destination waiting for dispatch
- *
- * @return int message queue depth
*/
public int getMessageCount()
{
@@ -210,9 +184,7 @@
/**
* Gets the message count delta of pending messages
- * since last method call. Therefore
- *
- * @return int message queue depth delta
+ * since last method call.
*/
public int getMessageCountDelta()
{
@@ -224,19 +196,11 @@
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;
@@ -245,128 +209,125 @@
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()
+ private void setHistoryLimit(int daycountmax)
{
- 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)
+ synchronized (dayCounters)
{
if (dayCounterMax > 0)
{
// limit day history to specified day count
- int delta = dayCounter.size() - dayCounterMax;
+ int delta = dayCounters.size() - dayCounterMax;
for (int i = 0; i < delta; i++)
{
// reduce array size to requested size by dropping
// oldest day counters
- dayCounter.remove(0);
+ dayCounters.remove(0);
}
// create initial day counter when empty
- bInitialize = dayCounter.isEmpty();
+ bInitialize = dayCounters.isEmpty();
}
else if (dayCounterMax == 0)
{
// disable history
- dayCounter.clear();
+ dayCounters.clear();
}
else
{
// unlimited day history
// create initial day counter when empty
- bInitialize = dayCounter.isEmpty();
+ bInitialize = dayCounters.isEmpty();
}
// optionally initialize first day counter entry
if (bInitialize)
{
- dayCounter.add(new DayCounter(new GregorianCalendar(), true));
+ dayCounters.add(new DayCounter(new GregorianCalendar(), true));
}
}
}
+ public void resetHistory()
+ {
+ int max = dayCounterMax;
+
+ setHistoryLimit(0);
+ setHistoryLimit(max);
+ }
+
+ public List<DayCounter> getHistory()
+ {
+ updateHistory(0);
+
+ return new ArrayList<DayCounter>(dayCounters);
+ }
+
/**
+ * 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 (dayCounters)
+ {
+ // first line: history day count
+ ret += dayCounters.size() + "\n";
+
+ // following lines: day counter data
+ for (int i = 0; i < dayCounters.size(); i++)
+ {
+ DayCounter counter = dayCounters.get(i);
+
+ ret += counter.getDayCounterAsString() + "\n";
+ }
+ }
+
+ return ret;
+ }
+
+ public String toString()
+ {
+ return "MessageCounter[destName" + destName +
+ ", destSubscription=" +
+ destSubscription +
+ ", destTopic=" +
+ destTopic +
+ ", destDurable=" +
+ destDurable +
+ ", destQueue=" +
+ destQueue +
+ "]";
+ }
+
+ // Package protected ---------------------------------------------
+
+ // Protected -----------------------------------------------------
+
+ // Private -------------------------------------------------------
+
+ /**
* Update message counter history
*
* @param newMessages number of new messages to add to the latest day counter
@@ -374,15 +335,15 @@
private void updateHistory(int newMessages)
{
// check history activation
- if (dayCounter.isEmpty())
+ if (dayCounters.isEmpty())
{
return;
}
// calculate day difference between current date and date of last day counter entry
- synchronized (dayCounter)
+ synchronized (dayCounters)
{
- DayCounter counterLast = (DayCounter) dayCounter.get(dayCounter.size() - 1);
+ DayCounter counterLast = dayCounters.get(dayCounters.size() - 1);
GregorianCalendar calNow = new GregorianCalendar();
GregorianCalendar calLast = counterLast.getDate();
@@ -405,7 +366,7 @@
long millisPerDay = 86400000; // 24 * 60 * 60 * 1000
long millisDelta = calNow.getTime().getTime() - calLast.getTime().getTime();
- int dayDelta = (int) (millisDelta / millisPerDay);
+ int dayDelta = (int)(millisDelta / millisPerDay);
if (dayDelta > 0)
{
@@ -423,80 +384,27 @@
counterNew = new DayCounter(calLast, false);
counterNew.finalizeDayCounter();
- dayCounter.add(counterNew);
+ dayCounters.add(counterNew);
}
// add new day counter entry for current day
counterNew = new DayCounter(calNow, false);
- dayCounter.add(counterNew);
+ dayCounters.add(counterNew);
// ensure history day count limit
setHistoryLimit(dayCounterMax);
}
// update last day counter entry
- counterLast = (DayCounter) dayCounter.get(dayCounter.size() - 1);
+ counterLast = dayCounters.get(dayCounters.size() - 1);
counterLast.updateDayCounter(newMessages);
}
}
- /**
- * Reset message counter history
- */
- public void resetHistory()
- {
- int max = dayCounterMax;
+ // Inner classes -------------------------------------------------
- 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
@@ -504,6 +412,7 @@
static final int HOURS = 24;
GregorianCalendar date = null;
+
int[] counters = new int[HOURS];
/**
@@ -516,7 +425,7 @@
DayCounter(GregorianCalendar date, boolean isStartDay)
{
// store internal copy of creation date
- this.date = (GregorianCalendar) date.clone();
+ 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')
@@ -548,14 +457,14 @@
*/
public GregorianCalendar getDate()
{
- return (GregorianCalendar) date.clone();
+ return (GregorianCalendar)date.clone();
}
public int[] getCounters()
{
- return counters;
+ return counters;
}
-
+
/**
* Update day counter hour array elements
*
@@ -578,7 +487,7 @@
{
// found first initialized hour counter
// -> set all following uninitialized
- // counter values to 0
+ // counter values to 0
bUpdate = true;
}
@@ -608,7 +517,7 @@
{
// found first initialized hour counter
// -> finalize all following uninitialized
- // counter values
+ // counter values
bFinalize = true;
}
@@ -633,7 +542,7 @@
String strData = dateFormat.format(date.getTime());
- // append 24 comma separated hour counter values
+ // append 24 comma separated hour counter values
for (int i = 0; i < HOURS; i++)
{
strData += "," + counters[i];
@@ -643,4 +552,3 @@
}
}
}
-
Modified: trunk/src/main/org/jboss/messaging/core/messagecounter/impl/MessageCounterHelper.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/messagecounter/impl/MessageCounterHelper.java 2008-11-05 14:26:09 UTC (rev 5278)
+++ trunk/src/main/org/jboss/messaging/core/messagecounter/impl/MessageCounterHelper.java 2008-11-05 16:52:19 UTC (rev 5279)
@@ -22,6 +22,8 @@
package org.jboss.messaging.core.messagecounter.impl;
+import java.text.DateFormat;
+import java.util.Date;
import java.util.StringTokenizer;
import org.jboss.messaging.core.messagecounter.MessageCounter;
@@ -36,14 +38,12 @@
{
// Constants -----------------------------------------------------
+ private static DateFormat DATE_FORMAT = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.MEDIUM);
+
// Attributes ----------------------------------------------------
// Static --------------------------------------------------------
- // Constructors --------------------------------------------------
-
- // Public --------------------------------------------------------
-
public static String listMessageCounterAsHTML(MessageCounter[] counters)
{
if (counters == null)
@@ -64,37 +64,30 @@
for (int i = 0; i < counters.length; i++)
{
- String data = counters[i].getCounterAsString();
- StringTokenizer token = new StringTokenizer(data, ",");
- String value;
-
+ MessageCounter counter = counters[i];
+ String type = counter.isDestinationTopic() ? "Topic" : "Queue";
+ String subscription = counter.getDestinationSubscription();
+ if (subscription == null)
+ {
+ subscription = "-";
+ }
+ String durableStr = "-"; // makes no sense for a queue
+ if (counter.isDestinationTopic())
+ {
+ durableStr = Boolean.toString(counter.isDestinationDurable());
+ }
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>" + type + "</td>";
+ ret += "<td>" + counter.getDestinationName() + "</td>";
+ ret += "<td>" + subscription + "</td>";
+ ret += "<td>" + durableStr + "</td>";
+ ret += "<td>" + counter.getCount() + "</td>";
+ ret += "<td>" + prettify(counter.getCountDelta()) + "</td>";
+ ret += "<td>" + prettify(counter.getMessageCount()) + "</td>";
+ ret += "<td>" + prettify(counter.getMessageCountDelta()) + "</td>";
+ ret += "<td>" + asDate(counter.getLastUpdate()) + "</td>"; // date last add
- 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>\n";
}
@@ -117,7 +110,7 @@
ret += " <li>";
// destination name
- ret += (counters[i].getDestinationTopic() ? "Topic '" : "Queue '") + counters[i].getDestinationName() + "'";
+ ret += (counters[i].isDestinationTopic() ? "Topic '" : "Queue '") + counters[i].getDestinationName() + "'";
ret += "</li>\n";
if (counters[i].getDestinationSubscription() != null)
@@ -182,7 +175,32 @@
return ret;
}
+
+ private static String prettify(int value)
+ {
+ if (value == 0)
+ {
+ return "-";
+ }
+ return Integer.toString(value);
+ }
+
+ private static String asDate(long time)
+ {
+ if (time > 0)
+ {
+ return DATE_FORMAT.format(new Date(time));
+ }
+ else
+ {
+ return "-";
+ }
+ }
+ // Constructors --------------------------------------------------
+
+ // Public --------------------------------------------------------
+
// Package protected ---------------------------------------------
// Protected -----------------------------------------------------
Modified: trunk/src/main/org/jboss/messaging/jms/server/management/impl/JMSQueueControl.java
===================================================================
--- trunk/src/main/org/jboss/messaging/jms/server/management/impl/JMSQueueControl.java 2008-11-05 14:26:09 UTC (rev 5278)
+++ trunk/src/main/org/jboss/messaging/jms/server/management/impl/JMSQueueControl.java 2008-11-05 16:52:19 UTC (rev 5279)
@@ -322,7 +322,7 @@
String timestamp = dateFormat.format(new Date(counter.getLastUpdate()));
MessageCounterInfo info = new MessageCounterInfo(counter
.getDestinationName(), counter.getDestinationSubscription(),
- counter.getDestinationDurable(), counter.getCount(), counter
+ counter.isDestinationDurable(), counter.getCount(), counter
.getCountDelta(), counter.getMessageCount(), counter
.getMessageCountDelta(), timestamp);
return info.toCompositeData();
More information about the jboss-cvs-commits
mailing list