KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > mq > MessageStatistics


1 /*
2 * JBoss, Home of Professional Open Source
3 * Copyright 2005, JBoss Inc., and individual contributors as indicated
4 * by the @authors tag. See the copyright.txt in the distribution for a
5 * full listing of individual contributors.
6 *
7 * This is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU Lesser General Public License as
9 * published by the Free Software Foundation; either version 2.1 of
10 * the License, or (at your option) any later version.
11 *
12 * This software is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this software; if not, write to the Free
19 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20 * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21 */

22 package org.jboss.mq;
23
24 import java.io.Serializable JavaDoc;
25 import java.text.DateFormat JavaDoc;
26 import java.util.Date JavaDoc;
27
28 /**
29  * Message statistics
30  *
31  * @author <a HREF="mailto:adrian@jboss.org">Adrian Brock</a>
32  * @version <tt>$Revision: 37459 $</tt>
33  */

34 public class MessageStatistics implements Serializable JavaDoc
35 {
36    // Constants -----------------------------------------------------
37

38    /** The serialVersionUID */
39    static final long serialVersionUID = 8056884098781414022L;
40
41    // Attributes ----------------------------------------------------
42

43    /** Whether we are topic */
44    private boolean topic;
45
46    /** Whether we are durable */
47    private boolean durable;
48
49    /** The name */
50    private String JavaDoc name;
51
52    /** The subscription id */
53    private String JavaDoc subscriptionID;
54
55    /** The message count */
56    private int count;
57
58    /** The message count delta */
59    private int countDelta;
60
61    /** The message depth */
62    private int depth;
63
64    /** The message depth delta */
65    private int depthDelta;
66
67    /** The last update */
68    private long timeLastUpdate;
69
70    // Static --------------------------------------------------------
71

72    // Constructors --------------------------------------------------
73

74    /**
75     * Construct a new Message Statistics
76     */

77    public MessageStatistics()
78    {
79    }
80
81    // Public --------------------------------------------------------
82

83    /**
84     * Get the count.
85     *
86     * @return Returns the count.
87     */

88    public int getCount()
89    {
90       return count;
91    }
92
93    /**
94     * Set the count.
95     *
96     * @param count The count to set.
97     */

98    public void setCount(int count)
99    {
100       this.count = count;
101    }
102
103    /**
104     * Get the countDelta.
105     *
106     * @return Returns the countDelta.
107     */

108    public int getCountDelta()
109    {
110       return countDelta;
111    }
112
113    /**
114     * Set the countDelta.
115     *
116     * @param countDelta The countDelta to set.
117     */

118    public void setCountDelta(int countDelta)
119    {
120       this.countDelta = countDelta;
121    }
122
123    /**
124     * Get the depth.
125     *
126     * @return Returns the depth.
127     */

128    public int getDepth()
129    {
130       return depth;
131    }
132
133    /**
134     * Set the depth.
135     *
136     * @param depth The depth to set.
137     */

138    public void setDepth(int depth)
139    {
140       this.depth = depth;
141    }
142
143    /**
144     * Get the depthDelta.
145     *
146     * @return Returns the depthDelta.
147     */

148    public int getDepthDelta()
149    {
150       return depthDelta;
151    }
152
153    /**
154     * Set the depthDelta.
155     *
156     * @param depthDelta The depthDelta to set.
157     */

158    public void setDepthDelta(int depthDelta)
159    {
160       this.depthDelta = depthDelta;
161    }
162
163    /**
164     * Get the durable.
165     *
166     * @return Returns the durable.
167     */

168    public boolean isDurable()
169    {
170       return durable;
171    }
172
173    /**
174     * Set the durable.
175     *
176     * @param durable The durable to set.
177     */

178    public void setDurable(boolean durable)
179    {
180       this.durable = durable;
181    }
182
183    /**
184     * Get the name.
185     *
186     * @return Returns the name.
187     */

188    public String JavaDoc getName()
189    {
190       return name;
191    }
192
193    /**
194     * Set the name.
195     *
196     * @param name The name to set.
197     */

198    public void setName(String JavaDoc name)
199    {
200       this.name = name;
201    }
202
203    /**
204     * Get the subscriptionID.
205     *
206     * @return Returns the subscriptionID.
207     */

208    public String JavaDoc getSubscriptionID()
209    {
210       return subscriptionID;
211    }
212
213    /**
214     * Set the subscriptionID.
215     *
216     * @param subscriptionID The subscriptionID to set.
217     */

218    public void setSubscriptionID(String JavaDoc subscriptionID)
219    {
220       this.subscriptionID = subscriptionID;
221    }
222
223    /**
224     * Get the timeLastUpdate.
225     *
226     * @return Returns the timeLastUpdate.
227     */

228    public long getTimeLastUpdate()
229    {
230       return timeLastUpdate;
231    }
232
233    /**
234     * Set the timeLastUpdate.
235     *
236     * @param timeLastUpdate The timeLastUpdate to set.
237     */

238    public void setTimeLastUpdate(long timeLastUpdate)
239    {
240       this.timeLastUpdate = timeLastUpdate;
241    }
242
243    /**
244     * Get the topic.
245     *
246     * @return Returns the topic.
247     */

248    public boolean isTopic()
249    {
250       return topic;
251    }
252
253    /**
254     * Set the topic.
255     *
256     * @param topic The topic to set.
257     */

258    public void setTopic(boolean topic)
259    {
260       this.topic = topic;
261    }
262
263    /**
264     * Get message data as string in format
265     *
266     * "Topic/Queue, Name, Subscription, Durable, Count, CountDelta,
267     * Depth, DepthDelta, Timestamp Last Increment"
268     *
269     * @return String data as a string
270     */

271    public String JavaDoc getAsString()
272    {
273       StringBuffer JavaDoc buffer = new StringBuffer JavaDoc(50);
274
275       // Topic/Queue
276
if (topic)
277          buffer.append("Topic,");
278       else
279          buffer.append("Queue,");
280
281       // name
282
buffer.append(name).append(',');
283
284       // subscription
285
if (subscriptionID != null)
286          buffer.append(subscriptionID).append(',');
287       else
288          buffer.append("-,");
289
290       // Durable subscription
291
if (topic)
292       {
293          // Topic
294
if (durable)
295             buffer.append("DURABLE,");
296          else
297             buffer.append("NONDURABLE,");
298       }
299       else
300       {
301          buffer.append("-,");
302       }
303
304       // counter values
305
buffer.append(count).append(',').append(countDelta).append(',').append(depth).append(',').append(depthDelta)
306             .append(',');
307
308       // timestamp last counter update
309
if (timeLastUpdate > 0)
310       {
311          DateFormat JavaDoc dateFormat = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.MEDIUM);
312
313          buffer.append(dateFormat.format(new Date JavaDoc(timeLastUpdate)));
314       }
315       else
316       {
317          buffer.append('-');
318       }
319
320       return buffer.toString();
321    }
322
323    // Object overrides ----------------------------------------------
324

325    public String JavaDoc toString()
326    {
327       return getAsString();
328    }
329
330    // Package protected ---------------------------------------------
331

332    // Protected -----------------------------------------------------
333

334    // Private -------------------------------------------------------
335

336    // Inner classes -------------------------------------------------
337

338 }
Popular Tags