Repository: ignite
Updated Branches:
  refs/heads/ignite-2099 [created] 9ff351b50


IGNITE-2099: WIP.


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

Branch: refs/heads/ignite-2099
Commit: 86f4892dced3f4ed6b3dcfb59f639aaa9cc53f77
Parents: 0adee3a
Author: vozerov-gridgain <[email protected]>
Authored: Wed Dec 9 12:53:00 2015 +0300
Committer: vozerov-gridgain <[email protected]>
Committed: Wed Dec 9 12:53:00 2015 +0300

----------------------------------------------------------------------
 .../ignite/binary/BinaryCollectionFactory.java  | 33 ++++++++
 .../apache/ignite/binary/BinaryMapFactory.java  | 33 ++++++++
 .../apache/ignite/binary/BinaryRawReader.java   |  8 +-
 .../org/apache/ignite/binary/BinaryReader.java  |  9 +--
 .../internal/portable/BinaryReaderExImpl.java   | 83 ++++++++++++++------
 .../internal/portable/PortableContext.java      | 12 ---
 .../ignite/internal/portable/PortableUtils.java | 74 +++++++++--------
 .../portable/BinaryMarshallerSelfTest.java      |  4 +-
 .../BinaryObjectBuilderAdditionalSelfTest.java  | 71 ++++++++++-------
 .../mutabletest/GridPortableTestClasses.java    | 77 +++++++++++++-----
 10 files changed, 269 insertions(+), 135 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/86f4892d/modules/core/src/main/java/org/apache/ignite/binary/BinaryCollectionFactory.java
----------------------------------------------------------------------
diff --git 
a/modules/core/src/main/java/org/apache/ignite/binary/BinaryCollectionFactory.java
 
b/modules/core/src/main/java/org/apache/ignite/binary/BinaryCollectionFactory.java
new file mode 100644
index 0000000..0e5bf83
--- /dev/null
+++ 
b/modules/core/src/main/java/org/apache/ignite/binary/BinaryCollectionFactory.java
@@ -0,0 +1,33 @@
+/*
+ * 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.binary;
+
+import java.util.Collection;
+
+/**
+ * Collection factory.
+ */
+public interface BinaryCollectionFactory<K> {
+    /**
+     * Create collection.
+     *
+     * @param size Amount of elements in collection.
+     * @return Collection.
+     */
+    public Collection<K> create(int size);
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/86f4892d/modules/core/src/main/java/org/apache/ignite/binary/BinaryMapFactory.java
----------------------------------------------------------------------
diff --git 
a/modules/core/src/main/java/org/apache/ignite/binary/BinaryMapFactory.java 
b/modules/core/src/main/java/org/apache/ignite/binary/BinaryMapFactory.java
new file mode 100644
index 0000000..d514bf9
--- /dev/null
+++ b/modules/core/src/main/java/org/apache/ignite/binary/BinaryMapFactory.java
@@ -0,0 +1,33 @@
+/*
+ * 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.binary;
+
+import java.util.Map;
+
+/**
+ * Map factory.
+ */
+public interface BinaryMapFactory<K, V> {
+    /**
+     * Create collection.
+     *
+     * @param size Amount of elements in collection.
+     * @return Collection.
+     */
+    public Map<K, V> create(int size);
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/86f4892d/modules/core/src/main/java/org/apache/ignite/binary/BinaryRawReader.java
----------------------------------------------------------------------
diff --git 
a/modules/core/src/main/java/org/apache/ignite/binary/BinaryRawReader.java 
b/modules/core/src/main/java/org/apache/ignite/binary/BinaryRawReader.java
index 7ff515a..ce059d1 100644
--- a/modules/core/src/main/java/org/apache/ignite/binary/BinaryRawReader.java
+++ b/modules/core/src/main/java/org/apache/ignite/binary/BinaryRawReader.java
@@ -206,11 +206,11 @@ public interface BinaryRawReader {
     @Nullable public <T> Collection<T> readCollection() throws 
BinaryObjectException;
 
     /**
-     * @param colCls Collection class.
+     * @param factory Collection factory.
      * @return Collection.
      * @throws BinaryObjectException In case of error.
      */
-    @Nullable public <T> Collection<T> readCollection(Class<? extends 
Collection<T>> colCls)
+    @Nullable public <T> Collection<T> 
readCollection(BinaryCollectionFactory<T> factory)
         throws BinaryObjectException;
 
     /**
@@ -220,11 +220,11 @@ public interface BinaryRawReader {
     @Nullable public <K, V> Map<K, V> readMap() throws BinaryObjectException;
 
     /**
-     * @param mapCls Map class.
+     * @param factory Map factory.
      * @return Map.
      * @throws BinaryObjectException In case of error.
      */
-    @Nullable public <K, V> Map<K, V> readMap(Class<? extends Map<K, V>> 
mapCls) throws BinaryObjectException;
+    @Nullable public <K, V> Map<K, V> readMap(BinaryMapFactory<K, V> factory) 
throws BinaryObjectException;
 
     /**
      * @return Value.

http://git-wip-us.apache.org/repos/asf/ignite/blob/86f4892d/modules/core/src/main/java/org/apache/ignite/binary/BinaryReader.java
----------------------------------------------------------------------
diff --git 
a/modules/core/src/main/java/org/apache/ignite/binary/BinaryReader.java 
b/modules/core/src/main/java/org/apache/ignite/binary/BinaryReader.java
index b8183a2..be7a156 100644
--- a/modules/core/src/main/java/org/apache/ignite/binary/BinaryReader.java
+++ b/modules/core/src/main/java/org/apache/ignite/binary/BinaryReader.java
@@ -242,11 +242,11 @@ public interface BinaryReader {
 
     /**
      * @param fieldName Field name.
-     * @param colCls Collection class.
+     * @param factory Collection factory.
      * @return Collection.
      * @throws BinaryObjectException In case of error.
      */
-    public <T> Collection<T> readCollection(String fieldName, Class<? extends 
Collection<T>> colCls)
+    public <T> Collection<T> readCollection(String fieldName, 
BinaryCollectionFactory<T> factory)
         throws BinaryObjectException;
 
     /**
@@ -258,12 +258,11 @@ public interface BinaryReader {
 
     /**
      * @param fieldName Field name.
-     * @param mapCls Map class.
+     * @param factory Map factory.
      * @return Map.
      * @throws BinaryObjectException In case of error.
      */
-    public <K, V> Map<K, V> readMap(String fieldName, Class<? extends Map<K, 
V>> mapCls)
-        throws BinaryObjectException;
+    public <K, V> Map<K, V> readMap(String fieldName, BinaryMapFactory<K, V> 
factory) throws BinaryObjectException;
 
     /**
      * @param fieldName Field name.

http://git-wip-us.apache.org/repos/asf/ignite/blob/86f4892d/modules/core/src/main/java/org/apache/ignite/internal/portable/BinaryReaderExImpl.java
----------------------------------------------------------------------
diff --git 
a/modules/core/src/main/java/org/apache/ignite/internal/portable/BinaryReaderExImpl.java
 
b/modules/core/src/main/java/org/apache/ignite/internal/portable/BinaryReaderExImpl.java
index a0aa2e5..e2d098b 100644
--- 
a/modules/core/src/main/java/org/apache/ignite/internal/portable/BinaryReaderExImpl.java
+++ 
b/modules/core/src/main/java/org/apache/ignite/internal/portable/BinaryReaderExImpl.java
@@ -26,8 +26,11 @@ import java.util.Collection;
 import java.util.Date;
 import java.util.Map;
 import java.util.UUID;
+
+import org.apache.ignite.binary.BinaryCollectionFactory;
 import org.apache.ignite.binary.BinaryIdMapper;
 import org.apache.ignite.binary.BinaryInvalidTypeException;
+import org.apache.ignite.binary.BinaryMapFactory;
 import org.apache.ignite.binary.BinaryObject;
 import org.apache.ignite.binary.BinaryObjectException;
 import org.apache.ignite.binary.BinaryRawReader;
@@ -1236,20 +1239,20 @@ public class BinaryReaderExImpl implements 
BinaryReader, BinaryRawReaderEx, Bina
     }
 
     /** {@inheritDoc} */
-    @Nullable @Override public <T> Collection<T> readCollection(String 
fieldName,
-        Class<? extends Collection<T>> colCls) throws BinaryObjectException {
-        return findFieldByName(fieldName) ? readCollection0(colCls) : null;
+    @Nullable @Override public <T> Collection<T> readCollection(String 
fieldName, BinaryCollectionFactory<T> factory)
+        throws BinaryObjectException {
+        return findFieldByName(fieldName) ? readCollection0(factory) : null;
     }
 
     /**
      * @param fieldId Field ID.
-     * @param colCls Collection class.
+     * @param factory Collection factory.
      * @return Value.
      * @throws BinaryObjectException In case of error.
      */
-    @Nullable <T> Collection<T> readCollection(int fieldId, @Nullable Class<? 
extends Collection> colCls)
+    @Nullable <T> Collection<T> readCollection(int fieldId, @Nullable 
BinaryCollectionFactory<T> factory)
         throws BinaryObjectException {
-        return findFieldById(fieldId) ? (Collection<T>)readCollection0(colCls) 
: null;
+        return findFieldById(fieldId) ? 
(Collection<T>)readCollection0(factory) : null;
     }
 
     /** {@inheritDoc} */
@@ -1258,26 +1261,41 @@ public class BinaryReaderExImpl implements 
BinaryReader, BinaryRawReaderEx, Bina
     }
 
     /** {@inheritDoc} */
-    @Nullable @Override public <T> Collection<T> readCollection(Class<? 
extends Collection<T>> colCls)
+    @Nullable @Override public <T> Collection<T> 
readCollection(BinaryCollectionFactory<T> factory)
         throws BinaryObjectException {
-        return readCollection0(colCls);
+        return readCollection0(factory);
     }
 
     /**
      * Internal read collection routine.
      *
-     * @param cls Collection class.
+     * @param factory Collection factory.
      * @return Value.
      * @throws BinaryObjectException If failed.
      */
-    private Collection readCollection0(@Nullable Class<? extends Collection> 
cls)
+    private Collection readCollection0(@Nullable BinaryCollectionFactory 
factory)
         throws BinaryObjectException {
         switch (checkFlag(COL)) {
             case NORMAL:
-                return (Collection)PortableUtils.doReadCollection(in, ctx, 
ldr, this, true, cls);
+                return (Collection)PortableUtils.doReadCollection(in, ctx, 
ldr, this, true, factory);
 
-            case HANDLE:
-                return readHandleField();
+            case HANDLE: {
+                int handlePos = PortableUtils.positionForHandle(in) - 
in.readInt();
+
+                Object obj = getHandle(handlePos);
+
+                if (obj == null) {
+                    int retPos = in.position();
+
+                    streamPosition(handlePos);
+
+                    obj = readCollection0(factory);
+
+                    streamPosition(retPos);
+                }
+
+                return (Collection)obj;
+            }
 
             default:
                 return null;
@@ -1290,19 +1308,19 @@ public class BinaryReaderExImpl implements 
BinaryReader, BinaryRawReaderEx, Bina
     }
 
     /** {@inheritDoc} */
-    @Nullable @Override public <K, V> Map<K, V> readMap(String fieldName, 
Class<? extends Map<K, V>> mapCls)
+    @Nullable @Override public <K, V> Map<K, V> readMap(String fieldName, 
BinaryMapFactory<K, V> factory)
         throws BinaryObjectException {
-        return findFieldByName(fieldName) ? readMap0(mapCls) : null;
+        return findFieldByName(fieldName) ? readMap0(factory) : null;
     }
 
     /**
      * @param fieldId Field ID.
-     * @param mapCls Map class.
+     * @param factory Factory.
      * @return Value.
      * @throws BinaryObjectException In case of error.
      */
-    @Nullable Map<?, ?> readMap(int fieldId, @Nullable Class<? extends Map> 
mapCls) throws BinaryObjectException {
-        return findFieldById(fieldId) ? readMap0(mapCls) : null;
+    @Nullable Map<?, ?> readMap(int fieldId, @Nullable BinaryMapFactory 
factory) throws BinaryObjectException {
+        return findFieldById(fieldId) ? readMap0(factory) : null;
     }
 
     /** {@inheritDoc} */
@@ -1311,25 +1329,40 @@ public class BinaryReaderExImpl implements 
BinaryReader, BinaryRawReaderEx, Bina
     }
 
     /** {@inheritDoc} */
-    @Nullable @Override public <K, V> Map<K, V> readMap(Class<? extends Map<K, 
V>> mapCls)
+    @Nullable @Override public <K, V> Map<K, V> readMap(BinaryMapFactory<K, V> 
factory)
         throws BinaryObjectException {
-        return readMap0(mapCls);
+        return readMap0(factory);
     }
 
     /**
      * Internal read map routine.
      *
-     * @param cls Map class.
+     * @param factory Factory.
      * @return Value.
      * @throws BinaryObjectException If failed.
      */
-    private Map readMap0(@Nullable Class<? extends Map> cls) throws 
BinaryObjectException {
+    private Map readMap0(@Nullable BinaryMapFactory factory) throws 
BinaryObjectException {
         switch (checkFlag(MAP)) {
             case NORMAL:
-                return (Map)PortableUtils.doReadMap(in, ctx, ldr, this, true, 
cls);
+                return (Map)PortableUtils.doReadMap(in, ctx, ldr, this, true, 
factory);
 
-            case HANDLE:
-                return readHandleField();
+            case HANDLE: {
+                int handlePos = PortableUtils.positionForHandle(in) - 
in.readInt();
+
+                Object obj = getHandle(handlePos);
+
+                if (obj == null) {
+                    int retPos = in.position();
+
+                    streamPosition(handlePos);
+
+                    obj = readMap0(factory);
+
+                    streamPosition(retPos);
+                }
+
+                return (Map)obj;
+            }
 
             default:
                 return null;

http://git-wip-us.apache.org/repos/asf/ignite/blob/86f4892d/modules/core/src/main/java/org/apache/ignite/internal/portable/PortableContext.java
----------------------------------------------------------------------
diff --git 
a/modules/core/src/main/java/org/apache/ignite/internal/portable/PortableContext.java
 
b/modules/core/src/main/java/org/apache/ignite/internal/portable/PortableContext.java
index 8bad737..7449863 100644
--- 
a/modules/core/src/main/java/org/apache/ignite/internal/portable/PortableContext.java
+++ 
b/modules/core/src/main/java/org/apache/ignite/internal/portable/PortableContext.java
@@ -164,16 +164,9 @@ public class PortableContext implements Externalizable {
         colTypes.put(LinkedList.class, GridPortableMarshaller.LINKED_LIST);
         colTypes.put(HashSet.class, GridPortableMarshaller.HASH_SET);
         colTypes.put(LinkedHashSet.class, 
GridPortableMarshaller.LINKED_HASH_SET);
-        colTypes.put(TreeSet.class, GridPortableMarshaller.TREE_SET);
-        colTypes.put(ConcurrentSkipListSet.class, 
GridPortableMarshaller.CONC_SKIP_LIST_SET);
-        colTypes.put(ConcurrentLinkedQueue.class, 
GridPortableMarshaller.CONC_LINKED_QUEUE);
 
         mapTypes.put(HashMap.class, GridPortableMarshaller.HASH_MAP);
         mapTypes.put(LinkedHashMap.class, 
GridPortableMarshaller.LINKED_HASH_MAP);
-        mapTypes.put(TreeMap.class, GridPortableMarshaller.TREE_MAP);
-        mapTypes.put(ConcurrentHashMap.class, 
GridPortableMarshaller.CONC_HASH_MAP);
-        mapTypes.put(ConcurrentHashMap8.class, 
GridPortableMarshaller.CONC_HASH_MAP);
-        mapTypes.put(Properties.class, GridPortableMarshaller.PROPERTIES_MAP);
 
         // IDs range from [0..200] is used by Java SDK API and GridGain legacy 
API
 
@@ -210,14 +203,9 @@ public class PortableContext implements Externalizable {
         registerPredefinedType(LinkedList.class, 0);
         registerPredefinedType(HashSet.class, 0);
         registerPredefinedType(LinkedHashSet.class, 0);
-        registerPredefinedType(TreeSet.class, 0);
-        registerPredefinedType(ConcurrentSkipListSet.class, 0);
 
         registerPredefinedType(HashMap.class, 0);
         registerPredefinedType(LinkedHashMap.class, 0);
-        registerPredefinedType(TreeMap.class, 0);
-        registerPredefinedType(ConcurrentHashMap.class, 0);
-        registerPredefinedType(ConcurrentHashMap8.class, 0);
 
         registerPredefinedType(GridMapEntry.class, 60);
         registerPredefinedType(IgniteBiTuple.class, 61);

http://git-wip-us.apache.org/repos/asf/ignite/blob/86f4892d/modules/core/src/main/java/org/apache/ignite/internal/portable/PortableUtils.java
----------------------------------------------------------------------
diff --git 
a/modules/core/src/main/java/org/apache/ignite/internal/portable/PortableUtils.java
 
b/modules/core/src/main/java/org/apache/ignite/internal/portable/PortableUtils.java
index 5d794ca..42d9d85 100644
--- 
a/modules/core/src/main/java/org/apache/ignite/internal/portable/PortableUtils.java
+++ 
b/modules/core/src/main/java/org/apache/ignite/internal/portable/PortableUtils.java
@@ -17,9 +17,10 @@
 
 package org.apache.ignite.internal.portable;
 
-import java.util.concurrent.ConcurrentLinkedQueue;
 import org.apache.ignite.IgniteCheckedException;
+import org.apache.ignite.binary.BinaryCollectionFactory;
 import org.apache.ignite.binary.BinaryInvalidTypeException;
+import org.apache.ignite.binary.BinaryMapFactory;
 import org.apache.ignite.binary.BinaryObject;
 import org.apache.ignite.binary.BinaryObjectException;
 import org.apache.ignite.binary.Binarylizable;
@@ -35,8 +36,6 @@ import org.jsr166.ConcurrentHashMap8;
 import java.io.ByteArrayInputStream;
 import java.io.Externalizable;
 import java.lang.reflect.Array;
-import java.lang.reflect.Constructor;
-import java.lang.reflect.InvocationTargetException;
 import java.math.BigDecimal;
 import java.math.BigInteger;
 import java.sql.Timestamp;
@@ -56,6 +55,7 @@ import java.util.TreeMap;
 import java.util.TreeSet;
 import java.util.UUID;
 import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ConcurrentLinkedQueue;
 import java.util.concurrent.ConcurrentSkipListSet;
 
 import static java.nio.charset.StandardCharsets.UTF_8;
@@ -1004,8 +1004,7 @@ public class PortableUtils {
         else if (cls == Timestamp[].class)
             return BinaryWriteMode.TIMESTAMP_ARR;
         else if (cls.isArray())
-            return cls.getComponentType().isEnum() ?
-                BinaryWriteMode.ENUM_ARR : BinaryWriteMode.OBJECT_ARR;
+            return cls.getComponentType().isEnum() ? BinaryWriteMode.ENUM_ARR 
: BinaryWriteMode.OBJECT_ARR;
         else if (cls == BinaryObjectImpl.class)
             return BinaryWriteMode.PORTABLE_OBJ;
         else if (Binarylizable.class.isAssignableFrom(cls))
@@ -1014,9 +1013,9 @@ public class PortableUtils {
             return BinaryWriteMode.EXTERNALIZABLE;
         else if (Map.Entry.class.isAssignableFrom(cls))
             return BinaryWriteMode.MAP_ENTRY;
-        else if (Collection.class.isAssignableFrom(cls))
+        else if (isSpecialCollection(cls))
             return BinaryWriteMode.COL;
-        else if (Map.class.isAssignableFrom(cls))
+        else if (isSpecialMap(cls))
             return BinaryWriteMode.MAP;
         else if (cls.isEnum())
             return BinaryWriteMode.ENUM;
@@ -1027,6 +1026,27 @@ public class PortableUtils {
     }
 
     /**
+     * Check if class represents a collection which must be treated specially.
+     *
+     * @param cls Class.
+     * @return {@code True} if this is a special collection class.
+     */
+    private static boolean isSpecialCollection(Class cls) {
+        return ArrayList.class.equals(cls) || LinkedList.class.equals(cls) ||
+            HashSet.class.equals(cls) || LinkedHashSet.class.equals(cls);
+    }
+
+    /**
+     * Check if class represents a map which must be treated specially.
+     *
+     * @param cls Class.
+     * @return {@code True} if this is a special map class.
+     */
+    private static boolean isSpecialMap(Class cls) {
+        return HashMap.class.equals(cls) || LinkedHashMap.class.equals(cls);
+    }
+
+    /**
      * @return Value.
      */
     public static byte[] doReadByteArray(PortableInputStream in) {
@@ -1738,13 +1758,13 @@ public class PortableUtils {
 
     /**
      * @param deserialize Deep flag.
-     * @param cls Collection class.
+     * @param factory Collection factory.
      * @return Value.
      * @throws BinaryObjectException In case of error.
      */
     @SuppressWarnings("unchecked")
     public static Collection<?> doReadCollection(PortableInputStream in, 
PortableContext ctx, ClassLoader ldr,
-        BinaryReaderHandlesHolder handles, boolean deserialize, @Nullable 
Class<? extends Collection> cls)
+        BinaryReaderHandlesHolder handles, boolean deserialize, 
BinaryCollectionFactory factory)
         throws BinaryObjectException {
         int hPos = positionForHandle(in);
 
@@ -1756,20 +1776,8 @@ public class PortableUtils {
 
         Collection<Object> col;
 
-        if (cls != null) {
-            try {
-                Constructor<? extends Collection> cons = cls.getConstructor();
-
-                col = cons.newInstance();
-            }
-            catch (NoSuchMethodException ignored) {
-                throw new BinaryObjectException("Collection class doesn't have 
public default constructor: " +
-                    cls.getName());
-            }
-            catch (InvocationTargetException | InstantiationException | 
IllegalAccessException e) {
-                throw new BinaryObjectException("Failed to instantiate 
collection: " + cls.getName(), e);
-            }
-        }
+        if (factory != null)
+            col = factory.create(size);
         else {
             switch (colType) {
                 case ARR_LIST:
@@ -1832,13 +1840,13 @@ public class PortableUtils {
 
     /**
      * @param deserialize Deep flag.
-     * @param cls Map class.
+     * @param factory Map factory.
      * @return Value.
      * @throws BinaryObjectException In case of error.
      */
     @SuppressWarnings("unchecked")
     public static Map<?, ?> doReadMap(PortableInputStream in, PortableContext 
ctx, ClassLoader ldr,
-        BinaryReaderHandlesHolder handles, boolean deserialize, @Nullable 
Class<? extends Map> cls)
+        BinaryReaderHandlesHolder handles, boolean deserialize, 
BinaryMapFactory factory)
         throws BinaryObjectException {
         int hPos = positionForHandle(in);
 
@@ -1850,20 +1858,8 @@ public class PortableUtils {
 
         Map<Object, Object> map;
 
-        if (cls != null) {
-            try {
-                Constructor<? extends Map> cons = cls.getConstructor();
-
-                map = cons.newInstance();
-            }
-            catch (NoSuchMethodException ignored) {
-                throw new BinaryObjectException("Map class doesn't have public 
default constructor: " +
-                    cls.getName());
-            }
-            catch (InvocationTargetException | InstantiationException | 
IllegalAccessException e) {
-                throw new BinaryObjectException("Failed to instantiate map: " 
+ cls.getName(), e);
-            }
-        }
+        if (factory != null)
+            map = factory.create(size);
         else {
             switch (mapType) {
                 case HASH_MAP:

http://git-wip-us.apache.org/repos/asf/ignite/blob/86f4892d/modules/core/src/test/java/org/apache/ignite/internal/portable/BinaryMarshallerSelfTest.java
----------------------------------------------------------------------
diff --git 
a/modules/core/src/test/java/org/apache/ignite/internal/portable/BinaryMarshallerSelfTest.java
 
b/modules/core/src/test/java/org/apache/ignite/internal/portable/BinaryMarshallerSelfTest.java
index a06e6c3..64093e7 100644
--- 
a/modules/core/src/test/java/org/apache/ignite/internal/portable/BinaryMarshallerSelfTest.java
+++ 
b/modules/core/src/test/java/org/apache/ignite/internal/portable/BinaryMarshallerSelfTest.java
@@ -1141,8 +1141,8 @@ public class BinaryMarshallerSelfTest extends 
GridCommonAbstractTest {
         ));
 
         Object[] arr = new Object[] {new Value(1), new Value(2), new Value(3)};
-        Collection<Value> col = Arrays.asList(new Value(4), new Value(5), new 
Value(6));
-        Map<Key, Value> map = F.asMap(new Key(10), new Value(10), new Key(20), 
new Value(20), new Key(30), new Value(30));
+        Collection<Value> col = new ArrayList<>(Arrays.asList(new Value(4), 
new Value(5), new Value(6)));
+        Map<Key, Value> map = new HashMap<>(F.asMap(new Key(10), new 
Value(10), new Key(20), new Value(20), new Key(30), new Value(30)));
 
         CollectionFieldsObject obj = new CollectionFieldsObject(arr, col, map);
 

http://git-wip-us.apache.org/repos/asf/ignite/blob/86f4892d/modules/core/src/test/java/org/apache/ignite/internal/portable/BinaryObjectBuilderAdditionalSelfTest.java
----------------------------------------------------------------------
diff --git 
a/modules/core/src/test/java/org/apache/ignite/internal/portable/BinaryObjectBuilderAdditionalSelfTest.java
 
b/modules/core/src/test/java/org/apache/ignite/internal/portable/BinaryObjectBuilderAdditionalSelfTest.java
index cfeb714..119500a 100644
--- 
a/modules/core/src/test/java/org/apache/ignite/internal/portable/BinaryObjectBuilderAdditionalSelfTest.java
+++ 
b/modules/core/src/test/java/org/apache/ignite/internal/portable/BinaryObjectBuilderAdditionalSelfTest.java
@@ -21,6 +21,24 @@ import com.google.common.collect.ImmutableMap;
 import com.google.common.collect.Lists;
 import com.google.common.collect.Maps;
 import com.google.common.collect.Sets;
+import org.apache.ignite.IgniteBinary;
+import org.apache.ignite.IgniteCheckedException;
+import org.apache.ignite.binary.BinaryObject;
+import org.apache.ignite.binary.BinaryObjectBuilder;
+import org.apache.ignite.binary.BinaryType;
+import org.apache.ignite.configuration.BinaryConfiguration;
+import org.apache.ignite.configuration.CacheConfiguration;
+import org.apache.ignite.configuration.IgniteConfiguration;
+import org.apache.ignite.internal.portable.builder.BinaryObjectBuilderImpl;
+import org.apache.ignite.internal.portable.builder.PortableBuilderEnum;
+import 
org.apache.ignite.internal.portable.mutabletest.GridBinaryMarshalerAwareTestClass;
+import 
org.apache.ignite.internal.processors.cache.portable.CacheObjectBinaryProcessorImpl;
+import org.apache.ignite.internal.processors.cache.portable.IgniteBinaryImpl;
+import org.apache.ignite.internal.util.lang.GridMapEntry;
+import org.apache.ignite.testframework.GridTestUtils;
+import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
+import org.junit.Assert;
+
 import java.lang.reflect.Field;
 import java.math.BigDecimal;
 import java.sql.Timestamp;
@@ -35,27 +53,11 @@ import java.util.Map;
 import java.util.Objects;
 import java.util.Set;
 import java.util.UUID;
-import org.apache.ignite.IgniteCheckedException;
-import org.apache.ignite.IgniteBinary;
-import org.apache.ignite.configuration.BinaryConfiguration;
-import org.apache.ignite.configuration.CacheConfiguration;
-import org.apache.ignite.configuration.IgniteConfiguration;
-import org.apache.ignite.internal.portable.builder.PortableBuilderEnum;
-import org.apache.ignite.internal.portable.builder.BinaryObjectBuilderImpl;
-import 
org.apache.ignite.internal.portable.mutabletest.GridBinaryMarshalerAwareTestClass;
-import 
org.apache.ignite.internal.processors.cache.portable.CacheObjectBinaryProcessorImpl;
-import org.apache.ignite.internal.processors.cache.portable.IgniteBinaryImpl;
-import org.apache.ignite.internal.util.lang.GridMapEntry;
-import org.apache.ignite.binary.BinaryObjectBuilder;
-import org.apache.ignite.binary.BinaryType;
-import org.apache.ignite.binary.BinaryObject;
-import org.apache.ignite.testframework.GridTestUtils;
-import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
-import org.junit.Assert;
 
 import static org.apache.ignite.cache.CacheMode.REPLICATED;
 import static 
org.apache.ignite.internal.portable.mutabletest.GridPortableTestClasses.Address;
-import static 
org.apache.ignite.internal.portable.mutabletest.GridPortableTestClasses.AddressBook;
+import static 
org.apache.ignite.internal.portable.mutabletest.GridPortableTestClasses.Addresses;
+import static 
org.apache.ignite.internal.portable.mutabletest.GridPortableTestClasses.Companies;
 import static 
org.apache.ignite.internal.portable.mutabletest.GridPortableTestClasses.Company;
 import static 
org.apache.ignite.internal.portable.mutabletest.GridPortableTestClasses.TestObjectAllTypes;
 import static 
org.apache.ignite.internal.portable.mutabletest.GridPortableTestClasses.TestObjectArrayList;
@@ -1116,30 +1118,39 @@ public class BinaryObjectBuilderAdditionalSelfTest 
extends GridCommonAbstractTes
      *
      */
     public void testChangeMap() {
-        AddressBook addrBook = new AddressBook();
+        Addresses addrs = new Addresses();
+
+        addrs.addCompany(new Company(1, "Google inc", 100,
+            new Address("Saint-Petersburg", "Torzhkovskya", 1, 53), 
"occupation"));
+
+        addrs.addCompany(new Company(2, "Apple inc", 100,
+            new Address("Saint-Petersburg", "Torzhkovskya", 1, 54), 
"occupation"));
+
+        addrs.addCompany(new Company(3, "Microsoft", 100,
+            new Address("Saint-Petersburg", "Torzhkovskya", 1, 55), 
"occupation"));
+
+        addrs.addCompany(new Company(4, "Oracle", 100,
+            new Address("Saint-Petersburg", "Nevskiy", 1, 1), "occupation"));
 
-        addrBook.addCompany(new Company(1, "Google inc", 100, new 
Address("Saint-Petersburg", "Torzhkovskya", 1, 53), "occupation"));
-        addrBook.addCompany(new Company(2, "Apple inc", 100, new 
Address("Saint-Petersburg", "Torzhkovskya", 1, 54), "occupation"));
-        addrBook.addCompany(new Company(3, "Microsoft", 100, new 
Address("Saint-Petersburg", "Torzhkovskya", 1, 55), "occupation"));
-        addrBook.addCompany(new Company(4, "Oracle", 100, new 
Address("Saint-Petersburg", "Nevskiy", 1, 1), "occupation"));
+        BinaryObjectBuilderImpl binaryAddres = wrap(addrs);
 
-        BinaryObjectBuilderImpl mutableObj = wrap(addrBook);
+        Map<String, BinaryObjectBuilderImpl> map = 
binaryAddres.getField("companyByStreet");
 
-        Map<String, List<BinaryObjectBuilderImpl>> map = 
mutableObj.getField("companyByStreet");
+        BinaryObjectBuilderImpl binaryCompanies = map.get("Torzhkovskya");
 
-        List<BinaryObjectBuilderImpl> list = map.get("Torzhkovskya");
+        List<BinaryObjectBuilderImpl> binaryCompaniesList = 
binaryCompanies.getField("companies");
 
-        BinaryObjectBuilderImpl company = list.get(0);
+        BinaryObjectBuilderImpl company = binaryCompaniesList.get(0);
 
         assert "Google inc".equals(company.<String>getField("name"));
 
-        list.remove(0);
+        binaryCompaniesList.remove(0);
 
-        AddressBook res = mutableObj.build().deserialize();
+        Addresses res = binaryAddres.build().deserialize();
 
         assertEquals(Arrays.asList("Nevskiy", "Torzhkovskya"), new 
ArrayList<>(res.getCompanyByStreet().keySet()));
 
-        List<Company> torzhkovskyaCompanies = 
res.getCompanyByStreet().get("Torzhkovskya");
+        Companies torzhkovskyaCompanies = 
res.getCompanyByStreet().get("Torzhkovskya");
 
         assertEquals(2, torzhkovskyaCompanies.size());
         assertEquals("Apple inc", torzhkovskyaCompanies.get(0).name);

http://git-wip-us.apache.org/repos/asf/ignite/blob/86f4892d/modules/core/src/test/java/org/apache/ignite/internal/portable/mutabletest/GridPortableTestClasses.java
----------------------------------------------------------------------
diff --git 
a/modules/core/src/test/java/org/apache/ignite/internal/portable/mutabletest/GridPortableTestClasses.java
 
b/modules/core/src/test/java/org/apache/ignite/internal/portable/mutabletest/GridPortableTestClasses.java
index 69687ab..3aaa0d0 100644
--- 
a/modules/core/src/test/java/org/apache/ignite/internal/portable/mutabletest/GridPortableTestClasses.java
+++ 
b/modules/core/src/test/java/org/apache/ignite/internal/portable/mutabletest/GridPortableTestClasses.java
@@ -31,6 +31,12 @@ import java.util.List;
 import java.util.Map;
 import java.util.TreeMap;
 import java.util.UUID;
+
+import org.apache.ignite.binary.BinaryMapFactory;
+import org.apache.ignite.binary.BinaryObjectException;
+import org.apache.ignite.binary.BinaryReader;
+import org.apache.ignite.binary.BinaryWriter;
+import org.apache.ignite.binary.Binarylizable;
 import org.apache.ignite.internal.util.lang.GridMapEntry;
 import org.apache.ignite.binary.BinaryObject;
 
@@ -315,7 +321,10 @@ public class GridPortableTestClasses {
     /**
      *
      */
-    public static class Address {
+    public static class Address implements Serializable {
+        /** SUID. */
+        private static final long serialVersionUID = 0L;
+
         /** City. */
         public String city;
 
@@ -354,7 +363,10 @@ public class GridPortableTestClasses {
     /**
      *
      */
-    public static class Company {
+    public static class Company implements Serializable {
+        /** SUID. */
+        private static final long serialVersionUID = 0L;
+
         /** ID. */
         public int id;
 
@@ -396,28 +408,50 @@ public class GridPortableTestClasses {
     }
 
     /**
-     *
+     * Companies.
      */
-    public static class AddressBook {
-        /** */
-        private Map<String, List<Company>> companyByStreet = new TreeMap<>();
+    public static class Companies {
+        /** Companies. */
+        private ArrayList<Company> companies = new ArrayList<>();
 
         /**
-         * @param street Street.
+         * @param idx Index.
          * @return Company.
          */
-        public List<Company> findCompany(String street) {
-            return companyByStreet.get(street);
+        public Company get(int idx) {
+            return companies.get(idx);
+        }
+
+        /**
+         * @param company Company.
+         */
+        public void add(Company company) {
+            companies.add(company);
+        }
+
+        /**
+         * @return Size.
+         */
+        public int size() {
+            return companies.size();
         }
+    }
+
+    /**
+     *
+     */
+    public static class Addresses implements Binarylizable {
+        /** */
+        private Map<String, Companies> companyByStreet = new TreeMap<>();
 
         /**
          * @param company Company.
          */
         public void addCompany(Company company) {
-            List<Company> list = companyByStreet.get(company.address.street);
+            Companies list = companyByStreet.get(company.address.street);
 
             if (list == null) {
-                list = new ArrayList<>();
+                list = new Companies();
 
                 companyByStreet.put(company.address.street, list);
             }
@@ -428,16 +462,23 @@ public class GridPortableTestClasses {
         /**
          * @return map
          */
-        public Map<String, List<Company>> getCompanyByStreet() {
+        public Map<String, Companies> getCompanyByStreet() {
             return companyByStreet;
         }
 
-        /**
-         * @param companyByStreet map
-         */
-        public void setCompanyByStreet(Map<String, List<Company>> 
companyByStreet) {
-            this.companyByStreet = companyByStreet;
+        /** {@inheritDoc} */
+        @Override public void writeBinary(BinaryWriter writer) throws 
BinaryObjectException {
+            writer.writeMap("companyByStreet", companyByStreet);
         }
-    }
 
+        /** {@inheritDoc} */
+        @SuppressWarnings("unchecked")
+        @Override public void readBinary(BinaryReader reader) throws 
BinaryObjectException {
+            companyByStreet = reader.readMap("companyByStreet", new 
BinaryMapFactory<String, Companies>() {
+                @Override public Map<String, Companies> create(int size) {
+                    return new TreeMap<>();
+                }
+            });
+        }
+    }
 }
\ No newline at end of file

Reply via email to