Coverage Report - org.mule.management.stats.AllStatistics
 
Classes in this File Line Coverage Branch Coverage Complexity
AllStatistics
0%
0/31
0%
0/12
0
 
 1  
 /*
 2  
  * $Id: AllStatistics.java 19191 2010-08-25 21:05:23Z tcarlson $
 3  
  * --------------------------------------------------------------------------------------
 4  
  * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.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.management.stats;
 12  
 
 13  
 import org.mule.management.stats.printers.AbstractTablePrinter;
 14  
 import org.mule.management.stats.printers.SimplePrinter;
 15  
 
 16  
 import java.io.PrintWriter;
 17  
 import java.util.Collection;
 18  
 import java.util.HashMap;
 19  
 import java.util.Map;
 20  
 
 21  
 /**
 22  
  * <code>AllStatistics</code> TODO
 23  
  */
 24  
 public class AllStatistics
 25  
 {
 26  
     private boolean isStatisticsEnabled;
 27  
     private long startTime;
 28  
 
 29  0
     private Map<String, ServiceStatistics> serviceStats = new HashMap<String, ServiceStatistics>();
 30  
 
 31  
     /**
 32  
      * 
 33  
      */
 34  
     public AllStatistics()
 35  0
     {
 36  0
         clear();
 37  0
     }
 38  
 
 39  
     public void logSummary()
 40  
     {
 41  0
         logSummary(new SimplePrinter(System.out));
 42  0
     }
 43  
 
 44  
     public void logSummary(PrintWriter printer)
 45  
     {
 46  
 
 47  0
         if (printer instanceof AbstractTablePrinter)
 48  
         {
 49  0
             printer.print(serviceStats.values());
 50  
         }
 51  
         else
 52  
         {
 53  0
             for (ServiceStatistics serviceStatistics : serviceStats.values())
 54  
             {
 55  0
                 printer.print(serviceStatistics);
 56  
             }
 57  
         }
 58  
         // printer.println("-----------------------------");
 59  
         // printer.println("duration (ms): " + (System.currentTimeMillis() -
 60  
         // startTime));
 61  0
     }
 62  
 
 63  
     public synchronized void clear()
 64  
     {
 65  0
         for (ServiceStatistics serviceStatistics : getServiceStatistics())
 66  
         {
 67  0
             (serviceStatistics).clear();
 68  
         }
 69  0
         startTime = System.currentTimeMillis();
 70  0
     }
 71  
 
 72  
     /**
 73  
      * Are statistics logged
 74  
      */
 75  
     public boolean isEnabled()
 76  
     {
 77  0
         return isStatisticsEnabled;
 78  
     }
 79  
 
 80  
     /**
 81  
      * Enable statistics logs (this is a dynamic parameter)
 82  
      */
 83  
     public void setEnabled(boolean b)
 84  
     {
 85  0
         isStatisticsEnabled = b;
 86  
 
 87  0
         for (ServiceStatistics serviceStatistics : serviceStats.values())
 88  
         {
 89  0
             (serviceStatistics).setEnabled(b);
 90  
         }
 91  0
     }
 92  
 
 93  
     public synchronized long getStartTime()
 94  
     {
 95  0
         return startTime;
 96  
     }
 97  
 
 98  
     public synchronized void setStartTime(long startTime)
 99  
     {
 100  0
         this.startTime = startTime;
 101  0
     }
 102  
 
 103  
     public synchronized void add(ServiceStatistics stat)
 104  
     {
 105  0
         if (stat != null)
 106  
         {
 107  0
             serviceStats.put(stat.getName(), stat);
 108  
         }
 109  0
     }
 110  
 
 111  
     public synchronized void remove(ServiceStatistics stat)
 112  
     {
 113  0
         if (stat != null)
 114  
         {
 115  0
             serviceStats.remove(stat.getName());
 116  
         }
 117  0
     }
 118  
 
 119  
     /**
 120  
      * @deprecated use #getServiceStatistics
 121  
      */
 122  
     @Deprecated
 123  
     public synchronized Collection<ServiceStatistics> getComponentStatistics()
 124  
     {
 125  0
         return serviceStats.values();
 126  
     }
 127  
 
 128  
     public synchronized Collection<ServiceStatistics> getServiceStatistics()
 129  
     {
 130  0
         return serviceStats.values();
 131  
     }
 132  
 }