Skip to content
This repository was archived by the owner on Dec 23, 2023. It is now read-only.

Commit 5a97afd

Browse files
author
Bogdan Drutu
authored
Change the name TagContext to TagMap in the implementation. (#1681)
1 parent fb5c811 commit 5a97afd

File tree

13 files changed

+119
-122
lines changed

13 files changed

+119
-122
lines changed

impl_core/src/main/java/io/opencensus/implcore/stats/RecordUtils.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
import io.opencensus.implcore.stats.MutableAggregation.MutableMean;
2828
import io.opencensus.implcore.stats.MutableAggregation.MutableSumDouble;
2929
import io.opencensus.implcore.stats.MutableAggregation.MutableSumLong;
30-
import io.opencensus.implcore.tags.TagContextImpl;
30+
import io.opencensus.implcore.tags.TagMapImpl;
3131
import io.opencensus.stats.Aggregation;
3232
import io.opencensus.stats.Aggregation.Count;
3333
import io.opencensus.stats.Aggregation.Distribution;
@@ -62,8 +62,8 @@ final class RecordUtils {
6262
@javax.annotation.Nullable @VisibleForTesting static final TagValue UNKNOWN_TAG_VALUE = null;
6363

6464
static Map<TagKey, TagValue> getTagMap(TagContext ctx) {
65-
if (ctx instanceof TagContextImpl) {
66-
return ((TagContextImpl) ctx).getTags();
65+
if (ctx instanceof TagMapImpl) {
66+
return ((TagMapImpl) ctx).getTags();
6767
} else {
6868
Map<TagKey, TagValue> tags = Maps.newHashMap();
6969
for (Iterator<Tag> i = InternalUtils.getTags(ctx); i.hasNext(); ) {

impl_core/src/main/java/io/opencensus/implcore/tags/CurrentTagContextUtils.java renamed to impl_core/src/main/java/io/opencensus/implcore/tags/CurrentTagMapUtils.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,16 +24,16 @@
2424
/**
2525
* Utility methods for accessing the {@link TagContext} contained in the {@link io.grpc.Context}.
2626
*/
27-
final class CurrentTagContextUtils {
27+
final class CurrentTagMapUtils {
2828

29-
private CurrentTagContextUtils() {}
29+
private CurrentTagMapUtils() {}
3030

3131
/**
3232
* Returns the {@link TagContext} from the current context.
3333
*
3434
* @return the {@code TagContext} from the current context.
3535
*/
36-
static TagContext getCurrentTagContext() {
36+
static TagContext getCurrentTagMap() {
3737
return ContextUtils.TAG_CONTEXT_KEY.get();
3838
}
3939

@@ -46,20 +46,20 @@ static TagContext getCurrentTagContext() {
4646
* @return an object that defines a scope where the given {@code TagContext} is set to the current
4747
* context.
4848
*/
49-
static Scope withTagContext(TagContext tags) {
50-
return new WithTagContext(tags);
49+
static Scope withTagMap(TagContext tags) {
50+
return new WithTagMap(tags);
5151
}
5252

53-
private static final class WithTagContext implements Scope {
53+
private static final class WithTagMap implements Scope {
5454

5555
private final Context orig;
5656

5757
/**
58-
* Constructs a new {@link WithTagContext}.
58+
* Constructs a new {@link WithTagMap}.
5959
*
6060
* @param tags the {@code TagContext} to be added to the current {@code Context}.
6161
*/
62-
private WithTagContext(TagContext tags) {
62+
private WithTagMap(TagContext tags) {
6363
orig = Context.current().withValue(ContextUtils.TAG_CONTEXT_KEY, tags).attach();
6464
}
6565

impl_core/src/main/java/io/opencensus/implcore/tags/NoopTagContextBuilder.java renamed to impl_core/src/main/java/io/opencensus/implcore/tags/NoopTagMapBuilder.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,10 @@
2424
import io.opencensus.tags.TagValue;
2525

2626
/** {@link TagContextBuilder} that is used when tagging is disabled. */
27-
final class NoopTagContextBuilder extends TagContextBuilder {
28-
static final NoopTagContextBuilder INSTANCE = new NoopTagContextBuilder();
27+
final class NoopTagMapBuilder extends TagContextBuilder {
28+
static final NoopTagMapBuilder INSTANCE = new NoopTagMapBuilder();
2929

30-
private NoopTagContextBuilder() {}
30+
private NoopTagMapBuilder() {}
3131

3232
@Override
3333
public TagContextBuilder put(TagKey key, TagValue value) {
@@ -41,7 +41,7 @@ public TagContextBuilder remove(TagKey key) {
4141

4242
@Override
4343
public TagContext build() {
44-
return TagContextImpl.EMPTY;
44+
return TagMapImpl.EMPTY;
4545
}
4646

4747
@Override

impl_core/src/main/java/io/opencensus/implcore/tags/TagContextUtils.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ private TagContextUtils() {}
2727
* @param tag tag containing the key and value to set.
2828
* @param builder the builder to update.
2929
*/
30-
static void addTagToBuilder(Tag tag, TagContextBuilderImpl builder) {
30+
static void addTagToBuilder(Tag tag, TagMapBuilderImpl builder) {
3131
builder.put(tag.getKey(), tag.getValue());
3232
}
3333
}

impl_core/src/main/java/io/opencensus/implcore/tags/TagContextBuilderImpl.java renamed to impl_core/src/main/java/io/opencensus/implcore/tags/TagMapBuilderImpl.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,36 +25,36 @@
2525
import java.util.HashMap;
2626
import java.util.Map;
2727

28-
final class TagContextBuilderImpl extends TagContextBuilder {
28+
final class TagMapBuilderImpl extends TagContextBuilder {
2929
private final Map<TagKey, TagValue> tags;
3030

31-
TagContextBuilderImpl(Map<TagKey, TagValue> tags) {
31+
TagMapBuilderImpl(Map<TagKey, TagValue> tags) {
3232
this.tags = new HashMap<TagKey, TagValue>(tags);
3333
}
3434

35-
TagContextBuilderImpl() {
35+
TagMapBuilderImpl() {
3636
this.tags = new HashMap<TagKey, TagValue>();
3737
}
3838

3939
@Override
40-
public TagContextBuilderImpl put(TagKey key, TagValue value) {
40+
public TagMapBuilderImpl put(TagKey key, TagValue value) {
4141
tags.put(checkNotNull(key, "key"), checkNotNull(value, "value"));
4242
return this;
4343
}
4444

4545
@Override
46-
public TagContextBuilderImpl remove(TagKey key) {
46+
public TagMapBuilderImpl remove(TagKey key) {
4747
tags.remove(checkNotNull(key, "key"));
4848
return this;
4949
}
5050

5151
@Override
52-
public TagContextImpl build() {
53-
return new TagContextImpl(tags);
52+
public TagMapImpl build() {
53+
return new TagMapImpl(tags);
5454
}
5555

5656
@Override
5757
public Scope buildScoped() {
58-
return CurrentTagContextUtils.withTagContext(build());
58+
return CurrentTagMapUtils.withTagMap(build());
5959
}
6060
}

impl_core/src/main/java/io/opencensus/implcore/tags/TagContextImpl.java renamed to impl_core/src/main/java/io/opencensus/implcore/tags/TagMapImpl.java

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,14 @@
2929
import javax.annotation.concurrent.Immutable;
3030

3131
@Immutable
32-
public final class TagContextImpl extends TagContext {
32+
public final class TagMapImpl extends TagContext {
3333

34-
public static final TagContextImpl EMPTY =
35-
new TagContextImpl(Collections.<TagKey, TagValue>emptyMap());
34+
public static final TagMapImpl EMPTY = new TagMapImpl(Collections.<TagKey, TagValue>emptyMap());
3635

3736
// The types of the TagKey and value must match for each entry.
3837
private final Map<TagKey, TagValue> tags;
3938

40-
public TagContextImpl(Map<? extends TagKey, ? extends TagValue> tags) {
39+
public TagMapImpl(Map<? extends TagKey, ? extends TagValue> tags) {
4140
this.tags = Collections.unmodifiableMap(new HashMap<TagKey, TagValue>(tags));
4241
}
4342

@@ -52,9 +51,9 @@ protected Iterator<Tag> getIterator() {
5251

5352
@Override
5453
public boolean equals(@Nullable Object other) {
55-
// Directly compare the tags when both objects are TagContextImpls, for efficiency.
56-
if (other instanceof TagContextImpl) {
57-
return getTags().equals(((TagContextImpl) other).getTags());
54+
// Directly compare the tags when both objects are TagMapImpls, for efficiency.
55+
if (other instanceof TagMapImpl) {
56+
return getTags().equals(((TagMapImpl) other).getTags());
5857
}
5958
return super.equals(other);
6059
}

impl_core/src/main/java/io/opencensus/implcore/tags/TaggerImpl.java

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@
2929

3030
/** Implementation of {@link Tagger}. */
3131
public final class TaggerImpl extends Tagger {
32-
// All methods in this class use TagContextImpl and TagContextBuilderImpl. For example,
33-
// withTagContext(...) always puts a TagContextImpl into scope, even if the argument is another
32+
// All methods in this class use TagMapImpl and TagMapBuilderImpl. For example,
33+
// withTagContext(...) always puts a TagMapImpl into scope, even if the argument is another
3434
// TagContext subclass.
3535

3636
private final CurrentState state;
@@ -40,54 +40,54 @@ public final class TaggerImpl extends Tagger {
4040
}
4141

4242
@Override
43-
public TagContextImpl empty() {
44-
return TagContextImpl.EMPTY;
43+
public TagMapImpl empty() {
44+
return TagMapImpl.EMPTY;
4545
}
4646

4747
@Override
48-
public TagContextImpl getCurrentTagContext() {
48+
public TagMapImpl getCurrentTagContext() {
4949
return state.getInternal() == State.DISABLED
50-
? TagContextImpl.EMPTY
51-
: toTagContextImpl(CurrentTagContextUtils.getCurrentTagContext());
50+
? TagMapImpl.EMPTY
51+
: toTagMapImpl(CurrentTagMapUtils.getCurrentTagMap());
5252
}
5353

5454
@Override
5555
public TagContextBuilder emptyBuilder() {
5656
return state.getInternal() == State.DISABLED
57-
? NoopTagContextBuilder.INSTANCE
58-
: new TagContextBuilderImpl();
57+
? NoopTagMapBuilder.INSTANCE
58+
: new TagMapBuilderImpl();
5959
}
6060

6161
@Override
6262
public TagContextBuilder currentBuilder() {
6363
return state.getInternal() == State.DISABLED
64-
? NoopTagContextBuilder.INSTANCE
65-
: toBuilder(CurrentTagContextUtils.getCurrentTagContext());
64+
? NoopTagMapBuilder.INSTANCE
65+
: toBuilder(CurrentTagMapUtils.getCurrentTagMap());
6666
}
6767

6868
@Override
6969
public TagContextBuilder toBuilder(TagContext tags) {
7070
return state.getInternal() == State.DISABLED
71-
? NoopTagContextBuilder.INSTANCE
72-
: toTagContextBuilderImpl(tags);
71+
? NoopTagMapBuilder.INSTANCE
72+
: toTagMapBuilderImpl(tags);
7373
}
7474

7575
@Override
7676
public Scope withTagContext(TagContext tags) {
7777
return state.getInternal() == State.DISABLED
7878
? NoopScope.getInstance()
79-
: CurrentTagContextUtils.withTagContext(toTagContextImpl(tags));
79+
: CurrentTagMapUtils.withTagMap(toTagMapImpl(tags));
8080
}
8181

82-
private static TagContextImpl toTagContextImpl(TagContext tags) {
83-
if (tags instanceof TagContextImpl) {
84-
return (TagContextImpl) tags;
82+
private static TagMapImpl toTagMapImpl(TagContext tags) {
83+
if (tags instanceof TagMapImpl) {
84+
return (TagMapImpl) tags;
8585
} else {
8686
Iterator<Tag> i = InternalUtils.getTags(tags);
8787
if (!i.hasNext()) {
88-
return TagContextImpl.EMPTY;
88+
return TagMapImpl.EMPTY;
8989
}
90-
TagContextBuilderImpl builder = new TagContextBuilderImpl();
90+
TagMapBuilderImpl builder = new TagMapBuilderImpl();
9191
while (i.hasNext()) {
9292
Tag tag = i.next();
9393
if (tag != null) {
@@ -98,12 +98,12 @@ private static TagContextImpl toTagContextImpl(TagContext tags) {
9898
}
9999
}
100100

101-
private static TagContextBuilderImpl toTagContextBuilderImpl(TagContext tags) {
102-
// Copy the tags more efficiently in the expected case, when the TagContext is a TagContextImpl.
103-
if (tags instanceof TagContextImpl) {
104-
return new TagContextBuilderImpl(((TagContextImpl) tags).getTags());
101+
private static TagMapBuilderImpl toTagMapBuilderImpl(TagContext tags) {
102+
// Copy the tags more efficiently in the expected case, when the TagContext is a TagMapImpl.
103+
if (tags instanceof TagMapImpl) {
104+
return new TagMapBuilderImpl(((TagMapImpl) tags).getTags());
105105
} else {
106-
TagContextBuilderImpl builder = new TagContextBuilderImpl();
106+
TagMapBuilderImpl builder = new TagMapBuilderImpl();
107107
for (Iterator<Tag> i = InternalUtils.getTags(tags); i.hasNext(); ) {
108108
Tag tag = i.next();
109109
if (tag != null) {

impl_core/src/main/java/io/opencensus/implcore/tags/propagation/SerializationUtils.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
import com.google.common.io.ByteArrayDataOutput;
2222
import com.google.common.io.ByteStreams;
2323
import io.opencensus.implcore.internal.VarInt;
24-
import io.opencensus.implcore.tags.TagContextImpl;
24+
import io.opencensus.implcore.tags.TagMapImpl;
2525
import io.opencensus.tags.InternalUtils;
2626
import io.opencensus.tags.Tag;
2727
import io.opencensus.tags.TagContext;
@@ -94,7 +94,7 @@ static byte[] serializeBinary(TagContext tags) throws TagContextSerializationExc
9494

9595
// Deserializes input to TagContext based on the binary format standard.
9696
// The encoded tags are of the form: <version_id><encoded_tags>
97-
static TagContextImpl deserializeBinary(byte[] bytes) throws TagContextDeserializationException {
97+
static TagMapImpl deserializeBinary(byte[] bytes) throws TagContextDeserializationException {
9898
try {
9999
if (bytes.length == 0) {
100100
// Does not allow empty byte array.
@@ -107,7 +107,7 @@ static TagContextImpl deserializeBinary(byte[] bytes) throws TagContextDeseriali
107107
throw new TagContextDeserializationException(
108108
"Wrong Version ID: " + versionId + ". Currently supports version up to: " + VERSION_ID);
109109
}
110-
return new TagContextImpl(parseTags(buffer));
110+
return new TagMapImpl(parseTags(buffer));
111111
} catch (BufferUnderflowException exn) {
112112
throw new TagContextDeserializationException(exn.toString()); // byte array format error.
113113
}

impl_core/src/main/java/io/opencensus/implcore/tags/propagation/TagContextBinarySerializerImpl.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

1919
import io.opencensus.implcore.internal.CurrentState;
2020
import io.opencensus.implcore.internal.CurrentState.State;
21-
import io.opencensus.implcore.tags.TagContextImpl;
21+
import io.opencensus.implcore.tags.TagMapImpl;
2222
import io.opencensus.tags.TagContext;
2323
import io.opencensus.tags.propagation.TagContextBinarySerializer;
2424
import io.opencensus.tags.propagation.TagContextDeserializationException;
@@ -43,7 +43,7 @@ public byte[] toByteArray(TagContext tags) throws TagContextSerializationExcepti
4343
@Override
4444
public TagContext fromByteArray(byte[] bytes) throws TagContextDeserializationException {
4545
return state.getInternal() == State.DISABLED
46-
? TagContextImpl.EMPTY
46+
? TagMapImpl.EMPTY
4747
: SerializationUtils.deserializeBinary(bytes);
4848
}
4949
}

0 commit comments

Comments
 (0)