KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > mule > management > stats > printers > AbstractTablePrinter


1 /*
2  * $Id: AbstractTablePrinter.java 4259 2006-12-14 03:12:07Z aperepel $
3  * --------------------------------------------------------------------------------------
4  * Copyright (c) MuleSource, Inc. All rights reserved. http://www.mulesource.com
5  *
6  * The software in this package is published under the terms of the MuleSource MPL
7  * license, a copy of which has been included with this distribution in the
8  * LICENSE.txt file.
9  */

10
11 package org.mule.management.stats.printers;
12
13 import java.io.OutputStream JavaDoc;
14 import java.io.PrintWriter JavaDoc;
15 import java.io.Writer JavaDoc;
16 import java.util.ArrayList JavaDoc;
17 import java.util.Collection JavaDoc;
18 import java.util.Iterator JavaDoc;
19 import java.util.List JavaDoc;
20 import java.util.Map JavaDoc;
21
22 import org.mule.management.stats.ComponentStatistics;
23 import org.mule.management.stats.RouterStatistics;
24
25 /**
26  * <code>HtmlTablePrinter</code> prints event processing stats as a HTML table
27  */

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