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

cdc.perfs.core.SourceImpl Maven / Gradle / Ivy

There is a newer version: 0.52.0
Show newest version
package cdc.perfs.core;

import cdc.perfs.api.MeasureLevel;
import cdc.perfs.api.Source;

/**
 * Source implementation.
 *
 * @author Damien Carbonne
 */
public final class SourceImpl implements Source {
    /** Environment of the source. */
    private final AbstractEnvironment environment;
    /** Name of the source. */
    private final String name;
    /** Maximum level of measures. */
    private MeasureLevel maxLevel = MeasureLevel.DEBUG;
    /** Number of measures associated to this source. */
    private int measuresCount = 0;

    protected SourceImpl(AbstractEnvironment environment,
                         String name) {
        this.environment = environment;
        this.name = name;
    }

    public AbstractEnvironment getEnvironment() {
        return environment;
    }

    @Override
    public String getName() {
        return name;
    }

    @Override
    public void setMaxLevel(MeasureLevel maxLevel) {
        if (maxLevel == null) {
            throw new IllegalArgumentException("Null level");
        }
        this.maxLevel = maxLevel;
        environment.fireSourceChanged(this);
    }

    @Override
    public MeasureLevel getMaxLevel() {
        return maxLevel;
    }

    @Override
    public boolean isEnabled(MeasureLevel level) {
        return level != null && level.ordinal() <= maxLevel.ordinal();
    }

    @Override
    public String toString() {
        return name;
    }

    public void setMeasuresCount(int count) {
        this.measuresCount = count;
        environment.fireSourceChanged(this);
    }

    public void incrementMeasuresCount() {
        measuresCount++;
        environment.fireSourceChanged(this);
    }

    @Override
    public int getMeasuresCount() {
        return measuresCount;
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy