Coverage Report - org.mule.module.management.mbean.StatisticsService
 
Classes in this File Line Coverage Branch Coverage Complexity
StatisticsService
33%
10/30
50%
1/2
1.111
 
 1  
 /*
 2  
  * $Id: StatisticsService.java 11234 2008-03-06 23:44:34Z tcarlson $
 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 CPAL v1.0
 7  
  * license, a copy of which has been included with this distribution in the
 8  
  * LICENSE.txt file.
 9  
  */
 10  
 
 11  
 package org.mule.module.management.mbean;
 12  
 
 13  
 import org.mule.api.MuleContext;
 14  
 import org.mule.management.stats.AllStatistics;
 15  
 import org.mule.management.stats.printers.CSVPrinter;
 16  
 import org.mule.management.stats.printers.HtmlTablePrinter;
 17  
 import org.mule.management.stats.printers.XMLPrinter;
 18  
 
 19  
 import java.io.StringWriter;
 20  
 import java.util.Collection;
 21  
 
 22  
 import org.apache.commons.logging.Log;
 23  
 import org.apache.commons.logging.LogFactory;
 24  
 
 25  
 /**
 26  
  * <code>StatisicsService</code> exposes Mule processing statistics
 27  
  */
 28  28
 public class StatisticsService implements StatisticsServiceMBean
 29  
 {
 30  
     /**
 31  
      * Serial version
 32  
      */
 33  
     private static final long serialVersionUID = -4949499389883146363L;
 34  
 
 35  
     /**
 36  
      * logger used by this class
 37  
      */
 38  12
     protected static final Log logger = LogFactory.getLog(StatisticsService.class);
 39  
 
 40  28
     private AllStatistics stats = new AllStatistics();
 41  28
     private MuleContext muleContext = null;
 42  
 
 43  
     public void setMuleContext(MuleContext context)
 44  
     {
 45  22
         this.muleContext = context;
 46  22
         if (muleContext == null)
 47  
         {
 48  0
             stats = new AllStatistics();
 49  
         }
 50  
         else
 51  
         {
 52  22
             stats = this.muleContext.getStatistics();
 53  
         }
 54  
 
 55  22
     }
 56  
 
 57  
     /**
 58  
      * @see org.mule.api.management.stats.Statistics#clear()
 59  
      */
 60  
     public void clear()
 61  
     {
 62  0
         stats.clear();
 63  0
     }
 64  
 
 65  
     /**
 66  
      * @see org.mule.api.management.stats.Statistics#isEnabled()
 67  
      */
 68  
     public boolean isEnabled()
 69  
     {
 70  0
         return stats.isEnabled();
 71  
     }
 72  
 
 73  
     /**
 74  
      * @see org.mule.api.management.stats.Statistics#setEnabled(boolean)
 75  
      */
 76  
     public void setEnabled(boolean b)
 77  
     {
 78  22
         stats.setEnabled(b);
 79  
 
 80  22
     }
 81  
 
 82  
     public Collection getComponentStatistics()
 83  
     {
 84  0
         return stats.getComponentStatistics();
 85  
     }
 86  
 
 87  
     public void logSummary()
 88  
     {
 89  0
         stats.logSummary();
 90  0
     }
 91  
 
 92  
     public String printCSVSummary ()
 93  
     {
 94  0
         StringWriter w = new StringWriter(2048);
 95  0
         CSVPrinter printer = new CSVPrinter(w);
 96  0
         printer.setPrintHeaders(true);
 97  0
         stats.logSummary(printer);
 98  0
         return w.toString();
 99  
     }
 100  
 
 101  
     public String printHtmlSummary ()
 102  
     {
 103  0
         StringWriter w = new StringWriter(8192);
 104  0
         HtmlTablePrinter printer = new HtmlTablePrinter(w);
 105  0
         stats.logSummary(printer);
 106  0
         return w.toString();
 107  
     }
 108  
 
 109  
     public String printXmlSummary()
 110  
     {
 111  0
         StringWriter w = new StringWriter(8192);
 112  0
         XMLPrinter printer = new XMLPrinter(w);
 113  0
         stats.logSummary(printer);
 114  0
         return w.toString();
 115  
     }
 116  
 
 117  
 }