Coverage Report - org.mule.management.stats.ComponentStatistics
 
Classes in this File Line Coverage Branch Coverage Complexity
ComponentStatistics
28%
9/32
0%
0/10
1.182
 
 1  
 /*
 2  
  * $Id: ComponentStatistics.java 11488 2008-03-24 14:38:49Z 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.SimplePrinter;
 15  
 
 16  
 import java.io.PrintWriter;
 17  
 
 18  
 /**
 19  
  * 
 20  
  */
 21  852
 public class ComponentStatistics implements Statistics
 22  
 {
 23  
     /**
 24  
      * Serial version
 25  
      */
 26  
     private static final long serialVersionUID = -2086999226732861674L;
 27  
 
 28  852
     private long minExecutionTime = 0;
 29  852
     private long maxExecutionTime = 0;
 30  852
     private long averageExecutionTime = 0;
 31  852
     private long executedEvent = 0;
 32  852
     private long totalExecTime = 0;
 33  852
     private boolean enabled = false;
 34  
 
 35  
     public void clear()
 36  
     {
 37  0
         minExecutionTime = 0;
 38  0
         maxExecutionTime = 0;
 39  0
         executedEvent = 0;
 40  0
         totalExecTime = 0;
 41  0
     }
 42  
 
 43  
     public boolean isEnabled()
 44  
     {
 45  0
         return enabled;
 46  
     }
 47  
 
 48  
     public void logSummary()
 49  
     {
 50  0
         logSummary(new SimplePrinter(System.out));
 51  0
     }
 52  
 
 53  
     public void logSummary(PrintWriter printer)
 54  
     {
 55  0
         printer.print(this);
 56  0
     }
 57  
 
 58  
     public void setEnabled(boolean b)
 59  
     {
 60  398
         this.enabled = b;
 61  398
     }
 62  
 
 63  
     public long getMaxExecutionTime()
 64  
     {
 65  0
         return maxExecutionTime;
 66  
     }
 67  
 
 68  
     public long getMinExecutionTime()
 69  
     {
 70  0
         return minExecutionTime;
 71  
     }
 72  
 
 73  
     public long getTotalExecutionTime()
 74  
     {
 75  0
         return totalExecTime;
 76  
     }
 77  
 
 78  
     public long getExecutedEvents()
 79  
     {
 80  0
         return executedEvent;
 81  
     }
 82  
 
 83  
     public synchronized void addExecutionTime(long time)
 84  
     {
 85  0
         executedEvent++;
 86  
 
 87  0
         totalExecTime += (time == 0 ? 1 : time);
 88  
 
 89  0
         if (minExecutionTime == 0 || time < minExecutionTime)
 90  
         {
 91  0
             minExecutionTime = time;
 92  
         }
 93  0
         if (maxExecutionTime == 0 || time > maxExecutionTime)
 94  
         {
 95  0
             maxExecutionTime = time;
 96  
         }
 97  0
         averageExecutionTime = Math.round(totalExecTime / executedEvent);
 98  0
     }
 99  
 
 100  
     public long getAverageExecutionTime()
 101  
     {
 102  0
         return averageExecutionTime;
 103  
     }
 104  
 
 105  
 }