Coverage Report - org.mule.util.counters.impl.TimeAverage
 
Classes in this File Line Coverage Branch Coverage Complexity
TimeAverage
0%
0/13
N/A
1
 
 1  
 /*
 2  
  * $Id: TimeAverage.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.util.counters.impl;
 12  
 
 13  
 import org.mule.util.counters.CounterFactory.Type;
 14  
 
 15  
 public class TimeAverage extends AggregateCounter
 16  
 {
 17  
 
 18  0
     private double sum = 0.0;
 19  0
     private double lastValue = 0.0;
 20  0
     private final long firstTime = System.currentTimeMillis();
 21  0
     private long lastTime = firstTime;
 22  
 
 23  
     public TimeAverage(String name, AbstractCounter base)
 24  
     {
 25  0
         super(name, Type.AVERAGE, base);
 26  0
     }
 27  
 
 28  
     public double nextValue()
 29  
     {
 30  0
         long current = System.currentTimeMillis();
 31  0
         return (sum + lastValue * (current - this.lastTime)) / (current - firstTime);
 32  
     }
 33  
 
 34  
     public void doCompute()
 35  
     {
 36  0
         long current = System.currentTimeMillis();
 37  0
         this.sum += this.lastValue * (current - this.lastTime);
 38  0
         this.lastValue = getBase().nextValue();
 39  0
         this.lastTime = current;
 40  0
     }
 41  
 
 42  
 }