aboutsummaryrefslogtreecommitdiff
path: root/impl_core/src/main/java/io/opencensus
diff options
context:
space:
mode:
authorKristen Kozak <sebright@google.com>2017-12-19 20:02:00 -0800
committerKristen Kozak <sebright@google.com>2017-12-19 20:02:00 -0800
commit6e53b74c4325ed2a80caf5f162614ba6fbec4c3c (patch)
tree904ad07c3ed045c61e2ef4215548c6ed1c983e2e /impl_core/src/main/java/io/opencensus
parent2fc0d4dd057ca28e1e9c37d18ebcfac6d2136de9 (diff)
downloadopencensus-java-6e53b74c4325ed2a80caf5f162614ba6fbec4c3c.tar.gz
Add Checker Framework annotations in comments (issue #359).
Putting the annotations in comments allows us to use Java 8 syntax and avoid depending on the Checker Framework library. Note that we need to use org.checkerframework.checker.nullness.qual.Nullable for marking types nullable, because javax.annotation.Nullable can't be applied to types.
Diffstat (limited to 'impl_core/src/main/java/io/opencensus')
-rw-r--r--impl_core/src/main/java/io/opencensus/implcore/stats/IntervalBucket.java11
-rw-r--r--impl_core/src/main/java/io/opencensus/implcore/stats/MeasureToViewMap.java13
-rw-r--r--impl_core/src/main/java/io/opencensus/implcore/stats/MutableViewData.java30
3 files changed, 34 insertions, 20 deletions
diff --git a/impl_core/src/main/java/io/opencensus/implcore/stats/IntervalBucket.java b/impl_core/src/main/java/io/opencensus/implcore/stats/IntervalBucket.java
index 68380791..a35948a7 100644
--- a/impl_core/src/main/java/io/opencensus/implcore/stats/IntervalBucket.java
+++ b/impl_core/src/main/java/io/opencensus/implcore/stats/IntervalBucket.java
@@ -28,6 +28,10 @@ import io.opencensus.tags.TagValue;
import java.util.List;
import java.util.Map;
+/*>>>
+import org.checkerframework.checker.nullness.qual.Nullable;
+*/
+
/** The bucket with aggregated {@code MeasureValue}s used for {@code IntervalViewData}. */
final class IntervalBucket {
@@ -36,7 +40,8 @@ final class IntervalBucket {
private final Timestamp start;
private final Duration duration;
private final Aggregation aggregation;
- private final Map<List<TagValue>, MutableAggregation> tagValueAggregationMap = Maps.newHashMap();
+ private final Map<List</*@Nullable*/ TagValue>, MutableAggregation> tagValueAggregationMap =
+ Maps.newHashMap();
IntervalBucket(Timestamp start, Duration duration, Aggregation aggregation) {
checkNotNull(start, "Start");
@@ -48,7 +53,7 @@ final class IntervalBucket {
this.aggregation = aggregation;
}
- Map<List<TagValue>, MutableAggregation> getTagValueAggregationMap() {
+ Map<List</*@Nullable*/ TagValue>, MutableAggregation> getTagValueAggregationMap() {
return tagValueAggregationMap;
}
@@ -57,7 +62,7 @@ final class IntervalBucket {
}
// Puts a new value into the internal MutableAggregations, based on the TagValues.
- void record(List<TagValue> tagValues, double value) {
+ void record(List</*@Nullable*/ TagValue> tagValues, double value) {
if (!tagValueAggregationMap.containsKey(tagValues)) {
tagValueAggregationMap.put(tagValues, MutableViewData.createMutableAggregation(aggregation));
}
diff --git a/impl_core/src/main/java/io/opencensus/implcore/stats/MeasureToViewMap.java b/impl_core/src/main/java/io/opencensus/implcore/stats/MeasureToViewMap.java
index 4e55c741..64173713 100644
--- a/impl_core/src/main/java/io/opencensus/implcore/stats/MeasureToViewMap.java
+++ b/impl_core/src/main/java/io/opencensus/implcore/stats/MeasureToViewMap.java
@@ -40,9 +40,12 @@ import java.util.Iterator;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
-import javax.annotation.Nullable;
import javax.annotation.concurrent.GuardedBy;
+/*>>>
+import org.checkerframework.checker.nullness.qual.Nullable;
+*/
+
/** A class that stores a singleton map from {@code MeasureName}s to {@link MutableViewData}s. */
final class MeasureToViewMap {
@@ -63,10 +66,10 @@ final class MeasureToViewMap {
// Cached set of exported views. It must be set to null whenever a view is registered or
// unregistered.
- @Nullable private volatile Set<View> exportedViews;
+ @javax.annotation.Nullable private volatile Set<View> exportedViews;
/** Returns a {@link ViewData} corresponding to the given {@link View.Name}. */
- @Nullable
+ @javax.annotation.Nullable
synchronized ViewData getView(View.Name viewName, Clock clock, StatsCollectionState state) {
MutableViewData view = getMutableViewData(viewName);
return view == null ? null : view.toViewData(clock.now(), state);
@@ -119,7 +122,7 @@ final class MeasureToViewMap {
mutableMap.put(view.getMeasure().getName(), MutableViewData.create(view, clock.now()));
}
- @Nullable
+ @javax.annotation.Nullable
private synchronized MutableViewData getMutableViewData(View.Name viewName) {
View view = registeredViews.get(viewName);
if (view == null) {
@@ -155,7 +158,7 @@ final class MeasureToViewMap {
measurement.match(
new RecordDoubleValueFunc(tags, view, timestamp),
new RecordLongValueFunc(tags, view, timestamp),
- Functions.<Void>throwAssertionError());
+ Functions.</*@Nullable*/ Void>throwAssertionError());
}
}
}
diff --git a/impl_core/src/main/java/io/opencensus/implcore/stats/MutableViewData.java b/impl_core/src/main/java/io/opencensus/implcore/stats/MutableViewData.java
index 7d251559..4963ce59 100644
--- a/impl_core/src/main/java/io/opencensus/implcore/stats/MutableViewData.java
+++ b/impl_core/src/main/java/io/opencensus/implcore/stats/MutableViewData.java
@@ -63,7 +63,10 @@ import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
-import javax.annotation.Nullable;
+
+/*>>>
+import org.checkerframework.checker.nullness.qual.Nullable;
+*/
/** A mutable version of {@link ViewData}, used for recording stats and start/end time. */
abstract class MutableViewData {
@@ -71,7 +74,7 @@ abstract class MutableViewData {
private static final long MILLIS_PER_SECOND = 1000L;
private static final long NANOS_PER_MILLI = 1000 * 1000;
- @Nullable @VisibleForTesting static final TagValue UNKNOWN_TAG_VALUE = null;
+ @javax.annotation.Nullable @VisibleForTesting static final TagValue UNKNOWN_TAG_VALUE = null;
@VisibleForTesting static final Timestamp ZERO_TIMESTAMP = Timestamp.create(0, 0);
@@ -134,9 +137,9 @@ abstract class MutableViewData {
}
@VisibleForTesting
- static List<TagValue> getTagValues(
+ static List</*@Nullable*/ TagValue> getTagValues(
Map<? extends TagKey, ? extends TagValue> tags, List<? extends TagKey> columns) {
- List<TagValue> tagValues = new ArrayList<TagValue>(columns.size());
+ List</*@Nullable*/ TagValue> tagValues = new ArrayList</*@Nullable*/ TagValue>(columns.size());
// Record all the measures in a "Greedy" way.
// Every view aggregates every measure. This is similar to doing a GROUPBY view’s keys.
for (int i = 0; i < columns.size(); ++i) {
@@ -202,7 +205,7 @@ abstract class MutableViewData {
private static final class CumulativeMutableViewData extends MutableViewData {
private Timestamp start;
- private final Map<List<TagValue>, MutableAggregation> tagValueAggregationMap =
+ private final Map<List</*@Nullable*/ TagValue>, MutableAggregation> tagValueAggregationMap =
Maps.newHashMap();
private CumulativeMutableViewData(View view, Timestamp start) {
@@ -212,7 +215,8 @@ abstract class MutableViewData {
@Override
void record(TagContext context, double value, Timestamp timestamp) {
- List<TagValue> tagValues = getTagValues(getTagMap(context), super.view.getColumns());
+ List</*@Nullable*/ TagValue> tagValues =
+ getTagValues(getTagMap(context), super.view.getColumns());
if (!tagValueAggregationMap.containsKey(tagValues)) {
tagValueAggregationMap.put(
tagValues, createMutableAggregation(super.view.getAggregation()));
@@ -305,7 +309,8 @@ abstract class MutableViewData {
@Override
void record(TagContext context, double value, Timestamp timestamp) {
- List<TagValue> tagValues = getTagValues(getTagMap(context), super.view.getColumns());
+ List</*@Nullable*/ TagValue> tagValues =
+ getTagValues(getTagMap(context), super.view.getColumns());
refreshBucketList(timestamp);
// It is always the last bucket that does the recording.
NullnessUtils.castNonNull(buckets.peekLast()).record(tagValues, value);
@@ -390,8 +395,9 @@ abstract class MutableViewData {
// Combine stats within each bucket, aggregate stats by tag values, and return the mapping from
// tag values to aggregation data.
- private Map<List<TagValue>, AggregationData> combineBucketsAndGetAggregationMap(Timestamp now) {
- Multimap<List<TagValue>, MutableAggregation> multimap = HashMultimap.create();
+ private Map<List</*@Nullable*/ TagValue>, AggregationData> combineBucketsAndGetAggregationMap(
+ Timestamp now) {
+ Multimap<List</*@Nullable*/ TagValue>, MutableAggregation> multimap = HashMultimap.create();
// TODO(sebright): Decide whether to use a different class instead of LinkedList.
@SuppressWarnings("JdkObsolete")
@@ -399,7 +405,7 @@ abstract class MutableViewData {
Aggregation aggregation = super.view.getAggregation();
putBucketsIntoMultiMap(shallowCopy, multimap, aggregation, now);
- Map<List<TagValue>, MutableAggregation> singleMap =
+ Map<List</*@Nullable*/ TagValue>, MutableAggregation> singleMap =
aggregateOnEachTagValueList(multimap, aggregation);
return createAggregationMap(singleMap, super.getView().getMeasure());
}
@@ -408,7 +414,7 @@ abstract class MutableViewData {
// mutable aggregations (map value) from different buckets.
private static void putBucketsIntoMultiMap(
LinkedList<IntervalBucket> buckets,
- Multimap<List<TagValue>, MutableAggregation> multimap,
+ Multimap<List</*@Nullable*/ TagValue>, MutableAggregation> multimap,
Aggregation aggregation,
Timestamp now) {
// Put fractional stats of the head (oldest) bucket.
@@ -430,7 +436,7 @@ abstract class MutableViewData {
shouldSkipFirst = false;
continue; // skip the first bucket
}
- for (Entry<List<TagValue>, MutableAggregation> entry :
+ for (Entry<List</*@Nullable*/ TagValue>, MutableAggregation> entry :
bucket.getTagValueAggregationMap().entrySet()) {
multimap.put(entry.getKey(), entry.getValue());
}