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

com.yammer.metrics.util.ToggleGauge Maven / Gradle / Ivy

There is a newer version: 3.0.0-BETA1
Show newest version
package com.yammer.metrics.util;

import com.yammer.metrics.core.Gauge;

import java.util.concurrent.atomic.AtomicInteger;

/**
 * Returns a {@code 1} the first time it's called, a {@code 0} every time after that.
 */
public class ToggleGauge extends Gauge {
    private final AtomicInteger value = new AtomicInteger(1);

    @Override
    public Integer value() {
        try {
            return value.get();
        } finally {
            this.value.set(0);
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy