From 01dc826c0744ff9a3e8a1daaec63b591deff95c1 Mon Sep 17 00:00:00 2001 From: Georgios Andrianakis Date: Wed, 27 Oct 2021 18:33:19 +0300 Subject: [PATCH] Remove lambdas from runtime code of Micrometer Furthermore, also apply some minor polish --- .../runtime/MicrometerMetricsFactory.java | 2 +- .../runtime/MicrometerRecorder.java | 21 ++++++++++--------- 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/extensions/micrometer/runtime/src/main/java/io/quarkus/micrometer/runtime/MicrometerMetricsFactory.java b/extensions/micrometer/runtime/src/main/java/io/quarkus/micrometer/runtime/MicrometerMetricsFactory.java index c584234891685..e237dfc60abcf 100644 --- a/extensions/micrometer/runtime/src/main/java/io/quarkus/micrometer/runtime/MicrometerMetricsFactory.java +++ b/extensions/micrometer/runtime/src/main/java/io/quarkus/micrometer/runtime/MicrometerMetricsFactory.java @@ -145,7 +145,7 @@ public Supplier buildTimer(Supplier f) { } } - class MicrometerTimeRecorder implements TimeRecorder { + static class MicrometerTimeRecorder implements TimeRecorder { Timer timer; MicrometerTimeRecorder(Timer timer) { diff --git a/extensions/micrometer/runtime/src/main/java/io/quarkus/micrometer/runtime/MicrometerRecorder.java b/extensions/micrometer/runtime/src/main/java/io/quarkus/micrometer/runtime/MicrometerRecorder.java index bc58d9d13298f..33fdf547acc5c 100644 --- a/extensions/micrometer/runtime/src/main/java/io/quarkus/micrometer/runtime/MicrometerRecorder.java +++ b/extensions/micrometer/runtime/src/main/java/io/quarkus/micrometer/runtime/MicrometerRecorder.java @@ -1,7 +1,6 @@ package io.quarkus.micrometer.runtime; import java.util.ArrayList; -import java.util.Collection; import java.util.HashMap; import java.util.HashSet; import java.util.List; @@ -127,21 +126,23 @@ public void configureRegistries(MicrometerConfig config, // configured, some measurements may be missed. Instance allBinders = beanManager.createInstance() .select(MeterBinder.class, Any.Literal.INSTANCE); - allBinders.forEach(x -> x.bindTo(Metrics.globalRegistry)); + for (MeterBinder meterBinder : allBinders) { + meterBinder.bindTo(Metrics.globalRegistry); + } context.addShutdownTask(new Runnable() { @Override public void run() { if (LaunchMode.current() == LaunchMode.DEVELOPMENT) { // Drop existing meters (recreated on next use) - Collection meters = new ArrayList<>(Metrics.globalRegistry.getMeters()); - meters.forEach(m -> Metrics.globalRegistry.remove(m)); + for (Meter meter : Metrics.globalRegistry.getMeters()) { + Metrics.globalRegistry.remove(meter); + } + } + for (MeterRegistry meterRegistry : Metrics.globalRegistry.getRegistries()) { + meterRegistry.close(); + Metrics.removeRegistry(meterRegistry); } - Collection cleanup = new ArrayList<>(Metrics.globalRegistry.getRegistries()); - cleanup.forEach(x -> { - x.close(); - Metrics.removeRegistry(x); - }); } }); } @@ -173,7 +174,7 @@ public static Class getClassForName(String classname) { Class clazz = null; try { clazz = Class.forName(classname, false, Thread.currentThread().getContextClassLoader()); - } catch (ClassNotFoundException e) { + } catch (ClassNotFoundException ignored) { } log.debugf("getClass: TCCL: %s ## %s : %s", Thread.currentThread().getContextClassLoader(), classname, (clazz != null)); return clazz;