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