KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > mule > management > mbeans > ComponentStats


1 /*
2  * $Id: ComponentStats.java 3798 2006-11-04 04:07:14Z aperepel $
3  * --------------------------------------------------------------------------------------
4  * Copyright (c) MuleSource, Inc. All rights reserved. http://www.mulesource.com
5  *
6  * The software in this package is published under the terms of the MuleSource MPL
7  * license, a copy of which has been included with this distribution in the
8  * LICENSE.txt file.
9  */

10
11 package org.mule.management.mbeans;
12
13 import javax.management.MBeanRegistration JavaDoc;
14 import javax.management.MBeanServer JavaDoc;
15 import javax.management.ObjectName JavaDoc;
16
17 import org.apache.commons.logging.Log;
18 import org.apache.commons.logging.LogFactory;
19 import org.mule.management.stats.ComponentStatistics;
20 import org.mule.management.stats.RouterStatistics;
21
22 /**
23  * <code>ComponentStats</code> TODO
24  *
25  * @author <a HREF="mailto:ross.mason@symphonysoft.com">Ross Mason</a>
26  * @author Guillaume Nodet
27  * @version $Revision: 3798 $
28  */

29 public class ComponentStats implements ComponentStatsMBean, MBeanRegistration JavaDoc
30 {
31
32     /**
33      * logger used by this class
34      */

35     private static Log LOGGER = LogFactory.getLog(ComponentStats.class);
36
37     private MBeanServer JavaDoc server;
38
39     private ObjectName JavaDoc name;
40     private ObjectName JavaDoc inboundName;
41     private ObjectName JavaDoc outboundName;
42
43     private ComponentStatistics statistics;
44
45     public ComponentStats(ComponentStatistics statistics)
46     {
47         this.statistics = statistics;
48     }
49
50     /**
51      *
52      */

53     public void clearStatistics()
54     {
55         statistics.clear();
56     }
57
58     /**
59      * @return
60      */

61     public long getAsyncEventsReceived()
62     {
63         return statistics.getAsyncEventsReceived();
64     }
65
66     /**
67      * @return
68      */

69     public long getAsyncEventsSent()
70     {
71         return statistics.getAsyncEventsSent();
72     }
73
74     /**
75      * @return
76      */

77     public long getAverageExecutionTime()
78     {
79         return statistics.getAverageExecutionTime();
80     }
81
82     /**
83      * @return
84      */

85     public long getAverageQueueSize()
86     {
87         return statistics.getAverageQueueSize();
88     }
89
90     /**
91      * @return
92      */

93     public long getExecutedEvents()
94     {
95         return statistics.getExecutedEvents();
96     }
97
98     /**
99      * @return
100      */

101     public long getExecutionErrors()
102     {
103         return statistics.getExecutionErrors();
104     }
105
106     /**
107      * @return
108      */

109     public long getFatalErrors()
110     {
111         return statistics.getFatalErrors();
112     }
113
114     /**
115      * @return
116      */

117     public long getMaxExecutionTime()
118     {
119         return statistics.getMaxExecutionTime();
120     }
121
122     /**
123      * @return
124      */

125     public long getMaxQueueSize()
126     {
127         return statistics.getMaxQueueSize();
128     }
129
130     /**
131      * @return
132      */

133     public long getMinExecutionTime()
134     {
135         return statistics.getMinExecutionTime();
136     }
137
138     /**
139      * @return
140      */

141     public String JavaDoc getName()
142     {
143         return statistics.getName();
144     }
145
146     /**
147      * @return
148      */

149     public long getQueuedEvents()
150     {
151         return statistics.getQueuedEvents();
152     }
153
154     /**
155      * @return
156      */

157     public long getReplyToEventsSent()
158     {
159         return statistics.getReplyToEventsSent();
160     }
161
162     /**
163      * @return
164      */

165     public long getSyncEventsReceived()
166     {
167         return statistics.getSyncEventsReceived();
168     }
169
170     /**
171      * @return
172      */

173     public long getSyncEventsSent()
174     {
175         return statistics.getSyncEventsSent();
176     }
177
178     /**
179      * @return
180      */

181     public long getTotalEventsReceived()
182     {
183         return statistics.getTotalEventsReceived();
184     }
185
186     /**
187      * @return
188      */

189     public long getTotalEventsSent()
190     {
191         return statistics.getTotalEventsSent();
192     }
193
194     /**
195      * @return
196      */

197     public long getTotalExecutionTime()
198     {
199         return statistics.getTotalExecutionTime();
200     }
201
202     /*
203      * (non-Javadoc)
204      *
205      * @see javax.management.MBeanRegistration#preRegister(javax.management.MBeanServer,
206      * javax.management.ObjectName)
207      */

208     public ObjectName JavaDoc preRegister(MBeanServer JavaDoc server, ObjectName JavaDoc name) throws Exception JavaDoc
209     {
210         this.server = server;
211         this.name = name;
212         return name;
213     }
214
215     /*
216      * (non-Javadoc)
217      *
218      * @see javax.management.MBeanRegistration#postRegister(java.lang.Boolean)
219      */

220     public void postRegister(Boolean JavaDoc registrationDone)
221     {
222
223         try
224         {
225             RouterStatistics is = this.statistics.getInboundRouterStat();
226             if (is != null)
227             {
228                 inboundName = new ObjectName JavaDoc(name.getDomain() + ":type=org.mule.Statistics,component="
229                                              + statistics.getName() + ",router=inbound");
230                 // unregister old version if exists
231
if (this.server.isRegistered(inboundName))
232                 {
233                     this.server.unregisterMBean(inboundName);
234                 }
235                 this.server.registerMBean(new RouterStats(is), this.inboundName);
236             }
237             RouterStatistics os = this.statistics.getOutboundRouterStat();
238             if (os != null)
239             {
240                 outboundName = new ObjectName JavaDoc(name.getDomain() + ":type=org.mule.Statistics,component="
241                                               + statistics.getName() + ",router=outbound");
242                 // unregister old version if exists
243
if (this.server.isRegistered(outboundName))
244                 {
245                     this.server.unregisterMBean(outboundName);
246                 }
247                 this.server.registerMBean(new RouterStats(os), this.outboundName);
248             }
249         }
250         catch (Exception JavaDoc e)
251         {
252             LOGGER.error("Error post-registering MBean", e);
253         }
254
255     }
256
257     /*
258      * (non-Javadoc)
259      *
260      * @see javax.management.MBeanRegistration#preDeregister()
261      */

262     public void preDeregister() throws Exception JavaDoc
263     {
264         // nothing to do
265
}
266
267     /*
268      * (non-Javadoc)
269      *
270      * @see javax.management.MBeanRegistration#postDeregister()
271      */

272     public void postDeregister()
273     {
274         try
275         {
276             if (this.server.isRegistered(inboundName))
277             {
278                 this.server.unregisterMBean(inboundName);
279             }
280         }
281         catch (Exception JavaDoc ex)
282         {
283             LOGGER.error("Error unregistering ComponentStats child " + inboundName.getCanonicalName(), ex);
284         }
285         try
286         {
287             if (this.server.isRegistered(outboundName))
288             {
289                 this.server.unregisterMBean(outboundName);
290             }
291         }
292         catch (Exception JavaDoc ex)
293         {
294             LOGGER.error("Error unregistering ComponentStats child " + inboundName.getCanonicalName(), ex);
295         }
296     }
297
298     /*
299      * (non-Javadoc)
300      *
301      * @see org.mule.management.mbeans.ComponentStatsMBean#getInboundRouter()
302      */

303     public ObjectName JavaDoc getRouterInbound()
304     {
305         return this.inboundName;
306     }
307
308     /*
309      * (non-Javadoc)
310      *
311      * @see org.mule.management.mbeans.ComponentStatsMBean#getOutboundRouter()
312      */

313     public ObjectName JavaDoc getRouterOutbound()
314     {
315         return this.outboundName;
316     }
317 }
318
Popular Tags