@Override public void reset() { final Map<MetricName, Metric> metricMap = registry.allMetrics(); final Set<Entry<MetricName, Metric>> entrySet = metricMap.entrySet(); for (final Entry<MetricName, Metric> entry : entrySet) { final MetricName name = entry.getKey(); final Metric metric = entry.getValue(); if (metric instanceof Counter) { ((Counter) metric).clear(); } if (metric instanceof Timer) { ((Timer) metric).clear(); } if (metric instanceof Histogram) { ((Histogram) metric).clear(); } if (metric instanceof Clearable) { ((Clearable) metric).clear(); } } }
/** * Creates a new {@link Timer}. * * @param tickThread background thread for updating the rates * @param durationUnit the scale unit for this timer's duration metrics * @param rateUnit the scale unit for this timer's rate metrics * @param clock the clock used to calculate duration */ Timer( ScheduledExecutorService tickThread, TimeUnit durationUnit, TimeUnit rateUnit, Clock clock) { this.durationUnit = durationUnit; this.rateUnit = rateUnit; this.meter = new Meter(tickThread, "calls", rateUnit, clock); this.clock = clock; clear(); }