From e545e5aa32c2a893bfcb3e395c0fec6d8719de8e Mon Sep 17 00:00:00 2001 From: Phillip Webb Date: Thu, 23 Jan 2014 22:01:47 -0800 Subject: [PATCH] Polish --- .../MetricFilterAutoConfiguration.java | 8 -------- .../export/PrefixMetricGroupExporter.java | 2 -- .../metrics/reader/CompositeMetricReader.java | 20 ++++++++++--------- .../actuate/metrics/reader/MetricReader.java | 3 --- .../metrics/reader/PrefixMetricReader.java | 1 - .../repository/MultiMetricRepository.java | 3 --- .../redis/RedisMetricRepository.java | 2 -- .../boot/actuate/metrics/rich/RichGauge.java | 7 ++----- .../actuate/metrics/rich/RichGaugeReader.java | 2 -- .../actuate/metrics/writer/MetricWriter.java | 3 --- .../boot/SpringApplication.java | 20 +++++++++---------- 11 files changed, 23 insertions(+), 48 deletions(-) diff --git a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/autoconfigure/MetricFilterAutoConfiguration.java b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/autoconfigure/MetricFilterAutoConfiguration.java index 6bfb1b4f6b..d7f1528cd4 100644 --- a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/autoconfigure/MetricFilterAutoConfiguration.java +++ b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/autoconfigure/MetricFilterAutoConfiguration.java @@ -72,14 +72,6 @@ public class MetricFilterAutoConfiguration { @Order(Ordered.HIGHEST_PRECEDENCE) private final class MetricsFilter extends OncePerRequestFilter { - /* - * (non-Javadoc) - * - * @see - * org.springframework.web.filter.OncePerRequestFilter#doFilterInternal(javax. - * servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse, - * javax.servlet.FilterChain) - */ @Override protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain chain) throws ServletException, diff --git a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/export/PrefixMetricGroupExporter.java b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/export/PrefixMetricGroupExporter.java index 67c4fa187b..844b4a7b1c 100644 --- a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/export/PrefixMetricGroupExporter.java +++ b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/export/PrefixMetricGroupExporter.java @@ -42,7 +42,6 @@ public class PrefixMetricGroupExporter extends AbstractMetricExporter { /** * Create a new exporter for metrics to a writer based on an empty prefix for the * metric names. - * * @param reader a reader as the source of metrics * @param writer the writer to send the metrics to */ @@ -53,7 +52,6 @@ public class PrefixMetricGroupExporter extends AbstractMetricExporter { /** * Create a new exporter for metrics to a writer based on a prefix for the metric * names. - * * @param reader a reader as the source of metrics * @param writer the writer to send the metrics to * @param prefix the prefix for metrics to export diff --git a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/reader/CompositeMetricReader.java b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/reader/CompositeMetricReader.java index df5340cdea..dfc9141e68 100644 --- a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/reader/CompositeMetricReader.java +++ b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/reader/CompositeMetricReader.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2013 the original author or authors. + * Copyright 2012-2014 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -17,26 +17,28 @@ package org.springframework.boot.actuate.metrics.reader; import java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; import java.util.List; import org.springframework.boot.actuate.metrics.Metric; /** + * Composite implementation of {@link MetricReader}. + * * @author Dave Syer */ public class CompositeMetricReader implements MetricReader { - private List delegates = Collections.emptyList(); + private final List readers = new ArrayList(); - public void setDelegates(Collection delegates) { - this.delegates = new ArrayList(delegates); + public CompositeMetricReader(MetricReader... readers) { + for (MetricReader reader : readers) { + this.readers.add(reader); + } } @Override public Metric findOne(String metricName) { - for (MetricReader delegate : this.delegates) { + for (MetricReader delegate : this.readers) { Metric value = delegate.findOne(metricName); if (value != null) { return value; @@ -48,7 +50,7 @@ public class CompositeMetricReader implements MetricReader { @Override public Iterable> findAll() { List> values = new ArrayList>((int) count()); - for (MetricReader delegate : this.delegates) { + for (MetricReader delegate : this.readers) { Iterable> all = delegate.findAll(); for (Metric value : all) { values.add(value); @@ -60,7 +62,7 @@ public class CompositeMetricReader implements MetricReader { @Override public long count() { long count = 0; - for (MetricReader delegate : this.delegates) { + for (MetricReader delegate : this.readers) { count += delegate.count(); } diff --git a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/reader/MetricReader.java b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/reader/MetricReader.java index 01039de70d..112da131c9 100644 --- a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/reader/MetricReader.java +++ b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/reader/MetricReader.java @@ -28,7 +28,6 @@ public interface MetricReader { /** * Find an instance of the metric with the given name (usually the latest recorded * value). - * * @param metricName the name of the metric to find * @return a metric value or null if there are none with that name */ @@ -36,14 +35,12 @@ public interface MetricReader { /** * Find all the metrics known to this reader. - * * @return all instances of metrics known to this reader */ Iterable> findAll(); /** * The number of metrics known to this reader. - * * @return the number of metrics */ long count(); diff --git a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/reader/PrefixMetricReader.java b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/reader/PrefixMetricReader.java index 136944d77b..1723261d28 100644 --- a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/reader/PrefixMetricReader.java +++ b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/reader/PrefixMetricReader.java @@ -27,7 +27,6 @@ public interface PrefixMetricReader { /** * Find all metrics whose name starts with the given prefix. - * * @param prefix the prefix for metric names * @return all metrics with names starting with the prefix */ diff --git a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/repository/MultiMetricRepository.java b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/repository/MultiMetricRepository.java index 8f612e2897..ecefafbeaa 100644 --- a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/repository/MultiMetricRepository.java +++ b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/repository/MultiMetricRepository.java @@ -31,7 +31,6 @@ public interface MultiMetricRepository extends PrefixMetricReader { /** * Save some metric values and associate them with a group name. - * * @param group the name of the group * @param values the metric values to save */ @@ -40,14 +39,12 @@ public interface MultiMetricRepository extends PrefixMetricReader { /** * Rest the values of all metrics in the group. Implementations may choose to discard * the old values. - * * @param group reset the whole group */ void reset(String group); /** * The names of all the groups known to this repository - * * @return all available group names */ Iterable groups(); diff --git a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/repository/redis/RedisMetricRepository.java b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/repository/redis/RedisMetricRepository.java index 300a891d4c..201d04dd2e 100644 --- a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/repository/redis/RedisMetricRepository.java +++ b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/repository/redis/RedisMetricRepository.java @@ -64,7 +64,6 @@ public class RedisMetricRepository implements MetricRepository { /** * The prefix for all metrics keys. - * * @param prefix the prefix to set for all metrics keys */ public void setPrefix(String prefix) { @@ -79,7 +78,6 @@ public class RedisMetricRepository implements MetricRepository { * zset under this key. Defaults to "keys.spring.metrics". REad operations, especially * {@link #findAll()} and {@link #count()}, will be much more efficient if the key is * unique to the {@link #setPrefix(String) prefix} of this repository. - * * @param key the key to set */ public void setKey(String key) { diff --git a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/rich/RichGauge.java b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/rich/RichGauge.java index 722481152c..7a6bd6330c 100644 --- a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/rich/RichGauge.java +++ b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/rich/RichGauge.java @@ -46,11 +46,8 @@ public final class RichGauge { private double alpha; /** - * Creates an "empty" gauge. - * - * The average, max and min will be zero, but this initial value will not be included - * after the first value has been set on the gauge. - * + * Creates an "empty" gauge. The average, max and min will be zero, but this initial + * value will not be included after the first value has been set on the gauge. * @param name the name under which the gauge will be stored. */ public RichGauge(String name) { diff --git a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/rich/RichGaugeReader.java b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/rich/RichGaugeReader.java index 43ea9ab1d4..938f323948 100644 --- a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/rich/RichGaugeReader.java +++ b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/rich/RichGaugeReader.java @@ -25,7 +25,6 @@ public interface RichGaugeReader { /** * Find a single instance of a rich gauge by name. - * * @param name the name of the gauge * @return a rich gauge value */ @@ -33,7 +32,6 @@ public interface RichGaugeReader { /** * Find all instances of rich gauge known to this reader. - * * @return all instances known to this reader */ Iterable findAll(); diff --git a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/writer/MetricWriter.java b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/writer/MetricWriter.java index 1545f0d098..e7d74d81a2 100644 --- a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/writer/MetricWriter.java +++ b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/writer/MetricWriter.java @@ -28,14 +28,12 @@ public interface MetricWriter { /** * Increment the value of a metric (or decrement if the delta is negative). The name * of the delta is the name of the metric to increment. - * * @param delta the amount to increment by */ void increment(Delta delta); /** * Set the value of a metric. - * * @param value */ void set(Metric value); @@ -43,7 +41,6 @@ public interface MetricWriter { /** * Reset the value of a metric, usually to zero value. Implementations can discard the * old values if desired, but may choose not to. - * * @param metricName the name to reset */ void reset(String metricName); diff --git a/spring-boot/src/main/java/org/springframework/boot/SpringApplication.java b/spring-boot/src/main/java/org/springframework/boot/SpringApplication.java index 2e5a1e50e2..cbf80a2ad7 100644 --- a/spring-boot/src/main/java/org/springframework/boot/SpringApplication.java +++ b/spring-boot/src/main/java/org/springframework/boot/SpringApplication.java @@ -375,22 +375,25 @@ public class SpringApplication { } protected void handleError(ConfigurableApplicationContext context, - ApplicationEventMulticaster multicaster, Throwable ex, String... args) { + ApplicationEventMulticaster multicaster, Throwable exception, String... args) { try { multicaster.multicastEvent(new SpringApplicationErrorEvent(this, context, - args, ex)); + args, exception)); } - catch (Exception e) { + catch (Exception ex) { // We don't want to fail here and mask the original exception if (this.log.isDebugEnabled()) { - this.log.error("Error handling failed", e); + this.log.error("Error handling failed", ex); } else { - this.log.warn("Error handling failed (" + e.getMessage() + ")"); + this.log.warn("Error handling failed (" + ex.getMessage() == null ? "no error message" + : ex.getMessage() + ")"); } } - if (context != null) { - context.close(); + finally { + if (context != null) { + context.close(); + } } } @@ -524,7 +527,6 @@ public class SpringApplication { * @see #setApplicationContextClass(Class) */ protected ConfigurableApplicationContext createApplicationContext() { - Class contextClass = this.applicationContextClass; if (contextClass == null) { try { @@ -538,9 +540,7 @@ public class SpringApplication { + "please specify an ApplicationContextClass", ex); } } - return (ConfigurableApplicationContext) BeanUtils.instantiate(contextClass); - } /**