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

com.alachisoft.ncache.common.caching.statistics.customcounters.PerformanceCounterBase 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
 */
public abstract class PerformanceCounterBase implements PerformanceCounter {

    protected double _value;
    protected double _lastValue;
    private String _name;
    private String _instanceName;
    private String _category;

    public PerformanceCounterBase(String name, String instance) {
        _name = name;
        _instanceName = instance;
        _category = null;
        _value = 0;
        _lastValue = 0;
    }

    public PerformanceCounterBase(String category, String name, String instance) {
        _name = name;
        _instanceName = instance;
        _category = category;
        _value = 0;
        _lastValue = 0;
    }

    /**
     * Gets the name of the counter.
     *
     * @return
     */
    @Override
    public String getName() {
        return _name;
    }

    /**
     * Gets the name of the instance to which this counter belongs.
     *
     * @return
     */
    @Override
    public String getInstanceName() {
        return _instanceName;
    }

    /**
     * Gets the category of the counter.
     *
     * @return
     */
    @Override
    public String getCategory() {
        return _category;
    }

    /**
     * Increments the counter value by one.
     */
    @Override
    public abstract void increment();

    /**
     * Decrements the counter value by given value
     *
     * @param value
     */
    @Override
    public abstract void incrementBy(double value);

    /**
     * Increments the counter value by one.
     */
    @Override
    public abstract void decrement();

    /**
     * Decrements the counter value by given value.
     *
     * @param value
     */
    @Override
    public abstract void decrementBy(double value);

    /**
     * Gets the counter value
     *
     * @return
     */
    @Override
    public abstract double getValue();

    /**
     * Sets the counter value
     *
     * @param _value
     */
    @Override
    public abstract void setValue(double _value);

    /**
     *
     */
    public void reset() {
        synchronized (this) {
            _value = _lastValue = 0;
        }
    }

    @Override
    public String toString() {
        String toStr = "[";
        toStr += _name != null ? "Name :" + _name : "";
        toStr += _instanceName != null ? "; Instance :" + _instanceName : "";
        toStr += _category != null ? "; Category :" + _category + "]" : "";
        return toStr;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy