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