From bc143adc32e6db5e158485246d8d3aa6592b1cff Mon Sep 17 00:00:00 2001 From: rghetia Date: Thu, 21 Jun 2018 22:01:16 -0700 Subject: Summary Span: Add encoder/decoder for Server Stats. (#1272) * Summary Span: Add encoder/decoder for Server Stats. * Fixed build errors reported by Kokoro/Travis. * Fixed review comments. - Added missing javadoc annotation. - included version in encoder/decoder. - renamed get methods for ServerStats. * Change version from 0.15 to 0.16 - also fixed CURRENT_VERSION for encoder/decoder and added test for it. * Make ServerStatsEncoding public. * Add Test ServerStatsFieldEnum.Size replace traceOption() wiht getTraceOption() --- .../opencensus/common/ServerStatsFieldEnums.java | 157 +++++++++++++++++++++ 1 file changed, 157 insertions(+) create mode 100644 api/src/main/java/io/opencensus/common/ServerStatsFieldEnums.java (limited to 'api/src/main/java/io/opencensus/common/ServerStatsFieldEnums.java') diff --git a/api/src/main/java/io/opencensus/common/ServerStatsFieldEnums.java b/api/src/main/java/io/opencensus/common/ServerStatsFieldEnums.java new file mode 100644 index 00000000..92194d96 --- /dev/null +++ b/api/src/main/java/io/opencensus/common/ServerStatsFieldEnums.java @@ -0,0 +1,157 @@ +/* + * Copyright 2018, OpenCensus Authors + * + * 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 io.opencensus.common; + +import java.util.TreeMap; + +/** + * A Enum representation for Ids and Size for attributes of {@code ServerStats}. + * + *

See opencensus-server-stats-specs + * for the field ids and their length defined for Server Stats + * + * @since 0.16 + */ +public final class ServerStatsFieldEnums { + + /** + * Available Ids for {@code ServerStats} attributes. + * + * @since 0.16 + */ + public enum Id { + /** + * Id for Latency observed at Load Balancer. + * + * @since 0.16 + */ + SERVER_STATS_LB_LATENCY_ID(0), + /** + * Id for Latency observed at Server. + * + * @since 0.16 + */ + SERVER_STATS_SERVICE_LATENCY_ID(1), + /** + * Id for Trace options. + * + * @since 0.16 + */ + SERVER_STATS_TRACE_OPTION_ID(2); + + private final int value; + + private Id(int value) { + this.value = value; + } + + /** + * Returns the numerical value of the {@link Id}. + * + * @return the numerical value of the {@code Id}. + * @since 0.16 + */ + public int value() { + return value; + } + + private static final TreeMap map = new TreeMap(); + + static { + for (Id id : Id.values()) { + map.put(id.value, id); + } + } + + /** + * Returns the {@link Id} representing the value value of the id. + * + * @param value integer value for which {@code Id} is being requested. + * @return the numerical value of the id. null if the id is not valid + * @since 0.16 + */ + public static Id valueOf(int value) { + return (Id) map.get(value); + } + } + + /** + * Size for each attributes in {@code ServerStats}. + * + * @since 0.16 + */ + public enum Size { + /** + * Number of bytes used to represent latency observed at Load Balancer + * + * @since 0.16 + */ + SERVER_STATS_LB_LATENCY_SIZE(8), + /** + * Number of bytes used to represent latency observed at Server + * + * @since 0.16 + */ + SERVER_STATS_SERVICE_LATENCY_SIZE(8), + /** + * Number of bytes used to represent Trace option + * + * @since 0.16 + */ + SERVER_STATS_TRACE_OPTION_SIZE(1); + + private final int value; + + private Size(int value) { + this.value = value; + } + + /** + * Returns the numerical value of the {@link Size}. + * + * @return the numerical value of the {@code Size}. + * @since 0.16 + */ + public int value() { + return value; + } + } + + private static final int TOTALSIZE = computeTotalSize(); + + private ServerStatsFieldEnums() {} + + private static int computeTotalSize() { + int sum = 0; + for (Size sizeValue : Size.values()) { + sum += sizeValue.value(); + sum += 1; // For Id + } + return sum; + } + + /** + * Returns the total size required to encode the {@code ServerStats} + * + * @return the total size required to encode all fields in {@code ServerStats}. + * @since 0.16 + */ + public static int getTotalSize() { + return TOTALSIZE; + } +} -- cgit v1.2.3 From 8939d9fd639a8a7ff8b25e1a7e6c44d8b2e987db Mon Sep 17 00:00:00 2001 From: sebright Date: Wed, 1 Aug 2018 16:34:05 -0700 Subject: Fix incorrect argument to Checker Framework, and fix nullness warnings. (#1354) 709d97aa321d5729988fd63b960bbece04cfba10 modified the -AskipDefs argument to the Checker Framework (a regular expression) in a way that caused it to skip checking all files. This commit fixes the regular expression and the new Checker Framework warnings. --- api/src/main/java/io/opencensus/common/ServerStatsFieldEnums.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'api/src/main/java/io/opencensus/common/ServerStatsFieldEnums.java') diff --git a/api/src/main/java/io/opencensus/common/ServerStatsFieldEnums.java b/api/src/main/java/io/opencensus/common/ServerStatsFieldEnums.java index 92194d96..79cb196e 100644 --- a/api/src/main/java/io/opencensus/common/ServerStatsFieldEnums.java +++ b/api/src/main/java/io/opencensus/common/ServerStatsFieldEnums.java @@ -17,6 +17,7 @@ package io.opencensus.common; import java.util.TreeMap; +import javax.annotation.Nullable; /** * A Enum representation for Ids and Size for attributes of {@code ServerStats}. @@ -85,8 +86,9 @@ public final class ServerStatsFieldEnums { * @return the numerical value of the id. null if the id is not valid * @since 0.16 */ + @Nullable public static Id valueOf(int value) { - return (Id) map.get(value); + return map.get(value); } } -- cgit v1.2.3 From 0a2f5799a2809b84e4c0da4b2cb743b798ca0fc8 Mon Sep 17 00:00:00 2001 From: sebright Date: Thu, 16 Aug 2018 15:04:02 -0700 Subject: checkstyle: 8.0 -> 8.12 (#1369) This commit also merges new changes to checkstyle.xml and fixes new checkstyle warnings related to Javadocs. --- api/src/main/java/io/opencensus/common/ServerStatsFieldEnums.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'api/src/main/java/io/opencensus/common/ServerStatsFieldEnums.java') diff --git a/api/src/main/java/io/opencensus/common/ServerStatsFieldEnums.java b/api/src/main/java/io/opencensus/common/ServerStatsFieldEnums.java index 79cb196e..ff3cfda9 100644 --- a/api/src/main/java/io/opencensus/common/ServerStatsFieldEnums.java +++ b/api/src/main/java/io/opencensus/common/ServerStatsFieldEnums.java @@ -99,19 +99,19 @@ public final class ServerStatsFieldEnums { */ public enum Size { /** - * Number of bytes used to represent latency observed at Load Balancer + * Number of bytes used to represent latency observed at Load Balancer. * * @since 0.16 */ SERVER_STATS_LB_LATENCY_SIZE(8), /** - * Number of bytes used to represent latency observed at Server + * Number of bytes used to represent latency observed at Server. * * @since 0.16 */ SERVER_STATS_SERVICE_LATENCY_SIZE(8), /** - * Number of bytes used to represent Trace option + * Number of bytes used to represent Trace option. * * @since 0.16 */ @@ -148,7 +148,7 @@ public final class ServerStatsFieldEnums { } /** - * Returns the total size required to encode the {@code ServerStats} + * Returns the total size required to encode the {@code ServerStats}. * * @return the total size required to encode all fields in {@code ServerStats}. * @since 0.16 -- cgit v1.2.3