All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.alachisoft.ncache.common.caching.statistics.customcounters.AverageCounter Maven / Gradle / Ivy

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.alachisoft.ncache.common.caching.statistics.customcounters;

/**
 * @author Muneeb Shahid
 * 

* AverageCounter is an instantaneous counter used for calculating average operations performed in one second. For e.g Average data sent */ public class AverageCounter extends InstantaneousCounter { private double _sum = 0; private double _totalCount = 0; public AverageCounter(String name, String instance) { super(name, instance); } public AverageCounter(String category, String name, String instance) { super(category, name, instance); } @Override protected void calculate(double value) { _sum += value; } public void incrementBy(double value, double count) { synchronized (this) { super.incrementBy(value); _totalCount += count; if (_totalCount != 0) _value = _sum / _totalCount; else _value = 0; } } public void incrementBase(long count) { synchronized (this) { _totalCount += count; } } @Override public void incrementBy(double value) { this.incrementBy(value, 1); } @Override protected void flipChanged() { _sum = 0; _totalCount = 0; } @Override public void decrement() { } @Override public void decrementBy(double value) { } @Override public void setValue(double _value) { _lastValue = this._value; this._value = _value; } public double getValue(){ return _value; } public double getTotalCount() { return _totalCount; } public double getSum() { return _sum; } }





© 2015 - 2025 Weber Informatics LLC | Privacy Policy