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