pull/272/head
Phillip Webb 11 years ago
parent 76b15c4446
commit e545e5aa32

@ -72,14 +72,6 @@ public class MetricFilterAutoConfiguration {
@Order(Ordered.HIGHEST_PRECEDENCE) @Order(Ordered.HIGHEST_PRECEDENCE)
private final class MetricsFilter extends OncePerRequestFilter { 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 @Override
protected void doFilterInternal(HttpServletRequest request, protected void doFilterInternal(HttpServletRequest request,
HttpServletResponse response, FilterChain chain) throws ServletException, HttpServletResponse response, FilterChain chain) throws ServletException,

@ -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 * Create a new exporter for metrics to a writer based on an empty prefix for the
* metric names. * metric names.
*
* @param reader a reader as the source of metrics * @param reader a reader as the source of metrics
* @param writer the writer to send the metrics to * @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 * Create a new exporter for metrics to a writer based on a prefix for the metric
* names. * names.
*
* @param reader a reader as the source of metrics * @param reader a reader as the source of metrics
* @param writer the writer to send the metrics to * @param writer the writer to send the metrics to
* @param prefix the prefix for metrics to export * @param prefix the prefix for metrics to export

@ -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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with 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; package org.springframework.boot.actuate.metrics.reader;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List; import java.util.List;
import org.springframework.boot.actuate.metrics.Metric; import org.springframework.boot.actuate.metrics.Metric;
/** /**
* Composite implementation of {@link MetricReader}.
*
* @author Dave Syer * @author Dave Syer
*/ */
public class CompositeMetricReader implements MetricReader { public class CompositeMetricReader implements MetricReader {
private List<MetricReader> delegates = Collections.emptyList(); private final List<MetricReader> readers = new ArrayList<MetricReader>();
public void setDelegates(Collection<MetricReader> delegates) { public CompositeMetricReader(MetricReader... readers) {
this.delegates = new ArrayList<MetricReader>(delegates); for (MetricReader reader : readers) {
this.readers.add(reader);
}
} }
@Override @Override
public Metric<?> findOne(String metricName) { public Metric<?> findOne(String metricName) {
for (MetricReader delegate : this.delegates) { for (MetricReader delegate : this.readers) {
Metric<?> value = delegate.findOne(metricName); Metric<?> value = delegate.findOne(metricName);
if (value != null) { if (value != null) {
return value; return value;
@ -48,7 +50,7 @@ public class CompositeMetricReader implements MetricReader {
@Override @Override
public Iterable<Metric<?>> findAll() { public Iterable<Metric<?>> findAll() {
List<Metric<?>> values = new ArrayList<Metric<?>>((int) count()); List<Metric<?>> values = new ArrayList<Metric<?>>((int) count());
for (MetricReader delegate : this.delegates) { for (MetricReader delegate : this.readers) {
Iterable<Metric<?>> all = delegate.findAll(); Iterable<Metric<?>> all = delegate.findAll();
for (Metric<?> value : all) { for (Metric<?> value : all) {
values.add(value); values.add(value);
@ -60,7 +62,7 @@ public class CompositeMetricReader implements MetricReader {
@Override @Override
public long count() { public long count() {
long count = 0; long count = 0;
for (MetricReader delegate : this.delegates) { for (MetricReader delegate : this.readers) {
count += delegate.count(); count += delegate.count();
} }

@ -28,7 +28,6 @@ public interface MetricReader {
/** /**
* Find an instance of the metric with the given name (usually the latest recorded * Find an instance of the metric with the given name (usually the latest recorded
* value). * value).
*
* @param metricName the name of the metric to find * @param metricName the name of the metric to find
* @return a metric value or null if there are none with that name * @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. * Find all the metrics known to this reader.
*
* @return all instances of metrics known to this reader * @return all instances of metrics known to this reader
*/ */
Iterable<Metric<?>> findAll(); Iterable<Metric<?>> findAll();
/** /**
* The number of metrics known to this reader. * The number of metrics known to this reader.
*
* @return the number of metrics * @return the number of metrics
*/ */
long count(); long count();

@ -27,7 +27,6 @@ public interface PrefixMetricReader {
/** /**
* Find all metrics whose name starts with the given prefix. * Find all metrics whose name starts with the given prefix.
*
* @param prefix the prefix for metric names * @param prefix the prefix for metric names
* @return all metrics with names starting with the prefix * @return all metrics with names starting with the prefix
*/ */

@ -31,7 +31,6 @@ public interface MultiMetricRepository extends PrefixMetricReader {
/** /**
* Save some metric values and associate them with a group name. * Save some metric values and associate them with a group name.
*
* @param group the name of the group * @param group the name of the group
* @param values the metric values to save * @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 * Rest the values of all metrics in the group. Implementations may choose to discard
* the old values. * the old values.
*
* @param group reset the whole group * @param group reset the whole group
*/ */
void reset(String group); void reset(String group);
/** /**
* The names of all the groups known to this repository * The names of all the groups known to this repository
*
* @return all available group names * @return all available group names
*/ */
Iterable<String> groups(); Iterable<String> groups();

@ -64,7 +64,6 @@ public class RedisMetricRepository implements MetricRepository {
/** /**
* The prefix for all metrics keys. * The prefix for all metrics keys.
*
* @param prefix the prefix to set for all metrics keys * @param prefix the prefix to set for all metrics keys
*/ */
public void setPrefix(String prefix) { 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 * 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 * {@link #findAll()} and {@link #count()}, will be much more efficient if the key is
* unique to the {@link #setPrefix(String) prefix} of this repository. * unique to the {@link #setPrefix(String) prefix} of this repository.
*
* @param key the key to set * @param key the key to set
*/ */
public void setKey(String key) { public void setKey(String key) {

@ -46,11 +46,8 @@ public final class RichGauge {
private double alpha; private double alpha;
/** /**
* Creates an "empty" 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.
* 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. * @param name the name under which the gauge will be stored.
*/ */
public RichGauge(String name) { public RichGauge(String name) {

@ -25,7 +25,6 @@ public interface RichGaugeReader {
/** /**
* Find a single instance of a rich gauge by name. * Find a single instance of a rich gauge by name.
*
* @param name the name of the gauge * @param name the name of the gauge
* @return a rich gauge value * @return a rich gauge value
*/ */
@ -33,7 +32,6 @@ public interface RichGaugeReader {
/** /**
* Find all instances of rich gauge known to this reader. * Find all instances of rich gauge known to this reader.
*
* @return all instances known to this reader * @return all instances known to this reader
*/ */
Iterable<RichGauge> findAll(); Iterable<RichGauge> findAll();

@ -28,14 +28,12 @@ public interface MetricWriter {
/** /**
* Increment the value of a metric (or decrement if the delta is negative). The name * 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. * of the delta is the name of the metric to increment.
*
* @param delta the amount to increment by * @param delta the amount to increment by
*/ */
void increment(Delta<?> delta); void increment(Delta<?> delta);
/** /**
* Set the value of a metric. * Set the value of a metric.
*
* @param value * @param value
*/ */
void set(Metric<?> 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 * Reset the value of a metric, usually to zero value. Implementations can discard the
* old values if desired, but may choose not to. * old values if desired, but may choose not to.
*
* @param metricName the name to reset * @param metricName the name to reset
*/ */
void reset(String metricName); void reset(String metricName);

@ -375,24 +375,27 @@ public class SpringApplication {
} }
protected void handleError(ConfigurableApplicationContext context, protected void handleError(ConfigurableApplicationContext context,
ApplicationEventMulticaster multicaster, Throwable ex, String... args) { ApplicationEventMulticaster multicaster, Throwable exception, String... args) {
try { try {
multicaster.multicastEvent(new SpringApplicationErrorEvent(this, context, 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 // We don't want to fail here and mask the original exception
if (this.log.isDebugEnabled()) { if (this.log.isDebugEnabled()) {
this.log.error("Error handling failed", e); this.log.error("Error handling failed", ex);
} }
else { else {
this.log.warn("Error handling failed (" + e.getMessage() + ")"); this.log.warn("Error handling failed (" + ex.getMessage() == null ? "no error message"
: ex.getMessage() + ")");
} }
} }
finally {
if (context != null) { if (context != null) {
context.close(); context.close();
} }
} }
}
private void registerListeners(ApplicationEventMulticaster multicaster, private void registerListeners(ApplicationEventMulticaster multicaster,
Set<Object> sources) { Set<Object> sources) {
@ -524,7 +527,6 @@ public class SpringApplication {
* @see #setApplicationContextClass(Class) * @see #setApplicationContextClass(Class)
*/ */
protected ConfigurableApplicationContext createApplicationContext() { protected ConfigurableApplicationContext createApplicationContext() {
Class<?> contextClass = this.applicationContextClass; Class<?> contextClass = this.applicationContextClass;
if (contextClass == null) { if (contextClass == null) {
try { try {
@ -538,9 +540,7 @@ public class SpringApplication {
+ "please specify an ApplicationContextClass", ex); + "please specify an ApplicationContextClass", ex);
} }
} }
return (ConfigurableApplicationContext) BeanUtils.instantiate(contextClass); return (ConfigurableApplicationContext) BeanUtils.instantiate(contextClass);
} }
/** /**

Loading…
Cancel
Save