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