codahale/metrics — pull request #516 by earthling (2014-01-22 22:43:13+00:00)
Title: Make MetricRegistry more amenable to subclassing.

We use Metrics to record many, many short lived and contextual metrics. A best effort is made to remove them from the `MetricRegistry` when possible, but leaks are inevitable. We have a subclass of `MetricRegistry` that provides a `ConcurrentMap` backed by a Guava cache which is bounded in size and also uses weak values. Our `MetricRegistry` subclass implements the `RemovalListener` interface for the cache, but by the time the removal notice is received, the metric is already removed from the cache. We still want to notify `MetricRegistryListener`s so the methods to dispatch the event has been made protected (so that our implementation of the `RemovalListener` may invoke them).

The second change is to pass the removed metric through the corresponding methods on the `MetricRegistryListener`. This is done so that our custom reporter (for sending metrics directly to Splunk, if you're interested) can still report metrics that have been created and updated and removed within the space between two executions of the scheduled 'report' interval. Receiving the removed metric in the implementation of `MetricRegistryListener` lets us be sure the values from these short lived metrics are not lost.

Thank you.