1 10 11 package org.mule.management.stats.printers; 12 13 import java.io.OutputStream ; 14 import java.io.PrintWriter ; 15 import java.io.Writer ; 16 import java.util.ArrayList ; 17 import java.util.Collection ; 18 import java.util.Iterator ; 19 import java.util.List ; 20 import java.util.Map ; 21 22 import org.mule.management.stats.ComponentStatistics; 23 import org.mule.management.stats.RouterStatistics; 24 25 28 public class AbstractTablePrinter extends PrintWriter 29 { 30 31 public AbstractTablePrinter(Writer out) 32 { 33 super(out, true); 34 } 35 36 public AbstractTablePrinter(OutputStream out) 37 { 38 super(out, true); 39 } 40 41 public String [] getHeaders() 42 { 43 String [] column = new String [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 [] 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 [] col, int index) 118 { 119 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 routed = stats.getRouted(); 135 136 col[index++] = "-"; 137 if (!routed.isEmpty()) 138 { 139 Iterator it = routed.entrySet().iterator(); 140 141 StringBuffer buf = new StringBuffer (40); 142 while (it.hasNext()) 143 { 144 Map.Entry e = (Map.Entry )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 [][] getTable(Collection stats) 161 { 162 String [] cols = getHeaders(); 163 String [][] table = new String [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 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 obj) 179 { 180 if (obj instanceof Collection ) 181 { 182 print((Collection )obj); 183 } 184 else if (obj instanceof ComponentStatistics) 185 { 186 List l = new ArrayList (); 187 l.add(obj); 188 print(l); 189 } 190 else 191 { 192 super.print(obj); 193 } 194 } 195 196 public void println(Object obj) 197 { 198 print(obj); 199 println(); 200 } 201 202 public void print(Collection c) 203 { 204 throw new UnsupportedOperationException (); 205 } 206 207 public void println(String string) 210 { 211 this.println((Object )string); 212 } 213 214 public void print(String string) 217 { 218 this.print((Object )string); 219 } 220 221 } 222 | Popular Tags |