DomGarguilo commented on code in PR #4784:
URL: https://github.com/apache/accumulo/pull/4784#discussion_r1701920499


##########
core/src/main/java/org/apache/accumulo/core/util/Timer.java:
##########
@@ -0,0 +1,112 @@
+/*
+ * 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
+ *
+ *   https://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.accumulo.core.util;
+
+import java.time.Duration;
+
+/**
+ * This class provides a timer for measuring elapsed time.
+ */
+public final class Timer {
+
+  private long startNanos;
+  private long accumulatedNanos;
+  private boolean isStarted;
+
+  private Timer() {
+    this.accumulatedNanos = 0;
+    this.isStarted = false;
+  }
+
+  /**
+   * Creates and starts a new Timer instance.
+   *
+   * @return a new Timer instance that is already started.
+   */
+  public static Timer startNew() {
+    Timer timer = new Timer();
+    timer.start();
+    return timer;
+  }
+
+  /**
+   * Starts the timer if it is not already running.
+   *
+   * @throws IllegalStateException if the timer is already running.
+   */
+  public void start() throws IllegalStateException {
+    if (isStarted) {
+      throw new IllegalStateException("Timer is already running");
+    }
+    startNanos = System.nanoTime();
+    isStarted = true;
+  }
+
+  /**
+   * Stops the timer if it is running and accumulates the elapsed time.
+   *
+   * @throws IllegalStateException if the timer is not running.
+   */
+  public void stop() throws IllegalStateException {

Review Comment:
   I had the same idea but then thought it could be helpful in a situation 
where we want to start and stop a single timer multiple times to measure 
different parts of a process.
   
   I guess this isn't being done (with this object) at the moment so it might 
not be a case that we would use very often. We could also just use multiple 
`Timer`s in this case or some other pattern to measure time.
   
   So I am fine with dropping it if you think its a good idea.



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