ignite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sboi...@apache.org
Subject [1/8] incubator-ignite git commit: Ignite - Moved changes (GG-9591)
Date Fri, 26 Dec 2014 09:14:15 GMT
Repository: incubator-ignite
Updated Branches:
  refs/heads/ignite-44 bcb30d104 -> 090bf073f


Ignite - Moved changes (GG-9591)


Project: http://git-wip-us.apache.org/repos/asf/incubator-ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-ignite/commit/a6fad326
Tree: http://git-wip-us.apache.org/repos/asf/incubator-ignite/tree/a6fad326
Diff: http://git-wip-us.apache.org/repos/asf/incubator-ignite/diff/a6fad326

Branch: refs/heads/ignite-44
Commit: a6fad3261625aea1689818250f6e362e79b70ffb
Parents: 3f25425
Author: nikolay_tikhonov <ntikhonov@gridgain.com>
Authored: Tue Dec 23 12:38:50 2014 +0300
Committer: nikolay_tikhonov <ntikhonov@gridgain.com>
Committed: Tue Dec 23 12:42:45 2014 +0300

----------------------------------------------------------------------
 .../org/gridgain/grid/kernal/GridKernal.java    |  4 +
 .../java/org/gridgain/grid/util/GridUtils.java  | 87 ++++++++++++++------
 .../gridgain/grid/util/GridTestClockTimer.java  | 31 +++++++
 .../testframework/junits/GridAbstractTest.java  |  8 ++
 4 files changed, 105 insertions(+), 25 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/a6fad326/modules/core/src/main/java/org/gridgain/grid/kernal/GridKernal.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/gridgain/grid/kernal/GridKernal.java b/modules/core/src/main/java/org/gridgain/grid/kernal/GridKernal.java
index 99821ca..5359353 100644
--- a/modules/core/src/main/java/org/gridgain/grid/kernal/GridKernal.java
+++ b/modules/core/src/main/java/org/gridgain/grid/kernal/GridKernal.java
@@ -655,6 +655,8 @@ public class GridKernal extends ClusterGroupAdapter implements GridEx,
IgniteMBe
 
             nodeLoc = new ClusterNodeLocalMapImpl(ctx);
 
+            U.onGridStart();
+
             // Set context into rich adapter.
             setKernalContext(ctx);
 
@@ -2096,6 +2098,8 @@ public class GridKernal extends ClusterGroupAdapter implements GridEx,
IgniteMBe
                     }
                 }
             }
+
+            U.onGridStop();
         }
         else {
             // Proper notification.

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/a6fad326/modules/core/src/main/java/org/gridgain/grid/util/GridUtils.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/gridgain/grid/util/GridUtils.java b/modules/core/src/main/java/org/gridgain/grid/util/GridUtils.java
index fb7955d..b687a31 100644
--- a/modules/core/src/main/java/org/gridgain/grid/util/GridUtils.java
+++ b/modules/core/src/main/java/org/gridgain/grid/util/GridUtils.java
@@ -255,7 +255,7 @@ public abstract class GridUtils {
     private static InetAddress locHost;
 
     /** */
-    private static volatile long curTimeMillis = System.currentTimeMillis();
+    static volatile long curTimeMillis = System.currentTimeMillis();
 
     /** Primitive class map. */
     private static final Map<String, Class<?>> primitiveMap = new HashMap<>(16,
.5f);
@@ -284,6 +284,15 @@ public abstract class GridUtils {
     /** GridGain Work Directory. */
     public static final String GRIDGAIN_WORK_DIR = System.getenv(GG_WORK_DIR);
 
+    /** Clock timer. */
+    private static Thread timer;
+
+    /** Grid counter. */
+    private static int gridCnt;
+
+    /** Mutex. */
+    private static final Object mux = new Object();
+
     /**
      * Initializes enterprise check.
      */
@@ -498,30 +507,6 @@ public abstract class GridUtils {
             }
         }
 
-        Thread timer = new Thread(new Runnable() {
-            @SuppressWarnings({"BusyWait", "InfiniteLoopStatement"})
-            @Override public void run() {
-                while (true) {
-                    curTimeMillis = System.currentTimeMillis();
-
-                    try {
-                        Thread.sleep(10);
-                    }
-                    catch (InterruptedException ignored) {
-                        U.log(null, "Timer thread has been interrupted.");
-
-                        break;
-                    }
-                }
-            }
-        }, "gridgain-clock");
-
-        timer.setDaemon(true);
-
-        timer.setPriority(10);
-
-        timer.start();
-
         PORTABLE_CLS.add(Byte.class);
         PORTABLE_CLS.add(Short.class);
         PORTABLE_CLS.add(Integer.class);
@@ -2046,6 +2031,58 @@ public abstract class GridUtils {
     }
 
     /**
+     * Starts clock timer if grid is first.
+     */
+    public static void onGridStart() {
+        synchronized (mux) {
+            if (gridCnt == 0) {
+                timer = new Thread(new Runnable() {
+                    @SuppressWarnings({"BusyWait", "InfiniteLoopStatement"})
+                    @Override public void run() {
+                        while (true) {
+                            curTimeMillis = System.currentTimeMillis();
+
+                            try {
+                                Thread.sleep(10);
+                            }
+                            catch (InterruptedException ignored) {
+                                U.log(null, "Timer thread has been interrupted.");
+
+                                break;
+                            }
+                        }
+                    }
+                }, "gridgain-clock");
+
+                timer.setDaemon(true);
+
+                timer.setPriority(10);
+
+                timer.start();
+            }
+
+            ++gridCnt;
+        }
+    }
+
+    /**
+     * Stops clock timer if all nodes into JVM were stopped.
+     */
+    public static void onGridStop(){
+        synchronized (mux) {
+            assert gridCnt > 0 : gridCnt;
+
+            --gridCnt;
+
+            if (gridCnt == 0 && timer != null) {
+                timer.interrupt();
+
+                timer = null;
+            }
+        }
+    }
+
+    /**
      * Copies input byte stream to output byte stream.
      *
      * @param in Input byte stream.

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/a6fad326/modules/core/src/test/java/org/gridgain/grid/util/GridTestClockTimer.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/gridgain/grid/util/GridTestClockTimer.java b/modules/core/src/test/java/org/gridgain/grid/util/GridTestClockTimer.java
new file mode 100644
index 0000000..9cbe308
--- /dev/null
+++ b/modules/core/src/test/java/org/gridgain/grid/util/GridTestClockTimer.java
@@ -0,0 +1,31 @@
+/* @java.file.header */
+
+/*  _________        _____ __________________        _____
+ *  __  ____/___________(_)______  /__  ____/______ ____(_)_______
+ *  _  / __  __  ___/__  / _  __  / _  / __  _  __ `/__  / __  __ \
+ *  / /_/ /  _  /    _  /  / /_/ /  / /_/ /  / /_/ / _  /  _  / / /
+ *  \____/   /_/     /_/   \_,__/   \____/   \__,_/  /_/   /_/ /_/
+ */
+
+package org.gridgain.grid.util;
+
+/**
+ * Clock timer for tests.
+ */
+public class GridTestClockTimer implements Runnable {
+    /** {@inheritDoc} */
+    @Override public void run() {
+        while (true) {
+            GridUtils.curTimeMillis = System.currentTimeMillis();
+
+            try {
+                Thread.sleep(10);
+            }
+            catch (InterruptedException ignored) {
+                GridUtils.log(null, "Timer thread has been interrupted.");
+
+                break;
+            }
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/a6fad326/modules/core/src/test/java/org/gridgain/testframework/junits/GridAbstractTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/gridgain/testframework/junits/GridAbstractTest.java
b/modules/core/src/test/java/org/gridgain/testframework/junits/GridAbstractTest.java
index 570bc77..922acc4 100644
--- a/modules/core/src/test/java/org/gridgain/testframework/junits/GridAbstractTest.java
+++ b/modules/core/src/test/java/org/gridgain/testframework/junits/GridAbstractTest.java
@@ -88,6 +88,14 @@ public abstract class GridAbstractTest extends TestCase {
 
     static {
         System.setProperty(IgniteSystemProperties.GG_ATOMIC_CACHE_DELETE_HISTORY_SIZE, "10000");
+        
+        Thread timer = new Thread(new GridTestClockTimer(), "gridgain-clock-for-tests");
+
+        timer.setDaemon(true);
+
+        timer.setPriority(10);
+
+        timer.start();
     }
 
     /** */


Mime
View raw message