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

Alachisoft.NCache.Common.Stats.UsageStats Maven / Gradle / Ivy

package Alachisoft.NCache.Common.Stats;

import java.io.Serializable;

//using System.Management;
//C# TO JAVA CONVERTER TODO TASK: There is no preprocessor in Java:
//#if !MONO
//#endif

/**
 * Class that is useful in capturing statistics.
 */
public class UsageStats implements Serializable {

    /**
     * Timestamp for the begining of a sample.
     */
    private long _lastStart;
    /**
     * Timestamp for the end of a sample.
     */
    private long _lastStop;

    /**
     * Constructor
     */
    public UsageStats() {
        reset();
    }

    /**
     * Returns the time interval for the last sample
     */
    public final long getCurrent() {
        synchronized (this) {
            return _lastStop - _lastStart;
        }
    }

    /**
     * Resets the statistics collected so far.
     */
    public final void reset() {
        _lastStart = _lastStop = 0;
    }

    /**
     * Timestamps the start of a sampling interval.
     */
    public final void BeginSample() {
        _lastStart = System.nanoTime();
    }

    /**
     * Timestamps the end of interval and calculates the sample time
     */
    public final void EndSample() {
        _lastStop = System.nanoTime();
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy