private void flush(GaugeWriter writer) { if (writer instanceof CompositeMetricWriter) { for (MetricWriter child : (CompositeMetricWriter) writer) { flush(child); } } try { if (ClassUtils.isPresent("java.io.Flushable", null)) { if (writer instanceof Flushable) { ((Flushable) writer).flush(); return; } } Method method = ReflectionUtils.findMethod(writer.getClass(), "flush"); if (method != null) { ReflectionUtils.invokeMethod(method, writer); } } catch (Exception ex) { logger.warn("Could not flush MetricWriter: " + ex.getClass() + ": " + ex.getMessage()); } }
private void flush(MetricWriter writer) { if (writer instanceof CompositeMetricWriter) { for (MetricWriter child : (CompositeMetricWriter) writer) { flush(child); } } try { if (ClassUtils.isPresent("java.io.Flushable", null)) { if (writer instanceof Flushable) { ((Flushable) writer).flush(); return; } } Method method = ReflectionUtils.findMethod(writer.getClass(), "flush"); if (method != null) { ReflectionUtils.invokeMethod(method, writer); } } catch (Exception ex) { logger.warn("Could not flush MetricWriter: " + ex.getClass() + ": " + ex.getMessage()); } }
@Bean @Primary @ConditionalOnMissingClass("org.springframework.messaging.MessageChannel") @ConditionalOnMissingBean(name = "primaryMetricWriter") public MetricWriter primaryMetricWriter(List<MetricWriter> writers) { return new CompositeMetricWriter(writers); }
@Bean(name = "primaryMetricWriter") @Primary static public MetricWriter primaryMetricWriter(List<MetricWriter> writers) { // Normally the Metrics are written asynchronously to Spring Boot's repository. In tests we need to do it synchronously to be able to verify // the correct output. MetricWriter compositeMetricWriter = new CompositeMetricWriter(writers); return compositeMetricWriter; }