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