org.vertexium.metric.NullMetricRegistry Maven / Gradle / Ivy
package org.vertexium.metric;
import com.google.common.base.Joiner;
import java.util.HashMap;
import java.util.Map;
import java.util.function.Supplier;
public class NullMetricRegistry implements VertexiumMetricRegistry {
private final Map countersByName = new HashMap<>();
private final Map timersByName = new HashMap<>();
private final Map histogramsByName = new HashMap<>();
private final Map gaugesByName = new HashMap<>();
private final Map stackTraceTrackersByName = new HashMap<>();
@Override
public String createName(Class clazz, String... nameParts) {
return clazz.getName() + "." + Joiner.on(".").join(nameParts);
}
@Override
public Counter getCounter(String name) {
return countersByName.computeIfAbsent(name, s -> new Counter() {
long count;
@Override
public void increment(long amount) {
count += amount;
}
@Override
public void decrement(long amount) {
count += amount;
}
@Override
public long getCount() {
return count;
}
});
}
@Override
public Iterable getCounters() {
return countersByName.values();
}
@Override
public Timer getTimer(String name) {
return timersByName.computeIfAbsent(name, s -> new Timer() {
@Override
public T time(Supplier supplier) {
return supplier.get();
}
});
}
@Override
public Iterable getTimers() {
return timersByName.values();
}
@Override
public Histogram getHistogram(String name) {
return histogramsByName.computeIfAbsent(name, s -> new Histogram() {
@Override
public void update(int value) {
}
@Override
public void update(long value) {
}
});
}
@Override
public Iterable getHistograms() {
return histogramsByName.values();
}
@Override
@SuppressWarnings("unchecked")
public Gauge getGauge(String name, Supplier supplier) {
return gaugesByName.computeIfAbsent(name, s -> new Gauge() {
});
}
@Override
public Iterable getGauges() {
return gaugesByName.values();
}
@Override
public StackTraceTracker getStackTraceTracker(String name) {
return stackTraceTrackersByName.computeIfAbsent(name, s -> new StackTraceTracker());
}
@Override
public Iterable extends StackTraceTracker> getStackTraceTrackers() {
return stackTraceTrackersByName.values();
}
@Override
public void shutdown() {
countersByName.clear();
timersByName.clear();
histogramsByName.clear();
gaugesByName.clear();
stackTraceTrackersByName.clear();
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy