ignite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From vkuliche...@apache.org
Subject [38/50] [abbrv] ignite git commit: review IGNITE-2708 Need to validate that SPIs are started only once (commit with proper author)
Date Fri, 13 May 2016 19:21:10 GMT
review IGNITE-2708 Need to validate that SPIs are started only once (commit with proper author)


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

Branch: refs/heads/ignite-2949
Commit: 98338ff89525be276a7d651b6d561b8b013f8c3d
Parents: bf561e1
Author: Ryan Zhao <ryan.zhao.cs@gmail.com>
Authored: Fri May 13 15:00:43 2016 +0600
Committer: Yakov Zhdanov <yzhdanov@gridgain.com>
Committed: Fri May 13 15:00:43 2016 +0600

----------------------------------------------------------------------
 .../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/98338ff8/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 d8bd8e83..1a0d60f 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/98338ff8/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 f31aae7..65b0420 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;
@@ -97,11 +97,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
@@ -118,6 +121,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/98338ff8/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 0998025..e1db958 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
@@ -987,6 +987,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