/** * The units associated with the interval */ default TimeUnit getTimeUnit() { if (isScheduled()) { return TimeUnit.MINUTES; } else { return null; } }
final boolean startReporter(ReporterFactory reporterFactory) { boolean success = false; try { reporterFactory.startReporter(); return true; reporterFactory.getClass().getName()); Reporter reporter = reporterFactory.getReporter(metricsCollector.getMetricRegistry()); if (reporter instanceof ScheduledReporter) { ((ScheduledReporter) reporter).start(reporterFactory.getInterval(), reporterFactory.getTimeUnit()); return true; if (!reporterFactory.isScheduled() || reporterFactory.getInterval() == null) { m.invoke(reporter, reporterFactory.getInterval(), reporterFactory.getTimeUnit()); success = true;
final boolean stopReporter(ReporterFactory reporterFactory) { boolean success = false; try { reporterFactory.stopReporter(); return true; } catch (UnsupportedOperationException e) { logger.debug("ReporterFactory {} does not expose custom startup behavior.", reporterFactory.getClass().getName()); } try { Method m = reporterFactory.getClass().getMethod("stop", (Class<?>[]) null); m.invoke(reporterFactory, (Object[]) null); success = true; } catch (Throwable t) { logger.warn("Unable to stop reporter of type {}", reporterFactory.getClass(), t); } return success; }
/** * The interval at which Reporters produced by this Factory should report */ default Long getInterval() { if (isScheduled()) { return 1L; } else { return null; } }