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