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