codahale/metrics — pull request #228 by jesseeichar (2012-04-17 06:14:29+00:00)
Title: DefaultWebappMetricsFilter will get metrics factory from servlet context

This pull request is related to ticket: https://github.com/codahale/metrics/issues/210

During the init call the MetricsRegistry is obtained from the servlet context object.

Two important considerations:

* The MetricsRegistry is read once during init. Another design was to check the MetricsRegistry during doFilter and if it has changed the initialize all meters. I did not want this because it could have a potentially negative impact on performance since the check and initialization would have to be synchronized.
* Since the MetricsRegistry is only read during init, some mechanism is required to initialize it for all servlets and filters before the filter is called. In MetricsServlet this is not a problem because the servlet is initialized only called once it is called so another servlet can set the MetricsRegistry in the context for the MetricsServlet to use. In the case of the WebappMetricsFilter another filter must set the MetricsRegistry.

Since the WebappMetricsFilter uses an attribute key passed from subclass each attribute can have its own MetricsRegistry if that is desired.