Created
May 19, 2017 06:02
-
-
Save anuraaga/7c37e012fcd260c4da2bc0963ab79315 to your computer and use it in GitHub Desktop.
Array type coercion (arrays are covariant)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/core/src/main/java/com/linecorp/armeria/internal/metric/PrometheusMetricRequestDecorator.java b/core/src/main/java/com/linecorp/armeria/internal/metric/PrometheusMetricRequestDecorator.java | |
index 29a4523d..ce71ae60 100644 | |
--- a/core/src/main/java/com/linecorp/armeria/internal/metric/PrometheusMetricRequestDecorator.java | |
+++ b/core/src/main/java/com/linecorp/armeria/internal/metric/PrometheusMetricRequestDecorator.java | |
@@ -24,8 +24,8 @@ import java.util.concurrent.TimeUnit; | |
import java.util.function.Function; | |
import java.util.stream.Stream; | |
-import com.google.common.collect.ImmutableList; | |
import com.google.common.collect.ImmutableSortedMap; | |
+import com.google.common.collect.Iterables; | |
import com.linecorp.armeria.client.Client; | |
import com.linecorp.armeria.client.ClientRequestContext; | |
@@ -144,24 +144,24 @@ public final class PrometheusMetricRequestDecorator<T extends MetricLabel<T>, | |
} | |
private final Function<RequestLog, Map<T, String>> labelingFunction; | |
- private final MetricAdapter metricAdapter; | |
+ private final MetricAdapter<T> metricAdapter; | |
private PrometheusMetricRequestDecorator( | |
CollectorRegistry collectorRegistry, | |
- Object[] metricLabels, | |
+ T[] metricLabels, | |
Function<RequestLog, Map<T, String>> labelingFunction, | |
String prefix) { | |
requireNonNull(collectorRegistry, "collectorRegistry"); | |
requireNonNull(metricLabels, "metricLabels"); | |
- Object[] metricLabelsCopy = Arrays.copyOf(metricLabels, metricLabels.length); | |
- for (Object metricLabel : metricLabelsCopy) { | |
+ T[] metricLabelsCopy = Arrays.copyOf(metricLabels, metricLabels.length); | |
+ for (T metricLabel : metricLabelsCopy) { | |
requireNonNull(metricLabel, "metricLabels contains null"); | |
} | |
requireNonNull(labelingFunction, "labelingFunction"); | |
requireNonNull(prefix, "prefix"); | |
this.labelingFunction = labelingFunction; | |
- this.metricAdapter = new MetricAdapter(collectorRegistry, metricLabelsCopy, prefix, HELP_STRING); | |
+ this.metricAdapter = new MetricAdapter<>(collectorRegistry, metricLabelsCopy, prefix, HELP_STRING); | |
} | |
private PrometheusMetricRequestDecorator( | |
@@ -170,7 +170,7 @@ public final class PrometheusMetricRequestDecorator<T extends MetricLabel<T>, | |
Function<RequestLog, Map<T, String>> labelingFunction, | |
String prefix) { | |
this(collectorRegistry, | |
- ImmutableList.copyOf(requireNonNull(metricLabels, "metricLabels")).toArray(), | |
+ (T[]) Iterables.toArray(requireNonNull(metricLabels, "metricLabels"), MetricLabel.class), | |
labelingFunction, | |
prefix); | |
} | |
@@ -255,7 +255,7 @@ public final class PrometheusMetricRequestDecorator<T extends MetricLabel<T>, | |
O apply(C c, I i) throws Exception; | |
} | |
- private static final class MetricAdapter { | |
+ private static final class MetricAdapter<T extends MetricLabel<T>> { | |
private final Summary timer; | |
private final Counter success; | |
@@ -265,7 +265,7 @@ public final class PrometheusMetricRequestDecorator<T extends MetricLabel<T>, | |
private final Summary responseBytes; | |
private MetricAdapter(CollectorRegistry collectorRegistry, | |
- Object[] metricLabels, | |
+ T[] metricLabels, | |
String namePrefix, | |
String help) { | |
requireNonNull(collectorRegistry, "collectorRegistry"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment