You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ignite.apache.org by sb...@apache.org on 2015/09/03 13:13:43 UTC
[22/30] ignite git commit: IGNITE-1362: Fixed IgniteKernal instance
leak to update notifier.
IGNITE-1362: Fixed IgniteKernal instance leak to update notifier.
Project: http://git-wip-us.apache.org/repos/asf/ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/0b9d7cab
Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/0b9d7cab
Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/0b9d7cab
Branch: refs/heads/ignite-1353
Commit: 0b9d7cab98dddeabdc05e4981457a960c332b26d
Parents: 3a280a0
Author: vozerov-gridgain <vo...@gridgain.com>
Authored: Thu Sep 3 11:25:00 2015 +0300
Committer: vozerov-gridgain <vo...@gridgain.com>
Committed: Thu Sep 3 11:25:00 2015 +0300
----------------------------------------------------------------------
.../apache/ignite/internal/IgniteKernal.java | 97 ++++++++++++++------
1 file changed, 69 insertions(+), 28 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/ignite/blob/0b9d7cab/modules/core/src/main/java/org/apache/ignite/internal/IgniteKernal.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/IgniteKernal.java b/modules/core/src/main/java/org/apache/ignite/internal/IgniteKernal.java
index d9fef86..9a724df 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/IgniteKernal.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/IgniteKernal.java
@@ -28,6 +28,7 @@ import java.io.ObjectStreamException;
import java.io.Serializable;
import java.lang.management.ManagementFactory;
import java.lang.management.RuntimeMXBean;
+import java.lang.ref.WeakReference;
import java.lang.reflect.Constructor;
import java.text.DateFormat;
import java.text.DecimalFormat;
@@ -820,34 +821,8 @@ public class IgniteKernal implements IgniteEx, IgniteMXBean, Externalizable {
updateNtfTimer = new Timer("ignite-update-notifier-timer", true);
// Setup periodic version check.
- updateNtfTimer.scheduleAtFixedRate(new GridTimerTask() {
- private boolean first = true;
-
- @Override public void safeRun() throws InterruptedException {
- if (!first)
- verChecker.topologySize(cluster().nodes().size());
-
- verChecker.checkForNewVersion(execSvc, log);
-
- // Just wait for 10 secs.
- Thread.sleep(PERIODIC_VER_CHECK_CONN_TIMEOUT);
-
- // Just wait another 60 secs in order to get
- // version info even on slow connection.
- for (int i = 0; i < 60 && verChecker.latestVersion() == null; i++)
- Thread.sleep(1000);
-
- // Report status if one is available.
- // No-op if status is NOT available.
- verChecker.reportStatus(log);
-
- if (first) {
- first = false;
-
- verChecker.reportOnlyNew(true);
- }
- }
- }, 0, PERIODIC_VER_CHECK_DELAY);
+ updateNtfTimer.scheduleAtFixedRate(new UpdateNotifierTimerTask(this, verChecker),
+ 0, PERIODIC_VER_CHECK_DELAY);
}
catch (IgniteCheckedException e) {
if (log.isDebugEnabled())
@@ -3194,4 +3169,70 @@ public class IgniteKernal implements IgniteEx, IgniteMXBean, Externalizable {
@Override public String toString() {
return S.toString(IgniteKernal.class, this);
}
+
+ /**
+ * Update notifier timer task.
+ */
+ private static class UpdateNotifierTimerTask extends GridTimerTask {
+ /** Reference to kernal. */
+ private final WeakReference<IgniteKernal> kernalRef;
+
+ /** Logger. */
+ private final IgniteLogger log;
+
+ /** Executor service. */
+ private final ExecutorService execSvc;
+
+ /** Version checker. */
+ private final GridUpdateNotifier verChecker;
+
+ /** Whether this is the first run. */
+ private boolean first = true;
+
+ /**
+ * Constructor.
+ *
+ * @param kernal Kernal.
+ * @param verChecker Version checker.
+ */
+ private UpdateNotifierTimerTask(IgniteKernal kernal, GridUpdateNotifier verChecker) {
+ kernalRef = new WeakReference<>(kernal);
+
+ log = kernal.log.getLogger(UpdateNotifierTimerTask.class);
+
+ execSvc = kernal.executorService();
+
+ this.verChecker = verChecker;
+ }
+
+ /** {@inheritDoc} */
+ @Override public void safeRun() throws InterruptedException {
+ if (!first) {
+ IgniteKernal kernal = kernalRef.get();
+
+ if (kernal != null)
+ verChecker.topologySize(kernal.cluster().nodes().size());
+ }
+
+ verChecker.checkForNewVersion(execSvc, log);
+
+ // Just wait for 10 secs.
+ Thread.sleep(PERIODIC_VER_CHECK_CONN_TIMEOUT);
+
+ // Just wait another 60 secs in order to get
+ // version info even on slow connection.
+ for (int i = 0; i < 60 && verChecker.latestVersion() == null; i++)
+ Thread.sleep(1000);
+
+ // Report status if one is available.
+ // No-op if status is NOT available.
+ verChecker.reportStatus(log);
+
+ if (first) {
+ first = false;
+
+ verChecker.reportOnlyNew(true);
+ }
+ }
+ }
}