1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
package org.mule.management.stats; |
12 | |
|
13 | |
import org.mule.api.management.stats.Statistics; |
14 | |
import org.mule.management.stats.printers.SimplePrinter; |
15 | |
|
16 | |
import java.io.PrintWriter; |
17 | |
|
18 | |
public class ServiceStatistics implements Statistics |
19 | |
{ |
20 | |
|
21 | |
|
22 | |
|
23 | |
private static final long serialVersionUID = -2086999226732861674L; |
24 | |
|
25 | |
private String name; |
26 | 398 | private long receivedEventSync = 0; |
27 | 398 | private long receivedEventASync = 0; |
28 | 398 | private long queuedEvent = 0; |
29 | 398 | private long maxQueuedEvent = 0; |
30 | 398 | private long averageQueueSize = 0; |
31 | 398 | private long totalQueuedEvent = 0; |
32 | 398 | private long sentEventSync = 0; |
33 | 398 | private long sentReplyToEvent = 0; |
34 | 398 | private long sentEventASync = 0; |
35 | 398 | private long executionError = 0; |
36 | 398 | private long fatalError = 0; |
37 | |
|
38 | 398 | private int threadPoolSize = 0; |
39 | 398 | private long samplePeriod = 0; |
40 | 398 | private boolean enabled = false; |
41 | |
|
42 | 398 | private RouterStatistics inboundRouterStat = null; |
43 | 398 | private ComponentStatistics componentStat = null; |
44 | 398 | private RouterStatistics outboundRouterStat = null; |
45 | |
|
46 | |
public ServiceStatistics(String name) |
47 | |
{ |
48 | 8 | this(name, 0); |
49 | 8 | } |
50 | |
|
51 | |
|
52 | |
|
53 | |
|
54 | |
|
55 | |
|
56 | |
public ServiceStatistics(String name, int threadPoolSize) |
57 | |
{ |
58 | 398 | super(); |
59 | 398 | this.name = name; |
60 | |
|
61 | 398 | this.threadPoolSize = threadPoolSize; |
62 | 398 | clear(); |
63 | 398 | } |
64 | |
|
65 | |
|
66 | |
|
67 | |
|
68 | |
public boolean isEnabled() |
69 | |
{ |
70 | 0 | return enabled; |
71 | |
} |
72 | |
|
73 | |
|
74 | |
|
75 | |
|
76 | |
public synchronized void setEnabled(boolean b) |
77 | |
{ |
78 | 398 | enabled = b; |
79 | |
|
80 | 398 | if (inboundRouterStat != null) |
81 | |
{ |
82 | 0 | inboundRouterStat.setEnabled(b); |
83 | |
} |
84 | 398 | if (componentStat != null) |
85 | |
{ |
86 | 0 | componentStat.setEnabled(b); |
87 | |
} |
88 | 398 | if (outboundRouterStat != null) |
89 | |
{ |
90 | 0 | outboundRouterStat.setEnabled(b); |
91 | |
} |
92 | 398 | } |
93 | |
|
94 | |
public synchronized void incReceivedEventSync() |
95 | |
{ |
96 | 0 | receivedEventSync++; |
97 | 0 | } |
98 | |
|
99 | |
public synchronized void incReceivedEventASync() |
100 | |
{ |
101 | 0 | receivedEventASync++; |
102 | 0 | } |
103 | |
|
104 | |
public synchronized void incExecutionError() |
105 | |
{ |
106 | 0 | executionError++; |
107 | 0 | } |
108 | |
|
109 | |
public synchronized void incFatalError() |
110 | |
{ |
111 | 0 | fatalError++; |
112 | 0 | } |
113 | |
|
114 | |
public synchronized void incSentEventSync() |
115 | |
{ |
116 | 0 | sentEventSync++; |
117 | 0 | } |
118 | |
|
119 | |
public synchronized void incSentEventASync() |
120 | |
{ |
121 | 0 | sentEventASync++; |
122 | 0 | } |
123 | |
|
124 | |
public synchronized void incSentReplyToEvent() |
125 | |
{ |
126 | 0 | sentReplyToEvent++; |
127 | 0 | } |
128 | |
|
129 | |
public synchronized void incQueuedEvent() |
130 | |
{ |
131 | 0 | queuedEvent++; |
132 | 0 | totalQueuedEvent++; |
133 | 0 | if (queuedEvent > maxQueuedEvent) |
134 | |
{ |
135 | 0 | maxQueuedEvent = queuedEvent; |
136 | |
} |
137 | |
|
138 | 0 | averageQueueSize = Math.round(getAsyncEventsReceived() / totalQueuedEvent); |
139 | |
|
140 | 0 | } |
141 | |
|
142 | |
public synchronized void decQueuedEvent() |
143 | |
{ |
144 | 0 | queuedEvent--; |
145 | 0 | } |
146 | |
|
147 | |
public long getAverageExecutionTime() |
148 | |
{ |
149 | 0 | return componentStat.getAverageExecutionTime(); |
150 | |
} |
151 | |
|
152 | |
public long getAverageQueueSize() |
153 | |
{ |
154 | 0 | return averageQueueSize; |
155 | |
} |
156 | |
|
157 | |
public long getMaxQueueSize() |
158 | |
{ |
159 | 0 | return maxQueuedEvent; |
160 | |
} |
161 | |
|
162 | |
|
163 | |
|
164 | |
|
165 | |
|
166 | |
public long getMaxExecutionTime() |
167 | |
{ |
168 | 0 | return componentStat.getMaxExecutionTime(); |
169 | |
} |
170 | |
|
171 | |
public long getFatalErrors() |
172 | |
{ |
173 | 0 | return fatalError; |
174 | |
} |
175 | |
|
176 | |
|
177 | |
|
178 | |
|
179 | |
|
180 | |
public long getMinExecutionTime() |
181 | |
{ |
182 | 0 | return componentStat.getMinExecutionTime(); |
183 | |
} |
184 | |
|
185 | |
|
186 | |
|
187 | |
|
188 | |
|
189 | |
public long getTotalExecutionTime() |
190 | |
{ |
191 | 0 | return componentStat.getTotalExecutionTime(); |
192 | |
} |
193 | |
|
194 | |
public long getQueuedEvents() |
195 | |
{ |
196 | 0 | return queuedEvent; |
197 | |
} |
198 | |
|
199 | |
public long getAsyncEventsReceived() |
200 | |
{ |
201 | 0 | return receivedEventASync; |
202 | |
} |
203 | |
|
204 | |
public long getSyncEventsReceived() |
205 | |
{ |
206 | 0 | return receivedEventSync; |
207 | |
} |
208 | |
|
209 | |
public long getReplyToEventsSent() |
210 | |
{ |
211 | 0 | return sentReplyToEvent; |
212 | |
} |
213 | |
|
214 | |
public long getSyncEventsSent() |
215 | |
{ |
216 | 0 | return sentEventSync; |
217 | |
} |
218 | |
|
219 | |
public long getAsyncEventsSent() |
220 | |
{ |
221 | 0 | return sentEventASync; |
222 | |
} |
223 | |
|
224 | |
public long getTotalEventsSent() |
225 | |
{ |
226 | 0 | return getSyncEventsSent() + getAsyncEventsSent(); |
227 | |
} |
228 | |
|
229 | |
public long getTotalEventsReceived() |
230 | |
{ |
231 | 0 | return getSyncEventsReceived() + getAsyncEventsReceived(); |
232 | |
} |
233 | |
|
234 | |
public long getExecutedEvents() |
235 | |
{ |
236 | 0 | return componentStat.getExecutedEvents(); |
237 | |
} |
238 | |
|
239 | |
public long getExecutionErrors() |
240 | |
{ |
241 | 0 | return executionError; |
242 | |
} |
243 | |
|
244 | |
public synchronized String getName() |
245 | |
{ |
246 | 410 | return name; |
247 | |
} |
248 | |
|
249 | |
public synchronized void setName(String name) |
250 | |
{ |
251 | 0 | this.name = name; |
252 | 0 | } |
253 | |
|
254 | |
|
255 | |
|
256 | |
|
257 | |
public void logSummary() |
258 | |
{ |
259 | 0 | logSummary(new SimplePrinter(System.out)); |
260 | 0 | } |
261 | |
|
262 | |
public void logSummary(PrintWriter printer) |
263 | |
{ |
264 | 0 | printer.print(this); |
265 | 0 | } |
266 | |
|
267 | |
public synchronized void clear() |
268 | |
{ |
269 | 398 | receivedEventSync = 0; |
270 | 398 | receivedEventASync = 0; |
271 | 398 | queuedEvent = 0; |
272 | 398 | maxQueuedEvent = 0; |
273 | 398 | totalQueuedEvent = 0; |
274 | 398 | averageQueueSize = 0; |
275 | |
|
276 | 398 | sentEventSync = 0; |
277 | 398 | sentEventASync = 0; |
278 | 398 | sentReplyToEvent = 0; |
279 | |
|
280 | 398 | executionError = 0; |
281 | 398 | fatalError = 0; |
282 | |
|
283 | 398 | if (getInboundRouterStat() != null) |
284 | |
{ |
285 | 0 | getInboundRouterStat().clear(); |
286 | |
} |
287 | 398 | if (getOutboundRouterStat() != null) |
288 | |
{ |
289 | 0 | getOutboundRouterStat().clear(); |
290 | |
} |
291 | |
|
292 | 398 | samplePeriod = System.currentTimeMillis(); |
293 | |
|
294 | 398 | } |
295 | |
|
296 | |
|
297 | |
|
298 | |
|
299 | |
public RouterStatistics getInboundRouterStat() |
300 | |
{ |
301 | 398 | return inboundRouterStat; |
302 | |
} |
303 | |
|
304 | |
|
305 | |
|
306 | |
|
307 | |
public void setInboundRouterStat(RouterStatistics inboundRouterStat) |
308 | |
{ |
309 | 398 | this.inboundRouterStat = inboundRouterStat; |
310 | 398 | this.inboundRouterStat.setEnabled(enabled); |
311 | 398 | } |
312 | |
|
313 | |
|
314 | |
|
315 | |
|
316 | |
public RouterStatistics getOutboundRouterStat() |
317 | |
{ |
318 | 398 | return outboundRouterStat; |
319 | |
} |
320 | |
|
321 | |
|
322 | |
|
323 | |
|
324 | |
public void setOutboundRouterStat(RouterStatistics outboundRouterStat) |
325 | |
{ |
326 | 398 | this.outboundRouterStat = outboundRouterStat; |
327 | 398 | this.outboundRouterStat.setEnabled(enabled); |
328 | 398 | } |
329 | |
|
330 | |
|
331 | |
|
332 | |
|
333 | |
public ComponentStatistics getComponentStat() |
334 | |
{ |
335 | 0 | return componentStat; |
336 | |
} |
337 | |
|
338 | |
|
339 | |
|
340 | |
|
341 | |
public void setComponentStat(ComponentStatistics componentStat) |
342 | |
{ |
343 | 398 | this.componentStat = componentStat; |
344 | 398 | this.componentStat.setEnabled(enabled); |
345 | 398 | } |
346 | |
|
347 | |
public int getThreadPoolSize() |
348 | |
{ |
349 | 0 | return threadPoolSize; |
350 | |
} |
351 | |
|
352 | |
public long getSamplePeriod() |
353 | |
{ |
354 | 0 | return System.currentTimeMillis() - samplePeriod; |
355 | |
} |
356 | |
} |