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

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

There is a newer version: 5.3.3
Show newest version
/*
 * 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
 * 

* Instantaneous counter is the base class for all types of instantaneous counters. An instantaneous counters values must change after each second i.e. on per second basis. All * values calculated in a time interval of one seconds becomes invalid for the next interval and it is re-initialized. */ public abstract class InstantaneousCounter extends PerformanceCounterBase { InstantaneousFlip currentFlip; public InstantaneousCounter(String name, String instance) { super(name, instance); currentFlip = FlipManager.flip.clone(); } public InstantaneousCounter(String category, String name, String instance) { super(category, name, instance); currentFlip = FlipManager.flip.clone(); } @Override public void increment() { incrementBy(1); } @Override public void incrementBy(double value) { synchronized (this) { if (!currentFlip.equals(FlipManager.flip)) { if (FlipManager.flip.getFlip() == currentFlip.getFlip() + 1) { _lastValue = _value; } else { _lastValue = 0; } _value = 0; currentFlip = FlipManager.flip.clone(); flipChanged(); } calculate(value); } } protected abstract void calculate(double value); protected abstract void flipChanged(); @Override public double getValue() { updateIfFlipChanged(); return _lastValue; } protected void updateIfFlipChanged() { synchronized (this) { if (!currentFlip.equals(FlipManager.flip)) { if (FlipManager.flip.getFlip() == currentFlip.getFlip() + 1) { _lastValue = _value; } else { _lastValue = 0; } _value = 0; currentFlip = FlipManager.flip.clone(); flipChanged(); } } } }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy