![JAR search and dependency download from the Maven repository](/logo.png)
com.nitorcreations.willow.metrics.AvailableMetricsMetric Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of willow-servers Show documentation
Show all versions of willow-servers Show documentation
Willow operational servlets and servers
The newest version!
package com.nitorcreations.willow.metrics;
import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.inject.Inject;
import javax.inject.Named;
import com.google.inject.Injector;
import com.nitorcreations.willow.messages.metrics.MetricConfig;
@Named("/available")
public class AvailableMetricsMetric implements Metric {
private final Logger log = Logger.getLogger(getClass().getCanonicalName());
@Inject
private transient Map metrics;
@Inject
Injector injector;
@Override
public Object calculateMetric(MetricConfig conf) {
HashMap ret = new HashMap();
for (Entry next : metrics.entrySet()) {
Class extends Metric> nextClass = next.getValue().getClass();
if (nextClass != this.getClass()) {
try {
Metric m = nextClass.newInstance();
injector.injectMembers(m);
ret.put(next.getKey(), m.hasData(conf));
} catch (InstantiationException | IllegalAccessException e) {
log.log(Level.FINE, "Failed to create metric", e);
}
}
}
return ret;
}
@Override
public boolean hasData(MetricConfig conf) {
return true;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy