FileDocCategorySizeDatePackage
MutableAverageRangeStatisticImpl.javaAPI DocGlassfish v2 API6861Fri May 04 22:25:48 BST 2007com.sun.enterprise.admin.monitor.stats

MutableAverageRangeStatisticImpl

public class MutableAverageRangeStatisticImpl extends Object implements AverageRangeStatistic, MutableCountStatistic
author
lwhite

Fields Summary
public static final long
DEFAULT_MAX_BOUND
DEFAULT_UPPER_BOUND is maximum value Long can attain
private MutableBoundedRangeStatisticImpl
mutableBoundedRangeStat
private long
numberOfSamples
private long
runningTotal
private String
description
Constructors Summary
public MutableAverageRangeStatisticImpl(javax.management.j2ee.statistics.BoundedRangeStatistic initial)
Constructs an instance of MutableAverageRangeStatisticImpl that encapsulates the given Statistic. The only parameter denotes the initial state of this statistic. It is guaranteed that the initial state is preserved internally, so that one can reset to the initial state.

param
initial an instance of BoundedRangeStatistic that represents initial state

    
                                                                    
       
        mutableBoundedRangeStat = new MutableBoundedRangeStatisticImpl(initial);
        numberOfSamples = 0L;
        runningTotal = 0L;
        description = initial.getDescription();        
    
Methods Summary
public longgetAverage()

        if(numberOfSamples == 0) {
            return -1;
        } else {
            return runningTotal / numberOfSamples;
        }
    
public longgetCurrent()

        return mutableBoundedRangeStat.getCurrent();
    
public java.lang.StringgetDescription()

        return description;
        //return mutableBoundedRangeStat.getDescription();
    
public longgetHighWaterMark()

        return mutableBoundedRangeStat.getHighWaterMark();
    
public longgetLastSampleTime()

        return mutableBoundedRangeStat.getLastSampleTime();
    
public longgetLowWaterMark()

        long result = mutableBoundedRangeStat.getLowWaterMark();
        if(result == DEFAULT_MAX_BOUND) {
            result = 0L;
        }
        return result;
    
public java.lang.StringgetName()

        return mutableBoundedRangeStat.getName();
    
public longgetStartTime()

        return mutableBoundedRangeStat.getStartTime();
    
public java.lang.StringgetUnit()

        return mutableBoundedRangeStat.getUnit();
    
public javax.management.j2ee.statistics.StatisticmodifiableView()

        
        return this;
    
public voidreset()

        mutableBoundedRangeStat.reset();
        this.resetAverageStats();
    
private voidresetAverageStats()

        numberOfSamples = 0L;
        runningTotal = 0L;
    
public voidsetCount(long current)

        mutableBoundedRangeStat.setCount(current);
        if(DEFAULT_MAX_BOUND - runningTotal < current) {
            this.resetAverageStats();
        }
        numberOfSamples++;
        runningTotal += current;
    
public javax.management.j2ee.statistics.StatisticunmodifiableView()

        
        return ( new AverageRangeStatisticImpl(
            this.getCurrent(),               // this is the actual changing statistic
            this.getHighWaterMark(),         // highWaterMark may change per current
            this.getLowWaterMark(),          // lowWaterMark may change per current
            mutableBoundedRangeStat.getUpperBound(),    // upperBound is not designed to change
            mutableBoundedRangeStat.getLowerBound(),    // lowerBound is not designed to change
            mutableBoundedRangeStat.getName(),          // name does not change
            mutableBoundedRangeStat.getUnit(),          // unit does not change
            mutableBoundedRangeStat.getDescription(),   // description does not change
            this.getLastSampleTime(),        // changes all the time!
            this.getStartTime(),             // changes if reset is called earlier
            this.numberOfSamples,       // this is the current number of samples
            this.runningTotal           // this is the current running total
        ));