1
2
3
4
5
6
7
8
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
25
26
27
28
29
30 public class ComponentStats implements ComponentStatsMBean, MBeanRegistration
31 {
32
33
34
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
61
62 public long getAsyncEventsReceived()
63 {
64 return statistics.getAsyncEventsReceived();
65 }
66
67
68
69
70 public long getAsyncEventsSent()
71 {
72 return statistics.getAsyncEventsSent();
73 }
74
75
76
77
78 public long getAverageExecutionTime()
79 {
80 return statistics.getAverageExecutionTime();
81 }
82
83
84
85
86 public long getAverageQueueSize()
87 {
88 return statistics.getAverageQueueSize();
89 }
90
91
92
93
94 public long getExecutedEvents()
95 {
96 return statistics.getExecutedEvents();
97 }
98
99
100
101
102 public long getExecutionErrors()
103 {
104 return statistics.getExecutionErrors();
105 }
106
107
108
109
110 public long getFatalErrors()
111 {
112 return statistics.getFatalErrors();
113 }
114
115
116
117
118 public long getMaxExecutionTime()
119 {
120 return statistics.getMaxExecutionTime();
121 }
122
123
124
125
126 public long getMaxQueueSize()
127 {
128 return statistics.getMaxQueueSize();
129 }
130
131
132
133
134 public long getMinExecutionTime()
135 {
136 return statistics.getMinExecutionTime();
137 }
138
139
140
141
142 public String getName()
143 {
144 return statistics.getName();
145 }
146
147
148
149
150 public long getQueuedEvents()
151 {
152 return statistics.getQueuedEvents();
153 }
154
155
156
157
158 public long getReplyToEventsSent()
159 {
160 return statistics.getReplyToEventsSent();
161 }
162
163
164
165
166 public long getSyncEventsReceived()
167 {
168 return statistics.getSyncEventsReceived();
169 }
170
171
172
173
174 public long getSyncEventsSent()
175 {
176 return statistics.getSyncEventsSent();
177 }
178
179
180
181
182 public long getTotalEventsReceived()
183 {
184 return statistics.getTotalEventsReceived();
185 }
186
187
188
189
190 public long getTotalEventsSent()
191 {
192 return statistics.getTotalEventsSent();
193 }
194
195
196
197
198 public long getTotalExecutionTime()
199 {
200 return statistics.getTotalExecutionTime();
201 }
202
203
204
205
206
207
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
218
219
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
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
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
260
261
262
263 public void preDeregister() throws Exception
264 {
265
266 }
267
268
269
270
271
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
301
302
303
304 public ObjectName getRouterInbound()
305 {
306 return this.inboundName;
307 }
308
309
310
311
312
313
314 public ObjectName getRouterOutbound()
315 {
316 return this.outboundName;
317 }
318 }