ignite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sboi...@apache.org
Subject [07/17] ignite git commit: review IGNITE-2708 Need to validate that SPIs are started only once (commit with proper author) (cherry picked from commit 98338ff)
Date Wed, 01 Jun 2016 11:27:53 GMT
review IGNITE-2708 Need to validate that SPIs are started only once (commit with proper author)
(cherry picked from commit 98338ff)


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

Branch: refs/heads/ignite-3038
Commit: c5019c661b71665c410dd78a9ef4cb4a39a88ab5
Parents: 9639e79
Author: Ryan Zhao <ryan.zhao.cs@gmail.com>
Authored: Fri May 13 12:00:43 2016 +0300
Committer: Denis Magda <dmagda@gridgain.com>
Committed: Tue May 31 09:29:33 2016 +0300

----------------------------------------------------------------------
 .../internal/managers/GridManagerAdapter.java   |  3 ++
 .../org/apache/ignite/spi/IgniteSpiAdapter.java | 29 ++++++++++++++++++--
 .../ignite/internal/GridFactorySelfTest.java    | 25 +++++++++++++++++
 3 files changed, 54 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/c5019c66/modules/core/src/main/java/org/apache/ignite/internal/managers/GridManagerAdapter.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/managers/GridManagerAdapter.java
b/modules/core/src/main/java/org/apache/ignite/internal/managers/GridManagerAdapter.java
index cb41d4b..58d64f6 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/managers/GridManagerAdapter.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/managers/GridManagerAdapter.java
@@ -209,6 +209,9 @@ public abstract class GridManagerAdapter<T extends IgniteSpi> implements
GridMan
         Collection<String> names = U.newHashSet(spis.length);
 
         for (T spi : spis) {
+            if (spi instanceof IgniteSpiAdapter)
+                ((IgniteSpiAdapter)spi).onBeforeStart();
+
             // Inject all spi resources.
             ctx.resource().inject(spi);
 

http://git-wip-us.apache.org/repos/asf/ignite/blob/c5019c66/modules/core/src/main/java/org/apache/ignite/spi/IgniteSpiAdapter.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/spi/IgniteSpiAdapter.java b/modules/core/src/main/java/org/apache/ignite/spi/IgniteSpiAdapter.java
index 999013f..7cb2e13 100644
--- a/modules/core/src/main/java/org/apache/ignite/spi/IgniteSpiAdapter.java
+++ b/modules/core/src/main/java/org/apache/ignite/spi/IgniteSpiAdapter.java
@@ -25,6 +25,7 @@ import java.util.Date;
 import java.util.List;
 import java.util.Map;
 import java.util.UUID;
+import java.util.concurrent.atomic.AtomicBoolean;
 import javax.management.JMException;
 import javax.management.MBeanServer;
 import javax.management.ObjectName;
@@ -39,7 +40,6 @@ import org.apache.ignite.internal.IgniteKernal;
 import org.apache.ignite.internal.IgniteNodeAttributes;
 import org.apache.ignite.internal.managers.communication.GridMessageListener;
 import org.apache.ignite.internal.managers.eventstorage.GridLocalEventListener;
-import org.apache.ignite.internal.processors.cache.GridCacheUtils;
 import org.apache.ignite.internal.processors.timeout.GridSpiTimeoutObject;
 import org.apache.ignite.internal.util.IgniteExceptionRegistry;
 import org.apache.ignite.internal.util.typedef.F;
@@ -96,11 +96,14 @@ public abstract class IgniteSpiAdapter implements IgniteSpi, IgniteSpiManagement
     private boolean failureDetectionTimeoutEnabled = true;
 
     /**
-     *  Failure detection timeout. Initialized with the value of
-     *  {@link IgniteConfiguration#getFailureDetectionTimeout()}.
+     * Failure detection timeout. Initialized with the value of
+     * {@link IgniteConfiguration#getFailureDetectionTimeout()}.
      */
     private long failureDetectionTimeout;
 
+    /** Start flag to deny repeating start attempts. */
+    private final AtomicBoolean startedFlag = new AtomicBoolean();
+
     /**
      * Creates new adapter and initializes it from the current (this) class.
      * SPI name will be initialized to the simple name of the class
@@ -117,6 +120,26 @@ public abstract class IgniteSpiAdapter implements IgniteSpi, IgniteSpiManagement
         startTstamp = U.currentTimeMillis();
     }
 
+    /**
+     * This method is called by built-in managers implementation to avoid
+     * repeating SPI start attempts.
+     */
+    public final void onBeforeStart() {
+        if (!startedFlag.compareAndSet(false, true))
+            throw new IllegalStateException("SPI has already been started " +
+                "(always create new configuration instance for each starting Ignite instances)
" +
+                "[spi=" + this + ']');
+    }
+
+    /**
+     * Checks if {@link #onBeforeStart()} has been called on this SPI instance.
+     *
+     * @return {@code True} if {@link #onBeforeStart()} has already been called.
+     */
+    public final boolean started() {
+        return startedFlag.get();
+    }
+
     /** {@inheritDoc} */
     @Override public final String getStartTimestampFormatted() {
         return DateFormat.getDateTimeInstance().format(new Date(startTstamp));

http://git-wip-us.apache.org/repos/asf/ignite/blob/c5019c66/modules/spring/src/test/java/org/apache/ignite/internal/GridFactorySelfTest.java
----------------------------------------------------------------------
diff --git a/modules/spring/src/test/java/org/apache/ignite/internal/GridFactorySelfTest.java
b/modules/spring/src/test/java/org/apache/ignite/internal/GridFactorySelfTest.java
index 539067b..b94ed48 100644
--- a/modules/spring/src/test/java/org/apache/ignite/internal/GridFactorySelfTest.java
+++ b/modules/spring/src/test/java/org/apache/ignite/internal/GridFactorySelfTest.java
@@ -902,6 +902,31 @@ public class GridFactorySelfTest extends GridCommonAbstractTest {
     }
 
     /**
+     * @throws Exception If failed.
+     */
+    public void testRepeatingStart() throws Exception {
+        try {
+            IgniteConfiguration c = getConfiguration("1");
+
+            startGrid("1", c);
+
+            assert ((TcpDiscoverySpi)c.getDiscoverySpi()).started();
+
+            try {
+                startGrid("2", c);
+
+                fail("Should not be able to start grid using same configuration instance.");
+            }
+            catch (Exception e) {
+                info("Caught expected exception: " + e);
+            }
+        }
+        finally {
+            stopAllGrids();
+        }
+    }
+
+    /**
      * Test task.
      */
     private static class TestTask extends ComputeTaskSplitAdapter<Void, Void> {


Mime
View raw message