ignite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sboi...@apache.org
Subject [30/48] incubator-ignite git commit: # IGNITE-187 Reworked kernal start to use @SkipDaemon annotation.
Date Thu, 05 Mar 2015 20:10:45 GMT
# IGNITE-187 Reworked kernal start to use @SkipDaemon annotation.


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

Branch: refs/heads/ignite-release-test-no-mod
Commit: 9dcd5b097aed41812270f12ed19aa88bc0ddb037
Parents: 8987f61
Author: AKuznetsov <akuznetsov@gridgain.com>
Authored: Wed Mar 4 23:21:56 2015 +0700
Committer: AKuznetsov <akuznetsov@gridgain.com>
Committed: Wed Mar 4 23:21:56 2015 +0700

----------------------------------------------------------------------
 .../apache/ignite/internal/IgniteKernal.java    | 25 +++++++++++---
 .../org/apache/ignite/internal/SkipDaemon.java  | 29 +++++++++++++++++
 .../ignite/internal/managers/GridManager.java   | 10 ++++++
 .../internal/managers/GridManagerAdapter.java   | 34 +++++++++-----------
 .../checkpoint/GridCheckpointManager.java       |  7 +---
 .../collision/GridCollisionManager.java         |  7 +---
 .../discovery/GridDiscoveryManager.java         | 11 +++++--
 .../managers/indexing/GridIndexingManager.java  |  7 +---
 .../swapspace/GridSwapSpaceManager.java         |  7 +---
 .../org/apache/ignite/spi/IgniteSpiAdapter.java | 20 ++----------
 .../ignite/spi/IgniteSpiConsistencyChecked.java |  7 ----
 11 files changed, 91 insertions(+), 73 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/9dcd5b09/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 ae481f5..7b289ee 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
@@ -453,8 +453,7 @@ public class IgniteKernal implements IgniteEx, IgniteMXBean, Externalizable
{
         assert cfg != null;
 
         return F.transform(cfg.getUserAttributes().entrySet(), new C1<Map.Entry<String,
?>, String>() {
-            @Override
-            public String apply(Map.Entry<String, ?> e) {
+            @Override public String apply(Map.Entry<String, ?> e) {
                 return e.getKey() + ", " + e.getValue().toString();
             }
         });
@@ -803,7 +802,12 @@ public class IgniteKernal implements IgniteEx, IgniteMXBean, Externalizable
{
                 if (comp instanceof GridIoManager)
                     continue;
 
-                comp.onKernalStart();
+                if (!skipDaemon(comp)) {
+                    if (log.isDebugEnabled())
+                        log.debug("Skipping onKernalStart on daemon node for component: "
+ comp);
+
+                    comp.onKernalStart();
+                }
             }
 
             // Register MBeans.
@@ -1701,7 +1705,12 @@ public class IgniteKernal implements IgniteEx, IgniteMXBean, Externalizable
{
                 GridComponent comp = it.previous();
 
                 try {
-                    comp.onKernalStop(cancel);
+                    if (!skipDaemon(comp)) {
+                        if (log.isDebugEnabled())
+                            log.debug("Skipping onKernalStop on daemon node for component:
" + comp);
+
+                        comp.onKernalStop(cancel);
+                    }
                 }
                 catch (Throwable e) {
                     errOnStop = true;
@@ -2667,6 +2676,14 @@ public class IgniteKernal implements IgniteEx, IgniteMXBean, Externalizable
{
         }
     }
 
+    /**
+     * @param comp Grid component class.
+     * @return {@code true} if node running in daemon mode and component marked by {@code
SkipDaemon} annotation.
+     */
+    private boolean skipDaemon(GridComponent comp) {
+        return ctx.isDaemon() && U.hasAnnotation(comp.getClass(), SkipDaemon.class);
+    }
+
     /** {@inheritDoc} */
     @Override public String toString() {
         return S.toString(IgniteKernal.class, this);

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/9dcd5b09/modules/core/src/main/java/org/apache/ignite/internal/SkipDaemon.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/SkipDaemon.java b/modules/core/src/main/java/org/apache/ignite/internal/SkipDaemon.java
new file mode 100644
index 0000000..5fb2c25
--- /dev/null
+++ b/modules/core/src/main/java/org/apache/ignite/internal/SkipDaemon.java
@@ -0,0 +1,29 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.internal;
+
+import java.lang.annotation.*;
+
+/**
+ * Lifecycle callbacks will not be called for grid components marked with this annotation.
+ */
+@Retention(RetentionPolicy.RUNTIME)
+@Target(ElementType.TYPE)
+public @interface SkipDaemon {
+    // No-op.
+}

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/9dcd5b09/modules/core/src/main/java/org/apache/ignite/internal/managers/GridManager.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/managers/GridManager.java
b/modules/core/src/main/java/org/apache/ignite/internal/managers/GridManager.java
index 236d83b..39f9925 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/managers/GridManager.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/managers/GridManager.java
@@ -31,4 +31,14 @@ public interface GridManager extends GridComponent {
      * @return {@code true} if at least one SPI does not have a {@code NO-OP} implementation,
{@code false} otherwise.
      */
     public boolean enabled();
+
+    /**
+     * This method is called before manager will start SPI.
+     */
+    public void onBeforeSpiStart();
+
+    /**
+     * This method is called after manager started SPI.
+     */
+    public void onAfterSpiStart();
 }

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/9dcd5b09/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 2a0aaec..c47dac04 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
@@ -33,7 +33,6 @@ import org.apache.ignite.lang.*;
 import org.apache.ignite.plugin.extensions.communication.*;
 import org.apache.ignite.plugin.security.*;
 import org.apache.ignite.spi.*;
-import org.apache.ignite.spi.discovery.*;
 import org.apache.ignite.spi.swapspace.*;
 import org.jetbrains.annotations.*;
 
@@ -43,7 +42,6 @@ import java.util.*;
 
 import static java.util.Arrays.*;
 import static java.util.concurrent.TimeUnit.*;
-import static org.apache.ignite.internal.IgniteVersionUtils.*;
 import static org.apache.ignite.internal.managers.communication.GridIoPolicy.*;
 
 /**
@@ -160,19 +158,14 @@ public abstract class GridManagerAdapter<T extends IgniteSpi>
implements GridMan
         }
     }
 
-    /**
-     * Inject resources into wrapped SPI.
-     *
-     * @throws IgniteCheckedException If injection failed.
-     */
-    protected final void injectSpi() throws IgniteCheckedException {
-        for (T spi : spis) {
-            // Inject all spi resources.
-            ctx.resource().inject(spi);
+    /** {@inheritDoc} */
+    @Override public void onBeforeSpiStart() {
+        // No-op.
+    }
 
-            // Inject SPI internal objects.
-            inject(spi);
-        }
+    /** {@inheritDoc} */
+    @Override public void onAfterSpiStart() {
+        // No-op.
     }
 
     /**
@@ -183,9 +176,13 @@ public abstract class GridManagerAdapter<T extends IgniteSpi> implements
GridMan
     protected final void startSpi() throws IgniteCheckedException {
         Collection<String> names = U.newHashSet(spis.length);
 
-        injectSpi();
-
         for (T spi : spis) {
+            // Inject all spi resources.
+            ctx.resource().inject(spi);
+
+            // Inject SPI internal objects.
+            inject(spi);
+
             try {
                 Map<String, Object> retval = spi.getNodeAttributes();
 
@@ -220,8 +217,7 @@ public abstract class GridManagerAdapter<T extends IgniteSpi> implements
GridMan
             if (log.isDebugEnabled())
                 log.debug("Starting SPI implementation: " + spi.getClass().getName());
 
-            if (spi instanceof DiscoverySpi)
-                ((DiscoverySpi)spi).setNodeAttributes(ctx.nodeAttributes(), VER);
+            onBeforeSpiStart();
 
             try {
                 spi.spiStart(ctx.gridName());
@@ -230,6 +226,8 @@ public abstract class GridManagerAdapter<T extends IgniteSpi> implements
GridMan
                 throw new IgniteCheckedException("Failed to start SPI: " + spi, e);
             }
 
+            onAfterSpiStart();
+
             if (log.isDebugEnabled())
                 log.debug("SPI module started OK: " + spi.getClass().getName());
         }

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/9dcd5b09/modules/core/src/main/java/org/apache/ignite/internal/managers/checkpoint/GridCheckpointManager.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/managers/checkpoint/GridCheckpointManager.java
b/modules/core/src/main/java/org/apache/ignite/internal/managers/checkpoint/GridCheckpointManager.java
index bcaa70a..d811a51 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/managers/checkpoint/GridCheckpointManager.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/managers/checkpoint/GridCheckpointManager.java
@@ -46,6 +46,7 @@ import static org.jdk8.backport.ConcurrentLinkedHashMap.QueuePolicy.*;
 /**
  * This class defines a checkpoint manager.
  */
+@SkipDaemon
 @SuppressWarnings({"SynchronizationOnLocalVariableOrMethodParameter", "deprecation"})
 public class GridCheckpointManager extends GridManagerAdapter<CheckpointSpi> {
     /** Max closed topics to store. */
@@ -75,12 +76,6 @@ public class GridCheckpointManager extends GridManagerAdapter<CheckpointSpi>
{
 
     /** {@inheritDoc} */
     @Override public void start() throws IgniteCheckedException {
-        if (ctx.config().isDaemon()) {
-            injectSpi();
-
-            return;
-        }
-
         for (CheckpointSpi spi : getSpis()) {
             spi.setCheckpointListener(new CheckpointListener() {
                 @Override public void onCheckpointRemoved(String key) {

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/9dcd5b09/modules/core/src/main/java/org/apache/ignite/internal/managers/collision/GridCollisionManager.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/managers/collision/GridCollisionManager.java
b/modules/core/src/main/java/org/apache/ignite/internal/managers/collision/GridCollisionManager.java
index e38617a..9eca079 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/managers/collision/GridCollisionManager.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/managers/collision/GridCollisionManager.java
@@ -30,6 +30,7 @@ import java.util.concurrent.atomic.*;
 /**
  * This class defines a collision manager.
  */
+@SkipDaemon
 public class GridCollisionManager extends GridManagerAdapter<CollisionSpi> {
     /** Reference for external listener. */
     private final AtomicReference<CollisionExternalListener> extLsnr =
@@ -44,12 +45,6 @@ public class GridCollisionManager extends GridManagerAdapter<CollisionSpi>
{
 
     /** {@inheritDoc} */
     @Override public void start() throws IgniteCheckedException {
-        if (ctx.config().isDaemon()) {
-            injectSpi();
-
-            return;
-        }
-
         startSpi();
 
         if (enabled()) {

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/9dcd5b09/modules/core/src/main/java/org/apache/ignite/internal/managers/discovery/GridDiscoveryManager.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/managers/discovery/GridDiscoveryManager.java
b/modules/core/src/main/java/org/apache/ignite/internal/managers/discovery/GridDiscoveryManager.java
index e7020c1..775de77 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/managers/discovery/GridDiscoveryManager.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/managers/discovery/GridDiscoveryManager.java
@@ -53,6 +53,7 @@ import java.util.zip.*;
 import static java.util.concurrent.TimeUnit.*;
 import static org.apache.ignite.events.EventType.*;
 import static org.apache.ignite.internal.IgniteNodeAttributes.*;
+import static org.apache.ignite.internal.IgniteVersionUtils.*;
 import static org.apache.ignite.plugin.segmentation.GridSegmentationPolicy.*;
 
 /**
@@ -190,6 +191,13 @@ public class GridDiscoveryManager extends GridManagerAdapter<DiscoverySpi>
{
     }
 
     /** {@inheritDoc} */
+    @Override public void onBeforeSpiStart() {
+        DiscoverySpi spi = getSpi();
+
+        spi.setNodeAttributes(ctx.nodeAttributes(), VER);
+    }
+
+    /** {@inheritDoc} */
     @Override public void start() throws IgniteCheckedException {
         long totSysMemory = -1;
 
@@ -2137,8 +2145,7 @@ public class GridDiscoveryManager extends GridManagerAdapter<DiscoverySpi>
{
          * @param id Node ID.
          * @return Node.
          */
-        @Nullable
-        ClusterNode node(UUID id) {
+        @Nullable ClusterNode node(UUID id) {
             return nodeMap.get(id);
         }
 

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/9dcd5b09/modules/core/src/main/java/org/apache/ignite/internal/managers/indexing/GridIndexingManager.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/managers/indexing/GridIndexingManager.java
b/modules/core/src/main/java/org/apache/ignite/internal/managers/indexing/GridIndexingManager.java
index 5e734a2..5cb150e 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/managers/indexing/GridIndexingManager.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/managers/indexing/GridIndexingManager.java
@@ -30,6 +30,7 @@ import java.util.*;
 /**
  * Manages cache indexing.
  */
+@SkipDaemon
 public class GridIndexingManager extends GridManagerAdapter<IndexingSpi> {
     /** */
     private final GridSpinBusyLock busyLock = new GridSpinBusyLock();
@@ -45,12 +46,6 @@ public class GridIndexingManager extends GridManagerAdapter<IndexingSpi>
{
      * @throws IgniteCheckedException Thrown in case of any errors.
      */
     @Override public void start() throws IgniteCheckedException {
-        if (ctx.config().isDaemon()) {
-            injectSpi();
-
-            return;
-        }
-
         if (!enabled())
             U.warn(log, "Indexing is disabled (to enable please configure GridIndexingSpi).");
 

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/9dcd5b09/modules/core/src/main/java/org/apache/ignite/internal/managers/swapspace/GridSwapSpaceManager.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/managers/swapspace/GridSwapSpaceManager.java
b/modules/core/src/main/java/org/apache/ignite/internal/managers/swapspace/GridSwapSpaceManager.java
index 2b7fbeb..ec50578 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/managers/swapspace/GridSwapSpaceManager.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/managers/swapspace/GridSwapSpaceManager.java
@@ -37,6 +37,7 @@ import static org.apache.ignite.events.EventType.*;
 /**
  *
  */
+@SkipDaemon
 public class GridSwapSpaceManager extends GridManagerAdapter<SwapSpaceSpi> {
     /** */
     private Marshaller marsh;
@@ -50,12 +51,6 @@ public class GridSwapSpaceManager extends GridManagerAdapter<SwapSpaceSpi>
{
 
     /** {@inheritDoc} */
     @Override public void start() throws IgniteCheckedException {
-        if (ctx.config().isDaemon()) {
-            injectSpi();
-
-            return;
-        }
-
         getSpi().setListener(new SwapSpaceSpiListener() {
             @Override public void onSwapEvent(int evtType, @Nullable String spaceName, @Nullable
byte[] keyBytes) {
                 if (ctx.event().isRecordable(evtType)) {

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/9dcd5b09/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 f8ffb29..e015c99 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
@@ -366,15 +366,6 @@ public abstract class IgniteSpiAdapter implements IgniteSpi, IgniteSpiManagement
     }
 
     /**
-     * @return {@code true} if this check is optional.
-     */
-    private boolean checkDaemon() {
-        IgniteSpiConsistencyChecked ann = U.getAnnotation(getClass(), IgniteSpiConsistencyChecked.class);
-
-        return ann != null && ann.checkDaemon();
-    }
-
-    /**
      * @return {@code true} if this check is enabled.
      */
     private boolean checkEnabled() {
@@ -408,13 +399,6 @@ public abstract class IgniteSpiAdapter implements IgniteSpi, IgniteSpiManagement
         assert spiCtx != null;
         assert node != null;
 
-        if (node.isDaemon() && !checkDaemon()) {
-            if (log.isDebugEnabled())
-                log.debug("Skipping configuration consistency check for daemon node: " +
node);
-
-            return;
-        }
-
         /*
          * Optional SPI means that we should not print warning if SPIs are different but
          * still need to compare attributes if SPIs are the same.
@@ -658,8 +642,7 @@ public abstract class IgniteSpiAdapter implements IgniteSpi, IgniteSpiManagement
         }
 
         /** {@inheritDoc} */
-        @Nullable @Override
-        public ClusterNode node(UUID nodeId) {
+        @Nullable @Override public ClusterNode node(UUID nodeId) {
             return null;
         }
 
@@ -714,6 +697,7 @@ public abstract class IgniteSpiAdapter implements IgniteSpi, IgniteSpiManagement
             return null;
         }
 
+        /** {@inheritDoc} */
         @Override public MessageFormatter messageFormatter() {
             return null;
         }

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/9dcd5b09/modules/core/src/main/java/org/apache/ignite/spi/IgniteSpiConsistencyChecked.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/spi/IgniteSpiConsistencyChecked.java
b/modules/core/src/main/java/org/apache/ignite/spi/IgniteSpiConsistencyChecked.java
index 717ef2e..b9219c2 100644
--- a/modules/core/src/main/java/org/apache/ignite/spi/IgniteSpiConsistencyChecked.java
+++ b/modules/core/src/main/java/org/apache/ignite/spi/IgniteSpiConsistencyChecked.java
@@ -36,11 +36,4 @@ public @interface IgniteSpiConsistencyChecked {
      */
     @SuppressWarnings("JavaDoc")
     public boolean optional();
-
-    /**
-     * Flag for performing consistency check for daemon node.
-     *
-     * @return {@code True} if need to perform consistence check for daemon node, {@code
false} otherwise.
-     */
-    public boolean checkDaemon() default false;
 }


Mime
View raw message