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