1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
package org.mule.management.stats.printers; |
12 | |
|
13 | |
import org.mule.management.stats.FlowConstructStatistics; |
14 | |
import org.mule.management.stats.ServiceStatistics; |
15 | |
import org.mule.management.stats.RouterStatistics; |
16 | |
import org.mule.management.stats.SedaServiceStatistics; |
17 | |
|
18 | |
import java.io.OutputStream; |
19 | |
import java.io.PrintWriter; |
20 | |
import java.io.Writer; |
21 | |
import java.util.ArrayList; |
22 | |
import java.util.Arrays; |
23 | |
import java.util.Collection; |
24 | |
import java.util.Iterator; |
25 | |
import java.util.List; |
26 | |
import java.util.Map; |
27 | |
|
28 | |
|
29 | |
|
30 | |
|
31 | |
public class AbstractTablePrinter extends PrintWriter |
32 | |
{ |
33 | |
public AbstractTablePrinter(Writer out) |
34 | |
{ |
35 | 0 | super(out, true); |
36 | 0 | } |
37 | |
|
38 | |
public AbstractTablePrinter(OutputStream out) |
39 | |
{ |
40 | 0 | super(out, true); |
41 | 0 | } |
42 | |
|
43 | |
public String[] getHeaders() |
44 | |
{ |
45 | 0 | String[] column = new String[41]; |
46 | 0 | column[0] = "Name"; |
47 | 0 | column[1] = "Service Pool Max Size"; |
48 | 0 | column[2] = "Service Pool Size"; |
49 | 0 | column[3] = "Thread Pool Size"; |
50 | 0 | column[4] = "Current Queue Size"; |
51 | 0 | column[5] = "Max Queue Size"; |
52 | 0 | column[6] = "Avg Queue Size"; |
53 | 0 | column[7] = "Sync Events Received"; |
54 | 0 | column[8] = "Async Events Received"; |
55 | 0 | column[9] = "Total Events Received"; |
56 | 0 | column[10] = "Sync Events Sent"; |
57 | 0 | column[11] = "Async Events Sent"; |
58 | 0 | column[12] = "ReplyTo Events Sent"; |
59 | 0 | column[13] = "Total Events Sent"; |
60 | 0 | column[14] = "Executed Events"; |
61 | 0 | column[15] = "Execution Messages"; |
62 | 0 | column[16] = "Fatal Messages"; |
63 | 0 | column[17] = "Min Execution Time"; |
64 | 0 | column[18] = "Max Execution Time"; |
65 | 0 | column[19] = "Avg Execution Time"; |
66 | 0 | column[20] = "Total Execution Time"; |
67 | 0 | column[21] = "Processed Events"; |
68 | 0 | column[22] = "Min Processing Time"; |
69 | 0 | column[23] = "Max Processing Time"; |
70 | 0 | column[24] = "Avg Processing Time"; |
71 | 0 | column[25] = "Total Processing Time"; |
72 | 0 | column[26] = "In Router Statistics"; |
73 | 0 | column[27] = "Total Received"; |
74 | 0 | column[28] = "Total Routed"; |
75 | 0 | column[29] = "Not Routed"; |
76 | 0 | column[30] = "Caught Events"; |
77 | 0 | column[31] = "By Provider"; |
78 | 0 | column[32] = ""; |
79 | 0 | column[33] = "Out Router Statistics"; |
80 | 0 | column[34] = "Total Received"; |
81 | 0 | column[35] = "Total Routed"; |
82 | 0 | column[36] = "Not Routed"; |
83 | 0 | column[37] = "Caught Events"; |
84 | 0 | column[38] = "By Provider"; |
85 | 0 | column[39] = ""; |
86 | 0 | column[40] = "Sample Period"; |
87 | 0 | return column; |
88 | |
} |
89 | |
|
90 | |
protected void getColumn(FlowConstructStatistics stats, String[] col) |
91 | |
{ |
92 | 0 | if (stats == null) |
93 | |
{ |
94 | 0 | return; |
95 | |
} |
96 | 0 | ServiceStatistics serviceStats = (stats instanceof ServiceStatistics) ? (ServiceStatistics) stats : null; |
97 | |
|
98 | 0 | Arrays.fill(col, "-"); |
99 | |
|
100 | 0 | col[0] = stats.getName(); |
101 | |
|
102 | |
|
103 | 0 | if (stats instanceof SedaServiceStatistics) |
104 | |
{ |
105 | 0 | col[1] = ((SedaServiceStatistics) stats).getComponentPoolMaxSize() + "/" |
106 | |
+ ((SedaServiceStatistics) stats).getComponentPoolAbsoluteMaxSize(); |
107 | 0 | col[2] = String.valueOf(((SedaServiceStatistics) stats).getComponentPoolSize()); |
108 | |
} |
109 | |
else |
110 | |
{ |
111 | 0 | col[1] = "-"; |
112 | 0 | col[2] = "-"; |
113 | |
} |
114 | 0 | col[3] = String.valueOf(stats.getThreadPoolSize()); |
115 | 0 | if (serviceStats != null) |
116 | |
{ |
117 | 0 | col[4] = String.valueOf(serviceStats.getQueuedEvents()); |
118 | 0 | col[5] = String.valueOf(serviceStats.getMaxQueueSize()); |
119 | 0 | col[6] = String.valueOf(serviceStats.getAverageQueueSize()); |
120 | |
} |
121 | 0 | col[7] = String.valueOf(stats.getSyncEventsReceived()); |
122 | 0 | col[8] = String.valueOf(stats.getAsyncEventsReceived()); |
123 | 0 | col[9] = String.valueOf(stats.getTotalEventsReceived()); |
124 | 0 | if (serviceStats != null) |
125 | |
{ |
126 | 0 | col[10] = String.valueOf(serviceStats.getSyncEventsSent()); |
127 | 0 | col[11] = String.valueOf(serviceStats.getAsyncEventsSent()); |
128 | 0 | col[12] = String.valueOf(serviceStats.getReplyToEventsSent()); |
129 | 0 | col[13] = String.valueOf(serviceStats.getTotalEventsSent()); |
130 | |
} |
131 | |
|
132 | 0 | if (serviceStats != null) |
133 | |
{ |
134 | 0 | col[14] = String.valueOf(serviceStats.getExecutedEvents()); |
135 | |
} |
136 | 0 | col[15] = String.valueOf(stats.getExecutionErrors()); |
137 | 0 | col[16] = String.valueOf(stats.getFatalErrors()); |
138 | 0 | if (serviceStats != null) |
139 | |
{ |
140 | 0 | col[17] = String.valueOf(serviceStats.getMinExecutionTime()); |
141 | 0 | col[18] = String.valueOf(serviceStats.getMaxExecutionTime()); |
142 | 0 | col[19] = String.valueOf(serviceStats.getAverageExecutionTime()); |
143 | 0 | col[20] = String.valueOf(serviceStats.getTotalExecutionTime()); |
144 | |
} |
145 | |
|
146 | 0 | col[21] = String.valueOf(stats.getProcessedEvents()); |
147 | 0 | col[22] = String.valueOf(stats.getMinProcessingTime()); |
148 | 0 | col[23] = String.valueOf(stats.getMaxProcessingTime()); |
149 | 0 | col[24] = String.valueOf(stats.getAverageProcessingTime()); |
150 | 0 | col[25] = String.valueOf(stats.getTotalProcessingTime()); |
151 | |
|
152 | 0 | if (serviceStats != null) |
153 | |
{ |
154 | 0 | int i = getRouterInfo(serviceStats.getInboundRouterStat(), col, 26); |
155 | 0 | i = getRouterInfo(serviceStats.getOutboundRouterStat(), col, i); |
156 | |
} |
157 | |
|
158 | 0 | col[40] = String.valueOf(stats.getSamplePeriod()); |
159 | 0 | } |
160 | |
|
161 | |
protected int getRouterInfo(RouterStatistics stats, String[] col, int index) |
162 | |
{ |
163 | |
|
164 | 0 | if (stats.isInbound()) |
165 | |
{ |
166 | 0 | col[index++] = "-"; |
167 | |
} |
168 | |
else |
169 | |
{ |
170 | 0 | col[index++] = "-"; |
171 | |
} |
172 | |
|
173 | 0 | col[index++] = String.valueOf(stats.getTotalReceived()); |
174 | 0 | col[index++] = String.valueOf(stats.getTotalRouted()); |
175 | 0 | col[index++] = String.valueOf(stats.getNotRouted()); |
176 | 0 | col[index++] = String.valueOf(stats.getCaughtMessages()); |
177 | |
|
178 | 0 | Map routed = stats.getRouted(); |
179 | |
|
180 | 0 | col[index++] = "-"; |
181 | 0 | if (!routed.isEmpty()) |
182 | |
{ |
183 | 0 | Iterator it = routed.entrySet().iterator(); |
184 | |
|
185 | 0 | StringBuffer buf = new StringBuffer(40); |
186 | 0 | while (it.hasNext()) |
187 | |
{ |
188 | 0 | Map.Entry e = (Map.Entry) it.next(); |
189 | 0 | buf.append(e.getKey()).append('=').append(e.getValue()); |
190 | 0 | if (it.hasNext()) |
191 | |
{ |
192 | 0 | buf.append(';'); |
193 | |
} |
194 | 0 | } |
195 | 0 | col[index++] = buf.toString(); |
196 | 0 | } |
197 | |
else |
198 | |
{ |
199 | 0 | col[index++] = ""; |
200 | |
} |
201 | 0 | return index; |
202 | |
} |
203 | |
|
204 | |
protected String[][] getTable(Collection stats) |
205 | |
{ |
206 | 0 | String[] cols = getHeaders(); |
207 | 0 | String[][] table = new String[stats.size() + 1][cols.length]; |
208 | 0 | for (int i = 0; i < cols.length; i++) |
209 | |
{ |
210 | 0 | table[0][i] = cols[i]; |
211 | |
} |
212 | |
|
213 | 0 | int i = 1; |
214 | 0 | for (Iterator iterator = stats.iterator(); iterator.hasNext(); i++) |
215 | |
{ |
216 | 0 | getColumn((FlowConstructStatistics) iterator.next(), table[i]); |
217 | |
} |
218 | |
|
219 | 0 | return table; |
220 | |
} |
221 | |
|
222 | |
public void print(Object obj) |
223 | |
{ |
224 | 0 | if (obj instanceof Collection) |
225 | |
{ |
226 | 0 | print((Collection) obj); |
227 | |
} |
228 | 0 | else if (obj instanceof ServiceStatistics) |
229 | |
{ |
230 | 0 | List l = new ArrayList(); |
231 | 0 | l.add(obj); |
232 | 0 | print(l); |
233 | 0 | } |
234 | |
else |
235 | |
{ |
236 | 0 | super.print(obj); |
237 | |
} |
238 | 0 | } |
239 | |
|
240 | |
public void println(Object obj) |
241 | |
{ |
242 | 0 | print(obj); |
243 | 0 | println(); |
244 | 0 | } |
245 | |
|
246 | |
public void print(Collection c) |
247 | |
{ |
248 | 0 | throw new UnsupportedOperationException(); |
249 | |
} |
250 | |
|
251 | |
|
252 | |
|
253 | |
public void println(String string) |
254 | |
{ |
255 | 0 | this.println((Object) string); |
256 | 0 | } |
257 | |
|
258 | |
|
259 | |
|
260 | |
public void print(String string) |
261 | |
{ |
262 | 0 | this.print((Object) string); |
263 | 0 | } |
264 | |
|
265 | |
} |