ignite-757 - message factory for components

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

Branch: refs/heads/ignite-286
Commit: 5d0e620fc19959ea5fa58e5a473ad2ccf2da1814
Parents: ab052ac
Author: S.Vladykin <svlady...@gridgain.com>
Authored: Mon Apr 27 13:38:24 2015 +0300
Committer: S.Vladykin <svlady...@gridgain.com>
Committed: Mon Apr 27 13:38:24 2015 +0300

----------------------------------------------------------------------
 .../ignite/internal/IgniteComponentType.java    | 36 +++++++++++++++++++-
 .../managers/communication/GridIoManager.java   | 17 +++++----
 2 files changed, 43 insertions(+), 10 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/5d0e620f/modules/core/src/main/java/org/apache/ignite/internal/IgniteComponentType.java
----------------------------------------------------------------------
diff --git 
a/modules/core/src/main/java/org/apache/ignite/internal/IgniteComponentType.java
 
b/modules/core/src/main/java/org/apache/ignite/internal/IgniteComponentType.java
index 6ed8a63..4b937b1 100644
--- 
a/modules/core/src/main/java/org/apache/ignite/internal/IgniteComponentType.java
+++ 
b/modules/core/src/main/java/org/apache/ignite/internal/IgniteComponentType.java
@@ -18,6 +18,8 @@
 package org.apache.ignite.internal;
 
 import org.apache.ignite.*;
+import org.apache.ignite.internal.util.typedef.internal.*;
+import org.apache.ignite.plugin.extensions.communication.*;
 import org.jetbrains.annotations.*;
 
 import java.lang.reflect.*;
@@ -58,7 +60,8 @@ public enum IgniteComponentType {
     INDEXING(
         null,
         "org.apache.ignite.internal.processors.query.h2.IgniteH2Indexing",
-        "ignite-indexing"
+        "ignite-indexing",
+        
"org.apache.ignite.internal.processors.query.h2.twostep.msg.GridH2ValueMessageFactory"
     ),
 
     /** Nodes starting using SSH. */
@@ -91,6 +94,9 @@ public enum IgniteComponentType {
     /** Module name. */
     private final String module;
 
+    /** Optional message factory for component. */
+    private final String msgFactoryCls;
+
     /**
      * Constructor.
      *
@@ -99,9 +105,22 @@ public enum IgniteComponentType {
      * @param module Module name.
      */
     IgniteComponentType(String noOpClsName, String clsName, String module) {
+        this(noOpClsName, clsName, module, null);
+    }
+
+    /**
+     * Constructor.
+     *
+     * @param noOpClsName Class name for no-op implementation.
+     * @param clsName Class name.
+     * @param module Module name.
+     * @param msgFactoryCls {@link MessageFactory} class for the component.
+     */
+    IgniteComponentType(String noOpClsName, String clsName, String module, 
String msgFactoryCls) {
         this.noOpClsName = noOpClsName;
         this.clsName = clsName;
         this.module = module;
+        this.msgFactoryCls = msgFactoryCls;
     }
 
     /**
@@ -273,6 +292,21 @@ public enum IgniteComponentType {
     }
 
     /**
+     * Creates message factory for the component.
+     *
+     * @return Message factory or {@code null} if none or the component is not 
in classpath.
+     * @throws IgniteCheckedException If failed.
+     */
+    @Nullable public MessageFactory messageFactory() throws 
IgniteCheckedException {
+        Class<?> cls;
+
+        if (msgFactoryCls == null || null == (cls = 
U.classForName(msgFactoryCls, null)))
+            return null;
+
+        return (MessageFactory)U.newInstance(cls);
+    }
+
+    /**
      * @param err Creation error.
      * @return Component creation exception.
      */

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/5d0e620f/modules/core/src/main/java/org/apache/ignite/internal/managers/communication/GridIoManager.java
----------------------------------------------------------------------
diff --git 
a/modules/core/src/main/java/org/apache/ignite/internal/managers/communication/GridIoManager.java
 
b/modules/core/src/main/java/org/apache/ignite/internal/managers/communication/GridIoManager.java
index dba043a..e088ce5 100644
--- 
a/modules/core/src/main/java/org/apache/ignite/internal/managers/communication/GridIoManager.java
+++ 
b/modules/core/src/main/java/org/apache/ignite/internal/managers/communication/GridIoManager.java
@@ -232,18 +232,17 @@ public class GridIoManager extends 
GridManagerAdapter<CommunicationSpi<Serializa
         if (msgs == null)
             msgs = EMPTY;
 
-        MessageFactory qryMsgs = null;
+        List<MessageFactory> compMsgs = new ArrayList<>();
 
-        try {
-            qryMsgs = U.newInstance( // TODO fix this dirty hack
-                
"org.apache.ignite.internal.processors.query.h2.twostep.msg.GridH2ValueMessageFactory");
-        }
-        catch (IgniteCheckedException e) {
-            // No-op.
+        for (IgniteComponentType compType : IgniteComponentType.values()) {
+            MessageFactory f = compType.messageFactory();
+
+            if (f != null)
+                compMsgs.add(f);
         }
 
-        if (qryMsgs != null)
-            msgs = F.concat(msgs, qryMsgs);
+        if (!compMsgs.isEmpty())
+            msgs = F.concat(msgs, compMsgs.toArray(new 
MessageFactory[compMsgs.size()]));
 
         msgFactory = new GridIoMessageFactory(msgs);
 

Reply via email to