1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
package org.mule.management.stats; |
12 | |
|
13 | |
import java.io.PrintWriter; |
14 | |
|
15 | |
import org.mule.management.stats.printers.SimplePrinter; |
16 | |
|
17 | |
import edu.emory.mathcs.backport.java.util.concurrent.atomic.AtomicLong; |
18 | |
|
19 | |
public class ServiceStatistics extends FlowConstructStatistics implements QueueStatistics |
20 | |
{ |
21 | |
private static final long serialVersionUID = -2086999226732861675L; |
22 | |
|
23 | 0 | private final AtomicLong sentEventSync = new AtomicLong(0); |
24 | 0 | private final AtomicLong sentReplyToEvent = new AtomicLong(0); |
25 | 0 | private final AtomicLong sentEventASync = new AtomicLong(0); |
26 | 0 | private final AtomicLong executionError = new AtomicLong(0); |
27 | 0 | private final AtomicLong fatalError = new AtomicLong(0); |
28 | |
|
29 | |
|
30 | |
|
31 | 0 | private long queuedEvent = 0; |
32 | 0 | private long maxQueuedEvent = 0; |
33 | 0 | private long averageQueueSize = 0; |
34 | 0 | private long totalQueuedEvent = 0; |
35 | |
|
36 | 0 | private int threadPoolSize = 0; |
37 | 0 | private long samplePeriod = 0; |
38 | |
|
39 | 0 | private RouterStatistics inboundRouterStat = null; |
40 | 0 | private ComponentStatistics componentStat = null; |
41 | 0 | private RouterStatistics outboundRouterStat = null; |
42 | |
|
43 | |
public ServiceStatistics(String name) |
44 | |
{ |
45 | 0 | this(name, 0); |
46 | 0 | } |
47 | |
|
48 | |
public ServiceStatistics(String name, int threadPoolSize) |
49 | |
{ |
50 | 0 | super(name); |
51 | |
|
52 | 0 | this.threadPoolSize = threadPoolSize; |
53 | 0 | clear(); |
54 | 0 | } |
55 | |
|
56 | |
|
57 | |
|
58 | |
|
59 | |
@Override |
60 | |
public synchronized void setEnabled(boolean b) |
61 | |
{ |
62 | 0 | super.setEnabled(b); |
63 | |
|
64 | 0 | if (inboundRouterStat != null) |
65 | |
{ |
66 | 0 | inboundRouterStat.setEnabled(b); |
67 | |
} |
68 | 0 | if (componentStat != null) |
69 | |
{ |
70 | 0 | componentStat.setEnabled(b); |
71 | |
} |
72 | 0 | if (outboundRouterStat != null) |
73 | |
{ |
74 | 0 | outboundRouterStat.setEnabled(b); |
75 | |
} |
76 | 0 | } |
77 | |
|
78 | |
public void incExecutionError() |
79 | |
{ |
80 | 0 | executionError.addAndGet(1); |
81 | 0 | } |
82 | |
|
83 | |
public void incFatalError() |
84 | |
{ |
85 | 0 | fatalError.addAndGet(1); |
86 | 0 | } |
87 | |
|
88 | |
public void incSentEventSync() |
89 | |
{ |
90 | 0 | sentEventSync.addAndGet(1); |
91 | 0 | } |
92 | |
|
93 | |
public void incSentEventASync() |
94 | |
{ |
95 | 0 | sentEventASync.addAndGet(1); |
96 | 0 | } |
97 | |
|
98 | |
public void incSentReplyToEvent() |
99 | |
{ |
100 | 0 | sentReplyToEvent.addAndGet(1); |
101 | 0 | } |
102 | |
|
103 | |
public synchronized void incQueuedEvent() |
104 | |
{ |
105 | 0 | queuedEvent++; |
106 | 0 | totalQueuedEvent++; |
107 | 0 | if (queuedEvent > maxQueuedEvent) |
108 | |
{ |
109 | 0 | maxQueuedEvent = queuedEvent; |
110 | |
} |
111 | 0 | averageQueueSize = receivedEventASync.get() / totalQueuedEvent; |
112 | 0 | } |
113 | |
|
114 | |
public synchronized void decQueuedEvent() |
115 | |
{ |
116 | 0 | queuedEvent--; |
117 | 0 | } |
118 | |
|
119 | |
public long getAverageExecutionTime() |
120 | |
{ |
121 | 0 | return componentStat.getAverageExecutionTime(); |
122 | |
} |
123 | |
|
124 | |
public synchronized long getAverageQueueSize() |
125 | |
{ |
126 | 0 | return averageQueueSize; |
127 | |
} |
128 | |
|
129 | |
public synchronized long getMaxQueueSize() |
130 | |
{ |
131 | 0 | return maxQueuedEvent; |
132 | |
} |
133 | |
|
134 | |
|
135 | |
|
136 | |
|
137 | |
@Deprecated |
138 | |
public long getMaxExecutionTime() |
139 | |
{ |
140 | 0 | return componentStat.getMaxExecutionTime(); |
141 | |
} |
142 | |
|
143 | |
public long getFatalErrors() |
144 | |
{ |
145 | 0 | return fatalError.get(); |
146 | |
} |
147 | |
|
148 | |
|
149 | |
|
150 | |
|
151 | |
@Deprecated |
152 | |
public long getMinExecutionTime() |
153 | |
{ |
154 | 0 | return componentStat.getMinExecutionTime(); |
155 | |
} |
156 | |
|
157 | |
|
158 | |
|
159 | |
|
160 | |
@Deprecated |
161 | |
public long getTotalExecutionTime() |
162 | |
{ |
163 | 0 | return componentStat.getTotalExecutionTime(); |
164 | |
} |
165 | |
|
166 | |
public synchronized long getQueuedEvents() |
167 | |
{ |
168 | 0 | return queuedEvent; |
169 | |
} |
170 | |
|
171 | |
public long getReplyToEventsSent() |
172 | |
{ |
173 | 0 | return sentReplyToEvent.get(); |
174 | |
} |
175 | |
|
176 | |
public long getSyncEventsSent() |
177 | |
{ |
178 | 0 | return sentEventSync.get(); |
179 | |
} |
180 | |
|
181 | |
public long getAsyncEventsSent() |
182 | |
{ |
183 | 0 | return sentEventASync.get(); |
184 | |
} |
185 | |
|
186 | |
public long getTotalEventsSent() |
187 | |
{ |
188 | 0 | return getSyncEventsSent() + getAsyncEventsSent(); |
189 | |
} |
190 | |
|
191 | |
public long getTotalEventsReceived() |
192 | |
{ |
193 | 0 | return getSyncEventsReceived() + getAsyncEventsReceived(); |
194 | |
} |
195 | |
|
196 | |
public long getExecutedEvents() |
197 | |
{ |
198 | 0 | return componentStat.getExecutedEvents(); |
199 | |
} |
200 | |
|
201 | |
public long getExecutionErrors() |
202 | |
{ |
203 | 0 | return executionError.get(); |
204 | |
} |
205 | |
|
206 | |
public void logSummary() |
207 | |
{ |
208 | 0 | logSummary(new SimplePrinter(System.out)); |
209 | 0 | } |
210 | |
|
211 | |
public void logSummary(PrintWriter printer) |
212 | |
{ |
213 | 0 | printer.print(this); |
214 | 0 | } |
215 | |
|
216 | |
@Override |
217 | |
public synchronized void clear() |
218 | |
{ |
219 | 0 | super.clear(); |
220 | 0 | queuedEvent = 0; |
221 | 0 | maxQueuedEvent = 0; |
222 | 0 | totalQueuedEvent = 0; |
223 | 0 | averageQueueSize = 0; |
224 | |
|
225 | 0 | sentEventSync.set(0); |
226 | 0 | sentEventASync.set(0); |
227 | 0 | sentReplyToEvent.set(0); |
228 | |
|
229 | 0 | executionError.set(0); |
230 | 0 | fatalError.set(0); |
231 | |
|
232 | 0 | if (getInboundRouterStat() != null) |
233 | |
{ |
234 | 0 | getInboundRouterStat().clear(); |
235 | |
} |
236 | 0 | if (getOutboundRouterStat() != null) |
237 | |
{ |
238 | 0 | getOutboundRouterStat().clear(); |
239 | |
} |
240 | |
|
241 | 0 | samplePeriod = System.currentTimeMillis(); |
242 | 0 | } |
243 | |
|
244 | |
public RouterStatistics getInboundRouterStat() |
245 | |
{ |
246 | 0 | return inboundRouterStat; |
247 | |
} |
248 | |
|
249 | |
public void setInboundRouterStat(RouterStatistics inboundRouterStat) |
250 | |
{ |
251 | 0 | this.inboundRouterStat = inboundRouterStat; |
252 | 0 | this.inboundRouterStat.setEnabled(enabled); |
253 | 0 | } |
254 | |
|
255 | |
public RouterStatistics getOutboundRouterStat() |
256 | |
{ |
257 | 0 | return outboundRouterStat; |
258 | |
} |
259 | |
|
260 | |
public void setOutboundRouterStat(RouterStatistics outboundRouterStat) |
261 | |
{ |
262 | 0 | this.outboundRouterStat = outboundRouterStat; |
263 | 0 | this.outboundRouterStat.setEnabled(enabled); |
264 | 0 | } |
265 | |
|
266 | |
public ComponentStatistics getComponentStat() |
267 | |
{ |
268 | 0 | return componentStat; |
269 | |
} |
270 | |
|
271 | |
public void setComponentStat(ComponentStatistics componentStat) |
272 | |
{ |
273 | 0 | this.componentStat = componentStat; |
274 | 0 | this.componentStat.setEnabled(enabled); |
275 | 0 | } |
276 | |
|
277 | |
public int getThreadPoolSize() |
278 | |
{ |
279 | 0 | return threadPoolSize; |
280 | |
} |
281 | |
|
282 | |
public long getSamplePeriod() |
283 | |
{ |
284 | 0 | return System.currentTimeMillis() - samplePeriod; |
285 | |
} |
286 | |
} |