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

com.nitorcreations.willow.metrics.AvailableMetricsMetric Maven / Gradle / Ivy

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 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