-
Notifications
You must be signed in to change notification settings - Fork 1.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow subclasses to add metrics to MetricsRegistry #112
Allow subclasses to add metrics to MetricsRegistry #112
Conversation
…rimarily for tests) Also, use getOrAdd() for Timers and Meters
I'm OK with making |
Yep, but does this patch actually change the behaviour for adding Timer/Meters? I at least thought I only removed duplication (I'm not in front of a computer right now). /mårten. On 17 nov 2011, at 23:57, Coda Halereply@reply.github.com wrote:
|
It went from creating the metric after checking to creating the metric before checking. I've got one more fix for this and it should be fine. |
Either I'm way too tired or we're not reading the same diff ;) Since I didn't touch/reorder the line creating instance I fail to see how that could be the case On 18 nov 2011, at 00:17, Coda Halereply@reply.github.com wrote:
|
When final Metric existingMetric = metrics.get(metricName);
if (existingMetric == null) {
final TimerMetric metric = new TimerMetric(newMeterTickThreadPool(), durationUnit, rateUnit);
// etc
} to (effectively) this: final TimerMetric metric = new TimerMetric(newMeterTickThreadPool(), durationUnit, rateUnit);
final Metric existingMetric = metrics.get(metricName);
if (existingMetric == null) {
// etc.
} |
The check (line 285 to 287 in the diff) is untouched and thus performed before getOrAdd and before creating the metric instance. I noticed now however that my patch caused the check to be carried out twice. Once in newXYZ (before creating the metric) and once in getOrAdd (when the metric have been created). On 18 nov 2011, at 00:36, Coda Halereply@reply.github.com wrote:
|
Ah well, so it did. sigh I really need to stop trying to read diffs on GitHub. Sorry about that. |
No worries. You really had me staring down those lines of code trying to figure out what I'd missed :D On 18 nov 2011, at 02:07, Coda Halereply@reply.github.com wrote:
|
This is primarily for testing purposes: being able to subclass MetricsRegistry and use getOrAdd() from the subclass to add manually constructed metrics (and possibly mock objects).
I made getOrAdd()
final
since I feels its logic is an integral part of MetricsRegistry that you shouldn't tamper with it. Might be to conservative?Also took the opportunity to use getOrAdd in
newMeter
andnewTimer
.