aboutsummaryrefslogtreecommitdiff
path: root/impl_core/src/main/java/io/opencensus/implcore/metrics/LongGaugeImpl.java
diff options
context:
space:
mode:
authorMayur Kale <mayurkale@google.com>2018-10-15 15:08:51 -0700
committerGitHub <noreply@github.com>2018-10-15 15:08:51 -0700
commite56a976d242d34b65e224f74d91fbafec83f96ad (patch)
treefbff5c32548a8e6f588edfa38ca338e9410e8b33 /impl_core/src/main/java/io/opencensus/implcore/metrics/LongGaugeImpl.java
parent418e675ee250299b77370620229bf7d3cd6c6830 (diff)
downloadopencensus-java-e56a976d242d34b65e224f74d91fbafec83f96ad.tar.gz
Gauge API : Add DoubleGauge Support (Part2) (#1496)
* Gauge API : Add DoubleGauge Support (Part2) * Fix review comments
Diffstat (limited to 'impl_core/src/main/java/io/opencensus/implcore/metrics/LongGaugeImpl.java')
-rw-r--r--impl_core/src/main/java/io/opencensus/implcore/metrics/LongGaugeImpl.java13
1 files changed, 6 insertions, 7 deletions
diff --git a/impl_core/src/main/java/io/opencensus/implcore/metrics/LongGaugeImpl.java b/impl_core/src/main/java/io/opencensus/implcore/metrics/LongGaugeImpl.java
index a7f84347..64cb3200 100644
--- a/impl_core/src/main/java/io/opencensus/implcore/metrics/LongGaugeImpl.java
+++ b/impl_core/src/main/java/io/opencensus/implcore/metrics/LongGaugeImpl.java
@@ -33,7 +33,7 @@ import io.opencensus.metrics.export.TimeSeries;
import io.opencensus.metrics.export.Value;
import java.util.ArrayList;
import java.util.Collections;
-import java.util.HashMap;
+import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.atomic.AtomicLong;
@@ -82,7 +82,7 @@ public final class LongGaugeImpl extends LongGauge implements Meter {
if (existingPoint != null) {
return existingPoint;
}
- return registerTimeSeries(defaultLabelValues);
+ return registerTimeSeries(Collections.unmodifiableList(defaultLabelValues));
}
@Override
@@ -90,7 +90,7 @@ public final class LongGaugeImpl extends LongGauge implements Meter {
checkNotNull(labelValues, "labelValues should not be null.");
Map<List<LabelValue>, PointImpl> registeredPointsCopy =
- new HashMap<List<LabelValue>, PointImpl>(registeredPoints);
+ new LinkedHashMap<List<LabelValue>, PointImpl>(registeredPoints);
if (registeredPointsCopy.remove(labelValues) == null) {
// The element not present, no need to update the current map of points.
return;
@@ -118,7 +118,7 @@ public final class LongGaugeImpl extends LongGauge implements Meter {
// Updating the map of points happens under a lock to avoid multiple add operations
// to happen in the same time.
Map<List<LabelValue>, PointImpl> registeredPointsCopy =
- new HashMap<List<LabelValue>, PointImpl>(registeredPoints);
+ new LinkedHashMap<List<LabelValue>, PointImpl>(registeredPoints);
registeredPointsCopy.put(labelValues, newPoint);
registeredPoints = Collections.unmodifiableMap(registeredPointsCopy);
@@ -133,13 +133,12 @@ public final class LongGaugeImpl extends LongGauge implements Meter {
return null;
}
- int pointCount = currentRegisteredPoints.size();
- if (pointCount == 1) {
+ if (currentRegisteredPoints.size() == 1) {
PointImpl point = currentRegisteredPoints.values().iterator().next();
return Metric.createWithOneTimeSeries(metricDescriptor, point.getTimeSeries(clock));
}
- List<TimeSeries> timeSeriesList = new ArrayList<TimeSeries>(pointCount);
+ List<TimeSeries> timeSeriesList = new ArrayList<TimeSeries>(currentRegisteredPoints.size());
for (Map.Entry<List<LabelValue>, PointImpl> entry : currentRegisteredPoints.entrySet()) {
timeSeriesList.add(entry.getValue().getTimeSeries(clock));
}