SzyWilliam commented on code in PR #997:
URL: https://github.com/apache/ratis/pull/997#discussion_r1437954323


##########
ratis-common/src/main/java/org/apache/ratis/util/BatchLogger.java:
##########
@@ -0,0 +1,122 @@
+/*
+ * 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.ratis.util;
+
+import org.slf4j.Logger;
+
+import java.util.Objects;
+import java.util.Optional;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ConcurrentMap;
+import java.util.function.Consumer;
+
+/** For batching excessive log messages. */
+public final class BatchLogger {
+
+  private BatchLogger() {
+  }
+
+  public static final class UniqueId {
+    private final StackTraceElement traceElement;
+    private final String name;
+
+    private UniqueId(StackTraceElement traceElement, String name) {
+      this.traceElement = traceElement;
+      this.name = name;
+    }
+
+    @Override
+    public boolean equals(Object obj) {
+      if (obj == this) {
+        return true;
+      } else if (!(obj instanceof UniqueId)) {
+        return false;
+      }
+
+      final UniqueId that = (UniqueId) obj;
+      return Objects.equals(this.traceElement, that.traceElement)
+          && Objects.equals(this.name, that.name);
+    }
+
+    @Override
+    public int hashCode() {
+      return traceElement.hashCode() ^ name.hashCode();
+    }
+  }
+
+  public static UniqueId makeUniqueId(String name) {
+    return new UniqueId(JavaUtils.getCallerStackTraceElement(), name);
+  }
+
+  private static final class BatchedLogEntry {
+    private final Consumer<String> log;
+    private final Runnable logOp;
+    private Timestamp startTime = null;
+    private int count = 0;
+
+    private BatchedLogEntry(Consumer<String> log, Runnable logOp) {
+      this.log = log;
+      this.logOp = logOp;
+    }

Review Comment:
   Done



-- 
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]

Reply via email to