Polish contribution
- Add @author tag - Remove unnecessary final modifiers - Avoid writing to volatile field when new gauge is used Closes gh-3977
This commit is contained in:
parent
3fb0ae3e3b
commit
64bcba47a9
|
@ -46,6 +46,8 @@ import com.codahale.metrics.Timer;
|
||||||
* </ul>
|
* </ul>
|
||||||
*
|
*
|
||||||
* @author Dave Syer
|
* @author Dave Syer
|
||||||
|
* @author Jay Anderson
|
||||||
|
* @author Andy Wilkinson
|
||||||
*/
|
*/
|
||||||
public class DropwizardMetricServices implements CounterService, GaugeService {
|
public class DropwizardMetricServices implements CounterService, GaugeService {
|
||||||
|
|
||||||
|
@ -103,15 +105,15 @@ public class DropwizardMetricServices implements CounterService, GaugeService {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setGaugeValue(final String name, final double value) {
|
private void setGaugeValue(String name, double value) {
|
||||||
// NOTE: Dropwizard provides no way to do this atomically
|
// NOTE: Dropwizard provides no way to do this atomically
|
||||||
SimpleGauge gauge = this.gauges.get(name);
|
SimpleGauge gauge = this.gauges.get(name);
|
||||||
if (gauge == null) {
|
if (gauge == null) {
|
||||||
final SimpleGauge newGauge = new SimpleGauge(value);
|
SimpleGauge newGauge = new SimpleGauge(value);
|
||||||
gauge = this.gauges.putIfAbsent(name, newGauge);
|
gauge = this.gauges.putIfAbsent(name, newGauge);
|
||||||
if (gauge == null) {
|
if (gauge == null) {
|
||||||
gauge = newGauge;
|
this.registry.register(name, newGauge);
|
||||||
this.registry.register(name, gauge);
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
gauge.setValue(value);
|
gauge.setValue(value);
|
||||||
|
@ -161,7 +163,7 @@ public class DropwizardMetricServices implements CounterService, GaugeService {
|
||||||
return this.value;
|
return this.value;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setValue(final double value) {
|
public void setValue(double value) {
|
||||||
this.value = value;
|
this.value = value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -65,9 +65,10 @@ public class DropwizardMetricServicesTests {
|
||||||
@Test
|
@Test
|
||||||
public void setGauge() {
|
public void setGauge() {
|
||||||
this.writer.submit("foo", 2.1);
|
this.writer.submit("foo", 2.1);
|
||||||
this.writer.submit("foo", 2.3);
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
Gauge<Double> gauge = (Gauge<Double>) this.registry.getMetrics().get("gauge.foo");
|
Gauge<Double> gauge = (Gauge<Double>) this.registry.getMetrics().get("gauge.foo");
|
||||||
|
assertEquals(new Double(2.1), gauge.getValue());
|
||||||
|
this.writer.submit("foo", 2.3);
|
||||||
assertEquals(new Double(2.3), gauge.getValue());
|
assertEquals(new Double(2.3), gauge.getValue());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue