shishkovilja commented on code in PR #12249:
URL: https://github.com/apache/ignite/pull/12249#discussion_r2254394779


##########
modules/commons/src/main/java/org/apache/ignite/internal/util/CommonUtils.java:
##########
@@ -334,4 +351,108 @@ public static int nextPowerOf2(int v) {
 
         return 1 << (32 - Integer.numberOfLeadingZeros(v - 1));
     }
+
+    /**
+     * Starts clock timer if grid is first.
+     */
+    public static void onGridStart() {

Review Comment:
   Method is currently unused and duplicated with corresponding IgniteUtils 
method.



##########
modules/commons/src/main/java/org/apache/ignite/internal/util/CommonUtils.java:
##########
@@ -334,4 +351,108 @@ public static int nextPowerOf2(int v) {
 
         return 1 << (32 - Integer.numberOfLeadingZeros(v - 1));
     }
+
+    /**
+     * Starts clock timer if grid is first.
+     */
+    public static void onGridStart() {
+        synchronized (mux) {
+            if (gridCnt == 0) {
+                assert timer == null;
+
+                timer = new Thread(new Runnable() {
+                    @SuppressWarnings({"BusyWait"})
+                    @Override public void run() {
+                        while (true) {
+                            curTimeMillis = System.currentTimeMillis();
+
+                            try {
+                                Thread.sleep(10);
+                            }
+                            catch (InterruptedException ignored) {
+                                break;
+                            }
+                        }
+                    }
+                }, "ignite-clock");
+
+                timer.setDaemon(true);
+
+                timer.setPriority(10);
+
+                timer.start();
+            }
+
+            ++gridCnt;
+        }
+    }
+
+    /**
+     * Stops clock timer if all nodes into JVM were stopped.
+     * @throws InterruptedException If interrupted.
+     */
+    public static void onGridStop() throws InterruptedException {

Review Comment:
   Method is currently unused and duplicated with corresponding IgniteUtils 
method.



##########
modules/commons/src/main/java/org/apache/ignite/internal/util/CommonUtils.java:
##########
@@ -334,4 +351,108 @@ public static int nextPowerOf2(int v) {
 
         return 1 << (32 - Integer.numberOfLeadingZeros(v - 1));
     }
+
+    /**
+     * Starts clock timer if grid is first.
+     */
+    public static void onGridStart() {
+        synchronized (mux) {
+            if (gridCnt == 0) {
+                assert timer == null;
+
+                timer = new Thread(new Runnable() {
+                    @SuppressWarnings({"BusyWait"})
+                    @Override public void run() {
+                        while (true) {
+                            curTimeMillis = System.currentTimeMillis();
+
+                            try {
+                                Thread.sleep(10);
+                            }
+                            catch (InterruptedException ignored) {
+                                break;
+                            }
+                        }
+                    }
+                }, "ignite-clock");
+
+                timer.setDaemon(true);
+
+                timer.setPriority(10);
+
+                timer.start();
+            }
+
+            ++gridCnt;
+        }
+    }
+
+    /**
+     * Stops clock timer if all nodes into JVM were stopped.
+     * @throws InterruptedException If interrupted.
+     */
+    public static void onGridStop() throws InterruptedException {
+        synchronized (mux) {
+            // Grid start may fail and onGridStart() does not get called.
+            if (gridCnt == 0)
+                return;
+
+            --gridCnt;
+
+            Thread timer0 = timer;
+
+            if (gridCnt == 0 && timer0 != null) {
+                timer = null;
+
+                timer0.interrupt();
+
+                timer0.join();
+            }
+        }
+    }
+
+    /**
+     * @return System time approximated by 10 ms.
+     */
+    public static long currentTimeMillis() {

Review Comment:
   Method is duplicated by IgniteUtils.



-- 
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: notifications-unsubscr...@ignite.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to