diff options
-rw-r--r-- | simplemetrics/src/main/java/com/yahoo/metrics/simple/MetricReceiver.java | 81 | ||||
-rw-r--r-- | vespajlib/src/main/java/com/yahoo/concurrent/ThreadLocalDirectory.java | 46 |
2 files changed, 49 insertions, 78 deletions
diff --git a/simplemetrics/src/main/java/com/yahoo/metrics/simple/MetricReceiver.java b/simplemetrics/src/main/java/com/yahoo/metrics/simple/MetricReceiver.java index a2b82978a26..e0e3469e257 100644 --- a/simplemetrics/src/main/java/com/yahoo/metrics/simple/MetricReceiver.java +++ b/simplemetrics/src/main/java/com/yahoo/metrics/simple/MetricReceiver.java @@ -29,6 +29,7 @@ public class MetricReceiver { private volatile Map<String, MetricSettings> metricSettings; private static final class NullCounter extends Counter { + NullCounter() { super(null, null, null); } @@ -72,18 +73,23 @@ public class MetricReceiver { public PointBuilder builder() { return super.builder(); } + } public static final class MockReceiver extends MetricReceiver { + private final ThreadLocalDirectory<Bucket, Sample> collection; + private MockReceiver(ThreadLocalDirectory<Bucket, Sample> collection) { super(collection, null); this.collection = collection; } + public MockReceiver() { this(new ThreadLocalDirectory<>(new MetricUpdater())); } - /** gathers all data since last snapshot */ + + /** Gathers all data since last snapshot */ public Bucket getSnapshot() { final Bucket merged = new Bucket(); for (Bucket b : collection.fetch()) { @@ -91,13 +97,16 @@ public class MetricReceiver { } return merged; } - /** utility method for testing */ + + /** Utility method for testing */ public Point point(String dim, String val) { return pointBuilder().set(dim, val).build(); } + } private static final class NullReceiver extends MetricReceiver { + NullReceiver() { super(null, null); } @@ -164,21 +173,18 @@ public class MetricReceiver { * {@link #declareGauge(String)}, or {@link #declareGauge(String, Point)} * instead. * - * @param s - * a single simple containing all meta data necessary to update a - * metric + * @param sample a single simple containing all meta data necessary to update a metric */ - public void update(Sample s) { + public void update(Sample sample) { // pass around the receiver instead of histogram settings to avoid reading any volatile if unnecessary - s.setReceiver(this); - metricsCollection.update(s); + sample.setReceiver(this); + metricsCollection.update(sample); } /** * Declare a counter metric without setting any default position. * - * @param name - * the name of the metric + * @param name the name of the metric * @return a thread-safe counter */ public Counter declareCounter(String name) { @@ -189,11 +195,8 @@ public class MetricReceiver { * Declare a counter metric, with default dimension values as given. Create * the point argument by using a builder from {@link #pointBuilder()}. * - * @param name - * the name of the metric - * @param boundDimensions - * dimensions which have a fixed value in the life cycle of the - * metric object or null + * @param name the name of the metric + * @param boundDimensions dimensions which have a fixed value in the life cycle of the metric object or null * @return a thread-safe counter with given default values */ public Counter declareCounter(String name, Point boundDimensions) { @@ -203,8 +206,7 @@ public class MetricReceiver { /** * Declare a gauge metric with any default position. * - * @param name - * the name of the metric + * @param name the name of the metric * @return a thread-safe gauge instance */ public Gauge declareGauge(String name) { @@ -215,21 +217,12 @@ public class MetricReceiver { * Declare a gauge metric, with default dimension values as given. Create * the point argument by using a builder from {@link #pointBuilder()}. * - * @param name - * the name of the metric - * @param boundDimensions - * dimensions which have a fixed value in the life cycle of the - * metric object or null + * @param name the name of the metric + * @param boundDimensions dimensions which have a fixed value in the life cycle of the metric object or null * @return a thread-safe gauge metric */ public Gauge declareGauge(String name, Point boundDimensions) { - Optional<Point> optionalOfBoundDimensions; - if (boundDimensions == null) { - optionalOfBoundDimensions = Optional.empty(); - } else { - optionalOfBoundDimensions = Optional.of(boundDimensions); - } - return declareGauge(name, optionalOfBoundDimensions, null); + return declareGauge(name, Optional.ofNullable(boundDimensions), null); } /** @@ -238,13 +231,9 @@ public class MetricReceiver { * MetricSettings instances are built using * {@link MetricSettings.Builder}. * - * @param name - * the name of the metric - * @param boundDimensions - * an optional of dimensions which have a fixed value in the life - * cycle of the metric object - * @param customSettings - * any optional settings + * @param name the name of the metric + * @param boundDimensions an optional of dimensions which have a fixed value in the life cycle of the metric object + * @param customSettings any optional settings * @return a thread-safe gauge metric */ public Gauge declareGauge(String name, Optional<Point> boundDimensions, MetricSettings customSettings) { @@ -283,14 +272,8 @@ public class MetricReceiver { /** * Add how to build a histogram for a given metric. * - * <p> - * Do note, this is not part of the public API. - * </p> - * - * @param metricName - * the metric where samples should be put in a histogram - * @param definition - * settings for a histogram + * @param metricName the metric where samples should be put in a histogram + * @param definition settings for a histogram */ void addMetricDefinition(String metricName, MetricSettings definition) { synchronized (histogramDefinitionsLock) { @@ -304,15 +287,9 @@ public class MetricReceiver { } /** - * Get how to build a histogram for a given metric, or null if no histogram - * should be created. - * - * <p> - * Do note, this is not part of the public API. - * </p> + * Get how to build a histogram for a given metric, or null if no histogram should be created. * - * @param metricName - * the name of an arbitrary metric + * @param metricName the name of an arbitrary metric * @return the corresponding histogram definition or null */ MetricSettings getMetricDefinition(String metricName) { diff --git a/vespajlib/src/main/java/com/yahoo/concurrent/ThreadLocalDirectory.java b/vespajlib/src/main/java/com/yahoo/concurrent/ThreadLocalDirectory.java index d5235caef9f..5ab1c88775a 100644 --- a/vespajlib/src/main/java/com/yahoo/concurrent/ThreadLocalDirectory.java +++ b/vespajlib/src/main/java/com/yahoo/concurrent/ThreadLocalDirectory.java @@ -62,14 +62,13 @@ import java.util.List; * example. * </p> * - * @param AGGREGATOR - * the type input data is aggregated into - * @param SAMPLE - * the type of input data + * @param <AGGREGATOR> the type input data is aggregated into + * @param <SAMPLE> the type of input data * - * @author <a href="mailto:steinar@yahoo-inc.com">Steinar Knutsen</a> + * @author Steinar Knutsen */ public final class ThreadLocalDirectory<AGGREGATOR, SAMPLE> { + /** * Factory interface to create the data container for each generation of * samples, and putting data into it. @@ -85,12 +84,11 @@ public final class ThreadLocalDirectory<AGGREGATOR, SAMPLE> { * need to implement both. * </p> * - * @param AGGREGATOR - * The type of the data container to produce - * @param SAMPLE - * The type of the incoming data to store in the container. + * @param <AGGREGATOR> the type of the data container to produce + * @param <SAMPLE> the type of the incoming data to store in the container. */ public interface Updater<AGGREGATOR, SAMPLE> { + /** * Create data container to receive produced data. This is invoked once * on every instance every time ThreadLocalDirectory.fetch() is invoked. @@ -137,7 +135,7 @@ public final class ThreadLocalDirectory<AGGREGATOR, SAMPLE> { * * @return a fresh structure to receive data */ - public AGGREGATOR createGenerationInstance(AGGREGATOR previous); + AGGREGATOR createGenerationInstance(AGGREGATOR previous); /** * Insert a data element of type S into the current generation of data @@ -180,7 +178,8 @@ public final class ThreadLocalDirectory<AGGREGATOR, SAMPLE> { * the data to insert * @return the new current value, may be the same as previous */ - public AGGREGATOR update(AGGREGATOR current, SAMPLE x); + AGGREGATOR update(AGGREGATOR current, SAMPLE x); + } /** @@ -188,14 +187,12 @@ public final class ThreadLocalDirectory<AGGREGATOR, SAMPLE> { * ThreadLocalDirectory without resetting the local instances in each * thread. * - * @param <AGGREGATOR> - * as for {@link Updater} - * @param <SAMPLE> - * as for {@link Updater} + * @param <AGGREGATOR> as for {@link Updater} + * @param <SAMPLE> as for {@link Updater} * @see ThreadLocalDirectory#view() */ - public interface ObservableUpdater<AGGREGATOR, SAMPLE> extends - Updater<AGGREGATOR, SAMPLE> { + public interface ObservableUpdater<AGGREGATOR, SAMPLE> extends Updater<AGGREGATOR, SAMPLE> { + /** * Create an application specific copy of the AGGREGATOR for a thread. * @@ -203,7 +200,8 @@ public final class ThreadLocalDirectory<AGGREGATOR, SAMPLE> { * the AGGREGATOR instance to copy * @return a copy of the incoming parameter */ - public AGGREGATOR copy(AGGREGATOR current); + AGGREGATOR copy(AGGREGATOR current); + } private final ThreadLocal<LocalInstance<AGGREGATOR, SAMPLE>> local = new ThreadLocal<>(); @@ -268,8 +266,7 @@ public final class ThreadLocalDirectory<AGGREGATOR, SAMPLE> { * to have been instantiated with an updater implementing ObservableUpdater. * * @return a list of a copy of the current data in all producer threads - * @throws IllegalStateException - * if the updater does not implement {@link ObservableUpdater} + * @throws IllegalStateException if the updater does not implement {@link ObservableUpdater} */ public List<AGGREGATOR> view() { if (observableUpdater == null) { @@ -310,8 +307,7 @@ public final class ThreadLocalDirectory<AGGREGATOR, SAMPLE> { /** * Input data from a producer thread. * - * @param x - * the data to insert + * @param x the data to insert */ public void update(SAMPLE x) { update(x, getOrCreateLocal()); @@ -330,10 +326,8 @@ public final class ThreadLocalDirectory<AGGREGATOR, SAMPLE> { * calls necessary to update(SAMPLE, LocalInstance<AGGREGATOR, SAMPLE>). * </p> * - * @param x - * the data to insert - * @param localInstance - * the local data insertion instance + * @param x the data to insert + * @param localInstance the local data insertion instance */ public void update(SAMPLE x, LocalInstance<AGGREGATOR, SAMPLE> localInstance) { boolean isRegistered; |