View Javadoc

1   /*
2    * $Id: ComponentStats.java 7976 2007-08-21 14:26:13Z dirk.olmes $
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 CPAL v1.0
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 org.mule.management.stats.ComponentStatistics;
14  import org.mule.management.stats.RouterStatistics;
15  
16  import javax.management.MBeanRegistration;
17  import javax.management.MBeanServer;
18  import javax.management.ObjectName;
19  
20  import org.apache.commons.logging.Log;
21  import org.apache.commons.logging.LogFactory;
22  
23  /**
24   * <code>ComponentStats</code> TODO
25   * 
26   * @author <a href="mailto:ross.mason@symphonysoft.com">Ross Mason</a>
27   * @author Guillaume Nodet
28   * @version $Revision: 7976 $
29   */
30  public class ComponentStats implements ComponentStatsMBean, MBeanRegistration
31  {
32  
33      /**
34       * logger used by this class
35       */
36      private static Log LOGGER = LogFactory.getLog(ComponentStats.class);
37  
38      private MBeanServer server;
39  
40      private ObjectName name;
41      private ObjectName inboundName;
42      private ObjectName outboundName;
43  
44      private ComponentStatistics statistics;
45  
46      public ComponentStats(ComponentStatistics statistics)
47      {
48          this.statistics = statistics;
49      }
50  
51      /**
52       * 
53       */
54      public void clearStatistics()
55      {
56          statistics.clear();
57      }
58  
59      /**
60       * @return
61       */
62      public long getAsyncEventsReceived()
63      {
64          return statistics.getAsyncEventsReceived();
65      }
66  
67      /**
68       * @return
69       */
70      public long getAsyncEventsSent()
71      {
72          return statistics.getAsyncEventsSent();
73      }
74  
75      /**
76       * @return
77       */
78      public long getAverageExecutionTime()
79      {
80          return statistics.getAverageExecutionTime();
81      }
82  
83      /**
84       * @return
85       */
86      public long getAverageQueueSize()
87      {
88          return statistics.getAverageQueueSize();
89      }
90  
91      /**
92       * @return
93       */
94      public long getExecutedEvents()
95      {
96          return statistics.getExecutedEvents();
97      }
98  
99      /**
100      * @return
101      */
102     public long getExecutionErrors()
103     {
104         return statistics.getExecutionErrors();
105     }
106 
107     /**
108      * @return
109      */
110     public long getFatalErrors()
111     {
112         return statistics.getFatalErrors();
113     }
114 
115     /**
116      * @return
117      */
118     public long getMaxExecutionTime()
119     {
120         return statistics.getMaxExecutionTime();
121     }
122 
123     /**
124      * @return
125      */
126     public long getMaxQueueSize()
127     {
128         return statistics.getMaxQueueSize();
129     }
130 
131     /**
132      * @return
133      */
134     public long getMinExecutionTime()
135     {
136         return statistics.getMinExecutionTime();
137     }
138 
139     /**
140      * @return
141      */
142     public String getName()
143     {
144         return statistics.getName();
145     }
146 
147     /**
148      * @return
149      */
150     public long getQueuedEvents()
151     {
152         return statistics.getQueuedEvents();
153     }
154 
155     /**
156      * @return
157      */
158     public long getReplyToEventsSent()
159     {
160         return statistics.getReplyToEventsSent();
161     }
162 
163     /**
164      * @return
165      */
166     public long getSyncEventsReceived()
167     {
168         return statistics.getSyncEventsReceived();
169     }
170 
171     /**
172      * @return
173      */
174     public long getSyncEventsSent()
175     {
176         return statistics.getSyncEventsSent();
177     }
178 
179     /**
180      * @return
181      */
182     public long getTotalEventsReceived()
183     {
184         return statistics.getTotalEventsReceived();
185     }
186 
187     /**
188      * @return
189      */
190     public long getTotalEventsSent()
191     {
192         return statistics.getTotalEventsSent();
193     }
194 
195     /**
196      * @return
197      */
198     public long getTotalExecutionTime()
199     {
200         return statistics.getTotalExecutionTime();
201     }
202 
203     /*
204      * (non-Javadoc)
205      * 
206      * @see javax.management.MBeanRegistration#preRegister(javax.management.MBeanServer,
207      *      javax.management.ObjectName)
208      */
209     public ObjectName preRegister(MBeanServer server, ObjectName name) throws Exception
210     {
211         this.server = server;
212         this.name = name;
213         return name;
214     }
215 
216     /*
217      * (non-Javadoc)
218      * 
219      * @see javax.management.MBeanRegistration#postRegister(java.lang.Boolean)
220      */
221     public void postRegister(Boolean registrationDone)
222     {
223 
224         try
225         {
226             RouterStatistics is = this.statistics.getInboundRouterStat();
227             if (is != null)
228             {
229                 inboundName = new ObjectName(name.getDomain() + ":type=org.mule.Statistics,component="
230                                              + statistics.getName() + ",router=inbound");
231                 // unregister old version if exists
232                 if (this.server.isRegistered(inboundName))
233                 {
234                     this.server.unregisterMBean(inboundName);
235                 }
236                 this.server.registerMBean(new RouterStats(is), this.inboundName);
237             }
238             RouterStatistics os = this.statistics.getOutboundRouterStat();
239             if (os != null)
240             {
241                 outboundName = new ObjectName(name.getDomain() + ":type=org.mule.Statistics,component="
242                                               + statistics.getName() + ",router=outbound");
243                 // unregister old version if exists
244                 if (this.server.isRegistered(outboundName))
245                 {
246                     this.server.unregisterMBean(outboundName);
247                 }
248                 this.server.registerMBean(new RouterStats(os), this.outboundName);
249             }
250         }
251         catch (Exception e)
252         {
253             LOGGER.error("Error post-registering MBean", e);
254         }
255 
256     }
257 
258     /*
259      * (non-Javadoc)
260      * 
261      * @see javax.management.MBeanRegistration#preDeregister()
262      */
263     public void preDeregister() throws Exception
264     {
265         // nothing to do
266     }
267 
268     /*
269      * (non-Javadoc)
270      * 
271      * @see javax.management.MBeanRegistration#postDeregister()
272      */
273     public void postDeregister()
274     {
275         try
276         {
277             if (this.server.isRegistered(inboundName))
278             {
279                 this.server.unregisterMBean(inboundName);
280             }
281         }
282         catch (Exception ex)
283         {
284             LOGGER.error("Error unregistering ComponentStats child " + inboundName.getCanonicalName(), ex);
285         }
286         try
287         {
288             if (this.server.isRegistered(outboundName))
289             {
290                 this.server.unregisterMBean(outboundName);
291             }
292         }
293         catch (Exception ex)
294         {
295             LOGGER.error("Error unregistering ComponentStats child " + inboundName.getCanonicalName(), ex);
296         }
297     }
298 
299     /*
300      * (non-Javadoc)
301      * 
302      * @see org.mule.management.mbeans.ComponentStatsMBean#getInboundRouter()
303      */
304     public ObjectName getRouterInbound()
305     {
306         return this.inboundName;
307     }
308 
309     /*
310      * (non-Javadoc)
311      * 
312      * @see org.mule.management.mbeans.ComponentStatsMBean#getOutboundRouter()
313      */
314     public ObjectName getRouterOutbound()
315     {
316         return this.outboundName;
317     }
318 }