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