1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
package org.mule.module.management.mbean; |
12 | |
|
13 | |
import org.mule.api.MuleContext; |
14 | |
import org.mule.api.MuleException; |
15 | |
import org.mule.api.config.MuleConfiguration; |
16 | |
import org.mule.api.service.Service; |
17 | |
import org.mule.management.stats.ServiceStatistics; |
18 | |
import org.mule.model.seda.SedaService; |
19 | |
import org.mule.service.AbstractService; |
20 | |
|
21 | |
import javax.management.MBeanRegistration; |
22 | |
import javax.management.MBeanServer; |
23 | |
import javax.management.ObjectName; |
24 | |
|
25 | |
import org.apache.commons.logging.Log; |
26 | |
import org.apache.commons.logging.LogFactory; |
27 | |
|
28 | |
|
29 | |
|
30 | |
|
31 | |
|
32 | |
public class ServiceService implements ServiceServiceMBean, MBeanRegistration, ServiceStatsMBean |
33 | |
{ |
34 | |
|
35 | |
|
36 | |
|
37 | |
|
38 | 0 | private static Log LOGGER = LogFactory.getLog(ServiceService.class); |
39 | |
|
40 | |
private MBeanServer server; |
41 | |
|
42 | |
private String name; |
43 | |
|
44 | |
private ObjectName statsName; |
45 | |
|
46 | |
private ObjectName objectName; |
47 | |
|
48 | |
private ServiceStatistics statistics; |
49 | |
|
50 | |
private MuleContext muleContext; |
51 | |
|
52 | |
public ServiceService(String name, MuleContext muleContext) |
53 | 0 | { |
54 | 0 | this.muleContext = muleContext; |
55 | 0 | this.name = name; |
56 | 0 | this.statistics = getComponent().getStatistics(); |
57 | |
|
58 | 0 | } |
59 | |
|
60 | |
public int getQueueSize() |
61 | |
{ |
62 | 0 | Service c = getComponent(); |
63 | 0 | if (c instanceof SedaService) |
64 | |
{ |
65 | 0 | return (int) c.getStatistics().getQueuedEvents(); |
66 | |
} |
67 | |
else |
68 | |
{ |
69 | 0 | return -1; |
70 | |
} |
71 | |
} |
72 | |
|
73 | |
|
74 | |
|
75 | |
|
76 | |
|
77 | |
|
78 | |
|
79 | |
|
80 | |
|
81 | |
|
82 | |
|
83 | |
|
84 | |
public void pause() throws MuleException |
85 | |
{ |
86 | 0 | getComponent().pause(); |
87 | 0 | } |
88 | |
|
89 | |
|
90 | |
|
91 | |
|
92 | |
|
93 | |
|
94 | |
|
95 | |
public void resume() throws MuleException |
96 | |
{ |
97 | 0 | getComponent().resume(); |
98 | 0 | } |
99 | |
|
100 | |
public boolean isPaused() |
101 | |
{ |
102 | 0 | return getComponent().isPaused(); |
103 | |
} |
104 | |
|
105 | |
public boolean isStopped() |
106 | |
{ |
107 | 0 | return getComponent().isStopped(); |
108 | |
} |
109 | |
|
110 | |
public void stop() throws MuleException |
111 | |
{ |
112 | 0 | getComponent().stop(); |
113 | 0 | } |
114 | |
|
115 | |
public void forceStop() throws MuleException |
116 | |
{ |
117 | 0 | getComponent().forceStop(); |
118 | 0 | } |
119 | |
|
120 | |
public boolean isStopping() |
121 | |
{ |
122 | 0 | return getComponent().isStopping(); |
123 | |
} |
124 | |
|
125 | |
public void dispose() throws MuleException |
126 | |
{ |
127 | 0 | getComponent().dispose(); |
128 | 0 | } |
129 | |
|
130 | |
public void start() throws MuleException |
131 | |
{ |
132 | 0 | getComponent().start(); |
133 | 0 | } |
134 | |
|
135 | |
public ObjectName getStatistics() |
136 | |
{ |
137 | 0 | return statsName; |
138 | |
} |
139 | |
|
140 | |
public ObjectName preRegister(MBeanServer server, ObjectName name) throws Exception |
141 | |
{ |
142 | 0 | this.server = server; |
143 | 0 | this.objectName = name; |
144 | 0 | return name; |
145 | |
} |
146 | |
|
147 | |
public void postRegister(Boolean registrationDone) |
148 | |
{ |
149 | |
try |
150 | |
{ |
151 | 0 | if (getComponent().getStatistics() != null) |
152 | |
{ |
153 | 0 | statsName = new ObjectName(objectName.getDomain() + ":type=org.mule.Statistics,service=" |
154 | |
+ getName()); |
155 | |
|
156 | 0 | if (this.server.isRegistered(statsName)) |
157 | |
{ |
158 | 0 | this.server.unregisterMBean(statsName); |
159 | |
} |
160 | |
|
161 | 0 | this.server.registerMBean(new ServiceStats(getComponent().getStatistics()), this.statsName); |
162 | |
} |
163 | |
} |
164 | 0 | catch (Exception e) |
165 | |
{ |
166 | 0 | LOGGER.error("Error post-registering the MBean", e); |
167 | 0 | } |
168 | 0 | } |
169 | |
|
170 | |
public void preDeregister() throws Exception |
171 | |
{ |
172 | |
try |
173 | |
{ |
174 | 0 | if (this.server.isRegistered(statsName)) |
175 | |
{ |
176 | 0 | this.server.unregisterMBean(statsName); |
177 | |
} |
178 | |
} |
179 | 0 | catch (Exception ex) |
180 | |
{ |
181 | 0 | LOGGER.error("Error unregistering ServiceService child " + statsName.getCanonicalName(), ex); |
182 | 0 | } |
183 | 0 | } |
184 | |
|
185 | |
public void postDeregister() |
186 | |
{ |
187 | |
|
188 | 0 | } |
189 | |
|
190 | |
private AbstractService getComponent() |
191 | |
{ |
192 | 0 | return (AbstractService)muleContext.getRegistry().lookupService(getName()); |
193 | |
} |
194 | |
|
195 | |
|
196 | |
|
197 | |
public void clearStatistics() |
198 | |
{ |
199 | 0 | statistics.clear(); |
200 | 0 | } |
201 | |
|
202 | |
public long getAsyncEventsReceived() |
203 | |
{ |
204 | 0 | return statistics.getAsyncEventsReceived(); |
205 | |
} |
206 | |
|
207 | |
public long getAsyncEventsSent() |
208 | |
{ |
209 | 0 | return statistics.getAsyncEventsSent(); |
210 | |
} |
211 | |
|
212 | |
public long getAverageExecutionTime() |
213 | |
{ |
214 | 0 | return statistics.getAverageExecutionTime(); |
215 | |
} |
216 | |
|
217 | |
public long getAverageQueueSize() |
218 | |
{ |
219 | 0 | return statistics.getAverageQueueSize(); |
220 | |
} |
221 | |
|
222 | |
public long getExecutedEvents() |
223 | |
{ |
224 | 0 | return statistics.getExecutedEvents(); |
225 | |
} |
226 | |
|
227 | |
public long getExecutionErrors() |
228 | |
{ |
229 | 0 | return statistics.getExecutionErrors(); |
230 | |
} |
231 | |
|
232 | |
public long getFatalErrors() |
233 | |
{ |
234 | 0 | return statistics.getFatalErrors(); |
235 | |
} |
236 | |
|
237 | |
public long getMaxExecutionTime() |
238 | |
{ |
239 | 0 | return statistics.getMaxExecutionTime(); |
240 | |
} |
241 | |
|
242 | |
public long getMaxQueueSize() |
243 | |
{ |
244 | 0 | return statistics.getMaxQueueSize(); |
245 | |
} |
246 | |
|
247 | |
public long getMinExecutionTime() |
248 | |
{ |
249 | 0 | return statistics.getMinExecutionTime(); |
250 | |
} |
251 | |
|
252 | |
public String getName() |
253 | |
{ |
254 | 0 | return name; |
255 | |
} |
256 | |
|
257 | |
public long getQueuedEvents() |
258 | |
{ |
259 | 0 | return statistics.getQueuedEvents(); |
260 | |
} |
261 | |
|
262 | |
public long getReplyToEventsSent() |
263 | |
{ |
264 | 0 | return statistics.getReplyToEventsSent(); |
265 | |
} |
266 | |
|
267 | |
public long getSyncEventsReceived() |
268 | |
{ |
269 | 0 | return statistics.getSyncEventsReceived(); |
270 | |
} |
271 | |
|
272 | |
public long getSyncEventsSent() |
273 | |
{ |
274 | 0 | return statistics.getSyncEventsSent(); |
275 | |
} |
276 | |
|
277 | |
public long getTotalEventsReceived() |
278 | |
{ |
279 | 0 | return statistics.getTotalEventsReceived(); |
280 | |
} |
281 | |
|
282 | |
public long getTotalEventsSent() |
283 | |
{ |
284 | 0 | return statistics.getTotalEventsSent(); |
285 | |
} |
286 | |
|
287 | |
public long getTotalExecutionTime() |
288 | |
{ |
289 | 0 | return statistics.getTotalExecutionTime(); |
290 | |
} |
291 | |
} |