sarankk commented on code in PR #102:
URL: https://github.com/apache/cassandra-sidecar/pull/102#discussion_r1534287032


##########
src/main/java/org/apache/cassandra/sidecar/metrics/NamedMetric.java:
##########
@@ -0,0 +1,171 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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 org.apache.cassandra.sidecar.metrics;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Objects;
+import java.util.function.Function;
+import java.util.stream.Collectors;
+
+import com.codahale.metrics.Metric;
+import org.apache.cassandra.sidecar.common.DataObjectBuilder;
+
+/**
+ * {@link NamedMetric} is for creating {@link Metric} with a structured name. 
Metric name should contain domain it
+ * is captured for and optional tags for additional context.
+ *
+ * @param <T>   {@link NamedMetric} can be created for any {@link Metric} 
type. T represents the Metric type
+ *              {@link NamedMetric} represents
+ */
+public class NamedMetric<T extends Metric>
+{
+    public final String canonicalName;
+    public final T metric;
+
+    private NamedMetric(Builder<T> builder)
+    {
+        this.canonicalName = builder.makeFullName();
+        this.metric = builder.register(canonicalName);
+    }
+
+    public static <T extends Metric> Builder<T> builder(Function<String, T> 
metricCreator)
+    {
+        return new Builder<>(metricCreator);
+    }
+
+    /**
+     * {@link NamedMetric} builder static inner class.
+     *
+     * @param <T>    {@link NamedMetric} can be created for any {@link Metric} 
type. T represents the Metric type
+     *               {@link NamedMetric} represents
+     */
+    public static class Builder<T extends Metric> implements 
DataObjectBuilder<Builder<T>, NamedMetric<T>>
+    {
+        private final Function<String, T> metricCreator;
+        private final List<Tag> tags = new ArrayList<>();
+        private String domain;
+        private String name;
+
+        public Builder(Function<String, T> metricCreator)
+        {
+            this.metricCreator = metricCreator;
+        }
+
+        /**
+         * Sets {@code domain} of metric and returns a reference to this 
builder to enable method chaining.
+         *
+         * @param domain domain metric is part of
+         * @return a reference to this Builder
+         */

Review Comment:
   Yes, makes sense. I added it to be consistent in doc style



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to