1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
package org.mule.management.stats.printers; |
12 | |
|
13 | |
import org.mule.management.stats.ServiceStatistics; |
14 | |
import org.mule.management.stats.RouterStatistics; |
15 | |
import org.mule.management.stats.SedaServiceStatistics; |
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] = "Service Name"; |
46 | 0 | column[1] = "Service Pool Max Size"; |
47 | 0 | column[2] = "Service 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(ServiceStatistics stats, String[] col) |
85 | |
{ |
86 | 0 | if (stats == null) |
87 | |
{ |
88 | 0 | return; |
89 | |
} |
90 | |
|
91 | |
|
92 | 0 | col[0] = stats.getName(); |
93 | |
|
94 | |
|
95 | 0 | if (stats instanceof SedaServiceStatistics) |
96 | |
{ |
97 | 0 | col[1] = ((SedaServiceStatistics) stats).getComponentPoolMaxSize() + "/" |
98 | |
+ ((SedaServiceStatistics) stats).getComponentPoolAbsoluteMaxSize(); |
99 | 0 | col[2] = String.valueOf(((SedaServiceStatistics) stats).getComponentPoolSize()); |
100 | |
} |
101 | |
else |
102 | |
{ |
103 | 0 | col[1] = "-"; |
104 | 0 | col[2] = "-"; |
105 | |
} |
106 | 0 | col[3] = String.valueOf(stats.getThreadPoolSize()); |
107 | 0 | col[4] = String.valueOf(stats.getQueuedEvents()); |
108 | 0 | col[5] = String.valueOf(stats.getMaxQueueSize()); |
109 | 0 | col[6] = String.valueOf(stats.getAverageQueueSize()); |
110 | 0 | col[7] = String.valueOf(stats.getSyncEventsReceived()); |
111 | 0 | col[8] = String.valueOf(stats.getAsyncEventsReceived()); |
112 | 0 | col[9] = String.valueOf(stats.getTotalEventsReceived()); |
113 | 0 | col[10] = String.valueOf(stats.getSyncEventsSent()); |
114 | 0 | col[11] = String.valueOf(stats.getAsyncEventsSent()); |
115 | 0 | col[12] = String.valueOf(stats.getReplyToEventsSent()); |
116 | 0 | col[13] = String.valueOf(stats.getTotalEventsSent()); |
117 | 0 | col[14] = String.valueOf(stats.getExecutedEvents()); |
118 | 0 | col[15] = String.valueOf(stats.getExecutionErrors()); |
119 | 0 | col[16] = String.valueOf(stats.getFatalErrors()); |
120 | 0 | col[17] = String.valueOf(stats.getMinExecutionTime()); |
121 | 0 | col[18] = String.valueOf(stats.getMaxExecutionTime()); |
122 | 0 | col[19] = String.valueOf(stats.getAverageExecutionTime()); |
123 | 0 | col[20] = String.valueOf(stats.getTotalExecutionTime()); |
124 | |
|
125 | 0 | int i = getRouterInfo(stats.getInboundRouterStat(), col, 21); |
126 | 0 | i = getRouterInfo(stats.getOutboundRouterStat(), col, i); |
127 | 0 | col[i] = String.valueOf(stats.getSamplePeriod()); |
128 | 0 | } |
129 | |
|
130 | |
protected int getRouterInfo(RouterStatistics stats, String[] col, int index) |
131 | |
{ |
132 | |
|
133 | 0 | if (stats.isInbound()) |
134 | |
{ |
135 | 0 | col[index++] = "-"; |
136 | |
} |
137 | |
else |
138 | |
{ |
139 | 0 | col[index++] = "-"; |
140 | |
} |
141 | |
|
142 | 0 | col[index++] = String.valueOf(stats.getTotalReceived()); |
143 | 0 | col[index++] = String.valueOf(stats.getTotalRouted()); |
144 | 0 | col[index++] = String.valueOf(stats.getNotRouted()); |
145 | 0 | col[index++] = String.valueOf(stats.getCaughtMessages()); |
146 | |
|
147 | 0 | Map routed = stats.getRouted(); |
148 | |
|
149 | 0 | col[index++] = "-"; |
150 | 0 | if (!routed.isEmpty()) |
151 | |
{ |
152 | 0 | Iterator it = routed.entrySet().iterator(); |
153 | |
|
154 | 0 | StringBuffer buf = new StringBuffer(40); |
155 | 0 | while (it.hasNext()) |
156 | |
{ |
157 | 0 | Map.Entry e = (Map.Entry) it.next(); |
158 | 0 | buf.append(e.getKey()).append('=').append(e.getValue()); |
159 | 0 | if (it.hasNext()) |
160 | |
{ |
161 | 0 | buf.append(';'); |
162 | |
} |
163 | 0 | } |
164 | 0 | col[index++] = buf.toString(); |
165 | 0 | } |
166 | |
else |
167 | |
{ |
168 | 0 | col[index++] = ""; |
169 | |
} |
170 | 0 | return index; |
171 | |
} |
172 | |
|
173 | |
protected String[][] getTable(Collection stats) |
174 | |
{ |
175 | 0 | String[] cols = getHeaders(); |
176 | 0 | String[][] table = new String[stats.size() + 1][cols.length]; |
177 | 0 | for (int i = 0; i < cols.length; i++) |
178 | |
{ |
179 | 0 | table[0][i] = cols[i]; |
180 | |
} |
181 | |
|
182 | 0 | int i = 1; |
183 | 0 | for (Iterator iterator = stats.iterator(); iterator.hasNext(); i++) |
184 | |
{ |
185 | 0 | getColumn((ServiceStatistics) iterator.next(), table[i]); |
186 | |
} |
187 | |
|
188 | 0 | return table; |
189 | |
} |
190 | |
|
191 | |
public void print(Object obj) |
192 | |
{ |
193 | 0 | if (obj instanceof Collection) |
194 | |
{ |
195 | 0 | print((Collection) obj); |
196 | |
} |
197 | 0 | else if (obj instanceof ServiceStatistics) |
198 | |
{ |
199 | 0 | List l = new ArrayList(); |
200 | 0 | l.add(obj); |
201 | 0 | print(l); |
202 | 0 | } |
203 | |
else |
204 | |
{ |
205 | 0 | super.print(obj); |
206 | |
} |
207 | 0 | } |
208 | |
|
209 | |
public void println(Object obj) |
210 | |
{ |
211 | 0 | print(obj); |
212 | 0 | println(); |
213 | 0 | } |
214 | |
|
215 | |
public void print(Collection c) |
216 | |
{ |
217 | 0 | throw new UnsupportedOperationException(); |
218 | |
} |
219 | |
|
220 | |
|
221 | |
|
222 | |
public void println(String string) |
223 | |
{ |
224 | 0 | this.println((Object) string); |
225 | 0 | } |
226 | |
|
227 | |
|
228 | |
|
229 | |
public void print(String string) |
230 | |
{ |
231 | 0 | this.print((Object) string); |
232 | 0 | } |
233 | |
|
234 | |
} |