001: /*
002: * JBoss, Home of Professional Open Source.
003: * Copyright 2006, Red Hat Middleware LLC, and individual contributors
004: * as indicated by the @author tags. See the copyright.txt file in the
005: * distribution for a full listing of individual contributors.
006: *
007: * This is free software; you can redistribute it and/or modify it
008: * under the terms of the GNU Lesser General Public License as
009: * published by the Free Software Foundation; either version 2.1 of
010: * the License, or (at your option) any later version.
011: *
012: * This software is distributed in the hope that it will be useful,
013: * but WITHOUT ANY WARRANTY; without even the implied warranty of
014: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
015: * Lesser General Public License for more details.
016: *
017: * You should have received a copy of the GNU Lesser General Public
018: * License along with this software; if not, write to the Free
019: * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
020: * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
021: */
022: package org.jboss.mq;
023:
024: import java.io.Serializable;
025: import java.text.DateFormat;
026: import java.util.Date;
027:
028: /**
029: * Message statistics
030: *
031: * @author <a href="mailto:adrian@jboss.org">Adrian Brock</a>
032: * @version <tt>$Revision: 57198 $</tt>
033: */
034: public class MessageStatistics implements Serializable {
035: // Constants -----------------------------------------------------
036:
037: /** The serialVersionUID */
038: static final long serialVersionUID = 8056884098781414022L;
039:
040: // Attributes ----------------------------------------------------
041:
042: /** Whether we are topic */
043: private boolean topic;
044:
045: /** Whether we are durable */
046: private boolean durable;
047:
048: /** The name */
049: private String name;
050:
051: /** The subscription id */
052: private String subscriptionID;
053:
054: /** The message count */
055: private int count;
056:
057: /** The message count delta */
058: private int countDelta;
059:
060: /** The message depth */
061: private int depth;
062:
063: /** The message depth delta */
064: private int depthDelta;
065:
066: /** The last update */
067: private long timeLastUpdate;
068:
069: // Static --------------------------------------------------------
070:
071: // Constructors --------------------------------------------------
072:
073: /**
074: * Construct a new Message Statistics
075: */
076: public MessageStatistics() {
077: }
078:
079: // Public --------------------------------------------------------
080:
081: /**
082: * Get the count.
083: *
084: * @return Returns the count.
085: */
086: public int getCount() {
087: return count;
088: }
089:
090: /**
091: * Set the count.
092: *
093: * @param count The count to set.
094: */
095: public void setCount(int count) {
096: this .count = count;
097: }
098:
099: /**
100: * Get the countDelta.
101: *
102: * @return Returns the countDelta.
103: */
104: public int getCountDelta() {
105: return countDelta;
106: }
107:
108: /**
109: * Set the countDelta.
110: *
111: * @param countDelta The countDelta to set.
112: */
113: public void setCountDelta(int countDelta) {
114: this .countDelta = countDelta;
115: }
116:
117: /**
118: * Get the depth.
119: *
120: * @return Returns the depth.
121: */
122: public int getDepth() {
123: return depth;
124: }
125:
126: /**
127: * Set the depth.
128: *
129: * @param depth The depth to set.
130: */
131: public void setDepth(int depth) {
132: this .depth = depth;
133: }
134:
135: /**
136: * Get the depthDelta.
137: *
138: * @return Returns the depthDelta.
139: */
140: public int getDepthDelta() {
141: return depthDelta;
142: }
143:
144: /**
145: * Set the depthDelta.
146: *
147: * @param depthDelta The depthDelta to set.
148: */
149: public void setDepthDelta(int depthDelta) {
150: this .depthDelta = depthDelta;
151: }
152:
153: /**
154: * Get the durable.
155: *
156: * @return Returns the durable.
157: */
158: public boolean isDurable() {
159: return durable;
160: }
161:
162: /**
163: * Set the durable.
164: *
165: * @param durable The durable to set.
166: */
167: public void setDurable(boolean durable) {
168: this .durable = durable;
169: }
170:
171: /**
172: * Get the name.
173: *
174: * @return Returns the name.
175: */
176: public String getName() {
177: return name;
178: }
179:
180: /**
181: * Set the name.
182: *
183: * @param name The name to set.
184: */
185: public void setName(String name) {
186: this .name = name;
187: }
188:
189: /**
190: * Get the subscriptionID.
191: *
192: * @return Returns the subscriptionID.
193: */
194: public String getSubscriptionID() {
195: return subscriptionID;
196: }
197:
198: /**
199: * Set the subscriptionID.
200: *
201: * @param subscriptionID The subscriptionID to set.
202: */
203: public void setSubscriptionID(String subscriptionID) {
204: this .subscriptionID = subscriptionID;
205: }
206:
207: /**
208: * Get the timeLastUpdate.
209: *
210: * @return Returns the timeLastUpdate.
211: */
212: public long getTimeLastUpdate() {
213: return timeLastUpdate;
214: }
215:
216: /**
217: * Set the timeLastUpdate.
218: *
219: * @param timeLastUpdate The timeLastUpdate to set.
220: */
221: public void setTimeLastUpdate(long timeLastUpdate) {
222: this .timeLastUpdate = timeLastUpdate;
223: }
224:
225: /**
226: * Get the topic.
227: *
228: * @return Returns the topic.
229: */
230: public boolean isTopic() {
231: return topic;
232: }
233:
234: /**
235: * Set the topic.
236: *
237: * @param topic The topic to set.
238: */
239: public void setTopic(boolean topic) {
240: this .topic = topic;
241: }
242:
243: /**
244: * Get message data as string in format
245: *
246: * "Topic/Queue, Name, Subscription, Durable, Count, CountDelta,
247: * Depth, DepthDelta, Timestamp Last Increment"
248: *
249: * @return String data as a string
250: */
251: public String getAsString() {
252: StringBuffer buffer = new StringBuffer(50);
253:
254: // Topic/Queue
255: if (topic)
256: buffer.append("Topic,");
257: else
258: buffer.append("Queue,");
259:
260: // name
261: buffer.append(name).append(',');
262:
263: // subscription
264: if (subscriptionID != null)
265: buffer.append(subscriptionID).append(',');
266: else
267: buffer.append("-,");
268:
269: // Durable subscription
270: if (topic) {
271: // Topic
272: if (durable)
273: buffer.append("DURABLE,");
274: else
275: buffer.append("NONDURABLE,");
276: } else {
277: buffer.append("-,");
278: }
279:
280: // counter values
281: buffer.append(count).append(',').append(countDelta).append(',')
282: .append(depth).append(',').append(depthDelta).append(
283: ',');
284:
285: // timestamp last counter update
286: if (timeLastUpdate > 0) {
287: DateFormat dateFormat = DateFormat.getDateTimeInstance(
288: DateFormat.SHORT, DateFormat.MEDIUM);
289:
290: buffer.append(dateFormat.format(new Date(timeLastUpdate)));
291: } else {
292: buffer.append('-');
293: }
294:
295: return buffer.toString();
296: }
297:
298: // Object overrides ----------------------------------------------
299:
300: public String toString() {
301: return getAsString();
302: }
303:
304: // Package protected ---------------------------------------------
305:
306: // Protected -----------------------------------------------------
307:
308: // Private -------------------------------------------------------
309:
310: // Inner classes -------------------------------------------------
311:
312: }
|