diff --git a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/buffer/BufferMetricReader.java b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/buffer/BufferMetricReader.java index d59aee945f..79f247bcbf 100644 --- a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/buffer/BufferMetricReader.java +++ b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/buffer/BufferMetricReader.java @@ -49,28 +49,6 @@ public class BufferMetricReader implements MetricReader, PrefixMetricReader { this.gauges = gauges; } - @Override - public Iterable> findAll(String prefix) { - final List> metrics = new ArrayList>(); - this.counters.forEach(Pattern.compile(prefix + ".*").asPredicate(), - new BiConsumer() { - @Override - public void accept(String name, LongBuffer value) { - metrics.add(new Metric(name, value.getValue(), new Date( - value.getTimestamp()))); - } - }); - this.gauges.forEach(Pattern.compile(prefix + ".*").asPredicate(), - new BiConsumer() { - @Override - public void accept(String name, DoubleBuffer value) { - metrics.add(new Metric(name, value.getValue(), new Date( - value.getTimestamp()))); - } - }); - return metrics; - } - @Override public Metric findOne(final String name) { LongBuffer buffer = this.counters.find(name); @@ -88,27 +66,40 @@ public class BufferMetricReader implements MetricReader, PrefixMetricReader { @Override public Iterable> findAll() { + return findAll(this.all); + } + + @Override + public Iterable> findAll(String prefix) { + return findAll(Pattern.compile(prefix + ".*").asPredicate()); + } + + @Override + public long count() { + return this.counters.count() + this.gauges.count(); + } + + private Iterable> findAll(Predicate predicate) { final List> metrics = new ArrayList>(); - this.counters.forEach(this.all, new BiConsumer() { + this.counters.forEach(predicate, new BiConsumer() { + @Override public void accept(String name, LongBuffer value) { metrics.add(new Metric(name, value.getValue(), new Date(value .getTimestamp()))); } + }); - this.gauges.forEach(this.all, new BiConsumer() { + this.gauges.forEach(predicate, new BiConsumer() { + @Override public void accept(String name, DoubleBuffer value) { metrics.add(new Metric(name, value.getValue(), new Date(value .getTimestamp()))); } + }); return metrics; } - @Override - public long count() { - return this.counters.count() + this.gauges.count(); - } - } diff --git a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/buffer/CounterBuffers.java b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/buffer/CounterBuffers.java index c46a687459..1d0e3b5625 100644 --- a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/buffer/CounterBuffers.java +++ b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/buffer/CounterBuffers.java @@ -52,12 +52,7 @@ public class CounterBuffers { } public void get(final String name, final Consumer consumer) { - read(name, new Consumer() { - @Override - public void accept(LongBuffer adder) { - consumer.accept(adder); - } - }); + read(name, consumer); } public void increment(final String name, final long delta) { @@ -83,12 +78,7 @@ public class CounterBuffers { } private void read(final String name, final Consumer consumer) { - acceptInternal(name, new Consumer() { - @Override - public void accept(LongBuffer adder) { - consumer.accept(adder); - } - }); + acceptInternal(name, consumer); } private void write(final String name, final Consumer consumer) { diff --git a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/buffer/GaugeBuffers.java b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/buffer/GaugeBuffers.java index a381a11e8a..aa899c1a61 100644 --- a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/buffer/GaugeBuffers.java +++ b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/buffer/GaugeBuffers.java @@ -52,12 +52,7 @@ public class GaugeBuffers { } public void get(final String name, final Consumer consumer) { - acceptInternal(name, new Consumer() { - @Override - public void accept(DoubleBuffer value) { - consumer.accept(value); - } - }); + acceptInternal(name, consumer); } public void set(final String name, final double value) {