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