1
2
3
4
5
6
7
8
9
10
11 package org.mule.management.mbeans;
12
13 import org.mule.impl.model.AbstractComponent;
14 import org.mule.impl.model.ModelHelper;
15 import org.mule.impl.model.seda.SedaComponent;
16 import org.mule.management.stats.ComponentStatistics;
17 import org.mule.umo.UMOComponent;
18 import org.mule.umo.UMOException;
19
20 import javax.management.MBeanRegistration;
21 import javax.management.MBeanServer;
22 import javax.management.ObjectName;
23
24 import org.apache.commons.logging.Log;
25 import org.apache.commons.logging.LogFactory;
26
27
28
29
30
31
32
33
34 public class ComponentService implements ComponentServiceMBean, MBeanRegistration, ComponentStatsMBean
35 {
36
37
38
39
40 private static Log LOGGER = LogFactory.getLog(ComponentService.class);
41
42 private MBeanServer server;
43
44 private String name;
45
46 private ObjectName statsName;
47
48 private ObjectName objectName;
49
50 private ComponentStatistics statistics;
51
52 public ComponentService(String name)
53 {
54 this.name = name;
55 this.statistics = getComponent().getStatistics();
56
57 }
58
59 public int getQueueSize()
60 {
61 UMOComponent c = getComponent();
62 if (c instanceof SedaComponent)
63 {
64 return ((SedaComponent)c).getQueueSize();
65 }
66 else
67 {
68 return -1;
69 }
70 }
71
72
73
74
75
76
77
78
79
80
81
82
83 public void pause() throws UMOException
84 {
85 getComponent().pause();
86 }
87
88
89
90
91
92
93
94 public void resume() throws UMOException
95 {
96 getComponent().resume();
97 }
98
99 public boolean isPaused()
100 {
101 return getComponent().isPaused();
102 }
103
104 public boolean isStopped()
105 {
106 return getComponent().isStopped();
107 }
108
109 public void stop() throws UMOException
110 {
111 getComponent().stop();
112 }
113
114 public void forceStop() throws UMOException
115 {
116 getComponent().forceStop();
117 }
118
119 public boolean isStopping()
120 {
121 return getComponent().isStopping();
122 }
123
124 public void dispose() throws UMOException
125 {
126 getComponent().dispose();
127 }
128
129 public void start() throws UMOException
130 {
131 getComponent().start();
132 }
133
134
135
136
137
138
139 public ObjectName getStatistics()
140 {
141 return statsName;
142 }
143
144
145
146
147
148
149
150 public ObjectName preRegister(MBeanServer server, ObjectName name) throws Exception
151 {
152 this.server = server;
153 this.objectName = name;
154 return name;
155 }
156
157
158
159
160
161
162 public void postRegister(Boolean registrationDone)
163 {
164 try
165 {
166 if (getComponent().getStatistics() != null)
167 {
168 statsName = new ObjectName(objectName.getDomain() + ":type=org.mule.Statistics,component="
169 + getName());
170
171 if (this.server.isRegistered(statsName))
172 {
173 this.server.unregisterMBean(statsName);
174 }
175
176 this.server.registerMBean(new ComponentStats(getComponent().getStatistics()), this.statsName);
177 }
178 }
179 catch (Exception e)
180 {
181 LOGGER.error("Error post-registering the MBean", e);
182 }
183 }
184
185
186
187
188
189
190 public void preDeregister() throws Exception
191 {
192 try
193 {
194 if (this.server.isRegistered(statsName))
195 {
196 this.server.unregisterMBean(statsName);
197 }
198 }
199 catch (Exception ex)
200 {
201 LOGGER.error("Error unregistering ComponentService child " + statsName.getCanonicalName(), ex);
202 }
203 }
204
205
206
207
208
209
210 public void postDeregister()
211 {
212
213 }
214
215 private AbstractComponent getComponent()
216 {
217 return (AbstractComponent)ModelHelper.getComponent(getName());
218 }
219
220
221
222
223
224
225 public void clearStatistics()
226 {
227 statistics.clear();
228 }
229
230
231
232
233 public long getAsyncEventsReceived()
234 {
235 return statistics.getAsyncEventsReceived();
236 }
237
238
239
240
241 public long getAsyncEventsSent()
242 {
243 return statistics.getAsyncEventsSent();
244 }
245
246
247
248
249 public long getAverageExecutionTime()
250 {
251 return statistics.getAverageExecutionTime();
252 }
253
254
255
256
257 public long getAverageQueueSize()
258 {
259 return statistics.getAverageQueueSize();
260 }
261
262
263
264
265 public long getExecutedEvents()
266 {
267 return statistics.getExecutedEvents();
268 }
269
270
271
272
273 public long getExecutionErrors()
274 {
275 return statistics.getExecutionErrors();
276 }
277
278
279
280
281 public long getFatalErrors()
282 {
283 return statistics.getFatalErrors();
284 }
285
286
287
288
289 public long getMaxExecutionTime()
290 {
291 return statistics.getMaxExecutionTime();
292 }
293
294
295
296
297 public long getMaxQueueSize()
298 {
299 return statistics.getMaxQueueSize();
300 }
301
302
303
304
305 public long getMinExecutionTime()
306 {
307 return statistics.getMinExecutionTime();
308 }
309
310
311
312
313 public String getName()
314 {
315 return name;
316 }
317
318
319
320
321 public long getQueuedEvents()
322 {
323 return statistics.getQueuedEvents();
324 }
325
326
327
328
329 public long getReplyToEventsSent()
330 {
331 return statistics.getReplyToEventsSent();
332 }
333
334
335
336
337 public long getSyncEventsReceived()
338 {
339 return statistics.getSyncEventsReceived();
340 }
341
342
343
344
345 public long getSyncEventsSent()
346 {
347 return statistics.getSyncEventsSent();
348 }
349
350
351
352
353 public long getTotalEventsReceived()
354 {
355 return statistics.getTotalEventsReceived();
356 }
357
358
359
360
361 public long getTotalEventsSent()
362 {
363 return statistics.getTotalEventsSent();
364 }
365
366
367
368
369 public long getTotalExecutionTime()
370 {
371 return statistics.getTotalExecutionTime();
372 }
373 }