1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
package org.mule.management.stats; |
12 | |
|
13 | |
import org.mule.api.endpoint.ImmutableEndpoint; |
14 | |
import org.mule.api.management.stats.Statistics; |
15 | |
import org.mule.management.stats.printers.SimplePrinter; |
16 | |
|
17 | |
import java.io.PrintWriter; |
18 | |
import java.util.ArrayList; |
19 | |
import java.util.Collection; |
20 | |
import java.util.HashMap; |
21 | |
import java.util.List; |
22 | |
import java.util.Map; |
23 | |
|
24 | |
|
25 | |
|
26 | |
|
27 | |
|
28 | |
public class RouterStatistics implements Statistics |
29 | |
{ |
30 | |
|
31 | |
|
32 | |
|
33 | |
|
34 | |
private static final long serialVersionUID = 4540482357430845065L; |
35 | |
|
36 | |
public static final int TYPE_INBOUND = 1; |
37 | |
public static final int TYPE_OUTBOUND = 2; |
38 | |
public static final int TYPE_RESPONSE = 3; |
39 | |
public static final int TYPE_BINDING = 4; |
40 | |
|
41 | |
private boolean enabled; |
42 | |
private long notRouted; |
43 | |
private long caughtInCatchAll; |
44 | |
private long totalRouted; |
45 | |
private long totalReceived; |
46 | |
private Map routed; |
47 | |
private int type; |
48 | |
|
49 | |
|
50 | |
|
51 | |
|
52 | |
public synchronized void clear() |
53 | |
{ |
54 | 0 | notRouted = 0; |
55 | 0 | totalRouted = 0; |
56 | 0 | totalReceived = 0; |
57 | 0 | caughtInCatchAll = 0; |
58 | 0 | routed.clear(); |
59 | 0 | } |
60 | |
|
61 | |
|
62 | |
|
63 | |
|
64 | |
public boolean isEnabled() |
65 | |
{ |
66 | 0 | return enabled; |
67 | |
} |
68 | |
|
69 | |
public void logSummary() |
70 | |
{ |
71 | 0 | logSummary(new SimplePrinter(System.out)); |
72 | 0 | } |
73 | |
|
74 | |
public void logSummary(PrintWriter printer) |
75 | |
{ |
76 | 0 | printer.print(this); |
77 | 0 | } |
78 | |
|
79 | |
|
80 | |
|
81 | |
|
82 | |
public synchronized void setEnabled(boolean b) |
83 | |
{ |
84 | 0 | enabled = b; |
85 | 0 | } |
86 | |
|
87 | |
|
88 | |
|
89 | |
|
90 | |
public RouterStatistics(int type) |
91 | |
{ |
92 | 0 | super(); |
93 | 0 | this.type = type; |
94 | 0 | routed = new HashMap(); |
95 | 0 | } |
96 | |
|
97 | |
|
98 | |
|
99 | |
|
100 | |
|
101 | |
|
102 | |
public void incrementRoutedMessage(Collection endpoints) |
103 | |
{ |
104 | 0 | if (endpoints == null || endpoints.isEmpty()) |
105 | |
{ |
106 | 0 | return; |
107 | |
} |
108 | 0 | List list = new ArrayList(endpoints); |
109 | 0 | synchronized (list) |
110 | |
{ |
111 | 0 | for (int i = 0; i < list.size(); i++) |
112 | |
{ |
113 | 0 | incrementRoutedMessage(list.get(i)); |
114 | |
} |
115 | 0 | } |
116 | 0 | } |
117 | |
|
118 | |
|
119 | |
|
120 | |
|
121 | |
|
122 | |
|
123 | |
public synchronized void incrementRoutedMessage(Object endpoint) |
124 | |
{ |
125 | 0 | if (endpoint == null) |
126 | |
{ |
127 | 0 | return; |
128 | |
} |
129 | |
|
130 | |
String name; |
131 | 0 | if (endpoint instanceof ImmutableEndpoint) |
132 | |
{ |
133 | 0 | name = ((ImmutableEndpoint)endpoint).getName(); |
134 | |
} |
135 | |
else |
136 | |
{ |
137 | 0 | name = endpoint.toString(); |
138 | |
} |
139 | |
|
140 | 0 | Long cpt = (Long) routed.get(name); |
141 | 0 | long count = 0; |
142 | |
|
143 | 0 | if (cpt != null) |
144 | |
{ |
145 | 0 | count = cpt.longValue(); |
146 | |
} |
147 | |
|
148 | |
|
149 | |
|
150 | 0 | routed.put(name, new Long(++count)); |
151 | |
|
152 | 0 | totalRouted++; |
153 | 0 | totalReceived++; |
154 | 0 | } |
155 | |
|
156 | |
|
157 | |
|
158 | |
|
159 | |
public synchronized void incrementNoRoutedMessage() |
160 | |
{ |
161 | 0 | notRouted++; |
162 | 0 | totalReceived++; |
163 | 0 | } |
164 | |
|
165 | |
|
166 | |
|
167 | |
|
168 | |
public synchronized void incrementCaughtMessage() |
169 | |
{ |
170 | 0 | caughtInCatchAll++; |
171 | 0 | } |
172 | |
|
173 | |
|
174 | |
|
175 | |
|
176 | |
public final long getCaughtMessages() |
177 | |
{ |
178 | 0 | return caughtInCatchAll; |
179 | |
} |
180 | |
|
181 | |
|
182 | |
|
183 | |
|
184 | |
public final long getNotRouted() |
185 | |
{ |
186 | 0 | return notRouted; |
187 | |
} |
188 | |
|
189 | |
|
190 | |
|
191 | |
|
192 | |
public final long getTotalReceived() |
193 | |
{ |
194 | 0 | return totalReceived; |
195 | |
} |
196 | |
|
197 | |
|
198 | |
|
199 | |
|
200 | |
public final long getTotalRouted() |
201 | |
{ |
202 | 0 | return totalRouted; |
203 | |
} |
204 | |
|
205 | |
|
206 | |
|
207 | |
|
208 | |
public final long getRouted(String endpointName) |
209 | |
{ |
210 | 0 | Long l = (Long) routed.get(endpointName); |
211 | |
|
212 | 0 | if (l == null) |
213 | |
{ |
214 | 0 | return 0; |
215 | |
} |
216 | |
else |
217 | |
{ |
218 | 0 | return l.longValue(); |
219 | |
} |
220 | |
} |
221 | |
|
222 | |
public boolean isInbound() |
223 | |
{ |
224 | 0 | return type == TYPE_INBOUND; |
225 | |
} |
226 | |
|
227 | |
public Map getRouted() |
228 | |
{ |
229 | 0 | return routed; |
230 | |
} |
231 | |
} |