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