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