Repository: incubator-ignite
Updated Branches:
  refs/heads/ignite-82 6cf139fee -> 3e371e69f


IGNITE-61 - Direct marshalling


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

Branch: refs/heads/ignite-82
Commit: b71137177ed94dca9b90b1211cd207a63e9469b4
Parents: b3cb580
Author: Valentin Kulichenko <vkuliche...@gridgain.com>
Authored: Sun Feb 8 14:37:39 2015 -0800
Committer: Valentin Kulichenko <vkuliche...@gridgain.com>
Committed: Sun Feb 8 14:37:39 2015 -0800

----------------------------------------------------------------------
 .../internal/direct/DirectByteBufferStream.java | 50 ++++++++++----------
 1 file changed, 26 insertions(+), 24 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/b7113717/modules/core/src/main/java/org/apache/ignite/internal/direct/DirectByteBufferStream.java
----------------------------------------------------------------------
diff --git 
a/modules/core/src/main/java/org/apache/ignite/internal/direct/DirectByteBufferStream.java
 
b/modules/core/src/main/java/org/apache/ignite/internal/direct/DirectByteBufferStream.java
index 9d79f41..6b33fe3 100644
--- 
a/modules/core/src/main/java/org/apache/ignite/internal/direct/DirectByteBufferStream.java
+++ 
b/modules/core/src/main/java/org/apache/ignite/internal/direct/DirectByteBufferStream.java
@@ -25,6 +25,7 @@ import org.jetbrains.annotations.*;
 import sun.misc.*;
 import sun.nio.ch.*;
 
+import java.lang.reflect.*;
 import java.nio.*;
 import java.util.*;
 
@@ -238,7 +239,22 @@ public class DirectByteBufferStream {
         TYPES.put(BitSet.class, Type.BIT_SET);
         TYPES.put(UUID.class, Type.UUID);
         TYPES.put(IgniteUuid.class, Type.IGNITE_UUID);
-        TYPES.put(MessageAdapter.class, Type.MSG);
+    }
+
+    /**
+     * @param cls Class.
+     * @return Type enum value.
+     */
+    private static Type type(Class<?> cls) {
+        Type type = TYPES.get(cls);
+
+        if (type == null) {
+            assert MessageAdapter.class.isAssignableFrom(cls) : cls;
+
+            type = Type.MSG;
+        }
+
+        return type;
     }
 
     /** */
@@ -549,9 +565,7 @@ public class DirectByteBufferStream {
                 it = arrayIterator(arr);
             }
 
-            Type itemType = TYPES.get(itemCls);
-
-            assert itemType != null;
+            Type itemType = type(itemCls);
 
             while (it.hasNext() || cur != NULL) {
                 if (cur == NULL)
@@ -582,9 +596,7 @@ public class DirectByteBufferStream {
                 it = col.iterator();
             }
 
-            Type itemType = TYPES.get(itemCls);
-
-            assert itemType != null;
+            Type itemType = type(itemCls);
 
             while (it.hasNext() || cur != NULL) {
                 if (cur == NULL)
@@ -616,11 +628,8 @@ public class DirectByteBufferStream {
                 it = map.entrySet().iterator();
             }
 
-            Type keyType = TYPES.get(keyCls);
-            Type valType = TYPES.get(valCls);
-
-            assert keyType != null;
-            assert valType != null;
+            Type keyType = type(keyCls);
+            Type valType = type(valCls);
 
             while (it.hasNext() || cur != NULL) {
                 if (cur == NULL)
@@ -897,11 +906,9 @@ public class DirectByteBufferStream {
 
         if (readSize >= 0) {
             if (objArr == null)
-                objArr = new Object[readSize];
+                objArr = (Object[])Array.newInstance(itemCls, readSize);
 
-            Type itemType = TYPES.get(itemCls);
-
-            assert itemType != null;
+            Type itemType = type(itemCls);
 
             for (int i = readItems; i < readSize; i++) {
                 Object item = read(itemType);
@@ -941,9 +948,7 @@ public class DirectByteBufferStream {
             if (col == null)
                 col = new ArrayList<>(readSize);
 
-            Type itemType = TYPES.get(itemCls);
-
-            assert itemType != null;
+            Type itemType = type(itemCls);
 
             for (int i = readItems; i < readSize; i++) {
                 Object item = read(itemType);
@@ -983,11 +988,8 @@ public class DirectByteBufferStream {
             if (map == null)
                 map = U.newHashMap(readSize);
 
-            Type keyType = TYPES.get(keyCls);
-            Type valType = TYPES.get(valCls);
-
-            assert keyType != null;
-            assert valType != null;
+            Type keyType = type(keyCls);
+            Type valType = type(valCls);
 
             for (int i = readItems; i < readSize; i++) {
                 if (!keyDone) {

Reply via email to