From 4e1f6ff3c26b6278efbcf2c7ea923c3f5bf872c5 Mon Sep 17 00:00:00 2001 From: Bogdan Drutu Date: Sun, 19 Feb 2017 10:36:20 -0800 Subject: Move core_impl to the equivalent maven path. --- BUILD | 2 +- .../stats/StatsContextFactoryImpl.java | 42 ----------- .../instrumentation/stats/StatsContextImpl.java | 83 --------------------- .../instrumentation/stats/StatsCurrentContext.java | 34 --------- .../instrumentation/stats/StatsSerializer.java | 84 ---------------------- core_impl/pom.xml | 1 - .../stats/StatsContextFactoryImpl.java | 42 +++++++++++ .../instrumentation/stats/StatsContextImpl.java | 83 +++++++++++++++++++++ .../instrumentation/stats/StatsCurrentContext.java | 34 +++++++++ .../instrumentation/stats/StatsSerializer.java | 84 ++++++++++++++++++++++ 10 files changed, 244 insertions(+), 245 deletions(-) delete mode 100644 core_impl/java/com/google/instrumentation/stats/StatsContextFactoryImpl.java delete mode 100644 core_impl/java/com/google/instrumentation/stats/StatsContextImpl.java delete mode 100644 core_impl/java/com/google/instrumentation/stats/StatsCurrentContext.java delete mode 100644 core_impl/java/com/google/instrumentation/stats/StatsSerializer.java create mode 100644 core_impl/src/main/java/com/google/instrumentation/stats/StatsContextFactoryImpl.java create mode 100644 core_impl/src/main/java/com/google/instrumentation/stats/StatsContextImpl.java create mode 100644 core_impl/src/main/java/com/google/instrumentation/stats/StatsCurrentContext.java create mode 100644 core_impl/src/main/java/com/google/instrumentation/stats/StatsSerializer.java diff --git a/BUILD b/BUILD index 532edbb2..e14102f2 100644 --- a/BUILD +++ b/BUILD @@ -34,7 +34,7 @@ java_library( java_library( name = "stats-core_impl", - srcs = glob(["core_impl/java/com/google/instrumentation/stats/*.java"]), + srcs = glob(["core_impl/src/main/java/com/google/instrumentation/stats/*.java"]), deps = [ ":shared", ":stats-core", diff --git a/core_impl/java/com/google/instrumentation/stats/StatsContextFactoryImpl.java b/core_impl/java/com/google/instrumentation/stats/StatsContextFactoryImpl.java deleted file mode 100644 index f888b997..00000000 --- a/core_impl/java/com/google/instrumentation/stats/StatsContextFactoryImpl.java +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Copyright 2016, Google Inc. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * http://www.apache.org/licenses/LICENSE-2.0 - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.google.instrumentation.stats; - -import java.io.InputStream; -import java.io.IOException; -import java.util.HashMap; - -/** - * Native Implementation of {@link StatsContextFactory}. - */ -public final class StatsContextFactoryImpl extends StatsContextFactory { - static final StatsContextImpl DEFAULT = new StatsContextImpl(new HashMap(0)); - - public StatsContextFactoryImpl() {} - - /** - * Deserializes a {@link StatsContextImpl} from a serialized {@code CensusContextProto}. - * - *

The encoded tags are of the form: {@code + 'key' + + 'value'}* - */ - @Override - public StatsContextImpl deserialize(InputStream input) throws IOException { - return StatsSerializer.deserialize(input); - } - - @Override - public StatsContext getDefault() { - return DEFAULT; - } -} diff --git a/core_impl/java/com/google/instrumentation/stats/StatsContextImpl.java b/core_impl/java/com/google/instrumentation/stats/StatsContextImpl.java deleted file mode 100644 index af7d94fc..00000000 --- a/core_impl/java/com/google/instrumentation/stats/StatsContextImpl.java +++ /dev/null @@ -1,83 +0,0 @@ -/* - * Copyright 2016, Google Inc. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * http://www.apache.org/licenses/LICENSE-2.0 - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.google.instrumentation.stats; - -import java.io.IOException; -import java.io.OutputStream; -import java.util.HashMap; - -/** - * Native Implementation of {@link StatsContext}. - */ -final class StatsContextImpl extends StatsContext { - final HashMap tags; - - StatsContextImpl(HashMap tags) { - this.tags = tags; - } - - @Override - public Builder builder() { - return new Builder(tags); - } - - @Override - public StatsContextImpl record(MeasurementMap stats) { - return this; - } - - /** - * Serializes a {@link StatsContextImpl} into {@code CensusContextProto} serialized format. - * - *

The encoded tags are of the form: {@code + 'key' + + 'value'}* - */ - @Override - public void serialize(OutputStream output) throws IOException { - StatsSerializer.serialize(this, output); - } - - @Override - public boolean equals(Object obj) { - return (obj instanceof StatsContextImpl) && tags.equals(((StatsContextImpl) obj).tags); - } - - @Override - public int hashCode() { - return tags.hashCode(); - } - - @Override - public String toString() { - return tags.toString(); - } - - private static final class Builder extends StatsContext.Builder { - private final HashMap tags; - - private Builder(HashMap tags) { - this.tags = new HashMap(tags); - } - - @Override - public Builder set(TagKey key, TagValue value) { - tags.put(key.toString(), value.toString()); - return this; - } - - @Override - public StatsContext build() { - return new StatsContextImpl(new HashMap(tags)); - } - } -} diff --git a/core_impl/java/com/google/instrumentation/stats/StatsCurrentContext.java b/core_impl/java/com/google/instrumentation/stats/StatsCurrentContext.java deleted file mode 100644 index 53b138b2..00000000 --- a/core_impl/java/com/google/instrumentation/stats/StatsCurrentContext.java +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Copyright 2016, Google Inc. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * http://www.apache.org/licenses/LICENSE-2.0 - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.google.instrumentation.stats; - -/** - * Native implementation of thread-local {@link StatsContext}. - */ -class StatsCurrentContext { - static final ThreadLocal contexts = new ThreadLocal() { - @Override - protected StatsContextImpl initialValue() { - return StatsContextFactoryImpl.DEFAULT; - } - }; - - public static void set(StatsContextImpl context) { - contexts.set(context); - } - - public static StatsContextImpl get() { - return contexts.get(); - } -} diff --git a/core_impl/java/com/google/instrumentation/stats/StatsSerializer.java b/core_impl/java/com/google/instrumentation/stats/StatsSerializer.java deleted file mode 100644 index 62c4ca66..00000000 --- a/core_impl/java/com/google/instrumentation/stats/StatsSerializer.java +++ /dev/null @@ -1,84 +0,0 @@ -/* - * Copyright 2016, Google Inc. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * http://www.apache.org/licenses/LICENSE-2.0 - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.google.instrumentation.stats; - -import com.google.instrumentation.stats.proto.StatsContextProto; -import com.google.io.base.VarInt; -import com.google.protobuf.ByteString; - -import java.io.InputStream; -import java.io.IOException; -import java.io.OutputStream; -import java.nio.BufferUnderflowException; -import java.nio.ByteBuffer; -import java.util.HashMap; -import java.util.Map.Entry; -import java.util.Set; - -/** - * Native implementation {@link StatsContext} serialization. - */ -final class StatsSerializer { - // Serializes a StatsContext by transforming it into a StatsContextProto. The - // encoded tags are of the form: - // num_tags [key_len key_bytes value_len value_bytes]* - static void serialize(StatsContextImpl context, OutputStream output) throws IOException { - ByteBuffer buffer = ByteBuffer.allocate(1024); - Set> tags = context.tags.entrySet(); - VarInt.putVarInt(tags.size(), buffer); - for (Entry tag : tags) { - encode(tag.getKey(), buffer); - encode(tag.getValue(), buffer); - } - int length = buffer.capacity() - buffer.remaining(); - buffer.rewind(); - ByteString encodedTags = ByteString.copyFrom(buffer, length); - StatsContextProto.StatsContext.newBuilder().setTags(encodedTags).build().writeTo(output); - } - - // Deserializes based on an serialized StatsContextProto. The encoded tags are of the form: - // num_tags [key_len key_bytes value_len value_bytes]* - static StatsContextImpl deserialize(InputStream input) throws IOException { - try { - StatsContextProto.StatsContext context = StatsContextProto.StatsContext.parseFrom(input); - ByteBuffer buffer = context.getTags().asReadOnlyByteBuffer(); - int numTags = VarInt.getVarInt(buffer); - HashMap tags = new HashMap(numTags); - for (int i = 0; i < numTags; i++) { - String key = decode(buffer); - String val = decode(buffer); - tags.put(key, val); - } - return new StatsContextImpl(tags); - } catch (BufferUnderflowException exn) { - throw new IOException(exn); - } - } - - private static final void encode(String input, ByteBuffer buffer) { - VarInt.putVarInt(input.length(), buffer); - for (int i = 0; i < input.length(); i++) { - buffer.put((byte) input.charAt(i)); - } - } - - private static final String decode(ByteBuffer buffer) { - int length = VarInt.getVarInt(buffer); - StringBuilder builder = new StringBuilder(); - for (int i = 0; i < length; i++) { - builder.append((char) buffer.get()); - } - return builder.toString(); - } -} diff --git a/core_impl/pom.xml b/core_impl/pom.xml index 76071b8d..9c66396e 100644 --- a/core_impl/pom.xml +++ b/core_impl/pom.xml @@ -38,7 +38,6 @@ - java maven-compiler-plugin diff --git a/core_impl/src/main/java/com/google/instrumentation/stats/StatsContextFactoryImpl.java b/core_impl/src/main/java/com/google/instrumentation/stats/StatsContextFactoryImpl.java new file mode 100644 index 00000000..f888b997 --- /dev/null +++ b/core_impl/src/main/java/com/google/instrumentation/stats/StatsContextFactoryImpl.java @@ -0,0 +1,42 @@ +/* + * Copyright 2016, Google Inc. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0 + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.instrumentation.stats; + +import java.io.InputStream; +import java.io.IOException; +import java.util.HashMap; + +/** + * Native Implementation of {@link StatsContextFactory}. + */ +public final class StatsContextFactoryImpl extends StatsContextFactory { + static final StatsContextImpl DEFAULT = new StatsContextImpl(new HashMap(0)); + + public StatsContextFactoryImpl() {} + + /** + * Deserializes a {@link StatsContextImpl} from a serialized {@code CensusContextProto}. + * + *

The encoded tags are of the form: {@code + 'key' + + 'value'}* + */ + @Override + public StatsContextImpl deserialize(InputStream input) throws IOException { + return StatsSerializer.deserialize(input); + } + + @Override + public StatsContext getDefault() { + return DEFAULT; + } +} diff --git a/core_impl/src/main/java/com/google/instrumentation/stats/StatsContextImpl.java b/core_impl/src/main/java/com/google/instrumentation/stats/StatsContextImpl.java new file mode 100644 index 00000000..af7d94fc --- /dev/null +++ b/core_impl/src/main/java/com/google/instrumentation/stats/StatsContextImpl.java @@ -0,0 +1,83 @@ +/* + * Copyright 2016, Google Inc. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0 + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.instrumentation.stats; + +import java.io.IOException; +import java.io.OutputStream; +import java.util.HashMap; + +/** + * Native Implementation of {@link StatsContext}. + */ +final class StatsContextImpl extends StatsContext { + final HashMap tags; + + StatsContextImpl(HashMap tags) { + this.tags = tags; + } + + @Override + public Builder builder() { + return new Builder(tags); + } + + @Override + public StatsContextImpl record(MeasurementMap stats) { + return this; + } + + /** + * Serializes a {@link StatsContextImpl} into {@code CensusContextProto} serialized format. + * + *

The encoded tags are of the form: {@code + 'key' + + 'value'}* + */ + @Override + public void serialize(OutputStream output) throws IOException { + StatsSerializer.serialize(this, output); + } + + @Override + public boolean equals(Object obj) { + return (obj instanceof StatsContextImpl) && tags.equals(((StatsContextImpl) obj).tags); + } + + @Override + public int hashCode() { + return tags.hashCode(); + } + + @Override + public String toString() { + return tags.toString(); + } + + private static final class Builder extends StatsContext.Builder { + private final HashMap tags; + + private Builder(HashMap tags) { + this.tags = new HashMap(tags); + } + + @Override + public Builder set(TagKey key, TagValue value) { + tags.put(key.toString(), value.toString()); + return this; + } + + @Override + public StatsContext build() { + return new StatsContextImpl(new HashMap(tags)); + } + } +} diff --git a/core_impl/src/main/java/com/google/instrumentation/stats/StatsCurrentContext.java b/core_impl/src/main/java/com/google/instrumentation/stats/StatsCurrentContext.java new file mode 100644 index 00000000..53b138b2 --- /dev/null +++ b/core_impl/src/main/java/com/google/instrumentation/stats/StatsCurrentContext.java @@ -0,0 +1,34 @@ +/* + * Copyright 2016, Google Inc. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0 + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.instrumentation.stats; + +/** + * Native implementation of thread-local {@link StatsContext}. + */ +class StatsCurrentContext { + static final ThreadLocal contexts = new ThreadLocal() { + @Override + protected StatsContextImpl initialValue() { + return StatsContextFactoryImpl.DEFAULT; + } + }; + + public static void set(StatsContextImpl context) { + contexts.set(context); + } + + public static StatsContextImpl get() { + return contexts.get(); + } +} diff --git a/core_impl/src/main/java/com/google/instrumentation/stats/StatsSerializer.java b/core_impl/src/main/java/com/google/instrumentation/stats/StatsSerializer.java new file mode 100644 index 00000000..62c4ca66 --- /dev/null +++ b/core_impl/src/main/java/com/google/instrumentation/stats/StatsSerializer.java @@ -0,0 +1,84 @@ +/* + * Copyright 2016, Google Inc. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0 + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.instrumentation.stats; + +import com.google.instrumentation.stats.proto.StatsContextProto; +import com.google.io.base.VarInt; +import com.google.protobuf.ByteString; + +import java.io.InputStream; +import java.io.IOException; +import java.io.OutputStream; +import java.nio.BufferUnderflowException; +import java.nio.ByteBuffer; +import java.util.HashMap; +import java.util.Map.Entry; +import java.util.Set; + +/** + * Native implementation {@link StatsContext} serialization. + */ +final class StatsSerializer { + // Serializes a StatsContext by transforming it into a StatsContextProto. The + // encoded tags are of the form: + // num_tags [key_len key_bytes value_len value_bytes]* + static void serialize(StatsContextImpl context, OutputStream output) throws IOException { + ByteBuffer buffer = ByteBuffer.allocate(1024); + Set> tags = context.tags.entrySet(); + VarInt.putVarInt(tags.size(), buffer); + for (Entry tag : tags) { + encode(tag.getKey(), buffer); + encode(tag.getValue(), buffer); + } + int length = buffer.capacity() - buffer.remaining(); + buffer.rewind(); + ByteString encodedTags = ByteString.copyFrom(buffer, length); + StatsContextProto.StatsContext.newBuilder().setTags(encodedTags).build().writeTo(output); + } + + // Deserializes based on an serialized StatsContextProto. The encoded tags are of the form: + // num_tags [key_len key_bytes value_len value_bytes]* + static StatsContextImpl deserialize(InputStream input) throws IOException { + try { + StatsContextProto.StatsContext context = StatsContextProto.StatsContext.parseFrom(input); + ByteBuffer buffer = context.getTags().asReadOnlyByteBuffer(); + int numTags = VarInt.getVarInt(buffer); + HashMap tags = new HashMap(numTags); + for (int i = 0; i < numTags; i++) { + String key = decode(buffer); + String val = decode(buffer); + tags.put(key, val); + } + return new StatsContextImpl(tags); + } catch (BufferUnderflowException exn) { + throw new IOException(exn); + } + } + + private static final void encode(String input, ByteBuffer buffer) { + VarInt.putVarInt(input.length(), buffer); + for (int i = 0; i < input.length(); i++) { + buffer.put((byte) input.charAt(i)); + } + } + + private static final String decode(ByteBuffer buffer) { + int length = VarInt.getVarInt(buffer); + StringBuilder builder = new StringBuilder(); + for (int i = 0; i < length; i++) { + builder.append((char) buffer.get()); + } + return builder.toString(); + } +} -- cgit v1.2.3