Github user srdo commented on a diff in the pull request: https://github.com/apache/storm/pull/2763#discussion_r203720155 --- Diff: storm-server/src/main/java/org/apache/storm/metric/StormMetricsRegistry.java --- @@ -27,52 +28,63 @@ @SuppressWarnings("unchecked") public class StormMetricsRegistry { - public static final MetricRegistry DEFAULT_REGISTRY = new MetricRegistry(); + private static final MetricRegistry DEFAULT_REGISTRY = new MetricRegistry(); private static final Logger LOG = LoggerFactory.getLogger(StormMetricsRegistry.class); - public static Meter registerMeter(String name) { - Meter meter = new Meter(); - return register(name, meter); + public static Meter registerMeter(final String name) { + return register(name, new Meter()); } - // TODO: should replace Callable to Gauge<Integer> when nimbus.clj is translated to java - public static Gauge<Integer> registerGauge(final String name, final Callable fn) { - Gauge<Integer> gauge = new Gauge<Integer>() { - @Override - public Integer getValue() { - try { - return (Integer) fn.call(); - } catch (Exception e) { - LOG.error("Error getting gauge value for {}", name, e); - } - return 0; + /** + * Register a gauge with provided callback. + * @param name name of the gauge + * @param fn callback that measures + * @param <V> type of measurement the callback returns, also the type of gauge + * @return registered gauge + */ + public static <V> Gauge<V> registerGauge(final String name, final Callable<V> fn) { + return register(name, () -> { + try { + return fn.call(); + } catch (Exception e) { + LOG.error("Error getting gauge value for {}", name, e); } - }; - return register(name, gauge); + return null; --- End diff -- Why does it make sense to return null rather than 0?
---