You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ignite.apache.org by ak...@apache.org on 2015/12/11 16:55:29 UTC

[01/59] [abbrv] ignite git commit: ignite-2065: rename "portable" packages to "binary"

Repository: ignite
Updated Branches:
  refs/heads/ignite-843-rc2 330ba1a30 -> 4ad4f76d9


http://git-wip-us.apache.org/repos/asf/ignite/blob/1dbf20e0/modules/core/src/test/java/org/apache/ignite/platform/PlatformComputeBinarizableArgTask.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/platform/PlatformComputeBinarizableArgTask.java b/modules/core/src/test/java/org/apache/ignite/platform/PlatformComputeBinarizableArgTask.java
index 148d828..3ae1dc3 100644
--- a/modules/core/src/test/java/org/apache/ignite/platform/PlatformComputeBinarizableArgTask.java
+++ b/modules/core/src/test/java/org/apache/ignite/platform/PlatformComputeBinarizableArgTask.java
@@ -25,7 +25,7 @@ import org.apache.ignite.compute.ComputeJob;
 import org.apache.ignite.compute.ComputeJobAdapter;
 import org.apache.ignite.compute.ComputeJobResult;
 import org.apache.ignite.compute.ComputeTaskAdapter;
-import org.apache.ignite.internal.portable.BinaryObjectEx;
+import org.apache.ignite.internal.binary.BinaryObjectEx;
 import org.apache.ignite.internal.util.typedef.F;
 import org.apache.ignite.resources.IgniteInstanceResource;
 import org.jetbrains.annotations.Nullable;
@@ -116,4 +116,4 @@ public class PlatformComputeBinarizableArgTask extends ComputeTaskAdapter<Object
             arg = in.readObject();
         }
     }
-}
\ No newline at end of file
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/1dbf20e0/modules/core/src/test/java/org/apache/ignite/platform/PlatformEventsWriteEventTask.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/platform/PlatformEventsWriteEventTask.java b/modules/core/src/test/java/org/apache/ignite/platform/PlatformEventsWriteEventTask.java
index 84c3584..9fbe272 100644
--- a/modules/core/src/test/java/org/apache/ignite/platform/PlatformEventsWriteEventTask.java
+++ b/modules/core/src/test/java/org/apache/ignite/platform/PlatformEventsWriteEventTask.java
@@ -32,7 +32,7 @@ import org.apache.ignite.events.DiscoveryEvent;
 import org.apache.ignite.events.JobEvent;
 import org.apache.ignite.events.SwapSpaceEvent;
 import org.apache.ignite.events.TaskEvent;
-import org.apache.ignite.internal.portable.BinaryRawWriterEx;
+import org.apache.ignite.internal.binary.BinaryRawWriterEx;
 import org.apache.ignite.internal.processors.platform.PlatformContext;
 import org.apache.ignite.internal.processors.platform.memory.PlatformMemory;
 import org.apache.ignite.internal.processors.platform.memory.PlatformOutputStream;
@@ -141,4 +141,4 @@ public class PlatformEventsWriteEventTask extends ComputeTaskAdapter<Long, Objec
             return true;
         }
     }
-}
\ No newline at end of file
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/1dbf20e0/modules/core/src/test/java/org/apache/ignite/session/GridSessionCheckpointSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/session/GridSessionCheckpointSelfTest.java b/modules/core/src/test/java/org/apache/ignite/session/GridSessionCheckpointSelfTest.java
index 2fd62c1..ded30cb 100644
--- a/modules/core/src/test/java/org/apache/ignite/session/GridSessionCheckpointSelfTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/session/GridSessionCheckpointSelfTest.java
@@ -19,9 +19,9 @@ package org.apache.ignite.session;
 
 import org.apache.ignite.configuration.CacheConfiguration;
 import org.apache.ignite.configuration.IgniteConfiguration;
-import org.apache.ignite.internal.portable.BinaryCachingMetadataHandler;
-import org.apache.ignite.internal.portable.BinaryMarshaller;
-import org.apache.ignite.internal.portable.PortableContext;
+import org.apache.ignite.internal.binary.BinaryCachingMetadataHandler;
+import org.apache.ignite.internal.binary.BinaryMarshaller;
+import org.apache.ignite.internal.binary.PortableContext;
 import org.apache.ignite.internal.util.IgniteUtils;
 import org.apache.ignite.marshaller.Marshaller;
 import org.apache.ignite.marshaller.MarshallerContextTestImpl;
@@ -109,4 +109,4 @@ public class GridSessionCheckpointSelfTest extends GridSessionCheckpointAbstract
 
         checkCheckpoints(cfg);
     }
-}
\ No newline at end of file
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/1dbf20e0/modules/core/src/test/java/org/apache/ignite/testframework/junits/GridAbstractTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/testframework/junits/GridAbstractTest.java b/modules/core/src/test/java/org/apache/ignite/testframework/junits/GridAbstractTest.java
index 2d91895..b83cba9 100644
--- a/modules/core/src/test/java/org/apache/ignite/testframework/junits/GridAbstractTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/testframework/junits/GridAbstractTest.java
@@ -60,8 +60,8 @@ import org.apache.ignite.internal.IgniteEx;
 import org.apache.ignite.internal.IgniteInternalFuture;
 import org.apache.ignite.internal.IgniteKernal;
 import org.apache.ignite.internal.IgnitionEx;
-import org.apache.ignite.internal.portable.BinaryEnumCache;
-import org.apache.ignite.internal.portable.BinaryMarshaller;
+import org.apache.ignite.internal.binary.BinaryEnumCache;
+import org.apache.ignite.internal.binary.BinaryMarshaller;
 import org.apache.ignite.internal.processors.resource.GridSpringResourceContext;
 import org.apache.ignite.internal.util.GridClassLoaderCache;
 import org.apache.ignite.internal.util.GridTestClockTimer;

http://git-wip-us.apache.org/repos/asf/ignite/blob/1dbf20e0/modules/core/src/test/java/org/apache/ignite/testframework/junits/IgniteMock.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/testframework/junits/IgniteMock.java b/modules/core/src/test/java/org/apache/ignite/testframework/junits/IgniteMock.java
index 7f27f36..8c8b831 100644
--- a/modules/core/src/test/java/org/apache/ignite/testframework/junits/IgniteMock.java
+++ b/modules/core/src/test/java/org/apache/ignite/testframework/junits/IgniteMock.java
@@ -50,9 +50,9 @@ import org.apache.ignite.configuration.CacheConfiguration;
 import org.apache.ignite.configuration.CollectionConfiguration;
 import org.apache.ignite.configuration.IgniteConfiguration;
 import org.apache.ignite.configuration.NearCacheConfiguration;
-import org.apache.ignite.internal.portable.BinaryCachingMetadataHandler;
-import org.apache.ignite.internal.portable.PortableContext;
-import org.apache.ignite.internal.portable.builder.BinaryObjectBuilderImpl;
+import org.apache.ignite.internal.binary.BinaryCachingMetadataHandler;
+import org.apache.ignite.internal.binary.PortableContext;
+import org.apache.ignite.internal.binary.builder.BinaryObjectBuilderImpl;
 import org.apache.ignite.internal.processors.cacheobject.NoOpBinary;
 import org.apache.ignite.lang.IgniteProductVersion;
 import org.apache.ignite.marshaller.Marshaller;

http://git-wip-us.apache.org/repos/asf/ignite/blob/1dbf20e0/modules/core/src/test/java/org/apache/ignite/testframework/junits/IgniteTestResources.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/testframework/junits/IgniteTestResources.java b/modules/core/src/test/java/org/apache/ignite/testframework/junits/IgniteTestResources.java
index 097c75f..69ecb4f 100644
--- a/modules/core/src/test/java/org/apache/ignite/testframework/junits/IgniteTestResources.java
+++ b/modules/core/src/test/java/org/apache/ignite/testframework/junits/IgniteTestResources.java
@@ -27,9 +27,9 @@ import javax.management.MBeanServer;
 import org.apache.ignite.IgniteCheckedException;
 import org.apache.ignite.IgniteLogger;
 import org.apache.ignite.configuration.IgniteConfiguration;
-import org.apache.ignite.internal.portable.BinaryCachingMetadataHandler;
-import org.apache.ignite.internal.portable.BinaryMarshaller;
-import org.apache.ignite.internal.portable.PortableContext;
+import org.apache.ignite.internal.binary.BinaryCachingMetadataHandler;
+import org.apache.ignite.internal.binary.BinaryMarshaller;
+import org.apache.ignite.internal.binary.PortableContext;
 import org.apache.ignite.internal.processors.resource.GridResourceProcessor;
 import org.apache.ignite.internal.util.IgniteUtils;
 import org.apache.ignite.internal.util.typedef.internal.U;
@@ -271,4 +271,4 @@ public class IgniteTestResources {
 
         return marsh;
     }
-}
\ No newline at end of file
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/1dbf20e0/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteBinaryObjectsCacheDataStructuresSelfTestSuite.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteBinaryObjectsCacheDataStructuresSelfTestSuite.java b/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteBinaryObjectsCacheDataStructuresSelfTestSuite.java
index d18e3e3..e15540a 100644
--- a/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteBinaryObjectsCacheDataStructuresSelfTestSuite.java
+++ b/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteBinaryObjectsCacheDataStructuresSelfTestSuite.java
@@ -18,7 +18,7 @@
 package org.apache.ignite.testsuites;
 
 import junit.framework.TestSuite;
-import org.apache.ignite.internal.portable.BinaryMarshaller;
+import org.apache.ignite.internal.binary.BinaryMarshaller;
 import org.apache.ignite.testframework.config.GridTestProperties;
 
 /**

http://git-wip-us.apache.org/repos/asf/ignite/blob/1dbf20e0/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteBinaryObjectsCacheExpiryPolicyTestSuite.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteBinaryObjectsCacheExpiryPolicyTestSuite.java b/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteBinaryObjectsCacheExpiryPolicyTestSuite.java
index 8391c54..7cb4051 100644
--- a/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteBinaryObjectsCacheExpiryPolicyTestSuite.java
+++ b/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteBinaryObjectsCacheExpiryPolicyTestSuite.java
@@ -18,7 +18,7 @@
 package org.apache.ignite.testsuites;
 
 import junit.framework.TestSuite;
-import org.apache.ignite.internal.portable.BinaryMarshaller;
+import org.apache.ignite.internal.binary.BinaryMarshaller;
 import org.apache.ignite.internal.processors.cache.expiry.IgniteCacheExpiryPolicyTestSuite;
 import org.apache.ignite.testframework.config.GridTestProperties;
 

http://git-wip-us.apache.org/repos/asf/ignite/blob/1dbf20e0/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteBinaryObjectsCacheRestartTestSuite.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteBinaryObjectsCacheRestartTestSuite.java b/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteBinaryObjectsCacheRestartTestSuite.java
index a739188..e3c9f68 100644
--- a/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteBinaryObjectsCacheRestartTestSuite.java
+++ b/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteBinaryObjectsCacheRestartTestSuite.java
@@ -18,7 +18,7 @@
 package org.apache.ignite.testsuites;
 
 import junit.framework.TestSuite;
-import org.apache.ignite.internal.portable.BinaryMarshaller;
+import org.apache.ignite.internal.binary.BinaryMarshaller;
 import org.apache.ignite.testframework.config.GridTestProperties;
 
 /**

http://git-wip-us.apache.org/repos/asf/ignite/blob/1dbf20e0/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteBinaryObjectsCacheTestSuite2.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteBinaryObjectsCacheTestSuite2.java b/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteBinaryObjectsCacheTestSuite2.java
index e5fa314..c13693b 100644
--- a/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteBinaryObjectsCacheTestSuite2.java
+++ b/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteBinaryObjectsCacheTestSuite2.java
@@ -18,7 +18,7 @@
 package org.apache.ignite.testsuites;
 
 import junit.framework.TestSuite;
-import org.apache.ignite.internal.portable.BinaryMarshaller;
+import org.apache.ignite.internal.binary.BinaryMarshaller;
 import org.apache.ignite.testframework.config.GridTestProperties;
 
 /**

http://git-wip-us.apache.org/repos/asf/ignite/blob/1dbf20e0/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteBinaryObjectsCacheTestSuite3.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteBinaryObjectsCacheTestSuite3.java b/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteBinaryObjectsCacheTestSuite3.java
index 3aecda3..7a6a0a6 100644
--- a/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteBinaryObjectsCacheTestSuite3.java
+++ b/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteBinaryObjectsCacheTestSuite3.java
@@ -18,9 +18,9 @@
 package org.apache.ignite.testsuites;
 
 import junit.framework.TestSuite;
-import org.apache.ignite.internal.portable.BinaryMarshaller;
-import org.apache.ignite.internal.processors.cache.portable.GridCacheBinaryAtomicEntryProcessorDeploymentSelfTest;
-import org.apache.ignite.internal.processors.cache.portable.GridCacheBinaryTransactionalEntryProcessorDeploymentSelfTest;
+import org.apache.ignite.internal.binary.BinaryMarshaller;
+import org.apache.ignite.internal.processors.cache.binary.GridCacheBinaryAtomicEntryProcessorDeploymentSelfTest;
+import org.apache.ignite.internal.processors.cache.binary.GridCacheBinaryTransactionalEntryProcessorDeploymentSelfTest;
 import org.apache.ignite.testframework.config.GridTestProperties;
 
 /**

http://git-wip-us.apache.org/repos/asf/ignite/blob/1dbf20e0/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteBinaryObjectsCacheTestSuite4.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteBinaryObjectsCacheTestSuite4.java b/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteBinaryObjectsCacheTestSuite4.java
index 74c8e61..2292a93 100644
--- a/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteBinaryObjectsCacheTestSuite4.java
+++ b/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteBinaryObjectsCacheTestSuite4.java
@@ -18,7 +18,7 @@
 package org.apache.ignite.testsuites;
 
 import junit.framework.TestSuite;
-import org.apache.ignite.internal.portable.BinaryMarshaller;
+import org.apache.ignite.internal.binary.BinaryMarshaller;
 import org.apache.ignite.testframework.config.GridTestProperties;
 
 /**

http://git-wip-us.apache.org/repos/asf/ignite/blob/1dbf20e0/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteBinaryObjectsComputeGridTestSuite.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteBinaryObjectsComputeGridTestSuite.java b/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteBinaryObjectsComputeGridTestSuite.java
index a53187c..35be98d 100644
--- a/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteBinaryObjectsComputeGridTestSuite.java
+++ b/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteBinaryObjectsComputeGridTestSuite.java
@@ -18,7 +18,7 @@
 package org.apache.ignite.testsuites;
 
 import junit.framework.TestSuite;
-import org.apache.ignite.internal.portable.BinaryMarshaller;
+import org.apache.ignite.internal.binary.BinaryMarshaller;
 import org.apache.ignite.testframework.config.GridTestProperties;
 
 /**

http://git-wip-us.apache.org/repos/asf/ignite/blob/1dbf20e0/modules/core/src/test/java/org/apache/ignite/testsuites/IgnitePortableCacheFullApiTestSuite.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/testsuites/IgnitePortableCacheFullApiTestSuite.java b/modules/core/src/test/java/org/apache/ignite/testsuites/IgnitePortableCacheFullApiTestSuite.java
index f0f5fcc..3ba5b45 100644
--- a/modules/core/src/test/java/org/apache/ignite/testsuites/IgnitePortableCacheFullApiTestSuite.java
+++ b/modules/core/src/test/java/org/apache/ignite/testsuites/IgnitePortableCacheFullApiTestSuite.java
@@ -18,7 +18,7 @@
 package org.apache.ignite.testsuites;
 
 import junit.framework.TestSuite;
-import org.apache.ignite.internal.portable.BinaryMarshaller;
+import org.apache.ignite.internal.binary.BinaryMarshaller;
 import org.apache.ignite.testframework.config.GridTestProperties;
 
 /**
@@ -34,4 +34,4 @@ public class IgnitePortableCacheFullApiTestSuite extends TestSuite {
 
         return IgniteCacheFullApiSelfTestSuite.suite();
     }
-}
\ No newline at end of file
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/1dbf20e0/modules/core/src/test/java/org/apache/ignite/testsuites/IgnitePortableCacheTestSuite.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/testsuites/IgnitePortableCacheTestSuite.java b/modules/core/src/test/java/org/apache/ignite/testsuites/IgnitePortableCacheTestSuite.java
index efe4d2a..f569718 100644
--- a/modules/core/src/test/java/org/apache/ignite/testsuites/IgnitePortableCacheTestSuite.java
+++ b/modules/core/src/test/java/org/apache/ignite/testsuites/IgnitePortableCacheTestSuite.java
@@ -19,7 +19,7 @@ package org.apache.ignite.testsuites;
 
 import java.util.HashSet;
 import junit.framework.TestSuite;
-import org.apache.ignite.internal.portable.BinaryMarshaller;
+import org.apache.ignite.internal.binary.BinaryMarshaller;
 import org.apache.ignite.internal.processors.cache.GridCacheAffinityRoutingSelfTest;
 import org.apache.ignite.internal.processors.cache.GridCacheEntryMemorySizeSelfTest;
 import org.apache.ignite.internal.processors.cache.GridCacheMvccSelfTest;
@@ -28,21 +28,21 @@ import org.apache.ignite.internal.processors.cache.GridCacheOffHeapTieredEvictio
 import org.apache.ignite.internal.processors.cache.GridCacheOffHeapTieredEvictionSelfTest;
 import org.apache.ignite.internal.processors.cache.GridCacheOffHeapTieredSelfTest;
 import org.apache.ignite.internal.processors.cache.expiry.IgniteCacheAtomicLocalExpiryPolicyTest;
-import org.apache.ignite.internal.processors.cache.portable.GridPortableCacheEntryMemorySizeSelfTest;
-import org.apache.ignite.internal.processors.cache.portable.datastreaming.DataStreamProcessorPortableSelfTest;
-import org.apache.ignite.internal.processors.cache.portable.datastreaming.GridDataStreamerImplSelfTest;
-import org.apache.ignite.internal.processors.cache.portable.distributed.dht.GridCacheAffinityRoutingPortableSelfTest;
-import org.apache.ignite.internal.processors.cache.portable.distributed.dht.GridCacheAtomicPartitionedOnlyPortableDataStreamerMultiNodeSelfTest;
-import org.apache.ignite.internal.processors.cache.portable.distributed.dht.GridCacheAtomicPartitionedOnlyPortableDataStreamerMultithreadedSelfTest;
-import org.apache.ignite.internal.processors.cache.portable.distributed.dht.GridCacheAtomicPartitionedOnlyPortableMultiNodeSelfTest;
-import org.apache.ignite.internal.processors.cache.portable.distributed.dht.GridCacheAtomicPartitionedOnlyPortableMultithreadedSelfTest;
-import org.apache.ignite.internal.processors.cache.portable.distributed.dht.GridCacheMemoryModePortableSelfTest;
-import org.apache.ignite.internal.processors.cache.portable.distributed.dht.GridCacheOffHeapTieredAtomicPortableSelfTest;
-import org.apache.ignite.internal.processors.cache.portable.distributed.dht.GridCacheOffHeapTieredEvictionAtomicPortableSelfTest;
-import org.apache.ignite.internal.processors.cache.portable.distributed.dht.GridCacheOffHeapTieredEvictionPortableSelfTest;
-import org.apache.ignite.internal.processors.cache.portable.distributed.dht.GridCacheOffHeapTieredPortableSelfTest;
-import org.apache.ignite.internal.processors.cache.portable.distributed.dht.GridCachePortablesNearPartitionedByteArrayValuesSelfTest;
-import org.apache.ignite.internal.processors.cache.portable.distributed.dht.GridCachePortablesPartitionedOnlyByteArrayValuesSelfTest;
+import org.apache.ignite.internal.processors.cache.binary.GridPortableCacheEntryMemorySizeSelfTest;
+import org.apache.ignite.internal.processors.cache.binary.datastreaming.DataStreamProcessorPortableSelfTest;
+import org.apache.ignite.internal.processors.cache.binary.datastreaming.GridDataStreamerImplSelfTest;
+import org.apache.ignite.internal.processors.cache.binary.distributed.dht.GridCacheAffinityRoutingPortableSelfTest;
+import org.apache.ignite.internal.processors.cache.binary.distributed.dht.GridCacheAtomicPartitionedOnlyPortableDataStreamerMultiNodeSelfTest;
+import org.apache.ignite.internal.processors.cache.binary.distributed.dht.GridCacheAtomicPartitionedOnlyPortableDataStreamerMultithreadedSelfTest;
+import org.apache.ignite.internal.processors.cache.binary.distributed.dht.GridCacheAtomicPartitionedOnlyPortableMultiNodeSelfTest;
+import org.apache.ignite.internal.processors.cache.binary.distributed.dht.GridCacheAtomicPartitionedOnlyPortableMultithreadedSelfTest;
+import org.apache.ignite.internal.processors.cache.binary.distributed.dht.GridCacheMemoryModePortableSelfTest;
+import org.apache.ignite.internal.processors.cache.binary.distributed.dht.GridCacheOffHeapTieredAtomicPortableSelfTest;
+import org.apache.ignite.internal.processors.cache.binary.distributed.dht.GridCacheOffHeapTieredEvictionAtomicPortableSelfTest;
+import org.apache.ignite.internal.processors.cache.binary.distributed.dht.GridCacheOffHeapTieredEvictionPortableSelfTest;
+import org.apache.ignite.internal.processors.cache.binary.distributed.dht.GridCacheOffHeapTieredPortableSelfTest;
+import org.apache.ignite.internal.processors.cache.binary.distributed.dht.GridCachePortablesNearPartitionedByteArrayValuesSelfTest;
+import org.apache.ignite.internal.processors.cache.binary.distributed.dht.GridCachePortablesPartitionedOnlyByteArrayValuesSelfTest;
 import org.apache.ignite.internal.processors.datastreamer.DataStreamProcessorSelfTest;
 import org.apache.ignite.testframework.config.GridTestProperties;
 
@@ -98,4 +98,4 @@ public class IgnitePortableCacheTestSuite extends TestSuite {
 
         return suite;
     }
-}
\ No newline at end of file
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/1dbf20e0/modules/core/src/test/java/org/apache/ignite/testsuites/IgnitePortableObjectsTestSuite.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/testsuites/IgnitePortableObjectsTestSuite.java b/modules/core/src/test/java/org/apache/ignite/testsuites/IgnitePortableObjectsTestSuite.java
index 62952b5..4329225 100644
--- a/modules/core/src/test/java/org/apache/ignite/testsuites/IgnitePortableObjectsTestSuite.java
+++ b/modules/core/src/test/java/org/apache/ignite/testsuites/IgnitePortableObjectsTestSuite.java
@@ -18,42 +18,42 @@
 package org.apache.ignite.testsuites;
 
 import junit.framework.TestSuite;
-import org.apache.ignite.internal.portable.BinaryEnumsSelfTest;
-import org.apache.ignite.internal.portable.GridPortableAffinityKeySelfTest;
-import org.apache.ignite.internal.portable.BinaryObjectBuilderAdditionalSelfTest;
-import org.apache.ignite.internal.portable.BinaryObjectBuilderSelfTest;
-import org.apache.ignite.internal.portable.GridPortableMarshallerCtxDisabledSelfTest;
-import org.apache.ignite.internal.portable.BinaryMarshallerSelfTest;
-import org.apache.ignite.internal.portable.GridPortableMetaDataSelfTest;
-import org.apache.ignite.internal.portable.GridPortableWildcardsSelfTest;
-import org.apache.ignite.internal.portable.BinaryFooterOffsetsHeapSelfTest;
-import org.apache.ignite.internal.portable.BinaryFooterOffsetsOffheapSelfTest;
-import org.apache.ignite.internal.portable.BinaryFieldsHeapSelfTest;
-import org.apache.ignite.internal.portable.BinaryFieldsOffheapSelfTest;
-import org.apache.ignite.internal.portable.noncompact.BinaryFieldsHeapNonCompactSelfTest;
-import org.apache.ignite.internal.portable.noncompact.BinaryFieldsOffheapNonCompactSelfTest;
-import org.apache.ignite.internal.portable.noncompact.BinaryFooterOffsetsHeapNonCompactSelfTest;
-import org.apache.ignite.internal.portable.noncompact.BinaryFooterOffsetsOffheapNonCompactSelfTest;
-import org.apache.ignite.internal.portable.noncompact.BinaryMarshallerNonCompactSelfTest;
-import org.apache.ignite.internal.portable.noncompact.BinaryObjectBuilderAdditionalNonCompactSelfTest;
-import org.apache.ignite.internal.portable.noncompact.BinaryObjectBuilderNonCompactSelfTest;
+import org.apache.ignite.internal.binary.BinaryEnumsSelfTest;
+import org.apache.ignite.internal.binary.GridPortableAffinityKeySelfTest;
+import org.apache.ignite.internal.binary.BinaryObjectBuilderAdditionalSelfTest;
+import org.apache.ignite.internal.binary.BinaryObjectBuilderSelfTest;
+import org.apache.ignite.internal.binary.GridPortableMarshallerCtxDisabledSelfTest;
+import org.apache.ignite.internal.binary.BinaryMarshallerSelfTest;
+import org.apache.ignite.internal.binary.GridPortableMetaDataSelfTest;
+import org.apache.ignite.internal.binary.GridPortableWildcardsSelfTest;
+import org.apache.ignite.internal.binary.BinaryFooterOffsetsHeapSelfTest;
+import org.apache.ignite.internal.binary.BinaryFooterOffsetsOffheapSelfTest;
+import org.apache.ignite.internal.binary.BinaryFieldsHeapSelfTest;
+import org.apache.ignite.internal.binary.BinaryFieldsOffheapSelfTest;
+import org.apache.ignite.internal.binary.noncompact.BinaryFieldsHeapNonCompactSelfTest;
+import org.apache.ignite.internal.binary.noncompact.BinaryFieldsOffheapNonCompactSelfTest;
+import org.apache.ignite.internal.binary.noncompact.BinaryFooterOffsetsHeapNonCompactSelfTest;
+import org.apache.ignite.internal.binary.noncompact.BinaryFooterOffsetsOffheapNonCompactSelfTest;
+import org.apache.ignite.internal.binary.noncompact.BinaryMarshallerNonCompactSelfTest;
+import org.apache.ignite.internal.binary.noncompact.BinaryObjectBuilderAdditionalNonCompactSelfTest;
+import org.apache.ignite.internal.binary.noncompact.BinaryObjectBuilderNonCompactSelfTest;
 import org.apache.ignite.internal.processors.cache.distributed.IgniteBinaryMetadataUpdateChangingTopologySelfTest;
-import org.apache.ignite.internal.processors.cache.portable.GridCacheClientNodeBinaryObjectMetadataMultinodeTest;
-import org.apache.ignite.internal.processors.cache.portable.GridCacheClientNodeBinaryObjectMetadataTest;
-import org.apache.ignite.internal.processors.cache.portable.GridCachePortableStoreObjectsSelfTest;
-import org.apache.ignite.internal.processors.cache.portable.GridCachePortableStorePortablesSelfTest;
-import org.apache.ignite.internal.processors.cache.portable.distributed.dht.GridCacheBinaryObjectsAtomicNearDisabledOffheapTieredSelfTest;
-import org.apache.ignite.internal.processors.cache.portable.distributed.dht.GridCacheBinaryObjectsAtomicNearDisabledSelfTest;
-import org.apache.ignite.internal.processors.cache.portable.distributed.dht.GridCacheBinaryObjectsAtomicOffheapTieredSelfTest;
-import org.apache.ignite.internal.processors.cache.portable.distributed.dht.GridCacheBinaryObjectsAtomicSelfTest;
-import org.apache.ignite.internal.processors.cache.portable.distributed.dht.GridCacheBinaryObjectsPartitionedNearDisabledOffheapTieredSelfTest;
-import org.apache.ignite.internal.processors.cache.portable.distributed.dht.GridCacheBinaryObjectsPartitionedNearDisabledSelfTest;
-import org.apache.ignite.internal.processors.cache.portable.distributed.dht.GridCacheBinaryObjectsPartitionedOffheapTieredSelfTest;
-import org.apache.ignite.internal.processors.cache.portable.distributed.dht.GridCacheBinaryObjectsPartitionedSelfTest;
-import org.apache.ignite.internal.processors.cache.portable.distributed.replicated.GridCacheBinaryObjectsReplicatedSelfTest;
-import org.apache.ignite.internal.processors.cache.portable.local.GridCacheBinaryObjectsAtomicLocalSelfTest;
-import org.apache.ignite.internal.processors.cache.portable.local.GridCacheBinaryObjectsLocalOffheapTieredSelfTest;
-import org.apache.ignite.internal.processors.cache.portable.local.GridCacheBinaryObjectsLocalSelfTest;
+import org.apache.ignite.internal.processors.cache.binary.GridCacheClientNodeBinaryObjectMetadataMultinodeTest;
+import org.apache.ignite.internal.processors.cache.binary.GridCacheClientNodeBinaryObjectMetadataTest;
+import org.apache.ignite.internal.processors.cache.binary.GridCachePortableStoreObjectsSelfTest;
+import org.apache.ignite.internal.processors.cache.binary.GridCachePortableStorePortablesSelfTest;
+import org.apache.ignite.internal.processors.cache.binary.distributed.dht.GridCacheBinaryObjectsAtomicNearDisabledOffheapTieredSelfTest;
+import org.apache.ignite.internal.processors.cache.binary.distributed.dht.GridCacheBinaryObjectsAtomicNearDisabledSelfTest;
+import org.apache.ignite.internal.processors.cache.binary.distributed.dht.GridCacheBinaryObjectsAtomicOffheapTieredSelfTest;
+import org.apache.ignite.internal.processors.cache.binary.distributed.dht.GridCacheBinaryObjectsAtomicSelfTest;
+import org.apache.ignite.internal.processors.cache.binary.distributed.dht.GridCacheBinaryObjectsPartitionedNearDisabledOffheapTieredSelfTest;
+import org.apache.ignite.internal.processors.cache.binary.distributed.dht.GridCacheBinaryObjectsPartitionedNearDisabledSelfTest;
+import org.apache.ignite.internal.processors.cache.binary.distributed.dht.GridCacheBinaryObjectsPartitionedOffheapTieredSelfTest;
+import org.apache.ignite.internal.processors.cache.binary.distributed.dht.GridCacheBinaryObjectsPartitionedSelfTest;
+import org.apache.ignite.internal.processors.cache.binary.distributed.replicated.GridCacheBinaryObjectsReplicatedSelfTest;
+import org.apache.ignite.internal.processors.cache.binary.local.GridCacheBinaryObjectsAtomicLocalSelfTest;
+import org.apache.ignite.internal.processors.cache.binary.local.GridCacheBinaryObjectsLocalOffheapTieredSelfTest;
+import org.apache.ignite.internal.processors.cache.binary.local.GridCacheBinaryObjectsLocalSelfTest;
 
 /**
  * Test for portable objects stored in cache.

http://git-wip-us.apache.org/repos/asf/ignite/blob/1dbf20e0/modules/core/src/test/portables/repo/org/apache/ignite/portable/test1/1.1/test1-1.1.pom
----------------------------------------------------------------------
diff --git a/modules/core/src/test/portables/repo/org/apache/ignite/portable/test1/1.1/test1-1.1.pom b/modules/core/src/test/portables/repo/org/apache/ignite/portable/test1/1.1/test1-1.1.pom
index c79dfbf..533a3c9 100644
--- a/modules/core/src/test/portables/repo/org/apache/ignite/portable/test1/1.1/test1-1.1.pom
+++ b/modules/core/src/test/portables/repo/org/apache/ignite/portable/test1/1.1/test1-1.1.pom
@@ -2,7 +2,7 @@
 <project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
   <modelVersion>4.0.0</modelVersion>
-  <groupId>org.apache.ignite.portable</groupId>
+  <groupId>org.apache.ignite.binary</groupId>
   <artifactId>test1</artifactId>
   <version>1.1</version>
   <description>POM was created from install:install-file</description>

http://git-wip-us.apache.org/repos/asf/ignite/blob/1dbf20e0/modules/core/src/test/portables/repo/org/apache/ignite/portable/test1/maven-metadata-local.xml
----------------------------------------------------------------------
diff --git a/modules/core/src/test/portables/repo/org/apache/ignite/portable/test1/maven-metadata-local.xml b/modules/core/src/test/portables/repo/org/apache/ignite/portable/test1/maven-metadata-local.xml
index 33f5abf..4ca5d44 100644
--- a/modules/core/src/test/portables/repo/org/apache/ignite/portable/test1/maven-metadata-local.xml
+++ b/modules/core/src/test/portables/repo/org/apache/ignite/portable/test1/maven-metadata-local.xml
@@ -1,6 +1,6 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <metadata>
-  <groupId>org.apache.ignite.portable</groupId>
+  <groupId>org.apache.ignite.binary</groupId>
   <artifactId>test1</artifactId>
   <versioning>
     <release>1.1</release>

http://git-wip-us.apache.org/repos/asf/ignite/blob/1dbf20e0/modules/core/src/test/portables/repo/org/apache/ignite/portable/test2/1.1/test2-1.1.pom
----------------------------------------------------------------------
diff --git a/modules/core/src/test/portables/repo/org/apache/ignite/portable/test2/1.1/test2-1.1.pom b/modules/core/src/test/portables/repo/org/apache/ignite/portable/test2/1.1/test2-1.1.pom
index 37621e1..2eaaeff 100644
--- a/modules/core/src/test/portables/repo/org/apache/ignite/portable/test2/1.1/test2-1.1.pom
+++ b/modules/core/src/test/portables/repo/org/apache/ignite/portable/test2/1.1/test2-1.1.pom
@@ -2,7 +2,7 @@
 <project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
   <modelVersion>4.0.0</modelVersion>
-  <groupId>org.apache.ignite.portable</groupId>
+  <groupId>org.apache.ignite.binary</groupId>
   <artifactId>test2</artifactId>
   <version>1.1</version>
   <description>POM was created from install:install-file</description>

http://git-wip-us.apache.org/repos/asf/ignite/blob/1dbf20e0/modules/core/src/test/portables/repo/org/apache/ignite/portable/test2/maven-metadata-local.xml
----------------------------------------------------------------------
diff --git a/modules/core/src/test/portables/repo/org/apache/ignite/portable/test2/maven-metadata-local.xml b/modules/core/src/test/portables/repo/org/apache/ignite/portable/test2/maven-metadata-local.xml
index 9c705ef..c45c88f 100644
--- a/modules/core/src/test/portables/repo/org/apache/ignite/portable/test2/maven-metadata-local.xml
+++ b/modules/core/src/test/portables/repo/org/apache/ignite/portable/test2/maven-metadata-local.xml
@@ -1,6 +1,6 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <metadata>
-  <groupId>org.apache.ignite.portable</groupId>
+  <groupId>org.apache.ignite.binary</groupId>
   <artifactId>test2</artifactId>
   <versioning>
     <release>1.1</release>

http://git-wip-us.apache.org/repos/asf/ignite/blob/1dbf20e0/modules/indexing/src/test/java/org/apache/ignite/testsuites/IgnitePortableCacheQueryTestSuite.java
----------------------------------------------------------------------
diff --git a/modules/indexing/src/test/java/org/apache/ignite/testsuites/IgnitePortableCacheQueryTestSuite.java b/modules/indexing/src/test/java/org/apache/ignite/testsuites/IgnitePortableCacheQueryTestSuite.java
index 4e9be93..da34d75 100644
--- a/modules/indexing/src/test/java/org/apache/ignite/testsuites/IgnitePortableCacheQueryTestSuite.java
+++ b/modules/indexing/src/test/java/org/apache/ignite/testsuites/IgnitePortableCacheQueryTestSuite.java
@@ -34,8 +34,8 @@ import org.apache.ignite.internal.processors.cache.IgniteCachePartitionedQueryMu
 import org.apache.ignite.internal.processors.cache.IgniteCacheQueryEvictsMultiThreadedSelfTest;
 import org.apache.ignite.internal.processors.cache.IgniteCacheQueryMultiThreadedSelfTest;
 import org.apache.ignite.internal.processors.cache.IgniteCacheQueryOffheapMultiThreadedSelfTest;
-import org.apache.ignite.internal.processors.cache.portable.distributed.dht.GridCachePortableDuplicateIndexObjectPartitionedAtomicSelfTest;
-import org.apache.ignite.internal.processors.cache.portable.distributed.dht.GridCachePortableDuplicateIndexObjectPartitionedTransactionalSelfTest;
+import org.apache.ignite.internal.processors.cache.binary.distributed.dht.GridCachePortableDuplicateIndexObjectPartitionedAtomicSelfTest;
+import org.apache.ignite.internal.processors.cache.binary.distributed.dht.GridCachePortableDuplicateIndexObjectPartitionedTransactionalSelfTest;
 import org.apache.ignite.internal.processors.cache.query.continuous.GridCacheContinuousQueryAtomicNearEnabledSelfTest;
 import org.apache.ignite.internal.processors.cache.query.continuous.GridCacheContinuousQueryAtomicP2PDisabledSelfTest;
 import org.apache.ignite.internal.processors.cache.query.continuous.GridCacheContinuousQueryAtomicSelfTest;
@@ -45,7 +45,7 @@ import org.apache.ignite.internal.processors.cache.query.continuous.GridCacheCon
 import org.apache.ignite.internal.processors.query.h2.sql.BaseH2CompareQueryTest;
 import org.apache.ignite.internal.processors.query.h2.sql.GridQueryParsingTest;
 import org.apache.ignite.internal.processors.query.h2.sql.H2CompareBigQueryTest;
-import org.apache.ignite.internal.portable.BinaryMarshaller;
+import org.apache.ignite.internal.binary.BinaryMarshaller;
 import org.apache.ignite.spi.communication.tcp.GridOrderedMessageCancelSelfTest;
 import org.apache.ignite.testframework.config.GridTestProperties;
 
@@ -114,4 +114,4 @@ public class IgnitePortableCacheQueryTestSuite extends TestSuite {
 
         return suite;
     }
-}
\ No newline at end of file
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/1dbf20e0/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Config/marshaller-explicit.xml
----------------------------------------------------------------------
diff --git a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Config/marshaller-explicit.xml b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Config/marshaller-explicit.xml
index 366ac13..0d0e911 100644
--- a/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Config/marshaller-explicit.xml
+++ b/modules/platforms/dotnet/Apache.Ignite.Core.Tests/Config/marshaller-explicit.xml
@@ -32,7 +32,7 @@
         </property>
 
         <property name="marshaller">
-            <bean class="org.apache.ignite.internal.portable.BinaryMarshaller"/>
+            <bean class="org.apache.ignite.internal.binary.BinaryMarshaller"/>
         </property>
 
         <property name="discoverySpi">

http://git-wip-us.apache.org/repos/asf/ignite/blob/1dbf20e0/modules/yardstick/config/ignite-int-max-values-offheap-config.xml
----------------------------------------------------------------------
diff --git a/modules/yardstick/config/ignite-int-max-values-offheap-config.xml b/modules/yardstick/config/ignite-int-max-values-offheap-config.xml
index 1aaab67..86e9656 100644
--- a/modules/yardstick/config/ignite-int-max-values-offheap-config.xml
+++ b/modules/yardstick/config/ignite-int-max-values-offheap-config.xml
@@ -36,7 +36,7 @@
 
 <!--
         <property name="marshaller">
-            <bean class="org.apache.ignite.internal.portable.api.PortableMarshaller"/>
+            <bean class="org.apache.ignite.internal.binary.BinaryMarshaller"/>
         </property>
 -->
 

http://git-wip-us.apache.org/repos/asf/ignite/blob/1dbf20e0/modules/yardstick/config/ignite-int-max-values-onheap-config.xml
----------------------------------------------------------------------
diff --git a/modules/yardstick/config/ignite-int-max-values-onheap-config.xml b/modules/yardstick/config/ignite-int-max-values-onheap-config.xml
index d1359b3..65f51b9 100644
--- a/modules/yardstick/config/ignite-int-max-values-onheap-config.xml
+++ b/modules/yardstick/config/ignite-int-max-values-onheap-config.xml
@@ -36,7 +36,7 @@
 
 <!--
         <property name="marshaller">
-            <bean class="org.apache.ignite.internal.portable.api.PortableMarshaller"/>
+            <bean class="org.apache.ignite.internal.binary.BinaryMarshaller"/>
         </property>
 -->
 

http://git-wip-us.apache.org/repos/asf/ignite/blob/1dbf20e0/modules/yardstick/config/ignite-int-max-values-swap-config.xml
----------------------------------------------------------------------
diff --git a/modules/yardstick/config/ignite-int-max-values-swap-config.xml b/modules/yardstick/config/ignite-int-max-values-swap-config.xml
index 8634b4f..edb15d3 100644
--- a/modules/yardstick/config/ignite-int-max-values-swap-config.xml
+++ b/modules/yardstick/config/ignite-int-max-values-swap-config.xml
@@ -36,7 +36,7 @@
 
 <!--
         <property name="marshaller">
-            <bean class="org.apache.ignite.internal.portable.api.PortableMarshaller"/>
+            <bean class="org.apache.ignite.internal.binary.BinaryMarshaller"/>
         </property>
 -->
 


[26/59] [abbrv] ignite git commit: ignite-2065: rename "portable" packages to "binary"

Posted by ak...@apache.org.
http://git-wip-us.apache.org/repos/asf/ignite/blob/1dbf20e0/modules/core/src/main/java/org/apache/ignite/internal/binary/PortableSchemaRegistry.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/binary/PortableSchemaRegistry.java b/modules/core/src/main/java/org/apache/ignite/internal/binary/PortableSchemaRegistry.java
new file mode 100644
index 0000000..f3f92ee
--- /dev/null
+++ b/modules/core/src/main/java/org/apache/ignite/internal/binary/PortableSchemaRegistry.java
@@ -0,0 +1,172 @@
+/*
+ * 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.binary;
+
+import org.jetbrains.annotations.Nullable;
+
+import java.util.HashMap;
+
+/**
+ * Portable schema registry. Contains all well-known object schemas.
+ * <p>
+ * We rely on the fact that usually object has only few different schemas. For this reason we inline several
+ * of them with optional fallback to normal hash map lookup.
+ *
+ */
+public class PortableSchemaRegistry {
+    /** Empty schema ID. */
+    private static final int EMPTY = 0;
+
+    /** Whether registry still works in inline mode. */
+    private volatile boolean inline = true;
+
+    /** First schema ID. */
+    private int schemaId1;
+
+    /** Second schema ID. */
+    private int schemaId2;
+
+    /** Third schema ID. */
+    private int schemaId3;
+
+    /** Fourth schema ID. */
+    private int schemaId4;
+
+    /** First schema. */
+    private PortableSchema schema1;
+
+    /** Second schema. */
+    private PortableSchema schema2;
+
+    /** Third schema. */
+    private PortableSchema schema3;
+
+    /** Fourth schema. */
+    private PortableSchema schema4;
+
+    /** Schemas with COW semantics. */
+    private volatile HashMap<Integer, PortableSchema> schemas;
+
+    /**
+     * Get schema for the given ID. We rely on very relaxed memory semantics here assuming that it is not critical
+     * to return false-positive {@code null} values.
+     *
+     * @param schemaId Schema ID.
+     * @return Schema or {@code null}.
+     */
+    @Nullable public PortableSchema schema(int schemaId) {
+        if (inline) {
+            if (schemaId == schemaId1)
+                return schema1;
+            else if (schemaId == schemaId2)
+                return schema2;
+            else if (schemaId == schemaId3)
+                return schema3;
+            else if (schemaId == schemaId4)
+                return schema4;
+        }
+        else {
+            HashMap<Integer, PortableSchema> schemas0 = schemas;
+
+            // Null can be observed here due to either data race or race condition when switching to non-inlined mode.
+            // Both of them are benign for us because they lead only to unnecessary schema re-calc.
+            if (schemas0 != null)
+                return schemas0.get(schemaId);
+        }
+
+        return null;
+    }
+
+    /**
+     * Add schema.
+     *
+     * @param schemaId Schema ID.
+     * @param schema Schema.
+     */
+    public void addSchema(int schemaId, PortableSchema schema) {
+        synchronized (this) {
+            if (inline) {
+                // Check if this is already known schema.
+                if (schemaId == schemaId1 || schemaId == schemaId2 || schemaId == schemaId3 || schemaId == schemaId4)
+                    return;
+
+                // Try positioning new schema in inline mode.
+                if (schemaId1 == EMPTY) {
+                    schemaId1 = schemaId;
+
+                    schema1 = schema;
+
+                    inline = true; // Forcing HB edge just in case.
+
+                    return;
+                }
+
+                if (schemaId2 == EMPTY) {
+                    schemaId2 = schemaId;
+
+                    schema2 = schema;
+
+                    inline = true; // Forcing HB edge just in case.
+
+                    return;
+                }
+
+                if (schemaId3 == EMPTY) {
+                    schemaId3 = schemaId;
+
+                    schema3 = schema;
+
+                    inline = true; // Forcing HB edge just in case.
+
+                    return;
+                }
+
+                if (schemaId4 == EMPTY) {
+                    schemaId4 = schemaId;
+
+                    schema4 = schema;
+
+                    inline = true; // Forcing HB edge just in case.
+
+                    return;
+                }
+
+                // No luck, switching to hash map mode.
+                HashMap<Integer, PortableSchema> newSchemas = new HashMap<>();
+
+                newSchemas.put(schemaId1, schema1);
+                newSchemas.put(schemaId2, schema2);
+                newSchemas.put(schemaId3, schema3);
+                newSchemas.put(schemaId4, schema4);
+
+                newSchemas.put(schemaId, schema);
+
+                schemas = newSchemas;
+
+                inline = false;
+            }
+            else {
+                HashMap<Integer, PortableSchema> newSchemas = new HashMap<>(schemas);
+
+                newSchemas.put(schemaId, schema);
+
+                schemas = newSchemas;
+            }
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/1dbf20e0/modules/core/src/main/java/org/apache/ignite/internal/binary/PortableUtils.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/binary/PortableUtils.java b/modules/core/src/main/java/org/apache/ignite/internal/binary/PortableUtils.java
new file mode 100644
index 0000000..979b70c
--- /dev/null
+++ b/modules/core/src/main/java/org/apache/ignite/internal/binary/PortableUtils.java
@@ -0,0 +1,1909 @@
+/*
+ * 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.binary;
+
+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;
+import org.apache.ignite.internal.binary.builder.PortableLazyValue;
+import org.apache.ignite.internal.binary.streams.PortableInputStream;
+import org.apache.ignite.internal.binary.builder.PortableLazyValue;
+import org.apache.ignite.internal.binary.streams.PortableInputStream;
+import org.apache.ignite.internal.util.typedef.F;
+import org.apache.ignite.internal.util.typedef.internal.U;
+import org.apache.ignite.lang.IgniteBiTuple;
+import org.jetbrains.annotations.Nullable;
+import org.jsr166.ConcurrentHashMap8;
+
+import java.io.ByteArrayInputStream;
+import java.io.Externalizable;
+import java.lang.reflect.Array;
+import java.math.BigDecimal;
+import java.math.BigInteger;
+import java.sql.Timestamp;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.LinkedHashMap;
+import java.util.LinkedHashSet;
+import java.util.LinkedList;
+import java.util.Map;
+import java.util.Set;
+import java.util.TreeMap;
+import java.util.TreeSet;
+import java.util.UUID;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ConcurrentSkipListSet;
+
+import static java.nio.charset.StandardCharsets.UTF_8;
+import static org.apache.ignite.internal.binary.GridPortableMarshaller.ARR_LIST;
+import static org.apache.ignite.internal.binary.GridPortableMarshaller.BOOLEAN;
+import static org.apache.ignite.internal.binary.GridPortableMarshaller.BOOLEAN_ARR;
+import static org.apache.ignite.internal.binary.GridPortableMarshaller.BYTE;
+import static org.apache.ignite.internal.binary.GridPortableMarshaller.BYTE_ARR;
+import static org.apache.ignite.internal.binary.GridPortableMarshaller.CHAR;
+import static org.apache.ignite.internal.binary.GridPortableMarshaller.CHAR_ARR;
+import static org.apache.ignite.internal.binary.GridPortableMarshaller.CLASS;
+import static org.apache.ignite.internal.binary.GridPortableMarshaller.COL;
+import static org.apache.ignite.internal.binary.GridPortableMarshaller.DATE;
+import static org.apache.ignite.internal.binary.GridPortableMarshaller.DATE_ARR;
+import static org.apache.ignite.internal.binary.GridPortableMarshaller.DECIMAL;
+import static org.apache.ignite.internal.binary.GridPortableMarshaller.DECIMAL_ARR;
+import static org.apache.ignite.internal.binary.GridPortableMarshaller.DOUBLE;
+import static org.apache.ignite.internal.binary.GridPortableMarshaller.DOUBLE_ARR;
+import static org.apache.ignite.internal.binary.GridPortableMarshaller.ENUM;
+import static org.apache.ignite.internal.binary.GridPortableMarshaller.ENUM_ARR;
+import static org.apache.ignite.internal.binary.GridPortableMarshaller.FLOAT;
+import static org.apache.ignite.internal.binary.GridPortableMarshaller.FLOAT_ARR;
+import static org.apache.ignite.internal.binary.GridPortableMarshaller.HANDLE;
+import static org.apache.ignite.internal.binary.GridPortableMarshaller.HASH_MAP;
+import static org.apache.ignite.internal.binary.GridPortableMarshaller.HASH_SET;
+import static org.apache.ignite.internal.binary.GridPortableMarshaller.INT;
+import static org.apache.ignite.internal.binary.GridPortableMarshaller.INT_ARR;
+import static org.apache.ignite.internal.binary.GridPortableMarshaller.LINKED_HASH_MAP;
+import static org.apache.ignite.internal.binary.GridPortableMarshaller.LINKED_HASH_SET;
+import static org.apache.ignite.internal.binary.GridPortableMarshaller.LINKED_LIST;
+import static org.apache.ignite.internal.binary.GridPortableMarshaller.LONG;
+import static org.apache.ignite.internal.binary.GridPortableMarshaller.LONG_ARR;
+import static org.apache.ignite.internal.binary.GridPortableMarshaller.MAP;
+import static org.apache.ignite.internal.binary.GridPortableMarshaller.NULL;
+import static org.apache.ignite.internal.binary.GridPortableMarshaller.OBJ;
+import static org.apache.ignite.internal.binary.GridPortableMarshaller.OBJECT_TYPE_ID;
+import static org.apache.ignite.internal.binary.GridPortableMarshaller.OBJ_ARR;
+import static org.apache.ignite.internal.binary.GridPortableMarshaller.OPTM_MARSH;
+import static org.apache.ignite.internal.binary.GridPortableMarshaller.PORTABLE_OBJ;
+import static org.apache.ignite.internal.binary.GridPortableMarshaller.PROTO_VER;
+import static org.apache.ignite.internal.binary.GridPortableMarshaller.SHORT;
+import static org.apache.ignite.internal.binary.GridPortableMarshaller.SHORT_ARR;
+import static org.apache.ignite.internal.binary.GridPortableMarshaller.STRING;
+import static org.apache.ignite.internal.binary.GridPortableMarshaller.STRING_ARR;
+import static org.apache.ignite.internal.binary.GridPortableMarshaller.TIMESTAMP;
+import static org.apache.ignite.internal.binary.GridPortableMarshaller.TIMESTAMP_ARR;
+import static org.apache.ignite.internal.binary.GridPortableMarshaller.UNREGISTERED_TYPE_ID;
+import static org.apache.ignite.internal.binary.GridPortableMarshaller.USER_COL;
+import static org.apache.ignite.internal.binary.GridPortableMarshaller.USER_SET;
+import static org.apache.ignite.internal.binary.GridPortableMarshaller.UUID;
+import static org.apache.ignite.internal.binary.GridPortableMarshaller.UUID_ARR;
+
+/**
+ * Portable utils.
+ */
+public class PortableUtils {
+    /** */
+    public static final Map<Class<?>, Byte> PLAIN_CLASS_TO_FLAG = new HashMap<>();
+
+    /** */
+    public static final Map<Byte, Class<?>> FLAG_TO_CLASS = new HashMap<>();
+
+    /** {@code true} if serialized value of this type cannot contain references to objects. */
+    private static final boolean[] PLAIN_TYPE_FLAG = new boolean[102];
+
+    /** Portable classes. */
+    private static final Collection<Class<?>> PORTABLE_CLS = new HashSet<>();
+
+    /** Flag: user type. */
+    public static final short FLAG_USR_TYP = 0x0001;
+
+    /** Flag: only raw data exists. */
+    public static final short FLAG_HAS_SCHEMA = 0x0002;
+
+    /** Flag indicating that object has raw data. */
+    public static final short FLAG_HAS_RAW = 0x0004;
+
+    /** Flag: offsets take 1 byte. */
+    public static final short FLAG_OFFSET_ONE_BYTE = 0x0008;
+
+    /** Flag: offsets take 2 bytes. */
+    public static final short FLAG_OFFSET_TWO_BYTES = 0x0010;
+
+    /** Flag: compact footer, no field IDs. */
+    public static final short FLAG_COMPACT_FOOTER = 0x0020;
+
+    /** Offset which fits into 1 byte. */
+    public static final int OFFSET_1 = 1;
+
+    /** Offset which fits into 2 bytes. */
+    public static final int OFFSET_2 = 2;
+
+    /** Offset which fits into 4 bytes. */
+    public static final int OFFSET_4 = 4;
+
+    /** Field ID length. */
+    public static final int FIELD_ID_LEN = 4;
+
+    /** Field type names. */
+    private static final String[] FIELD_TYPE_NAMES;
+
+    /** FNV1 hash offset basis. */
+    private static final int FNV1_OFFSET_BASIS = 0x811C9DC5;
+
+    /** FNV1 hash prime. */
+    private static final int FNV1_PRIME = 0x01000193;
+
+    /**
+     * Static class initializer.
+     */
+    static {
+        PLAIN_CLASS_TO_FLAG.put(Byte.class, GridPortableMarshaller.BYTE);
+        PLAIN_CLASS_TO_FLAG.put(Short.class, GridPortableMarshaller.SHORT);
+        PLAIN_CLASS_TO_FLAG.put(Integer.class, GridPortableMarshaller.INT);
+        PLAIN_CLASS_TO_FLAG.put(Long.class, GridPortableMarshaller.LONG);
+        PLAIN_CLASS_TO_FLAG.put(Float.class, GridPortableMarshaller.FLOAT);
+        PLAIN_CLASS_TO_FLAG.put(Double.class, GridPortableMarshaller.DOUBLE);
+        PLAIN_CLASS_TO_FLAG.put(Character.class, GridPortableMarshaller.CHAR);
+        PLAIN_CLASS_TO_FLAG.put(Boolean.class, GridPortableMarshaller.BOOLEAN);
+        PLAIN_CLASS_TO_FLAG.put(BigDecimal.class, GridPortableMarshaller.DECIMAL);
+        PLAIN_CLASS_TO_FLAG.put(String.class, GridPortableMarshaller.STRING);
+        PLAIN_CLASS_TO_FLAG.put(UUID.class, GridPortableMarshaller.UUID);
+        PLAIN_CLASS_TO_FLAG.put(Date.class, GridPortableMarshaller.DATE);
+        PLAIN_CLASS_TO_FLAG.put(Timestamp.class, GridPortableMarshaller.TIMESTAMP);
+
+        PLAIN_CLASS_TO_FLAG.put(byte[].class, GridPortableMarshaller.BYTE_ARR);
+        PLAIN_CLASS_TO_FLAG.put(short[].class, GridPortableMarshaller.SHORT_ARR);
+        PLAIN_CLASS_TO_FLAG.put(int[].class, GridPortableMarshaller.INT_ARR);
+        PLAIN_CLASS_TO_FLAG.put(long[].class, GridPortableMarshaller.LONG_ARR);
+        PLAIN_CLASS_TO_FLAG.put(float[].class, GridPortableMarshaller.FLOAT_ARR);
+        PLAIN_CLASS_TO_FLAG.put(double[].class, GridPortableMarshaller.DOUBLE_ARR);
+        PLAIN_CLASS_TO_FLAG.put(char[].class, GridPortableMarshaller.CHAR_ARR);
+        PLAIN_CLASS_TO_FLAG.put(boolean[].class, GridPortableMarshaller.BOOLEAN_ARR);
+        PLAIN_CLASS_TO_FLAG.put(BigDecimal[].class, GridPortableMarshaller.DECIMAL_ARR);
+        PLAIN_CLASS_TO_FLAG.put(String[].class, GridPortableMarshaller.STRING_ARR);
+        PLAIN_CLASS_TO_FLAG.put(UUID[].class, GridPortableMarshaller.UUID_ARR);
+        PLAIN_CLASS_TO_FLAG.put(Date[].class, GridPortableMarshaller.DATE_ARR);
+        PLAIN_CLASS_TO_FLAG.put(Timestamp[].class, GridPortableMarshaller.TIMESTAMP_ARR);
+
+        for (Map.Entry<Class<?>, Byte> entry : PLAIN_CLASS_TO_FLAG.entrySet())
+            FLAG_TO_CLASS.put(entry.getValue(), entry.getKey());
+
+        PLAIN_CLASS_TO_FLAG.put(byte.class, GridPortableMarshaller.BYTE);
+        PLAIN_CLASS_TO_FLAG.put(short.class, GridPortableMarshaller.SHORT);
+        PLAIN_CLASS_TO_FLAG.put(int.class, GridPortableMarshaller.INT);
+        PLAIN_CLASS_TO_FLAG.put(long.class, GridPortableMarshaller.LONG);
+        PLAIN_CLASS_TO_FLAG.put(float.class, GridPortableMarshaller.FLOAT);
+        PLAIN_CLASS_TO_FLAG.put(double.class, GridPortableMarshaller.DOUBLE);
+        PLAIN_CLASS_TO_FLAG.put(char.class, GridPortableMarshaller.CHAR);
+        PLAIN_CLASS_TO_FLAG.put(boolean.class, GridPortableMarshaller.BOOLEAN);
+
+        for (byte b : new byte[] {
+            GridPortableMarshaller.BYTE, GridPortableMarshaller.SHORT, GridPortableMarshaller.INT, GridPortableMarshaller.LONG, GridPortableMarshaller.FLOAT, GridPortableMarshaller.DOUBLE,
+            GridPortableMarshaller.CHAR, GridPortableMarshaller.BOOLEAN, GridPortableMarshaller.DECIMAL, GridPortableMarshaller.STRING, GridPortableMarshaller.UUID, GridPortableMarshaller.DATE, GridPortableMarshaller.TIMESTAMP,
+            GridPortableMarshaller.BYTE_ARR, GridPortableMarshaller.SHORT_ARR, GridPortableMarshaller.INT_ARR, GridPortableMarshaller.LONG_ARR, GridPortableMarshaller.FLOAT_ARR, GridPortableMarshaller.DOUBLE_ARR,
+            GridPortableMarshaller.CHAR_ARR, GridPortableMarshaller.BOOLEAN_ARR, GridPortableMarshaller.DECIMAL_ARR, GridPortableMarshaller.STRING_ARR, GridPortableMarshaller.UUID_ARR, GridPortableMarshaller.DATE_ARR, GridPortableMarshaller.TIMESTAMP_ARR,
+            GridPortableMarshaller.ENUM, GridPortableMarshaller.ENUM_ARR, GridPortableMarshaller.NULL}) {
+
+            PLAIN_TYPE_FLAG[b] = true;
+        }
+
+        PORTABLE_CLS.add(Byte.class);
+        PORTABLE_CLS.add(Short.class);
+        PORTABLE_CLS.add(Integer.class);
+        PORTABLE_CLS.add(Long.class);
+        PORTABLE_CLS.add(Float.class);
+        PORTABLE_CLS.add(Double.class);
+        PORTABLE_CLS.add(Character.class);
+        PORTABLE_CLS.add(Boolean.class);
+        PORTABLE_CLS.add(String.class);
+        PORTABLE_CLS.add(UUID.class);
+        PORTABLE_CLS.add(Date.class);
+        PORTABLE_CLS.add(Timestamp.class);
+        PORTABLE_CLS.add(BigDecimal.class);
+        PORTABLE_CLS.add(byte[].class);
+        PORTABLE_CLS.add(short[].class);
+        PORTABLE_CLS.add(int[].class);
+        PORTABLE_CLS.add(long[].class);
+        PORTABLE_CLS.add(float[].class);
+        PORTABLE_CLS.add(double[].class);
+        PORTABLE_CLS.add(char[].class);
+        PORTABLE_CLS.add(boolean[].class);
+        PORTABLE_CLS.add(String[].class);
+        PORTABLE_CLS.add(UUID[].class);
+        PORTABLE_CLS.add(Date[].class);
+        PORTABLE_CLS.add(Timestamp[].class);
+        PORTABLE_CLS.add(BigDecimal[].class);
+
+        FIELD_TYPE_NAMES = new String[104];
+
+        FIELD_TYPE_NAMES[GridPortableMarshaller.BYTE] = "byte";
+        FIELD_TYPE_NAMES[GridPortableMarshaller.SHORT] = "short";
+        FIELD_TYPE_NAMES[GridPortableMarshaller.INT] = "int";
+        FIELD_TYPE_NAMES[GridPortableMarshaller.LONG] = "long";
+        FIELD_TYPE_NAMES[GridPortableMarshaller.BOOLEAN] = "boolean";
+        FIELD_TYPE_NAMES[GridPortableMarshaller.FLOAT] = "float";
+        FIELD_TYPE_NAMES[GridPortableMarshaller.DOUBLE] = "double";
+        FIELD_TYPE_NAMES[GridPortableMarshaller.CHAR] = "char";
+        FIELD_TYPE_NAMES[GridPortableMarshaller.UUID] = "UUID";
+        FIELD_TYPE_NAMES[GridPortableMarshaller.DECIMAL] = "decimal";
+        FIELD_TYPE_NAMES[GridPortableMarshaller.STRING] = "String";
+        FIELD_TYPE_NAMES[GridPortableMarshaller.DATE] = "Date";
+        FIELD_TYPE_NAMES[GridPortableMarshaller.TIMESTAMP] = "Timestamp";
+        FIELD_TYPE_NAMES[GridPortableMarshaller.ENUM] = "Enum";
+        FIELD_TYPE_NAMES[GridPortableMarshaller.OBJ] = "Object";
+        FIELD_TYPE_NAMES[GridPortableMarshaller.PORTABLE_OBJ] = "Object";
+        FIELD_TYPE_NAMES[GridPortableMarshaller.COL] = "Collection";
+        FIELD_TYPE_NAMES[GridPortableMarshaller.MAP] = "Map";
+        FIELD_TYPE_NAMES[GridPortableMarshaller.CLASS] = "Class";
+        FIELD_TYPE_NAMES[GridPortableMarshaller.BYTE_ARR] = "byte[]";
+        FIELD_TYPE_NAMES[GridPortableMarshaller.SHORT_ARR] = "short[]";
+        FIELD_TYPE_NAMES[GridPortableMarshaller.INT_ARR] = "int[]";
+        FIELD_TYPE_NAMES[GridPortableMarshaller.LONG_ARR] = "long[]";
+        FIELD_TYPE_NAMES[GridPortableMarshaller.BOOLEAN_ARR] = "boolean[]";
+        FIELD_TYPE_NAMES[GridPortableMarshaller.FLOAT_ARR] = "float[]";
+        FIELD_TYPE_NAMES[GridPortableMarshaller.DOUBLE_ARR] = "double[]";
+        FIELD_TYPE_NAMES[GridPortableMarshaller.CHAR_ARR] = "char[]";
+        FIELD_TYPE_NAMES[GridPortableMarshaller.UUID_ARR] = "UUID[]";
+        FIELD_TYPE_NAMES[GridPortableMarshaller.DECIMAL_ARR] = "decimal[]";
+        FIELD_TYPE_NAMES[GridPortableMarshaller.STRING_ARR] = "String[]";
+        FIELD_TYPE_NAMES[GridPortableMarshaller.DATE_ARR] = "Date[]";
+        FIELD_TYPE_NAMES[GridPortableMarshaller.TIMESTAMP_ARR] = "Timestamp[]";
+        FIELD_TYPE_NAMES[GridPortableMarshaller.OBJ_ARR] = "Object[]";
+        FIELD_TYPE_NAMES[GridPortableMarshaller.ENUM_ARR] = "Enum[]";
+    }
+
+    /**
+     * Check if user type flag is set.
+     *
+     * @param flags Flags.
+     * @return {@code True} if set.
+     */
+    public static boolean isUserType(short flags) {
+        return isFlagSet(flags, FLAG_USR_TYP);
+    }
+
+    /**
+     * Check if raw-only flag is set.
+     *
+     * @param flags Flags.
+     * @return {@code True} if set.
+     */
+    public static boolean hasSchema(short flags) {
+        return isFlagSet(flags, FLAG_HAS_SCHEMA);
+    }
+
+    /**
+     * Check if raw-only flag is set.
+     *
+     * @param flags Flags.
+     * @return {@code True} if set.
+     */
+    public static boolean hasRaw(short flags) {
+        return isFlagSet(flags, FLAG_HAS_RAW);
+    }
+
+    /**
+     * Check if "no-field-ids" flag is set.
+     *
+     * @param flags Flags.
+     * @return {@code True} if set.
+     */
+    public static boolean isCompactFooter(short flags) {
+        return isFlagSet(flags, FLAG_COMPACT_FOOTER);
+    }
+
+    /**
+     * Check whether particular flag is set.
+     *
+     * @param flags Flags.
+     * @param flag Flag.
+     * @return {@code True} if flag is set in flags.
+     */
+    private static boolean isFlagSet(short flags, short flag) {
+        return (flags & flag) == flag;
+    }
+
+    /**
+     * Schema initial ID.
+     *
+     * @return ID.
+     */
+    public static int schemaInitialId() {
+        return FNV1_OFFSET_BASIS;
+    }
+
+    /**
+     * Update schema ID when new field is added.
+     *
+     * @param schemaId Current schema ID.
+     * @param fieldId Field ID.
+     * @return New schema ID.
+     */
+    public static int updateSchemaId(int schemaId, int fieldId) {
+        schemaId = schemaId ^ (fieldId & 0xFF);
+        schemaId = schemaId * FNV1_PRIME;
+        schemaId = schemaId ^ ((fieldId >> 8) & 0xFF);
+        schemaId = schemaId * FNV1_PRIME;
+        schemaId = schemaId ^ ((fieldId >> 16) & 0xFF);
+        schemaId = schemaId * FNV1_PRIME;
+        schemaId = schemaId ^ ((fieldId >> 24) & 0xFF);
+        schemaId = schemaId * FNV1_PRIME;
+
+        return schemaId;
+    }
+
+    /**
+     * @param typeName Field type name.
+     * @return Field type ID;
+     */
+    @SuppressWarnings("StringEquality")
+    public static int fieldTypeId(String typeName) {
+        for (int i = 0; i < FIELD_TYPE_NAMES.length; i++) {
+            String typeName0 = FIELD_TYPE_NAMES[i];
+
+            if (typeName.equals(typeName0))
+                return i;
+        }
+
+        throw new IllegalArgumentException("Invalid metadata type name: " + typeName);
+    }
+
+    /**
+     * @param typeId Field type ID.
+     * @return Field type name.
+     */
+    public static String fieldTypeName(int typeId) {
+        assert typeId >= 0 && typeId < FIELD_TYPE_NAMES.length : typeId;
+
+        String typeName = FIELD_TYPE_NAMES[typeId];
+
+        assert typeName != null : typeId;
+
+        return typeName;
+    }
+
+    /**
+     * Write value with flag. e.g. writePlainObject(writer, (byte)77) will write two byte: {BYTE, 77}.
+     *
+     * @param writer W
+     * @param val Value.
+     */
+    public static void writePlainObject(BinaryWriterExImpl writer, Object val) {
+        Byte flag = PLAIN_CLASS_TO_FLAG.get(val.getClass());
+
+        if (flag == null)
+            throw new IllegalArgumentException("Can't write object with type: " + val.getClass());
+
+        switch (flag) {
+            case GridPortableMarshaller.BYTE:
+                writer.writeByte(flag);
+                writer.writeByte((Byte)val);
+
+                break;
+
+            case GridPortableMarshaller.SHORT:
+                writer.writeByte(flag);
+                writer.writeShort((Short)val);
+
+                break;
+
+            case GridPortableMarshaller.INT:
+                writer.writeByte(flag);
+                writer.writeInt((Integer)val);
+
+                break;
+
+            case GridPortableMarshaller.LONG:
+                writer.writeByte(flag);
+                writer.writeLong((Long)val);
+
+                break;
+
+            case GridPortableMarshaller.FLOAT:
+                writer.writeByte(flag);
+                writer.writeFloat((Float)val);
+
+                break;
+
+            case GridPortableMarshaller.DOUBLE:
+                writer.writeByte(flag);
+                writer.writeDouble((Double)val);
+
+                break;
+
+            case GridPortableMarshaller.CHAR:
+                writer.writeByte(flag);
+                writer.writeChar((Character)val);
+
+                break;
+
+            case GridPortableMarshaller.BOOLEAN:
+                writer.writeByte(flag);
+                writer.writeBoolean((Boolean)val);
+
+                break;
+
+            case GridPortableMarshaller.DECIMAL:
+                writer.doWriteDecimal((BigDecimal)val);
+
+                break;
+
+            case GridPortableMarshaller.STRING:
+                writer.doWriteString((String)val);
+
+                break;
+
+            case GridPortableMarshaller.UUID:
+                writer.doWriteUuid((UUID)val);
+
+                break;
+
+            case GridPortableMarshaller.DATE:
+                writer.doWriteDate((Date)val);
+
+                break;
+
+            case GridPortableMarshaller.TIMESTAMP:
+                writer.doWriteTimestamp((Timestamp) val);
+
+                break;
+
+            case GridPortableMarshaller.BYTE_ARR:
+                writer.doWriteByteArray((byte[])val);
+
+                break;
+
+            case GridPortableMarshaller.SHORT_ARR:
+                writer.doWriteShortArray((short[])val);
+
+                break;
+
+            case GridPortableMarshaller.INT_ARR:
+                writer.doWriteIntArray((int[])val);
+
+                break;
+
+            case GridPortableMarshaller.LONG_ARR:
+                writer.doWriteLongArray((long[])val);
+
+                break;
+
+            case GridPortableMarshaller.FLOAT_ARR:
+                writer.doWriteFloatArray((float[])val);
+
+                break;
+
+            case GridPortableMarshaller.DOUBLE_ARR:
+                writer.doWriteDoubleArray((double[])val);
+
+                break;
+
+            case GridPortableMarshaller.CHAR_ARR:
+                writer.doWriteCharArray((char[])val);
+
+                break;
+
+            case GridPortableMarshaller.BOOLEAN_ARR:
+                writer.doWriteBooleanArray((boolean[])val);
+
+                break;
+
+            case GridPortableMarshaller.DECIMAL_ARR:
+                writer.doWriteDecimalArray((BigDecimal[])val);
+
+                break;
+
+            case GridPortableMarshaller.STRING_ARR:
+                writer.doWriteStringArray((String[])val);
+
+                break;
+
+            case GridPortableMarshaller.UUID_ARR:
+                writer.doWriteUuidArray((UUID[])val);
+
+                break;
+
+            case GridPortableMarshaller.DATE_ARR:
+                writer.doWriteDateArray((Date[])val);
+
+                break;
+
+            case GridPortableMarshaller.TIMESTAMP_ARR:
+                writer.doWriteTimestampArray((Timestamp[])val);
+
+                break;
+
+            default:
+                throw new IllegalArgumentException("Can't write object with type: " + val.getClass());
+        }
+    }
+
+    /**
+     * @param obj Value to unwrap.
+     * @return Unwrapped value.
+     */
+    public static Object unwrapLazy(@Nullable Object obj) {
+        if (obj instanceof PortableLazyValue)
+            return ((PortableLazyValue)obj).value();
+
+        return obj;
+    }
+
+    /**
+     * @param delegate Iterator to delegate.
+     * @return New iterator.
+     */
+    public static Iterator<Object> unwrapLazyIterator(final Iterator<Object> delegate) {
+        return new Iterator<Object>() {
+            @Override public boolean hasNext() {
+                return delegate.hasNext();
+            }
+
+            @Override public Object next() {
+                return unwrapLazy(delegate.next());
+            }
+
+            @Override public void remove() {
+                delegate.remove();
+            }
+        };
+    }
+
+    /**
+     * @return {@code true} if content of serialized value cannot contain references to other object.
+     */
+    public static boolean isPlainType(int type) {
+        return type > 0 && type < PLAIN_TYPE_FLAG.length && PLAIN_TYPE_FLAG[type];
+    }
+
+    /**
+     * Checks whether an array type values can or can not contain references to other object.
+     *
+     * @param type Array type.
+     * @return {@code true} if content of serialized array value cannot contain references to other object.
+     */
+    public static boolean isPlainArrayType(int type) {
+        return (type >= GridPortableMarshaller.BYTE_ARR && type <= GridPortableMarshaller.DATE_ARR) || type == GridPortableMarshaller.TIMESTAMP_ARR;
+    }
+
+    /**
+     * @param cls Class.
+     * @return Portable field type.
+     */
+    public static byte typeByClass(Class<?> cls) {
+        Byte type = PLAIN_CLASS_TO_FLAG.get(cls);
+
+        if (type != null)
+            return type;
+
+        if (cls.isEnum())
+            return GridPortableMarshaller.ENUM;
+
+        if (cls.isArray())
+            return cls.getComponentType().isEnum() || cls.getComponentType() == Enum.class ? GridPortableMarshaller.ENUM_ARR : GridPortableMarshaller.OBJ_ARR;
+
+        if (isSpecialCollection(cls))
+            return GridPortableMarshaller.COL;
+
+        if (isSpecialMap(cls))
+            return GridPortableMarshaller.MAP;
+
+        return GridPortableMarshaller.OBJ;
+    }
+
+    /**
+     * Tells whether provided type is portable.
+     *
+     * @param cls Class to check.
+     * @return Whether type is portable.
+     */
+    public static boolean isPortableType(Class<?> cls) {
+        assert cls != null;
+
+        return BinaryObject.class.isAssignableFrom(cls) ||
+            PORTABLE_CLS.contains(cls) ||
+            cls.isEnum() ||
+            (cls.isArray() && cls.getComponentType().isEnum());
+    }
+
+    /**
+     * Attempts to create a new map of the same type as {@code map} has. Otherwise returns new {@code HashMap} instance.
+     *
+     * @param map Original map.
+     * @return New map.
+     */
+    public static <K, V> Map<K, V> newMap(Map<K, V> map) {
+        if (map instanceof LinkedHashMap)
+            return U.newLinkedHashMap(map.size());
+        else if (map instanceof TreeMap)
+            return new TreeMap<>(((TreeMap<Object, Object>)map).comparator());
+        else if (map instanceof ConcurrentHashMap8)
+            return new ConcurrentHashMap8<>(U.capacity(map.size()));
+        else if (map instanceof ConcurrentHashMap)
+            return new ConcurrentHashMap<>(U.capacity(map.size()));
+
+        return U.newHashMap(map.size());
+    }
+
+    /**
+     * Attempts to create a new set of the same type as {@code set} has. Otherwise returns new {@code HashSet} instance.
+     *
+     * @param set Original set.
+     * @return New set.
+     */
+    public static <V> Set<V> newSet(Set<V> set) {
+        if (set instanceof LinkedHashSet)
+            return U.newLinkedHashSet(set.size());
+        else if (set instanceof TreeSet)
+            return new TreeSet<>(((TreeSet<Object>)set).comparator());
+        else if (set instanceof ConcurrentSkipListSet)
+            return new ConcurrentSkipListSet<>(((ConcurrentSkipListSet<Object>)set).comparator());
+
+        return U.newHashSet(set.size());
+    }
+
+    /**
+     * Check protocol version.
+     *
+     * @param protoVer Protocol version.
+     */
+    public static void checkProtocolVersion(byte protoVer) {
+        if (GridPortableMarshaller.PROTO_VER != protoVer)
+            throw new BinaryObjectException("Unsupported protocol version: " + protoVer);
+    }
+
+    /**
+     * Get portable object length.
+     *
+     * @param in Input stream.
+     * @param start Start position.
+     * @return Length.
+     */
+    public static int length(PortablePositionReadable in, int start) {
+        return in.readIntPositioned(start + GridPortableMarshaller.TOTAL_LEN_POS);
+    }
+
+    /**
+     * Get footer start of the object.
+     *
+     * @param in Input stream.
+     * @param start Object start position inside the stream.
+     * @return Footer start.
+     */
+    public static int footerStartRelative(PortablePositionReadable in, int start) {
+        short flags = in.readShortPositioned(start + GridPortableMarshaller.FLAGS_POS);
+
+        if (hasSchema(flags))
+            // Schema exists, use offset.
+            return in.readIntPositioned(start + GridPortableMarshaller.SCHEMA_OR_RAW_OFF_POS);
+        else
+            // No schema, footer start equals to object end.
+            return length(in, start);
+    }
+
+    /**
+     * Get object's footer.
+     *
+     * @param in Input stream.
+     * @param start Start position.
+     * @return Footer start.
+     */
+    public static int footerStartAbsolute(PortablePositionReadable in, int start) {
+        return footerStartRelative(in, start) + start;
+    }
+
+    /**
+     * Get object's footer.
+     *
+     * @param in Input stream.
+     * @param start Start position.
+     * @return Footer.
+     */
+    public static IgniteBiTuple<Integer, Integer> footerAbsolute(PortablePositionReadable in, int start) {
+        short flags = in.readShortPositioned(start + GridPortableMarshaller.FLAGS_POS);
+
+        int footerEnd = length(in, start);
+
+        if (hasSchema(flags)) {
+            // Schema exists.
+            int footerStart = in.readIntPositioned(start + GridPortableMarshaller.SCHEMA_OR_RAW_OFF_POS);
+
+            if (hasRaw(flags))
+                footerEnd -= 4;
+
+            assert footerStart <= footerEnd;
+
+            return F.t(start + footerStart, start + footerEnd);
+        }
+        else
+            // No schema.
+            return F.t(start + footerEnd, start + footerEnd);
+    }
+
+    /**
+     * Get relative raw offset of the object.
+     *
+     * @param in Input stream.
+     * @param start Object start position inside the stream.
+     * @return Raw offset.
+     */
+    public static int rawOffsetRelative(PortablePositionReadable in, int start) {
+        short flags = in.readShortPositioned(start + GridPortableMarshaller.FLAGS_POS);
+
+        int len = length(in, start);
+
+        if (hasSchema(flags)){
+            // Schema exists.
+            if (hasRaw(flags))
+                // Raw offset is set, it is at the very end of the object.
+                return in.readIntPositioned(start + len - 4);
+            else
+                // Raw offset is not set, so just return schema offset.
+                return in.readIntPositioned(start + GridPortableMarshaller.SCHEMA_OR_RAW_OFF_POS);
+        }
+        else
+            // No schema, raw offset is located on schema offset position.
+            return in.readIntPositioned(start + GridPortableMarshaller.SCHEMA_OR_RAW_OFF_POS);
+    }
+
+    /**
+     * Get absolute raw offset of the object.
+     *
+     * @param in Input stream.
+     * @param start Object start position inside the stream.
+     * @return Raw offset.
+     */
+    public static int rawOffsetAbsolute(PortablePositionReadable in, int start) {
+        return start + rawOffsetRelative(in, start);
+    }
+
+    /**
+     * Get offset length for the given flags.
+     *
+     * @param flags Flags.
+     * @return Offset size.
+     */
+    public static int fieldOffsetLength(short flags) {
+        if ((flags & FLAG_OFFSET_ONE_BYTE) == FLAG_OFFSET_ONE_BYTE)
+            return OFFSET_1;
+        else if ((flags & FLAG_OFFSET_TWO_BYTES) == FLAG_OFFSET_TWO_BYTES)
+            return OFFSET_2;
+        else
+            return OFFSET_4;
+    }
+
+    /**
+     * Get field ID length.
+     *
+     * @param flags Flags.
+     * @return Field ID length.
+     */
+    public static int fieldIdLength(short flags) {
+        return isCompactFooter(flags) ? 0 : FIELD_ID_LEN;
+    }
+
+    /**
+     * Get relative field offset.
+     *
+     * @param stream Stream.
+     * @param pos Position.
+     * @param fieldOffsetSize Field offset size.
+     * @return Relative field offset.
+     */
+    public static int fieldOffsetRelative(PortablePositionReadable stream, int pos, int fieldOffsetSize) {
+        int res;
+
+        if (fieldOffsetSize == OFFSET_1)
+            res = (int)stream.readBytePositioned(pos) & 0xFF;
+        else if (fieldOffsetSize == OFFSET_2)
+            res = (int)stream.readShortPositioned(pos) & 0xFFFF;
+        else
+            res = stream.readIntPositioned(pos);
+
+        return res;
+    }
+
+    /**
+     * Merge old and new metas.
+     *
+     * @param oldMeta Old meta.
+     * @param newMeta New meta.
+     * @return New meta if old meta was null, old meta if no changes detected, merged meta otherwise.
+     * @throws BinaryObjectException If merge failed due to metadata conflict.
+     */
+    public static BinaryMetadata mergeMetadata(@Nullable BinaryMetadata oldMeta, BinaryMetadata newMeta) {
+        assert newMeta != null;
+
+        if (oldMeta == null)
+            return newMeta;
+        else {
+            assert oldMeta.typeId() == newMeta.typeId();
+
+            // Check type name.
+            if (!F.eq(oldMeta.typeName(), newMeta.typeName())) {
+                throw new BinaryObjectException(
+                    "Two portable types have duplicate type ID [" + "typeId=" + oldMeta.typeId() +
+                        ", typeName1=" + oldMeta.typeName() + ", typeName2=" + newMeta.typeName() + ']'
+                );
+            }
+
+            // Check affinity field names.
+            if (!F.eq(oldMeta.affinityKeyFieldName(), newMeta.affinityKeyFieldName())) {
+                throw new BinaryObjectException(
+                    "Binary type has different affinity key fields [" + "typeName=" + newMeta.typeName() +
+                        ", affKeyFieldName1=" + oldMeta.affinityKeyFieldName() +
+                        ", affKeyFieldName2=" + newMeta.affinityKeyFieldName() + ']'
+                );
+            }
+
+            // Check enum flag.
+            if (oldMeta.isEnum() != newMeta.isEnum()) {
+                if (oldMeta.isEnum())
+                    throw new BinaryObjectException("Binary type already registered as enum: " +
+                        newMeta.typeName());
+                else
+                    throw new BinaryObjectException("Binary type already registered as non-enum: " +
+                        newMeta.typeName());
+            }
+
+            // Check and merge fields.
+            boolean changed = false;
+
+            Map<String, Integer> mergedFields = new HashMap<>(oldMeta.fieldsMap());
+            Map<String, Integer> newFields = newMeta.fieldsMap();
+
+            for (Map.Entry<String, Integer> newField : newFields.entrySet()) {
+                Integer oldFieldType = mergedFields.put(newField.getKey(), newField.getValue());
+
+                if (oldFieldType == null)
+                    changed = true;
+                else if (!F.eq(oldFieldType, newField.getValue())) {
+                    throw new BinaryObjectException(
+                        "Binary type has different field types [" + "typeName=" + oldMeta.typeName() +
+                            ", fieldName=" + newField.getKey() +
+                            ", fieldTypeName1=" + fieldTypeName(oldFieldType) +
+                            ", fieldTypeName2=" + fieldTypeName(newField.getValue()) + ']'
+                    );
+                }
+            }
+
+            // Check and merge schemas.
+            Collection<PortableSchema> mergedSchemas = new HashSet<>(oldMeta.schemas());
+
+            for (PortableSchema newSchema : newMeta.schemas()) {
+                if (mergedSchemas.add(newSchema))
+                    changed = true;
+            }
+
+            // Return either old meta if no changes detected, or new merged meta.
+            return changed ? new BinaryMetadata(oldMeta.typeId(), oldMeta.typeName(), mergedFields,
+                oldMeta.affinityKeyFieldName(), mergedSchemas, oldMeta.isEnum()) : oldMeta;
+        }
+    }
+
+    /**
+     * @param cls Class.
+     * @return Mode.
+     */
+    @SuppressWarnings("IfMayBeConditional")
+    public static BinaryWriteMode mode(Class<?> cls) {
+        assert cls != null;
+
+        /** Primitives. */
+        if (cls == byte.class)
+            return BinaryWriteMode.P_BYTE;
+        else if (cls == boolean.class)
+            return BinaryWriteMode.P_BOOLEAN;
+        else if (cls == short.class)
+            return BinaryWriteMode.P_SHORT;
+        else if (cls == char.class)
+            return BinaryWriteMode.P_CHAR;
+        else if (cls == int.class)
+            return BinaryWriteMode.P_INT;
+        else if (cls == long.class)
+            return BinaryWriteMode.P_LONG;
+        else if (cls == float.class)
+            return BinaryWriteMode.P_FLOAT;
+        else if (cls == double.class)
+            return BinaryWriteMode.P_DOUBLE;
+
+        /** Boxed primitives. */
+        else if (cls == Byte.class)
+            return BinaryWriteMode.BYTE;
+        else if (cls == Boolean.class)
+            return BinaryWriteMode.BOOLEAN;
+        else if (cls == Short.class)
+            return BinaryWriteMode.SHORT;
+        else if (cls == Character.class)
+            return BinaryWriteMode.CHAR;
+        else if (cls == Integer.class)
+            return BinaryWriteMode.INT;
+        else if (cls == Long.class)
+            return BinaryWriteMode.LONG;
+        else if (cls == Float.class)
+            return BinaryWriteMode.FLOAT;
+        else if (cls == Double.class)
+            return BinaryWriteMode.DOUBLE;
+
+        /** The rest types. */
+        else if (cls == BigDecimal.class)
+            return BinaryWriteMode.DECIMAL;
+        else if (cls == String.class)
+            return BinaryWriteMode.STRING;
+        else if (cls == UUID.class)
+            return BinaryWriteMode.UUID;
+        else if (cls == Date.class)
+            return BinaryWriteMode.DATE;
+        else if (cls == Timestamp.class)
+            return BinaryWriteMode.TIMESTAMP;
+        else if (cls == byte[].class)
+            return BinaryWriteMode.BYTE_ARR;
+        else if (cls == short[].class)
+            return BinaryWriteMode.SHORT_ARR;
+        else if (cls == int[].class)
+            return BinaryWriteMode.INT_ARR;
+        else if (cls == long[].class)
+            return BinaryWriteMode.LONG_ARR;
+        else if (cls == float[].class)
+            return BinaryWriteMode.FLOAT_ARR;
+        else if (cls == double[].class)
+            return BinaryWriteMode.DOUBLE_ARR;
+        else if (cls == char[].class)
+            return BinaryWriteMode.CHAR_ARR;
+        else if (cls == boolean[].class)
+            return BinaryWriteMode.BOOLEAN_ARR;
+        else if (cls == BigDecimal[].class)
+            return BinaryWriteMode.DECIMAL_ARR;
+        else if (cls == String[].class)
+            return BinaryWriteMode.STRING_ARR;
+        else if (cls == UUID[].class)
+            return BinaryWriteMode.UUID_ARR;
+        else if (cls == Date[].class)
+            return BinaryWriteMode.DATE_ARR;
+        else if (cls == Timestamp[].class)
+            return BinaryWriteMode.TIMESTAMP_ARR;
+        else if (cls.isArray())
+            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))
+            return BinaryWriteMode.PORTABLE;
+        else if (Externalizable.class.isAssignableFrom(cls))
+            return BinaryWriteMode.EXTERNALIZABLE;
+        else if (isSpecialCollection(cls))
+            return BinaryWriteMode.COL;
+        else if (isSpecialMap(cls))
+            return BinaryWriteMode.MAP;
+        else if (cls.isEnum())
+            return BinaryWriteMode.ENUM;
+        else if (cls == Class.class)
+            return BinaryWriteMode.CLASS;
+        else
+            return BinaryWriteMode.OBJECT;
+    }
+
+    /**
+     * 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) {
+        int len = in.readInt();
+
+        return in.readByteArray(len);
+    }
+
+    /**
+     * @return Value.
+     */
+    public static boolean[] doReadBooleanArray(PortableInputStream in) {
+        int len = in.readInt();
+
+        return in.readBooleanArray(len);
+    }
+
+    /**
+     * @return Value.
+     */
+    public static short[] doReadShortArray(PortableInputStream in) {
+        int len = in.readInt();
+
+        return in.readShortArray(len);
+    }
+
+    /**
+     * @return Value.
+     */
+    public static char[] doReadCharArray(PortableInputStream in) {
+        int len = in.readInt();
+
+        return in.readCharArray(len);
+    }
+
+    /**
+     * @return Value.
+     */
+    public static int[] doReadIntArray(PortableInputStream in) {
+        int len = in.readInt();
+
+        return in.readIntArray(len);
+    }
+
+    /**
+     * @return Value.
+     */
+    public static long[] doReadLongArray(PortableInputStream in) {
+        int len = in.readInt();
+
+        return in.readLongArray(len);
+    }
+
+    /**
+     * @return Value.
+     */
+    public static float[] doReadFloatArray(PortableInputStream in) {
+        int len = in.readInt();
+
+        return in.readFloatArray(len);
+    }
+
+    /**
+     * @return Value.
+     */
+    public static double[] doReadDoubleArray(PortableInputStream in) {
+        int len = in.readInt();
+
+        return in.readDoubleArray(len);
+    }
+
+    /**
+     * @return Value.
+     */
+    public static BigDecimal doReadDecimal(PortableInputStream in) {
+        int scale = in.readInt();
+        byte[] mag = doReadByteArray(in);
+
+        BigInteger intVal = new BigInteger(mag);
+
+        if (scale < 0) {
+            scale &= 0x7FFFFFFF;
+
+            intVal = intVal.negate();
+        }
+
+        return new BigDecimal(intVal, scale);
+    }
+
+    /**
+     * @return Value.
+     */
+    public static String doReadString(PortableInputStream in) {
+        if (!in.hasArray())
+            return new String(doReadByteArray(in), UTF_8);
+
+        int strLen = in.readInt();
+
+        int pos = in.position();
+
+        // String will copy necessary array part for us.
+        String res = new String(in.array(), pos, strLen, UTF_8);
+
+        in.position(pos + strLen);
+
+        return res;
+    }
+
+    /**
+     * @return Value.
+     */
+    public static UUID doReadUuid(PortableInputStream in) {
+        return new UUID(in.readLong(), in.readLong());
+    }
+
+    /**
+     * @return Value.
+     */
+    public static Date doReadDate(PortableInputStream in) {
+        long time = in.readLong();
+
+        return new Date(time);
+    }
+
+    /**
+     * @return Value.
+     */
+    public static Timestamp doReadTimestamp(PortableInputStream in) {
+        long time = in.readLong();
+        int nanos = in.readInt();
+
+        Timestamp ts = new Timestamp(time);
+
+        ts.setNanos(ts.getNanos() + nanos);
+
+        return ts;
+    }
+
+    /**
+     * @return Value.
+     * @throws BinaryObjectException In case of error.
+     */
+    public static BigDecimal[] doReadDecimalArray(PortableInputStream in) throws BinaryObjectException {
+        int len = in.readInt();
+
+        BigDecimal[] arr = new BigDecimal[len];
+
+        for (int i = 0; i < len; i++) {
+            byte flag = in.readByte();
+
+            if (flag == GridPortableMarshaller.NULL)
+                arr[i] = null;
+            else {
+                if (flag != GridPortableMarshaller.DECIMAL)
+                    throw new BinaryObjectException("Invalid flag value: " + flag);
+
+                arr[i] = doReadDecimal(in);
+            }
+        }
+
+        return arr;
+    }
+
+    /**
+     * @return Value.
+     * @throws BinaryObjectException In case of error.
+     */
+    public static String[] doReadStringArray(PortableInputStream in) throws BinaryObjectException {
+        int len = in.readInt();
+
+        String[] arr = new String[len];
+
+        for (int i = 0; i < len; i++) {
+            byte flag = in.readByte();
+
+            if (flag == GridPortableMarshaller.NULL)
+                arr[i] = null;
+            else {
+                if (flag != GridPortableMarshaller.STRING)
+                    throw new BinaryObjectException("Invalid flag value: " + flag);
+
+                arr[i] = doReadString(in);
+            }
+        }
+
+        return arr;
+    }
+
+    /**
+     * @return Value.
+     * @throws BinaryObjectException In case of error.
+     */
+    public static UUID[] doReadUuidArray(PortableInputStream in) throws BinaryObjectException {
+        int len = in.readInt();
+
+        UUID[] arr = new UUID[len];
+
+        for (int i = 0; i < len; i++) {
+            byte flag = in.readByte();
+
+            if (flag == GridPortableMarshaller.NULL)
+                arr[i] = null;
+            else {
+                if (flag != GridPortableMarshaller.UUID)
+                    throw new BinaryObjectException("Invalid flag value: " + flag);
+
+                arr[i] = doReadUuid(in);
+            }
+        }
+
+        return arr;
+    }
+
+    /**
+     * @return Value.
+     * @throws BinaryObjectException In case of error.
+     */
+    public static Date[] doReadDateArray(PortableInputStream in) throws BinaryObjectException {
+        int len = in.readInt();
+
+        Date[] arr = new Date[len];
+
+        for (int i = 0; i < len; i++) {
+            byte flag = in.readByte();
+
+            if (flag == GridPortableMarshaller.NULL)
+                arr[i] = null;
+            else {
+                if (flag != GridPortableMarshaller.DATE)
+                    throw new BinaryObjectException("Invalid flag value: " + flag);
+
+                arr[i] = doReadDate(in);
+            }
+        }
+
+        return arr;
+    }
+
+    /**
+     * @return Value.
+     * @throws BinaryObjectException In case of error.
+     */
+    public static Timestamp[] doReadTimestampArray(PortableInputStream in) throws BinaryObjectException {
+        int len = in.readInt();
+
+        Timestamp[] arr = new Timestamp[len];
+
+        for (int i = 0; i < len; i++) {
+            byte flag = in.readByte();
+
+            if (flag == GridPortableMarshaller.NULL)
+                arr[i] = null;
+            else {
+                if (flag != GridPortableMarshaller.TIMESTAMP)
+                    throw new BinaryObjectException("Invalid flag value: " + flag);
+
+                arr[i] = doReadTimestamp(in);
+            }
+        }
+
+        return arr;
+    }
+
+    /**
+     * @return Value.
+     */
+    public static BinaryObject doReadPortableObject(PortableInputStream in, PortableContext ctx) {
+        if (in.offheapPointer() > 0) {
+            int len = in.readInt();
+
+            int pos = in.position();
+
+            in.position(in.position() + len);
+
+            int start = in.readInt();
+
+            return new BinaryObjectOffheapImpl(ctx, in.offheapPointer() + pos, start, len);
+        }
+        else {
+            byte[] arr = doReadByteArray(in);
+            int start = in.readInt();
+
+            return new BinaryObjectImpl(ctx, arr, start);
+        }
+    }
+
+    /**
+     * @return Value.
+     */
+    public static Class doReadClass(PortableInputStream in, PortableContext ctx, ClassLoader ldr)
+        throws BinaryObjectException {
+        int typeId = in.readInt();
+
+        return doReadClass(in, ctx, ldr, typeId);
+    }
+
+    /**
+     * Read plain type.
+     *
+     * @param in Input stream.
+     * @return Plain type.
+     */
+    private static EnumType doReadEnumType(PortableInputStream in) {
+        int typeId = in.readInt();
+
+        if (typeId != GridPortableMarshaller.UNREGISTERED_TYPE_ID)
+            return new EnumType(typeId, null);
+        else {
+            String clsName = doReadClassName(in);
+
+            return new EnumType(GridPortableMarshaller.UNREGISTERED_TYPE_ID, clsName);
+        }
+    }
+
+    /**
+     * @param in Input stream.
+     * @return Class name.
+     */
+    private static String doReadClassName(PortableInputStream in) {
+        byte flag = in.readByte();
+
+        if (flag != GridPortableMarshaller.STRING)
+            throw new BinaryObjectException("Failed to read class name [position=" + (in.position() - 1) + ']');
+
+        return doReadString(in);
+    }
+
+    /**
+     * @param typeId Type id.
+     * @return Value.
+     */
+    public static Class doReadClass(PortableInputStream in, PortableContext ctx, ClassLoader ldr, int typeId)
+        throws BinaryObjectException {
+        Class cls;
+
+        if (typeId == GridPortableMarshaller.OBJECT_TYPE_ID)
+            return Object.class;
+
+        if (typeId != GridPortableMarshaller.UNREGISTERED_TYPE_ID)
+            cls = ctx.descriptorForTypeId(true, typeId, ldr, false).describedClass();
+        else {
+            String clsName = doReadClassName(in);
+
+            try {
+                cls = U.forName(clsName, ldr);
+            }
+            catch (ClassNotFoundException e) {
+                throw new BinaryInvalidTypeException("Failed to load the class: " + clsName, e);
+            }
+
+            // forces registering of class by type id, at least locally
+            ctx.descriptorForClass(cls, true);
+        }
+
+        return cls;
+    }
+
+    /**
+     * Resolve the class.
+     *
+     * @param ctx Portable context.
+     * @param typeId Type ID.
+     * @param clsName Class name.
+     * @param ldr Class loaded.
+     * @return Resovled class.
+     */
+    public static Class resolveClass(PortableContext ctx, int typeId, @Nullable String clsName,
+        @Nullable ClassLoader ldr, boolean deserialize) {
+        Class cls;
+
+        if (typeId == GridPortableMarshaller.OBJECT_TYPE_ID)
+            return Object.class;
+
+        if (typeId != GridPortableMarshaller.UNREGISTERED_TYPE_ID)
+            cls = ctx.descriptorForTypeId(true, typeId, ldr, deserialize).describedClass();
+        else {
+            try {
+                cls = U.forName(clsName, ldr);
+            }
+            catch (ClassNotFoundException e) {
+                throw new BinaryInvalidTypeException("Failed to load the class: " + clsName, e);
+            }
+
+            // forces registering of class by type id, at least locally
+            ctx.descriptorForClass(cls, true);
+        }
+
+        return cls;
+    }
+
+    /**
+     * Read portable enum.
+     *
+     * @param in Input stream.
+     * @param ctx Portable context.
+     * @param type Plain type.
+     * @return Enum.
+     */
+    private static BinaryEnumObjectImpl doReadPortableEnum(PortableInputStream in, PortableContext ctx,
+        EnumType type) {
+        return new BinaryEnumObjectImpl(ctx, type.typeId, type.clsName, in.readInt());
+    }
+
+    /**
+     * Read portable enum array.
+     *
+     * @param in Input stream.
+     * @param ctx Portable context.
+     * @return Enum array.
+     */
+    private static Object[] doReadPortableEnumArray(PortableInputStream in, PortableContext ctx) {
+        int len = in.readInt();
+
+        Object[] arr = (Object[]) Array.newInstance(BinaryObject.class, len);
+
+        for (int i = 0; i < len; i++) {
+            byte flag = in.readByte();
+
+            if (flag == GridPortableMarshaller.NULL)
+                arr[i] = null;
+            else
+                arr[i] = doReadPortableEnum(in, ctx, doReadEnumType(in));
+        }
+
+        return arr;
+    }
+
+    /**
+     * Having target class in place we simply read ordinal and create final representation.
+     *
+     * @param cls Enum class.
+     * @return Value.
+     */
+    public static Enum<?> doReadEnum(PortableInputStream in, Class<?> cls) throws BinaryObjectException {
+        assert cls != null;
+
+        if (!cls.isEnum())
+            throw new BinaryObjectException("Class does not represent enum type: " + cls.getName());
+
+        int ord = in.readInt();
+
+        return BinaryEnumCache.get(cls, ord);
+    }
+
+    /**
+     * @param cls Enum class.
+     * @return Value.
+     */
+    public static Object[] doReadEnumArray(PortableInputStream in, PortableContext ctx, ClassLoader ldr, Class<?> cls)
+        throws BinaryObjectException {
+        int len = in.readInt();
+
+        Object[] arr = (Object[]) Array.newInstance(cls, len);
+
+        for (int i = 0; i < len; i++) {
+            byte flag = in.readByte();
+
+            if (flag == GridPortableMarshaller.NULL)
+                arr[i] = null;
+            else
+                arr[i] = doReadEnum(in, doReadClass(in, ctx, ldr));
+        }
+
+        return arr;
+    }
+
+    /**
+     * Read object serialized using optimized marshaller.
+     *
+     * @return Result.
+     */
+    public static Object doReadOptimized(PortableInputStream in, PortableContext ctx, @Nullable ClassLoader clsLdr) {
+        int len = in.readInt();
+
+        ByteArrayInputStream input = new ByteArrayInputStream(in.array(), in.position(), len);
+
+        try {
+            return ctx.optimizedMarsh().unmarshal(input, clsLdr);
+        }
+        catch (IgniteCheckedException e) {
+            throw new BinaryObjectException("Failed to unmarshal object with optimized marshaller", e);
+        }
+        finally {
+            in.position(in.position() + len);
+        }
+    }
+
+    /**
+     * @return Object.
+     * @throws BinaryObjectException In case of error.
+     */
+    @Nullable public static Object doReadObject(PortableInputStream in, PortableContext ctx, ClassLoader ldr,
+        BinaryReaderHandlesHolder handles) throws BinaryObjectException {
+        return new BinaryReaderExImpl(ctx, in, ldr, handles.handles()).deserialize();
+    }
+
+    /**
+     * @return Unmarshalled value.
+     * @throws BinaryObjectException In case of error.
+     */
+    @Nullable public static Object unmarshal(PortableInputStream in, PortableContext ctx, ClassLoader ldr)
+        throws BinaryObjectException {
+        return unmarshal(in, ctx, ldr, new BinaryReaderHandlesHolderImpl());
+    }
+
+    /**
+     * @return Unmarshalled value.
+     * @throws BinaryObjectException In case of error.
+     */
+    @Nullable public static Object unmarshal(PortableInputStream in, PortableContext ctx, ClassLoader ldr,
+        BinaryReaderHandlesHolder handles) throws BinaryObjectException {
+        return unmarshal(in, ctx, ldr, handles, false);
+    }
+
+    /**
+     * @return Unmarshalled value.
+     * @throws BinaryObjectException In case of error.
+     */
+    @Nullable public static Object unmarshal(PortableInputStream in, PortableContext ctx, ClassLoader ldr,
+        BinaryReaderHandlesHolder handles, boolean detach) throws BinaryObjectException {
+        int start = in.position();
+
+        byte flag = in.readByte();
+
+        switch (flag) {
+            case GridPortableMarshaller.NULL:
+                return null;
+
+            case GridPortableMarshaller.HANDLE: {
+                int handlePos = start - in.readInt();
+
+                Object obj = handles.getHandle(handlePos);
+
+                if (obj == null) {
+                    int retPos = in.position();
+
+                    in.position(handlePos);
+
+                    obj = unmarshal(in, ctx, ldr, handles);
+
+                    in.position(retPos);
+                }
+
+                return obj;
+            }
+
+            case GridPortableMarshaller.OBJ: {
+                checkProtocolVersion(in.readByte());
+
+                int len = length(in, start);
+
+                BinaryObjectExImpl po;
+
+                if (detach) {
+                    // In detach mode we simply copy object's content.
+                    in.position(start);
+
+                    po = new BinaryObjectImpl(ctx, in.readByteArray(len), 0);
+                }
+                else {
+                    if (in.offheapPointer() == 0)
+                        po = new BinaryObjectImpl(ctx, in.array(), start);
+                    else
+                        po = new BinaryObjectOffheapImpl(ctx, in.offheapPointer(), start,
+                            in.remaining() + in.position());
+
+                    in.position(start + po.length());
+                }
+
+                handles.setHandle(po, start);
+
+                return po;
+            }
+
+            case GridPortableMarshaller.BYTE:
+                return in.readByte();
+
+            case GridPortableMarshaller.SHORT:
+                return in.readShort();
+
+            case GridPortableMarshaller.INT:
+                return in.readInt();
+
+            case GridPortableMarshaller.LONG:
+                return in.readLong();
+
+            case GridPortableMarshaller.FLOAT:
+                return in.readFloat();
+
+            case GridPortableMarshaller.DOUBLE:
+                return in.readDouble();
+
+            case GridPortableMarshaller.CHAR:
+                return in.readChar();
+
+            case GridPortableMarshaller.BOOLEAN:
+                return in.readBoolean();
+
+            case GridPortableMarshaller.DECIMAL:
+                return doReadDecimal(in);
+
+            case GridPortableMarshaller.STRING:
+                return doReadString(in);
+
+            case GridPortableMarshaller.UUID:
+                return doReadUuid(in);
+
+            case GridPortableMarshaller.DATE:
+                return doReadDate(in);
+
+            case GridPortableMarshaller.TIMESTAMP:
+                return doReadTimestamp(in);
+
+            case GridPortableMarshaller.BYTE_ARR:
+                return doReadByteArray(in);
+
+            case GridPortableMarshaller.SHORT_ARR:
+                return doReadShortArray(in);
+
+            case GridPortableMarshaller.INT_ARR:
+                return doReadIntArray(in);
+
+            case GridPortableMarshaller.LONG_ARR:
+                return doReadLongArray(in);
+
+            case GridPortableMarshaller.FLOAT_ARR:
+                return doReadFloatArray(in);
+
+            case GridPortableMarshaller.DOUBLE_ARR:
+                return doReadDoubleArray(in);
+
+            case GridPortableMarshaller.CHAR_ARR:
+                return doReadCharArray(in);
+
+            case GridPortableMarshaller.BOOLEAN_ARR:
+                return doReadBooleanArray(in);
+
+            case GridPortableMarshaller.DECIMAL_ARR:
+                return doReadDecimalArray(in);
+
+            case GridPortableMarshaller.STRING_ARR:
+                return doReadStringArray(in);
+
+            case GridPortableMarshaller.UUID_ARR:
+                return doReadUuidArray(in);
+
+            case GridPortableMarshaller.DATE_ARR:
+                return doReadDateArray(in);
+
+            case GridPortableMarshaller.TIMESTAMP_ARR:
+                return doReadTimestampArray(in);
+
+            case GridPortableMarshaller.OBJ_ARR:
+                return doReadObjectArray(in, ctx, ldr, handles, false);
+
+            case GridPortableMarshaller.COL:
+                return doReadCollection(in, ctx, ldr, handles, false, null);
+
+            case GridPortableMarshaller.MAP:
+                return doReadMap(in, ctx, ldr, handles, false, null);
+
+            case GridPortableMarshaller.PORTABLE_OBJ:
+                return doReadPortableObject(in, ctx);
+
+            case GridPortableMarshaller.ENUM:
+                return doReadPortableEnum(in, ctx, doReadEnumType(in));
+
+            case GridPortableMarshaller.ENUM_ARR:
+                doReadEnumType(in); // Simply skip this part as we do not need it.
+
+                return doReadPortableEnumArray(in, ctx);
+
+            case GridPortableMarshaller.CLASS:
+                return doReadClass(in, ctx, ldr);
+
+            case GridPortableMarshaller.OPTM_MARSH:
+                return doReadOptimized(in, ctx, ldr);
+
+            default:
+                throw new BinaryObjectException("Invalid flag value: " + flag);
+        }
+    }
+
+    /**
+     * @param deserialize Deep flag.
+     * @return Value.
+     * @throws BinaryObjectException In case of error.
+     */
+    public static Object[] doReadObjectArray(PortableInputStream in, PortableContext ctx, ClassLoader ldr,
+        BinaryReaderHandlesHolder handles, boolean deserialize) throws BinaryObjectException {
+        int hPos = positionForHandle(in);
+
+        Class compType = doReadClass(in, ctx, ldr);
+
+        int len = in.readInt();
+
+        Object[] arr = deserialize ? (Object[])Array.newInstance(compType, len) : new Object[len];
+
+        handles.setHandle(arr, hPos);
+
+        for (int i = 0; i < len; i++)
+            arr[i] = deserializeOrUnmarshal(in, ctx, ldr, handles, deserialize);
+
+        return arr;
+    }
+
+    /**
+     * @param deserialize Deep flag.
+     * @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, BinaryCollectionFactory factory)
+        throws BinaryObjectException {
+        int hPos = positionForHandle(in);
+
+        int size = in.readInt();
+
+        assert size >= 0;
+
+        byte colType = in.readByte();
+
+        Collection<Object> col;
+
+        if (factory != null)
+            col = factory.create(size);
+        else {
+            switch (colType) {
+                case GridPortableMarshaller.ARR_LIST:
+                    col = new ArrayList<>(size);
+
+                    break;
+
+                case GridPortableMarshaller.LINKED_LIST:
+                    col = new LinkedList<>();
+
+                    break;
+
+                case GridPortableMarshaller.HASH_SET:
+                    col = U.newHashSet(size);
+
+                    break;
+
+                case GridPortableMarshaller.LINKED_HASH_SET:
+                    col = U.newLinkedHashSet(size);
+
+                    break;
+
+                case GridPortableMarshaller.USER_SET:
+                    col = U.newHashSet(size);
+
+                    break;
+
+                case GridPortableMarshaller.USER_COL:
+                    col = new ArrayList<>(size);
+
+                    break;
+
+                default:
+                    throw new BinaryObjectException("Invalid collection type: " + colType);
+            }
+        }
+
+        handles.setHandle(col, hPos);
+
+        for (int i = 0; i < size; i++)
+            col.add(deserializeOrUnmarshal(in, ctx, ldr, handles, deserialize));
+
+        return col;
+    }
+
+    /**
+     * @param deserialize Deep flag.
+     * @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, BinaryMapFactory factory)
+        throws BinaryObjectException {
+        int hPos = positionForHandle(in);
+
+        int size = in.readInt();
+
+        assert size >= 0;
+
+        byte mapType = in.readByte();
+
+        Map<Object, Object> map;
+
+        if (factory != null)
+            map = factory.create(size);
+        else {
+            switch (mapType) {
+                case GridPortableMarshaller.HASH_MAP:
+                    map = U.newHashMap(size);
+
+                    break;
+
+                case GridPortableMarshaller.LINKED_HASH_MAP:
+                    map = U.newLinkedHashMap(size);
+
+                    break;
+
+                case GridPortableMarshaller.USER_COL:
+                    map = U.newHashMap(size);
+
+                    break;
+
+                default:
+                    throw new BinaryObjectException("Invalid map type: " + mapType);
+            }
+        }
+
+        handles.setHandle(map, hPos);
+
+        for (int i = 0; i < size; i++) {
+            Object key = deserializeOrUnmarshal(in, ctx, ldr, handles, deserialize);
+            Object val = deserializeOrUnmarshal(in, ctx, ldr, handles, deserialize);
+
+            map.put(key, val);
+        }
+
+        return map;
+    }
+
+    /**
+     * Deserialize or unmarshal the object.
+     *
+     * @param deserialize Deserialize.
+     * @return Result.
+     */
+    private static Object deserializeOrUnmarshal(PortableInputStream in, PortableContext ctx, ClassLoader ldr,
+        BinaryReaderHandlesHolder handles, boolean deserialize) {
+        return deserialize ? doReadObject(in, ctx, ldr, handles) : unmarshal(in, ctx, ldr, handles);
+    }
+
+    /**
+     * Get position to be used for handle. We assume here that the hdr byte was read, hence subtract -1.
+     *
+     * @return Position for handle.
+     */
+    public static int positionForHandle(PortableInputStream in) {
+        return in.position() - 1;
+    }
+
+    /**
+     * Enum type.
+     */
+    private static class EnumType {
+        /** Type ID. */
+        private final int typeId;
+
+        /** Class name. */
+        private final String clsName;
+
+        /**
+         * Constructor.
+         *
+         * @param typeId Type ID.
+         * @param clsName Class name.
+         */
+        public EnumType(int typeId, @Nullable String clsName) {
+            assert typeId != GridPortableMarshaller.UNREGISTERED_TYPE_ID && clsName == null ||
+                typeId == GridPortableMarshaller.UNREGISTERED_TYPE_ID && clsName != null;
+
+            this.typeId = typeId;
+            this.clsName = clsName;
+        }
+    }
+}


[22/59] [abbrv] ignite git commit: ignite-2065: rename "portable" packages to "binary"

Posted by ak...@apache.org.
http://git-wip-us.apache.org/repos/asf/ignite/blob/1dbf20e0/modules/core/src/main/java/org/apache/ignite/internal/portable/BinaryObjectImpl.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/portable/BinaryObjectImpl.java b/modules/core/src/main/java/org/apache/ignite/internal/portable/BinaryObjectImpl.java
deleted file mode 100644
index c8528d9..0000000
--- a/modules/core/src/main/java/org/apache/ignite/internal/portable/BinaryObjectImpl.java
+++ /dev/null
@@ -1,584 +0,0 @@
-/*
- * 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.portable;
-
-import java.io.Externalizable;
-import java.io.IOException;
-import java.io.ObjectInput;
-import java.io.ObjectOutput;
-import java.math.BigDecimal;
-import java.math.BigInteger;
-import java.nio.ByteBuffer;
-import java.sql.Timestamp;
-import java.util.Date;
-import java.util.UUID;
-import org.apache.ignite.IgniteCheckedException;
-import org.apache.ignite.binary.BinaryObject;
-import org.apache.ignite.binary.BinaryObjectException;
-import org.apache.ignite.binary.BinaryType;
-import org.apache.ignite.internal.GridDirectTransient;
-import org.apache.ignite.internal.IgniteCodeGeneratingFail;
-import org.apache.ignite.internal.portable.streams.PortableHeapInputStream;
-import org.apache.ignite.internal.processors.cache.CacheObject;
-import org.apache.ignite.internal.processors.cache.CacheObjectContext;
-import org.apache.ignite.internal.processors.cache.KeyCacheObject;
-import org.apache.ignite.internal.processors.cache.portable.CacheObjectBinaryProcessorImpl;
-import org.apache.ignite.internal.util.typedef.internal.U;
-import org.apache.ignite.plugin.extensions.communication.MessageReader;
-import org.apache.ignite.plugin.extensions.communication.MessageWriter;
-import org.jetbrains.annotations.Nullable;
-
-import static java.nio.charset.StandardCharsets.UTF_8;
-import static org.apache.ignite.internal.portable.GridPortableMarshaller.BOOLEAN;
-import static org.apache.ignite.internal.portable.GridPortableMarshaller.BYTE;
-import static org.apache.ignite.internal.portable.GridPortableMarshaller.CHAR;
-import static org.apache.ignite.internal.portable.GridPortableMarshaller.DATE;
-import static org.apache.ignite.internal.portable.GridPortableMarshaller.DECIMAL;
-import static org.apache.ignite.internal.portable.GridPortableMarshaller.DOUBLE;
-import static org.apache.ignite.internal.portable.GridPortableMarshaller.FLOAT;
-import static org.apache.ignite.internal.portable.GridPortableMarshaller.INT;
-import static org.apache.ignite.internal.portable.GridPortableMarshaller.LONG;
-import static org.apache.ignite.internal.portable.GridPortableMarshaller.NULL;
-import static org.apache.ignite.internal.portable.GridPortableMarshaller.SHORT;
-import static org.apache.ignite.internal.portable.GridPortableMarshaller.STRING;
-import static org.apache.ignite.internal.portable.GridPortableMarshaller.TIMESTAMP;
-import static org.apache.ignite.internal.portable.GridPortableMarshaller.UUID;
-
-/**
- * Portable object implementation.
- */
-@IgniteCodeGeneratingFail // Fields arr and start should not be generated by MessageCodeGenerator.
-public final class BinaryObjectImpl extends BinaryObjectExImpl implements Externalizable, KeyCacheObject {
-    /** */
-    private static final long serialVersionUID = 0L;
-
-    /** */
-    @GridDirectTransient
-    private PortableContext ctx;
-
-    /** */
-    private byte[] arr;
-
-    /** */
-    private int start;
-
-    /** */
-    @GridDirectTransient
-    private Object obj;
-
-    /** */
-    @GridDirectTransient
-    private boolean detachAllowed;
-
-    /**
-     * For {@link Externalizable}.
-     */
-    public BinaryObjectImpl() {
-        // No-op.
-    }
-
-    /**
-     * @param ctx Context.
-     * @param arr Array.
-     * @param start Start.
-     */
-    public BinaryObjectImpl(PortableContext ctx, byte[] arr, int start) {
-        assert ctx != null;
-        assert arr != null;
-
-        this.ctx = ctx;
-        this.arr = arr;
-        this.start = start;
-    }
-
-    /** {@inheritDoc} */
-    @Override public byte cacheObjectType() {
-        return TYPE_BINARY;
-    }
-
-    /** {@inheritDoc} */
-    @Override public boolean isPlatformType() {
-        return false;
-    }
-
-    /** {@inheritDoc} */
-    @Override public boolean internal() {
-        return false;
-    }
-
-    /** {@inheritDoc} */
-    @SuppressWarnings("unchecked")
-    @Nullable @Override public <T> T value(CacheObjectContext ctx, boolean cpy) {
-        Object obj0 = obj;
-
-        if (obj0 == null || (cpy && needCopy(ctx)))
-            obj0 = deserializeValue(ctx);
-
-        return (T)obj0;
-    }
-
-    /** {@inheritDoc} */
-    @Override public byte[] valueBytes(CacheObjectContext ctx) throws IgniteCheckedException {
-        if (detached())
-            return array();
-
-        int len = length();
-
-        byte[] arr0 = new byte[len];
-
-        U.arrayCopy(arr, start, arr0, 0, len);
-
-        return arr0;
-    }
-
-    /** {@inheritDoc} */
-    @Override public CacheObject prepareForCache(CacheObjectContext ctx) {
-        if (detached())
-            return this;
-
-        return (BinaryObjectImpl)detach();
-    }
-
-    /** {@inheritDoc} */
-    @Override public void finishUnmarshal(CacheObjectContext ctx, ClassLoader ldr) throws IgniteCheckedException {
-        this.ctx = ((CacheObjectBinaryProcessorImpl)ctx.processor()).portableContext();
-    }
-
-    /** {@inheritDoc} */
-    @Override public void prepareMarshal(CacheObjectContext ctx) throws IgniteCheckedException {
-        // No-op.
-    }
-
-    /** {@inheritDoc} */
-    @Override public int length() {
-        return PortablePrimitives.readInt(arr, start + GridPortableMarshaller.TOTAL_LEN_POS);
-    }
-
-    /**
-     * @return Detached portable object.
-     */
-    public BinaryObject detach() {
-        if (!detachAllowed || detached())
-            return this;
-
-        int len = length();
-
-        byte[] arr0 = new byte[len];
-
-        U.arrayCopy(arr, start, arr0, 0, len);
-
-        return new BinaryObjectImpl(ctx, arr0, 0);
-    }
-
-    /**
-     * @return Detached or not.
-     */
-    public boolean detached() {
-        return start == 0 && length() == arr.length;
-    }
-
-    /**
-     * @param detachAllowed Detach allowed flag.
-     */
-    public void detachAllowed(boolean detachAllowed) {
-        this.detachAllowed = detachAllowed;
-    }
-
-    /**
-     * @return Context.
-     */
-    public PortableContext context() {
-        return ctx;
-    }
-
-    /**
-     * @param ctx Context.
-     */
-    public void context(PortableContext ctx) {
-        this.ctx = ctx;
-    }
-
-    /** {@inheritDoc} */
-    @Override public byte[] array() {
-        return arr;
-    }
-
-    /** {@inheritDoc} */
-    @Override public int start() {
-        return start;
-    }
-
-    /** {@inheritDoc} */
-    @Override public long offheapAddress() {
-        return 0;
-    }
-
-    /** {@inheritDoc} */
-    @Override protected boolean hasArray() {
-        return true;
-    }
-
-    /** {@inheritDoc} */
-    @Override public int typeId() {
-        return PortablePrimitives.readInt(arr, start + GridPortableMarshaller.TYPE_ID_POS);
-    }
-
-    /** {@inheritDoc} */
-    @Nullable @Override public BinaryType type() throws BinaryObjectException {
-        if (ctx == null)
-            throw new BinaryObjectException("PortableContext is not set for the object.");
-
-        return ctx.metadata(typeId());
-    }
-
-    /** {@inheritDoc} */
-    @SuppressWarnings("unchecked")
-    @Nullable @Override public <F> F field(String fieldName) throws BinaryObjectException {
-        return (F) reader(null).unmarshalField(fieldName);
-    }
-
-    /** {@inheritDoc} */
-    @SuppressWarnings("unchecked")
-    @Nullable @Override public <F> F field(int fieldId) throws BinaryObjectException {
-        return (F) reader(null).unmarshalField(fieldId);
-    }
-
-    /** {@inheritDoc} */
-    @SuppressWarnings("unchecked")
-    @Nullable @Override protected <F> F fieldByOrder(int order) {
-        Object val;
-
-        // Calculate field position.
-        int schemaOffset = PortablePrimitives.readInt(arr, start + GridPortableMarshaller.SCHEMA_OR_RAW_OFF_POS);
-
-        short flags = PortablePrimitives.readShort(arr, start + GridPortableMarshaller.FLAGS_POS);
-
-        int fieldIdLen = PortableUtils.isCompactFooter(flags) ? 0 : PortableUtils.FIELD_ID_LEN;
-        int fieldOffsetLen = PortableUtils.fieldOffsetLength(flags);
-
-        int fieldOffsetPos = start + schemaOffset + order * (fieldIdLen + fieldOffsetLen) + fieldIdLen;
-
-        int fieldPos;
-
-        if (fieldOffsetLen == PortableUtils.OFFSET_1)
-            fieldPos = start + ((int)PortablePrimitives.readByte(arr, fieldOffsetPos) & 0xFF);
-        else if (fieldOffsetLen == PortableUtils.OFFSET_2)
-            fieldPos = start + ((int)PortablePrimitives.readShort(arr, fieldOffsetPos) & 0xFFFF);
-        else
-            fieldPos = start + PortablePrimitives.readInt(arr, fieldOffsetPos);
-
-        // Read header and try performing fast lookup for well-known types (the most common types go first).
-        byte hdr = PortablePrimitives.readByte(arr, fieldPos);
-
-        switch (hdr) {
-            case INT:
-                val = PortablePrimitives.readInt(arr, fieldPos + 1);
-
-                break;
-
-            case LONG:
-                val = PortablePrimitives.readLong(arr, fieldPos + 1);
-
-                break;
-
-            case BOOLEAN:
-                val = PortablePrimitives.readBoolean(arr, fieldPos + 1);
-
-                break;
-
-            case SHORT:
-                val = PortablePrimitives.readShort(arr, fieldPos + 1);
-
-                break;
-
-            case BYTE:
-                val = PortablePrimitives.readByte(arr, fieldPos + 1);
-
-                break;
-
-            case CHAR:
-                val = PortablePrimitives.readChar(arr, fieldPos + 1);
-
-                break;
-
-            case FLOAT:
-                val = PortablePrimitives.readFloat(arr, fieldPos + 1);
-
-                break;
-
-            case DOUBLE:
-                val = PortablePrimitives.readDouble(arr, fieldPos + 1);
-
-                break;
-
-            case STRING: {
-                int dataLen = PortablePrimitives.readInt(arr, fieldPos + 1);
-
-                val = new String(arr, fieldPos + 5, dataLen, UTF_8);
-
-                break;
-            }
-
-            case DATE: {
-                long time = PortablePrimitives.readLong(arr, fieldPos + 1);
-
-                val = new Date(time);
-
-                break;
-            }
-
-            case TIMESTAMP: {
-                long time = PortablePrimitives.readLong(arr, fieldPos + 1);
-                int nanos = PortablePrimitives.readInt(arr, fieldPos + 1 + 8);
-
-                Timestamp ts = new Timestamp(time);
-
-                ts.setNanos(ts.getNanos() + nanos);
-
-                val = ts;
-
-                break;
-            }
-
-            case UUID: {
-                long most = PortablePrimitives.readLong(arr, fieldPos + 1);
-                long least = PortablePrimitives.readLong(arr, fieldPos + 1 + 8);
-
-                val = new UUID(most, least);
-
-                break;
-            }
-
-            case DECIMAL: {
-                int scale = PortablePrimitives.readInt(arr, fieldPos + 1);
-
-                int dataLen = PortablePrimitives.readInt(arr, fieldPos + 5);
-                byte[] data = PortablePrimitives.readByteArray(arr, fieldPos + 9, dataLen);
-
-                BigInteger intVal = new BigInteger(data);
-
-                if (scale < 0) {
-                    scale &= 0x7FFFFFFF;
-
-                    intVal = intVal.negate();
-                }
-
-                val = new BigDecimal(intVal, scale);
-
-                break;
-            }
-
-            case NULL:
-                val = null;
-
-                break;
-
-            default:
-                val = PortableUtils.unmarshal(PortableHeapInputStream.create(arr, fieldPos), ctx, null);
-
-                break;
-        }
-
-        return (F)val;
-    }
-
-    /** {@inheritDoc} */
-    @SuppressWarnings("unchecked")
-    @Nullable @Override protected <F> F field(BinaryReaderHandles rCtx, String fieldName) {
-        return (F)reader(rCtx).unmarshalField(fieldName);
-    }
-
-    /** {@inheritDoc} */
-    @Override public boolean hasField(String fieldName) {
-        return reader(null).findFieldByName(fieldName);
-    }
-
-    /** {@inheritDoc} */
-    @SuppressWarnings("unchecked")
-    @Nullable @Override public <T> T deserialize() throws BinaryObjectException {
-        Object obj0 = obj;
-
-        if (obj0 == null)
-            obj0 = deserializeValue(null);
-
-        return (T)obj0;
-    }
-
-    /** {@inheritDoc} */
-    @Override public BinaryObject clone() throws CloneNotSupportedException {
-        return super.clone();
-    }
-
-    /** {@inheritDoc} */
-    @Override public int hashCode() {
-        return PortablePrimitives.readInt(arr, start + GridPortableMarshaller.HASH_CODE_POS);
-    }
-
-    /** {@inheritDoc} */
-    @Override protected int schemaId() {
-        return PortablePrimitives.readInt(arr, start + GridPortableMarshaller.SCHEMA_ID_POS);
-    }
-
-    /** {@inheritDoc} */
-    @Override protected PortableSchema createSchema() {
-        return reader(null).getOrCreateSchema();
-    }
-
-    /** {@inheritDoc} */
-    @Override public void writeExternal(ObjectOutput out) throws IOException {
-        out.writeObject(ctx);
-
-        if (detachAllowed) {
-            int len = length();
-
-            out.writeInt(len);
-            out.write(arr, start, len);
-            out.writeInt(0);
-        }
-        else {
-            out.writeInt(arr.length);
-            out.write(arr);
-            out.writeInt(start);
-        }
-    }
-
-    /** {@inheritDoc} */
-    @Override public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
-        ctx = (PortableContext)in.readObject();
-
-        arr = new byte[in.readInt()];
-
-        in.readFully(arr);
-
-        start = in.readInt();
-    }
-
-    /** {@inheritDoc} */
-    @Override public boolean writeTo(ByteBuffer buf, MessageWriter writer) {
-        writer.setBuffer(buf);
-
-        if (!writer.isHeaderWritten()) {
-            if (!writer.writeHeader(directType(), fieldsCount()))
-                return false;
-
-            writer.onHeaderWritten();
-        }
-
-        switch (writer.state()) {
-            case 0:
-                if (!writer.writeByteArray("arr",
-                    arr,
-                    detachAllowed ? start : 0,
-                    detachAllowed ? length() : arr.length))
-                    return false;
-
-                writer.incrementState();
-
-            case 1:
-                if (!writer.writeInt("start", detachAllowed ? 0 : start))
-                    return false;
-
-                writer.incrementState();
-
-        }
-
-        return true;
-    }
-
-    /** {@inheritDoc} */
-    @Override public boolean readFrom(ByteBuffer buf, MessageReader reader) {
-        reader.setBuffer(buf);
-
-        if (!reader.beforeMessageRead())
-            return false;
-
-        switch (reader.state()) {
-            case 0:
-                arr = reader.readByteArray("arr");
-
-                if (!reader.isLastRead())
-                    return false;
-
-                reader.incrementState();
-
-            case 1:
-                start = reader.readInt("start");
-
-                if (!reader.isLastRead())
-                    return false;
-
-                reader.incrementState();
-
-        }
-
-        return true;
-    }
-
-    /** {@inheritDoc} */
-    @Override public byte directType() {
-        return 113;
-    }
-
-    /** {@inheritDoc} */
-    @Override public byte fieldsCount() {
-        return 3;
-    }
-
-    /**
-     * Runs value deserialization regardless of whether obj already has the deserialized value.
-     * Will set obj if descriptor is configured to keep deserialized values.
-     * @param coCtx CacheObjectContext.
-     * @return Object.
-     */
-    private Object deserializeValue(@Nullable CacheObjectContext coCtx) {
-        // TODO: IGNITE-1272 - Deserialize with proper class loader.
-        BinaryReaderExImpl reader = reader(null);
-
-        Object obj0 = reader.deserialize();
-
-        PortableClassDescriptor desc = reader.descriptor();
-
-        assert desc != null;
-
-        if (coCtx != null && coCtx.storeValue())
-            obj = obj0;
-
-        return obj0;
-    }
-
-    /**
-     * @param ctx Context.
-     * @return {@code True} need to copy value returned to user.
-     */
-    private boolean needCopy(CacheObjectContext ctx) {
-        return ctx.copyOnGet() && obj != null && !ctx.processor().immutable(obj);
-    }
-
-    /**
-     * Create new reader for this object.
-     *
-     * @param rCtx Reader context.
-     * @return Reader.
-     */
-    private BinaryReaderExImpl reader(@Nullable BinaryReaderHandles rCtx) {
-        return new BinaryReaderExImpl(ctx,
-            PortableHeapInputStream.create(arr, start),
-            ctx.configuration().getClassLoader(),
-            rCtx);
-    }
-}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ignite/blob/1dbf20e0/modules/core/src/main/java/org/apache/ignite/internal/portable/BinaryObjectOffheapImpl.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/portable/BinaryObjectOffheapImpl.java b/modules/core/src/main/java/org/apache/ignite/internal/portable/BinaryObjectOffheapImpl.java
deleted file mode 100644
index 6de0432..0000000
--- a/modules/core/src/main/java/org/apache/ignite/internal/portable/BinaryObjectOffheapImpl.java
+++ /dev/null
@@ -1,429 +0,0 @@
-/*
- * 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.portable;
-
-import org.apache.ignite.IgniteCheckedException;
-import org.apache.ignite.binary.BinaryObject;
-import org.apache.ignite.binary.BinaryObjectException;
-import org.apache.ignite.binary.BinaryType;
-import org.apache.ignite.internal.portable.streams.PortableOffheapInputStream;
-import org.apache.ignite.internal.processors.cache.CacheObject;
-import org.apache.ignite.internal.processors.cache.CacheObjectContext;
-import org.apache.ignite.internal.util.GridUnsafe;
-import org.apache.ignite.internal.util.typedef.internal.U;
-import org.apache.ignite.plugin.extensions.communication.MessageReader;
-import org.apache.ignite.plugin.extensions.communication.MessageWriter;
-import org.jetbrains.annotations.Nullable;
-import sun.misc.Unsafe;
-
-import java.io.Externalizable;
-import java.io.IOException;
-import java.io.ObjectInput;
-import java.io.ObjectOutput;
-import java.math.BigDecimal;
-import java.math.BigInteger;
-import java.nio.ByteBuffer;
-import java.sql.Timestamp;
-import java.util.Date;
-import java.util.UUID;
-
-import static java.nio.charset.StandardCharsets.UTF_8;
-import static org.apache.ignite.internal.portable.GridPortableMarshaller.BOOLEAN;
-import static org.apache.ignite.internal.portable.GridPortableMarshaller.BYTE;
-import static org.apache.ignite.internal.portable.GridPortableMarshaller.CHAR;
-import static org.apache.ignite.internal.portable.GridPortableMarshaller.DATE;
-import static org.apache.ignite.internal.portable.GridPortableMarshaller.DECIMAL;
-import static org.apache.ignite.internal.portable.GridPortableMarshaller.DOUBLE;
-import static org.apache.ignite.internal.portable.GridPortableMarshaller.FLOAT;
-import static org.apache.ignite.internal.portable.GridPortableMarshaller.INT;
-import static org.apache.ignite.internal.portable.GridPortableMarshaller.LONG;
-import static org.apache.ignite.internal.portable.GridPortableMarshaller.NULL;
-import static org.apache.ignite.internal.portable.GridPortableMarshaller.SHORT;
-import static org.apache.ignite.internal.portable.GridPortableMarshaller.STRING;
-import static org.apache.ignite.internal.portable.GridPortableMarshaller.TIMESTAMP;
-import static org.apache.ignite.internal.portable.GridPortableMarshaller.UUID;
-
-/**
- *  Portable object implementation over offheap memory
- */
-public class BinaryObjectOffheapImpl extends BinaryObjectExImpl implements Externalizable, CacheObject {
-    /** */
-    private static final long serialVersionUID = 0L;
-
-    /** */
-    private static final Unsafe UNSAFE = GridUnsafe.unsafe();
-
-    /** */
-    private final PortableContext ctx;
-
-    /** */
-    private final long ptr;
-
-    /** */
-    private final int start;
-
-    /** */
-    private final int size;
-
-    /**
-     * For {@link Externalizable} (not supported).
-     */
-    public BinaryObjectOffheapImpl() {
-        throw new UnsupportedOperationException();
-    }
-
-    /**
-     * @param ctx Context.
-     * @param ptr Memory address.
-     * @param start Object start.
-     * @param size Memory size.
-     */
-    public BinaryObjectOffheapImpl(PortableContext ctx, long ptr, int start, int size) {
-        this.ctx = ctx;
-        this.ptr = ptr;
-        this.start = start;
-        this.size = size;
-    }
-
-    /**
-     * @return Heap-based copy.
-     */
-    public BinaryObject heapCopy() {
-        return new BinaryObjectImpl(ctx, U.copyMemory(ptr, size), start);
-    }
-
-    /** {@inheritDoc} */
-    @Override public int typeId() {
-        return UNSAFE.getInt(ptr + start + GridPortableMarshaller.TYPE_ID_POS);
-    }
-
-    /** {@inheritDoc} */
-    @Override public int length() {
-        return UNSAFE.getInt(ptr + start + GridPortableMarshaller.TOTAL_LEN_POS);
-    }
-
-    /** {@inheritDoc} */
-    @Override public int hashCode() {
-        return UNSAFE.getInt(ptr + start + GridPortableMarshaller.HASH_CODE_POS);
-    }
-
-    /** {@inheritDoc} */
-    @Override protected int schemaId() {
-        return UNSAFE.getInt(ptr + start + GridPortableMarshaller.SCHEMA_ID_POS);
-    }
-
-    /** {@inheritDoc} */
-    @Override protected PortableSchema createSchema() {
-        return reader(null).getOrCreateSchema();
-    }
-
-    /** {@inheritDoc} */
-    @Override public int start() {
-        return start;
-    }
-
-    /** {@inheritDoc} */
-    @Override public byte[] array() {
-        return null;
-    }
-
-    /** {@inheritDoc} */
-    @Override public long offheapAddress() {
-        return ptr;
-    }
-
-    /** {@inheritDoc} */
-    @Override protected boolean hasArray() {
-        return false;
-    }
-
-    /** {@inheritDoc} */
-    @Nullable @Override public BinaryType type() throws BinaryObjectException {
-        if (ctx == null)
-            throw new BinaryObjectException("PortableContext is not set for the object.");
-
-        return ctx.metadata(typeId());
-    }
-
-    /** {@inheritDoc} */
-    @SuppressWarnings("unchecked")
-    @Nullable @Override public <F> F field(String fieldName) throws BinaryObjectException {
-        return (F) reader(null).unmarshalField(fieldName);
-    }
-
-    /** {@inheritDoc} */
-    @SuppressWarnings("unchecked")
-    @Nullable @Override public <F> F field(int fieldId) throws BinaryObjectException {
-        return (F) reader(null).unmarshalField(fieldId);
-    }
-
-    /** {@inheritDoc} */
-    @SuppressWarnings("unchecked")
-    @Nullable @Override protected <F> F fieldByOrder(int order) {
-        Object val;
-
-        // Calculate field position.
-        int schemaOffset = PortablePrimitives.readInt(ptr, start + GridPortableMarshaller.SCHEMA_OR_RAW_OFF_POS);
-
-        short flags = PortablePrimitives.readShort(ptr, start + GridPortableMarshaller.FLAGS_POS);
-
-        int fieldIdLen = PortableUtils.isCompactFooter(flags) ? 0 : PortableUtils.FIELD_ID_LEN;
-        int fieldOffsetLen = PortableUtils.fieldOffsetLength(flags);
-
-        int fieldOffsetPos = start + schemaOffset + order * (fieldIdLen + fieldOffsetLen) + fieldIdLen;
-
-        int fieldPos;
-
-        if (fieldOffsetLen == PortableUtils.OFFSET_1)
-            fieldPos = start + ((int)PortablePrimitives.readByte(ptr, fieldOffsetPos) & 0xFF);
-        else if (fieldOffsetLen == PortableUtils.OFFSET_2)
-            fieldPos = start + ((int)PortablePrimitives.readShort(ptr, fieldOffsetPos) & 0xFFFF);
-        else
-            fieldPos = start + PortablePrimitives.readInt(ptr, fieldOffsetPos);
-
-        // Read header and try performing fast lookup for well-known types (the most common types go first).
-        byte hdr = PortablePrimitives.readByte(ptr, fieldPos);
-
-        switch (hdr) {
-            case INT:
-                val = PortablePrimitives.readInt(ptr, fieldPos + 1);
-
-                break;
-
-            case LONG:
-                val = PortablePrimitives.readLong(ptr, fieldPos + 1);
-
-                break;
-
-            case BOOLEAN:
-                val = PortablePrimitives.readBoolean(ptr, fieldPos + 1);
-
-                break;
-
-            case SHORT:
-                val = PortablePrimitives.readShort(ptr, fieldPos + 1);
-
-                break;
-
-            case BYTE:
-                val = PortablePrimitives.readByte(ptr, fieldPos + 1);
-
-                break;
-
-            case CHAR:
-                val = PortablePrimitives.readChar(ptr, fieldPos + 1);
-
-                break;
-
-            case FLOAT:
-                val = PortablePrimitives.readFloat(ptr, fieldPos + 1);
-
-                break;
-
-            case DOUBLE:
-                val = PortablePrimitives.readDouble(ptr, fieldPos + 1);
-
-                break;
-
-            case STRING: {
-                int dataLen = PortablePrimitives.readInt(ptr, fieldPos + 1);
-                byte[] data = PortablePrimitives.readByteArray(ptr, fieldPos + 5, dataLen);
-
-                val = new String(data, UTF_8);
-
-                break;
-            }
-
-            case DATE: {
-                long time = PortablePrimitives.readLong(ptr, fieldPos + 1);
-
-                val = new Date(time);
-
-                break;
-            }
-
-            case TIMESTAMP: {
-                long time = PortablePrimitives.readLong(ptr, fieldPos + 1);
-                int nanos = PortablePrimitives.readInt(ptr, fieldPos + 1 + 8);
-
-                Timestamp ts = new Timestamp(time);
-
-                ts.setNanos(ts.getNanos() + nanos);
-
-                val = ts;
-
-                break;
-            }
-
-            case UUID: {
-                long most = PortablePrimitives.readLong(ptr, fieldPos + 1);
-                long least = PortablePrimitives.readLong(ptr, fieldPos + 1 + 8);
-
-                val = new UUID(most, least);
-
-                break;
-            }
-
-            case DECIMAL: {
-                int scale = PortablePrimitives.readInt(ptr, fieldPos + 1);
-
-                int dataLen = PortablePrimitives.readInt(ptr, fieldPos + 5);
-                byte[] data = PortablePrimitives.readByteArray(ptr, fieldPos + 9, dataLen);
-
-                BigInteger intVal = new BigInteger(data);
-
-                if (scale < 0) {
-                    scale &= 0x7FFFFFFF;
-
-                    intVal = intVal.negate();
-                }
-
-                val = new BigDecimal(intVal, scale);
-
-                break;
-            }
-
-            case NULL:
-                val = null;
-
-                break;
-
-            default:
-                PortableOffheapInputStream stream = new PortableOffheapInputStream(ptr, size, false);
-
-                stream.position(fieldPos);
-
-                val = PortableUtils.unmarshal(stream, ctx, null);
-
-                break;
-        }
-
-        return (F)val;
-    }
-
-    /** {@inheritDoc} */
-    @SuppressWarnings("unchecked")
-    @Nullable @Override protected <F> F field(BinaryReaderHandles rCtx, String fieldName) {
-        return (F)reader(rCtx).unmarshalField(fieldName);
-    }
-
-    /** {@inheritDoc} */
-    @Override public boolean hasField(String fieldName) {
-        return reader(null).findFieldByName(fieldName);
-    }
-
-    /** {@inheritDoc} */
-    @SuppressWarnings("unchecked")
-    @Nullable @Override public <T> T deserialize() throws BinaryObjectException {
-        return (T)deserializeValue();
-    }
-
-    /** {@inheritDoc} */
-    @SuppressWarnings("CloneDoesntCallSuperClone")
-    @Override public BinaryObject clone() throws CloneNotSupportedException {
-        return heapCopy();
-    }
-
-    /** {@inheritDoc} */
-    @Override public byte cacheObjectType() {
-        throw new UnsupportedOperationException();
-    }
-
-    /** {@inheritDoc} */
-    @Override public boolean isPlatformType() {
-        return false;
-    }
-
-    /** {@inheritDoc} */
-    @SuppressWarnings("unchecked")
-    @Nullable @Override public <T> T value(CacheObjectContext ctx, boolean cpy) {
-        return (T)deserializeValue();
-    }
-
-    /** {@inheritDoc} */
-    @Override public byte[] valueBytes(CacheObjectContext ctx) throws IgniteCheckedException {
-        throw new UnsupportedOperationException();
-    }
-
-    /** {@inheritDoc} */
-    @Override public CacheObject prepareForCache(CacheObjectContext ctx) {
-        throw new UnsupportedOperationException();
-    }
-
-    /** {@inheritDoc} */
-    @Override public void finishUnmarshal(CacheObjectContext ctx, ClassLoader ldr) throws IgniteCheckedException {
-        throw new UnsupportedOperationException();
-    }
-
-    /** {@inheritDoc} */
-    @Override public void prepareMarshal(CacheObjectContext ctx) throws IgniteCheckedException {
-        throw new UnsupportedOperationException();
-    }
-
-    /** {@inheritDoc} */
-    @Override public boolean writeTo(ByteBuffer buf, MessageWriter writer) {
-        throw new UnsupportedOperationException();
-    }
-
-    /** {@inheritDoc} */
-    @Override public boolean readFrom(ByteBuffer buf, MessageReader reader) {
-        throw new UnsupportedOperationException();
-    }
-
-    /** {@inheritDoc} */
-    @Override public byte directType() {
-        throw new UnsupportedOperationException();
-    }
-
-    /** {@inheritDoc} */
-    @Override public byte fieldsCount() {
-        throw new UnsupportedOperationException();
-    }
-
-    /** {@inheritDoc} */
-    @Override public void writeExternal(ObjectOutput out) throws IOException {
-        throw new UnsupportedOperationException(); // To make sure it is not marshalled.
-    }
-
-    /** {@inheritDoc} */
-    @Override public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
-        throw new UnsupportedOperationException(); // To make sure it is not marshalled.
-    }
-
-    /**
-     * @return Deserialized value.
-     */
-    private Object deserializeValue() {
-        // TODO: IGNITE-1272 - Deserialize with proper class loader.
-        return reader(null).deserialize();
-    }
-
-    /**
-     * Create new reader for this object.
-     *
-     * @param rCtx Reader context.
-     * @return Reader.
-     */
-    private BinaryReaderExImpl reader(@Nullable BinaryReaderHandles rCtx) {
-        PortableOffheapInputStream stream = new PortableOffheapInputStream(ptr, size, false);
-
-        stream.position(start);
-
-        return new BinaryReaderExImpl(ctx, stream, null, rCtx);
-    }
-}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ignite/blob/1dbf20e0/modules/core/src/main/java/org/apache/ignite/internal/portable/BinaryRawReaderEx.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/portable/BinaryRawReaderEx.java b/modules/core/src/main/java/org/apache/ignite/internal/portable/BinaryRawReaderEx.java
deleted file mode 100644
index 3d7c61a..0000000
--- a/modules/core/src/main/java/org/apache/ignite/internal/portable/BinaryRawReaderEx.java
+++ /dev/null
@@ -1,33 +0,0 @@
-/*
- * 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.portable;
-
-import org.apache.ignite.binary.BinaryObjectException;
-import org.apache.ignite.binary.BinaryRawReader;
-import org.jetbrains.annotations.Nullable;
-
-/**
- * Extended reader interface.
- */
-public interface BinaryRawReaderEx extends BinaryRawReader {
-    /**
-     * @return Object.
-     * @throws org.apache.ignite.binary.BinaryObjectException In case of error.
-     */
-    @Nullable public Object readObjectDetached() throws BinaryObjectException;
-}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ignite/blob/1dbf20e0/modules/core/src/main/java/org/apache/ignite/internal/portable/BinaryRawWriterEx.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/portable/BinaryRawWriterEx.java b/modules/core/src/main/java/org/apache/ignite/internal/portable/BinaryRawWriterEx.java
deleted file mode 100644
index 96312b4..0000000
--- a/modules/core/src/main/java/org/apache/ignite/internal/portable/BinaryRawWriterEx.java
+++ /dev/null
@@ -1,60 +0,0 @@
-/*
- * 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.portable;
-
-import org.apache.ignite.internal.portable.streams.PortableOutputStream;
-import org.apache.ignite.binary.BinaryObjectException;
-import org.apache.ignite.binary.BinaryRawWriter;
-import org.jetbrains.annotations.Nullable;
-
-/**
- * Extended writer interface.
- */
-public interface BinaryRawWriterEx extends BinaryRawWriter, AutoCloseable {
-    /**
-     * @param obj Object to write.
-     * @throws org.apache.ignite.binary.BinaryObjectException In case of error.
-     */
-    public void writeObjectDetached(@Nullable Object obj) throws BinaryObjectException;
-
-    /**
-     * @return Output stream.
-     */
-    public PortableOutputStream out();
-
-    /**
-     * Cleans resources.
-     */
-    @Override public void close();
-
-    /**
-     * Reserve a room for an integer.
-     *
-     * @return Position in the stream where value is to be written.
-     */
-    public int reserveInt();
-
-    /**
-     * Write int value at the specific position.
-     *
-     * @param pos Position.
-     * @param val Value.
-     * @throws org.apache.ignite.binary.BinaryObjectException If failed.
-     */
-    public void writeInt(int pos, int val) throws BinaryObjectException;
-}
\ No newline at end of file


[21/59] [abbrv] ignite git commit: ignite-2065: rename "portable" packages to "binary"

Posted by ak...@apache.org.
http://git-wip-us.apache.org/repos/asf/ignite/blob/1dbf20e0/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
deleted file mode 100644
index 6a8091f..0000000
--- a/modules/core/src/main/java/org/apache/ignite/internal/portable/BinaryReaderExImpl.java
+++ /dev/null
@@ -1,2028 +0,0 @@
-/*
- * 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.portable;
-
-import java.io.EOFException;
-import java.io.IOException;
-import java.io.ObjectInput;
-import java.math.BigDecimal;
-import java.sql.Timestamp;
-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;
-import org.apache.ignite.binary.BinaryReader;
-import org.apache.ignite.internal.portable.streams.PortableInputStream;
-import org.apache.ignite.internal.util.typedef.internal.SB;
-import org.jetbrains.annotations.NotNull;
-import org.jetbrains.annotations.Nullable;
-
-import static org.apache.ignite.internal.portable.GridPortableMarshaller.BOOLEAN;
-import static org.apache.ignite.internal.portable.GridPortableMarshaller.BOOLEAN_ARR;
-import static org.apache.ignite.internal.portable.GridPortableMarshaller.BYTE;
-import static org.apache.ignite.internal.portable.GridPortableMarshaller.BYTE_ARR;
-import static org.apache.ignite.internal.portable.GridPortableMarshaller.CHAR;
-import static org.apache.ignite.internal.portable.GridPortableMarshaller.CHAR_ARR;
-import static org.apache.ignite.internal.portable.GridPortableMarshaller.CLASS;
-import static org.apache.ignite.internal.portable.GridPortableMarshaller.COL;
-import static org.apache.ignite.internal.portable.GridPortableMarshaller.DATE;
-import static org.apache.ignite.internal.portable.GridPortableMarshaller.DATE_ARR;
-import static org.apache.ignite.internal.portable.GridPortableMarshaller.DECIMAL;
-import static org.apache.ignite.internal.portable.GridPortableMarshaller.DECIMAL_ARR;
-import static org.apache.ignite.internal.portable.GridPortableMarshaller.DFLT_HDR_LEN;
-import static org.apache.ignite.internal.portable.GridPortableMarshaller.DOUBLE;
-import static org.apache.ignite.internal.portable.GridPortableMarshaller.DOUBLE_ARR;
-import static org.apache.ignite.internal.portable.GridPortableMarshaller.ENUM;
-import static org.apache.ignite.internal.portable.GridPortableMarshaller.ENUM_ARR;
-import static org.apache.ignite.internal.portable.GridPortableMarshaller.FLOAT;
-import static org.apache.ignite.internal.portable.GridPortableMarshaller.FLOAT_ARR;
-import static org.apache.ignite.internal.portable.GridPortableMarshaller.HANDLE;
-import static org.apache.ignite.internal.portable.GridPortableMarshaller.INT;
-import static org.apache.ignite.internal.portable.GridPortableMarshaller.INT_ARR;
-import static org.apache.ignite.internal.portable.GridPortableMarshaller.LONG;
-import static org.apache.ignite.internal.portable.GridPortableMarshaller.LONG_ARR;
-import static org.apache.ignite.internal.portable.GridPortableMarshaller.MAP;
-import static org.apache.ignite.internal.portable.GridPortableMarshaller.NULL;
-import static org.apache.ignite.internal.portable.GridPortableMarshaller.OBJ;
-import static org.apache.ignite.internal.portable.GridPortableMarshaller.OBJ_ARR;
-import static org.apache.ignite.internal.portable.GridPortableMarshaller.OPTM_MARSH;
-import static org.apache.ignite.internal.portable.GridPortableMarshaller.PORTABLE_OBJ;
-import static org.apache.ignite.internal.portable.GridPortableMarshaller.SHORT;
-import static org.apache.ignite.internal.portable.GridPortableMarshaller.SHORT_ARR;
-import static org.apache.ignite.internal.portable.GridPortableMarshaller.STRING;
-import static org.apache.ignite.internal.portable.GridPortableMarshaller.STRING_ARR;
-import static org.apache.ignite.internal.portable.GridPortableMarshaller.TIMESTAMP;
-import static org.apache.ignite.internal.portable.GridPortableMarshaller.TIMESTAMP_ARR;
-import static org.apache.ignite.internal.portable.GridPortableMarshaller.UNREGISTERED_TYPE_ID;
-import static org.apache.ignite.internal.portable.GridPortableMarshaller.UUID;
-import static org.apache.ignite.internal.portable.GridPortableMarshaller.UUID_ARR;
-
-/**
- * Portable reader implementation.
- */
-@SuppressWarnings("unchecked")
-public class BinaryReaderExImpl implements BinaryReader, BinaryRawReaderEx, BinaryReaderHandlesHolder, ObjectInput {
-    /** Portable context. */
-    private final PortableContext ctx;
-
-    /** Input stream. */
-    private final PortableInputStream in;
-
-    /** Class loaded. */
-    private final ClassLoader ldr;
-
-    /** Reader context which is constantly passed between objects. */
-    private BinaryReaderHandles hnds;
-
-    /** */
-    private final int start;
-
-    /** Start of actual data. Positioned right after the header. */
-    private final int dataStart;
-
-    /** Type ID. */
-    private final int typeId;
-
-    /** Raw offset. */
-    private final int rawOff;
-
-    /** Footer start. */
-    private final int footerStart;
-
-    /** Footer end. */
-    private final int footerLen;
-
-    /** ID mapper. */
-    private final BinaryIdMapper idMapper;
-
-    /** Schema Id. */
-    private final int schemaId;
-
-    /** Whether this is user type or not. */
-    private final boolean userType;
-
-    /** Whether field IDs exist. */
-    private final int fieldIdLen;
-
-    /** Offset size in bytes. */
-    private final int fieldOffsetLen;
-
-    /** Object schema. */
-    private final PortableSchema schema;
-
-    /** Whether passed IDs matches schema order. Reset to false as soon as a single mismatch detected. */
-    private boolean matching = true;
-
-    /** Order of a field whose match is expected. */
-    private int matchingOrder;
-
-    /** Whether stream is in raw mode. */
-    private boolean raw;
-
-    /**
-     * Constructor.
-     *
-     * @param ctx Context.
-     * @param in Input stream.
-     * @param ldr Class loader.
-     */
-    public BinaryReaderExImpl(PortableContext ctx, PortableInputStream in, ClassLoader ldr) {
-        this(ctx, in, ldr, null);
-    }
-
-    /**
-     * Constructor.
-     *
-     * @param ctx Context.
-     * @param in Input stream.
-     * @param ldr Class loader.
-     * @param hnds Context.
-     */
-    public BinaryReaderExImpl(PortableContext ctx, PortableInputStream in, ClassLoader ldr,
-        @Nullable BinaryReaderHandles hnds) {
-        this(ctx, in, ldr, hnds, false);
-    }
-
-    /**
-     * Constructor.
-     *
-     * @param ctx Context.
-     * @param in Input stream.
-     * @param ldr Class loader.
-     * @param hnds Context.
-     * @param skipHdrCheck Whether to skip header check.
-     */
-    public BinaryReaderExImpl(PortableContext ctx, PortableInputStream in, ClassLoader ldr,
-        @Nullable BinaryReaderHandles hnds, boolean skipHdrCheck) {
-        // Initialize base members.
-        this.ctx = ctx;
-        this.in = in;
-        this.ldr = ldr;
-        this.hnds = hnds;
-
-        start = in.position();
-
-        // Perform full header parsing in case of portable object.
-        if (!skipHdrCheck && (in.readByte() == GridPortableMarshaller.OBJ)) {
-            // Ensure protocol is fine.
-            PortableUtils.checkProtocolVersion(in.readByte());
-
-            // Read header content.
-            short flags = in.readShort();
-            int typeId0 = in.readInt();
-
-            in.readInt(); // Skip hash code.
-
-            int len = in.readInt();
-            schemaId = in.readInt();
-            int offset = in.readInt();
-
-            // Get trivial flag values.
-            userType = PortableUtils.isUserType(flags);
-            fieldIdLen = PortableUtils.fieldIdLength(flags);
-            fieldOffsetLen = PortableUtils.fieldOffsetLength(flags);
-
-            // Calculate footer borders and raw offset.
-            if (PortableUtils.hasSchema(flags)) {
-                // Schema exists.
-                footerStart = start + offset;
-
-                if (PortableUtils.hasRaw(flags)) {
-                    footerLen = len - offset - 4;
-                    rawOff = start + in.readIntPositioned(start + len - 4);
-                }
-                else {
-                    footerLen = len - offset;
-                    rawOff = start + len;
-                }
-            }
-            else {
-                // No schema.
-                footerStart = start + len;
-                footerLen = 0;
-
-                if (PortableUtils.hasRaw(flags))
-                    rawOff = start + offset;
-                else
-                    rawOff = start + len;
-            }
-
-            // Finally, we have to resolve real type ID.
-            if (typeId0 == UNREGISTERED_TYPE_ID) {
-                int off = in.position();
-
-                // Registers class by type ID, at least locally if the cache is not ready yet.
-                typeId = ctx.descriptorForClass(PortableUtils.doReadClass(in, ctx, ldr, typeId0), false).typeId();
-
-                int clsNameLen = in.position() - off;
-
-                dataStart = start + DFLT_HDR_LEN + clsNameLen;
-            }
-            else {
-                typeId = typeId0;
-
-                dataStart = start + DFLT_HDR_LEN;
-            }
-
-            idMapper = userType ? ctx.userTypeIdMapper(typeId) : BinaryInternalIdMapper.defaultInstance();
-            schema = PortableUtils.hasSchema(flags) ? getOrCreateSchema() : null;
-        }
-        else {
-            dataStart = 0;
-            typeId = 0;
-            rawOff = 0;
-            footerStart = 0;
-            footerLen = 0;
-            idMapper = null;
-            schemaId = 0;
-            userType = false;
-            fieldIdLen = 0;
-            fieldOffsetLen = 0;
-            schema = null;
-        }
-
-        streamPosition(start);
-    }
-
-    /**
-     * @return Input stream.
-     */
-    public PortableInputStream in() {
-        return in;
-    }
-
-    /**
-     * @return Descriptor.
-     */
-    PortableClassDescriptor descriptor() {
-        return ctx.descriptorForTypeId(userType, typeId, ldr, true);
-    }
-
-    /**
-     * @param offset Offset in the array.
-     * @return Unmarshalled value.
-     * @throws BinaryObjectException In case of error.
-     */
-    public Object unmarshal(int offset) throws BinaryObjectException {
-        streamPosition(offset);
-
-        return in.position() >= 0 ? PortableUtils.unmarshal(in, ctx, ldr, this) : null;
-    }
-
-    /**
-     * @param fieldName Field name.
-     * @return Unmarshalled value.
-     * @throws BinaryObjectException In case of error.
-     */
-    @Nullable Object unmarshalField(String fieldName) throws BinaryObjectException {
-        return findFieldByName(fieldName) ? PortableUtils.unmarshal(in, ctx, ldr, this) : null;
-    }
-
-    /**
-     * @param fieldId Field ID.
-     * @return Unmarshalled value.
-     * @throws BinaryObjectException In case of error.
-     */
-    @Nullable Object unmarshalField(int fieldId) throws BinaryObjectException {
-        return findFieldById(fieldId) ? PortableUtils.unmarshal(in, ctx, ldr, this) : null;
-    }
-
-    /**
-     * @param fieldId Field ID.
-     * @return Portable object.
-     * @throws BinaryObjectException In case of error.
-     */
-    @Nullable BinaryObject readPortableObject(int fieldId) throws BinaryObjectException {
-        if (findFieldById(fieldId)) {
-            if (checkFlag(PORTABLE_OBJ) == Flag.NULL)
-                return null;
-
-            return new BinaryObjectImpl(ctx, PortableUtils.doReadByteArray(in), in.readInt());
-        }
-        else
-            return null;
-    }
-
-    /**
-     * @param fieldId Field ID.
-     * @return Field class.
-     * @throws BinaryObjectException In case of error.
-     */
-    @Nullable Class<?> readClass(int fieldId) throws BinaryObjectException {
-        if (findFieldById(fieldId)) {
-            if (checkFlag(CLASS) == Flag.NULL)
-                return null;
-
-            return PortableUtils.doReadClass(in, ctx, ldr);
-        }
-
-        return null;
-    }
-
-    /**
-     * @param obj Object.
-     */
-    void setHandle(Object obj) {
-        setHandle(obj, start);
-    }
-
-    /** {@inheritDoc} */
-    @Override public void setHandle(Object obj, int pos) {
-        handles().put(pos, obj);
-    }
-
-    /** {@inheritDoc} */
-    @Override public Object getHandle(int pos) {
-        return hnds != null ? hnds.get(pos) : null;
-    }
-
-    /** {@inheritDoc} */
-    @Override public BinaryReaderHandles handles() {
-        if (hnds == null)
-            hnds = new BinaryReaderHandles();
-
-        return hnds;
-    }
-
-    /**
-     * Recreating field value from a handle.
-     *
-     * @param <T> Field type.
-     * @return Field.
-     */
-    private <T> T readHandleField() {
-        int handlePos = PortableUtils.positionForHandle(in) - in.readInt();
-
-        Object obj = getHandle(handlePos);
-
-        if (obj == null) {
-            int retPos = in.position();
-
-            streamPosition(handlePos);
-
-            obj = PortableUtils.doReadObject(in, ctx, ldr, this);
-
-            streamPosition(retPos);
-        }
-
-        return (T)obj;
-    }
-    /** {@inheritDoc} */
-    @Override public byte readByte(String fieldName) throws BinaryObjectException {
-        return findFieldByName(fieldName) && checkFlagNoHandles(BYTE) == Flag.NORMAL ? in.readByte() : 0;
-    }
-
-    /**
-     * @param fieldId Field ID.
-     * @return Value.
-     * @throws BinaryObjectException If failed.
-     */
-    byte readByte(int fieldId) throws BinaryObjectException {
-        return findFieldById(fieldId) && checkFlagNoHandles(BYTE) == Flag.NORMAL ? in.readByte() : 0;
-    }
-
-    /**
-     * @param fieldId Field ID.
-     * @return Value.
-     * @throws BinaryObjectException In case of error.
-     */
-    @Nullable Byte readByteNullable(int fieldId) throws BinaryObjectException {
-        return findFieldById(fieldId) && checkFlagNoHandles(BYTE) == Flag.NORMAL ? in.readByte() : null;
-    }
-
-    /** {@inheritDoc} */
-    @Override public byte readByte() throws BinaryObjectException {
-        return in.readByte();
-    }
-
-    /** {@inheritDoc} */
-    @Nullable @Override public byte[] readByteArray(String fieldName) throws BinaryObjectException {
-        return findFieldByName(fieldName) ? this.readByteArray() : null;
-    }
-
-    /**
-     * @param fieldId Field ID.
-     * @return Value.
-     * @throws BinaryObjectException In case of error.
-     */
-    @Nullable byte[] readByteArray(int fieldId) throws BinaryObjectException {
-        return findFieldById(fieldId) ? this.readByteArray() : null;
-    }
-
-    /** {@inheritDoc} */
-    @Nullable @Override public byte[] readByteArray() throws BinaryObjectException {
-        switch (checkFlag(BYTE_ARR)) {
-            case NORMAL:
-                return PortableUtils.doReadByteArray(in);
-
-            case HANDLE:
-                return readHandleField();
-
-            default:
-                return null;
-        }
-    }
-
-    /** {@inheritDoc} */
-    @Override public boolean readBoolean(String fieldName) throws BinaryObjectException {
-        return findFieldByName(fieldName) && checkFlagNoHandles(BOOLEAN) == Flag.NORMAL && in.readBoolean();
-    }
-
-    /**
-     * @param fieldId Field ID.
-     * @return Value.
-     * @throws BinaryObjectException If failed.
-     */
-    boolean readBoolean(int fieldId) throws BinaryObjectException {
-        return findFieldById(fieldId) && checkFlagNoHandles(BOOLEAN) == Flag.NORMAL && in.readBoolean();
-    }
-
-    /**
-     * @param fieldId Field ID.
-     * @return Value.
-     * @throws BinaryObjectException In case of error.
-     */
-    @Nullable Boolean readBooleanNullable(int fieldId) throws BinaryObjectException {
-        return findFieldById(fieldId) && checkFlagNoHandles(BOOLEAN) == Flag.NORMAL ? in.readBoolean() : null;
-    }
-
-    /** {@inheritDoc} */
-    @Override public boolean readBoolean() throws BinaryObjectException {
-        return in.readBoolean();
-    }
-
-    /** {@inheritDoc} */
-    @Nullable @Override public boolean[] readBooleanArray(String fieldName) throws BinaryObjectException {
-        return findFieldByName(fieldName) ? this.readBooleanArray() : null;
-    }
-
-    /**
-     * @param fieldId Field ID.
-     * @return Value.
-     * @throws BinaryObjectException In case of error.
-     */
-    @Nullable boolean[] readBooleanArray(int fieldId) throws BinaryObjectException {
-        return findFieldById(fieldId) ? this.readBooleanArray() : null;
-    }
-
-    /** {@inheritDoc} */
-    @Nullable @Override public boolean[] readBooleanArray() throws BinaryObjectException {
-        switch (checkFlag(BOOLEAN_ARR)) {
-            case NORMAL:
-                return PortableUtils.doReadBooleanArray(in);
-
-            case HANDLE:
-                return readHandleField();
-
-            default:
-                return null;
-        }
-    }
-
-    /** {@inheritDoc} */
-    @Override public short readShort(String fieldName) throws BinaryObjectException {
-        return findFieldByName(fieldName) && checkFlagNoHandles(SHORT) == Flag.NORMAL ? in.readShort() : 0;
-    }
-
-    /**
-     * @param fieldId Field ID.
-     * @return Value.
-     * @throws BinaryObjectException If failed.
-     */
-    short readShort(int fieldId) throws BinaryObjectException {
-        return findFieldById(fieldId) && checkFlagNoHandles(SHORT) == Flag.NORMAL ? in.readShort() : 0;
-    }
-
-    /**
-     * @param fieldId Field ID.
-     * @return Value.
-     * @throws BinaryObjectException In case of error.
-     */
-    @Nullable Short readShortNullable(int fieldId) throws BinaryObjectException {
-        return findFieldById(fieldId) && checkFlagNoHandles(SHORT) == Flag.NORMAL ? in.readShort() : null;
-    }
-
-    /** {@inheritDoc} */
-    @Override public short readShort() throws BinaryObjectException {
-        return in.readShort();
-    }
-
-    /** {@inheritDoc} */
-    @Nullable @Override public short[] readShortArray(String fieldName) throws BinaryObjectException {
-        return findFieldByName(fieldName) ? this.readShortArray() : null;
-    }
-
-    /**
-     * @param fieldId Field ID.
-     * @return Value.
-     * @throws BinaryObjectException In case of error.
-     */
-    @Nullable short[] readShortArray(int fieldId) throws BinaryObjectException {
-        return findFieldById(fieldId) ? this.readShortArray() : null;
-    }
-
-    /** {@inheritDoc} */
-    @Nullable @Override public short[] readShortArray() throws BinaryObjectException {
-        switch (checkFlag(SHORT_ARR)) {
-            case NORMAL:
-                return PortableUtils.doReadShortArray(in);
-
-            case HANDLE:
-                return readHandleField();
-
-            default:
-                return null;
-        }
-    }
-
-    /** {@inheritDoc} */
-    @Override public char readChar(String fieldName) throws BinaryObjectException {
-        return findFieldByName(fieldName) && checkFlagNoHandles(CHAR) == Flag.NORMAL ? in.readChar() : 0;
-    }
-
-    /**
-     * @param fieldId Field ID.
-     * @return Value.
-     * @throws BinaryObjectException If failed.
-     */
-    char readChar(int fieldId) throws BinaryObjectException {
-        return findFieldById(fieldId) && checkFlagNoHandles(CHAR) == Flag.NORMAL ? in.readChar() : 0;
-    }
-
-    /**
-     * @param fieldId Field ID.
-     * @return Value.
-     * @throws BinaryObjectException In case of error.
-     */
-    @Nullable Character readCharNullable(int fieldId) throws BinaryObjectException {
-        return findFieldById(fieldId) && checkFlagNoHandles(CHAR) == Flag.NORMAL ? in.readChar() : null;
-    }
-
-    /** {@inheritDoc} */
-    @Override public char readChar() throws BinaryObjectException {
-        return in.readChar();
-    }
-
-    /** {@inheritDoc} */
-    @Nullable @Override public char[] readCharArray(String fieldName) throws BinaryObjectException {
-        return findFieldByName(fieldName) ? this.readCharArray() : null;
-    }
-
-    /**
-     * @param fieldId Field ID.
-     * @return Value.
-     * @throws BinaryObjectException In case of error.
-     */
-    @Nullable char[] readCharArray(int fieldId) throws BinaryObjectException {
-        return findFieldById(fieldId) ? this.readCharArray() : null;
-    }
-
-    /** {@inheritDoc} */
-    @Nullable @Override public char[] readCharArray() throws BinaryObjectException {
-        switch (checkFlag(CHAR_ARR)) {
-            case NORMAL:
-                return PortableUtils.doReadCharArray(in);
-
-            case HANDLE:
-                return readHandleField();
-
-            default:
-                return null;
-        }
-    }
-
-    /** {@inheritDoc} */
-    @Override public int readInt(String fieldName) throws BinaryObjectException {
-        return findFieldByName(fieldName) && checkFlagNoHandles(INT) == Flag.NORMAL ? in.readInt() : 0;
-    }
-
-    /**
-     * @param fieldId Field ID.
-     * @return Value.
-     * @throws BinaryObjectException If failed.
-     */
-    int readInt(int fieldId) throws BinaryObjectException {
-        return findFieldById(fieldId) && checkFlagNoHandles(INT) == Flag.NORMAL ? in.readInt() : 0;
-    }
-
-    /**
-     * @param fieldId Field ID.
-     * @return Value.
-     * @throws BinaryObjectException In case of error.
-     */
-    @Nullable Integer readIntNullable(int fieldId) throws BinaryObjectException {
-        return findFieldById(fieldId) && checkFlagNoHandles(INT) == Flag.NORMAL ? in.readInt() : null;
-    }
-    
-    /** {@inheritDoc} */
-    @Override public int readInt() throws BinaryObjectException {
-        return in.readInt();
-    }
-
-    /** {@inheritDoc} */
-    @Nullable @Override public int[] readIntArray(String fieldName) throws BinaryObjectException {
-        return findFieldByName(fieldName) ? this.readIntArray() : null;
-    }
-
-    /**
-     * @param fieldId Field ID.
-     * @return Value.
-     * @throws BinaryObjectException In case of error.
-     */
-    @Nullable int[] readIntArray(int fieldId) throws BinaryObjectException {
-        return findFieldById(fieldId) ? this.readIntArray() : null;
-    }
-
-    /** {@inheritDoc} */
-    @Nullable @Override public int[] readIntArray() throws BinaryObjectException {
-        switch (checkFlag(INT_ARR)) {
-            case NORMAL:
-                return PortableUtils.doReadIntArray(in);
-
-            case HANDLE:
-                return readHandleField();
-
-            default:
-                return null;
-        }
-    }
-
-    /** {@inheritDoc} */
-    @Override public long readLong(String fieldName) throws BinaryObjectException {
-        return findFieldByName(fieldName) && checkFlagNoHandles(LONG) == Flag.NORMAL ? in.readLong() : 0;
-    }
-
-    /**
-     * @param fieldId Field ID.
-     * @return Value.
-     * @throws BinaryObjectException If failed.
-     */
-    long readLong(int fieldId) throws BinaryObjectException {
-        return findFieldById(fieldId) && checkFlagNoHandles(LONG) == Flag.NORMAL ? in.readLong() : 0;
-    }
-
-    /**
-     * @param fieldId Field ID.
-     * @return Value.
-     * @throws BinaryObjectException In case of error.
-     */
-    @Nullable Long readLongNullable(int fieldId) throws BinaryObjectException {
-        return findFieldById(fieldId) && checkFlagNoHandles(LONG) == Flag.NORMAL ? in.readLong() : null;
-    }
-
-    /** {@inheritDoc} */
-    @Override public long readLong() throws BinaryObjectException {
-        return in.readLong();
-    }
-
-    /** {@inheritDoc} */
-    @Nullable @Override public long[] readLongArray(String fieldName) throws BinaryObjectException {
-        return findFieldByName(fieldName) ? this.readLongArray() : null;
-    }
-
-    /**
-     * @param fieldId Field ID.
-     * @return Value.
-     * @throws BinaryObjectException In case of error.
-     */
-    @Nullable long[] readLongArray(int fieldId) throws BinaryObjectException {
-        return findFieldById(fieldId) ? this.readLongArray() : null;
-    }
-
-    /** {@inheritDoc} */
-    @Nullable @Override public long[] readLongArray() throws BinaryObjectException {
-        switch (checkFlag(LONG_ARR)) {
-            case NORMAL:
-                return PortableUtils.doReadLongArray(in);
-
-            case HANDLE:
-                return readHandleField();
-
-            default:
-                return null;
-        }
-    }
-
-    /** {@inheritDoc} */
-    @Override public float readFloat(String fieldName) throws BinaryObjectException {
-        return findFieldByName(fieldName) && checkFlagNoHandles(FLOAT) == Flag.NORMAL ? in.readFloat() : 0;
-    }
-
-    /**
-     * @param fieldId Field ID.
-     * @return Value.
-     * @throws BinaryObjectException If failed.
-     */
-    float readFloat(int fieldId) throws BinaryObjectException {
-        return findFieldById(fieldId) && checkFlagNoHandles(FLOAT) == Flag.NORMAL ? in.readFloat() : 0;
-    }
-
-    /**
-     * @param fieldId Field ID.
-     * @return Value.
-     * @throws BinaryObjectException In case of error.
-     */
-    @Nullable Float readFloatNullable(int fieldId) throws BinaryObjectException {
-        return findFieldById(fieldId) && checkFlagNoHandles(FLOAT) == Flag.NORMAL ? in.readFloat() : null;
-    }
-
-    /** {@inheritDoc} */
-    @Override public float readFloat() throws BinaryObjectException {
-        return in.readFloat();
-    }
-
-    /** {@inheritDoc} */
-    @Nullable @Override public float[] readFloatArray(String fieldName) throws BinaryObjectException {
-        return findFieldByName(fieldName) ? this.readFloatArray() : null;
-    }
-
-    /**
-     * @param fieldId Field ID.
-     * @return Value.
-     * @throws BinaryObjectException In case of error.
-     */
-    @Nullable float[] readFloatArray(int fieldId) throws BinaryObjectException {
-        return findFieldById(fieldId) ? this.readFloatArray() : null;
-    }
-
-    /** {@inheritDoc} */
-    @Nullable @Override public float[] readFloatArray() throws BinaryObjectException {
-        switch (checkFlag(FLOAT_ARR)) {
-            case NORMAL:
-                return PortableUtils.doReadFloatArray(in);
-
-            case HANDLE:
-                return readHandleField();
-
-            default:
-                return null;
-        }
-    }
-
-    /** {@inheritDoc} */
-    @Override public double readDouble(String fieldName) throws BinaryObjectException {
-        return findFieldByName(fieldName) && checkFlagNoHandles(DOUBLE) == Flag.NORMAL ? in.readDouble() : 0;
-    }
-
-    /**
-     * @param fieldId Field ID.
-     * @return Value.
-     * @throws BinaryObjectException If failed.
-     */
-    double readDouble(int fieldId) throws BinaryObjectException {
-        return findFieldById(fieldId) && checkFlagNoHandles(DOUBLE) == Flag.NORMAL ? in.readDouble() : 0;
-    }
-
-    /**
-     * @param fieldId Field ID.
-     * @return Value.
-     * @throws BinaryObjectException In case of error.
-     */
-    @Nullable Double readDoubleNullable(int fieldId) throws BinaryObjectException {
-        return findFieldById(fieldId) && checkFlagNoHandles(DOUBLE) == Flag.NORMAL ? in.readDouble() : null;
-    }
-
-    /** {@inheritDoc} */
-    @Override public double readDouble() throws BinaryObjectException {
-        return in.readDouble();
-    }
-
-    /** {@inheritDoc} */
-    @Nullable @Override public double[] readDoubleArray(String fieldName) throws BinaryObjectException {
-        return findFieldByName(fieldName) ? this.readDoubleArray() : null;
-    }
-
-    /**
-     * @param fieldId Field ID.
-     * @return Value.
-     * @throws BinaryObjectException In case of error.
-     */
-    @Nullable double[] readDoubleArray(int fieldId) throws BinaryObjectException {
-        return findFieldById(fieldId) ? this.readDoubleArray() : null;
-    }
-
-    /** {@inheritDoc} */
-    @Nullable @Override public double[] readDoubleArray() throws BinaryObjectException {
-        switch (checkFlag(DOUBLE_ARR)) {
-            case NORMAL:
-                return PortableUtils.doReadDoubleArray(in);
-
-            case HANDLE:
-                return readHandleField();
-
-            default:
-                return null;
-        }
-    }
-
-    /** {@inheritDoc} */
-    @Override @Nullable public BigDecimal readDecimal(String fieldName) throws BinaryObjectException {
-        return findFieldByName(fieldName) ? this.readDecimal() : null;
-    }
-
-    /**
-     * @param fieldId Field ID.
-     * @return Value.
-     * @throws BinaryObjectException In case of error.
-     */
-    @Nullable BigDecimal readDecimal(int fieldId) throws BinaryObjectException {
-        return findFieldById(fieldId) ? this.readDecimal() : null;
-    }
-
-    /** {@inheritDoc} */
-    @Override @Nullable public BigDecimal readDecimal() throws BinaryObjectException {
-        return checkFlagNoHandles(DECIMAL) == Flag.NORMAL ? PortableUtils.doReadDecimal(in) : null;
-    }
-
-    /** {@inheritDoc} */
-    @Override @Nullable public BigDecimal[] readDecimalArray(String fieldName) throws BinaryObjectException {
-        return findFieldByName(fieldName) ? this.readDecimalArray() : null;
-    }
-
-    /**
-     * @param fieldId Field ID.
-     * @return Value.
-     * @throws BinaryObjectException In case of error.
-     */
-    @Nullable BigDecimal[] readDecimalArray(int fieldId) throws BinaryObjectException {
-        return findFieldById(fieldId) ? this.readDecimalArray() : null;
-    }
-
-    /** {@inheritDoc} */
-    @Override @Nullable public BigDecimal[] readDecimalArray() throws BinaryObjectException {
-        switch (checkFlag(DECIMAL_ARR)) {
-            case NORMAL:
-                return PortableUtils.doReadDecimalArray(in);
-
-            case HANDLE:
-                return readHandleField();
-
-            default:
-                return null;
-        }
-    }
-
-    /** {@inheritDoc} */
-    @Override @Nullable public String readString(String fieldName) throws BinaryObjectException {
-        return findFieldByName(fieldName) ? this.readString() : null;
-    }
-
-    /**
-     * @param fieldId Field ID.
-     * @return Value.
-     * @throws BinaryObjectException In case of error.
-     */
-    @Nullable String readString(int fieldId) throws BinaryObjectException {
-        return findFieldById(fieldId) ? this.readString() : null;
-    }
-
-    /** {@inheritDoc} */
-    @Override @Nullable public String readString() throws BinaryObjectException {
-        return checkFlagNoHandles(STRING) == Flag.NORMAL ? PortableUtils.doReadString(in) : null;
-    }
-
-    /** {@inheritDoc} */
-    @Override @Nullable public String[] readStringArray(String fieldName) throws BinaryObjectException {
-        return findFieldByName(fieldName) ? this.readStringArray() : null;
-    }
-
-    /**
-     * @param fieldId Field ID.
-     * @return Value.
-     * @throws BinaryObjectException In case of error.
-     */
-    @Nullable String[] readStringArray(int fieldId) throws BinaryObjectException {
-        return findFieldById(fieldId) ? this.readStringArray() : null;
-    }
-
-    /** {@inheritDoc} */
-    @Override @Nullable public String[] readStringArray() throws BinaryObjectException {
-        switch (checkFlag(STRING_ARR)) {
-            case NORMAL:
-                return PortableUtils.doReadStringArray(in);
-
-            case HANDLE:
-                return readHandleField();
-
-            default:
-                return null;
-        }
-    }
-
-    /** {@inheritDoc} */
-    @Override @Nullable public UUID readUuid(String fieldName) throws BinaryObjectException {
-        return findFieldByName(fieldName) ? this.readUuid() : null;
-    }
-
-    /**
-     * @param fieldId Field ID.
-     * @return Value.
-     * @throws BinaryObjectException In case of error.
-     */
-    @Nullable UUID readUuid(int fieldId) throws BinaryObjectException {
-        return findFieldById(fieldId) ? this.readUuid() : null;
-    }
-
-    /** {@inheritDoc} */
-    @Override @Nullable public UUID readUuid() throws BinaryObjectException {
-        return checkFlagNoHandles(UUID) == Flag.NORMAL ? PortableUtils.doReadUuid(in) : null;
-    }
-
-    /** {@inheritDoc} */
-    @Override @Nullable public UUID[] readUuidArray(String fieldName) throws BinaryObjectException {
-        return findFieldByName(fieldName) ? this.readUuidArray() : null;
-    }
-
-    /**
-     * @param fieldId Field ID.
-     * @return Value.
-     * @throws BinaryObjectException In case of error.
-     */
-    @Nullable UUID[] readUuidArray(int fieldId) throws BinaryObjectException {
-        return findFieldById(fieldId) ? this.readUuidArray() : null;
-    }
-
-    /** {@inheritDoc} */
-    @Override @Nullable public UUID[] readUuidArray() throws BinaryObjectException {
-        switch (checkFlag(UUID_ARR)) {
-            case NORMAL:
-                return PortableUtils.doReadUuidArray(in);
-
-            case HANDLE:
-                return readHandleField();
-
-            default:
-                return null;
-        }
-    }
-
-    /** {@inheritDoc} */
-    @Override @Nullable public Date readDate(String fieldName) throws BinaryObjectException {
-        return findFieldByName(fieldName) ? this.readDate() : null;
-    }
-
-    /**
-     * @param fieldId Field ID.
-     * @return Value.
-     * @throws BinaryObjectException In case of error.
-     */
-    @Nullable Date readDate(int fieldId) throws BinaryObjectException {
-        return findFieldById(fieldId) ? this.readDate() : null;
-    }
-
-    /** {@inheritDoc} */
-    @Override @Nullable public Date readDate() throws BinaryObjectException {
-        return checkFlagNoHandles(DATE) == Flag.NORMAL ? PortableUtils.doReadDate(in) : null;
-    }
-
-    /** {@inheritDoc} */
-    @Override @Nullable public Date[] readDateArray(String fieldName) throws BinaryObjectException {
-        return findFieldByName(fieldName) ? this.readDateArray() : null;
-    }
-
-    /**
-     * @param fieldId Field ID.
-     * @return Value.
-     * @throws BinaryObjectException In case of error.
-     */
-    @Nullable Date[] readDateArray(int fieldId) throws BinaryObjectException {
-        return findFieldById(fieldId) ? this.readDateArray() : null;
-    }
-
-    /** {@inheritDoc} */
-    @Override @Nullable public Date[] readDateArray() throws BinaryObjectException {
-        switch (checkFlag(DATE_ARR)) {
-            case NORMAL:
-                return PortableUtils.doReadDateArray(in);
-
-            case HANDLE:
-                return readHandleField();
-
-            default:
-                return null;
-        }
-    }
-
-    /** {@inheritDoc} */
-    @Override @Nullable public Timestamp readTimestamp(String fieldName) throws BinaryObjectException {
-        return findFieldByName(fieldName) ? this.readTimestamp() : null;
-    }
-
-    /**
-     * @param fieldId Field ID.
-     * @return Value.
-     * @throws BinaryObjectException In case of error.
-     */
-    @Nullable Timestamp readTimestamp(int fieldId) throws BinaryObjectException {
-        return findFieldById(fieldId) ? this.readTimestamp() : null;
-    }
-
-    /** {@inheritDoc} */
-    @Override @Nullable public Timestamp readTimestamp() throws BinaryObjectException {
-        return checkFlagNoHandles(TIMESTAMP) == Flag.NORMAL ? PortableUtils.doReadTimestamp(in) : null;
-    }
-
-    /** {@inheritDoc} */
-    @Override @Nullable public Timestamp[] readTimestampArray(String fieldName) throws BinaryObjectException {
-        return findFieldByName(fieldName) ? this.readTimestampArray() : null;
-    }
-
-    /**
-     * @param fieldId Field ID.
-     * @return Value.
-     * @throws BinaryObjectException In case of error.
-     */
-    @Nullable Timestamp[] readTimestampArray(int fieldId) throws BinaryObjectException {
-        return findFieldById(fieldId) ? this.readTimestampArray() : null;
-    }
-
-    /** {@inheritDoc} */
-    @Override @Nullable public Timestamp[] readTimestampArray() throws BinaryObjectException {
-        switch (checkFlag(TIMESTAMP_ARR)) {
-            case NORMAL:
-                return PortableUtils.doReadTimestampArray(in);
-
-            case HANDLE:
-                return readHandleField();
-
-            default:
-                return null;
-        }
-    }
-
-    /** {@inheritDoc} */
-    @SuppressWarnings("unchecked")
-    @Nullable @Override public <T> T readObject(String fieldName) throws BinaryObjectException {
-        return findFieldByName(fieldName) ? (T)PortableUtils.doReadObject(in, ctx, ldr, this) : null;
-    }
-
-    /**
-     * @param fieldId Field ID.
-     * @return Value.
-     * @throws BinaryObjectException In case of error.
-     */
-    @Nullable Object readObject(int fieldId) throws BinaryObjectException {
-        return findFieldById(fieldId) ? PortableUtils.doReadObject(in, ctx, ldr, this) : null;
-    }
-
-    /** {@inheritDoc} */
-    @Override public Object readObject() throws BinaryObjectException {
-        return PortableUtils.doReadObject(in, ctx, ldr, this);
-    }
-
-    /** {@inheritDoc} */
-    @Nullable @Override public Object readObjectDetached() throws BinaryObjectException {
-        return PortableUtils.unmarshal(in, ctx, ldr, this, true);
-    }
-
-    /** {@inheritDoc} */
-    @Nullable @Override public Object[] readObjectArray(String fieldName) throws BinaryObjectException {
-        return findFieldByName(fieldName) ? this.readObjectArray() : null;
-    }
-
-    /**
-     * @param fieldId Field ID.
-     * @return Value.
-     * @throws BinaryObjectException In case of error.
-     */
-    @Nullable Object[] readObjectArray(int fieldId) throws BinaryObjectException {
-        return findFieldById(fieldId) ? this.readObjectArray() : null;
-    }
-
-    /** {@inheritDoc} */
-    @Nullable @Override public Object[] readObjectArray() throws BinaryObjectException {
-        switch (checkFlag(OBJ_ARR)) {
-            case NORMAL:
-                return PortableUtils.doReadObjectArray(in, ctx, ldr, this, true);
-
-            case HANDLE:
-                return readHandleField();
-
-            default:
-                return null;
-        }
-    }
-
-    /** {@inheritDoc} */
-    @Nullable @Override public <T extends Enum<?>> T readEnum(String fieldName) throws BinaryObjectException {
-        return findFieldByName(fieldName) ? (T)readEnum0(null) : null;
-    }
-
-    /**
-     * @param fieldId Field ID.
-     * @param cls Class.
-     * @return Value.
-     * @throws BinaryObjectException In case of error.
-     */
-    @Nullable Enum<?> readEnum(int fieldId, @Nullable Class<?> cls) throws BinaryObjectException {
-        return findFieldById(fieldId) ? readEnum0(cls) : null;
-    }
-
-    /** {@inheritDoc} */
-    @Nullable @Override public <T extends Enum<?>> T readEnum() throws BinaryObjectException {
-        return (T)readEnum0(null);
-    }
-
-    /**
-     * Internal routine to read enum for named field.
-     *
-     * @param cls Class.
-     * @return Value.
-     * @throws BinaryObjectException In case of error.
-     */
-    private Enum<?> readEnum0(@Nullable Class<?> cls) throws BinaryObjectException {
-        if (checkFlagNoHandles(ENUM) == Flag.NORMAL) {
-            // Read class even if we know it in advance to set correct stream position.
-            Class<?> cls0 = PortableUtils.doReadClass(in, ctx, ldr);
-
-            if (cls == null)
-                cls = cls0;
-
-            return PortableUtils.doReadEnum(in, cls);
-        }
-        else
-            return null;
-    }
-
-    /** {@inheritDoc} */
-    @Nullable @Override public <T extends Enum<?>> T[] readEnumArray(String fieldName)
-        throws BinaryObjectException {
-        return findFieldByName(fieldName) ? (T[])readEnumArray0(null) : null;
-    }
-
-    /**
-     * @param fieldId Field ID.
-     * @param cls Class.
-     * @return Value.
-     * @throws BinaryObjectException In case of error.
-     */
-    @Nullable Object[] readEnumArray(int fieldId, @Nullable Class<?> cls) throws BinaryObjectException {
-        return findFieldById(fieldId) ? readEnumArray0(cls) : null;
-    }
-
-    /** {@inheritDoc} */
-    @Nullable @Override public <T extends Enum<?>> T[] readEnumArray() throws BinaryObjectException {
-        return (T[])readEnumArray0(null);
-    }
-
-    /**
-     * Internal routine to read enum for named field.
-     *
-     * @param cls Class.
-     * @return Value.
-     * @throws BinaryObjectException In case of error.
-     */
-    private Object[] readEnumArray0(@Nullable Class<?> cls) throws BinaryObjectException {
-        switch (checkFlag(ENUM_ARR)) {
-            case NORMAL:
-                // Read class even if we know it in advance to set correct stream position.
-                Class<?> cls0 = PortableUtils.doReadClass(in, ctx, ldr);
-
-                if (cls == null)
-                    cls = cls0;
-
-                return PortableUtils.doReadEnumArray(in, ctx, ldr, cls);
-
-            case HANDLE:
-                return readHandleField();
-
-            default:
-                return null;
-        }
-    }
-
-    /** {@inheritDoc} */
-    @Nullable @Override public <T> Collection<T> readCollection(String fieldName) throws BinaryObjectException {
-        return findFieldByName(fieldName) ? (Collection<T>)readCollection0(null) : null;
-    }
-
-    /** {@inheritDoc} */
-    @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 factory Collection factory.
-     * @return Value.
-     * @throws BinaryObjectException In case of error.
-     */
-    @Nullable <T> Collection<T> readCollection(int fieldId, @Nullable BinaryCollectionFactory<T> factory)
-        throws BinaryObjectException {
-        return findFieldById(fieldId) ? (Collection<T>)readCollection0(factory) : null;
-    }
-
-    /** {@inheritDoc} */
-    @Nullable @Override public <T> Collection<T> readCollection() throws BinaryObjectException {
-        return readCollection0(null);
-    }
-
-    /** {@inheritDoc} */
-    @Nullable @Override public <T> Collection<T> readCollection(BinaryCollectionFactory<T> factory)
-        throws BinaryObjectException {
-        return readCollection0(factory);
-    }
-
-    /**
-     * Internal read collection routine.
-     *
-     * @param factory Collection factory.
-     * @return Value.
-     * @throws BinaryObjectException If failed.
-     */
-    private Collection readCollection0(@Nullable BinaryCollectionFactory factory)
-        throws BinaryObjectException {
-        switch (checkFlag(COL)) {
-            case NORMAL:
-                return (Collection)PortableUtils.doReadCollection(in, ctx, ldr, this, true, factory);
-
-            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;
-        }
-    }
-
-    /** {@inheritDoc} */
-    @Nullable @Override public <K, V> Map<K, V> readMap(String fieldName) throws BinaryObjectException {
-        return findFieldByName(fieldName) ? (Map<K, V>)readMap0(null) : null;
-    }
-
-    /** {@inheritDoc} */
-    @Nullable @Override public <K, V> Map<K, V> readMap(String fieldName, BinaryMapFactory<K, V> factory)
-        throws BinaryObjectException {
-        return findFieldByName(fieldName) ? readMap0(factory) : null;
-    }
-
-    /**
-     * @param fieldId Field ID.
-     * @param factory Factory.
-     * @return Value.
-     * @throws BinaryObjectException In case of error.
-     */
-    @Nullable Map<?, ?> readMap(int fieldId, @Nullable BinaryMapFactory factory) throws BinaryObjectException {
-        return findFieldById(fieldId) ? readMap0(factory) : null;
-    }
-
-    /** {@inheritDoc} */
-    @Nullable @Override public <K, V> Map<K, V> readMap() throws BinaryObjectException {
-        return readMap0(null);
-    }
-
-    /** {@inheritDoc} */
-    @Nullable @Override public <K, V> Map<K, V> readMap(BinaryMapFactory<K, V> factory)
-        throws BinaryObjectException {
-        return readMap0(factory);
-    }
-
-    /**
-     * Internal read map routine.
-     *
-     * @param factory Factory.
-     * @return Value.
-     * @throws BinaryObjectException If failed.
-     */
-    private Map readMap0(@Nullable BinaryMapFactory factory) throws BinaryObjectException {
-        switch (checkFlag(MAP)) {
-            case NORMAL:
-                return (Map)PortableUtils.doReadMap(in, ctx, ldr, this, true, factory);
-
-            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;
-        }
-    }
-
-    /**
-     * Ensure that type flag is either null, handle or contains expected value.
-     *
-     * @param expFlag Expected value.
-     * @return Flag mode.
-     * @throws BinaryObjectException If flag is neither null, nor handle or expected.
-     */
-    private Flag checkFlag(byte expFlag) {
-        byte flag = in.readByte();
-
-        if (flag == expFlag)
-            return Flag.NORMAL;
-        else if (flag == NULL)
-            return Flag.NULL;
-        else if (flag == HANDLE)
-            return Flag.HANDLE;
-
-        int pos = PortableUtils.positionForHandle(in);
-
-        throw new BinaryObjectException("Unexpected flag value [pos=" + pos + ", expected=" + expFlag +
-            ", actual=" + flag + ']');
-    }
-
-    /**
-     * Ensure that type flag is either null or contains expected value.
-     *
-     * @param expFlag Expected value.
-     * @return Flag mode.
-     * @throws BinaryObjectException If flag is neither null, nor expected.
-     */
-    private Flag checkFlagNoHandles(byte expFlag) {
-        byte flag = in.readByte();
-
-        if (flag == expFlag)
-            return Flag.NORMAL;
-        else if (flag == NULL)
-            return Flag.NULL;
-
-        int pos = PortableUtils.positionForHandle(in);
-
-        throw new BinaryObjectException("Unexpected flag value [pos=" + pos + ", expected=" + expFlag +
-            ", actual=" + flag + ']');
-    }
-
-    /** {@inheritDoc} */
-    @Override public BinaryRawReader rawReader() {
-        if (!raw) {
-            streamPositionRandom(rawOff);
-
-            raw = true;
-
-            return this;
-        }
-        else
-            throw new BinaryObjectException("Method \"rawReader\" can be called only once.");
-    }
-
-    /**
-     * @return Deserialized object.
-     * @throws BinaryObjectException If failed.
-     */
-    @Nullable Object deserialize() throws BinaryObjectException {
-        Object obj;
-
-        byte flag = in.readByte();
-
-        switch (flag) {
-            case NULL:
-                obj = null;
-
-                break;
-
-            case HANDLE:
-                int handlePos = start - in.readInt();
-
-                obj = getHandle(handlePos);
-
-                if (obj == null) {
-                    int retPos = in.position();
-
-                    streamPosition(handlePos);
-
-                    obj = PortableUtils.doReadObject(in, ctx, ldr, this);
-
-                    streamPosition(retPos);
-                }
-
-                break;
-
-            case OBJ:
-                PortableClassDescriptor desc = ctx.descriptorForTypeId(userType, typeId, ldr, true);
-
-                streamPosition(dataStart);
-
-                if (desc == null)
-                    throw new BinaryInvalidTypeException("Unknown type ID: " + typeId);
-
-                obj = desc.read(this);
-
-                streamPosition(footerStart + footerLen);
-
-                break;
-
-            case BYTE:
-                obj = in.readByte();
-
-                break;
-
-            case SHORT:
-                obj = in.readShort();
-
-                break;
-
-            case INT:
-                obj = in.readInt();
-
-                break;
-
-            case LONG:
-                obj = in.readLong();
-
-                break;
-
-            case FLOAT:
-                obj = in.readFloat();
-
-                break;
-
-            case DOUBLE:
-                obj = in.readDouble();
-
-                break;
-
-            case CHAR:
-                obj = in.readChar();
-
-                break;
-
-            case BOOLEAN:
-                obj = in.readBoolean();
-
-                break;
-
-            case DECIMAL:
-                obj = PortableUtils.doReadDecimal(in);
-
-                break;
-
-            case STRING:
-                obj = PortableUtils.doReadString(in);
-
-                break;
-
-            case UUID:
-                obj = PortableUtils.doReadUuid(in);
-
-                break;
-
-            case DATE:
-                obj = PortableUtils.doReadDate(in);
-
-                break;
-
-            case TIMESTAMP:
-                obj = PortableUtils.doReadTimestamp(in);
-
-                break;
-
-            case BYTE_ARR:
-                obj = PortableUtils.doReadByteArray(in);
-
-                break;
-
-            case SHORT_ARR:
-                obj = PortableUtils.doReadShortArray(in);
-
-                break;
-
-            case INT_ARR:
-                obj = PortableUtils.doReadIntArray(in);
-
-                break;
-
-            case LONG_ARR:
-                obj = PortableUtils.doReadLongArray(in);
-
-                break;
-
-            case FLOAT_ARR:
-                obj = PortableUtils.doReadFloatArray(in);
-
-                break;
-
-            case DOUBLE_ARR:
-                obj = PortableUtils.doReadDoubleArray(in);
-
-                break;
-
-            case CHAR_ARR:
-                obj = PortableUtils.doReadCharArray(in);
-
-                break;
-
-            case BOOLEAN_ARR:
-                obj = PortableUtils.doReadBooleanArray(in);
-
-                break;
-
-            case DECIMAL_ARR:
-                obj = PortableUtils.doReadDecimalArray(in);
-
-                break;
-
-            case STRING_ARR:
-                obj = PortableUtils.doReadStringArray(in);
-
-                break;
-
-            case UUID_ARR:
-                obj = PortableUtils.doReadUuidArray(in);
-
-                break;
-
-            case DATE_ARR:
-                obj = PortableUtils.doReadDateArray(in);
-
-                break;
-
-            case TIMESTAMP_ARR:
-                obj = PortableUtils.doReadTimestampArray(in);
-
-                break;
-
-            case OBJ_ARR:
-                obj = PortableUtils.doReadObjectArray(in, ctx, ldr, this, true);
-
-                break;
-
-            case COL:
-                obj = PortableUtils.doReadCollection(in, ctx, ldr, this, true, null);
-
-                break;
-
-            case MAP:
-                obj = PortableUtils.doReadMap(in, ctx, ldr, this, true, null);
-
-                break;
-
-            case PORTABLE_OBJ:
-                obj = PortableUtils.doReadPortableObject(in, ctx);
-
-                ((BinaryObjectImpl)obj).context(ctx);
-
-                if (!GridPortableMarshaller.KEEP_PORTABLES.get())
-                    obj = ((BinaryObject)obj).deserialize();
-
-                break;
-
-            case ENUM:
-                obj = PortableUtils.doReadEnum(in, PortableUtils.doReadClass(in, ctx, ldr));
-
-                break;
-
-            case ENUM_ARR:
-                obj = PortableUtils.doReadEnumArray(in, ctx, ldr, PortableUtils.doReadClass(in, ctx, ldr));
-
-                break;
-
-            case CLASS:
-                obj = PortableUtils.doReadClass(in, ctx, ldr);
-
-                break;
-
-            case OPTM_MARSH:
-                obj = PortableUtils.doReadOptimized(in, ctx, ldr);
-
-                break;
-
-            default:
-                throw new BinaryObjectException("Invalid flag value: " + flag);
-        }
-
-        return obj;
-    }
-
-    /**
-     * @return Deserialized object.
-     * @throws BinaryObjectException If failed.
-     */
-    @Nullable Object readField(int fieldId) throws BinaryObjectException {
-        if (!findFieldById(fieldId))
-            return null;
-
-        return new BinaryReaderExImpl(ctx, in, ldr, hnds).deserialize();
-    }
-
-    /**
-     * @param name Field name.
-     * @return Field offset.
-     */
-    private int fieldId(String name) {
-        assert name != null;
-
-        return idMapper.fieldId(typeId, name);
-    }
-
-    /**
-     * Get or create object schema.
-     *
-     * @return Schema.
-     */
-    public PortableSchema getOrCreateSchema() {
-        PortableSchema schema = ctx.schemaRegistry(typeId).schema(schemaId);
-
-        if (schema == null) {
-            if (fieldIdLen != PortableUtils.FIELD_ID_LEN) {
-                BinaryTypeImpl type = (BinaryTypeImpl)ctx.metadata(typeId);
-
-                if (type == null || type.metadata() == null)
-                    throw new BinaryObjectException("Cannot find metadata for object with compact footer: " +
-                        typeId);
-
-                for (PortableSchema typeSchema : type.metadata().schemas()) {
-                    if (schemaId == typeSchema.schemaId()) {
-                        schema = typeSchema;
-
-                        break;
-                    }
-                }
-
-                if (schema == null)
-                    throw new BinaryObjectException("Cannot find schema for object with compact footer [" +
-                        "typeId=" + typeId + ", schemaId=" + schemaId + ']');
-            }
-            else
-                schema = createSchema();
-
-            assert schema != null;
-
-            ctx.schemaRegistry(typeId).addSchema(schemaId, schema);
-        }
-
-        return schema;
-    }
-
-    /**
-     * Create schema.
-     *
-     * @return Schema.
-     */
-    private PortableSchema createSchema() {
-        assert fieldIdLen == PortableUtils.FIELD_ID_LEN;
-
-        PortableSchema.Builder builder = PortableSchema.Builder.newBuilder();
-
-        int searchPos = footerStart;
-        int searchEnd = searchPos + footerLen;
-
-        while (searchPos < searchEnd) {
-            int fieldId = in.readIntPositioned(searchPos);
-
-            builder.addField(fieldId);
-
-            searchPos += PortableUtils.FIELD_ID_LEN + fieldOffsetLen;
-        }
-
-        return builder.build();
-    }
-
-    /**
-     * Try finding the field by name.
-     *
-     * @param name Field name.
-     * @return Offset.
-     */
-    public boolean findFieldByName(String name) {
-        if (raw)
-            throw new BinaryObjectException("Failed to read named field because reader is in raw mode.");
-
-        assert dataStart != start;
-
-        if (footerLen == 0)
-            return false;
-
-        if (userType) {
-            int order;
-
-            if (matching) {
-                int expOrder = matchingOrder++;
-
-                PortableSchema.Confirmation confirm = schema.confirmOrder(expOrder, name);
-
-                switch (confirm) {
-                    case CONFIRMED:
-                        // The best case: got order without ID calculation and (ID -> order) lookup.
-                        if (expOrder == 0)
-                            // When we read the very first field, position is set to start, hence this re-positioning.
-                            streamPosition(dataStart);
-
-                        return true;
-
-                    case REJECTED:
-                        // Rejected, no more speculations are possible. Fallback to the slowest scenario.
-                        matching = false;
-
-                        order = schema.order(fieldId(name));
-
-                        break;
-
-                    default:
-                        // Field name is not know for this order. Need to calculate ID and repeat speculation.
-                        assert confirm == PortableSchema.Confirmation.CLARIFY;
-
-                        int id = fieldId(name);
-                        int realId = schema.fieldId(expOrder);
-
-                        if (id == realId) {
-                            // IDs matched, cache field name inside schema.
-                            schema.clarifyFieldName(expOrder, name);
-
-                            if (expOrder == 0)
-                                streamPosition(dataStart);
-
-                            return true;
-                        }
-                        else {
-                            // No match, stop further speculations.
-                            matching = false;
-
-                            order = schema.order(id);
-                        }
-
-                        break;
-                }
-            }
-            else
-                order = schema.order(fieldId(name));
-
-            return trySetUserFieldPosition(order);
-        }
-        else
-            return trySetSystemFieldPosition(fieldId(name));
-    }
-
-    /**
-     * Try finding the field by ID. Used for types with stable schema (Serializable) to avoid
-     * (string -> ID) calculations.
-     *
-     * @param id Field ID.
-     * @return {@code True} if field was found and stream was positioned accordingly.
-     */
-    private boolean findFieldById(int id) {
-        assert !raw; // Assert, not exception, because this is called only from internals for Serializable types.
-        assert dataStart != start;
-
-        if (footerLen == 0)
-            return false;
-
-        if (userType) {
-            int order;
-
-            if (matching) {
-                // Trying to get field order speculatively.
-                int expOrder = matchingOrder++;
-
-                int realId = schema.fieldId(expOrder);
-
-                if (realId == id) {
-                    if (expOrder == 0)
-                        streamPosition(dataStart);
-
-                    return true;
-                }
-                else {
-                    // Mismatch detected, no need for further speculations.
-                    matching = false;
-
-                    order = schema.order(id);
-                }
-            }
-            else
-                order = schema.order(id);
-
-            return trySetUserFieldPosition(order);
-        }
-        else
-            return trySetSystemFieldPosition(id);
-    }
-
-    /**
-     * Set position for the given user field order.
-     *
-     * @param order Order.
-     * @return {@code True} if field was found and stream was positioned accordingly.
-     */
-    private boolean trySetUserFieldPosition(int order) {
-        if (order != PortableSchema.ORDER_NOT_FOUND) {
-            int offsetPos = footerStart + order * (fieldIdLen + fieldOffsetLen) + fieldIdLen;
-
-            int pos = start + PortableUtils.fieldOffsetRelative(in, offsetPos, fieldOffsetLen);
-
-            streamPosition(pos);
-
-            return true;
-        }
-        else
-            return false;
-    }
-
-    /**
-     * Set position for the given system field ID.
-     *
-     * @param id Field ID.
-     * @return {@code True} if field was found and stream was positioned accordingly.
-     */
-    private boolean trySetSystemFieldPosition(int id) {
-        // System types are never written with compact footers because they do not have metadata.
-        assert fieldIdLen == PortableUtils.FIELD_ID_LEN;
-
-        int searchPos = footerStart;
-        int searchTail = searchPos + footerLen;
-
-        while (true) {
-            if (searchPos >= searchTail)
-                return false;
-
-            int id0 = in.readIntPositioned(searchPos);
-
-            if (id0 == id) {
-                int pos = start + PortableUtils.fieldOffsetRelative(in, searchPos + PortableUtils.FIELD_ID_LEN,
-                    fieldOffsetLen);
-
-                streamPosition(pos);
-
-                return true;
-            }
-
-            searchPos += PortableUtils.FIELD_ID_LEN + fieldOffsetLen;
-        }
-    }
-
-    /**
-     * Set stream position.
-     *
-     * @param pos Position.
-     */
-    private void streamPosition(int pos) {
-        in.position(pos);
-    }
-
-    /**
-     * Set stream position as a part of some random read. Further speculations will be disabled after this call.
-     *
-     * @param pos Position.
-     */
-    private void streamPositionRandom(int pos) {
-        streamPosition(pos);
-
-        matching = false;
-    }
-
-    /** {@inheritDoc} */
-    @Override public int readUnsignedByte() throws IOException {
-        return readByte() & 0xff;
-    }
-
-    /** {@inheritDoc} */
-    @Override public int readUnsignedShort() throws IOException {
-        return readShort() & 0xffff;
-    }
-
-    /** {@inheritDoc} */
-    @Override public String readLine() throws IOException {
-        SB sb = new SB();
-
-        int b;
-
-        while ((b = read()) >= 0) {
-            char c = (char)b;
-
-            switch (c) {
-                case '\n':
-                    return sb.toString();
-
-                case '\r':
-                    b = read();
-
-                    if (b < 0 || b == '\n')
-                        return sb.toString();
-                    else
-                        sb.a((char)b);
-
-                    break;
-
-                default:
-                    sb.a(c);
-            }
-        }
-
-        return sb.toString();
-    }
-
-    /** {@inheritDoc} */
-    @SuppressWarnings("ConstantConditions")
-    @NotNull @Override public String readUTF() throws IOException {
-        return readString();
-    }
-
-    /** {@inheritDoc} */
-    @SuppressWarnings("NullableProblems")
-    @Override public void readFully(byte[] b) throws IOException {
-        readFully(b, 0, b.length);
-    }
-
-    /** {@inheritDoc} */
-    @SuppressWarnings("NullableProblems")
-    @Override public void readFully(byte[] b, int off, int len) throws IOException {
-        int cnt = in.read(b, off, len);
-
-        if (cnt < len)
-            throw new EOFException();
-    }
-
-    /** {@inheritDoc} */
-    @Override public int skipBytes(int n) throws IOException {
-        int toSkip = Math.min(in.remaining(), n);
-
-        streamPositionRandom(in.position() + toSkip);
-
-        return toSkip;
-    }
-
-    /** {@inheritDoc} */
-    @Override public int read() throws IOException {
-        return readByte();
-    }
-
-    /** {@inheritDoc} */
-    @Override public int read(byte[] b) throws IOException {
-        return read(b, 0, b.length);
-    }
-
-    /** {@inheritDoc} */
-    @Override public int read(byte[] b, int off, int len) throws IOException {
-        return in.read(b, off, len);
-    }
-
-    /** {@inheritDoc} */
-    @Override public long skip(long n) throws IOException {
-        return skipBytes((int) n);
-    }
-
-    /** {@inheritDoc} */
-    @Override public int available() throws IOException {
-        return in.remaining();
-    }
-
-    /** {@inheritDoc} */
-    @Override public void close() throws IOException {
-        // No-op.
-    }
-
-    /**
-     * Flag.
-     */
-    private static enum Flag {
-        /** Regular. */
-        NORMAL,
-
-        /** Handle. */
-        HANDLE,
-
-        /** Null. */
-        NULL
-    }
-}

http://git-wip-us.apache.org/repos/asf/ignite/blob/1dbf20e0/modules/core/src/main/java/org/apache/ignite/internal/portable/BinaryReaderHandles.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/portable/BinaryReaderHandles.java b/modules/core/src/main/java/org/apache/ignite/internal/portable/BinaryReaderHandles.java
deleted file mode 100644
index 0024db0..0000000
--- a/modules/core/src/main/java/org/apache/ignite/internal/portable/BinaryReaderHandles.java
+++ /dev/null
@@ -1,108 +0,0 @@
-/*
- * 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.portable;
-
-import org.jetbrains.annotations.Nullable;
-
-import java.util.HashMap;
-import java.util.Map;
-
-/**
- * Reader handles.
- */
-public class BinaryReaderHandles {
-    /** Mode: empty. */
-    private static final int MODE_EMPTY = 0;
-
-    /** Mode: single object. */
-    private static final int MODE_SINGLE = 1;
-
-    /** Mode: multiple objects. */
-    private static final int MODE_MULTIPLE = 2;
-
-    /** Position.  */
-    private int singlePos;
-
-    /** Data. This is either an object or a map. */
-    private Object data;
-
-    /** Mode. */
-    private int mode = MODE_EMPTY;
-
-    /**
-     * Get object by position.
-     *
-     * @param pos Position.
-     * @return Object.
-     */
-    @SuppressWarnings("unchecked")
-    public @Nullable <T> T get(int pos) {
-        switch (mode) {
-            case MODE_EMPTY:
-                return null;
-
-            case MODE_SINGLE:
-                return (T)data;
-
-            default:
-                assert mode == MODE_MULTIPLE;
-
-                return (T)((Map<Integer, Object>)data).get(pos);
-        }
-    }
-
-    /**
-     * Put object to registry and return previous position (if any).
-     *
-     * @param pos Position.
-     * @param obj Object.
-     */
-    @SuppressWarnings("unchecked")
-    public void put(int pos, Object obj) {
-        assert pos >= 0;
-        assert obj != null;
-
-        switch (mode) {
-            case MODE_EMPTY:
-                this.singlePos = pos;
-                this.data = obj;
-                this.mode = MODE_SINGLE;
-
-                break;
-
-            case MODE_SINGLE:
-                Map<Integer, Object> newData = new HashMap(3, 1.0f);
-
-                newData.put(singlePos, data);
-                newData.put(pos, obj);
-
-                this.singlePos = -1;
-                this.data = newData;
-                this.mode = MODE_MULTIPLE;
-
-                break;
-
-            default:
-                assert mode == MODE_MULTIPLE;
-
-                Map<Integer, Object> data0 = (Map<Integer, Object>)data;
-
-                data0.put(pos, obj);
-        }
-    }
-}

http://git-wip-us.apache.org/repos/asf/ignite/blob/1dbf20e0/modules/core/src/main/java/org/apache/ignite/internal/portable/BinaryReaderHandlesHolder.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/portable/BinaryReaderHandlesHolder.java b/modules/core/src/main/java/org/apache/ignite/internal/portable/BinaryReaderHandlesHolder.java
deleted file mode 100644
index 09a896c..0000000
--- a/modules/core/src/main/java/org/apache/ignite/internal/portable/BinaryReaderHandlesHolder.java
+++ /dev/null
@@ -1,46 +0,0 @@
-/*
- * 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.portable;
-
-/**
- * Holder for handles.
- */
-public interface BinaryReaderHandlesHolder {
-    /**
-     * Set handle.
-     *
-     * @param obj Object.
-     * @param pos Position.
-     */
-    public void setHandle(Object obj, int pos);
-
-    /**
-     * Get handle.
-     *
-     * @param pos Position.
-     * @return Handle.
-     */
-    public Object getHandle(int pos);
-
-    /**
-     * Get all handles.
-     *
-     * @return Handles.
-     */
-    public BinaryReaderHandles handles();
-}

http://git-wip-us.apache.org/repos/asf/ignite/blob/1dbf20e0/modules/core/src/main/java/org/apache/ignite/internal/portable/BinaryReaderHandlesHolderImpl.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/portable/BinaryReaderHandlesHolderImpl.java b/modules/core/src/main/java/org/apache/ignite/internal/portable/BinaryReaderHandlesHolderImpl.java
deleted file mode 100644
index 1d40136..0000000
--- a/modules/core/src/main/java/org/apache/ignite/internal/portable/BinaryReaderHandlesHolderImpl.java
+++ /dev/null
@@ -1,44 +0,0 @@
-/*
- * 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.portable;
-
-/**
- * Simple holder for handles.
- */
-public class BinaryReaderHandlesHolderImpl implements BinaryReaderHandlesHolder  {
-    /** Handles. */
-    private BinaryReaderHandles hnds;
-
-    /** {@inheritDoc} */
-    @Override public void setHandle(Object obj, int pos) {
-        handles().put(pos, obj);
-    }
-
-    /** {@inheritDoc} */
-    @Override public Object getHandle(int pos) {
-        return hnds != null ? hnds.get(pos) : null;
-    }
-
-    /** {@inheritDoc} */
-    @Override public BinaryReaderHandles handles() {
-        if (hnds == null)
-            hnds = new BinaryReaderHandles();
-
-        return hnds;
-    }
-}

http://git-wip-us.apache.org/repos/asf/ignite/blob/1dbf20e0/modules/core/src/main/java/org/apache/ignite/internal/portable/BinaryThreadLocalContext.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/portable/BinaryThreadLocalContext.java b/modules/core/src/main/java/org/apache/ignite/internal/portable/BinaryThreadLocalContext.java
deleted file mode 100644
index c6a7fc3..0000000
--- a/modules/core/src/main/java/org/apache/ignite/internal/portable/BinaryThreadLocalContext.java
+++ /dev/null
@@ -1,69 +0,0 @@
-/*
- * 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.portable;
-
-import org.apache.ignite.internal.portable.streams.PortableMemoryAllocator;
-import org.apache.ignite.internal.portable.streams.PortableMemoryAllocatorChunk;
-
-/**
- * Contains thread-local data for binary marshalling.
- */
-public class BinaryThreadLocalContext {
-    /** Thread-local instance. */
-    private static final ThreadLocal<BinaryThreadLocalContext> CTX = new ThreadLocal<BinaryThreadLocalContext>() {
-        @Override protected BinaryThreadLocalContext initialValue() {
-            return new BinaryThreadLocalContext();
-        }
-    };
-
-    /** Memory chunk. */
-    private final PortableMemoryAllocatorChunk chunk = PortableMemoryAllocator.INSTANCE.chunk();
-
-    /** Schema holder. */
-    private final BinaryWriterSchemaHolder schema = new BinaryWriterSchemaHolder();
-
-    /**
-     * Get current context.
-     *
-     * @return Context.
-     */
-    public static BinaryThreadLocalContext get() {
-        return CTX.get();
-    }
-
-    /**
-     * Private constructor.
-     */
-    private BinaryThreadLocalContext() {
-        // No-op.
-    }
-
-    /**
-     * @return Memory chunk.
-     */
-    public PortableMemoryAllocatorChunk chunk() {
-        return chunk;
-    }
-
-    /**
-     * @return Schema holder.
-     */
-    public BinaryWriterSchemaHolder schemaHolder() {
-        return schema;
-    }
-}

http://git-wip-us.apache.org/repos/asf/ignite/blob/1dbf20e0/modules/core/src/main/java/org/apache/ignite/internal/portable/BinaryTypeImpl.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/portable/BinaryTypeImpl.java b/modules/core/src/main/java/org/apache/ignite/internal/portable/BinaryTypeImpl.java
deleted file mode 100644
index f471af2..0000000
--- a/modules/core/src/main/java/org/apache/ignite/internal/portable/BinaryTypeImpl.java
+++ /dev/null
@@ -1,93 +0,0 @@
-/*
- * 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.portable;
-
-import org.apache.ignite.binary.BinaryType;
-
-import java.util.Collection;
-
-/**
- * Binary type implementation.
- */
-public class BinaryTypeImpl implements BinaryType {
-    /** Portable context. */
-    private final PortableContext ctx;
-
-    /** Type metadata. */
-    private final BinaryMetadata meta;
-
-    /**
-     * Constructor.
-     *
-     * @param ctx Portable context.
-     * @param meta Type  metadata.
-     */
-    public BinaryTypeImpl(PortableContext ctx, BinaryMetadata meta) {
-        this.ctx = ctx;
-        this.meta = meta;
-    }
-
-    /** {@inheritDoc} */
-    @Override public String typeName() {
-        return meta.typeName();
-    }
-
-    /** {@inheritDoc} */
-    @Override public int typeId() {
-        return meta.typeId();
-    }
-
-    /** {@inheritDoc} */
-    @Override public Collection<String> fieldNames() {
-        return meta.fields();
-    }
-
-    /** {@inheritDoc} */
-    @Override public String fieldTypeName(String fieldName) {
-        return meta.fieldTypeName(fieldName);
-    }
-
-    /** {@inheritDoc} */
-    @Override public BinaryFieldImpl field(String fieldName) {
-        return ctx.createField(meta.typeId(), fieldName);
-    }
-
-    /** {@inheritDoc} */
-    @Override public String affinityKeyFieldName() {
-        return meta.affinityKeyFieldName();
-    }
-
-    /** {@inheritDoc} */
-    @Override public boolean isEnum() {
-        return meta.isEnum();
-    }
-
-    /**
-     * @return Context.
-     */
-    public PortableContext context() {
-        return ctx;
-    }
-
-    /**
-     * @return Metadata.
-     */
-    public BinaryMetadata metadata() {
-        return meta;
-    }
-}

http://git-wip-us.apache.org/repos/asf/ignite/blob/1dbf20e0/modules/core/src/main/java/org/apache/ignite/internal/portable/BinaryWriteMode.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/portable/BinaryWriteMode.java b/modules/core/src/main/java/org/apache/ignite/internal/portable/BinaryWriteMode.java
deleted file mode 100644
index 3e0bf69..0000000
--- a/modules/core/src/main/java/org/apache/ignite/internal/portable/BinaryWriteMode.java
+++ /dev/null
@@ -1,178 +0,0 @@
-/*
- * 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.portable;
-
-/**
- * Various write modes for binary objects.
- */
-public enum BinaryWriteMode {
-    /** Primitive byte. */
-    P_BYTE(GridPortableMarshaller.BYTE),
-
-    /** Primitive boolean. */
-    P_BOOLEAN(GridPortableMarshaller.BOOLEAN),
-
-    /** Primitive short. */
-    P_SHORT(GridPortableMarshaller.SHORT),
-
-    /** Primitive char. */
-    P_CHAR(GridPortableMarshaller.CHAR),
-
-    /** Primitive int. */
-    P_INT(GridPortableMarshaller.INT),
-
-    /** Primitive long. */
-    P_LONG(GridPortableMarshaller.LONG),
-
-    /** Primitive float. */
-    P_FLOAT(GridPortableMarshaller.FLOAT),
-
-    /** Primitive int. */
-    P_DOUBLE(GridPortableMarshaller.DOUBLE),
-
-    /** */
-    BYTE(GridPortableMarshaller.BYTE),
-
-    /** */
-    SHORT(GridPortableMarshaller.SHORT),
-
-    /** */
-    INT(GridPortableMarshaller.INT),
-
-    /** */
-    LONG(GridPortableMarshaller.LONG),
-
-    /** */
-    FLOAT(GridPortableMarshaller.FLOAT),
-
-    /** */
-    DOUBLE(GridPortableMarshaller.DOUBLE),
-
-    /** */
-    CHAR(GridPortableMarshaller.CHAR),
-
-    /** */
-    BOOLEAN(GridPortableMarshaller.BOOLEAN),
-
-    /** */
-    DECIMAL(GridPortableMarshaller.DECIMAL),
-
-    /** */
-    STRING(GridPortableMarshaller.STRING),
-
-    /** */
-    UUID(GridPortableMarshaller.UUID),
-
-    /** */
-    DATE(GridPortableMarshaller.DATE),
-
-    /** */
-    TIMESTAMP(GridPortableMarshaller.TIMESTAMP),
-
-    /** */
-    BYTE_ARR(GridPortableMarshaller.BYTE_ARR),
-
-    /** */
-    SHORT_ARR(GridPortableMarshaller.SHORT_ARR),
-
-    /** */
-    INT_ARR(GridPortableMarshaller.INT_ARR),
-
-    /** */
-    LONG_ARR(GridPortableMarshaller.LONG_ARR),
-
-    /** */
-    FLOAT_ARR(GridPortableMarshaller.FLOAT_ARR),
-
-    /** */
-    DOUBLE_ARR(GridPortableMarshaller.DOUBLE_ARR),
-
-    /** */
-    CHAR_ARR(GridPortableMarshaller.CHAR_ARR),
-
-    /** */
-    BOOLEAN_ARR(GridPortableMarshaller.BOOLEAN_ARR),
-
-    /** */
-    DECIMAL_ARR(GridPortableMarshaller.DECIMAL_ARR),
-
-    /** */
-    STRING_ARR(GridPortableMarshaller.STRING_ARR),
-
-    /** */
-    UUID_ARR(GridPortableMarshaller.UUID_ARR),
-
-    /** */
-    DATE_ARR(GridPortableMarshaller.DATE_ARR),
-
-    /** */
-    TIMESTAMP_ARR(GridPortableMarshaller.TIMESTAMP_ARR),
-
-    /** */
-    OBJECT_ARR(GridPortableMarshaller.OBJ_ARR),
-
-    /** */
-    COL(GridPortableMarshaller.COL),
-
-    /** */
-    MAP(GridPortableMarshaller.MAP),
-
-    /** */
-    PORTABLE_OBJ(GridPortableMarshaller.OBJ),
-
-    /** */
-    ENUM(GridPortableMarshaller.ENUM),
-
-    /** Portable enum. */
-    PORTABLE_ENUM(GridPortableMarshaller.ENUM),
-
-    /** */
-    ENUM_ARR(GridPortableMarshaller.ENUM_ARR),
-
-    /** */
-    CLASS(GridPortableMarshaller.CLASS),
-
-    /** */
-    PORTABLE(GridPortableMarshaller.PORTABLE_OBJ),
-
-    /** */
-    EXTERNALIZABLE(GridPortableMarshaller.OBJ),
-
-    /** */
-    OBJECT(GridPortableMarshaller.OBJ),
-
-    /** */
-    EXCLUSION(GridPortableMarshaller.OBJ);
-
-    /** Type ID. */
-    private final int typeId;
-
-    /**
-     * @param typeId Type ID.
-     */
-    private BinaryWriteMode(int typeId) {
-        this.typeId = typeId;
-    }
-
-    /**
-     * @return Type ID.
-     */
-    public int typeId() {
-        return typeId;
-    }
-}


[42/59] [abbrv] ignite git commit: ignite-2065: Fix RAT

Posted by ak...@apache.org.
ignite-2065: Fix RAT


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

Branch: refs/heads/ignite-843-rc2
Commit: 2b3c93ec97761f70a889c6d408ff43272e786b06
Parents: 98ef0ba
Author: ashutak <as...@gridgain.com>
Authored: Fri Dec 11 17:30:23 2015 +0300
Committer: ashutak <as...@gridgain.com>
Committed: Fri Dec 11 17:30:23 2015 +0300

----------------------------------------------------------------------
 parent/pom.xml | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/2b3c93ec/parent/pom.xml
----------------------------------------------------------------------
diff --git a/parent/pom.xml b/parent/pom.xml
index 8728858..0f2d363 100644
--- a/parent/pom.xml
+++ b/parent/pom.xml
@@ -846,10 +846,10 @@
                                         <exclude>dev-tools/.gradle/**/*</exclude>
                                         <exclude>dev-tools/gradle/wrapper/**/*</exclude>
                                         <exclude>dev-tools/gradlew</exclude>
-                                        <exclude>src/test/portables/repo/org/apache/ignite/portable/test2/1.1/test2-1.1.pom</exclude>
-                                        <exclude>src/test/portables/repo/org/apache/ignite/portable/test2/maven-metadata-local.xml</exclude>
-                                        <exclude>src/test/portables/repo/org/apache/ignite/portable/test1/1.1/test1-1.1.pom</exclude>
-                                        <exclude>src/test/portables/repo/org/apache/ignite/portable/test1/maven-metadata-local.xml</exclude>
+                                        <exclude>src/test/portables/repo/org/apache/ignite/binary/test2/1.1/test2-1.1.pom</exclude>
+                                        <exclude>src/test/portables/repo/org/apache/ignite/binary/test2/maven-metadata-local.xml</exclude>
+                                        <exclude>src/test/portables/repo/org/apache/ignite/binary/test1/1.1/test1-1.1.pom</exclude>
+                                        <exclude>src/test/portables/repo/org/apache/ignite/binary/test1/maven-metadata-local.xml</exclude>
                                         <!--shmem-->
                                         <exclude>ipc/shmem/**/Makefile.in</exclude><!--auto generated files-->
                                         <exclude>ipc/shmem/**/Makefile</exclude><!--auto generated files-->


[05/59] [abbrv] ignite git commit: ignite-2065: rename "portable" packages to "binary"

Posted by ak...@apache.org.
http://git-wip-us.apache.org/repos/asf/ignite/blob/1dbf20e0/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/binary/GridCacheBinaryObjectsAbstractMultiThreadedSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/binary/GridCacheBinaryObjectsAbstractMultiThreadedSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/binary/GridCacheBinaryObjectsAbstractMultiThreadedSelfTest.java
new file mode 100644
index 0000000..043f24f
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/binary/GridCacheBinaryObjectsAbstractMultiThreadedSelfTest.java
@@ -0,0 +1,241 @@
+/*
+ * 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.processors.cache.binary;
+
+import java.io.Serializable;
+import java.util.Arrays;
+import java.util.concurrent.Callable;
+import java.util.concurrent.ThreadLocalRandom;
+import java.util.concurrent.atomic.AtomicBoolean;
+import java.util.concurrent.atomic.AtomicInteger;
+import org.apache.ignite.IgniteCache;
+import org.apache.ignite.cache.CacheAtomicityMode;
+import org.apache.ignite.cache.CacheMode;
+import org.apache.ignite.cache.CacheWriteSynchronizationMode;
+import org.apache.ignite.configuration.BinaryConfiguration;
+import org.apache.ignite.configuration.CacheConfiguration;
+import org.apache.ignite.configuration.IgniteConfiguration;
+import org.apache.ignite.configuration.NearCacheConfiguration;
+import org.apache.ignite.internal.IgniteInternalFuture;
+import org.apache.ignite.internal.processors.cache.IgniteCacheProxy;
+import org.apache.ignite.internal.binary.BinaryMarshaller;
+import org.apache.ignite.binary.BinaryObjectException;
+import org.apache.ignite.binary.Binarylizable;
+import org.apache.ignite.binary.BinaryObject;
+import org.apache.ignite.binary.BinaryReader;
+import org.apache.ignite.binary.BinaryTypeConfiguration;
+import org.apache.ignite.binary.BinaryWriter;
+import org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi;
+import org.apache.ignite.spi.discovery.tcp.ipfinder.TcpDiscoveryIpFinder;
+import org.apache.ignite.spi.discovery.tcp.ipfinder.vm.TcpDiscoveryVmIpFinder;
+import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
+import org.jsr166.LongAdder8;
+
+import static org.apache.ignite.cache.CacheWriteSynchronizationMode.PRIMARY_SYNC;
+
+/**
+ * Test for portable objects stored in cache.
+ */
+public abstract class GridCacheBinaryObjectsAbstractMultiThreadedSelfTest extends GridCommonAbstractTest {
+    /** */
+    private static final TcpDiscoveryIpFinder IP_FINDER = new TcpDiscoveryVmIpFinder(true);
+
+    /** */
+    private static final int THREAD_CNT = 64;
+
+    /** */
+    private static final AtomicInteger idxGen = new AtomicInteger();
+
+    /** {@inheritDoc} */
+    @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception {
+        IgniteConfiguration cfg = super.getConfiguration(gridName);
+
+        ((TcpDiscoverySpi)cfg.getDiscoverySpi()).setIpFinder(IP_FINDER);
+
+        CacheConfiguration cacheCfg = new CacheConfiguration();
+
+        cacheCfg.setCacheMode(cacheMode());
+        cacheCfg.setAtomicityMode(atomicityMode());
+        cacheCfg.setNearConfiguration(nearConfiguration());
+        cacheCfg.setWriteSynchronizationMode(writeSynchronizationMode());
+
+        cfg.setCacheConfiguration(cacheCfg);
+
+        BinaryConfiguration bCfg = new BinaryConfiguration();
+
+        bCfg.setTypeConfigurations(Arrays.asList(
+            new BinaryTypeConfiguration(TestObject.class.getName())));
+
+        cfg.setBinaryConfiguration(bCfg);
+        cfg.setMarshaller(new BinaryMarshaller());
+
+        return cfg;
+    }
+
+    /**
+     * @return Sync mode.
+     */
+    protected CacheWriteSynchronizationMode writeSynchronizationMode() {
+        return PRIMARY_SYNC;
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void beforeTestsStarted() throws Exception {
+        startGridsMultiThreaded(gridCount());
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void afterTestsStopped() throws Exception {
+        stopAllGrids();
+    }
+
+    /**
+     * @return Cache mode.
+     */
+    protected abstract CacheMode cacheMode();
+
+    /**
+     * @return Atomicity mode.
+     */
+    protected abstract CacheAtomicityMode atomicityMode();
+
+    /**
+     * @return Distribution mode.
+     */
+    protected abstract NearCacheConfiguration nearConfiguration();
+
+    /**
+     * @return Grid count.
+     */
+    protected int gridCount() {
+        return 1;
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    @SuppressWarnings("BusyWait") public void testGetPut() throws Exception {
+        final AtomicBoolean flag = new AtomicBoolean();
+
+        final LongAdder8 cnt = new LongAdder8();
+
+        IgniteInternalFuture<?> f = multithreadedAsync(
+            new Callable<Object>() {
+                @Override public Object call() throws Exception {
+                    int threadId = idxGen.getAndIncrement() % 2;
+
+                    ThreadLocalRandom rnd = ThreadLocalRandom.current();
+
+                    while (!flag.get()) {
+                        IgniteCache<Object, Object> c = jcache(rnd.nextInt(gridCount()));
+
+                        switch (threadId) {
+                            case 0:
+                                // Put/get/remove portable -> portable.
+
+                                c.put(new TestObject(rnd.nextInt(10000)), new TestObject(rnd.nextInt(10000)));
+
+                                IgniteCache<Object, Object> p2 = ((IgniteCacheProxy<Object, Object>)c).keepPortable();
+
+                                BinaryObject v = (BinaryObject)p2.get(new TestObject(rnd.nextInt(10000)));
+
+                                if (v != null)
+                                    v.deserialize();
+
+                                c.remove(new TestObject(rnd.nextInt(10000)));
+
+                                break;
+
+                            case 1:
+                                // Put/get int -> portable.
+                                c.put(rnd.nextInt(10000), new TestObject(rnd.nextInt(10000)));
+
+                                IgniteCache<Integer, BinaryObject> p4 = ((IgniteCacheProxy<Object, Object>)c).keepPortable();
+
+                                BinaryObject v1 = p4.get(rnd.nextInt(10000));
+
+                                if (v1 != null)
+                                    v1.deserialize();
+
+                                p4.remove(rnd.nextInt(10000));
+
+                                break;
+
+                            default:
+                                assert false;
+                        }
+
+                        cnt.add(3);
+                    }
+
+                    return null;
+                }
+            },
+            THREAD_CNT
+        );
+
+        for (int i = 0; i < 30 && !f.isDone(); i++)
+            Thread.sleep(1000);
+
+        flag.set(true);
+
+        f.get();
+
+        info("Operations in 30 sec: " + cnt.sum());
+    }
+
+    /**
+     */
+    private static class TestObject implements Binarylizable, Serializable {
+        /** */
+        private int val;
+
+        /**
+         */
+        private TestObject() {
+            // No-op.
+        }
+
+        /**
+         * @param val Value.
+         */
+        private TestObject(int val) {
+            this.val = val;
+        }
+
+        /** {@inheritDoc} */
+        @Override public int hashCode() {
+            return val;
+        }
+
+        /** {@inheritDoc} */
+        @Override public boolean equals(Object obj) {
+            return obj instanceof TestObject && ((TestObject)obj).val == val;
+        }
+
+        /** {@inheritDoc} */
+        @Override public void writeBinary(BinaryWriter writer) throws BinaryObjectException {
+            writer.writeInt("val", val);
+        }
+
+        /** {@inheritDoc} */
+        @Override public void readBinary(BinaryReader reader) throws BinaryObjectException {
+            val = reader.readInt("val");
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/1dbf20e0/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/binary/GridCacheBinaryObjectsAbstractSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/binary/GridCacheBinaryObjectsAbstractSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/binary/GridCacheBinaryObjectsAbstractSelfTest.java
new file mode 100644
index 0000000..d24e1e4
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/binary/GridCacheBinaryObjectsAbstractSelfTest.java
@@ -0,0 +1,981 @@
+/*
+ * 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.processors.cache.binary;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.Set;
+import javax.cache.Cache;
+import javax.cache.processor.EntryProcessor;
+import javax.cache.processor.MutableEntry;
+import org.apache.ignite.Ignite;
+import org.apache.ignite.IgniteCache;
+import org.apache.ignite.IgniteBinary;
+import org.apache.ignite.cache.CacheAtomicityMode;
+import org.apache.ignite.cache.CacheMode;
+import org.apache.ignite.cache.CachePeekMode;
+import org.apache.ignite.cache.store.CacheStoreAdapter;
+import org.apache.ignite.configuration.CacheConfiguration;
+import org.apache.ignite.configuration.IgniteConfiguration;
+import org.apache.ignite.configuration.NearCacheConfiguration;
+import org.apache.ignite.internal.IgniteKernal;
+import org.apache.ignite.internal.binary.BinaryObjectImpl;
+import org.apache.ignite.internal.processors.cache.GridCacheAdapter;
+import org.apache.ignite.internal.processors.cache.GridCacheEntryEx;
+import org.apache.ignite.internal.processors.cache.IgniteCacheProxy;
+import org.apache.ignite.internal.util.typedef.P2;
+import org.apache.ignite.internal.util.typedef.internal.CU;
+import org.apache.ignite.internal.util.typedef.internal.U;
+import org.apache.ignite.lang.IgniteBiInClosure;
+import org.apache.ignite.internal.binary.BinaryMarshaller;
+import org.apache.ignite.binary.BinaryObjectBuilder;
+import org.apache.ignite.binary.BinaryObjectException;
+import org.apache.ignite.binary.Binarylizable;
+import org.apache.ignite.binary.BinaryObject;
+import org.apache.ignite.binary.BinaryReader;
+import org.apache.ignite.binary.BinaryWriter;
+import org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi;
+import org.apache.ignite.spi.discovery.tcp.ipfinder.TcpDiscoveryIpFinder;
+import org.apache.ignite.spi.discovery.tcp.ipfinder.vm.TcpDiscoveryVmIpFinder;
+import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
+import org.apache.ignite.transactions.Transaction;
+import org.jetbrains.annotations.Nullable;
+
+import static org.apache.ignite.cache.CacheAtomicityMode.TRANSACTIONAL;
+import static org.apache.ignite.cache.CacheMemoryMode.OFFHEAP_TIERED;
+import static org.apache.ignite.cache.CacheWriteSynchronizationMode.FULL_SYNC;
+import static org.apache.ignite.transactions.TransactionConcurrency.PESSIMISTIC;
+import static org.apache.ignite.transactions.TransactionIsolation.READ_COMMITTED;
+import static org.apache.ignite.transactions.TransactionIsolation.REPEATABLE_READ;
+
+/**
+ * Test for portable objects stored in cache.
+ */
+public abstract class GridCacheBinaryObjectsAbstractSelfTest extends GridCommonAbstractTest {
+    /** */
+    public static final TcpDiscoveryIpFinder IP_FINDER = new TcpDiscoveryVmIpFinder(true);
+
+    /** */
+    private static final int ENTRY_CNT = 100;
+
+    /** {@inheritDoc} */
+    @SuppressWarnings("unchecked")
+    @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception {
+        IgniteConfiguration cfg = super.getConfiguration(gridName);
+
+        TcpDiscoverySpi disco = new TcpDiscoverySpi();
+
+        disco.setIpFinder(IP_FINDER);
+
+        cfg.setDiscoverySpi(disco);
+
+        CacheConfiguration cacheCfg = new CacheConfiguration();
+
+        cacheCfg.setCacheMode(cacheMode());
+        cacheCfg.setAtomicityMode(atomicityMode());
+        cacheCfg.setNearConfiguration(nearConfiguration());
+        cacheCfg.setWriteSynchronizationMode(FULL_SYNC);
+        cacheCfg.setCacheStoreFactory(singletonFactory(new TestStore()));
+        cacheCfg.setReadThrough(true);
+        cacheCfg.setWriteThrough(true);
+        cacheCfg.setLoadPreviousValue(true);
+        cacheCfg.setBackups(1);
+
+        if (offheapTiered()) {
+            cacheCfg.setMemoryMode(OFFHEAP_TIERED);
+            cacheCfg.setOffHeapMaxMemory(0);
+        }
+
+        cfg.setCacheConfiguration(cacheCfg);
+
+        cfg.setMarshaller(new BinaryMarshaller());
+
+        return cfg;
+    }
+
+    /**
+     * @return {@code True} if should use OFFHEAP_TIERED mode.
+     */
+    protected boolean offheapTiered() {
+        return false;
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void beforeTestsStarted() throws Exception {
+        startGridsMultiThreaded(gridCount());
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void afterTestsStopped() throws Exception {
+        stopAllGrids();
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void afterTest() throws Exception {
+        for (int i = 0; i < gridCount(); i++) {
+            GridCacheAdapter<Object, Object> c = ((IgniteKernal)grid(i)).internalCache();
+
+            for (GridCacheEntryEx e : c.map().entries0()) {
+                Object key = e.key().value(c.context().cacheObjectContext(), false);
+                Object val = CU.value(e.rawGet(), c.context(), false);
+
+                if (key instanceof BinaryObject)
+                    assert ((BinaryObjectImpl)key).detached() : val;
+
+                if (val instanceof BinaryObject)
+                    assert ((BinaryObjectImpl)val).detached() : val;
+            }
+        }
+
+        IgniteCache<Object, Object> c = jcache(0);
+
+        for (int i = 0; i < ENTRY_CNT; i++)
+            c.remove(i);
+
+        if (offheapTiered()) {
+            for (int k = 0; k < 100; k++)
+                c.remove(k);
+        }
+
+        assertEquals(0, c.size());
+    }
+
+    /**
+     * @return Cache mode.
+     */
+    protected abstract CacheMode cacheMode();
+
+    /**
+     * @return Atomicity mode.
+     */
+    protected abstract CacheAtomicityMode atomicityMode();
+
+    /**
+     * @return Distribution mode.
+     */
+    protected abstract NearCacheConfiguration nearConfiguration();
+
+    /**
+     * @return Grid count.
+     */
+    protected abstract int gridCount();
+
+    /**
+     * @throws Exception If failed.
+     */
+    @SuppressWarnings("unchecked")
+    public void testCircularReference() throws Exception {
+        IgniteCache c = keepPortableCache();
+
+        TestReferenceObject obj1 = new TestReferenceObject();
+
+        obj1.obj = new TestReferenceObject(obj1);
+
+        c.put(1, obj1);
+
+        BinaryObject po = (BinaryObject)c.get(1);
+
+        String str = po.toString();
+
+        log.info("toString: " + str);
+
+        assertNotNull(str);
+
+        assertTrue("Unexpected toString: " + str,
+            str.startsWith("TestReferenceObject") && str.contains("obj=TestReferenceObject ["));
+
+        TestReferenceObject obj1_r = po.deserialize();
+
+        assertNotNull(obj1_r);
+
+        TestReferenceObject obj2_r = obj1_r.obj;
+
+        assertNotNull(obj2_r);
+
+        assertSame(obj1_r, obj2_r.obj);
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testGet() throws Exception {
+        IgniteCache<Integer, TestObject> c = jcache(0);
+
+        for (int i = 0; i < ENTRY_CNT; i++)
+            c.put(i, new TestObject(i));
+
+        for (int i = 0; i < ENTRY_CNT; i++) {
+            TestObject obj = c.get(i);
+
+            assertEquals(i, obj.val);
+        }
+
+        IgniteCache<Integer, BinaryObject> kpc = keepPortableCache();
+
+        for (int i = 0; i < ENTRY_CNT; i++) {
+            BinaryObject po = kpc.get(i);
+
+            assertEquals(i, (int)po.field("val"));
+        }
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testIterator() throws Exception {
+        IgniteCache<Integer, TestObject> c = jcache(0);
+
+        Map<Integer, TestObject> entries = new HashMap<>();
+
+        for (int i = 0; i < ENTRY_CNT; i++) {
+            TestObject val = new TestObject(i);
+
+            c.put(i, val);
+
+            entries.put(i, val);
+        }
+
+        IgniteCache<Integer, BinaryObject> prj = ((IgniteCacheProxy)c).keepPortable();
+
+        Iterator<Cache.Entry<Integer, BinaryObject>> it = prj.iterator();
+
+        assertTrue(it.hasNext());
+
+        while (it.hasNext()) {
+            Cache.Entry<Integer, BinaryObject> entry = it.next();
+
+            assertTrue(entries.containsKey(entry.getKey()));
+
+            TestObject o = entries.get(entry.getKey());
+
+            BinaryObject po = entry.getValue();
+
+            assertEquals(o.val, (int)po.field("val"));
+
+            entries.remove(entry.getKey());
+        }
+
+        assertEquals(0, entries.size());
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testCollection() throws Exception {
+        IgniteCache<Integer, Collection<TestObject>> c = jcache(0);
+
+        for (int i = 0; i < ENTRY_CNT; i++) {
+            Collection<TestObject> col = new ArrayList<>(3);
+
+            for (int j = 0; j < 3; j++)
+                col.add(new TestObject(i * 10 + j));
+
+            c.put(i, col);
+        }
+
+        for (int i = 0; i < ENTRY_CNT; i++) {
+            Collection<TestObject> col = c.get(i);
+
+            assertEquals(3, col.size());
+
+            Iterator<TestObject> it = col.iterator();
+
+            for (int j = 0; j < 3; j++) {
+                assertTrue(it.hasNext());
+
+                assertEquals(i * 10 + j, it.next().val);
+            }
+        }
+
+        IgniteCache<Integer, Collection<BinaryObject>> kpc = keepPortableCache();
+
+        for (int i = 0; i < ENTRY_CNT; i++) {
+            Collection<BinaryObject> col = kpc.get(i);
+
+            assertEquals(3, col.size());
+
+            Iterator<BinaryObject> it = col.iterator();
+
+            for (int j = 0; j < 3; j++) {
+                assertTrue(it.hasNext());
+
+                assertEquals(i * 10 + j, (int)it.next().field("val"));
+            }
+        }
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testMap() throws Exception {
+        IgniteCache<Integer, Map<Integer, TestObject>> c = jcache(0);
+
+        for (int i = 0; i < ENTRY_CNT; i++) {
+            Map<Integer, TestObject> map = U.newHashMap(3);
+
+            for (int j = 0; j < 3; j++) {
+                int idx = i * 10 + j;
+
+                map.put(idx, new TestObject(idx));
+            }
+
+            c.put(i, map);
+        }
+
+        for (int i = 0; i < ENTRY_CNT; i++) {
+            Map<Integer, TestObject> map = c.get(i);
+
+            assertEquals(3, map.size());
+
+            for (int j = 0; j < 3; j++) {
+                int idx = i * 10 + j;
+
+                assertEquals(idx, map.get(idx).val);
+            }
+        }
+
+        IgniteCache<Integer, Map<Integer, BinaryObject>> kpc = keepPortableCache();
+
+        for (int i = 0; i < ENTRY_CNT; i++) {
+            Map<Integer, BinaryObject> map = kpc.get(i);
+
+            assertEquals(3, map.size());
+
+            for (int j = 0; j < 3; j++) {
+                int idx = i * 10 + j;
+
+                assertEquals(idx, (int)map.get(idx).field("val"));
+            }
+        }
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testGetAsync() throws Exception {
+        IgniteCache<Integer, TestObject> c = jcache(0);
+
+        IgniteCache<Integer, TestObject> cacheAsync = c.withAsync();
+
+        for (int i = 0; i < ENTRY_CNT; i++)
+            c.put(i, new TestObject(i));
+
+        for (int i = 0; i < ENTRY_CNT; i++) {
+            cacheAsync.get(i);
+
+            TestObject obj = cacheAsync.<TestObject>future().get();
+
+            assertNotNull(obj);
+
+            assertEquals(i, obj.val);
+        }
+
+        IgniteCache<Integer, BinaryObject> kpc = keepPortableCache();
+
+        IgniteCache<Integer, BinaryObject> cachePortableAsync = kpc.withAsync();
+
+        for (int i = 0; i < ENTRY_CNT; i++) {
+            cachePortableAsync.get(i);
+
+            BinaryObject po = cachePortableAsync.<BinaryObject>future().get();
+
+            assertEquals(i, (int)po.field("val"));
+        }
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testGetTx() throws Exception {
+        if (atomicityMode() != TRANSACTIONAL)
+            return;
+
+        IgniteCache<Integer, TestObject> c = jcache(0);
+
+        for (int i = 0; i < ENTRY_CNT; i++)
+            c.put(i, new TestObject(i));
+
+        for (int i = 0; i < ENTRY_CNT; i++) {
+            try (Transaction tx = grid(0).transactions().txStart(PESSIMISTIC, REPEATABLE_READ)) {
+                TestObject obj = c.get(i);
+
+                assertEquals(i, obj.val);
+
+                tx.commit();
+            }
+        }
+
+        for (int i = 0; i < ENTRY_CNT; i++) {
+            try (Transaction tx = grid(0).transactions().txStart(PESSIMISTIC, READ_COMMITTED)) {
+                TestObject obj = c.get(i);
+
+                assertEquals(i, obj.val);
+
+                tx.commit();
+            }
+        }
+
+        IgniteCache<Integer, BinaryObject> kpc = keepPortableCache();
+
+        for (int i = 0; i < ENTRY_CNT; i++) {
+            try (Transaction tx = grid(0).transactions().txStart(PESSIMISTIC, REPEATABLE_READ)) {
+                BinaryObject po = kpc.get(i);
+
+                assertEquals(i, (int)po.field("val"));
+
+                tx.commit();
+            }
+        }
+
+        for (int i = 0; i < ENTRY_CNT; i++) {
+            try (Transaction tx = grid(0).transactions().txStart(PESSIMISTIC, READ_COMMITTED)) {
+                BinaryObject po = kpc.get(i);
+
+                assertEquals(i, (int)po.field("val"));
+
+                tx.commit();
+            }
+        }
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testGetAsyncTx() throws Exception {
+        if (atomicityMode() != TRANSACTIONAL)
+            return;
+
+        IgniteCache<Integer, TestObject> c = jcache(0);
+
+        IgniteCache<Integer, TestObject> cacheAsync = c.withAsync();
+
+        for (int i = 0; i < ENTRY_CNT; i++)
+            c.put(i, new TestObject(i));
+
+        for (int i = 0; i < ENTRY_CNT; i++) {
+            try (Transaction tx = grid(0).transactions().txStart(PESSIMISTIC, REPEATABLE_READ)) {
+                cacheAsync.get(i);
+
+                TestObject obj = cacheAsync.<TestObject>future().get();
+
+                assertEquals(i, obj.val);
+
+                tx.commit();
+            }
+        }
+
+        IgniteCache<Integer, BinaryObject> kpc = keepPortableCache();
+        IgniteCache<Integer, BinaryObject> cachePortableAsync = kpc.withAsync();
+
+        for (int i = 0; i < ENTRY_CNT; i++) {
+            try (Transaction tx = grid(0).transactions().txStart(PESSIMISTIC, REPEATABLE_READ)) {
+                cachePortableAsync.get(i);
+
+                BinaryObject po = cachePortableAsync.<BinaryObject>future().get();
+
+                assertEquals(i, (int)po.field("val"));
+
+                tx.commit();
+            }
+        }
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testGetAll() throws Exception {
+        IgniteCache<Integer, TestObject> c = jcache(0);
+
+        for (int i = 0; i < ENTRY_CNT; i++)
+            c.put(i, new TestObject(i));
+
+        for (int i = 0; i < ENTRY_CNT; ) {
+            Set<Integer> keys = new HashSet<>();
+
+            for (int j = 0; j < 10; j++)
+                keys.add(i++);
+
+            Map<Integer, TestObject> objs = c.getAll(keys);
+
+            assertEquals(10, objs.size());
+
+            for (Map.Entry<Integer, TestObject> e : objs.entrySet())
+                assertEquals(e.getKey().intValue(), e.getValue().val);
+        }
+
+        IgniteCache<Integer, BinaryObject> kpc = keepPortableCache();
+
+        for (int i = 0; i < ENTRY_CNT; ) {
+            Set<Integer> keys = new HashSet<>();
+
+            for (int j = 0; j < 10; j++)
+                keys.add(i++);
+
+            Map<Integer, BinaryObject> objs = kpc.getAll(keys);
+
+            assertEquals(10, objs.size());
+
+            for (Map.Entry<Integer, BinaryObject> e : objs.entrySet())
+                assertEquals(new Integer(e.getKey().intValue()), e.getValue().field("val"));
+        }
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testGetAllAsync() throws Exception {
+        IgniteCache<Integer, TestObject> c = jcache(0);
+
+        IgniteCache<Integer, TestObject> cacheAsync = c.withAsync();
+
+        for (int i = 0; i < ENTRY_CNT; i++)
+            c.put(i, new TestObject(i));
+
+        for (int i = 0; i < ENTRY_CNT; ) {
+            Set<Integer> keys = new HashSet<>();
+
+            for (int j = 0; j < 10; j++)
+                keys.add(i++);
+
+            cacheAsync.getAll(keys);
+
+            Map<Integer, TestObject> objs = cacheAsync.<Map<Integer, TestObject>>future().get();
+
+            assertEquals(10, objs.size());
+
+            for (Map.Entry<Integer, TestObject> e : objs.entrySet())
+                assertEquals(e.getKey().intValue(), e.getValue().val);
+        }
+
+        IgniteCache<Integer, BinaryObject> kpc = keepPortableCache();
+        IgniteCache<Integer, BinaryObject> cachePortableAsync = kpc.withAsync();
+
+        for (int i = 0; i < ENTRY_CNT; ) {
+            Set<Integer> keys = new HashSet<>();
+
+            for (int j = 0; j < 10; j++)
+                keys.add(i++);
+
+
+            cachePortableAsync.getAll(keys);
+
+            Map<Integer, BinaryObject> objs = cachePortableAsync.<Map<Integer, BinaryObject>>future().get();
+
+            assertEquals(10, objs.size());
+
+            for (Map.Entry<Integer, BinaryObject> e : objs.entrySet())
+                assertEquals(new Integer(e.getKey().intValue()), e.getValue().field("val"));
+        }
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testGetAllTx() throws Exception {
+        if (atomicityMode() != TRANSACTIONAL)
+            return;
+
+        IgniteCache<Integer, TestObject> c = jcache(0);
+
+        for (int i = 0; i < ENTRY_CNT; i++)
+            c.put(i, new TestObject(i));
+
+        for (int i = 0; i < ENTRY_CNT; ) {
+            Set<Integer> keys = new HashSet<>();
+
+            for (int j = 0; j < 10; j++)
+                keys.add(i++);
+
+            try (Transaction tx = grid(0).transactions().txStart(PESSIMISTIC, REPEATABLE_READ)) {
+                Map<Integer, TestObject> objs = c.getAll(keys);
+
+                assertEquals(10, objs.size());
+
+                for (Map.Entry<Integer, TestObject> e : objs.entrySet())
+                    assertEquals(e.getKey().intValue(), e.getValue().val);
+
+                tx.commit();
+            }
+
+            try (Transaction tx = grid(0).transactions().txStart(PESSIMISTIC, READ_COMMITTED)) {
+                Map<Integer, TestObject> objs = c.getAll(keys);
+
+                assertEquals(10, objs.size());
+
+                for (Map.Entry<Integer, TestObject> e : objs.entrySet())
+                    assertEquals(e.getKey().intValue(), e.getValue().val);
+
+                tx.commit();
+            }
+        }
+
+        IgniteCache<Integer, BinaryObject> kpc = keepPortableCache();
+
+        for (int i = 0; i < ENTRY_CNT; ) {
+            Set<Integer> keys = new HashSet<>();
+
+            for (int j = 0; j < 10; j++)
+                keys.add(i++);
+
+            try (Transaction tx = grid(0).transactions().txStart(PESSIMISTIC, REPEATABLE_READ)) {
+                Map<Integer, BinaryObject> objs = kpc.getAll(keys);
+
+                assertEquals(10, objs.size());
+
+                for (Map.Entry<Integer, BinaryObject> e : objs.entrySet())
+                    assertEquals(new Integer(e.getKey().intValue()), e.getValue().field("val"));
+
+                tx.commit();
+            }
+
+            try (Transaction tx = grid(0).transactions().txStart(PESSIMISTIC, READ_COMMITTED)) {
+                Map<Integer, BinaryObject> objs = kpc.getAll(keys);
+
+                assertEquals(10, objs.size());
+
+                for (Map.Entry<Integer, BinaryObject> e : objs.entrySet())
+                    assertEquals(new Integer(e.getKey().intValue()), e.getValue().field("val"));
+
+                tx.commit();
+            }
+        }
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testGetAllAsyncTx() throws Exception {
+        if (atomicityMode() != TRANSACTIONAL)
+            return;
+
+        IgniteCache<Integer, TestObject> c = jcache(0);
+        IgniteCache<Integer, TestObject> cacheAsync = c.withAsync();
+
+        for (int i = 0; i < ENTRY_CNT; i++)
+            c.put(i, new TestObject(i));
+
+        for (int i = 0; i < ENTRY_CNT; ) {
+            Set<Integer> keys = new HashSet<>();
+
+            for (int j = 0; j < 10; j++)
+                keys.add(i++);
+
+            try (Transaction tx = grid(0).transactions().txStart(PESSIMISTIC, REPEATABLE_READ)) {
+                cacheAsync.getAll(keys);
+
+                Map<Integer, TestObject> objs = cacheAsync.<Map<Integer, TestObject>>future().get();
+
+                assertEquals(10, objs.size());
+
+                for (Map.Entry<Integer, TestObject> e : objs.entrySet())
+                    assertEquals(e.getKey().intValue(), e.getValue().val);
+
+                tx.commit();
+            }
+        }
+
+        IgniteCache<Integer, BinaryObject> cache = keepPortableCache();
+
+        for (int i = 0; i < ENTRY_CNT; ) {
+            Set<Integer> keys = new HashSet<>();
+
+            for (int j = 0; j < 10; j++)
+                keys.add(i++);
+
+            IgniteCache<Integer, BinaryObject> asyncCache = cache.withAsync();
+
+            try (Transaction tx = grid(0).transactions().txStart(PESSIMISTIC, REPEATABLE_READ)) {
+                asyncCache.getAll(keys);
+
+                Map<Integer, BinaryObject> objs = asyncCache.<Map<Integer, BinaryObject>>future().get();
+
+                assertEquals(10, objs.size());
+
+                for (Map.Entry<Integer, BinaryObject> e : objs.entrySet())
+                    assertEquals(new Integer(e.getKey().intValue()), e.getValue().field("val"));
+
+                tx.commit();
+            }
+        }
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testLoadCache() throws Exception {
+        for (int i = 0; i < gridCount(); i++)
+            jcache(i).localLoadCache(null);
+
+        IgniteCache<Integer, TestObject> cache = jcache(0);
+
+        assertEquals(3, cache.size(CachePeekMode.PRIMARY));
+
+        assertEquals(1, cache.get(1).val);
+        assertEquals(2, cache.get(2).val);
+        assertEquals(3, cache.get(3).val);
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testLoadCacheAsync() throws Exception {
+        for (int i = 0; i < gridCount(); i++) {
+            IgniteCache<Object, Object> jcache = jcache(i).withAsync();
+
+            jcache.loadCache(null);
+
+            jcache.future().get();
+        }
+
+        IgniteCache<Integer, TestObject> cache = jcache(0);
+
+        assertEquals(3, cache.size(CachePeekMode.PRIMARY));
+
+        assertEquals(1, cache.get(1).val);
+        assertEquals(2, cache.get(2).val);
+        assertEquals(3, cache.get(3).val);
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testLoadCacheFilteredAsync() throws Exception {
+        for (int i = 0; i < gridCount(); i++) {
+            IgniteCache<Integer, TestObject> c = this.<Integer, TestObject>jcache(i).withAsync();
+
+            c.loadCache(new P2<Integer, TestObject>() {
+                @Override public boolean apply(Integer key, TestObject val) {
+                    return val.val < 3;
+                }
+            });
+
+            c.future().get();
+        }
+
+        IgniteCache<Integer, TestObject> cache = jcache(0);
+
+        assertEquals(2, cache.size(CachePeekMode.PRIMARY));
+
+        assertEquals(1, cache.get(1).val);
+        assertEquals(2, cache.get(2).val);
+
+        assertNull(cache.get(3));
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testTransform() throws Exception {
+        IgniteCache<Integer, BinaryObject> c = keepPortableCache();
+
+        checkTransform(primaryKey(c));
+
+        if (cacheMode() != CacheMode.LOCAL) {
+            checkTransform(backupKey(c));
+
+            if (nearConfiguration() != null)
+                checkTransform(nearKey(c));
+        }
+    }
+
+    /**
+     * @return Cache with keep portable flag.
+     */
+    private <K, V> IgniteCache<K, V> keepPortableCache() {
+        return ignite(0).cache(null).withKeepBinary();
+    }
+
+    /**
+     * @param key Key.
+     * @throws Exception If failed.
+     */
+    private void checkTransform(Integer key) throws Exception {
+        log.info("Transform: " + key);
+
+        IgniteCache<Integer, BinaryObject> c = keepPortableCache();
+
+        try {
+            c.invoke(key, new EntryProcessor<Integer, BinaryObject, Void>() {
+                @Override public Void process(MutableEntry<Integer, BinaryObject> e, Object... args) {
+                    BinaryObject val = e.getValue();
+
+                    assertNull("Unexpected value: " + val, val);
+
+                    return null;
+                }
+            });
+
+            jcache(0).put(key, new TestObject(1));
+
+            c.invoke(key, new EntryProcessor<Integer, BinaryObject, Void>() {
+                @Override public Void process(MutableEntry<Integer, BinaryObject> e, Object... args) {
+                    BinaryObject val = e.getValue();
+
+                    assertNotNull("Unexpected value: " + val, val);
+
+                    assertEquals(new Integer(1), val.field("val"));
+
+                    Ignite ignite = e.unwrap(Ignite.class);
+
+                    IgniteBinary portables = ignite.binary();
+
+                    BinaryObjectBuilder builder = portables.builder(val);
+
+                    builder.setField("val", 2);
+
+                    e.setValue(builder.build());
+
+                    return null;
+                }
+            });
+
+            BinaryObject obj = c.get(key);
+
+            assertEquals(new Integer(2), obj.field("val"));
+
+            c.invoke(key, new EntryProcessor<Integer, BinaryObject, Void>() {
+                @Override public Void process(MutableEntry<Integer, BinaryObject> e, Object... args) {
+                    BinaryObject val = e.getValue();
+
+                    assertNotNull("Unexpected value: " + val, val);
+
+                    assertEquals(new Integer(2), val.field("val"));
+
+                    e.setValue(val);
+
+                    return null;
+                }
+            });
+
+            obj = c.get(key);
+
+            assertEquals(new Integer(2), obj.field("val"));
+
+            c.invoke(key, new EntryProcessor<Integer, BinaryObject, Void>() {
+                @Override public Void process(MutableEntry<Integer, BinaryObject> e, Object... args) {
+                    BinaryObject val = e.getValue();
+
+                    assertNotNull("Unexpected value: " + val, val);
+
+                    assertEquals(new Integer(2), val.field("val"));
+
+                    e.remove();
+
+                    return null;
+                }
+            });
+
+            assertNull(c.get(key));
+        }
+        finally {
+            c.remove(key);
+        }
+    }
+
+    /**
+     *
+     */
+    private static class TestObject implements Binarylizable {
+        /** */
+        private int val;
+
+        /**
+         */
+        private TestObject() {
+            // No-op.
+        }
+
+        /**
+         * @param val Value.
+         */
+        private TestObject(int val) {
+            this.val = val;
+        }
+
+        /** {@inheritDoc} */
+        @Override public void writeBinary(BinaryWriter writer) throws BinaryObjectException {
+            writer.writeInt("val", val);
+        }
+
+        /** {@inheritDoc} */
+        @Override public void readBinary(BinaryReader reader) throws BinaryObjectException {
+            val = reader.readInt("val");
+        }
+    }
+
+    /**
+     *
+     */
+    private static class TestReferenceObject implements Binarylizable {
+        /** */
+        private TestReferenceObject obj;
+
+        /**
+         */
+        private TestReferenceObject() {
+            // No-op.
+        }
+
+        /**
+         * @param obj Object.
+         */
+        private TestReferenceObject(TestReferenceObject obj) {
+            this.obj = obj;
+        }
+
+        /** {@inheritDoc} */
+        @Override public void writeBinary(BinaryWriter writer) throws BinaryObjectException {
+            writer.writeObject("obj", obj);
+        }
+
+        /** {@inheritDoc} */
+        @Override public void readBinary(BinaryReader reader) throws BinaryObjectException {
+            obj = reader.readObject("obj");
+        }
+    }
+
+    /**
+     *
+     */
+    private static class TestStore extends CacheStoreAdapter<Integer, Object> {
+        /** {@inheritDoc} */
+        @Override public void loadCache(IgniteBiInClosure<Integer, Object> clo, Object... args) {
+            for (int i = 1; i <= 3; i++)
+                clo.apply(i, new TestObject(i));
+        }
+
+        /** {@inheritDoc} */
+        @Nullable @Override public Object load(Integer key) {
+            return null;
+        }
+
+        /** {@inheritDoc} */
+        @Override public void write(Cache.Entry<? extends Integer, ?> e) {
+            // No-op.
+        }
+
+        /** {@inheritDoc} */
+        @Override public void delete(Object key) {
+            // No-op.
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/1dbf20e0/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/binary/GridCacheBinaryTransactionalEntryProcessorDeploymentSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/binary/GridCacheBinaryTransactionalEntryProcessorDeploymentSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/binary/GridCacheBinaryTransactionalEntryProcessorDeploymentSelfTest.java
new file mode 100644
index 0000000..6e8523f
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/binary/GridCacheBinaryTransactionalEntryProcessorDeploymentSelfTest.java
@@ -0,0 +1,31 @@
+/*
+ *  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.processors.cache.binary;
+
+import org.apache.ignite.cache.CacheAtomicityMode;
+
+/**
+ * Cache EntryProcessor + Deployment for transactional cache.
+ */
+public class GridCacheBinaryTransactionalEntryProcessorDeploymentSelfTest extends
+    GridCacheBinaryAtomicEntryProcessorDeploymentSelfTest {
+    /** {@inheritDoc} */
+    @Override protected CacheAtomicityMode atomicityMode() {
+        return CacheAtomicityMode.TRANSACTIONAL;
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/1dbf20e0/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/binary/GridCacheClientNodeBinaryObjectMetadataMultinodeTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/binary/GridCacheClientNodeBinaryObjectMetadataMultinodeTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/binary/GridCacheClientNodeBinaryObjectMetadataMultinodeTest.java
new file mode 100644
index 0000000..004494e
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/binary/GridCacheClientNodeBinaryObjectMetadataMultinodeTest.java
@@ -0,0 +1,295 @@
+/*
+ * 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.processors.cache.binary;
+
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.Set;
+import java.util.concurrent.Callable;
+import java.util.concurrent.CyclicBarrier;
+import java.util.concurrent.ThreadLocalRandom;
+import java.util.concurrent.atomic.AtomicBoolean;
+import java.util.concurrent.atomic.AtomicInteger;
+import org.apache.ignite.Ignite;
+import org.apache.ignite.IgniteCache;
+import org.apache.ignite.IgniteBinary;
+import org.apache.ignite.configuration.CacheConfiguration;
+import org.apache.ignite.configuration.IgniteConfiguration;
+import org.apache.ignite.internal.IgniteInternalFuture;
+import org.apache.ignite.internal.util.lang.GridAbsPredicate;
+import org.apache.ignite.internal.util.typedef.internal.U;
+import org.apache.ignite.internal.binary.BinaryMarshaller;
+import org.apache.ignite.binary.BinaryObjectBuilder;
+import org.apache.ignite.binary.BinaryType;
+import org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi;
+import org.apache.ignite.spi.discovery.tcp.ipfinder.TcpDiscoveryIpFinder;
+import org.apache.ignite.spi.discovery.tcp.ipfinder.vm.TcpDiscoveryVmIpFinder;
+import org.apache.ignite.testframework.GridTestUtils;
+import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
+import org.eclipse.jetty.util.ConcurrentHashSet;
+
+import static org.apache.ignite.cache.CacheWriteSynchronizationMode.FULL_SYNC;
+
+/**
+ *
+ */
+public class GridCacheClientNodeBinaryObjectMetadataMultinodeTest extends GridCommonAbstractTest {
+    /** */
+    protected static TcpDiscoveryIpFinder ipFinder = new TcpDiscoveryVmIpFinder(true);
+
+    /** */
+    private boolean client;
+
+    /** {@inheritDoc} */
+    @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception {
+        IgniteConfiguration cfg = super.getConfiguration(gridName);
+
+        cfg.setPeerClassLoadingEnabled(false);
+
+        ((TcpDiscoverySpi)cfg.getDiscoverySpi()).setIpFinder(ipFinder).setForceServerMode(true);
+
+        cfg.setMarshaller(new BinaryMarshaller());
+
+        CacheConfiguration ccfg = new CacheConfiguration();
+
+        ccfg.setWriteSynchronizationMode(FULL_SYNC);
+
+        cfg.setCacheConfiguration(ccfg);
+
+        cfg.setClientMode(client);
+
+        return cfg;
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void afterTest() throws Exception {
+        super.afterTest();
+
+        stopAllGrids();
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testClientMetadataInitialization() throws Exception {
+        startGrids(2);
+
+        final AtomicBoolean stop = new AtomicBoolean();
+
+        final ConcurrentHashSet<String> allTypes = new ConcurrentHashSet<>();
+
+        IgniteInternalFuture<?> fut;
+
+        try {
+            // Update portable metadata concurrently with client nodes start.
+            fut = GridTestUtils.runMultiThreadedAsync(new Callable<Object>() {
+                @Override public Object call() throws Exception {
+                    IgniteBinary portables = ignite(0).binary();
+
+                    IgniteCache<Object, Object> cache = ignite(0).cache(null).withKeepBinary();
+
+                    ThreadLocalRandom rnd = ThreadLocalRandom.current();
+
+                    for (int i = 0; i < 1000; i++) {
+                        log.info("Iteration: " + i);
+
+                        String type = "portable-type-" + i;
+
+                        allTypes.add(type);
+
+                        for (int f = 0; f < 10; f++) {
+                            BinaryObjectBuilder builder = portables.builder(type);
+
+                            String fieldName = "f" + f;
+
+                            builder.setField(fieldName, i);
+
+                            cache.put(rnd.nextInt(0, 100_000), builder.build());
+
+                            if (f % 100 == 0)
+                                log.info("Put iteration: " + f);
+                        }
+
+                        if (stop.get())
+                            break;
+                    }
+
+                    return null;
+                }
+            }, 5, "update-thread");
+        }
+        finally {
+            stop.set(true);
+        }
+
+        client = true;
+
+        startGridsMultiThreaded(2, 5);
+
+        fut.get();
+
+        assertFalse(allTypes.isEmpty());
+
+        log.info("Expected portable types: " + allTypes.size());
+
+        assertEquals(7, ignite(0).cluster().nodes().size());
+
+        for (int i = 0; i < 7; i++) {
+            log.info("Check metadata on node: " + i);
+
+            boolean client = i > 1;
+
+            assertEquals((Object)client, ignite(i).configuration().isClientMode());
+
+            IgniteBinary portables = ignite(i).binary();
+
+            Collection<BinaryType> metaCol = portables.types();
+
+            assertEquals(allTypes.size(), metaCol.size());
+
+            Set<String> names = new HashSet<>();
+
+            for (BinaryType meta : metaCol) {
+                assertTrue(names.add(meta.typeName()));
+
+                assertNull(meta.affinityKeyFieldName());
+
+                assertEquals(10, meta.fieldNames().size());
+            }
+
+            assertEquals(allTypes.size(), names.size());
+        }
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testFailoverOnStart() throws Exception {
+        startGrids(4);
+
+        IgniteBinary portables = ignite(0).binary();
+
+        IgniteCache<Object, Object> cache = ignite(0).cache(null).withKeepBinary();
+
+        for (int i = 0; i < 1000; i++) {
+            BinaryObjectBuilder builder = portables.builder("type-" + i);
+
+            builder.setField("f0", i);
+
+            cache.put(i, builder.build());
+        }
+
+        client = true;
+
+        final CyclicBarrier barrier = new CyclicBarrier(6);
+
+        final AtomicInteger startIdx = new AtomicInteger(4);
+
+        IgniteInternalFuture<?> fut = GridTestUtils.runMultiThreadedAsync(new Callable<Object>() {
+            @Override public Object call() throws Exception {
+                barrier.await();
+
+                Ignite ignite = startGrid(startIdx.getAndIncrement());
+
+                assertTrue(ignite.configuration().isClientMode());
+
+                log.info("Started node: " + ignite.name());
+
+                return null;
+            }
+        }, 5, "start-thread");
+
+        barrier.await();
+
+        U.sleep(ThreadLocalRandom.current().nextInt(10, 100));
+
+        for (int i = 0; i < 3; i++)
+            stopGrid(i);
+
+        fut.get();
+
+        assertEquals(6, ignite(3).cluster().nodes().size());
+
+        for (int i = 3; i < 7; i++) {
+            log.info("Check metadata on node: " + i);
+
+            boolean client = i > 3;
+
+            assertEquals((Object) client, ignite(i).configuration().isClientMode());
+
+            portables = ignite(i).binary();
+
+            final IgniteBinary p0 = portables;
+
+            GridTestUtils.waitForCondition(new GridAbsPredicate() {
+                @Override public boolean apply() {
+                    Collection<BinaryType> metaCol = p0.types();
+
+                    return metaCol.size() == 1000;
+                }
+            }, getTestTimeout());
+
+            Collection<BinaryType> metaCol = portables.types();
+
+            assertEquals(1000, metaCol.size());
+
+            Set<String> names = new HashSet<>();
+
+            for (BinaryType meta : metaCol) {
+                assertTrue(names.add(meta.typeName()));
+
+                assertNull(meta.affinityKeyFieldName());
+
+                assertEquals(1, meta.fieldNames().size());
+            }
+
+            assertEquals(1000, names.size());
+        }
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testClientStartsFirst() throws Exception {
+        client = true;
+
+        Ignite ignite0 = startGrid(0);
+
+        assertTrue(ignite0.configuration().isClientMode());
+
+        client = false;
+
+        Ignite ignite1 = startGrid(1);
+
+        assertFalse(ignite1.configuration().isClientMode());
+
+        IgniteBinary portables = ignite(1).binary();
+
+        IgniteCache<Object, Object> cache = ignite(1).cache(null).withKeepBinary();
+
+        for (int i = 0; i < 100; i++) {
+            BinaryObjectBuilder builder = portables.builder("type-" + i);
+
+            builder.setField("f0", i);
+
+            cache.put(i, builder.build());
+        }
+
+        assertEquals(100, ignite(0).binary().types().size());
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/1dbf20e0/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/binary/GridCacheClientNodeBinaryObjectMetadataTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/binary/GridCacheClientNodeBinaryObjectMetadataTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/binary/GridCacheClientNodeBinaryObjectMetadataTest.java
new file mode 100644
index 0000000..2a71748
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/binary/GridCacheClientNodeBinaryObjectMetadataTest.java
@@ -0,0 +1,221 @@
+/*
+ * 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.processors.cache.binary;
+
+import java.util.Arrays;
+import java.util.Collection;
+import org.apache.ignite.Ignite;
+import org.apache.ignite.binary.BinaryType;
+import org.apache.ignite.binary.BinaryTypeConfiguration;
+import org.apache.ignite.cache.CacheAtomicityMode;
+import org.apache.ignite.cache.CacheKeyConfiguration;
+import org.apache.ignite.cache.CacheMode;
+import org.apache.ignite.cache.affinity.Affinity;
+import org.apache.ignite.configuration.BinaryConfiguration;
+import org.apache.ignite.configuration.IgniteConfiguration;
+import org.apache.ignite.configuration.NearCacheConfiguration;
+import org.apache.ignite.internal.processors.cache.GridCacheAbstractSelfTest;
+import org.apache.ignite.internal.binary.BinaryMarshaller;
+import org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi;
+
+import static org.apache.ignite.cache.CacheAtomicityMode.ATOMIC;
+
+/**
+ *
+ */
+public class GridCacheClientNodeBinaryObjectMetadataTest extends GridCacheAbstractSelfTest {
+    /** {@inheritDoc} */
+    @Override protected int gridCount() {
+        return 4;
+    }
+
+    /** {@inheritDoc} */
+    @Override protected CacheMode cacheMode() {
+        return CacheMode.PARTITIONED;
+    }
+
+    /** {@inheritDoc} */
+    @Override protected CacheAtomicityMode atomicityMode() {
+        return ATOMIC;
+    }
+
+    /** {@inheritDoc} */
+    @Override protected NearCacheConfiguration nearConfiguration() {
+        return null;
+    }
+
+    /** {@inheritDoc} */
+    @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception {
+        IgniteConfiguration cfg = super.getConfiguration(gridName);
+
+        BinaryMarshaller marsh = new BinaryMarshaller();
+
+        BinaryConfiguration bCfg = new BinaryConfiguration();
+
+        bCfg.setClassNames(Arrays.asList(TestObject1.class.getName(), TestObject2.class.getName()));
+
+        BinaryTypeConfiguration typeCfg = new BinaryTypeConfiguration();
+
+        typeCfg.setTypeName(TestObject1.class.getName());
+
+        CacheKeyConfiguration keyCfg = new CacheKeyConfiguration(TestObject1.class.getName(), "val2");
+
+        cfg.setCacheKeyConfiguration(keyCfg);
+
+        bCfg.setTypeConfigurations(Arrays.asList(typeCfg));
+
+        cfg.setBinaryConfiguration(bCfg);
+
+        if (gridName.equals(getTestGridName(gridCount() - 1)))
+            cfg.setClientMode(true);
+
+        cfg.setMarshaller(marsh);
+
+        ((TcpDiscoverySpi)cfg.getDiscoverySpi()).setForceServerMode(true);
+
+        return cfg;
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testPortableMetadataOnClient() throws Exception {
+        Ignite ignite0 = ignite(gridCount() - 1);
+
+        assertTrue(ignite0.configuration().isClientMode());
+
+        Ignite ignite1 = ignite(0);
+
+        assertFalse(ignite1.configuration().isClientMode());
+
+        Affinity<Object> aff0 = ignite0.affinity(null);
+        Affinity<Object> aff1 = ignite1.affinity(null);
+
+        for (int i = 0 ; i < 100; i++) {
+            TestObject1 obj1 = new TestObject1(i, i + 1);
+
+            assertEquals(aff1.mapKeyToPrimaryAndBackups(obj1),
+                aff0.mapKeyToPrimaryAndBackups(obj1));
+
+            TestObject2 obj2 = new TestObject2(i, i + 1);
+
+            assertEquals(aff1.mapKeyToPrimaryAndBackups(obj2),
+                aff0.mapKeyToPrimaryAndBackups(obj2));
+        }
+
+        Collection<BinaryType> meta1 = ignite1.binary().types();
+        Collection<BinaryType> meta2 = ignite1.binary().types();
+
+        assertEquals(meta1.size(), meta2.size());
+
+        for (BinaryType m1 : meta1) {
+            boolean found = false;
+
+            for (BinaryType m2 : meta1) {
+                if (m1.typeName().equals(m2.typeName())) {
+                    assertEquals(m1.affinityKeyFieldName(), m2.affinityKeyFieldName());
+                    assertEquals(m1.fieldNames(), m2.fieldNames());
+
+                    found = true;
+
+                    break;
+                }
+            }
+
+            assertTrue(found);
+        }
+    }
+
+    /**
+     *
+     */
+    static class TestObject1 {
+        /** */
+        private int val1;
+
+        /** */
+        private int val2;
+
+        /**
+         * @param val1 Value 1.
+         * @param val2 Value 2.
+         */
+        public TestObject1(int val1, int val2) {
+            this.val1 = val1;
+            this.val2 = val2;
+        }
+
+        /** {@inheritDoc} */
+        @Override public boolean equals(Object o) {
+            if (this == o)
+                return true;
+
+            if (o == null || getClass() != o.getClass())
+                return false;
+
+            TestObject1 that = (TestObject1)o;
+
+            return val1 == that.val1;
+
+        }
+
+        /** {@inheritDoc} */
+        @Override public int hashCode() {
+            return val1;
+        }
+    }
+
+    /**
+     *
+     */
+    static class TestObject2 {
+        /** */
+        private int val1;
+
+        /** */
+        private int val2;
+
+        /**
+         * @param val1 Value 1.
+         * @param val2 Value 2.
+         */
+        public TestObject2(int val1, int val2) {
+            this.val1 = val1;
+            this.val2 = val2;
+        }
+
+        /** {@inheritDoc} */
+        @Override public boolean equals(Object o) {
+            if (this == o)
+                return true;
+
+            if (o == null || getClass() != o.getClass())
+                return false;
+
+            TestObject2 that = (TestObject2)o;
+
+            return val2 == that.val2;
+
+        }
+
+        /** {@inheritDoc} */
+        @Override public int hashCode() {
+            return val2;
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/1dbf20e0/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/binary/GridCachePortableStoreAbstractSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/binary/GridCachePortableStoreAbstractSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/binary/GridCachePortableStoreAbstractSelfTest.java
new file mode 100644
index 0000000..b9d7b5d
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/binary/GridCachePortableStoreAbstractSelfTest.java
@@ -0,0 +1,300 @@
+/*
+ * 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.processors.cache.binary;
+
+import com.google.common.collect.ImmutableSet;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+import javax.cache.Cache;
+import org.apache.ignite.cache.store.CacheStoreAdapter;
+import org.apache.ignite.configuration.BinaryConfiguration;
+import org.apache.ignite.configuration.CacheConfiguration;
+import org.apache.ignite.configuration.IgniteConfiguration;
+import org.apache.ignite.internal.binary.BinaryMarshaller;
+import org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi;
+import org.apache.ignite.spi.discovery.tcp.ipfinder.TcpDiscoveryIpFinder;
+import org.apache.ignite.spi.discovery.tcp.ipfinder.vm.TcpDiscoveryVmIpFinder;
+import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
+import org.jetbrains.annotations.Nullable;
+import org.jsr166.ConcurrentHashMap8;
+
+/**
+ * Tests for cache store with binary.
+ */
+public abstract class GridCachePortableStoreAbstractSelfTest extends GridCommonAbstractTest {
+    /** */
+    private static final TcpDiscoveryIpFinder IP_FINDER = new TcpDiscoveryVmIpFinder(true);
+
+    /** */
+    private static final TestStore STORE = new TestStore();
+
+    /** {@inheritDoc} */
+    @SuppressWarnings("unchecked")
+    @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception {
+        IgniteConfiguration cfg = super.getConfiguration(gridName);
+
+        BinaryConfiguration bCfg = new BinaryConfiguration();
+
+        bCfg.setClassNames(Arrays.asList(Key.class.getName(), Value.class.getName()));
+
+        cfg.setBinaryConfiguration(bCfg);
+
+        cfg.setMarshaller(new BinaryMarshaller());
+
+        CacheConfiguration cacheCfg = new CacheConfiguration();
+
+        cacheCfg.setCacheStoreFactory(singletonFactory(STORE));
+        cacheCfg.setKeepBinaryInStore(keepPortableInStore());
+        cacheCfg.setReadThrough(true);
+        cacheCfg.setWriteThrough(true);
+        cacheCfg.setLoadPreviousValue(true);
+
+        cfg.setCacheConfiguration(cacheCfg);
+
+        TcpDiscoverySpi disco = new TcpDiscoverySpi();
+
+        disco.setIpFinder(IP_FINDER);
+
+        cfg.setDiscoverySpi(disco);
+
+        return cfg;
+    }
+
+    /**
+     * @return Keep binary in store flag.
+     */
+    protected abstract boolean keepPortableInStore();
+
+    /** {@inheritDoc} */
+    @Override protected void beforeTestsStarted() throws Exception {
+        startGrid();
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void afterTestsStopped() throws Exception {
+        stopGrid();
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void beforeTest() throws Exception {
+        STORE.map().clear();
+
+        jcache().clear();
+
+        assert jcache().size() == 0;
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testPut() throws Exception {
+        jcache().put(new Key(1), new Value(1));
+
+        checkMap(STORE.map(), 1);
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testPutAll() throws Exception {
+        Map<Object, Object> map = new HashMap<>();
+
+        for (int i = 1; i <= 3; i++)
+            map.put(new Key(i), new Value(i));
+
+        jcache().putAll(map);
+
+        checkMap(STORE.map(), 1, 2, 3);
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testLoad() throws Exception {
+        populateMap(STORE.map(), 1);
+
+        Object val = jcache().get(new Key(1));
+
+        assertTrue(String.valueOf(val), val instanceof Value);
+
+        assertEquals(1, ((Value)val).index());
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testLoadAll() throws Exception {
+        populateMap(STORE.map(), 1, 2, 3);
+
+        Set<Object> keys = new HashSet<>();
+
+        for (int i = 1; i <= 3; i++)
+            keys.add(new Key(i));
+
+        Map<Object, Object> res = jcache().getAll(keys);
+
+        assertEquals(3, res.size());
+
+        for (int i = 1; i <= 3; i++) {
+            Object val = res.get(new Key(i));
+
+            assertTrue(String.valueOf(val), val instanceof Value);
+
+            assertEquals(i, ((Value)val).index());
+        }
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testRemove() throws Exception {
+        for (int i = 1; i <= 3; i++)
+            jcache().put(new Key(i), new Value(i));
+
+        jcache().remove(new Key(1));
+
+        checkMap(STORE.map(), 2, 3);
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testRemoveAll() throws Exception {
+        for (int i = 1; i <= 3; i++)
+            jcache().put(new Key(i), new Value(i));
+
+        jcache().removeAll(ImmutableSet.of(new Key(1), new Key(2)));
+
+        checkMap(STORE.map(), 3);
+    }
+
+    /**
+     * @param map Map.
+     * @param idxs Indexes.
+     */
+    protected abstract void populateMap(Map<Object, Object> map, int... idxs);
+
+    /**
+     * @param map Map.
+     * @param idxs Indexes.
+     */
+    protected abstract void checkMap(Map<Object, Object> map, int... idxs);
+
+    /**
+     */
+    protected static class Key {
+        /** */
+        private int idx;
+
+        /**
+         * @param idx Index.
+         */
+        public Key(int idx) {
+            this.idx = idx;
+        }
+
+        /**
+         * @return Index.
+         */
+        int index() {
+            return idx;
+        }
+
+        /** {@inheritDoc} */
+        @Override public boolean equals(Object o) {
+            if (this == o)
+                return true;
+
+            if (o == null || getClass() != o.getClass())
+                return false;
+
+            Key key = (Key)o;
+
+            return idx == key.idx;
+        }
+
+        /** {@inheritDoc} */
+        @Override public int hashCode() {
+            return idx;
+        }
+
+        /** {@inheritDoc} */
+        @Override public String toString() {
+            return "Key [idx=" + idx + ']';
+        }
+    }
+
+    /**
+     */
+    protected static class Value {
+        /** */
+        private int idx;
+
+        /**
+         * @param idx Index.
+         */
+        public Value(int idx) {
+            this.idx = idx;
+        }
+
+        /**
+         * @return Index.
+         */
+        int index() {
+            return idx;
+        }
+
+        /** {@inheritDoc} */
+        @Override public String toString() {
+            return "Value [idx=" + idx + ']';
+        }
+    }
+
+    /**
+     *
+     */
+    private static class TestStore extends CacheStoreAdapter<Object, Object> {
+        /** */
+        private final Map<Object, Object> map = new ConcurrentHashMap8<>();
+
+        /** {@inheritDoc} */
+        @Nullable @Override public Object load(Object key) {
+            return map.get(key);
+        }
+
+        /** {@inheritDoc} */
+        @Override public void write(Cache.Entry<?, ?> e) {
+            map.put(e.getKey(), e.getValue());
+        }
+
+        /** {@inheritDoc} */
+        @Override public void delete(Object key) {
+            map.remove(key);
+        }
+
+        /**
+         * @return Map.
+         */
+        Map<Object, Object> map() {
+            return map;
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/1dbf20e0/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/binary/GridCachePortableStoreObjectsSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/binary/GridCachePortableStoreObjectsSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/binary/GridCachePortableStoreObjectsSelfTest.java
new file mode 100644
index 0000000..00d1ae4
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/binary/GridCachePortableStoreObjectsSelfTest.java
@@ -0,0 +1,55 @@
+/*
+ * 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.processors.cache.binary;
+
+import java.util.Map;
+
+/**
+ * Tests for cache store with binary.
+ */
+public class GridCachePortableStoreObjectsSelfTest extends GridCachePortableStoreAbstractSelfTest {
+    /** {@inheritDoc} */
+    @Override protected boolean keepPortableInStore() {
+        return false;
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void populateMap(Map<Object, Object> map, int... idxs) {
+        assert map != null;
+        assert idxs != null;
+
+        for (int idx : idxs)
+            map.put(new Key(idx), new Value(idx));
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void checkMap(Map<Object, Object> map, int... idxs) {
+        assert map != null;
+        assert idxs != null;
+
+        assertEquals(idxs.length, map.size());
+
+        for (int idx : idxs) {
+            Object val = map.get(new Key(idx));
+
+            assertTrue(String.valueOf(val), val instanceof Value);
+
+            assertEquals(idx, ((Value)val).index());
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/1dbf20e0/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/binary/GridCachePortableStorePortablesSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/binary/GridCachePortableStorePortablesSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/binary/GridCachePortableStorePortablesSelfTest.java
new file mode 100644
index 0000000..40fc9c6
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/binary/GridCachePortableStorePortablesSelfTest.java
@@ -0,0 +1,66 @@
+/*
+ * 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.processors.cache.binary;
+
+import java.util.Map;
+import org.apache.ignite.binary.BinaryObject;
+
+/**
+ * Tests for cache store with binary.
+ */
+public class GridCachePortableStorePortablesSelfTest extends GridCachePortableStoreAbstractSelfTest {
+    /** {@inheritDoc} */
+    @Override protected boolean keepPortableInStore() {
+        return true;
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void populateMap(Map<Object, Object> map, int... idxs) {
+        assert map != null;
+        assert idxs != null;
+
+        for (int idx : idxs)
+            map.put(portable(new Key(idx)), portable(new Value(idx)));
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void checkMap(Map<Object, Object> map, int... idxs) {
+        assert map != null;
+        assert idxs != null;
+
+        assertEquals(idxs.length, map.size());
+
+        for (int idx : idxs) {
+            Object val = map.get(portable(new Key(idx)));
+
+            assertTrue(String.valueOf(val), val instanceof BinaryObject);
+
+            BinaryObject po = (BinaryObject)val;
+
+            assertEquals("Value", po.type().typeName());
+            assertEquals(new Integer(idx), po.field("idx"));
+        }
+    }
+
+    /**
+     * @param obj Object.
+     * @return Portable object.
+     */
+    private Object portable(Object obj) {
+        return grid().binary().toBinary(obj);
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/1dbf20e0/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/binary/GridPortableCacheEntryMemorySizeSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/binary/GridPortableCacheEntryMemorySizeSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/binary/GridPortableCacheEntryMemorySizeSelfTest.java
new file mode 100644
index 0000000..f2c75c9
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/binary/GridPortableCacheEntryMemorySizeSelfTest.java
@@ -0,0 +1,48 @@
+/*
+ * 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.processors.cache.binary;
+
+import org.apache.ignite.IgniteCheckedException;
+import org.apache.ignite.configuration.IgniteConfiguration;
+import org.apache.ignite.internal.binary.BinaryNoopMetadataHandler;
+import org.apache.ignite.internal.binary.PortableContext;
+import org.apache.ignite.internal.processors.cache.GridCacheEntryMemorySizeSelfTest;
+import org.apache.ignite.internal.util.IgniteUtils;
+import org.apache.ignite.marshaller.Marshaller;
+import org.apache.ignite.marshaller.MarshallerContextTestImpl;
+import org.apache.ignite.internal.binary.BinaryMarshaller;
+
+/**
+ *
+ */
+public class GridPortableCacheEntryMemorySizeSelfTest extends GridCacheEntryMemorySizeSelfTest {
+    /** {@inheritDoc} */
+    @Override protected Marshaller createMarshaller() throws IgniteCheckedException {
+        BinaryMarshaller marsh = new BinaryMarshaller();
+
+        marsh.setContext(new MarshallerContextTestImpl(null));
+
+        IgniteConfiguration iCfg = new IgniteConfiguration();
+
+        PortableContext pCtx = new PortableContext(BinaryNoopMetadataHandler.instance(), iCfg);
+
+        IgniteUtils.invoke(BinaryMarshaller.class, marsh, "setPortableContext", pCtx, iCfg);
+
+        return marsh;
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/1dbf20e0/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/binary/GridPortableDuplicateIndexObjectsAbstractSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/binary/GridPortableDuplicateIndexObjectsAbstractSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/binary/GridPortableDuplicateIndexObjectsAbstractSelfTest.java
new file mode 100644
index 0000000..6ef8749
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/binary/GridPortableDuplicateIndexObjectsAbstractSelfTest.java
@@ -0,0 +1,161 @@
+/*
+ * 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.processors.cache.binary;
+
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import org.apache.ignite.IgniteCache;
+import org.apache.ignite.cache.CacheAtomicityMode;
+import org.apache.ignite.cache.CacheMode;
+import org.apache.ignite.cache.CacheTypeMetadata;
+import org.apache.ignite.cache.query.SqlFieldsQuery;
+import org.apache.ignite.configuration.BinaryConfiguration;
+import org.apache.ignite.configuration.CacheConfiguration;
+import org.apache.ignite.configuration.IgniteConfiguration;
+import org.apache.ignite.internal.processors.cache.GridCacheAbstractSelfTest;
+import org.apache.ignite.internal.util.typedef.F;
+import org.apache.ignite.internal.binary.BinaryMarshaller;
+import org.apache.ignite.binary.BinaryObject;
+
+/**
+ * Tests that portable object is the same in cache entry and in index.
+ */
+public abstract class GridPortableDuplicateIndexObjectsAbstractSelfTest extends GridCacheAbstractSelfTest {
+    /** {@inheritDoc} */
+    @Override protected int gridCount() {
+        return 1;
+    }
+
+    /** {@inheritDoc} */
+    @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception {
+        IgniteConfiguration cfg = super.getConfiguration(gridName);
+
+        BinaryConfiguration bCfg = new BinaryConfiguration();
+
+        bCfg.setClassNames(Collections.singletonList(TestPortable.class.getName()));
+
+        cfg.setBinaryConfiguration(bCfg);
+
+        cfg.setMarshaller(new BinaryMarshaller());
+
+        return cfg;
+    }
+
+    /** {@inheritDoc} */
+    @Override protected CacheConfiguration cacheConfiguration(String gridName) throws Exception {
+        CacheConfiguration ccfg = super.cacheConfiguration(gridName);
+
+        ccfg.setCopyOnRead(false);
+
+        CacheTypeMetadata meta = new CacheTypeMetadata();
+
+        meta.setKeyType(Integer.class);
+        meta.setValueType(TestPortable.class.getName());
+
+        Map<String, Class<?>> idx = new HashMap<>();
+
+        idx.put("fieldOne", String.class);
+        idx.put("fieldTwo", Integer.class);
+
+        meta.setAscendingFields(idx);
+
+        ccfg.setTypeMetadata(Collections.singletonList(meta));
+
+        return ccfg;
+    }
+
+    /** {@inheritDoc} */
+    @Override public abstract CacheAtomicityMode atomicityMode();
+
+    /** {@inheritDoc} */
+    @Override public abstract CacheMode cacheMode();
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testIndexReferences() throws Exception {
+        IgniteCache<Integer, TestPortable> cache = grid(0).cache(null);
+
+        String fieldOneVal = "123";
+        int fieldTwoVal = 123;
+        int key = 0;
+
+        cache.put(key, new TestPortable(fieldOneVal, fieldTwoVal));
+
+        IgniteCache<Integer, BinaryObject> prj = grid(0).cache(null).withKeepBinary();
+
+        BinaryObject cacheVal = prj.get(key);
+
+        assertEquals(fieldOneVal, cacheVal.field("fieldOne"));
+        assertEquals(new Integer(fieldTwoVal), cacheVal.field("fieldTwo"));
+
+        List<?> row = F.first(prj.query(new SqlFieldsQuery("select _val from " +
+            "TestPortable where _key = ?").setArgs(key)).getAll());
+
+        assertEquals(1, row.size());
+
+        BinaryObject qryVal = (BinaryObject)row.get(0);
+
+        assertEquals(fieldOneVal, qryVal.field("fieldOne"));
+        assertEquals(new Integer(fieldTwoVal), qryVal.field("fieldTwo"));
+        assertSame(cacheVal, qryVal);
+    }
+
+    /**
+     * Test portable object.
+     */
+    private static class TestPortable {
+        /** */
+        private String fieldOne;
+
+        /** */
+        private int fieldTwo;
+
+        /**
+         *
+         */
+        private TestPortable() {
+            // No-op.
+        }
+
+        /**
+         * @param fieldOne Field one.
+         * @param fieldTwo Field two.
+         */
+        private TestPortable(String fieldOne, int fieldTwo) {
+            this.fieldOne = fieldOne;
+            this.fieldTwo = fieldTwo;
+        }
+
+        /**
+         * @return Field one.
+         */
+        public String fieldOne() {
+            return fieldOne;
+        }
+
+        /**
+         * @return Field two.
+         */
+        public int fieldTwo() {
+            return fieldTwo;
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/1dbf20e0/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/binary/datastreaming/DataStreamProcessorPortableSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/binary/datastreaming/DataStreamProcessorPortableSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/binary/datastreaming/DataStreamProcessorPortableSelfTest.java
new file mode 100644
index 0000000..0538b9e
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/binary/datastreaming/DataStreamProcessorPortableSelfTest.java
@@ -0,0 +1,71 @@
+/*
+ * 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.processors.cache.binary.datastreaming;
+
+import java.util.Collection;
+import java.util.Map;
+import org.apache.ignite.IgniteCache;
+import org.apache.ignite.binary.BinaryObject;
+import org.apache.ignite.configuration.IgniteConfiguration;
+import org.apache.ignite.internal.processors.datastreamer.DataStreamProcessorSelfTest;
+import org.apache.ignite.internal.binary.BinaryMarshaller;
+import org.apache.ignite.stream.StreamReceiver;
+
+/**
+ *
+ */
+public class DataStreamProcessorPortableSelfTest extends DataStreamProcessorSelfTest {
+    /** {@inheritDoc} */
+    @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception {
+        IgniteConfiguration cfg = super.getConfiguration(gridName);
+
+        BinaryMarshaller marsh = new BinaryMarshaller();
+
+        cfg.setMarshaller(marsh);
+
+        return cfg;
+    }
+
+    /** {@inheritDoc} */
+    @Override protected StreamReceiver<String, TestObject> getStreamReceiver() {
+        return new TestDataReceiver();
+    }
+
+    /** {@inheritDoc} */
+    @Override protected boolean customKeepBinary() {
+        return true;
+    }
+
+    /**
+     *
+     */
+    private static class TestDataReceiver implements StreamReceiver<String, TestObject> {
+        /** {@inheritDoc} */
+        @Override public void receive(IgniteCache<String, TestObject> cache,
+            Collection<Map.Entry<String, TestObject>> entries) {
+            for (Map.Entry<String, TestObject> e : entries) {
+                assertTrue(e.getKey() instanceof String);
+                assertTrue(String.valueOf(e.getValue()), e.getValue() instanceof BinaryObject);
+
+                TestObject obj = ((BinaryObject)e.getValue()).deserialize();
+
+                cache.put(e.getKey(), new TestObject(obj.val + 1));
+            }
+        }
+    }
+}


[23/59] [abbrv] ignite git commit: ignite-2065: rename "portable" packages to "binary"

Posted by ak...@apache.org.
http://git-wip-us.apache.org/repos/asf/ignite/blob/1dbf20e0/modules/core/src/main/java/org/apache/ignite/internal/portable/BinaryCachingMetadataHandler.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/portable/BinaryCachingMetadataHandler.java b/modules/core/src/main/java/org/apache/ignite/internal/portable/BinaryCachingMetadataHandler.java
deleted file mode 100644
index a3c846b..0000000
--- a/modules/core/src/main/java/org/apache/ignite/internal/portable/BinaryCachingMetadataHandler.java
+++ /dev/null
@@ -1,70 +0,0 @@
-/*
- * 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.portable;
-
-import org.apache.ignite.binary.BinaryObjectException;
-import org.apache.ignite.binary.BinaryType;
-
-import java.util.HashMap;
-
-/**
- * Simple caching metadata handler. Used mainly in tests.
- */
-public class BinaryCachingMetadataHandler implements BinaryMetadataHandler {
-    /** Cached metadatas. */
-    private final HashMap<Integer, BinaryType> metas = new HashMap<>();
-
-    /**
-     * Create new handler instance.
-     *
-     * @return New handler.
-     */
-    public static BinaryCachingMetadataHandler create() {
-        return new BinaryCachingMetadataHandler();
-    }
-
-    /**
-     * Private constructor.
-     */
-    private BinaryCachingMetadataHandler() {
-        // No-op.
-    }
-
-    /** {@inheritDoc} */
-    @Override public synchronized void addMeta(int typeId, BinaryType type) throws BinaryObjectException {
-        synchronized (this) {
-            BinaryType oldType = metas.put(typeId, type);
-
-            if (oldType != null) {
-                BinaryMetadata oldMeta = ((BinaryTypeImpl)oldType).metadata();
-                BinaryMetadata newMeta = ((BinaryTypeImpl)type).metadata();
-
-                BinaryMetadata mergedMeta = PortableUtils.mergeMetadata(oldMeta, newMeta);
-
-                BinaryType mergedType = mergedMeta.wrap(((BinaryTypeImpl)oldType).context());
-
-                metas.put(typeId, mergedType);
-            }
-        }
-    }
-
-    /** {@inheritDoc} */
-    @Override public synchronized BinaryType metadata(int typeId) throws BinaryObjectException {
-        return metas.get(typeId);
-    }
-}

http://git-wip-us.apache.org/repos/asf/ignite/blob/1dbf20e0/modules/core/src/main/java/org/apache/ignite/internal/portable/BinaryEnumCache.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/portable/BinaryEnumCache.java b/modules/core/src/main/java/org/apache/ignite/internal/portable/BinaryEnumCache.java
deleted file mode 100644
index fc042e5..0000000
--- a/modules/core/src/main/java/org/apache/ignite/internal/portable/BinaryEnumCache.java
+++ /dev/null
@@ -1,69 +0,0 @@
-/*
- * 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.portable;
-
-import org.apache.ignite.binary.BinaryObjectException;
-import org.jsr166.ConcurrentHashMap8;
-
-import java.util.concurrent.ConcurrentMap;
-
-/**
- * Cache for enum constants.
- */
-public class BinaryEnumCache {
-    /** Cache for enum constants. */
-    private static final ConcurrentMap<Class<?>, Object[]> ENUM_CACHE = new ConcurrentHashMap8<>();
-
-    /**
-     * Get value for the given class and ordinal.
-     *
-     * @param cls Class.
-     * @param ord Ordinal.
-     * @return Value.
-     * @throws BinaryObjectException In case of invalid ordinal.
-     */
-    @SuppressWarnings("unchecked")
-    public static <T> T get(Class<?> cls, int ord) throws BinaryObjectException {
-        assert cls != null;
-
-        if (ord >= 0) {
-            Object[] vals = ENUM_CACHE.get(cls);
-
-            if (vals == null) {
-                vals = cls.getEnumConstants();
-
-                ENUM_CACHE.putIfAbsent(cls, vals);
-            }
-
-            if (ord < vals.length)
-                return (T) vals[ord];
-            else
-                throw new BinaryObjectException("Failed to get enum value for ordinal (do you have correct class " +
-                    "version?) [cls=" + cls.getName() + ", ordinal=" + ord + ", totalValues=" + vals.length + ']');
-        }
-        else
-            return null;
-    }
-
-    /**
-     * Clears cache.
-     */
-    public static void clear() {
-        ENUM_CACHE.clear();
-    }
-}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ignite/blob/1dbf20e0/modules/core/src/main/java/org/apache/ignite/internal/portable/BinaryEnumObjectImpl.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/portable/BinaryEnumObjectImpl.java b/modules/core/src/main/java/org/apache/ignite/internal/portable/BinaryEnumObjectImpl.java
deleted file mode 100644
index 467d767..0000000
--- a/modules/core/src/main/java/org/apache/ignite/internal/portable/BinaryEnumObjectImpl.java
+++ /dev/null
@@ -1,311 +0,0 @@
-/*
- * 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.portable;
-
-import org.apache.ignite.IgniteCheckedException;
-import org.apache.ignite.binary.BinaryObject;
-import org.apache.ignite.binary.BinaryObjectException;
-import org.apache.ignite.binary.BinaryType;
-import org.apache.ignite.internal.GridDirectTransient;
-import org.apache.ignite.internal.processors.cache.CacheObject;
-import org.apache.ignite.internal.processors.cache.CacheObjectContext;
-import org.apache.ignite.internal.processors.cache.portable.CacheObjectBinaryProcessorImpl;
-import org.apache.ignite.internal.util.typedef.internal.SB;
-import org.apache.ignite.plugin.extensions.communication.MessageReader;
-import org.apache.ignite.plugin.extensions.communication.MessageWriter;
-import org.jetbrains.annotations.Nullable;
-
-import java.io.Externalizable;
-import java.io.IOException;
-import java.io.ObjectInput;
-import java.io.ObjectOutput;
-import java.nio.ByteBuffer;
-
-/**
- * Binary enum object.
- */
-public class BinaryEnumObjectImpl implements BinaryObjectEx, Externalizable, CacheObject {
-    /** */
-    private static final long serialVersionUID = 0L;
-
-    /** Context. */
-    @GridDirectTransient
-    private PortableContext ctx;
-
-    /** Type ID. */
-    private int typeId;
-
-    /** Raw data. */
-    private String clsName;
-
-    /** Ordinal. */
-    private int ord;
-
-    /**
-     * {@link Externalizable} support.
-     */
-    public BinaryEnumObjectImpl() {
-        // No-op.
-    }
-
-    /**
-     * Constructor.
-     *
-     * @param ctx Context.
-     * @param typeId Type ID.
-     * @param clsName Class name.
-     * @param ord Ordinal.
-     */
-    public BinaryEnumObjectImpl(PortableContext ctx, int typeId, @Nullable String clsName, int ord) {
-        assert ctx != null;
-
-        this.ctx = ctx;
-        this.typeId = typeId;
-        this.clsName = clsName;
-        this.ord = ord;
-    }
-
-    /**
-     * @return Class name.
-     */
-    @Nullable public String className() {
-        return clsName;
-    }
-
-    /** {@inheritDoc} */
-    @Override public int typeId() {
-        return typeId;
-    }
-
-    /** {@inheritDoc} */
-    @Override public BinaryType type() throws BinaryObjectException {
-        return ctx.metadata(typeId());
-    }
-
-    /** {@inheritDoc} */
-    @Override public <F> F field(String fieldName) throws BinaryObjectException {
-        return null;
-    }
-
-    /** {@inheritDoc} */
-    @Override public boolean hasField(String fieldName) {
-        return false;
-    }
-
-    /** {@inheritDoc} */
-    @SuppressWarnings("unchecked")
-    @Override public <T> T deserialize() throws BinaryObjectException {
-        Class cls = PortableUtils.resolveClass(ctx, typeId, clsName, null, true);
-
-        return BinaryEnumCache.get(cls, ord);
-    }
-
-    /** {@inheritDoc} */
-    @Override public BinaryObject clone() throws CloneNotSupportedException {
-        return (BinaryObject)super.clone();
-    }
-
-    /** {@inheritDoc} */
-    @Override public int enumOrdinal() throws BinaryObjectException {
-        return ord;
-    }
-
-    /** {@inheritDoc} */
-    @Override public int hashCode() {
-        return 31 * typeId + ord;
-    }
-
-    /** {@inheritDoc} */
-    @Override public boolean equals(Object obj) {
-        if (obj != null && (obj instanceof BinaryEnumObjectImpl)) {
-            BinaryEnumObjectImpl other = (BinaryEnumObjectImpl)obj;
-
-            return typeId == other.typeId && ord == other.ord;
-        }
-
-        return false;
-    }
-
-    /** {@inheritDoc} */
-    @Override public String toString() {
-        // 1. Try deserializing the object.
-        try {
-            Object val = deserialize();
-
-            return new SB().a(val).toString();
-        }
-        catch (Exception e) {
-            // No-op.
-        }
-
-        // 2. Try getting meta.
-        BinaryType type;
-
-        try {
-            type = type();
-        }
-        catch (Exception e) {
-            type = null;
-        }
-
-        if (type != null) {
-            return type.typeName() + "[ordinal=" + ord  + ']';
-        }
-        else {
-            if (typeId == GridPortableMarshaller.UNREGISTERED_TYPE_ID)
-                return "BinaryEnum[clsName=" + clsName + ", ordinal=" + ord + ']';
-            else
-                return "BinaryEnum[typeId=" + typeId + ", ordinal=" + ord + ']';
-        }
-    }
-
-    /** {@inheritDoc} */
-    @Override public void writeExternal(ObjectOutput out) throws IOException {
-        out.writeObject(ctx);
-
-        out.writeInt(typeId);
-        out.writeObject(clsName);
-        out.writeInt(ord);
-    }
-
-    /** {@inheritDoc} */
-    @Override public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
-        ctx = (PortableContext)in.readObject();
-
-        typeId = in.readInt();
-        clsName = (String)in.readObject();
-        ord = in.readInt();
-    }
-
-    /** {@inheritDoc} */
-    @Nullable @Override public <T> T value(CacheObjectContext ctx, boolean cpy) {
-        return deserialize();
-    }
-
-    /** {@inheritDoc} */
-    @Override public byte[] valueBytes(CacheObjectContext cacheCtx) throws IgniteCheckedException {
-        return ctx.marshaller().marshal(this);
-    }
-
-    /** {@inheritDoc} */
-    @Override public byte cacheObjectType() {
-        return TYPE_BINARY;
-    }
-
-    /** {@inheritDoc} */
-    @Override public boolean isPlatformType() {
-        return false;
-    }
-
-    /** {@inheritDoc} */
-    @Override public CacheObject prepareForCache(CacheObjectContext ctx) {
-        return this;
-    }
-
-    /** {@inheritDoc} */
-    @Override public void finishUnmarshal(CacheObjectContext ctx, ClassLoader ldr) throws IgniteCheckedException {
-        this.ctx = ((CacheObjectBinaryProcessorImpl)ctx.processor()).portableContext();
-    }
-
-    /** {@inheritDoc} */
-    @Override public void prepareMarshal(CacheObjectContext ctx) throws IgniteCheckedException {
-        // No-op.
-    }
-
-    /** {@inheritDoc} */
-    @Override public byte directType() {
-        return 119;
-    }
-
-    /** {@inheritDoc} */
-    @Override public byte fieldsCount() {
-        return 3;
-    }
-
-    /** {@inheritDoc} */
-    @Override public boolean writeTo(ByteBuffer buf, MessageWriter writer) {
-        writer.setBuffer(buf);
-
-        if (!writer.isHeaderWritten()) {
-            if (!writer.writeHeader(directType(), fieldsCount()))
-                return false;
-
-            writer.onHeaderWritten();
-        }
-
-        switch (writer.state()) {
-            case 0:
-                if (!writer.writeString("clsName", clsName))
-                    return false;
-
-                writer.incrementState();
-
-            case 1:
-                if (!writer.writeInt("ord", ord))
-                    return false;
-
-                writer.incrementState();
-
-            case 2:
-                if (!writer.writeInt("typeId", typeId))
-                    return false;
-
-                writer.incrementState();
-
-        }
-
-        return true;
-    }
-
-    /** {@inheritDoc} */
-    @Override public boolean readFrom(ByteBuffer buf, MessageReader reader) {
-        reader.setBuffer(buf);
-
-        if (!reader.beforeMessageRead())
-            return false;
-
-        switch (reader.state()) {
-            case 0:
-                clsName = reader.readString("clsName");
-
-                if (!reader.isLastRead())
-                    return false;
-
-                reader.incrementState();
-
-            case 1:
-                ord = reader.readInt("ord");
-
-                if (!reader.isLastRead())
-                    return false;
-
-                reader.incrementState();
-
-            case 2:
-                typeId = reader.readInt("typeId");
-
-                if (!reader.isLastRead())
-                    return false;
-
-                reader.incrementState();
-
-        }
-
-        return reader.afterMessageRead(BinaryEnumObjectImpl.class);
-    }
-}

http://git-wip-us.apache.org/repos/asf/ignite/blob/1dbf20e0/modules/core/src/main/java/org/apache/ignite/internal/portable/BinaryFieldAccessor.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/portable/BinaryFieldAccessor.java b/modules/core/src/main/java/org/apache/ignite/internal/portable/BinaryFieldAccessor.java
deleted file mode 100644
index 7701fb5..0000000
--- a/modules/core/src/main/java/org/apache/ignite/internal/portable/BinaryFieldAccessor.java
+++ /dev/null
@@ -1,856 +0,0 @@
-/*
- * 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.portable;
-
-import org.apache.ignite.binary.BinaryObjectException;
-import org.apache.ignite.internal.util.GridUnsafe;
-import org.apache.ignite.internal.util.typedef.internal.U;
-import sun.misc.Unsafe;
-
-import java.lang.reflect.Field;
-import java.math.BigDecimal;
-import java.sql.Timestamp;
-import java.util.Collection;
-import java.util.Date;
-import java.util.Map;
-import java.util.UUID;
-
-/**
- * Field accessor to speedup access.
- */
-public abstract class BinaryFieldAccessor {
-    /** Field ID. */
-    protected final int id;
-
-    /** Mode. */
-    protected final BinaryWriteMode mode;
-
-    /**
-     * Create accessor for the field.
-     *
-     * @param field Field.
-     * @param id FIeld ID.
-     * @return Accessor.
-     */
-    public static BinaryFieldAccessor create(Field field, int id) {
-        BinaryWriteMode mode = PortableUtils.mode(field.getType());
-
-        switch (mode) {
-            case P_BYTE:
-                return new BytePrimitiveAccessor(field, id);
-
-            case P_BOOLEAN:
-                return new BooleanPrimitiveAccessor(field, id);
-
-            case P_SHORT:
-                return new ShortPrimitiveAccessor(field, id);
-
-            case P_CHAR:
-                return new CharPrimitiveAccessor(field, id);
-
-            case P_INT:
-                return new IntPrimitiveAccessor(field, id);
-
-            case P_LONG:
-                return new LongPrimitiveAccessor(field, id);
-
-            case P_FLOAT:
-                return new FloatPrimitiveAccessor(field, id);
-
-            case P_DOUBLE:
-                return new DoublePrimitiveAccessor(field, id);
-
-            case BYTE:
-            case BOOLEAN:
-            case SHORT:
-            case CHAR:
-            case INT:
-            case LONG:
-            case FLOAT:
-            case DOUBLE:
-            case DECIMAL:
-            case STRING:
-            case UUID:
-            case DATE:
-            case TIMESTAMP:
-            case BYTE_ARR:
-            case SHORT_ARR:
-            case INT_ARR:
-            case LONG_ARR:
-            case FLOAT_ARR:
-            case DOUBLE_ARR:
-            case CHAR_ARR:
-            case BOOLEAN_ARR:
-            case DECIMAL_ARR:
-            case STRING_ARR:
-            case UUID_ARR:
-            case DATE_ARR:
-            case TIMESTAMP_ARR:
-            case ENUM_ARR:
-            case OBJECT_ARR:
-            case PORTABLE_OBJ:
-            case PORTABLE:
-            case EXTERNALIZABLE:
-                return new DefaultFinalClassAccessor(field, id, mode, false);
-
-            default:
-                return new DefaultFinalClassAccessor(field, id, mode, !U.isFinal(field.getType()));
-        }
-    }
-
-    /**
-     * Protected constructor.
-     *
-     * @param id Field ID.
-     * @param mode Mode;
-     */
-    protected BinaryFieldAccessor(int id, BinaryWriteMode mode) {
-        assert id != 0;
-        assert mode != null;
-
-        this.id = id;
-        this.mode = mode;
-    }
-
-    /**
-     * Get mode.
-     *
-     * @return Mode.
-     */
-    public BinaryWriteMode mode() {
-        return mode;
-    }
-
-    /**
-     * Write field.
-     *
-     * @param obj Object.
-     * @param writer Writer.
-     * @throws BinaryObjectException If failed.
-     */
-    public abstract void write(Object obj, BinaryWriterExImpl writer) throws BinaryObjectException;
-
-    /**
-     * Read field.
-     *
-     * @param obj Object.
-     * @param reader Reader.
-     * @throws BinaryObjectException If failed.
-     */
-    public abstract void read(Object obj, BinaryReaderExImpl reader) throws BinaryObjectException;
-
-    /**
-     * Base primitive field accessor.
-     */
-    private static abstract class AbstractPrimitiveAccessor extends BinaryFieldAccessor {
-        /** Unsafe instance. */
-        protected static final Unsafe UNSAFE = GridUnsafe.unsafe();
-
-        /** Offset. */
-        protected final long offset;
-
-        /**
-         * Constructor.
-         *
-         * @param field Field.
-         * @param id Field ID.
-         * @param mode Mode.
-         */
-        protected AbstractPrimitiveAccessor(Field field, int id, BinaryWriteMode mode) {
-            super(id, mode);
-
-            assert field != null;
-
-            offset = UNSAFE.objectFieldOffset(field);
-        }
-    }
-
-    /**
-     * Byte field accessor.
-     */
-    private static class BytePrimitiveAccessor extends AbstractPrimitiveAccessor {
-        /**
-         * Constructor.
-         *
-         * @param field Field.
-         */
-        public BytePrimitiveAccessor(Field field, int id) {
-            super(field, id, BinaryWriteMode.P_BYTE);
-        }
-
-        /** {@inheritDoc} */
-        @Override public void write(Object obj, BinaryWriterExImpl writer) throws BinaryObjectException {
-            writer.writeFieldIdNoSchemaUpdate(id);
-
-            byte val = UNSAFE.getByte(obj, offset);
-
-            writer.writeByteFieldPrimitive(val);
-        }
-
-        /** {@inheritDoc} */
-        @Override public void read(Object obj, BinaryReaderExImpl reader) throws BinaryObjectException {
-            byte val = reader.readByte(id);
-
-            UNSAFE.putByte(obj, offset, val);
-        }
-    }
-
-    /**
-     * Boolean field accessor.
-     */
-    private static class BooleanPrimitiveAccessor extends AbstractPrimitiveAccessor {
-        /**
-         * Constructor.
-         *
-         * @param field Field.
-         */
-        public BooleanPrimitiveAccessor(Field field, int id) {
-            super(field, id, BinaryWriteMode.P_BOOLEAN);
-        }
-
-        /** {@inheritDoc} */
-        @Override public void write(Object obj, BinaryWriterExImpl writer) throws BinaryObjectException {
-            writer.writeFieldIdNoSchemaUpdate(id);
-
-            boolean val = UNSAFE.getBoolean(obj, offset);
-
-            writer.writeBooleanFieldPrimitive(val);
-        }
-
-        /** {@inheritDoc} */
-        @Override public void read(Object obj, BinaryReaderExImpl reader) throws BinaryObjectException {
-            boolean val = reader.readBoolean(id);
-
-            UNSAFE.putBoolean(obj, offset, val);
-        }
-    }
-
-    /**
-     * Short field accessor.
-     */
-    private static class ShortPrimitiveAccessor extends AbstractPrimitiveAccessor {
-        /**
-         * Constructor.
-         *
-         * @param field Field.
-         */
-        public ShortPrimitiveAccessor(Field field, int id) {
-            super(field, id, BinaryWriteMode.P_SHORT);
-        }
-
-        /** {@inheritDoc} */
-        @Override public void write(Object obj, BinaryWriterExImpl writer) throws BinaryObjectException {
-            writer.writeFieldIdNoSchemaUpdate(id);
-
-            short val = UNSAFE.getShort(obj, offset);
-
-            writer.writeShortFieldPrimitive(val);
-        }
-
-        /** {@inheritDoc} */
-        @Override public void read(Object obj, BinaryReaderExImpl reader) throws BinaryObjectException {
-            short val = reader.readShort(id);
-
-            UNSAFE.putShort(obj, offset, val);
-        }
-    }
-
-    /**
-     * Char field accessor.
-     */
-    private static class CharPrimitiveAccessor extends AbstractPrimitiveAccessor {
-        /**
-         * Constructor.
-         *
-         * @param field Field.
-         */
-        public CharPrimitiveAccessor(Field field, int id) {
-            super(field, id, BinaryWriteMode.P_CHAR);
-        }
-
-        /** {@inheritDoc} */
-        @Override public void write(Object obj, BinaryWriterExImpl writer) throws BinaryObjectException {
-            writer.writeFieldIdNoSchemaUpdate(id);
-
-            char val = UNSAFE.getChar(obj, offset);
-
-            writer.writeCharFieldPrimitive(val);
-        }
-
-        /** {@inheritDoc} */
-        @Override public void read(Object obj, BinaryReaderExImpl reader) throws BinaryObjectException {
-            char val = reader.readChar(id);
-
-            UNSAFE.putChar(obj, offset, val);
-        }
-    }
-
-    /**
-     * Int field accessor.
-     */
-    private static class IntPrimitiveAccessor extends AbstractPrimitiveAccessor {
-        /**
-         * Constructor.
-         *
-         * @param field Field.
-         */
-        public IntPrimitiveAccessor(Field field, int id) {
-            super(field, id, BinaryWriteMode.P_INT);
-        }
-
-        /** {@inheritDoc} */
-        @Override public void write(Object obj, BinaryWriterExImpl writer) throws BinaryObjectException {
-            writer.writeFieldIdNoSchemaUpdate(id);
-
-            int val = UNSAFE.getInt(obj, offset);
-
-            writer.writeIntFieldPrimitive(val);
-        }
-
-        /** {@inheritDoc} */
-        @Override public void read(Object obj, BinaryReaderExImpl reader) throws BinaryObjectException {
-            int val = reader.readInt(id);
-
-            UNSAFE.putInt(obj, offset, val);
-        }
-    }
-
-    /**
-     * Long field accessor.
-     */
-    private static class LongPrimitiveAccessor extends AbstractPrimitiveAccessor {
-        /**
-         * Constructor.
-         *
-         * @param field Field.
-         */
-        public LongPrimitiveAccessor(Field field, int id) {
-            super(field, id, BinaryWriteMode.P_LONG);
-        }
-
-        /** {@inheritDoc} */
-        @Override public void write(Object obj, BinaryWriterExImpl writer) throws BinaryObjectException {
-            writer.writeFieldIdNoSchemaUpdate(id);
-
-            long val = UNSAFE.getLong(obj, offset);
-
-            writer.writeLongFieldPrimitive(val);
-        }
-
-        /** {@inheritDoc} */
-        @Override public void read(Object obj, BinaryReaderExImpl reader) throws BinaryObjectException {
-            long val = reader.readLong(id);
-
-            UNSAFE.putLong(obj, offset, val);
-        }
-    }
-
-    /**
-     * Float field accessor.
-     */
-    private static class FloatPrimitiveAccessor extends AbstractPrimitiveAccessor {
-        /**
-         * Constructor.
-         *
-         * @param field Field.
-         */
-        public FloatPrimitiveAccessor(Field field, int id) {
-            super(field, id, BinaryWriteMode.P_FLOAT);
-        }
-
-        /** {@inheritDoc} */
-        @Override public void write(Object obj, BinaryWriterExImpl writer) throws BinaryObjectException {
-            writer.writeFieldIdNoSchemaUpdate(id);
-
-            float val = UNSAFE.getFloat(obj, offset);
-
-            writer.writeFloatFieldPrimitive(val);
-        }
-
-        /** {@inheritDoc} */
-        @Override public void read(Object obj, BinaryReaderExImpl reader) throws BinaryObjectException {
-            float val = reader.readFloat(id);
-
-            UNSAFE.putFloat(obj, offset, val);
-        }
-    }
-
-    /**
-     * Double field accessor.
-     */
-    private static class DoublePrimitiveAccessor extends AbstractPrimitiveAccessor {
-        /**
-         * Constructor.
-         *
-         * @param field Field.
-         */
-        public DoublePrimitiveAccessor(Field field, int id) {
-            super(field, id, BinaryWriteMode.P_DOUBLE);
-        }
-
-        /** {@inheritDoc} */
-        @Override public void write(Object obj, BinaryWriterExImpl writer) throws BinaryObjectException {
-            writer.writeFieldIdNoSchemaUpdate(id);
-
-            double val = UNSAFE.getDouble(obj, offset);
-
-            writer.writeDoubleFieldPrimitive(val);
-        }
-
-        /** {@inheritDoc} */
-        @Override public void read(Object obj, BinaryReaderExImpl reader) throws BinaryObjectException {
-            double val = reader.readDouble(id);
-
-            UNSAFE.putDouble(obj, offset, val);
-        }
-    }
-
-    /**
-     * Default accessor.
-     */
-    private static class DefaultFinalClassAccessor extends BinaryFieldAccessor {
-        /** Target field. */
-        private final Field field;
-
-        /** Dynamic accessor flag. */
-        private final boolean dynamic;
-
-        /**
-         * Constructor.
-         *
-         * @param field Field.
-         * @param id Field ID.
-         * @param mode Mode.
-         */
-        DefaultFinalClassAccessor(Field field, int id, BinaryWriteMode mode, boolean dynamic) {
-            super(id, mode);
-
-            assert field != null;
-
-            this.field = field;
-            this.dynamic = dynamic;
-        }
-
-        /** {@inheritDoc} */
-        @Override public void write(Object obj, BinaryWriterExImpl writer) throws BinaryObjectException {
-            assert obj != null;
-            assert writer != null;
-
-            writer.writeFieldIdNoSchemaUpdate(id);
-
-            Object val;
-
-            try {
-                val = field.get(obj);
-            }
-            catch (IllegalAccessException e) {
-                throw new BinaryObjectException("Failed to get value for field: " + field, e);
-            }
-
-            switch (mode(val)) {
-                case BYTE:
-                    writer.writeByteField((Byte) val);
-
-                    break;
-
-                case SHORT:
-                    writer.writeShortField((Short) val);
-
-                    break;
-
-                case INT:
-                    writer.writeIntField((Integer) val);
-
-                    break;
-
-                case LONG:
-                    writer.writeLongField((Long)val);
-
-                    break;
-
-                case FLOAT:
-                    writer.writeFloatField((Float)val);
-
-                    break;
-
-                case DOUBLE:
-                    writer.writeDoubleField((Double)val);
-
-                    break;
-
-                case CHAR:
-                    writer.writeCharField((Character)val);
-
-                    break;
-
-                case BOOLEAN:
-                    writer.writeBooleanField((Boolean)val);
-
-                    break;
-
-                case DECIMAL:
-                    writer.writeDecimalField((BigDecimal)val);
-
-                    break;
-
-                case STRING:
-                    writer.writeStringField((String)val);
-
-                    break;
-
-                case UUID:
-                    writer.writeUuidField((UUID)val);
-
-                    break;
-
-                case DATE:
-                    writer.writeDateField((Date)val);
-
-                    break;
-
-                case TIMESTAMP:
-                    writer.writeTimestampField((Timestamp)val);
-
-                    break;
-
-                case BYTE_ARR:
-                    writer.writeByteArrayField((byte[])val);
-
-                    break;
-
-                case SHORT_ARR:
-                    writer.writeShortArrayField((short[])val);
-
-                    break;
-
-                case INT_ARR:
-                    writer.writeIntArrayField((int[])val);
-
-                    break;
-
-                case LONG_ARR:
-                    writer.writeLongArrayField((long[])val);
-
-                    break;
-
-                case FLOAT_ARR:
-                    writer.writeFloatArrayField((float[])val);
-
-                    break;
-
-                case DOUBLE_ARR:
-                    writer.writeDoubleArrayField((double[])val);
-
-                    break;
-
-                case CHAR_ARR:
-                    writer.writeCharArrayField((char[])val);
-
-                    break;
-
-                case BOOLEAN_ARR:
-                    writer.writeBooleanArrayField((boolean[])val);
-
-                    break;
-
-                case DECIMAL_ARR:
-                    writer.writeDecimalArrayField((BigDecimal[])val);
-
-                    break;
-
-                case STRING_ARR:
-                    writer.writeStringArrayField((String[])val);
-
-                    break;
-
-                case UUID_ARR:
-                    writer.writeUuidArrayField((UUID[])val);
-
-                    break;
-
-                case DATE_ARR:
-                    writer.writeDateArrayField((Date[])val);
-
-                    break;
-
-                case TIMESTAMP_ARR:
-                    writer.writeTimestampArrayField((Timestamp[])val);
-
-                    break;
-
-                case OBJECT_ARR:
-                    writer.writeObjectArrayField((Object[])val);
-
-                    break;
-
-                case COL:
-                    writer.writeCollectionField((Collection<?>)val);
-
-                    break;
-
-                case MAP:
-                    writer.writeMapField((Map<?, ?>)val);
-
-                    break;
-
-                case PORTABLE_OBJ:
-                    writer.writePortableObjectField((BinaryObjectImpl)val);
-
-                    break;
-
-                case ENUM:
-                    writer.writeEnumField((Enum<?>)val);
-
-                    break;
-
-                case ENUM_ARR:
-                    writer.writeEnumArrayField((Object[])val);
-
-                    break;
-
-                case PORTABLE:
-                case EXTERNALIZABLE:
-                case OBJECT:
-                    writer.writeObjectField(val);
-
-                    break;
-
-                case CLASS:
-                    writer.writeClassField((Class)val);
-
-                    break;
-
-                default:
-                    assert false : "Invalid mode: " + mode;
-            }
-        }
-
-        /** {@inheritDoc} */
-        @Override public void read(Object obj, BinaryReaderExImpl reader) throws BinaryObjectException {
-            Object val = dynamic ? reader.readField(id) : readFixedType(reader);
-
-            try {
-                if (val != null || !field.getType().isPrimitive())
-                    field.set(obj, val);
-            }
-            catch (IllegalAccessException e) {
-                throw new BinaryObjectException("Failed to set value for field: " + field, e);
-            }
-        }
-
-        /**
-         * Reads fixed type from the given reader with flags validation.
-         *
-         * @param reader Reader to read from.
-         * @return Read value.
-         * @throws BinaryObjectException If failed to read value from the stream.
-         */
-        protected Object readFixedType(BinaryReaderExImpl reader) throws BinaryObjectException {
-            Object val = null;
-
-            switch (mode) {
-                case BYTE:
-                    val = reader.readByteNullable(id);
-
-                    break;
-
-                case SHORT:
-                    val = reader.readShortNullable(id);
-
-                    break;
-
-                case INT:
-                    val = reader.readIntNullable(id);
-
-                    break;
-
-                case LONG:
-                    val = reader.readLongNullable(id);
-
-                    break;
-
-                case FLOAT:
-                    val = reader.readFloatNullable(id);
-
-                    break;
-
-                case DOUBLE:
-                    val = reader.readDoubleNullable(id);
-
-                    break;
-
-                case CHAR:
-                    val = reader.readCharNullable(id);
-
-                    break;
-
-                case BOOLEAN:
-                    val = reader.readBooleanNullable(id);
-
-                    break;
-
-                case DECIMAL:
-                    val = reader.readDecimal(id);
-
-                    break;
-
-                case STRING:
-                    val = reader.readString(id);
-
-                    break;
-
-                case UUID:
-                    val = reader.readUuid(id);
-
-                    break;
-
-                case DATE:
-                    val = reader.readDate(id);
-
-                    break;
-
-                case TIMESTAMP:
-                    val = reader.readTimestamp(id);
-
-                    break;
-
-                case BYTE_ARR:
-                    val = reader.readByteArray(id);
-
-                    break;
-
-                case SHORT_ARR:
-                    val = reader.readShortArray(id);
-
-                    break;
-
-                case INT_ARR:
-                    val = reader.readIntArray(id);
-
-                    break;
-
-                case LONG_ARR:
-                    val = reader.readLongArray(id);
-
-                    break;
-
-                case FLOAT_ARR:
-                    val = reader.readFloatArray(id);
-
-                    break;
-
-                case DOUBLE_ARR:
-                    val = reader.readDoubleArray(id);
-
-                    break;
-
-                case CHAR_ARR:
-                    val = reader.readCharArray(id);
-
-                    break;
-
-                case BOOLEAN_ARR:
-                    val = reader.readBooleanArray(id);
-
-                    break;
-
-                case DECIMAL_ARR:
-                    val = reader.readDecimalArray(id);
-
-                    break;
-
-                case STRING_ARR:
-                    val = reader.readStringArray(id);
-
-                    break;
-
-                case UUID_ARR:
-                    val = reader.readUuidArray(id);
-
-                    break;
-
-                case DATE_ARR:
-                    val = reader.readDateArray(id);
-
-                    break;
-
-                case TIMESTAMP_ARR:
-                    val = reader.readTimestampArray(id);
-
-                    break;
-
-                case OBJECT_ARR:
-                    val = reader.readObjectArray(id);
-
-                    break;
-
-                case COL:
-                    val = reader.readCollection(id, null);
-
-                    break;
-
-                case MAP:
-                    val = reader.readMap(id, null);
-
-                    break;
-
-                case PORTABLE_OBJ:
-                    val = reader.readPortableObject(id);
-
-                    break;
-
-                case ENUM:
-                    val = reader.readEnum(id, field.getType());
-
-                    break;
-
-                case ENUM_ARR:
-                    val = reader.readEnumArray(id, field.getType().getComponentType());
-
-                    break;
-
-                case PORTABLE:
-                case EXTERNALIZABLE:
-                case OBJECT:
-                    val = reader.readObject(id);
-
-                    break;
-
-                case CLASS:
-                    val = reader.readClass(id);
-
-                    break;
-
-                default:
-                    assert false : "Invalid mode: " + mode;
-            }
-
-            return val;
-        }
-
-        /**
-         * @param val Val to get write mode for.
-         * @return Write mode.
-         */
-        protected BinaryWriteMode mode(Object val) {
-            return dynamic ?
-                val == null ? BinaryWriteMode.OBJECT : PortableUtils.mode(val.getClass()) :
-                mode;
-        }
-    }
-}

http://git-wip-us.apache.org/repos/asf/ignite/blob/1dbf20e0/modules/core/src/main/java/org/apache/ignite/internal/portable/BinaryFieldImpl.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/portable/BinaryFieldImpl.java b/modules/core/src/main/java/org/apache/ignite/internal/portable/BinaryFieldImpl.java
deleted file mode 100644
index b471fbe..0000000
--- a/modules/core/src/main/java/org/apache/ignite/internal/portable/BinaryFieldImpl.java
+++ /dev/null
@@ -1,116 +0,0 @@
-/*
- * 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.portable;
-
-import org.apache.ignite.binary.BinaryObjectException;
-import org.apache.ignite.internal.util.tostring.GridToStringExclude;
-import org.apache.ignite.internal.util.typedef.internal.S;
-import org.apache.ignite.binary.BinaryObject;
-import org.apache.ignite.binary.BinaryField;
-
-/**
- * Implementation of portable field descriptor.
- */
-public class BinaryFieldImpl implements BinaryField {
-    /** Type ID. */
-    private final int typeId;
-
-    /** Well-known object schemas. */
-    @GridToStringExclude
-    private final PortableSchemaRegistry schemas;
-
-    /** Field name. */
-    private final String fieldName;
-
-    /** Pre-calculated field ID. */
-    private final int fieldId;
-
-    /**
-     * Constructor.
-     *
-     * @param schemas Schemas.
-     * @param fieldName Field name.
-     * @param fieldId Field ID.
-     */
-    public BinaryFieldImpl(int typeId, PortableSchemaRegistry schemas, String fieldName, int fieldId) {
-        assert typeId != 0;
-        assert schemas != null;
-        assert fieldName != null;
-        assert fieldId != 0;
-
-        this.typeId = typeId;
-        this.schemas = schemas;
-        this.fieldName = fieldName;
-        this.fieldId = fieldId;
-    }
-
-    /** {@inheritDoc} */
-    @Override public String name() {
-        return fieldName;
-    }
-
-    /** {@inheritDoc} */
-    @Override public boolean exists(BinaryObject obj) {
-        BinaryObjectExImpl obj0 = (BinaryObjectExImpl)obj;
-
-        return fieldOrder(obj0) != PortableSchema.ORDER_NOT_FOUND;
-    }
-
-    /** {@inheritDoc} */
-    @SuppressWarnings("unchecked")
-    @Override public <T> T value(BinaryObject obj) {
-        BinaryObjectExImpl obj0 = (BinaryObjectExImpl)obj;
-
-        int order = fieldOrder(obj0);
-
-        return order != PortableSchema.ORDER_NOT_FOUND ? (T)obj0.fieldByOrder(order) : null;
-    }
-
-    /**
-     * Get relative field offset.
-     *
-     * @param obj Object.
-     * @return Field offset.
-     */
-    private int fieldOrder(BinaryObjectExImpl obj) {
-        if (typeId != obj.typeId()) {
-            throw new BinaryObjectException("Failed to get field because type ID of passed object differs" +
-                " from type ID this " + BinaryField.class.getSimpleName() + " belongs to [expected=" + typeId +
-                ", actual=" + obj.typeId() + ']');
-        }
-
-        int schemaId = obj.schemaId();
-
-        PortableSchema schema = schemas.schema(schemaId);
-
-        if (schema == null) {
-            schema = obj.createSchema();
-
-            schemas.addSchema(schemaId, schema);
-        }
-
-        assert schema != null;
-
-        return schema.order(fieldId);
-    }
-
-    /** {@inheritDoc} */
-    @Override public String toString() {
-        return S.toString(BinaryFieldImpl.class, this);
-    }
-}

http://git-wip-us.apache.org/repos/asf/ignite/blob/1dbf20e0/modules/core/src/main/java/org/apache/ignite/internal/portable/BinaryInternalIdMapper.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/portable/BinaryInternalIdMapper.java b/modules/core/src/main/java/org/apache/ignite/internal/portable/BinaryInternalIdMapper.java
deleted file mode 100644
index 2b5a53a..0000000
--- a/modules/core/src/main/java/org/apache/ignite/internal/portable/BinaryInternalIdMapper.java
+++ /dev/null
@@ -1,161 +0,0 @@
-/*
- * 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.portable;
-
-import org.apache.ignite.binary.BinaryIdMapper;
-import org.apache.ignite.binary.BinaryObjectException;
-import org.jetbrains.annotations.Nullable;
-
-/**
- * Internal ID mapper. Mimics ID mapper interface, but provides default implementation and offers slightly better
- * performance on micro-level in default case because it doesn't need virtual calls.
- */
-public class BinaryInternalIdMapper implements BinaryIdMapper {
-    /** Maximum lower-case character. */
-    private static final char MAX_LOWER_CASE_CHAR = 0x7e;
-
-    /** Cached lower-case characters. */
-    private static final char[] LOWER_CASE_CHARS;
-
-    /** Default implementation. */
-    private static final BinaryInternalIdMapper DFLT = new BinaryInternalIdMapper();
-
-    /**
-     * Static initializer.
-     */
-    static {
-        LOWER_CASE_CHARS = new char[MAX_LOWER_CASE_CHAR + 1];
-
-        for (char c = 0; c <= MAX_LOWER_CASE_CHAR; c++)
-            LOWER_CASE_CHARS[c] = Character.toLowerCase(c);
-    }
-
-    /**
-     * Get default instance.
-     *
-     * @return Default instance.
-     */
-    public static BinaryInternalIdMapper defaultInstance() {
-        return DFLT;
-    }
-
-    /**
-     * Create internal mapper.
-     *
-     * @param mapper Public mapper.
-     * @return Internal mapper.
-     */
-    public static BinaryInternalIdMapper create(@Nullable BinaryIdMapper mapper) {
-        return mapper == null ? DFLT : new Wrapper(mapper);
-    }
-
-    /**
-     * Private constructor.
-     */
-    protected BinaryInternalIdMapper() {
-        // No-op.
-    }
-
-    /**
-     * Get type ID.
-     *
-     * @param typeName Type name.
-     * @return Type ID.
-     */
-    public int typeId(String typeName) {
-        assert typeName != null;
-
-        return lowerCaseHashCode(typeName, true);
-    }
-
-    /**
-     * Get field ID.
-     *
-     * @param typeId Type ID.
-     * @param fieldName Field name.
-     * @return Field ID.
-     */
-    public int fieldId(int typeId, String fieldName) {
-        assert fieldName != null;
-
-        return lowerCaseHashCode(fieldName, false);
-    }
-
-    /**
-     * Routine to calculate string hash code an
-     *
-     * @param str String.
-     * @param type {@code True} if this is type name, false otherwise.
-     * @return Hash code for given string converted to lower case.
-     */
-    private static int lowerCaseHashCode(String str, boolean type) {
-        int len = str.length();
-
-        int h = 0;
-
-        for (int i = 0; i < len; i++) {
-            int c = str.charAt(i);
-
-            c = c <= MAX_LOWER_CASE_CHAR ? LOWER_CASE_CHARS[c] : Character.toLowerCase(c);
-
-            h = 31 * h + c;
-        }
-
-        if (h != 0)
-            return h;
-        else {
-            String what = type ? "type" : "field";
-
-            throw new BinaryObjectException("Default binary ID mapper resolved " + what + " ID to zero " +
-                "(either change " + what + "'s name or use custom ID mapper) [name=" + str + ']');
-        }
-    }
-
-    /**
-     * Wrapping ID mapper.
-     */
-    private static class Wrapper extends BinaryInternalIdMapper {
-        /** Delegate. */
-        private final BinaryIdMapper mapper;
-
-        /**
-         * Constructor.
-         *
-         * @param mapper Delegate.
-         */
-        private Wrapper(BinaryIdMapper mapper) {
-            assert mapper != null;
-
-            this.mapper = mapper;
-        }
-
-        /** {@inheritDoc} */
-        @Override public int typeId(String typeName) {
-            int id = mapper.typeId(typeName);
-
-            return id != 0 ? id : super.typeId(typeName);
-        }
-
-        /** {@inheritDoc} */
-        @Override public int fieldId(int typeId, String fieldName) {
-            int id = mapper.fieldId(typeId, fieldName);
-
-            return id != 0 ? id : super.fieldId(typeId, fieldName);
-        }
-    }
-}

http://git-wip-us.apache.org/repos/asf/ignite/blob/1dbf20e0/modules/core/src/main/java/org/apache/ignite/internal/portable/BinaryMarshaller.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/portable/BinaryMarshaller.java b/modules/core/src/main/java/org/apache/ignite/internal/portable/BinaryMarshaller.java
deleted file mode 100644
index bfaae74..0000000
--- a/modules/core/src/main/java/org/apache/ignite/internal/portable/BinaryMarshaller.java
+++ /dev/null
@@ -1,142 +0,0 @@
-/*
- * 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.portable;
-
-import java.io.ByteArrayOutputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.OutputStream;
-import org.apache.ignite.IgniteCheckedException;
-import org.apache.ignite.binary.BinaryObjectException;
-import org.apache.ignite.configuration.IgniteConfiguration;
-import org.apache.ignite.internal.util.GridUnsafe;
-import org.apache.ignite.marshaller.AbstractMarshaller;
-import org.apache.ignite.marshaller.MarshallerContext;
-import org.jetbrains.annotations.Nullable;
-import sun.misc.Unsafe;
-
-/**
- * Implementation of {@link org.apache.ignite.marshaller.Marshaller} that lets to serialize and deserialize all objects
- * in the binary format.
- */
-public class BinaryMarshaller extends AbstractMarshaller {
-    /** */
-    private GridPortableMarshaller impl;
-
-    /**
-     * Checks whether {@code BinaryMarshaller} is able to work on the current JVM.
-     * <p>
-     * As long as {@code BinaryMarshaller} uses JVM-private API, which is not guaranteed
-     * to be available on all JVM, this method should be called to ensure marshaller could work properly.
-     * <p>
-     * Result of this method is automatically checked in constructor.
-     *
-     * @return {@code true} if {@code BinaryMarshaller} can work on the current JVM or
-     *      {@code false} if it can't.
-     */
-    @SuppressWarnings({"TypeParameterExtendsFinalClass", "ErrorNotRethrown"})
-    public static boolean available() {
-        try {
-            Unsafe unsafe = GridUnsafe.unsafe();
-
-            Class<? extends Unsafe> unsafeCls = unsafe.getClass();
-
-            unsafeCls.getMethod("allocateInstance", Class.class);
-            unsafeCls.getMethod("copyMemory", Object.class, long.class, Object.class, long.class, long.class);
-
-            return true;
-        }
-        catch (Exception ignored) {
-            return false;
-        }
-        catch (NoClassDefFoundError ignored) {
-            return false;
-        }
-    }
-
-    /**
-     * Returns currently set {@link MarshallerContext}.
-     *
-     * @return Marshaller context.
-     */
-    public MarshallerContext getContext() {
-        return ctx;
-    }
-
-    /**
-     * Sets {@link PortableContext}.
-     * <p/>
-     * @param ctx Portable context.
-     */
-    @SuppressWarnings("UnusedDeclaration")
-    private void setPortableContext(PortableContext ctx, IgniteConfiguration cfg) {
-        ctx.configure(this, cfg);
-
-        impl = new GridPortableMarshaller(ctx);
-    }
-
-    /** {@inheritDoc} */
-    @Override public byte[] marshal(@Nullable Object obj) throws IgniteCheckedException {
-        return impl.marshal(obj);
-    }
-
-    /** {@inheritDoc} */
-    @Override public void marshal(@Nullable Object obj, OutputStream out) throws IgniteCheckedException {
-        byte[] arr = marshal(obj);
-
-        try {
-            out.write(arr);
-        }
-        catch (IOException e) {
-            throw new BinaryObjectException("Failed to marshal the object: " + obj, e);
-        }
-    }
-
-    /** {@inheritDoc} */
-    @Override public <T> T unmarshal(byte[] bytes, @Nullable ClassLoader clsLdr) throws IgniteCheckedException {
-        return impl.deserialize(bytes, clsLdr);
-    }
-
-    /** {@inheritDoc} */
-    @Override public <T> T unmarshal(InputStream in, @Nullable ClassLoader clsLdr) throws IgniteCheckedException {
-        ByteArrayOutputStream buf = new ByteArrayOutputStream();
-
-        // we have to fully read the InputStream because GridPortableMarshaller requires support of a method that
-        // returns number of bytes remaining.
-        try {
-            byte[] arr = new byte[4096];
-
-            int cnt;
-
-            while ((cnt = in.read(arr)) != -1)
-                buf.write(arr, 0, cnt);
-
-            buf.flush();
-
-            return impl.deserialize(buf.toByteArray(), clsLdr);
-        }
-        catch (IOException e) {
-            throw new BinaryObjectException("Failed to unmarshal the object from InputStream", e);
-        }
-    }
-
-    /** {@inheritDoc} */
-    @Override public void onUndeploy(ClassLoader ldr) {
-        impl.context().onUndeploy(ldr);
-    }
-}

http://git-wip-us.apache.org/repos/asf/ignite/blob/1dbf20e0/modules/core/src/main/java/org/apache/ignite/internal/portable/BinaryMetadata.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/portable/BinaryMetadata.java b/modules/core/src/main/java/org/apache/ignite/internal/portable/BinaryMetadata.java
deleted file mode 100644
index 8ba2e23..0000000
--- a/modules/core/src/main/java/org/apache/ignite/internal/portable/BinaryMetadata.java
+++ /dev/null
@@ -1,180 +0,0 @@
-/*
- * 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.portable;
-
-import java.io.Externalizable;
-import java.io.IOException;
-import java.io.ObjectInput;
-import java.io.ObjectOutput;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.Map;
-import org.apache.ignite.internal.util.tostring.GridToStringInclude;
-import org.apache.ignite.internal.util.typedef.internal.S;
-import org.apache.ignite.internal.util.typedef.internal.U;
-import org.jetbrains.annotations.Nullable;
-
-/**
- * Portable metadata which is passed over a wire.
- */
-public class BinaryMetadata implements Externalizable {
-    /** */
-    private static final long serialVersionUID = 0L;
-
-    /** Type ID. */
-    private int typeId;
-
-    /** Type name. */
-    private String typeName;
-
-    /** Recorded object fields. */
-    @GridToStringInclude
-    private Map<String, Integer> fields;
-
-    /** Affinity key field name. */
-    private String affKeyFieldName;
-
-    /** Schemas associated with type. */
-    private Collection<PortableSchema> schemas;
-
-    /** Whether this is enum type. */
-    private boolean isEnum;
-
-    /**
-     * For {@link Externalizable}.
-     */
-    public BinaryMetadata() {
-        // No-op.
-    }
-
-    /**
-     * Constructor.
-     *
-     * @param typeId Type ID.
-     * @param typeName Type name.
-     * @param fields Fields map.
-     * @param affKeyFieldName Affinity key field name.
-     * @param schemas Schemas.
-     * @param isEnum Enum flag.
-     */
-    public BinaryMetadata(int typeId, String typeName, @Nullable Map<String, Integer> fields,
-        @Nullable String affKeyFieldName, @Nullable Collection<PortableSchema> schemas, boolean isEnum) {
-        assert typeName != null;
-
-        this.typeId = typeId;
-        this.typeName = typeName;
-        this.fields = fields;
-        this.affKeyFieldName = affKeyFieldName;
-        this.schemas = schemas;
-        this.isEnum = isEnum;
-    }
-
-    /**
-     * @return Type ID.
-     */
-    public int typeId() {
-        return typeId;
-    }
-
-    /**
-     * @return Type name.
-     */
-    public String typeName() {
-        return typeName;
-    }
-
-    /**
-     * @return Fields.
-     */
-    public Collection<String> fields() {
-        return fields != null ? fields.keySet() : Collections.<String>emptyList();
-    }
-
-    /**
-     * @return Fields.
-     */
-    public Map<String, Integer> fieldsMap() {
-        return fields != null ? fields : Collections.<String, Integer>emptyMap();
-    }
-
-    /**
-     * @param fieldName Field name.
-     * @return Field type name.
-     */
-    @Nullable public String fieldTypeName(String fieldName) {
-        Integer typeId = fields != null ? fields.get(fieldName) : null;
-
-        return typeId != null ? PortableUtils.fieldTypeName(typeId) : null;
-    }
-
-    /**
-     * @return Affinity key field name.
-     */
-    @Nullable public String affinityKeyFieldName() {
-        return affKeyFieldName;
-    }
-
-    /**
-     * @return Schemas.
-     */
-    public Collection<PortableSchema> schemas() {
-        return schemas != null ? schemas : Collections.<PortableSchema>emptyList();
-    }
-
-    /**
-     * @return {@code True} if this is enum type.
-     */
-    public boolean isEnum() {
-        return isEnum;
-    }
-
-    /**
-     * Wrap metadata into binary type.
-     *
-     * @param ctx Portable context.
-     * @return Binary type.
-     */
-    public BinaryTypeImpl wrap(PortableContext ctx) {
-        return new BinaryTypeImpl(ctx, this);
-    }
-
-    /** {@inheritDoc} */
-    @Override public void writeExternal(ObjectOutput out) throws IOException {
-        out.writeInt(typeId);
-        U.writeString(out, typeName);
-        U.writeMap(out, fields);
-        U.writeString(out, affKeyFieldName);
-        U.writeCollection(out, schemas);
-        out.writeBoolean(isEnum);
-    }
-
-    /** {@inheritDoc} */
-    @Override public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
-        typeId = in.readInt();
-        typeName = U.readString(in);
-        fields = U.readMap(in);
-        affKeyFieldName = U.readString(in);
-        schemas = U.readCollection(in);
-        isEnum = in.readBoolean();
-    }
-
-    /** {@inheritDoc} */
-    @Override public String toString() {
-        return S.toString(BinaryMetadata.class, this);
-    }
-}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ignite/blob/1dbf20e0/modules/core/src/main/java/org/apache/ignite/internal/portable/BinaryMetadataCollector.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/portable/BinaryMetadataCollector.java b/modules/core/src/main/java/org/apache/ignite/internal/portable/BinaryMetadataCollector.java
deleted file mode 100644
index 6ad0ad1..0000000
--- a/modules/core/src/main/java/org/apache/ignite/internal/portable/BinaryMetadataCollector.java
+++ /dev/null
@@ -1,277 +0,0 @@
-/*
- * 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.portable;
-
-import org.apache.ignite.binary.BinaryIdMapper;
-import org.apache.ignite.binary.BinaryObjectException;
-import org.apache.ignite.binary.BinaryRawWriter;
-import org.apache.ignite.binary.BinaryWriter;
-import org.jetbrains.annotations.Nullable;
-
-import java.lang.reflect.InvocationHandler;
-import java.lang.reflect.Method;
-import java.lang.reflect.Proxy;
-import java.math.BigDecimal;
-import java.sql.Timestamp;
-import java.util.Collection;
-import java.util.Date;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.UUID;
-
-/**
- * Writer for meta data collection.
- */
-class BinaryMetadataCollector implements BinaryWriter {
-    /** Type ID. */
-    private final int typeId;
-
-    /** Type name. */
-    private final String typeName;
-
-    /** ID mapper. */
-    private final BinaryIdMapper idMapper;
-
-    /** Collected metadata. */
-    private final Map<String, Integer> meta = new HashMap<>();
-
-    /** Schema builder. */
-    private PortableSchema.Builder schemaBuilder = PortableSchema.Builder.newBuilder();
-
-    /**
-     * Constructor.
-     *
-     * @param typeId Type ID.
-     * @param typeName Type name.
-     * @param idMapper ID mapper.
-     */
-    BinaryMetadataCollector(int typeId, String typeName, BinaryIdMapper idMapper) {
-        this.typeId = typeId;
-        this.typeName = typeName;
-        this.idMapper = idMapper;
-    }
-
-    /**
-     * @return Field meta data.
-     */
-    Map<String, Integer> meta() {
-        return meta;
-    }
-
-    /**
-     * @return Schemas.
-     */
-    PortableSchema schema() {
-        return schemaBuilder.build();
-    }
-
-    /** {@inheritDoc} */
-    @Override public void writeByte(String fieldName, byte val) throws BinaryObjectException {
-        add(fieldName, BinaryWriteMode.BYTE);
-    }
-
-    /** {@inheritDoc} */
-    @Override public void writeShort(String fieldName, short val) throws BinaryObjectException {
-        add(fieldName, BinaryWriteMode.SHORT);
-    }
-
-    /** {@inheritDoc} */
-    @Override public void writeInt(String fieldName, int val) throws BinaryObjectException {
-        add(fieldName, BinaryWriteMode.INT);
-    }
-
-    /** {@inheritDoc} */
-    @Override public void writeLong(String fieldName, long val) throws BinaryObjectException {
-        add(fieldName, BinaryWriteMode.LONG);
-    }
-
-    /** {@inheritDoc} */
-    @Override public void writeFloat(String fieldName, float val) throws BinaryObjectException {
-        add(fieldName, BinaryWriteMode.FLOAT);
-    }
-
-    /** {@inheritDoc} */
-    @Override public void writeDouble(String fieldName, double val) throws BinaryObjectException {
-        add(fieldName, BinaryWriteMode.DOUBLE);
-    }
-
-    /** {@inheritDoc} */
-    @Override public void writeChar(String fieldName, char val) throws BinaryObjectException {
-        add(fieldName, BinaryWriteMode.CHAR);
-    }
-
-    /** {@inheritDoc} */
-    @Override public void writeBoolean(String fieldName, boolean val) throws BinaryObjectException {
-        add(fieldName, BinaryWriteMode.BOOLEAN);
-    }
-
-    /** {@inheritDoc} */
-    @Override public void writeDecimal(String fieldName, @Nullable BigDecimal val) throws BinaryObjectException {
-        add(fieldName, BinaryWriteMode.DECIMAL);
-    }
-
-    /** {@inheritDoc} */
-    @Override public void writeString(String fieldName, @Nullable String val) throws BinaryObjectException {
-        add(fieldName, BinaryWriteMode.STRING);
-    }
-
-    /** {@inheritDoc} */
-    @Override public void writeUuid(String fieldName, @Nullable UUID val) throws BinaryObjectException {
-        add(fieldName, BinaryWriteMode.UUID);
-    }
-
-    /** {@inheritDoc} */
-    @Override public void writeDate(String fieldName, @Nullable Date val) throws BinaryObjectException {
-        add(fieldName, BinaryWriteMode.DATE);
-    }
-
-    /** {@inheritDoc} */
-    @Override public void writeTimestamp(String fieldName, @Nullable Timestamp val) throws BinaryObjectException {
-        add(fieldName, BinaryWriteMode.TIMESTAMP);
-    }
-
-    /** {@inheritDoc} */
-    @Override public <T extends Enum<?>> void writeEnum(String fieldName, T val) throws BinaryObjectException {
-        add(fieldName, BinaryWriteMode.ENUM);
-    }
-
-    /** {@inheritDoc} */
-    @Override public <T extends Enum<?>> void writeEnumArray(String fieldName, T[] val) throws BinaryObjectException {
-        add(fieldName, BinaryWriteMode.ENUM_ARR);
-    }
-
-    /** {@inheritDoc} */
-    @Override public void writeObject(String fieldName, @Nullable Object obj) throws BinaryObjectException {
-        add(fieldName, BinaryWriteMode.OBJECT);
-    }
-
-    /** {@inheritDoc} */
-    @Override public void writeByteArray(String fieldName, @Nullable byte[] val) throws BinaryObjectException {
-        add(fieldName, BinaryWriteMode.BYTE_ARR);
-    }
-
-    /** {@inheritDoc} */
-    @Override public void writeShortArray(String fieldName, @Nullable short[] val) throws BinaryObjectException {
-        add(fieldName, BinaryWriteMode.SHORT_ARR);
-    }
-
-    /** {@inheritDoc} */
-    @Override public void writeIntArray(String fieldName, @Nullable int[] val) throws BinaryObjectException {
-        add(fieldName, BinaryWriteMode.INT_ARR);
-    }
-
-    /** {@inheritDoc} */
-    @Override public void writeLongArray(String fieldName, @Nullable long[] val) throws BinaryObjectException {
-        add(fieldName, BinaryWriteMode.LONG_ARR);
-    }
-
-    /** {@inheritDoc} */
-    @Override public void writeFloatArray(String fieldName, @Nullable float[] val) throws BinaryObjectException {
-        add(fieldName, BinaryWriteMode.FLOAT_ARR);
-    }
-
-    /** {@inheritDoc} */
-    @Override public void writeDoubleArray(String fieldName, @Nullable double[] val) throws BinaryObjectException {
-        add(fieldName, BinaryWriteMode.DOUBLE_ARR);
-    }
-
-    /** {@inheritDoc} */
-    @Override public void writeCharArray(String fieldName, @Nullable char[] val) throws BinaryObjectException {
-        add(fieldName, BinaryWriteMode.CHAR_ARR);
-    }
-
-    /** {@inheritDoc} */
-    @Override public void writeBooleanArray(String fieldName, @Nullable boolean[] val) throws BinaryObjectException {
-        add(fieldName, BinaryWriteMode.BOOLEAN_ARR);
-    }
-
-    /** {@inheritDoc} */
-    @Override public void writeDecimalArray(String fieldName, @Nullable BigDecimal[] val) throws BinaryObjectException {
-        add(fieldName, BinaryWriteMode.DECIMAL_ARR);
-    }
-
-    /** {@inheritDoc} */
-    @Override public void writeStringArray(String fieldName, @Nullable String[] val) throws BinaryObjectException {
-        add(fieldName, BinaryWriteMode.STRING_ARR);
-    }
-
-    /** {@inheritDoc} */
-    @Override public void writeUuidArray(String fieldName, @Nullable UUID[] val) throws BinaryObjectException {
-        add(fieldName, BinaryWriteMode.UUID_ARR);
-    }
-
-    /** {@inheritDoc} */
-    @Override public void writeDateArray(String fieldName, @Nullable Date[] val) throws BinaryObjectException {
-        add(fieldName, BinaryWriteMode.DATE_ARR);
-    }
-
-    /** {@inheritDoc} */
-    @Override public void writeTimestampArray(String fieldName, @Nullable Timestamp[] val) throws BinaryObjectException {
-        add(fieldName, BinaryWriteMode.TIMESTAMP_ARR);
-    }
-
-    /** {@inheritDoc} */
-    @Override public void writeObjectArray(String fieldName, @Nullable Object[] val) throws BinaryObjectException {
-        add(fieldName, BinaryWriteMode.OBJECT_ARR);
-    }
-
-    /** {@inheritDoc} */
-    @Override public <T> void writeCollection(String fieldName, @Nullable Collection<T> col)
-        throws BinaryObjectException {
-        add(fieldName, BinaryWriteMode.COL);
-    }
-
-    /** {@inheritDoc} */
-    @Override public <K, V> void writeMap(String fieldName, @Nullable Map<K, V> map) throws BinaryObjectException {
-        add(fieldName, BinaryWriteMode.MAP);
-    }
-
-    /** {@inheritDoc} */
-    @Override public BinaryRawWriter rawWriter() {
-        return (BinaryRawWriter)Proxy.newProxyInstance(getClass().getClassLoader(),
-            new Class<?>[] { BinaryRawWriterEx.class },
-            new InvocationHandler() {
-                @Override public Object invoke(Object proxy, Method mtd, Object[] args) throws Throwable {
-                    return null;
-                }
-            });
-    }
-
-    /**
-     * @param name Field name.
-     * @param mode Field mode.
-     * @throws BinaryObjectException In case of error.
-     */
-    private void add(String name, BinaryWriteMode mode) throws BinaryObjectException {
-        assert name != null;
-
-        int fieldTypeId = mode.typeId();
-
-        Integer oldFieldTypeId = meta.put(name, fieldTypeId);
-
-        if (oldFieldTypeId != null && !oldFieldTypeId.equals(fieldTypeId)) {
-            throw new BinaryObjectException(
-                "Field is written twice with different types [" + "typeName=" + typeName + ", fieldName=" + name +
-                ", fieldTypeName1=" + PortableUtils.fieldTypeName(oldFieldTypeId) +
-                ", fieldTypeName2=" + PortableUtils.fieldTypeName(fieldTypeId) + ']'
-            );
-        }
-
-        schemaBuilder.addField(idMapper.fieldId(typeId, name));
-    }
-}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ignite/blob/1dbf20e0/modules/core/src/main/java/org/apache/ignite/internal/portable/BinaryMetadataHandler.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/portable/BinaryMetadataHandler.java b/modules/core/src/main/java/org/apache/ignite/internal/portable/BinaryMetadataHandler.java
deleted file mode 100644
index add8c2d..0000000
--- a/modules/core/src/main/java/org/apache/ignite/internal/portable/BinaryMetadataHandler.java
+++ /dev/null
@@ -1,44 +0,0 @@
-/*
- * 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.portable;
-
-import org.apache.ignite.binary.BinaryObjectException;
-import org.apache.ignite.binary.BinaryType;
-
-/**
- * Portable meta data handler.
- */
-public interface BinaryMetadataHandler {
-    /**
-     * Adds meta data.
-     *
-     * @param typeId Type ID.
-     * @param meta Meta data.
-     * @throws org.apache.ignite.binary.BinaryObjectException In case of error.
-     */
-    public void addMeta(int typeId, BinaryType meta) throws BinaryObjectException;
-
-    /**
-     * Gets meta data for provided type ID.
-     *
-     * @param typeId Type ID.
-     * @return Meta data.
-     * @throws org.apache.ignite.binary.BinaryObjectException In case of error.
-     */
-    public BinaryType metadata(int typeId) throws BinaryObjectException;
-}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ignite/blob/1dbf20e0/modules/core/src/main/java/org/apache/ignite/internal/portable/BinaryNoopMetadataHandler.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/portable/BinaryNoopMetadataHandler.java b/modules/core/src/main/java/org/apache/ignite/internal/portable/BinaryNoopMetadataHandler.java
deleted file mode 100644
index c4fc5e3..0000000
--- a/modules/core/src/main/java/org/apache/ignite/internal/portable/BinaryNoopMetadataHandler.java
+++ /dev/null
@@ -1,53 +0,0 @@
-/*
- * 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.portable;
-
-import org.apache.ignite.binary.BinaryObjectException;
-import org.apache.ignite.binary.BinaryType;
-
-/**
- * No-op metadata handler.
- */
-public class BinaryNoopMetadataHandler implements BinaryMetadataHandler {
-    /** Cached singleton instance. */
-    private static final BinaryNoopMetadataHandler INSTANCE = new BinaryNoopMetadataHandler();
-
-    /**
-     * @return Instance.
-     */
-    public static BinaryNoopMetadataHandler instance() {
-        return INSTANCE;
-    }
-
-    /**
-     * Private constructor.
-     */
-    private BinaryNoopMetadataHandler() {
-        // No-op.
-    }
-
-    /** {@inheritDoc} */
-    @Override public void addMeta(int typeId, BinaryType meta) throws BinaryObjectException {
-        // No-op.
-    }
-
-    /** {@inheritDoc} */
-    @Override public BinaryType metadata(int typeId) throws BinaryObjectException {
-        return null;
-    }
-}

http://git-wip-us.apache.org/repos/asf/ignite/blob/1dbf20e0/modules/core/src/main/java/org/apache/ignite/internal/portable/BinaryObjectEx.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/portable/BinaryObjectEx.java b/modules/core/src/main/java/org/apache/ignite/internal/portable/BinaryObjectEx.java
deleted file mode 100644
index acc8e4b..0000000
--- a/modules/core/src/main/java/org/apache/ignite/internal/portable/BinaryObjectEx.java
+++ /dev/null
@@ -1,30 +0,0 @@
-/*
- * 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.portable;
-
-import org.apache.ignite.binary.BinaryObject;
-
-/**
- * Extended binary object interface.
- */
-public interface BinaryObjectEx extends BinaryObject {
-    /**
-     * @return Type ID.
-     */
-    public int typeId();
-}

http://git-wip-us.apache.org/repos/asf/ignite/blob/1dbf20e0/modules/core/src/main/java/org/apache/ignite/internal/portable/BinaryObjectExImpl.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/portable/BinaryObjectExImpl.java b/modules/core/src/main/java/org/apache/ignite/internal/portable/BinaryObjectExImpl.java
deleted file mode 100644
index a32329a..0000000
--- a/modules/core/src/main/java/org/apache/ignite/internal/portable/BinaryObjectExImpl.java
+++ /dev/null
@@ -1,251 +0,0 @@
-/*
- * 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.portable;
-
-import java.math.BigDecimal;
-import java.util.Arrays;
-import java.util.IdentityHashMap;
-import org.apache.ignite.IgniteException;
-import org.apache.ignite.internal.util.offheap.unsafe.GridUnsafeMemory;
-import org.apache.ignite.internal.util.typedef.internal.SB;
-import org.apache.ignite.binary.BinaryObjectException;
-import org.apache.ignite.binary.BinaryType;
-import org.apache.ignite.binary.BinaryObject;
-import org.jetbrains.annotations.Nullable;
-
-/**
- * Internal portable object interface.
- */
-public abstract class BinaryObjectExImpl implements BinaryObjectEx {
-    /**
-     * @return Length.
-     */
-    public abstract int length();
-
-    /**
-     * @return Object start.
-     */
-    public abstract int start();
-
-    /**
-     * @return {@code True} if object is array based.
-     */
-    protected abstract boolean hasArray();
-
-    /**
-     * @return Object array if object is array based, otherwise {@code null}.
-     */
-    public abstract byte[] array();
-
-    /**
-     * @return Object offheap address is object is offheap based, otherwise 0.
-     */
-    public abstract long offheapAddress();
-
-    /**
-     * Gets field value.
-     *
-     * @param fieldId Field ID.
-     * @return Field value.
-     * @throws org.apache.ignite.binary.BinaryObjectException In case of any other error.
-     */
-    @Nullable public abstract <F> F field(int fieldId) throws BinaryObjectException;
-
-    /** {@inheritDoc} */
-    @Override public int enumOrdinal() throws BinaryObjectException {
-        throw new BinaryObjectException("Object is not enum.");
-    }
-
-    /**
-     * Get field by offset.
-     *
-     * @param fieldOffset Field offset.
-     * @return Field value.
-     */
-    @Nullable protected abstract <F> F fieldByOrder(int fieldOffset);
-
-    /**
-     * @param ctx Reader context.
-     * @param fieldName Field name.
-     * @return Field value.
-     */
-    @Nullable protected abstract <F> F field(BinaryReaderHandles ctx, String fieldName);
-
-    /**
-     * Get schema ID.
-     *
-     * @return Schema ID.
-     */
-    protected abstract int schemaId();
-
-    /**
-     * Create schema for object.
-     *
-     * @return Schema.
-     */
-    protected abstract PortableSchema createSchema();
-
-    /** {@inheritDoc} */
-    @Override public BinaryObject clone() throws CloneNotSupportedException {
-        return (BinaryObject)super.clone();
-    }
-
-    /** {@inheritDoc} */
-    public boolean equals(Object other) {
-        if (other == this)
-            return true;
-
-        if (other == null)
-            return false;
-
-        if (!(other instanceof BinaryObjectExImpl))
-            return false;
-
-        BinaryObjectExImpl otherPo = (BinaryObjectExImpl)other;
-
-        if (length() != otherPo.length() || typeId() != otherPo.typeId())
-            return false;
-
-        if (hasArray()) {
-            if (otherPo.hasArray()) {
-                int len = length();
-                int end = start() + len;
-
-                byte[] arr = array();
-                byte[] otherArr = otherPo.array();
-
-                for (int i = start(), j = otherPo.start(); i < end; i++, j++) {
-                    if (arr[i] != otherArr[j])
-                        return false;
-                }
-
-                return true;
-            }
-            else {
-                assert otherPo.offheapAddress() > 0;
-
-                return GridUnsafeMemory.compare(otherPo.offheapAddress() + otherPo.start(), array());
-            }
-        }
-        else {
-            assert offheapAddress() > 0;
-
-            if (otherPo.hasArray())
-                return GridUnsafeMemory.compare(offheapAddress() + start(), otherPo.array());
-            else {
-                assert otherPo.offheapAddress() > 0;
-
-                return GridUnsafeMemory.compare(offheapAddress() + start(),
-                    otherPo.offheapAddress() + otherPo.start(),
-                    length());
-            }
-        }
-    }
-
-    /**
-     * @param ctx Reader context.
-     * @param handles Handles for already traversed objects.
-     * @return String representation.
-     */
-    private String toString(BinaryReaderHandles ctx, IdentityHashMap<BinaryObject, Integer> handles) {
-        int idHash = System.identityHashCode(this);
-        int hash = hashCode();
-
-        BinaryType meta;
-
-        try {
-            meta = type();
-        }
-        catch (BinaryObjectException ignore) {
-            meta = null;
-        }
-
-        if (meta == null)
-            return BinaryObject.class.getSimpleName() +  " [idHash=" + idHash + ", hash=" + hash + ", typeId=" + typeId() + ']';
-
-        handles.put(this, idHash);
-
-        SB buf = new SB(meta.typeName());
-
-        if (meta.fieldNames() != null) {
-            buf.a(" [idHash=").a(idHash).a(", hash=").a(hash);
-
-            for (String name : meta.fieldNames()) {
-                Object val = field(ctx, name);
-
-                buf.a(", ").a(name).a('=');
-
-                if (val instanceof byte[])
-                    buf.a(Arrays.toString((byte[]) val));
-                else if (val instanceof short[])
-                    buf.a(Arrays.toString((short[])val));
-                else if (val instanceof int[])
-                    buf.a(Arrays.toString((int[])val));
-                else if (val instanceof long[])
-                    buf.a(Arrays.toString((long[])val));
-                else if (val instanceof float[])
-                    buf.a(Arrays.toString((float[])val));
-                else if (val instanceof double[])
-                    buf.a(Arrays.toString((double[])val));
-                else if (val instanceof char[])
-                    buf.a(Arrays.toString((char[])val));
-                else if (val instanceof boolean[])
-                    buf.a(Arrays.toString((boolean[]) val));
-                else if (val instanceof BigDecimal[])
-                    buf.a(Arrays.toString((BigDecimal[])val));
-                else {
-                    if (val instanceof BinaryObjectExImpl) {
-                        BinaryObjectExImpl po = (BinaryObjectExImpl)val;
-
-                        Integer idHash0 = handles.get(val);
-
-                        if (idHash0 != null) {  // Circular reference.
-                            BinaryType meta0 = po.type();
-
-                            assert meta0 != null;
-
-                            buf.a(meta0.typeName()).a(" [hash=").a(idHash0).a(", ...]");
-                        }
-                        else
-                            buf.a(po.toString(ctx, handles));
-                    }
-                    else
-                        buf.a(val);
-                }
-            }
-
-            buf.a(']');
-        }
-
-        return buf.toString();
-    }
-
-    /** {@inheritDoc} */
-    @Override public String toString() {
-        try {
-            BinaryReaderHandles ctx = new BinaryReaderHandles();
-
-            ctx.put(start(), this);
-
-            return toString(ctx, new IdentityHashMap<BinaryObject, Integer>());
-        }
-        catch (BinaryObjectException e) {
-            throw new IgniteException("Failed to create string representation of portable object.", e);
-        }
-    }
-}
\ No newline at end of file


[41/59] [abbrv] ignite git commit: IGNITE-2082: Added docs generation for the CPP

Posted by ak...@apache.org.
IGNITE-2082: Added docs generation for the CPP


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

Branch: refs/heads/ignite-843-rc2
Commit: 98ef0ba35bdb103ea8317e5d1b0b5a4d2fe45f35
Parents: ec1ffe1
Author: sboikov <sb...@gridgain.com>
Authored: Fri Dec 11 17:26:09 2015 +0300
Committer: sboikov <sb...@gridgain.com>
Committed: Fri Dec 11 17:26:09 2015 +0300

----------------------------------------------------------------------
 .gitignore                       |    1 +
 assembly/release-fabric-base.xml |    6 +
 modules/platforms/cpp/cpp.dxg    | 1722 +++++++++++++++++++++++++++++++++
 3 files changed, 1729 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/98ef0ba3/.gitignore
----------------------------------------------------------------------
diff --git a/.gitignore b/.gitignore
index 2eac5d9..ef12f3a 100644
--- a/.gitignore
+++ b/.gitignore
@@ -27,3 +27,4 @@ git-patch-prop-local.sh
 **/cpp/**/vs/x64/
 **/cpp/**/vs/Win32/
 **/dotnet/**/obj/
+/modules/platforms/cpp/doc/

http://git-wip-us.apache.org/repos/asf/ignite/blob/98ef0ba3/assembly/release-fabric-base.xml
----------------------------------------------------------------------
diff --git a/assembly/release-fabric-base.xml b/assembly/release-fabric-base.xml
index e6d4eb9..5f6d5eb 100644
--- a/assembly/release-fabric-base.xml
+++ b/assembly/release-fabric-base.xml
@@ -131,6 +131,12 @@
             <outputDirectory>/platforms/cpp/licenses</outputDirectory>
         </fileSet>
 
+        <!-- Move CPP docs. -->
+        <fileSet>
+            <directory>modules/platforms/cpp/doc</directory>
+            <outputDirectory>/platforms/cpp/docs</outputDirectory>
+        </fileSet>
+
         <!-- Other files. -->
         <fileSet>
             <directory>bin</directory>

http://git-wip-us.apache.org/repos/asf/ignite/blob/98ef0ba3/modules/platforms/cpp/cpp.dxg
----------------------------------------------------------------------
diff --git a/modules/platforms/cpp/cpp.dxg b/modules/platforms/cpp/cpp.dxg
new file mode 100644
index 0000000..968ff71
--- /dev/null
+++ b/modules/platforms/cpp/cpp.dxg
@@ -0,0 +1,1722 @@
+# Doxyfile 1.7.4
+
+# This file describes the settings to be used by the documentation system
+# doxygen (www.doxygen.org) for a project.
+#
+# All text after a hash (#) is considered a comment and will be ignored.
+# The format is:
+#       TAG = value [value, ...]
+# For lists items can also be appended using:
+#       TAG += value [value, ...]
+# Values that contain spaces should be placed between quotes (" ").
+
+#---------------------------------------------------------------------------
+# Project related configuration options
+#---------------------------------------------------------------------------
+
+# This tag specifies the encoding used for all characters in the config file
+# that follow. The default is UTF-8 which is also the encoding used for all
+# text before the first occurrence of this tag. Doxygen uses libiconv (or the
+# iconv built into libc) for the transcoding. See
+# http://www.gnu.org/software/libiconv for the list of possible encodings.
+
+DOXYFILE_ENCODING      = UTF-8
+
+# The PROJECT_NAME tag is a single word (or a sequence of words surrounded
+# by quotes) that should identify the project.
+
+PROJECT_NAME           = "&nbsp; Apache Ignite C++ Client Library"
+
+# The PROJECT_NUMBER tag can be used to enter a project or revision number.
+# This could be handy for archiving the generated documentation or
+# if some version control system is used.
+
+PROJECT_NUMBER         =
+
+# Using the PROJECT_BRIEF tag one can provide an optional one line description
+# for a project that appears at the top of each page and should give viewer
+# a quick idea about the purpose of the project. Keep the description short.
+
+PROJECT_BRIEF          =
+
+# With the PROJECT_LOGO tag one can specify an logo or icon that is
+# included in the documentation. The maximum height of the logo should not
+# exceed 55 pixels and the maximum width should not exceed 200 pixels.
+# Doxygen will copy the logo to the output directory.
+
+PROJECT_LOGO           =
+
+# The OUTPUT_DIRECTORY tag is used to specify the (relative or absolute)
+# base path where the generated documentation will be put.
+# If a relative path is entered, it will be relative to the location
+# where doxygen was started. If left blank the current directory will be used.
+
+OUTPUT_DIRECTORY       = docs
+
+# If the CREATE_SUBDIRS tag is set to YES, then doxygen will create
+# 4096 sub-directories (in 2 levels) under the output directory of each output
+# format and will distribute the generated files over these directories.
+# Enabling this option can be useful when feeding doxygen a huge amount of
+# source files, where putting all generated files in the same directory would
+# otherwise cause performance problems for the file system.
+
+CREATE_SUBDIRS         = NO
+
+# The OUTPUT_LANGUAGE tag is used to specify the language in which all
+# documentation generated by doxygen is written. Doxygen will use this
+# information to generate all constant output in the proper language.
+# The default language is English, other supported languages are:
+# Afrikaans, Arabic, Brazilian, Catalan, Chinese, Chinese-Traditional,
+# Croatian, Czech, Danish, Dutch, Esperanto, Farsi, Finnish, French, German,
+# Greek, Hungarian, Italian, Japanese, Japanese-en (Japanese with English
+# messages), Korean, Korean-en, Lithuanian, Norwegian, Macedonian, Persian,
+# Polish, Portuguese, Romanian, Russian, Serbian, Serbian-Cyrillic, Slovak,
+# Slovene, Spanish, Swedish, Ukrainian, and Vietnamese.
+
+OUTPUT_LANGUAGE        = English
+
+# If the BRIEF_MEMBER_DESC tag is set to YES (the default) Doxygen will
+# include brief member descriptions after the members that are listed in
+# the file and class documentation (similar to JavaDoc).
+# Set to NO to disable this.
+
+BRIEF_MEMBER_DESC      = YES
+
+# If the REPEAT_BRIEF tag is set to YES (the default) Doxygen will prepend
+# the brief description of a member or function before the detailed description.
+# Note: if both HIDE_UNDOC_MEMBERS and BRIEF_MEMBER_DESC are set to NO, the
+# brief descriptions will be completely suppressed.
+
+REPEAT_BRIEF           = YES
+
+# This tag implements a quasi-intelligent brief description abbreviator
+# that is used to form the text in various listings. Each string
+# in this list, if found as the leading text of the brief description, will be
+# stripped from the text and the result after processing the whole list, is
+# used as the annotated text. Otherwise, the brief description is used as-is.
+# If left blank, the following values are used ("$name" is automatically
+# replaced with the name of the entity): "The $name class" "The $name widget"
+# "The $name file" "is" "provides" "specifies" "contains"
+# "represents" "a" "an" "the"
+
+ABBREVIATE_BRIEF       =
+
+# If the ALWAYS_DETAILED_SEC and REPEAT_BRIEF tags are both set to YES then
+# Doxygen will generate a detailed section even if there is only a brief
+# description.
+
+ALWAYS_DETAILED_SEC    = NO
+
+# If the INLINE_INHERITED_MEMB tag is set to YES, doxygen will show all
+# inherited members of a class in the documentation of that class as if those
+# members were ordinary class members. Constructors, destructors and assignment
+# operators of the base classes will not be shown.
+
+INLINE_INHERITED_MEMB  = NO
+
+# If the FULL_PATH_NAMES tag is set to YES then Doxygen will prepend the full
+# path before files name in the file list and in the header files. If set
+# to NO the shortest path that makes the file name unique will be used.
+
+FULL_PATH_NAMES        = NO
+
+# If the FULL_PATH_NAMES tag is set to YES then the STRIP_FROM_PATH tag
+# can be used to strip a user-defined part of the path. Stripping is
+# only done if one of the specified strings matches the left-hand part of
+# the path. The tag can be used to show relative paths in the file list.
+# If left blank the directory from which doxygen is run is used as the
+# path to strip.
+
+STRIP_FROM_PATH        =
+
+# The STRIP_FROM_INC_PATH tag can be used to strip a user-defined part of
+# the path mentioned in the documentation of a class, which tells
+# the reader which header file to include in order to use a class.
+# If left blank only the name of the header file containing the class
+# definition is used. Otherwise one should specify the include paths that
+# are normally passed to the compiler using the -I flag.
+
+STRIP_FROM_INC_PATH    =
+
+# If the SHORT_NAMES tag is set to YES, doxygen will generate much shorter
+# (but less readable) file names. This can be useful if your file system
+# doesn't support long names like on DOS, Mac, or CD-ROM.
+
+SHORT_NAMES            = NO
+
+# If the JAVADOC_AUTOBRIEF tag is set to YES then Doxygen
+# will interpret the first line (until the first dot) of a JavaDoc-style
+# comment as the brief description. If set to NO, the JavaDoc
+# comments will behave just like regular Qt-style comments
+# (thus requiring an explicit @brief command for a brief description.)
+
+JAVADOC_AUTOBRIEF      = NO
+
+# If the QT_AUTOBRIEF tag is set to YES then Doxygen will
+# interpret the first line (until the first dot) of a Qt-style
+# comment as the brief description. If set to NO, the comments
+# will behave just like regular Qt-style comments (thus requiring
+# an explicit \brief command for a brief description.)
+
+QT_AUTOBRIEF           = NO
+
+# The MULTILINE_CPP_IS_BRIEF tag can be set to YES to make Doxygen
+# treat a multi-line C++ special comment block (i.e. a block of //! or ///
+# comments) as a brief description. This used to be the default behaviour.
+# The new default is to treat a multi-line C++ comment block as a detailed
+# description. Set this tag to YES if you prefer the old behaviour instead.
+
+MULTILINE_CPP_IS_BRIEF = NO
+
+# If the INHERIT_DOCS tag is set to YES (the default) then an undocumented
+# member inherits the documentation from any documented member that it
+# re-implements.
+
+INHERIT_DOCS           = YES
+
+# If the SEPARATE_MEMBER_PAGES tag is set to YES, then doxygen will produce
+# a new page for each member. If set to NO, the documentation of a member will
+# be part of the file/class/namespace that contains it.
+
+SEPARATE_MEMBER_PAGES  = NO
+
+# The TAB_SIZE tag can be used to set the number of spaces in a tab.
+# Doxygen uses this value to replace tabs by spaces in code fragments.
+
+TAB_SIZE               = 8
+
+# This tag can be used to specify a number of aliases that acts
+# as commands in the documentation. An alias has the form "name=value".
+# For example adding "sideeffect=\par Side Effects:\n" will allow you to
+# put the command \sideeffect (or @sideeffect) in the documentation, which
+# will result in a user-defined paragraph with heading "Side Effects:".
+# You can put \n's in the value part of an alias to insert newlines.
+
+ALIASES                =
+
+# Set the OPTIMIZE_OUTPUT_FOR_C tag to YES if your project consists of C
+# sources only. Doxygen will then generate output that is more tailored for C.
+# For instance, some of the names that are used will be different. The list
+# of all members will be omitted, etc.
+
+OPTIMIZE_OUTPUT_FOR_C  = NO
+
+# Set the OPTIMIZE_OUTPUT_JAVA tag to YES if your project consists of Java
+# sources only. Doxygen will then generate output that is more tailored for
+# Java. For instance, namespaces will be presented as packages, qualified
+# scopes will look different, etc.
+
+OPTIMIZE_OUTPUT_JAVA   = NO
+
+# Set the OPTIMIZE_FOR_FORTRAN tag to YES if your project consists of Fortran
+# sources only. Doxygen will then generate output that is more tailored for
+# Fortran.
+
+OPTIMIZE_FOR_FORTRAN   = NO
+
+# Set the OPTIMIZE_OUTPUT_VHDL tag to YES if your project consists of VHDL
+# sources. Doxygen will then generate output that is tailored for
+# VHDL.
+
+OPTIMIZE_OUTPUT_VHDL   = NO
+
+# Doxygen selects the parser to use depending on the extension of the files it
+# parses. With this tag you can assign which parser to use for a given extension.
+# Doxygen has a built-in mapping, but you can override or extend it using this
+# tag. The format is ext=language, where ext is a file extension, and language
+# is one of the parsers supported by doxygen: IDL, Java, Javascript, CSharp, C,
+# C++, D, PHP, Objective-C, Python, Fortran, VHDL, C, C++. For instance to make
+# doxygen treat .inc files as Fortran files (default is PHP), and .f files as C
+# (default is Fortran), use: inc=Fortran f=C. Note that for custom extensions
+# you also need to set FILE_PATTERNS otherwise the files are not read by doxygen.
+
+EXTENSION_MAPPING      =
+
+# If you use STL classes (i.e. std::string, std::vector, etc.) but do not want
+# to include (a tag file for) the STL sources as input, then you should
+# set this tag to YES in order to let doxygen match functions declarations and
+# definitions whose arguments contain STL classes (e.g. func(std::string); v.s.
+# func(std::string) {}). This also makes the inheritance and collaboration
+# diagrams that involve STL classes more complete and accurate.
+
+BUILTIN_STL_SUPPORT    = NO
+
+# If you use Microsoft's C++/CLI language, you should set this option to YES to
+# enable parsing support.
+
+CPP_CLI_SUPPORT        = NO
+
+# Set the SIP_SUPPORT tag to YES if your project consists of sip sources only.
+# Doxygen will parse them like normal C++ but will assume all classes use public
+# instead of private inheritance when no explicit protection keyword is present.
+
+SIP_SUPPORT            = NO
+
+# For Microsoft's IDL there are propget and propput attributes to indicate getter
+# and setter methods for a property. Setting this option to YES (the default)
+# will make doxygen replace the get and set methods by a property in the
+# documentation. This will only work if the methods are indeed getting or
+# setting a simple type. If this is not the case, or you want to show the
+# methods anyway, you should set this option to NO.
+
+IDL_PROPERTY_SUPPORT   = YES
+
+# If member grouping is used in the documentation and the DISTRIBUTE_GROUP_DOC
+# tag is set to YES, then doxygen will reuse the documentation of the first
+# member in the group (if any) for the other members of the group. By default
+# all members of a group must be documented explicitly.
+
+DISTRIBUTE_GROUP_DOC   = NO
+
+# Set the SUBGROUPING tag to YES (the default) to allow class member groups of
+# the same type (for instance a group of public functions) to be put as a
+# subgroup of that type (e.g. under the Public Functions section). Set it to
+# NO to prevent subgrouping. Alternatively, this can be done per class using
+# the \nosubgrouping command.
+
+SUBGROUPING            = YES
+
+# When the INLINE_GROUPED_CLASSES tag is set to YES, classes, structs and
+# unions are shown inside the group in which they are included (e.g. using
+# @ingroup) instead of on a separate page (for HTML and Man pages) or
+# section (for LaTeX and RTF).
+
+INLINE_GROUPED_CLASSES = NO
+
+# When TYPEDEF_HIDES_STRUCT is enabled, a typedef of a struct, union, or enum
+# is documented as struct, union, or enum with the name of the typedef. So
+# typedef struct TypeS {} TypeT, will appear in the documentation as a struct
+# with name TypeT. When disabled the typedef will appear as a member of a file,
+# namespace, or class. And the struct will be named TypeS. This can typically
+# be useful for C code in case the coding convention dictates that all compound
+# types are typedef'ed and only the typedef is referenced, never the tag name.
+
+TYPEDEF_HIDES_STRUCT   = NO
+
+# The SYMBOL_CACHE_SIZE determines the size of the internal cache use to
+# determine which symbols to keep in memory and which to flush to disk.
+# When the cache is full, less often used symbols will be written to disk.
+# For small to medium size projects (<1000 input files) the default value is
+# probably good enough. For larger projects a too small cache size can cause
+# doxygen to be busy swapping symbols to and from disk most of the time
+# causing a significant performance penalty.
+# If the system has enough physical memory increasing the cache will improve the
+# performance by keeping more symbols in memory. Note that the value works on
+# a logarithmic scale so increasing the size by one will roughly double the
+# memory usage. The cache size is given by this formula:
+# 2^(16+SYMBOL_CACHE_SIZE). The valid range is 0..9, the default is 0,
+# corresponding to a cache size of 2^16 = 65536 symbols
+
+SYMBOL_CACHE_SIZE      = 0
+
+#---------------------------------------------------------------------------
+# Build related configuration options
+#---------------------------------------------------------------------------
+
+# If the EXTRACT_ALL tag is set to YES doxygen will assume all entities in
+# documentation are documented, even if no documentation was available.
+# Private class members and static file members will be hidden unless
+# the EXTRACT_PRIVATE and EXTRACT_STATIC tags are set to YES
+
+EXTRACT_ALL            = NO
+
+# If the EXTRACT_PRIVATE tag is set to YES all private members of a class
+# will be included in the documentation.
+
+EXTRACT_PRIVATE        = NO
+
+# If the EXTRACT_STATIC tag is set to YES all static members of a file
+# will be included in the documentation.
+
+EXTRACT_STATIC         = NO
+
+# If the EXTRACT_LOCAL_CLASSES tag is set to YES classes (and structs)
+# defined locally in source files will be included in the documentation.
+# If set to NO only classes defined in header files are included.
+
+EXTRACT_LOCAL_CLASSES  = YES
+
+# This flag is only useful for Objective-C code. When set to YES local
+# methods, which are defined in the implementation section but not in
+# the interface are included in the documentation.
+# If set to NO (the default) only methods in the interface are included.
+
+EXTRACT_LOCAL_METHODS  = NO
+
+# If this flag is set to YES, the members of anonymous namespaces will be
+# extracted and appear in the documentation as a namespace called
+# 'anonymous_namespace{file}', where file will be replaced with the base
+# name of the file that contains the anonymous namespace. By default
+# anonymous namespaces are hidden.
+
+EXTRACT_ANON_NSPACES   = NO
+
+# If the HIDE_UNDOC_MEMBERS tag is set to YES, Doxygen will hide all
+# undocumented members of documented classes, files or namespaces.
+# If set to NO (the default) these members will be included in the
+# various overviews, but no documentation section is generated.
+# This option has no effect if EXTRACT_ALL is enabled.
+
+HIDE_UNDOC_MEMBERS     = NO
+
+# If the HIDE_UNDOC_CLASSES tag is set to YES, Doxygen will hide all
+# undocumented classes that are normally visible in the class hierarchy.
+# If set to NO (the default) these classes will be included in the various
+# overviews. This option has no effect if EXTRACT_ALL is enabled.
+
+HIDE_UNDOC_CLASSES     = NO
+
+# If the HIDE_FRIEND_COMPOUNDS tag is set to YES, Doxygen will hide all
+# friend (class|struct|union) declarations.
+# If set to NO (the default) these declarations will be included in the
+# documentation.
+
+HIDE_FRIEND_COMPOUNDS  = NO
+
+# If the HIDE_IN_BODY_DOCS tag is set to YES, Doxygen will hide any
+# documentation blocks found inside the body of a function.
+# If set to NO (the default) these blocks will be appended to the
+# function's detailed documentation block.
+
+HIDE_IN_BODY_DOCS      = NO
+
+# The INTERNAL_DOCS tag determines if documentation
+# that is typed after a \internal command is included. If the tag is set
+# to NO (the default) then the documentation will be excluded.
+# Set it to YES to include the internal documentation.
+
+INTERNAL_DOCS          = NO
+
+# If the CASE_SENSE_NAMES tag is set to NO then Doxygen will only generate
+# file names in lower-case letters. If set to YES upper-case letters are also
+# allowed. This is useful if you have classes or files whose names only differ
+# in case and if your file system supports case sensitive file names. Windows
+# and Mac users are advised to set this option to NO.
+
+CASE_SENSE_NAMES       = YES
+
+# If the HIDE_SCOPE_NAMES tag is set to NO (the default) then Doxygen
+# will show members with their full class and namespace scopes in the
+# documentation. If set to YES the scope will be hidden.
+
+HIDE_SCOPE_NAMES       = NO
+
+# If the SHOW_INCLUDE_FILES tag is set to YES (the default) then Doxygen
+# will put a list of the files that are included by a file in the documentation
+# of that file.
+
+SHOW_INCLUDE_FILES     = YES
+
+# If the FORCE_LOCAL_INCLUDES tag is set to YES then Doxygen
+# will list include files with double quotes in the documentation
+# rather than with sharp brackets.
+
+FORCE_LOCAL_INCLUDES   = NO
+
+# If the INLINE_INFO tag is set to YES (the default) then a tag [inline]
+# is inserted in the documentation for inline members.
+
+INLINE_INFO            = YES
+
+# If the SORT_MEMBER_DOCS tag is set to YES (the default) then doxygen
+# will sort the (detailed) documentation of file and class members
+# alphabetically by member name. If set to NO the members will appear in
+# declaration order.
+
+SORT_MEMBER_DOCS       = YES
+
+# If the SORT_BRIEF_DOCS tag is set to YES then doxygen will sort the
+# brief documentation of file, namespace and class members alphabetically
+# by member name. If set to NO (the default) the members will appear in
+# declaration order.
+
+SORT_BRIEF_DOCS        = NO
+
+# If the SORT_MEMBERS_CTORS_1ST tag is set to YES then doxygen
+# will sort the (brief and detailed) documentation of class members so that
+# constructors and destructors are listed first. If set to NO (the default)
+# the constructors will appear in the respective orders defined by
+# SORT_MEMBER_DOCS and SORT_BRIEF_DOCS.
+# This tag will be ignored for brief docs if SORT_BRIEF_DOCS is set to NO
+# and ignored for detailed docs if SORT_MEMBER_DOCS is set to NO.
+
+SORT_MEMBERS_CTORS_1ST = NO
+
+# If the SORT_GROUP_NAMES tag is set to YES then doxygen will sort the
+# hierarchy of group names into alphabetical order. If set to NO (the default)
+# the group names will appear in their defined order.
+
+SORT_GROUP_NAMES       = NO
+
+# If the SORT_BY_SCOPE_NAME tag is set to YES, the class list will be
+# sorted by fully-qualified names, including namespaces. If set to
+# NO (the default), the class list will be sorted only by class name,
+# not including the namespace part.
+# Note: This option is not very useful if HIDE_SCOPE_NAMES is set to YES.
+# Note: This option applies only to the class list, not to the
+# alphabetical list.
+
+SORT_BY_SCOPE_NAME     = NO
+
+# If the STRICT_PROTO_MATCHING option is enabled and doxygen fails to
+# do proper type resolution of all parameters of a function it will reject a
+# match between the prototype and the implementation of a member function even
+# if there is only one candidate or it is obvious which candidate to choose
+# by doing a simple string match. By disabling STRICT_PROTO_MATCHING doxygen
+# will still accept a match between prototype and implementation in such cases.
+
+STRICT_PROTO_MATCHING  = NO
+
+# The GENERATE_TODOLIST tag can be used to enable (YES) or
+# disable (NO) the todo list. This list is created by putting \todo
+# commands in the documentation.
+
+GENERATE_TODOLIST      = YES
+
+# The GENERATE_TESTLIST tag can be used to enable (YES) or
+# disable (NO) the test list. This list is created by putting \test
+# commands in the documentation.
+
+GENERATE_TESTLIST      = YES
+
+# The GENERATE_BUGLIST tag can be used to enable (YES) or
+# disable (NO) the bug list. This list is created by putting \bug
+# commands in the documentation.
+
+GENERATE_BUGLIST       = YES
+
+# The GENERATE_DEPRECATEDLIST tag can be used to enable (YES) or
+# disable (NO) the deprecated list. This list is created by putting
+# \deprecated commands in the documentation.
+
+GENERATE_DEPRECATEDLIST= YES
+
+# The ENABLED_SECTIONS tag can be used to enable conditional
+# documentation sections, marked by \if sectionname ... \endif.
+
+ENABLED_SECTIONS       =
+
+# The MAX_INITIALIZER_LINES tag determines the maximum number of lines
+# the initial value of a variable or macro consists of for it to appear in
+# the documentation. If the initializer consists of more lines than specified
+# here it will be hidden. Use a value of 0 to hide initializers completely.
+# The appearance of the initializer of individual variables and macros in the
+# documentation can be controlled using \showinitializer or \hideinitializer
+# command in the documentation regardless of this setting.
+
+MAX_INITIALIZER_LINES  = 30
+
+# Set the SHOW_USED_FILES tag to NO to disable the list of files generated
+# at the bottom of the documentation of classes and structs. If set to YES the
+# list will mention the files that were used to generate the documentation.
+
+SHOW_USED_FILES        = YES
+
+# If the sources in your project are distributed over multiple directories
+# then setting the SHOW_DIRECTORIES tag to YES will show the directory hierarchy
+# in the documentation. The default is NO.
+
+SHOW_DIRECTORIES       = NO
+
+# Set the SHOW_FILES tag to NO to disable the generation of the Files page.
+# This will remove the Files entry from the Quick Index and from the
+# Folder Tree View (if specified). The default is YES.
+
+SHOW_FILES             = YES
+
+# Set the SHOW_NAMESPACES tag to NO to disable the generation of the
+# Namespaces page.
+# This will remove the Namespaces entry from the Quick Index
+# and from the Folder Tree View (if specified). The default is YES.
+
+SHOW_NAMESPACES        = YES
+
+# The FILE_VERSION_FILTER tag can be used to specify a program or script that
+# doxygen should invoke to get the current version for each file (typically from
+# the version control system). Doxygen will invoke the program by executing (via
+# popen()) the command <command> <input-file>, where <command> is the value of
+# the FILE_VERSION_FILTER tag, and <input-file> is the name of an input file
+# provided by doxygen. Whatever the program writes to standard output
+# is used as the file version. See the manual for examples.
+
+FILE_VERSION_FILTER    =
+
+# The LAYOUT_FILE tag can be used to specify a layout file which will be parsed
+# by doxygen. The layout file controls the global structure of the generated
+# output files in an output format independent way. The create the layout file
+# that represents doxygen's defaults, run doxygen with the -l option.
+# You can optionally specify a file name after the option, if omitted
+# DoxygenLayout.xml will be used as the name of the layout file.
+
+LAYOUT_FILE            =
+
+#---------------------------------------------------------------------------
+# configuration options related to warning and progress messages
+#---------------------------------------------------------------------------
+
+# The QUIET tag can be used to turn on/off the messages that are generated
+# by doxygen. Possible values are YES and NO. If left blank NO is used.
+
+QUIET                  = YES
+
+# The WARNINGS tag can be used to turn on/off the warning messages that are
+# generated by doxygen. Possible values are YES and NO. If left blank
+# NO is used.
+
+WARNINGS               = NO
+
+# If WARN_IF_UNDOCUMENTED is set to YES, then doxygen will generate warnings
+# for undocumented members. If EXTRACT_ALL is set to YES then this flag will
+# automatically be disabled.
+
+WARN_IF_UNDOCUMENTED   = NO
+
+# If WARN_IF_DOC_ERROR is set to YES, doxygen will generate warnings for
+# potential errors in the documentation, such as not documenting some
+# parameters in a documented function, or documenting parameters that
+# don't exist or using markup commands wrongly.
+
+WARN_IF_DOC_ERROR      = NO
+
+# The WARN_NO_PARAMDOC option can be enabled to get warnings for
+# functions that are documented, but have no documentation for their parameters
+# or return value. If set to NO (the default) doxygen will only warn about
+# wrong or incomplete parameter documentation, but not about the absence of
+# documentation.
+
+WARN_NO_PARAMDOC       = NO
+
+# The WARN_FORMAT tag determines the format of the warning messages that
+# doxygen can produce. The string should contain the $file, $line, and $text
+# tags, which will be replaced by the file and line number from which the
+# warning originated and the warning text. Optionally the format may contain
+# $version, which will be replaced by the version of the file (if it could
+# be obtained via FILE_VERSION_FILTER)
+
+WARN_FORMAT            = "$file:$line: $text"
+
+# The WARN_LOGFILE tag can be used to specify a file to which warning
+# and error messages should be written. If left blank the output is written
+# to stderr.
+
+WARN_LOGFILE           =
+
+#---------------------------------------------------------------------------
+# configuration options related to the input files
+#---------------------------------------------------------------------------
+
+# The INPUT tag can be used to specify the files and/or directories that contain
+# documented source files. You may enter file names like "myfile.cpp" or
+# directories like "/usr/src/myproject". Separate the files or directories
+# with spaces.
+
+INPUT                  = include src/model src/impl src/impl/cmd src/impl/connection src/impl/hash src/impl/utils
+
+# This tag can be used to specify the character encoding of the source files
+# that doxygen parses. Internally doxygen uses the UTF-8 encoding, which is
+# also the default input encoding. Doxygen uses libiconv (or the iconv built
+# into libc) for the transcoding. See http://www.gnu.org/software/libiconv for
+# the list of possible encodings.
+
+INPUT_ENCODING         = UTF-8
+
+# If the value of the INPUT tag contains directories, you can use the
+# FILE_PATTERNS tag to specify one or more wildcard pattern (like *.cpp
+# and *.h) to filter out the source-files in the directories. If left
+# blank the following patterns are tested:
+# *.c *.cc *.cxx *.cpp *.c++ *.d *.java *.ii *.ixx *.ipp *.i++ *.inl *.h *.hh
+# *.hxx *.hpp *.h++ *.idl *.odl *.cs *.php *.php3 *.inc *.m *.mm *.dox *.py
+# *.f90 *.f *.for *.vhd *.vhdl
+
+FILE_PATTERNS          =
+
+# The RECURSIVE tag can be used to turn specify whether or not subdirectories
+# should be searched for input files as well. Possible values are YES and NO.
+# If left blank NO is used.
+
+RECURSIVE              = YES
+
+# The EXCLUDE tag can be used to specify files and/or directories that should
+# excluded from the INPUT source files. This way you can easily exclude a
+# subdirectory from a directory tree whose root is specified with the INPUT tag.
+
+EXCLUDE                =
+
+# The EXCLUDE_SYMLINKS tag can be used select whether or not files or
+# directories that are symbolic links (a Unix file system feature) are excluded
+# from the input.
+
+EXCLUDE_SYMLINKS       = NO
+
+# If the value of the INPUT tag contains directories, you can use the
+# EXCLUDE_PATTERNS tag to specify one or more wildcard patterns to exclude
+# certain files from those directories. Note that the wildcards are matched
+# against the file with absolute path, so to exclude all test directories
+# for example use the pattern */test/*
+
+EXCLUDE_PATTERNS       = *ClientMessages.pb.*
+
+# The EXCLUDE_SYMBOLS tag can be used to specify one or more symbol names
+# (namespaces, classes, functions, etc.) that should be excluded from the
+# output. The symbol name can be a fully qualified name, a word, or if the
+# wildcard * is used, a substring. Examples: ANamespace, AClass,
+# AClass::ANamespace, ANamespace::*Test
+
+EXCLUDE_SYMBOLS        =
+
+# The EXAMPLE_PATH tag can be used to specify one or more files or
+# directories that contain example code fragments that are included (see
+# the \include command).
+
+EXAMPLE_PATH           =
+
+# If the value of the EXAMPLE_PATH tag contains directories, you can use the
+# EXAMPLE_PATTERNS tag to specify one or more wildcard pattern (like *.cpp
+# and *.h) to filter out the source-files in the directories. If left
+# blank all files are included.
+
+EXAMPLE_PATTERNS       =
+
+# If the EXAMPLE_RECURSIVE tag is set to YES then subdirectories will be
+# searched for input files to be used with the \include or \dontinclude
+# commands irrespective of the value of the RECURSIVE tag.
+# Possible values are YES and NO. If left blank NO is used.
+
+EXAMPLE_RECURSIVE      = NO
+
+# The IMAGE_PATH tag can be used to specify one or more files or
+# directories that contain image that are included in the documentation (see
+# the \image command).
+
+IMAGE_PATH             =
+
+# The INPUT_FILTER tag can be used to specify a program that doxygen should
+# invoke to filter for each input file. Doxygen will invoke the filter program
+# by executing (via popen()) the command <filter> <input-file>, where <filter>
+# is the value of the INPUT_FILTER tag, and <input-file> is the name of an
+# input file. Doxygen will then use the output that the filter program writes
+# to standard output.
+# If FILTER_PATTERNS is specified, this tag will be
+# ignored.
+
+INPUT_FILTER           =
+
+# The FILTER_PATTERNS tag can be used to specify filters on a per file pattern
+# basis.
+# Doxygen will compare the file name with each pattern and apply the
+# filter if there is a match.
+# The filters are a list of the form:
+# pattern=filter (like *.cpp=my_cpp_filter). See INPUT_FILTER for further
+# info on how filters are used. If FILTER_PATTERNS is empty or if
+# non of the patterns match the file name, INPUT_FILTER is applied.
+
+FILTER_PATTERNS        =
+
+# If the FILTER_SOURCE_FILES tag is set to YES, the input filter (if set using
+# INPUT_FILTER) will be used to filter the input files when producing source
+# files to browse (i.e. when SOURCE_BROWSER is set to YES).
+
+FILTER_SOURCE_FILES    = NO
+
+# The FILTER_SOURCE_PATTERNS tag can be used to specify source filters per file
+# pattern. A pattern will override the setting for FILTER_PATTERN (if any)
+# and it is also possible to disable source filtering for a specific pattern
+# using *.ext= (so without naming a filter). This option only has effect when
+# FILTER_SOURCE_FILES is enabled.
+
+FILTER_SOURCE_PATTERNS =
+
+#---------------------------------------------------------------------------
+# configuration options related to source browsing
+#---------------------------------------------------------------------------
+
+# If the SOURCE_BROWSER tag is set to YES then a list of source files will
+# be generated. Documented entities will be cross-referenced with these sources.
+# Note: To get rid of all source code in the generated output, make sure also
+# VERBATIM_HEADERS is set to NO.
+
+SOURCE_BROWSER         = NO
+
+# Setting the INLINE_SOURCES tag to YES will include the body
+# of functions and classes directly in the documentation.
+
+INLINE_SOURCES         = NO
+
+# Setting the STRIP_CODE_COMMENTS tag to YES (the default) will instruct
+# doxygen to hide any special comment blocks from generated source code
+# fragments. Normal C and C++ comments will always remain visible.
+
+STRIP_CODE_COMMENTS    = YES
+
+# If the REFERENCED_BY_RELATION tag is set to YES
+# then for each documented function all documented
+# functions referencing it will be listed.
+
+REFERENCED_BY_RELATION = NO
+
+# If the REFERENCES_RELATION tag is set to YES
+# then for each documented function all documented entities
+# called/used by that function will be listed.
+
+REFERENCES_RELATION    = NO
+
+# If the REFERENCES_LINK_SOURCE tag is set to YES (the default)
+# and SOURCE_BROWSER tag is set to YES, then the hyperlinks from
+# functions in REFERENCES_RELATION and REFERENCED_BY_RELATION lists will
+# link to the source code.
+# Otherwise they will link to the documentation.
+
+REFERENCES_LINK_SOURCE = NO
+
+# If the USE_HTAGS tag is set to YES then the references to source code
+# will point to the HTML generated by the htags(1) tool instead of doxygen
+# built-in source browser. The htags tool is part of GNU's global source
+# tagging system (see http://www.gnu.org/software/global/global.html). You
+# will need version 4.8.6 or higher.
+
+USE_HTAGS              = NO
+
+# If the VERBATIM_HEADERS tag is set to YES (the default) then Doxygen
+# will generate a verbatim copy of the header file for each class for
+# which an include is specified. Set to NO to disable this.
+
+VERBATIM_HEADERS       = YES
+
+#---------------------------------------------------------------------------
+# configuration options related to the alphabetical class index
+#---------------------------------------------------------------------------
+
+# If the ALPHABETICAL_INDEX tag is set to YES, an alphabetical index
+# of all compounds will be generated. Enable this if the project
+# contains a lot of classes, structs, unions or interfaces.
+
+ALPHABETICAL_INDEX     = YES
+
+# If the alphabetical index is enabled (see ALPHABETICAL_INDEX) then
+# the COLS_IN_ALPHA_INDEX tag can be used to specify the number of columns
+# in which this list will be split (can be a number in the range [1..20])
+
+COLS_IN_ALPHA_INDEX    = 5
+
+# In case all classes in a project start with a common prefix, all
+# classes will be put under the same header in the alphabetical index.
+# The IGNORE_PREFIX tag can be used to specify one or more prefixes that
+# should be ignored while generating the index headers.
+
+IGNORE_PREFIX          =
+
+#---------------------------------------------------------------------------
+# configuration options related to the HTML output
+#---------------------------------------------------------------------------
+
+# If the GENERATE_HTML tag is set to YES (the default) Doxygen will
+# generate HTML output.
+
+GENERATE_HTML          = YES
+
+# The HTML_OUTPUT tag is used to specify where the HTML docs will be put.
+# If a relative path is entered the value of OUTPUT_DIRECTORY will be
+# put in front of it. If left blank `html' will be used as the default path.
+
+HTML_OUTPUT            = html
+
+# The HTML_FILE_EXTENSION tag can be used to specify the file extension for
+# each generated HTML page (for example: .htm,.php,.asp). If it is left blank
+# doxygen will generate files with .html extension.
+
+HTML_FILE_EXTENSION    = .html
+
+# The HTML_HEADER tag can be used to specify a personal HTML header for
+# each generated HTML page. If it is left blank doxygen will generate a
+# standard header. Note that when using a custom header you are responsible
+# for the proper inclusion of any scripts and style sheets that doxygen
+# needs, which is dependent on the configuration options used.
+# It is adviced to generate a default header using "doxygen -w html
+# header.html footer.html stylesheet.css YourConfigFile" and then modify
+# that header. Note that the header is subject to change so you typically
+# have to redo this when upgrading to a newer version of doxygen or when changing the value of configuration settings such as GENERATE_TREEVIEW!
+
+HTML_HEADER            =
+
+# The HTML_FOOTER tag can be used to specify a personal HTML footer for
+# each generated HTML page. If it is left blank doxygen will generate a
+# standard footer.
+
+HTML_FOOTER            =
+
+# The HTML_STYLESHEET tag can be used to specify a user-defined cascading
+# style sheet that is used by each HTML page. It can be used to
+# fine-tune the look of the HTML output. If the tag is left blank doxygen
+# will generate a default style sheet. Note that doxygen will try to copy
+# the style sheet file to the HTML output directory, so don't put your own
+# stylesheet in the HTML output directory as well, or it will be erased!
+
+HTML_STYLESHEET        =
+
+# The HTML_EXTRA_FILES tag can be used to specify one or more extra images or
+# other source files which should be copied to the HTML output directory. Note
+# that these files will be copied to the base HTML output directory. Use the
+# $relpath$ marker in the HTML_HEADER and/or HTML_FOOTER files to load these
+# files. In the HTML_STYLESHEET file, use the file name only. Also note that
+# the files will be copied as-is; there are no commands or markers available.
+
+HTML_EXTRA_FILES       =
+
+# The HTML_COLORSTYLE_HUE tag controls the color of the HTML output.
+# Doxygen will adjust the colors in the stylesheet and background images
+# according to this color. Hue is specified as an angle on a colorwheel,
+# see http://en.wikipedia.org/wiki/Hue for more information.
+# For instance the value 0 represents red, 60 is yellow, 120 is green,
+# 180 is cyan, 240 is blue, 300 purple, and 360 is red again.
+# The allowed range is 0 to 359.
+
+HTML_COLORSTYLE_HUE    = 220
+
+# The HTML_COLORSTYLE_SAT tag controls the purity (or saturation) of
+# the colors in the HTML output. For a value of 0 the output will use
+# grayscales only. A value of 255 will produce the most vivid colors.
+
+HTML_COLORSTYLE_SAT    = 100
+
+# The HTML_COLORSTYLE_GAMMA tag controls the gamma correction applied to
+# the luminance component of the colors in the HTML output. Values below
+# 100 gradually make the output lighter, whereas values above 100 make
+# the output darker. The value divided by 100 is the actual gamma applied,
+# so 80 represents a gamma of 0.8, The value 220 represents a gamma of 2.2,
+# and 100 does not change the gamma.
+
+HTML_COLORSTYLE_GAMMA  = 80
+
+# If the HTML_TIMESTAMP tag is set to YES then the footer of each generated HTML
+# page will contain the date and time when the page was generated. Setting
+# this to NO can help when comparing the output of multiple runs.
+
+HTML_TIMESTAMP         = YES
+
+# If the HTML_ALIGN_MEMBERS tag is set to YES, the members of classes,
+# files or namespaces will be aligned in HTML using tables. If set to
+# NO a bullet list will be used.
+
+HTML_ALIGN_MEMBERS     = YES
+
+# If the HTML_DYNAMIC_SECTIONS tag is set to YES then the generated HTML
+# documentation will contain sections that can be hidden and shown after the
+# page has loaded. For this to work a browser that supports
+# JavaScript and DHTML is required (for instance Mozilla 1.0+, Firefox
+# Netscape 6.0+, Internet explorer 5.0+, Konqueror, or Safari).
+
+HTML_DYNAMIC_SECTIONS  = NO
+
+# If the GENERATE_DOCSET tag is set to YES, additional index files
+# will be generated that can be used as input for Apple's Xcode 3
+# integrated development environment, introduced with OSX 10.5 (Leopard).
+# To create a documentation set, doxygen will generate a Makefile in the
+# HTML output directory. Running make will produce the docset in that
+# directory and running "make install" will install the docset in
+# ~/Library/Developer/Shared/Documentation/DocSets so that Xcode will find
+# it at startup.
+# See http://developer.apple.com/tools/creatingdocsetswithdoxygen.html
+# for more information.
+
+GENERATE_DOCSET        = NO
+
+# When GENERATE_DOCSET tag is set to YES, this tag determines the name of the
+# feed. A documentation feed provides an umbrella under which multiple
+# documentation sets from a single provider (such as a company or product suite)
+# can be grouped.
+
+DOCSET_FEEDNAME        = "Doxygen generated docs"
+
+# When GENERATE_DOCSET tag is set to YES, this tag specifies a string that
+# should uniquely identify the documentation set bundle. This should be a
+# reverse domain-name style string, e.g. com.mycompany.MyDocSet. Doxygen
+# will append .docset to the name.
+
+DOCSET_BUNDLE_ID       = org.doxygen.Project
+
+# When GENERATE_PUBLISHER_ID tag specifies a string that should uniquely identify
+# the documentation publisher. This should be a reverse domain-name style
+# string, e.g. com.mycompany.MyDocSet.documentation.
+
+DOCSET_PUBLISHER_ID    = org.doxygen.Publisher
+
+# The GENERATE_PUBLISHER_NAME tag identifies the documentation publisher.
+
+DOCSET_PUBLISHER_NAME  = Publisher
+
+# If the GENERATE_HTMLHELP tag is set to YES, additional index files
+# will be generated that can be used as input for tools like the
+# Microsoft HTML help workshop to generate a compiled HTML help file (.chm)
+# of the generated HTML documentation.
+
+GENERATE_HTMLHELP      = NO
+
+# If the GENERATE_HTMLHELP tag is set to YES, the CHM_FILE tag can
+# be used to specify the file name of the resulting .chm file. You
+# can add a path in front of the file if the result should not be
+# written to the html output directory.
+
+CHM_FILE               =
+
+# If the GENERATE_HTMLHELP tag is set to YES, the HHC_LOCATION tag can
+# be used to specify the location (absolute path including file name) of
+# the HTML help compiler (hhc.exe). If non-empty doxygen will try to run
+# the HTML help compiler on the generated index.hhp.
+
+HHC_LOCATION           =
+
+# If the GENERATE_HTMLHELP tag is set to YES, the GENERATE_CHI flag
+# controls if a separate .chi index file is generated (YES) or that
+# it should be included in the master .chm file (NO).
+
+GENERATE_CHI           = NO
+
+# If the GENERATE_HTMLHELP tag is set to YES, the CHM_INDEX_ENCODING
+# is used to encode HtmlHelp index (hhk), content (hhc) and project file
+# content.
+
+CHM_INDEX_ENCODING     =
+
+# If the GENERATE_HTMLHELP tag is set to YES, the BINARY_TOC flag
+# controls whether a binary table of contents is generated (YES) or a
+# normal table of contents (NO) in the .chm file.
+
+BINARY_TOC             = NO
+
+# The TOC_EXPAND flag can be set to YES to add extra items for group members
+# to the contents of the HTML help documentation and to the tree view.
+
+TOC_EXPAND             = NO
+
+# If the GENERATE_QHP tag is set to YES and both QHP_NAMESPACE and
+# QHP_VIRTUAL_FOLDER are set, an additional index file will be generated
+# that can be used as input for Qt's qhelpgenerator to generate a
+# Qt Compressed Help (.qch) of the generated HTML documentation.
+
+GENERATE_QHP           = NO
+
+# If the QHG_LOCATION tag is specified, the QCH_FILE tag can
+# be used to specify the file name of the resulting .qch file.
+# The path specified is relative to the HTML output folder.
+
+QCH_FILE               =
+
+# The QHP_NAMESPACE tag specifies the namespace to use when generating
+# Qt Help Project output. For more information please see
+# http://doc.trolltech.com/qthelpproject.html#namespace
+
+QHP_NAMESPACE          = org.doxygen.Project
+
+# The QHP_VIRTUAL_FOLDER tag specifies the namespace to use when generating
+# Qt Help Project output. For more information please see
+# http://doc.trolltech.com/qthelpproject.html#virtual-folders
+
+QHP_VIRTUAL_FOLDER     = doc
+
+# If QHP_CUST_FILTER_NAME is set, it specifies the name of a custom filter to
+# add. For more information please see
+# http://doc.trolltech.com/qthelpproject.html#custom-filters
+
+QHP_CUST_FILTER_NAME   =
+
+# The QHP_CUST_FILT_ATTRS tag specifies the list of the attributes of the
+# custom filter to add. For more information please see
+# <a href="http://doc.trolltech.com/qthelpproject.html#custom-filters">
+# Qt Help Project / Custom Filters</a>.
+
+QHP_CUST_FILTER_ATTRS  =
+
+# The QHP_SECT_FILTER_ATTRS tag specifies the list of the attributes this
+# project's
+# filter section matches.
+# <a href="http://doc.trolltech.com/qthelpproject.html#filter-attributes">
+# Qt Help Project / Filter Attributes</a>.
+
+QHP_SECT_FILTER_ATTRS  =
+
+# If the GENERATE_QHP tag is set to YES, the QHG_LOCATION tag can
+# be used to specify the location of Qt's qhelpgenerator.
+# If non-empty doxygen will try to run qhelpgenerator on the generated
+# .qhp file.
+
+QHG_LOCATION           =
+
+# If the GENERATE_ECLIPSEHELP tag is set to YES, additional index files
+#  will be generated, which together with the HTML files, form an Eclipse help
+# plugin. To install this plugin and make it available under the help contents
+# menu in Eclipse, the contents of the directory containing the HTML and XML
+# files needs to be copied into the plugins directory of eclipse. The name of
+# the directory within the plugins directory should be the same as
+# the ECLIPSE_DOC_ID value. After copying Eclipse needs to be restarted before
+# the help appears.
+
+GENERATE_ECLIPSEHELP   = NO
+
+# A unique identifier for the eclipse help plugin. When installing the plugin
+# the directory name containing the HTML and XML files should also have
+# this name.
+
+ECLIPSE_DOC_ID         = org.doxygen.Project
+
+# The DISABLE_INDEX tag can be used to turn on/off the condensed index at
+# top of each HTML page. The value NO (the default) enables the index and
+# the value YES disables it.
+
+DISABLE_INDEX          = NO
+
+# The ENUM_VALUES_PER_LINE tag can be used to set the number of enum values
+# (range [0,1..20]) that doxygen will group on one line in the generated HTML
+# documentation. Note that a value of 0 will completely suppress the enum
+# values from appearing in the overview section.
+
+ENUM_VALUES_PER_LINE   = 4
+
+# The GENERATE_TREEVIEW tag is used to specify whether a tree-like index
+# structure should be generated to display hierarchical information.
+# If the tag value is set to YES, a side panel will be generated
+# containing a tree-like index structure (just like the one that
+# is generated for HTML Help). For this to work a browser that supports
+# JavaScript, DHTML, CSS and frames is required (i.e. any modern browser).
+# Windows users are probably better off using the HTML help feature.
+
+GENERATE_TREEVIEW      = NO
+
+# By enabling USE_INLINE_TREES, doxygen will generate the Groups, Directories,
+# and Class Hierarchy pages using a tree view instead of an ordered list.
+
+USE_INLINE_TREES       = NO
+
+# If the treeview is enabled (see GENERATE_TREEVIEW) then this tag can be
+# used to set the initial width (in pixels) of the frame in which the tree
+# is shown.
+
+TREEVIEW_WIDTH         = 250
+
+# When the EXT_LINKS_IN_WINDOW option is set to YES doxygen will open
+# links to external symbols imported via tag files in a separate window.
+
+EXT_LINKS_IN_WINDOW    = NO
+
+# Use this tag to change the font size of Latex formulas included
+# as images in the HTML documentation. The default is 10. Note that
+# when you change the font size after a successful doxygen run you need
+# to manually remove any form_*.png images from the HTML output directory
+# to force them to be regenerated.
+
+FORMULA_FONTSIZE       = 10
+
+# Use the FORMULA_TRANPARENT tag to determine whether or not the images
+# generated for formulas are transparent PNGs. Transparent PNGs are
+# not supported properly for IE 6.0, but are supported on all modern browsers.
+# Note that when changing this option you need to delete any form_*.png files
+# in the HTML output before the changes have effect.
+
+FORMULA_TRANSPARENT    = YES
+
+# Enable the USE_MATHJAX option to render LaTeX formulas using MathJax
+# (see http://www.mathjax.org) which uses client side Javascript for the
+# rendering instead of using prerendered bitmaps. Use this if you do not
+# have LaTeX installed or if you want to formulas look prettier in the HTML
+# output. When enabled you also need to install MathJax separately and
+# configure the path to it using the MATHJAX_RELPATH option.
+
+USE_MATHJAX            = NO
+
+# When MathJax is enabled you need to specify the location relative to the
+# HTML output directory using the MATHJAX_RELPATH option. The destination
+# directory should contain the MathJax.js script. For instance, if the mathjax
+# directory is located at the same level as the HTML output directory, then
+# MATHJAX_RELPATH should be ../mathjax. The default value points to the
+# mathjax.org site, so you can quickly see the result without installing
+# MathJax, but it is strongly recommended to install a local copy of MathJax
+# before deployment.
+
+MATHJAX_RELPATH        = http://www.mathjax.org/mathjax
+
+# When the SEARCHENGINE tag is enabled doxygen will generate a search box
+# for the HTML output. The underlying search engine uses javascript
+# and DHTML and should work on any modern browser. Note that when using
+# HTML help (GENERATE_HTMLHELP), Qt help (GENERATE_QHP), or docsets
+# (GENERATE_DOCSET) there is already a search function so this one should
+# typically be disabled. For large projects the javascript based search engine
+# can be slow, then enabling SERVER_BASED_SEARCH may provide a better solution.
+
+SEARCHENGINE           = YES
+
+# When the SERVER_BASED_SEARCH tag is enabled the search engine will be
+# implemented using a PHP enabled web server instead of at the web client
+# using Javascript. Doxygen will generate the search PHP script and index
+# file to put on the web server. The advantage of the server
+# based approach is that it scales better to large projects and allows
+# full text search. The disadvantages are that it is more difficult to setup
+# and does not have live searching capabilities.
+
+SERVER_BASED_SEARCH    = NO
+
+#---------------------------------------------------------------------------
+# configuration options related to the LaTeX output
+#---------------------------------------------------------------------------
+
+# If the GENERATE_LATEX tag is set to YES (the default) Doxygen will
+# generate Latex output.
+
+GENERATE_LATEX         = NO
+
+# The LATEX_OUTPUT tag is used to specify where the LaTeX docs will be put.
+# If a relative path is entered the value of OUTPUT_DIRECTORY will be
+# put in front of it. If left blank `latex' will be used as the default path.
+
+LATEX_OUTPUT           = latex
+
+# The LATEX_CMD_NAME tag can be used to specify the LaTeX command name to be
+# invoked. If left blank `latex' will be used as the default command name.
+# Note that when enabling USE_PDFLATEX this option is only used for
+# generating bitmaps for formulas in the HTML output, but not in the
+# Makefile that is written to the output directory.
+
+LATEX_CMD_NAME         = latex
+
+# The MAKEINDEX_CMD_NAME tag can be used to specify the command name to
+# generate index for LaTeX. If left blank `makeindex' will be used as the
+# default command name.
+
+MAKEINDEX_CMD_NAME     = makeindex
+
+# If the COMPACT_LATEX tag is set to YES Doxygen generates more compact
+# LaTeX documents. This may be useful for small projects and may help to
+# save some trees in general.
+
+COMPACT_LATEX          = NO
+
+# The PAPER_TYPE tag can be used to set the paper type that is used
+# by the printer. Possible values are: a4, letter, legal and
+# executive. If left blank a4wide will be used.
+
+PAPER_TYPE             = a4
+
+# The EXTRA_PACKAGES tag can be to specify one or more names of LaTeX
+# packages that should be included in the LaTeX output.
+
+EXTRA_PACKAGES         =
+
+# The LATEX_HEADER tag can be used to specify a personal LaTeX header for
+# the generated latex document. The header should contain everything until
+# the first chapter. If it is left blank doxygen will generate a
+# standard header. Notice: only use this tag if you know what you are doing!
+
+LATEX_HEADER           =
+
+# The LATEX_FOOTER tag can be used to specify a personal LaTeX footer for
+# the generated latex document. The footer should contain everything after
+# the last chapter. If it is left blank doxygen will generate a
+# standard footer. Notice: only use this tag if you know what you are doing!
+
+LATEX_FOOTER           =
+
+# If the PDF_HYPERLINKS tag is set to YES, the LaTeX that is generated
+# is prepared for conversion to pdf (using ps2pdf). The pdf file will
+# contain links (just like the HTML output) instead of page references
+# This makes the output suitable for online browsing using a pdf viewer.
+
+PDF_HYPERLINKS         = YES
+
+# If the USE_PDFLATEX tag is set to YES, pdflatex will be used instead of
+# plain latex in the generated Makefile. Set this option to YES to get a
+# higher quality PDF documentation.
+
+USE_PDFLATEX           = YES
+
+# If the LATEX_BATCHMODE tag is set to YES, doxygen will add the \\batchmode.
+# command to the generated LaTeX files. This will instruct LaTeX to keep
+# running if errors occur, instead of asking the user for help.
+# This option is also used when generating formulas in HTML.
+
+LATEX_BATCHMODE        = NO
+
+# If LATEX_HIDE_INDICES is set to YES then doxygen will not
+# include the index chapters (such as File Index, Compound Index, etc.)
+# in the output.
+
+LATEX_HIDE_INDICES     = NO
+
+# If LATEX_SOURCE_CODE is set to YES then doxygen will include
+# source code with syntax highlighting in the LaTeX output.
+# Note that which sources are shown also depends on other settings
+# such as SOURCE_BROWSER.
+
+LATEX_SOURCE_CODE      = NO
+
+#---------------------------------------------------------------------------
+# configuration options related to the RTF output
+#---------------------------------------------------------------------------
+
+# If the GENERATE_RTF tag is set to YES Doxygen will generate RTF output
+# The RTF output is optimized for Word 97 and may not look very pretty with
+# other RTF readers or editors.
+
+GENERATE_RTF           = NO
+
+# The RTF_OUTPUT tag is used to specify where the RTF docs will be put.
+# If a relative path is entered the value of OUTPUT_DIRECTORY will be
+# put in front of it. If left blank `rtf' will be used as the default path.
+
+RTF_OUTPUT             = rtf
+
+# If the COMPACT_RTF tag is set to YES Doxygen generates more compact
+# RTF documents. This may be useful for small projects and may help to
+# save some trees in general.
+
+COMPACT_RTF            = NO
+
+# If the RTF_HYPERLINKS tag is set to YES, the RTF that is generated
+# will contain hyperlink fields. The RTF file will
+# contain links (just like the HTML output) instead of page references.
+# This makes the output suitable for online browsing using WORD or other
+# programs which support those fields.
+# Note: wordpad (write) and others do not support links.
+
+RTF_HYPERLINKS         = NO
+
+# Load stylesheet definitions from file. Syntax is similar to doxygen's
+# config file, i.e. a series of assignments. You only have to provide
+# replacements, missing definitions are set to their default value.
+
+RTF_STYLESHEET_FILE    =
+
+# Set optional variables used in the generation of an rtf document.
+# Syntax is similar to doxygen's config file.
+
+RTF_EXTENSIONS_FILE    =
+
+#---------------------------------------------------------------------------
+# configuration options related to the man page output
+#---------------------------------------------------------------------------
+
+# If the GENERATE_MAN tag is set to YES (the default) Doxygen will
+# generate man pages
+
+GENERATE_MAN           = NO
+
+# The MAN_OUTPUT tag is used to specify where the man pages will be put.
+# If a relative path is entered the value of OUTPUT_DIRECTORY will be
+# put in front of it. If left blank `man' will be used as the default path.
+
+MAN_OUTPUT             = man
+
+# The MAN_EXTENSION tag determines the extension that is added to
+# the generated man pages (default is the subroutine's section .3)
+
+MAN_EXTENSION          = .3
+
+# If the MAN_LINKS tag is set to YES and Doxygen generates man output,
+# then it will generate one additional man file for each entity
+# documented in the real man page(s). These additional files
+# only source the real man page, but without them the man command
+# would be unable to find the correct page. The default is NO.
+
+MAN_LINKS              = NO
+
+#---------------------------------------------------------------------------
+# configuration options related to the XML output
+#---------------------------------------------------------------------------
+
+# If the GENERATE_XML tag is set to YES Doxygen will
+# generate an XML file that captures the structure of
+# the code including all documentation.
+
+GENERATE_XML           = NO
+
+# The XML_OUTPUT tag is used to specify where the XML pages will be put.
+# If a relative path is entered the value of OUTPUT_DIRECTORY will be
+# put in front of it. If left blank `xml' will be used as the default path.
+
+XML_OUTPUT             = xml
+
+# The XML_SCHEMA tag can be used to specify an XML schema,
+# which can be used by a validating XML parser to check the
+# syntax of the XML files.
+
+XML_SCHEMA             =
+
+# The XML_DTD tag can be used to specify an XML DTD,
+# which can be used by a validating XML parser to check the
+# syntax of the XML files.
+
+XML_DTD                =
+
+# If the XML_PROGRAMLISTING tag is set to YES Doxygen will
+# dump the program listings (including syntax highlighting
+# and cross-referencing information) to the XML output. Note that
+# enabling this will significantly increase the size of the XML output.
+
+XML_PROGRAMLISTING     = YES
+
+#---------------------------------------------------------------------------
+# configuration options for the AutoGen Definitions output
+#---------------------------------------------------------------------------
+
+# If the GENERATE_AUTOGEN_DEF tag is set to YES Doxygen will
+# generate an AutoGen Definitions (see autogen.sf.net) file
+# that captures the structure of the code including all
+# documentation. Note that this feature is still experimental
+# and incomplete at the moment.
+
+GENERATE_AUTOGEN_DEF   = NO
+
+#---------------------------------------------------------------------------
+# configuration options related to the Perl module output
+#---------------------------------------------------------------------------
+
+# If the GENERATE_PERLMOD tag is set to YES Doxygen will
+# generate a Perl module file that captures the structure of
+# the code including all documentation. Note that this
+# feature is still experimental and incomplete at the
+# moment.
+
+GENERATE_PERLMOD       = NO
+
+# If the PERLMOD_LATEX tag is set to YES Doxygen will generate
+# the necessary Makefile rules, Perl scripts and LaTeX code to be able
+# to generate PDF and DVI output from the Perl module output.
+
+PERLMOD_LATEX          = NO
+
+# If the PERLMOD_PRETTY tag is set to YES the Perl module output will be
+# nicely formatted so it can be parsed by a human reader.
+# This is useful
+# if you want to understand what is going on.
+# On the other hand, if this
+# tag is set to NO the size of the Perl module output will be much smaller
+# and Perl will parse it just the same.
+
+PERLMOD_PRETTY         = YES
+
+# The names of the make variables in the generated doxyrules.make file
+# are prefixed with the string contained in PERLMOD_MAKEVAR_PREFIX.
+# This is useful so different doxyrules.make files included by the same
+# Makefile don't overwrite each other's variables.
+
+PERLMOD_MAKEVAR_PREFIX =
+
+#---------------------------------------------------------------------------
+# Configuration options related to the preprocessor
+#---------------------------------------------------------------------------
+
+# If the ENABLE_PREPROCESSING tag is set to YES (the default) Doxygen will
+# evaluate all C-preprocessor directives found in the sources and include
+# files.
+
+ENABLE_PREPROCESSING   = YES
+
+# If the MACRO_EXPANSION tag is set to YES Doxygen will expand all macro
+# names in the source code. If set to NO (the default) only conditional
+# compilation will be performed. Macro expansion can be done in a controlled
+# way by setting EXPAND_ONLY_PREDEF to YES.
+
+MACRO_EXPANSION        = NO
+
+# If the EXPAND_ONLY_PREDEF and MACRO_EXPANSION tags are both set to YES
+# then the macro expansion is limited to the macros specified with the
+# PREDEFINED and EXPAND_AS_DEFINED tags.
+
+EXPAND_ONLY_PREDEF     = NO
+
+# If the SEARCH_INCLUDES tag is set to YES (the default) the includes files
+# pointed to by INCLUDE_PATH will be searched when a #include is found.
+
+SEARCH_INCLUDES        = YES
+
+# The INCLUDE_PATH tag can be used to specify one or more directories that
+# contain include files that are not input files but should be processed by
+# the preprocessor.
+
+INCLUDE_PATH           =
+
+# You can use the INCLUDE_FILE_PATTERNS tag to specify one or more wildcard
+# patterns (like *.h and *.hpp) to filter out the header-files in the
+# directories. If left blank, the patterns specified with FILE_PATTERNS will
+# be used.
+
+INCLUDE_FILE_PATTERNS  =
+
+# The PREDEFINED tag can be used to specify one or more macro names that
+# are defined before the preprocessor is started (similar to the -D option of
+# gcc). The argument of the tag is a list of macros of the form: name
+# or name=definition (no spaces). If the definition and the = are
+# omitted =1 is assumed. To prevent a macro definition from being
+# undefined via #undef or recursively expanded use the := operator
+# instead of the = operator.
+
+PREDEFINED             =
+
+# If the MACRO_EXPANSION and EXPAND_ONLY_PREDEF tags are set to YES then
+# this tag can be used to specify a list of macro names that should be expanded.
+# The macro definition that is found in the sources will be used.
+# Use the PREDEFINED tag if you want to use a different macro definition that
+# overrules the definition found in the source code.
+
+EXPAND_AS_DEFINED      =
+
+# If the SKIP_FUNCTION_MACROS tag is set to YES (the default) then
+# doxygen's preprocessor will remove all references to function-like macros
+# that are alone on a line, have an all uppercase name, and do not end with a
+# semicolon, because these will confuse the parser if not removed.
+
+SKIP_FUNCTION_MACROS   = YES
+
+#---------------------------------------------------------------------------
+# Configuration::additions related to external references
+#---------------------------------------------------------------------------
+
+# The TAGFILES option can be used to specify one or more tagfiles.
+# Optionally an initial location of the external documentation
+# can be added for each tagfile. The format of a tag file without
+# this location is as follows:
+#
+# TAGFILES = file1 file2 ...
+# Adding location for the tag files is done as follows:
+#
+# TAGFILES = file1=loc1 "file2 = loc2" ...
+# where "loc1" and "loc2" can be relative or absolute paths or
+# URLs. If a location is present for each tag, the installdox tool
+# does not have to be run to correct the links.
+# Note that each tag file must have a unique name
+# (where the name does NOT include the path)
+# If a tag file is not located in the directory in which doxygen
+# is run, you must also specify the path to the tagfile here.
+
+TAGFILES               =
+
+# When a file name is specified after GENERATE_TAGFILE, doxygen will create
+# a tag file that is based on the input files it reads.
+
+GENERATE_TAGFILE       =
+
+# If the ALLEXTERNALS tag is set to YES all external classes will be listed
+# in the class index. If set to NO only the inherited external classes
+# will be listed.
+
+ALLEXTERNALS           = NO
+
+# If the EXTERNAL_GROUPS tag is set to YES all external groups will be listed
+# in the modules index. If set to NO, only the current project's groups will
+# be listed.
+
+EXTERNAL_GROUPS        = YES
+
+# The PERL_PATH should be the absolute path and name of the perl script
+# interpreter (i.e. the result of `which perl').
+
+PERL_PATH              = /usr/bin/perl
+
+#---------------------------------------------------------------------------
+# Configuration options related to the dot tool
+#---------------------------------------------------------------------------
+
+# If the CLASS_DIAGRAMS tag is set to YES (the default) Doxygen will
+# generate a inheritance diagram (in HTML, RTF and LaTeX) for classes with base
+# or super classes. Setting the tag to NO turns the diagrams off. Note that
+# this option also works with HAVE_DOT disabled, but it is recommended to
+# install and use dot, since it yields more powerful graphs.
+
+CLASS_DIAGRAMS         = YES
+
+# You can define message sequence charts within doxygen comments using the \msc
+# command. Doxygen will then run the mscgen tool (see
+# http://www.mcternan.me.uk/mscgen/) to produce the chart and insert it in the
+# documentation. The MSCGEN_PATH tag allows you to specify the directory where
+# the mscgen tool resides. If left empty the tool is assumed to be found in the
+# default search path.
+
+MSCGEN_PATH            =
+
+# If set to YES, the inheritance and collaboration graphs will hide
+# inheritance and usage relations if the target is undocumented
+# or is not a class.
+
+HIDE_UNDOC_RELATIONS   = YES
+
+# If you set the HAVE_DOT tag to YES then doxygen will assume the dot tool is
+# available from the path. This tool is part of Graphviz, a graph visualization
+# toolkit from AT&T and Lucent Bell Labs. The other options in this section
+# have no effect if this option is set to NO (the default)
+
+HAVE_DOT               = NO
+
+# The DOT_NUM_THREADS specifies the number of dot invocations doxygen is
+# allowed to run in parallel. When set to 0 (the default) doxygen will
+# base this on the number of processors available in the system. You can set it
+# explicitly to a value larger than 0 to get control over the balance
+# between CPU load and processing speed.
+
+DOT_NUM_THREADS        = 0
+
+# By default doxygen will write a font called Helvetica to the output
+# directory and reference it in all dot files that doxygen generates.
+# When you want a differently looking font you can specify the font name
+# using DOT_FONTNAME. You need to make sure dot is able to find the font,
+# which can be done by putting it in a standard location or by setting the
+# DOTFONTPATH environment variable or by setting DOT_FONTPATH to the directory
+# containing the font.
+
+DOT_FONTNAME           = Helvetica
+
+# The DOT_FONTSIZE tag can be used to set the size of the font of dot graphs.
+# The default size is 10pt.
+
+DOT_FONTSIZE           = 10
+
+# By default doxygen will tell dot to use the output directory to look for the
+# FreeSans.ttf font (which doxygen will put there itself). If you specify a
+# different font using DOT_FONTNAME you can set the path where dot
+# can find it using this tag.
+
+DOT_FONTPATH           =
+
+# If the CLASS_GRAPH and HAVE_DOT tags are set to YES then doxygen
+# will generate a graph for each documented class showing the direct and
+# indirect inheritance relations. Setting this tag to YES will force the
+# the CLASS_DIAGRAMS tag to NO.
+
+CLASS_GRAPH            = YES
+
+# If the COLLABORATION_GRAPH and HAVE_DOT tags are set to YES then doxygen
+# will generate a graph for each documented class showing the direct and
+# indirect implementation dependencies (inheritance, containment, and
+# class references variables) of the class with other documented classes.
+
+COLLABORATION_GRAPH    = YES
+
+# If the GROUP_GRAPHS and HAVE_DOT tags are set to YES then doxygen
+# will generate a graph for groups, showing the direct groups dependencies
+
+GROUP_GRAPHS           = YES
+
+# If the UML_LOOK tag is set to YES doxygen will generate inheritance and
+# collaboration diagrams in a style similar to the OMG's Unified Modeling
+# Language.
+
+UML_LOOK               = NO
+
+# If set to YES, the inheritance and collaboration graphs will show the
+# relations between templates and their instances.
+
+TEMPLATE_RELATIONS     = NO
+
+# If the ENABLE_PREPROCESSING, SEARCH_INCLUDES, INCLUDE_GRAPH, and HAVE_DOT
+# tags are set to YES then doxygen will generate a graph for each documented
+# file showing the direct and indirect include dependencies of the file with
+# other documented files.
+
+INCLUDE_GRAPH          = YES
+
+# If the ENABLE_PREPROCESSING, SEARCH_INCLUDES, INCLUDED_BY_GRAPH, and
+# HAVE_DOT tags are set to YES then doxygen will generate a graph for each
+# documented header file showing the documented files that directly or
+# indirectly include this file.
+
+INCLUDED_BY_GRAPH      = YES
+
+# If the CALL_GRAPH and HAVE_DOT options are set to YES then
+# doxygen will generate a call dependency graph for every global function
+# or class method. Note that enabling this option will significantly increase
+# the time of a run. So in most cases it will be better to enable call graphs
+# for selected functions only using the \callgraph command.
+
+CALL_GRAPH             = NO
+
+# If the CALLER_GRAPH and HAVE_DOT tags are set to YES then
+# doxygen will generate a caller dependency graph for every global function
+# or class method. Note that enabling this option will significantly increase
+# the time of a run. So in most cases it will be better to enable caller
+# graphs for selected functions only using the \callergraph command.
+
+CALLER_GRAPH           = NO
+
+# If the GRAPHICAL_HIERARCHY and HAVE_DOT tags are set to YES then doxygen
+# will generate a graphical hierarchy of all classes instead of a textual one.
+
+GRAPHICAL_HIERARCHY    = YES
+
+# If the DIRECTORY_GRAPH, SHOW_DIRECTORIES and HAVE_DOT tags are set to YES
+# then doxygen will show the dependencies a directory has on other directories
+# in a graphical way. The dependency relations are determined by the #include
+# relations between the files in the directories.
+
+DIRECTORY_GRAPH        = YES
+
+# The DOT_IMAGE_FORMAT tag can be used to set the image format of the images
+# generated by dot. Possible values are svg, png, jpg, or gif.
+# If left blank png will be used.
+
+DOT_IMAGE_FORMAT       = png
+
+# The tag DOT_PATH can be used to specify the path where the dot tool can be
+# found. If left blank, it is assumed the dot tool can be found in the path.
+
+DOT_PATH               =
+
+# The DOTFILE_DIRS tag can be used to specify one or more directories that
+# contain dot files that are included in the documentation (see the
+# \dotfile command).
+
+DOTFILE_DIRS           =
+
+# The MSCFILE_DIRS tag can be used to specify one or more directories that
+# contain msc files that are included in the documentation (see the
+# \mscfile command).
+
+MSCFILE_DIRS           =
+
+# The DOT_GRAPH_MAX_NODES tag can be used to set the maximum number of
+# nodes that will be shown in the graph. If the number of nodes in a graph
+# becomes larger than this value, doxygen will truncate the graph, which is
+# visualized by representing a node as a red box. Note that doxygen if the
+# number of direct children of the root node in a graph is already larger than
+# DOT_GRAPH_MAX_NODES then the graph will not be shown at all. Also note
+# that the size of a graph can be further restricted by MAX_DOT_GRAPH_DEPTH.
+
+DOT_GRAPH_MAX_NODES    = 50
+
+# The MAX_DOT_GRAPH_DEPTH tag can be used to set the maximum depth of the
+# graphs generated by dot. A depth value of 3 means that only nodes reachable
+# from the root by following a path via at most 3 edges will be shown. Nodes
+# that lay further from the root node will be omitted. Note that setting this
+# option to 1 or 2 may greatly reduce the computation time needed for large
+# code bases. Also note that the size of a graph can be further restricted by
+# DOT_GRAPH_MAX_NODES. Using a depth of 0 means no depth restriction.
+
+MAX_DOT_GRAPH_DEPTH    = 0
+
+# Set the DOT_TRANSPARENT tag to YES to generate images with a transparent
+# background. This is disabled by default, because dot on Windows does not
+# seem to support this out of the box. Warning: Depending on the platform used,
+# enabling this option may lead to badly anti-aliased labels on the edges of
+# a graph (i.e. they become hard to read).
+
+DOT_TRANSPARENT        = NO
+
+# Set the DOT_MULTI_TARGETS tag to YES allow dot to generate multiple output
+# files in one run (i.e. multiple -o and -T options on the command line). This
+# makes dot run faster, but since only newer versions of dot (>1.8.10)
+# support this, this feature is disabled by default.
+
+DOT_MULTI_TARGETS      = YES
+
+# If the GENERATE_LEGEND tag is set to YES (the default) Doxygen will
+# generate a legend page explaining the meaning of the various boxes and
+# arrows in the dot generated graphs.
+
+GENERATE_LEGEND        = YES
+
+# If the DOT_CLEANUP tag is set to YES (the default) Doxygen will
+# remove the intermediate dot files that are used to generate
+# the various graphs.
+
+DOT_CLEANUP            = YES
+
+;INPUT=core/include/ignite core/src
+;EXCLUDE=core/include/ignite/impl core/os/linux/include/ignite/impl core/os/linux/src/impl core/os/win/include/ignite/impl core/os/win/src/impl core/src/impl
+;STRIP_FROM_PATH=core/include/ignite core/src
+;OUTPUT_DIRECTORY=doc
+;PROJECT_LOGO=../../../assembly/docfiles/ignite_logo.png


[47/59] [abbrv] ignite git commit: ignite-2065: rename "portable" classes to "binary"

Posted by ak...@apache.org.
http://git-wip-us.apache.org/repos/asf/ignite/blob/71ad9cea/modules/core/src/main/java/org/apache/ignite/internal/binary/builder/PortableValueWithType.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/binary/builder/PortableValueWithType.java b/modules/core/src/main/java/org/apache/ignite/internal/binary/builder/PortableValueWithType.java
deleted file mode 100644
index 6c5ddfe..0000000
--- a/modules/core/src/main/java/org/apache/ignite/internal/binary/builder/PortableValueWithType.java
+++ /dev/null
@@ -1,77 +0,0 @@
-/*
- * 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.binary.builder;
-
-import org.apache.ignite.internal.binary.BinaryWriterExImpl;
-import org.apache.ignite.internal.binary.BinaryWriterExImpl;
-import org.apache.ignite.internal.util.typedef.internal.S;
-
-/**
- *
- */
-class PortableValueWithType implements PortableLazyValue {
-    /** */
-    private byte type;
-
-    /** */
-    private Object val;
-
-    /**
-     * @param type Type
-     * @param val Value.
-     */
-    PortableValueWithType(byte type, Object val) {
-        this.type = type;
-        this.val = val;
-    }
-
-    /** {@inheritDoc} */
-    @Override public void writeTo(BinaryWriterExImpl writer, PortableBuilderSerializer ctx) {
-        if (val instanceof PortableBuilderSerializationAware)
-            ((PortableBuilderSerializationAware)val).writeTo(writer, ctx);
-        else
-            ctx.writeValue(writer, val);
-    }
-
-    /**
-     * @return Type ID.
-     */
-    public int typeId() {
-        return type;
-    }
-
-    /** {@inheritDoc} */
-    @Override public Object value() {
-        if (val instanceof PortableLazyValue)
-            return ((PortableLazyValue)val).value();
-
-        return val;
-    }
-
-    /**
-     * @param val New value.
-     */
-    public void value(Object val) {
-        this.val = val;
-    }
-
-    /** {@inheritDoc} */
-    @Override public String toString() {
-        return S.toString(PortableValueWithType.class, this);
-    }
-}

http://git-wip-us.apache.org/repos/asf/ignite/blob/71ad9cea/modules/core/src/main/java/org/apache/ignite/internal/binary/streams/BinaryAbstractInputStream.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/binary/streams/BinaryAbstractInputStream.java b/modules/core/src/main/java/org/apache/ignite/internal/binary/streams/BinaryAbstractInputStream.java
new file mode 100644
index 0000000..e3be794
--- /dev/null
+++ b/modules/core/src/main/java/org/apache/ignite/internal/binary/streams/BinaryAbstractInputStream.java
@@ -0,0 +1,379 @@
+/*
+ * 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.binary.streams;
+
+import org.apache.ignite.binary.BinaryObjectException;
+
+/**
+ * Portable abstract input stream.
+ */
+public abstract class BinaryAbstractInputStream extends BinaryAbstractStream
+    implements BinaryInputStream {
+    /** Length of data inside array. */
+    protected int len;
+
+    /** {@inheritDoc} */
+    @Override public byte readByte() {
+        ensureEnoughData(1);
+
+        return readByteAndShift();
+    }
+
+    /** {@inheritDoc} */
+    @Override public byte[] readByteArray(int cnt) {
+        ensureEnoughData(cnt);
+
+        byte[] res = new byte[cnt];
+
+        copyAndShift(res, BYTE_ARR_OFF, cnt);
+
+        return res;
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean readBoolean() {
+        return readByte() == BYTE_ONE;
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean[] readBooleanArray(int cnt) {
+        ensureEnoughData(cnt);
+
+        boolean[] res = new boolean[cnt];
+
+        copyAndShift(res, BOOLEAN_ARR_OFF, cnt);
+
+        return res;
+    }
+
+    /** {@inheritDoc} */
+    @Override public short readShort() {
+        ensureEnoughData(2);
+
+        short res = readShortFast();
+
+        shift(2);
+
+        if (!LITTLE_ENDIAN)
+            res = Short.reverseBytes(res);
+
+        return res;
+    }
+
+    /** {@inheritDoc} */
+    @Override public short[] readShortArray(int cnt) {
+        int len = cnt << 1;
+
+        ensureEnoughData(len);
+
+        short[] res = new short[cnt];
+
+        copyAndShift(res, SHORT_ARR_OFF, len);
+
+        if (!LITTLE_ENDIAN) {
+            for (int i = 0; i < res.length; i++)
+                res[i] = Short.reverseBytes(res[i]);
+        }
+
+        return res;
+    }
+
+    /** {@inheritDoc} */
+    @Override public char readChar() {
+        ensureEnoughData(2);
+
+        char res = readCharFast();
+
+        shift(2);
+
+        if (!LITTLE_ENDIAN)
+            res = Character.reverseBytes(res);
+
+        return res;
+    }
+
+    /** {@inheritDoc} */
+    @Override public char[] readCharArray(int cnt) {
+        int len = cnt << 1;
+
+        ensureEnoughData(len);
+
+        char[] res = new char[cnt];
+
+        copyAndShift(res, CHAR_ARR_OFF, len);
+
+        if (!LITTLE_ENDIAN) {
+            for (int i = 0; i < res.length; i++)
+                res[i] = Character.reverseBytes(res[i]);
+        }
+
+        return res;
+    }
+
+    /** {@inheritDoc} */
+    @Override public int readInt() {
+        ensureEnoughData(4);
+
+        int res = readIntFast();
+
+        shift(4);
+
+        if (!LITTLE_ENDIAN)
+            res = Integer.reverseBytes(res);
+
+        return res;
+    }
+
+    /** {@inheritDoc} */
+    @Override public int[] readIntArray(int cnt) {
+        int len = cnt << 2;
+
+        ensureEnoughData(len);
+
+        int[] res = new int[cnt];
+
+        copyAndShift(res, INT_ARR_OFF, len);
+
+        if (!LITTLE_ENDIAN) {
+            for (int i = 0; i < res.length; i++)
+                res[i] = Integer.reverseBytes(res[i]);
+        }
+
+        return res;
+    }
+
+    /** {@inheritDoc} */
+    @Override public byte readBytePositioned(int pos) {
+        int delta = pos + 1 - this.pos;
+
+        if (delta > 0)
+            ensureEnoughData(delta);
+
+        return readBytePositioned0(pos);
+    }
+
+    /** {@inheritDoc} */
+    @Override public short readShortPositioned(int pos) {
+        int delta = pos + 2 - this.pos;
+
+        if (delta > 0)
+            ensureEnoughData(delta);
+
+        return readShortPositioned0(pos);
+    }
+
+    /** {@inheritDoc} */
+    @Override public int readIntPositioned(int pos) {
+        int delta = pos + 4 - this.pos;
+
+        if (delta > 0)
+            ensureEnoughData(delta);
+
+        return readIntPositioned0(pos);
+    }
+
+    /** {@inheritDoc} */
+    @Override public float readFloat() {
+        return Float.intBitsToFloat(readInt());
+    }
+
+    /** {@inheritDoc} */
+    @Override public float[] readFloatArray(int cnt) {
+        int len = cnt << 2;
+
+        ensureEnoughData(len);
+
+        float[] res = new float[cnt];
+
+        if (LITTLE_ENDIAN)
+            copyAndShift(res, FLOAT_ARR_OFF, len);
+        else {
+            for (int i = 0; i < res.length; i++) {
+                int x = readIntFast();
+
+                shift(4);
+
+                res[i] = Float.intBitsToFloat(Integer.reverseBytes(x));
+            }
+        }
+
+        return res;
+    }
+
+    /** {@inheritDoc} */
+    @Override public long readLong() {
+        ensureEnoughData(8);
+
+        long res = readLongFast();
+
+        shift(8);
+
+        if (!LITTLE_ENDIAN)
+            res = Long.reverseBytes(res);
+
+        return res;
+    }
+
+    /** {@inheritDoc} */
+    @Override public long[] readLongArray(int cnt) {
+        int len = cnt << 3;
+
+        ensureEnoughData(len);
+
+        long[] res = new long[cnt];
+
+        copyAndShift(res, LONG_ARR_OFF, len);
+
+        if (!LITTLE_ENDIAN) {
+            for (int i = 0; i < res.length; i++)
+                res[i] = Long.reverseBytes(res[i]);
+        }
+
+        return res;
+    }
+
+    /** {@inheritDoc} */
+    @Override public double readDouble() {
+        return Double.longBitsToDouble(readLong());
+    }
+
+    /** {@inheritDoc} */
+    @Override public double[] readDoubleArray(int cnt) {
+        int len = cnt << 3;
+
+        ensureEnoughData(len);
+
+        double[] res = new double[cnt];
+
+        if (LITTLE_ENDIAN)
+            copyAndShift(res, DOUBLE_ARR_OFF, len);
+        else {
+            for (int i = 0; i < res.length; i++) {
+                long x = readLongFast();
+
+                shift(8);
+
+                res[i] = Double.longBitsToDouble(Long.reverseBytes(x));
+            }
+        }
+
+        return res;
+    }
+
+    /** {@inheritDoc} */
+    @Override public int read(byte[] arr, int off, int len) {
+        if (len > remaining())
+            len = remaining();
+
+        copyAndShift(arr, BYTE_ARR_OFF + off, len);
+
+        return len;
+    }
+
+    /** {@inheritDoc} */
+    @Override public void position(int pos) {
+        if (remaining() + this.pos < pos)
+            throw new BinaryObjectException("Position is out of bounds: " + pos);
+        else
+            this.pos = pos;
+    }
+
+    /** {@inheritDoc} */
+    @Override public long offheapPointer() {
+        return 0;
+    }
+
+    /**
+     * Ensure that there is enough data.
+     *
+     * @param cnt Length.
+     */
+    protected void ensureEnoughData(int cnt) {
+        if (remaining() < cnt)
+            throw new BinaryObjectException("Not enough data to read the value [position=" + pos +
+                ", requiredBytes=" + cnt + ", remainingBytes=" + remaining() + ']');
+    }
+
+    /**
+     * Read next byte from the stream and perform shift.
+     *
+     * @return Next byte.
+     */
+    protected abstract byte readByteAndShift();
+
+    /**
+     * Copy data to target object shift position afterwards.
+     *
+     * @param target Target.
+     * @param off Offset.
+     * @param len Length.
+     */
+    protected abstract void copyAndShift(Object target, long off, int len);
+
+    /**
+     * Read short value (fast path).
+     *
+     * @return Short value.
+     */
+    protected abstract short readShortFast();
+
+    /**
+     * Read char value (fast path).
+     *
+     * @return Char value.
+     */
+    protected abstract char readCharFast();
+
+    /**
+     * Read int value (fast path).
+     *
+     * @return Int value.
+     */
+    protected abstract int readIntFast();
+
+    /**
+     * Read long value (fast path).
+     *
+     * @return Long value.
+     */
+    protected abstract long readLongFast();
+
+    /**
+     * Internal routine for positioned byte value read.
+     *
+     * @param pos Position.
+     * @return Int value.
+     */
+    protected abstract byte readBytePositioned0(int pos);
+
+    /**
+     * Internal routine for positioned short value read.
+     *
+     * @param pos Position.
+     * @return Int value.
+     */
+    protected abstract short readShortPositioned0(int pos);
+
+    /**
+     * Internal routine for positioned int value read.
+     *
+     * @param pos Position.
+     * @return Int value.
+     */
+    protected abstract int readIntPositioned0(int pos);
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/71ad9cea/modules/core/src/main/java/org/apache/ignite/internal/binary/streams/BinaryAbstractOutputStream.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/binary/streams/BinaryAbstractOutputStream.java b/modules/core/src/main/java/org/apache/ignite/internal/binary/streams/BinaryAbstractOutputStream.java
new file mode 100644
index 0000000..199ee71
--- /dev/null
+++ b/modules/core/src/main/java/org/apache/ignite/internal/binary/streams/BinaryAbstractOutputStream.java
@@ -0,0 +1,347 @@
+/*
+ * 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.binary.streams;
+
+/**
+ * Base portable output stream.
+ */
+public abstract class BinaryAbstractOutputStream extends BinaryAbstractStream
+    implements BinaryOutputStream {
+    /** Minimal capacity when it is reasonable to start doubling resize. */
+    private static final int MIN_CAP = 256;
+
+    /** {@inheritDoc} */
+    @Override public void writeByte(byte val) {
+        ensureCapacity(pos + 1);
+
+        writeByteAndShift(val);
+    }
+
+    /** {@inheritDoc} */
+    @Override public void writeByteArray(byte[] val) {
+        ensureCapacity(pos + val.length);
+
+        copyAndShift(val, BYTE_ARR_OFF, val.length);
+    }
+
+    /** {@inheritDoc} */
+    @Override public void writeBoolean(boolean val) {
+        writeByte(val ? BYTE_ONE : BYTE_ZERO);
+    }
+
+    /** {@inheritDoc} */
+    @Override public void writeBooleanArray(boolean[] val) {
+        ensureCapacity(pos + val.length);
+
+        copyAndShift(val, BOOLEAN_ARR_OFF, val.length);
+    }
+
+    /** {@inheritDoc} */
+    @Override public void writeShort(short val) {
+        ensureCapacity(pos + 2);
+
+        if (!LITTLE_ENDIAN)
+            val = Short.reverseBytes(val);
+
+        writeShortFast(val);
+
+        shift(2);
+    }
+
+    /** {@inheritDoc} */
+    @Override public void writeShortArray(short[] val) {
+        int cnt = val.length << 1;
+
+        ensureCapacity(pos + cnt);
+
+        if (LITTLE_ENDIAN)
+            copyAndShift(val, SHORT_ARR_OFF, cnt);
+        else {
+            for (short item : val)
+                writeShortFast(Short.reverseBytes(item));
+
+            shift(cnt);
+        }
+    }
+
+    /** {@inheritDoc} */
+    @Override public void writeChar(char val) {
+        ensureCapacity(pos + 2);
+
+        if (!LITTLE_ENDIAN)
+            val = Character.reverseBytes(val);
+
+        writeCharFast(val);
+
+        shift(2);
+    }
+
+    /** {@inheritDoc} */
+    @Override public void writeCharArray(char[] val) {
+        int cnt = val.length << 1;
+
+        ensureCapacity(pos + cnt);
+
+        if (LITTLE_ENDIAN)
+            copyAndShift(val, CHAR_ARR_OFF, cnt);
+        else {
+            for (char item : val)
+                writeCharFast(Character.reverseBytes(item));
+
+            shift(cnt);
+        }
+    }
+
+    /** {@inheritDoc} */
+    @Override public void writeInt(int val) {
+        ensureCapacity(pos + 4);
+
+        if (!LITTLE_ENDIAN)
+            val = Integer.reverseBytes(val);
+
+        writeIntFast(val);
+
+        shift(4);
+    }
+
+    /** {@inheritDoc} */
+    @Override public void writeShort(int pos, short val) {
+        ensureCapacity(pos + 2);
+
+        unsafeWriteShort(pos, val);
+    }
+
+    /** {@inheritDoc} */
+    @Override public void writeInt(int pos, int val) {
+        ensureCapacity(pos + 4);
+
+        unsafeWriteInt(pos, val);
+    }
+
+    /** {@inheritDoc} */
+    @Override public void writeIntArray(int[] val) {
+        int cnt = val.length << 2;
+
+        ensureCapacity(pos + cnt);
+
+        if (LITTLE_ENDIAN)
+            copyAndShift(val, INT_ARR_OFF, cnt);
+        else {
+            for (int item : val)
+                writeIntFast(Integer.reverseBytes(item));
+
+            shift(cnt);
+        }
+    }
+
+    /** {@inheritDoc} */
+    @Override public void writeFloat(float val) {
+        writeInt(Float.floatToIntBits(val));
+    }
+
+    /** {@inheritDoc} */
+    @Override public void writeFloatArray(float[] val) {
+        int cnt = val.length << 2;
+
+        ensureCapacity(pos + cnt);
+
+        if (LITTLE_ENDIAN)
+            copyAndShift(val, FLOAT_ARR_OFF, cnt);
+        else {
+            for (float item : val) {
+                writeIntFast(Integer.reverseBytes(Float.floatToIntBits(item)));
+
+                shift(4);
+            }
+        }
+    }
+
+    /** {@inheritDoc} */
+    @Override public void writeLong(long val) {
+        ensureCapacity(pos + 8);
+
+        if (!LITTLE_ENDIAN)
+            val = Long.reverseBytes(val);
+
+        writeLongFast(val);
+
+        shift(8);
+    }
+
+    /** {@inheritDoc} */
+    @Override public void writeLongArray(long[] val) {
+        int cnt = val.length << 3;
+
+        ensureCapacity(pos + cnt);
+
+        if (LITTLE_ENDIAN)
+            copyAndShift(val, LONG_ARR_OFF, cnt);
+        else {
+            for (long item : val)
+                writeLongFast(Long.reverseBytes(item));
+
+            shift(cnt);
+        }
+    }
+
+    /** {@inheritDoc} */
+    @Override public void writeDouble(double val) {
+        writeLong(Double.doubleToLongBits(val));
+    }
+
+    /** {@inheritDoc} */
+    @Override public void writeDoubleArray(double[] val) {
+        int cnt = val.length << 3;
+
+        ensureCapacity(pos + cnt);
+
+        if (LITTLE_ENDIAN)
+            copyAndShift(val, DOUBLE_ARR_OFF, cnt);
+        else {
+            for (double item : val) {
+                writeLongFast(Long.reverseBytes(Double.doubleToLongBits(item)));
+
+                shift(8);
+            }
+        }
+    }
+
+    /** {@inheritDoc} */
+    @Override public void write(byte[] arr, int off, int len) {
+        ensureCapacity(pos + len);
+
+        copyAndShift(arr, BYTE_ARR_OFF + off, len);
+    }
+
+    /** {@inheritDoc} */
+    @Override public void write(long addr, int cnt) {
+        ensureCapacity(pos + cnt);
+
+        copyAndShift(null, addr, cnt);
+    }
+
+    /** {@inheritDoc} */
+    @Override public void position(int pos) {
+        ensureCapacity(pos);
+
+        unsafePosition(pos);
+    }
+
+    /** {@inheritDoc} */
+    @Override public long offheapPointer() {
+        return 0;
+    }
+
+    /** {@inheritDoc} */
+    @Override public void unsafeEnsure(int cap) {
+        ensureCapacity(pos + cap);
+    }
+
+    /** {@inheritDoc} */
+    @Override public void unsafePosition(int pos) {
+        this.pos = pos;
+    }
+
+    /** {@inheritDoc} */
+    @Override public void unsafeWriteBoolean(boolean val) {
+        unsafeWriteByte(val ? BYTE_ONE : BYTE_ZERO);
+    }
+
+    /** {@inheritDoc} */
+    @Override public void unsafeWriteFloat(float val) {
+        unsafeWriteInt(Float.floatToIntBits(val));
+    }
+
+    /** {@inheritDoc} */
+    @Override public void unsafeWriteDouble(double val) {
+        unsafeWriteLong(Double.doubleToLongBits(val));
+    }
+
+    /**
+     * Calculate new capacity.
+     *
+     * @param curCap Current capacity.
+     * @param reqCap Required capacity.
+     * @return New capacity.
+     */
+    protected static int capacity(int curCap, int reqCap) {
+        int newCap;
+
+        if (reqCap < MIN_CAP)
+            newCap = MIN_CAP;
+        else {
+            newCap = curCap << 1;
+
+            if (newCap < reqCap)
+                newCap = reqCap;
+        }
+
+        return newCap;
+    }
+
+    /**
+     * Write next byte to the stream.
+     *
+     * @param val Value.
+     */
+    protected abstract void writeByteAndShift(byte val);
+
+    /**
+     * Copy source object to the stream shift position afterwards.
+     *
+     * @param src Source.
+     * @param off Offset.
+     * @param len Length.
+     */
+    protected abstract void copyAndShift(Object src, long off, int len);
+
+    /**
+     * Write short value (fast path).
+     *
+     * @param val Short value.
+     */
+    protected abstract void writeShortFast(short val);
+
+    /**
+     * Write char value (fast path).
+     *
+     * @param val Char value.
+     */
+    protected abstract void writeCharFast(char val);
+
+    /**
+     * Write int value (fast path).
+     *
+     * @param val Int value.
+     */
+    protected abstract void writeIntFast(int val);
+
+    /**
+     * Write long value (fast path).
+     *
+     * @param val Long value.
+     */
+    protected abstract void writeLongFast(long val);
+
+    /**
+     * Ensure capacity.
+     *
+     * @param cnt Required byte count.
+     */
+    protected abstract void ensureCapacity(int cnt);
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/71ad9cea/modules/core/src/main/java/org/apache/ignite/internal/binary/streams/BinaryAbstractStream.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/binary/streams/BinaryAbstractStream.java b/modules/core/src/main/java/org/apache/ignite/internal/binary/streams/BinaryAbstractStream.java
new file mode 100644
index 0000000..ce57631
--- /dev/null
+++ b/modules/core/src/main/java/org/apache/ignite/internal/binary/streams/BinaryAbstractStream.java
@@ -0,0 +1,80 @@
+/*
+ * 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.binary.streams;
+
+import java.nio.ByteOrder;
+import org.apache.ignite.internal.util.GridUnsafe;
+import sun.misc.Unsafe;
+
+/**
+ * Portable abstract stream.
+ */
+public abstract class BinaryAbstractStream implements BinaryStream {
+    /** Byte: zero. */
+    protected static final byte BYTE_ZERO = 0;
+
+    /** Byte: one. */
+    protected static final byte BYTE_ONE = 1;
+
+    /** Whether little endian is used on the platform. */
+    protected static final boolean LITTLE_ENDIAN = ByteOrder.nativeOrder() == ByteOrder.LITTLE_ENDIAN;
+
+    /** Unsafe instance. */
+    protected static final Unsafe UNSAFE = GridUnsafe.unsafe();
+
+    /** Array offset: boolean. */
+    protected static final long BOOLEAN_ARR_OFF = UNSAFE.arrayBaseOffset(boolean[].class);
+
+    /** Array offset: byte. */
+    protected static final long BYTE_ARR_OFF = UNSAFE.arrayBaseOffset(byte[].class);
+
+    /** Array offset: short. */
+    protected static final long SHORT_ARR_OFF = UNSAFE.arrayBaseOffset(short[].class);
+
+    /** Array offset: char. */
+    protected static final long CHAR_ARR_OFF = UNSAFE.arrayBaseOffset(char[].class);
+
+    /** Array offset: int. */
+    protected static final long INT_ARR_OFF = UNSAFE.arrayBaseOffset(int[].class);
+
+    /** Array offset: float. */
+    protected static final long FLOAT_ARR_OFF = UNSAFE.arrayBaseOffset(float[].class);
+
+    /** Array offset: long. */
+    protected static final long LONG_ARR_OFF = UNSAFE.arrayBaseOffset(long[].class);
+
+    /** Array offset: double. */
+    protected static final long DOUBLE_ARR_OFF = UNSAFE.arrayBaseOffset(double[].class);
+
+    /** Position. */
+    protected int pos;
+
+    /** {@inheritDoc} */
+    @Override public int position() {
+        return pos;
+    }
+
+    /**
+     * Shift position.
+     *
+     * @param cnt Byte count.
+     */
+    protected void shift(int cnt) {
+        pos += cnt;
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/71ad9cea/modules/core/src/main/java/org/apache/ignite/internal/binary/streams/BinaryHeapInputStream.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/binary/streams/BinaryHeapInputStream.java b/modules/core/src/main/java/org/apache/ignite/internal/binary/streams/BinaryHeapInputStream.java
new file mode 100644
index 0000000..502b9dc
--- /dev/null
+++ b/modules/core/src/main/java/org/apache/ignite/internal/binary/streams/BinaryHeapInputStream.java
@@ -0,0 +1,166 @@
+/*
+ * 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.binary.streams;
+
+import java.util.Arrays;
+
+/**
+ * Portable off-heap input stream.
+ */
+public final class BinaryHeapInputStream extends BinaryAbstractInputStream {
+    /**
+     * Create stream with pointer set at the given position.
+     *
+     * @param data Data.
+     * @param pos Position.
+     * @return Stream.
+     */
+    public static BinaryHeapInputStream create(byte[] data, int pos) {
+        assert pos < data.length;
+
+        BinaryHeapInputStream stream = new BinaryHeapInputStream(data);
+
+        stream.pos = pos;
+
+        return stream;
+    }
+
+    /** Data. */
+    private byte[] data;
+
+    /**
+     * Constructor.
+     *
+     * @param data Data.
+     */
+    public BinaryHeapInputStream(byte[] data) {
+        this.data = data;
+
+        len = data.length;
+    }
+
+    /**
+     * @return Copy of this stream.
+     */
+    public BinaryHeapInputStream copy() {
+        BinaryHeapInputStream in = new BinaryHeapInputStream(Arrays.copyOf(data, data.length));
+
+        in.position(pos);
+
+        return in;
+    }
+
+    /**
+     * Method called from JNI to resize stream.
+     *
+     * @param len Required length.
+     * @return Underlying byte array.
+     */
+    public byte[] resize(int len) {
+        if (data.length < len) {
+            byte[] data0 = new byte[len];
+
+            UNSAFE.copyMemory(data, BYTE_ARR_OFF, data0, BYTE_ARR_OFF, data.length);
+
+            data = data0;
+        }
+
+        return data;
+    }
+
+    /** {@inheritDoc} */
+    @Override public int remaining() {
+        return data.length - pos;
+    }
+
+    /** {@inheritDoc} */
+    @Override public byte[] array() {
+        return data;
+    }
+
+    /** {@inheritDoc} */
+    @Override public byte[] arrayCopy() {
+        byte[] res = new byte[len];
+
+        UNSAFE.copyMemory(data, BYTE_ARR_OFF, res, BYTE_ARR_OFF, res.length);
+
+        return res;
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean hasArray() {
+        return true;
+    }
+
+    /** {@inheritDoc} */
+    @Override protected byte readByteAndShift() {
+        return data[pos++];
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void copyAndShift(Object target, long off, int len) {
+        UNSAFE.copyMemory(data, BYTE_ARR_OFF + pos, target, off, len);
+
+        shift(len);
+    }
+
+    /** {@inheritDoc} */
+    @Override protected short readShortFast() {
+        return UNSAFE.getShort(data, BYTE_ARR_OFF + pos);
+    }
+
+    /** {@inheritDoc} */
+    @Override protected char readCharFast() {
+        return UNSAFE.getChar(data, BYTE_ARR_OFF + pos);
+    }
+
+    /** {@inheritDoc} */
+    @Override protected int readIntFast() {
+        return UNSAFE.getInt(data, BYTE_ARR_OFF + pos);
+    }
+
+    /** {@inheritDoc} */
+    @Override protected long readLongFast() {
+        return UNSAFE.getLong(data, BYTE_ARR_OFF + pos);
+    }
+
+    /** {@inheritDoc} */
+    @Override protected byte readBytePositioned0(int pos) {
+        return UNSAFE.getByte(data, BYTE_ARR_OFF + pos);
+    }
+
+    /** {@inheritDoc} */
+    @Override protected short readShortPositioned0(int pos) {
+        short res = UNSAFE.getShort(data, BYTE_ARR_OFF + pos);
+
+        if (!LITTLE_ENDIAN)
+            res = Short.reverseBytes(res);
+
+        return res;
+    }
+
+    /** {@inheritDoc} */
+    @Override protected int readIntPositioned0(int pos) {
+        int res = UNSAFE.getInt(data, BYTE_ARR_OFF + pos);
+
+        if (!LITTLE_ENDIAN)
+            res = Integer.reverseBytes(res);
+
+        return res;
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/71ad9cea/modules/core/src/main/java/org/apache/ignite/internal/binary/streams/BinaryHeapOutputStream.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/binary/streams/BinaryHeapOutputStream.java b/modules/core/src/main/java/org/apache/ignite/internal/binary/streams/BinaryHeapOutputStream.java
new file mode 100644
index 0000000..02c3441
--- /dev/null
+++ b/modules/core/src/main/java/org/apache/ignite/internal/binary/streams/BinaryHeapOutputStream.java
@@ -0,0 +1,176 @@
+/*
+ * 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.binary.streams;
+
+/**
+ * Portable heap output stream.
+ */
+public final class BinaryHeapOutputStream extends BinaryAbstractOutputStream {
+    /** Allocator. */
+    private final BinaryMemoryAllocatorChunk chunk;
+
+    /** Data. */
+    private byte[] data;
+
+    /**
+     * Constructor.
+     *
+     * @param cap Initial capacity.
+     */
+    public BinaryHeapOutputStream(int cap) {
+        this(cap, BinaryMemoryAllocator.INSTANCE.chunk());
+    }
+
+    /**
+     * Constructor.
+     *
+     * @param cap Capacity.
+     * @param chunk Chunk.
+     */
+    public BinaryHeapOutputStream(int cap, BinaryMemoryAllocatorChunk chunk) {
+        this.chunk = chunk;
+
+        data = chunk.allocate(cap);
+    }
+
+    /** {@inheritDoc} */
+    @Override public void close() {
+        chunk.release(data, pos);
+    }
+
+    /** {@inheritDoc} */
+    @Override public void ensureCapacity(int cnt) {
+        if (cnt > data.length) {
+            int newCap = capacity(data.length, cnt);
+
+            data = chunk.reallocate(data, newCap);
+        }
+    }
+
+    /** {@inheritDoc} */
+    @Override public byte[] array() {
+        return data;
+    }
+
+    /** {@inheritDoc} */
+    @Override public byte[] arrayCopy() {
+        byte[] res = new byte[pos];
+
+        UNSAFE.copyMemory(data, BYTE_ARR_OFF, res, BYTE_ARR_OFF, pos);
+
+        return res;
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean hasArray() {
+        return true;
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void writeByteAndShift(byte val) {
+        data[pos++] = val;
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void copyAndShift(Object src, long off, int len) {
+        UNSAFE.copyMemory(src, off, data, BYTE_ARR_OFF + pos, len);
+
+        shift(len);
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void writeShortFast(short val) {
+        UNSAFE.putShort(data, BYTE_ARR_OFF + pos, val);
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void writeCharFast(char val) {
+        UNSAFE.putChar(data, BYTE_ARR_OFF + pos, val);
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void writeIntFast(int val) {
+        UNSAFE.putInt(data, BYTE_ARR_OFF + pos, val);
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void writeLongFast(long val) {
+        UNSAFE.putLong(data, BYTE_ARR_OFF + pos, val);
+    }
+
+    /** {@inheritDoc} */
+    @Override public void unsafeWriteByte(byte val) {
+        UNSAFE.putByte(data, BYTE_ARR_OFF + pos++, val);
+    }
+
+    /** {@inheritDoc} */
+    @Override public void unsafeWriteShort(short val) {
+        if (!LITTLE_ENDIAN)
+            val = Short.reverseBytes(val);
+
+        UNSAFE.putShort(data, BYTE_ARR_OFF + pos, val);
+
+        shift(2);
+    }
+
+    /** {@inheritDoc} */
+    @Override public void unsafeWriteShort(int pos, short val) {
+        if (!LITTLE_ENDIAN)
+            val = Short.reverseBytes(val);
+
+        UNSAFE.putShort(data, BYTE_ARR_OFF + pos, val);
+    }
+
+    /** {@inheritDoc} */
+    @Override public void unsafeWriteChar(char val) {
+        if (!LITTLE_ENDIAN)
+            val = Character.reverseBytes(val);
+
+        UNSAFE.putChar(data, BYTE_ARR_OFF + pos, val);
+
+        shift(2);
+    }
+
+    /** {@inheritDoc} */
+    @Override public void unsafeWriteInt(int val) {
+        if (!LITTLE_ENDIAN)
+            val = Integer.reverseBytes(val);
+
+        UNSAFE.putInt(data, BYTE_ARR_OFF + pos, val);
+
+        shift(4);
+    }
+
+    /** {@inheritDoc} */
+    @Override public void unsafeWriteInt(int pos, int val) {
+        if (!LITTLE_ENDIAN)
+            val = Integer.reverseBytes(val);
+
+        UNSAFE.putInt(data, BYTE_ARR_OFF + pos, val);
+    }
+
+    /** {@inheritDoc} */
+    @Override public void unsafeWriteLong(long val) {
+        if (!LITTLE_ENDIAN)
+            val = Long.reverseBytes(val);
+
+        UNSAFE.putLong(data, BYTE_ARR_OFF + pos, val);
+
+        shift(8);
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/71ad9cea/modules/core/src/main/java/org/apache/ignite/internal/binary/streams/BinaryInputStream.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/binary/streams/BinaryInputStream.java b/modules/core/src/main/java/org/apache/ignite/internal/binary/streams/BinaryInputStream.java
new file mode 100644
index 0000000..63457e4
--- /dev/null
+++ b/modules/core/src/main/java/org/apache/ignite/internal/binary/streams/BinaryInputStream.java
@@ -0,0 +1,162 @@
+/*
+ * 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.binary.streams;
+
+import org.apache.ignite.internal.binary.BinaryPositionReadable;
+
+/**
+ * Portable input stream.
+ */
+public interface BinaryInputStream extends BinaryStream, BinaryPositionReadable {
+    /**
+     * Read byte value.
+     *
+     * @return Byte value.
+     */
+    public byte readByte();
+
+    /**
+     * Read byte array.
+     *
+     * @param cnt Expected item count.
+     * @return Byte array.
+     */
+    public byte[] readByteArray(int cnt);
+
+    /**
+     * Reads {@code cnt} of bytes into byte array.
+     *
+     * @param arr Expected item count.
+     * @param off offset
+     * @param cnt number of bytes to read.
+     * @return actual length read.
+     */
+    public int read(byte[] arr, int off, int cnt);
+
+    /**
+     * Read boolean value.
+     *
+     * @return Boolean value.
+     */
+    public boolean readBoolean();
+
+    /**
+     * Read boolean array.
+     *
+     * @param cnt Expected item count.
+     * @return Boolean array.
+     */
+    public boolean[] readBooleanArray(int cnt);
+
+    /**
+     * Read short value.
+     *
+     * @return Short value.
+     */
+    public short readShort();
+
+    /**
+     * Read short array.
+     *
+     * @param cnt Expected item count.
+     * @return Short array.
+     */
+    public short[] readShortArray(int cnt);
+
+    /**
+     * Read char value.
+     *
+     * @return Char value.
+     */
+    public char readChar();
+
+    /**
+     * Read char array.
+     *
+     * @param cnt Expected item count.
+     * @return Char array.
+     */
+    public char[] readCharArray(int cnt);
+
+    /**
+     * Read int value.
+     *
+     * @return Int value.
+     */
+    public int readInt();
+
+    /**
+     * Read int array.
+     *
+     * @param cnt Expected item count.
+     * @return Int array.
+     */
+    public int[] readIntArray(int cnt);
+
+    /**
+     * Read float value.
+     *
+     * @return Float value.
+     */
+    public float readFloat();
+
+    /**
+     * Read float array.
+     *
+     * @param cnt Expected item count.
+     * @return Float array.
+     */
+    public float[] readFloatArray(int cnt);
+
+    /**
+     * Read long value.
+     *
+     * @return Long value.
+     */
+    public long readLong();
+
+    /**
+     * Read long array.
+     *
+     * @param cnt Expected item count.
+     * @return Long array.
+     */
+    public long[] readLongArray(int cnt);
+
+    /**
+     * Read double value.
+     *
+     * @return Double value.
+     */
+    public double readDouble();
+
+    /**
+     * Read double array.
+     *
+     * @param cnt Expected item count.
+     * @return Double array.
+     */
+    public double[] readDoubleArray(int cnt);
+
+    /**
+     * Gets amount of remaining data in bytes.
+     *
+     * @return Remaining data.
+     */
+    public int remaining();
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/71ad9cea/modules/core/src/main/java/org/apache/ignite/internal/binary/streams/BinaryMemoryAllocator.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/binary/streams/BinaryMemoryAllocator.java b/modules/core/src/main/java/org/apache/ignite/internal/binary/streams/BinaryMemoryAllocator.java
new file mode 100644
index 0000000..5471bc5
--- /dev/null
+++ b/modules/core/src/main/java/org/apache/ignite/internal/binary/streams/BinaryMemoryAllocator.java
@@ -0,0 +1,57 @@
+/*
+ * 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.binary.streams;
+
+/**
+ * Thread-local memory allocator.
+ */
+public final class BinaryMemoryAllocator {
+    /** Memory allocator instance. */
+    public static final BinaryMemoryAllocator INSTANCE = new BinaryMemoryAllocator();
+
+    /** Holders. */
+    private static final ThreadLocal<BinaryMemoryAllocatorChunk> holders = new ThreadLocal<>();
+
+    /**
+     * Ensures singleton.
+     */
+    private BinaryMemoryAllocator() {
+        // No-op.
+    }
+
+    public BinaryMemoryAllocatorChunk chunk() {
+        BinaryMemoryAllocatorChunk holder = holders.get();
+
+        if (holder == null)
+            holders.set(holder = new BinaryMemoryAllocatorChunk());
+
+        return holder;
+    }
+
+    /**
+     * Checks whether a thread-local array is acquired or not.
+     * The function is used by Unit tests.
+     *
+     * @return {@code true} if acquired {@code false} otherwise.
+     */
+    public boolean isAcquired() {
+        BinaryMemoryAllocatorChunk holder = holders.get();
+
+        return holder != null && holder.isAcquired();
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/71ad9cea/modules/core/src/main/java/org/apache/ignite/internal/binary/streams/BinaryMemoryAllocatorChunk.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/binary/streams/BinaryMemoryAllocatorChunk.java b/modules/core/src/main/java/org/apache/ignite/internal/binary/streams/BinaryMemoryAllocatorChunk.java
new file mode 100644
index 0000000..7c73742
--- /dev/null
+++ b/modules/core/src/main/java/org/apache/ignite/internal/binary/streams/BinaryMemoryAllocatorChunk.java
@@ -0,0 +1,117 @@
+/*
+ * 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.binary.streams;
+
+import org.apache.ignite.internal.util.GridUnsafe;
+import org.apache.ignite.internal.util.typedef.internal.U;
+import sun.misc.Unsafe;
+
+import static org.apache.ignite.IgniteSystemProperties.IGNITE_MARSHAL_BUFFERS_RECHECK;
+
+/**
+ * Memory allocator chunk.
+ */
+public class BinaryMemoryAllocatorChunk {
+    /** Unsafe instance. */
+    protected static final Unsafe UNSAFE = GridUnsafe.unsafe();
+
+    /** Array offset: byte. */
+    protected static final long BYTE_ARR_OFF = UNSAFE.arrayBaseOffset(byte[].class);
+
+    /** Buffer size re-check frequency. */
+    private static final Long CHECK_FREQ = Long.getLong(IGNITE_MARSHAL_BUFFERS_RECHECK, 10000);
+
+    /** Data array */
+    private byte[] data;
+
+    /** Max message size detected between checks. */
+    private int maxMsgSize;
+
+    /** Last time array size is checked. */
+    private long lastCheck = U.currentTimeMillis();
+
+    /** Whether the holder is acquired or not. */
+    private boolean acquired;
+
+    /**
+     * Allocate.
+     *
+     * @param size Desired size.
+     * @return Data.
+     */
+    public byte[] allocate(int size) {
+        if (acquired)
+            return new byte[size];
+
+        acquired = true;
+
+        if (data == null || size > data.length)
+            data = new byte[size];
+
+        return data;
+    }
+
+    /**
+     * Reallocate.
+     *
+     * @param data Old data.
+     * @param size Size.
+     * @return New data.
+     */
+    public byte[] reallocate(byte[] data, int size) {
+        byte[] newData = new byte[size];
+
+        if (this.data == data)
+            this.data = newData;
+
+        UNSAFE.copyMemory(data, BYTE_ARR_OFF, newData, BYTE_ARR_OFF, data.length);
+
+        return newData;
+    }
+
+    /**
+     * Shrinks array size if needed.
+     */
+    public void release(byte[] data, int maxMsgSize) {
+        if (this.data != data)
+            return;
+
+        if (maxMsgSize > this.maxMsgSize)
+            this.maxMsgSize = maxMsgSize;
+
+        this.acquired = false;
+
+        long now = U.currentTimeMillis();
+
+        if (now - this.lastCheck >= CHECK_FREQ) {
+            int halfSize = data.length >> 1;
+
+            if (this.maxMsgSize < halfSize)
+                this.data = new byte[halfSize];
+
+            this.lastCheck = now;
+        }
+    }
+
+    /**
+     * @return {@code True} if acquired.
+     */
+    public boolean isAcquired() {
+        return acquired;
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/71ad9cea/modules/core/src/main/java/org/apache/ignite/internal/binary/streams/BinaryOffheapInputStream.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/binary/streams/BinaryOffheapInputStream.java b/modules/core/src/main/java/org/apache/ignite/internal/binary/streams/BinaryOffheapInputStream.java
new file mode 100644
index 0000000..dc18c9e
--- /dev/null
+++ b/modules/core/src/main/java/org/apache/ignite/internal/binary/streams/BinaryOffheapInputStream.java
@@ -0,0 +1,144 @@
+/*
+ * 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.binary.streams;
+
+/**
+ * Portable off-heap input stream.
+ */
+public class BinaryOffheapInputStream extends BinaryAbstractInputStream {
+    /** Pointer. */
+    private final long ptr;
+
+    /** Capacity. */
+    private final int cap;
+
+    /** */
+    private boolean forceHeap;
+
+    /**
+     * Constructor.
+     *
+     * @param ptr Pointer.
+     * @param cap Capacity.
+     */
+    public BinaryOffheapInputStream(long ptr, int cap) {
+        this(ptr, cap, false);
+    }
+
+    /**
+     * Constructor.
+     *
+     * @param ptr Pointer.
+     * @param cap Capacity.
+     * @param forceHeap If {@code true} method {@link #offheapPointer} returns 0 and unmarshalling will
+     *        create heap-based objects.
+     */
+    public BinaryOffheapInputStream(long ptr, int cap, boolean forceHeap) {
+        this.ptr = ptr;
+        this.cap = cap;
+        this.forceHeap = forceHeap;
+
+        len = cap;
+    }
+
+    /** {@inheritDoc} */
+    @Override public int remaining() {
+        return cap - pos;
+    }
+
+    /** {@inheritDoc} */
+    @Override public byte[] array() {
+        return arrayCopy();
+    }
+
+    /** {@inheritDoc} */
+    @Override public byte[] arrayCopy() {
+        byte[] res = new byte[len];
+
+        UNSAFE.copyMemory(null, ptr, res, BYTE_ARR_OFF, res.length);
+
+        return res;
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean hasArray() {
+        return false;
+    }
+
+    /** {@inheritDoc} */
+    @Override protected byte readByteAndShift() {
+        return UNSAFE.getByte(ptr + pos++);
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void copyAndShift(Object target, long off, int len) {
+        UNSAFE.copyMemory(null, ptr + pos, target, off, len);
+
+        shift(len);
+    }
+
+    /** {@inheritDoc} */
+    @Override protected short readShortFast() {
+        return UNSAFE.getShort(ptr + pos);
+    }
+
+    /** {@inheritDoc} */
+    @Override protected char readCharFast() {
+        return UNSAFE.getChar(ptr + pos);
+    }
+
+    /** {@inheritDoc} */
+    @Override protected int readIntFast() {
+        return UNSAFE.getInt(ptr + pos);
+    }
+
+    /** {@inheritDoc} */
+    @Override protected long readLongFast() {
+        return UNSAFE.getLong(ptr + pos);
+    }
+
+    /** {@inheritDoc} */
+    @Override protected byte readBytePositioned0(int pos) {
+        return UNSAFE.getByte(ptr + pos);
+    }
+
+    /** {@inheritDoc} */
+    @Override protected short readShortPositioned0(int pos) {
+        short res = UNSAFE.getShort(ptr + pos);
+
+        if (!LITTLE_ENDIAN)
+            res = Short.reverseBytes(res);
+
+        return res;
+    }
+
+    /** {@inheritDoc} */
+    @Override protected int readIntPositioned0(int pos) {
+        int res = UNSAFE.getInt(ptr + pos);
+
+        if (!LITTLE_ENDIAN)
+            res = Integer.reverseBytes(res);
+
+        return res;
+    }
+
+    /** {@inheritDoc} */
+    @Override public long offheapPointer() {
+        return forceHeap ? 0 : ptr;
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/71ad9cea/modules/core/src/main/java/org/apache/ignite/internal/binary/streams/BinaryOffheapOutputStream.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/binary/streams/BinaryOffheapOutputStream.java b/modules/core/src/main/java/org/apache/ignite/internal/binary/streams/BinaryOffheapOutputStream.java
new file mode 100644
index 0000000..24b65b2
--- /dev/null
+++ b/modules/core/src/main/java/org/apache/ignite/internal/binary/streams/BinaryOffheapOutputStream.java
@@ -0,0 +1,222 @@
+/*
+ * 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.binary.streams;
+
+/**
+ * Portable offheap output stream.
+ */
+public class BinaryOffheapOutputStream extends BinaryAbstractOutputStream {
+    /** Pointer. */
+    private long ptr;
+
+    /** Length of bytes that cen be used before resize is necessary. */
+    private int cap;
+
+    /**
+     * Constructor.
+     *
+     * @param cap Capacity.
+     */
+    public BinaryOffheapOutputStream(int cap) {
+        this(0, cap);
+    }
+
+    /**
+     * Constructor.
+     *
+     * @param ptr Pointer to existing address.
+     * @param cap Capacity.
+     */
+    public BinaryOffheapOutputStream(long ptr, int cap) {
+        this.ptr = ptr == 0 ? allocate(cap) : ptr;
+
+        this.cap = cap;
+    }
+
+    /** {@inheritDoc} */
+    @Override public void close() {
+        release(ptr);
+    }
+
+    /** {@inheritDoc} */
+    @Override public void ensureCapacity(int cnt) {
+        if (cnt > cap) {
+            int newCap = capacity(cap, cnt);
+
+            ptr = reallocate(ptr, newCap);
+
+            cap = newCap;
+        }
+    }
+
+    /** {@inheritDoc} */
+    @Override public byte[] array() {
+        return arrayCopy();
+    }
+
+    /** {@inheritDoc} */
+    @Override public byte[] arrayCopy() {
+        byte[] res = new byte[pos];
+
+        UNSAFE.copyMemory(null, ptr, res, BYTE_ARR_OFF, pos);
+
+        return res;
+    }
+
+    /**
+     * @return Pointer.
+     */
+    public long pointer() {
+        return ptr;
+    }
+
+    /**
+     * @return Capacity.
+     */
+    public int capacity() {
+        return cap;
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void writeByteAndShift(byte val) {
+        UNSAFE.putByte(ptr + pos++, val);
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void copyAndShift(Object src, long offset, int len) {
+        UNSAFE.copyMemory(src, offset, null, ptr + pos, len);
+
+        shift(len);
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void writeShortFast(short val) {
+        UNSAFE.putShort(ptr + pos, val);
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void writeCharFast(char val) {
+        UNSAFE.putChar(ptr + pos, val);
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void writeIntFast(int val) {
+        UNSAFE.putInt(ptr + pos, val);
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void writeLongFast(long val) {
+        UNSAFE.putLong(ptr + pos, val);
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean hasArray() {
+        return false;
+    }
+
+    /** {@inheritDoc} */
+    @Override public void unsafeWriteByte(byte val) {
+        UNSAFE.putByte(ptr + pos++, val);
+    }
+
+    /** {@inheritDoc} */
+    @Override public void unsafeWriteShort(short val) {
+        if (!LITTLE_ENDIAN)
+            val = Short.reverseBytes(val);
+
+        UNSAFE.putShort(ptr + pos, val);
+
+        shift(2);
+    }
+
+    /** {@inheritDoc} */
+    @Override public void unsafeWriteShort(int pos, short val) {
+        if (!LITTLE_ENDIAN)
+            val = Short.reverseBytes(val);
+
+        UNSAFE.putShort(ptr + pos, val);
+    }
+
+    /** {@inheritDoc} */
+    @Override public void unsafeWriteChar(char val) {
+        if (!LITTLE_ENDIAN)
+            val = Character.reverseBytes(val);
+
+        UNSAFE.putChar(ptr + pos, val);
+
+        shift(2);
+    }
+
+    /** {@inheritDoc} */
+    @Override public void unsafeWriteInt(int val) {
+        if (!LITTLE_ENDIAN)
+            val = Integer.reverseBytes(val);
+
+        UNSAFE.putInt(ptr + pos, val);
+
+        shift(4);
+    }
+
+    /** {@inheritDoc} */
+    @Override public void unsafeWriteInt(int pos, int val) {
+        if (!LITTLE_ENDIAN)
+            val = Integer.reverseBytes(val);
+
+        UNSAFE.putInt(ptr + pos, val);
+    }
+
+    /** {@inheritDoc} */
+    @Override public void unsafeWriteLong(long val) {
+        if (!LITTLE_ENDIAN)
+            val = Long.reverseBytes(val);
+
+        UNSAFE.putLong(ptr + pos, val);
+
+        shift(8);
+    }
+
+    /**
+     * Allocate memory.
+     *
+     * @param cap Capacity.
+     * @return Pointer.
+     */
+    protected long allocate(int cap) {
+        return UNSAFE.allocateMemory(cap);
+    }
+
+    /**
+     * Reallocate memory.
+     *
+     * @param ptr Old pointer.
+     * @param cap Capacity.
+     * @return New pointer.
+     */
+    protected long reallocate(long ptr, int cap) {
+        return UNSAFE.reallocateMemory(ptr, cap);
+    }
+
+    /**
+     * Release memory.
+     *
+     * @param ptr Pointer.
+     */
+    protected void release(long ptr) {
+        UNSAFE.freeMemory(ptr);
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/71ad9cea/modules/core/src/main/java/org/apache/ignite/internal/binary/streams/BinaryOutputStream.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/binary/streams/BinaryOutputStream.java b/modules/core/src/main/java/org/apache/ignite/internal/binary/streams/BinaryOutputStream.java
new file mode 100644
index 0000000..1c3f4bf
--- /dev/null
+++ b/modules/core/src/main/java/org/apache/ignite/internal/binary/streams/BinaryOutputStream.java
@@ -0,0 +1,259 @@
+/*
+ * 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.binary.streams;
+
+/**
+ * Portable output stream.
+ */
+public interface BinaryOutputStream extends BinaryStream, AutoCloseable {
+    /**
+     * Write byte value.
+     *
+     * @param val Byte value.
+     */
+    public void writeByte(byte val);
+
+    /**
+     * Write byte array.
+     *
+     * @param val Byte array.
+     */
+    public void writeByteArray(byte[] val);
+
+    /**
+     * Write boolean value.
+     *
+     * @param val Boolean value.
+     */
+    public void writeBoolean(boolean val);
+
+    /**
+     * Write boolean array.
+     *
+     * @param val Boolean array.
+     */
+    public void writeBooleanArray(boolean[] val);
+
+    /**
+     * Write short value.
+     *
+     * @param val Short value.
+     */
+    public void writeShort(short val);
+
+    /**
+     * Write short array.
+     *
+     * @param val Short array.
+     */
+    public void writeShortArray(short[] val);
+
+    /**
+     * Write char value.
+     *
+     * @param val Char value.
+     */
+    public void writeChar(char val);
+
+    /**
+     * Write char array.
+     *
+     * @param val Char array.
+     */
+    public void writeCharArray(char[] val);
+
+    /**
+     * Write int value.
+     *
+     * @param val Int value.
+     */
+    public void writeInt(int val);
+
+    /**
+     * Write short value at the given position.
+     *
+     * @param pos Position.
+     * @param val Value.
+     */
+    public void writeShort(int pos, short val);
+
+    /**
+     * Write int value to the given position.
+     *
+     * @param pos Position.
+     * @param val Value.
+     */
+    public void writeInt(int pos, int val);
+
+    /**
+     * Write int array.
+     *
+     * @param val Int array.
+     */
+    public void writeIntArray(int[] val);
+
+    /**
+     * Write float value.
+     *
+     * @param val Float value.
+     */
+    public void writeFloat(float val);
+
+    /**
+     * Write float array.
+     *
+     * @param val Float array.
+     */
+    public void writeFloatArray(float[] val);
+
+    /**
+     * Write long value.
+     *
+     * @param val Long value.
+     */
+    public void writeLong(long val);
+
+    /**
+     * Write long array.
+     *
+     * @param val Long array.
+     */
+    public void writeLongArray(long[] val);
+
+    /**
+     * Write double value.
+     *
+     * @param val Double value.
+     */
+    public void writeDouble(double val);
+
+    /**
+     * Write double array.
+     *
+     * @param val Double array.
+     */
+    public void writeDoubleArray(double[] val);
+
+    /**
+     * Write byte array.
+     *
+     * @param arr Array.
+     * @param off Offset.
+     * @param len Length.
+     */
+    public void write(byte[] arr, int off, int len);
+
+    /**
+     * Write data from unmanaged memory.
+     *
+     * @param addr Address.
+     * @param cnt Count.
+     */
+    public void write(long addr, int cnt);
+
+    /**
+     * Close the stream releasing resources.
+     */
+    @Override public void close();
+
+    /**
+     * Set position in unsafe mode.
+     *
+     * @param pos Position.
+     */
+    public void unsafePosition(int pos);
+
+    /**
+     * Ensure capacity for unsafe writes.
+     *
+     * @param cap Capacity.
+     */
+    public void unsafeEnsure(int cap);
+
+    /**
+     * Write byte in unsafe mode.
+     *
+     * @param val Value.
+     */
+    public void unsafeWriteByte(byte val);
+
+    /**
+     * Write boolean in unsafe mode.
+     *
+     * @param val Value.
+     */
+    public void unsafeWriteBoolean(boolean val);
+
+    /**
+     * Write short in unsafe mode.
+     *
+     * @param val Value.
+     */
+    public void unsafeWriteShort(short val);
+
+    /**
+     * Write short in unsafe mode.
+     *
+     * @param pos Position.
+     * @param val Value.
+     */
+    public void unsafeWriteShort(int pos, short val);
+
+    /**
+     * Write char in unsafe mode.
+     *
+     * @param val Value.
+     */
+    public void unsafeWriteChar(char val);
+
+    /**
+     * Write int in unsafe mode.
+     *
+     * @param val Value.
+     */
+    public void unsafeWriteInt(int val);
+
+    /**
+     * Write int in unsafe mode.
+     *
+     * @param pos Position.
+     * @param val Value.
+     */
+    public void unsafeWriteInt(int pos, int val);
+
+    /**
+     * Write long in unsafe mode.
+     *
+     * @param val Value.
+     */
+    public void unsafeWriteLong(long val);
+
+    /**
+     * Write float in unsafe mode.
+     *
+     * @param val Value.
+     */
+    public void unsafeWriteFloat(float val);
+
+    /**
+     * Write double in unsafe mode.
+     *
+     * @param val Value.
+     */
+    public void unsafeWriteDouble(double val);
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/71ad9cea/modules/core/src/main/java/org/apache/ignite/internal/binary/streams/BinaryStream.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/binary/streams/BinaryStream.java b/modules/core/src/main/java/org/apache/ignite/internal/binary/streams/BinaryStream.java
new file mode 100644
index 0000000..229e34c
--- /dev/null
+++ b/modules/core/src/main/java/org/apache/ignite/internal/binary/streams/BinaryStream.java
@@ -0,0 +1,53 @@
+/*
+ * 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.binary.streams;
+
+/**
+ * Portable stream.
+ */
+public interface BinaryStream {
+    /**
+     * @return Position.
+     */
+    public int position();
+
+    /**
+     * @param pos Position.
+     */
+    public void position(int pos);
+
+    /**
+     * @return Underlying array.
+     */
+    public byte[] array();
+
+    /**
+     * @return Copy of data in the stream.
+     */
+    public byte[] arrayCopy();
+
+    /**
+     * @return Offheap pointer if stream is offheap based, otherwise {@code 0}.
+     */
+    public long offheapPointer();
+
+    /**
+     * @return {@code True} is stream is array based.
+     */
+    public boolean hasArray();
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/71ad9cea/modules/core/src/main/java/org/apache/ignite/internal/binary/streams/PortableAbstractInputStream.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/binary/streams/PortableAbstractInputStream.java b/modules/core/src/main/java/org/apache/ignite/internal/binary/streams/PortableAbstractInputStream.java
deleted file mode 100644
index 9d36b47..0000000
--- a/modules/core/src/main/java/org/apache/ignite/internal/binary/streams/PortableAbstractInputStream.java
+++ /dev/null
@@ -1,379 +0,0 @@
-/*
- * 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.binary.streams;
-
-import org.apache.ignite.binary.BinaryObjectException;
-
-/**
- * Portable abstract input stream.
- */
-public abstract class PortableAbstractInputStream extends PortableAbstractStream
-    implements PortableInputStream {
-    /** Length of data inside array. */
-    protected int len;
-
-    /** {@inheritDoc} */
-    @Override public byte readByte() {
-        ensureEnoughData(1);
-
-        return readByteAndShift();
-    }
-
-    /** {@inheritDoc} */
-    @Override public byte[] readByteArray(int cnt) {
-        ensureEnoughData(cnt);
-
-        byte[] res = new byte[cnt];
-
-        copyAndShift(res, BYTE_ARR_OFF, cnt);
-
-        return res;
-    }
-
-    /** {@inheritDoc} */
-    @Override public boolean readBoolean() {
-        return readByte() == BYTE_ONE;
-    }
-
-    /** {@inheritDoc} */
-    @Override public boolean[] readBooleanArray(int cnt) {
-        ensureEnoughData(cnt);
-
-        boolean[] res = new boolean[cnt];
-
-        copyAndShift(res, BOOLEAN_ARR_OFF, cnt);
-
-        return res;
-    }
-
-    /** {@inheritDoc} */
-    @Override public short readShort() {
-        ensureEnoughData(2);
-
-        short res = readShortFast();
-
-        shift(2);
-
-        if (!LITTLE_ENDIAN)
-            res = Short.reverseBytes(res);
-
-        return res;
-    }
-
-    /** {@inheritDoc} */
-    @Override public short[] readShortArray(int cnt) {
-        int len = cnt << 1;
-
-        ensureEnoughData(len);
-
-        short[] res = new short[cnt];
-
-        copyAndShift(res, SHORT_ARR_OFF, len);
-
-        if (!LITTLE_ENDIAN) {
-            for (int i = 0; i < res.length; i++)
-                res[i] = Short.reverseBytes(res[i]);
-        }
-
-        return res;
-    }
-
-    /** {@inheritDoc} */
-    @Override public char readChar() {
-        ensureEnoughData(2);
-
-        char res = readCharFast();
-
-        shift(2);
-
-        if (!LITTLE_ENDIAN)
-            res = Character.reverseBytes(res);
-
-        return res;
-    }
-
-    /** {@inheritDoc} */
-    @Override public char[] readCharArray(int cnt) {
-        int len = cnt << 1;
-
-        ensureEnoughData(len);
-
-        char[] res = new char[cnt];
-
-        copyAndShift(res, CHAR_ARR_OFF, len);
-
-        if (!LITTLE_ENDIAN) {
-            for (int i = 0; i < res.length; i++)
-                res[i] = Character.reverseBytes(res[i]);
-        }
-
-        return res;
-    }
-
-    /** {@inheritDoc} */
-    @Override public int readInt() {
-        ensureEnoughData(4);
-
-        int res = readIntFast();
-
-        shift(4);
-
-        if (!LITTLE_ENDIAN)
-            res = Integer.reverseBytes(res);
-
-        return res;
-    }
-
-    /** {@inheritDoc} */
-    @Override public int[] readIntArray(int cnt) {
-        int len = cnt << 2;
-
-        ensureEnoughData(len);
-
-        int[] res = new int[cnt];
-
-        copyAndShift(res, INT_ARR_OFF, len);
-
-        if (!LITTLE_ENDIAN) {
-            for (int i = 0; i < res.length; i++)
-                res[i] = Integer.reverseBytes(res[i]);
-        }
-
-        return res;
-    }
-
-    /** {@inheritDoc} */
-    @Override public byte readBytePositioned(int pos) {
-        int delta = pos + 1 - this.pos;
-
-        if (delta > 0)
-            ensureEnoughData(delta);
-
-        return readBytePositioned0(pos);
-    }
-
-    /** {@inheritDoc} */
-    @Override public short readShortPositioned(int pos) {
-        int delta = pos + 2 - this.pos;
-
-        if (delta > 0)
-            ensureEnoughData(delta);
-
-        return readShortPositioned0(pos);
-    }
-
-    /** {@inheritDoc} */
-    @Override public int readIntPositioned(int pos) {
-        int delta = pos + 4 - this.pos;
-
-        if (delta > 0)
-            ensureEnoughData(delta);
-
-        return readIntPositioned0(pos);
-    }
-
-    /** {@inheritDoc} */
-    @Override public float readFloat() {
-        return Float.intBitsToFloat(readInt());
-    }
-
-    /** {@inheritDoc} */
-    @Override public float[] readFloatArray(int cnt) {
-        int len = cnt << 2;
-
-        ensureEnoughData(len);
-
-        float[] res = new float[cnt];
-
-        if (LITTLE_ENDIAN)
-            copyAndShift(res, FLOAT_ARR_OFF, len);
-        else {
-            for (int i = 0; i < res.length; i++) {
-                int x = readIntFast();
-
-                shift(4);
-
-                res[i] = Float.intBitsToFloat(Integer.reverseBytes(x));
-            }
-        }
-
-        return res;
-    }
-
-    /** {@inheritDoc} */
-    @Override public long readLong() {
-        ensureEnoughData(8);
-
-        long res = readLongFast();
-
-        shift(8);
-
-        if (!LITTLE_ENDIAN)
-            res = Long.reverseBytes(res);
-
-        return res;
-    }
-
-    /** {@inheritDoc} */
-    @Override public long[] readLongArray(int cnt) {
-        int len = cnt << 3;
-
-        ensureEnoughData(len);
-
-        long[] res = new long[cnt];
-
-        copyAndShift(res, LONG_ARR_OFF, len);
-
-        if (!LITTLE_ENDIAN) {
-            for (int i = 0; i < res.length; i++)
-                res[i] = Long.reverseBytes(res[i]);
-        }
-
-        return res;
-    }
-
-    /** {@inheritDoc} */
-    @Override public double readDouble() {
-        return Double.longBitsToDouble(readLong());
-    }
-
-    /** {@inheritDoc} */
-    @Override public double[] readDoubleArray(int cnt) {
-        int len = cnt << 3;
-
-        ensureEnoughData(len);
-
-        double[] res = new double[cnt];
-
-        if (LITTLE_ENDIAN)
-            copyAndShift(res, DOUBLE_ARR_OFF, len);
-        else {
-            for (int i = 0; i < res.length; i++) {
-                long x = readLongFast();
-
-                shift(8);
-
-                res[i] = Double.longBitsToDouble(Long.reverseBytes(x));
-            }
-        }
-
-        return res;
-    }
-
-    /** {@inheritDoc} */
-    @Override public int read(byte[] arr, int off, int len) {
-        if (len > remaining())
-            len = remaining();
-
-        copyAndShift(arr, BYTE_ARR_OFF + off, len);
-
-        return len;
-    }
-
-    /** {@inheritDoc} */
-    @Override public void position(int pos) {
-        if (remaining() + this.pos < pos)
-            throw new BinaryObjectException("Position is out of bounds: " + pos);
-        else
-            this.pos = pos;
-    }
-
-    /** {@inheritDoc} */
-    @Override public long offheapPointer() {
-        return 0;
-    }
-
-    /**
-     * Ensure that there is enough data.
-     *
-     * @param cnt Length.
-     */
-    protected void ensureEnoughData(int cnt) {
-        if (remaining() < cnt)
-            throw new BinaryObjectException("Not enough data to read the value [position=" + pos +
-                ", requiredBytes=" + cnt + ", remainingBytes=" + remaining() + ']');
-    }
-
-    /**
-     * Read next byte from the stream and perform shift.
-     *
-     * @return Next byte.
-     */
-    protected abstract byte readByteAndShift();
-
-    /**
-     * Copy data to target object shift position afterwards.
-     *
-     * @param target Target.
-     * @param off Offset.
-     * @param len Length.
-     */
-    protected abstract void copyAndShift(Object target, long off, int len);
-
-    /**
-     * Read short value (fast path).
-     *
-     * @return Short value.
-     */
-    protected abstract short readShortFast();
-
-    /**
-     * Read char value (fast path).
-     *
-     * @return Char value.
-     */
-    protected abstract char readCharFast();
-
-    /**
-     * Read int value (fast path).
-     *
-     * @return Int value.
-     */
-    protected abstract int readIntFast();
-
-    /**
-     * Read long value (fast path).
-     *
-     * @return Long value.
-     */
-    protected abstract long readLongFast();
-
-    /**
-     * Internal routine for positioned byte value read.
-     *
-     * @param pos Position.
-     * @return Int value.
-     */
-    protected abstract byte readBytePositioned0(int pos);
-
-    /**
-     * Internal routine for positioned short value read.
-     *
-     * @param pos Position.
-     * @return Int value.
-     */
-    protected abstract short readShortPositioned0(int pos);
-
-    /**
-     * Internal routine for positioned int value read.
-     *
-     * @param pos Position.
-     * @return Int value.
-     */
-    protected abstract int readIntPositioned0(int pos);
-}

http://git-wip-us.apache.org/repos/asf/ignite/blob/71ad9cea/modules/core/src/main/java/org/apache/ignite/internal/binary/streams/PortableAbstractOutputStream.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/binary/streams/PortableAbstractOutputStream.java b/modules/core/src/main/java/org/apache/ignite/internal/binary/streams/PortableAbstractOutputStream.java
deleted file mode 100644
index 85064c5..0000000
--- a/modules/core/src/main/java/org/apache/ignite/internal/binary/streams/PortableAbstractOutputStream.java
+++ /dev/null
@@ -1,347 +0,0 @@
-/*
- * 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.binary.streams;
-
-/**
- * Base portable output stream.
- */
-public abstract class PortableAbstractOutputStream extends PortableAbstractStream
-    implements PortableOutputStream {
-    /** Minimal capacity when it is reasonable to start doubling resize. */
-    private static final int MIN_CAP = 256;
-
-    /** {@inheritDoc} */
-    @Override public void writeByte(byte val) {
-        ensureCapacity(pos + 1);
-
-        writeByteAndShift(val);
-    }
-
-    /** {@inheritDoc} */
-    @Override public void writeByteArray(byte[] val) {
-        ensureCapacity(pos + val.length);
-
-        copyAndShift(val, BYTE_ARR_OFF, val.length);
-    }
-
-    /** {@inheritDoc} */
-    @Override public void writeBoolean(boolean val) {
-        writeByte(val ? BYTE_ONE : BYTE_ZERO);
-    }
-
-    /** {@inheritDoc} */
-    @Override public void writeBooleanArray(boolean[] val) {
-        ensureCapacity(pos + val.length);
-
-        copyAndShift(val, BOOLEAN_ARR_OFF, val.length);
-    }
-
-    /** {@inheritDoc} */
-    @Override public void writeShort(short val) {
-        ensureCapacity(pos + 2);
-
-        if (!LITTLE_ENDIAN)
-            val = Short.reverseBytes(val);
-
-        writeShortFast(val);
-
-        shift(2);
-    }
-
-    /** {@inheritDoc} */
-    @Override public void writeShortArray(short[] val) {
-        int cnt = val.length << 1;
-
-        ensureCapacity(pos + cnt);
-
-        if (LITTLE_ENDIAN)
-            copyAndShift(val, SHORT_ARR_OFF, cnt);
-        else {
-            for (short item : val)
-                writeShortFast(Short.reverseBytes(item));
-
-            shift(cnt);
-        }
-    }
-
-    /** {@inheritDoc} */
-    @Override public void writeChar(char val) {
-        ensureCapacity(pos + 2);
-
-        if (!LITTLE_ENDIAN)
-            val = Character.reverseBytes(val);
-
-        writeCharFast(val);
-
-        shift(2);
-    }
-
-    /** {@inheritDoc} */
-    @Override public void writeCharArray(char[] val) {
-        int cnt = val.length << 1;
-
-        ensureCapacity(pos + cnt);
-
-        if (LITTLE_ENDIAN)
-            copyAndShift(val, CHAR_ARR_OFF, cnt);
-        else {
-            for (char item : val)
-                writeCharFast(Character.reverseBytes(item));
-
-            shift(cnt);
-        }
-    }
-
-    /** {@inheritDoc} */
-    @Override public void writeInt(int val) {
-        ensureCapacity(pos + 4);
-
-        if (!LITTLE_ENDIAN)
-            val = Integer.reverseBytes(val);
-
-        writeIntFast(val);
-
-        shift(4);
-    }
-
-    /** {@inheritDoc} */
-    @Override public void writeShort(int pos, short val) {
-        ensureCapacity(pos + 2);
-
-        unsafeWriteShort(pos, val);
-    }
-
-    /** {@inheritDoc} */
-    @Override public void writeInt(int pos, int val) {
-        ensureCapacity(pos + 4);
-
-        unsafeWriteInt(pos, val);
-    }
-
-    /** {@inheritDoc} */
-    @Override public void writeIntArray(int[] val) {
-        int cnt = val.length << 2;
-
-        ensureCapacity(pos + cnt);
-
-        if (LITTLE_ENDIAN)
-            copyAndShift(val, INT_ARR_OFF, cnt);
-        else {
-            for (int item : val)
-                writeIntFast(Integer.reverseBytes(item));
-
-            shift(cnt);
-        }
-    }
-
-    /** {@inheritDoc} */
-    @Override public void writeFloat(float val) {
-        writeInt(Float.floatToIntBits(val));
-    }
-
-    /** {@inheritDoc} */
-    @Override public void writeFloatArray(float[] val) {
-        int cnt = val.length << 2;
-
-        ensureCapacity(pos + cnt);
-
-        if (LITTLE_ENDIAN)
-            copyAndShift(val, FLOAT_ARR_OFF, cnt);
-        else {
-            for (float item : val) {
-                writeIntFast(Integer.reverseBytes(Float.floatToIntBits(item)));
-
-                shift(4);
-            }
-        }
-    }
-
-    /** {@inheritDoc} */
-    @Override public void writeLong(long val) {
-        ensureCapacity(pos + 8);
-
-        if (!LITTLE_ENDIAN)
-            val = Long.reverseBytes(val);
-
-        writeLongFast(val);
-
-        shift(8);
-    }
-
-    /** {@inheritDoc} */
-    @Override public void writeLongArray(long[] val) {
-        int cnt = val.length << 3;
-
-        ensureCapacity(pos + cnt);
-
-        if (LITTLE_ENDIAN)
-            copyAndShift(val, LONG_ARR_OFF, cnt);
-        else {
-            for (long item : val)
-                writeLongFast(Long.reverseBytes(item));
-
-            shift(cnt);
-        }
-    }
-
-    /** {@inheritDoc} */
-    @Override public void writeDouble(double val) {
-        writeLong(Double.doubleToLongBits(val));
-    }
-
-    /** {@inheritDoc} */
-    @Override public void writeDoubleArray(double[] val) {
-        int cnt = val.length << 3;
-
-        ensureCapacity(pos + cnt);
-
-        if (LITTLE_ENDIAN)
-            copyAndShift(val, DOUBLE_ARR_OFF, cnt);
-        else {
-            for (double item : val) {
-                writeLongFast(Long.reverseBytes(Double.doubleToLongBits(item)));
-
-                shift(8);
-            }
-        }
-    }
-
-    /** {@inheritDoc} */
-    @Override public void write(byte[] arr, int off, int len) {
-        ensureCapacity(pos + len);
-
-        copyAndShift(arr, BYTE_ARR_OFF + off, len);
-    }
-
-    /** {@inheritDoc} */
-    @Override public void write(long addr, int cnt) {
-        ensureCapacity(pos + cnt);
-
-        copyAndShift(null, addr, cnt);
-    }
-
-    /** {@inheritDoc} */
-    @Override public void position(int pos) {
-        ensureCapacity(pos);
-
-        unsafePosition(pos);
-    }
-
-    /** {@inheritDoc} */
-    @Override public long offheapPointer() {
-        return 0;
-    }
-
-    /** {@inheritDoc} */
-    @Override public void unsafeEnsure(int cap) {
-        ensureCapacity(pos + cap);
-    }
-
-    /** {@inheritDoc} */
-    @Override public void unsafePosition(int pos) {
-        this.pos = pos;
-    }
-
-    /** {@inheritDoc} */
-    @Override public void unsafeWriteBoolean(boolean val) {
-        unsafeWriteByte(val ? BYTE_ONE : BYTE_ZERO);
-    }
-
-    /** {@inheritDoc} */
-    @Override public void unsafeWriteFloat(float val) {
-        unsafeWriteInt(Float.floatToIntBits(val));
-    }
-
-    /** {@inheritDoc} */
-    @Override public void unsafeWriteDouble(double val) {
-        unsafeWriteLong(Double.doubleToLongBits(val));
-    }
-
-    /**
-     * Calculate new capacity.
-     *
-     * @param curCap Current capacity.
-     * @param reqCap Required capacity.
-     * @return New capacity.
-     */
-    protected static int capacity(int curCap, int reqCap) {
-        int newCap;
-
-        if (reqCap < MIN_CAP)
-            newCap = MIN_CAP;
-        else {
-            newCap = curCap << 1;
-
-            if (newCap < reqCap)
-                newCap = reqCap;
-        }
-
-        return newCap;
-    }
-
-    /**
-     * Write next byte to the stream.
-     *
-     * @param val Value.
-     */
-    protected abstract void writeByteAndShift(byte val);
-
-    /**
-     * Copy source object to the stream shift position afterwards.
-     *
-     * @param src Source.
-     * @param off Offset.
-     * @param len Length.
-     */
-    protected abstract void copyAndShift(Object src, long off, int len);
-
-    /**
-     * Write short value (fast path).
-     *
-     * @param val Short value.
-     */
-    protected abstract void writeShortFast(short val);
-
-    /**
-     * Write char value (fast path).
-     *
-     * @param val Char value.
-     */
-    protected abstract void writeCharFast(char val);
-
-    /**
-     * Write int value (fast path).
-     *
-     * @param val Int value.
-     */
-    protected abstract void writeIntFast(int val);
-
-    /**
-     * Write long value (fast path).
-     *
-     * @param val Long value.
-     */
-    protected abstract void writeLongFast(long val);
-
-    /**
-     * Ensure capacity.
-     *
-     * @param cnt Required byte count.
-     */
-    protected abstract void ensureCapacity(int cnt);
-}

http://git-wip-us.apache.org/repos/asf/ignite/blob/71ad9cea/modules/core/src/main/java/org/apache/ignite/internal/binary/streams/PortableAbstractStream.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/binary/streams/PortableAbstractStream.java b/modules/core/src/main/java/org/apache/ignite/internal/binary/streams/PortableAbstractStream.java
deleted file mode 100644
index fcc32cb..0000000
--- a/modules/core/src/main/java/org/apache/ignite/internal/binary/streams/PortableAbstractStream.java
+++ /dev/null
@@ -1,80 +0,0 @@
-/*
- * 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.binary.streams;
-
-import java.nio.ByteOrder;
-import org.apache.ignite.internal.util.GridUnsafe;
-import sun.misc.Unsafe;
-
-/**
- * Portable abstract stream.
- */
-public abstract class PortableAbstractStream implements PortableStream {
-    /** Byte: zero. */
-    protected static final byte BYTE_ZERO = 0;
-
-    /** Byte: one. */
-    protected static final byte BYTE_ONE = 1;
-
-    /** Whether little endian is used on the platform. */
-    protected static final boolean LITTLE_ENDIAN = ByteOrder.nativeOrder() == ByteOrder.LITTLE_ENDIAN;
-
-    /** Unsafe instance. */
-    protected static final Unsafe UNSAFE = GridUnsafe.unsafe();
-
-    /** Array offset: boolean. */
-    protected static final long BOOLEAN_ARR_OFF = UNSAFE.arrayBaseOffset(boolean[].class);
-
-    /** Array offset: byte. */
-    protected static final long BYTE_ARR_OFF = UNSAFE.arrayBaseOffset(byte[].class);
-
-    /** Array offset: short. */
-    protected static final long SHORT_ARR_OFF = UNSAFE.arrayBaseOffset(short[].class);
-
-    /** Array offset: char. */
-    protected static final long CHAR_ARR_OFF = UNSAFE.arrayBaseOffset(char[].class);
-
-    /** Array offset: int. */
-    protected static final long INT_ARR_OFF = UNSAFE.arrayBaseOffset(int[].class);
-
-    /** Array offset: float. */
-    protected static final long FLOAT_ARR_OFF = UNSAFE.arrayBaseOffset(float[].class);
-
-    /** Array offset: long. */
-    protected static final long LONG_ARR_OFF = UNSAFE.arrayBaseOffset(long[].class);
-
-    /** Array offset: double. */
-    protected static final long DOUBLE_ARR_OFF = UNSAFE.arrayBaseOffset(double[].class);
-
-    /** Position. */
-    protected int pos;
-
-    /** {@inheritDoc} */
-    @Override public int position() {
-        return pos;
-    }
-
-    /**
-     * Shift position.
-     *
-     * @param cnt Byte count.
-     */
-    protected void shift(int cnt) {
-        pos += cnt;
-    }
-}


[58/59] [abbrv] ignite git commit: ignite-2065: rename "portable" classes to "binary" (in tests)

Posted by ak...@apache.org.
ignite-2065: rename "portable" classes to "binary" (in tests)


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

Branch: refs/heads/ignite-843-rc2
Commit: 469bf6d62f4ce6088ca99a2cb6823523958c3470
Parents: 71ad9ce
Author: ashutak <as...@gridgain.com>
Authored: Fri Dec 11 18:08:18 2015 +0300
Committer: ashutak <as...@gridgain.com>
Committed: Fri Dec 11 18:08:18 2015 +0300

----------------------------------------------------------------------
 .../BinaryObjectBuilderAdditionalSelfTest.java  | 258 +++++-----
 .../binary/BinaryObjectBuilderSelfTest.java     |  46 +-
 .../binary/GridBinaryMetaDataSelfTest.java      | 371 ++++++++++++++
 .../binary/GridBinaryWildcardsSelfTest.java     | 464 ++++++++++++++++++
 .../binary/GridPortableMetaDataSelfTest.java    | 371 --------------
 .../binary/GridPortableWildcardsSelfTest.java   | 464 ------------------
 .../mutabletest/GridBinaryTestClasses.java      | 484 +++++++++++++++++++
 .../mutabletest/GridPortableTestClasses.java    | 484 -------------------
 .../binary/test/GridBinaryTestClass1.java       |  28 ++
 .../binary/test/GridBinaryTestClass2.java       |  24 +
 .../binary/test/GridPortableTestClass1.java     |  28 --
 .../binary/test/GridPortableTestClass2.java     |  24 -
 .../test/subpackage/GridBinaryTestClass3.java   |  24 +
 .../test/subpackage/GridPortableTestClass3.java |  24 -
 .../GridCacheBinaryStoreBinariesSelfTest.java   |  66 +++
 .../GridCacheBinaryStorePortablesSelfTest.java  |  66 ---
 ...sNearPartitionedByteArrayValuesSelfTest.java |  41 ++
 ...sNearPartitionedByteArrayValuesSelfTest.java |  41 --
 .../IgniteBinaryCacheFullApiTestSuite.java      |  37 ++
 .../testsuites/IgniteBinaryCacheTestSuite.java  | 101 ++++
 .../IgniteBinaryObjectsTestSuite.java           | 114 +++++
 .../IgnitePortableCacheFullApiTestSuite.java    |  37 --
 .../IgnitePortableCacheTestSuite.java           | 101 ----
 .../IgnitePortableObjectsTestSuite.java         | 114 -----
 .../IgniteBinaryCacheQueryTestSuite.java        | 119 +++++
 .../IgnitePortableCacheQueryTestSuite.java      | 119 -----
 26 files changed, 2025 insertions(+), 2025 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/469bf6d6/modules/core/src/test/java/org/apache/ignite/internal/binary/BinaryObjectBuilderAdditionalSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/binary/BinaryObjectBuilderAdditionalSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/binary/BinaryObjectBuilderAdditionalSelfTest.java
index bf329a5..a1f980c 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/binary/BinaryObjectBuilderAdditionalSelfTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/binary/BinaryObjectBuilderAdditionalSelfTest.java
@@ -30,7 +30,7 @@ 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.binary.mutabletest.GridPortableTestClasses;
+import org.apache.ignite.internal.binary.mutabletest.GridBinaryTestClasses;
 import org.apache.ignite.internal.binary.builder.BinaryObjectBuilderImpl;
 import org.apache.ignite.internal.binary.builder.BinaryBuilderEnum;
 import org.apache.ignite.internal.binary.mutabletest.GridBinaryMarshalerAwareTestClass;
@@ -116,13 +116,13 @@ public class BinaryObjectBuilderAdditionalSelfTest extends GridCommonAbstractTes
      * @throws Exception If failed.
      */
     public void testSimpleTypeFieldRead() throws Exception {
-        GridPortableTestClasses.TestObjectAllTypes exp = new GridPortableTestClasses.TestObjectAllTypes();
+        GridBinaryTestClasses.TestObjectAllTypes exp = new GridBinaryTestClasses.TestObjectAllTypes();
 
         exp.setDefaultData();
 
         BinaryObjectBuilder mutPo = wrap(exp);
 
-        for (Field field : GridPortableTestClasses.TestObjectAllTypes.class.getDeclaredFields()) {
+        for (Field field : GridBinaryTestClasses.TestObjectAllTypes.class.getDeclaredFields()) {
             Object expVal = field.get(exp);
             Object actVal = mutPo.getField(field.getName());
 
@@ -150,13 +150,13 @@ public class BinaryObjectBuilderAdditionalSelfTest extends GridCommonAbstractTes
      *
      */
     public void testSimpleTypeFieldSerialize() {
-        GridPortableTestClasses.TestObjectAllTypes exp = new GridPortableTestClasses.TestObjectAllTypes();
+        GridBinaryTestClasses.TestObjectAllTypes exp = new GridBinaryTestClasses.TestObjectAllTypes();
 
         exp.setDefaultData();
 
         BinaryObjectBuilderImpl mutPo = wrap(exp);
 
-        GridPortableTestClasses.TestObjectAllTypes res = mutPo.build().deserialize();
+        GridBinaryTestClasses.TestObjectAllTypes res = mutPo.build().deserialize();
 
         GridTestUtils.deepEquals(exp, res);
     }
@@ -165,16 +165,16 @@ public class BinaryObjectBuilderAdditionalSelfTest extends GridCommonAbstractTes
      * @throws Exception If any error occurs.
      */
     public void testSimpleTypeFieldOverride() throws Exception {
-        GridPortableTestClasses.TestObjectAllTypes exp = new GridPortableTestClasses.TestObjectAllTypes();
+        GridBinaryTestClasses.TestObjectAllTypes exp = new GridBinaryTestClasses.TestObjectAllTypes();
 
         exp.setDefaultData();
 
-        BinaryObjectBuilderImpl mutPo = wrap(new GridPortableTestClasses.TestObjectAllTypes());
+        BinaryObjectBuilderImpl mutPo = wrap(new GridBinaryTestClasses.TestObjectAllTypes());
 
-        for (Field field : GridPortableTestClasses.TestObjectAllTypes.class.getDeclaredFields())
+        for (Field field : GridBinaryTestClasses.TestObjectAllTypes.class.getDeclaredFields())
             mutPo.setField(field.getName(), field.get(exp));
 
-        GridPortableTestClasses.TestObjectAllTypes res = mutPo.build().deserialize();
+        GridBinaryTestClasses.TestObjectAllTypes res = mutPo.build().deserialize();
 
         GridTestUtils.deepEquals(exp, res);
     }
@@ -183,20 +183,20 @@ public class BinaryObjectBuilderAdditionalSelfTest extends GridCommonAbstractTes
      * @throws Exception If any error occurs.
      */
     public void testSimpleTypeFieldSetNull() throws Exception {
-        GridPortableTestClasses.TestObjectAllTypes exp = new GridPortableTestClasses.TestObjectAllTypes();
+        GridBinaryTestClasses.TestObjectAllTypes exp = new GridBinaryTestClasses.TestObjectAllTypes();
 
         exp.setDefaultData();
 
         BinaryObjectBuilderImpl mutPo = wrap(exp);
 
-        for (Field field : GridPortableTestClasses.TestObjectAllTypes.class.getDeclaredFields()) {
+        for (Field field : GridBinaryTestClasses.TestObjectAllTypes.class.getDeclaredFields()) {
             if (!field.getType().isPrimitive())
                 mutPo.setField(field.getName(), null);
         }
 
-        GridPortableTestClasses.TestObjectAllTypes res = mutPo.build().deserialize();
+        GridBinaryTestClasses.TestObjectAllTypes res = mutPo.build().deserialize();
 
-        for (Field field : GridPortableTestClasses.TestObjectAllTypes.class.getDeclaredFields()) {
+        for (Field field : GridBinaryTestClasses.TestObjectAllTypes.class.getDeclaredFields()) {
             if (!field.getType().isPrimitive())
                 assertNull(field.getName(), field.get(res));
         }
@@ -206,8 +206,8 @@ public class BinaryObjectBuilderAdditionalSelfTest extends GridCommonAbstractTes
      * @throws IgniteCheckedException If any error occurs.
      */
     public void testMakeCyclicDependency() throws IgniteCheckedException {
-        GridPortableTestClasses.TestObjectOuter outer = new GridPortableTestClasses.TestObjectOuter();
-        outer.inner = new GridPortableTestClasses.TestObjectInner();
+        GridBinaryTestClasses.TestObjectOuter outer = new GridBinaryTestClasses.TestObjectOuter();
+        outer.inner = new GridBinaryTestClasses.TestObjectInner();
 
         BinaryObjectBuilderImpl mutOuter = wrap(outer);
 
@@ -216,7 +216,7 @@ public class BinaryObjectBuilderAdditionalSelfTest extends GridCommonAbstractTes
         mutInner.setField("outer", mutOuter);
         mutInner.setField("foo", mutInner);
 
-        GridPortableTestClasses.TestObjectOuter res = mutOuter.build().deserialize();
+        GridBinaryTestClasses.TestObjectOuter res = mutOuter.build().deserialize();
 
         assertEquals(res, res.inner.outer);
         assertEquals(res.inner, res.inner.foo);
@@ -226,7 +226,7 @@ public class BinaryObjectBuilderAdditionalSelfTest extends GridCommonAbstractTes
      *
      */
     public void testDateArrayModification() {
-        GridPortableTestClasses.TestObjectAllTypes obj = new GridPortableTestClasses.TestObjectAllTypes();
+        GridBinaryTestClasses.TestObjectAllTypes obj = new GridBinaryTestClasses.TestObjectAllTypes();
 
         obj.dateArr =  new Date[] {new Date(11111), new Date(11111), new Date(11111)};
 
@@ -235,7 +235,7 @@ public class BinaryObjectBuilderAdditionalSelfTest extends GridCommonAbstractTes
         Date[] arr = mutObj.getField("dateArr");
         arr[0] = new Date(22222);
 
-        GridPortableTestClasses.TestObjectAllTypes res = mutObj.build().deserialize();
+        GridBinaryTestClasses.TestObjectAllTypes res = mutObj.build().deserialize();
 
         Assert.assertArrayEquals(new Date[] {new Date(22222), new Date(11111), new Date(11111)}, res.dateArr);
     }
@@ -244,7 +244,7 @@ public class BinaryObjectBuilderAdditionalSelfTest extends GridCommonAbstractTes
      *
      */
     public void testTimestampArrayModification() {
-        GridPortableTestClasses.TestObjectAllTypes obj = new GridPortableTestClasses.TestObjectAllTypes();
+        GridBinaryTestClasses.TestObjectAllTypes obj = new GridBinaryTestClasses.TestObjectAllTypes();
 
         obj.tsArr = new Timestamp[] {new Timestamp(111222333), new Timestamp(222333444)};
 
@@ -253,7 +253,7 @@ public class BinaryObjectBuilderAdditionalSelfTest extends GridCommonAbstractTes
         Timestamp[] arr = mutObj.getField("tsArr");
         arr[0] = new Timestamp(333444555);
 
-        GridPortableTestClasses.TestObjectAllTypes res = mutObj.build().deserialize();
+        GridBinaryTestClasses.TestObjectAllTypes res = mutObj.build().deserialize();
 
         Assert.assertArrayEquals(new Timestamp[] {new Timestamp(333444555), new Timestamp(222333444)}, res.tsArr);
     }
@@ -262,7 +262,7 @@ public class BinaryObjectBuilderAdditionalSelfTest extends GridCommonAbstractTes
      *
      */
     public void testUUIDArrayModification() {
-        GridPortableTestClasses.TestObjectAllTypes obj = new GridPortableTestClasses.TestObjectAllTypes();
+        GridBinaryTestClasses.TestObjectAllTypes obj = new GridBinaryTestClasses.TestObjectAllTypes();
 
         obj.uuidArr = new UUID[] {new UUID(1, 1), new UUID(1, 1), new UUID(1, 1)};
 
@@ -271,7 +271,7 @@ public class BinaryObjectBuilderAdditionalSelfTest extends GridCommonAbstractTes
         UUID[] arr = mutObj.getField("uuidArr");
         arr[0] = new UUID(2, 2);
 
-        GridPortableTestClasses.TestObjectAllTypes res = mutObj.build().deserialize();
+        GridBinaryTestClasses.TestObjectAllTypes res = mutObj.build().deserialize();
 
         Assert.assertArrayEquals(new UUID[] {new UUID(2, 2), new UUID(1, 1), new UUID(1, 1)}, res.uuidArr);
     }
@@ -280,7 +280,7 @@ public class BinaryObjectBuilderAdditionalSelfTest extends GridCommonAbstractTes
      *
      */
     public void testDecimalArrayModification() {
-        GridPortableTestClasses.TestObjectAllTypes obj = new GridPortableTestClasses.TestObjectAllTypes();
+        GridBinaryTestClasses.TestObjectAllTypes obj = new GridBinaryTestClasses.TestObjectAllTypes();
 
         obj.bdArr = new BigDecimal[] {new BigDecimal(1000), new BigDecimal(1000), new BigDecimal(1000)};
 
@@ -289,7 +289,7 @@ public class BinaryObjectBuilderAdditionalSelfTest extends GridCommonAbstractTes
         BigDecimal[] arr = mutObj.getField("bdArr");
         arr[0] = new BigDecimal(2000);
 
-        GridPortableTestClasses.TestObjectAllTypes res = mutObj.build().deserialize();
+        GridBinaryTestClasses.TestObjectAllTypes res = mutObj.build().deserialize();
 
         Assert.assertArrayEquals(new BigDecimal[] {new BigDecimal(1000), new BigDecimal(1000), new BigDecimal(1000)},
             res.bdArr);
@@ -299,7 +299,7 @@ public class BinaryObjectBuilderAdditionalSelfTest extends GridCommonAbstractTes
      *
      */
     public void testBooleanArrayModification() {
-        GridPortableTestClasses.TestObjectAllTypes obj = new GridPortableTestClasses.TestObjectAllTypes();
+        GridBinaryTestClasses.TestObjectAllTypes obj = new GridBinaryTestClasses.TestObjectAllTypes();
 
         obj.zArr = new boolean[] {false, false, false};
 
@@ -308,7 +308,7 @@ public class BinaryObjectBuilderAdditionalSelfTest extends GridCommonAbstractTes
         boolean[] arr = mutObj.getField("zArr");
         arr[0] = true;
 
-        GridPortableTestClasses.TestObjectAllTypes res = mutObj.build().deserialize();
+        GridBinaryTestClasses.TestObjectAllTypes res = mutObj.build().deserialize();
 
         boolean[] expected = new boolean[] {true, false, false};
 
@@ -322,7 +322,7 @@ public class BinaryObjectBuilderAdditionalSelfTest extends GridCommonAbstractTes
      *
      */
     public void testCharArrayModification() {
-        GridPortableTestClasses.TestObjectAllTypes obj = new GridPortableTestClasses.TestObjectAllTypes();
+        GridBinaryTestClasses.TestObjectAllTypes obj = new GridBinaryTestClasses.TestObjectAllTypes();
 
         obj.cArr = new char[] {'a', 'a', 'a'};
 
@@ -331,7 +331,7 @@ public class BinaryObjectBuilderAdditionalSelfTest extends GridCommonAbstractTes
         char[] arr = mutObj.getField("cArr");
         arr[0] = 'b';
 
-        GridPortableTestClasses.TestObjectAllTypes res = mutObj.build().deserialize();
+        GridBinaryTestClasses.TestObjectAllTypes res = mutObj.build().deserialize();
 
         Assert.assertArrayEquals(new char[] {'b', 'a', 'a'}, res.cArr);
     }
@@ -340,7 +340,7 @@ public class BinaryObjectBuilderAdditionalSelfTest extends GridCommonAbstractTes
      *
      */
     public void testDoubleArrayModification() {
-        GridPortableTestClasses.TestObjectAllTypes obj = new GridPortableTestClasses.TestObjectAllTypes();
+        GridBinaryTestClasses.TestObjectAllTypes obj = new GridBinaryTestClasses.TestObjectAllTypes();
 
         obj.dArr = new double[] {1.0, 1.0, 1.0};
 
@@ -349,7 +349,7 @@ public class BinaryObjectBuilderAdditionalSelfTest extends GridCommonAbstractTes
         double[] arr = mutObj.getField("dArr");
         arr[0] = 2.0;
 
-        GridPortableTestClasses.TestObjectAllTypes res = mutObj.build().deserialize();
+        GridBinaryTestClasses.TestObjectAllTypes res = mutObj.build().deserialize();
 
         Assert.assertArrayEquals(new double[] {2.0, 1.0, 1.0}, res.dArr, 0);
     }
@@ -358,7 +358,7 @@ public class BinaryObjectBuilderAdditionalSelfTest extends GridCommonAbstractTes
      *
      */
     public void testFloatArrayModification() {
-        GridPortableTestClasses.TestObjectAllTypes obj = new GridPortableTestClasses.TestObjectAllTypes();
+        GridBinaryTestClasses.TestObjectAllTypes obj = new GridBinaryTestClasses.TestObjectAllTypes();
 
         obj.fArr = new float[] {1.0f, 1.0f, 1.0f};
 
@@ -369,7 +369,7 @@ public class BinaryObjectBuilderAdditionalSelfTest extends GridCommonAbstractTes
 
         BinaryObject resBinary = mutObj.build();
 
-        GridPortableTestClasses.TestObjectAllTypes res = resBinary.deserialize();
+        GridBinaryTestClasses.TestObjectAllTypes res = resBinary.deserialize();
 
         Assert.assertArrayEquals(new float[] {2.0f, 1.0f, 1.0f}, res.fArr, 0);
     }
@@ -378,7 +378,7 @@ public class BinaryObjectBuilderAdditionalSelfTest extends GridCommonAbstractTes
      *
      */
     public void testLongArrayModification() {
-        GridPortableTestClasses.TestObjectAllTypes obj = new GridPortableTestClasses.TestObjectAllTypes();
+        GridBinaryTestClasses.TestObjectAllTypes obj = new GridBinaryTestClasses.TestObjectAllTypes();
 
         obj.lArr = new long[] {1, 1, 1};
 
@@ -387,7 +387,7 @@ public class BinaryObjectBuilderAdditionalSelfTest extends GridCommonAbstractTes
         long[] arr = mutObj.getField("lArr");
         arr[0] = 2;
 
-        GridPortableTestClasses.TestObjectAllTypes res = mutObj.build().deserialize();
+        GridBinaryTestClasses.TestObjectAllTypes res = mutObj.build().deserialize();
 
         Assert.assertArrayEquals(new long[] {2, 1, 1}, res.lArr);
     }
@@ -396,7 +396,7 @@ public class BinaryObjectBuilderAdditionalSelfTest extends GridCommonAbstractTes
      *
      */
     public void testIntArrayModification() {
-        GridPortableTestClasses.TestObjectAllTypes obj = new GridPortableTestClasses.TestObjectAllTypes();
+        GridBinaryTestClasses.TestObjectAllTypes obj = new GridBinaryTestClasses.TestObjectAllTypes();
 
         obj.iArr = new int[] {1, 1, 1};
 
@@ -405,7 +405,7 @@ public class BinaryObjectBuilderAdditionalSelfTest extends GridCommonAbstractTes
         int[] arr = mutObj.getField("iArr");
         arr[0] = 2;
 
-        GridPortableTestClasses.TestObjectAllTypes res = mutObj.build().deserialize();
+        GridBinaryTestClasses.TestObjectAllTypes res = mutObj.build().deserialize();
 
         Assert.assertArrayEquals(new int[] {2, 1, 1}, res.iArr);
     }
@@ -414,7 +414,7 @@ public class BinaryObjectBuilderAdditionalSelfTest extends GridCommonAbstractTes
      *
      */
     public void testShortArrayModification() {
-        GridPortableTestClasses.TestObjectAllTypes obj = new GridPortableTestClasses.TestObjectAllTypes();
+        GridBinaryTestClasses.TestObjectAllTypes obj = new GridBinaryTestClasses.TestObjectAllTypes();
 
         obj.sArr = new short[] {1, 1, 1};
 
@@ -423,7 +423,7 @@ public class BinaryObjectBuilderAdditionalSelfTest extends GridCommonAbstractTes
         short[] arr = mutObj.getField("sArr");
         arr[0] = 2;
 
-        GridPortableTestClasses.TestObjectAllTypes res = mutObj.build().deserialize();
+        GridBinaryTestClasses.TestObjectAllTypes res = mutObj.build().deserialize();
 
         Assert.assertArrayEquals(new short[] {2, 1, 1}, res.sArr);
     }
@@ -432,7 +432,7 @@ public class BinaryObjectBuilderAdditionalSelfTest extends GridCommonAbstractTes
      *
      */
     public void testByteArrayModification() {
-        GridPortableTestClasses.TestObjectAllTypes obj = new GridPortableTestClasses.TestObjectAllTypes();
+        GridBinaryTestClasses.TestObjectAllTypes obj = new GridBinaryTestClasses.TestObjectAllTypes();
 
         obj.bArr = new byte[] {1, 1, 1};
 
@@ -441,7 +441,7 @@ public class BinaryObjectBuilderAdditionalSelfTest extends GridCommonAbstractTes
         byte[] arr = mutObj.getField("bArr");
         arr[0] = 2;
 
-        GridPortableTestClasses.TestObjectAllTypes res = mutObj.build().deserialize();
+        GridBinaryTestClasses.TestObjectAllTypes res = mutObj.build().deserialize();
 
         Assert.assertArrayEquals(new byte[] {2, 1, 1}, res.bArr);
     }
@@ -450,7 +450,7 @@ public class BinaryObjectBuilderAdditionalSelfTest extends GridCommonAbstractTes
      *
      */
     public void testStringArrayModification() {
-        GridPortableTestClasses.TestObjectAllTypes obj = new GridPortableTestClasses.TestObjectAllTypes();
+        GridBinaryTestClasses.TestObjectAllTypes obj = new GridBinaryTestClasses.TestObjectAllTypes();
 
         obj.strArr = new String[] {"a", "a", "a"};
 
@@ -459,7 +459,7 @@ public class BinaryObjectBuilderAdditionalSelfTest extends GridCommonAbstractTes
         String[] arr = mutObj.getField("strArr");
         arr[0] = "b";
 
-        GridPortableTestClasses.TestObjectAllTypes res = mutObj.build().deserialize();
+        GridBinaryTestClasses.TestObjectAllTypes res = mutObj.build().deserialize();
 
         Assert.assertArrayEquals(new String[] {"b", "a", "a"}, res.strArr);
     }
@@ -468,7 +468,7 @@ public class BinaryObjectBuilderAdditionalSelfTest extends GridCommonAbstractTes
      *
      */
     public void testModifyObjectArray() {
-        GridPortableTestClasses.TestObjectContainer obj = new GridPortableTestClasses.TestObjectContainer();
+        GridBinaryTestClasses.TestObjectContainer obj = new GridBinaryTestClasses.TestObjectContainer();
         obj.foo = new Object[] {"a"};
 
         BinaryObjectBuilderImpl mutObj = wrap(obj);
@@ -479,7 +479,7 @@ public class BinaryObjectBuilderAdditionalSelfTest extends GridCommonAbstractTes
 
         arr[0] = "b";
 
-        GridPortableTestClasses.TestObjectContainer res = mutObj.build().deserialize();
+        GridBinaryTestClasses.TestObjectContainer res = mutObj.build().deserialize();
 
         Assert.assertArrayEquals(new Object[] {"b"}, (Object[])res.foo);
     }
@@ -488,13 +488,13 @@ public class BinaryObjectBuilderAdditionalSelfTest extends GridCommonAbstractTes
      *
      */
     public void testOverrideObjectArrayField() {
-        BinaryObjectBuilderImpl mutObj = wrap(new GridPortableTestClasses.TestObjectContainer());
+        BinaryObjectBuilderImpl mutObj = wrap(new GridBinaryTestClasses.TestObjectContainer());
 
         Object[] createdArr = {mutObj, "a", 1, new String[] {"s", "s"}, new byte[] {1, 2}, new UUID(3, 0)};
 
         mutObj.setField("foo", createdArr.clone());
 
-        GridPortableTestClasses.TestObjectContainer res = mutObj.build().deserialize();
+        GridBinaryTestClasses.TestObjectContainer res = mutObj.build().deserialize();
 
         createdArr[0] = res;
 
@@ -505,7 +505,7 @@ public class BinaryObjectBuilderAdditionalSelfTest extends GridCommonAbstractTes
      *
      */
     public void testDeepArray() {
-        GridPortableTestClasses.TestObjectContainer obj = new GridPortableTestClasses.TestObjectContainer();
+        GridBinaryTestClasses.TestObjectContainer obj = new GridBinaryTestClasses.TestObjectContainer();
         obj.foo = new Object[] {new Object[] {"a", obj}};
 
         BinaryObjectBuilderImpl mutObj = wrap(obj);
@@ -517,7 +517,7 @@ public class BinaryObjectBuilderAdditionalSelfTest extends GridCommonAbstractTes
 
         arr[0] = mutObj;
 
-        GridPortableTestClasses.TestObjectContainer res = mutObj.build().deserialize();
+        GridBinaryTestClasses.TestObjectContainer res = mutObj.build().deserialize();
 
         arr = (Object[])((Object[])res.foo)[0];
 
@@ -529,7 +529,7 @@ public class BinaryObjectBuilderAdditionalSelfTest extends GridCommonAbstractTes
      *
      */
     public void testArrayListRead() {
-        GridPortableTestClasses.TestObjectContainer obj = new GridPortableTestClasses.TestObjectContainer();
+        GridBinaryTestClasses.TestObjectContainer obj = new GridBinaryTestClasses.TestObjectContainer();
         obj.foo = Lists.newArrayList(obj, "a");
 
         BinaryObjectBuilderImpl mutObj = wrap(obj);
@@ -543,7 +543,7 @@ public class BinaryObjectBuilderAdditionalSelfTest extends GridCommonAbstractTes
      *
      */
     public void testArrayListOverride() {
-        GridPortableTestClasses.TestObjectContainer obj = new GridPortableTestClasses.TestObjectContainer();
+        GridBinaryTestClasses.TestObjectContainer obj = new GridBinaryTestClasses.TestObjectContainer();
 
         BinaryObjectBuilderImpl mutObj = wrap(obj);
 
@@ -551,7 +551,7 @@ public class BinaryObjectBuilderAdditionalSelfTest extends GridCommonAbstractTes
 
         mutObj.setField("foo", list);
 
-        GridPortableTestClasses.TestObjectContainer res = mutObj.build().deserialize();
+        GridBinaryTestClasses.TestObjectContainer res = mutObj.build().deserialize();
 
         list.set(0, res);
 
@@ -563,7 +563,7 @@ public class BinaryObjectBuilderAdditionalSelfTest extends GridCommonAbstractTes
      *
      */
     public void testArrayListModification() {
-        GridPortableTestClasses.TestObjectContainer obj = new GridPortableTestClasses.TestObjectContainer();
+        GridBinaryTestClasses.TestObjectContainer obj = new GridBinaryTestClasses.TestObjectContainer();
         obj.foo = Lists.newArrayList("a", "b", "c");
 
         BinaryObjectBuilderImpl mutObj = wrap(obj);
@@ -580,7 +580,7 @@ public class BinaryObjectBuilderAdditionalSelfTest extends GridCommonAbstractTes
         assertEquals(1, list.indexOf("b"));
         assertEquals(1, list.lastIndexOf("b"));
 
-        GridPortableTestClasses.TestObjectContainer res = mutObj.build().deserialize();
+        GridBinaryTestClasses.TestObjectContainer res = mutObj.build().deserialize();
 
         assertTrue(res.foo instanceof ArrayList);
         assertEquals(Arrays.asList("_", "b", "c", "!"), res.foo);
@@ -590,7 +590,7 @@ public class BinaryObjectBuilderAdditionalSelfTest extends GridCommonAbstractTes
      *
      */
     public void testArrayListClear() {
-        GridPortableTestClasses.TestObjectContainer obj = new GridPortableTestClasses.TestObjectContainer();
+        GridBinaryTestClasses.TestObjectContainer obj = new GridBinaryTestClasses.TestObjectContainer();
         obj.foo = Lists.newArrayList("a", "b", "c");
 
         BinaryObjectBuilderImpl mutObj = wrap(obj);
@@ -599,14 +599,14 @@ public class BinaryObjectBuilderAdditionalSelfTest extends GridCommonAbstractTes
 
         list.clear();
 
-        TestCase.assertEquals(Collections.emptyList(), mutObj.build().<GridPortableTestClasses.TestObjectContainer>deserialize().foo);
+        TestCase.assertEquals(Collections.emptyList(), mutObj.build().<GridBinaryTestClasses.TestObjectContainer>deserialize().foo);
     }
 
     /**
      *
      */
     public void testArrayListWriteUnmodifiable() {
-        GridPortableTestClasses.TestObjectContainer obj = new GridPortableTestClasses.TestObjectContainer();
+        GridBinaryTestClasses.TestObjectContainer obj = new GridBinaryTestClasses.TestObjectContainer();
 
         ArrayList<Object> src = Lists.newArrayList(obj, "a", "b", "c");
 
@@ -614,7 +614,7 @@ public class BinaryObjectBuilderAdditionalSelfTest extends GridCommonAbstractTes
 
         BinaryObjectBuilderImpl mutObj = wrap(obj);
 
-        GridPortableTestClasses.TestObjectContainer deserialized = mutObj.build().deserialize();
+        GridBinaryTestClasses.TestObjectContainer deserialized = mutObj.build().deserialize();
 
         List<Object> res = (List<Object>)deserialized.foo;
 
@@ -627,7 +627,7 @@ public class BinaryObjectBuilderAdditionalSelfTest extends GridCommonAbstractTes
      *
      */
     public void testLinkedListRead() {
-        GridPortableTestClasses.TestObjectContainer obj = new GridPortableTestClasses.TestObjectContainer();
+        GridBinaryTestClasses.TestObjectContainer obj = new GridBinaryTestClasses.TestObjectContainer();
         obj.foo = Lists.newLinkedList(Arrays.asList(obj, "a"));
 
         BinaryObjectBuilderImpl mutObj = wrap(obj);
@@ -641,7 +641,7 @@ public class BinaryObjectBuilderAdditionalSelfTest extends GridCommonAbstractTes
      *
      */
     public void testLinkedListOverride() {
-        GridPortableTestClasses.TestObjectContainer obj = new GridPortableTestClasses.TestObjectContainer();
+        GridBinaryTestClasses.TestObjectContainer obj = new GridBinaryTestClasses.TestObjectContainer();
 
         BinaryObjectBuilderImpl mutObj = wrap(obj);
 
@@ -649,7 +649,7 @@ public class BinaryObjectBuilderAdditionalSelfTest extends GridCommonAbstractTes
 
         mutObj.setField("foo", list);
 
-        GridPortableTestClasses.TestObjectContainer res = mutObj.build().deserialize();
+        GridBinaryTestClasses.TestObjectContainer res = mutObj.build().deserialize();
 
         list.set(0, res);
 
@@ -661,7 +661,7 @@ public class BinaryObjectBuilderAdditionalSelfTest extends GridCommonAbstractTes
      *
      */
     public void testLinkedListModification() {
-        GridPortableTestClasses.TestObjectContainer obj = new GridPortableTestClasses.TestObjectContainer();
+        GridBinaryTestClasses.TestObjectContainer obj = new GridBinaryTestClasses.TestObjectContainer();
 
         obj.foo = Lists.newLinkedList(Arrays.asList("a", "b", "c"));
 
@@ -679,7 +679,7 @@ public class BinaryObjectBuilderAdditionalSelfTest extends GridCommonAbstractTes
         assertEquals(1, list.indexOf("b"));
         assertEquals(1, list.lastIndexOf("b"));
 
-        GridPortableTestClasses.TestObjectContainer res = mutObj.build().deserialize();
+        GridBinaryTestClasses.TestObjectContainer res = mutObj.build().deserialize();
 
         assertTrue(res.foo instanceof LinkedList);
         assertEquals(Arrays.asList("_", "b", "c", "!"), res.foo);
@@ -689,7 +689,7 @@ public class BinaryObjectBuilderAdditionalSelfTest extends GridCommonAbstractTes
      *
      */
     public void testLinkedListWriteUnmodifiable() {
-        GridPortableTestClasses.TestObjectContainer obj = new GridPortableTestClasses.TestObjectContainer();
+        GridBinaryTestClasses.TestObjectContainer obj = new GridBinaryTestClasses.TestObjectContainer();
 
         LinkedList<Object> src = Lists.newLinkedList(Arrays.asList(obj, "a", "b", "c"));
 
@@ -697,7 +697,7 @@ public class BinaryObjectBuilderAdditionalSelfTest extends GridCommonAbstractTes
 
         BinaryObjectBuilderImpl mutObj = wrap(obj);
 
-        GridPortableTestClasses.TestObjectContainer deserialized = mutObj.build().deserialize();
+        GridBinaryTestClasses.TestObjectContainer deserialized = mutObj.build().deserialize();
 
         List<Object> res = (List<Object>)deserialized.foo;
 
@@ -710,7 +710,7 @@ public class BinaryObjectBuilderAdditionalSelfTest extends GridCommonAbstractTes
      *
      */
     public void testHashSetRead() {
-        GridPortableTestClasses.TestObjectContainer obj = new GridPortableTestClasses.TestObjectContainer();
+        GridBinaryTestClasses.TestObjectContainer obj = new GridBinaryTestClasses.TestObjectContainer();
         obj.foo = Sets.newHashSet(obj, "a");
 
         BinaryObjectBuilderImpl mutObj = wrap(obj);
@@ -724,7 +724,7 @@ public class BinaryObjectBuilderAdditionalSelfTest extends GridCommonAbstractTes
      *
      */
     public void testHashSetOverride() {
-        GridPortableTestClasses.TestObjectContainer obj = new GridPortableTestClasses.TestObjectContainer();
+        GridBinaryTestClasses.TestObjectContainer obj = new GridBinaryTestClasses.TestObjectContainer();
 
         BinaryObjectBuilderImpl mutObj = wrap(obj);
 
@@ -732,7 +732,7 @@ public class BinaryObjectBuilderAdditionalSelfTest extends GridCommonAbstractTes
 
         mutObj.setField("foo", c);
 
-        GridPortableTestClasses.TestObjectContainer res = mutObj.build().deserialize();
+        GridBinaryTestClasses.TestObjectContainer res = mutObj.build().deserialize();
 
         c.remove(mutObj);
         c.add(res);
@@ -745,7 +745,7 @@ public class BinaryObjectBuilderAdditionalSelfTest extends GridCommonAbstractTes
      *
      */
     public void testHashSetModification() {
-        GridPortableTestClasses.TestObjectContainer obj = new GridPortableTestClasses.TestObjectContainer();
+        GridBinaryTestClasses.TestObjectContainer obj = new GridBinaryTestClasses.TestObjectContainer();
         obj.foo = Sets.newHashSet("a", "b", "c");
 
         BinaryObjectBuilderImpl mutObj = wrap(obj);
@@ -759,7 +759,7 @@ public class BinaryObjectBuilderAdditionalSelfTest extends GridCommonAbstractTes
         assertTrue(set.contains("a"));
         assertTrue(set.contains("!"));
 
-        GridPortableTestClasses.TestObjectContainer res = mutObj.build().deserialize();
+        GridBinaryTestClasses.TestObjectContainer res = mutObj.build().deserialize();
 
         assertTrue(res.foo instanceof HashSet);
         assertEquals(Sets.newHashSet("a", "!", "c"), res.foo);
@@ -769,13 +769,13 @@ public class BinaryObjectBuilderAdditionalSelfTest extends GridCommonAbstractTes
      *
      */
     public void testHashSetWriteUnmodifiable() {
-        GridPortableTestClasses.TestObjectContainer obj = new GridPortableTestClasses.TestObjectContainer();
+        GridBinaryTestClasses.TestObjectContainer obj = new GridBinaryTestClasses.TestObjectContainer();
 
         Set<Object> src = Sets.newHashSet(obj, "a", "b", "c");
 
         obj.foo = src;
 
-        GridPortableTestClasses.TestObjectContainer deserialized = wrap(obj).build().deserialize();
+        GridBinaryTestClasses.TestObjectContainer deserialized = wrap(obj).build().deserialize();
 
         Set<Object> res = (Set<Object>)deserialized.foo;
 
@@ -789,7 +789,7 @@ public class BinaryObjectBuilderAdditionalSelfTest extends GridCommonAbstractTes
      *
      */
     public void testMapRead() {
-        GridPortableTestClasses.TestObjectContainer obj = new GridPortableTestClasses.TestObjectContainer();
+        GridBinaryTestClasses.TestObjectContainer obj = new GridBinaryTestClasses.TestObjectContainer();
         obj.foo = Maps.newHashMap(ImmutableMap.of(obj, "a", "b", obj));
 
         BinaryObjectBuilderImpl mutObj = wrap(obj);
@@ -803,7 +803,7 @@ public class BinaryObjectBuilderAdditionalSelfTest extends GridCommonAbstractTes
      *
      */
     public void testMapOverride() {
-        GridPortableTestClasses.TestObjectContainer obj = new GridPortableTestClasses.TestObjectContainer();
+        GridBinaryTestClasses.TestObjectContainer obj = new GridBinaryTestClasses.TestObjectContainer();
 
         BinaryObjectBuilderImpl mutObj = wrap(obj);
 
@@ -811,7 +811,7 @@ public class BinaryObjectBuilderAdditionalSelfTest extends GridCommonAbstractTes
 
         mutObj.setField("foo", map);
 
-        GridPortableTestClasses.TestObjectContainer res = mutObj.build().deserialize();
+        GridBinaryTestClasses.TestObjectContainer res = mutObj.build().deserialize();
 
         assertEquals(ImmutableMap.of(res, "a", "b", res), res.foo);
     }
@@ -820,7 +820,7 @@ public class BinaryObjectBuilderAdditionalSelfTest extends GridCommonAbstractTes
      *
      */
     public void testMapModification() {
-        GridPortableTestClasses.TestObjectContainer obj = new GridPortableTestClasses.TestObjectContainer();
+        GridBinaryTestClasses.TestObjectContainer obj = new GridBinaryTestClasses.TestObjectContainer();
         obj.foo = Maps.newHashMap(ImmutableMap.of(1, "a", 2, "b"));
 
         BinaryObjectBuilderImpl mutObj = wrap(obj);
@@ -832,7 +832,7 @@ public class BinaryObjectBuilderAdditionalSelfTest extends GridCommonAbstractTes
 
         assertEquals("a", rmv);
 
-        GridPortableTestClasses.TestObjectContainer res = mutObj.build().deserialize();
+        GridBinaryTestClasses.TestObjectContainer res = mutObj.build().deserialize();
 
         assertEquals(ImmutableMap.of(2, "b", 3, res), res.foo);
     }
@@ -841,18 +841,18 @@ public class BinaryObjectBuilderAdditionalSelfTest extends GridCommonAbstractTes
      *
      */
     public void testEnumArrayModification() {
-        GridPortableTestClasses.TestObjectAllTypes obj = new GridPortableTestClasses.TestObjectAllTypes();
+        GridBinaryTestClasses.TestObjectAllTypes obj = new GridBinaryTestClasses.TestObjectAllTypes();
 
-        obj.enumArr = new GridPortableTestClasses.TestObjectEnum[] {GridPortableTestClasses.TestObjectEnum.A, GridPortableTestClasses.TestObjectEnum.B};
+        obj.enumArr = new GridBinaryTestClasses.TestObjectEnum[] {GridBinaryTestClasses.TestObjectEnum.A, GridBinaryTestClasses.TestObjectEnum.B};
 
         BinaryObjectBuilderImpl mutObj = wrap(obj);
 
         BinaryBuilderEnum[] arr = mutObj.getField("enumArr");
-        arr[0] = new BinaryBuilderEnum(mutObj.typeId(), GridPortableTestClasses.TestObjectEnum.B);
+        arr[0] = new BinaryBuilderEnum(mutObj.typeId(), GridBinaryTestClasses.TestObjectEnum.B);
 
-        GridPortableTestClasses.TestObjectAllTypes res = mutObj.build().deserialize();
+        GridBinaryTestClasses.TestObjectAllTypes res = mutObj.build().deserialize();
 
-        Assert.assertArrayEquals(new GridPortableTestClasses.TestObjectEnum[] {GridPortableTestClasses.TestObjectEnum.A, GridPortableTestClasses.TestObjectEnum.B}, res.enumArr);
+        Assert.assertArrayEquals(new GridBinaryTestClasses.TestObjectEnum[] {GridBinaryTestClasses.TestObjectEnum.A, GridBinaryTestClasses.TestObjectEnum.B}, res.enumArr);
     }
 
     /**
@@ -877,7 +877,7 @@ public class BinaryObjectBuilderAdditionalSelfTest extends GridCommonAbstractTes
      *
      */
     public void testHashCode() {
-        GridPortableTestClasses.TestObjectContainer obj = new GridPortableTestClasses.TestObjectContainer();
+        GridBinaryTestClasses.TestObjectContainer obj = new GridBinaryTestClasses.TestObjectContainer();
 
         BinaryObjectBuilderImpl mutableObj = wrap(obj);
 
@@ -892,7 +892,7 @@ public class BinaryObjectBuilderAdditionalSelfTest extends GridCommonAbstractTes
      *
      */
     public void testCollectionsInCollection() {
-        GridPortableTestClasses.TestObjectContainer obj = new GridPortableTestClasses.TestObjectContainer();
+        GridBinaryTestClasses.TestObjectContainer obj = new GridBinaryTestClasses.TestObjectContainer();
         obj.foo = Lists.newArrayList(
             Lists.newArrayList(1, 2),
             Lists.newLinkedList(Arrays.asList(1, 2)),
@@ -900,7 +900,7 @@ public class BinaryObjectBuilderAdditionalSelfTest extends GridCommonAbstractTes
             Sets.newLinkedHashSet(Arrays.asList("a", "b")),
             Maps.newHashMap(ImmutableMap.of(1, "a", 2, "b")));
 
-        GridPortableTestClasses.TestObjectContainer deserialized = wrap(obj).build().deserialize();
+        GridBinaryTestClasses.TestObjectContainer deserialized = wrap(obj).build().deserialize();
 
         assertEquals(obj.foo, deserialized.foo);
     }
@@ -909,13 +909,13 @@ public class BinaryObjectBuilderAdditionalSelfTest extends GridCommonAbstractTes
      *
      */
     public void testMapEntryOverride() {
-        GridPortableTestClasses.TestObjectContainer obj = new GridPortableTestClasses.TestObjectContainer();
+        GridBinaryTestClasses.TestObjectContainer obj = new GridBinaryTestClasses.TestObjectContainer();
 
         BinaryObjectBuilderImpl mutableObj = wrap(obj);
 
         mutableObj.setField("foo", new GridMapEntry<>(1, "a"));
 
-        GridPortableTestClasses.TestObjectContainer res = mutableObj.build().deserialize();
+        GridBinaryTestClasses.TestObjectContainer res = mutableObj.build().deserialize();
 
         assertEquals(new GridMapEntry<>(1, "a"), res.foo);
     }
@@ -924,14 +924,14 @@ public class BinaryObjectBuilderAdditionalSelfTest extends GridCommonAbstractTes
      *
      */
     public void testMetadataChangingDoublePut() {
-        BinaryObjectBuilderImpl mutableObj = wrap(new GridPortableTestClasses.TestObjectContainer());
+        BinaryObjectBuilderImpl mutableObj = wrap(new GridBinaryTestClasses.TestObjectContainer());
 
         mutableObj.setField("xx567", "a");
         mutableObj.setField("xx567", "b");
 
         mutableObj.build();
 
-        BinaryType metadata = portables().type(GridPortableTestClasses.TestObjectContainer.class);
+        BinaryType metadata = portables().type(GridBinaryTestClasses.TestObjectContainer.class);
 
         assertEquals("String", metadata.fieldTypeName("xx567"));
     }
@@ -940,14 +940,14 @@ public class BinaryObjectBuilderAdditionalSelfTest extends GridCommonAbstractTes
      *
      */
     public void testMetadataChangingDoublePut2() {
-        BinaryObjectBuilderImpl mutableObj = wrap(new GridPortableTestClasses.TestObjectContainer());
+        BinaryObjectBuilderImpl mutableObj = wrap(new GridBinaryTestClasses.TestObjectContainer());
 
         mutableObj.setField("xx567", "a");
         mutableObj.setField("xx567", "b");
 
         mutableObj.build();
 
-        BinaryType metadata = portables().type(GridPortableTestClasses.TestObjectContainer.class);
+        BinaryType metadata = portables().type(GridBinaryTestClasses.TestObjectContainer.class);
 
         assertEquals("String", metadata.fieldTypeName("xx567"));
     }
@@ -956,7 +956,7 @@ public class BinaryObjectBuilderAdditionalSelfTest extends GridCommonAbstractTes
      *
      */
     public void testMetadataChanging() {
-        GridPortableTestClasses.TestObjectContainer c = new GridPortableTestClasses.TestObjectContainer();
+        GridBinaryTestClasses.TestObjectContainer c = new GridBinaryTestClasses.TestObjectContainer();
 
         BinaryObjectBuilderImpl mutableObj = wrap(c);
 
@@ -966,8 +966,8 @@ public class BinaryObjectBuilderAdditionalSelfTest extends GridCommonAbstractTes
         mutableObj.setField("strField", "1");
         mutableObj.setField("colField", Lists.newArrayList("1"));
         mutableObj.setField("mapField", Maps.newHashMap(ImmutableMap.of(1, "1")));
-        mutableObj.setField("enumField", GridPortableTestClasses.TestObjectEnum.A);
-        mutableObj.setField("enumArrField", new Enum[] {GridPortableTestClasses.TestObjectEnum.A});
+        mutableObj.setField("enumField", GridBinaryTestClasses.TestObjectEnum.A);
+        mutableObj.setField("enumArrField", new Enum[] {GridBinaryTestClasses.TestObjectEnum.A});
 
         mutableObj.build();
 
@@ -990,7 +990,7 @@ public class BinaryObjectBuilderAdditionalSelfTest extends GridCommonAbstractTes
      *
      */
     public void testDateInObjectField() {
-        GridPortableTestClasses.TestObjectContainer obj = new GridPortableTestClasses.TestObjectContainer();
+        GridBinaryTestClasses.TestObjectContainer obj = new GridBinaryTestClasses.TestObjectContainer();
 
         obj.foo = new Date();
 
@@ -1003,7 +1003,7 @@ public class BinaryObjectBuilderAdditionalSelfTest extends GridCommonAbstractTes
      *
      */
     public void testTimestampInObjectField() {
-        GridPortableTestClasses.TestObjectContainer obj = new GridPortableTestClasses.TestObjectContainer();
+        GridBinaryTestClasses.TestObjectContainer obj = new GridBinaryTestClasses.TestObjectContainer();
 
         obj.foo = new Timestamp(100020003);
 
@@ -1016,7 +1016,7 @@ public class BinaryObjectBuilderAdditionalSelfTest extends GridCommonAbstractTes
      *
      */
     public void testDateInCollection() {
-        GridPortableTestClasses.TestObjectContainer obj = new GridPortableTestClasses.TestObjectContainer();
+        GridBinaryTestClasses.TestObjectContainer obj = new GridBinaryTestClasses.TestObjectContainer();
 
         obj.foo = Lists.newArrayList(new Date());
 
@@ -1029,7 +1029,7 @@ public class BinaryObjectBuilderAdditionalSelfTest extends GridCommonAbstractTes
      *
      */
     public void testTimestampInCollection() {
-        GridPortableTestClasses.TestObjectContainer obj = new GridPortableTestClasses.TestObjectContainer();
+        GridBinaryTestClasses.TestObjectContainer obj = new GridBinaryTestClasses.TestObjectContainer();
 
         obj.foo = Lists.newArrayList(new Timestamp(100020003));
 
@@ -1043,7 +1043,7 @@ public class BinaryObjectBuilderAdditionalSelfTest extends GridCommonAbstractTes
      */
     @SuppressWarnings("AssertEqualsBetweenInconvertibleTypes")
     public void testDateArrayOverride() {
-        GridPortableTestClasses.TestObjectContainer obj = new GridPortableTestClasses.TestObjectContainer();
+        GridBinaryTestClasses.TestObjectContainer obj = new GridBinaryTestClasses.TestObjectContainer();
 
         BinaryObjectBuilderImpl mutableObj = wrap(obj);
 
@@ -1051,7 +1051,7 @@ public class BinaryObjectBuilderAdditionalSelfTest extends GridCommonAbstractTes
 
         mutableObj.setField("foo", arr);
 
-        GridPortableTestClasses.TestObjectContainer res = mutableObj.build().deserialize();
+        GridBinaryTestClasses.TestObjectContainer res = mutableObj.build().deserialize();
 
         assertEquals(Date[].class, res.foo.getClass());
         assertTrue(Objects.deepEquals(arr, res.foo));
@@ -1062,7 +1062,7 @@ public class BinaryObjectBuilderAdditionalSelfTest extends GridCommonAbstractTes
      */
     @SuppressWarnings("AssertEqualsBetweenInconvertibleTypes")
     public void testTimestampArrayOverride() {
-        GridPortableTestClasses.TestObjectContainer obj = new GridPortableTestClasses.TestObjectContainer();
+        GridBinaryTestClasses.TestObjectContainer obj = new GridBinaryTestClasses.TestObjectContainer();
 
         BinaryObjectBuilderImpl mutableObj = wrap(obj);
 
@@ -1070,7 +1070,7 @@ public class BinaryObjectBuilderAdditionalSelfTest extends GridCommonAbstractTes
 
         mutableObj.setField("foo", arr);
 
-        GridPortableTestClasses.TestObjectContainer res = mutableObj.build().deserialize();
+        GridBinaryTestClasses.TestObjectContainer res = mutableObj.build().deserialize();
 
         assertEquals(Timestamp[].class, res.foo.getClass());
         assertTrue(Objects.deepEquals(arr, res.foo));
@@ -1080,19 +1080,19 @@ public class BinaryObjectBuilderAdditionalSelfTest extends GridCommonAbstractTes
      *
      */
     public void testChangeMap() {
-        GridPortableTestClasses.Addresses addrs = new GridPortableTestClasses.Addresses();
+        GridBinaryTestClasses.Addresses addrs = new GridBinaryTestClasses.Addresses();
 
-        addrs.addCompany(new GridPortableTestClasses.Company(1, "Google inc", 100,
-            new GridPortableTestClasses.Address("Saint-Petersburg", "Torzhkovskya", 1, 53), "occupation"));
+        addrs.addCompany(new GridBinaryTestClasses.Company(1, "Google inc", 100,
+            new GridBinaryTestClasses.Address("Saint-Petersburg", "Torzhkovskya", 1, 53), "occupation"));
 
-        addrs.addCompany(new GridPortableTestClasses.Company(2, "Apple inc", 100,
-            new GridPortableTestClasses.Address("Saint-Petersburg", "Torzhkovskya", 1, 54), "occupation"));
+        addrs.addCompany(new GridBinaryTestClasses.Company(2, "Apple inc", 100,
+            new GridBinaryTestClasses.Address("Saint-Petersburg", "Torzhkovskya", 1, 54), "occupation"));
 
-        addrs.addCompany(new GridPortableTestClasses.Company(3, "Microsoft", 100,
-            new GridPortableTestClasses.Address("Saint-Petersburg", "Torzhkovskya", 1, 55), "occupation"));
+        addrs.addCompany(new GridBinaryTestClasses.Company(3, "Microsoft", 100,
+            new GridBinaryTestClasses.Address("Saint-Petersburg", "Torzhkovskya", 1, 55), "occupation"));
 
-        addrs.addCompany(new GridPortableTestClasses.Company(4, "Oracle", 100,
-            new GridPortableTestClasses.Address("Saint-Petersburg", "Nevskiy", 1, 1), "occupation"));
+        addrs.addCompany(new GridBinaryTestClasses.Company(4, "Oracle", 100,
+            new GridBinaryTestClasses.Address("Saint-Petersburg", "Nevskiy", 1, 1), "occupation"));
 
         BinaryObjectBuilderImpl binaryAddres = wrap(addrs);
 
@@ -1108,11 +1108,11 @@ public class BinaryObjectBuilderAdditionalSelfTest extends GridCommonAbstractTes
 
         binaryCompaniesList.remove(0);
 
-        GridPortableTestClasses.Addresses res = binaryAddres.build().deserialize();
+        GridBinaryTestClasses.Addresses res = binaryAddres.build().deserialize();
 
         assertEquals(Arrays.asList("Nevskiy", "Torzhkovskya"), new ArrayList<>(res.getCompanyByStreet().keySet()));
 
-        GridPortableTestClasses.Companies torzhkovskyaCompanies = res.getCompanyByStreet().get("Torzhkovskya");
+        GridBinaryTestClasses.Companies torzhkovskyaCompanies = res.getCompanyByStreet().get("Torzhkovskya");
 
         assertEquals(2, torzhkovskyaCompanies.size());
         assertEquals("Apple inc", torzhkovskyaCompanies.get(0).name);
@@ -1122,8 +1122,8 @@ public class BinaryObjectBuilderAdditionalSelfTest extends GridCommonAbstractTes
      *
      */
     public void testSavingObjectWithNotZeroStart() {
-        GridPortableTestClasses.TestObjectOuter out = new GridPortableTestClasses.TestObjectOuter();
-        GridPortableTestClasses.TestObjectInner inner = new GridPortableTestClasses.TestObjectInner();
+        GridBinaryTestClasses.TestObjectOuter out = new GridBinaryTestClasses.TestObjectOuter();
+        GridBinaryTestClasses.TestObjectInner inner = new GridBinaryTestClasses.TestObjectInner();
 
         out.inner = inner;
         inner.outer = out;
@@ -1132,7 +1132,7 @@ public class BinaryObjectBuilderAdditionalSelfTest extends GridCommonAbstractTes
 
         BinaryObjectBuilderImpl innerBuilder = builder.getField("inner");
 
-        GridPortableTestClasses.TestObjectInner res = innerBuilder.build().deserialize();
+        GridBinaryTestClasses.TestObjectInner res = innerBuilder.build().deserialize();
 
         assertSame(res, res.outer.inner);
     }
@@ -1141,13 +1141,13 @@ public class BinaryObjectBuilderAdditionalSelfTest extends GridCommonAbstractTes
      *
      */
     public void testPortableObjectField() {
-        GridPortableTestClasses.TestObjectContainer container = new GridPortableTestClasses.TestObjectContainer(toPortable(new GridPortableTestClasses.TestObjectArrayList()));
+        GridBinaryTestClasses.TestObjectContainer container = new GridBinaryTestClasses.TestObjectContainer(toPortable(new GridBinaryTestClasses.TestObjectArrayList()));
 
         BinaryObjectBuilderImpl wrapper = wrap(container);
 
         assertTrue(wrapper.getField("foo") instanceof BinaryObject);
 
-        GridPortableTestClasses.TestObjectContainer deserialized = wrapper.build().deserialize();
+        GridBinaryTestClasses.TestObjectContainer deserialized = wrapper.build().deserialize();
         assertTrue(deserialized.foo instanceof BinaryObject);
     }
 
@@ -1155,48 +1155,48 @@ public class BinaryObjectBuilderAdditionalSelfTest extends GridCommonAbstractTes
      *
      */
     public void testAssignPortableObject() {
-        GridPortableTestClasses.TestObjectContainer container = new GridPortableTestClasses.TestObjectContainer();
+        GridBinaryTestClasses.TestObjectContainer container = new GridBinaryTestClasses.TestObjectContainer();
 
         BinaryObjectBuilderImpl wrapper = wrap(container);
 
-        wrapper.setField("foo", toPortable(new GridPortableTestClasses.TestObjectArrayList()));
+        wrapper.setField("foo", toPortable(new GridBinaryTestClasses.TestObjectArrayList()));
 
-        GridPortableTestClasses.TestObjectContainer deserialized = wrapper.build().deserialize();
-        assertTrue(deserialized.foo instanceof GridPortableTestClasses.TestObjectArrayList);
+        GridBinaryTestClasses.TestObjectContainer deserialized = wrapper.build().deserialize();
+        assertTrue(deserialized.foo instanceof GridBinaryTestClasses.TestObjectArrayList);
     }
 
     /**
      *
      */
     public void testRemoveFromNewObject() {
-        BinaryObjectBuilderImpl wrapper = newWrapper(GridPortableTestClasses.TestObjectAllTypes.class);
+        BinaryObjectBuilderImpl wrapper = newWrapper(GridBinaryTestClasses.TestObjectAllTypes.class);
 
         wrapper.setField("str", "a");
 
         wrapper.removeField("str");
 
-        TestCase.assertNull(wrapper.build().<GridPortableTestClasses.TestObjectAllTypes>deserialize().str);
+        TestCase.assertNull(wrapper.build().<GridBinaryTestClasses.TestObjectAllTypes>deserialize().str);
     }
 
     /**
      *
      */
     public void testRemoveFromExistingObject() {
-        GridPortableTestClasses.TestObjectAllTypes obj = new GridPortableTestClasses.TestObjectAllTypes();
+        GridBinaryTestClasses.TestObjectAllTypes obj = new GridBinaryTestClasses.TestObjectAllTypes();
         obj.setDefaultData();
 
         BinaryObjectBuilderImpl wrapper = wrap(toPortable(obj));
 
         wrapper.removeField("str");
 
-        TestCase.assertNull(wrapper.build().<GridPortableTestClasses.TestObjectAllTypes>deserialize().str);
+        TestCase.assertNull(wrapper.build().<GridBinaryTestClasses.TestObjectAllTypes>deserialize().str);
     }
 
     /**
      *
      */
     public void testCyclicArrays() {
-        GridPortableTestClasses.TestObjectContainer obj = new GridPortableTestClasses.TestObjectContainer();
+        GridBinaryTestClasses.TestObjectContainer obj = new GridBinaryTestClasses.TestObjectContainer();
 
         Object[] arr1 = new Object[1];
         Object[] arr2 = new Object[] {arr1};
@@ -1205,7 +1205,7 @@ public class BinaryObjectBuilderAdditionalSelfTest extends GridCommonAbstractTes
 
         obj.foo = arr1;
 
-        GridPortableTestClasses.TestObjectContainer res = toPortable(obj).deserialize();
+        GridBinaryTestClasses.TestObjectContainer res = toPortable(obj).deserialize();
 
         Object[] resArr = (Object[])res.foo;
 
@@ -1217,7 +1217,7 @@ public class BinaryObjectBuilderAdditionalSelfTest extends GridCommonAbstractTes
      */
     @SuppressWarnings("TypeMayBeWeakened")
     public void testCyclicArrayList() {
-        GridPortableTestClasses.TestObjectContainer obj = new GridPortableTestClasses.TestObjectContainer();
+        GridBinaryTestClasses.TestObjectContainer obj = new GridBinaryTestClasses.TestObjectContainer();
 
         List<Object> arr1 = new ArrayList<>();
         List<Object> arr2 = new ArrayList<>();
@@ -1227,7 +1227,7 @@ public class BinaryObjectBuilderAdditionalSelfTest extends GridCommonAbstractTes
 
         obj.foo = arr1;
 
-        GridPortableTestClasses.TestObjectContainer res = toPortable(obj).deserialize();
+        GridBinaryTestClasses.TestObjectContainer res = toPortable(obj).deserialize();
 
         List<?> resArr = (List<?>)res.foo;
 

http://git-wip-us.apache.org/repos/asf/ignite/blob/469bf6d6/modules/core/src/test/java/org/apache/ignite/internal/binary/BinaryObjectBuilderSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/binary/BinaryObjectBuilderSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/binary/BinaryObjectBuilderSelfTest.java
index d02347c..2a3fe53 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/binary/BinaryObjectBuilderSelfTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/binary/BinaryObjectBuilderSelfTest.java
@@ -36,7 +36,7 @@ import org.apache.ignite.binary.BinaryType;
 import org.apache.ignite.binary.BinaryTypeConfiguration;
 import org.apache.ignite.configuration.BinaryConfiguration;
 import org.apache.ignite.configuration.IgniteConfiguration;
-import org.apache.ignite.internal.binary.mutabletest.GridPortableTestClasses;
+import org.apache.ignite.internal.binary.mutabletest.GridBinaryTestClasses;
 import org.apache.ignite.internal.binary.builder.BinaryObjectBuilderImpl;
 import org.apache.ignite.internal.processors.cache.binary.CacheObjectBinaryProcessorImpl;
 import org.apache.ignite.internal.util.GridUnsafe;
@@ -111,11 +111,11 @@ public class BinaryObjectBuilderSelfTest extends GridCommonAbstractTest {
      *
      */
     public void testAllFieldsSerialization() {
-        GridPortableTestClasses.TestObjectAllTypes obj = new GridPortableTestClasses.TestObjectAllTypes();
+        GridBinaryTestClasses.TestObjectAllTypes obj = new GridBinaryTestClasses.TestObjectAllTypes();
         obj.setDefaultData();
         obj.enumArr = null;
 
-        GridPortableTestClasses.TestObjectAllTypes deserialized = builder(toPortable(obj)).build().deserialize();
+        GridBinaryTestClasses.TestObjectAllTypes deserialized = builder(toPortable(obj)).build().deserialize();
 
         GridTestUtils.deepEquals(obj, deserialized);
     }
@@ -868,7 +868,7 @@ public class BinaryObjectBuilderSelfTest extends GridCommonAbstractTest {
      *
      */
     public void testGetFromCopiedObj() {
-        BinaryObject objStr = builder(GridPortableTestClasses.TestObjectAllTypes.class.getName()).setField("str", "aaa").build();
+        BinaryObject objStr = builder(GridBinaryTestClasses.TestObjectAllTypes.class.getName()).setField("str", "aaa").build();
 
         BinaryObjectBuilderImpl builder = builder(objStr);
         assertEquals("aaa", builder.getField("str"));
@@ -877,7 +877,7 @@ public class BinaryObjectBuilderSelfTest extends GridCommonAbstractTest {
         assertEquals("bbb", builder.getField("str"));
 
         assertNull(builder.getField("i_"));
-        TestCase.assertEquals("bbb", builder.build().<GridPortableTestClasses.TestObjectAllTypes>deserialize().str);
+        TestCase.assertEquals("bbb", builder.build().<GridBinaryTestClasses.TestObjectAllTypes>deserialize().str);
     }
 
     /**
@@ -886,46 +886,46 @@ public class BinaryObjectBuilderSelfTest extends GridCommonAbstractTest {
     @SuppressWarnings("unchecked")
     public void testCopyFromInnerObjects() {
         ArrayList<Object> list = new ArrayList<>();
-        list.add(new GridPortableTestClasses.TestObjectAllTypes());
+        list.add(new GridBinaryTestClasses.TestObjectAllTypes());
         list.add(list.get(0));
 
-        GridPortableTestClasses.TestObjectContainer c = new GridPortableTestClasses.TestObjectContainer(list);
+        GridBinaryTestClasses.TestObjectContainer c = new GridBinaryTestClasses.TestObjectContainer(list);
 
         BinaryObjectBuilderImpl builder = builder(toPortable(c));
         builder.<List>getField("foo").add("!!!");
 
         BinaryObject res = builder.build();
 
-        GridPortableTestClasses.TestObjectContainer deserialized = res.deserialize();
+        GridBinaryTestClasses.TestObjectContainer deserialized = res.deserialize();
 
         List deserializedList = (List)deserialized.foo;
 
         assertSame(deserializedList.get(0), deserializedList.get(1));
         assertEquals("!!!", deserializedList.get(2));
-        assertTrue(deserializedList.get(0) instanceof GridPortableTestClasses.TestObjectAllTypes);
+        assertTrue(deserializedList.get(0) instanceof GridBinaryTestClasses.TestObjectAllTypes);
     }
 
     /**
      *
      */
     public void testSetPortableObject() {
-        BinaryObject portableObj = builder(GridPortableTestClasses.TestObjectContainer.class.getName())
-            .setField("foo", toPortable(new GridPortableTestClasses.TestObjectAllTypes()))
+        BinaryObject portableObj = builder(GridBinaryTestClasses.TestObjectContainer.class.getName())
+            .setField("foo", toPortable(new GridBinaryTestClasses.TestObjectAllTypes()))
             .build();
 
-        assertTrue(portableObj.<GridPortableTestClasses.TestObjectContainer>deserialize().foo instanceof GridPortableTestClasses.TestObjectAllTypes);
+        assertTrue(portableObj.<GridBinaryTestClasses.TestObjectContainer>deserialize().foo instanceof GridBinaryTestClasses.TestObjectAllTypes);
     }
 
     /**
      *
      */
     public void testPlainPortableObjectCopyFrom() {
-        GridPortableTestClasses.TestObjectPlainPortable obj = new GridPortableTestClasses.TestObjectPlainPortable(toPortable(new GridPortableTestClasses.TestObjectAllTypes()));
+        GridBinaryTestClasses.TestObjectPlainPortable obj = new GridBinaryTestClasses.TestObjectPlainPortable(toPortable(new GridBinaryTestClasses.TestObjectAllTypes()));
 
         BinaryObjectBuilderImpl builder = builder(toPortable(obj));
         assertTrue(builder.getField("plainPortable") instanceof BinaryObject);
 
-        GridPortableTestClasses.TestObjectPlainPortable deserialized = builder.build().deserialize();
+        GridBinaryTestClasses.TestObjectPlainPortable deserialized = builder.build().deserialize();
         assertTrue(deserialized.plainPortable != null);
     }
 
@@ -933,20 +933,20 @@ public class BinaryObjectBuilderSelfTest extends GridCommonAbstractTest {
      *
      */
     public void testRemoveFromNewObject() {
-        BinaryObjectBuilder builder = builder(GridPortableTestClasses.TestObjectAllTypes.class.getName());
+        BinaryObjectBuilder builder = builder(GridBinaryTestClasses.TestObjectAllTypes.class.getName());
 
         builder.setField("str", "a");
 
         builder.removeField("str");
 
-        TestCase.assertNull(builder.build().<GridPortableTestClasses.TestObjectAllTypes>deserialize().str);
+        TestCase.assertNull(builder.build().<GridBinaryTestClasses.TestObjectAllTypes>deserialize().str);
     }
 
     /**
      *
      */
     public void testRemoveFromExistingObject() {
-        GridPortableTestClasses.TestObjectAllTypes obj = new GridPortableTestClasses.TestObjectAllTypes();
+        GridBinaryTestClasses.TestObjectAllTypes obj = new GridBinaryTestClasses.TestObjectAllTypes();
         obj.setDefaultData();
         obj.enumArr = null;
 
@@ -956,7 +956,7 @@ public class BinaryObjectBuilderSelfTest extends GridCommonAbstractTest {
 
         BinaryObject binary = builder.build();
 
-        GridPortableTestClasses.TestObjectAllTypes deserialzied = binary.deserialize();
+        GridBinaryTestClasses.TestObjectAllTypes deserialzied = binary.deserialize();
 
         assertNull(deserialzied.str);
     }
@@ -965,7 +965,7 @@ public class BinaryObjectBuilderSelfTest extends GridCommonAbstractTest {
      *
      */
     public void testRemoveFromExistingObjectAfterGet() {
-        GridPortableTestClasses.TestObjectAllTypes obj = new GridPortableTestClasses.TestObjectAllTypes();
+        GridBinaryTestClasses.TestObjectAllTypes obj = new GridBinaryTestClasses.TestObjectAllTypes();
         obj.setDefaultData();
         obj.enumArr = null;
 
@@ -975,15 +975,15 @@ public class BinaryObjectBuilderSelfTest extends GridCommonAbstractTest {
 
         builder.removeField("str");
 
-        TestCase.assertNull(builder.build().<GridPortableTestClasses.TestObjectAllTypes>deserialize().str);
+        TestCase.assertNull(builder.build().<GridBinaryTestClasses.TestObjectAllTypes>deserialize().str);
     }
 
     /**
      * @throws IgniteCheckedException If any error occurs.
      */
     public void testDontBrokeCyclicDependency() throws IgniteCheckedException {
-        GridPortableTestClasses.TestObjectOuter outer = new GridPortableTestClasses.TestObjectOuter();
-        outer.inner = new GridPortableTestClasses.TestObjectInner();
+        GridBinaryTestClasses.TestObjectOuter outer = new GridBinaryTestClasses.TestObjectOuter();
+        outer.inner = new GridBinaryTestClasses.TestObjectInner();
         outer.inner.outer = outer;
         outer.foo = "a";
 
@@ -991,7 +991,7 @@ public class BinaryObjectBuilderSelfTest extends GridCommonAbstractTest {
 
         builder.setField("foo", "b");
 
-        GridPortableTestClasses.TestObjectOuter res = builder.build().deserialize();
+        GridBinaryTestClasses.TestObjectOuter res = builder.build().deserialize();
 
         assertEquals("b", res.foo);
         assertSame(res, res.inner.outer);

http://git-wip-us.apache.org/repos/asf/ignite/blob/469bf6d6/modules/core/src/test/java/org/apache/ignite/internal/binary/GridBinaryMetaDataSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/binary/GridBinaryMetaDataSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/binary/GridBinaryMetaDataSelfTest.java
new file mode 100644
index 0000000..970cbc7
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/binary/GridBinaryMetaDataSelfTest.java
@@ -0,0 +1,371 @@
+/*
+ * 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.binary;
+
+import java.math.BigDecimal;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Date;
+import java.util.HashMap;
+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.binary.BinaryObjectException;
+import org.apache.ignite.binary.Binarylizable;
+import org.apache.ignite.binary.BinaryType;
+import org.apache.ignite.binary.BinaryObject;
+import org.apache.ignite.binary.BinaryRawWriter;
+import org.apache.ignite.binary.BinaryReader;
+import org.apache.ignite.binary.BinaryWriter;
+import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
+
+/**
+ * Portable meta data test.
+ */
+public class GridBinaryMetaDataSelfTest extends GridCommonAbstractTest {
+    /** */
+    private static int idx;
+
+    /** {@inheritDoc} */
+    @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception {
+        IgniteConfiguration cfg = super.getConfiguration(gridName);
+
+        BinaryConfiguration bCfg = new BinaryConfiguration();
+
+        bCfg.setClassNames(Arrays.asList(TestObject1.class.getName(), TestObject2.class.getName()));
+
+        cfg.setBinaryConfiguration(bCfg);
+
+        cfg.setMarshaller(new BinaryMarshaller());
+
+        CacheConfiguration ccfg = new CacheConfiguration();
+
+        cfg.setCacheConfiguration(ccfg);
+
+        return cfg;
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void beforeTest() throws Exception {
+        idx = 0;
+
+        startGrid();
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void afterTest() throws Exception {
+        stopGrid();
+    }
+
+    /**
+     * @return Portables API.
+     */
+    protected IgniteBinary portables() {
+        return grid().binary();
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testGetAll() throws Exception {
+        portables().toBinary(new TestObject2());
+
+        Collection<BinaryType> metas = portables().types();
+
+        assertEquals(2, metas.size());
+
+        for (BinaryType meta : metas) {
+            Collection<String> fields;
+
+            switch (meta.typeName()) {
+                case "TestObject1":
+                    fields = meta.fieldNames();
+
+                    assertEquals(7, fields.size());
+
+                    assertTrue(fields.contains("intVal"));
+                    assertTrue(fields.contains("strVal"));
+                    assertTrue(fields.contains("arrVal"));
+                    assertTrue(fields.contains("obj1Val"));
+                    assertTrue(fields.contains("obj2Val"));
+                    assertTrue(fields.contains("decVal"));
+                    assertTrue(fields.contains("decArrVal"));
+
+                    assertEquals("int", meta.fieldTypeName("intVal"));
+                    assertEquals("String", meta.fieldTypeName("strVal"));
+                    assertEquals("byte[]", meta.fieldTypeName("arrVal"));
+                    assertEquals("Object", meta.fieldTypeName("obj1Val"));
+                    assertEquals("Object", meta.fieldTypeName("obj2Val"));
+                    assertEquals("decimal", meta.fieldTypeName("decVal"));
+                    assertEquals("decimal[]", meta.fieldTypeName("decArrVal"));
+
+                    break;
+
+                case "TestObject2":
+                    fields = meta.fieldNames();
+
+                    assertEquals(7, fields.size());
+
+                    assertTrue(fields.contains("boolVal"));
+                    assertTrue(fields.contains("dateVal"));
+                    assertTrue(fields.contains("uuidArrVal"));
+                    assertTrue(fields.contains("objVal"));
+                    assertTrue(fields.contains("mapVal"));
+                    assertTrue(fields.contains("decVal"));
+                    assertTrue(fields.contains("decArrVal"));
+
+                    assertEquals("boolean", meta.fieldTypeName("boolVal"));
+                    assertEquals("Date", meta.fieldTypeName("dateVal"));
+                    assertEquals("UUID[]", meta.fieldTypeName("uuidArrVal"));
+                    assertEquals("Object", meta.fieldTypeName("objVal"));
+                    assertEquals("Map", meta.fieldTypeName("mapVal"));
+                    assertEquals("decimal", meta.fieldTypeName("decVal"));
+                    assertEquals("decimal[]", meta.fieldTypeName("decArrVal"));
+
+                    break;
+
+                default:
+                    assert false : meta.typeName();
+            }
+        }
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testNoConfiguration() throws Exception {
+        portables().toBinary(new TestObject3());
+
+        assertNotNull(portables().type(TestObject3.class));
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testReflection() throws Exception {
+        BinaryType meta = portables().type(TestObject1.class);
+
+        assertNotNull(meta);
+
+        assertEquals("TestObject1", meta.typeName());
+
+        Collection<String> fields = meta.fieldNames();
+
+        assertEquals(7, fields.size());
+
+        assertTrue(fields.contains("intVal"));
+        assertTrue(fields.contains("strVal"));
+        assertTrue(fields.contains("arrVal"));
+        assertTrue(fields.contains("obj1Val"));
+        assertTrue(fields.contains("obj2Val"));
+        assertTrue(fields.contains("decVal"));
+        assertTrue(fields.contains("decArrVal"));
+
+        assertEquals("int", meta.fieldTypeName("intVal"));
+        assertEquals("String", meta.fieldTypeName("strVal"));
+        assertEquals("byte[]", meta.fieldTypeName("arrVal"));
+        assertEquals("Object", meta.fieldTypeName("obj1Val"));
+        assertEquals("Object", meta.fieldTypeName("obj2Val"));
+        assertEquals("decimal", meta.fieldTypeName("decVal"));
+        assertEquals("decimal[]", meta.fieldTypeName("decArrVal"));
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testPortableMarshalAware() throws Exception {
+        portables().toBinary(new TestObject2());
+
+        BinaryType meta = portables().type(TestObject2.class);
+
+        assertNotNull(meta);
+
+        assertEquals("TestObject2", meta.typeName());
+
+        Collection<String> fields = meta.fieldNames();
+
+        assertEquals(7, fields.size());
+
+        assertTrue(fields.contains("boolVal"));
+        assertTrue(fields.contains("dateVal"));
+        assertTrue(fields.contains("uuidArrVal"));
+        assertTrue(fields.contains("objVal"));
+        assertTrue(fields.contains("mapVal"));
+        assertTrue(fields.contains("decVal"));
+        assertTrue(fields.contains("decArrVal"));
+
+        assertEquals("boolean", meta.fieldTypeName("boolVal"));
+        assertEquals("Date", meta.fieldTypeName("dateVal"));
+        assertEquals("UUID[]", meta.fieldTypeName("uuidArrVal"));
+        assertEquals("Object", meta.fieldTypeName("objVal"));
+        assertEquals("Map", meta.fieldTypeName("mapVal"));
+        assertEquals("decimal", meta.fieldTypeName("decVal"));
+        assertEquals("decimal[]", meta.fieldTypeName("decArrVal"));
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testMerge() throws Exception {
+        portables().toBinary(new TestObject2());
+
+        idx = 1;
+
+        portables().toBinary(new TestObject2());
+
+        BinaryType meta = portables().type(TestObject2.class);
+
+        assertNotNull(meta);
+
+        assertEquals("TestObject2", meta.typeName());
+
+        Collection<String> fields = meta.fieldNames();
+
+        assertEquals(9, fields.size());
+
+        assertTrue(fields.contains("boolVal"));
+        assertTrue(fields.contains("dateVal"));
+        assertTrue(fields.contains("uuidArrVal"));
+        assertTrue(fields.contains("objVal"));
+        assertTrue(fields.contains("mapVal"));
+        assertTrue(fields.contains("charVal"));
+        assertTrue(fields.contains("colVal"));
+        assertTrue(fields.contains("decVal"));
+        assertTrue(fields.contains("decArrVal"));
+
+        assertEquals("boolean", meta.fieldTypeName("boolVal"));
+        assertEquals("Date", meta.fieldTypeName("dateVal"));
+        assertEquals("UUID[]", meta.fieldTypeName("uuidArrVal"));
+        assertEquals("Object", meta.fieldTypeName("objVal"));
+        assertEquals("Map", meta.fieldTypeName("mapVal"));
+        assertEquals("char", meta.fieldTypeName("charVal"));
+        assertEquals("Collection", meta.fieldTypeName("colVal"));
+        assertEquals("decimal", meta.fieldTypeName("decVal"));
+        assertEquals("decimal[]", meta.fieldTypeName("decArrVal"));
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testSerializedObject() throws Exception {
+        TestObject1 obj = new TestObject1();
+
+        obj.intVal = 10;
+        obj.strVal = "str";
+        obj.arrVal = new byte[] {2, 4, 6};
+        obj.obj1Val = null;
+        obj.obj2Val = new TestObject2();
+        obj.decVal = BigDecimal.ZERO;
+        obj.decArrVal = new BigDecimal[] { BigDecimal.ONE };
+
+        BinaryObject po = portables().toBinary(obj);
+
+        info(po.toString());
+
+        BinaryType meta = po.type();
+
+        assertNotNull(meta);
+
+        assertEquals("TestObject1", meta.typeName());
+
+        Collection<String> fields = meta.fieldNames();
+
+        assertEquals(7, fields.size());
+
+        assertTrue(fields.contains("intVal"));
+        assertTrue(fields.contains("strVal"));
+        assertTrue(fields.contains("arrVal"));
+        assertTrue(fields.contains("obj1Val"));
+        assertTrue(fields.contains("obj2Val"));
+        assertTrue(fields.contains("decVal"));
+        assertTrue(fields.contains("decArrVal"));
+
+        assertEquals("int", meta.fieldTypeName("intVal"));
+        assertEquals("String", meta.fieldTypeName("strVal"));
+        assertEquals("byte[]", meta.fieldTypeName("arrVal"));
+        assertEquals("Object", meta.fieldTypeName("obj1Val"));
+        assertEquals("Object", meta.fieldTypeName("obj2Val"));
+        assertEquals("decimal", meta.fieldTypeName("decVal"));
+        assertEquals("decimal[]", meta.fieldTypeName("decArrVal"));
+    }
+
+    /**
+     */
+    @SuppressWarnings("UnusedDeclaration")
+    private static class TestObject1 {
+        /** */
+        private int intVal;
+
+        /** */
+        private String strVal;
+
+        /** */
+        private byte[] arrVal;
+
+        /** */
+        private TestObject1 obj1Val;
+
+        /** */
+        private TestObject2 obj2Val;
+
+        /** */
+        private BigDecimal decVal;
+
+        /** */
+        private BigDecimal[] decArrVal;
+    }
+
+    /**
+     */
+    private static class TestObject2 implements Binarylizable {
+        /** {@inheritDoc} */
+        @Override public void writeBinary(BinaryWriter writer) throws BinaryObjectException {
+            writer.writeBoolean("boolVal", false);
+            writer.writeDate("dateVal", new Date());
+            writer.writeUuidArray("uuidArrVal", null);
+            writer.writeObject("objVal", null);
+            writer.writeMap("mapVal", new HashMap<>());
+            writer.writeDecimal("decVal", BigDecimal.ZERO);
+            writer.writeDecimalArray("decArrVal", new BigDecimal[] { BigDecimal.ONE });
+
+            if (idx == 1) {
+                writer.writeChar("charVal", (char)0);
+                writer.writeCollection("colVal", null);
+            }
+
+            BinaryRawWriter raw = writer.rawWriter();
+
+            raw.writeChar((char)0);
+            raw.writeCollection(null);
+        }
+
+        /** {@inheritDoc} */
+        @Override public void readBinary(BinaryReader reader) throws BinaryObjectException {
+            // No-op.
+        }
+    }
+
+    /**
+     */
+    @SuppressWarnings("UnusedDeclaration")
+    private static class TestObject3 {
+        /** */
+        private int intVal;
+    }
+}


[40/59] [abbrv] ignite git commit: Changed docker file.

Posted by ak...@apache.org.
Changed docker file.


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

Branch: refs/heads/ignite-843-rc2
Commit: ec1ffe13465221c497e603eb51dc690bc8a16f3d
Parents: 9a02acb
Author: nikolay_tikhonov <nt...@gridgain.com>
Authored: Fri Dec 11 16:47:57 2015 +0300
Committer: nikolay_tikhonov <nt...@gridgain.com>
Committed: Fri Dec 11 16:47:57 2015 +0300

----------------------------------------------------------------------
 modules/docker/1.0.0/Dockerfile    | 40 +++++++++++++++++++++
 modules/docker/1.0.0/run.sh        | 50 ++++++++++++++++++++++++++
 modules/docker/1.1.0/Dockerfile    | 40 +++++++++++++++++++++
 modules/docker/1.1.0/run.sh        | 50 ++++++++++++++++++++++++++
 modules/docker/1.2.0/Dockerfile    | 40 +++++++++++++++++++++
 modules/docker/1.2.0/run.sh        | 50 ++++++++++++++++++++++++++
 modules/docker/1.3.0/Dockerfile    | 40 +++++++++++++++++++++
 modules/docker/1.3.0/run.sh        | 50 ++++++++++++++++++++++++++
 modules/docker/1.4.0/Dockerfile    | 40 +++++++++++++++++++++
 modules/docker/1.4.0/run.sh        | 50 ++++++++++++++++++++++++++
 modules/docker/Dockerfile          | 41 +++++++---------------
 modules/docker/build_users_libs.sh | 39 ---------------------
 modules/docker/download_ignite.sh  | 49 --------------------------
 modules/docker/execute.sh          | 62 ---------------------------------
 modules/docker/run.sh              | 36 +++++++++++++------
 15 files changed, 489 insertions(+), 188 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/ec1ffe13/modules/docker/1.0.0/Dockerfile
----------------------------------------------------------------------
diff --git a/modules/docker/1.0.0/Dockerfile b/modules/docker/1.0.0/Dockerfile
new file mode 100644
index 0000000..79c35c8
--- /dev/null
+++ b/modules/docker/1.0.0/Dockerfile
@@ -0,0 +1,40 @@
+#
+# 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.
+#
+
+# Start from a Java image.
+FROM java:7
+
+# Ignite version
+ENV IGNITE_VERSION 1.0.0-incubating
+
+WORKDIR /opt/ignite
+
+ADD http://www.us.apache.org/dist/ignite/1.0.0/ignite-fabric-1.0.0-incubating.zip /opt/ignite/ignite.zip
+
+# Ignite home
+ENV IGNITE_HOME /opt/ignite/ignite-fabric-1.0.0-incubating
+
+RUN unzip ignite.zip
+
+RUN rm ignite.zip
+
+# Copy sh files and set permission
+ADD ./run.sh $IGNITE_HOME/
+
+RUN chmod +x $IGNITE_HOME/run.sh
+
+CMD $IGNITE_HOME/run.sh
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ignite/blob/ec1ffe13/modules/docker/1.0.0/run.sh
----------------------------------------------------------------------
diff --git a/modules/docker/1.0.0/run.sh b/modules/docker/1.0.0/run.sh
new file mode 100644
index 0000000..dbf2871
--- /dev/null
+++ b/modules/docker/1.0.0/run.sh
@@ -0,0 +1,50 @@
+#!/bin/bash
+#
+# 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.
+#
+
+if [ ! -z "$OPTION_LIBS" ]; then
+  IFS=, LIBS_LIST=("$OPTION_LIBS")
+
+  for lib in ${LIBS_LIST[@]}; do
+    cp -r $IGNITE_HOME/libs/optional/"$lib"/* \
+        $IGNITE_HOME/libs/
+  done
+fi
+
+if [ ! -z "$EXTERNAL_LIBS" ]; then
+  IFS=, LIBS_LIST=("$EXTERNAL_LIBS")
+
+  for lib in ${LIBS_LIST[@]}; do
+    echo $lib >> temp
+  done
+
+  wget -i temp -P $IGNITE_HOME/libs
+
+  rm temp
+fi
+
+QUIET=""
+
+if [ "$IGNITE_QUIET" = "false" ]; then
+  QUIET="-v"
+fi
+
+if [ -z $CONFIG_URI ]; then
+  $IGNITE_HOME/bin/ignite.sh $QUIET
+else
+  $IGNITE_HOME/bin/ignite.sh $QUIET $CONFIG_URI
+fi

http://git-wip-us.apache.org/repos/asf/ignite/blob/ec1ffe13/modules/docker/1.1.0/Dockerfile
----------------------------------------------------------------------
diff --git a/modules/docker/1.1.0/Dockerfile b/modules/docker/1.1.0/Dockerfile
new file mode 100644
index 0000000..f132309
--- /dev/null
+++ b/modules/docker/1.1.0/Dockerfile
@@ -0,0 +1,40 @@
+#
+# 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.
+#
+
+# Start from a Java image.
+FROM java:7
+
+# Ignite version
+ENV IGNITE_VERSION 1.1.0-incubating
+
+WORKDIR /opt/ignite
+
+ADD http://www.us.apache.org/dist/ignite/1.1.0/apache-ignite-fabric-1.1.0-incubating-bin.zip /opt/ignite/ignite.zip
+
+# Ignite home
+ENV IGNITE_HOME /opt/ignite/apache-ignite-fabric-1.1.0-incubating-bin
+
+RUN unzip ignite.zip
+
+RUN rm ignite.zip
+
+# Copy sh files and set permission
+ADD ./run.sh $IGNITE_HOME/
+
+RUN chmod +x $IGNITE_HOME/run.sh
+
+CMD $IGNITE_HOME/run.sh
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ignite/blob/ec1ffe13/modules/docker/1.1.0/run.sh
----------------------------------------------------------------------
diff --git a/modules/docker/1.1.0/run.sh b/modules/docker/1.1.0/run.sh
new file mode 100644
index 0000000..dbf2871
--- /dev/null
+++ b/modules/docker/1.1.0/run.sh
@@ -0,0 +1,50 @@
+#!/bin/bash
+#
+# 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.
+#
+
+if [ ! -z "$OPTION_LIBS" ]; then
+  IFS=, LIBS_LIST=("$OPTION_LIBS")
+
+  for lib in ${LIBS_LIST[@]}; do
+    cp -r $IGNITE_HOME/libs/optional/"$lib"/* \
+        $IGNITE_HOME/libs/
+  done
+fi
+
+if [ ! -z "$EXTERNAL_LIBS" ]; then
+  IFS=, LIBS_LIST=("$EXTERNAL_LIBS")
+
+  for lib in ${LIBS_LIST[@]}; do
+    echo $lib >> temp
+  done
+
+  wget -i temp -P $IGNITE_HOME/libs
+
+  rm temp
+fi
+
+QUIET=""
+
+if [ "$IGNITE_QUIET" = "false" ]; then
+  QUIET="-v"
+fi
+
+if [ -z $CONFIG_URI ]; then
+  $IGNITE_HOME/bin/ignite.sh $QUIET
+else
+  $IGNITE_HOME/bin/ignite.sh $QUIET $CONFIG_URI
+fi

http://git-wip-us.apache.org/repos/asf/ignite/blob/ec1ffe13/modules/docker/1.2.0/Dockerfile
----------------------------------------------------------------------
diff --git a/modules/docker/1.2.0/Dockerfile b/modules/docker/1.2.0/Dockerfile
new file mode 100644
index 0000000..b4b1a4a
--- /dev/null
+++ b/modules/docker/1.2.0/Dockerfile
@@ -0,0 +1,40 @@
+#
+# 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.
+#
+
+# Start from a Java image.
+FROM java:7
+
+# Ignite version
+ENV IGNITE_VERSION 1.2.0-incubating
+
+WORKDIR /opt/ignite
+
+ADD http://www.us.apache.org/dist/ignite/1.2.0/apache-ignite-fabric-1.2.0-incubating-bin.zip /opt/ignite/ignite.zip
+
+# Ignite home
+ENV IGNITE_HOME /opt/ignite/apache-ignite-fabric-1.2.0-incubating-bin
+
+RUN unzip ignite.zip
+
+RUN rm ignite.zip
+
+# Copy sh files and set permission
+ADD ./run.sh $IGNITE_HOME/
+
+RUN chmod +x $IGNITE_HOME/run.sh
+
+CMD $IGNITE_HOME/run.sh
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ignite/blob/ec1ffe13/modules/docker/1.2.0/run.sh
----------------------------------------------------------------------
diff --git a/modules/docker/1.2.0/run.sh b/modules/docker/1.2.0/run.sh
new file mode 100644
index 0000000..dbf2871
--- /dev/null
+++ b/modules/docker/1.2.0/run.sh
@@ -0,0 +1,50 @@
+#!/bin/bash
+#
+# 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.
+#
+
+if [ ! -z "$OPTION_LIBS" ]; then
+  IFS=, LIBS_LIST=("$OPTION_LIBS")
+
+  for lib in ${LIBS_LIST[@]}; do
+    cp -r $IGNITE_HOME/libs/optional/"$lib"/* \
+        $IGNITE_HOME/libs/
+  done
+fi
+
+if [ ! -z "$EXTERNAL_LIBS" ]; then
+  IFS=, LIBS_LIST=("$EXTERNAL_LIBS")
+
+  for lib in ${LIBS_LIST[@]}; do
+    echo $lib >> temp
+  done
+
+  wget -i temp -P $IGNITE_HOME/libs
+
+  rm temp
+fi
+
+QUIET=""
+
+if [ "$IGNITE_QUIET" = "false" ]; then
+  QUIET="-v"
+fi
+
+if [ -z $CONFIG_URI ]; then
+  $IGNITE_HOME/bin/ignite.sh $QUIET
+else
+  $IGNITE_HOME/bin/ignite.sh $QUIET $CONFIG_URI
+fi

http://git-wip-us.apache.org/repos/asf/ignite/blob/ec1ffe13/modules/docker/1.3.0/Dockerfile
----------------------------------------------------------------------
diff --git a/modules/docker/1.3.0/Dockerfile b/modules/docker/1.3.0/Dockerfile
new file mode 100644
index 0000000..eade9d9
--- /dev/null
+++ b/modules/docker/1.3.0/Dockerfile
@@ -0,0 +1,40 @@
+#
+# 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.
+#
+
+# Start from a Java image.
+FROM java:7
+
+# Ignite version
+ENV IGNITE_VERSION 1.3.0-incubating
+
+WORKDIR /opt/ignite
+
+ADD http://www.us.apache.org/dist/ignite/1.3.0/apache-ignite-fabric-1.3.0-incubating-bin.zip /opt/ignite/ignite.zip
+
+# Ignite home
+ENV IGNITE_HOME /opt/ignite/apache-ignite-fabric-1.3.0-incubating-bin
+
+RUN unzip ignite.zip
+
+RUN rm ignite.zip
+
+# Copy sh files and set permission
+ADD ./run.sh $IGNITE_HOME/
+
+RUN chmod +x $IGNITE_HOME/run.sh
+
+CMD $IGNITE_HOME/run.sh
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ignite/blob/ec1ffe13/modules/docker/1.3.0/run.sh
----------------------------------------------------------------------
diff --git a/modules/docker/1.3.0/run.sh b/modules/docker/1.3.0/run.sh
new file mode 100644
index 0000000..dbf2871
--- /dev/null
+++ b/modules/docker/1.3.0/run.sh
@@ -0,0 +1,50 @@
+#!/bin/bash
+#
+# 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.
+#
+
+if [ ! -z "$OPTION_LIBS" ]; then
+  IFS=, LIBS_LIST=("$OPTION_LIBS")
+
+  for lib in ${LIBS_LIST[@]}; do
+    cp -r $IGNITE_HOME/libs/optional/"$lib"/* \
+        $IGNITE_HOME/libs/
+  done
+fi
+
+if [ ! -z "$EXTERNAL_LIBS" ]; then
+  IFS=, LIBS_LIST=("$EXTERNAL_LIBS")
+
+  for lib in ${LIBS_LIST[@]}; do
+    echo $lib >> temp
+  done
+
+  wget -i temp -P $IGNITE_HOME/libs
+
+  rm temp
+fi
+
+QUIET=""
+
+if [ "$IGNITE_QUIET" = "false" ]; then
+  QUIET="-v"
+fi
+
+if [ -z $CONFIG_URI ]; then
+  $IGNITE_HOME/bin/ignite.sh $QUIET
+else
+  $IGNITE_HOME/bin/ignite.sh $QUIET $CONFIG_URI
+fi

http://git-wip-us.apache.org/repos/asf/ignite/blob/ec1ffe13/modules/docker/1.4.0/Dockerfile
----------------------------------------------------------------------
diff --git a/modules/docker/1.4.0/Dockerfile b/modules/docker/1.4.0/Dockerfile
new file mode 100644
index 0000000..41f6a68
--- /dev/null
+++ b/modules/docker/1.4.0/Dockerfile
@@ -0,0 +1,40 @@
+#
+# 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.
+#
+
+# Start from a Java image.
+FROM java:7
+
+# Ignite version
+ENV IGNITE_VERSION 1.4.0
+
+WORKDIR /opt/ignite
+
+ADD http://www.us.apache.org/dist/ignite/1.4.0/apache-ignite-fabric-1.4.0-bin.zip /opt/ignite/ignite.zip
+
+# Ignite home
+ENV IGNITE_HOME /opt/ignite/apache-ignite-fabric-1.4.0-bin
+
+RUN unzip ignite.zip
+
+RUN rm ignite.zip
+
+# Copy sh files and set permission
+ADD ./run.sh $IGNITE_HOME/
+
+RUN chmod +x $IGNITE_HOME/run.sh
+
+CMD $IGNITE_HOME/run.sh
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ignite/blob/ec1ffe13/modules/docker/1.4.0/run.sh
----------------------------------------------------------------------
diff --git a/modules/docker/1.4.0/run.sh b/modules/docker/1.4.0/run.sh
new file mode 100644
index 0000000..dbf2871
--- /dev/null
+++ b/modules/docker/1.4.0/run.sh
@@ -0,0 +1,50 @@
+#!/bin/bash
+#
+# 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.
+#
+
+if [ ! -z "$OPTION_LIBS" ]; then
+  IFS=, LIBS_LIST=("$OPTION_LIBS")
+
+  for lib in ${LIBS_LIST[@]}; do
+    cp -r $IGNITE_HOME/libs/optional/"$lib"/* \
+        $IGNITE_HOME/libs/
+  done
+fi
+
+if [ ! -z "$EXTERNAL_LIBS" ]; then
+  IFS=, LIBS_LIST=("$EXTERNAL_LIBS")
+
+  for lib in ${LIBS_LIST[@]}; do
+    echo $lib >> temp
+  done
+
+  wget -i temp -P $IGNITE_HOME/libs
+
+  rm temp
+fi
+
+QUIET=""
+
+if [ "$IGNITE_QUIET" = "false" ]; then
+  QUIET="-v"
+fi
+
+if [ -z $CONFIG_URI ]; then
+  $IGNITE_HOME/bin/ignite.sh $QUIET
+else
+  $IGNITE_HOME/bin/ignite.sh $QUIET $CONFIG_URI
+fi

http://git-wip-us.apache.org/repos/asf/ignite/blob/ec1ffe13/modules/docker/Dockerfile
----------------------------------------------------------------------
diff --git a/modules/docker/Dockerfile b/modules/docker/Dockerfile
index 11e2e3d..11be2b4 100644
--- a/modules/docker/Dockerfile
+++ b/modules/docker/Dockerfile
@@ -15,41 +15,26 @@
 # limitations under the License.
 #
 
-# Start from a Debian image.
-FROM debian:8
+# Start from a Java image.
+FROM java:7
 
-# Install tools.
-RUN apt-get update && apt-get install -y --fix-missing \
-  wget \
-  dstat \
-  maven \
-  git
+# Ignite version
+ENV IGNITE_VERSION 1.5.0-b1
 
-# Intasll Oracle JDK.
-RUN mkdir /opt/jdk
+WORKDIR /opt/ignite
 
-RUN wget --header "Cookie: oraclelicense=accept-securebackup-cookie" \
-  http://download.oracle.com/otn-pub/java/jdk/7u76-b13/jdk-7u76-linux-x64.tar.gz
+ADD http://www.us.apache.org/dist/ignite/1.5.0-b1/apache-ignite-fabric-1.5.0-b1-bin.zip /opt/ignite/ignite.zip
 
-RUN tar -zxf jdk-7u76-linux-x64.tar.gz -C /opt/jdk
+# Ignite home
+ENV IGNITE_HOME /opt/ignite/apache-ignite-fabric-1.5.0-b1-bin
 
-RUN rm jdk-7u76-linux-x64.tar.gz
+RUN unzip ignite.zip
 
-RUN update-alternatives --install /usr/bin/java java /opt/jdk/jdk1.7.0_76/bin/java 100
-
-RUN update-alternatives --install /usr/bin/javac javac /opt/jdk/jdk1.7.0_76/bin/javac 100
-
-# Sets java variables.
-ENV JAVA_HOME /opt/jdk/jdk1.7.0_76/
-
-# Create working directory
-RUN mkdir /home/ignite_home
-
-WORKDIR /home/ignite_home
+RUN rm ignite.zip
 
 # Copy sh files and set permission
-ADD *.sh ./
+ADD ./run.sh $IGNITE_HOME/
 
-RUN chmod +x *.sh
+RUN chmod +x $IGNITE_HOME/run.sh
 
-CMD ./run.sh
\ No newline at end of file
+CMD $IGNITE_HOME/run.sh
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ignite/blob/ec1ffe13/modules/docker/build_users_libs.sh
----------------------------------------------------------------------
diff --git a/modules/docker/build_users_libs.sh b/modules/docker/build_users_libs.sh
deleted file mode 100644
index 4d37187..0000000
--- a/modules/docker/build_users_libs.sh
+++ /dev/null
@@ -1,39 +0,0 @@
-#!/bin/bash
-#
-# 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.
-#
-
-if [ -z $GIT_REPO ]; then
-  echo Users git repo is not provided.
-
-  exit 0
-fi
-
-git clone $GIT_REPO user-repo
-
-cd user-repo
-
-if [ ! -z $GIT_BRANCH ]; then
-  git checkout $GIT_BRANCH
-fi
-
-if [ ! -z "$BUILD_CMD" ]; then
-  echo "Starting to execute build command: $BUILD_CMD"
-
-  eval "$BUILD_CMD"
-else
-  mvn clean package
-fi
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ignite/blob/ec1ffe13/modules/docker/download_ignite.sh
----------------------------------------------------------------------
diff --git a/modules/docker/download_ignite.sh b/modules/docker/download_ignite.sh
deleted file mode 100644
index 8a91c59..0000000
--- a/modules/docker/download_ignite.sh
+++ /dev/null
@@ -1,49 +0,0 @@
-#!/bin/bash
-#
-# 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.
-#
-
-function download {
-  wget -O ignite.zip $1
-
-  unzip ignite.zip -d ignite
-
-  rm ignite.zip
-
-  exit 0
-}
-
-if [ ! -z $IGNITE_URL ]; then
-  download $IGNITE_URL
-fi
-
-if [ ! -z $IGNITE_VERSION ]; then
-  if [[ $IGNITE_VERSION  =~ [0-9]*\.[0-9]*\.0 ]]; then
-    download http://apache-mirror.rbc.ru/pub/apache/ignite/${IGNITE_VERSION}/apache-ignite-fabric-${IGNITE_VERSION}-bin.zip
-  else
-    download http://www.gridgain.com/media/gridgain-community-fabric-${IGNITE_VERSION}.zip
-  fi
-fi
-
-if [ -z $IGNITE_SOURCE ] || [ $IGNITE_SOURCE = "COMMUNITY" ]; then
-  download http://tiny.cc/updater/download_community.php
-fi
-
-if [ $IGNITE_SOURCE = "APACHE" ]; then
-  download http://tiny.cc/updater/download_ignite.php
-fi
-
-echo "Unsupported IGNITE_SOURCE type: ${IGNITE_SOURCE}"

http://git-wip-us.apache.org/repos/asf/ignite/blob/ec1ffe13/modules/docker/execute.sh
----------------------------------------------------------------------
diff --git a/modules/docker/execute.sh b/modules/docker/execute.sh
deleted file mode 100644
index 8afba59..0000000
--- a/modules/docker/execute.sh
+++ /dev/null
@@ -1,62 +0,0 @@
-#!/bin/bash
-#
-# 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.
-#
-
-if [ ! -z "$GIT_REPO" ]; then
-  if [ -z "$LIB_PATTERN" ]; then
-    find user-repo/ -regextype posix-extended -regex "user-repo/target/.*(jar|zip)$" -exec cp {} ignite/*/libs \;
-  else
-    find user-repo/ -regextype posix-extended -regex "$LIB_PATTERN" -exec cp {} ignite/*/libs \;
-  fi
-fi
-
-if [ -z "$OPTION_LIBS" ]; then
-  OPTION_LIBS="ignite-log4j"
-fi
-
-if [ ! -z "$OPTION_LIBS" ]; then
-  IFS=, LIBS_LIST=("$OPTION_LIBS")
-
-  for lib in ${LIBS_LIST[@]}; do
-    cp -r ./ignite/*/libs/optional/"$lib"/* ./ignite/*/libs
-  done
-fi
-
-# Try to download
-if [ ! -z "$IGNITE_CONFIG" ]; then
-  wget -O ignite-config.xml "$IGNITE_CONFIG" 2>/dev/null
-
-  RETVAL=$?
-
-  [ $RETVAL -eq 0 ] && IGNITE_CONFIG=ignite-config.xml
-
-  [ $RETVAL -ne 0 ] && rm ignite-config.xml && echo "Failed download config: $IGNITE_CONFIG. Try to load config from classpath."
-fi
-
-if [ ! -z "$EXEC_CMD" ]; then
-  echo "Starting to execute command: $EXEC_CMD"
-
-  eval "$EXEC_CMD"
-
-  exit 0
-fi
-
-if [ -z "$IGNITE_CONFIG" ]; then
-  ignite/*/bin/ignite.sh
-else
-  ignite/*/bin/ignite.sh ignite-config.xml
-fi
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ignite/blob/ec1ffe13/modules/docker/run.sh
----------------------------------------------------------------------
diff --git a/modules/docker/run.sh b/modules/docker/run.sh
index 0f01c1c..dbf2871 100644
--- a/modules/docker/run.sh
+++ b/modules/docker/run.sh
@@ -16,19 +16,35 @@
 # limitations under the License.
 #
 
-if [ -z $SKIP_BUILD_LIBS ]; then
-  ./build_users_libs.sh
+if [ ! -z "$OPTION_LIBS" ]; then
+  IFS=, LIBS_LIST=("$OPTION_LIBS")
 
-  PROJ_VER=$(mvn -f user-repo/pom.xml dependency:list | grep ':ignite-core:jar:.*:' | \
-    sed -rn 's/.*([0-9]+\.[0-9]+\.[0-9]+).*/\1/p')
+  for lib in ${LIBS_LIST[@]}; do
+    cp -r $IGNITE_HOME/libs/optional/"$lib"/* \
+        $IGNITE_HOME/libs/
+  done
+fi
+
+if [ ! -z "$EXTERNAL_LIBS" ]; then
+  IFS=, LIBS_LIST=("$EXTERNAL_LIBS")
+
+  for lib in ${LIBS_LIST[@]}; do
+    echo $lib >> temp
+  done
 
-  if [ ! -z $PROJ_VER ]; then
-    IGNITE_VERSION=$PROJ_VER
-  fi
+  wget -i temp -P $IGNITE_HOME/libs
+
+  rm temp
 fi
 
-if [ -z $SKIP_DOWNLOAD ]; then
-  IGNITE_VERSION=$IGNITE_VERSION ./download_ignite.sh
+QUIET=""
+
+if [ "$IGNITE_QUIET" = "false" ]; then
+  QUIET="-v"
 fi
 
-./execute.sh
\ No newline at end of file
+if [ -z $CONFIG_URI ]; then
+  $IGNITE_HOME/bin/ignite.sh $QUIET
+else
+  $IGNITE_HOME/bin/ignite.sh $QUIET $CONFIG_URI
+fi


[46/59] [abbrv] ignite git commit: ignite-2065: rename "portable" classes to "binary"

Posted by ak...@apache.org.
http://git-wip-us.apache.org/repos/asf/ignite/blob/71ad9cea/modules/core/src/main/java/org/apache/ignite/internal/binary/streams/PortableHeapInputStream.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/binary/streams/PortableHeapInputStream.java b/modules/core/src/main/java/org/apache/ignite/internal/binary/streams/PortableHeapInputStream.java
deleted file mode 100644
index d8717ce..0000000
--- a/modules/core/src/main/java/org/apache/ignite/internal/binary/streams/PortableHeapInputStream.java
+++ /dev/null
@@ -1,166 +0,0 @@
-/*
- * 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.binary.streams;
-
-import java.util.Arrays;
-
-/**
- * Portable off-heap input stream.
- */
-public final class PortableHeapInputStream extends PortableAbstractInputStream {
-    /**
-     * Create stream with pointer set at the given position.
-     *
-     * @param data Data.
-     * @param pos Position.
-     * @return Stream.
-     */
-    public static PortableHeapInputStream create(byte[] data, int pos) {
-        assert pos < data.length;
-
-        PortableHeapInputStream stream = new PortableHeapInputStream(data);
-
-        stream.pos = pos;
-
-        return stream;
-    }
-
-    /** Data. */
-    private byte[] data;
-
-    /**
-     * Constructor.
-     *
-     * @param data Data.
-     */
-    public PortableHeapInputStream(byte[] data) {
-        this.data = data;
-
-        len = data.length;
-    }
-
-    /**
-     * @return Copy of this stream.
-     */
-    public PortableHeapInputStream copy() {
-        PortableHeapInputStream in = new PortableHeapInputStream(Arrays.copyOf(data, data.length));
-
-        in.position(pos);
-
-        return in;
-    }
-
-    /**
-     * Method called from JNI to resize stream.
-     *
-     * @param len Required length.
-     * @return Underlying byte array.
-     */
-    public byte[] resize(int len) {
-        if (data.length < len) {
-            byte[] data0 = new byte[len];
-
-            UNSAFE.copyMemory(data, BYTE_ARR_OFF, data0, BYTE_ARR_OFF, data.length);
-
-            data = data0;
-        }
-
-        return data;
-    }
-
-    /** {@inheritDoc} */
-    @Override public int remaining() {
-        return data.length - pos;
-    }
-
-    /** {@inheritDoc} */
-    @Override public byte[] array() {
-        return data;
-    }
-
-    /** {@inheritDoc} */
-    @Override public byte[] arrayCopy() {
-        byte[] res = new byte[len];
-
-        UNSAFE.copyMemory(data, BYTE_ARR_OFF, res, BYTE_ARR_OFF, res.length);
-
-        return res;
-    }
-
-    /** {@inheritDoc} */
-    @Override public boolean hasArray() {
-        return true;
-    }
-
-    /** {@inheritDoc} */
-    @Override protected byte readByteAndShift() {
-        return data[pos++];
-    }
-
-    /** {@inheritDoc} */
-    @Override protected void copyAndShift(Object target, long off, int len) {
-        UNSAFE.copyMemory(data, BYTE_ARR_OFF + pos, target, off, len);
-
-        shift(len);
-    }
-
-    /** {@inheritDoc} */
-    @Override protected short readShortFast() {
-        return UNSAFE.getShort(data, BYTE_ARR_OFF + pos);
-    }
-
-    /** {@inheritDoc} */
-    @Override protected char readCharFast() {
-        return UNSAFE.getChar(data, BYTE_ARR_OFF + pos);
-    }
-
-    /** {@inheritDoc} */
-    @Override protected int readIntFast() {
-        return UNSAFE.getInt(data, BYTE_ARR_OFF + pos);
-    }
-
-    /** {@inheritDoc} */
-    @Override protected long readLongFast() {
-        return UNSAFE.getLong(data, BYTE_ARR_OFF + pos);
-    }
-
-    /** {@inheritDoc} */
-    @Override protected byte readBytePositioned0(int pos) {
-        return UNSAFE.getByte(data, BYTE_ARR_OFF + pos);
-    }
-
-    /** {@inheritDoc} */
-    @Override protected short readShortPositioned0(int pos) {
-        short res = UNSAFE.getShort(data, BYTE_ARR_OFF + pos);
-
-        if (!LITTLE_ENDIAN)
-            res = Short.reverseBytes(res);
-
-        return res;
-    }
-
-    /** {@inheritDoc} */
-    @Override protected int readIntPositioned0(int pos) {
-        int res = UNSAFE.getInt(data, BYTE_ARR_OFF + pos);
-
-        if (!LITTLE_ENDIAN)
-            res = Integer.reverseBytes(res);
-
-        return res;
-    }
-}

http://git-wip-us.apache.org/repos/asf/ignite/blob/71ad9cea/modules/core/src/main/java/org/apache/ignite/internal/binary/streams/PortableHeapOutputStream.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/binary/streams/PortableHeapOutputStream.java b/modules/core/src/main/java/org/apache/ignite/internal/binary/streams/PortableHeapOutputStream.java
deleted file mode 100644
index 8f9ca4a..0000000
--- a/modules/core/src/main/java/org/apache/ignite/internal/binary/streams/PortableHeapOutputStream.java
+++ /dev/null
@@ -1,176 +0,0 @@
-/*
- * 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.binary.streams;
-
-/**
- * Portable heap output stream.
- */
-public final class PortableHeapOutputStream extends PortableAbstractOutputStream {
-    /** Allocator. */
-    private final PortableMemoryAllocatorChunk chunk;
-
-    /** Data. */
-    private byte[] data;
-
-    /**
-     * Constructor.
-     *
-     * @param cap Initial capacity.
-     */
-    public PortableHeapOutputStream(int cap) {
-        this(cap, PortableMemoryAllocator.INSTANCE.chunk());
-    }
-
-    /**
-     * Constructor.
-     *
-     * @param cap Capacity.
-     * @param chunk Chunk.
-     */
-    public PortableHeapOutputStream(int cap, PortableMemoryAllocatorChunk chunk) {
-        this.chunk = chunk;
-
-        data = chunk.allocate(cap);
-    }
-
-    /** {@inheritDoc} */
-    @Override public void close() {
-        chunk.release(data, pos);
-    }
-
-    /** {@inheritDoc} */
-    @Override public void ensureCapacity(int cnt) {
-        if (cnt > data.length) {
-            int newCap = capacity(data.length, cnt);
-
-            data = chunk.reallocate(data, newCap);
-        }
-    }
-
-    /** {@inheritDoc} */
-    @Override public byte[] array() {
-        return data;
-    }
-
-    /** {@inheritDoc} */
-    @Override public byte[] arrayCopy() {
-        byte[] res = new byte[pos];
-
-        UNSAFE.copyMemory(data, BYTE_ARR_OFF, res, BYTE_ARR_OFF, pos);
-
-        return res;
-    }
-
-    /** {@inheritDoc} */
-    @Override public boolean hasArray() {
-        return true;
-    }
-
-    /** {@inheritDoc} */
-    @Override protected void writeByteAndShift(byte val) {
-        data[pos++] = val;
-    }
-
-    /** {@inheritDoc} */
-    @Override protected void copyAndShift(Object src, long off, int len) {
-        UNSAFE.copyMemory(src, off, data, BYTE_ARR_OFF + pos, len);
-
-        shift(len);
-    }
-
-    /** {@inheritDoc} */
-    @Override protected void writeShortFast(short val) {
-        UNSAFE.putShort(data, BYTE_ARR_OFF + pos, val);
-    }
-
-    /** {@inheritDoc} */
-    @Override protected void writeCharFast(char val) {
-        UNSAFE.putChar(data, BYTE_ARR_OFF + pos, val);
-    }
-
-    /** {@inheritDoc} */
-    @Override protected void writeIntFast(int val) {
-        UNSAFE.putInt(data, BYTE_ARR_OFF + pos, val);
-    }
-
-    /** {@inheritDoc} */
-    @Override protected void writeLongFast(long val) {
-        UNSAFE.putLong(data, BYTE_ARR_OFF + pos, val);
-    }
-
-    /** {@inheritDoc} */
-    @Override public void unsafeWriteByte(byte val) {
-        UNSAFE.putByte(data, BYTE_ARR_OFF + pos++, val);
-    }
-
-    /** {@inheritDoc} */
-    @Override public void unsafeWriteShort(short val) {
-        if (!LITTLE_ENDIAN)
-            val = Short.reverseBytes(val);
-
-        UNSAFE.putShort(data, BYTE_ARR_OFF + pos, val);
-
-        shift(2);
-    }
-
-    /** {@inheritDoc} */
-    @Override public void unsafeWriteShort(int pos, short val) {
-        if (!LITTLE_ENDIAN)
-            val = Short.reverseBytes(val);
-
-        UNSAFE.putShort(data, BYTE_ARR_OFF + pos, val);
-    }
-
-    /** {@inheritDoc} */
-    @Override public void unsafeWriteChar(char val) {
-        if (!LITTLE_ENDIAN)
-            val = Character.reverseBytes(val);
-
-        UNSAFE.putChar(data, BYTE_ARR_OFF + pos, val);
-
-        shift(2);
-    }
-
-    /** {@inheritDoc} */
-    @Override public void unsafeWriteInt(int val) {
-        if (!LITTLE_ENDIAN)
-            val = Integer.reverseBytes(val);
-
-        UNSAFE.putInt(data, BYTE_ARR_OFF + pos, val);
-
-        shift(4);
-    }
-
-    /** {@inheritDoc} */
-    @Override public void unsafeWriteInt(int pos, int val) {
-        if (!LITTLE_ENDIAN)
-            val = Integer.reverseBytes(val);
-
-        UNSAFE.putInt(data, BYTE_ARR_OFF + pos, val);
-    }
-
-    /** {@inheritDoc} */
-    @Override public void unsafeWriteLong(long val) {
-        if (!LITTLE_ENDIAN)
-            val = Long.reverseBytes(val);
-
-        UNSAFE.putLong(data, BYTE_ARR_OFF + pos, val);
-
-        shift(8);
-    }
-}

http://git-wip-us.apache.org/repos/asf/ignite/blob/71ad9cea/modules/core/src/main/java/org/apache/ignite/internal/binary/streams/PortableInputStream.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/binary/streams/PortableInputStream.java b/modules/core/src/main/java/org/apache/ignite/internal/binary/streams/PortableInputStream.java
deleted file mode 100644
index cf71dc7..0000000
--- a/modules/core/src/main/java/org/apache/ignite/internal/binary/streams/PortableInputStream.java
+++ /dev/null
@@ -1,163 +0,0 @@
-/*
- * 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.binary.streams;
-
-import org.apache.ignite.internal.binary.PortablePositionReadable;
-import org.apache.ignite.internal.binary.PortablePositionReadable;
-
-/**
- * Portable input stream.
- */
-public interface PortableInputStream extends PortableStream, PortablePositionReadable {
-    /**
-     * Read byte value.
-     *
-     * @return Byte value.
-     */
-    public byte readByte();
-
-    /**
-     * Read byte array.
-     *
-     * @param cnt Expected item count.
-     * @return Byte array.
-     */
-    public byte[] readByteArray(int cnt);
-
-    /**
-     * Reads {@code cnt} of bytes into byte array.
-     *
-     * @param arr Expected item count.
-     * @param off offset
-     * @param cnt number of bytes to read.
-     * @return actual length read.
-     */
-    public int read(byte[] arr, int off, int cnt);
-
-    /**
-     * Read boolean value.
-     *
-     * @return Boolean value.
-     */
-    public boolean readBoolean();
-
-    /**
-     * Read boolean array.
-     *
-     * @param cnt Expected item count.
-     * @return Boolean array.
-     */
-    public boolean[] readBooleanArray(int cnt);
-
-    /**
-     * Read short value.
-     *
-     * @return Short value.
-     */
-    public short readShort();
-
-    /**
-     * Read short array.
-     *
-     * @param cnt Expected item count.
-     * @return Short array.
-     */
-    public short[] readShortArray(int cnt);
-
-    /**
-     * Read char value.
-     *
-     * @return Char value.
-     */
-    public char readChar();
-
-    /**
-     * Read char array.
-     *
-     * @param cnt Expected item count.
-     * @return Char array.
-     */
-    public char[] readCharArray(int cnt);
-
-    /**
-     * Read int value.
-     *
-     * @return Int value.
-     */
-    public int readInt();
-
-    /**
-     * Read int array.
-     *
-     * @param cnt Expected item count.
-     * @return Int array.
-     */
-    public int[] readIntArray(int cnt);
-
-    /**
-     * Read float value.
-     *
-     * @return Float value.
-     */
-    public float readFloat();
-
-    /**
-     * Read float array.
-     *
-     * @param cnt Expected item count.
-     * @return Float array.
-     */
-    public float[] readFloatArray(int cnt);
-
-    /**
-     * Read long value.
-     *
-     * @return Long value.
-     */
-    public long readLong();
-
-    /**
-     * Read long array.
-     *
-     * @param cnt Expected item count.
-     * @return Long array.
-     */
-    public long[] readLongArray(int cnt);
-
-    /**
-     * Read double value.
-     *
-     * @return Double value.
-     */
-    public double readDouble();
-
-    /**
-     * Read double array.
-     *
-     * @param cnt Expected item count.
-     * @return Double array.
-     */
-    public double[] readDoubleArray(int cnt);
-
-    /**
-     * Gets amount of remaining data in bytes.
-     *
-     * @return Remaining data.
-     */
-    public int remaining();
-}

http://git-wip-us.apache.org/repos/asf/ignite/blob/71ad9cea/modules/core/src/main/java/org/apache/ignite/internal/binary/streams/PortableMemoryAllocator.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/binary/streams/PortableMemoryAllocator.java b/modules/core/src/main/java/org/apache/ignite/internal/binary/streams/PortableMemoryAllocator.java
deleted file mode 100644
index f20a7bc..0000000
--- a/modules/core/src/main/java/org/apache/ignite/internal/binary/streams/PortableMemoryAllocator.java
+++ /dev/null
@@ -1,57 +0,0 @@
-/*
- * 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.binary.streams;
-
-/**
- * Thread-local memory allocator.
- */
-public final class PortableMemoryAllocator {
-    /** Memory allocator instance. */
-    public static final PortableMemoryAllocator INSTANCE = new PortableMemoryAllocator();
-
-    /** Holders. */
-    private static final ThreadLocal<PortableMemoryAllocatorChunk> holders = new ThreadLocal<>();
-
-    /**
-     * Ensures singleton.
-     */
-    private PortableMemoryAllocator() {
-        // No-op.
-    }
-
-    public PortableMemoryAllocatorChunk chunk() {
-        PortableMemoryAllocatorChunk holder = holders.get();
-
-        if (holder == null)
-            holders.set(holder = new PortableMemoryAllocatorChunk());
-
-        return holder;
-    }
-
-    /**
-     * Checks whether a thread-local array is acquired or not.
-     * The function is used by Unit tests.
-     *
-     * @return {@code true} if acquired {@code false} otherwise.
-     */
-    public boolean isAcquired() {
-        PortableMemoryAllocatorChunk holder = holders.get();
-
-        return holder != null && holder.isAcquired();
-    }
-}

http://git-wip-us.apache.org/repos/asf/ignite/blob/71ad9cea/modules/core/src/main/java/org/apache/ignite/internal/binary/streams/PortableMemoryAllocatorChunk.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/binary/streams/PortableMemoryAllocatorChunk.java b/modules/core/src/main/java/org/apache/ignite/internal/binary/streams/PortableMemoryAllocatorChunk.java
deleted file mode 100644
index 749a0b4..0000000
--- a/modules/core/src/main/java/org/apache/ignite/internal/binary/streams/PortableMemoryAllocatorChunk.java
+++ /dev/null
@@ -1,117 +0,0 @@
-/*
- * 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.binary.streams;
-
-import org.apache.ignite.internal.util.GridUnsafe;
-import org.apache.ignite.internal.util.typedef.internal.U;
-import sun.misc.Unsafe;
-
-import static org.apache.ignite.IgniteSystemProperties.IGNITE_MARSHAL_BUFFERS_RECHECK;
-
-/**
- * Memory allocator chunk.
- */
-public class PortableMemoryAllocatorChunk {
-    /** Unsafe instance. */
-    protected static final Unsafe UNSAFE = GridUnsafe.unsafe();
-
-    /** Array offset: byte. */
-    protected static final long BYTE_ARR_OFF = UNSAFE.arrayBaseOffset(byte[].class);
-
-    /** Buffer size re-check frequency. */
-    private static final Long CHECK_FREQ = Long.getLong(IGNITE_MARSHAL_BUFFERS_RECHECK, 10000);
-
-    /** Data array */
-    private byte[] data;
-
-    /** Max message size detected between checks. */
-    private int maxMsgSize;
-
-    /** Last time array size is checked. */
-    private long lastCheck = U.currentTimeMillis();
-
-    /** Whether the holder is acquired or not. */
-    private boolean acquired;
-
-    /**
-     * Allocate.
-     *
-     * @param size Desired size.
-     * @return Data.
-     */
-    public byte[] allocate(int size) {
-        if (acquired)
-            return new byte[size];
-
-        acquired = true;
-
-        if (data == null || size > data.length)
-            data = new byte[size];
-
-        return data;
-    }
-
-    /**
-     * Reallocate.
-     *
-     * @param data Old data.
-     * @param size Size.
-     * @return New data.
-     */
-    public byte[] reallocate(byte[] data, int size) {
-        byte[] newData = new byte[size];
-
-        if (this.data == data)
-            this.data = newData;
-
-        UNSAFE.copyMemory(data, BYTE_ARR_OFF, newData, BYTE_ARR_OFF, data.length);
-
-        return newData;
-    }
-
-    /**
-     * Shrinks array size if needed.
-     */
-    public void release(byte[] data, int maxMsgSize) {
-        if (this.data != data)
-            return;
-
-        if (maxMsgSize > this.maxMsgSize)
-            this.maxMsgSize = maxMsgSize;
-
-        this.acquired = false;
-
-        long now = U.currentTimeMillis();
-
-        if (now - this.lastCheck >= CHECK_FREQ) {
-            int halfSize = data.length >> 1;
-
-            if (this.maxMsgSize < halfSize)
-                this.data = new byte[halfSize];
-
-            this.lastCheck = now;
-        }
-    }
-
-    /**
-     * @return {@code True} if acquired.
-     */
-    public boolean isAcquired() {
-        return acquired;
-    }
-}

http://git-wip-us.apache.org/repos/asf/ignite/blob/71ad9cea/modules/core/src/main/java/org/apache/ignite/internal/binary/streams/PortableOffheapInputStream.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/binary/streams/PortableOffheapInputStream.java b/modules/core/src/main/java/org/apache/ignite/internal/binary/streams/PortableOffheapInputStream.java
deleted file mode 100644
index 2a4d7d7..0000000
--- a/modules/core/src/main/java/org/apache/ignite/internal/binary/streams/PortableOffheapInputStream.java
+++ /dev/null
@@ -1,144 +0,0 @@
-/*
- * 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.binary.streams;
-
-/**
- * Portable off-heap input stream.
- */
-public class PortableOffheapInputStream extends PortableAbstractInputStream {
-    /** Pointer. */
-    private final long ptr;
-
-    /** Capacity. */
-    private final int cap;
-
-    /** */
-    private boolean forceHeap;
-
-    /**
-     * Constructor.
-     *
-     * @param ptr Pointer.
-     * @param cap Capacity.
-     */
-    public PortableOffheapInputStream(long ptr, int cap) {
-        this(ptr, cap, false);
-    }
-
-    /**
-     * Constructor.
-     *
-     * @param ptr Pointer.
-     * @param cap Capacity.
-     * @param forceHeap If {@code true} method {@link #offheapPointer} returns 0 and unmarshalling will
-     *        create heap-based objects.
-     */
-    public PortableOffheapInputStream(long ptr, int cap, boolean forceHeap) {
-        this.ptr = ptr;
-        this.cap = cap;
-        this.forceHeap = forceHeap;
-
-        len = cap;
-    }
-
-    /** {@inheritDoc} */
-    @Override public int remaining() {
-        return cap - pos;
-    }
-
-    /** {@inheritDoc} */
-    @Override public byte[] array() {
-        return arrayCopy();
-    }
-
-    /** {@inheritDoc} */
-    @Override public byte[] arrayCopy() {
-        byte[] res = new byte[len];
-
-        UNSAFE.copyMemory(null, ptr, res, BYTE_ARR_OFF, res.length);
-
-        return res;
-    }
-
-    /** {@inheritDoc} */
-    @Override public boolean hasArray() {
-        return false;
-    }
-
-    /** {@inheritDoc} */
-    @Override protected byte readByteAndShift() {
-        return UNSAFE.getByte(ptr + pos++);
-    }
-
-    /** {@inheritDoc} */
-    @Override protected void copyAndShift(Object target, long off, int len) {
-        UNSAFE.copyMemory(null, ptr + pos, target, off, len);
-
-        shift(len);
-    }
-
-    /** {@inheritDoc} */
-    @Override protected short readShortFast() {
-        return UNSAFE.getShort(ptr + pos);
-    }
-
-    /** {@inheritDoc} */
-    @Override protected char readCharFast() {
-        return UNSAFE.getChar(ptr + pos);
-    }
-
-    /** {@inheritDoc} */
-    @Override protected int readIntFast() {
-        return UNSAFE.getInt(ptr + pos);
-    }
-
-    /** {@inheritDoc} */
-    @Override protected long readLongFast() {
-        return UNSAFE.getLong(ptr + pos);
-    }
-
-    /** {@inheritDoc} */
-    @Override protected byte readBytePositioned0(int pos) {
-        return UNSAFE.getByte(ptr + pos);
-    }
-
-    /** {@inheritDoc} */
-    @Override protected short readShortPositioned0(int pos) {
-        short res = UNSAFE.getShort(ptr + pos);
-
-        if (!LITTLE_ENDIAN)
-            res = Short.reverseBytes(res);
-
-        return res;
-    }
-
-    /** {@inheritDoc} */
-    @Override protected int readIntPositioned0(int pos) {
-        int res = UNSAFE.getInt(ptr + pos);
-
-        if (!LITTLE_ENDIAN)
-            res = Integer.reverseBytes(res);
-
-        return res;
-    }
-
-    /** {@inheritDoc} */
-    @Override public long offheapPointer() {
-        return forceHeap ? 0 : ptr;
-    }
-}

http://git-wip-us.apache.org/repos/asf/ignite/blob/71ad9cea/modules/core/src/main/java/org/apache/ignite/internal/binary/streams/PortableOffheapOutputStream.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/binary/streams/PortableOffheapOutputStream.java b/modules/core/src/main/java/org/apache/ignite/internal/binary/streams/PortableOffheapOutputStream.java
deleted file mode 100644
index 9bcb1f4..0000000
--- a/modules/core/src/main/java/org/apache/ignite/internal/binary/streams/PortableOffheapOutputStream.java
+++ /dev/null
@@ -1,222 +0,0 @@
-/*
- * 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.binary.streams;
-
-/**
- * Portable offheap output stream.
- */
-public class PortableOffheapOutputStream extends PortableAbstractOutputStream {
-    /** Pointer. */
-    private long ptr;
-
-    /** Length of bytes that cen be used before resize is necessary. */
-    private int cap;
-
-    /**
-     * Constructor.
-     *
-     * @param cap Capacity.
-     */
-    public PortableOffheapOutputStream(int cap) {
-        this(0, cap);
-    }
-
-    /**
-     * Constructor.
-     *
-     * @param ptr Pointer to existing address.
-     * @param cap Capacity.
-     */
-    public PortableOffheapOutputStream(long ptr, int cap) {
-        this.ptr = ptr == 0 ? allocate(cap) : ptr;
-
-        this.cap = cap;
-    }
-
-    /** {@inheritDoc} */
-    @Override public void close() {
-        release(ptr);
-    }
-
-    /** {@inheritDoc} */
-    @Override public void ensureCapacity(int cnt) {
-        if (cnt > cap) {
-            int newCap = capacity(cap, cnt);
-
-            ptr = reallocate(ptr, newCap);
-
-            cap = newCap;
-        }
-    }
-
-    /** {@inheritDoc} */
-    @Override public byte[] array() {
-        return arrayCopy();
-    }
-
-    /** {@inheritDoc} */
-    @Override public byte[] arrayCopy() {
-        byte[] res = new byte[pos];
-
-        UNSAFE.copyMemory(null, ptr, res, BYTE_ARR_OFF, pos);
-
-        return res;
-    }
-
-    /**
-     * @return Pointer.
-     */
-    public long pointer() {
-        return ptr;
-    }
-
-    /**
-     * @return Capacity.
-     */
-    public int capacity() {
-        return cap;
-    }
-
-    /** {@inheritDoc} */
-    @Override protected void writeByteAndShift(byte val) {
-        UNSAFE.putByte(ptr + pos++, val);
-    }
-
-    /** {@inheritDoc} */
-    @Override protected void copyAndShift(Object src, long offset, int len) {
-        UNSAFE.copyMemory(src, offset, null, ptr + pos, len);
-
-        shift(len);
-    }
-
-    /** {@inheritDoc} */
-    @Override protected void writeShortFast(short val) {
-        UNSAFE.putShort(ptr + pos, val);
-    }
-
-    /** {@inheritDoc} */
-    @Override protected void writeCharFast(char val) {
-        UNSAFE.putChar(ptr + pos, val);
-    }
-
-    /** {@inheritDoc} */
-    @Override protected void writeIntFast(int val) {
-        UNSAFE.putInt(ptr + pos, val);
-    }
-
-    /** {@inheritDoc} */
-    @Override protected void writeLongFast(long val) {
-        UNSAFE.putLong(ptr + pos, val);
-    }
-
-    /** {@inheritDoc} */
-    @Override public boolean hasArray() {
-        return false;
-    }
-
-    /** {@inheritDoc} */
-    @Override public void unsafeWriteByte(byte val) {
-        UNSAFE.putByte(ptr + pos++, val);
-    }
-
-    /** {@inheritDoc} */
-    @Override public void unsafeWriteShort(short val) {
-        if (!LITTLE_ENDIAN)
-            val = Short.reverseBytes(val);
-
-        UNSAFE.putShort(ptr + pos, val);
-
-        shift(2);
-    }
-
-    /** {@inheritDoc} */
-    @Override public void unsafeWriteShort(int pos, short val) {
-        if (!LITTLE_ENDIAN)
-            val = Short.reverseBytes(val);
-
-        UNSAFE.putShort(ptr + pos, val);
-    }
-
-    /** {@inheritDoc} */
-    @Override public void unsafeWriteChar(char val) {
-        if (!LITTLE_ENDIAN)
-            val = Character.reverseBytes(val);
-
-        UNSAFE.putChar(ptr + pos, val);
-
-        shift(2);
-    }
-
-    /** {@inheritDoc} */
-    @Override public void unsafeWriteInt(int val) {
-        if (!LITTLE_ENDIAN)
-            val = Integer.reverseBytes(val);
-
-        UNSAFE.putInt(ptr + pos, val);
-
-        shift(4);
-    }
-
-    /** {@inheritDoc} */
-    @Override public void unsafeWriteInt(int pos, int val) {
-        if (!LITTLE_ENDIAN)
-            val = Integer.reverseBytes(val);
-
-        UNSAFE.putInt(ptr + pos, val);
-    }
-
-    /** {@inheritDoc} */
-    @Override public void unsafeWriteLong(long val) {
-        if (!LITTLE_ENDIAN)
-            val = Long.reverseBytes(val);
-
-        UNSAFE.putLong(ptr + pos, val);
-
-        shift(8);
-    }
-
-    /**
-     * Allocate memory.
-     *
-     * @param cap Capacity.
-     * @return Pointer.
-     */
-    protected long allocate(int cap) {
-        return UNSAFE.allocateMemory(cap);
-    }
-
-    /**
-     * Reallocate memory.
-     *
-     * @param ptr Old pointer.
-     * @param cap Capacity.
-     * @return New pointer.
-     */
-    protected long reallocate(long ptr, int cap) {
-        return UNSAFE.reallocateMemory(ptr, cap);
-    }
-
-    /**
-     * Release memory.
-     *
-     * @param ptr Pointer.
-     */
-    protected void release(long ptr) {
-        UNSAFE.freeMemory(ptr);
-    }
-}

http://git-wip-us.apache.org/repos/asf/ignite/blob/71ad9cea/modules/core/src/main/java/org/apache/ignite/internal/binary/streams/PortableOutputStream.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/binary/streams/PortableOutputStream.java b/modules/core/src/main/java/org/apache/ignite/internal/binary/streams/PortableOutputStream.java
deleted file mode 100644
index a686e54..0000000
--- a/modules/core/src/main/java/org/apache/ignite/internal/binary/streams/PortableOutputStream.java
+++ /dev/null
@@ -1,259 +0,0 @@
-/*
- * 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.binary.streams;
-
-/**
- * Portable output stream.
- */
-public interface PortableOutputStream extends PortableStream, AutoCloseable {
-    /**
-     * Write byte value.
-     *
-     * @param val Byte value.
-     */
-    public void writeByte(byte val);
-
-    /**
-     * Write byte array.
-     *
-     * @param val Byte array.
-     */
-    public void writeByteArray(byte[] val);
-
-    /**
-     * Write boolean value.
-     *
-     * @param val Boolean value.
-     */
-    public void writeBoolean(boolean val);
-
-    /**
-     * Write boolean array.
-     *
-     * @param val Boolean array.
-     */
-    public void writeBooleanArray(boolean[] val);
-
-    /**
-     * Write short value.
-     *
-     * @param val Short value.
-     */
-    public void writeShort(short val);
-
-    /**
-     * Write short array.
-     *
-     * @param val Short array.
-     */
-    public void writeShortArray(short[] val);
-
-    /**
-     * Write char value.
-     *
-     * @param val Char value.
-     */
-    public void writeChar(char val);
-
-    /**
-     * Write char array.
-     *
-     * @param val Char array.
-     */
-    public void writeCharArray(char[] val);
-
-    /**
-     * Write int value.
-     *
-     * @param val Int value.
-     */
-    public void writeInt(int val);
-
-    /**
-     * Write short value at the given position.
-     *
-     * @param pos Position.
-     * @param val Value.
-     */
-    public void writeShort(int pos, short val);
-
-    /**
-     * Write int value to the given position.
-     *
-     * @param pos Position.
-     * @param val Value.
-     */
-    public void writeInt(int pos, int val);
-
-    /**
-     * Write int array.
-     *
-     * @param val Int array.
-     */
-    public void writeIntArray(int[] val);
-
-    /**
-     * Write float value.
-     *
-     * @param val Float value.
-     */
-    public void writeFloat(float val);
-
-    /**
-     * Write float array.
-     *
-     * @param val Float array.
-     */
-    public void writeFloatArray(float[] val);
-
-    /**
-     * Write long value.
-     *
-     * @param val Long value.
-     */
-    public void writeLong(long val);
-
-    /**
-     * Write long array.
-     *
-     * @param val Long array.
-     */
-    public void writeLongArray(long[] val);
-
-    /**
-     * Write double value.
-     *
-     * @param val Double value.
-     */
-    public void writeDouble(double val);
-
-    /**
-     * Write double array.
-     *
-     * @param val Double array.
-     */
-    public void writeDoubleArray(double[] val);
-
-    /**
-     * Write byte array.
-     *
-     * @param arr Array.
-     * @param off Offset.
-     * @param len Length.
-     */
-    public void write(byte[] arr, int off, int len);
-
-    /**
-     * Write data from unmanaged memory.
-     *
-     * @param addr Address.
-     * @param cnt Count.
-     */
-    public void write(long addr, int cnt);
-
-    /**
-     * Close the stream releasing resources.
-     */
-    @Override public void close();
-
-    /**
-     * Set position in unsafe mode.
-     *
-     * @param pos Position.
-     */
-    public void unsafePosition(int pos);
-
-    /**
-     * Ensure capacity for unsafe writes.
-     *
-     * @param cap Capacity.
-     */
-    public void unsafeEnsure(int cap);
-
-    /**
-     * Write byte in unsafe mode.
-     *
-     * @param val Value.
-     */
-    public void unsafeWriteByte(byte val);
-
-    /**
-     * Write boolean in unsafe mode.
-     *
-     * @param val Value.
-     */
-    public void unsafeWriteBoolean(boolean val);
-
-    /**
-     * Write short in unsafe mode.
-     *
-     * @param val Value.
-     */
-    public void unsafeWriteShort(short val);
-
-    /**
-     * Write short in unsafe mode.
-     *
-     * @param pos Position.
-     * @param val Value.
-     */
-    public void unsafeWriteShort(int pos, short val);
-
-    /**
-     * Write char in unsafe mode.
-     *
-     * @param val Value.
-     */
-    public void unsafeWriteChar(char val);
-
-    /**
-     * Write int in unsafe mode.
-     *
-     * @param val Value.
-     */
-    public void unsafeWriteInt(int val);
-
-    /**
-     * Write int in unsafe mode.
-     *
-     * @param pos Position.
-     * @param val Value.
-     */
-    public void unsafeWriteInt(int pos, int val);
-
-    /**
-     * Write long in unsafe mode.
-     *
-     * @param val Value.
-     */
-    public void unsafeWriteLong(long val);
-
-    /**
-     * Write float in unsafe mode.
-     *
-     * @param val Value.
-     */
-    public void unsafeWriteFloat(float val);
-
-    /**
-     * Write double in unsafe mode.
-     *
-     * @param val Value.
-     */
-    public void unsafeWriteDouble(double val);
-}

http://git-wip-us.apache.org/repos/asf/ignite/blob/71ad9cea/modules/core/src/main/java/org/apache/ignite/internal/binary/streams/PortableStream.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/binary/streams/PortableStream.java b/modules/core/src/main/java/org/apache/ignite/internal/binary/streams/PortableStream.java
deleted file mode 100644
index 18d4609..0000000
--- a/modules/core/src/main/java/org/apache/ignite/internal/binary/streams/PortableStream.java
+++ /dev/null
@@ -1,53 +0,0 @@
-/*
- * 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.binary.streams;
-
-/**
- * Portable stream.
- */
-public interface PortableStream {
-    /**
-     * @return Position.
-     */
-    public int position();
-
-    /**
-     * @param pos Position.
-     */
-    public void position(int pos);
-
-    /**
-     * @return Underlying array.
-     */
-    public byte[] array();
-
-    /**
-     * @return Copy of data in the stream.
-     */
-    public byte[] arrayCopy();
-
-    /**
-     * @return Offheap pointer if stream is offheap based, otherwise {@code 0}.
-     */
-    public long offheapPointer();
-
-    /**
-     * @return {@code True} is stream is array based.
-     */
-    public boolean hasArray();
-}

http://git-wip-us.apache.org/repos/asf/ignite/blob/71ad9cea/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheObjectContext.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheObjectContext.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheObjectContext.java
index 6c6c0d2..88a8027 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheObjectContext.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheObjectContext.java
@@ -23,7 +23,7 @@ import java.util.Map;
 import java.util.Set;
 import org.apache.ignite.cache.affinity.AffinityKeyMapper;
 import org.apache.ignite.internal.GridKernalContext;
-import org.apache.ignite.internal.binary.PortableUtils;
+import org.apache.ignite.internal.binary.BinaryUtils;
 import org.apache.ignite.internal.processors.cacheobject.IgniteCacheObjectProcessor;
 import org.apache.ignite.internal.util.typedef.F;
 
@@ -203,7 +203,7 @@ import org.apache.ignite.internal.util.typedef.F;
         if (keepPortable)
             return map;
 
-        Map<Object, Object> map0 = PortableUtils.newMap(map);
+        Map<Object, Object> map0 = BinaryUtils.newMap(map);
 
         for (Map.Entry<Object, Object> e : map.entrySet())
             map0.put(unwrapPortable(e.getKey(), keepPortable, cpy), unwrapPortable(e.getValue(), keepPortable, cpy));
@@ -241,7 +241,7 @@ import org.apache.ignite.internal.util.typedef.F;
      * @return Unwrapped set.
      */
     private Set<Object> unwrapPortables(Set<Object> set, boolean keepPortable, boolean cpy) {
-        Set<Object> set0 = PortableUtils.newSet(set);
+        Set<Object> set0 = BinaryUtils.newSet(set);
 
         for (Object obj : set)
             set0.add(unwrapPortable(obj, keepPortable, cpy));

http://git-wip-us.apache.org/repos/asf/ignite/blob/71ad9cea/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/binary/BinaryMetadataKey.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/binary/BinaryMetadataKey.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/binary/BinaryMetadataKey.java
new file mode 100644
index 0000000..f6204fb
--- /dev/null
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/binary/BinaryMetadataKey.java
@@ -0,0 +1,82 @@
+/*
+ * 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.processors.cache.binary;
+
+import java.io.Externalizable;
+import java.io.IOException;
+import java.io.ObjectInput;
+import java.io.ObjectOutput;
+import org.apache.ignite.internal.processors.cache.GridCacheUtilityKey;
+import org.apache.ignite.internal.util.typedef.internal.S;
+
+/**
+ * Key for portable meta data.
+ */
+class BinaryMetadataKey extends GridCacheUtilityKey<BinaryMetadataKey> implements Externalizable {
+    /** */
+    private static final long serialVersionUID = 0L;
+
+    /** */
+    private int typeId;
+
+    /**
+     * For {@link Externalizable}.
+     */
+    public BinaryMetadataKey() {
+        // No-op.
+    }
+
+    /**
+     * @param typeId Type ID.
+     */
+    BinaryMetadataKey(int typeId) {
+        this.typeId = typeId;
+    }
+
+    /**
+     * @return Type id.
+     */
+    public int typeId() {
+        return typeId;
+    }
+
+    /** {@inheritDoc} */
+    @Override public void writeExternal(ObjectOutput out) throws IOException {
+        out.writeInt(typeId);
+    }
+
+    /** {@inheritDoc} */
+    @Override public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
+        typeId = in.readInt();
+    }
+
+    /** {@inheritDoc} */
+    @Override protected boolean equalsx(BinaryMetadataKey key) {
+        return typeId == key.typeId;
+    }
+
+    /** {@inheritDoc} */
+    @Override public int hashCode() {
+        return typeId;
+    }
+
+    /** {@inheritDoc} */
+    @Override public String toString() {
+        return S.toString(BinaryMetadataKey.class, this);
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/71ad9cea/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/binary/CacheDefaultBinaryAffinityKeyMapper.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/binary/CacheDefaultBinaryAffinityKeyMapper.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/binary/CacheDefaultBinaryAffinityKeyMapper.java
new file mode 100644
index 0000000..c0a4612
--- /dev/null
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/binary/CacheDefaultBinaryAffinityKeyMapper.java
@@ -0,0 +1,51 @@
+/*
+ * 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.processors.cache.binary;
+
+import org.apache.ignite.IgniteException;
+import org.apache.ignite.internal.IgniteKernal;
+import org.apache.ignite.internal.processors.cache.GridCacheDefaultAffinityKeyMapper;
+import org.apache.ignite.internal.util.typedef.internal.U;
+import org.apache.ignite.binary.BinaryObject;
+
+/**
+ *
+ */
+public class CacheDefaultBinaryAffinityKeyMapper extends GridCacheDefaultAffinityKeyMapper {
+    /** */
+    private static final long serialVersionUID = 0L;
+
+    /** {@inheritDoc} */
+    @Override public Object affinityKey(Object key) {
+        IgniteKernal kernal = (IgniteKernal)ignite;
+
+        CacheObjectBinaryProcessorImpl proc = (CacheObjectBinaryProcessorImpl)kernal.context().cacheObjects();
+
+        try {
+            key = proc.toPortable(key);
+        }
+        catch (IgniteException e) {
+            U.error(log, "Failed to marshal key to portable: " + key, e);
+        }
+
+        if (key instanceof BinaryObject)
+            return proc.affinityKey((BinaryObject)key);
+        else
+            return super.affinityKey(key);
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/71ad9cea/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/binary/CacheDefaultPortableAffinityKeyMapper.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/binary/CacheDefaultPortableAffinityKeyMapper.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/binary/CacheDefaultPortableAffinityKeyMapper.java
deleted file mode 100644
index 698cd7b..0000000
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/binary/CacheDefaultPortableAffinityKeyMapper.java
+++ /dev/null
@@ -1,51 +0,0 @@
-/*
- * 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.processors.cache.binary;
-
-import org.apache.ignite.IgniteException;
-import org.apache.ignite.internal.IgniteKernal;
-import org.apache.ignite.internal.processors.cache.GridCacheDefaultAffinityKeyMapper;
-import org.apache.ignite.internal.util.typedef.internal.U;
-import org.apache.ignite.binary.BinaryObject;
-
-/**
- *
- */
-public class CacheDefaultPortableAffinityKeyMapper extends GridCacheDefaultAffinityKeyMapper {
-    /** */
-    private static final long serialVersionUID = 0L;
-
-    /** {@inheritDoc} */
-    @Override public Object affinityKey(Object key) {
-        IgniteKernal kernal = (IgniteKernal)ignite;
-
-        CacheObjectBinaryProcessorImpl proc = (CacheObjectBinaryProcessorImpl)kernal.context().cacheObjects();
-
-        try {
-            key = proc.toPortable(key);
-        }
-        catch (IgniteException e) {
-            U.error(log, "Failed to marshal key to portable: " + key, e);
-        }
-
-        if (key instanceof BinaryObject)
-            return proc.affinityKey((BinaryObject)key);
-        else
-            return super.affinityKey(key);
-    }
-}

http://git-wip-us.apache.org/repos/asf/ignite/blob/71ad9cea/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/binary/CacheObjectBinaryContext.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/binary/CacheObjectBinaryContext.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/binary/CacheObjectBinaryContext.java
new file mode 100644
index 0000000..039f5ce
--- /dev/null
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/binary/CacheObjectBinaryContext.java
@@ -0,0 +1,56 @@
+/*
+ * 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.processors.cache.binary;
+
+import org.apache.ignite.internal.GridKernalContext;
+import org.apache.ignite.internal.processors.cache.CacheDefaultBinaryAffinityKeyMapper;
+import org.apache.ignite.internal.processors.cache.CacheObjectContext;
+import org.apache.ignite.internal.processors.cache.GridCacheDefaultAffinityKeyMapper;
+
+/**
+ *
+ */
+public class CacheObjectBinaryContext extends CacheObjectContext {
+    /** */
+    private boolean portableEnabled;
+
+    /**
+     * @param kernalCtx Kernal context.
+     * @param portableEnabled Portable enabled flag.
+     * @param cpyOnGet Copy on get flag.
+     * @param storeVal {@code True} if should store unmarshalled value in cache.
+     * @param depEnabled {@code true} if deployment is enabled for the given cache.
+     */
+    public CacheObjectBinaryContext(GridKernalContext kernalCtx,
+        boolean cpyOnGet,
+        boolean storeVal,
+        boolean portableEnabled,
+        boolean depEnabled) {
+        super(kernalCtx, portableEnabled ? new CacheDefaultBinaryAffinityKeyMapper() :
+            new GridCacheDefaultAffinityKeyMapper(), cpyOnGet, storeVal, depEnabled);
+
+        this.portableEnabled = portableEnabled;
+    }
+
+    /**
+     * @return Portable enabled flag.
+     */
+    public boolean portableEnabled() {
+        return portableEnabled;
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/71ad9cea/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/binary/CacheObjectBinaryProcessorImpl.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/binary/CacheObjectBinaryProcessorImpl.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/binary/CacheObjectBinaryProcessorImpl.java
index 12e7078..a9f0d74 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/binary/CacheObjectBinaryProcessorImpl.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/binary/CacheObjectBinaryProcessorImpl.java
@@ -57,12 +57,12 @@ import org.apache.ignite.internal.binary.BinaryObjectEx;
 import org.apache.ignite.internal.binary.BinaryObjectImpl;
 import org.apache.ignite.internal.binary.BinaryObjectOffheapImpl;
 import org.apache.ignite.internal.binary.BinaryTypeImpl;
-import org.apache.ignite.internal.binary.GridPortableMarshaller;
-import org.apache.ignite.internal.binary.PortableContext;
-import org.apache.ignite.internal.binary.PortableUtils;
+import org.apache.ignite.internal.binary.GridBinaryMarshaller;
+import org.apache.ignite.internal.binary.BinaryContext;
+import org.apache.ignite.internal.binary.BinaryUtils;
 import org.apache.ignite.internal.binary.builder.BinaryObjectBuilderImpl;
-import org.apache.ignite.internal.binary.streams.PortableInputStream;
-import org.apache.ignite.internal.binary.streams.PortableOffheapInputStream;
+import org.apache.ignite.internal.binary.streams.BinaryInputStream;
+import org.apache.ignite.internal.binary.streams.BinaryOffheapInputStream;
 import org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion;
 import org.apache.ignite.internal.processors.cache.CacheEntryPredicate;
 import org.apache.ignite.internal.processors.cache.CacheEntryPredicateAdapter;
@@ -112,7 +112,7 @@ public class CacheObjectBinaryProcessorImpl extends IgniteCacheObjectProcessorIm
     private final boolean clientNode;
 
     /** */
-    private volatile IgniteCacheProxy<PortableMetadataKey, BinaryMetadata> metaDataCache;
+    private volatile IgniteCacheProxy<BinaryMetadataKey, BinaryMetadata> metaDataCache;
 
     /** */
     private final ConcurrentHashMap8<Integer, BinaryTypeImpl> clientMetaDataCache;
@@ -122,18 +122,18 @@ public class CacheObjectBinaryProcessorImpl extends IgniteCacheObjectProcessorIm
         private static final long serialVersionUID = 0L;
 
         @Override public boolean apply(GridCacheEntryEx e) {
-            return e.key().value(e.context().cacheObjectContext(), false) instanceof PortableMetadataKey;
+            return e.key().value(e.context().cacheObjectContext(), false) instanceof BinaryMetadataKey;
         }
     };
 
     /** */
-    private PortableContext portableCtx;
+    private BinaryContext portableCtx;
 
     /** */
     private Marshaller marsh;
 
     /** */
-    private GridPortableMarshaller portableMarsh;
+    private GridBinaryMarshaller portableMarsh;
 
     /** */
     @GridToStringExclude
@@ -170,11 +170,11 @@ public class CacheObjectBinaryProcessorImpl extends IgniteCacheObjectProcessorIm
 
                     if (metaDataCache == null) {
                         BinaryMetadata oldMeta = metaBuf.get(typeId);
-                        BinaryMetadata mergedMeta = PortableUtils.mergeMetadata(oldMeta, newMeta0);
+                        BinaryMetadata mergedMeta = BinaryUtils.mergeMetadata(oldMeta, newMeta0);
 
                         if (oldMeta != mergedMeta) {
                             synchronized (this) {
-                                mergedMeta = PortableUtils.mergeMetadata(oldMeta, newMeta0);
+                                mergedMeta = BinaryUtils.mergeMetadata(oldMeta, newMeta0);
 
                                 if (oldMeta != mergedMeta)
                                     metaBuf.put(typeId, mergedMeta);
@@ -206,12 +206,12 @@ public class CacheObjectBinaryProcessorImpl extends IgniteCacheObjectProcessorIm
 
             BinaryMarshaller pMarh0 = (BinaryMarshaller)marsh;
 
-            portableCtx = new PortableContext(metaHnd, ctx.config());
+            portableCtx = new BinaryContext(metaHnd, ctx.config());
 
             IgniteUtils.invoke(BinaryMarshaller.class, pMarh0, "setPortableContext", portableCtx,
                 ctx.config());
 
-            portableMarsh = new GridPortableMarshaller(portableCtx);
+            portableMarsh = new GridBinaryMarshaller(portableCtx);
 
             portables = new IgniteBinaryImpl(ctx, this);
         }
@@ -249,7 +249,7 @@ public class CacheObjectBinaryProcessorImpl extends IgniteCacheObjectProcessorIm
 
                 GridCacheQueryManager qryMgr = metaDataCache.context().queries();
 
-                CacheQuery<Map.Entry<PortableMetadataKey, BinaryMetadata>> qry =
+                CacheQuery<Map.Entry<BinaryMetadataKey, BinaryMetadata>> qry =
                     qryMgr.createScanQuery(new MetaDataPredicate(), null, false);
 
                 qry.keepAll(false);
@@ -257,9 +257,9 @@ public class CacheObjectBinaryProcessorImpl extends IgniteCacheObjectProcessorIm
                 qry.projection(ctx.cluster().get().forNode(oldestSrvNode));
 
                 try {
-                    CacheQueryFuture<Map.Entry<PortableMetadataKey, BinaryMetadata>> fut = qry.execute();
+                    CacheQueryFuture<Map.Entry<BinaryMetadataKey, BinaryMetadata>> fut = qry.execute();
 
-                    Map.Entry<PortableMetadataKey, BinaryMetadata> next;
+                    Map.Entry<BinaryMetadataKey, BinaryMetadata> next;
 
                     while ((next = fut.next()) != null) {
                         assert next.getKey() != null : next;
@@ -305,7 +305,7 @@ public class CacheObjectBinaryProcessorImpl extends IgniteCacheObjectProcessorIm
      * @param key Metadata key.
      * @param newMeta Metadata.
      */
-    private void addClientCacheMetaData(PortableMetadataKey key, final BinaryMetadata newMeta) {
+    private void addClientCacheMetaData(BinaryMetadataKey key, final BinaryMetadata newMeta) {
         int key0 = key.typeId();
 
         clientMetaDataCache.compute(key0, new ConcurrentHashMap8.BiFun<Integer, BinaryTypeImpl, BinaryTypeImpl>() {
@@ -315,7 +315,7 @@ public class CacheObjectBinaryProcessorImpl extends IgniteCacheObjectProcessorIm
                 BinaryMetadata oldMeta0 = oldMeta != null ? oldMeta.metadata() : null;
 
                 try {
-                    res = PortableUtils.mergeMetadata(oldMeta0, newMeta);
+                    res = BinaryUtils.mergeMetadata(oldMeta0, newMeta);
                 }
                 catch (BinaryObjectException e) {
                     res = oldMeta0;
@@ -365,7 +365,7 @@ public class CacheObjectBinaryProcessorImpl extends IgniteCacheObjectProcessorIm
         if (type != CacheObject.TYPE_BYTE_ARR) {
             assert size > 0 : size;
 
-            PortableInputStream in = new PortableOffheapInputStream(ptr, size, forceHeap);
+            BinaryInputStream in = new BinaryOffheapInputStream(ptr, size, forceHeap);
 
             return portableMarsh.unmarshal(in);
         }
@@ -379,7 +379,7 @@ public class CacheObjectBinaryProcessorImpl extends IgniteCacheObjectProcessorIm
         if (obj == null)
             return null;
 
-        if (PortableUtils.isPortableType(obj.getClass()))
+        if (BinaryUtils.isPortableType(obj.getClass()))
             return obj;
 
         if (obj instanceof Object[]) {
@@ -408,7 +408,7 @@ public class CacheObjectBinaryProcessorImpl extends IgniteCacheObjectProcessorIm
             Collection<Object> pCol;
 
             if (col instanceof Set)
-                pCol = (Collection<Object>)PortableUtils.newSet((Set<?>)col);
+                pCol = (Collection<Object>)BinaryUtils.newSet((Set<?>)col);
             else
                 pCol = new ArrayList<>(col.size());
 
@@ -421,7 +421,7 @@ public class CacheObjectBinaryProcessorImpl extends IgniteCacheObjectProcessorIm
         if (obj instanceof Map) {
             Map<?, ?> map = (Map<?, ?>)obj;
 
-            Map<Object, Object> pMap = PortableUtils.newMap((Map<Object, Object>)obj);
+            Map<Object, Object> pMap = BinaryUtils.newMap((Map<Object, Object>)obj);
 
             for (Map.Entry<?, ?> e : map.entrySet())
                 pMap.put(marshalToPortable(e.getKey()), marshalToPortable(e.getValue()));
@@ -451,7 +451,7 @@ public class CacheObjectBinaryProcessorImpl extends IgniteCacheObjectProcessorIm
     /**
      * @return Marshaller.
      */
-    public GridPortableMarshaller marshaller() {
+    public GridBinaryMarshaller marshaller() {
         return portableMarsh;
     }
 
@@ -480,11 +480,11 @@ public class CacheObjectBinaryProcessorImpl extends IgniteCacheObjectProcessorIm
 
         BinaryMetadata newMeta0 = ((BinaryTypeImpl)newMeta).metadata();
 
-        final PortableMetadataKey key = new PortableMetadataKey(typeId);
+        final BinaryMetadataKey key = new BinaryMetadataKey(typeId);
 
         try {
             BinaryMetadata oldMeta = metaDataCache.localPeek(key);
-            BinaryMetadata mergedMeta = PortableUtils.mergeMetadata(oldMeta, newMeta0);
+            BinaryMetadata mergedMeta = BinaryUtils.mergeMetadata(oldMeta, newMeta0);
 
             BinaryObjectException err = metaDataCache.invoke(key, new MetadataProcessor(mergedMeta));
 
@@ -505,12 +505,12 @@ public class CacheObjectBinaryProcessorImpl extends IgniteCacheObjectProcessorIm
                 if (typeMeta != null)
                     return typeMeta;
 
-                BinaryMetadata meta = metaDataCache.getTopologySafe(new PortableMetadataKey(typeId));
+                BinaryMetadata meta = metaDataCache.getTopologySafe(new BinaryMetadataKey(typeId));
 
                 return meta != null ? meta.wrap(portableCtx) : null;
             }
             else {
-                PortableMetadataKey key = new PortableMetadataKey(typeId);
+                BinaryMetadataKey key = new BinaryMetadataKey(typeId);
 
                 BinaryMetadata meta = metaDataCache.localPeek(key);
 
@@ -529,16 +529,16 @@ public class CacheObjectBinaryProcessorImpl extends IgniteCacheObjectProcessorIm
     @Override public Map<Integer, BinaryType> metadata(Collection<Integer> typeIds)
         throws BinaryObjectException {
         try {
-            Collection<PortableMetadataKey> keys = new ArrayList<>(typeIds.size());
+            Collection<BinaryMetadataKey> keys = new ArrayList<>(typeIds.size());
 
             for (Integer typeId : typeIds)
-                keys.add(new PortableMetadataKey(typeId));
+                keys.add(new BinaryMetadataKey(typeId));
 
-            Map<PortableMetadataKey, BinaryMetadata> meta = metaDataCache.getAll(keys);
+            Map<BinaryMetadataKey, BinaryMetadata> meta = metaDataCache.getAll(keys);
 
             Map<Integer, BinaryType> res = U.newHashMap(meta.size());
 
-            for (Map.Entry<PortableMetadataKey, BinaryMetadata> e : meta.entrySet())
+            for (Map.Entry<BinaryMetadataKey, BinaryMetadata> e : meta.entrySet())
                 res.put(e.getKey().typeId(), e.getValue().wrap(portableCtx));
 
             return res;
@@ -559,10 +559,10 @@ public class CacheObjectBinaryProcessorImpl extends IgniteCacheObjectProcessorIm
             });
         else {
             return F.viewReadOnly(metaDataCache.entrySetx(metaPred),
-                new C1<Cache.Entry<PortableMetadataKey, BinaryMetadata>, BinaryType>() {
+                new C1<Cache.Entry<BinaryMetadataKey, BinaryMetadata>, BinaryType>() {
                     private static final long serialVersionUID = 0L;
 
-                    @Override public BinaryType apply(Cache.Entry<PortableMetadataKey, BinaryMetadata> e) {
+                    @Override public BinaryType apply(Cache.Entry<BinaryMetadataKey, BinaryMetadata> e) {
                         return e.getValue().wrap(portableCtx);
                     }
                 });
@@ -571,7 +571,7 @@ public class CacheObjectBinaryProcessorImpl extends IgniteCacheObjectProcessorIm
 
     /** {@inheritDoc} */
     @Override public BinaryObject buildEnum(String typeName, int ord) throws IgniteException {
-        typeName = PortableContext.typeName(typeName);
+        typeName = BinaryContext.typeName(typeName);
 
         int typeId = portableCtx.typeId(typeName);
 
@@ -649,7 +649,7 @@ public class CacheObjectBinaryProcessorImpl extends IgniteCacheObjectProcessorIm
     /**
      * @return Portable context.
      */
-    public PortableContext portableContext() {
+    public BinaryContext portableContext() {
         return portableCtx;
     }
 
@@ -662,7 +662,7 @@ public class CacheObjectBinaryProcessorImpl extends IgniteCacheObjectProcessorIm
 
         CacheObjectContext ctx0 = super.contextForCache(cfg);
 
-        CacheObjectContext res = new CacheObjectPortableContext(ctx,
+        CacheObjectContext res = new CacheObjectBinaryContext(ctx,
             ctx0.copyOnGet(),
             ctx0.storeValue(),
             portableEnabled,
@@ -675,7 +675,7 @@ public class CacheObjectBinaryProcessorImpl extends IgniteCacheObjectProcessorIm
 
     /** {@inheritDoc} */
     @Override public byte[] marshal(CacheObjectContext ctx, Object val) throws IgniteCheckedException {
-        if (!((CacheObjectPortableContext)ctx).portableEnabled() || portableMarsh == null)
+        if (!((CacheObjectBinaryContext)ctx).portableEnabled() || portableMarsh == null)
             return super.marshal(ctx, val);
 
         byte[] arr = portableMarsh.marshal(val);
@@ -688,7 +688,7 @@ public class CacheObjectBinaryProcessorImpl extends IgniteCacheObjectProcessorIm
     /** {@inheritDoc} */
     @Override public Object unmarshal(CacheObjectContext ctx, byte[] bytes, ClassLoader clsLdr)
         throws IgniteCheckedException {
-        if (!((CacheObjectPortableContext)ctx).portableEnabled() || portableMarsh == null)
+        if (!((CacheObjectBinaryContext)ctx).portableEnabled() || portableMarsh == null)
             return super.unmarshal(ctx, bytes, clsLdr);
 
         return portableMarsh.unmarshal(bytes, clsLdr);
@@ -696,13 +696,13 @@ public class CacheObjectBinaryProcessorImpl extends IgniteCacheObjectProcessorIm
 
     /** {@inheritDoc} */
     @Override public KeyCacheObject toCacheKeyObject(CacheObjectContext ctx, Object obj, boolean userObj) {
-        if (!((CacheObjectPortableContext)ctx).portableEnabled())
+        if (!((CacheObjectBinaryContext)ctx).portableEnabled())
             return super.toCacheKeyObject(ctx, obj, userObj);
 
         if (obj instanceof KeyCacheObject)
             return (KeyCacheObject)obj;
 
-        if (((CacheObjectPortableContext)ctx).portableEnabled()) {
+        if (((CacheObjectBinaryContext)ctx).portableEnabled()) {
             obj = toPortable(obj);
 
             if (obj instanceof BinaryObject)
@@ -715,7 +715,7 @@ public class CacheObjectBinaryProcessorImpl extends IgniteCacheObjectProcessorIm
     /** {@inheritDoc} */
     @Nullable @Override public CacheObject toCacheObject(CacheObjectContext ctx, @Nullable Object obj,
         boolean userObj) {
-        if (!((CacheObjectPortableContext)ctx).portableEnabled())
+        if (!((CacheObjectBinaryContext)ctx).portableEnabled())
             return super.toCacheObject(ctx, obj, userObj);
 
         if (obj == null || obj instanceof CacheObject)
@@ -740,7 +740,7 @@ public class CacheObjectBinaryProcessorImpl extends IgniteCacheObjectProcessorIm
     /** {@inheritDoc} */
     @Override public CacheObject toCacheObject(GridCacheContext ctx, long valPtr, boolean tmp)
         throws IgniteCheckedException {
-        if (!((CacheObjectPortableContext)ctx.cacheObjectContext()).portableEnabled())
+        if (!((CacheObjectBinaryContext)ctx.cacheObjectContext()).portableEnabled())
             return super.toCacheObject(ctx, valPtr, tmp);
 
         Object val = unmarshal(valPtr, !tmp);
@@ -753,7 +753,7 @@ public class CacheObjectBinaryProcessorImpl extends IgniteCacheObjectProcessorIm
 
     /** {@inheritDoc} */
     @Override public Object unwrapTemporary(GridCacheContext ctx, Object obj) throws BinaryObjectException {
-        if (!((CacheObjectPortableContext)ctx.cacheObjectContext()).portableEnabled())
+        if (!((CacheObjectBinaryContext)ctx.cacheObjectContext()).portableEnabled())
             return obj;
 
         if (obj instanceof BinaryObjectOffheapImpl)
@@ -781,7 +781,7 @@ public class CacheObjectBinaryProcessorImpl extends IgniteCacheObjectProcessorIm
      * Processor responsible for metadata update.
      */
     private static class MetadataProcessor
-        implements EntryProcessor<PortableMetadataKey, BinaryMetadata, BinaryObjectException>, Externalizable {
+        implements EntryProcessor<BinaryMetadataKey, BinaryMetadata, BinaryObjectException>, Externalizable {
         /** */
         private static final long serialVersionUID = 0L;
 
@@ -805,12 +805,12 @@ public class CacheObjectBinaryProcessorImpl extends IgniteCacheObjectProcessorIm
         }
 
         /** {@inheritDoc} */
-        @Override public BinaryObjectException process(MutableEntry<PortableMetadataKey, BinaryMetadata> entry,
+        @Override public BinaryObjectException process(MutableEntry<BinaryMetadataKey, BinaryMetadata> entry,
             Object... args) {
             try {
                 BinaryMetadata oldMeta = entry.getValue();
 
-                BinaryMetadata mergedMeta = PortableUtils.mergeMetadata(oldMeta, newMeta);
+                BinaryMetadata mergedMeta = BinaryUtils.mergeMetadata(oldMeta, newMeta);
 
                 if (mergedMeta != oldMeta)
                     entry.setValue(mergedMeta);
@@ -841,15 +841,15 @@ public class CacheObjectBinaryProcessorImpl extends IgniteCacheObjectProcessorIm
     /**
      *
      */
-    class MetaDataEntryListener implements CacheEntryUpdatedListener<PortableMetadataKey, BinaryMetadata> {
+    class MetaDataEntryListener implements CacheEntryUpdatedListener<BinaryMetadataKey, BinaryMetadata> {
         /** {@inheritDoc} */
         @Override public void onUpdated(
-            Iterable<CacheEntryEvent<? extends PortableMetadataKey, ? extends BinaryMetadata>> evts)
+            Iterable<CacheEntryEvent<? extends BinaryMetadataKey, ? extends BinaryMetadata>> evts)
             throws CacheEntryListenerException {
-            for (CacheEntryEvent<? extends PortableMetadataKey, ? extends BinaryMetadata> evt : evts) {
+            for (CacheEntryEvent<? extends BinaryMetadataKey, ? extends BinaryMetadata> evt : evts) {
                 assert evt.getEventType() == EventType.CREATED || evt.getEventType() == EventType.UPDATED : evt;
 
-                PortableMetadataKey key = evt.getKey();
+                BinaryMetadataKey key = evt.getKey();
 
                 final BinaryMetadata newMeta = evt.getValue();
 
@@ -874,7 +874,7 @@ public class CacheObjectBinaryProcessorImpl extends IgniteCacheObjectProcessorIm
 
         /** {@inheritDoc} */
         @Override public boolean evaluate(CacheEntryEvent<?, ?> evt) throws CacheEntryListenerException {
-            return evt.getKey() instanceof PortableMetadataKey;
+            return evt.getKey() instanceof BinaryMetadataKey;
         }
 
         /** {@inheritDoc} */
@@ -892,7 +892,7 @@ public class CacheObjectBinaryProcessorImpl extends IgniteCacheObjectProcessorIm
 
         /** {@inheritDoc} */
         @Override public boolean apply(Object key, Object val) {
-            return key instanceof PortableMetadataKey;
+            return key instanceof BinaryMetadataKey;
         }
 
         /** {@inheritDoc} */

http://git-wip-us.apache.org/repos/asf/ignite/blob/71ad9cea/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/binary/CacheObjectPortableContext.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/binary/CacheObjectPortableContext.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/binary/CacheObjectPortableContext.java
deleted file mode 100644
index c2b5261..0000000
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/binary/CacheObjectPortableContext.java
+++ /dev/null
@@ -1,56 +0,0 @@
-/*
- * 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.processors.cache.binary;
-
-import org.apache.ignite.internal.GridKernalContext;
-import org.apache.ignite.internal.processors.cache.CacheDefaultBinaryAffinityKeyMapper;
-import org.apache.ignite.internal.processors.cache.CacheObjectContext;
-import org.apache.ignite.internal.processors.cache.GridCacheDefaultAffinityKeyMapper;
-
-/**
- *
- */
-public class CacheObjectPortableContext extends CacheObjectContext {
-    /** */
-    private boolean portableEnabled;
-
-    /**
-     * @param kernalCtx Kernal context.
-     * @param portableEnabled Portable enabled flag.
-     * @param cpyOnGet Copy on get flag.
-     * @param storeVal {@code True} if should store unmarshalled value in cache.
-     * @param depEnabled {@code true} if deployment is enabled for the given cache.
-     */
-    public CacheObjectPortableContext(GridKernalContext kernalCtx,
-        boolean cpyOnGet,
-        boolean storeVal,
-        boolean portableEnabled,
-        boolean depEnabled) {
-        super(kernalCtx, portableEnabled ? new CacheDefaultBinaryAffinityKeyMapper() :
-            new GridCacheDefaultAffinityKeyMapper(), cpyOnGet, storeVal, depEnabled);
-
-        this.portableEnabled = portableEnabled;
-    }
-
-    /**
-     * @return Portable enabled flag.
-     */
-    public boolean portableEnabled() {
-        return portableEnabled;
-    }
-}

http://git-wip-us.apache.org/repos/asf/ignite/blob/71ad9cea/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/binary/PortableMetadataKey.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/binary/PortableMetadataKey.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/binary/PortableMetadataKey.java
deleted file mode 100644
index 3b0ce8e..0000000
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/binary/PortableMetadataKey.java
+++ /dev/null
@@ -1,82 +0,0 @@
-/*
- * 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.processors.cache.binary;
-
-import java.io.Externalizable;
-import java.io.IOException;
-import java.io.ObjectInput;
-import java.io.ObjectOutput;
-import org.apache.ignite.internal.processors.cache.GridCacheUtilityKey;
-import org.apache.ignite.internal.util.typedef.internal.S;
-
-/**
- * Key for portable meta data.
- */
-class PortableMetadataKey extends GridCacheUtilityKey<PortableMetadataKey> implements Externalizable {
-    /** */
-    private static final long serialVersionUID = 0L;
-
-    /** */
-    private int typeId;
-
-    /**
-     * For {@link Externalizable}.
-     */
-    public PortableMetadataKey() {
-        // No-op.
-    }
-
-    /**
-     * @param typeId Type ID.
-     */
-    PortableMetadataKey(int typeId) {
-        this.typeId = typeId;
-    }
-
-    /**
-     * @return Type id.
-     */
-    public int typeId() {
-        return typeId;
-    }
-
-    /** {@inheritDoc} */
-    @Override public void writeExternal(ObjectOutput out) throws IOException {
-        out.writeInt(typeId);
-    }
-
-    /** {@inheritDoc} */
-    @Override public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
-        typeId = in.readInt();
-    }
-
-    /** {@inheritDoc} */
-    @Override protected boolean equalsx(PortableMetadataKey key) {
-        return typeId == key.typeId;
-    }
-
-    /** {@inheritDoc} */
-    @Override public int hashCode() {
-        return typeId;
-    }
-
-    /** {@inheritDoc} */
-    @Override public String toString() {
-        return S.toString(PortableMetadataKey.class, this);
-    }
-}

http://git-wip-us.apache.org/repos/asf/ignite/blob/71ad9cea/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/PlatformContextImpl.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/PlatformContextImpl.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/PlatformContextImpl.java
index e8c9d4d..f69ea3e 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/PlatformContextImpl.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/PlatformContextImpl.java
@@ -38,7 +38,7 @@ import org.apache.ignite.internal.binary.BinaryRawReaderEx;
 import org.apache.ignite.internal.binary.BinaryRawWriterEx;
 import org.apache.ignite.internal.binary.BinaryReaderExImpl;
 import org.apache.ignite.internal.binary.BinaryTypeImpl;
-import org.apache.ignite.internal.binary.GridPortableMarshaller;
+import org.apache.ignite.internal.binary.GridBinaryMarshaller;
 import org.apache.ignite.internal.processors.cache.binary.CacheObjectBinaryProcessorImpl;
 import org.apache.ignite.internal.processors.platform.cache.PlatformCacheEntryFilter;
 import org.apache.ignite.internal.processors.platform.cache.PlatformCacheEntryFilterImpl;
@@ -94,7 +94,7 @@ public class PlatformContextImpl implements PlatformContext {
     private final GridKernalContext ctx;
 
     /** Marshaller. */
-    private final GridPortableMarshaller marsh;
+    private final GridBinaryMarshaller marsh;
 
     /** Memory manager. */
     private final PlatformMemoryManagerImpl mem;

http://git-wip-us.apache.org/repos/asf/ignite/blob/71ad9cea/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/dotnet/PlatformDotNetConfigurationClosure.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/dotnet/PlatformDotNetConfigurationClosure.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/dotnet/PlatformDotNetConfigurationClosure.java
index caea840..b2bd5d4 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/dotnet/PlatformDotNetConfigurationClosure.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/dotnet/PlatformDotNetConfigurationClosure.java
@@ -25,8 +25,8 @@ import org.apache.ignite.configuration.PlatformConfiguration;
 import org.apache.ignite.internal.MarshallerContextImpl;
 import org.apache.ignite.internal.binary.BinaryNoopMetadataHandler;
 import org.apache.ignite.internal.binary.BinaryRawWriterEx;
-import org.apache.ignite.internal.binary.GridPortableMarshaller;
-import org.apache.ignite.internal.binary.PortableContext;
+import org.apache.ignite.internal.binary.GridBinaryMarshaller;
+import org.apache.ignite.internal.binary.BinaryContext;
 import org.apache.ignite.internal.processors.platform.PlatformAbstractConfigurationClosure;
 import org.apache.ignite.internal.processors.platform.lifecycle.PlatformLifecycleBean;
 import org.apache.ignite.internal.processors.platform.memory.PlatformInputStream;
@@ -239,9 +239,9 @@ public class PlatformDotNetConfigurationClosure extends PlatformAbstractConfigur
      * @return Marshaller.
      */
     @SuppressWarnings("deprecation")
-    private static GridPortableMarshaller marshaller() {
+    private static GridBinaryMarshaller marshaller() {
         try {
-            PortableContext ctx = new PortableContext(BinaryNoopMetadataHandler.instance(), new IgniteConfiguration());
+            BinaryContext ctx = new BinaryContext(BinaryNoopMetadataHandler.instance(), new IgniteConfiguration());
 
             BinaryMarshaller marsh = new BinaryMarshaller();
 
@@ -249,7 +249,7 @@ public class PlatformDotNetConfigurationClosure extends PlatformAbstractConfigur
 
             ctx.configure(marsh, new IgniteConfiguration());
 
-            return new GridPortableMarshaller(ctx);
+            return new GridBinaryMarshaller(ctx);
         }
         catch (IgniteCheckedException e) {
             throw U.convertException(e);

http://git-wip-us.apache.org/repos/asf/ignite/blob/71ad9cea/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/memory/PlatformInputStream.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/memory/PlatformInputStream.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/memory/PlatformInputStream.java
index 321e592..e4d1e46 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/memory/PlatformInputStream.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/memory/PlatformInputStream.java
@@ -17,12 +17,12 @@
 
 package org.apache.ignite.internal.processors.platform.memory;
 
-import org.apache.ignite.internal.binary.streams.PortableInputStream;
+import org.apache.ignite.internal.binary.streams.BinaryInputStream;
 
 /**
  * Interop output stream,
  */
-public interface PlatformInputStream extends PortableInputStream {
+public interface PlatformInputStream extends BinaryInputStream {
     /**
      * Synchronize input. Must be called before start reading data from a memory changed by another platform.
      */

http://git-wip-us.apache.org/repos/asf/ignite/blob/71ad9cea/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/memory/PlatformOutputStream.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/memory/PlatformOutputStream.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/memory/PlatformOutputStream.java
index 7894f0c..95cbac2 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/memory/PlatformOutputStream.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/memory/PlatformOutputStream.java
@@ -17,12 +17,12 @@
 
 package org.apache.ignite.internal.processors.platform.memory;
 
-import org.apache.ignite.internal.binary.streams.PortableOutputStream;
+import org.apache.ignite.internal.binary.streams.BinaryOutputStream;
 
 /**
  * Interop output stream.
  */
-public interface PlatformOutputStream extends PortableOutputStream {
+public interface PlatformOutputStream extends BinaryOutputStream {
     /**
      * Synchronize output stream with underlying memory
      */

http://git-wip-us.apache.org/repos/asf/ignite/blob/71ad9cea/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/client/message/GridClientBinaryMetaData.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/client/message/GridClientBinaryMetaData.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/client/message/GridClientBinaryMetaData.java
new file mode 100644
index 0000000..daa056b
--- /dev/null
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/client/message/GridClientBinaryMetaData.java
@@ -0,0 +1,71 @@
+/*
+ * 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.processors.rest.client.message;
+
+import java.util.Map;
+import org.apache.ignite.internal.util.typedef.internal.S;
+
+/**
+ * Portable meta data sent from client.
+ */
+public class GridClientBinaryMetaData {
+    /** */
+    private int typeId;
+
+    /** */
+    private String typeName;
+
+    /** */
+    private Map<String, Integer> fields;
+
+    /** */
+    private String affKeyFieldName;
+
+    /**
+     * @return Type ID.
+     */
+    public int typeId() {
+        return typeId;
+    }
+
+    /**
+     * @return Type name.
+     */
+    public String typeName() {
+        return typeName;
+    }
+
+    /**
+     * @return Fields.
+     */
+    public Map<String, Integer> fields() {
+        return fields;
+    }
+
+    /**
+     * @return Affinity key field name.
+     */
+    public String affinityKeyFieldName() {
+        return affKeyFieldName;
+    }
+
+    /** {@inheritDoc} */
+    @Override public String toString() {
+        return S.toString(GridClientBinaryMetaData.class, this);
+    }
+}


[56/59] [abbrv] ignite git commit: ignite-2065: rename "portable" classes to "binary" (in tests)

Posted by ak...@apache.org.
http://git-wip-us.apache.org/repos/asf/ignite/blob/469bf6d6/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/binary/distributed/dht/GridCacheBinariesNearPartitionedByteArrayValuesSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/binary/distributed/dht/GridCacheBinariesNearPartitionedByteArrayValuesSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/binary/distributed/dht/GridCacheBinariesNearPartitionedByteArrayValuesSelfTest.java
new file mode 100644
index 0000000..13b374c
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/binary/distributed/dht/GridCacheBinariesNearPartitionedByteArrayValuesSelfTest.java
@@ -0,0 +1,41 @@
+/*
+ * 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.processors.cache.binary.distributed.dht;
+
+import org.apache.ignite.configuration.IgniteConfiguration;
+import org.apache.ignite.internal.processors.cache.distributed.near.GridCacheAbstractNearPartitionedByteArrayValuesSelfTest;
+import org.apache.ignite.internal.binary.BinaryMarshaller;
+
+/**
+ *
+ */
+public class GridCacheBinariesNearPartitionedByteArrayValuesSelfTest
+    extends GridCacheAbstractNearPartitionedByteArrayValuesSelfTest {
+    /** {@inheritDoc} */
+    @Override protected boolean peerClassLoading() {
+        return false;
+    }
+
+    /** {@inheritDoc} */
+    @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception {
+        IgniteConfiguration cfg = super.getConfiguration(gridName);
+
+        cfg.setMarshaller(new BinaryMarshaller());
+
+        return cfg;
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/469bf6d6/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/binary/distributed/dht/GridCachePortablesNearPartitionedByteArrayValuesSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/binary/distributed/dht/GridCachePortablesNearPartitionedByteArrayValuesSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/binary/distributed/dht/GridCachePortablesNearPartitionedByteArrayValuesSelfTest.java
deleted file mode 100644
index 9c1572e..0000000
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/binary/distributed/dht/GridCachePortablesNearPartitionedByteArrayValuesSelfTest.java
+++ /dev/null
@@ -1,41 +0,0 @@
-/*
- * 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.processors.cache.binary.distributed.dht;
-
-import org.apache.ignite.configuration.IgniteConfiguration;
-import org.apache.ignite.internal.processors.cache.distributed.near.GridCacheAbstractNearPartitionedByteArrayValuesSelfTest;
-import org.apache.ignite.internal.binary.BinaryMarshaller;
-
-/**
- *
- */
-public class GridCachePortablesNearPartitionedByteArrayValuesSelfTest
-    extends GridCacheAbstractNearPartitionedByteArrayValuesSelfTest {
-    /** {@inheritDoc} */
-    @Override protected boolean peerClassLoading() {
-        return false;
-    }
-
-    /** {@inheritDoc} */
-    @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception {
-        IgniteConfiguration cfg = super.getConfiguration(gridName);
-
-        cfg.setMarshaller(new BinaryMarshaller());
-
-        return cfg;
-    }
-}

http://git-wip-us.apache.org/repos/asf/ignite/blob/469bf6d6/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteBinaryCacheFullApiTestSuite.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteBinaryCacheFullApiTestSuite.java b/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteBinaryCacheFullApiTestSuite.java
new file mode 100644
index 0000000..3dc78cc
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteBinaryCacheFullApiTestSuite.java
@@ -0,0 +1,37 @@
+/*
+ * 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.testsuites;
+
+import junit.framework.TestSuite;
+import org.apache.ignite.internal.binary.BinaryMarshaller;
+import org.apache.ignite.testframework.config.GridTestProperties;
+
+/**
+ * Cache full API suite with portable marshaller.
+ */
+public class IgniteBinaryCacheFullApiTestSuite extends TestSuite {
+    /**
+     * @return Suite.
+     * @throws Exception In case of error.
+     */
+    public static TestSuite suite() throws Exception {
+        GridTestProperties.setProperty(GridTestProperties.MARSH_CLASS_NAME, BinaryMarshaller.class.getName());
+
+        return IgniteCacheFullApiSelfTestSuite.suite();
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/469bf6d6/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteBinaryCacheTestSuite.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteBinaryCacheTestSuite.java b/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteBinaryCacheTestSuite.java
new file mode 100644
index 0000000..729bebe
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteBinaryCacheTestSuite.java
@@ -0,0 +1,101 @@
+/*
+ * 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.testsuites;
+
+import java.util.HashSet;
+import junit.framework.TestSuite;
+import org.apache.ignite.internal.binary.BinaryMarshaller;
+import org.apache.ignite.internal.processors.cache.GridCacheAffinityRoutingSelfTest;
+import org.apache.ignite.internal.processors.cache.GridCacheEntryMemorySizeSelfTest;
+import org.apache.ignite.internal.processors.cache.GridCacheMvccSelfTest;
+import org.apache.ignite.internal.processors.cache.GridCacheOffHeapTieredAtomicSelfTest;
+import org.apache.ignite.internal.processors.cache.GridCacheOffHeapTieredEvictionAtomicSelfTest;
+import org.apache.ignite.internal.processors.cache.GridCacheOffHeapTieredEvictionSelfTest;
+import org.apache.ignite.internal.processors.cache.GridCacheOffHeapTieredSelfTest;
+import org.apache.ignite.internal.processors.cache.expiry.IgniteCacheAtomicLocalExpiryPolicyTest;
+import org.apache.ignite.internal.processors.cache.binary.GridBinaryCacheEntryMemorySizeSelfTest;
+import org.apache.ignite.internal.processors.cache.binary.datastreaming.DataStreamProcessorBinarySelfTest;
+import org.apache.ignite.internal.processors.cache.binary.datastreaming.GridDataStreamerImplSelfTest;
+import org.apache.ignite.internal.processors.cache.binary.distributed.dht.GridCacheAffinityRoutingBinarySelfTest;
+import org.apache.ignite.internal.processors.cache.binary.distributed.dht.GridCacheAtomicPartitionedOnlyBinaryDataStreamerMultiNodeSelfTest;
+import org.apache.ignite.internal.processors.cache.binary.distributed.dht.GridCacheAtomicPartitionedOnlyBinaryDataStreamerMultithreadedSelfTest;
+import org.apache.ignite.internal.processors.cache.binary.distributed.dht.GridCacheAtomicPartitionedOnlyBinaryMultiNodeSelfTest;
+import org.apache.ignite.internal.processors.cache.binary.distributed.dht.GridCacheAtomicPartitionedOnlyBinaryMultithreadedSelfTest;
+import org.apache.ignite.internal.processors.cache.binary.distributed.dht.GridCacheMemoryModeBinarySelfTest;
+import org.apache.ignite.internal.processors.cache.binary.distributed.dht.GridCacheOffHeapTieredAtomicBinarySelfTest;
+import org.apache.ignite.internal.processors.cache.binary.distributed.dht.GridCacheOffHeapTieredEvictionAtomicBinarySelfTest;
+import org.apache.ignite.internal.processors.cache.binary.distributed.dht.GridCacheOffHeapTieredEvictionBinarySelfTest;
+import org.apache.ignite.internal.processors.cache.binary.distributed.dht.GridCacheOffHeapTieredBinarySelfTest;
+import org.apache.ignite.internal.processors.cache.binary.distributed.dht.GridCacheBinariesNearPartitionedByteArrayValuesSelfTest;
+import org.apache.ignite.internal.processors.cache.binary.distributed.dht.GridCacheBinariesPartitionedOnlyByteArrayValuesSelfTest;
+import org.apache.ignite.internal.processors.datastreamer.DataStreamProcessorSelfTest;
+import org.apache.ignite.testframework.config.GridTestProperties;
+
+/**
+ * Cache suite with portable marshaller.
+ */
+public class IgniteBinaryCacheTestSuite extends TestSuite {
+    /**
+     * @return Suite.
+     * @throws Exception In case of error.
+     */
+    public static TestSuite suite() throws Exception {
+        GridTestProperties.setProperty(GridTestProperties.MARSH_CLASS_NAME, BinaryMarshaller.class.getName());
+
+        TestSuite suite = new TestSuite("Portable Cache Test Suite");
+
+        HashSet<Class> ignoredTests = new HashSet<>();
+
+        // Tests below have a special version for Portable Marshaller
+        ignoredTests.add(DataStreamProcessorSelfTest.class);
+        ignoredTests.add(GridCacheOffHeapTieredEvictionAtomicSelfTest.class);
+        ignoredTests.add(GridCacheOffHeapTieredEvictionSelfTest.class);
+        ignoredTests.add(GridCacheOffHeapTieredSelfTest.class);
+        ignoredTests.add(GridCacheOffHeapTieredAtomicSelfTest.class);
+        ignoredTests.add(GridCacheAffinityRoutingSelfTest.class);
+        ignoredTests.add(IgniteCacheAtomicLocalExpiryPolicyTest.class);
+        ignoredTests.add(GridCacheEntryMemorySizeSelfTest.class);
+
+        // Tests that are not ready to be used with PortableMarshaller
+        ignoredTests.add(GridCacheMvccSelfTest.class);
+
+        suite.addTest(IgniteCacheTestSuite.suite(ignoredTests));
+
+        suite.addTestSuite(GridCacheMemoryModeBinarySelfTest.class);
+        suite.addTestSuite(GridCacheOffHeapTieredEvictionAtomicBinarySelfTest.class);
+        suite.addTestSuite(GridCacheOffHeapTieredEvictionBinarySelfTest.class);
+
+        suite.addTestSuite(GridCacheBinariesPartitionedOnlyByteArrayValuesSelfTest.class);
+        suite.addTestSuite(GridCacheBinariesNearPartitionedByteArrayValuesSelfTest.class);
+        suite.addTestSuite(GridCacheOffHeapTieredBinarySelfTest.class);
+        suite.addTestSuite(GridCacheOffHeapTieredAtomicBinarySelfTest.class);
+
+        suite.addTestSuite(GridDataStreamerImplSelfTest.class);
+        suite.addTestSuite(DataStreamProcessorBinarySelfTest.class);
+        suite.addTestSuite(GridCacheAtomicPartitionedOnlyBinaryDataStreamerMultiNodeSelfTest.class);
+        suite.addTestSuite(GridCacheAtomicPartitionedOnlyBinaryDataStreamerMultithreadedSelfTest.class);
+
+        suite.addTestSuite(GridCacheAtomicPartitionedOnlyBinaryMultiNodeSelfTest.class);
+        suite.addTestSuite(GridCacheAtomicPartitionedOnlyBinaryMultithreadedSelfTest.class);
+
+        suite.addTestSuite(GridCacheAffinityRoutingBinarySelfTest.class);
+        suite.addTestSuite(GridBinaryCacheEntryMemorySizeSelfTest.class);
+
+        return suite;
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/469bf6d6/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteBinaryObjectsTestSuite.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteBinaryObjectsTestSuite.java b/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteBinaryObjectsTestSuite.java
new file mode 100644
index 0000000..271ff33
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/testsuites/IgniteBinaryObjectsTestSuite.java
@@ -0,0 +1,114 @@
+/*
+ * 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.testsuites;
+
+import junit.framework.TestSuite;
+import org.apache.ignite.internal.binary.BinaryEnumsSelfTest;
+import org.apache.ignite.internal.binary.GridBinaryAffinityKeySelfTest;
+import org.apache.ignite.internal.binary.BinaryObjectBuilderAdditionalSelfTest;
+import org.apache.ignite.internal.binary.BinaryObjectBuilderSelfTest;
+import org.apache.ignite.internal.binary.GridBinaryMarshallerCtxDisabledSelfTest;
+import org.apache.ignite.internal.binary.BinaryMarshallerSelfTest;
+import org.apache.ignite.internal.binary.GridBinaryMetaDataSelfTest;
+import org.apache.ignite.internal.binary.GridBinaryWildcardsSelfTest;
+import org.apache.ignite.internal.binary.BinaryFooterOffsetsHeapSelfTest;
+import org.apache.ignite.internal.binary.BinaryFooterOffsetsOffheapSelfTest;
+import org.apache.ignite.internal.binary.BinaryFieldsHeapSelfTest;
+import org.apache.ignite.internal.binary.BinaryFieldsOffheapSelfTest;
+import org.apache.ignite.internal.binary.noncompact.BinaryFieldsHeapNonCompactSelfTest;
+import org.apache.ignite.internal.binary.noncompact.BinaryFieldsOffheapNonCompactSelfTest;
+import org.apache.ignite.internal.binary.noncompact.BinaryFooterOffsetsHeapNonCompactSelfTest;
+import org.apache.ignite.internal.binary.noncompact.BinaryFooterOffsetsOffheapNonCompactSelfTest;
+import org.apache.ignite.internal.binary.noncompact.BinaryMarshallerNonCompactSelfTest;
+import org.apache.ignite.internal.binary.noncompact.BinaryObjectBuilderAdditionalNonCompactSelfTest;
+import org.apache.ignite.internal.binary.noncompact.BinaryObjectBuilderNonCompactSelfTest;
+import org.apache.ignite.internal.processors.cache.distributed.IgniteBinaryMetadataUpdateChangingTopologySelfTest;
+import org.apache.ignite.internal.processors.cache.binary.GridCacheClientNodeBinaryObjectMetadataMultinodeTest;
+import org.apache.ignite.internal.processors.cache.binary.GridCacheClientNodeBinaryObjectMetadataTest;
+import org.apache.ignite.internal.processors.cache.binary.GridCacheBinaryStoreObjectsSelfTest;
+import org.apache.ignite.internal.processors.cache.binary.GridCacheBinaryStoreBinariesSelfTest;
+import org.apache.ignite.internal.processors.cache.binary.distributed.dht.GridCacheBinaryObjectsAtomicNearDisabledOffheapTieredSelfTest;
+import org.apache.ignite.internal.processors.cache.binary.distributed.dht.GridCacheBinaryObjectsAtomicNearDisabledSelfTest;
+import org.apache.ignite.internal.processors.cache.binary.distributed.dht.GridCacheBinaryObjectsAtomicOffheapTieredSelfTest;
+import org.apache.ignite.internal.processors.cache.binary.distributed.dht.GridCacheBinaryObjectsAtomicSelfTest;
+import org.apache.ignite.internal.processors.cache.binary.distributed.dht.GridCacheBinaryObjectsPartitionedNearDisabledOffheapTieredSelfTest;
+import org.apache.ignite.internal.processors.cache.binary.distributed.dht.GridCacheBinaryObjectsPartitionedNearDisabledSelfTest;
+import org.apache.ignite.internal.processors.cache.binary.distributed.dht.GridCacheBinaryObjectsPartitionedOffheapTieredSelfTest;
+import org.apache.ignite.internal.processors.cache.binary.distributed.dht.GridCacheBinaryObjectsPartitionedSelfTest;
+import org.apache.ignite.internal.processors.cache.binary.distributed.replicated.GridCacheBinaryObjectsReplicatedSelfTest;
+import org.apache.ignite.internal.processors.cache.binary.local.GridCacheBinaryObjectsAtomicLocalSelfTest;
+import org.apache.ignite.internal.processors.cache.binary.local.GridCacheBinaryObjectsLocalOffheapTieredSelfTest;
+import org.apache.ignite.internal.processors.cache.binary.local.GridCacheBinaryObjectsLocalSelfTest;
+
+/**
+ * Test for portable objects stored in cache.
+ */
+public class IgniteBinaryObjectsTestSuite extends TestSuite {
+    /**
+     * @return Suite.
+     * @throws Exception If failed.
+     */
+    public static TestSuite suite() throws Exception {
+        TestSuite suite = new TestSuite("Ignite Binary Objects Test Suite");
+
+        suite.addTestSuite(BinaryMarshallerSelfTest.class);
+        suite.addTestSuite(GridBinaryMarshallerCtxDisabledSelfTest.class);
+        suite.addTestSuite(BinaryObjectBuilderSelfTest.class);
+        suite.addTestSuite(BinaryObjectBuilderAdditionalSelfTest.class);
+        suite.addTestSuite(BinaryFieldsHeapSelfTest.class);
+        suite.addTestSuite(BinaryFieldsOffheapSelfTest.class);
+        suite.addTestSuite(BinaryFooterOffsetsHeapSelfTest.class);
+        suite.addTestSuite(BinaryFooterOffsetsOffheapSelfTest.class);
+        suite.addTestSuite(BinaryEnumsSelfTest.class);
+        suite.addTestSuite(GridBinaryMetaDataSelfTest.class);
+        suite.addTestSuite(GridBinaryAffinityKeySelfTest.class);
+        suite.addTestSuite(GridBinaryWildcardsSelfTest.class);
+
+        // Tests for objects with non-compact footers.
+        suite.addTestSuite(BinaryMarshallerNonCompactSelfTest.class);
+        suite.addTestSuite(BinaryObjectBuilderNonCompactSelfTest.class);
+        suite.addTestSuite(BinaryObjectBuilderAdditionalNonCompactSelfTest.class);
+        suite.addTestSuite(BinaryFieldsHeapNonCompactSelfTest.class);
+        suite.addTestSuite(BinaryFieldsOffheapNonCompactSelfTest.class);
+        suite.addTestSuite(BinaryFooterOffsetsHeapNonCompactSelfTest.class);
+        suite.addTestSuite(BinaryFooterOffsetsOffheapNonCompactSelfTest.class);
+
+        suite.addTestSuite(GridCacheBinaryObjectsLocalSelfTest.class);
+        suite.addTestSuite(GridCacheBinaryObjectsAtomicLocalSelfTest.class);
+        suite.addTestSuite(GridCacheBinaryObjectsReplicatedSelfTest.class);
+        suite.addTestSuite(GridCacheBinaryObjectsPartitionedSelfTest.class);
+        suite.addTestSuite(GridCacheBinaryObjectsPartitionedNearDisabledSelfTest.class);
+        suite.addTestSuite(GridCacheBinaryObjectsAtomicSelfTest.class);
+        suite.addTestSuite(GridCacheBinaryObjectsAtomicNearDisabledSelfTest.class);
+
+        suite.addTestSuite(GridCacheBinaryObjectsLocalOffheapTieredSelfTest.class);
+        suite.addTestSuite(GridCacheBinaryObjectsAtomicOffheapTieredSelfTest.class);
+        suite.addTestSuite(GridCacheBinaryObjectsAtomicNearDisabledOffheapTieredSelfTest.class);
+        suite.addTestSuite(GridCacheBinaryObjectsPartitionedOffheapTieredSelfTest.class);
+        suite.addTestSuite(GridCacheBinaryObjectsPartitionedNearDisabledOffheapTieredSelfTest.class);
+
+        suite.addTestSuite(GridCacheBinaryStoreObjectsSelfTest.class);
+        suite.addTestSuite(GridCacheBinaryStoreBinariesSelfTest.class);
+
+        suite.addTestSuite(GridCacheClientNodeBinaryObjectMetadataTest.class);
+        suite.addTestSuite(GridCacheClientNodeBinaryObjectMetadataMultinodeTest.class);
+        suite.addTestSuite(IgniteBinaryMetadataUpdateChangingTopologySelfTest.class);
+
+        return suite;
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/469bf6d6/modules/core/src/test/java/org/apache/ignite/testsuites/IgnitePortableCacheFullApiTestSuite.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/testsuites/IgnitePortableCacheFullApiTestSuite.java b/modules/core/src/test/java/org/apache/ignite/testsuites/IgnitePortableCacheFullApiTestSuite.java
deleted file mode 100644
index 3ba5b45..0000000
--- a/modules/core/src/test/java/org/apache/ignite/testsuites/IgnitePortableCacheFullApiTestSuite.java
+++ /dev/null
@@ -1,37 +0,0 @@
-/*
- * 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.testsuites;
-
-import junit.framework.TestSuite;
-import org.apache.ignite.internal.binary.BinaryMarshaller;
-import org.apache.ignite.testframework.config.GridTestProperties;
-
-/**
- * Cache full API suite with portable marshaller.
- */
-public class IgnitePortableCacheFullApiTestSuite extends TestSuite {
-    /**
-     * @return Suite.
-     * @throws Exception In case of error.
-     */
-    public static TestSuite suite() throws Exception {
-        GridTestProperties.setProperty(GridTestProperties.MARSH_CLASS_NAME, BinaryMarshaller.class.getName());
-
-        return IgniteCacheFullApiSelfTestSuite.suite();
-    }
-}

http://git-wip-us.apache.org/repos/asf/ignite/blob/469bf6d6/modules/core/src/test/java/org/apache/ignite/testsuites/IgnitePortableCacheTestSuite.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/testsuites/IgnitePortableCacheTestSuite.java b/modules/core/src/test/java/org/apache/ignite/testsuites/IgnitePortableCacheTestSuite.java
deleted file mode 100644
index f5745d8..0000000
--- a/modules/core/src/test/java/org/apache/ignite/testsuites/IgnitePortableCacheTestSuite.java
+++ /dev/null
@@ -1,101 +0,0 @@
-/*
- * 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.testsuites;
-
-import java.util.HashSet;
-import junit.framework.TestSuite;
-import org.apache.ignite.internal.binary.BinaryMarshaller;
-import org.apache.ignite.internal.processors.cache.GridCacheAffinityRoutingSelfTest;
-import org.apache.ignite.internal.processors.cache.GridCacheEntryMemorySizeSelfTest;
-import org.apache.ignite.internal.processors.cache.GridCacheMvccSelfTest;
-import org.apache.ignite.internal.processors.cache.GridCacheOffHeapTieredAtomicSelfTest;
-import org.apache.ignite.internal.processors.cache.GridCacheOffHeapTieredEvictionAtomicSelfTest;
-import org.apache.ignite.internal.processors.cache.GridCacheOffHeapTieredEvictionSelfTest;
-import org.apache.ignite.internal.processors.cache.GridCacheOffHeapTieredSelfTest;
-import org.apache.ignite.internal.processors.cache.expiry.IgniteCacheAtomicLocalExpiryPolicyTest;
-import org.apache.ignite.internal.processors.cache.binary.GridBinaryCacheEntryMemorySizeSelfTest;
-import org.apache.ignite.internal.processors.cache.binary.datastreaming.DataStreamProcessorBinarySelfTest;
-import org.apache.ignite.internal.processors.cache.binary.datastreaming.GridDataStreamerImplSelfTest;
-import org.apache.ignite.internal.processors.cache.binary.distributed.dht.GridCacheAffinityRoutingBinarySelfTest;
-import org.apache.ignite.internal.processors.cache.binary.distributed.dht.GridCacheAtomicPartitionedOnlyBinaryDataStreamerMultiNodeSelfTest;
-import org.apache.ignite.internal.processors.cache.binary.distributed.dht.GridCacheAtomicPartitionedOnlyBinaryDataStreamerMultithreadedSelfTest;
-import org.apache.ignite.internal.processors.cache.binary.distributed.dht.GridCacheAtomicPartitionedOnlyBinaryMultiNodeSelfTest;
-import org.apache.ignite.internal.processors.cache.binary.distributed.dht.GridCacheAtomicPartitionedOnlyBinaryMultithreadedSelfTest;
-import org.apache.ignite.internal.processors.cache.binary.distributed.dht.GridCacheMemoryModeBinarySelfTest;
-import org.apache.ignite.internal.processors.cache.binary.distributed.dht.GridCacheOffHeapTieredAtomicBinarySelfTest;
-import org.apache.ignite.internal.processors.cache.binary.distributed.dht.GridCacheOffHeapTieredEvictionAtomicBinarySelfTest;
-import org.apache.ignite.internal.processors.cache.binary.distributed.dht.GridCacheOffHeapTieredEvictionBinarySelfTest;
-import org.apache.ignite.internal.processors.cache.binary.distributed.dht.GridCacheOffHeapTieredBinarySelfTest;
-import org.apache.ignite.internal.processors.cache.binary.distributed.dht.GridCachePortablesNearPartitionedByteArrayValuesSelfTest;
-import org.apache.ignite.internal.processors.cache.binary.distributed.dht.GridCacheBinariesPartitionedOnlyByteArrayValuesSelfTest;
-import org.apache.ignite.internal.processors.datastreamer.DataStreamProcessorSelfTest;
-import org.apache.ignite.testframework.config.GridTestProperties;
-
-/**
- * Cache suite with portable marshaller.
- */
-public class IgnitePortableCacheTestSuite extends TestSuite {
-    /**
-     * @return Suite.
-     * @throws Exception In case of error.
-     */
-    public static TestSuite suite() throws Exception {
-        GridTestProperties.setProperty(GridTestProperties.MARSH_CLASS_NAME, BinaryMarshaller.class.getName());
-
-        TestSuite suite = new TestSuite("Portable Cache Test Suite");
-
-        HashSet<Class> ignoredTests = new HashSet<>();
-
-        // Tests below have a special version for Portable Marshaller
-        ignoredTests.add(DataStreamProcessorSelfTest.class);
-        ignoredTests.add(GridCacheOffHeapTieredEvictionAtomicSelfTest.class);
-        ignoredTests.add(GridCacheOffHeapTieredEvictionSelfTest.class);
-        ignoredTests.add(GridCacheOffHeapTieredSelfTest.class);
-        ignoredTests.add(GridCacheOffHeapTieredAtomicSelfTest.class);
-        ignoredTests.add(GridCacheAffinityRoutingSelfTest.class);
-        ignoredTests.add(IgniteCacheAtomicLocalExpiryPolicyTest.class);
-        ignoredTests.add(GridCacheEntryMemorySizeSelfTest.class);
-
-        // Tests that are not ready to be used with PortableMarshaller
-        ignoredTests.add(GridCacheMvccSelfTest.class);
-
-        suite.addTest(IgniteCacheTestSuite.suite(ignoredTests));
-
-        suite.addTestSuite(GridCacheMemoryModeBinarySelfTest.class);
-        suite.addTestSuite(GridCacheOffHeapTieredEvictionAtomicBinarySelfTest.class);
-        suite.addTestSuite(GridCacheOffHeapTieredEvictionBinarySelfTest.class);
-
-        suite.addTestSuite(GridCacheBinariesPartitionedOnlyByteArrayValuesSelfTest.class);
-        suite.addTestSuite(GridCachePortablesNearPartitionedByteArrayValuesSelfTest.class);
-        suite.addTestSuite(GridCacheOffHeapTieredBinarySelfTest.class);
-        suite.addTestSuite(GridCacheOffHeapTieredAtomicBinarySelfTest.class);
-
-        suite.addTestSuite(GridDataStreamerImplSelfTest.class);
-        suite.addTestSuite(DataStreamProcessorBinarySelfTest.class);
-        suite.addTestSuite(GridCacheAtomicPartitionedOnlyBinaryDataStreamerMultiNodeSelfTest.class);
-        suite.addTestSuite(GridCacheAtomicPartitionedOnlyBinaryDataStreamerMultithreadedSelfTest.class);
-
-        suite.addTestSuite(GridCacheAtomicPartitionedOnlyBinaryMultiNodeSelfTest.class);
-        suite.addTestSuite(GridCacheAtomicPartitionedOnlyBinaryMultithreadedSelfTest.class);
-
-        suite.addTestSuite(GridCacheAffinityRoutingBinarySelfTest.class);
-        suite.addTestSuite(GridBinaryCacheEntryMemorySizeSelfTest.class);
-
-        return suite;
-    }
-}

http://git-wip-us.apache.org/repos/asf/ignite/blob/469bf6d6/modules/core/src/test/java/org/apache/ignite/testsuites/IgnitePortableObjectsTestSuite.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/testsuites/IgnitePortableObjectsTestSuite.java b/modules/core/src/test/java/org/apache/ignite/testsuites/IgnitePortableObjectsTestSuite.java
deleted file mode 100644
index 942a5fa..0000000
--- a/modules/core/src/test/java/org/apache/ignite/testsuites/IgnitePortableObjectsTestSuite.java
+++ /dev/null
@@ -1,114 +0,0 @@
-/*
- * 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.testsuites;
-
-import junit.framework.TestSuite;
-import org.apache.ignite.internal.binary.BinaryEnumsSelfTest;
-import org.apache.ignite.internal.binary.GridBinaryAffinityKeySelfTest;
-import org.apache.ignite.internal.binary.BinaryObjectBuilderAdditionalSelfTest;
-import org.apache.ignite.internal.binary.BinaryObjectBuilderSelfTest;
-import org.apache.ignite.internal.binary.GridBinaryMarshallerCtxDisabledSelfTest;
-import org.apache.ignite.internal.binary.BinaryMarshallerSelfTest;
-import org.apache.ignite.internal.binary.GridPortableMetaDataSelfTest;
-import org.apache.ignite.internal.binary.GridPortableWildcardsSelfTest;
-import org.apache.ignite.internal.binary.BinaryFooterOffsetsHeapSelfTest;
-import org.apache.ignite.internal.binary.BinaryFooterOffsetsOffheapSelfTest;
-import org.apache.ignite.internal.binary.BinaryFieldsHeapSelfTest;
-import org.apache.ignite.internal.binary.BinaryFieldsOffheapSelfTest;
-import org.apache.ignite.internal.binary.noncompact.BinaryFieldsHeapNonCompactSelfTest;
-import org.apache.ignite.internal.binary.noncompact.BinaryFieldsOffheapNonCompactSelfTest;
-import org.apache.ignite.internal.binary.noncompact.BinaryFooterOffsetsHeapNonCompactSelfTest;
-import org.apache.ignite.internal.binary.noncompact.BinaryFooterOffsetsOffheapNonCompactSelfTest;
-import org.apache.ignite.internal.binary.noncompact.BinaryMarshallerNonCompactSelfTest;
-import org.apache.ignite.internal.binary.noncompact.BinaryObjectBuilderAdditionalNonCompactSelfTest;
-import org.apache.ignite.internal.binary.noncompact.BinaryObjectBuilderNonCompactSelfTest;
-import org.apache.ignite.internal.processors.cache.distributed.IgniteBinaryMetadataUpdateChangingTopologySelfTest;
-import org.apache.ignite.internal.processors.cache.binary.GridCacheClientNodeBinaryObjectMetadataMultinodeTest;
-import org.apache.ignite.internal.processors.cache.binary.GridCacheClientNodeBinaryObjectMetadataTest;
-import org.apache.ignite.internal.processors.cache.binary.GridCacheBinaryStoreObjectsSelfTest;
-import org.apache.ignite.internal.processors.cache.binary.GridCacheBinaryStorePortablesSelfTest;
-import org.apache.ignite.internal.processors.cache.binary.distributed.dht.GridCacheBinaryObjectsAtomicNearDisabledOffheapTieredSelfTest;
-import org.apache.ignite.internal.processors.cache.binary.distributed.dht.GridCacheBinaryObjectsAtomicNearDisabledSelfTest;
-import org.apache.ignite.internal.processors.cache.binary.distributed.dht.GridCacheBinaryObjectsAtomicOffheapTieredSelfTest;
-import org.apache.ignite.internal.processors.cache.binary.distributed.dht.GridCacheBinaryObjectsAtomicSelfTest;
-import org.apache.ignite.internal.processors.cache.binary.distributed.dht.GridCacheBinaryObjectsPartitionedNearDisabledOffheapTieredSelfTest;
-import org.apache.ignite.internal.processors.cache.binary.distributed.dht.GridCacheBinaryObjectsPartitionedNearDisabledSelfTest;
-import org.apache.ignite.internal.processors.cache.binary.distributed.dht.GridCacheBinaryObjectsPartitionedOffheapTieredSelfTest;
-import org.apache.ignite.internal.processors.cache.binary.distributed.dht.GridCacheBinaryObjectsPartitionedSelfTest;
-import org.apache.ignite.internal.processors.cache.binary.distributed.replicated.GridCacheBinaryObjectsReplicatedSelfTest;
-import org.apache.ignite.internal.processors.cache.binary.local.GridCacheBinaryObjectsAtomicLocalSelfTest;
-import org.apache.ignite.internal.processors.cache.binary.local.GridCacheBinaryObjectsLocalOffheapTieredSelfTest;
-import org.apache.ignite.internal.processors.cache.binary.local.GridCacheBinaryObjectsLocalSelfTest;
-
-/**
- * Test for portable objects stored in cache.
- */
-public class IgnitePortableObjectsTestSuite extends TestSuite {
-    /**
-     * @return Suite.
-     * @throws Exception If failed.
-     */
-    public static TestSuite suite() throws Exception {
-        TestSuite suite = new TestSuite("Ignite Binary Objects Test Suite");
-
-        suite.addTestSuite(BinaryMarshallerSelfTest.class);
-        suite.addTestSuite(GridBinaryMarshallerCtxDisabledSelfTest.class);
-        suite.addTestSuite(BinaryObjectBuilderSelfTest.class);
-        suite.addTestSuite(BinaryObjectBuilderAdditionalSelfTest.class);
-        suite.addTestSuite(BinaryFieldsHeapSelfTest.class);
-        suite.addTestSuite(BinaryFieldsOffheapSelfTest.class);
-        suite.addTestSuite(BinaryFooterOffsetsHeapSelfTest.class);
-        suite.addTestSuite(BinaryFooterOffsetsOffheapSelfTest.class);
-        suite.addTestSuite(BinaryEnumsSelfTest.class);
-        suite.addTestSuite(GridPortableMetaDataSelfTest.class);
-        suite.addTestSuite(GridBinaryAffinityKeySelfTest.class);
-        suite.addTestSuite(GridPortableWildcardsSelfTest.class);
-
-        // Tests for objects with non-compact footers.
-        suite.addTestSuite(BinaryMarshallerNonCompactSelfTest.class);
-        suite.addTestSuite(BinaryObjectBuilderNonCompactSelfTest.class);
-        suite.addTestSuite(BinaryObjectBuilderAdditionalNonCompactSelfTest.class);
-        suite.addTestSuite(BinaryFieldsHeapNonCompactSelfTest.class);
-        suite.addTestSuite(BinaryFieldsOffheapNonCompactSelfTest.class);
-        suite.addTestSuite(BinaryFooterOffsetsHeapNonCompactSelfTest.class);
-        suite.addTestSuite(BinaryFooterOffsetsOffheapNonCompactSelfTest.class);
-
-        suite.addTestSuite(GridCacheBinaryObjectsLocalSelfTest.class);
-        suite.addTestSuite(GridCacheBinaryObjectsAtomicLocalSelfTest.class);
-        suite.addTestSuite(GridCacheBinaryObjectsReplicatedSelfTest.class);
-        suite.addTestSuite(GridCacheBinaryObjectsPartitionedSelfTest.class);
-        suite.addTestSuite(GridCacheBinaryObjectsPartitionedNearDisabledSelfTest.class);
-        suite.addTestSuite(GridCacheBinaryObjectsAtomicSelfTest.class);
-        suite.addTestSuite(GridCacheBinaryObjectsAtomicNearDisabledSelfTest.class);
-
-        suite.addTestSuite(GridCacheBinaryObjectsLocalOffheapTieredSelfTest.class);
-        suite.addTestSuite(GridCacheBinaryObjectsAtomicOffheapTieredSelfTest.class);
-        suite.addTestSuite(GridCacheBinaryObjectsAtomicNearDisabledOffheapTieredSelfTest.class);
-        suite.addTestSuite(GridCacheBinaryObjectsPartitionedOffheapTieredSelfTest.class);
-        suite.addTestSuite(GridCacheBinaryObjectsPartitionedNearDisabledOffheapTieredSelfTest.class);
-
-        suite.addTestSuite(GridCacheBinaryStoreObjectsSelfTest.class);
-        suite.addTestSuite(GridCacheBinaryStorePortablesSelfTest.class);
-
-        suite.addTestSuite(GridCacheClientNodeBinaryObjectMetadataTest.class);
-        suite.addTestSuite(GridCacheClientNodeBinaryObjectMetadataMultinodeTest.class);
-        suite.addTestSuite(IgniteBinaryMetadataUpdateChangingTopologySelfTest.class);
-
-        return suite;
-    }
-}

http://git-wip-us.apache.org/repos/asf/ignite/blob/469bf6d6/modules/indexing/src/test/java/org/apache/ignite/testsuites/IgniteBinaryCacheQueryTestSuite.java
----------------------------------------------------------------------
diff --git a/modules/indexing/src/test/java/org/apache/ignite/testsuites/IgniteBinaryCacheQueryTestSuite.java b/modules/indexing/src/test/java/org/apache/ignite/testsuites/IgniteBinaryCacheQueryTestSuite.java
new file mode 100644
index 0000000..daf9c45
--- /dev/null
+++ b/modules/indexing/src/test/java/org/apache/ignite/testsuites/IgniteBinaryCacheQueryTestSuite.java
@@ -0,0 +1,119 @@
+/*
+ * 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.testsuites;
+
+import junit.framework.TestSuite;
+import org.apache.ignite.internal.processors.cache.CacheLocalQueryMetricsSelfTest;
+import org.apache.ignite.internal.processors.cache.CachePartitionedQueryMetricsDistributedSelfTest;
+import org.apache.ignite.internal.processors.cache.CachePartitionedQueryMetricsLocalSelfTest;
+import org.apache.ignite.internal.processors.cache.CacheReplicatedQueryMetricsDistributedSelfTest;
+import org.apache.ignite.internal.processors.cache.CacheReplicatedQueryMetricsLocalSelfTest;
+import org.apache.ignite.internal.processors.cache.GridCacheQueryIndexDisabledSelfTest;
+import org.apache.ignite.internal.processors.cache.GridCacheQueryIndexingDisabledSelfTest;
+import org.apache.ignite.internal.processors.cache.GridCacheReduceQueryMultithreadedSelfTest;
+import org.apache.ignite.internal.processors.cache.IgniteBinaryObjectFieldsQuerySelfTest;
+import org.apache.ignite.internal.processors.cache.IgniteCacheFieldsQueryNoDataSelfTest;
+import org.apache.ignite.internal.processors.cache.IgniteCacheLargeResultSelfTest;
+import org.apache.ignite.internal.processors.cache.IgniteCacheOffheapTieredMultithreadedSelfTest;
+import org.apache.ignite.internal.processors.cache.IgniteCacheP2pUnmarshallingQueryErrorTest;
+import org.apache.ignite.internal.processors.cache.IgniteCachePartitionedQueryMultiThreadedSelfTest;
+import org.apache.ignite.internal.processors.cache.IgniteCacheQueryEvictsMultiThreadedSelfTest;
+import org.apache.ignite.internal.processors.cache.IgniteCacheQueryMultiThreadedSelfTest;
+import org.apache.ignite.internal.processors.cache.IgniteCacheQueryOffheapMultiThreadedSelfTest;
+import org.apache.ignite.internal.processors.cache.binary.distributed.dht.GridCacheBinaryDuplicateIndexObjectPartitionedAtomicSelfTest;
+import org.apache.ignite.internal.processors.cache.binary.distributed.dht.GridCacheBinaryDuplicateIndexObjectPartitionedTransactionalSelfTest;
+import org.apache.ignite.internal.processors.cache.query.continuous.GridCacheContinuousQueryAtomicNearEnabledSelfTest;
+import org.apache.ignite.internal.processors.cache.query.continuous.GridCacheContinuousQueryAtomicP2PDisabledSelfTest;
+import org.apache.ignite.internal.processors.cache.query.continuous.GridCacheContinuousQueryAtomicSelfTest;
+import org.apache.ignite.internal.processors.cache.query.continuous.GridCacheContinuousQueryLocalAtomicSelfTest;
+import org.apache.ignite.internal.processors.cache.query.continuous.GridCacheContinuousQueryPartitionedOnlySelfTest;
+import org.apache.ignite.internal.processors.cache.query.continuous.GridCacheContinuousQueryReplicatedAtomicSelfTest;
+import org.apache.ignite.internal.processors.query.h2.sql.BaseH2CompareQueryTest;
+import org.apache.ignite.internal.processors.query.h2.sql.GridQueryParsingTest;
+import org.apache.ignite.internal.processors.query.h2.sql.H2CompareBigQueryTest;
+import org.apache.ignite.internal.binary.BinaryMarshaller;
+import org.apache.ignite.spi.communication.tcp.GridOrderedMessageCancelSelfTest;
+import org.apache.ignite.testframework.config.GridTestProperties;
+
+/**
+ * Cache query suite with portable marshaller.
+ */
+public class IgniteBinaryCacheQueryTestSuite extends TestSuite {
+    /**
+     * @return Suite.
+     * @throws Exception In case of error.
+     */
+    public static TestSuite suite() throws Exception {
+        GridTestProperties.setProperty(GridTestProperties.MARSH_CLASS_NAME, BinaryMarshaller.class.getName());
+
+        TestSuite suite = new TestSuite("Grid Cache Query Test Suite using PortableMarshaller");
+
+        // Parsing
+        suite.addTestSuite(GridQueryParsingTest.class);
+
+        // Queries tests.
+        suite.addTestSuite(GridCacheQueryIndexDisabledSelfTest.class);
+        suite.addTestSuite(IgniteCachePartitionedQueryMultiThreadedSelfTest.class);
+        suite.addTestSuite(IgniteCacheLargeResultSelfTest.class);
+        suite.addTestSuite(IgniteCacheQueryMultiThreadedSelfTest.class);
+        suite.addTestSuite(IgniteCacheQueryEvictsMultiThreadedSelfTest.class);
+        suite.addTestSuite(IgniteCacheQueryOffheapMultiThreadedSelfTest.class);
+
+        suite.addTestSuite(IgniteCacheOffheapTieredMultithreadedSelfTest.class);
+        suite.addTestSuite(GridCacheReduceQueryMultithreadedSelfTest.class);
+
+
+        // Fields queries.
+        suite.addTestSuite(IgniteCacheFieldsQueryNoDataSelfTest.class);
+        suite.addTestSuite(IgniteBinaryObjectFieldsQuerySelfTest.class);
+
+        // Continuous queries.
+        suite.addTestSuite(GridCacheContinuousQueryLocalAtomicSelfTest.class);
+        suite.addTestSuite(GridCacheContinuousQueryReplicatedAtomicSelfTest.class);
+        suite.addTestSuite(GridCacheContinuousQueryPartitionedOnlySelfTest.class);
+        suite.addTestSuite(GridCacheContinuousQueryAtomicSelfTest.class);
+        suite.addTestSuite(GridCacheContinuousQueryAtomicNearEnabledSelfTest.class);
+        suite.addTestSuite(GridCacheContinuousQueryAtomicP2PDisabledSelfTest.class);
+
+        suite.addTestSuite(GridCacheQueryIndexingDisabledSelfTest.class);
+
+        //Should be adjusted. Not ready to be used with PortableMarshaller.
+        //suite.addTestSuite(GridCachePortableSwapScanQuerySelfTest.class);
+
+        suite.addTestSuite(GridOrderedMessageCancelSelfTest.class);
+
+        // Ignite cache and H2 comparison.
+        suite.addTestSuite(BaseH2CompareQueryTest.class);
+        suite.addTestSuite(H2CompareBigQueryTest.class);
+
+        // Metrics tests
+        suite.addTestSuite(CacheLocalQueryMetricsSelfTest.class);
+        suite.addTestSuite(CachePartitionedQueryMetricsDistributedSelfTest.class);
+        suite.addTestSuite(CachePartitionedQueryMetricsLocalSelfTest.class);
+        suite.addTestSuite(CacheReplicatedQueryMetricsDistributedSelfTest.class);
+        suite.addTestSuite(CacheReplicatedQueryMetricsLocalSelfTest.class);
+
+        //Unmarshallig query test.
+        suite.addTestSuite(IgniteCacheP2pUnmarshallingQueryErrorTest.class);
+
+        suite.addTestSuite(GridCacheBinaryDuplicateIndexObjectPartitionedAtomicSelfTest.class);
+        suite.addTestSuite(GridCacheBinaryDuplicateIndexObjectPartitionedTransactionalSelfTest.class);
+
+        return suite;
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/469bf6d6/modules/indexing/src/test/java/org/apache/ignite/testsuites/IgnitePortableCacheQueryTestSuite.java
----------------------------------------------------------------------
diff --git a/modules/indexing/src/test/java/org/apache/ignite/testsuites/IgnitePortableCacheQueryTestSuite.java b/modules/indexing/src/test/java/org/apache/ignite/testsuites/IgnitePortableCacheQueryTestSuite.java
deleted file mode 100644
index 2df9026..0000000
--- a/modules/indexing/src/test/java/org/apache/ignite/testsuites/IgnitePortableCacheQueryTestSuite.java
+++ /dev/null
@@ -1,119 +0,0 @@
-/*
- * 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.testsuites;
-
-import junit.framework.TestSuite;
-import org.apache.ignite.internal.processors.cache.CacheLocalQueryMetricsSelfTest;
-import org.apache.ignite.internal.processors.cache.CachePartitionedQueryMetricsDistributedSelfTest;
-import org.apache.ignite.internal.processors.cache.CachePartitionedQueryMetricsLocalSelfTest;
-import org.apache.ignite.internal.processors.cache.CacheReplicatedQueryMetricsDistributedSelfTest;
-import org.apache.ignite.internal.processors.cache.CacheReplicatedQueryMetricsLocalSelfTest;
-import org.apache.ignite.internal.processors.cache.GridCacheQueryIndexDisabledSelfTest;
-import org.apache.ignite.internal.processors.cache.GridCacheQueryIndexingDisabledSelfTest;
-import org.apache.ignite.internal.processors.cache.GridCacheReduceQueryMultithreadedSelfTest;
-import org.apache.ignite.internal.processors.cache.IgniteBinaryObjectFieldsQuerySelfTest;
-import org.apache.ignite.internal.processors.cache.IgniteCacheFieldsQueryNoDataSelfTest;
-import org.apache.ignite.internal.processors.cache.IgniteCacheLargeResultSelfTest;
-import org.apache.ignite.internal.processors.cache.IgniteCacheOffheapTieredMultithreadedSelfTest;
-import org.apache.ignite.internal.processors.cache.IgniteCacheP2pUnmarshallingQueryErrorTest;
-import org.apache.ignite.internal.processors.cache.IgniteCachePartitionedQueryMultiThreadedSelfTest;
-import org.apache.ignite.internal.processors.cache.IgniteCacheQueryEvictsMultiThreadedSelfTest;
-import org.apache.ignite.internal.processors.cache.IgniteCacheQueryMultiThreadedSelfTest;
-import org.apache.ignite.internal.processors.cache.IgniteCacheQueryOffheapMultiThreadedSelfTest;
-import org.apache.ignite.internal.processors.cache.binary.distributed.dht.GridCacheBinaryDuplicateIndexObjectPartitionedAtomicSelfTest;
-import org.apache.ignite.internal.processors.cache.binary.distributed.dht.GridCacheBinaryDuplicateIndexObjectPartitionedTransactionalSelfTest;
-import org.apache.ignite.internal.processors.cache.query.continuous.GridCacheContinuousQueryAtomicNearEnabledSelfTest;
-import org.apache.ignite.internal.processors.cache.query.continuous.GridCacheContinuousQueryAtomicP2PDisabledSelfTest;
-import org.apache.ignite.internal.processors.cache.query.continuous.GridCacheContinuousQueryAtomicSelfTest;
-import org.apache.ignite.internal.processors.cache.query.continuous.GridCacheContinuousQueryLocalAtomicSelfTest;
-import org.apache.ignite.internal.processors.cache.query.continuous.GridCacheContinuousQueryPartitionedOnlySelfTest;
-import org.apache.ignite.internal.processors.cache.query.continuous.GridCacheContinuousQueryReplicatedAtomicSelfTest;
-import org.apache.ignite.internal.processors.query.h2.sql.BaseH2CompareQueryTest;
-import org.apache.ignite.internal.processors.query.h2.sql.GridQueryParsingTest;
-import org.apache.ignite.internal.processors.query.h2.sql.H2CompareBigQueryTest;
-import org.apache.ignite.internal.binary.BinaryMarshaller;
-import org.apache.ignite.spi.communication.tcp.GridOrderedMessageCancelSelfTest;
-import org.apache.ignite.testframework.config.GridTestProperties;
-
-/**
- * Cache query suite with portable marshaller.
- */
-public class IgnitePortableCacheQueryTestSuite extends TestSuite {
-    /**
-     * @return Suite.
-     * @throws Exception In case of error.
-     */
-    public static TestSuite suite() throws Exception {
-        GridTestProperties.setProperty(GridTestProperties.MARSH_CLASS_NAME, BinaryMarshaller.class.getName());
-
-        TestSuite suite = new TestSuite("Grid Cache Query Test Suite using PortableMarshaller");
-
-        // Parsing
-        suite.addTestSuite(GridQueryParsingTest.class);
-
-        // Queries tests.
-        suite.addTestSuite(GridCacheQueryIndexDisabledSelfTest.class);
-        suite.addTestSuite(IgniteCachePartitionedQueryMultiThreadedSelfTest.class);
-        suite.addTestSuite(IgniteCacheLargeResultSelfTest.class);
-        suite.addTestSuite(IgniteCacheQueryMultiThreadedSelfTest.class);
-        suite.addTestSuite(IgniteCacheQueryEvictsMultiThreadedSelfTest.class);
-        suite.addTestSuite(IgniteCacheQueryOffheapMultiThreadedSelfTest.class);
-
-        suite.addTestSuite(IgniteCacheOffheapTieredMultithreadedSelfTest.class);
-        suite.addTestSuite(GridCacheReduceQueryMultithreadedSelfTest.class);
-
-
-        // Fields queries.
-        suite.addTestSuite(IgniteCacheFieldsQueryNoDataSelfTest.class);
-        suite.addTestSuite(IgniteBinaryObjectFieldsQuerySelfTest.class);
-
-        // Continuous queries.
-        suite.addTestSuite(GridCacheContinuousQueryLocalAtomicSelfTest.class);
-        suite.addTestSuite(GridCacheContinuousQueryReplicatedAtomicSelfTest.class);
-        suite.addTestSuite(GridCacheContinuousQueryPartitionedOnlySelfTest.class);
-        suite.addTestSuite(GridCacheContinuousQueryAtomicSelfTest.class);
-        suite.addTestSuite(GridCacheContinuousQueryAtomicNearEnabledSelfTest.class);
-        suite.addTestSuite(GridCacheContinuousQueryAtomicP2PDisabledSelfTest.class);
-
-        suite.addTestSuite(GridCacheQueryIndexingDisabledSelfTest.class);
-
-        //Should be adjusted. Not ready to be used with PortableMarshaller.
-        //suite.addTestSuite(GridCachePortableSwapScanQuerySelfTest.class);
-
-        suite.addTestSuite(GridOrderedMessageCancelSelfTest.class);
-
-        // Ignite cache and H2 comparison.
-        suite.addTestSuite(BaseH2CompareQueryTest.class);
-        suite.addTestSuite(H2CompareBigQueryTest.class);
-
-        // Metrics tests
-        suite.addTestSuite(CacheLocalQueryMetricsSelfTest.class);
-        suite.addTestSuite(CachePartitionedQueryMetricsDistributedSelfTest.class);
-        suite.addTestSuite(CachePartitionedQueryMetricsLocalSelfTest.class);
-        suite.addTestSuite(CacheReplicatedQueryMetricsDistributedSelfTest.class);
-        suite.addTestSuite(CacheReplicatedQueryMetricsLocalSelfTest.class);
-
-        //Unmarshallig query test.
-        suite.addTestSuite(IgniteCacheP2pUnmarshallingQueryErrorTest.class);
-
-        suite.addTestSuite(GridCacheBinaryDuplicateIndexObjectPartitionedAtomicSelfTest.class);
-        suite.addTestSuite(GridCacheBinaryDuplicateIndexObjectPartitionedTransactionalSelfTest.class);
-
-        return suite;
-    }
-}


[12/59] [abbrv] ignite git commit: ignite-2065: rename "portable" packages to "binary"

Posted by ak...@apache.org.
http://git-wip-us.apache.org/repos/asf/ignite/blob/1dbf20e0/modules/core/src/test/java/org/apache/ignite/internal/binary/BinaryMarshallerSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/binary/BinaryMarshallerSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/binary/BinaryMarshallerSelfTest.java
new file mode 100644
index 0000000..d4f3acf
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/binary/BinaryMarshallerSelfTest.java
@@ -0,0 +1,4209 @@
+/*
+ * 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.binary;
+
+import java.io.Externalizable;
+import java.io.IOException;
+import java.io.ObjectInput;
+import java.io.ObjectOutput;
+import java.io.Serializable;
+import java.lang.reflect.Field;
+import java.lang.reflect.InvocationHandler;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.lang.reflect.Proxy;
+import java.math.BigDecimal;
+import java.math.BigInteger;
+import java.net.InetSocketAddress;
+import java.sql.Timestamp;
+import java.util.AbstractQueue;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.LinkedHashMap;
+import java.util.LinkedHashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Objects;
+import java.util.Queue;
+import java.util.TreeMap;
+import java.util.TreeSet;
+import java.util.UUID;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ConcurrentSkipListSet;
+import junit.framework.Assert;
+import org.apache.ignite.IgniteCheckedException;
+import org.apache.ignite.binary.BinaryCollectionFactory;
+import org.apache.ignite.binary.BinaryIdMapper;
+import org.apache.ignite.binary.BinaryMapFactory;
+import org.apache.ignite.binary.BinaryObject;
+import org.apache.ignite.binary.BinaryObjectBuilder;
+import org.apache.ignite.binary.BinaryObjectException;
+import org.apache.ignite.binary.BinaryRawReader;
+import org.apache.ignite.binary.BinaryRawWriter;
+import org.apache.ignite.binary.BinaryReader;
+import org.apache.ignite.binary.BinarySerializer;
+import org.apache.ignite.binary.BinaryTypeConfiguration;
+import org.apache.ignite.binary.BinaryWriter;
+import org.apache.ignite.binary.Binarylizable;
+import org.apache.ignite.configuration.BinaryConfiguration;
+import org.apache.ignite.configuration.IgniteConfiguration;
+import org.apache.ignite.internal.binary.builder.BinaryObjectBuilderImpl;
+import org.apache.ignite.internal.processors.cache.CacheObjectContext;
+import org.apache.ignite.internal.util.GridUnsafe;
+import org.apache.ignite.internal.util.IgniteUtils;
+import org.apache.ignite.internal.util.lang.GridMapEntry;
+import org.apache.ignite.internal.util.typedef.F;
+import org.apache.ignite.internal.util.typedef.internal.S;
+import org.apache.ignite.internal.util.typedef.internal.U;
+import org.apache.ignite.marshaller.MarshallerContextTestImpl;
+import org.apache.ignite.testframework.GridTestUtils;
+import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
+import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.Nullable;
+import org.jsr166.ConcurrentHashMap8;
+import sun.misc.Unsafe;
+
+import static org.apache.ignite.internal.binary.streams.PortableMemoryAllocator.INSTANCE;
+import static org.junit.Assert.assertArrayEquals;
+import static org.junit.Assert.assertNotEquals;
+
+/**
+ * Portable marshaller tests.
+ */
+@SuppressWarnings({"OverlyStrongTypeCast", "ArrayHashCode", "ConstantConditions"})
+public class BinaryMarshallerSelfTest extends GridCommonAbstractTest {
+    /** */
+    private static final Unsafe UNSAFE = GridUnsafe.unsafe();
+
+    /** */
+    protected static final long BYTE_ARR_OFF = UNSAFE.arrayBaseOffset(byte[].class);
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testNull() throws Exception {
+        assertNull(marshalUnmarshal(null));
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testByte() throws Exception {
+        assertEquals((byte) 100, marshalUnmarshal((byte)100).byteValue());
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testShort() throws Exception {
+        assertEquals((short)100, marshalUnmarshal((short)100).shortValue());
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testInt() throws Exception {
+        assertEquals(100, marshalUnmarshal(100).intValue());
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testLong() throws Exception {
+        assertEquals(100L, marshalUnmarshal(100L).longValue());
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testFloat() throws Exception {
+        assertEquals(100.001f, marshalUnmarshal(100.001f), 0);
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testDouble() throws Exception {
+        assertEquals(100.001d, marshalUnmarshal(100.001d), 0);
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testChar() throws Exception {
+        assertEquals((char)100, marshalUnmarshal((char)100).charValue());
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testBoolean() throws Exception {
+        assertEquals(true, marshalUnmarshal(true).booleanValue());
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testDecimal() throws Exception {
+        BigDecimal val;
+
+        assertEquals((val = BigDecimal.ZERO), marshalUnmarshal(val));
+        assertEquals((val = BigDecimal.valueOf(Long.MAX_VALUE, 0)), marshalUnmarshal(val));
+        assertEquals((val = BigDecimal.valueOf(Long.MIN_VALUE, 0)), marshalUnmarshal(val));
+        assertEquals((val = BigDecimal.valueOf(Long.MAX_VALUE, 8)), marshalUnmarshal(val));
+        assertEquals((val = BigDecimal.valueOf(Long.MIN_VALUE, 8)), marshalUnmarshal(val));
+
+        assertEquals((val = new BigDecimal(new BigInteger("-79228162514264337593543950336"))), marshalUnmarshal(val));
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testString() throws Exception {
+        assertEquals("str", marshalUnmarshal("str"));
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testUuid() throws Exception {
+        UUID uuid = UUID.randomUUID();
+
+        assertEquals(uuid, marshalUnmarshal(uuid));
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testDate() throws Exception {
+        Date date = new Date();
+
+        Date val = marshalUnmarshal(date);
+
+        assertEquals(date, val);
+        assertEquals(Date.class, val.getClass());
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testTimestamp() throws Exception {
+        Timestamp ts = new Timestamp(System.currentTimeMillis());
+
+        ts.setNanos(999999999);
+
+        assertEquals(ts, marshalUnmarshal(ts));
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testByteArray() throws Exception {
+        byte[] arr = new byte[] {10, 20, 30};
+
+        assertArrayEquals(arr, marshalUnmarshal(arr));
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testShortArray() throws Exception {
+        short[] arr = new short[] {10, 20, 30};
+
+        assertArrayEquals(arr, marshalUnmarshal(arr));
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testIntArray() throws Exception {
+        int[] arr = new int[] {10, 20, 30};
+
+        assertArrayEquals(arr, marshalUnmarshal(arr));
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testLongArray() throws Exception {
+        long[] arr = new long[] {10, 20, 30};
+
+        assertArrayEquals(arr, marshalUnmarshal(arr));
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testFloatArray() throws Exception {
+        float[] arr = new float[] {10.1f, 20.1f, 30.1f};
+
+        assertArrayEquals(arr, marshalUnmarshal(arr), 0);
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testDoubleArray() throws Exception {
+        double[] arr = new double[] {10.1d, 20.1d, 30.1d};
+
+        assertArrayEquals(arr, marshalUnmarshal(arr), 0);
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testCharArray() throws Exception {
+        char[] arr = new char[] {10, 20, 30};
+
+        assertArrayEquals(arr, marshalUnmarshal(arr));
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testBooleanArray() throws Exception {
+        boolean[] arr = new boolean[] {true, false, true};
+
+        assertBooleanArrayEquals(arr, marshalUnmarshal(arr));
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testDecimalArray() throws Exception {
+        BigDecimal[] arr = new BigDecimal[] {BigDecimal.ZERO, BigDecimal.ONE, BigDecimal.TEN} ;
+
+        assertArrayEquals(arr, marshalUnmarshal(arr));
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testStringArray() throws Exception {
+        String[] arr = new String[] {"str1", "str2", "str3"};
+
+        assertArrayEquals(arr, marshalUnmarshal(arr));
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testUuidArray() throws Exception {
+        UUID[] arr = new UUID[] {UUID.randomUUID(), UUID.randomUUID(), UUID.randomUUID()};
+
+        assertArrayEquals(arr, marshalUnmarshal(arr));
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testDateArray() throws Exception {
+        Date[] arr = new Date[] {new Date(11111), new Date(22222), new Date(33333)};
+
+        assertArrayEquals(arr, marshalUnmarshal(arr));
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testObjectArray() throws Exception {
+        Object[] arr = new Object[] {1, 2, 3};
+
+        assertArrayEquals(arr, marshalUnmarshal(arr));
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testException() throws Exception {
+        Exception ex = new RuntimeException();
+
+        // Checks that Optimize marshaller will be used, because Throwable has writeObject method.
+        // Exception's stacktrace equals to zero-length array by default and generates at Throwable's writeObject method.
+        assertNotEquals(0, marshalUnmarshal(ex).getStackTrace().length);
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testCollection() throws Exception {
+        testCollection(new ArrayList<Integer>(3));
+        testCollection(new LinkedHashSet<Integer>());
+        testCollection(new HashSet<Integer>());
+        testCollection(new TreeSet<Integer>());
+        testCollection(new ConcurrentSkipListSet<Integer>());
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    private void testCollection(Collection<Integer> col) throws Exception {
+        col.add(1);
+        col.add(2);
+        col.add(3);
+
+        assertEquals(col, marshalUnmarshal(col));
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testMap() throws Exception {
+        testMap(new HashMap<Integer, String>());
+        testMap(new LinkedHashMap<Integer, String>());
+        testMap(new TreeMap<Integer, String>());
+        testMap(new ConcurrentHashMap8<Integer, String>());
+        testMap(new ConcurrentHashMap<Integer, String>());
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    private void testMap(Map<Integer, String> map) throws Exception {
+        map.put(1, "str1");
+        map.put(2, "str2");
+        map.put(3, "str3");
+
+        assertEquals(map, marshalUnmarshal(map));
+    }
+
+    /**
+     * Test serialization of custom collections.
+     *
+     * @throws Exception If failed.
+     */
+    @SuppressWarnings("unchecked")
+    public void testCustomCollections() throws Exception {
+        CustomCollections cc = new CustomCollections();
+
+        cc.list.add(1);
+        cc.customList.add(2);
+
+        CustomCollections copiedCc = marshalUnmarshal(cc);
+
+        assert copiedCc.customList.getClass().equals(CustomArrayList.class);
+
+        assertEquals(cc.list.size(), copiedCc.list.size());
+        assertEquals(cc.customList.size(), copiedCc.customList.size());
+
+        assertEquals(cc.list.get(0), copiedCc.list.get(0));
+        assertEquals(cc.customList.get(0), copiedCc.customList.get(0));
+    }
+
+    /**
+     * Test custom collections with factories.
+     *
+     * @throws Exception If failed.
+     */
+    @SuppressWarnings("unchecked")
+    public void testCustomCollectionsWithFactory() throws Exception {
+        CustomCollectionsWithFactory cc = new CustomCollectionsWithFactory();
+
+        cc.list.add(new DummyHolder(1));
+        cc.map.put(new DummyHolder(2), new DummyHolder(3));
+
+        CustomCollectionsWithFactory copiedCc = marshalUnmarshal(cc);
+
+        assertEquals(cc.list.size(), copiedCc.list.size());
+        assertEquals(cc.map.size(), copiedCc.map.size());
+
+        assertEquals(cc.list.get(0), copiedCc.list.get(0));
+        assertEquals(cc.map.get(new DummyHolder(2)), copiedCc.map.get(new DummyHolder(2)));
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testExternalizableHashCode() throws Exception {
+        SimpleExternalizable sim1 = new SimpleExternalizable("Simple");
+        SimpleExternalizable sim2 = new SimpleExternalizable("Simple");
+
+        BinaryMarshaller marsh = binaryMarshaller();
+
+        BinaryObjectImpl sim1Binary = marshal(sim1, marsh);
+        BinaryObjectImpl sim2Binary = marshal(sim2, marsh);
+
+        assertEquals(sim1.hashCode(), sim2.hashCode());
+        assertEquals(sim1.hashCode(), sim1Binary.hashCode());
+        assertEquals(sim2.hashCode(), sim2Binary.hashCode());
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testExternalizableInEnclosing() throws Exception {
+        SimpleEnclosingObject obj = new SimpleEnclosingObject();
+        obj.simpl = new SimpleExternalizable("field");
+
+        SimpleEnclosingObject other = marshalUnmarshal(obj);
+
+        assertEquals(((SimpleExternalizable)obj.simpl).field, ((SimpleExternalizable)other.simpl).field);
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testMapEntry() throws Exception {
+        Map.Entry<Integer, String> e = new GridMapEntry<>(1, "str1");
+
+        assertEquals(e, marshalUnmarshal(e));
+
+        Map<Integer, String> map = new HashMap<>(1);
+
+        map.put(2, "str2");
+
+        e = F.firstEntry(map);
+
+        Map.Entry<Integer, String> e0 = marshalUnmarshal(e);
+
+        assertEquals(2, e0.getKey().intValue());
+        assertEquals("str2", e0.getValue());
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testBinaryObject() throws Exception {
+        BinaryMarshaller marsh = binaryMarshaller(Arrays.asList(new BinaryTypeConfiguration(SimpleObject.class.getName())));
+
+        SimpleObject obj = simpleObject();
+
+        BinaryObject po = marshal(obj, marsh);
+
+        BinaryObject po0 = marshalUnmarshal(po, marsh);
+
+        assertTrue(po.hasField("b"));
+        assertTrue(po.hasField("s"));
+        assertTrue(po.hasField("i"));
+        assertTrue(po.hasField("l"));
+        assertTrue(po.hasField("f"));
+        assertTrue(po.hasField("d"));
+        assertTrue(po.hasField("c"));
+        assertTrue(po.hasField("bool"));
+
+        assertFalse(po.hasField("no_such_field"));
+
+        assertEquals(obj, po.deserialize());
+        assertEquals(obj, po0.deserialize());
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testEnum() throws Exception {
+        BinaryMarshaller marsh = binaryMarshaller(Arrays.asList(new BinaryTypeConfiguration(TestEnum.class.getName())));
+
+        assertEquals(TestEnum.B, marshalUnmarshal(TestEnum.B, marsh));
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testDateAndTimestampInSingleObject() throws Exception {
+        BinaryTypeConfiguration cfg1 = new BinaryTypeConfiguration(DateClass1.class.getName());
+
+        BinaryMarshaller marsh = binaryMarshaller(Arrays.asList(cfg1));
+
+        Date date = new Date();
+        Timestamp ts = new Timestamp(System.currentTimeMillis());
+
+        DateClass1 obj1 = new DateClass1();
+        obj1.date = date;
+        obj1.ts = ts;
+
+        BinaryObject po1 = marshal(obj1, marsh);
+
+        assertEquals(date, po1.field("date"));
+        assertEquals(Date.class, po1.field("date").getClass());
+        assertEquals(ts, po1.field("ts"));
+        assertEquals(Timestamp.class, po1.field("ts").getClass());
+
+        obj1 = po1.deserialize();
+        assertEquals(date, obj1.date);
+        assertEquals(ts, obj1.ts);
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testSimpleObject() throws Exception {
+        BinaryMarshaller marsh = binaryMarshaller(Arrays.asList(
+            new BinaryTypeConfiguration(SimpleObject.class.getName())
+        ));
+
+        SimpleObject obj = simpleObject();
+
+        BinaryObject po = marshal(obj, marsh);
+
+        assertEquals(obj.hashCode(), po.hashCode());
+
+        assertEquals(obj, po.deserialize());
+
+        assertEquals(obj.b, (byte)po.field("b"));
+        assertEquals(obj.s, (short)po.field("s"));
+        assertEquals(obj.i, (int)po.field("i"));
+        assertEquals(obj.l, (long)po.field("l"));
+        assertEquals(obj.f, (float)po.field("f"), 0);
+        assertEquals(obj.d, (double)po.field("d"), 0);
+        assertEquals(obj.c, (char)po.field("c"));
+        assertEquals(obj.bool, (boolean)po.field("bool"));
+        assertEquals(obj.str, po.field("str"));
+        assertEquals(obj.uuid, po.field("uuid"));
+        assertEquals(obj.date, po.field("date"));
+        assertEquals(Date.class, obj.date.getClass());
+        assertEquals(obj.ts, po.field("ts"));
+        assertArrayEquals(obj.bArr, (byte[])po.field("bArr"));
+        assertArrayEquals(obj.sArr, (short[])po.field("sArr"));
+        assertArrayEquals(obj.iArr, (int[])po.field("iArr"));
+        assertArrayEquals(obj.lArr, (long[])po.field("lArr"));
+        assertArrayEquals(obj.fArr, (float[])po.field("fArr"), 0);
+        assertArrayEquals(obj.dArr, (double[])po.field("dArr"), 0);
+        assertArrayEquals(obj.cArr, (char[])po.field("cArr"));
+        assertBooleanArrayEquals(obj.boolArr, (boolean[])po.field("boolArr"));
+        assertArrayEquals(obj.strArr, (String[])po.field("strArr"));
+        assertArrayEquals(obj.uuidArr, (UUID[])po.field("uuidArr"));
+        assertArrayEquals(obj.dateArr, (Date[])po.field("dateArr"));
+        assertArrayEquals(obj.objArr, (Object[])po.field("objArr"));
+        assertEquals(obj.col, po.field("col"));
+        assertEquals(obj.map, po.field("map"));
+        assertEquals(new Integer(obj.enumVal.ordinal()), new Integer(((BinaryObject)po.field("enumVal")).enumOrdinal()));
+        assertArrayEquals(ordinals(obj.enumArr), ordinals((BinaryObject[])po.field("enumArr")));
+        assertNull(po.field("unknown"));
+
+        BinaryObject innerPo = po.field("inner");
+
+        assertEquals(obj.inner, innerPo.deserialize());
+
+        assertEquals(obj.inner.b, (byte)innerPo.field("b"));
+        assertEquals(obj.inner.s, (short)innerPo.field("s"));
+        assertEquals(obj.inner.i, (int)innerPo.field("i"));
+        assertEquals(obj.inner.l, (long)innerPo.field("l"));
+        assertEquals(obj.inner.f, (float)innerPo.field("f"), 0);
+        assertEquals(obj.inner.d, (double)innerPo.field("d"), 0);
+        assertEquals(obj.inner.c, (char)innerPo.field("c"));
+        assertEquals(obj.inner.bool, (boolean)innerPo.field("bool"));
+        assertEquals(obj.inner.str, innerPo.field("str"));
+        assertEquals(obj.inner.uuid, innerPo.field("uuid"));
+        assertEquals(obj.inner.date, innerPo.field("date"));
+        assertEquals(Date.class, obj.inner.date.getClass());
+        assertEquals(obj.inner.ts, innerPo.field("ts"));
+        assertArrayEquals(obj.inner.bArr, (byte[])innerPo.field("bArr"));
+        assertArrayEquals(obj.inner.sArr, (short[])innerPo.field("sArr"));
+        assertArrayEquals(obj.inner.iArr, (int[])innerPo.field("iArr"));
+        assertArrayEquals(obj.inner.lArr, (long[])innerPo.field("lArr"));
+        assertArrayEquals(obj.inner.fArr, (float[])innerPo.field("fArr"), 0);
+        assertArrayEquals(obj.inner.dArr, (double[])innerPo.field("dArr"), 0);
+        assertArrayEquals(obj.inner.cArr, (char[])innerPo.field("cArr"));
+        assertBooleanArrayEquals(obj.inner.boolArr, (boolean[])innerPo.field("boolArr"));
+        assertArrayEquals(obj.inner.strArr, (String[])innerPo.field("strArr"));
+        assertArrayEquals(obj.inner.uuidArr, (UUID[])innerPo.field("uuidArr"));
+        assertArrayEquals(obj.inner.dateArr, (Date[])innerPo.field("dateArr"));
+        assertArrayEquals(obj.inner.objArr, (Object[])innerPo.field("objArr"));
+        assertEquals(obj.inner.col, innerPo.field("col"));
+        assertEquals(obj.inner.map, innerPo.field("map"));
+        assertEquals(new Integer(obj.inner.enumVal.ordinal()),
+            new Integer(((BinaryObject)innerPo.field("enumVal")).enumOrdinal()));
+        assertArrayEquals(ordinals(obj.inner.enumArr), ordinals((BinaryObject[])innerPo.field("enumArr")));
+        assertNull(innerPo.field("inner"));
+        assertNull(innerPo.field("unknown"));
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testPortable() throws Exception {
+        BinaryMarshaller marsh = binaryMarshaller(Arrays.asList(
+            new BinaryTypeConfiguration(SimpleObject.class.getName()),
+            new BinaryTypeConfiguration(TestBinary.class.getName())
+        ));
+
+        TestBinary obj = binaryObject();
+
+        BinaryObject po = marshal(obj, marsh);
+
+        assertEquals(obj.hashCode(), po.hashCode());
+
+        assertEquals(obj, po.deserialize());
+
+        assertEquals(obj.b, (byte)po.field("_b"));
+        assertEquals(obj.s, (short)po.field("_s"));
+        assertEquals(obj.i, (int)po.field("_i"));
+        assertEquals(obj.l, (long)po.field("_l"));
+        assertEquals(obj.f, (float)po.field("_f"), 0);
+        assertEquals(obj.d, (double)po.field("_d"), 0);
+        assertEquals(obj.c, (char)po.field("_c"));
+        assertEquals(obj.bool, (boolean)po.field("_bool"));
+        assertEquals(obj.str, po.field("_str"));
+        assertEquals(obj.uuid, po.field("_uuid"));
+        assertEquals(obj.date, po.field("_date"));
+        assertEquals(obj.ts, po.field("_ts"));
+        assertArrayEquals(obj.bArr, (byte[])po.field("_bArr"));
+        assertArrayEquals(obj.sArr, (short[])po.field("_sArr"));
+        assertArrayEquals(obj.iArr, (int[])po.field("_iArr"));
+        assertArrayEquals(obj.lArr, (long[])po.field("_lArr"));
+        assertArrayEquals(obj.fArr, (float[])po.field("_fArr"), 0);
+        assertArrayEquals(obj.dArr, (double[])po.field("_dArr"), 0);
+        assertArrayEquals(obj.cArr, (char[])po.field("_cArr"));
+        assertBooleanArrayEquals(obj.boolArr, (boolean[])po.field("_boolArr"));
+        assertArrayEquals(obj.strArr, (String[])po.field("_strArr"));
+        assertArrayEquals(obj.uuidArr, (UUID[])po.field("_uuidArr"));
+        assertArrayEquals(obj.dateArr, (Date[])po.field("_dateArr"));
+        assertArrayEquals(obj.objArr, (Object[])po.field("_objArr"));
+        assertEquals(obj.col, po.field("_col"));
+        assertEquals(obj.map, po.field("_map"));
+        assertEquals(new Integer(obj.enumVal.ordinal()), new Integer(((BinaryObject)po.field("_enumVal")).enumOrdinal()));
+        assertArrayEquals(ordinals(obj.enumArr), ordinals((BinaryObject[])po.field("_enumArr")));
+        assertNull(po.field("unknown"));
+
+        BinaryObject simplePo = po.field("_simple");
+
+        assertEquals(obj.simple, simplePo.deserialize());
+
+        assertEquals(obj.simple.b, (byte)simplePo.field("b"));
+        assertEquals(obj.simple.s, (short)simplePo.field("s"));
+        assertEquals(obj.simple.i, (int)simplePo.field("i"));
+        assertEquals(obj.simple.l, (long)simplePo.field("l"));
+        assertEquals(obj.simple.f, (float)simplePo.field("f"), 0);
+        assertEquals(obj.simple.d, (double)simplePo.field("d"), 0);
+        assertEquals(obj.simple.c, (char)simplePo.field("c"));
+        assertEquals(obj.simple.bool, (boolean)simplePo.field("bool"));
+        assertEquals(obj.simple.str, simplePo.field("str"));
+        assertEquals(obj.simple.uuid, simplePo.field("uuid"));
+        assertEquals(obj.simple.date, simplePo.field("date"));
+        assertEquals(Date.class, obj.simple.date.getClass());
+        assertEquals(obj.simple.ts, simplePo.field("ts"));
+        assertArrayEquals(obj.simple.bArr, (byte[])simplePo.field("bArr"));
+        assertArrayEquals(obj.simple.sArr, (short[])simplePo.field("sArr"));
+        assertArrayEquals(obj.simple.iArr, (int[])simplePo.field("iArr"));
+        assertArrayEquals(obj.simple.lArr, (long[])simplePo.field("lArr"));
+        assertArrayEquals(obj.simple.fArr, (float[])simplePo.field("fArr"), 0);
+        assertArrayEquals(obj.simple.dArr, (double[])simplePo.field("dArr"), 0);
+        assertArrayEquals(obj.simple.cArr, (char[])simplePo.field("cArr"));
+        assertBooleanArrayEquals(obj.simple.boolArr, (boolean[])simplePo.field("boolArr"));
+        assertArrayEquals(obj.simple.strArr, (String[])simplePo.field("strArr"));
+        assertArrayEquals(obj.simple.uuidArr, (UUID[])simplePo.field("uuidArr"));
+        assertArrayEquals(obj.simple.dateArr, (Date[])simplePo.field("dateArr"));
+        assertArrayEquals(obj.simple.objArr, (Object[])simplePo.field("objArr"));
+        assertEquals(obj.simple.col, simplePo.field("col"));
+        assertEquals(obj.simple.map, simplePo.field("map"));
+        assertEquals(new Integer(obj.simple.enumVal.ordinal()),
+            new Integer(((BinaryObject)simplePo.field("enumVal")).enumOrdinal()));
+        assertArrayEquals(ordinals(obj.simple.enumArr), ordinals((BinaryObject[])simplePo.field("enumArr")));
+        assertNull(simplePo.field("simple"));
+        assertNull(simplePo.field("portable"));
+        assertNull(simplePo.field("unknown"));
+
+        BinaryObject portablePo = po.field("_portable");
+
+        assertEquals(obj.portable, portablePo.deserialize());
+
+        assertEquals(obj.portable.b, (byte)portablePo.field("_b"));
+        assertEquals(obj.portable.s, (short)portablePo.field("_s"));
+        assertEquals(obj.portable.i, (int)portablePo.field("_i"));
+        assertEquals(obj.portable.l, (long)portablePo.field("_l"));
+        assertEquals(obj.portable.f, (float)portablePo.field("_f"), 0);
+        assertEquals(obj.portable.d, (double)portablePo.field("_d"), 0);
+        assertEquals(obj.portable.c, (char)portablePo.field("_c"));
+        assertEquals(obj.portable.bool, (boolean)portablePo.field("_bool"));
+        assertEquals(obj.portable.str, portablePo.field("_str"));
+        assertEquals(obj.portable.uuid, portablePo.field("_uuid"));
+        assertEquals(obj.portable.date, portablePo.field("_date"));
+        assertEquals(obj.portable.ts, portablePo.field("_ts"));
+        assertArrayEquals(obj.portable.bArr, (byte[])portablePo.field("_bArr"));
+        assertArrayEquals(obj.portable.sArr, (short[])portablePo.field("_sArr"));
+        assertArrayEquals(obj.portable.iArr, (int[])portablePo.field("_iArr"));
+        assertArrayEquals(obj.portable.lArr, (long[])portablePo.field("_lArr"));
+        assertArrayEquals(obj.portable.fArr, (float[])portablePo.field("_fArr"), 0);
+        assertArrayEquals(obj.portable.dArr, (double[])portablePo.field("_dArr"), 0);
+        assertArrayEquals(obj.portable.cArr, (char[])portablePo.field("_cArr"));
+        assertBooleanArrayEquals(obj.portable.boolArr, (boolean[])portablePo.field("_boolArr"));
+        assertArrayEquals(obj.portable.strArr, (String[])portablePo.field("_strArr"));
+        assertArrayEquals(obj.portable.uuidArr, (UUID[])portablePo.field("_uuidArr"));
+        assertArrayEquals(obj.portable.dateArr, (Date[])portablePo.field("_dateArr"));
+        assertArrayEquals(obj.portable.objArr, (Object[])portablePo.field("_objArr"));
+        assertEquals(obj.portable.col, portablePo.field("_col"));
+        assertEquals(obj.portable.map, portablePo.field("_map"));
+        assertEquals(new Integer(obj.portable.enumVal.ordinal()),
+            new Integer(((BinaryObject)portablePo.field("_enumVal")).enumOrdinal()));
+        assertArrayEquals(ordinals(obj.portable.enumArr), ordinals((BinaryObject[])portablePo.field("_enumArr")));
+        assertNull(portablePo.field("_simple"));
+        assertNull(portablePo.field("_portable"));
+        assertNull(portablePo.field("unknown"));
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testObjectFieldOfExternalizableCollection() throws Exception {
+        EnclosingObj obj = new EnclosingObj();
+
+        obj.queue = new TestQueue("test");
+
+        assertEquals(obj, marshalUnmarshal(obj));
+    }
+
+    /**
+     *
+     */
+    private static class EnclosingObj implements Serializable {
+        /** Queue. */
+        Queue<Integer> queue = new TestQueue("test");
+
+        /** {@inheritDoc} */
+        @Override public boolean equals(Object o) {
+            if (this == o)
+                return true;
+
+            if (o == null || getClass() != o.getClass())
+                return false;
+
+            EnclosingObj obj = (EnclosingObj)o;
+
+            return Objects.equals(queue, obj.queue);
+        }
+
+        /** {@inheritDoc} */
+        @Override public int hashCode() {
+            return Objects.hash(queue);
+        }
+    }
+
+    /**
+     *
+     */
+    private static class TestQueue extends AbstractQueue<Integer> implements Externalizable {
+        /** Name. */
+        private String name;
+
+        /**
+         * @param name Name.
+         */
+        public TestQueue(String name) {
+            this.name = name;
+        }
+
+        /** {@inheritDoc} */
+        @NotNull @Override public Iterator<Integer> iterator() {
+            return Collections.emptyIterator();
+        }
+
+        /** {@inheritDoc} */
+        @Override public int size() {
+            return 0;
+        }
+
+        /** {@inheritDoc} */
+        @Override public void writeExternal(ObjectOutput out) throws IOException {
+            out.writeObject(name);
+        }
+
+        /** {@inheritDoc} */
+        @Override public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
+            name = (String)in.readObject();
+        }
+
+        /** {@inheritDoc} */
+        @Override public boolean offer(Integer integer) {
+            throw new UnsupportedOperationException();
+        }
+
+        /** {@inheritDoc} */
+        @Override public Integer poll() {
+            throw new UnsupportedOperationException();
+        }
+
+        /** {@inheritDoc} */
+        @Override public Integer peek() {
+            throw new UnsupportedOperationException();
+        }
+
+        /** {@inheritDoc} */
+        @Override public boolean equals(Object o) {
+            if (this == o)
+                return true;
+
+            if (o == null || getClass() != o.getClass())
+                return false;
+
+            TestQueue integers = (TestQueue)o;
+
+            return Objects.equals(name, integers.name);
+        }
+
+        /** {@inheritDoc} */
+        @Override public int hashCode() {
+            return Objects.hash(name);
+        }
+    }
+
+    /**
+     * @param obj Simple object.
+     * @param po Portable object.
+     */
+    private void checkSimpleObjectData(SimpleObject obj, BinaryObject po) {
+        assertEquals(obj.b, (byte)po.field("b"));
+        assertEquals(obj.s, (short)po.field("s"));
+        assertEquals(obj.i, (int)po.field("i"));
+        assertEquals(obj.l, (long)po.field("l"));
+        assertEquals(obj.f, (float)po.field("f"), 0);
+        assertEquals(obj.d, (double)po.field("d"), 0);
+        assertEquals(obj.c, (char)po.field("c"));
+        assertEquals(obj.bool, (boolean)po.field("bool"));
+        assertEquals(obj.str, po.field("str"));
+        assertEquals(obj.uuid, po.field("uuid"));
+        assertEquals(obj.date, po.field("date"));
+        assertEquals(Date.class, obj.date.getClass());
+        assertEquals(obj.ts, po.field("ts"));
+        assertArrayEquals(obj.bArr, (byte[])po.field("bArr"));
+        assertArrayEquals(obj.sArr, (short[])po.field("sArr"));
+        assertArrayEquals(obj.iArr, (int[])po.field("iArr"));
+        assertArrayEquals(obj.lArr, (long[])po.field("lArr"));
+        assertArrayEquals(obj.fArr, (float[])po.field("fArr"), 0);
+        assertArrayEquals(obj.dArr, (double[])po.field("dArr"), 0);
+        assertArrayEquals(obj.cArr, (char[])po.field("cArr"));
+        assertBooleanArrayEquals(obj.boolArr, (boolean[])po.field("boolArr"));
+        assertArrayEquals(obj.strArr, (String[])po.field("strArr"));
+        assertArrayEquals(obj.uuidArr, (UUID[])po.field("uuidArr"));
+        assertArrayEquals(obj.dateArr, (Date[])po.field("dateArr"));
+        assertArrayEquals(obj.objArr, (Object[])po.field("objArr"));
+        assertEquals(obj.col, po.field("col"));
+        assertEquals(obj.map, po.field("map"));
+        assertEquals(new Integer(obj.enumVal.ordinal()), new Integer(((BinaryObject)po.field("enumVal")).enumOrdinal()));
+        assertArrayEquals(ordinals(obj.enumArr), ordinals((BinaryObject[])po.field("enumArr")));
+        assertNull(po.field("unknown"));
+
+        assertEquals(obj, po.deserialize());
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testClassWithoutPublicConstructor() throws Exception {
+        BinaryMarshaller marsh = binaryMarshaller(Arrays.asList(
+                new BinaryTypeConfiguration(NoPublicConstructor.class.getName()),
+                new BinaryTypeConfiguration(NoPublicDefaultConstructor.class.getName()),
+                new BinaryTypeConfiguration(ProtectedConstructor.class.getName()))
+        );
+
+        NoPublicConstructor npc = new NoPublicConstructor();
+        BinaryObject npc2 = marshal(npc, marsh);
+
+        assertEquals("test", npc2.<NoPublicConstructor>deserialize().val);
+
+        NoPublicDefaultConstructor npdc = new NoPublicDefaultConstructor(239);
+        BinaryObject npdc2 = marshal(npdc, marsh);
+
+        assertEquals(239, npdc2.<NoPublicDefaultConstructor>deserialize().val);
+
+        ProtectedConstructor pc = new ProtectedConstructor();
+        BinaryObject pc2 = marshal(pc, marsh);
+
+        assertEquals(ProtectedConstructor.class, pc2.<ProtectedConstructor>deserialize().getClass());
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testCustomSerializer() throws Exception {
+        BinaryTypeConfiguration type =
+            new BinaryTypeConfiguration(CustomSerializedObject1.class.getName());
+
+        type.setSerializer(new CustomSerializer1());
+
+        BinaryMarshaller marsh = binaryMarshaller(Arrays.asList(type));
+
+        CustomSerializedObject1 obj1 = new CustomSerializedObject1(10);
+
+        BinaryObject po1 = marshal(obj1, marsh);
+
+        assertEquals(20, po1.<CustomSerializedObject1>deserialize().val);
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testCustomSerializerWithGlobal() throws Exception {
+        BinaryTypeConfiguration type1 =
+            new BinaryTypeConfiguration(CustomSerializedObject1.class.getName());
+        BinaryTypeConfiguration type2 =
+            new BinaryTypeConfiguration(CustomSerializedObject2.class.getName());
+
+        type2.setSerializer(new CustomSerializer2());
+
+        BinaryMarshaller marsh = binaryMarshaller(new CustomSerializer1(), Arrays.asList(type1, type2));
+
+        CustomSerializedObject1 obj1 = new CustomSerializedObject1(10);
+
+        BinaryObject po1 = marshal(obj1, marsh);
+
+        assertEquals(20, po1.<CustomSerializedObject1>deserialize().val);
+
+        CustomSerializedObject2 obj2 = new CustomSerializedObject2(10);
+
+        BinaryObject po2 = marshal(obj2, marsh);
+
+        assertEquals(30, po2.<CustomSerializedObject2>deserialize().val);
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testCustomIdMapper() throws Exception {
+        BinaryTypeConfiguration type =
+            new BinaryTypeConfiguration(CustomMappedObject1.class.getName());
+
+        type.setIdMapper(new BinaryIdMapper() {
+            @Override public int typeId(String clsName) {
+                return 11111;
+            }
+
+            @Override public int fieldId(int typeId, String fieldName) {
+                assert typeId == 11111;
+
+                if ("val1".equals(fieldName))
+                    return 22222;
+                else if ("val2".equals(fieldName))
+                    return 33333;
+
+                assert false : "Unknown field: " + fieldName;
+
+                return 0;
+            }
+        });
+
+        BinaryMarshaller marsh = binaryMarshaller(Arrays.asList(type));
+
+        CustomMappedObject1 obj1 = new CustomMappedObject1(10, "str");
+
+        BinaryObjectExImpl po1 = marshal(obj1, marsh);
+
+        assertEquals(11111, po1.type().typeId());
+        assertEquals((Integer)10, po1.field(22222));
+        assertEquals("str", po1.field(33333));
+
+        assertEquals(10, po1.<CustomMappedObject1>deserialize().val1);
+        assertEquals("str", po1.<CustomMappedObject1>deserialize().val2);
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testCustomIdMapperWithGlobal() throws Exception {
+        BinaryTypeConfiguration type1 =
+            new BinaryTypeConfiguration(CustomMappedObject1.class.getName());
+        BinaryTypeConfiguration type2 =
+            new BinaryTypeConfiguration(CustomMappedObject2.class.getName());
+
+        type2.setIdMapper(new BinaryIdMapper() {
+            @Override public int typeId(String clsName) {
+                return 44444;
+            }
+
+            @Override public int fieldId(int typeId, String fieldName) {
+                assert typeId == 44444;
+
+                if ("val1".equals(fieldName)) return 55555;
+                else if ("val2".equals(fieldName)) return 66666;
+
+                assert false : "Unknown field: " + fieldName;
+
+                return 0;
+            }
+        });
+
+        BinaryMarshaller marsh = binaryMarshaller(new BinaryIdMapper() {
+            @Override public int typeId(String clsName) {
+                return 11111;
+            }
+
+            @Override public int fieldId(int typeId, String fieldName) {
+                assert typeId == 11111;
+
+                if ("val1".equals(fieldName))
+                    return 22222;
+                else if ("val2".equals(fieldName))
+                    return 33333;
+
+                assert false : "Unknown field: " + fieldName;
+
+                return 0;
+            }
+        }, Arrays.asList(type1, type2));
+
+        CustomMappedObject1 obj1 = new CustomMappedObject1(10, "str1");
+
+        BinaryObjectExImpl po1 = marshal(obj1, marsh);
+
+        assertEquals(11111, po1.type().typeId());
+        assertEquals((Integer)10, po1.field(22222));
+        assertEquals("str1", po1.field(33333));
+
+        assertEquals(10, po1.<CustomMappedObject1>deserialize().val1);
+        assertEquals("str1", po1.<CustomMappedObject1>deserialize().val2);
+
+        CustomMappedObject2 obj2 = new CustomMappedObject2(20, "str2");
+
+        BinaryObjectExImpl po2 = marshal(obj2, marsh);
+
+        assertEquals(44444, po2.type().typeId());
+        assertEquals((Integer)20, po2.field(55555));
+        assertEquals("str2", po2.field(66666));
+
+        assertEquals(20, po2.<CustomMappedObject2>deserialize().val1);
+        assertEquals("str2", po2.<CustomMappedObject2>deserialize().val2);
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testDynamicObject() throws Exception {
+        BinaryMarshaller marsh = binaryMarshaller(Arrays.asList(
+            new BinaryTypeConfiguration(DynamicObject.class.getName())
+        ));
+
+        BinaryObject po1 = marshal(new DynamicObject(0, 10, 20, 30), marsh);
+
+        assertEquals(new Integer(10), po1.field("val1"));
+        assertEquals(null, po1.field("val2"));
+        assertEquals(null, po1.field("val3"));
+
+        DynamicObject do1 = po1.deserialize();
+
+        assertEquals(10, do1.val1);
+        assertEquals(0, do1.val2);
+        assertEquals(0, do1.val3);
+
+        BinaryObject po2 = marshal(new DynamicObject(1, 10, 20, 30), marsh);
+
+        assertEquals(new Integer(10), po2.field("val1"));
+        assertEquals(new Integer(20), po2.field("val2"));
+        assertEquals(null, po2.field("val3"));
+
+        DynamicObject do2 = po2.deserialize();
+
+        assertEquals(10, do2.val1);
+        assertEquals(20, do2.val2);
+        assertEquals(0, do2.val3);
+
+        BinaryObject po3 = marshal(new DynamicObject(2, 10, 20, 30), marsh);
+
+        assertEquals(new Integer(10), po3.field("val1"));
+        assertEquals(new Integer(20), po3.field("val2"));
+        assertEquals(new Integer(30), po3.field("val3"));
+
+        DynamicObject do3 = po3.deserialize();
+
+        assertEquals(10, do3.val1);
+        assertEquals(20, do3.val2);
+        assertEquals(30, do3.val3);
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testCycleLink() throws Exception {
+        BinaryMarshaller marsh = binaryMarshaller(Arrays.asList(
+            new BinaryTypeConfiguration(CycleLinkObject.class.getName())
+        ));
+
+        CycleLinkObject obj = new CycleLinkObject();
+
+        obj.self = obj;
+
+        BinaryObject po = marshal(obj, marsh);
+
+        CycleLinkObject obj0 = po.deserialize();
+
+        assert obj0.self == obj0;
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testDetached() throws Exception {
+        BinaryMarshaller marsh = binaryMarshaller(Arrays.asList(
+            new BinaryTypeConfiguration(DetachedTestObject.class.getName()),
+            new BinaryTypeConfiguration(DetachedInnerTestObject.class.getName())
+        ));
+
+        UUID id = UUID.randomUUID();
+
+        DetachedTestObject obj = marshal(new DetachedTestObject(
+            new DetachedInnerTestObject(null, id)), marsh).deserialize();
+
+        assertEquals(id, obj.inner1.id);
+        assertEquals(id, obj.inner4.id);
+
+        assert obj.inner1 == obj.inner4;
+
+        BinaryObjectImpl innerPo = (BinaryObjectImpl)obj.inner2;
+
+        assert innerPo.detached();
+
+        DetachedInnerTestObject inner = innerPo.deserialize();
+
+        assertEquals(id, inner.id);
+
+        BinaryObjectImpl detachedPo = (BinaryObjectImpl)innerPo.detach();
+
+        assert detachedPo.detached();
+
+        inner = detachedPo.deserialize();
+
+        assertEquals(id, inner.id);
+
+        innerPo = (BinaryObjectImpl)obj.inner3;
+
+        assert innerPo.detached();
+
+        inner = innerPo.deserialize();
+
+        assertEquals(id, inner.id);
+        assertNotNull(inner.inner);
+
+        detachedPo = (BinaryObjectImpl)innerPo.detach();
+
+        assert detachedPo.detached();
+
+        inner = innerPo.deserialize();
+
+        assertEquals(id, inner.id);
+        assertNotNull(inner.inner);
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testCollectionFields() throws Exception {
+        BinaryMarshaller marsh = binaryMarshaller(Arrays.asList(
+            new BinaryTypeConfiguration(CollectionFieldsObject.class.getName()),
+            new BinaryTypeConfiguration(Key.class.getName()),
+            new BinaryTypeConfiguration(Value.class.getName())
+        ));
+
+        Object[] arr = new Object[] {new Value(1), new Value(2), new Value(3)};
+        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);
+
+        BinaryObject po = marshal(obj, marsh);
+
+        Object[] arr0 = po.field("arr");
+
+        assertEquals(3, arr0.length);
+
+        int i = 1;
+
+        for (Object valPo : arr0)
+            assertEquals(i++, ((BinaryObject)valPo).<Value>deserialize().val);
+
+        Collection<BinaryObject> col0 = po.field("col");
+
+        i = 4;
+
+        for (BinaryObject valPo : col0)
+            assertEquals(i++, valPo.<Value>deserialize().val);
+
+        Map<BinaryObject, BinaryObject> map0 = po.field("map");
+
+        for (Map.Entry<BinaryObject, BinaryObject> e : map0.entrySet())
+            assertEquals(e.getKey().<Key>deserialize().key, e.getValue().<Value>deserialize().val);
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void _testDefaultMapping() throws Exception {
+        BinaryTypeConfiguration customMappingType =
+            new BinaryTypeConfiguration(TestBinary.class.getName());
+
+        customMappingType.setIdMapper(new BinaryIdMapper() {
+            @Override public int typeId(String clsName) {
+                String typeName;
+
+                try {
+                    Method mtd = PortableContext.class.getDeclaredMethod("typeName", String.class);
+
+                    mtd.setAccessible(true);
+
+                    typeName = (String)mtd.invoke(null, clsName);
+                }
+                catch (NoSuchMethodException | InvocationTargetException | IllegalAccessException e) {
+                    throw new RuntimeException(e);
+                }
+
+                return typeName.toLowerCase().hashCode();
+            }
+
+            @Override public int fieldId(int typeId, String fieldName) {
+                return fieldName.toLowerCase().hashCode();
+            }
+        });
+
+        BinaryMarshaller marsh1 = binaryMarshaller(Arrays.asList(
+            new BinaryTypeConfiguration(SimpleObject.class.getName()),
+            customMappingType
+        ));
+
+        TestBinary obj = binaryObject();
+
+        BinaryObjectImpl po = marshal(obj, marsh1);
+
+        BinaryMarshaller marsh2 = binaryMarshaller(Arrays.asList(
+            new BinaryTypeConfiguration(SimpleObject.class.getName()),
+            new BinaryTypeConfiguration(TestBinary.class.getName())
+        ));
+
+        po = marshal(obj, marsh2);
+
+        assertEquals(obj, po.deserialize());
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testTypeNames() throws Exception {
+        BinaryTypeConfiguration customType1 = new BinaryTypeConfiguration(Value.class.getName());
+
+        customType1.setIdMapper(new BinaryIdMapper() {
+            @Override public int typeId(String clsName) {
+                return 300;
+            }
+
+            @Override public int fieldId(int typeId, String fieldName) {
+                return 0;
+            }
+        });
+
+        BinaryTypeConfiguration customType2 = new BinaryTypeConfiguration("org.gridgain.NonExistentClass1");
+
+        customType2.setIdMapper(new BinaryIdMapper() {
+            @Override public int typeId(String clsName) {
+                return 400;
+            }
+
+            @Override public int fieldId(int typeId, String fieldName) {
+                return 0;
+            }
+        });
+
+        BinaryTypeConfiguration customType3 = new BinaryTypeConfiguration("NonExistentClass2");
+
+        customType3.setIdMapper(new BinaryIdMapper() {
+            @Override public int typeId(String clsName) {
+                return 500;
+            }
+
+            @Override public int fieldId(int typeId, String fieldName) {
+                return 0;
+            }
+        });
+
+        BinaryTypeConfiguration customType4 = new BinaryTypeConfiguration("NonExistentClass5");
+
+        customType4.setIdMapper(new BinaryIdMapper() {
+            @Override public int typeId(String clsName) {
+                return 0;
+            }
+
+            @Override public int fieldId(int typeId, String fieldName) {
+                return 0;
+            }
+        });
+
+        BinaryMarshaller marsh = binaryMarshaller(Arrays.asList(
+            new BinaryTypeConfiguration(Key.class.getName()),
+            new BinaryTypeConfiguration("org.gridgain.NonExistentClass3"),
+            new BinaryTypeConfiguration("NonExistentClass4"),
+            customType1,
+            customType2,
+            customType3,
+            customType4
+        ));
+
+        PortableContext ctx = portableContext(marsh);
+
+        assertEquals("notconfiguredclass".hashCode(), ctx.typeId("NotConfiguredClass"));
+        assertEquals("key".hashCode(), ctx.typeId("Key"));
+        assertEquals("nonexistentclass3".hashCode(), ctx.typeId("NonExistentClass3"));
+        assertEquals("nonexistentclass4".hashCode(), ctx.typeId("NonExistentClass4"));
+        assertEquals(300, ctx.typeId(getClass().getSimpleName() + "$Value"));
+        assertEquals(400, ctx.typeId("NonExistentClass1"));
+        assertEquals(500, ctx.typeId("NonExistentClass2"));
+        assertEquals("nonexistentclass5".hashCode(), ctx.typeId("NonExistentClass5"));
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testFieldIdMapping() throws Exception {
+        BinaryTypeConfiguration customType1 = new BinaryTypeConfiguration(Value.class.getName());
+
+        customType1.setIdMapper(new BinaryIdMapper() {
+            @Override public int typeId(String clsName) {
+                return 300;
+            }
+
+            @Override public int fieldId(int typeId, String fieldName) {
+                switch (fieldName) {
+                    case "val1":
+                        return 301;
+
+                    case "val2":
+                        return 302;
+
+                    default:
+                        return 0;
+                }
+            }
+        });
+
+        BinaryTypeConfiguration customType2 = new BinaryTypeConfiguration("NonExistentClass1");
+
+        customType2.setIdMapper(new BinaryIdMapper() {
+            @Override public int typeId(String clsName) {
+                return 400;
+            }
+
+            @Override public int fieldId(int typeId, String fieldName) {
+                switch (fieldName) {
+                    case "val1":
+                        return 401;
+
+                    case "val2":
+                        return 402;
+
+                    default:
+                        return 0;
+                }
+            }
+        });
+
+        BinaryMarshaller marsh = binaryMarshaller(Arrays.asList(new BinaryTypeConfiguration(Key.class.getName()),
+            new BinaryTypeConfiguration("NonExistentClass2"),
+            customType1,
+            customType2));
+
+        PortableContext ctx = portableContext(marsh);
+
+        assertEquals("val".hashCode(), ctx.fieldId("key".hashCode(), "val"));
+        assertEquals("val".hashCode(), ctx.fieldId("nonexistentclass2".hashCode(), "val"));
+        assertEquals("val".hashCode(), ctx.fieldId("notconfiguredclass".hashCode(), "val"));
+        assertEquals(301, ctx.fieldId(300, "val1"));
+        assertEquals(302, ctx.fieldId(300, "val2"));
+        assertEquals("val3".hashCode(), ctx.fieldId(300, "val3"));
+        assertEquals(401, ctx.fieldId(400, "val1"));
+        assertEquals(402, ctx.fieldId(400, "val2"));
+        assertEquals("val3".hashCode(), ctx.fieldId(400, "val3"));
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testDuplicateTypeId() throws Exception {
+        BinaryTypeConfiguration customType1 = new BinaryTypeConfiguration("org.gridgain.Class1");
+
+        customType1.setIdMapper(new BinaryIdMapper() {
+            @Override public int typeId(String clsName) {
+                return 100;
+            }
+
+            @Override public int fieldId(int typeId, String fieldName) {
+                return 0;
+            }
+        });
+
+        BinaryTypeConfiguration customType2 = new BinaryTypeConfiguration("org.gridgain.Class2");
+
+        customType2.setIdMapper(new BinaryIdMapper() {
+            @Override public int typeId(String clsName) {
+                return 100;
+            }
+
+            @Override public int fieldId(int typeId, String fieldName) {
+                return 0;
+            }
+        });
+
+        try {
+            binaryMarshaller(Arrays.asList(customType1, customType2));
+        }
+        catch (IgniteCheckedException e) {
+            assertEquals("Duplicate type ID [clsName=org.gridgain.Class2, id=100]",
+                e.getCause().getCause().getMessage());
+
+            return;
+        }
+
+        assert false;
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testPortableCopy() throws Exception {
+        BinaryMarshaller marsh = binaryMarshaller(Arrays.asList(
+            new BinaryTypeConfiguration(SimpleObject.class.getName())
+        ));
+
+        SimpleObject obj = simpleObject();
+
+        final BinaryObject po = marshal(obj, marsh);
+
+        assertEquals(obj, po.deserialize());
+
+        BinaryObject copy = copy(po, null);
+
+        assertEquals(obj, copy.deserialize());
+
+        copy = copy(po, new HashMap<String, Object>());
+
+        assertEquals(obj, copy.deserialize());
+
+        Map<String, Object> map = new HashMap<>(1, 1.0f);
+
+        map.put("i", 3);
+
+        copy = copy(po, map);
+
+        assertEquals((byte)2, copy.<Byte>field("b").byteValue());
+        assertEquals((short)2, copy.<Short>field("s").shortValue());
+        assertEquals(3, copy.<Integer>field("i").intValue());
+        assertEquals(2L, copy.<Long>field("l").longValue());
+        assertEquals(2.2f, copy.<Float>field("f").floatValue(), 0);
+        assertEquals(2.2d, copy.<Double>field("d").doubleValue(), 0);
+        assertEquals((char)2, copy.<Character>field("c").charValue());
+        assertEquals(false, copy.<Boolean>field("bool").booleanValue());
+
+        SimpleObject obj0 = copy.deserialize();
+
+        assertEquals((byte)2, obj0.b);
+        assertEquals((short)2, obj0.s);
+        assertEquals(3, obj0.i);
+        assertEquals(2L, obj0.l);
+        assertEquals(2.2f, obj0.f, 0);
+        assertEquals(2.2d, obj0.d, 0);
+        assertEquals((char)2, obj0.c);
+        assertEquals(false, obj0.bool);
+
+        map = new HashMap<>(3, 1.0f);
+
+        map.put("b", (byte)3);
+        map.put("l", 3L);
+        map.put("bool", true);
+
+        copy = copy(po, map);
+
+        assertEquals((byte)3, copy.<Byte>field("b").byteValue());
+        assertEquals((short)2, copy.<Short>field("s").shortValue());
+        assertEquals(2, copy.<Integer>field("i").intValue());
+        assertEquals(3L, copy.<Long>field("l").longValue());
+        assertEquals(2.2f, copy.<Float>field("f").floatValue(), 0);
+        assertEquals(2.2d, copy.<Double>field("d").doubleValue(), 0);
+        assertEquals((char)2, copy.<Character>field("c").charValue());
+        assertEquals(true, copy.<Boolean>field("bool").booleanValue());
+
+        obj0 = copy.deserialize();
+
+        assertEquals((byte)3, obj0.b);
+        assertEquals((short)2, obj0.s);
+        assertEquals(2, obj0.i);
+        assertEquals(3L, obj0.l);
+        assertEquals(2.2f, obj0.f, 0);
+        assertEquals(2.2d, obj0.d, 0);
+        assertEquals((char)2, obj0.c);
+        assertEquals(true, obj0.bool);
+
+        map = new HashMap<>(8, 1.0f);
+
+        map.put("b", (byte)3);
+        map.put("s", (short)3);
+        map.put("i", 3);
+        map.put("l", 3L);
+        map.put("f", 3.3f);
+        map.put("d", 3.3d);
+        map.put("c", (char)3);
+        map.put("bool", true);
+
+        copy = copy(po, map);
+
+        assertEquals((byte)3, copy.<Byte>field("b").byteValue());
+        assertEquals((short)3, copy.<Short>field("s").shortValue());
+        assertEquals(3, copy.<Integer>field("i").intValue());
+        assertEquals(3L, copy.<Long>field("l").longValue());
+        assertEquals(3.3f, copy.<Float>field("f").floatValue(), 0);
+        assertEquals(3.3d, copy.<Double>field("d").doubleValue(), 0);
+        assertEquals((char)3, copy.<Character>field("c").charValue());
+        assertEquals(true, copy.<Boolean>field("bool").booleanValue());
+
+        obj0 = copy.deserialize();
+
+        assertEquals((byte)3, obj0.b);
+        assertEquals((short)3, obj0.s);
+        assertEquals(3, obj0.i);
+        assertEquals(3L, obj0.l);
+        assertEquals(3.3f, obj0.f, 0);
+        assertEquals(3.3d, obj0.d, 0);
+        assertEquals((char)3, obj0.c);
+        assertEquals(true, obj0.bool);
+
+//        GridTestUtils.assertThrows(
+//            log,
+//            new Callable<Object>() {
+//                @Override public Object call() throws Exception {
+//                    po.copy(F.<String, Object>asMap("i", false));
+//
+//                    return null;
+//                }
+//            },
+//            PortableException.class,
+//            "Invalid value type for field: i"
+//        );
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testPortableCopyString() throws Exception {
+        BinaryMarshaller marsh = binaryMarshaller(Arrays.asList(
+            new BinaryTypeConfiguration(SimpleObject.class.getName())
+        ));
+
+        SimpleObject obj = simpleObject();
+
+        BinaryObject po = marshal(obj, marsh);
+
+        BinaryObject copy = copy(po, F.<String, Object>asMap("str", "str3"));
+
+        assertEquals("str3", copy.<String>field("str"));
+
+        SimpleObject obj0 = copy.deserialize();
+
+        assertEquals("str3", obj0.str);
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testPortableCopyUuid() throws Exception {
+        BinaryMarshaller marsh = binaryMarshaller(Arrays.asList(
+            new BinaryTypeConfiguration(SimpleObject.class.getName())
+        ));
+
+        SimpleObject obj = simpleObject();
+
+        BinaryObject po = marshal(obj, marsh);
+
+        UUID uuid = UUID.randomUUID();
+
+        BinaryObject copy = copy(po, F.<String, Object>asMap("uuid", uuid));
+
+        assertEquals(uuid, copy.<UUID>field("uuid"));
+
+        SimpleObject obj0 = copy.deserialize();
+
+        assertEquals(uuid, obj0.uuid);
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testPortableCopyByteArray() throws Exception {
+        BinaryMarshaller marsh = binaryMarshaller(Arrays.asList(
+            new BinaryTypeConfiguration(SimpleObject.class.getName())
+        ));
+
+        SimpleObject obj = simpleObject();
+
+        BinaryObject po = marshal(obj, marsh);
+
+        BinaryObject copy = copy(po, F.<String, Object>asMap("bArr", new byte[]{1, 2, 3}));
+
+        assertArrayEquals(new byte[]{1, 2, 3}, copy.<byte[]>field("bArr"));
+
+        SimpleObject obj0 = copy.deserialize();
+
+        assertArrayEquals(new byte[]{1, 2, 3}, obj0.bArr);
+    }
+
+    /**
+     * @param po Portable object.
+     * @param fields Fields.
+     * @return Copy.
+     */
+    private BinaryObject copy(BinaryObject po, Map<String, Object> fields) {
+        BinaryObjectBuilder builder = BinaryObjectBuilderImpl.wrap(po);
+
+        if (fields != null) {
+            for (Map.Entry<String, Object> e : fields.entrySet())
+                builder.setField(e.getKey(), e.getValue());
+        }
+
+        return builder.build();
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testPortableCopyShortArray() throws Exception {
+        BinaryMarshaller marsh = binaryMarshaller(Arrays.asList(
+            new BinaryTypeConfiguration(SimpleObject.class.getName())
+        ));
+
+        SimpleObject obj = simpleObject();
+
+        BinaryObject po = marshal(obj, marsh);
+
+        BinaryObject copy = copy(po, F.<String, Object>asMap("sArr", new short[]{1, 2, 3}));
+
+        assertArrayEquals(new short[] {1, 2, 3}, copy.<short[]>field("sArr"));
+
+        SimpleObject obj0 = copy.deserialize();
+
+        assertArrayEquals(new short[] {1, 2, 3}, obj0.sArr);
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testPortableCopyIntArray() throws Exception {
+        BinaryMarshaller marsh = binaryMarshaller(Arrays.asList(
+            new BinaryTypeConfiguration(SimpleObject.class.getName())
+        ));
+
+        SimpleObject obj = simpleObject();
+
+        BinaryObject po = marshal(obj, marsh);
+
+        BinaryObject copy = copy(po, F.<String, Object>asMap("iArr", new int[]{1, 2, 3}));
+
+        assertArrayEquals(new int[] {1, 2, 3}, copy.<int[]>field("iArr"));
+
+        SimpleObject obj0 = copy.deserialize();
+
+        assertArrayEquals(new int[] {1, 2, 3}, obj0.iArr);
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testPortableCopyLongArray() throws Exception {
+        BinaryMarshaller marsh = binaryMarshaller(Arrays.asList(
+            new BinaryTypeConfiguration(SimpleObject.class.getName())
+        ));
+
+        SimpleObject obj = simpleObject();
+
+        BinaryObject po = marshal(obj, marsh);
+
+        BinaryObject copy = copy(po, F.<String, Object>asMap("lArr", new long[]{1, 2, 3}));
+
+        assertArrayEquals(new long[] {1, 2, 3}, copy.<long[]>field("lArr"));
+
+        SimpleObject obj0 = copy.deserialize();
+
+        assertArrayEquals(new long[] {1, 2, 3}, obj0.lArr);
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testPortableCopyFloatArray() throws Exception {
+        BinaryMarshaller marsh = binaryMarshaller(Arrays.asList(
+            new BinaryTypeConfiguration(SimpleObject.class.getName())
+        ));
+
+        SimpleObject obj = simpleObject();
+
+        BinaryObject po = marshal(obj, marsh);
+
+        BinaryObject copy = copy(po, F.<String, Object>asMap("fArr", new float[]{1, 2, 3}));
+
+        assertArrayEquals(new float[] {1, 2, 3}, copy.<float[]>field("fArr"), 0);
+
+        SimpleObject obj0 = copy.deserialize();
+
+        assertArrayEquals(new float[] {1, 2, 3}, obj0.fArr, 0);
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testPortableCopyDoubleArray() throws Exception {
+        BinaryMarshaller marsh = binaryMarshaller(Arrays.asList(
+            new BinaryTypeConfiguration(SimpleObject.class.getName())
+        ));
+
+        SimpleObject obj = simpleObject();
+
+        BinaryObject po = marshal(obj, marsh);
+
+        BinaryObject copy = copy(po, F.<String, Object>asMap("dArr", new double[]{1, 2, 3}));
+
+        assertArrayEquals(new double[] {1, 2, 3}, copy.<double[]>field("dArr"), 0);
+
+        SimpleObject obj0 = copy.deserialize();
+
+        assertArrayEquals(new double[] {1, 2, 3}, obj0.dArr, 0);
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testPortableCopyCharArray() throws Exception {
+        BinaryMarshaller marsh = binaryMarshaller(Arrays.asList(
+            new BinaryTypeConfiguration(SimpleObject.class.getName())
+        ));
+
+        SimpleObject obj = simpleObject();
+
+        BinaryObject po = marshal(obj, marsh);
+
+        BinaryObject copy = copy(po, F.<String, Object>asMap("cArr", new char[]{1, 2, 3}));
+
+        assertArrayEquals(new char[]{1, 2, 3}, copy.<char[]>field("cArr"));
+
+        SimpleObject obj0 = copy.deserialize();
+
+        assertArrayEquals(new char[]{1, 2, 3}, obj0.cArr);
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testPortableCopyStringArray() throws Exception {
+        BinaryMarshaller marsh = binaryMarshaller(Arrays.asList(
+            new BinaryTypeConfiguration(SimpleObject.class.getName())
+        ));
+
+        SimpleObject obj = simpleObject();
+
+        BinaryObject po = marshal(obj, marsh);
+
+        BinaryObject copy = copy(po, F.<String, Object>asMap("strArr", new String[]{"str1", "str2"}));
+
+        assertArrayEquals(new String[]{"str1", "str2"}, copy.<String[]>field("strArr"));
+
+        SimpleObject obj0 = copy.deserialize();
+
+        assertArrayEquals(new String[]{"str1", "str2"}, obj0.strArr);
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testPortableCopyObject() throws Exception {
+        BinaryMarshaller marsh = binaryMarshaller(Arrays.asList(
+            new BinaryTypeConfiguration(SimpleObject.class.getName())
+        ));
+
+        SimpleObject obj = simpleObject();
+
+        BinaryObject po = marshal(obj, marsh);
+
+        SimpleObject newObj = new SimpleObject();
+
+        newObj.i = 12345;
+        newObj.fArr = new float[] {5, 8, 0};
+        newObj.str = "newStr";
+
+        BinaryObject copy = copy(po, F.<String, Object>asMap("inner", newObj));
+
+        assertEquals(newObj, copy.<BinaryObject>field("inner").deserialize());
+
+        SimpleObject obj0 = copy.deserialize();
+
+        assertEquals(newObj, obj0.inner);
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testPortableCopyNonPrimitives() throws Exception {
+        BinaryMarshaller marsh = binaryMarshaller(Arrays.asList(
+            new BinaryTypeConfiguration(SimpleObject.class.getName())
+        ));
+
+        SimpleObject obj = simpleObject();
+
+        BinaryObject po = marshal(obj, marsh);
+
+        Map<String, Object> map = new HashMap<>(3, 1.0f);
+
+        SimpleObject newObj = new SimpleObject();
+
+        newObj.i = 12345;
+        newObj.fArr = new float[] {5, 8, 0};
+        newObj.str = "newStr";
+
+        map.put("str", "str555");
+        map.put("inner", newObj);
+        map.put("bArr", new byte[]{6, 7, 9});
+
+        BinaryObject copy = copy(po, map);
+
+        assertEquals("str555", copy.<String>field("str"));
+        assertEquals(newObj, copy.<BinaryObject>field("inner").deserialize());
+        assertArrayEquals(new byte[]{6, 7, 9}, copy.<byte[]>field("bArr"));
+
+        SimpleObject obj0 = copy.deserialize();
+
+        assertEquals("str555", obj0.str);
+        assertEquals(newObj, obj0.inner);
+        assertArrayEquals(new byte[]{6, 7, 9}, obj0.bArr);
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testPortableCopyMixed() throws Exception {
+        BinaryMarshaller marsh = binaryMarshaller(Arrays.asList(new BinaryTypeConfiguration(SimpleObject.class.getName())));
+
+        SimpleObject obj = simpleObject();
+
+        BinaryObject po = marshal(obj, marsh);
+
+        Map<String, Object> map = new HashMap<>(3, 1.0f);
+
+        SimpleObject newObj = new SimpleObject();
+
+        newObj.i = 12345;
+        newObj.fArr = new float[] {5, 8, 0};
+        newObj.str = "newStr";
+
+        map.put("i", 1234);
+        map.put("str", "str555");
+        map.put("inner", newObj);
+        map.put("s", (short)2323);
+        map.put("bArr", new byte[]{6, 7, 9});
+        map.put("b", (byte) 111);
+
+        BinaryObject copy = copy(po, map);
+
+        assertEquals(1234, copy.<Integer>field("i").intValue());
+        assertEquals("str555", copy.<String>field("str"));
+        assertEquals(newObj, copy.<BinaryObject>field("inner").deserialize());
+        assertEquals((short)2323, copy.<Short>field("s").shortValue());
+        assertArrayEquals(new byte[] {6, 7, 9}, copy.<byte[]>field("bArr"));
+        assertEquals((byte)111, copy.<Byte>field("b").byteValue());
+
+        SimpleObject obj0 = copy.deserialize();
+
+        assertEquals(1234, obj0.i);
+        assertEquals("str555", obj0.str);
+        assertEquals(newObj, obj0.inner);
+        assertEquals((short)2323, obj0.s);
+        assertArrayEquals(new byte[]{6, 7, 9}, obj0.bArr);
+        assertEquals((byte) 111, obj0.b);
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testKeepDeserialized() throws Exception {
+        BinaryMarshaller marsh = binaryMarshaller(Arrays.asList(new BinaryTypeConfiguration(SimpleObject.class.getName())));
+
+        BinaryObjectImpl po = marshal(simpleObject(), marsh);
+
+        CacheObjectContext coCtx = new CacheObjectContext(newContext(), null, false, true, false);
+
+        assert po.value(coCtx, false) == po.value(coCtx, false);
+
+        po = marshal(simpleObject(), marsh);
+
+        assert po.deserialize() != po.deserialize();
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testOffheapPortable() throws Exception {
+        BinaryMarshaller marsh = binaryMarshaller(Arrays.asList(new BinaryTypeConfiguration(SimpleObject.class.getName())));
+
+        PortableContext ctx = portableContext(marsh);
+
+        SimpleObject simpleObj = simpleObject();
+
+        BinaryObjectImpl obj = marshal(simpleObj, marsh);
+
+        long ptr = 0;
+
+        long ptr1 = 0;
+
+        long ptr2 = 0;
+
+        try {
+            ptr = copyOffheap(obj);
+
+            BinaryObjectOffheapImpl offheapObj = new BinaryObjectOffheapImpl(ctx,
+                ptr,
+                0,
+                obj.array().length);
+
+            assertTrue(offheapObj.equals(offheapObj));
+            assertFalse(offheapObj.equals(null));
+            assertFalse(offheapObj.equals("str"));
+            assertTrue(offheapObj.equals(obj));
+            assertTrue(obj.equals(offheapObj));
+
+            ptr1 = copyOffheap(obj);
+
+            BinaryObjectOffheapImpl offheapObj1 = new BinaryObjectOffheapImpl(ctx,
+                ptr1,
+                0,
+                obj.array().length);
+
+            assertTrue(offheapObj.equals(offheapObj1));
+            assertTrue(offheapObj1.equals(offheapObj));
+
+            assertEquals(obj.type().typeId(), offheapObj.type().typeId());
+            assertEquals(obj.hashCode(), offheapObj.hashCode());
+
+            checkSimpleObjectData(simpleObj, offheapObj);
+
+            BinaryObjectOffheapImpl innerOffheapObj = offheapObj.field("inner");
+
+            assertNotNull(innerOffheapObj);
+
+            checkSimpleObjectData(simpleObj.inner, innerOffheapObj);
+
+            obj = (BinaryObjectImpl)offheapObj.heapCopy();
+
+            assertEquals(obj.type().typeId(), offheapObj.type().typeId());
+            assertEquals(obj.hashCode(), offheapObj.hashCode());
+
+            checkSimpleObjectData(simpleObj, obj);
+
+            BinaryObjectImpl innerObj = obj.field("inner");
+
+            assertNotNull(innerObj);
+
+            checkSimpleObjectData(simpleObj.inner, innerObj);
+
+            simpleObj.d = 0;
+
+            obj = marshal(simpleObj, marsh);
+
+            assertFalse(offheapObj.equals(obj));
+            assertFalse(obj.equals(offheapObj));
+
+            ptr2 = copyOffheap(obj);
+
+            BinaryObjectOffheapImpl offheapObj2 = new BinaryObjectOffheapImpl(ctx,
+                ptr2,
+                0,
+                obj.array().length);
+
+            assertFalse(offheapObj.equals(offheapObj2));
+            assertFalse(offheapObj2.equals(offheapObj));
+        }
+        finally {
+            UNSAFE.freeMemory(ptr);
+
+            if (ptr1 > 0)
+                UNSAFE.freeMemory(ptr1);
+
+            if (ptr2 > 0)
+                UNSAFE.freeMemory(ptr2);
+        }
+    }
+
+    /**
+     *
+     */
+    public void testReadResolve() throws Exception {
+        BinaryMarshaller marsh = binaryMarshaller(Arrays.asList(
+            new BinaryTypeConfiguration(MySingleton.class.getName()),
+            new BinaryTypeConfiguration(SingletonMarker.class.getName())));
+
+        BinaryObjectImpl portableObj = marshal(MySingleton.INSTANCE, marsh);
+
+        assertTrue(portableObj.array().length <= 1024); // Check that big string was not serialized.
+
+        MySingleton singleton = portableObj.deserialize();
+
+        assertSame(MySingleton.INSTANCE, singleton);
+    }
+
+    /**
+     *
+     */
+    public void testReadResolveOnPortableAware() throws Exception {
+        BinaryMarshaller marsh = binaryMarshaller(Collections.singletonList(
+            new BinaryTypeConfiguration(MyTestClass.class.getName())));
+
+        BinaryObjectImpl portableObj = marshal(new MyTestClass(), marsh);
+
+        MyTestClass obj = portableObj.deserialize();
+
+        assertEquals("readResolve", obj.s);
+    }
+
+    /**
+     * @throws Exception If ecxeption thrown.
+     */
+    public void testDeclareReadResolveInParent() throws Exception {
+        BinaryMarshaller marsh = binaryMarshaller(Arrays.asList(new BinaryTypeConfiguration(ChildPortable.class.getName())));
+
+        BinaryObjectImpl portableObj = marshal(new ChildPortable(), marsh);
+
+        ChildPortable singleton = portableObj.deserialize();
+
+        assertNotNull(singleton.s);
+    }
+
+    /**
+     *
+     */
+    public void testDecimalFields() throws Exception {
+        Collection<BinaryTypeConfiguration> clsNames = new ArrayList<>();
+
+        clsNames.add(new BinaryTypeConfiguration(DecimalReflective.class.getName()));
+        clsNames.add(new BinaryTypeConfiguration(DecimalMarshalAware.class.getName()));
+
+        BinaryMarshaller marsh = binaryMarshaller(clsNames);
+
+        // 1. Test reflective stuff.
+        DecimalReflective obj1 = new DecimalReflective();
+
+        obj1.val = BigDecimal.ZERO;
+        obj1.valArr = new BigDecimal[] { BigDecimal.ONE, BigDecimal.TEN };
+
+        BinaryObjectImpl portObj = marshal(obj1, marsh);
+
+        assertEquals(obj1.val, portObj.field("val"));
+        assertArrayEquals(obj1.valArr, portObj.<BigDecimal[]>field("valArr"));
+
+        assertEquals(obj1.val, portObj.<DecimalReflective>deserialize().val);
+        assertArrayEquals(obj1.valArr, portObj.<DecimalReflective>deserialize().valArr);
+
+        // 2. Test marshal aware stuff.
+        DecimalMarshalAware obj2 = new DecimalMarshalAware();
+
+        obj2.val = BigDecimal.ZERO;
+        obj2.valArr = new BigDecimal[] { BigDecimal.ONE, BigDecimal.TEN.negate() };
+        obj2.rawVal = BigDecimal.TEN;
+        obj2.rawValArr = new BigDecimal[] { BigDecimal.ZERO, BigDecimal.ONE };
+
+        portObj = marshal(obj2, marsh);
+
+        assertEquals(obj2.val, portObj.field("val"));
+        assertArrayEquals(obj2.valArr, portObj.<BigDecimal[]>field("valArr"));
+
+        assertEquals(obj2.val, portObj.<DecimalMarshalAware>deserialize().val);
+        assertArrayEquals(obj2.valArr, portObj.<DecimalMarshalAware>deserialize().valArr);
+        assertEquals(obj2.rawVal, portObj.<DecimalMarshalAware>deserialize().rawVal);
+        assertArrayEquals(obj2.rawValArr, portObj.<DecimalMarshalAware>deserialize().rawValArr);
+    }
+
+    /**
+     * @throws IgniteCheckedException If failed.
+     */
+    public void testFinalField() throws IgniteCheckedException {
+        BinaryMarshaller marsh = binaryMarshaller();
+
+        SimpleObjectWithFinal obj = new SimpleObjectWithFinal();
+
+        SimpleObjectWithFinal po0 = marshalUnmarshal(obj, marsh);
+
+        assertEquals(obj.time, po0.time);
+    }
+
+    /**
+     * @throws IgniteCheckedException If failed.
+     */
+    public void testThreadLocalArrayReleased() throws Exception {
+        // Checking the writer directly.
+        assertEquals(false, INSTANCE.isAcquired());
+
+        BinaryMarshaller marsh = binaryMarshaller();
+
+        try (BinaryWriterExImpl writer = new BinaryWriterExImpl(portableContext(marsh))) {
+            assertEquals(true, INSTANCE.isAcquired());
+
+            writer.writeString("Thread local test");
+
+            writer.array();
+
+            assertEquals(true, INSTANCE.isAcquired());
+        }
+
+        // Checking the portable marshaller.
+        assertEquals(false, INSTANCE.isAcquired());
+
+        marsh = binaryMarshaller();
+
+        marsh.marshal(new SimpleObject());
+
+        assertEquals(false, INSTANCE.isAcquired());
+
+        marsh = binaryMarshaller();
+
+        // Checking the builder.
+        BinaryObjectBuilder builder = new BinaryObjectBuilderImpl(portableContext(marsh),
+            "org.gridgain.foo.bar.TestClass");
+
+        builder.setField("a", "1");
+
+        BinaryObject portableObj = builder.build();
+
+        assertEquals(false, INSTANCE.isAcquired());
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testDuplicateName() throws Exception {
+        BinaryMarshaller marsh = binaryMarshaller();
+
+        Test1.Job job1 = new Test1().new Job();
+        Test2.Job job2 = new Test2().new Job();
+
+        marsh.marshal(job1);
+
+        try {
+            marsh.marshal(job2);
+        }
+        catch (BinaryObjectException e) {
+            assertEquals(true, e.getMessage().contains("Failed to register class"));
+
+            return;
+        }
+
+        assert false;
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testClass() throws Exception {
+        BinaryMarshaller marsh = binaryMarshaller();
+
+        Class cls = BinaryMarshallerSelfTest.class;
+
+        Class unmarshalledCls = marshalUnmarshal(cls, marsh);
+
+        Assert.assertEquals(cls, unmarshalledCls);
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testClassFieldsMarshalling() throws Exception {
+        BinaryMarshaller marsh = binaryMarshaller();
+
+        ObjectWithClassFields obj = new ObjectWithClassFields();
+        obj.cls1 = BinaryMarshallerSelfTest.class;
+
+        byte[] marshal = marsh.marshal(obj);
+
+        ObjectWithClassFields obj2 = marsh.unmarshal(marshal, null);
+
+        assertEquals(obj.cls1, obj2.cls1);
+        assertNull(obj2.cls2);
+
+        BinaryObject portObj = marshal(obj, marsh);
+
+        Class cls1 = portObj.field("cls1");
+
+        assertEquals(obj.cls1, cls1);
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testMarshallingThroughJdk() throws Exception {
+        BinaryMarshaller marsh = binaryMarshaller();
+
+        InetSocketAddress addr = new InetSocketAddress("192.168.0.2", 4545);
+
+        byte[] arr = marsh.marshal(addr);
+
+        InetSocketAddress addr2 = marsh.unmarshal(arr, null);
+
+        assertEquals(addr.getHostString(), addr2.getHostString());
+        assertEquals(addr.getPort(), addr2.getPort());
+
+        TestAddress testAddr = new TestAddress();
+        testAddr.addr = addr;
+        testAddr.str1 = "Hello World";
+
+        SimpleObject simpleObj = new SimpleObject();
+        simpleObj.c = 'g';
+        simpleObj.date = new Date();
+
+        testAddr.obj = simpleObj;
+
+        arr = marsh.marshal(testAddr);
+
+        TestAddress testAddr2 = marsh.unmarshal(arr, null);
+
+        assertEquals(testAddr.addr.getHostString(), testAddr2.addr.getHostString());
+        assertEquals(testAddr.addr.getPort(), testAddr2.addr.getPort());
+        assertEquals(testAddr.str1, testAddr2.str1);
+        assertEquals(testAddr.obj.c, testAddr2.obj.c);
+        assertEquals(testAddr.obj.date, testAddr2.obj.date);
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testPredefinedTypeIds() throws Exception {
+        BinaryMarshaller marsh = binaryMarshaller();
+
+        PortableContext pCtx = portableContext(marsh);
+
+        Field field = pCtx.getClass().getDeclaredField("predefinedTypeNames");
+
+        field.setAccessible(true);
+
+        Map<String, Integer> map = (Map<String, Integer>)field.get(pCtx);
+
+        assertTrue(map.size() > 0);
+
+        for (Map.Entry<String, Integer> entry : map.entrySet()) {
+            int id = entry.getValue();
+
+            if (id == GridPortableMarshaller.UNREGISTERED_TYPE_ID)
+                continue;
+
+            PortableClassDescriptor desc = pCtx.descriptorForTypeId(false, entry.getValue(), null, false);
+
+            assertEquals(desc.typeId(), pCtx.typeId(desc.describedClass().getName()));
+            assertEquals(desc.typeId(), pCtx.typeId(pCtx.typeName(desc.describedClass().getName())));
+        }
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testCyclicReferencesMarshalling() throws Exception {
+        BinaryMarshaller marsh = binaryMarshaller();
+
+        SimpleObject obj = simpleObject();
+
+        obj.bArr = obj.inner.bArr;
+        obj.cArr = obj.inner.cArr;
+        obj.boolArr = obj.inner.boolArr;
+        obj.sArr = obj.inner.sArr;
+        obj.strArr = obj.inner.strArr;
+        obj.iArr = obj.inner.iArr;
+        obj.lArr = obj.inner.lArr;
+        obj.fArr = obj.inner.fArr;
+        obj.dArr = obj.inner.dArr;
+        obj.dateArr = obj.inner.dateArr;
+        obj.uuidArr = obj.inner.uuidArr;
+        obj.objArr = obj.inner.objArr;
+        obj.bdArr = obj.inner.bdArr;
+        obj.map = obj.inner.map;
+        obj.col = obj.inner.col;
+        obj.mEntry = obj.inner.mEntry;
+
+        SimpleObject res = (SimpleObject)marshalUnmarshal(obj, marsh);
+
+        assertEquals(obj, res);
+
+        assertTrue(res.objArr == res.inner.objArr);
+        assertTrue(res.map == res.inner.map);
+        assertTrue(res.col == res.inner.col);
+        assertTrue(res.mEntry == res.inner.mEntry);
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testProxy() throws Exception {
+        BinaryMarshaller marsh = binaryMarshaller();
+
+        SomeItf inItf = (SomeItf)Proxy.newProxyInstance(
+            BinaryMarshallerSelfTest.class.getClassLoader(), new Class[] {SomeItf.class},
+            new InvocationHandler() {
+                private NonSerializable obj = new NonSerializable(null);
+
+                @Override public Object invoke(Object proxy, Method mtd, Object[] args) throws Throwable {
+                    if ("hashCode".equals(mtd.getName()))
+                        return obj.hashCode();
+
+                    obj.checkAfterUnmarshalled();
+
+                    return 17;
+                }
+            }
+        );
+
+        SomeItf outItf = marsh.unmarshal(marsh.marshal(inItf), null);
+
+        assertEquals(outItf.checkAfterUnmarshalled(), 17);
+    }
+
+    /**
+     *
+     */
+    private static interface SomeItf {
+        /**
+         * @return Check result.
+         */
+        int checkAfterUnmarshalled();
+    }
+
+    /**
+     * Some non-serializable class.
+     */
+    @SuppressWarnings( {"PublicField","TransientFieldInNonSerializableClass","FieldMayBeStatic"})
+    private static class NonSerializableA {
+        /** */
+        private final long longVal = 0x33445566778899AAL;
+
+        /** */
+        protected Short shortVal = (short)0xAABB;
+
+        /** */
+        public String[] strArr = {"AA","BB"};
+
+        /** */
+        public boolean flag1 = true;
+
+        /** */
+        public boolean flag2;
+
+        /** */
+        public Boolean flag3;
+
+        /** */
+        public Boolean flag4 = true;
+
+        /** */
+        public Boolean flag5 = false;
+
+        /** */
+        private transient int intVal = 0xAABBCCDD;
+
+        /**
+         * @param strArr Array.
+         * @param shortVal Short value.
+         */
+        @SuppressWarnings( {"UnusedDeclaration"})
+        private NonSerializableA(@Nullable String[] strArr, @Nullable Short shortVal) {
+            // No-op.
+        }
+
+        /**
+         * Checks correctness of the state after unmarshalling.
+         */
+        void checkAfterUnmarshalled() {
+            assertEquals(longVal, 0x33445566778899AAL);
+
+            assertEquals(shortVal.shortValue(), (short)0xAABB);
+
+            assertTrue(Arrays.equals(strArr, new String[] {"AA","BB"}));
+
+            assertEquals(0, intVal);
+
+            assertTrue(flag1);
+            assertFalse(flag2);
+            assertNull(flag3);
+            assertTrue(flag4);
+            assertFalse(flag5);
+        }
+    }
+
+    /**
+     * Some non-serializable class.
+     */
+    @SuppressWarnings( {"PublicField","TransientFieldInNonSerializableClass","PackageVisibleInnerClass"})
+    static class NonSerializableB extends NonSerializableA {
+        /** */
+        public Short shortValue = 0x1122;
+
+        /** */
+        public long longValue = 0x8877665544332211L;
+
+        /** */
+        private transient NonSerializableA[] aArr = {
+            new NonSerializableA(null, null),
+            new NonSerializableA(null, null),
+            new NonSerializableA(null, null)
+        };
+
+        /** */
+        protected Double doubleVal = 123.456;
+
+        /**
+         * Just to eliminate the default constructor.
+         */
+        private NonSerializableB() {
+            super(null, null);
+        }
+
+        /**
+         * Checks correctness of the state after unmarshalling.
+         */
+        @Override void checkAfterUnmarshalled() {
+            super.checkAfterUnmarshalled();
+
+            assertEquals(shortValue.shortValue(), 0x1122);
+
+            assertEquals(longValue, 0x8877665544332211L);
+
+            assertNull(aArr);
+
+            assertEquals(doubleVal, 123.456);
+        }
+    }
+
+    /**
+     * Some non-serializable class.
+     */
+    @SuppressWarnings( {"TransientFieldInNonSerializableClass","PublicField"})
+    private static class NonSerializable extends NonSerializableB {
+        /** */
+        private int idVal = -17;
+
+        /** */
+        private final NonSerializableA aVal = new NonSerializableB();
+
+        /** */
+        private transient NonSerializableB bVal = new NonSerializableB();
+
+        /** */
+        private NonSerializableA[] bArr = new NonSerializableA[] {
+            new NonSerializableB(),
+            new NonSerializableA(null, null)
+        };
+
+        /** */
+        public float floatVal = 567.89F;
+
+        /**
+         * Just to eliminate the default constructor.
+         *
+         * @param aVal Unused.
+         */
+        @SuppressWarnings( {"UnusedDeclaration"})
+        private NonSerializable(NonSerializableA aVal) {
+        }
+
+        /**
+         * Checks correctness of the state after unmarshalling.
+         */
+        @Override void checkAfterUnmarshalled() {
+            super.checkAfterUnmarshalled();
+
+            assertEquals(idVal, -17);
+
+            aVal.checkAfterUnmarshalled();
+
+            assertNull(bVal);
+
+            for (NonSerializableA a : bArr) {
+                a.checkAfterUnmarshalled();
+            }
+
+            assertEquals(floatVal, 567.89F);
+        }
+    }
+
+    /**
+     * Object with class fields.
+     */
+    private static class ObjectWithClassFields {
+        /** */
+        private Class<?> cls1;
+
+        /** */
+        private Class<?> cls2;
+    }
+
+    /**
+     *
+     */
+    private static class TestAddress {
+        /** */
+        private SimpleObject obj;
+
+        /** */
+        private InetSocketAddress addr;
+
+        /** */
+        private String str1;
+    }
+
+    /**
+     *
+     */
+    private static class Test1 {
+        /**
+         *
+         */
+        private class Job {
+
+        }
+    }
+
+    /**
+     *
+     */
+    private static class Test2 {
+        /**
+         *
+         */
+        private class Job {
+
+        }
+    }
+
+    /**
+     * @param obj Object.
+     * @return Offheap address.
+     */
+    private long copyOffheap(BinaryObjectImpl obj) {
+        byte[] arr = obj.array();
+
+        long ptr = UNSAFE.allocateMemory(arr.length);
+
+        UNSAFE.copyMemory(arr, BYTE_ARR_OFF, null, ptr, arr.length);
+
+        return ptr;
+    }
+
+    /**
+     * @param enumArr Enum array.
+     * @return Ordinals.
+     */
+    private <T extends Enum<?>> Integer[] ordinals(T[] enumArr) {
+        Integer[] ords = new Integer[enumArr.length];
+
+        for (int i = 0; i < enumArr.length; i++)
+            ords[i] = enumArr[i].ordinal();
+
+        return ords;
+    }
+
+    /**
+     * @param enumArr Enum array.
+     * @return Ordinals.
+     */
+    private <T extends Enum<?>> Integer[] ordinals(BinaryObject[]

<TRUNCATED>

[35/59] [abbrv] ignite git commit: ignite-1.5 Minor fix in Schema Import Demo README.txt

Posted by ak...@apache.org.
ignite-1.5 Minor fix in Schema Import Demo README.txt


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

Branch: refs/heads/ignite-843-rc2
Commit: c2916442dc334c4968aade070d936139ba13d807
Parents: 69a6b0f
Author: Alexey Kuznetsov <ak...@apache.org>
Authored: Fri Dec 11 17:15:39 2015 +0700
Committer: Alexey Kuznetsov <ak...@apache.org>
Committed: Fri Dec 11 17:15:39 2015 +0700

----------------------------------------------------------------------
 examples/schema-import/README.txt | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/c2916442/examples/schema-import/README.txt
----------------------------------------------------------------------
diff --git a/examples/schema-import/README.txt b/examples/schema-import/README.txt
index c5aa2d5..ff2d517 100644
--- a/examples/schema-import/README.txt
+++ b/examples/schema-import/README.txt
@@ -25,7 +25,7 @@ Schema Import Utility Demo
 
 3. Paste content of "examples/schema-import/bin/db-init.sql" into H2 Console and execute.
 
-4. Start Schema Import utility: "bin/ignite-schema-import.sh examples/schema-import/bin/schema-import.properties"
+4. Start Schema Import utility: "IGNITE_HOME/bin/ignite-schema-import.sh examples/schema-import/bin/schema-import.properties"
    Schema Utility will start with predefined settings for this demo.
    Click "Next", "Generate" and answer "Yes" to all override warnings.
 


[18/59] [abbrv] ignite git commit: ignite-2065: rename "portable" packages to "binary"

Posted by ak...@apache.org.
http://git-wip-us.apache.org/repos/asf/ignite/blob/1dbf20e0/modules/core/src/main/java/org/apache/ignite/internal/portable/PortableSchemaRegistry.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/portable/PortableSchemaRegistry.java b/modules/core/src/main/java/org/apache/ignite/internal/portable/PortableSchemaRegistry.java
deleted file mode 100644
index e442b1f..0000000
--- a/modules/core/src/main/java/org/apache/ignite/internal/portable/PortableSchemaRegistry.java
+++ /dev/null
@@ -1,172 +0,0 @@
-/*
- * 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.portable;
-
-import org.jetbrains.annotations.Nullable;
-
-import java.util.HashMap;
-
-/**
- * Portable schema registry. Contains all well-known object schemas.
- * <p>
- * We rely on the fact that usually object has only few different schemas. For this reason we inline several
- * of them with optional fallback to normal hash map lookup.
- *
- */
-public class PortableSchemaRegistry {
-    /** Empty schema ID. */
-    private static final int EMPTY = 0;
-
-    /** Whether registry still works in inline mode. */
-    private volatile boolean inline = true;
-
-    /** First schema ID. */
-    private int schemaId1;
-
-    /** Second schema ID. */
-    private int schemaId2;
-
-    /** Third schema ID. */
-    private int schemaId3;
-
-    /** Fourth schema ID. */
-    private int schemaId4;
-
-    /** First schema. */
-    private PortableSchema schema1;
-
-    /** Second schema. */
-    private PortableSchema schema2;
-
-    /** Third schema. */
-    private PortableSchema schema3;
-
-    /** Fourth schema. */
-    private PortableSchema schema4;
-
-    /** Schemas with COW semantics. */
-    private volatile HashMap<Integer, PortableSchema> schemas;
-
-    /**
-     * Get schema for the given ID. We rely on very relaxed memory semantics here assuming that it is not critical
-     * to return false-positive {@code null} values.
-     *
-     * @param schemaId Schema ID.
-     * @return Schema or {@code null}.
-     */
-    @Nullable public PortableSchema schema(int schemaId) {
-        if (inline) {
-            if (schemaId == schemaId1)
-                return schema1;
-            else if (schemaId == schemaId2)
-                return schema2;
-            else if (schemaId == schemaId3)
-                return schema3;
-            else if (schemaId == schemaId4)
-                return schema4;
-        }
-        else {
-            HashMap<Integer, PortableSchema> schemas0 = schemas;
-
-            // Null can be observed here due to either data race or race condition when switching to non-inlined mode.
-            // Both of them are benign for us because they lead only to unnecessary schema re-calc.
-            if (schemas0 != null)
-                return schemas0.get(schemaId);
-        }
-
-        return null;
-    }
-
-    /**
-     * Add schema.
-     *
-     * @param schemaId Schema ID.
-     * @param schema Schema.
-     */
-    public void addSchema(int schemaId, PortableSchema schema) {
-        synchronized (this) {
-            if (inline) {
-                // Check if this is already known schema.
-                if (schemaId == schemaId1 || schemaId == schemaId2 || schemaId == schemaId3 || schemaId == schemaId4)
-                    return;
-
-                // Try positioning new schema in inline mode.
-                if (schemaId1 == EMPTY) {
-                    schemaId1 = schemaId;
-
-                    schema1 = schema;
-
-                    inline = true; // Forcing HB edge just in case.
-
-                    return;
-                }
-
-                if (schemaId2 == EMPTY) {
-                    schemaId2 = schemaId;
-
-                    schema2 = schema;
-
-                    inline = true; // Forcing HB edge just in case.
-
-                    return;
-                }
-
-                if (schemaId3 == EMPTY) {
-                    schemaId3 = schemaId;
-
-                    schema3 = schema;
-
-                    inline = true; // Forcing HB edge just in case.
-
-                    return;
-                }
-
-                if (schemaId4 == EMPTY) {
-                    schemaId4 = schemaId;
-
-                    schema4 = schema;
-
-                    inline = true; // Forcing HB edge just in case.
-
-                    return;
-                }
-
-                // No luck, switching to hash map mode.
-                HashMap<Integer, PortableSchema> newSchemas = new HashMap<>();
-
-                newSchemas.put(schemaId1, schema1);
-                newSchemas.put(schemaId2, schema2);
-                newSchemas.put(schemaId3, schema3);
-                newSchemas.put(schemaId4, schema4);
-
-                newSchemas.put(schemaId, schema);
-
-                schemas = newSchemas;
-
-                inline = false;
-            }
-            else {
-                HashMap<Integer, PortableSchema> newSchemas = new HashMap<>(schemas);
-
-                newSchemas.put(schemaId, schema);
-
-                schemas = newSchemas;
-            }
-        }
-    }
-}

http://git-wip-us.apache.org/repos/asf/ignite/blob/1dbf20e0/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
deleted file mode 100644
index 125bb25..0000000
--- a/modules/core/src/main/java/org/apache/ignite/internal/portable/PortableUtils.java
+++ /dev/null
@@ -1,1907 +0,0 @@
-/*
- * 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.portable;
-
-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;
-import org.apache.ignite.internal.portable.builder.PortableLazyValue;
-import org.apache.ignite.internal.portable.streams.PortableInputStream;
-import org.apache.ignite.internal.util.typedef.F;
-import org.apache.ignite.internal.util.typedef.internal.U;
-import org.apache.ignite.lang.IgniteBiTuple;
-import org.jetbrains.annotations.Nullable;
-import org.jsr166.ConcurrentHashMap8;
-
-import java.io.ByteArrayInputStream;
-import java.io.Externalizable;
-import java.lang.reflect.Array;
-import java.math.BigDecimal;
-import java.math.BigInteger;
-import java.sql.Timestamp;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Date;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.LinkedHashMap;
-import java.util.LinkedHashSet;
-import java.util.LinkedList;
-import java.util.Map;
-import java.util.Set;
-import java.util.TreeMap;
-import java.util.TreeSet;
-import java.util.UUID;
-import java.util.concurrent.ConcurrentHashMap;
-import java.util.concurrent.ConcurrentSkipListSet;
-
-import static java.nio.charset.StandardCharsets.UTF_8;
-import static org.apache.ignite.internal.portable.GridPortableMarshaller.ARR_LIST;
-import static org.apache.ignite.internal.portable.GridPortableMarshaller.BOOLEAN;
-import static org.apache.ignite.internal.portable.GridPortableMarshaller.BOOLEAN_ARR;
-import static org.apache.ignite.internal.portable.GridPortableMarshaller.BYTE;
-import static org.apache.ignite.internal.portable.GridPortableMarshaller.BYTE_ARR;
-import static org.apache.ignite.internal.portable.GridPortableMarshaller.CHAR;
-import static org.apache.ignite.internal.portable.GridPortableMarshaller.CHAR_ARR;
-import static org.apache.ignite.internal.portable.GridPortableMarshaller.CLASS;
-import static org.apache.ignite.internal.portable.GridPortableMarshaller.COL;
-import static org.apache.ignite.internal.portable.GridPortableMarshaller.DATE;
-import static org.apache.ignite.internal.portable.GridPortableMarshaller.DATE_ARR;
-import static org.apache.ignite.internal.portable.GridPortableMarshaller.DECIMAL;
-import static org.apache.ignite.internal.portable.GridPortableMarshaller.DECIMAL_ARR;
-import static org.apache.ignite.internal.portable.GridPortableMarshaller.DOUBLE;
-import static org.apache.ignite.internal.portable.GridPortableMarshaller.DOUBLE_ARR;
-import static org.apache.ignite.internal.portable.GridPortableMarshaller.ENUM;
-import static org.apache.ignite.internal.portable.GridPortableMarshaller.ENUM_ARR;
-import static org.apache.ignite.internal.portable.GridPortableMarshaller.FLOAT;
-import static org.apache.ignite.internal.portable.GridPortableMarshaller.FLOAT_ARR;
-import static org.apache.ignite.internal.portable.GridPortableMarshaller.HANDLE;
-import static org.apache.ignite.internal.portable.GridPortableMarshaller.HASH_MAP;
-import static org.apache.ignite.internal.portable.GridPortableMarshaller.HASH_SET;
-import static org.apache.ignite.internal.portable.GridPortableMarshaller.INT;
-import static org.apache.ignite.internal.portable.GridPortableMarshaller.INT_ARR;
-import static org.apache.ignite.internal.portable.GridPortableMarshaller.LINKED_HASH_MAP;
-import static org.apache.ignite.internal.portable.GridPortableMarshaller.LINKED_HASH_SET;
-import static org.apache.ignite.internal.portable.GridPortableMarshaller.LINKED_LIST;
-import static org.apache.ignite.internal.portable.GridPortableMarshaller.LONG;
-import static org.apache.ignite.internal.portable.GridPortableMarshaller.LONG_ARR;
-import static org.apache.ignite.internal.portable.GridPortableMarshaller.MAP;
-import static org.apache.ignite.internal.portable.GridPortableMarshaller.NULL;
-import static org.apache.ignite.internal.portable.GridPortableMarshaller.OBJ;
-import static org.apache.ignite.internal.portable.GridPortableMarshaller.OBJECT_TYPE_ID;
-import static org.apache.ignite.internal.portable.GridPortableMarshaller.OBJ_ARR;
-import static org.apache.ignite.internal.portable.GridPortableMarshaller.OPTM_MARSH;
-import static org.apache.ignite.internal.portable.GridPortableMarshaller.PORTABLE_OBJ;
-import static org.apache.ignite.internal.portable.GridPortableMarshaller.PROTO_VER;
-import static org.apache.ignite.internal.portable.GridPortableMarshaller.SHORT;
-import static org.apache.ignite.internal.portable.GridPortableMarshaller.SHORT_ARR;
-import static org.apache.ignite.internal.portable.GridPortableMarshaller.STRING;
-import static org.apache.ignite.internal.portable.GridPortableMarshaller.STRING_ARR;
-import static org.apache.ignite.internal.portable.GridPortableMarshaller.TIMESTAMP;
-import static org.apache.ignite.internal.portable.GridPortableMarshaller.TIMESTAMP_ARR;
-import static org.apache.ignite.internal.portable.GridPortableMarshaller.UNREGISTERED_TYPE_ID;
-import static org.apache.ignite.internal.portable.GridPortableMarshaller.USER_COL;
-import static org.apache.ignite.internal.portable.GridPortableMarshaller.USER_SET;
-import static org.apache.ignite.internal.portable.GridPortableMarshaller.UUID;
-import static org.apache.ignite.internal.portable.GridPortableMarshaller.UUID_ARR;
-
-/**
- * Portable utils.
- */
-public class PortableUtils {
-    /** */
-    public static final Map<Class<?>, Byte> PLAIN_CLASS_TO_FLAG = new HashMap<>();
-
-    /** */
-    public static final Map<Byte, Class<?>> FLAG_TO_CLASS = new HashMap<>();
-
-    /** {@code true} if serialized value of this type cannot contain references to objects. */
-    private static final boolean[] PLAIN_TYPE_FLAG = new boolean[102];
-
-    /** Portable classes. */
-    private static final Collection<Class<?>> PORTABLE_CLS = new HashSet<>();
-
-    /** Flag: user type. */
-    public static final short FLAG_USR_TYP = 0x0001;
-
-    /** Flag: only raw data exists. */
-    public static final short FLAG_HAS_SCHEMA = 0x0002;
-
-    /** Flag indicating that object has raw data. */
-    public static final short FLAG_HAS_RAW = 0x0004;
-
-    /** Flag: offsets take 1 byte. */
-    public static final short FLAG_OFFSET_ONE_BYTE = 0x0008;
-
-    /** Flag: offsets take 2 bytes. */
-    public static final short FLAG_OFFSET_TWO_BYTES = 0x0010;
-
-    /** Flag: compact footer, no field IDs. */
-    public static final short FLAG_COMPACT_FOOTER = 0x0020;
-
-    /** Offset which fits into 1 byte. */
-    public static final int OFFSET_1 = 1;
-
-    /** Offset which fits into 2 bytes. */
-    public static final int OFFSET_2 = 2;
-
-    /** Offset which fits into 4 bytes. */
-    public static final int OFFSET_4 = 4;
-
-    /** Field ID length. */
-    public static final int FIELD_ID_LEN = 4;
-
-    /** Field type names. */
-    private static final String[] FIELD_TYPE_NAMES;
-
-    /** FNV1 hash offset basis. */
-    private static final int FNV1_OFFSET_BASIS = 0x811C9DC5;
-
-    /** FNV1 hash prime. */
-    private static final int FNV1_PRIME = 0x01000193;
-
-    /**
-     * Static class initializer.
-     */
-    static {
-        PLAIN_CLASS_TO_FLAG.put(Byte.class, GridPortableMarshaller.BYTE);
-        PLAIN_CLASS_TO_FLAG.put(Short.class, GridPortableMarshaller.SHORT);
-        PLAIN_CLASS_TO_FLAG.put(Integer.class, GridPortableMarshaller.INT);
-        PLAIN_CLASS_TO_FLAG.put(Long.class, GridPortableMarshaller.LONG);
-        PLAIN_CLASS_TO_FLAG.put(Float.class, GridPortableMarshaller.FLOAT);
-        PLAIN_CLASS_TO_FLAG.put(Double.class, GridPortableMarshaller.DOUBLE);
-        PLAIN_CLASS_TO_FLAG.put(Character.class, GridPortableMarshaller.CHAR);
-        PLAIN_CLASS_TO_FLAG.put(Boolean.class, GridPortableMarshaller.BOOLEAN);
-        PLAIN_CLASS_TO_FLAG.put(BigDecimal.class, GridPortableMarshaller.DECIMAL);
-        PLAIN_CLASS_TO_FLAG.put(String.class, GridPortableMarshaller.STRING);
-        PLAIN_CLASS_TO_FLAG.put(UUID.class, GridPortableMarshaller.UUID);
-        PLAIN_CLASS_TO_FLAG.put(Date.class, GridPortableMarshaller.DATE);
-        PLAIN_CLASS_TO_FLAG.put(Timestamp.class, GridPortableMarshaller.TIMESTAMP);
-
-        PLAIN_CLASS_TO_FLAG.put(byte[].class, GridPortableMarshaller.BYTE_ARR);
-        PLAIN_CLASS_TO_FLAG.put(short[].class, GridPortableMarshaller.SHORT_ARR);
-        PLAIN_CLASS_TO_FLAG.put(int[].class, GridPortableMarshaller.INT_ARR);
-        PLAIN_CLASS_TO_FLAG.put(long[].class, GridPortableMarshaller.LONG_ARR);
-        PLAIN_CLASS_TO_FLAG.put(float[].class, GridPortableMarshaller.FLOAT_ARR);
-        PLAIN_CLASS_TO_FLAG.put(double[].class, GridPortableMarshaller.DOUBLE_ARR);
-        PLAIN_CLASS_TO_FLAG.put(char[].class, GridPortableMarshaller.CHAR_ARR);
-        PLAIN_CLASS_TO_FLAG.put(boolean[].class, GridPortableMarshaller.BOOLEAN_ARR);
-        PLAIN_CLASS_TO_FLAG.put(BigDecimal[].class, GridPortableMarshaller.DECIMAL_ARR);
-        PLAIN_CLASS_TO_FLAG.put(String[].class, GridPortableMarshaller.STRING_ARR);
-        PLAIN_CLASS_TO_FLAG.put(UUID[].class, GridPortableMarshaller.UUID_ARR);
-        PLAIN_CLASS_TO_FLAG.put(Date[].class, GridPortableMarshaller.DATE_ARR);
-        PLAIN_CLASS_TO_FLAG.put(Timestamp[].class, GridPortableMarshaller.TIMESTAMP_ARR);
-
-        for (Map.Entry<Class<?>, Byte> entry : PLAIN_CLASS_TO_FLAG.entrySet())
-            FLAG_TO_CLASS.put(entry.getValue(), entry.getKey());
-
-        PLAIN_CLASS_TO_FLAG.put(byte.class, GridPortableMarshaller.BYTE);
-        PLAIN_CLASS_TO_FLAG.put(short.class, GridPortableMarshaller.SHORT);
-        PLAIN_CLASS_TO_FLAG.put(int.class, GridPortableMarshaller.INT);
-        PLAIN_CLASS_TO_FLAG.put(long.class, GridPortableMarshaller.LONG);
-        PLAIN_CLASS_TO_FLAG.put(float.class, GridPortableMarshaller.FLOAT);
-        PLAIN_CLASS_TO_FLAG.put(double.class, GridPortableMarshaller.DOUBLE);
-        PLAIN_CLASS_TO_FLAG.put(char.class, GridPortableMarshaller.CHAR);
-        PLAIN_CLASS_TO_FLAG.put(boolean.class, GridPortableMarshaller.BOOLEAN);
-
-        for (byte b : new byte[] {
-            BYTE, SHORT, INT, LONG, FLOAT, DOUBLE,
-            CHAR, BOOLEAN, DECIMAL, STRING, UUID, DATE, TIMESTAMP,
-            BYTE_ARR, SHORT_ARR, INT_ARR, LONG_ARR, FLOAT_ARR, DOUBLE_ARR,
-            CHAR_ARR, BOOLEAN_ARR, DECIMAL_ARR, STRING_ARR, UUID_ARR, DATE_ARR, TIMESTAMP_ARR,
-            ENUM, ENUM_ARR, NULL}) {
-
-            PLAIN_TYPE_FLAG[b] = true;
-        }
-
-        PORTABLE_CLS.add(Byte.class);
-        PORTABLE_CLS.add(Short.class);
-        PORTABLE_CLS.add(Integer.class);
-        PORTABLE_CLS.add(Long.class);
-        PORTABLE_CLS.add(Float.class);
-        PORTABLE_CLS.add(Double.class);
-        PORTABLE_CLS.add(Character.class);
-        PORTABLE_CLS.add(Boolean.class);
-        PORTABLE_CLS.add(String.class);
-        PORTABLE_CLS.add(UUID.class);
-        PORTABLE_CLS.add(Date.class);
-        PORTABLE_CLS.add(Timestamp.class);
-        PORTABLE_CLS.add(BigDecimal.class);
-        PORTABLE_CLS.add(byte[].class);
-        PORTABLE_CLS.add(short[].class);
-        PORTABLE_CLS.add(int[].class);
-        PORTABLE_CLS.add(long[].class);
-        PORTABLE_CLS.add(float[].class);
-        PORTABLE_CLS.add(double[].class);
-        PORTABLE_CLS.add(char[].class);
-        PORTABLE_CLS.add(boolean[].class);
-        PORTABLE_CLS.add(String[].class);
-        PORTABLE_CLS.add(UUID[].class);
-        PORTABLE_CLS.add(Date[].class);
-        PORTABLE_CLS.add(Timestamp[].class);
-        PORTABLE_CLS.add(BigDecimal[].class);
-
-        FIELD_TYPE_NAMES = new String[104];
-
-        FIELD_TYPE_NAMES[BYTE] = "byte";
-        FIELD_TYPE_NAMES[SHORT] = "short";
-        FIELD_TYPE_NAMES[INT] = "int";
-        FIELD_TYPE_NAMES[LONG] = "long";
-        FIELD_TYPE_NAMES[BOOLEAN] = "boolean";
-        FIELD_TYPE_NAMES[FLOAT] = "float";
-        FIELD_TYPE_NAMES[DOUBLE] = "double";
-        FIELD_TYPE_NAMES[CHAR] = "char";
-        FIELD_TYPE_NAMES[UUID] = "UUID";
-        FIELD_TYPE_NAMES[DECIMAL] = "decimal";
-        FIELD_TYPE_NAMES[STRING] = "String";
-        FIELD_TYPE_NAMES[DATE] = "Date";
-        FIELD_TYPE_NAMES[TIMESTAMP] = "Timestamp";
-        FIELD_TYPE_NAMES[ENUM] = "Enum";
-        FIELD_TYPE_NAMES[OBJ] = "Object";
-        FIELD_TYPE_NAMES[PORTABLE_OBJ] = "Object";
-        FIELD_TYPE_NAMES[COL] = "Collection";
-        FIELD_TYPE_NAMES[MAP] = "Map";
-        FIELD_TYPE_NAMES[CLASS] = "Class";
-        FIELD_TYPE_NAMES[BYTE_ARR] = "byte[]";
-        FIELD_TYPE_NAMES[SHORT_ARR] = "short[]";
-        FIELD_TYPE_NAMES[INT_ARR] = "int[]";
-        FIELD_TYPE_NAMES[LONG_ARR] = "long[]";
-        FIELD_TYPE_NAMES[BOOLEAN_ARR] = "boolean[]";
-        FIELD_TYPE_NAMES[FLOAT_ARR] = "float[]";
-        FIELD_TYPE_NAMES[DOUBLE_ARR] = "double[]";
-        FIELD_TYPE_NAMES[CHAR_ARR] = "char[]";
-        FIELD_TYPE_NAMES[UUID_ARR] = "UUID[]";
-        FIELD_TYPE_NAMES[DECIMAL_ARR] = "decimal[]";
-        FIELD_TYPE_NAMES[STRING_ARR] = "String[]";
-        FIELD_TYPE_NAMES[DATE_ARR] = "Date[]";
-        FIELD_TYPE_NAMES[TIMESTAMP_ARR] = "Timestamp[]";
-        FIELD_TYPE_NAMES[OBJ_ARR] = "Object[]";
-        FIELD_TYPE_NAMES[ENUM_ARR] = "Enum[]";
-    }
-
-    /**
-     * Check if user type flag is set.
-     *
-     * @param flags Flags.
-     * @return {@code True} if set.
-     */
-    public static boolean isUserType(short flags) {
-        return isFlagSet(flags, FLAG_USR_TYP);
-    }
-
-    /**
-     * Check if raw-only flag is set.
-     *
-     * @param flags Flags.
-     * @return {@code True} if set.
-     */
-    public static boolean hasSchema(short flags) {
-        return isFlagSet(flags, FLAG_HAS_SCHEMA);
-    }
-
-    /**
-     * Check if raw-only flag is set.
-     *
-     * @param flags Flags.
-     * @return {@code True} if set.
-     */
-    public static boolean hasRaw(short flags) {
-        return isFlagSet(flags, FLAG_HAS_RAW);
-    }
-
-    /**
-     * Check if "no-field-ids" flag is set.
-     *
-     * @param flags Flags.
-     * @return {@code True} if set.
-     */
-    public static boolean isCompactFooter(short flags) {
-        return isFlagSet(flags, FLAG_COMPACT_FOOTER);
-    }
-
-    /**
-     * Check whether particular flag is set.
-     *
-     * @param flags Flags.
-     * @param flag Flag.
-     * @return {@code True} if flag is set in flags.
-     */
-    private static boolean isFlagSet(short flags, short flag) {
-        return (flags & flag) == flag;
-    }
-    
-    /**
-     * Schema initial ID.
-     *
-     * @return ID.
-     */
-    public static int schemaInitialId() {
-        return FNV1_OFFSET_BASIS;
-    }
-
-    /**
-     * Update schema ID when new field is added.
-     *
-     * @param schemaId Current schema ID.
-     * @param fieldId Field ID.
-     * @return New schema ID.
-     */
-    public static int updateSchemaId(int schemaId, int fieldId) {
-        schemaId = schemaId ^ (fieldId & 0xFF);
-        schemaId = schemaId * FNV1_PRIME;
-        schemaId = schemaId ^ ((fieldId >> 8) & 0xFF);
-        schemaId = schemaId * FNV1_PRIME;
-        schemaId = schemaId ^ ((fieldId >> 16) & 0xFF);
-        schemaId = schemaId * FNV1_PRIME;
-        schemaId = schemaId ^ ((fieldId >> 24) & 0xFF);
-        schemaId = schemaId * FNV1_PRIME;
-
-        return schemaId;
-    }
-
-    /**
-     * @param typeName Field type name.
-     * @return Field type ID;
-     */
-    @SuppressWarnings("StringEquality")
-    public static int fieldTypeId(String typeName) {
-        for (int i = 0; i < FIELD_TYPE_NAMES.length; i++) {
-            String typeName0 = FIELD_TYPE_NAMES[i];
-
-            if (typeName.equals(typeName0))
-                return i;
-        }
-
-        throw new IllegalArgumentException("Invalid metadata type name: " + typeName);
-    }
-
-    /**
-     * @param typeId Field type ID.
-     * @return Field type name.
-     */
-    public static String fieldTypeName(int typeId) {
-        assert typeId >= 0 && typeId < FIELD_TYPE_NAMES.length : typeId;
-
-        String typeName = FIELD_TYPE_NAMES[typeId];
-
-        assert typeName != null : typeId;
-
-        return typeName;
-    }
-
-    /**
-     * Write value with flag. e.g. writePlainObject(writer, (byte)77) will write two byte: {BYTE, 77}.
-     *
-     * @param writer W
-     * @param val Value.
-     */
-    public static void writePlainObject(BinaryWriterExImpl writer, Object val) {
-        Byte flag = PLAIN_CLASS_TO_FLAG.get(val.getClass());
-
-        if (flag == null)
-            throw new IllegalArgumentException("Can't write object with type: " + val.getClass());
-
-        switch (flag) {
-            case BYTE:
-                writer.writeByte(flag);
-                writer.writeByte((Byte)val);
-
-                break;
-
-            case SHORT:
-                writer.writeByte(flag);
-                writer.writeShort((Short)val);
-
-                break;
-
-            case INT:
-                writer.writeByte(flag);
-                writer.writeInt((Integer)val);
-
-                break;
-
-            case LONG:
-                writer.writeByte(flag);
-                writer.writeLong((Long)val);
-
-                break;
-
-            case FLOAT:
-                writer.writeByte(flag);
-                writer.writeFloat((Float)val);
-
-                break;
-
-            case DOUBLE:
-                writer.writeByte(flag);
-                writer.writeDouble((Double)val);
-
-                break;
-
-            case CHAR:
-                writer.writeByte(flag);
-                writer.writeChar((Character)val);
-
-                break;
-
-            case BOOLEAN:
-                writer.writeByte(flag);
-                writer.writeBoolean((Boolean)val);
-
-                break;
-
-            case DECIMAL:
-                writer.doWriteDecimal((BigDecimal)val);
-
-                break;
-
-            case STRING:
-                writer.doWriteString((String)val);
-
-                break;
-
-            case UUID:
-                writer.doWriteUuid((UUID)val);
-
-                break;
-
-            case DATE:
-                writer.doWriteDate((Date)val);
-
-                break;
-
-            case TIMESTAMP:
-                writer.doWriteTimestamp((Timestamp) val);
-
-                break;
-
-            case BYTE_ARR:
-                writer.doWriteByteArray((byte[])val);
-
-                break;
-
-            case SHORT_ARR:
-                writer.doWriteShortArray((short[])val);
-
-                break;
-
-            case INT_ARR:
-                writer.doWriteIntArray((int[])val);
-
-                break;
-
-            case LONG_ARR:
-                writer.doWriteLongArray((long[])val);
-
-                break;
-
-            case FLOAT_ARR:
-                writer.doWriteFloatArray((float[])val);
-
-                break;
-
-            case DOUBLE_ARR:
-                writer.doWriteDoubleArray((double[])val);
-
-                break;
-
-            case CHAR_ARR:
-                writer.doWriteCharArray((char[])val);
-
-                break;
-
-            case BOOLEAN_ARR:
-                writer.doWriteBooleanArray((boolean[])val);
-
-                break;
-
-            case DECIMAL_ARR:
-                writer.doWriteDecimalArray((BigDecimal[])val);
-
-                break;
-
-            case STRING_ARR:
-                writer.doWriteStringArray((String[])val);
-
-                break;
-
-            case UUID_ARR:
-                writer.doWriteUuidArray((UUID[])val);
-
-                break;
-
-            case DATE_ARR:
-                writer.doWriteDateArray((Date[])val);
-
-                break;
-
-            case TIMESTAMP_ARR:
-                writer.doWriteTimestampArray((Timestamp[])val);
-
-                break;
-
-            default:
-                throw new IllegalArgumentException("Can't write object with type: " + val.getClass());
-        }
-    }
-
-    /**
-     * @param obj Value to unwrap.
-     * @return Unwrapped value.
-     */
-    public static Object unwrapLazy(@Nullable Object obj) {
-        if (obj instanceof PortableLazyValue)
-            return ((PortableLazyValue)obj).value();
-
-        return obj;
-    }
-
-    /**
-     * @param delegate Iterator to delegate.
-     * @return New iterator.
-     */
-    public static Iterator<Object> unwrapLazyIterator(final Iterator<Object> delegate) {
-        return new Iterator<Object>() {
-            @Override public boolean hasNext() {
-                return delegate.hasNext();
-            }
-
-            @Override public Object next() {
-                return unwrapLazy(delegate.next());
-            }
-
-            @Override public void remove() {
-                delegate.remove();
-            }
-        };
-    }
-
-    /**
-     * @return {@code true} if content of serialized value cannot contain references to other object.
-     */
-    public static boolean isPlainType(int type) {
-        return type > 0 && type < PLAIN_TYPE_FLAG.length && PLAIN_TYPE_FLAG[type];
-    }
-
-    /**
-     * Checks whether an array type values can or can not contain references to other object.
-     *
-     * @param type Array type.
-     * @return {@code true} if content of serialized array value cannot contain references to other object.
-     */
-    public static boolean isPlainArrayType(int type) {
-        return (type >= BYTE_ARR && type <= DATE_ARR) || type == TIMESTAMP_ARR;
-    }
-
-    /**
-     * @param cls Class.
-     * @return Portable field type.
-     */
-    public static byte typeByClass(Class<?> cls) {
-        Byte type = PLAIN_CLASS_TO_FLAG.get(cls);
-
-        if (type != null)
-            return type;
-
-        if (cls.isEnum())
-            return ENUM;
-
-        if (cls.isArray())
-            return cls.getComponentType().isEnum() || cls.getComponentType() == Enum.class ? ENUM_ARR : OBJ_ARR;
-
-        if (isSpecialCollection(cls))
-            return COL;
-
-        if (isSpecialMap(cls))
-            return MAP;
-
-        return OBJ;
-    }
-
-    /**
-     * Tells whether provided type is portable.
-     *
-     * @param cls Class to check.
-     * @return Whether type is portable.
-     */
-    public static boolean isPortableType(Class<?> cls) {
-        assert cls != null;
-
-        return BinaryObject.class.isAssignableFrom(cls) ||
-            PORTABLE_CLS.contains(cls) ||
-            cls.isEnum() ||
-            (cls.isArray() && cls.getComponentType().isEnum());
-    }
-
-    /**
-     * Attempts to create a new map of the same type as {@code map} has. Otherwise returns new {@code HashMap} instance.
-     *
-     * @param map Original map.
-     * @return New map.
-     */
-    public static <K, V> Map<K, V> newMap(Map<K, V> map) {
-        if (map instanceof LinkedHashMap)
-            return U.newLinkedHashMap(map.size());
-        else if (map instanceof TreeMap)
-            return new TreeMap<>(((TreeMap<Object, Object>)map).comparator());
-        else if (map instanceof ConcurrentHashMap8)
-            return new ConcurrentHashMap8<>(U.capacity(map.size()));
-        else if (map instanceof ConcurrentHashMap)
-            return new ConcurrentHashMap<>(U.capacity(map.size()));
-
-        return U.newHashMap(map.size());
-    }
-
-    /**
-     * Attempts to create a new set of the same type as {@code set} has. Otherwise returns new {@code HashSet} instance.
-     *
-     * @param set Original set.
-     * @return New set.
-     */
-    public static <V> Set<V> newSet(Set<V> set) {
-        if (set instanceof LinkedHashSet)
-            return U.newLinkedHashSet(set.size());
-        else if (set instanceof TreeSet)
-            return new TreeSet<>(((TreeSet<Object>)set).comparator());
-        else if (set instanceof ConcurrentSkipListSet)
-            return new ConcurrentSkipListSet<>(((ConcurrentSkipListSet<Object>)set).comparator());
-
-        return U.newHashSet(set.size());
-    }
-
-    /**
-     * Check protocol version.
-     *
-     * @param protoVer Protocol version.
-     */
-    public static void checkProtocolVersion(byte protoVer) {
-        if (PROTO_VER != protoVer)
-            throw new BinaryObjectException("Unsupported protocol version: " + protoVer);
-    }
-
-    /**
-     * Get portable object length.
-     *
-     * @param in Input stream.
-     * @param start Start position.
-     * @return Length.
-     */
-    public static int length(PortablePositionReadable in, int start) {
-        return in.readIntPositioned(start + GridPortableMarshaller.TOTAL_LEN_POS);
-    }
-
-    /**
-     * Get footer start of the object.
-     *
-     * @param in Input stream.
-     * @param start Object start position inside the stream.
-     * @return Footer start.
-     */
-    public static int footerStartRelative(PortablePositionReadable in, int start) {
-        short flags = in.readShortPositioned(start + GridPortableMarshaller.FLAGS_POS);
-
-        if (hasSchema(flags))
-            // Schema exists, use offset.
-            return in.readIntPositioned(start + GridPortableMarshaller.SCHEMA_OR_RAW_OFF_POS);
-        else
-            // No schema, footer start equals to object end.
-            return length(in, start);
-    }
-
-    /**
-     * Get object's footer.
-     *
-     * @param in Input stream.
-     * @param start Start position.
-     * @return Footer start.
-     */
-    public static int footerStartAbsolute(PortablePositionReadable in, int start) {
-        return footerStartRelative(in, start) + start;
-    }
-
-    /**
-     * Get object's footer.
-     *
-     * @param in Input stream.
-     * @param start Start position.
-     * @return Footer.
-     */
-    public static IgniteBiTuple<Integer, Integer> footerAbsolute(PortablePositionReadable in, int start) {
-        short flags = in.readShortPositioned(start + GridPortableMarshaller.FLAGS_POS);
-
-        int footerEnd = length(in, start);
-
-        if (hasSchema(flags)) {
-            // Schema exists.
-            int footerStart = in.readIntPositioned(start + GridPortableMarshaller.SCHEMA_OR_RAW_OFF_POS);
-
-            if (hasRaw(flags))
-                footerEnd -= 4;
-
-            assert footerStart <= footerEnd;
-
-            return F.t(start + footerStart, start + footerEnd);
-        }
-        else
-            // No schema.
-            return F.t(start + footerEnd, start + footerEnd);
-    }
-
-    /**
-     * Get relative raw offset of the object.
-     *
-     * @param in Input stream.
-     * @param start Object start position inside the stream.
-     * @return Raw offset.
-     */
-    public static int rawOffsetRelative(PortablePositionReadable in, int start) {
-        short flags = in.readShortPositioned(start + GridPortableMarshaller.FLAGS_POS);
-
-        int len = length(in, start);
-
-        if (hasSchema(flags)){
-            // Schema exists.
-            if (hasRaw(flags))
-                // Raw offset is set, it is at the very end of the object.
-                return in.readIntPositioned(start + len - 4);
-            else
-                // Raw offset is not set, so just return schema offset.
-                return in.readIntPositioned(start + GridPortableMarshaller.SCHEMA_OR_RAW_OFF_POS);
-        }
-        else
-            // No schema, raw offset is located on schema offset position.
-            return in.readIntPositioned(start + GridPortableMarshaller.SCHEMA_OR_RAW_OFF_POS);
-    }
-
-    /**
-     * Get absolute raw offset of the object.
-     *
-     * @param in Input stream.
-     * @param start Object start position inside the stream.
-     * @return Raw offset.
-     */
-    public static int rawOffsetAbsolute(PortablePositionReadable in, int start) {
-        return start + rawOffsetRelative(in, start);
-    }
-
-    /**
-     * Get offset length for the given flags.
-     *
-     * @param flags Flags.
-     * @return Offset size.
-     */
-    public static int fieldOffsetLength(short flags) {
-        if ((flags & FLAG_OFFSET_ONE_BYTE) == FLAG_OFFSET_ONE_BYTE)
-            return OFFSET_1;
-        else if ((flags & FLAG_OFFSET_TWO_BYTES) == FLAG_OFFSET_TWO_BYTES)
-            return OFFSET_2;
-        else
-            return OFFSET_4;
-    }
-
-    /**
-     * Get field ID length.
-     *
-     * @param flags Flags.
-     * @return Field ID length.
-     */
-    public static int fieldIdLength(short flags) {
-        return isCompactFooter(flags) ? 0 : FIELD_ID_LEN;
-    }
-
-    /**
-     * Get relative field offset.
-     *
-     * @param stream Stream.
-     * @param pos Position.
-     * @param fieldOffsetSize Field offset size.
-     * @return Relative field offset.
-     */
-    public static int fieldOffsetRelative(PortablePositionReadable stream, int pos, int fieldOffsetSize) {
-        int res;
-
-        if (fieldOffsetSize == OFFSET_1)
-            res = (int)stream.readBytePositioned(pos) & 0xFF;
-        else if (fieldOffsetSize == OFFSET_2)
-            res = (int)stream.readShortPositioned(pos) & 0xFFFF;
-        else
-            res = stream.readIntPositioned(pos);
-
-        return res;
-    }
-
-    /**
-     * Merge old and new metas.
-     *
-     * @param oldMeta Old meta.
-     * @param newMeta New meta.
-     * @return New meta if old meta was null, old meta if no changes detected, merged meta otherwise.
-     * @throws BinaryObjectException If merge failed due to metadata conflict.
-     */
-    public static BinaryMetadata mergeMetadata(@Nullable BinaryMetadata oldMeta, BinaryMetadata newMeta) {
-        assert newMeta != null;
-
-        if (oldMeta == null)
-            return newMeta;
-        else {
-            assert oldMeta.typeId() == newMeta.typeId();
-
-            // Check type name.
-            if (!F.eq(oldMeta.typeName(), newMeta.typeName())) {
-                throw new BinaryObjectException(
-                    "Two portable types have duplicate type ID [" + "typeId=" + oldMeta.typeId() +
-                        ", typeName1=" + oldMeta.typeName() + ", typeName2=" + newMeta.typeName() + ']'
-                );
-            }
-
-            // Check affinity field names.
-            if (!F.eq(oldMeta.affinityKeyFieldName(), newMeta.affinityKeyFieldName())) {
-                throw new BinaryObjectException(
-                    "Binary type has different affinity key fields [" + "typeName=" + newMeta.typeName() +
-                        ", affKeyFieldName1=" + oldMeta.affinityKeyFieldName() +
-                        ", affKeyFieldName2=" + newMeta.affinityKeyFieldName() + ']'
-                );
-            }
-
-            // Check enum flag.
-            if (oldMeta.isEnum() != newMeta.isEnum()) {
-                if (oldMeta.isEnum())
-                    throw new BinaryObjectException("Binary type already registered as enum: " +
-                        newMeta.typeName());
-                else
-                    throw new BinaryObjectException("Binary type already registered as non-enum: " +
-                        newMeta.typeName());
-            }
-
-            // Check and merge fields.
-            boolean changed = false;
-
-            Map<String, Integer> mergedFields = new HashMap<>(oldMeta.fieldsMap());
-            Map<String, Integer> newFields = newMeta.fieldsMap();
-
-            for (Map.Entry<String, Integer> newField : newFields.entrySet()) {
-                Integer oldFieldType = mergedFields.put(newField.getKey(), newField.getValue());
-
-                if (oldFieldType == null)
-                    changed = true;
-                else if (!F.eq(oldFieldType, newField.getValue())) {
-                    throw new BinaryObjectException(
-                        "Binary type has different field types [" + "typeName=" + oldMeta.typeName() +
-                            ", fieldName=" + newField.getKey() +
-                            ", fieldTypeName1=" + fieldTypeName(oldFieldType) +
-                            ", fieldTypeName2=" + fieldTypeName(newField.getValue()) + ']'
-                    );
-                }
-            }
-
-            // Check and merge schemas.
-            Collection<PortableSchema> mergedSchemas = new HashSet<>(oldMeta.schemas());
-
-            for (PortableSchema newSchema : newMeta.schemas()) {
-                if (mergedSchemas.add(newSchema))
-                    changed = true;
-            }
-
-            // Return either old meta if no changes detected, or new merged meta.
-            return changed ? new BinaryMetadata(oldMeta.typeId(), oldMeta.typeName(), mergedFields,
-                oldMeta.affinityKeyFieldName(), mergedSchemas, oldMeta.isEnum()) : oldMeta;
-        }
-    }
-
-    /**
-     * @param cls Class.
-     * @return Mode.
-     */
-    @SuppressWarnings("IfMayBeConditional")
-    public static BinaryWriteMode mode(Class<?> cls) {
-        assert cls != null;
-
-        /** Primitives. */
-        if (cls == byte.class)
-            return BinaryWriteMode.P_BYTE;
-        else if (cls == boolean.class)
-            return BinaryWriteMode.P_BOOLEAN;
-        else if (cls == short.class)
-            return BinaryWriteMode.P_SHORT;
-        else if (cls == char.class)
-            return BinaryWriteMode.P_CHAR;
-        else if (cls == int.class)
-            return BinaryWriteMode.P_INT;
-        else if (cls == long.class)
-            return BinaryWriteMode.P_LONG;
-        else if (cls == float.class)
-            return BinaryWriteMode.P_FLOAT;
-        else if (cls == double.class)
-            return BinaryWriteMode.P_DOUBLE;
-
-        /** Boxed primitives. */
-        else if (cls == Byte.class)
-            return BinaryWriteMode.BYTE;
-        else if (cls == Boolean.class)
-            return BinaryWriteMode.BOOLEAN;
-        else if (cls == Short.class)
-            return BinaryWriteMode.SHORT;
-        else if (cls == Character.class)
-            return BinaryWriteMode.CHAR;
-        else if (cls == Integer.class)
-            return BinaryWriteMode.INT;
-        else if (cls == Long.class)
-            return BinaryWriteMode.LONG;
-        else if (cls == Float.class)
-            return BinaryWriteMode.FLOAT;
-        else if (cls == Double.class)
-            return BinaryWriteMode.DOUBLE;
-
-        /** The rest types. */
-        else if (cls == BigDecimal.class)
-            return BinaryWriteMode.DECIMAL;
-        else if (cls == String.class)
-            return BinaryWriteMode.STRING;
-        else if (cls == UUID.class)
-            return BinaryWriteMode.UUID;
-        else if (cls == Date.class)
-            return BinaryWriteMode.DATE;
-        else if (cls == Timestamp.class)
-            return BinaryWriteMode.TIMESTAMP;
-        else if (cls == byte[].class)
-            return BinaryWriteMode.BYTE_ARR;
-        else if (cls == short[].class)
-            return BinaryWriteMode.SHORT_ARR;
-        else if (cls == int[].class)
-            return BinaryWriteMode.INT_ARR;
-        else if (cls == long[].class)
-            return BinaryWriteMode.LONG_ARR;
-        else if (cls == float[].class)
-            return BinaryWriteMode.FLOAT_ARR;
-        else if (cls == double[].class)
-            return BinaryWriteMode.DOUBLE_ARR;
-        else if (cls == char[].class)
-            return BinaryWriteMode.CHAR_ARR;
-        else if (cls == boolean[].class)
-            return BinaryWriteMode.BOOLEAN_ARR;
-        else if (cls == BigDecimal[].class)
-            return BinaryWriteMode.DECIMAL_ARR;
-        else if (cls == String[].class)
-            return BinaryWriteMode.STRING_ARR;
-        else if (cls == UUID[].class)
-            return BinaryWriteMode.UUID_ARR;
-        else if (cls == Date[].class)
-            return BinaryWriteMode.DATE_ARR;
-        else if (cls == Timestamp[].class)
-            return BinaryWriteMode.TIMESTAMP_ARR;
-        else if (cls.isArray())
-            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))
-            return BinaryWriteMode.PORTABLE;
-        else if (Externalizable.class.isAssignableFrom(cls))
-            return BinaryWriteMode.EXTERNALIZABLE;
-        else if (isSpecialCollection(cls))
-            return BinaryWriteMode.COL;
-        else if (isSpecialMap(cls))
-            return BinaryWriteMode.MAP;
-        else if (cls.isEnum())
-            return BinaryWriteMode.ENUM;
-        else if (cls == Class.class)
-            return BinaryWriteMode.CLASS;
-        else
-            return BinaryWriteMode.OBJECT;
-    }
-
-    /**
-     * 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) {
-        int len = in.readInt();
-
-        return in.readByteArray(len);
-    }
-
-    /**
-     * @return Value.
-     */
-    public static boolean[] doReadBooleanArray(PortableInputStream in) {
-        int len = in.readInt();
-
-        return in.readBooleanArray(len);
-    }
-
-    /**
-     * @return Value.
-     */
-    public static short[] doReadShortArray(PortableInputStream in) {
-        int len = in.readInt();
-
-        return in.readShortArray(len);
-    }
-
-    /**
-     * @return Value.
-     */
-    public static char[] doReadCharArray(PortableInputStream in) {
-        int len = in.readInt();
-
-        return in.readCharArray(len);
-    }
-
-    /**
-     * @return Value.
-     */
-    public static int[] doReadIntArray(PortableInputStream in) {
-        int len = in.readInt();
-
-        return in.readIntArray(len);
-    }
-
-    /**
-     * @return Value.
-     */
-    public static long[] doReadLongArray(PortableInputStream in) {
-        int len = in.readInt();
-
-        return in.readLongArray(len);
-    }
-
-    /**
-     * @return Value.
-     */
-    public static float[] doReadFloatArray(PortableInputStream in) {
-        int len = in.readInt();
-
-        return in.readFloatArray(len);
-    }
-
-    /**
-     * @return Value.
-     */
-    public static double[] doReadDoubleArray(PortableInputStream in) {
-        int len = in.readInt();
-
-        return in.readDoubleArray(len);
-    }
-
-    /**
-     * @return Value.
-     */
-    public static BigDecimal doReadDecimal(PortableInputStream in) {
-        int scale = in.readInt();
-        byte[] mag = doReadByteArray(in);
-
-        BigInteger intVal = new BigInteger(mag);
-
-        if (scale < 0) {
-            scale &= 0x7FFFFFFF;
-
-            intVal = intVal.negate();
-        }
-
-        return new BigDecimal(intVal, scale);
-    }
-
-    /**
-     * @return Value.
-     */
-    public static String doReadString(PortableInputStream in) {
-        if (!in.hasArray())
-            return new String(doReadByteArray(in), UTF_8);
-
-        int strLen = in.readInt();
-
-        int pos = in.position();
-
-        // String will copy necessary array part for us.
-        String res = new String(in.array(), pos, strLen, UTF_8);
-
-        in.position(pos + strLen);
-
-        return res;
-    }
-
-    /**
-     * @return Value.
-     */
-    public static UUID doReadUuid(PortableInputStream in) {
-        return new UUID(in.readLong(), in.readLong());
-    }
-
-    /**
-     * @return Value.
-     */
-    public static Date doReadDate(PortableInputStream in) {
-        long time = in.readLong();
-
-        return new Date(time);
-    }
-
-    /**
-     * @return Value.
-     */
-    public static Timestamp doReadTimestamp(PortableInputStream in) {
-        long time = in.readLong();
-        int nanos = in.readInt();
-
-        Timestamp ts = new Timestamp(time);
-
-        ts.setNanos(ts.getNanos() + nanos);
-
-        return ts;
-    }
-
-    /**
-     * @return Value.
-     * @throws BinaryObjectException In case of error.
-     */
-    public static BigDecimal[] doReadDecimalArray(PortableInputStream in) throws BinaryObjectException {
-        int len = in.readInt();
-
-        BigDecimal[] arr = new BigDecimal[len];
-
-        for (int i = 0; i < len; i++) {
-            byte flag = in.readByte();
-
-            if (flag == NULL)
-                arr[i] = null;
-            else {
-                if (flag != DECIMAL)
-                    throw new BinaryObjectException("Invalid flag value: " + flag);
-
-                arr[i] = doReadDecimal(in);
-            }
-        }
-
-        return arr;
-    }
-
-    /**
-     * @return Value.
-     * @throws BinaryObjectException In case of error.
-     */
-    public static String[] doReadStringArray(PortableInputStream in) throws BinaryObjectException {
-        int len = in.readInt();
-
-        String[] arr = new String[len];
-
-        for (int i = 0; i < len; i++) {
-            byte flag = in.readByte();
-
-            if (flag == NULL)
-                arr[i] = null;
-            else {
-                if (flag != STRING)
-                    throw new BinaryObjectException("Invalid flag value: " + flag);
-
-                arr[i] = doReadString(in);
-            }
-        }
-
-        return arr;
-    }
-
-    /**
-     * @return Value.
-     * @throws BinaryObjectException In case of error.
-     */
-    public static UUID[] doReadUuidArray(PortableInputStream in) throws BinaryObjectException {
-        int len = in.readInt();
-
-        UUID[] arr = new UUID[len];
-
-        for (int i = 0; i < len; i++) {
-            byte flag = in.readByte();
-
-            if (flag == NULL)
-                arr[i] = null;
-            else {
-                if (flag != UUID)
-                    throw new BinaryObjectException("Invalid flag value: " + flag);
-
-                arr[i] = doReadUuid(in);
-            }
-        }
-
-        return arr;
-    }
-
-    /**
-     * @return Value.
-     * @throws BinaryObjectException In case of error.
-     */
-    public static Date[] doReadDateArray(PortableInputStream in) throws BinaryObjectException {
-        int len = in.readInt();
-
-        Date[] arr = new Date[len];
-
-        for (int i = 0; i < len; i++) {
-            byte flag = in.readByte();
-
-            if (flag == NULL)
-                arr[i] = null;
-            else {
-                if (flag != DATE)
-                    throw new BinaryObjectException("Invalid flag value: " + flag);
-
-                arr[i] = doReadDate(in);
-            }
-        }
-
-        return arr;
-    }
-
-    /**
-     * @return Value.
-     * @throws BinaryObjectException In case of error.
-     */
-    public static Timestamp[] doReadTimestampArray(PortableInputStream in) throws BinaryObjectException {
-        int len = in.readInt();
-
-        Timestamp[] arr = new Timestamp[len];
-
-        for (int i = 0; i < len; i++) {
-            byte flag = in.readByte();
-
-            if (flag == NULL)
-                arr[i] = null;
-            else {
-                if (flag != TIMESTAMP)
-                    throw new BinaryObjectException("Invalid flag value: " + flag);
-
-                arr[i] = doReadTimestamp(in);
-            }
-        }
-
-        return arr;
-    }
-
-    /**
-     * @return Value.
-     */
-    public static BinaryObject doReadPortableObject(PortableInputStream in, PortableContext ctx) {
-        if (in.offheapPointer() > 0) {
-            int len = in.readInt();
-
-            int pos = in.position();
-
-            in.position(in.position() + len);
-
-            int start = in.readInt();
-
-            return new BinaryObjectOffheapImpl(ctx, in.offheapPointer() + pos, start, len);
-        }
-        else {
-            byte[] arr = doReadByteArray(in);
-            int start = in.readInt();
-
-            return new BinaryObjectImpl(ctx, arr, start);
-        }
-    }
-
-    /**
-     * @return Value.
-     */
-    public static Class doReadClass(PortableInputStream in, PortableContext ctx, ClassLoader ldr)
-        throws BinaryObjectException {
-        int typeId = in.readInt();
-
-        return doReadClass(in, ctx, ldr, typeId);
-    }
-
-    /**
-     * Read plain type.
-     *
-     * @param in Input stream.
-     * @return Plain type.
-     */
-    private static EnumType doReadEnumType(PortableInputStream in) {
-        int typeId = in.readInt();
-
-        if (typeId != UNREGISTERED_TYPE_ID)
-            return new EnumType(typeId, null);
-        else {
-            String clsName = doReadClassName(in);
-
-            return new EnumType(UNREGISTERED_TYPE_ID, clsName);
-        }
-    }
-
-    /**
-     * @param in Input stream.
-     * @return Class name.
-     */
-    private static String doReadClassName(PortableInputStream in) {
-        byte flag = in.readByte();
-
-        if (flag != STRING)
-            throw new BinaryObjectException("Failed to read class name [position=" + (in.position() - 1) + ']');
-
-        return doReadString(in);
-    }
-
-    /**
-     * @param typeId Type id.
-     * @return Value.
-     */
-    public static Class doReadClass(PortableInputStream in, PortableContext ctx, ClassLoader ldr, int typeId)
-        throws BinaryObjectException {
-        Class cls;
-
-        if (typeId == OBJECT_TYPE_ID)
-            return Object.class;
-
-        if (typeId != UNREGISTERED_TYPE_ID)
-            cls = ctx.descriptorForTypeId(true, typeId, ldr, false).describedClass();
-        else {
-            String clsName = doReadClassName(in);
-
-            try {
-                cls = U.forName(clsName, ldr);
-            }
-            catch (ClassNotFoundException e) {
-                throw new BinaryInvalidTypeException("Failed to load the class: " + clsName, e);
-            }
-
-            // forces registering of class by type id, at least locally
-            ctx.descriptorForClass(cls, true);
-        }
-
-        return cls;
-    }
-
-    /**
-     * Resolve the class.
-     *
-     * @param ctx Portable context.
-     * @param typeId Type ID.
-     * @param clsName Class name.
-     * @param ldr Class loaded.
-     * @return Resovled class.
-     */
-    public static Class resolveClass(PortableContext ctx, int typeId, @Nullable String clsName,
-        @Nullable ClassLoader ldr, boolean deserialize) {
-        Class cls;
-
-        if (typeId == OBJECT_TYPE_ID)
-            return Object.class;
-
-        if (typeId != UNREGISTERED_TYPE_ID)
-            cls = ctx.descriptorForTypeId(true, typeId, ldr, deserialize).describedClass();
-        else {
-            try {
-                cls = U.forName(clsName, ldr);
-            }
-            catch (ClassNotFoundException e) {
-                throw new BinaryInvalidTypeException("Failed to load the class: " + clsName, e);
-            }
-
-            // forces registering of class by type id, at least locally
-            ctx.descriptorForClass(cls, true);
-        }
-
-        return cls;
-    }
-
-    /**
-     * Read portable enum.
-     *
-     * @param in Input stream.
-     * @param ctx Portable context.
-     * @param type Plain type.
-     * @return Enum.
-     */
-    private static BinaryEnumObjectImpl doReadPortableEnum(PortableInputStream in, PortableContext ctx,
-        EnumType type) {
-        return new BinaryEnumObjectImpl(ctx, type.typeId, type.clsName, in.readInt());
-    }
-
-    /**
-     * Read portable enum array.
-     *
-     * @param in Input stream.
-     * @param ctx Portable context.
-     * @return Enum array.
-     */
-    private static Object[] doReadPortableEnumArray(PortableInputStream in, PortableContext ctx) {
-        int len = in.readInt();
-
-        Object[] arr = (Object[]) Array.newInstance(BinaryObject.class, len);
-
-        for (int i = 0; i < len; i++) {
-            byte flag = in.readByte();
-
-            if (flag == NULL)
-                arr[i] = null;
-            else
-                arr[i] = doReadPortableEnum(in, ctx, doReadEnumType(in));
-        }
-
-        return arr;
-    }
-
-    /**
-     * Having target class in place we simply read ordinal and create final representation.
-     *
-     * @param cls Enum class.
-     * @return Value.
-     */
-    public static Enum<?> doReadEnum(PortableInputStream in, Class<?> cls) throws BinaryObjectException {
-        assert cls != null;
-
-        if (!cls.isEnum())
-            throw new BinaryObjectException("Class does not represent enum type: " + cls.getName());
-
-        int ord = in.readInt();
-
-        return BinaryEnumCache.get(cls, ord);
-    }
-
-    /**
-     * @param cls Enum class.
-     * @return Value.
-     */
-    public static Object[] doReadEnumArray(PortableInputStream in, PortableContext ctx, ClassLoader ldr, Class<?> cls)
-        throws BinaryObjectException {
-        int len = in.readInt();
-
-        Object[] arr = (Object[]) Array.newInstance(cls, len);
-
-        for (int i = 0; i < len; i++) {
-            byte flag = in.readByte();
-
-            if (flag == NULL)
-                arr[i] = null;
-            else
-                arr[i] = doReadEnum(in, doReadClass(in, ctx, ldr));
-        }
-
-        return arr;
-    }
-
-    /**
-     * Read object serialized using optimized marshaller.
-     *
-     * @return Result.
-     */
-    public static Object doReadOptimized(PortableInputStream in, PortableContext ctx, @Nullable ClassLoader clsLdr) {
-        int len = in.readInt();
-
-        ByteArrayInputStream input = new ByteArrayInputStream(in.array(), in.position(), len);
-
-        try {
-            return ctx.optimizedMarsh().unmarshal(input, clsLdr);
-        }
-        catch (IgniteCheckedException e) {
-            throw new BinaryObjectException("Failed to unmarshal object with optimized marshaller", e);
-        }
-        finally {
-            in.position(in.position() + len);
-        }
-    }
-
-    /**
-     * @return Object.
-     * @throws BinaryObjectException In case of error.
-     */
-    @Nullable public static Object doReadObject(PortableInputStream in, PortableContext ctx, ClassLoader ldr,
-        BinaryReaderHandlesHolder handles) throws BinaryObjectException {
-        return new BinaryReaderExImpl(ctx, in, ldr, handles.handles()).deserialize();
-    }
-
-    /**
-     * @return Unmarshalled value.
-     * @throws BinaryObjectException In case of error.
-     */
-    @Nullable public static Object unmarshal(PortableInputStream in, PortableContext ctx, ClassLoader ldr)
-        throws BinaryObjectException {
-        return unmarshal(in, ctx, ldr, new BinaryReaderHandlesHolderImpl());
-    }
-
-    /**
-     * @return Unmarshalled value.
-     * @throws BinaryObjectException In case of error.
-     */
-    @Nullable public static Object unmarshal(PortableInputStream in, PortableContext ctx, ClassLoader ldr,
-        BinaryReaderHandlesHolder handles) throws BinaryObjectException {
-        return unmarshal(in, ctx, ldr, handles, false);
-    }
-
-    /**
-     * @return Unmarshalled value.
-     * @throws BinaryObjectException In case of error.
-     */
-    @Nullable public static Object unmarshal(PortableInputStream in, PortableContext ctx, ClassLoader ldr,
-        BinaryReaderHandlesHolder handles, boolean detach) throws BinaryObjectException {
-        int start = in.position();
-
-        byte flag = in.readByte();
-
-        switch (flag) {
-            case NULL:
-                return null;
-
-            case HANDLE: {
-                int handlePos = start - in.readInt();
-
-                Object obj = handles.getHandle(handlePos);
-
-                if (obj == null) {
-                    int retPos = in.position();
-
-                    in.position(handlePos);
-
-                    obj = unmarshal(in, ctx, ldr, handles);
-
-                    in.position(retPos);
-                }
-
-                return obj;
-            }
-
-            case OBJ: {
-                checkProtocolVersion(in.readByte());
-
-                int len = length(in, start);
-
-                BinaryObjectExImpl po;
-
-                if (detach) {
-                    // In detach mode we simply copy object's content.
-                    in.position(start);
-
-                    po = new BinaryObjectImpl(ctx, in.readByteArray(len), 0);
-                }
-                else {
-                    if (in.offheapPointer() == 0)
-                        po = new BinaryObjectImpl(ctx, in.array(), start);
-                    else
-                        po = new BinaryObjectOffheapImpl(ctx, in.offheapPointer(), start,
-                            in.remaining() + in.position());
-
-                    in.position(start + po.length());
-                }
-
-                handles.setHandle(po, start);
-
-                return po;
-            }
-
-            case BYTE:
-                return in.readByte();
-
-            case SHORT:
-                return in.readShort();
-
-            case INT:
-                return in.readInt();
-
-            case LONG:
-                return in.readLong();
-
-            case FLOAT:
-                return in.readFloat();
-
-            case DOUBLE:
-                return in.readDouble();
-
-            case CHAR:
-                return in.readChar();
-
-            case BOOLEAN:
-                return in.readBoolean();
-
-            case DECIMAL:
-                return doReadDecimal(in);
-
-            case STRING:
-                return doReadString(in);
-
-            case UUID:
-                return doReadUuid(in);
-
-            case DATE:
-                return doReadDate(in);
-
-            case TIMESTAMP:
-                return doReadTimestamp(in);
-
-            case BYTE_ARR:
-                return doReadByteArray(in);
-
-            case SHORT_ARR:
-                return doReadShortArray(in);
-
-            case INT_ARR:
-                return doReadIntArray(in);
-
-            case LONG_ARR:
-                return doReadLongArray(in);
-
-            case FLOAT_ARR:
-                return doReadFloatArray(in);
-
-            case DOUBLE_ARR:
-                return doReadDoubleArray(in);
-
-            case CHAR_ARR:
-                return doReadCharArray(in);
-
-            case BOOLEAN_ARR:
-                return doReadBooleanArray(in);
-
-            case DECIMAL_ARR:
-                return doReadDecimalArray(in);
-
-            case STRING_ARR:
-                return doReadStringArray(in);
-
-            case UUID_ARR:
-                return doReadUuidArray(in);
-
-            case DATE_ARR:
-                return doReadDateArray(in);
-
-            case TIMESTAMP_ARR:
-                return doReadTimestampArray(in);
-
-            case OBJ_ARR:
-                return doReadObjectArray(in, ctx, ldr, handles, false);
-
-            case COL:
-                return doReadCollection(in, ctx, ldr, handles, false, null);
-
-            case MAP:
-                return doReadMap(in, ctx, ldr, handles, false, null);
-
-            case PORTABLE_OBJ:
-                return doReadPortableObject(in, ctx);
-
-            case ENUM:
-                return doReadPortableEnum(in, ctx, doReadEnumType(in));
-
-            case ENUM_ARR:
-                doReadEnumType(in); // Simply skip this part as we do not need it.
-
-                return doReadPortableEnumArray(in, ctx);
-
-            case CLASS:
-                return doReadClass(in, ctx, ldr);
-
-            case OPTM_MARSH:
-                return doReadOptimized(in, ctx, ldr);
-
-            default:
-                throw new BinaryObjectException("Invalid flag value: " + flag);
-        }
-    }
-
-    /**
-     * @param deserialize Deep flag.
-     * @return Value.
-     * @throws BinaryObjectException In case of error.
-     */
-    public static Object[] doReadObjectArray(PortableInputStream in, PortableContext ctx, ClassLoader ldr,
-        BinaryReaderHandlesHolder handles, boolean deserialize) throws BinaryObjectException {
-        int hPos = positionForHandle(in);
-
-        Class compType = doReadClass(in, ctx, ldr);
-
-        int len = in.readInt();
-
-        Object[] arr = deserialize ? (Object[])Array.newInstance(compType, len) : new Object[len];
-
-        handles.setHandle(arr, hPos);
-
-        for (int i = 0; i < len; i++)
-            arr[i] = deserializeOrUnmarshal(in, ctx, ldr, handles, deserialize);
-
-        return arr;
-    }
-
-    /**
-     * @param deserialize Deep flag.
-     * @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, BinaryCollectionFactory factory)
-        throws BinaryObjectException {
-        int hPos = positionForHandle(in);
-
-        int size = in.readInt();
-
-        assert size >= 0;
-
-        byte colType = in.readByte();
-
-        Collection<Object> col;
-
-        if (factory != null)
-            col = factory.create(size);
-        else {
-            switch (colType) {
-                case ARR_LIST:
-                    col = new ArrayList<>(size);
-
-                    break;
-
-                case LINKED_LIST:
-                    col = new LinkedList<>();
-
-                    break;
-
-                case HASH_SET:
-                    col = U.newHashSet(size);
-
-                    break;
-
-                case LINKED_HASH_SET:
-                    col = U.newLinkedHashSet(size);
-
-                    break;
-
-                case USER_SET:
-                    col = U.newHashSet(size);
-
-                    break;
-
-                case USER_COL:
-                    col = new ArrayList<>(size);
-
-                    break;
-
-                default:
-                    throw new BinaryObjectException("Invalid collection type: " + colType);
-            }
-        }
-
-        handles.setHandle(col, hPos);
-
-        for (int i = 0; i < size; i++)
-            col.add(deserializeOrUnmarshal(in, ctx, ldr, handles, deserialize));
-
-        return col;
-    }
-
-    /**
-     * @param deserialize Deep flag.
-     * @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, BinaryMapFactory factory)
-        throws BinaryObjectException {
-        int hPos = positionForHandle(in);
-
-        int size = in.readInt();
-
-        assert size >= 0;
-
-        byte mapType = in.readByte();
-
-        Map<Object, Object> map;
-
-        if (factory != null)
-            map = factory.create(size);
-        else {
-            switch (mapType) {
-                case HASH_MAP:
-                    map = U.newHashMap(size);
-
-                    break;
-
-                case LINKED_HASH_MAP:
-                    map = U.newLinkedHashMap(size);
-
-                    break;
-
-                case USER_COL:
-                    map = U.newHashMap(size);
-
-                    break;
-
-                default:
-                    throw new BinaryObjectException("Invalid map type: " + mapType);
-            }
-        }
-
-        handles.setHandle(map, hPos);
-
-        for (int i = 0; i < size; i++) {
-            Object key = deserializeOrUnmarshal(in, ctx, ldr, handles, deserialize);
-            Object val = deserializeOrUnmarshal(in, ctx, ldr, handles, deserialize);
-
-            map.put(key, val);
-        }
-
-        return map;
-    }
-
-    /**
-     * Deserialize or unmarshal the object.
-     *
-     * @param deserialize Deserialize.
-     * @return Result.
-     */
-    private static Object deserializeOrUnmarshal(PortableInputStream in, PortableContext ctx, ClassLoader ldr,
-        BinaryReaderHandlesHolder handles, boolean deserialize) {
-        return deserialize ? doReadObject(in, ctx, ldr, handles) : unmarshal(in, ctx, ldr, handles);
-    }
-
-    /**
-     * Get position to be used for handle. We assume here that the hdr byte was read, hence subtract -1.
-     *
-     * @return Position for handle.
-     */
-    public static int positionForHandle(PortableInputStream in) {
-        return in.position() - 1;
-    }
-
-    /**
-     * Enum type.
-     */
-    private static class EnumType {
-        /** Type ID. */
-        private final int typeId;
-
-        /** Class name. */
-        private final String clsName;
-
-        /**
-         * Constructor.
-         *
-         * @param typeId Type ID.
-         * @param clsName Class name.
-         */
-        public EnumType(int typeId, @Nullable String clsName) {
-            assert typeId != UNREGISTERED_TYPE_ID && clsName == null ||
-                typeId == UNREGISTERED_TYPE_ID && clsName != null;
-
-            this.typeId = typeId;
-            this.clsName = clsName;
-        }
-    }
-}
\ No newline at end of file


[08/59] [abbrv] ignite git commit: ignite-2065: rename "portable" packages to "binary"

Posted by ak...@apache.org.
http://git-wip-us.apache.org/repos/asf/ignite/blob/1dbf20e0/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
deleted file mode 100644
index 9277a77..0000000
--- a/modules/core/src/test/java/org/apache/ignite/internal/portable/BinaryMarshallerSelfTest.java
+++ /dev/null
@@ -1,4210 +0,0 @@
-/*
- * 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.portable;
-
-import java.io.Externalizable;
-import java.io.IOException;
-import java.io.ObjectInput;
-import java.io.ObjectOutput;
-import java.io.Serializable;
-import java.lang.reflect.Field;
-import java.lang.reflect.InvocationHandler;
-import java.lang.reflect.InvocationTargetException;
-import java.lang.reflect.Method;
-import java.lang.reflect.Proxy;
-import java.math.BigDecimal;
-import java.math.BigInteger;
-import java.net.InetSocketAddress;
-import java.sql.Timestamp;
-import java.util.AbstractQueue;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.Date;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.LinkedHashMap;
-import java.util.LinkedHashSet;
-import java.util.List;
-import java.util.Map;
-import java.util.Objects;
-import java.util.Queue;
-import java.util.TreeMap;
-import java.util.TreeSet;
-import java.util.UUID;
-import java.util.concurrent.ConcurrentHashMap;
-import java.util.concurrent.ConcurrentSkipListSet;
-import junit.framework.Assert;
-import org.apache.ignite.IgniteCheckedException;
-import org.apache.ignite.binary.BinaryCollectionFactory;
-import org.apache.ignite.binary.BinaryIdMapper;
-import org.apache.ignite.binary.BinaryMapFactory;
-import org.apache.ignite.binary.BinaryObject;
-import org.apache.ignite.binary.BinaryObjectBuilder;
-import org.apache.ignite.binary.BinaryObjectException;
-import org.apache.ignite.binary.BinaryRawReader;
-import org.apache.ignite.binary.BinaryRawWriter;
-import org.apache.ignite.binary.BinaryReader;
-import org.apache.ignite.binary.BinarySerializer;
-import org.apache.ignite.binary.BinaryTypeConfiguration;
-import org.apache.ignite.binary.BinaryWriter;
-import org.apache.ignite.binary.Binarylizable;
-import org.apache.ignite.configuration.BinaryConfiguration;
-import org.apache.ignite.configuration.IgniteConfiguration;
-import org.apache.ignite.internal.portable.builder.BinaryObjectBuilderImpl;
-import org.apache.ignite.internal.processors.cache.CacheObjectContext;
-import org.apache.ignite.internal.util.GridUnsafe;
-import org.apache.ignite.internal.util.IgniteUtils;
-import org.apache.ignite.internal.util.lang.GridMapEntry;
-import org.apache.ignite.internal.util.typedef.F;
-import org.apache.ignite.internal.util.typedef.internal.S;
-import org.apache.ignite.internal.util.typedef.internal.U;
-import org.apache.ignite.marshaller.MarshallerContextTestImpl;
-import org.apache.ignite.marshaller.optimized.OptimizedMarshaller;
-import org.apache.ignite.testframework.GridTestUtils;
-import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
-import org.jetbrains.annotations.NotNull;
-import org.jetbrains.annotations.Nullable;
-import org.jsr166.ConcurrentHashMap8;
-import sun.misc.Unsafe;
-
-import static org.apache.ignite.internal.portable.streams.PortableMemoryAllocator.INSTANCE;
-import static org.junit.Assert.assertArrayEquals;
-import static org.junit.Assert.assertNotEquals;
-
-/**
- * Portable marshaller tests.
- */
-@SuppressWarnings({"OverlyStrongTypeCast", "ArrayHashCode", "ConstantConditions"})
-public class BinaryMarshallerSelfTest extends GridCommonAbstractTest {
-    /** */
-    private static final Unsafe UNSAFE = GridUnsafe.unsafe();
-
-    /** */
-    protected static final long BYTE_ARR_OFF = UNSAFE.arrayBaseOffset(byte[].class);
-
-    /**
-     * @throws Exception If failed.
-     */
-    public void testNull() throws Exception {
-        assertNull(marshalUnmarshal(null));
-    }
-
-    /**
-     * @throws Exception If failed.
-     */
-    public void testByte() throws Exception {
-        assertEquals((byte) 100, marshalUnmarshal((byte)100).byteValue());
-    }
-
-    /**
-     * @throws Exception If failed.
-     */
-    public void testShort() throws Exception {
-        assertEquals((short)100, marshalUnmarshal((short)100).shortValue());
-    }
-
-    /**
-     * @throws Exception If failed.
-     */
-    public void testInt() throws Exception {
-        assertEquals(100, marshalUnmarshal(100).intValue());
-    }
-
-    /**
-     * @throws Exception If failed.
-     */
-    public void testLong() throws Exception {
-        assertEquals(100L, marshalUnmarshal(100L).longValue());
-    }
-
-    /**
-     * @throws Exception If failed.
-     */
-    public void testFloat() throws Exception {
-        assertEquals(100.001f, marshalUnmarshal(100.001f), 0);
-    }
-
-    /**
-     * @throws Exception If failed.
-     */
-    public void testDouble() throws Exception {
-        assertEquals(100.001d, marshalUnmarshal(100.001d), 0);
-    }
-
-    /**
-     * @throws Exception If failed.
-     */
-    public void testChar() throws Exception {
-        assertEquals((char)100, marshalUnmarshal((char)100).charValue());
-    }
-
-    /**
-     * @throws Exception If failed.
-     */
-    public void testBoolean() throws Exception {
-        assertEquals(true, marshalUnmarshal(true).booleanValue());
-    }
-
-    /**
-     * @throws Exception If failed.
-     */
-    public void testDecimal() throws Exception {
-        BigDecimal val;
-
-        assertEquals((val = BigDecimal.ZERO), marshalUnmarshal(val));
-        assertEquals((val = BigDecimal.valueOf(Long.MAX_VALUE, 0)), marshalUnmarshal(val));
-        assertEquals((val = BigDecimal.valueOf(Long.MIN_VALUE, 0)), marshalUnmarshal(val));
-        assertEquals((val = BigDecimal.valueOf(Long.MAX_VALUE, 8)), marshalUnmarshal(val));
-        assertEquals((val = BigDecimal.valueOf(Long.MIN_VALUE, 8)), marshalUnmarshal(val));
-
-        assertEquals((val = new BigDecimal(new BigInteger("-79228162514264337593543950336"))), marshalUnmarshal(val));
-    }
-
-    /**
-     * @throws Exception If failed.
-     */
-    public void testString() throws Exception {
-        assertEquals("str", marshalUnmarshal("str"));
-    }
-
-    /**
-     * @throws Exception If failed.
-     */
-    public void testUuid() throws Exception {
-        UUID uuid = UUID.randomUUID();
-
-        assertEquals(uuid, marshalUnmarshal(uuid));
-    }
-
-    /**
-     * @throws Exception If failed.
-     */
-    public void testDate() throws Exception {
-        Date date = new Date();
-
-        Date val = marshalUnmarshal(date);
-
-        assertEquals(date, val);
-        assertEquals(Date.class, val.getClass());
-    }
-
-    /**
-     * @throws Exception If failed.
-     */
-    public void testTimestamp() throws Exception {
-        Timestamp ts = new Timestamp(System.currentTimeMillis());
-
-        ts.setNanos(999999999);
-
-        assertEquals(ts, marshalUnmarshal(ts));
-    }
-
-    /**
-     * @throws Exception If failed.
-     */
-    public void testByteArray() throws Exception {
-        byte[] arr = new byte[] {10, 20, 30};
-
-        assertArrayEquals(arr, marshalUnmarshal(arr));
-    }
-
-    /**
-     * @throws Exception If failed.
-     */
-    public void testShortArray() throws Exception {
-        short[] arr = new short[] {10, 20, 30};
-
-        assertArrayEquals(arr, marshalUnmarshal(arr));
-    }
-
-    /**
-     * @throws Exception If failed.
-     */
-    public void testIntArray() throws Exception {
-        int[] arr = new int[] {10, 20, 30};
-
-        assertArrayEquals(arr, marshalUnmarshal(arr));
-    }
-
-    /**
-     * @throws Exception If failed.
-     */
-    public void testLongArray() throws Exception {
-        long[] arr = new long[] {10, 20, 30};
-
-        assertArrayEquals(arr, marshalUnmarshal(arr));
-    }
-
-    /**
-     * @throws Exception If failed.
-     */
-    public void testFloatArray() throws Exception {
-        float[] arr = new float[] {10.1f, 20.1f, 30.1f};
-
-        assertArrayEquals(arr, marshalUnmarshal(arr), 0);
-    }
-
-    /**
-     * @throws Exception If failed.
-     */
-    public void testDoubleArray() throws Exception {
-        double[] arr = new double[] {10.1d, 20.1d, 30.1d};
-
-        assertArrayEquals(arr, marshalUnmarshal(arr), 0);
-    }
-
-    /**
-     * @throws Exception If failed.
-     */
-    public void testCharArray() throws Exception {
-        char[] arr = new char[] {10, 20, 30};
-
-        assertArrayEquals(arr, marshalUnmarshal(arr));
-    }
-
-    /**
-     * @throws Exception If failed.
-     */
-    public void testBooleanArray() throws Exception {
-        boolean[] arr = new boolean[] {true, false, true};
-
-        assertBooleanArrayEquals(arr, marshalUnmarshal(arr));
-    }
-
-    /**
-     * @throws Exception If failed.
-     */
-    public void testDecimalArray() throws Exception {
-        BigDecimal[] arr = new BigDecimal[] {BigDecimal.ZERO, BigDecimal.ONE, BigDecimal.TEN} ;
-
-        assertArrayEquals(arr, marshalUnmarshal(arr));
-    }
-
-    /**
-     * @throws Exception If failed.
-     */
-    public void testStringArray() throws Exception {
-        String[] arr = new String[] {"str1", "str2", "str3"};
-
-        assertArrayEquals(arr, marshalUnmarshal(arr));
-    }
-
-    /**
-     * @throws Exception If failed.
-     */
-    public void testUuidArray() throws Exception {
-        UUID[] arr = new UUID[] {UUID.randomUUID(), UUID.randomUUID(), UUID.randomUUID()};
-
-        assertArrayEquals(arr, marshalUnmarshal(arr));
-    }
-
-    /**
-     * @throws Exception If failed.
-     */
-    public void testDateArray() throws Exception {
-        Date[] arr = new Date[] {new Date(11111), new Date(22222), new Date(33333)};
-
-        assertArrayEquals(arr, marshalUnmarshal(arr));
-    }
-
-    /**
-     * @throws Exception If failed.
-     */
-    public void testObjectArray() throws Exception {
-        Object[] arr = new Object[] {1, 2, 3};
-
-        assertArrayEquals(arr, marshalUnmarshal(arr));
-    }
-
-    /**
-     * @throws Exception If failed.
-     */
-    public void testException() throws Exception {
-        Exception ex = new RuntimeException();
-
-        // Checks that Optimize marshaller will be used, because Throwable has writeObject method.
-        // Exception's stacktrace equals to zero-length array by default and generates at Throwable's writeObject method.
-        assertNotEquals(0, marshalUnmarshal(ex).getStackTrace().length);
-    }
-
-    /**
-     * @throws Exception If failed.
-     */
-    public void testCollection() throws Exception {
-        testCollection(new ArrayList<Integer>(3));
-        testCollection(new LinkedHashSet<Integer>());
-        testCollection(new HashSet<Integer>());
-        testCollection(new TreeSet<Integer>());
-        testCollection(new ConcurrentSkipListSet<Integer>());
-    }
-
-    /**
-     * @throws Exception If failed.
-     */
-    private void testCollection(Collection<Integer> col) throws Exception {
-        col.add(1);
-        col.add(2);
-        col.add(3);
-
-        assertEquals(col, marshalUnmarshal(col));
-    }
-
-    /**
-     * @throws Exception If failed.
-     */
-    public void testMap() throws Exception {
-        testMap(new HashMap<Integer, String>());
-        testMap(new LinkedHashMap<Integer, String>());
-        testMap(new TreeMap<Integer, String>());
-        testMap(new ConcurrentHashMap8<Integer, String>());
-        testMap(new ConcurrentHashMap<Integer, String>());
-    }
-
-    /**
-     * @throws Exception If failed.
-     */
-    private void testMap(Map<Integer, String> map) throws Exception {
-        map.put(1, "str1");
-        map.put(2, "str2");
-        map.put(3, "str3");
-
-        assertEquals(map, marshalUnmarshal(map));
-    }
-
-    /**
-     * Test serialization of custom collections.
-     *
-     * @throws Exception If failed.
-     */
-    @SuppressWarnings("unchecked")
-    public void testCustomCollections() throws Exception {
-        CustomCollections cc = new CustomCollections();
-
-        cc.list.add(1);
-        cc.customList.add(2);
-
-        CustomCollections copiedCc = marshalUnmarshal(cc);
-
-        assert copiedCc.customList.getClass().equals(CustomArrayList.class);
-
-        assertEquals(cc.list.size(), copiedCc.list.size());
-        assertEquals(cc.customList.size(), copiedCc.customList.size());
-
-        assertEquals(cc.list.get(0), copiedCc.list.get(0));
-        assertEquals(cc.customList.get(0), copiedCc.customList.get(0));
-    }
-
-    /**
-     * Test custom collections with factories.
-     *
-     * @throws Exception If failed.
-     */
-    @SuppressWarnings("unchecked")
-    public void testCustomCollectionsWithFactory() throws Exception {
-        CustomCollectionsWithFactory cc = new CustomCollectionsWithFactory();
-
-        cc.list.add(new DummyHolder(1));
-        cc.map.put(new DummyHolder(2), new DummyHolder(3));
-
-        CustomCollectionsWithFactory copiedCc = marshalUnmarshal(cc);
-
-        assertEquals(cc.list.size(), copiedCc.list.size());
-        assertEquals(cc.map.size(), copiedCc.map.size());
-
-        assertEquals(cc.list.get(0), copiedCc.list.get(0));
-        assertEquals(cc.map.get(new DummyHolder(2)), copiedCc.map.get(new DummyHolder(2)));
-    }
-
-    /**
-     * @throws Exception If failed.
-     */
-    public void testExternalizableHashCode() throws Exception {
-        SimpleExternalizable sim1 = new SimpleExternalizable("Simple");
-        SimpleExternalizable sim2 = new SimpleExternalizable("Simple");
-
-        BinaryMarshaller marsh = binaryMarshaller();
-
-        BinaryObjectImpl sim1Binary = marshal(sim1, marsh);
-        BinaryObjectImpl sim2Binary = marshal(sim2, marsh);
-
-        assertEquals(sim1.hashCode(), sim2.hashCode());
-        assertEquals(sim1.hashCode(), sim1Binary.hashCode());
-        assertEquals(sim2.hashCode(), sim2Binary.hashCode());
-    }
-
-    /**
-     * @throws Exception If failed.
-     */
-    public void testExternalizableInEnclosing() throws Exception {
-        SimpleEnclosingObject obj = new SimpleEnclosingObject();
-        obj.simpl = new SimpleExternalizable("field");
-
-        SimpleEnclosingObject other = marshalUnmarshal(obj);
-
-        assertEquals(((SimpleExternalizable)obj.simpl).field, ((SimpleExternalizable)other.simpl).field);
-    }
-
-    /**
-     * @throws Exception If failed.
-     */
-    public void testMapEntry() throws Exception {
-        Map.Entry<Integer, String> e = new GridMapEntry<>(1, "str1");
-
-        assertEquals(e, marshalUnmarshal(e));
-
-        Map<Integer, String> map = new HashMap<>(1);
-
-        map.put(2, "str2");
-
-        e = F.firstEntry(map);
-
-        Map.Entry<Integer, String> e0 = marshalUnmarshal(e);
-
-        assertEquals(2, e0.getKey().intValue());
-        assertEquals("str2", e0.getValue());
-    }
-
-    /**
-     * @throws Exception If failed.
-     */
-    public void testBinaryObject() throws Exception {
-        BinaryMarshaller marsh = binaryMarshaller(Arrays.asList(new BinaryTypeConfiguration(SimpleObject.class.getName())));
-
-        SimpleObject obj = simpleObject();
-
-        BinaryObject po = marshal(obj, marsh);
-
-        BinaryObject po0 = marshalUnmarshal(po, marsh);
-
-        assertTrue(po.hasField("b"));
-        assertTrue(po.hasField("s"));
-        assertTrue(po.hasField("i"));
-        assertTrue(po.hasField("l"));
-        assertTrue(po.hasField("f"));
-        assertTrue(po.hasField("d"));
-        assertTrue(po.hasField("c"));
-        assertTrue(po.hasField("bool"));
-
-        assertFalse(po.hasField("no_such_field"));
-
-        assertEquals(obj, po.deserialize());
-        assertEquals(obj, po0.deserialize());
-    }
-
-    /**
-     * @throws Exception If failed.
-     */
-    public void testEnum() throws Exception {
-        BinaryMarshaller marsh = binaryMarshaller(Arrays.asList(new BinaryTypeConfiguration(TestEnum.class.getName())));
-
-        assertEquals(TestEnum.B, marshalUnmarshal(TestEnum.B, marsh));
-    }
-
-    /**
-     * @throws Exception If failed.
-     */
-    public void testDateAndTimestampInSingleObject() throws Exception {
-        BinaryTypeConfiguration cfg1 = new BinaryTypeConfiguration(DateClass1.class.getName());
-
-        BinaryMarshaller marsh = binaryMarshaller(Arrays.asList(cfg1));
-
-        Date date = new Date();
-        Timestamp ts = new Timestamp(System.currentTimeMillis());
-
-        DateClass1 obj1 = new DateClass1();
-        obj1.date = date;
-        obj1.ts = ts;
-
-        BinaryObject po1 = marshal(obj1, marsh);
-
-        assertEquals(date, po1.field("date"));
-        assertEquals(Date.class, po1.field("date").getClass());
-        assertEquals(ts, po1.field("ts"));
-        assertEquals(Timestamp.class, po1.field("ts").getClass());
-
-        obj1 = po1.deserialize();
-        assertEquals(date, obj1.date);
-        assertEquals(ts, obj1.ts);
-    }
-
-    /**
-     * @throws Exception If failed.
-     */
-    public void testSimpleObject() throws Exception {
-        BinaryMarshaller marsh = binaryMarshaller(Arrays.asList(
-            new BinaryTypeConfiguration(SimpleObject.class.getName())
-        ));
-
-        SimpleObject obj = simpleObject();
-
-        BinaryObject po = marshal(obj, marsh);
-
-        assertEquals(obj.hashCode(), po.hashCode());
-
-        assertEquals(obj, po.deserialize());
-
-        assertEquals(obj.b, (byte)po.field("b"));
-        assertEquals(obj.s, (short)po.field("s"));
-        assertEquals(obj.i, (int)po.field("i"));
-        assertEquals(obj.l, (long)po.field("l"));
-        assertEquals(obj.f, (float)po.field("f"), 0);
-        assertEquals(obj.d, (double)po.field("d"), 0);
-        assertEquals(obj.c, (char)po.field("c"));
-        assertEquals(obj.bool, (boolean)po.field("bool"));
-        assertEquals(obj.str, po.field("str"));
-        assertEquals(obj.uuid, po.field("uuid"));
-        assertEquals(obj.date, po.field("date"));
-        assertEquals(Date.class, obj.date.getClass());
-        assertEquals(obj.ts, po.field("ts"));
-        assertArrayEquals(obj.bArr, (byte[])po.field("bArr"));
-        assertArrayEquals(obj.sArr, (short[])po.field("sArr"));
-        assertArrayEquals(obj.iArr, (int[])po.field("iArr"));
-        assertArrayEquals(obj.lArr, (long[])po.field("lArr"));
-        assertArrayEquals(obj.fArr, (float[])po.field("fArr"), 0);
-        assertArrayEquals(obj.dArr, (double[])po.field("dArr"), 0);
-        assertArrayEquals(obj.cArr, (char[])po.field("cArr"));
-        assertBooleanArrayEquals(obj.boolArr, (boolean[])po.field("boolArr"));
-        assertArrayEquals(obj.strArr, (String[])po.field("strArr"));
-        assertArrayEquals(obj.uuidArr, (UUID[])po.field("uuidArr"));
-        assertArrayEquals(obj.dateArr, (Date[])po.field("dateArr"));
-        assertArrayEquals(obj.objArr, (Object[])po.field("objArr"));
-        assertEquals(obj.col, po.field("col"));
-        assertEquals(obj.map, po.field("map"));
-        assertEquals(new Integer(obj.enumVal.ordinal()), new Integer(((BinaryObject)po.field("enumVal")).enumOrdinal()));
-        assertArrayEquals(ordinals(obj.enumArr), ordinals((BinaryObject[])po.field("enumArr")));
-        assertNull(po.field("unknown"));
-
-        BinaryObject innerPo = po.field("inner");
-
-        assertEquals(obj.inner, innerPo.deserialize());
-
-        assertEquals(obj.inner.b, (byte)innerPo.field("b"));
-        assertEquals(obj.inner.s, (short)innerPo.field("s"));
-        assertEquals(obj.inner.i, (int)innerPo.field("i"));
-        assertEquals(obj.inner.l, (long)innerPo.field("l"));
-        assertEquals(obj.inner.f, (float)innerPo.field("f"), 0);
-        assertEquals(obj.inner.d, (double)innerPo.field("d"), 0);
-        assertEquals(obj.inner.c, (char)innerPo.field("c"));
-        assertEquals(obj.inner.bool, (boolean)innerPo.field("bool"));
-        assertEquals(obj.inner.str, innerPo.field("str"));
-        assertEquals(obj.inner.uuid, innerPo.field("uuid"));
-        assertEquals(obj.inner.date, innerPo.field("date"));
-        assertEquals(Date.class, obj.inner.date.getClass());
-        assertEquals(obj.inner.ts, innerPo.field("ts"));
-        assertArrayEquals(obj.inner.bArr, (byte[])innerPo.field("bArr"));
-        assertArrayEquals(obj.inner.sArr, (short[])innerPo.field("sArr"));
-        assertArrayEquals(obj.inner.iArr, (int[])innerPo.field("iArr"));
-        assertArrayEquals(obj.inner.lArr, (long[])innerPo.field("lArr"));
-        assertArrayEquals(obj.inner.fArr, (float[])innerPo.field("fArr"), 0);
-        assertArrayEquals(obj.inner.dArr, (double[])innerPo.field("dArr"), 0);
-        assertArrayEquals(obj.inner.cArr, (char[])innerPo.field("cArr"));
-        assertBooleanArrayEquals(obj.inner.boolArr, (boolean[])innerPo.field("boolArr"));
-        assertArrayEquals(obj.inner.strArr, (String[])innerPo.field("strArr"));
-        assertArrayEquals(obj.inner.uuidArr, (UUID[])innerPo.field("uuidArr"));
-        assertArrayEquals(obj.inner.dateArr, (Date[])innerPo.field("dateArr"));
-        assertArrayEquals(obj.inner.objArr, (Object[])innerPo.field("objArr"));
-        assertEquals(obj.inner.col, innerPo.field("col"));
-        assertEquals(obj.inner.map, innerPo.field("map"));
-        assertEquals(new Integer(obj.inner.enumVal.ordinal()),
-            new Integer(((BinaryObject)innerPo.field("enumVal")).enumOrdinal()));
-        assertArrayEquals(ordinals(obj.inner.enumArr), ordinals((BinaryObject[])innerPo.field("enumArr")));
-        assertNull(innerPo.field("inner"));
-        assertNull(innerPo.field("unknown"));
-    }
-
-    /**
-     * @throws Exception If failed.
-     */
-    public void testPortable() throws Exception {
-        BinaryMarshaller marsh = binaryMarshaller(Arrays.asList(
-            new BinaryTypeConfiguration(SimpleObject.class.getName()),
-            new BinaryTypeConfiguration(TestBinary.class.getName())
-        ));
-
-        TestBinary obj = binaryObject();
-
-        BinaryObject po = marshal(obj, marsh);
-
-        assertEquals(obj.hashCode(), po.hashCode());
-
-        assertEquals(obj, po.deserialize());
-
-        assertEquals(obj.b, (byte)po.field("_b"));
-        assertEquals(obj.s, (short)po.field("_s"));
-        assertEquals(obj.i, (int)po.field("_i"));
-        assertEquals(obj.l, (long)po.field("_l"));
-        assertEquals(obj.f, (float)po.field("_f"), 0);
-        assertEquals(obj.d, (double)po.field("_d"), 0);
-        assertEquals(obj.c, (char)po.field("_c"));
-        assertEquals(obj.bool, (boolean)po.field("_bool"));
-        assertEquals(obj.str, po.field("_str"));
-        assertEquals(obj.uuid, po.field("_uuid"));
-        assertEquals(obj.date, po.field("_date"));
-        assertEquals(obj.ts, po.field("_ts"));
-        assertArrayEquals(obj.bArr, (byte[])po.field("_bArr"));
-        assertArrayEquals(obj.sArr, (short[])po.field("_sArr"));
-        assertArrayEquals(obj.iArr, (int[])po.field("_iArr"));
-        assertArrayEquals(obj.lArr, (long[])po.field("_lArr"));
-        assertArrayEquals(obj.fArr, (float[])po.field("_fArr"), 0);
-        assertArrayEquals(obj.dArr, (double[])po.field("_dArr"), 0);
-        assertArrayEquals(obj.cArr, (char[])po.field("_cArr"));
-        assertBooleanArrayEquals(obj.boolArr, (boolean[])po.field("_boolArr"));
-        assertArrayEquals(obj.strArr, (String[])po.field("_strArr"));
-        assertArrayEquals(obj.uuidArr, (UUID[])po.field("_uuidArr"));
-        assertArrayEquals(obj.dateArr, (Date[])po.field("_dateArr"));
-        assertArrayEquals(obj.objArr, (Object[])po.field("_objArr"));
-        assertEquals(obj.col, po.field("_col"));
-        assertEquals(obj.map, po.field("_map"));
-        assertEquals(new Integer(obj.enumVal.ordinal()), new Integer(((BinaryObject)po.field("_enumVal")).enumOrdinal()));
-        assertArrayEquals(ordinals(obj.enumArr), ordinals((BinaryObject[])po.field("_enumArr")));
-        assertNull(po.field("unknown"));
-
-        BinaryObject simplePo = po.field("_simple");
-
-        assertEquals(obj.simple, simplePo.deserialize());
-
-        assertEquals(obj.simple.b, (byte)simplePo.field("b"));
-        assertEquals(obj.simple.s, (short)simplePo.field("s"));
-        assertEquals(obj.simple.i, (int)simplePo.field("i"));
-        assertEquals(obj.simple.l, (long)simplePo.field("l"));
-        assertEquals(obj.simple.f, (float)simplePo.field("f"), 0);
-        assertEquals(obj.simple.d, (double)simplePo.field("d"), 0);
-        assertEquals(obj.simple.c, (char)simplePo.field("c"));
-        assertEquals(obj.simple.bool, (boolean)simplePo.field("bool"));
-        assertEquals(obj.simple.str, simplePo.field("str"));
-        assertEquals(obj.simple.uuid, simplePo.field("uuid"));
-        assertEquals(obj.simple.date, simplePo.field("date"));
-        assertEquals(Date.class, obj.simple.date.getClass());
-        assertEquals(obj.simple.ts, simplePo.field("ts"));
-        assertArrayEquals(obj.simple.bArr, (byte[])simplePo.field("bArr"));
-        assertArrayEquals(obj.simple.sArr, (short[])simplePo.field("sArr"));
-        assertArrayEquals(obj.simple.iArr, (int[])simplePo.field("iArr"));
-        assertArrayEquals(obj.simple.lArr, (long[])simplePo.field("lArr"));
-        assertArrayEquals(obj.simple.fArr, (float[])simplePo.field("fArr"), 0);
-        assertArrayEquals(obj.simple.dArr, (double[])simplePo.field("dArr"), 0);
-        assertArrayEquals(obj.simple.cArr, (char[])simplePo.field("cArr"));
-        assertBooleanArrayEquals(obj.simple.boolArr, (boolean[])simplePo.field("boolArr"));
-        assertArrayEquals(obj.simple.strArr, (String[])simplePo.field("strArr"));
-        assertArrayEquals(obj.simple.uuidArr, (UUID[])simplePo.field("uuidArr"));
-        assertArrayEquals(obj.simple.dateArr, (Date[])simplePo.field("dateArr"));
-        assertArrayEquals(obj.simple.objArr, (Object[])simplePo.field("objArr"));
-        assertEquals(obj.simple.col, simplePo.field("col"));
-        assertEquals(obj.simple.map, simplePo.field("map"));
-        assertEquals(new Integer(obj.simple.enumVal.ordinal()),
-            new Integer(((BinaryObject)simplePo.field("enumVal")).enumOrdinal()));
-        assertArrayEquals(ordinals(obj.simple.enumArr), ordinals((BinaryObject[])simplePo.field("enumArr")));
-        assertNull(simplePo.field("simple"));
-        assertNull(simplePo.field("portable"));
-        assertNull(simplePo.field("unknown"));
-
-        BinaryObject portablePo = po.field("_portable");
-
-        assertEquals(obj.portable, portablePo.deserialize());
-
-        assertEquals(obj.portable.b, (byte)portablePo.field("_b"));
-        assertEquals(obj.portable.s, (short)portablePo.field("_s"));
-        assertEquals(obj.portable.i, (int)portablePo.field("_i"));
-        assertEquals(obj.portable.l, (long)portablePo.field("_l"));
-        assertEquals(obj.portable.f, (float)portablePo.field("_f"), 0);
-        assertEquals(obj.portable.d, (double)portablePo.field("_d"), 0);
-        assertEquals(obj.portable.c, (char)portablePo.field("_c"));
-        assertEquals(obj.portable.bool, (boolean)portablePo.field("_bool"));
-        assertEquals(obj.portable.str, portablePo.field("_str"));
-        assertEquals(obj.portable.uuid, portablePo.field("_uuid"));
-        assertEquals(obj.portable.date, portablePo.field("_date"));
-        assertEquals(obj.portable.ts, portablePo.field("_ts"));
-        assertArrayEquals(obj.portable.bArr, (byte[])portablePo.field("_bArr"));
-        assertArrayEquals(obj.portable.sArr, (short[])portablePo.field("_sArr"));
-        assertArrayEquals(obj.portable.iArr, (int[])portablePo.field("_iArr"));
-        assertArrayEquals(obj.portable.lArr, (long[])portablePo.field("_lArr"));
-        assertArrayEquals(obj.portable.fArr, (float[])portablePo.field("_fArr"), 0);
-        assertArrayEquals(obj.portable.dArr, (double[])portablePo.field("_dArr"), 0);
-        assertArrayEquals(obj.portable.cArr, (char[])portablePo.field("_cArr"));
-        assertBooleanArrayEquals(obj.portable.boolArr, (boolean[])portablePo.field("_boolArr"));
-        assertArrayEquals(obj.portable.strArr, (String[])portablePo.field("_strArr"));
-        assertArrayEquals(obj.portable.uuidArr, (UUID[])portablePo.field("_uuidArr"));
-        assertArrayEquals(obj.portable.dateArr, (Date[])portablePo.field("_dateArr"));
-        assertArrayEquals(obj.portable.objArr, (Object[])portablePo.field("_objArr"));
-        assertEquals(obj.portable.col, portablePo.field("_col"));
-        assertEquals(obj.portable.map, portablePo.field("_map"));
-        assertEquals(new Integer(obj.portable.enumVal.ordinal()),
-            new Integer(((BinaryObject)portablePo.field("_enumVal")).enumOrdinal()));
-        assertArrayEquals(ordinals(obj.portable.enumArr), ordinals((BinaryObject[])portablePo.field("_enumArr")));
-        assertNull(portablePo.field("_simple"));
-        assertNull(portablePo.field("_portable"));
-        assertNull(portablePo.field("unknown"));
-    }
-
-    /**
-     * @throws Exception If failed.
-     */
-    public void testObjectFieldOfExternalizableCollection() throws Exception {
-        EnclosingObj obj = new EnclosingObj();
-
-        obj.queue = new TestQueue("test");
-
-        assertEquals(obj, marshalUnmarshal(obj));
-    }
-
-    /**
-     *
-     */
-    private static class EnclosingObj implements Serializable {
-        /** Queue. */
-        Queue<Integer> queue = new TestQueue("test");
-
-        /** {@inheritDoc} */
-        @Override public boolean equals(Object o) {
-            if (this == o)
-                return true;
-
-            if (o == null || getClass() != o.getClass())
-                return false;
-
-            EnclosingObj obj = (EnclosingObj)o;
-
-            return Objects.equals(queue, obj.queue);
-        }
-
-        /** {@inheritDoc} */
-        @Override public int hashCode() {
-            return Objects.hash(queue);
-        }
-    }
-
-    /**
-     *
-     */
-    private static class TestQueue extends AbstractQueue<Integer> implements Externalizable {
-        /** Name. */
-        private String name;
-
-        /**
-         * @param name Name.
-         */
-        public TestQueue(String name) {
-            this.name = name;
-        }
-
-        /** {@inheritDoc} */
-        @NotNull @Override public Iterator<Integer> iterator() {
-            return Collections.emptyIterator();
-        }
-
-        /** {@inheritDoc} */
-        @Override public int size() {
-            return 0;
-        }
-
-        /** {@inheritDoc} */
-        @Override public void writeExternal(ObjectOutput out) throws IOException {
-            out.writeObject(name);
-        }
-
-        /** {@inheritDoc} */
-        @Override public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
-            name = (String)in.readObject();
-        }
-
-        /** {@inheritDoc} */
-        @Override public boolean offer(Integer integer) {
-            throw new UnsupportedOperationException();
-        }
-
-        /** {@inheritDoc} */
-        @Override public Integer poll() {
-            throw new UnsupportedOperationException();
-        }
-
-        /** {@inheritDoc} */
-        @Override public Integer peek() {
-            throw new UnsupportedOperationException();
-        }
-
-        /** {@inheritDoc} */
-        @Override public boolean equals(Object o) {
-            if (this == o)
-                return true;
-
-            if (o == null || getClass() != o.getClass())
-                return false;
-
-            TestQueue integers = (TestQueue)o;
-
-            return Objects.equals(name, integers.name);
-        }
-
-        /** {@inheritDoc} */
-        @Override public int hashCode() {
-            return Objects.hash(name);
-        }
-    }
-
-    /**
-     * @param obj Simple object.
-     * @param po Portable object.
-     */
-    private void checkSimpleObjectData(SimpleObject obj, BinaryObject po) {
-        assertEquals(obj.b, (byte)po.field("b"));
-        assertEquals(obj.s, (short)po.field("s"));
-        assertEquals(obj.i, (int)po.field("i"));
-        assertEquals(obj.l, (long)po.field("l"));
-        assertEquals(obj.f, (float)po.field("f"), 0);
-        assertEquals(obj.d, (double)po.field("d"), 0);
-        assertEquals(obj.c, (char)po.field("c"));
-        assertEquals(obj.bool, (boolean)po.field("bool"));
-        assertEquals(obj.str, po.field("str"));
-        assertEquals(obj.uuid, po.field("uuid"));
-        assertEquals(obj.date, po.field("date"));
-        assertEquals(Date.class, obj.date.getClass());
-        assertEquals(obj.ts, po.field("ts"));
-        assertArrayEquals(obj.bArr, (byte[])po.field("bArr"));
-        assertArrayEquals(obj.sArr, (short[])po.field("sArr"));
-        assertArrayEquals(obj.iArr, (int[])po.field("iArr"));
-        assertArrayEquals(obj.lArr, (long[])po.field("lArr"));
-        assertArrayEquals(obj.fArr, (float[])po.field("fArr"), 0);
-        assertArrayEquals(obj.dArr, (double[])po.field("dArr"), 0);
-        assertArrayEquals(obj.cArr, (char[])po.field("cArr"));
-        assertBooleanArrayEquals(obj.boolArr, (boolean[])po.field("boolArr"));
-        assertArrayEquals(obj.strArr, (String[])po.field("strArr"));
-        assertArrayEquals(obj.uuidArr, (UUID[])po.field("uuidArr"));
-        assertArrayEquals(obj.dateArr, (Date[])po.field("dateArr"));
-        assertArrayEquals(obj.objArr, (Object[])po.field("objArr"));
-        assertEquals(obj.col, po.field("col"));
-        assertEquals(obj.map, po.field("map"));
-        assertEquals(new Integer(obj.enumVal.ordinal()), new Integer(((BinaryObject)po.field("enumVal")).enumOrdinal()));
-        assertArrayEquals(ordinals(obj.enumArr), ordinals((BinaryObject[])po.field("enumArr")));
-        assertNull(po.field("unknown"));
-
-        assertEquals(obj, po.deserialize());
-    }
-
-    /**
-     * @throws Exception If failed.
-     */
-    public void testClassWithoutPublicConstructor() throws Exception {
-        BinaryMarshaller marsh = binaryMarshaller(Arrays.asList(
-                new BinaryTypeConfiguration(NoPublicConstructor.class.getName()),
-                new BinaryTypeConfiguration(NoPublicDefaultConstructor.class.getName()),
-                new BinaryTypeConfiguration(ProtectedConstructor.class.getName()))
-        );
-
-        NoPublicConstructor npc = new NoPublicConstructor();
-        BinaryObject npc2 = marshal(npc, marsh);
-
-        assertEquals("test", npc2.<NoPublicConstructor>deserialize().val);
-
-        NoPublicDefaultConstructor npdc = new NoPublicDefaultConstructor(239);
-        BinaryObject npdc2 = marshal(npdc, marsh);
-
-        assertEquals(239, npdc2.<NoPublicDefaultConstructor>deserialize().val);
-
-        ProtectedConstructor pc = new ProtectedConstructor();
-        BinaryObject pc2 = marshal(pc, marsh);
-
-        assertEquals(ProtectedConstructor.class, pc2.<ProtectedConstructor>deserialize().getClass());
-    }
-
-    /**
-     * @throws Exception If failed.
-     */
-    public void testCustomSerializer() throws Exception {
-        BinaryTypeConfiguration type =
-            new BinaryTypeConfiguration(CustomSerializedObject1.class.getName());
-
-        type.setSerializer(new CustomSerializer1());
-
-        BinaryMarshaller marsh = binaryMarshaller(Arrays.asList(type));
-
-        CustomSerializedObject1 obj1 = new CustomSerializedObject1(10);
-
-        BinaryObject po1 = marshal(obj1, marsh);
-
-        assertEquals(20, po1.<CustomSerializedObject1>deserialize().val);
-    }
-
-    /**
-     * @throws Exception If failed.
-     */
-    public void testCustomSerializerWithGlobal() throws Exception {
-        BinaryTypeConfiguration type1 =
-            new BinaryTypeConfiguration(CustomSerializedObject1.class.getName());
-        BinaryTypeConfiguration type2 =
-            new BinaryTypeConfiguration(CustomSerializedObject2.class.getName());
-
-        type2.setSerializer(new CustomSerializer2());
-
-        BinaryMarshaller marsh = binaryMarshaller(new CustomSerializer1(), Arrays.asList(type1, type2));
-
-        CustomSerializedObject1 obj1 = new CustomSerializedObject1(10);
-
-        BinaryObject po1 = marshal(obj1, marsh);
-
-        assertEquals(20, po1.<CustomSerializedObject1>deserialize().val);
-
-        CustomSerializedObject2 obj2 = new CustomSerializedObject2(10);
-
-        BinaryObject po2 = marshal(obj2, marsh);
-
-        assertEquals(30, po2.<CustomSerializedObject2>deserialize().val);
-    }
-
-    /**
-     * @throws Exception If failed.
-     */
-    public void testCustomIdMapper() throws Exception {
-        BinaryTypeConfiguration type =
-            new BinaryTypeConfiguration(CustomMappedObject1.class.getName());
-
-        type.setIdMapper(new BinaryIdMapper() {
-            @Override public int typeId(String clsName) {
-                return 11111;
-            }
-
-            @Override public int fieldId(int typeId, String fieldName) {
-                assert typeId == 11111;
-
-                if ("val1".equals(fieldName))
-                    return 22222;
-                else if ("val2".equals(fieldName))
-                    return 33333;
-
-                assert false : "Unknown field: " + fieldName;
-
-                return 0;
-            }
-        });
-
-        BinaryMarshaller marsh = binaryMarshaller(Arrays.asList(type));
-
-        CustomMappedObject1 obj1 = new CustomMappedObject1(10, "str");
-
-        BinaryObjectExImpl po1 = marshal(obj1, marsh);
-
-        assertEquals(11111, po1.type().typeId());
-        assertEquals((Integer)10, po1.field(22222));
-        assertEquals("str", po1.field(33333));
-
-        assertEquals(10, po1.<CustomMappedObject1>deserialize().val1);
-        assertEquals("str", po1.<CustomMappedObject1>deserialize().val2);
-    }
-
-    /**
-     * @throws Exception If failed.
-     */
-    public void testCustomIdMapperWithGlobal() throws Exception {
-        BinaryTypeConfiguration type1 =
-            new BinaryTypeConfiguration(CustomMappedObject1.class.getName());
-        BinaryTypeConfiguration type2 =
-            new BinaryTypeConfiguration(CustomMappedObject2.class.getName());
-
-        type2.setIdMapper(new BinaryIdMapper() {
-            @Override public int typeId(String clsName) {
-                return 44444;
-            }
-
-            @Override public int fieldId(int typeId, String fieldName) {
-                assert typeId == 44444;
-
-                if ("val1".equals(fieldName)) return 55555;
-                else if ("val2".equals(fieldName)) return 66666;
-
-                assert false : "Unknown field: " + fieldName;
-
-                return 0;
-            }
-        });
-
-        BinaryMarshaller marsh = binaryMarshaller(new BinaryIdMapper() {
-            @Override public int typeId(String clsName) {
-                return 11111;
-            }
-
-            @Override public int fieldId(int typeId, String fieldName) {
-                assert typeId == 11111;
-
-                if ("val1".equals(fieldName))
-                    return 22222;
-                else if ("val2".equals(fieldName))
-                    return 33333;
-
-                assert false : "Unknown field: " + fieldName;
-
-                return 0;
-            }
-        }, Arrays.asList(type1, type2));
-
-        CustomMappedObject1 obj1 = new CustomMappedObject1(10, "str1");
-
-        BinaryObjectExImpl po1 = marshal(obj1, marsh);
-
-        assertEquals(11111, po1.type().typeId());
-        assertEquals((Integer)10, po1.field(22222));
-        assertEquals("str1", po1.field(33333));
-
-        assertEquals(10, po1.<CustomMappedObject1>deserialize().val1);
-        assertEquals("str1", po1.<CustomMappedObject1>deserialize().val2);
-
-        CustomMappedObject2 obj2 = new CustomMappedObject2(20, "str2");
-
-        BinaryObjectExImpl po2 = marshal(obj2, marsh);
-
-        assertEquals(44444, po2.type().typeId());
-        assertEquals((Integer)20, po2.field(55555));
-        assertEquals("str2", po2.field(66666));
-
-        assertEquals(20, po2.<CustomMappedObject2>deserialize().val1);
-        assertEquals("str2", po2.<CustomMappedObject2>deserialize().val2);
-    }
-
-    /**
-     * @throws Exception If failed.
-     */
-    public void testDynamicObject() throws Exception {
-        BinaryMarshaller marsh = binaryMarshaller(Arrays.asList(
-            new BinaryTypeConfiguration(DynamicObject.class.getName())
-        ));
-
-        BinaryObject po1 = marshal(new DynamicObject(0, 10, 20, 30), marsh);
-
-        assertEquals(new Integer(10), po1.field("val1"));
-        assertEquals(null, po1.field("val2"));
-        assertEquals(null, po1.field("val3"));
-
-        DynamicObject do1 = po1.deserialize();
-
-        assertEquals(10, do1.val1);
-        assertEquals(0, do1.val2);
-        assertEquals(0, do1.val3);
-
-        BinaryObject po2 = marshal(new DynamicObject(1, 10, 20, 30), marsh);
-
-        assertEquals(new Integer(10), po2.field("val1"));
-        assertEquals(new Integer(20), po2.field("val2"));
-        assertEquals(null, po2.field("val3"));
-
-        DynamicObject do2 = po2.deserialize();
-
-        assertEquals(10, do2.val1);
-        assertEquals(20, do2.val2);
-        assertEquals(0, do2.val3);
-
-        BinaryObject po3 = marshal(new DynamicObject(2, 10, 20, 30), marsh);
-
-        assertEquals(new Integer(10), po3.field("val1"));
-        assertEquals(new Integer(20), po3.field("val2"));
-        assertEquals(new Integer(30), po3.field("val3"));
-
-        DynamicObject do3 = po3.deserialize();
-
-        assertEquals(10, do3.val1);
-        assertEquals(20, do3.val2);
-        assertEquals(30, do3.val3);
-    }
-
-    /**
-     * @throws Exception If failed.
-     */
-    public void testCycleLink() throws Exception {
-        BinaryMarshaller marsh = binaryMarshaller(Arrays.asList(
-            new BinaryTypeConfiguration(CycleLinkObject.class.getName())
-        ));
-
-        CycleLinkObject obj = new CycleLinkObject();
-
-        obj.self = obj;
-
-        BinaryObject po = marshal(obj, marsh);
-
-        CycleLinkObject obj0 = po.deserialize();
-
-        assert obj0.self == obj0;
-    }
-
-    /**
-     * @throws Exception If failed.
-     */
-    public void testDetached() throws Exception {
-        BinaryMarshaller marsh = binaryMarshaller(Arrays.asList(
-            new BinaryTypeConfiguration(DetachedTestObject.class.getName()),
-            new BinaryTypeConfiguration(DetachedInnerTestObject.class.getName())
-        ));
-
-        UUID id = UUID.randomUUID();
-
-        DetachedTestObject obj = marshal(new DetachedTestObject(
-            new DetachedInnerTestObject(null, id)), marsh).deserialize();
-
-        assertEquals(id, obj.inner1.id);
-        assertEquals(id, obj.inner4.id);
-
-        assert obj.inner1 == obj.inner4;
-
-        BinaryObjectImpl innerPo = (BinaryObjectImpl)obj.inner2;
-
-        assert innerPo.detached();
-
-        DetachedInnerTestObject inner = innerPo.deserialize();
-
-        assertEquals(id, inner.id);
-
-        BinaryObjectImpl detachedPo = (BinaryObjectImpl)innerPo.detach();
-
-        assert detachedPo.detached();
-
-        inner = detachedPo.deserialize();
-
-        assertEquals(id, inner.id);
-
-        innerPo = (BinaryObjectImpl)obj.inner3;
-
-        assert innerPo.detached();
-
-        inner = innerPo.deserialize();
-
-        assertEquals(id, inner.id);
-        assertNotNull(inner.inner);
-
-        detachedPo = (BinaryObjectImpl)innerPo.detach();
-
-        assert detachedPo.detached();
-
-        inner = innerPo.deserialize();
-
-        assertEquals(id, inner.id);
-        assertNotNull(inner.inner);
-    }
-
-    /**
-     * @throws Exception If failed.
-     */
-    public void testCollectionFields() throws Exception {
-        BinaryMarshaller marsh = binaryMarshaller(Arrays.asList(
-            new BinaryTypeConfiguration(CollectionFieldsObject.class.getName()),
-            new BinaryTypeConfiguration(Key.class.getName()),
-            new BinaryTypeConfiguration(Value.class.getName())
-        ));
-
-        Object[] arr = new Object[] {new Value(1), new Value(2), new Value(3)};
-        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);
-
-        BinaryObject po = marshal(obj, marsh);
-
-        Object[] arr0 = po.field("arr");
-
-        assertEquals(3, arr0.length);
-
-        int i = 1;
-
-        for (Object valPo : arr0)
-            assertEquals(i++, ((BinaryObject)valPo).<Value>deserialize().val);
-
-        Collection<BinaryObject> col0 = po.field("col");
-
-        i = 4;
-
-        for (BinaryObject valPo : col0)
-            assertEquals(i++, valPo.<Value>deserialize().val);
-
-        Map<BinaryObject, BinaryObject> map0 = po.field("map");
-
-        for (Map.Entry<BinaryObject, BinaryObject> e : map0.entrySet())
-            assertEquals(e.getKey().<Key>deserialize().key, e.getValue().<Value>deserialize().val);
-    }
-
-    /**
-     * @throws Exception If failed.
-     */
-    public void _testDefaultMapping() throws Exception {
-        BinaryTypeConfiguration customMappingType =
-            new BinaryTypeConfiguration(TestBinary.class.getName());
-
-        customMappingType.setIdMapper(new BinaryIdMapper() {
-            @Override public int typeId(String clsName) {
-                String typeName;
-
-                try {
-                    Method mtd = PortableContext.class.getDeclaredMethod("typeName", String.class);
-
-                    mtd.setAccessible(true);
-
-                    typeName = (String)mtd.invoke(null, clsName);
-                }
-                catch (NoSuchMethodException | InvocationTargetException | IllegalAccessException e) {
-                    throw new RuntimeException(e);
-                }
-
-                return typeName.toLowerCase().hashCode();
-            }
-
-            @Override public int fieldId(int typeId, String fieldName) {
-                return fieldName.toLowerCase().hashCode();
-            }
-        });
-
-        BinaryMarshaller marsh1 = binaryMarshaller(Arrays.asList(
-            new BinaryTypeConfiguration(SimpleObject.class.getName()),
-            customMappingType
-        ));
-
-        TestBinary obj = binaryObject();
-
-        BinaryObjectImpl po = marshal(obj, marsh1);
-
-        BinaryMarshaller marsh2 = binaryMarshaller(Arrays.asList(
-            new BinaryTypeConfiguration(SimpleObject.class.getName()),
-            new BinaryTypeConfiguration(TestBinary.class.getName())
-        ));
-
-        po = marshal(obj, marsh2);
-
-        assertEquals(obj, po.deserialize());
-    }
-
-    /**
-     * @throws Exception If failed.
-     */
-    public void testTypeNames() throws Exception {
-        BinaryTypeConfiguration customType1 = new BinaryTypeConfiguration(Value.class.getName());
-
-        customType1.setIdMapper(new BinaryIdMapper() {
-            @Override public int typeId(String clsName) {
-                return 300;
-            }
-
-            @Override public int fieldId(int typeId, String fieldName) {
-                return 0;
-            }
-        });
-
-        BinaryTypeConfiguration customType2 = new BinaryTypeConfiguration("org.gridgain.NonExistentClass1");
-
-        customType2.setIdMapper(new BinaryIdMapper() {
-            @Override public int typeId(String clsName) {
-                return 400;
-            }
-
-            @Override public int fieldId(int typeId, String fieldName) {
-                return 0;
-            }
-        });
-
-        BinaryTypeConfiguration customType3 = new BinaryTypeConfiguration("NonExistentClass2");
-
-        customType3.setIdMapper(new BinaryIdMapper() {
-            @Override public int typeId(String clsName) {
-                return 500;
-            }
-
-            @Override public int fieldId(int typeId, String fieldName) {
-                return 0;
-            }
-        });
-
-        BinaryTypeConfiguration customType4 = new BinaryTypeConfiguration("NonExistentClass5");
-
-        customType4.setIdMapper(new BinaryIdMapper() {
-            @Override public int typeId(String clsName) {
-                return 0;
-            }
-
-            @Override public int fieldId(int typeId, String fieldName) {
-                return 0;
-            }
-        });
-
-        BinaryMarshaller marsh = binaryMarshaller(Arrays.asList(
-            new BinaryTypeConfiguration(Key.class.getName()),
-            new BinaryTypeConfiguration("org.gridgain.NonExistentClass3"),
-            new BinaryTypeConfiguration("NonExistentClass4"),
-            customType1,
-            customType2,
-            customType3,
-            customType4
-        ));
-
-        PortableContext ctx = portableContext(marsh);
-
-        assertEquals("notconfiguredclass".hashCode(), ctx.typeId("NotConfiguredClass"));
-        assertEquals("key".hashCode(), ctx.typeId("Key"));
-        assertEquals("nonexistentclass3".hashCode(), ctx.typeId("NonExistentClass3"));
-        assertEquals("nonexistentclass4".hashCode(), ctx.typeId("NonExistentClass4"));
-        assertEquals(300, ctx.typeId(getClass().getSimpleName() + "$Value"));
-        assertEquals(400, ctx.typeId("NonExistentClass1"));
-        assertEquals(500, ctx.typeId("NonExistentClass2"));
-        assertEquals("nonexistentclass5".hashCode(), ctx.typeId("NonExistentClass5"));
-    }
-
-    /**
-     * @throws Exception If failed.
-     */
-    public void testFieldIdMapping() throws Exception {
-        BinaryTypeConfiguration customType1 = new BinaryTypeConfiguration(Value.class.getName());
-
-        customType1.setIdMapper(new BinaryIdMapper() {
-            @Override public int typeId(String clsName) {
-                return 300;
-            }
-
-            @Override public int fieldId(int typeId, String fieldName) {
-                switch (fieldName) {
-                    case "val1":
-                        return 301;
-
-                    case "val2":
-                        return 302;
-
-                    default:
-                        return 0;
-                }
-            }
-        });
-
-        BinaryTypeConfiguration customType2 = new BinaryTypeConfiguration("NonExistentClass1");
-
-        customType2.setIdMapper(new BinaryIdMapper() {
-            @Override public int typeId(String clsName) {
-                return 400;
-            }
-
-            @Override public int fieldId(int typeId, String fieldName) {
-                switch (fieldName) {
-                    case "val1":
-                        return 401;
-
-                    case "val2":
-                        return 402;
-
-                    default:
-                        return 0;
-                }
-            }
-        });
-
-        BinaryMarshaller marsh = binaryMarshaller(Arrays.asList(new BinaryTypeConfiguration(Key.class.getName()),
-            new BinaryTypeConfiguration("NonExistentClass2"),
-            customType1,
-            customType2));
-
-        PortableContext ctx = portableContext(marsh);
-
-        assertEquals("val".hashCode(), ctx.fieldId("key".hashCode(), "val"));
-        assertEquals("val".hashCode(), ctx.fieldId("nonexistentclass2".hashCode(), "val"));
-        assertEquals("val".hashCode(), ctx.fieldId("notconfiguredclass".hashCode(), "val"));
-        assertEquals(301, ctx.fieldId(300, "val1"));
-        assertEquals(302, ctx.fieldId(300, "val2"));
-        assertEquals("val3".hashCode(), ctx.fieldId(300, "val3"));
-        assertEquals(401, ctx.fieldId(400, "val1"));
-        assertEquals(402, ctx.fieldId(400, "val2"));
-        assertEquals("val3".hashCode(), ctx.fieldId(400, "val3"));
-    }
-
-    /**
-     * @throws Exception If failed.
-     */
-    public void testDuplicateTypeId() throws Exception {
-        BinaryTypeConfiguration customType1 = new BinaryTypeConfiguration("org.gridgain.Class1");
-
-        customType1.setIdMapper(new BinaryIdMapper() {
-            @Override public int typeId(String clsName) {
-                return 100;
-            }
-
-            @Override public int fieldId(int typeId, String fieldName) {
-                return 0;
-            }
-        });
-
-        BinaryTypeConfiguration customType2 = new BinaryTypeConfiguration("org.gridgain.Class2");
-
-        customType2.setIdMapper(new BinaryIdMapper() {
-            @Override public int typeId(String clsName) {
-                return 100;
-            }
-
-            @Override public int fieldId(int typeId, String fieldName) {
-                return 0;
-            }
-        });
-
-        try {
-            binaryMarshaller(Arrays.asList(customType1, customType2));
-        }
-        catch (IgniteCheckedException e) {
-            assertEquals("Duplicate type ID [clsName=org.gridgain.Class2, id=100]",
-                e.getCause().getCause().getMessage());
-
-            return;
-        }
-
-        assert false;
-    }
-
-    /**
-     * @throws Exception If failed.
-     */
-    public void testPortableCopy() throws Exception {
-        BinaryMarshaller marsh = binaryMarshaller(Arrays.asList(
-            new BinaryTypeConfiguration(SimpleObject.class.getName())
-        ));
-
-        SimpleObject obj = simpleObject();
-
-        final BinaryObject po = marshal(obj, marsh);
-
-        assertEquals(obj, po.deserialize());
-
-        BinaryObject copy = copy(po, null);
-
-        assertEquals(obj, copy.deserialize());
-
-        copy = copy(po, new HashMap<String, Object>());
-
-        assertEquals(obj, copy.deserialize());
-
-        Map<String, Object> map = new HashMap<>(1, 1.0f);
-
-        map.put("i", 3);
-
-        copy = copy(po, map);
-
-        assertEquals((byte)2, copy.<Byte>field("b").byteValue());
-        assertEquals((short)2, copy.<Short>field("s").shortValue());
-        assertEquals(3, copy.<Integer>field("i").intValue());
-        assertEquals(2L, copy.<Long>field("l").longValue());
-        assertEquals(2.2f, copy.<Float>field("f").floatValue(), 0);
-        assertEquals(2.2d, copy.<Double>field("d").doubleValue(), 0);
-        assertEquals((char)2, copy.<Character>field("c").charValue());
-        assertEquals(false, copy.<Boolean>field("bool").booleanValue());
-
-        SimpleObject obj0 = copy.deserialize();
-
-        assertEquals((byte)2, obj0.b);
-        assertEquals((short)2, obj0.s);
-        assertEquals(3, obj0.i);
-        assertEquals(2L, obj0.l);
-        assertEquals(2.2f, obj0.f, 0);
-        assertEquals(2.2d, obj0.d, 0);
-        assertEquals((char)2, obj0.c);
-        assertEquals(false, obj0.bool);
-
-        map = new HashMap<>(3, 1.0f);
-
-        map.put("b", (byte)3);
-        map.put("l", 3L);
-        map.put("bool", true);
-
-        copy = copy(po, map);
-
-        assertEquals((byte)3, copy.<Byte>field("b").byteValue());
-        assertEquals((short)2, copy.<Short>field("s").shortValue());
-        assertEquals(2, copy.<Integer>field("i").intValue());
-        assertEquals(3L, copy.<Long>field("l").longValue());
-        assertEquals(2.2f, copy.<Float>field("f").floatValue(), 0);
-        assertEquals(2.2d, copy.<Double>field("d").doubleValue(), 0);
-        assertEquals((char)2, copy.<Character>field("c").charValue());
-        assertEquals(true, copy.<Boolean>field("bool").booleanValue());
-
-        obj0 = copy.deserialize();
-
-        assertEquals((byte)3, obj0.b);
-        assertEquals((short)2, obj0.s);
-        assertEquals(2, obj0.i);
-        assertEquals(3L, obj0.l);
-        assertEquals(2.2f, obj0.f, 0);
-        assertEquals(2.2d, obj0.d, 0);
-        assertEquals((char)2, obj0.c);
-        assertEquals(true, obj0.bool);
-
-        map = new HashMap<>(8, 1.0f);
-
-        map.put("b", (byte)3);
-        map.put("s", (short)3);
-        map.put("i", 3);
-        map.put("l", 3L);
-        map.put("f", 3.3f);
-        map.put("d", 3.3d);
-        map.put("c", (char)3);
-        map.put("bool", true);
-
-        copy = copy(po, map);
-
-        assertEquals((byte)3, copy.<Byte>field("b").byteValue());
-        assertEquals((short)3, copy.<Short>field("s").shortValue());
-        assertEquals(3, copy.<Integer>field("i").intValue());
-        assertEquals(3L, copy.<Long>field("l").longValue());
-        assertEquals(3.3f, copy.<Float>field("f").floatValue(), 0);
-        assertEquals(3.3d, copy.<Double>field("d").doubleValue(), 0);
-        assertEquals((char)3, copy.<Character>field("c").charValue());
-        assertEquals(true, copy.<Boolean>field("bool").booleanValue());
-
-        obj0 = copy.deserialize();
-
-        assertEquals((byte)3, obj0.b);
-        assertEquals((short)3, obj0.s);
-        assertEquals(3, obj0.i);
-        assertEquals(3L, obj0.l);
-        assertEquals(3.3f, obj0.f, 0);
-        assertEquals(3.3d, obj0.d, 0);
-        assertEquals((char)3, obj0.c);
-        assertEquals(true, obj0.bool);
-
-//        GridTestUtils.assertThrows(
-//            log,
-//            new Callable<Object>() {
-//                @Override public Object call() throws Exception {
-//                    po.copy(F.<String, Object>asMap("i", false));
-//
-//                    return null;
-//                }
-//            },
-//            PortableException.class,
-//            "Invalid value type for field: i"
-//        );
-    }
-
-    /**
-     * @throws Exception If failed.
-     */
-    public void testPortableCopyString() throws Exception {
-        BinaryMarshaller marsh = binaryMarshaller(Arrays.asList(
-            new BinaryTypeConfiguration(SimpleObject.class.getName())
-        ));
-
-        SimpleObject obj = simpleObject();
-
-        BinaryObject po = marshal(obj, marsh);
-
-        BinaryObject copy = copy(po, F.<String, Object>asMap("str", "str3"));
-
-        assertEquals("str3", copy.<String>field("str"));
-
-        SimpleObject obj0 = copy.deserialize();
-
-        assertEquals("str3", obj0.str);
-    }
-
-    /**
-     * @throws Exception If failed.
-     */
-    public void testPortableCopyUuid() throws Exception {
-        BinaryMarshaller marsh = binaryMarshaller(Arrays.asList(
-            new BinaryTypeConfiguration(SimpleObject.class.getName())
-        ));
-
-        SimpleObject obj = simpleObject();
-
-        BinaryObject po = marshal(obj, marsh);
-
-        UUID uuid = UUID.randomUUID();
-
-        BinaryObject copy = copy(po, F.<String, Object>asMap("uuid", uuid));
-
-        assertEquals(uuid, copy.<UUID>field("uuid"));
-
-        SimpleObject obj0 = copy.deserialize();
-
-        assertEquals(uuid, obj0.uuid);
-    }
-
-    /**
-     * @throws Exception If failed.
-     */
-    public void testPortableCopyByteArray() throws Exception {
-        BinaryMarshaller marsh = binaryMarshaller(Arrays.asList(
-            new BinaryTypeConfiguration(SimpleObject.class.getName())
-        ));
-
-        SimpleObject obj = simpleObject();
-
-        BinaryObject po = marshal(obj, marsh);
-
-        BinaryObject copy = copy(po, F.<String, Object>asMap("bArr", new byte[]{1, 2, 3}));
-
-        assertArrayEquals(new byte[]{1, 2, 3}, copy.<byte[]>field("bArr"));
-
-        SimpleObject obj0 = copy.deserialize();
-
-        assertArrayEquals(new byte[]{1, 2, 3}, obj0.bArr);
-    }
-
-    /**
-     * @param po Portable object.
-     * @param fields Fields.
-     * @return Copy.
-     */
-    private BinaryObject copy(BinaryObject po, Map<String, Object> fields) {
-        BinaryObjectBuilder builder = BinaryObjectBuilderImpl.wrap(po);
-
-        if (fields != null) {
-            for (Map.Entry<String, Object> e : fields.entrySet())
-                builder.setField(e.getKey(), e.getValue());
-        }
-
-        return builder.build();
-    }
-
-    /**
-     * @throws Exception If failed.
-     */
-    public void testPortableCopyShortArray() throws Exception {
-        BinaryMarshaller marsh = binaryMarshaller(Arrays.asList(
-            new BinaryTypeConfiguration(SimpleObject.class.getName())
-        ));
-
-        SimpleObject obj = simpleObject();
-
-        BinaryObject po = marshal(obj, marsh);
-
-        BinaryObject copy = copy(po, F.<String, Object>asMap("sArr", new short[]{1, 2, 3}));
-
-        assertArrayEquals(new short[] {1, 2, 3}, copy.<short[]>field("sArr"));
-
-        SimpleObject obj0 = copy.deserialize();
-
-        assertArrayEquals(new short[] {1, 2, 3}, obj0.sArr);
-    }
-
-    /**
-     * @throws Exception If failed.
-     */
-    public void testPortableCopyIntArray() throws Exception {
-        BinaryMarshaller marsh = binaryMarshaller(Arrays.asList(
-            new BinaryTypeConfiguration(SimpleObject.class.getName())
-        ));
-
-        SimpleObject obj = simpleObject();
-
-        BinaryObject po = marshal(obj, marsh);
-
-        BinaryObject copy = copy(po, F.<String, Object>asMap("iArr", new int[]{1, 2, 3}));
-
-        assertArrayEquals(new int[] {1, 2, 3}, copy.<int[]>field("iArr"));
-
-        SimpleObject obj0 = copy.deserialize();
-
-        assertArrayEquals(new int[] {1, 2, 3}, obj0.iArr);
-    }
-
-    /**
-     * @throws Exception If failed.
-     */
-    public void testPortableCopyLongArray() throws Exception {
-        BinaryMarshaller marsh = binaryMarshaller(Arrays.asList(
-            new BinaryTypeConfiguration(SimpleObject.class.getName())
-        ));
-
-        SimpleObject obj = simpleObject();
-
-        BinaryObject po = marshal(obj, marsh);
-
-        BinaryObject copy = copy(po, F.<String, Object>asMap("lArr", new long[]{1, 2, 3}));
-
-        assertArrayEquals(new long[] {1, 2, 3}, copy.<long[]>field("lArr"));
-
-        SimpleObject obj0 = copy.deserialize();
-
-        assertArrayEquals(new long[] {1, 2, 3}, obj0.lArr);
-    }
-
-    /**
-     * @throws Exception If failed.
-     */
-    public void testPortableCopyFloatArray() throws Exception {
-        BinaryMarshaller marsh = binaryMarshaller(Arrays.asList(
-            new BinaryTypeConfiguration(SimpleObject.class.getName())
-        ));
-
-        SimpleObject obj = simpleObject();
-
-        BinaryObject po = marshal(obj, marsh);
-
-        BinaryObject copy = copy(po, F.<String, Object>asMap("fArr", new float[]{1, 2, 3}));
-
-        assertArrayEquals(new float[] {1, 2, 3}, copy.<float[]>field("fArr"), 0);
-
-        SimpleObject obj0 = copy.deserialize();
-
-        assertArrayEquals(new float[] {1, 2, 3}, obj0.fArr, 0);
-    }
-
-    /**
-     * @throws Exception If failed.
-     */
-    public void testPortableCopyDoubleArray() throws Exception {
-        BinaryMarshaller marsh = binaryMarshaller(Arrays.asList(
-            new BinaryTypeConfiguration(SimpleObject.class.getName())
-        ));
-
-        SimpleObject obj = simpleObject();
-
-        BinaryObject po = marshal(obj, marsh);
-
-        BinaryObject copy = copy(po, F.<String, Object>asMap("dArr", new double[]{1, 2, 3}));
-
-        assertArrayEquals(new double[] {1, 2, 3}, copy.<double[]>field("dArr"), 0);
-
-        SimpleObject obj0 = copy.deserialize();
-
-        assertArrayEquals(new double[] {1, 2, 3}, obj0.dArr, 0);
-    }
-
-    /**
-     * @throws Exception If failed.
-     */
-    public void testPortableCopyCharArray() throws Exception {
-        BinaryMarshaller marsh = binaryMarshaller(Arrays.asList(
-            new BinaryTypeConfiguration(SimpleObject.class.getName())
-        ));
-
-        SimpleObject obj = simpleObject();
-
-        BinaryObject po = marshal(obj, marsh);
-
-        BinaryObject copy = copy(po, F.<String, Object>asMap("cArr", new char[]{1, 2, 3}));
-
-        assertArrayEquals(new char[]{1, 2, 3}, copy.<char[]>field("cArr"));
-
-        SimpleObject obj0 = copy.deserialize();
-
-        assertArrayEquals(new char[]{1, 2, 3}, obj0.cArr);
-    }
-
-    /**
-     * @throws Exception If failed.
-     */
-    public void testPortableCopyStringArray() throws Exception {
-        BinaryMarshaller marsh = binaryMarshaller(Arrays.asList(
-            new BinaryTypeConfiguration(SimpleObject.class.getName())
-        ));
-
-        SimpleObject obj = simpleObject();
-
-        BinaryObject po = marshal(obj, marsh);
-
-        BinaryObject copy = copy(po, F.<String, Object>asMap("strArr", new String[]{"str1", "str2"}));
-
-        assertArrayEquals(new String[]{"str1", "str2"}, copy.<String[]>field("strArr"));
-
-        SimpleObject obj0 = copy.deserialize();
-
-        assertArrayEquals(new String[]{"str1", "str2"}, obj0.strArr);
-    }
-
-    /**
-     * @throws Exception If failed.
-     */
-    public void testPortableCopyObject() throws Exception {
-        BinaryMarshaller marsh = binaryMarshaller(Arrays.asList(
-            new BinaryTypeConfiguration(SimpleObject.class.getName())
-        ));
-
-        SimpleObject obj = simpleObject();
-
-        BinaryObject po = marshal(obj, marsh);
-
-        SimpleObject newObj = new SimpleObject();
-
-        newObj.i = 12345;
-        newObj.fArr = new float[] {5, 8, 0};
-        newObj.str = "newStr";
-
-        BinaryObject copy = copy(po, F.<String, Object>asMap("inner", newObj));
-
-        assertEquals(newObj, copy.<BinaryObject>field("inner").deserialize());
-
-        SimpleObject obj0 = copy.deserialize();
-
-        assertEquals(newObj, obj0.inner);
-    }
-
-    /**
-     * @throws Exception If failed.
-     */
-    public void testPortableCopyNonPrimitives() throws Exception {
-        BinaryMarshaller marsh = binaryMarshaller(Arrays.asList(
-            new BinaryTypeConfiguration(SimpleObject.class.getName())
-        ));
-
-        SimpleObject obj = simpleObject();
-
-        BinaryObject po = marshal(obj, marsh);
-
-        Map<String, Object> map = new HashMap<>(3, 1.0f);
-
-        SimpleObject newObj = new SimpleObject();
-
-        newObj.i = 12345;
-        newObj.fArr = new float[] {5, 8, 0};
-        newObj.str = "newStr";
-
-        map.put("str", "str555");
-        map.put("inner", newObj);
-        map.put("bArr", new byte[]{6, 7, 9});
-
-        BinaryObject copy = copy(po, map);
-
-        assertEquals("str555", copy.<String>field("str"));
-        assertEquals(newObj, copy.<BinaryObject>field("inner").deserialize());
-        assertArrayEquals(new byte[]{6, 7, 9}, copy.<byte[]>field("bArr"));
-
-        SimpleObject obj0 = copy.deserialize();
-
-        assertEquals("str555", obj0.str);
-        assertEquals(newObj, obj0.inner);
-        assertArrayEquals(new byte[]{6, 7, 9}, obj0.bArr);
-    }
-
-    /**
-     * @throws Exception If failed.
-     */
-    public void testPortableCopyMixed() throws Exception {
-        BinaryMarshaller marsh = binaryMarshaller(Arrays.asList(new BinaryTypeConfiguration(SimpleObject.class.getName())));
-
-        SimpleObject obj = simpleObject();
-
-        BinaryObject po = marshal(obj, marsh);
-
-        Map<String, Object> map = new HashMap<>(3, 1.0f);
-
-        SimpleObject newObj = new SimpleObject();
-
-        newObj.i = 12345;
-        newObj.fArr = new float[] {5, 8, 0};
-        newObj.str = "newStr";
-
-        map.put("i", 1234);
-        map.put("str", "str555");
-        map.put("inner", newObj);
-        map.put("s", (short)2323);
-        map.put("bArr", new byte[]{6, 7, 9});
-        map.put("b", (byte) 111);
-
-        BinaryObject copy = copy(po, map);
-
-        assertEquals(1234, copy.<Integer>field("i").intValue());
-        assertEquals("str555", copy.<String>field("str"));
-        assertEquals(newObj, copy.<BinaryObject>field("inner").deserialize());
-        assertEquals((short)2323, copy.<Short>field("s").shortValue());
-        assertArrayEquals(new byte[] {6, 7, 9}, copy.<byte[]>field("bArr"));
-        assertEquals((byte)111, copy.<Byte>field("b").byteValue());
-
-        SimpleObject obj0 = copy.deserialize();
-
-        assertEquals(1234, obj0.i);
-        assertEquals("str555", obj0.str);
-        assertEquals(newObj, obj0.inner);
-        assertEquals((short)2323, obj0.s);
-        assertArrayEquals(new byte[]{6, 7, 9}, obj0.bArr);
-        assertEquals((byte) 111, obj0.b);
-    }
-
-    /**
-     * @throws Exception If failed.
-     */
-    public void testKeepDeserialized() throws Exception {
-        BinaryMarshaller marsh = binaryMarshaller(Arrays.asList(new BinaryTypeConfiguration(SimpleObject.class.getName())));
-
-        BinaryObjectImpl po = marshal(simpleObject(), marsh);
-
-        CacheObjectContext coCtx = new CacheObjectContext(newContext(), null, false, true, false);
-
-        assert po.value(coCtx, false) == po.value(coCtx, false);
-
-        po = marshal(simpleObject(), marsh);
-
-        assert po.deserialize() != po.deserialize();
-    }
-
-    /**
-     * @throws Exception If failed.
-     */
-    public void testOffheapPortable() throws Exception {
-        BinaryMarshaller marsh = binaryMarshaller(Arrays.asList(new BinaryTypeConfiguration(SimpleObject.class.getName())));
-
-        PortableContext ctx = portableContext(marsh);
-
-        SimpleObject simpleObj = simpleObject();
-
-        BinaryObjectImpl obj = marshal(simpleObj, marsh);
-
-        long ptr = 0;
-
-        long ptr1 = 0;
-
-        long ptr2 = 0;
-
-        try {
-            ptr = copyOffheap(obj);
-
-            BinaryObjectOffheapImpl offheapObj = new BinaryObjectOffheapImpl(ctx,
-                ptr,
-                0,
-                obj.array().length);
-
-            assertTrue(offheapObj.equals(offheapObj));
-            assertFalse(offheapObj.equals(null));
-            assertFalse(offheapObj.equals("str"));
-            assertTrue(offheapObj.equals(obj));
-            assertTrue(obj.equals(offheapObj));
-
-            ptr1 = copyOffheap(obj);
-
-            BinaryObjectOffheapImpl offheapObj1 = new BinaryObjectOffheapImpl(ctx,
-                ptr1,
-                0,
-                obj.array().length);
-
-            assertTrue(offheapObj.equals(offheapObj1));
-            assertTrue(offheapObj1.equals(offheapObj));
-
-            assertEquals(obj.type().typeId(), offheapObj.type().typeId());
-            assertEquals(obj.hashCode(), offheapObj.hashCode());
-
-            checkSimpleObjectData(simpleObj, offheapObj);
-
-            BinaryObjectOffheapImpl innerOffheapObj = offheapObj.field("inner");
-
-            assertNotNull(innerOffheapObj);
-
-            checkSimpleObjectData(simpleObj.inner, innerOffheapObj);
-
-            obj = (BinaryObjectImpl)offheapObj.heapCopy();
-
-            assertEquals(obj.type().typeId(), offheapObj.type().typeId());
-            assertEquals(obj.hashCode(), offheapObj.hashCode());
-
-            checkSimpleObjectData(simpleObj, obj);
-
-            BinaryObjectImpl innerObj = obj.field("inner");
-
-            assertNotNull(innerObj);
-
-            checkSimpleObjectData(simpleObj.inner, innerObj);
-
-            simpleObj.d = 0;
-
-            obj = marshal(simpleObj, marsh);
-
-            assertFalse(offheapObj.equals(obj));
-            assertFalse(obj.equals(offheapObj));
-
-            ptr2 = copyOffheap(obj);
-
-            BinaryObjectOffheapImpl offheapObj2 = new BinaryObjectOffheapImpl(ctx,
-                ptr2,
-                0,
-                obj.array().length);
-
-            assertFalse(offheapObj.equals(offheapObj2));
-            assertFalse(offheapObj2.equals(offheapObj));
-        }
-        finally {
-            UNSAFE.freeMemory(ptr);
-
-            if (ptr1 > 0)
-                UNSAFE.freeMemory(ptr1);
-
-            if (ptr2 > 0)
-                UNSAFE.freeMemory(ptr2);
-        }
-    }
-
-    /**
-     *
-     */
-    public void testReadResolve() throws Exception {
-        BinaryMarshaller marsh = binaryMarshaller(Arrays.asList(
-            new BinaryTypeConfiguration(MySingleton.class.getName()),
-            new BinaryTypeConfiguration(SingletonMarker.class.getName())));
-
-        BinaryObjectImpl portableObj = marshal(MySingleton.INSTANCE, marsh);
-
-        assertTrue(portableObj.array().length <= 1024); // Check that big string was not serialized.
-
-        MySingleton singleton = portableObj.deserialize();
-
-        assertSame(MySingleton.INSTANCE, singleton);
-    }
-
-    /**
-     *
-     */
-    public void testReadResolveOnPortableAware() throws Exception {
-        BinaryMarshaller marsh = binaryMarshaller(Collections.singletonList(
-            new BinaryTypeConfiguration(MyTestClass.class.getName())));
-
-        BinaryObjectImpl portableObj = marshal(new MyTestClass(), marsh);
-
-        MyTestClass obj = portableObj.deserialize();
-
-        assertEquals("readResolve", obj.s);
-    }
-
-    /**
-     * @throws Exception If ecxeption thrown.
-     */
-    public void testDeclareReadResolveInParent() throws Exception {
-        BinaryMarshaller marsh = binaryMarshaller(Arrays.asList(new BinaryTypeConfiguration(ChildPortable.class.getName())));
-
-        BinaryObjectImpl portableObj = marshal(new ChildPortable(), marsh);
-
-        ChildPortable singleton = portableObj.deserialize();
-
-        assertNotNull(singleton.s);
-    }
-
-    /**
-     *
-     */
-    public void testDecimalFields() throws Exception {
-        Collection<BinaryTypeConfiguration> clsNames = new ArrayList<>();
-
-        clsNames.add(new BinaryTypeConfiguration(DecimalReflective.class.getName()));
-        clsNames.add(new BinaryTypeConfiguration(DecimalMarshalAware.class.getName()));
-
-        BinaryMarshaller marsh = binaryMarshaller(clsNames);
-
-        // 1. Test reflective stuff.
-        DecimalReflective obj1 = new DecimalReflective();
-
-        obj1.val = BigDecimal.ZERO;
-        obj1.valArr = new BigDecimal[] { BigDecimal.ONE, BigDecimal.TEN };
-
-        BinaryObjectImpl portObj = marshal(obj1, marsh);
-
-        assertEquals(obj1.val, portObj.field("val"));
-        assertArrayEquals(obj1.valArr, portObj.<BigDecimal[]>field("valArr"));
-
-        assertEquals(obj1.val, portObj.<DecimalReflective>deserialize().val);
-        assertArrayEquals(obj1.valArr, portObj.<DecimalReflective>deserialize().valArr);
-
-        // 2. Test marshal aware stuff.
-        DecimalMarshalAware obj2 = new DecimalMarshalAware();
-
-        obj2.val = BigDecimal.ZERO;
-        obj2.valArr = new BigDecimal[] { BigDecimal.ONE, BigDecimal.TEN.negate() };
-        obj2.rawVal = BigDecimal.TEN;
-        obj2.rawValArr = new BigDecimal[] { BigDecimal.ZERO, BigDecimal.ONE };
-
-        portObj = marshal(obj2, marsh);
-
-        assertEquals(obj2.val, portObj.field("val"));
-        assertArrayEquals(obj2.valArr, portObj.<BigDecimal[]>field("valArr"));
-
-        assertEquals(obj2.val, portObj.<DecimalMarshalAware>deserialize().val);
-        assertArrayEquals(obj2.valArr, portObj.<DecimalMarshalAware>deserialize().valArr);
-        assertEquals(obj2.rawVal, portObj.<DecimalMarshalAware>deserialize().rawVal);
-        assertArrayEquals(obj2.rawValArr, portObj.<DecimalMarshalAware>deserialize().rawValArr);
-    }
-
-    /**
-     * @throws IgniteCheckedException If failed.
-     */
-    public void testFinalField() throws IgniteCheckedException {
-        BinaryMarshaller marsh = binaryMarshaller();
-
-        SimpleObjectWithFinal obj = new SimpleObjectWithFinal();
-
-        SimpleObjectWithFinal po0 = marshalUnmarshal(obj, marsh);
-
-        assertEquals(obj.time, po0.time);
-    }
-
-    /**
-     * @throws IgniteCheckedException If failed.
-     */
-    public void testThreadLocalArrayReleased() throws Exception {
-        // Checking the writer directly.
-        assertEquals(false, INSTANCE.isAcquired());
-
-        BinaryMarshaller marsh = binaryMarshaller();
-
-        try (BinaryWriterExImpl writer = new BinaryWriterExImpl(portableContext(marsh))) {
-            assertEquals(true, INSTANCE.isAcquired());
-
-            writer.writeString("Thread local test");
-
-            writer.array();
-
-            assertEquals(true, INSTANCE.isAcquired());
-        }
-
-        // Checking the portable marshaller.
-        assertEquals(false, INSTANCE.isAcquired());
-
-        marsh = binaryMarshaller();
-
-        marsh.marshal(new SimpleObject());
-
-        assertEquals(false, INSTANCE.isAcquired());
-
-        marsh = binaryMarshaller();
-
-        // Checking the builder.
-        BinaryObjectBuilder builder = new BinaryObjectBuilderImpl(portableContext(marsh),
-            "org.gridgain.foo.bar.TestClass");
-
-        builder.setField("a", "1");
-
-        BinaryObject portableObj = builder.build();
-
-        assertEquals(false, INSTANCE.isAcquired());
-    }
-
-    /**
-     * @throws Exception If failed.
-     */
-    public void testDuplicateName() throws Exception {
-        BinaryMarshaller marsh = binaryMarshaller();
-
-        Test1.Job job1 = new Test1().new Job();
-        Test2.Job job2 = new Test2().new Job();
-
-        marsh.marshal(job1);
-
-        try {
-            marsh.marshal(job2);
-        }
-        catch (BinaryObjectException e) {
-            assertEquals(true, e.getMessage().contains("Failed to register class"));
-
-            return;
-        }
-
-        assert false;
-    }
-
-    /**
-     * @throws Exception If failed.
-     */
-    public void testClass() throws Exception {
-        BinaryMarshaller marsh = binaryMarshaller();
-
-        Class cls = BinaryMarshallerSelfTest.class;
-
-        Class unmarshalledCls = marshalUnmarshal(cls, marsh);
-
-        Assert.assertEquals(cls, unmarshalledCls);
-    }
-
-    /**
-     * @throws Exception If failed.
-     */
-    public void testClassFieldsMarshalling() throws Exception {
-        BinaryMarshaller marsh = binaryMarshaller();
-
-        ObjectWithClassFields obj = new ObjectWithClassFields();
-        obj.cls1 = BinaryMarshallerSelfTest.class;
-
-        byte[] marshal = marsh.marshal(obj);
-
-        ObjectWithClassFields obj2 = marsh.unmarshal(marshal, null);
-
-        assertEquals(obj.cls1, obj2.cls1);
-        assertNull(obj2.cls2);
-
-        BinaryObject portObj = marshal(obj, marsh);
-
-        Class cls1 = portObj.field("cls1");
-
-        assertEquals(obj.cls1, cls1);
-    }
-
-    /**
-     * @throws Exception If failed.
-     */
-    public void testMarshallingThroughJdk() throws Exception {
-        BinaryMarshaller marsh = binaryMarshaller();
-
-        InetSocketAddress addr = new InetSocketAddress("192.168.0.2", 4545);
-
-        byte[] arr = marsh.marshal(addr);
-
-        InetSocketAddress addr2 = marsh.unmarshal(arr, null);
-
-        assertEquals(addr.getHostString(), addr2.getHostString());
-        assertEquals(addr.getPort(), addr2.getPort());
-
-        TestAddress testAddr = new TestAddress();
-        testAddr.addr = addr;
-        testAddr.str1 = "Hello World";
-
-        SimpleObject simpleObj = new SimpleObject();
-        simpleObj.c = 'g';
-        simpleObj.date = new Date();
-
-        testAddr.obj = simpleObj;
-
-        arr = marsh.marshal(testAddr);
-
-        TestAddress testAddr2 = marsh.unmarshal(arr, null);
-
-        assertEquals(testAddr.addr.getHostString(), testAddr2.addr.getHostString());
-        assertEquals(testAddr.addr.getPort(), testAddr2.addr.getPort());
-        assertEquals(testAddr.str1, testAddr2.str1);
-        assertEquals(testAddr.obj.c, testAddr2.obj.c);
-        assertEquals(testAddr.obj.date, testAddr2.obj.date);
-    }
-
-    /**
-     * @throws Exception If failed.
-     */
-    public void testPredefinedTypeIds() throws Exception {
-        BinaryMarshaller marsh = binaryMarshaller();
-
-        PortableContext pCtx = portableContext(marsh);
-
-        Field field = pCtx.getClass().getDeclaredField("predefinedTypeNames");
-
-        field.setAccessible(true);
-
-        Map<String, Integer> map = (Map<String, Integer>)field.get(pCtx);
-
-        assertTrue(map.size() > 0);
-
-        for (Map.Entry<String, Integer> entry : map.entrySet()) {
-            int id = entry.getValue();
-
-            if (id == GridPortableMarshaller.UNREGISTERED_TYPE_ID)
-                continue;
-
-            PortableClassDescriptor desc = pCtx.descriptorForTypeId(false, entry.getValue(), null, false);
-
-            assertEquals(desc.typeId(), pCtx.typeId(desc.describedClass().getName()));
-            assertEquals(desc.typeId(), pCtx.typeId(pCtx.typeName(desc.describedClass().getName())));
-        }
-    }
-
-    /**
-     * @throws Exception If failed.
-     */
-    public void testCyclicReferencesMarshalling() throws Exception {
-        BinaryMarshaller marsh = binaryMarshaller();
-
-        SimpleObject obj = simpleObject();
-
-        obj.bArr = obj.inner.bArr;
-        obj.cArr = obj.inner.cArr;
-        obj.boolArr = obj.inner.boolArr;
-        obj.sArr = obj.inner.sArr;
-        obj.strArr = obj.inner.strArr;
-        obj.iArr = obj.inner.iArr;
-        obj.lArr = obj.inner.lArr;
-        obj.fArr = obj.inner.fArr;
-        obj.dArr = obj.inner.dArr;
-        obj.dateArr = obj.inner.dateArr;
-        obj.uuidArr = obj.inner.uuidArr;
-        obj.objArr = obj.inner.objArr;
-        obj.bdArr = obj.inner.bdArr;
-        obj.map = obj.inner.map;
-        obj.col = obj.inner.col;
-        obj.mEntry = obj.inner.mEntry;
-
-        SimpleObject res = (SimpleObject)marshalUnmarshal(obj, marsh);
-
-        assertEquals(obj, res);
-
-        assertTrue(res.objArr == res.inner.objArr);
-        assertTrue(res.map == res.inner.map);
-        assertTrue(res.col == res.inner.col);
-        assertTrue(res.mEntry == res.inner.mEntry);
-    }
-
-    /**
-     * @throws Exception If failed.
-     */
-    public void testProxy() throws Exception {
-        BinaryMarshaller marsh = binaryMarshaller();
-
-        SomeItf inItf = (SomeItf)Proxy.newProxyInstance(
-            BinaryMarshallerSelfTest.class.getClassLoader(), new Class[] {SomeItf.class},
-            new InvocationHandler() {
-                private NonSerializable obj = new NonSerializable(null);
-
-                @Override public Object invoke(Object proxy, Method mtd, Object[] args) throws Throwable {
-                    if ("hashCode".equals(mtd.getName()))
-                        return obj.hashCode();
-
-                    obj.checkAfterUnmarshalled();
-
-                    return 17;
-                }
-            }
-        );
-
-        SomeItf outItf = marsh.unmarshal(marsh.marshal(inItf), null);
-
-        assertEquals(outItf.checkAfterUnmarshalled(), 17);
-    }
-
-    /**
-     *
-     */
-    private static interface SomeItf {
-        /**
-         * @return Check result.
-         */
-        int checkAfterUnmarshalled();
-    }
-
-    /**
-     * Some non-serializable class.
-     */
-    @SuppressWarnings( {"PublicField","TransientFieldInNonSerializableClass","FieldMayBeStatic"})
-    private static class NonSerializableA {
-        /** */
-        private final long longVal = 0x33445566778899AAL;
-
-        /** */
-        protected Short shortVal = (short)0xAABB;
-
-        /** */
-        public String[] strArr = {"AA","BB"};
-
-        /** */
-        public boolean flag1 = true;
-
-        /** */
-        public boolean flag2;
-
-        /** */
-        public Boolean flag3;
-
-        /** */
-        public Boolean flag4 = true;
-
-        /** */
-        public Boolean flag5 = false;
-
-        /** */
-        private transient int intVal = 0xAABBCCDD;
-
-        /**
-         * @param strArr Array.
-         * @param shortVal Short value.
-         */
-        @SuppressWarnings( {"UnusedDeclaration"})
-        private NonSerializableA(@Nullable String[] strArr, @Nullable Short shortVal) {
-            // No-op.
-        }
-
-        /**
-         * Checks correctness of the state after unmarshalling.
-         */
-        void checkAfterUnmarshalled() {
-            assertEquals(longVal, 0x33445566778899AAL);
-
-            assertEquals(shortVal.shortValue(), (short)0xAABB);
-
-            assertTrue(Arrays.equals(strArr, new String[] {"AA","BB"}));
-
-            assertEquals(0, intVal);
-
-            assertTrue(flag1);
-            assertFalse(flag2);
-            assertNull(flag3);
-            assertTrue(flag4);
-            assertFalse(flag5);
-        }
-    }
-
-    /**
-     * Some non-serializable class.
-     */
-    @SuppressWarnings( {"PublicField","TransientFieldInNonSerializableClass","PackageVisibleInnerClass"})
-    static class NonSerializableB extends NonSerializableA {
-        /** */
-        public Short shortValue = 0x1122;
-
-        /** */
-        public long longValue = 0x8877665544332211L;
-
-        /** */
-        private transient NonSerializableA[] aArr = {
-            new NonSerializableA(null, null),
-            new NonSerializableA(null, null),
-            new NonSerializableA(null, null)
-        };
-
-        /** */
-        protected Double doubleVal = 123.456;
-
-        /**
-         * Just to eliminate the default constructor.
-         */
-        private NonSerializableB() {
-            super(null, null);
-        }
-
-        /**
-         * Checks correctness of the state after unmarshalling.
-         */
-        @Override void checkAfterUnmarshalled() {
-            super.checkAfterUnmarshalled();
-
-            assertEquals(shortValue.shortValue(), 0x1122);
-
-            assertEquals(longValue, 0x8877665544332211L);
-
-            assertNull(aArr);
-
-            assertEquals(doubleVal, 123.456);
-        }
-    }
-
-    /**
-     * Some non-serializable class.
-     */
-    @SuppressWarnings( {"TransientFieldInNonSerializableClass","PublicField"})
-    private static class NonSerializable extends NonSerializableB {
-        /** */
-        private int idVal = -17;
-
-        /** */
-        private final NonSerializableA aVal = new NonSerializableB();
-
-        /** */
-        private transient NonSerializableB bVal = new NonSerializableB();
-
-        /** */
-        private NonSerializableA[] bArr = new NonSerializableA[] {
-            new NonSerializableB(),
-            new NonSerializableA(null, null)
-        };
-
-        /** */
-        public float floatVal = 567.89F;
-
-        /**
-         * Just to eliminate the default constructor.
-         *
-         * @param aVal Unused.
-         */
-        @SuppressWarnings( {"UnusedDeclaration"})
-        private NonSerializable(NonSerializableA aVal) {
-        }
-
-        /**
-         * Checks correctness of the state after unmarshalling.
-         */
-        @Override void checkAfterUnmarshalled() {
-            super.checkAfterUnmarshalled();
-
-            assertEquals(idVal, -17);
-
-            aVal.checkAfterUnmarshalled();
-
-            assertNull(bVal);
-
-            for (NonSerializableA a : bArr) {
-                a.checkAfterUnmarshalled();
-            }
-
-            assertEquals(floatVal, 567.89F);
-        }
-    }
-
-    /**
-     * Object with class fields.
-     */
-    private static class ObjectWithClassFields {
-        /** */
-        private Class<?> cls1;
-
-        /** */
-        private Class<?> cls2;
-    }
-
-    /**
-     *
-     */
-    private static class TestAddress {
-        /** */
-        private SimpleObject obj;
-
-        /** */
-        private InetSocketAddress addr;
-
-        /** */
-        private String str1;
-    }
-
-    /**
-     *
-     */
-    private static class Test1 {
-        /**
-         *
-         */
-        private class Job {
-
-        }
-    }
-
-    /**
-     *
-     */
-    private static class Test2 {
-        /**
-         *
-         */
-        private class Job {
-
-        }
-    }
-
-    /**
-     * @param obj Object.
-     * @return Offheap address.
-     */
-    private long copyOffheap(BinaryObjectImpl obj) {
-        byte[] arr = obj.array();
-
-        long ptr = UNSAFE.allocateMemory(arr.length);
-
-        UNSAFE.copyMemory(arr, BYTE_ARR_OFF, null, ptr, arr.length);
-
-        return ptr;
-    }
-
-    /**
-     * @param enumArr Enum array.
-     * @return Ordinals.
-     */
-    private <T extends Enum<?>> Integer[] ordinals(T[] enumArr) {
-        Integer[] ords = new Integer[enumArr.length];
-
-        for (int i = 0; i < enumArr.length; i++)
-            ords[i] = enumArr[i].ordinal();
-
-        return ords;
-    }
-
-    /**
-     * @param enumArr Enum array.
-     * @return

<TRUNCATED>

[30/59] [abbrv] ignite git commit: ignite-2065: rename "portable" packages to "binary"

Posted by ak...@apache.org.
http://git-wip-us.apache.org/repos/asf/ignite/blob/1dbf20e0/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryMetadata.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryMetadata.java b/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryMetadata.java
new file mode 100644
index 0000000..cefad9e
--- /dev/null
+++ b/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryMetadata.java
@@ -0,0 +1,180 @@
+/*
+ * 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.binary;
+
+import java.io.Externalizable;
+import java.io.IOException;
+import java.io.ObjectInput;
+import java.io.ObjectOutput;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Map;
+import org.apache.ignite.internal.util.tostring.GridToStringInclude;
+import org.apache.ignite.internal.util.typedef.internal.S;
+import org.apache.ignite.internal.util.typedef.internal.U;
+import org.jetbrains.annotations.Nullable;
+
+/**
+ * Portable metadata which is passed over a wire.
+ */
+public class BinaryMetadata implements Externalizable {
+    /** */
+    private static final long serialVersionUID = 0L;
+
+    /** Type ID. */
+    private int typeId;
+
+    /** Type name. */
+    private String typeName;
+
+    /** Recorded object fields. */
+    @GridToStringInclude
+    private Map<String, Integer> fields;
+
+    /** Affinity key field name. */
+    private String affKeyFieldName;
+
+    /** Schemas associated with type. */
+    private Collection<PortableSchema> schemas;
+
+    /** Whether this is enum type. */
+    private boolean isEnum;
+
+    /**
+     * For {@link Externalizable}.
+     */
+    public BinaryMetadata() {
+        // No-op.
+    }
+
+    /**
+     * Constructor.
+     *
+     * @param typeId Type ID.
+     * @param typeName Type name.
+     * @param fields Fields map.
+     * @param affKeyFieldName Affinity key field name.
+     * @param schemas Schemas.
+     * @param isEnum Enum flag.
+     */
+    public BinaryMetadata(int typeId, String typeName, @Nullable Map<String, Integer> fields,
+        @Nullable String affKeyFieldName, @Nullable Collection<PortableSchema> schemas, boolean isEnum) {
+        assert typeName != null;
+
+        this.typeId = typeId;
+        this.typeName = typeName;
+        this.fields = fields;
+        this.affKeyFieldName = affKeyFieldName;
+        this.schemas = schemas;
+        this.isEnum = isEnum;
+    }
+
+    /**
+     * @return Type ID.
+     */
+    public int typeId() {
+        return typeId;
+    }
+
+    /**
+     * @return Type name.
+     */
+    public String typeName() {
+        return typeName;
+    }
+
+    /**
+     * @return Fields.
+     */
+    public Collection<String> fields() {
+        return fields != null ? fields.keySet() : Collections.<String>emptyList();
+    }
+
+    /**
+     * @return Fields.
+     */
+    public Map<String, Integer> fieldsMap() {
+        return fields != null ? fields : Collections.<String, Integer>emptyMap();
+    }
+
+    /**
+     * @param fieldName Field name.
+     * @return Field type name.
+     */
+    @Nullable public String fieldTypeName(String fieldName) {
+        Integer typeId = fields != null ? fields.get(fieldName) : null;
+
+        return typeId != null ? PortableUtils.fieldTypeName(typeId) : null;
+    }
+
+    /**
+     * @return Affinity key field name.
+     */
+    @Nullable public String affinityKeyFieldName() {
+        return affKeyFieldName;
+    }
+
+    /**
+     * @return Schemas.
+     */
+    public Collection<PortableSchema> schemas() {
+        return schemas != null ? schemas : Collections.<PortableSchema>emptyList();
+    }
+
+    /**
+     * @return {@code True} if this is enum type.
+     */
+    public boolean isEnum() {
+        return isEnum;
+    }
+
+    /**
+     * Wrap metadata into binary type.
+     *
+     * @param ctx Portable context.
+     * @return Binary type.
+     */
+    public BinaryTypeImpl wrap(PortableContext ctx) {
+        return new BinaryTypeImpl(ctx, this);
+    }
+
+    /** {@inheritDoc} */
+    @Override public void writeExternal(ObjectOutput out) throws IOException {
+        out.writeInt(typeId);
+        U.writeString(out, typeName);
+        U.writeMap(out, fields);
+        U.writeString(out, affKeyFieldName);
+        U.writeCollection(out, schemas);
+        out.writeBoolean(isEnum);
+    }
+
+    /** {@inheritDoc} */
+    @Override public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
+        typeId = in.readInt();
+        typeName = U.readString(in);
+        fields = U.readMap(in);
+        affKeyFieldName = U.readString(in);
+        schemas = U.readCollection(in);
+        isEnum = in.readBoolean();
+    }
+
+    /** {@inheritDoc} */
+    @Override public String toString() {
+        return S.toString(BinaryMetadata.class, this);
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/1dbf20e0/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryMetadataCollector.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryMetadataCollector.java b/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryMetadataCollector.java
new file mode 100644
index 0000000..af99cce
--- /dev/null
+++ b/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryMetadataCollector.java
@@ -0,0 +1,277 @@
+/*
+ * 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.binary;
+
+import org.apache.ignite.binary.BinaryIdMapper;
+import org.apache.ignite.binary.BinaryObjectException;
+import org.apache.ignite.binary.BinaryRawWriter;
+import org.apache.ignite.binary.BinaryWriter;
+import org.jetbrains.annotations.Nullable;
+
+import java.lang.reflect.InvocationHandler;
+import java.lang.reflect.Method;
+import java.lang.reflect.Proxy;
+import java.math.BigDecimal;
+import java.sql.Timestamp;
+import java.util.Collection;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.UUID;
+
+/**
+ * Writer for meta data collection.
+ */
+class BinaryMetadataCollector implements BinaryWriter {
+    /** Type ID. */
+    private final int typeId;
+
+    /** Type name. */
+    private final String typeName;
+
+    /** ID mapper. */
+    private final BinaryIdMapper idMapper;
+
+    /** Collected metadata. */
+    private final Map<String, Integer> meta = new HashMap<>();
+
+    /** Schema builder. */
+    private PortableSchema.Builder schemaBuilder = PortableSchema.Builder.newBuilder();
+
+    /**
+     * Constructor.
+     *
+     * @param typeId Type ID.
+     * @param typeName Type name.
+     * @param idMapper ID mapper.
+     */
+    BinaryMetadataCollector(int typeId, String typeName, BinaryIdMapper idMapper) {
+        this.typeId = typeId;
+        this.typeName = typeName;
+        this.idMapper = idMapper;
+    }
+
+    /**
+     * @return Field meta data.
+     */
+    Map<String, Integer> meta() {
+        return meta;
+    }
+
+    /**
+     * @return Schemas.
+     */
+    PortableSchema schema() {
+        return schemaBuilder.build();
+    }
+
+    /** {@inheritDoc} */
+    @Override public void writeByte(String fieldName, byte val) throws BinaryObjectException {
+        add(fieldName, BinaryWriteMode.BYTE);
+    }
+
+    /** {@inheritDoc} */
+    @Override public void writeShort(String fieldName, short val) throws BinaryObjectException {
+        add(fieldName, BinaryWriteMode.SHORT);
+    }
+
+    /** {@inheritDoc} */
+    @Override public void writeInt(String fieldName, int val) throws BinaryObjectException {
+        add(fieldName, BinaryWriteMode.INT);
+    }
+
+    /** {@inheritDoc} */
+    @Override public void writeLong(String fieldName, long val) throws BinaryObjectException {
+        add(fieldName, BinaryWriteMode.LONG);
+    }
+
+    /** {@inheritDoc} */
+    @Override public void writeFloat(String fieldName, float val) throws BinaryObjectException {
+        add(fieldName, BinaryWriteMode.FLOAT);
+    }
+
+    /** {@inheritDoc} */
+    @Override public void writeDouble(String fieldName, double val) throws BinaryObjectException {
+        add(fieldName, BinaryWriteMode.DOUBLE);
+    }
+
+    /** {@inheritDoc} */
+    @Override public void writeChar(String fieldName, char val) throws BinaryObjectException {
+        add(fieldName, BinaryWriteMode.CHAR);
+    }
+
+    /** {@inheritDoc} */
+    @Override public void writeBoolean(String fieldName, boolean val) throws BinaryObjectException {
+        add(fieldName, BinaryWriteMode.BOOLEAN);
+    }
+
+    /** {@inheritDoc} */
+    @Override public void writeDecimal(String fieldName, @Nullable BigDecimal val) throws BinaryObjectException {
+        add(fieldName, BinaryWriteMode.DECIMAL);
+    }
+
+    /** {@inheritDoc} */
+    @Override public void writeString(String fieldName, @Nullable String val) throws BinaryObjectException {
+        add(fieldName, BinaryWriteMode.STRING);
+    }
+
+    /** {@inheritDoc} */
+    @Override public void writeUuid(String fieldName, @Nullable UUID val) throws BinaryObjectException {
+        add(fieldName, BinaryWriteMode.UUID);
+    }
+
+    /** {@inheritDoc} */
+    @Override public void writeDate(String fieldName, @Nullable Date val) throws BinaryObjectException {
+        add(fieldName, BinaryWriteMode.DATE);
+    }
+
+    /** {@inheritDoc} */
+    @Override public void writeTimestamp(String fieldName, @Nullable Timestamp val) throws BinaryObjectException {
+        add(fieldName, BinaryWriteMode.TIMESTAMP);
+    }
+
+    /** {@inheritDoc} */
+    @Override public <T extends Enum<?>> void writeEnum(String fieldName, T val) throws BinaryObjectException {
+        add(fieldName, BinaryWriteMode.ENUM);
+    }
+
+    /** {@inheritDoc} */
+    @Override public <T extends Enum<?>> void writeEnumArray(String fieldName, T[] val) throws BinaryObjectException {
+        add(fieldName, BinaryWriteMode.ENUM_ARR);
+    }
+
+    /** {@inheritDoc} */
+    @Override public void writeObject(String fieldName, @Nullable Object obj) throws BinaryObjectException {
+        add(fieldName, BinaryWriteMode.OBJECT);
+    }
+
+    /** {@inheritDoc} */
+    @Override public void writeByteArray(String fieldName, @Nullable byte[] val) throws BinaryObjectException {
+        add(fieldName, BinaryWriteMode.BYTE_ARR);
+    }
+
+    /** {@inheritDoc} */
+    @Override public void writeShortArray(String fieldName, @Nullable short[] val) throws BinaryObjectException {
+        add(fieldName, BinaryWriteMode.SHORT_ARR);
+    }
+
+    /** {@inheritDoc} */
+    @Override public void writeIntArray(String fieldName, @Nullable int[] val) throws BinaryObjectException {
+        add(fieldName, BinaryWriteMode.INT_ARR);
+    }
+
+    /** {@inheritDoc} */
+    @Override public void writeLongArray(String fieldName, @Nullable long[] val) throws BinaryObjectException {
+        add(fieldName, BinaryWriteMode.LONG_ARR);
+    }
+
+    /** {@inheritDoc} */
+    @Override public void writeFloatArray(String fieldName, @Nullable float[] val) throws BinaryObjectException {
+        add(fieldName, BinaryWriteMode.FLOAT_ARR);
+    }
+
+    /** {@inheritDoc} */
+    @Override public void writeDoubleArray(String fieldName, @Nullable double[] val) throws BinaryObjectException {
+        add(fieldName, BinaryWriteMode.DOUBLE_ARR);
+    }
+
+    /** {@inheritDoc} */
+    @Override public void writeCharArray(String fieldName, @Nullable char[] val) throws BinaryObjectException {
+        add(fieldName, BinaryWriteMode.CHAR_ARR);
+    }
+
+    /** {@inheritDoc} */
+    @Override public void writeBooleanArray(String fieldName, @Nullable boolean[] val) throws BinaryObjectException {
+        add(fieldName, BinaryWriteMode.BOOLEAN_ARR);
+    }
+
+    /** {@inheritDoc} */
+    @Override public void writeDecimalArray(String fieldName, @Nullable BigDecimal[] val) throws BinaryObjectException {
+        add(fieldName, BinaryWriteMode.DECIMAL_ARR);
+    }
+
+    /** {@inheritDoc} */
+    @Override public void writeStringArray(String fieldName, @Nullable String[] val) throws BinaryObjectException {
+        add(fieldName, BinaryWriteMode.STRING_ARR);
+    }
+
+    /** {@inheritDoc} */
+    @Override public void writeUuidArray(String fieldName, @Nullable UUID[] val) throws BinaryObjectException {
+        add(fieldName, BinaryWriteMode.UUID_ARR);
+    }
+
+    /** {@inheritDoc} */
+    @Override public void writeDateArray(String fieldName, @Nullable Date[] val) throws BinaryObjectException {
+        add(fieldName, BinaryWriteMode.DATE_ARR);
+    }
+
+    /** {@inheritDoc} */
+    @Override public void writeTimestampArray(String fieldName, @Nullable Timestamp[] val) throws BinaryObjectException {
+        add(fieldName, BinaryWriteMode.TIMESTAMP_ARR);
+    }
+
+    /** {@inheritDoc} */
+    @Override public void writeObjectArray(String fieldName, @Nullable Object[] val) throws BinaryObjectException {
+        add(fieldName, BinaryWriteMode.OBJECT_ARR);
+    }
+
+    /** {@inheritDoc} */
+    @Override public <T> void writeCollection(String fieldName, @Nullable Collection<T> col)
+        throws BinaryObjectException {
+        add(fieldName, BinaryWriteMode.COL);
+    }
+
+    /** {@inheritDoc} */
+    @Override public <K, V> void writeMap(String fieldName, @Nullable Map<K, V> map) throws BinaryObjectException {
+        add(fieldName, BinaryWriteMode.MAP);
+    }
+
+    /** {@inheritDoc} */
+    @Override public BinaryRawWriter rawWriter() {
+        return (BinaryRawWriter)Proxy.newProxyInstance(getClass().getClassLoader(),
+            new Class<?>[] { BinaryRawWriterEx.class },
+            new InvocationHandler() {
+                @Override public Object invoke(Object proxy, Method mtd, Object[] args) throws Throwable {
+                    return null;
+                }
+            });
+    }
+
+    /**
+     * @param name Field name.
+     * @param mode Field mode.
+     * @throws BinaryObjectException In case of error.
+     */
+    private void add(String name, BinaryWriteMode mode) throws BinaryObjectException {
+        assert name != null;
+
+        int fieldTypeId = mode.typeId();
+
+        Integer oldFieldTypeId = meta.put(name, fieldTypeId);
+
+        if (oldFieldTypeId != null && !oldFieldTypeId.equals(fieldTypeId)) {
+            throw new BinaryObjectException(
+                "Field is written twice with different types [" + "typeName=" + typeName + ", fieldName=" + name +
+                ", fieldTypeName1=" + PortableUtils.fieldTypeName(oldFieldTypeId) +
+                ", fieldTypeName2=" + PortableUtils.fieldTypeName(fieldTypeId) + ']'
+            );
+        }
+
+        schemaBuilder.addField(idMapper.fieldId(typeId, name));
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/1dbf20e0/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryMetadataHandler.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryMetadataHandler.java b/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryMetadataHandler.java
new file mode 100644
index 0000000..fea2893
--- /dev/null
+++ b/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryMetadataHandler.java
@@ -0,0 +1,44 @@
+/*
+ * 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.binary;
+
+import org.apache.ignite.binary.BinaryObjectException;
+import org.apache.ignite.binary.BinaryType;
+
+/**
+ * Portable meta data handler.
+ */
+public interface BinaryMetadataHandler {
+    /**
+     * Adds meta data.
+     *
+     * @param typeId Type ID.
+     * @param meta Meta data.
+     * @throws org.apache.ignite.binary.BinaryObjectException In case of error.
+     */
+    public void addMeta(int typeId, BinaryType meta) throws BinaryObjectException;
+
+    /**
+     * Gets meta data for provided type ID.
+     *
+     * @param typeId Type ID.
+     * @return Meta data.
+     * @throws org.apache.ignite.binary.BinaryObjectException In case of error.
+     */
+    public BinaryType metadata(int typeId) throws BinaryObjectException;
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/1dbf20e0/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryNoopMetadataHandler.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryNoopMetadataHandler.java b/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryNoopMetadataHandler.java
new file mode 100644
index 0000000..9c0c37d
--- /dev/null
+++ b/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryNoopMetadataHandler.java
@@ -0,0 +1,53 @@
+/*
+ * 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.binary;
+
+import org.apache.ignite.binary.BinaryObjectException;
+import org.apache.ignite.binary.BinaryType;
+
+/**
+ * No-op metadata handler.
+ */
+public class BinaryNoopMetadataHandler implements BinaryMetadataHandler {
+    /** Cached singleton instance. */
+    private static final BinaryNoopMetadataHandler INSTANCE = new BinaryNoopMetadataHandler();
+
+    /**
+     * @return Instance.
+     */
+    public static BinaryNoopMetadataHandler instance() {
+        return INSTANCE;
+    }
+
+    /**
+     * Private constructor.
+     */
+    private BinaryNoopMetadataHandler() {
+        // No-op.
+    }
+
+    /** {@inheritDoc} */
+    @Override public void addMeta(int typeId, BinaryType meta) throws BinaryObjectException {
+        // No-op.
+    }
+
+    /** {@inheritDoc} */
+    @Override public BinaryType metadata(int typeId) throws BinaryObjectException {
+        return null;
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/1dbf20e0/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryObjectEx.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryObjectEx.java b/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryObjectEx.java
new file mode 100644
index 0000000..ba15d13
--- /dev/null
+++ b/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryObjectEx.java
@@ -0,0 +1,30 @@
+/*
+ * 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.binary;
+
+import org.apache.ignite.binary.BinaryObject;
+
+/**
+ * Extended binary object interface.
+ */
+public interface BinaryObjectEx extends BinaryObject {
+    /**
+     * @return Type ID.
+     */
+    public int typeId();
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/1dbf20e0/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryObjectExImpl.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryObjectExImpl.java b/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryObjectExImpl.java
new file mode 100644
index 0000000..d09bc28
--- /dev/null
+++ b/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryObjectExImpl.java
@@ -0,0 +1,251 @@
+/*
+ * 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.binary;
+
+import java.math.BigDecimal;
+import java.util.Arrays;
+import java.util.IdentityHashMap;
+import org.apache.ignite.IgniteException;
+import org.apache.ignite.internal.util.offheap.unsafe.GridUnsafeMemory;
+import org.apache.ignite.internal.util.typedef.internal.SB;
+import org.apache.ignite.binary.BinaryObjectException;
+import org.apache.ignite.binary.BinaryType;
+import org.apache.ignite.binary.BinaryObject;
+import org.jetbrains.annotations.Nullable;
+
+/**
+ * Internal portable object interface.
+ */
+public abstract class BinaryObjectExImpl implements BinaryObjectEx {
+    /**
+     * @return Length.
+     */
+    public abstract int length();
+
+    /**
+     * @return Object start.
+     */
+    public abstract int start();
+
+    /**
+     * @return {@code True} if object is array based.
+     */
+    protected abstract boolean hasArray();
+
+    /**
+     * @return Object array if object is array based, otherwise {@code null}.
+     */
+    public abstract byte[] array();
+
+    /**
+     * @return Object offheap address is object is offheap based, otherwise 0.
+     */
+    public abstract long offheapAddress();
+
+    /**
+     * Gets field value.
+     *
+     * @param fieldId Field ID.
+     * @return Field value.
+     * @throws org.apache.ignite.binary.BinaryObjectException In case of any other error.
+     */
+    @Nullable public abstract <F> F field(int fieldId) throws BinaryObjectException;
+
+    /** {@inheritDoc} */
+    @Override public int enumOrdinal() throws BinaryObjectException {
+        throw new BinaryObjectException("Object is not enum.");
+    }
+
+    /**
+     * Get field by offset.
+     *
+     * @param fieldOffset Field offset.
+     * @return Field value.
+     */
+    @Nullable protected abstract <F> F fieldByOrder(int fieldOffset);
+
+    /**
+     * @param ctx Reader context.
+     * @param fieldName Field name.
+     * @return Field value.
+     */
+    @Nullable protected abstract <F> F field(BinaryReaderHandles ctx, String fieldName);
+
+    /**
+     * Get schema ID.
+     *
+     * @return Schema ID.
+     */
+    protected abstract int schemaId();
+
+    /**
+     * Create schema for object.
+     *
+     * @return Schema.
+     */
+    protected abstract PortableSchema createSchema();
+
+    /** {@inheritDoc} */
+    @Override public BinaryObject clone() throws CloneNotSupportedException {
+        return (BinaryObject)super.clone();
+    }
+
+    /** {@inheritDoc} */
+    public boolean equals(Object other) {
+        if (other == this)
+            return true;
+
+        if (other == null)
+            return false;
+
+        if (!(other instanceof BinaryObjectExImpl))
+            return false;
+
+        BinaryObjectExImpl otherPo = (BinaryObjectExImpl)other;
+
+        if (length() != otherPo.length() || typeId() != otherPo.typeId())
+            return false;
+
+        if (hasArray()) {
+            if (otherPo.hasArray()) {
+                int len = length();
+                int end = start() + len;
+
+                byte[] arr = array();
+                byte[] otherArr = otherPo.array();
+
+                for (int i = start(), j = otherPo.start(); i < end; i++, j++) {
+                    if (arr[i] != otherArr[j])
+                        return false;
+                }
+
+                return true;
+            }
+            else {
+                assert otherPo.offheapAddress() > 0;
+
+                return GridUnsafeMemory.compare(otherPo.offheapAddress() + otherPo.start(), array());
+            }
+        }
+        else {
+            assert offheapAddress() > 0;
+
+            if (otherPo.hasArray())
+                return GridUnsafeMemory.compare(offheapAddress() + start(), otherPo.array());
+            else {
+                assert otherPo.offheapAddress() > 0;
+
+                return GridUnsafeMemory.compare(offheapAddress() + start(),
+                    otherPo.offheapAddress() + otherPo.start(),
+                    length());
+            }
+        }
+    }
+
+    /**
+     * @param ctx Reader context.
+     * @param handles Handles for already traversed objects.
+     * @return String representation.
+     */
+    private String toString(BinaryReaderHandles ctx, IdentityHashMap<BinaryObject, Integer> handles) {
+        int idHash = System.identityHashCode(this);
+        int hash = hashCode();
+
+        BinaryType meta;
+
+        try {
+            meta = type();
+        }
+        catch (BinaryObjectException ignore) {
+            meta = null;
+        }
+
+        if (meta == null)
+            return BinaryObject.class.getSimpleName() +  " [idHash=" + idHash + ", hash=" + hash + ", typeId=" + typeId() + ']';
+
+        handles.put(this, idHash);
+
+        SB buf = new SB(meta.typeName());
+
+        if (meta.fieldNames() != null) {
+            buf.a(" [idHash=").a(idHash).a(", hash=").a(hash);
+
+            for (String name : meta.fieldNames()) {
+                Object val = field(ctx, name);
+
+                buf.a(", ").a(name).a('=');
+
+                if (val instanceof byte[])
+                    buf.a(Arrays.toString((byte[]) val));
+                else if (val instanceof short[])
+                    buf.a(Arrays.toString((short[])val));
+                else if (val instanceof int[])
+                    buf.a(Arrays.toString((int[])val));
+                else if (val instanceof long[])
+                    buf.a(Arrays.toString((long[])val));
+                else if (val instanceof float[])
+                    buf.a(Arrays.toString((float[])val));
+                else if (val instanceof double[])
+                    buf.a(Arrays.toString((double[])val));
+                else if (val instanceof char[])
+                    buf.a(Arrays.toString((char[])val));
+                else if (val instanceof boolean[])
+                    buf.a(Arrays.toString((boolean[]) val));
+                else if (val instanceof BigDecimal[])
+                    buf.a(Arrays.toString((BigDecimal[])val));
+                else {
+                    if (val instanceof BinaryObjectExImpl) {
+                        BinaryObjectExImpl po = (BinaryObjectExImpl)val;
+
+                        Integer idHash0 = handles.get(val);
+
+                        if (idHash0 != null) {  // Circular reference.
+                            BinaryType meta0 = po.type();
+
+                            assert meta0 != null;
+
+                            buf.a(meta0.typeName()).a(" [hash=").a(idHash0).a(", ...]");
+                        }
+                        else
+                            buf.a(po.toString(ctx, handles));
+                    }
+                    else
+                        buf.a(val);
+                }
+            }
+
+            buf.a(']');
+        }
+
+        return buf.toString();
+    }
+
+    /** {@inheritDoc} */
+    @Override public String toString() {
+        try {
+            BinaryReaderHandles ctx = new BinaryReaderHandles();
+
+            ctx.put(start(), this);
+
+            return toString(ctx, new IdentityHashMap<BinaryObject, Integer>());
+        }
+        catch (BinaryObjectException e) {
+            throw new IgniteException("Failed to create string representation of portable object.", e);
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/1dbf20e0/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryObjectImpl.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryObjectImpl.java b/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryObjectImpl.java
new file mode 100644
index 0000000..a23330e
--- /dev/null
+++ b/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryObjectImpl.java
@@ -0,0 +1,570 @@
+/*
+ * 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.binary;
+
+import java.io.Externalizable;
+import java.io.IOException;
+import java.io.ObjectInput;
+import java.io.ObjectOutput;
+import java.math.BigDecimal;
+import java.math.BigInteger;
+import java.nio.ByteBuffer;
+import java.sql.Timestamp;
+import java.util.Date;
+import java.util.UUID;
+import org.apache.ignite.IgniteCheckedException;
+import org.apache.ignite.binary.BinaryObject;
+import org.apache.ignite.binary.BinaryObjectException;
+import org.apache.ignite.binary.BinaryType;
+import org.apache.ignite.internal.GridDirectTransient;
+import org.apache.ignite.internal.IgniteCodeGeneratingFail;
+import org.apache.ignite.internal.binary.streams.PortableHeapInputStream;
+import org.apache.ignite.internal.processors.cache.CacheObject;
+import org.apache.ignite.internal.processors.cache.CacheObjectContext;
+import org.apache.ignite.internal.processors.cache.KeyCacheObject;
+import org.apache.ignite.internal.processors.cache.binary.CacheObjectBinaryProcessorImpl;
+import org.apache.ignite.internal.util.typedef.internal.U;
+import org.apache.ignite.plugin.extensions.communication.MessageReader;
+import org.apache.ignite.plugin.extensions.communication.MessageWriter;
+import org.jetbrains.annotations.Nullable;
+
+import static java.nio.charset.StandardCharsets.UTF_8;
+
+/**
+ * Portable object implementation.
+ */
+@IgniteCodeGeneratingFail // Fields arr and start should not be generated by MessageCodeGenerator.
+public final class BinaryObjectImpl extends BinaryObjectExImpl implements Externalizable, KeyCacheObject {
+    /** */
+    private static final long serialVersionUID = 0L;
+
+    /** */
+    @GridDirectTransient
+    private PortableContext ctx;
+
+    /** */
+    private byte[] arr;
+
+    /** */
+    private int start;
+
+    /** */
+    @GridDirectTransient
+    private Object obj;
+
+    /** */
+    @GridDirectTransient
+    private boolean detachAllowed;
+
+    /**
+     * For {@link Externalizable}.
+     */
+    public BinaryObjectImpl() {
+        // No-op.
+    }
+
+    /**
+     * @param ctx Context.
+     * @param arr Array.
+     * @param start Start.
+     */
+    public BinaryObjectImpl(PortableContext ctx, byte[] arr, int start) {
+        assert ctx != null;
+        assert arr != null;
+
+        this.ctx = ctx;
+        this.arr = arr;
+        this.start = start;
+    }
+
+    /** {@inheritDoc} */
+    @Override public byte cacheObjectType() {
+        return TYPE_BINARY;
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean isPlatformType() {
+        return false;
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean internal() {
+        return false;
+    }
+
+    /** {@inheritDoc} */
+    @SuppressWarnings("unchecked")
+    @Nullable @Override public <T> T value(CacheObjectContext ctx, boolean cpy) {
+        Object obj0 = obj;
+
+        if (obj0 == null || (cpy && needCopy(ctx)))
+            obj0 = deserializeValue(ctx);
+
+        return (T)obj0;
+    }
+
+    /** {@inheritDoc} */
+    @Override public byte[] valueBytes(CacheObjectContext ctx) throws IgniteCheckedException {
+        if (detached())
+            return array();
+
+        int len = length();
+
+        byte[] arr0 = new byte[len];
+
+        U.arrayCopy(arr, start, arr0, 0, len);
+
+        return arr0;
+    }
+
+    /** {@inheritDoc} */
+    @Override public CacheObject prepareForCache(CacheObjectContext ctx) {
+        if (detached())
+            return this;
+
+        return (BinaryObjectImpl)detach();
+    }
+
+    /** {@inheritDoc} */
+    @Override public void finishUnmarshal(CacheObjectContext ctx, ClassLoader ldr) throws IgniteCheckedException {
+        this.ctx = ((CacheObjectBinaryProcessorImpl)ctx.processor()).portableContext();
+    }
+
+    /** {@inheritDoc} */
+    @Override public void prepareMarshal(CacheObjectContext ctx) throws IgniteCheckedException {
+        // No-op.
+    }
+
+    /** {@inheritDoc} */
+    @Override public int length() {
+        return PortablePrimitives.readInt(arr, start + GridPortableMarshaller.TOTAL_LEN_POS);
+    }
+
+    /**
+     * @return Detached portable object.
+     */
+    public BinaryObject detach() {
+        if (!detachAllowed || detached())
+            return this;
+
+        int len = length();
+
+        byte[] arr0 = new byte[len];
+
+        U.arrayCopy(arr, start, arr0, 0, len);
+
+        return new BinaryObjectImpl(ctx, arr0, 0);
+    }
+
+    /**
+     * @return Detached or not.
+     */
+    public boolean detached() {
+        return start == 0 && length() == arr.length;
+    }
+
+    /**
+     * @param detachAllowed Detach allowed flag.
+     */
+    public void detachAllowed(boolean detachAllowed) {
+        this.detachAllowed = detachAllowed;
+    }
+
+    /**
+     * @return Context.
+     */
+    public PortableContext context() {
+        return ctx;
+    }
+
+    /**
+     * @param ctx Context.
+     */
+    public void context(PortableContext ctx) {
+        this.ctx = ctx;
+    }
+
+    /** {@inheritDoc} */
+    @Override public byte[] array() {
+        return arr;
+    }
+
+    /** {@inheritDoc} */
+    @Override public int start() {
+        return start;
+    }
+
+    /** {@inheritDoc} */
+    @Override public long offheapAddress() {
+        return 0;
+    }
+
+    /** {@inheritDoc} */
+    @Override protected boolean hasArray() {
+        return true;
+    }
+
+    /** {@inheritDoc} */
+    @Override public int typeId() {
+        return PortablePrimitives.readInt(arr, start + GridPortableMarshaller.TYPE_ID_POS);
+    }
+
+    /** {@inheritDoc} */
+    @Nullable @Override public BinaryType type() throws BinaryObjectException {
+        if (ctx == null)
+            throw new BinaryObjectException("PortableContext is not set for the object.");
+
+        return ctx.metadata(typeId());
+    }
+
+    /** {@inheritDoc} */
+    @SuppressWarnings("unchecked")
+    @Nullable @Override public <F> F field(String fieldName) throws BinaryObjectException {
+        return (F) reader(null).unmarshalField(fieldName);
+    }
+
+    /** {@inheritDoc} */
+    @SuppressWarnings("unchecked")
+    @Nullable @Override public <F> F field(int fieldId) throws BinaryObjectException {
+        return (F) reader(null).unmarshalField(fieldId);
+    }
+
+    /** {@inheritDoc} */
+    @SuppressWarnings("unchecked")
+    @Nullable @Override protected <F> F fieldByOrder(int order) {
+        Object val;
+
+        // Calculate field position.
+        int schemaOffset = PortablePrimitives.readInt(arr, start + GridPortableMarshaller.SCHEMA_OR_RAW_OFF_POS);
+
+        short flags = PortablePrimitives.readShort(arr, start + GridPortableMarshaller.FLAGS_POS);
+
+        int fieldIdLen = PortableUtils.isCompactFooter(flags) ? 0 : PortableUtils.FIELD_ID_LEN;
+        int fieldOffsetLen = PortableUtils.fieldOffsetLength(flags);
+
+        int fieldOffsetPos = start + schemaOffset + order * (fieldIdLen + fieldOffsetLen) + fieldIdLen;
+
+        int fieldPos;
+
+        if (fieldOffsetLen == PortableUtils.OFFSET_1)
+            fieldPos = start + ((int)PortablePrimitives.readByte(arr, fieldOffsetPos) & 0xFF);
+        else if (fieldOffsetLen == PortableUtils.OFFSET_2)
+            fieldPos = start + ((int)PortablePrimitives.readShort(arr, fieldOffsetPos) & 0xFFFF);
+        else
+            fieldPos = start + PortablePrimitives.readInt(arr, fieldOffsetPos);
+
+        // Read header and try performing fast lookup for well-known types (the most common types go first).
+        byte hdr = PortablePrimitives.readByte(arr, fieldPos);
+
+        switch (hdr) {
+            case GridPortableMarshaller.INT:
+                val = PortablePrimitives.readInt(arr, fieldPos + 1);
+
+                break;
+
+            case GridPortableMarshaller.LONG:
+                val = PortablePrimitives.readLong(arr, fieldPos + 1);
+
+                break;
+
+            case GridPortableMarshaller.BOOLEAN:
+                val = PortablePrimitives.readBoolean(arr, fieldPos + 1);
+
+                break;
+
+            case GridPortableMarshaller.SHORT:
+                val = PortablePrimitives.readShort(arr, fieldPos + 1);
+
+                break;
+
+            case GridPortableMarshaller.BYTE:
+                val = PortablePrimitives.readByte(arr, fieldPos + 1);
+
+                break;
+
+            case GridPortableMarshaller.CHAR:
+                val = PortablePrimitives.readChar(arr, fieldPos + 1);
+
+                break;
+
+            case GridPortableMarshaller.FLOAT:
+                val = PortablePrimitives.readFloat(arr, fieldPos + 1);
+
+                break;
+
+            case GridPortableMarshaller.DOUBLE:
+                val = PortablePrimitives.readDouble(arr, fieldPos + 1);
+
+                break;
+
+            case GridPortableMarshaller.STRING: {
+                int dataLen = PortablePrimitives.readInt(arr, fieldPos + 1);
+
+                val = new String(arr, fieldPos + 5, dataLen, UTF_8);
+
+                break;
+            }
+
+            case GridPortableMarshaller.DATE: {
+                long time = PortablePrimitives.readLong(arr, fieldPos + 1);
+
+                val = new Date(time);
+
+                break;
+            }
+
+            case GridPortableMarshaller.TIMESTAMP: {
+                long time = PortablePrimitives.readLong(arr, fieldPos + 1);
+                int nanos = PortablePrimitives.readInt(arr, fieldPos + 1 + 8);
+
+                Timestamp ts = new Timestamp(time);
+
+                ts.setNanos(ts.getNanos() + nanos);
+
+                val = ts;
+
+                break;
+            }
+
+            case GridPortableMarshaller.UUID: {
+                long most = PortablePrimitives.readLong(arr, fieldPos + 1);
+                long least = PortablePrimitives.readLong(arr, fieldPos + 1 + 8);
+
+                val = new UUID(most, least);
+
+                break;
+            }
+
+            case GridPortableMarshaller.DECIMAL: {
+                int scale = PortablePrimitives.readInt(arr, fieldPos + 1);
+
+                int dataLen = PortablePrimitives.readInt(arr, fieldPos + 5);
+                byte[] data = PortablePrimitives.readByteArray(arr, fieldPos + 9, dataLen);
+
+                BigInteger intVal = new BigInteger(data);
+
+                if (scale < 0) {
+                    scale &= 0x7FFFFFFF;
+
+                    intVal = intVal.negate();
+                }
+
+                val = new BigDecimal(intVal, scale);
+
+                break;
+            }
+
+            case GridPortableMarshaller.NULL:
+                val = null;
+
+                break;
+
+            default:
+                val = PortableUtils.unmarshal(PortableHeapInputStream.create(arr, fieldPos), ctx, null);
+
+                break;
+        }
+
+        return (F)val;
+    }
+
+    /** {@inheritDoc} */
+    @SuppressWarnings("unchecked")
+    @Nullable @Override protected <F> F field(BinaryReaderHandles rCtx, String fieldName) {
+        return (F)reader(rCtx).unmarshalField(fieldName);
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean hasField(String fieldName) {
+        return reader(null).findFieldByName(fieldName);
+    }
+
+    /** {@inheritDoc} */
+    @SuppressWarnings("unchecked")
+    @Nullable @Override public <T> T deserialize() throws BinaryObjectException {
+        Object obj0 = obj;
+
+        if (obj0 == null)
+            obj0 = deserializeValue(null);
+
+        return (T)obj0;
+    }
+
+    /** {@inheritDoc} */
+    @Override public BinaryObject clone() throws CloneNotSupportedException {
+        return super.clone();
+    }
+
+    /** {@inheritDoc} */
+    @Override public int hashCode() {
+        return PortablePrimitives.readInt(arr, start + GridPortableMarshaller.HASH_CODE_POS);
+    }
+
+    /** {@inheritDoc} */
+    @Override protected int schemaId() {
+        return PortablePrimitives.readInt(arr, start + GridPortableMarshaller.SCHEMA_ID_POS);
+    }
+
+    /** {@inheritDoc} */
+    @Override protected PortableSchema createSchema() {
+        return reader(null).getOrCreateSchema();
+    }
+
+    /** {@inheritDoc} */
+    @Override public void writeExternal(ObjectOutput out) throws IOException {
+        out.writeObject(ctx);
+
+        if (detachAllowed) {
+            int len = length();
+
+            out.writeInt(len);
+            out.write(arr, start, len);
+            out.writeInt(0);
+        }
+        else {
+            out.writeInt(arr.length);
+            out.write(arr);
+            out.writeInt(start);
+        }
+    }
+
+    /** {@inheritDoc} */
+    @Override public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
+        ctx = (PortableContext)in.readObject();
+
+        arr = new byte[in.readInt()];
+
+        in.readFully(arr);
+
+        start = in.readInt();
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean writeTo(ByteBuffer buf, MessageWriter writer) {
+        writer.setBuffer(buf);
+
+        if (!writer.isHeaderWritten()) {
+            if (!writer.writeHeader(directType(), fieldsCount()))
+                return false;
+
+            writer.onHeaderWritten();
+        }
+
+        switch (writer.state()) {
+            case 0:
+                if (!writer.writeByteArray("arr",
+                    arr,
+                    detachAllowed ? start : 0,
+                    detachAllowed ? length() : arr.length))
+                    return false;
+
+                writer.incrementState();
+
+            case 1:
+                if (!writer.writeInt("start", detachAllowed ? 0 : start))
+                    return false;
+
+                writer.incrementState();
+
+        }
+
+        return true;
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean readFrom(ByteBuffer buf, MessageReader reader) {
+        reader.setBuffer(buf);
+
+        if (!reader.beforeMessageRead())
+            return false;
+
+        switch (reader.state()) {
+            case 0:
+                arr = reader.readByteArray("arr");
+
+                if (!reader.isLastRead())
+                    return false;
+
+                reader.incrementState();
+
+            case 1:
+                start = reader.readInt("start");
+
+                if (!reader.isLastRead())
+                    return false;
+
+                reader.incrementState();
+
+        }
+
+        return true;
+    }
+
+    /** {@inheritDoc} */
+    @Override public byte directType() {
+        return 113;
+    }
+
+    /** {@inheritDoc} */
+    @Override public byte fieldsCount() {
+        return 3;
+    }
+
+    /**
+     * Runs value deserialization regardless of whether obj already has the deserialized value.
+     * Will set obj if descriptor is configured to keep deserialized values.
+     * @param coCtx CacheObjectContext.
+     * @return Object.
+     */
+    private Object deserializeValue(@Nullable CacheObjectContext coCtx) {
+        // TODO: IGNITE-1272 - Deserialize with proper class loader.
+        BinaryReaderExImpl reader = reader(null);
+
+        Object obj0 = reader.deserialize();
+
+        PortableClassDescriptor desc = reader.descriptor();
+
+        assert desc != null;
+
+        if (coCtx != null && coCtx.storeValue())
+            obj = obj0;
+
+        return obj0;
+    }
+
+    /**
+     * @param ctx Context.
+     * @return {@code True} need to copy value returned to user.
+     */
+    private boolean needCopy(CacheObjectContext ctx) {
+        return ctx.copyOnGet() && obj != null && !ctx.processor().immutable(obj);
+    }
+
+    /**
+     * Create new reader for this object.
+     *
+     * @param rCtx Reader context.
+     * @return Reader.
+     */
+    private BinaryReaderExImpl reader(@Nullable BinaryReaderHandles rCtx) {
+        return new BinaryReaderExImpl(ctx,
+            PortableHeapInputStream.create(arr, start),
+            ctx.configuration().getClassLoader(),
+            rCtx);
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/1dbf20e0/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryObjectOffheapImpl.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryObjectOffheapImpl.java b/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryObjectOffheapImpl.java
new file mode 100644
index 0000000..27b46c1
--- /dev/null
+++ b/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryObjectOffheapImpl.java
@@ -0,0 +1,430 @@
+/*
+ * 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.binary;
+
+import org.apache.ignite.IgniteCheckedException;
+import org.apache.ignite.binary.BinaryObject;
+import org.apache.ignite.binary.BinaryObjectException;
+import org.apache.ignite.binary.BinaryType;
+import org.apache.ignite.internal.binary.streams.PortableOffheapInputStream;
+import org.apache.ignite.internal.binary.streams.PortableOffheapInputStream;
+import org.apache.ignite.internal.processors.cache.CacheObject;
+import org.apache.ignite.internal.processors.cache.CacheObjectContext;
+import org.apache.ignite.internal.util.GridUnsafe;
+import org.apache.ignite.internal.util.typedef.internal.U;
+import org.apache.ignite.plugin.extensions.communication.MessageReader;
+import org.apache.ignite.plugin.extensions.communication.MessageWriter;
+import org.jetbrains.annotations.Nullable;
+import sun.misc.Unsafe;
+
+import java.io.Externalizable;
+import java.io.IOException;
+import java.io.ObjectInput;
+import java.io.ObjectOutput;
+import java.math.BigDecimal;
+import java.math.BigInteger;
+import java.nio.ByteBuffer;
+import java.sql.Timestamp;
+import java.util.Date;
+import java.util.UUID;
+
+import static java.nio.charset.StandardCharsets.UTF_8;
+import static org.apache.ignite.internal.binary.GridPortableMarshaller.BOOLEAN;
+import static org.apache.ignite.internal.binary.GridPortableMarshaller.BYTE;
+import static org.apache.ignite.internal.binary.GridPortableMarshaller.CHAR;
+import static org.apache.ignite.internal.binary.GridPortableMarshaller.DATE;
+import static org.apache.ignite.internal.binary.GridPortableMarshaller.DECIMAL;
+import static org.apache.ignite.internal.binary.GridPortableMarshaller.DOUBLE;
+import static org.apache.ignite.internal.binary.GridPortableMarshaller.FLOAT;
+import static org.apache.ignite.internal.binary.GridPortableMarshaller.INT;
+import static org.apache.ignite.internal.binary.GridPortableMarshaller.LONG;
+import static org.apache.ignite.internal.binary.GridPortableMarshaller.NULL;
+import static org.apache.ignite.internal.binary.GridPortableMarshaller.SHORT;
+import static org.apache.ignite.internal.binary.GridPortableMarshaller.STRING;
+import static org.apache.ignite.internal.binary.GridPortableMarshaller.TIMESTAMP;
+import static org.apache.ignite.internal.binary.GridPortableMarshaller.UUID;
+
+/**
+ *  Portable object implementation over offheap memory
+ */
+public class BinaryObjectOffheapImpl extends BinaryObjectExImpl implements Externalizable, CacheObject {
+    /** */
+    private static final long serialVersionUID = 0L;
+
+    /** */
+    private static final Unsafe UNSAFE = GridUnsafe.unsafe();
+
+    /** */
+    private final PortableContext ctx;
+
+    /** */
+    private final long ptr;
+
+    /** */
+    private final int start;
+
+    /** */
+    private final int size;
+
+    /**
+     * For {@link Externalizable} (not supported).
+     */
+    public BinaryObjectOffheapImpl() {
+        throw new UnsupportedOperationException();
+    }
+
+    /**
+     * @param ctx Context.
+     * @param ptr Memory address.
+     * @param start Object start.
+     * @param size Memory size.
+     */
+    public BinaryObjectOffheapImpl(PortableContext ctx, long ptr, int start, int size) {
+        this.ctx = ctx;
+        this.ptr = ptr;
+        this.start = start;
+        this.size = size;
+    }
+
+    /**
+     * @return Heap-based copy.
+     */
+    public BinaryObject heapCopy() {
+        return new BinaryObjectImpl(ctx, U.copyMemory(ptr, size), start);
+    }
+
+    /** {@inheritDoc} */
+    @Override public int typeId() {
+        return UNSAFE.getInt(ptr + start + GridPortableMarshaller.TYPE_ID_POS);
+    }
+
+    /** {@inheritDoc} */
+    @Override public int length() {
+        return UNSAFE.getInt(ptr + start + GridPortableMarshaller.TOTAL_LEN_POS);
+    }
+
+    /** {@inheritDoc} */
+    @Override public int hashCode() {
+        return UNSAFE.getInt(ptr + start + GridPortableMarshaller.HASH_CODE_POS);
+    }
+
+    /** {@inheritDoc} */
+    @Override protected int schemaId() {
+        return UNSAFE.getInt(ptr + start + GridPortableMarshaller.SCHEMA_ID_POS);
+    }
+
+    /** {@inheritDoc} */
+    @Override protected PortableSchema createSchema() {
+        return reader(null).getOrCreateSchema();
+    }
+
+    /** {@inheritDoc} */
+    @Override public int start() {
+        return start;
+    }
+
+    /** {@inheritDoc} */
+    @Override public byte[] array() {
+        return null;
+    }
+
+    /** {@inheritDoc} */
+    @Override public long offheapAddress() {
+        return ptr;
+    }
+
+    /** {@inheritDoc} */
+    @Override protected boolean hasArray() {
+        return false;
+    }
+
+    /** {@inheritDoc} */
+    @Nullable @Override public BinaryType type() throws BinaryObjectException {
+        if (ctx == null)
+            throw new BinaryObjectException("PortableContext is not set for the object.");
+
+        return ctx.metadata(typeId());
+    }
+
+    /** {@inheritDoc} */
+    @SuppressWarnings("unchecked")
+    @Nullable @Override public <F> F field(String fieldName) throws BinaryObjectException {
+        return (F) reader(null).unmarshalField(fieldName);
+    }
+
+    /** {@inheritDoc} */
+    @SuppressWarnings("unchecked")
+    @Nullable @Override public <F> F field(int fieldId) throws BinaryObjectException {
+        return (F) reader(null).unmarshalField(fieldId);
+    }
+
+    /** {@inheritDoc} */
+    @SuppressWarnings("unchecked")
+    @Nullable @Override protected <F> F fieldByOrder(int order) {
+        Object val;
+
+        // Calculate field position.
+        int schemaOffset = PortablePrimitives.readInt(ptr, start + GridPortableMarshaller.SCHEMA_OR_RAW_OFF_POS);
+
+        short flags = PortablePrimitives.readShort(ptr, start + GridPortableMarshaller.FLAGS_POS);
+
+        int fieldIdLen = PortableUtils.isCompactFooter(flags) ? 0 : PortableUtils.FIELD_ID_LEN;
+        int fieldOffsetLen = PortableUtils.fieldOffsetLength(flags);
+
+        int fieldOffsetPos = start + schemaOffset + order * (fieldIdLen + fieldOffsetLen) + fieldIdLen;
+
+        int fieldPos;
+
+        if (fieldOffsetLen == PortableUtils.OFFSET_1)
+            fieldPos = start + ((int)PortablePrimitives.readByte(ptr, fieldOffsetPos) & 0xFF);
+        else if (fieldOffsetLen == PortableUtils.OFFSET_2)
+            fieldPos = start + ((int)PortablePrimitives.readShort(ptr, fieldOffsetPos) & 0xFFFF);
+        else
+            fieldPos = start + PortablePrimitives.readInt(ptr, fieldOffsetPos);
+
+        // Read header and try performing fast lookup for well-known types (the most common types go first).
+        byte hdr = PortablePrimitives.readByte(ptr, fieldPos);
+
+        switch (hdr) {
+            case GridPortableMarshaller.INT:
+                val = PortablePrimitives.readInt(ptr, fieldPos + 1);
+
+                break;
+
+            case GridPortableMarshaller.LONG:
+                val = PortablePrimitives.readLong(ptr, fieldPos + 1);
+
+                break;
+
+            case GridPortableMarshaller.BOOLEAN:
+                val = PortablePrimitives.readBoolean(ptr, fieldPos + 1);
+
+                break;
+
+            case GridPortableMarshaller.SHORT:
+                val = PortablePrimitives.readShort(ptr, fieldPos + 1);
+
+                break;
+
+            case GridPortableMarshaller.BYTE:
+                val = PortablePrimitives.readByte(ptr, fieldPos + 1);
+
+                break;
+
+            case GridPortableMarshaller.CHAR:
+                val = PortablePrimitives.readChar(ptr, fieldPos + 1);
+
+                break;
+
+            case GridPortableMarshaller.FLOAT:
+                val = PortablePrimitives.readFloat(ptr, fieldPos + 1);
+
+                break;
+
+            case GridPortableMarshaller.DOUBLE:
+                val = PortablePrimitives.readDouble(ptr, fieldPos + 1);
+
+                break;
+
+            case GridPortableMarshaller.STRING: {
+                int dataLen = PortablePrimitives.readInt(ptr, fieldPos + 1);
+                byte[] data = PortablePrimitives.readByteArray(ptr, fieldPos + 5, dataLen);
+
+                val = new String(data, UTF_8);
+
+                break;
+            }
+
+            case GridPortableMarshaller.DATE: {
+                long time = PortablePrimitives.readLong(ptr, fieldPos + 1);
+
+                val = new Date(time);
+
+                break;
+            }
+
+            case GridPortableMarshaller.TIMESTAMP: {
+                long time = PortablePrimitives.readLong(ptr, fieldPos + 1);
+                int nanos = PortablePrimitives.readInt(ptr, fieldPos + 1 + 8);
+
+                Timestamp ts = new Timestamp(time);
+
+                ts.setNanos(ts.getNanos() + nanos);
+
+                val = ts;
+
+                break;
+            }
+
+            case GridPortableMarshaller.UUID: {
+                long most = PortablePrimitives.readLong(ptr, fieldPos + 1);
+                long least = PortablePrimitives.readLong(ptr, fieldPos + 1 + 8);
+
+                val = new UUID(most, least);
+
+                break;
+            }
+
+            case GridPortableMarshaller.DECIMAL: {
+                int scale = PortablePrimitives.readInt(ptr, fieldPos + 1);
+
+                int dataLen = PortablePrimitives.readInt(ptr, fieldPos + 5);
+                byte[] data = PortablePrimitives.readByteArray(ptr, fieldPos + 9, dataLen);
+
+                BigInteger intVal = new BigInteger(data);
+
+                if (scale < 0) {
+                    scale &= 0x7FFFFFFF;
+
+                    intVal = intVal.negate();
+                }
+
+                val = new BigDecimal(intVal, scale);
+
+                break;
+            }
+
+            case GridPortableMarshaller.NULL:
+                val = null;
+
+                break;
+
+            default:
+                PortableOffheapInputStream stream = new PortableOffheapInputStream(ptr, size, false);
+
+                stream.position(fieldPos);
+
+                val = PortableUtils.unmarshal(stream, ctx, null);
+
+                break;
+        }
+
+        return (F)val;
+    }
+
+    /** {@inheritDoc} */
+    @SuppressWarnings("unchecked")
+    @Nullable @Override protected <F> F field(BinaryReaderHandles rCtx, String fieldName) {
+        return (F)reader(rCtx).unmarshalField(fieldName);
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean hasField(String fieldName) {
+        return reader(null).findFieldByName(fieldName);
+    }
+
+    /** {@inheritDoc} */
+    @SuppressWarnings("unchecked")
+    @Nullable @Override public <T> T deserialize() throws BinaryObjectException {
+        return (T)deserializeValue();
+    }
+
+    /** {@inheritDoc} */
+    @SuppressWarnings("CloneDoesntCallSuperClone")
+    @Override public BinaryObject clone() throws CloneNotSupportedException {
+        return heapCopy();
+    }
+
+    /** {@inheritDoc} */
+    @Override public byte cacheObjectType() {
+        throw new UnsupportedOperationException();
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean isPlatformType() {
+        return false;
+    }
+
+    /** {@inheritDoc} */
+    @SuppressWarnings("unchecked")
+    @Nullable @Override public <T> T value(CacheObjectContext ctx, boolean cpy) {
+        return (T)deserializeValue();
+    }
+
+    /** {@inheritDoc} */
+    @Override public byte[] valueBytes(CacheObjectContext ctx) throws IgniteCheckedException {
+        throw new UnsupportedOperationException();
+    }
+
+    /** {@inheritDoc} */
+    @Override public CacheObject prepareForCache(CacheObjectContext ctx) {
+        throw new UnsupportedOperationException();
+    }
+
+    /** {@inheritDoc} */
+    @Override public void finishUnmarshal(CacheObjectContext ctx, ClassLoader ldr) throws IgniteCheckedException {
+        throw new UnsupportedOperationException();
+    }
+
+    /** {@inheritDoc} */
+    @Override public void prepareMarshal(CacheObjectContext ctx) throws IgniteCheckedException {
+        throw new UnsupportedOperationException();
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean writeTo(ByteBuffer buf, MessageWriter writer) {
+        throw new UnsupportedOperationException();
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean readFrom(ByteBuffer buf, MessageReader reader) {
+        throw new UnsupportedOperationException();
+    }
+
+    /** {@inheritDoc} */
+    @Override public byte directType() {
+        throw new UnsupportedOperationException();
+    }
+
+    /** {@inheritDoc} */
+    @Override public byte fieldsCount() {
+        throw new UnsupportedOperationException();
+    }
+
+    /** {@inheritDoc} */
+    @Override public void writeExternal(ObjectOutput out) throws IOException {
+        throw new UnsupportedOperationException(); // To make sure it is not marshalled.
+    }
+
+    /** {@inheritDoc} */
+    @Override public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
+        throw new UnsupportedOperationException(); // To make sure it is not marshalled.
+    }
+
+    /**
+     * @return Deserialized value.
+     */
+    private Object deserializeValue() {
+        // TODO: IGNITE-1272 - Deserialize with proper class loader.
+        return reader(null).deserialize();
+    }
+
+    /**
+     * Create new reader for this object.
+     *
+     * @param rCtx Reader context.
+     * @return Reader.
+     */
+    private BinaryReaderExImpl reader(@Nullable BinaryReaderHandles rCtx) {
+        PortableOffheapInputStream stream = new PortableOffheapInputStream(ptr, size, false);
+
+        stream.position(start);
+
+        return new BinaryReaderExImpl(ctx, stream, null, rCtx);
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/1dbf20e0/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryRawReaderEx.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryRawReaderEx.java b/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryRawReaderEx.java
new file mode 100644
index 0000000..603275e
--- /dev/null
+++ b/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryRawReaderEx.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.internal.binary;
+
+import org.apache.ignite.binary.BinaryObjectException;
+import org.apache.ignite.binary.BinaryRawReader;
+import org.jetbrains.annotations.Nullable;
+
+/**
+ * Extended reader interface.
+ */
+public interface BinaryRawReaderEx extends BinaryRawReader {
+    /**
+     * @return Object.
+     * @throws org.apache.ignite.binary.BinaryObjectException In case of error.
+     */
+    @Nullable public Object readObjectDetached() throws BinaryObjectException;
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/1dbf20e0/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryRawWriterEx.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryRawWriterEx.java b/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryRawWriterEx.java
new file mode 100644
index 0000000..6e7e0cb
--- /dev/null
+++ b/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryRawWriterEx.java
@@ -0,0 +1,60 @@
+/*
+ * 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.binary;
+
+import org.apache.ignite.internal.binary.streams.PortableOutputStream;
+import org.apache.ignite.binary.BinaryObjectException;
+import org.apache.ignite.binary.BinaryRawWriter;
+import org.jetbrains.annotations.Nullable;
+
+/**
+ * Extended writer interface.
+ */
+public interface BinaryRawWriterEx extends BinaryRawWriter, AutoCloseable {
+    /**
+     * @param obj Object to write.
+     * @throws org.apache.ignite.binary.BinaryObjectException In case of error.
+     */
+    public void writeObjectDetached(@Nullable Object obj) throws BinaryObjectException;
+
+    /**
+     * @return Output stream.
+     */
+    public PortableOutputStream out();
+
+    /**
+     * Cleans resources.
+     */
+    @Override public void close();
+
+    /**
+     * Reserve a room for an integer.
+     *
+     * @return Position in the stream where value is to be written.
+     */
+    public int reserveInt();
+
+    /**
+     * Write int value at the specific position.
+     *
+     * @param pos Position.
+     * @param val Value.
+     * @throws org.apache.ignite.binary.BinaryObjectException If failed.
+     */
+    public void writeInt(int pos, int val) throws BinaryObjectException;
+}


[13/59] [abbrv] ignite git commit: ignite-2065: rename "portable" packages to "binary"

Posted by ak...@apache.org.
http://git-wip-us.apache.org/repos/asf/ignite/blob/1dbf20e0/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/dotnet/PlatformDotNetCacheStore.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/dotnet/PlatformDotNetCacheStore.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/dotnet/PlatformDotNetCacheStore.java
index 25521dc..c41ca6e 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/dotnet/PlatformDotNetCacheStore.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/dotnet/PlatformDotNetCacheStore.java
@@ -21,8 +21,8 @@ import org.apache.ignite.IgniteCheckedException;
 import org.apache.ignite.cache.store.CacheStore;
 import org.apache.ignite.cache.store.CacheStoreSession;
 import org.apache.ignite.internal.GridKernalContext;
-import org.apache.ignite.internal.portable.BinaryRawReaderEx;
-import org.apache.ignite.internal.portable.BinaryRawWriterEx;
+import org.apache.ignite.internal.binary.BinaryRawReaderEx;
+import org.apache.ignite.internal.binary.BinaryRawWriterEx;
 import org.apache.ignite.internal.processors.platform.PlatformContext;
 import org.apache.ignite.internal.processors.platform.cache.store.PlatformCacheStore;
 import org.apache.ignite.internal.processors.platform.cache.store.PlatformCacheStoreCallback;
@@ -481,4 +481,4 @@ public class PlatformDotNetCacheStore<K, V> implements CacheStore<K, V>, Platfor
             clo.apply((K) reader.readObjectDetached(), (V) reader.readObjectDetached());
         }
     }
-}
\ No newline at end of file
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/1dbf20e0/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/dotnet/PlatformDotNetConfigurationClosure.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/dotnet/PlatformDotNetConfigurationClosure.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/dotnet/PlatformDotNetConfigurationClosure.java
index c506a35..caea840 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/dotnet/PlatformDotNetConfigurationClosure.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/dotnet/PlatformDotNetConfigurationClosure.java
@@ -23,10 +23,10 @@ import org.apache.ignite.configuration.BinaryConfiguration;
 import org.apache.ignite.configuration.IgniteConfiguration;
 import org.apache.ignite.configuration.PlatformConfiguration;
 import org.apache.ignite.internal.MarshallerContextImpl;
-import org.apache.ignite.internal.portable.BinaryNoopMetadataHandler;
-import org.apache.ignite.internal.portable.BinaryRawWriterEx;
-import org.apache.ignite.internal.portable.GridPortableMarshaller;
-import org.apache.ignite.internal.portable.PortableContext;
+import org.apache.ignite.internal.binary.BinaryNoopMetadataHandler;
+import org.apache.ignite.internal.binary.BinaryRawWriterEx;
+import org.apache.ignite.internal.binary.GridPortableMarshaller;
+import org.apache.ignite.internal.binary.PortableContext;
 import org.apache.ignite.internal.processors.platform.PlatformAbstractConfigurationClosure;
 import org.apache.ignite.internal.processors.platform.lifecycle.PlatformLifecycleBean;
 import org.apache.ignite.internal.processors.platform.memory.PlatformInputStream;
@@ -38,7 +38,7 @@ import org.apache.ignite.internal.util.typedef.internal.U;
 import org.apache.ignite.lifecycle.LifecycleBean;
 import org.apache.ignite.marshaller.Marshaller;
 import org.apache.ignite.platform.dotnet.PlatformDotNetConfiguration;
-import org.apache.ignite.internal.portable.BinaryMarshaller;
+import org.apache.ignite.internal.binary.BinaryMarshaller;
 import org.apache.ignite.platform.dotnet.PlatformDotNetLifecycleBean;
 
 import java.util.ArrayList;
@@ -255,4 +255,4 @@ public class PlatformDotNetConfigurationClosure extends PlatformAbstractConfigur
             throw U.convertException(e);
         }
     }
-}
\ No newline at end of file
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/1dbf20e0/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/events/PlatformEventFilterListenerImpl.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/events/PlatformEventFilterListenerImpl.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/events/PlatformEventFilterListenerImpl.java
index a19f07e..624870a 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/events/PlatformEventFilterListenerImpl.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/events/PlatformEventFilterListenerImpl.java
@@ -19,7 +19,7 @@ package org.apache.ignite.internal.processors.platform.events;
 
 import org.apache.ignite.events.Event;
 import org.apache.ignite.internal.GridKernalContext;
-import org.apache.ignite.internal.portable.BinaryRawWriterEx;
+import org.apache.ignite.internal.binary.BinaryRawWriterEx;
 import org.apache.ignite.internal.processors.platform.PlatformContext;
 import org.apache.ignite.internal.processors.platform.PlatformEventFilterListener;
 import org.apache.ignite.internal.processors.platform.memory.PlatformMemory;
@@ -183,4 +183,4 @@ public class PlatformEventFilterListenerImpl implements PlatformEventFilterListe
         pred = in.readObject();
         types = (int[])in.readObject();
     }
-}
\ No newline at end of file
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/1dbf20e0/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/events/PlatformEvents.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/events/PlatformEvents.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/events/PlatformEvents.java
index a1af469..9bf0a8d 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/events/PlatformEvents.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/events/PlatformEvents.java
@@ -24,8 +24,8 @@ import org.apache.ignite.IgniteCheckedException;
 import org.apache.ignite.IgniteEvents;
 import org.apache.ignite.events.Event;
 import org.apache.ignite.events.EventAdapter;
-import org.apache.ignite.internal.portable.BinaryRawReaderEx;
-import org.apache.ignite.internal.portable.BinaryRawWriterEx;
+import org.apache.ignite.internal.binary.BinaryRawReaderEx;
+import org.apache.ignite.internal.binary.BinaryRawWriterEx;
 import org.apache.ignite.internal.processors.platform.PlatformAbstractTarget;
 import org.apache.ignite.internal.processors.platform.PlatformEventFilterListener;
 import org.apache.ignite.internal.processors.platform.PlatformContext;

http://git-wip-us.apache.org/repos/asf/ignite/blob/1dbf20e0/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/memory/PlatformInputStream.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/memory/PlatformInputStream.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/memory/PlatformInputStream.java
index 55c524e..321e592 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/memory/PlatformInputStream.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/memory/PlatformInputStream.java
@@ -17,7 +17,7 @@
 
 package org.apache.ignite.internal.processors.platform.memory;
 
-import org.apache.ignite.internal.portable.streams.PortableInputStream;
+import org.apache.ignite.internal.binary.streams.PortableInputStream;
 
 /**
  * Interop output stream,
@@ -27,4 +27,4 @@ public interface PlatformInputStream extends PortableInputStream {
      * Synchronize input. Must be called before start reading data from a memory changed by another platform.
      */
     public void synchronize();
-}
\ No newline at end of file
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/1dbf20e0/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/memory/PlatformOutputStream.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/memory/PlatformOutputStream.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/memory/PlatformOutputStream.java
index e3ef0b2..7894f0c 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/memory/PlatformOutputStream.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/memory/PlatformOutputStream.java
@@ -17,7 +17,7 @@
 
 package org.apache.ignite.internal.processors.platform.memory;
 
-import org.apache.ignite.internal.portable.streams.PortableOutputStream;
+import org.apache.ignite.internal.binary.streams.PortableOutputStream;
 
 /**
  * Interop output stream.
@@ -27,4 +27,4 @@ public interface PlatformOutputStream extends PortableOutputStream {
      * Synchronize output stream with underlying memory
      */
     public void synchronize();
-}
\ No newline at end of file
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/1dbf20e0/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/messaging/PlatformMessageFilterImpl.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/messaging/PlatformMessageFilterImpl.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/messaging/PlatformMessageFilterImpl.java
index 9e1b086..a737442 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/messaging/PlatformMessageFilterImpl.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/messaging/PlatformMessageFilterImpl.java
@@ -18,7 +18,7 @@
 package org.apache.ignite.internal.processors.platform.messaging;
 
 import org.apache.ignite.internal.GridKernalContext;
-import org.apache.ignite.internal.portable.BinaryRawWriterEx;
+import org.apache.ignite.internal.binary.BinaryRawWriterEx;
 import org.apache.ignite.internal.processors.platform.PlatformAbstractPredicate;
 import org.apache.ignite.internal.processors.platform.PlatformContext;
 import org.apache.ignite.internal.processors.platform.memory.PlatformMemory;
@@ -107,4 +107,4 @@ public class PlatformMessageFilterImpl extends PlatformAbstractPredicate impleme
             ptr = 0;
         }
     }
-}
\ No newline at end of file
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/1dbf20e0/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/messaging/PlatformMessageLocalFilter.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/messaging/PlatformMessageLocalFilter.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/messaging/PlatformMessageLocalFilter.java
index de3f255..54bbaeb 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/messaging/PlatformMessageLocalFilter.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/messaging/PlatformMessageLocalFilter.java
@@ -18,7 +18,7 @@
 package org.apache.ignite.internal.processors.platform.messaging;
 
 import org.apache.ignite.internal.GridKernalContext;
-import org.apache.ignite.internal.portable.BinaryRawWriterEx;
+import org.apache.ignite.internal.binary.BinaryRawWriterEx;
 import org.apache.ignite.internal.processors.platform.PlatformContext;
 import org.apache.ignite.internal.processors.platform.memory.PlatformMemory;
 import org.apache.ignite.internal.processors.platform.memory.PlatformOutputStream;

http://git-wip-us.apache.org/repos/asf/ignite/blob/1dbf20e0/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/messaging/PlatformMessaging.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/messaging/PlatformMessaging.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/messaging/PlatformMessaging.java
index 603d3db..88ea3c8 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/messaging/PlatformMessaging.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/messaging/PlatformMessaging.java
@@ -19,8 +19,8 @@ package org.apache.ignite.internal.processors.platform.messaging;
 
 import org.apache.ignite.IgniteCheckedException;
 import org.apache.ignite.IgniteMessaging;
-import org.apache.ignite.internal.portable.BinaryRawReaderEx;
-import org.apache.ignite.internal.portable.BinaryRawWriterEx;
+import org.apache.ignite.internal.binary.BinaryRawReaderEx;
+import org.apache.ignite.internal.binary.BinaryRawWriterEx;
 import org.apache.ignite.internal.processors.platform.PlatformAbstractTarget;
 import org.apache.ignite.internal.processors.platform.PlatformContext;
 import org.apache.ignite.internal.processors.platform.message.PlatformMessageFilter;
@@ -163,4 +163,4 @@ public class PlatformMessaging extends PlatformAbstractTarget {
     @Override protected IgniteFuture currentFuture() throws IgniteCheckedException {
         return messaging.future();
     }
-}
\ No newline at end of file
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/1dbf20e0/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/services/PlatformAbstractService.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/services/PlatformAbstractService.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/services/PlatformAbstractService.java
index df71a24..6d143aa 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/services/PlatformAbstractService.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/services/PlatformAbstractService.java
@@ -23,8 +23,8 @@ import java.io.ObjectInput;
 import java.io.ObjectOutput;
 import org.apache.ignite.Ignite;
 import org.apache.ignite.IgniteCheckedException;
-import org.apache.ignite.internal.portable.BinaryRawReaderEx;
-import org.apache.ignite.internal.portable.BinaryRawWriterEx;
+import org.apache.ignite.internal.binary.BinaryRawReaderEx;
+import org.apache.ignite.internal.binary.BinaryRawWriterEx;
 import org.apache.ignite.internal.processors.platform.PlatformContext;
 import org.apache.ignite.internal.processors.platform.memory.PlatformInputStream;
 import org.apache.ignite.internal.processors.platform.memory.PlatformMemory;
@@ -227,4 +227,4 @@ public abstract class PlatformAbstractService implements PlatformService, Extern
         out.writeObject(svc);
         out.writeBoolean(srvKeepPortable);
     }
-}
\ No newline at end of file
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/1dbf20e0/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/services/PlatformServices.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/services/PlatformServices.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/services/PlatformServices.java
index 320d5a9..ff09357 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/services/PlatformServices.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/services/PlatformServices.java
@@ -22,8 +22,8 @@ import java.util.Map;
 import java.util.UUID;
 import org.apache.ignite.IgniteCheckedException;
 import org.apache.ignite.IgniteServices;
-import org.apache.ignite.internal.portable.BinaryRawReaderEx;
-import org.apache.ignite.internal.portable.BinaryRawWriterEx;
+import org.apache.ignite.internal.binary.BinaryRawReaderEx;
+import org.apache.ignite.internal.binary.BinaryRawWriterEx;
 import org.apache.ignite.internal.processors.platform.PlatformAbstractTarget;
 import org.apache.ignite.internal.processors.platform.PlatformContext;
 import org.apache.ignite.internal.processors.platform.dotnet.PlatformDotNetService;
@@ -272,4 +272,4 @@ public class PlatformServices extends PlatformAbstractTarget {
     @Override protected IgniteFuture currentFuture() throws IgniteCheckedException {
         return services.future();
     }
-}
\ No newline at end of file
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/1dbf20e0/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/transactions/PlatformTransactions.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/transactions/PlatformTransactions.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/transactions/PlatformTransactions.java
index d97e071..8afabac 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/transactions/PlatformTransactions.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/transactions/PlatformTransactions.java
@@ -23,7 +23,7 @@ import java.util.concurrent.atomic.AtomicLong;
 import org.apache.ignite.IgniteCheckedException;
 import org.apache.ignite.IgniteTransactions;
 import org.apache.ignite.configuration.TransactionConfiguration;
-import org.apache.ignite.internal.portable.BinaryRawWriterEx;
+import org.apache.ignite.internal.binary.BinaryRawWriterEx;
 import org.apache.ignite.internal.processors.platform.PlatformAbstractTarget;
 import org.apache.ignite.internal.processors.platform.PlatformContext;
 import org.apache.ignite.internal.processors.platform.utils.PlatformFutureUtils;
@@ -256,4 +256,4 @@ public class PlatformTransactions extends PlatformAbstractTarget {
                 super.processOutStream(type, writer);
         }
     }
-}
\ No newline at end of file
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/1dbf20e0/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/utils/PlatformFutureUtils.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/utils/PlatformFutureUtils.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/utils/PlatformFutureUtils.java
index 335be4d..e6f28c9 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/utils/PlatformFutureUtils.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/utils/PlatformFutureUtils.java
@@ -18,7 +18,7 @@
 package org.apache.ignite.internal.processors.platform.utils;
 
 import org.apache.ignite.internal.IgniteInternalFuture;
-import org.apache.ignite.internal.portable.BinaryRawWriterEx;
+import org.apache.ignite.internal.binary.BinaryRawWriterEx;
 import org.apache.ignite.internal.processors.platform.PlatformAbstractTarget;
 import org.apache.ignite.internal.processors.platform.PlatformContext;
 import org.apache.ignite.internal.processors.platform.callback.PlatformCallbackGateway;
@@ -394,4 +394,4 @@ public class PlatformFutureUtils {
         }
     }
 
-}
\ No newline at end of file
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/1dbf20e0/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/utils/PlatformReaderBiClosure.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/utils/PlatformReaderBiClosure.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/utils/PlatformReaderBiClosure.java
index 199cf72..6506aed 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/utils/PlatformReaderBiClosure.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/utils/PlatformReaderBiClosure.java
@@ -17,7 +17,7 @@
 
 package org.apache.ignite.internal.processors.platform.utils;
 
-import org.apache.ignite.internal.portable.BinaryRawReaderEx;
+import org.apache.ignite.internal.binary.BinaryRawReaderEx;
 import org.apache.ignite.lang.IgniteBiTuple;
 
 /**
@@ -31,4 +31,4 @@ public interface PlatformReaderBiClosure<T1, T2> {
      * @return Object.
      */
     IgniteBiTuple<T1, T2> read(BinaryRawReaderEx reader);
-}
\ No newline at end of file
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/1dbf20e0/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/utils/PlatformReaderClosure.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/utils/PlatformReaderClosure.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/utils/PlatformReaderClosure.java
index 9330606..b281966 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/utils/PlatformReaderClosure.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/utils/PlatformReaderClosure.java
@@ -17,7 +17,7 @@
 
 package org.apache.ignite.internal.processors.platform.utils;
 
-import org.apache.ignite.internal.portable.BinaryRawReaderEx;
+import org.apache.ignite.internal.binary.BinaryRawReaderEx;
 
 /**
  * Reader closure.
@@ -31,4 +31,4 @@ public interface PlatformReaderClosure<T> {
      * @return Object.
      */
     T read(BinaryRawReaderEx reader);
-}
\ No newline at end of file
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/1dbf20e0/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/utils/PlatformUtils.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/utils/PlatformUtils.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/utils/PlatformUtils.java
index 6572764..4a29637 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/utils/PlatformUtils.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/utils/PlatformUtils.java
@@ -24,8 +24,8 @@ import org.apache.ignite.IgniteLogger;
 import org.apache.ignite.cache.CachePeekMode;
 import org.apache.ignite.internal.GridKernalContext;
 import org.apache.ignite.internal.IgniteKernal;
-import org.apache.ignite.internal.portable.BinaryRawReaderEx;
-import org.apache.ignite.internal.portable.BinaryRawWriterEx;
+import org.apache.ignite.internal.binary.BinaryRawReaderEx;
+import org.apache.ignite.internal.binary.BinaryRawWriterEx;
 import org.apache.ignite.internal.processors.platform.PlatformContext;
 import org.apache.ignite.internal.processors.platform.PlatformExtendedException;
 import org.apache.ignite.internal.processors.platform.PlatformNativeException;
@@ -807,4 +807,4 @@ public class PlatformUtils {
     private PlatformUtils() {
         // No-op.
     }
-}
\ No newline at end of file
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/1dbf20e0/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/utils/PlatformWriterBiClosure.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/utils/PlatformWriterBiClosure.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/utils/PlatformWriterBiClosure.java
index b0e6a65..f97991a 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/utils/PlatformWriterBiClosure.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/utils/PlatformWriterBiClosure.java
@@ -17,7 +17,7 @@
 
 package org.apache.ignite.internal.processors.platform.utils;
 
-import org.apache.ignite.internal.portable.BinaryRawWriterEx;
+import org.apache.ignite.internal.binary.BinaryRawWriterEx;
 
 /**
  * Interop writer bi-closure.
@@ -31,4 +31,4 @@ public interface PlatformWriterBiClosure<T1, T2> {
      * @param val2 Value 2.
      */
     public void write(BinaryRawWriterEx writer, T1 val1, T2 val2);
-}
\ No newline at end of file
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/1dbf20e0/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/utils/PlatformWriterClosure.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/utils/PlatformWriterClosure.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/utils/PlatformWriterClosure.java
index c55c209..f7d9861 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/utils/PlatformWriterClosure.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/utils/PlatformWriterClosure.java
@@ -17,7 +17,7 @@
 
 package org.apache.ignite.internal.processors.platform.utils;
 
-import org.apache.ignite.internal.portable.BinaryRawWriterEx;
+import org.apache.ignite.internal.binary.BinaryRawWriterEx;
 
 /**
  * Interop writer closure.
@@ -30,4 +30,4 @@ public interface PlatformWriterClosure<T> {
      * @param val Value.
      */
     public void write(BinaryRawWriterEx writer, T val);
-}
\ No newline at end of file
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/1dbf20e0/modules/core/src/main/java/org/apache/ignite/spi/checkpoint/sharedfs/SharedFsCheckpointSpi.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/spi/checkpoint/sharedfs/SharedFsCheckpointSpi.java b/modules/core/src/main/java/org/apache/ignite/spi/checkpoint/sharedfs/SharedFsCheckpointSpi.java
index 3a25455..36a4ea6 100644
--- a/modules/core/src/main/java/org/apache/ignite/spi/checkpoint/sharedfs/SharedFsCheckpointSpi.java
+++ b/modules/core/src/main/java/org/apache/ignite/spi/checkpoint/sharedfs/SharedFsCheckpointSpi.java
@@ -28,7 +28,7 @@ import java.util.Queue;
 import org.apache.ignite.Ignite;
 import org.apache.ignite.IgniteCheckedException;
 import org.apache.ignite.IgniteLogger;
-import org.apache.ignite.internal.portable.BinaryMarshaller;
+import org.apache.ignite.internal.binary.BinaryMarshaller;
 import org.apache.ignite.internal.util.typedef.F;
 import org.apache.ignite.internal.util.typedef.internal.A;
 import org.apache.ignite.internal.util.typedef.internal.S;
@@ -507,4 +507,4 @@ public class SharedFsCheckpointSpi extends IgniteSpiAdapter implements Checkpoin
     @Override public String toString() {
         return S.toString(SharedFsCheckpointSpi.class, this);
     }
-}
\ No newline at end of file
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/1dbf20e0/modules/core/src/main/resources/META-INF/classnames.properties
----------------------------------------------------------------------
diff --git a/modules/core/src/main/resources/META-INF/classnames.properties b/modules/core/src/main/resources/META-INF/classnames.properties
index 8ac3278..c1bac44 100644
--- a/modules/core/src/main/resources/META-INF/classnames.properties
+++ b/modules/core/src/main/resources/META-INF/classnames.properties
@@ -294,16 +294,16 @@ org.apache.ignite.internal.managers.eventstorage.GridEventStorageMessage
 org.apache.ignite.internal.managers.indexing.GridIndexingManager$1
 org.apache.ignite.internal.managers.loadbalancer.GridLoadBalancerAdapter
 org.apache.ignite.internal.managers.loadbalancer.GridLoadBalancerManager$1
-org.apache.ignite.internal.portable.BinaryMetadata
-org.apache.ignite.internal.portable.BinaryObjectEx
-org.apache.ignite.internal.portable.BinaryObjectImpl
-org.apache.ignite.internal.portable.BinaryObjectOffheapImpl
-org.apache.ignite.internal.portable.BinaryReaderExImpl$Flag
-org.apache.ignite.internal.portable.BinaryWriteMode
-org.apache.ignite.internal.portable.PortableContext
-org.apache.ignite.internal.portable.PortableSchema
-org.apache.ignite.internal.portable.PortableSchema$Confirmation
-org.apache.ignite.internal.portable.builder.PortableLazyMap$1$1$1
+org.apache.ignite.internal.binary.BinaryMetadata
+org.apache.ignite.internal.binary.BinaryObjectEx
+org.apache.ignite.internal.binary.BinaryObjectImpl
+org.apache.ignite.internal.binary.BinaryObjectOffheapImpl
+org.apache.ignite.internal.binary.BinaryReaderExImpl$Flag
+org.apache.ignite.internal.binary.BinaryWriteMode
+org.apache.ignite.internal.binary.PortableContext
+org.apache.ignite.internal.binary.PortableSchema
+org.apache.ignite.internal.binary.PortableSchema$Confirmation
+org.apache.ignite.internal.binary.builder.PortableLazyMap$1$1$1
 org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion
 org.apache.ignite.internal.processors.affinity.GridAffinityAssignment
 org.apache.ignite.internal.processors.affinity.GridAffinityMessage
@@ -745,14 +745,14 @@ org.apache.ignite.internal.processors.cache.local.atomic.GridLocalAtomicCache$4
 org.apache.ignite.internal.processors.cache.local.atomic.GridLocalAtomicCache$5
 org.apache.ignite.internal.processors.cache.local.atomic.GridLocalAtomicCache$6
 org.apache.ignite.internal.processors.cache.local.atomic.GridLocalAtomicCache$9
-org.apache.ignite.internal.processors.cache.portable.CacheDefaultPortableAffinityKeyMapper
-org.apache.ignite.internal.processors.cache.portable.CacheObjectBinaryProcessorImpl$1
-org.apache.ignite.internal.processors.cache.portable.CacheObjectBinaryProcessorImpl$4
-org.apache.ignite.internal.processors.cache.portable.CacheObjectBinaryProcessorImpl$5
-org.apache.ignite.internal.processors.cache.portable.CacheObjectBinaryProcessorImpl$MetaDataEntryFilter
-org.apache.ignite.internal.processors.cache.portable.CacheObjectBinaryProcessorImpl$MetaDataPredicate
-org.apache.ignite.internal.processors.cache.portable.CacheObjectBinaryProcessorImpl$MetadataProcessor
-org.apache.ignite.internal.processors.cache.portable.PortableMetadataKey
+org.apache.ignite.internal.binaryorg.apache.ignite.internal.processors.cache.binary.CacheDefaultPortableAffinityKeyMapper
+org.apache.ignite.internal.binaryorg.apache.ignite.internal.processors.cache.binary.CacheObjectBinaryProcessorImpl$1
+org.apache.ignite.internal.binaryorg.apache.ignite.internal.processors.cache.binary.CacheObjectBinaryProcessorImpl$4
+org.apache.ignite.internal.binaryorg.apache.ignite.internal.processors.cache.binary.CacheObjectBinaryProcessorImpl$5
+org.apache.ignite.internal.binaryorg.apache.ignite.internal.processors.cache.binary.CacheObjectBinaryProcessorImpl$MetaDataEntryFilter
+org.apache.ignite.internal.binaryorg.apache.ignite.internal.processors.cache.binary.CacheObjectBinaryProcessorImpl$MetaDataPredicate
+org.apache.ignite.internal.binaryorg.apache.ignite.internal.processors.cache.binary.CacheObjectBinaryProcessorImpl$MetadataProcessor
+org.apache.ignite.internal.binaryorg.apache.ignite.internal.processors.cache.binary.PortableMetadataKey
 org.apache.ignite.internal.processors.cache.query.CacheQueryType
 org.apache.ignite.internal.processors.cache.query.GridCacheDistributedQueryFuture$1
 org.apache.ignite.internal.processors.cache.query.GridCacheDistributedQueryFuture$3

http://git-wip-us.apache.org/repos/asf/ignite/blob/1dbf20e0/modules/core/src/test/java/org/apache/ignite/cache/store/jdbc/CacheJdbcPojoStoreBinaryMarshallerSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/cache/store/jdbc/CacheJdbcPojoStoreBinaryMarshallerSelfTest.java b/modules/core/src/test/java/org/apache/ignite/cache/store/jdbc/CacheJdbcPojoStoreBinaryMarshallerSelfTest.java
index 659efb0..b825a24 100644
--- a/modules/core/src/test/java/org/apache/ignite/cache/store/jdbc/CacheJdbcPojoStoreBinaryMarshallerSelfTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/cache/store/jdbc/CacheJdbcPojoStoreBinaryMarshallerSelfTest.java
@@ -18,7 +18,7 @@
 package org.apache.ignite.cache.store.jdbc;
 
 import org.apache.ignite.marshaller.Marshaller;
-import org.apache.ignite.internal.portable.BinaryMarshaller;
+import org.apache.ignite.internal.binary.BinaryMarshaller;
 
 /**
  * Class for {@code PojoCacheStore} tests.

http://git-wip-us.apache.org/repos/asf/ignite/blob/1dbf20e0/modules/core/src/test/java/org/apache/ignite/internal/binary/BinaryEnumsSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/binary/BinaryEnumsSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/binary/BinaryEnumsSelfTest.java
new file mode 100644
index 0000000..e503e07
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/binary/BinaryEnumsSelfTest.java
@@ -0,0 +1,446 @@
+/*
+ * 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.binary;
+
+import org.apache.ignite.Ignite;
+import org.apache.ignite.IgniteCache;
+import org.apache.ignite.binary.BinaryObject;
+import org.apache.ignite.binary.BinaryTypeConfiguration;
+import org.apache.ignite.cache.CacheMode;
+import org.apache.ignite.configuration.BinaryConfiguration;
+import org.apache.ignite.configuration.CacheConfiguration;
+import org.apache.ignite.configuration.IgniteConfiguration;
+import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
+
+import java.io.Serializable;
+import java.util.Arrays;
+
+/**
+ * Contains tests for binary enums.
+ */
+@SuppressWarnings("unchecked")
+public class BinaryEnumsSelfTest extends GridCommonAbstractTest {
+    /** Cache name. */
+    private static String CACHE_NAME = "cache";
+
+    /** Whether to register types or not. */
+    private boolean register;
+
+    /** Node 1. */
+    private Ignite node1;
+
+    /** Node 2. */
+    private Ignite node2;
+
+    /** Cache 1. */
+    private IgniteCache cache1;
+
+    /** Cache 2. */
+    private IgniteCache cache2;
+
+    /** Binary cache 1. */
+    private IgniteCache cacheBinary1;
+
+    /** Binary cache 2. */
+    private IgniteCache cacheBinary2;
+
+    /** {@inheritDoc} */
+    @Override protected void beforeTest() throws Exception {
+        register = false;
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void afterTest() throws Exception {
+        stopAllGrids();
+    }
+
+    /** {@inheritDoc} */
+    @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception {
+        IgniteConfiguration cfg = super.getConfiguration(gridName);
+
+        if (register) {
+            BinaryConfiguration bCfg = new BinaryConfiguration();
+
+            BinaryTypeConfiguration enumCfg = new BinaryTypeConfiguration(EnumType.class.getName());
+            enumCfg.setEnum(true);
+
+            bCfg.setTypeConfigurations(Arrays.asList(enumCfg, new BinaryTypeConfiguration(EnumHolder.class.getName())));
+
+            cfg.setBinaryConfiguration(bCfg);
+        }
+
+        cfg.setMarshaller(new BinaryMarshaller());
+
+        CacheConfiguration ccfg = new CacheConfiguration();
+        ccfg.setName(CACHE_NAME);
+        ccfg.setCacheMode(CacheMode.PARTITIONED);
+
+        cfg.setCacheConfiguration(ccfg);
+
+        return cfg;
+    }
+
+    /**
+     * Start up routine.
+     *
+     * @throws Exception If failed.
+     */
+    private void startUp(boolean register) throws Exception {
+        this.register = register;
+
+        node1 = startGrid(0);
+        cache1 = node1.cache(CACHE_NAME);
+        cacheBinary1 = cache1.withKeepBinary();
+
+        node2 = startGrid(1);
+        cache2 = node2.cache(CACHE_NAME);
+        cacheBinary2 = cache2.withKeepBinary();
+    }
+
+    /**
+     * Test operations on simple type which is registered in advance.
+     *
+     * @throws Exception If failed.
+     */
+    public void testSimpleRegistered() throws Exception {
+        checkSimple(true);
+    }
+
+    /**
+     * Test operations on simple type which is not registered in advance.
+     *
+     * @throws Exception If failed.
+     */
+    public void testSimpleNotRegistered() throws Exception {
+        checkSimple(false);
+    }
+
+    /**
+     * Test operations when enum is nested into an object (registered).
+     *
+     * @throws Exception If failed.
+     */
+    public void testNestedRegistered() throws Exception {
+        checkNested(true);
+    }
+
+    /**
+     * Test operations when enum is nested into an object (not registered).
+     *
+     * @throws Exception If failed.
+     */
+    public void testNestedNotRegistered() throws Exception {
+        checkNested(false);
+    }
+
+    /**
+     * Test builder operations on simple type which is registered in advance.
+     *
+     * @throws Exception If failed.
+     */
+    public void testSimpleBuilderRegistered() throws Exception {
+        checkSimpleBuilder(true);
+    }
+
+    /**
+     * Test builder operations on simple type which is not registered in advance.
+     *
+     * @throws Exception If failed.
+     */
+    public void testSimpleBuilderNotRegistered() throws Exception {
+        checkSimpleBuilder(false);
+    }
+
+    /**
+     * Test builder operations when enum is nested into an object (registered).
+     *
+     * @throws Exception If failed.
+     */
+    public void testNestedBuilderRegistered() throws Exception {
+        checkNestedBuilder(true);
+    }
+
+    /**
+     * Test builder operations when enum is nested into an object (not registered).
+     *
+     * @throws Exception If failed.
+     */
+    public void testNestedBuilderNotRegistered() throws Exception {
+        checkNestedBuilder(false);
+    }
+
+    /**
+     * Check simple serialization - deserialization.
+     *
+     * @param registered If type should be registered in advance.
+     * @throws Exception If failed.
+     */
+    public void checkSimple(boolean registered) throws Exception {
+        startUp(registered);
+
+        cache1.put(1, EnumType.ONE);
+
+        validateSimple(1, EnumType.ONE, registered);
+    }
+
+    /**
+     * Check nested serialization - deserialization.
+     *
+     * @param registered If type should be registered in advance.
+     * @throws Exception If failed.
+     */
+    private void checkNested(boolean registered) throws Exception {
+        startUp(registered);
+
+        cache1.put(1, new EnumHolder(EnumType.ONE));
+
+        validateNested(1, EnumType.ONE, registered);
+    }
+
+    /**
+     * Check nested builder serialization - deserialization.
+     *
+     * @param registered If type should be registered in advance.
+     * @throws Exception If failed.
+     */
+    private void checkNestedBuilder(boolean registered) throws Exception {
+        startUp(registered);
+
+        BinaryObject obj = node1.binary().builder("EnumHolder").setField("val", EnumType.ONE).build();
+
+        assert node1.binary().type("EnumHolder") != null;
+        assert node1.binary().type("EnumType") != null;
+
+        cacheBinary1.put(1, obj);
+
+        validateNested(1, EnumType.ONE, registered);
+
+        obj = (BinaryObject)cacheBinary1.get(1);
+        obj = node1.binary().builder(obj).setField("val", EnumType.TWO).build();
+
+        cacheBinary1.put(1, obj);
+
+        validateNested(1, EnumType.TWO, registered);
+    }
+
+    /**
+     * Validate nested object.
+     *
+     * @param key Key.
+     * @param val Value.
+     * @param registered Registered flag.
+     * @throws Exception If failed.
+     */
+    private void validateNested(int key, EnumType val, boolean registered) throws Exception {
+        if (registered) {
+            EnumHolder res1 = (EnumHolder) cache1.get(key);
+            EnumHolder res2 = (EnumHolder) cache2.get(key);
+
+            assertEquals(val, res1.val);
+            assertEquals(val, res2.val);
+        }
+
+        BinaryObject resBinary1 = (BinaryObject)cacheBinary1.get(key);
+        BinaryObject resBinary2 = (BinaryObject)cacheBinary2.get(key);
+
+        validate((BinaryObject)resBinary1.field("val"), val);
+        validate((BinaryObject)resBinary2.field("val"), val);
+    }
+
+    /**
+     * Check simple serialization - deserialization using builder.
+     *
+     * @param registered If type should be registered in advance.
+     * @throws Exception If failed.
+     */
+    public void checkSimpleBuilder(boolean registered) throws Exception {
+        startUp(registered);
+
+        BinaryObject binary = node1.binary().buildEnum(EnumType.class.getSimpleName(), EnumType.ONE.ordinal());
+
+        cacheBinary1.put(1, binary);
+
+        validateSimple(1, EnumType.ONE, registered);
+    }
+
+    /**
+     * Test enum array (registered).
+     *
+     * @throws Exception If failed.
+     */
+    public void testSimpleArrayRegistered() throws Exception {
+        checkSimpleArray(true);
+    }
+
+    /**
+     * Test enum array (not registered).
+     *
+     * @throws Exception If failed.
+     */
+    public void testSimpleArrayNotRegistered() throws Exception {
+        checkSimpleArray(false);
+    }
+
+    /**
+     * Test enum array created using builder (registered).
+     *
+     * @throws Exception If failed.
+     */
+    public void testSimpleBuilderArrayRegistered() throws Exception {
+        checkSimpleBuilderArray(true);
+    }
+
+    /**
+     * Test enum array created using builder (not registered).
+     *
+     * @throws Exception If failed.
+     */
+    public void testSimpleBuilderArrayNotRegistered() throws Exception {
+        checkSimpleBuilderArray(false);
+    }
+
+    /**
+     * Check arrays with builder.
+     *
+     * @param registered Registered flag.
+     * @throws Exception If failed.
+     */
+    public void checkSimpleArray(boolean registered) throws Exception {
+        startUp(registered);
+
+        cache1.put(1, new EnumType[] { EnumType.ONE, EnumType.TWO });
+
+        validateSimpleArray(registered);
+    }
+
+    /**
+     * Check arrays with builder.
+     *
+     * @param registered Registered flag.
+     * @throws Exception If failed.
+     */
+    public void checkSimpleBuilderArray(boolean registered) throws Exception {
+        startUp(registered);
+
+        BinaryObject binaryOne = node1.binary().buildEnum(EnumType.class.getSimpleName(), EnumType.ONE.ordinal());
+        BinaryObject binaryTwo = node1.binary().buildEnum(EnumType.class.getSimpleName(), EnumType.TWO.ordinal());
+
+        cacheBinary1.put(1, new BinaryObject[] { binaryOne, binaryTwo });
+
+        validateSimpleArray(registered);
+    }
+
+    /**
+     * Validate simple array.
+     *
+     * @param registered Registered flag.
+     */
+    private void validateSimpleArray(boolean registered) {
+        if (registered) {
+            Object[] arr1 = (Object[])cache1.get(1);
+            Object[] arr2 = (Object[])cache2.get(1);
+
+            assertEquals(2, arr1.length);
+            assertEquals(2, arr2.length);
+
+            assertEquals(EnumType.ONE, arr1[0]);
+            assertEquals(EnumType.TWO, arr1[1]);
+
+            assertEquals(EnumType.ONE, arr2[0]);
+            assertEquals(EnumType.TWO, arr2[1]);
+        }
+
+        Object[] arrBinary1 = (Object[])cacheBinary1.get(1);
+        Object[] arrBinary2 = (Object[])cacheBinary2.get(1);
+
+        assertEquals(2, arrBinary1.length);
+        assertEquals(2, arrBinary2.length);
+
+        validate((BinaryObject) arrBinary1[0], EnumType.ONE);
+        validate((BinaryObject) arrBinary1[1], EnumType.TWO);
+
+        validate((BinaryObject) arrBinary2[0], EnumType.ONE);
+        validate((BinaryObject) arrBinary2[1], EnumType.TWO);
+    }
+
+    /**
+     * Internal check routine for simple scenario.
+     *
+     * @param key Key.
+     * @param val Value.
+     * @param registered Registered flag.
+     * @throws Exception If failed.
+     */
+    private void validateSimple(int key, EnumType val, boolean registered) throws Exception {
+        if (registered) {
+            assertEquals(val, cache1.get(key));
+            assertEquals(val, cache2.get(key));
+        }
+
+        validate((BinaryObject) cacheBinary1.get(key), val);
+        validate((BinaryObject) cacheBinary2.get(key), val);
+    }
+
+    /**
+     * Validate single value.
+     *
+     * @param obj Binary value.
+     * @param val Expected value.
+     */
+    private void validate(BinaryObject obj, EnumType val) {
+        assertTrue(obj.type().isEnum());
+
+        assertEquals(node1.binary().typeId(EnumType.class.getName()), obj.type().typeId());
+        assertEquals(node2.binary().typeId(EnumType.class.getName()), obj.type().typeId());
+
+        assertEquals(val.ordinal(), obj.enumOrdinal());
+    }
+
+    /**
+     * Enumeration holder.
+     */
+    public static class EnumHolder implements Serializable {
+        /** Value. */
+        public EnumType val;
+
+        /**
+         * Default constructor.
+         */
+        @SuppressWarnings("UnusedDeclaration")
+        public EnumHolder() {
+            // No-op.
+        }
+
+        /**
+         * Constructor.
+         *
+         * @param val Value.
+         */
+        public EnumHolder(EnumType val) {
+            this.val = val;
+        }
+    }
+
+    /**
+     * Enumeration for tests.
+     */
+    public static enum EnumType {
+        ONE,
+        TWO
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/1dbf20e0/modules/core/src/test/java/org/apache/ignite/internal/binary/BinaryFieldsAbstractSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/binary/BinaryFieldsAbstractSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/binary/BinaryFieldsAbstractSelfTest.java
new file mode 100644
index 0000000..f12bb92
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/binary/BinaryFieldsAbstractSelfTest.java
@@ -0,0 +1,718 @@
+/*
+ * 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.binary;
+
+import org.apache.ignite.binary.BinaryField;
+import org.apache.ignite.binary.BinaryObject;
+import org.apache.ignite.binary.BinaryTypeConfiguration;
+import org.apache.ignite.configuration.BinaryConfiguration;
+import org.apache.ignite.configuration.IgniteConfiguration;
+import org.apache.ignite.internal.util.IgniteUtils;
+import org.apache.ignite.internal.util.typedef.internal.U;
+import org.apache.ignite.marshaller.MarshallerContextTestImpl;
+import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
+
+import java.math.BigDecimal;
+import java.sql.Timestamp;
+import java.util.Arrays;
+import java.util.Date;
+import java.util.UUID;
+
+/**
+ * Contains tests for portable object fields.
+ */
+public abstract class BinaryFieldsAbstractSelfTest extends GridCommonAbstractTest {
+    /** Marshaller. */
+    protected BinaryMarshaller dfltMarsh;
+
+    /**
+     * Create marshaller.
+     *
+     * @return Portable marshaller.
+     * @throws Exception If failed.
+     */
+    protected BinaryMarshaller createMarshaller() throws Exception {
+        PortableContext ctx = new PortableContext(BinaryCachingMetadataHandler.create(), new IgniteConfiguration());
+
+        BinaryMarshaller marsh = new BinaryMarshaller();
+
+        BinaryConfiguration bCfg = new BinaryConfiguration();
+
+        bCfg.setCompactFooter(compactFooter());
+
+        bCfg.setTypeConfigurations(Arrays.asList(
+            new BinaryTypeConfiguration(TestObject.class.getName()),
+            new BinaryTypeConfiguration(TestOuterObject.class.getName()),
+            new BinaryTypeConfiguration(TestInnerObject.class.getName())
+        ));
+
+        IgniteConfiguration iCfg = new IgniteConfiguration();
+
+        iCfg.setBinaryConfiguration(bCfg);
+
+        marsh.setContext(new MarshallerContextTestImpl(null));
+
+        IgniteUtils.invoke(BinaryMarshaller.class, marsh, "setPortableContext", ctx, iCfg);
+
+        return marsh;
+    }
+
+    /**
+     * @return Whether to use compact footer.
+     */
+    protected boolean compactFooter() {
+        return true;
+    }
+
+    /**
+     * Get portable context for the current marshaller.
+     *
+     * @param marsh Marshaller.
+     * @return Portable context.
+     */
+    protected static PortableContext portableContext(BinaryMarshaller marsh) {
+        GridPortableMarshaller impl = U.field(marsh, "impl");
+
+        return impl.context();
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void beforeTest() throws Exception {
+        super.beforeTest();
+
+        dfltMarsh = createMarshaller();
+    }
+
+    /**
+     * Test byte field.
+     *
+     * @throws Exception If failed.
+     */
+    public void testByte() throws Exception {
+        check("fByte");
+    }
+
+    /**
+     * Test byte array field.
+     *
+     * @throws Exception If failed.
+     */
+    public void testByteArray() throws Exception {
+        check("fByteArr");
+    }
+
+    /**
+     * Test boolean field.
+     *
+     * @throws Exception If failed.
+     */
+    public void testBoolean() throws Exception {
+        check("fBool");
+    }
+
+    /**
+     * Test boolean array field.
+     *
+     * @throws Exception If failed.
+     */
+    public void testBooleanArray() throws Exception {
+        check("fBoolArr");
+    }
+
+    /**
+     * Test short field.
+     *
+     * @throws Exception If failed.
+     */
+    public void testShort() throws Exception {
+        check("fShort");
+    }
+
+    /**
+     * Test short array field.
+     *
+     * @throws Exception If failed.
+     */
+    public void testShortArray() throws Exception {
+        check("fShortArr");
+    }
+
+    /**
+     * Test char field.
+     *
+     * @throws Exception If failed.
+     */
+    public void testChar() throws Exception {
+        check("fChar");
+    }
+
+    /**
+     * Test char array field.
+     *
+     * @throws Exception If failed.
+     */
+    public void testCharArray() throws Exception {
+        check("fCharArr");
+    }
+
+    /**
+     * Test int field.
+     *
+     * @throws Exception If failed.
+     */
+    public void testInt() throws Exception {
+        check("fInt");
+    }
+
+    /**
+     * Test int array field.
+     *
+     * @throws Exception If failed.
+     */
+    public void testIntArray() throws Exception {
+        check("fIntArr");
+    }
+
+    /**
+     * Test long field.
+     *
+     * @throws Exception If failed.
+     */
+    public void testLong() throws Exception {
+        check("fLong");
+    }
+
+    /**
+     * Test long array field.
+     *
+     * @throws Exception If failed.
+     */
+    public void testLongArray() throws Exception {
+        check("fLongArr");
+    }
+
+    /**
+     * Test float field.
+     *
+     * @throws Exception If failed.
+     */
+    public void testFloat() throws Exception {
+        check("fFloat");
+    }
+
+    /**
+     * Test float array field.
+     *
+     * @throws Exception If failed.
+     */
+    public void testFloatArray() throws Exception {
+        check("fFloatArr");
+    }
+
+    /**
+     * Test double field.
+     *
+     * @throws Exception If failed.
+     */
+    public void testDouble() throws Exception {
+        check("fDouble");
+    }
+
+    /**
+     * Test double array field.
+     *
+     * @throws Exception If failed.
+     */
+    public void testDoubleArray() throws Exception {
+        check("fDoubleArr");
+    }
+
+    /**
+     * Test string field.
+     *
+     * @throws Exception If failed.
+     */
+    public void testString() throws Exception {
+        check("fString");
+    }
+
+    /**
+     * Test string array field.
+     *
+     * @throws Exception If failed.
+     */
+    public void testStringArray() throws Exception {
+        check("fStringArr");
+    }
+
+    /**
+     * Test date field.
+     *
+     * @throws Exception If failed.
+     */
+    public void testDate() throws Exception {
+        check("fDate");
+    }
+
+    /**
+     * Test date array field.
+     *
+     * @throws Exception If failed.
+     */
+    public void testDateArray() throws Exception {
+        check("fDateArr");
+    }
+
+    /**
+     * Test timestamp field.
+     *
+     * @throws Exception If failed.
+     */
+    public void testTimestamp() throws Exception {
+        check("fTimestamp");
+    }
+
+    /**
+     * Test timestamp array field.
+     *
+     * @throws Exception If failed.
+     */
+    public void testTimestampArray() throws Exception {
+        check("fTimestampArr");
+    }
+
+    /**
+     * Test UUID field.
+     *
+     * @throws Exception If failed.
+     */
+    public void testUuid() throws Exception {
+        check("fUuid");
+    }
+
+    /**
+     * Test UUID array field.
+     *
+     * @throws Exception If failed.
+     */
+    public void testUuidArray() throws Exception {
+        check("fUuidArr");
+    }
+
+    /**
+     * Test decimal field.
+     *
+     * @throws Exception If failed.
+     */
+    public void testDecimal() throws Exception {
+        check("fDecimal");
+    }
+
+    /**
+     * Test decimal array field.
+     *
+     * @throws Exception If failed.
+     */
+    public void testDecimalArray() throws Exception {
+        check("fDecimalArr");
+    }
+
+    /**
+     * Test object field.
+     *
+     * @throws Exception If failed.
+     */
+    public void testObject() throws Exception {
+        check("fObj");
+    }
+
+    /**
+     * Test object array field.
+     *
+     * @throws Exception If failed.
+     */
+    public void testObjectArray() throws Exception {
+        check("fObjArr");
+    }
+
+    /**
+     * Test null field.
+     *
+     * @throws Exception If failed.
+     */
+    public void testNull() throws Exception {
+        check("fNull");
+    }
+
+    /**
+     * Test missing field.
+     *
+     * @throws Exception If failed.
+     */
+    public void testMissing() throws Exception {
+        String fieldName = "fMissing";
+
+        checkNormal(dfltMarsh, fieldName, false);
+        checkNested(dfltMarsh, fieldName, false);
+    }
+
+    /**
+     * Check field resolution in both normal and nested modes.
+     *
+     * @param fieldName Field name.
+     * @throws Exception If failed.
+     */
+    public void check(String fieldName) throws Exception {
+        checkNormal(dfltMarsh, fieldName, true);
+        checkNested(dfltMarsh, fieldName, true);
+    }
+
+    /**
+     * Check field.
+     *
+     * @param marsh Marshaller.
+     * @param fieldName Field name.
+     * @param exists Whether field should exist.
+     * @throws Exception If failed.
+     */
+    private void checkNormal(BinaryMarshaller marsh, String fieldName, boolean exists) throws Exception {
+        TestContext testCtx = context(marsh, fieldName);
+
+        check0(fieldName, testCtx, exists);
+    }
+
+    /**
+     * Check nested field.
+     *
+     * @param marsh Marshaller.
+     * @param fieldName Field name.
+     * @param exists Whether field should exist.
+     * @throws Exception If failed.
+     */
+    private void checkNested(BinaryMarshaller marsh, String fieldName, boolean exists) throws Exception {
+        TestContext testCtx = nestedContext(marsh, fieldName);
+
+        check0(fieldName, testCtx, exists);
+    }
+
+    /**
+     * Internal check routine.
+     *
+     * @param fieldName Field name.
+     * @param ctx Context.
+     * @param exists Whether field should exist.
+     * @throws Exception If failed.
+     */
+    private void check0(String fieldName, TestContext ctx, boolean exists) throws Exception {
+        Object val = ctx.field.value(ctx.portObj);
+
+        if (exists) {
+            assertTrue(ctx.field.exists(ctx.portObj));
+
+            Object expVal = U.field(ctx.obj, fieldName);
+
+            if (val instanceof BinaryObject)
+                val = ((BinaryObject) val).deserialize();
+
+            if (val != null && val.getClass().isArray()) {
+                assertNotNull(expVal);
+
+                if (val instanceof byte[])
+                    assertTrue(Arrays.equals((byte[]) expVal, (byte[]) val));
+                else if (val instanceof boolean[])
+                    assertTrue(Arrays.equals((boolean[]) expVal, (boolean[]) val));
+                else if (val instanceof short[])
+                    assertTrue(Arrays.equals((short[]) expVal, (short[]) val));
+                else if (val instanceof char[])
+                    assertTrue(Arrays.equals((char[]) expVal, (char[]) val));
+                else if (val instanceof int[])
+                    assertTrue(Arrays.equals((int[]) expVal, (int[]) val));
+                else if (val instanceof long[])
+                    assertTrue(Arrays.equals((long[]) expVal, (long[]) val));
+                else if (val instanceof float[])
+                    assertTrue(Arrays.equals((float[]) expVal, (float[]) val));
+                else if (val instanceof double[])
+                    assertTrue(Arrays.equals((double[]) expVal, (double[]) val));
+                else {
+                    Object[] expVal0 = (Object[])expVal;
+                    Object[] val0 = (Object[])val;
+
+                    assertEquals(expVal0.length, val0.length);
+
+                    for (int i = 0; i < expVal0.length; i++) {
+                        Object expItem = expVal0[i];
+                        Object item = val0[i];
+
+                        if (item instanceof BinaryObject)
+                            item = ((BinaryObject)item).deserialize();
+
+                        assertEquals(expItem, item);
+                    }
+                }
+            }
+            else
+                assertEquals(expVal, val);
+        }
+        else {
+            assertFalse(ctx.field.exists(ctx.portObj));
+
+            assert val == null;
+        }
+    }
+
+    /**
+     * Get test context.
+     *
+     * @param marsh Portable marshaller.
+     * @param fieldName Field name.
+     * @return Test context.
+     * @throws Exception If failed.
+     */
+    private TestContext context(BinaryMarshaller marsh, String fieldName) throws Exception {
+        TestObject obj = createObject();
+
+        BinaryObjectExImpl portObj = toPortable(marsh, obj);
+
+        BinaryField field = portObj.type().field(fieldName);
+
+        return new TestContext(obj, portObj, field);
+    }
+
+    /**
+     * Get test context with nested test object.
+     *
+     * @param marsh Portable marshaller.
+     * @param fieldName Field name.
+     * @return Test context.
+     * @throws Exception If failed.
+     */
+    private TestContext nestedContext(BinaryMarshaller marsh, String fieldName)
+        throws Exception {
+        TestObject obj = createObject();
+        TestOuterObject outObj = new TestOuterObject(obj);
+
+        BinaryObjectExImpl portOutObj = toPortable(marsh, outObj);
+        BinaryObjectExImpl portObj = portOutObj.field("fInner");
+
+        assert portObj != null;
+
+        BinaryField field = portObj.type().field(fieldName);
+
+        return new TestContext(obj, portObj, field);
+    }
+
+    /**
+     * Create test object.
+     *
+     * @return Test object.
+     */
+    private TestObject createObject() {
+        return new TestObject(0);
+    }
+
+    /**
+     * Convert object to portable object.
+     *
+     * @param marsh Marshaller.
+     * @param obj Object.
+     * @return Portable object.
+     * @throws Exception If failed.
+     */
+    protected abstract BinaryObjectExImpl toPortable(BinaryMarshaller marsh, Object obj) throws Exception;
+
+    /**
+     * Outer test object.
+     */
+    @SuppressWarnings("UnusedDeclaration")
+    public static class TestOuterObject {
+        /** Inner object. */
+        public TestObject fInner;
+
+        /**
+         * Default constructor.
+         */
+        public TestOuterObject() {
+            // No-op.
+        }
+
+        /**
+         * Constructor.
+         *
+         * @param fInner Inner object.
+         */
+        public TestOuterObject(TestObject fInner) {
+            this.fInner = fInner;
+        }
+    }
+
+    /**
+     * Test object class, c
+     */
+    @SuppressWarnings("UnusedDeclaration")
+    public static class TestObject {
+        /** Primitive fields. */
+        public byte fByte;
+        public boolean fBool;
+        public short fShort;
+        public char fChar;
+        public int fInt;
+        public long fLong;
+        public float fFloat;
+        public double fDouble;
+
+        public byte[] fByteArr;
+        public boolean[] fBoolArr;
+        public short[] fShortArr;
+        public char[] fCharArr;
+        public int[] fIntArr;
+        public long[] fLongArr;
+        public float[] fFloatArr;
+        public double[] fDoubleArr;
+
+        /** Special fields. */
+        public String fString;
+        public Date fDate;
+        public Timestamp fTimestamp;
+        public UUID fUuid;
+        public BigDecimal fDecimal;
+
+        public String[] fStringArr;
+        public Date[] fDateArr;
+        public Timestamp[] fTimestampArr;
+        public UUID[] fUuidArr;
+        public BigDecimal[] fDecimalArr;
+
+        /** Nested object. */
+        public TestInnerObject fObj;
+
+        public TestInnerObject[] fObjArr;
+
+        /** Field which is always set to null. */
+        public Object fNull;
+
+        /**
+         * Default constructor.
+         */
+        public TestObject() {
+            // No-op.
+        }
+
+        /**
+         * Non-default constructor.
+         *
+         * @param ignore Ignored.
+         */
+        public TestObject(int ignore) {
+            fByte = 1;
+            fBool = true;
+            fShort = 2;
+            fChar = 3;
+            fInt = 4;
+            fLong = 5;
+            fFloat = 6.6f;
+            fDouble = 7.7;
+
+            fByteArr = new byte[] { 1, 2 };
+            fBoolArr = new boolean[] { true, false };
+            fShortArr = new short[] { 2, 3 };
+            fCharArr = new char[] { 3, 4 };
+            fIntArr = new int[] { 4, 5 };
+            fLongArr = new long[] { 5, 6 };
+            fFloatArr = new float[] { 6.6f, 7.7f };
+            fDoubleArr = new double[] { 7.7, 8.8 };
+
+            fString = "8";
+            fDate = new Date();
+            fTimestamp = new Timestamp(new Date().getTime() + 1);
+            fUuid = UUID.randomUUID();
+            fDecimal = new BigDecimal(9);
+
+            fStringArr = new String[] { "8", "9" };
+            fDateArr = new Date[] { new Date(), new Date(new Date().getTime() + 1) };
+            fTimestampArr =
+                new Timestamp[] { new Timestamp(new Date().getTime() + 1), new Timestamp(new Date().getTime() + 2) };
+            fUuidArr = new UUID[] { UUID.randomUUID(), UUID.randomUUID() };
+            fDecimalArr = new BigDecimal[] { new BigDecimal(9), new BigDecimal(10) };
+
+            fObj = new TestInnerObject(10);
+            fObjArr = new TestInnerObject[] { new TestInnerObject(10), new TestInnerObject(11) };
+        }
+    }
+
+    /**
+     * Inner test object.
+     */
+    @SuppressWarnings("UnusedDeclaration")
+    public static class TestInnerObject {
+        /** Value. */
+        private int val;
+
+        /**
+         * Default constructor.
+         */
+        public TestInnerObject() {
+            // No-op.
+        }
+
+        /**
+         * Constructor.
+         *
+         * @param val Value.
+         */
+        public TestInnerObject(int val) {
+            this.val = val;
+        }
+
+        /** {@inheritDoc} */
+        @Override public int hashCode() {
+            return val;
+        }
+
+        /** {@inheritDoc} */
+        @Override public boolean equals(Object other) {
+            return other != null && other instanceof TestInnerObject && val == ((TestInnerObject)(other)).val;
+        }
+    }
+
+    /**
+     * Test context.
+     */
+    public static class TestContext {
+        /** Object. */
+        public final TestObject obj;
+
+        /** Portable object. */
+        public final BinaryObjectExImpl portObj;
+
+        /** Field. */
+        public final BinaryField field;
+
+        /**
+         * Constructor.
+         *
+         * @param obj Object.
+         * @param portObj Portable object.
+         * @param field Field.
+         */
+        public TestContext(TestObject obj, BinaryObjectExImpl portObj, BinaryField field) {
+            this.obj = obj;
+            this.portObj = portObj;
+            this.field = field;
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/1dbf20e0/modules/core/src/test/java/org/apache/ignite/internal/binary/BinaryFieldsHeapSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/binary/BinaryFieldsHeapSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/binary/BinaryFieldsHeapSelfTest.java
new file mode 100644
index 0000000..0e92bf4
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/binary/BinaryFieldsHeapSelfTest.java
@@ -0,0 +1,30 @@
+/*
+ * 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.binary;
+
+/**
+ * Field tests for heap-based portables.
+ */
+public class BinaryFieldsHeapSelfTest extends BinaryFieldsAbstractSelfTest {
+    /** {@inheritDoc} */
+    @Override protected BinaryObjectExImpl toPortable(BinaryMarshaller marsh, Object obj) throws Exception {
+        byte[] bytes = marsh.marshal(obj);
+
+        return new BinaryObjectImpl(portableContext(marsh), bytes, 0);
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/1dbf20e0/modules/core/src/test/java/org/apache/ignite/internal/binary/BinaryFieldsOffheapSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/binary/BinaryFieldsOffheapSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/binary/BinaryFieldsOffheapSelfTest.java
new file mode 100644
index 0000000..d24d898
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/binary/BinaryFieldsOffheapSelfTest.java
@@ -0,0 +1,60 @@
+/*
+ * 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.binary;
+
+import org.apache.ignite.internal.util.GridUnsafe;
+import org.eclipse.jetty.util.ConcurrentHashSet;
+import sun.misc.Unsafe;
+
+/**
+ * Field tests for heap-based portables.
+ */
+public class BinaryFieldsOffheapSelfTest extends BinaryFieldsAbstractSelfTest {
+    /** Unsafe instance. */
+    private static final Unsafe UNSAFE = GridUnsafe.unsafe();
+
+    /** Byte array offset for unsafe mechanics. */
+    protected static final long BYTE_ARR_OFF = UNSAFE.arrayBaseOffset(byte[].class);
+
+    /** Allocated unsafe pointer. */
+    private final ConcurrentHashSet<Long> ptrs = new ConcurrentHashSet<>();
+
+    /** {@inheritDoc} */
+    @Override protected void afterTest() throws Exception {
+        super.afterTest();
+
+        // Cleanup allocated objects.
+        for (Long ptr : ptrs)
+            UNSAFE.freeMemory(ptr);
+
+        ptrs.clear();
+    }
+
+    /** {@inheritDoc} */
+    @Override protected BinaryObjectExImpl toPortable(BinaryMarshaller marsh, Object obj) throws Exception {
+        byte[] arr = marsh.marshal(obj);
+
+        long ptr = UNSAFE.allocateMemory(arr.length);
+
+        ptrs.add(ptr);
+
+        UNSAFE.copyMemory(arr, BYTE_ARR_OFF, null, ptr, arr.length);
+
+        return new BinaryObjectOffheapImpl(portableContext(marsh), ptr, 0, arr.length);
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/1dbf20e0/modules/core/src/test/java/org/apache/ignite/internal/binary/BinaryFooterOffsetsAbstractSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/binary/BinaryFooterOffsetsAbstractSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/binary/BinaryFooterOffsetsAbstractSelfTest.java
new file mode 100644
index 0000000..1e0f375
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/binary/BinaryFooterOffsetsAbstractSelfTest.java
@@ -0,0 +1,205 @@
+/*
+ * 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.binary;
+
+import java.util.Arrays;
+import org.apache.ignite.binary.BinaryField;
+import org.apache.ignite.binary.BinaryTypeConfiguration;
+import org.apache.ignite.configuration.BinaryConfiguration;
+import org.apache.ignite.configuration.IgniteConfiguration;
+import org.apache.ignite.internal.util.IgniteUtils;
+import org.apache.ignite.marshaller.MarshallerContextTestImpl;
+import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
+
+/**
+ * Contains tests for compact offsets.
+ */
+public abstract class BinaryFooterOffsetsAbstractSelfTest extends GridCommonAbstractTest {
+    /** 2 pow 8. */
+    private static int POW_8 = 1 << 8;
+
+    /** 2 pow 16. */
+    private static int POW_16 = 1 << 16;
+
+    /** Marshaller. */
+    protected BinaryMarshaller marsh;
+
+    /** Portable context. */
+    protected PortableContext ctx;
+
+    /** {@inheritDoc} */
+    @Override protected void beforeTest() throws Exception {
+        super.beforeTest();
+
+        ctx = new PortableContext(BinaryCachingMetadataHandler.create(), new IgniteConfiguration());
+
+        marsh = new BinaryMarshaller();
+
+        IgniteConfiguration iCfg = new IgniteConfiguration();
+
+        BinaryConfiguration bCfg = new BinaryConfiguration();
+
+        bCfg.setTypeConfigurations(Arrays.asList(new BinaryTypeConfiguration(TestObject.class.getName())));
+
+        bCfg.setCompactFooter(compactFooter());
+
+        iCfg.setBinaryConfiguration(bCfg);
+
+        marsh.setContext(new MarshallerContextTestImpl(null));
+
+        IgniteUtils.invoke(BinaryMarshaller.class, marsh, "setPortableContext", ctx, iCfg);
+    }
+
+    /**
+     * @return Whether to use compact footers.
+     */
+    protected boolean compactFooter() {
+        return true;
+    }
+
+    /**
+     * Test 1 byte.
+     *
+     * @throws Exception If failed.
+     */
+    public void test1Byte() throws Exception {
+        check(POW_8 >> 2);
+    }
+
+    /**
+     * Test 1 byte with sign altering.
+     *
+     * @throws Exception If failed.
+     */
+    public void test1ByteSign() throws Exception {
+        check(POW_8 >> 1);
+    }
+
+    /**
+     * Test 2 bytes.
+     *
+     * @throws Exception If failed.
+     */
+    public void test2Bytes() throws Exception {
+        check(POW_16 >> 2);
+    }
+
+    /**
+     * Test 2 bytes with sign altering.
+     *
+     * @throws Exception If failed.
+     */
+    public void test2BytesSign() throws Exception {
+        check(POW_16 >> 1);
+    }
+
+    /**
+     * Test 4 bytes.
+     *
+     * @throws Exception If failed.
+     */
+    public void test4Bytes() throws Exception {
+        check(POW_16 << 2);
+    }
+
+    /**
+     * Main check routine.
+     *
+     * @param len Length of the first field.
+     *
+     * @throws Exception If failed.
+     */
+    private void check(int len) throws Exception {
+        TestObject obj = new TestObject(len);
+
+        BinaryObjectExImpl portObj = toPortable(marsh, obj);
+
+        // 1. Test portable object content.
+        assert portObj.hasField("field1");
+        assert portObj.hasField("field2");
+
+        byte[] field1 = portObj.field("field1");
+        Integer field2 = portObj.field("field2");
+
+        assert field1 != null;
+        assert field2 != null;
+
+        assert Arrays.equals(obj.field1, field1);
+        assert obj.field2 == field2;
+
+        // 2. Test fields API.
+        BinaryField field1Desc = portObj.type().field("field1");
+        BinaryField field2Desc = portObj.type().field("field2");
+
+        assert field1Desc.exists(portObj);
+        assert field2Desc.exists(portObj);
+
+        assert Arrays.equals(obj.field1, (byte[])field1Desc.value(portObj));
+        assert obj.field2 == (Integer)field2Desc.value(portObj);
+
+        // 3. Test deserialize.
+        TestObject objRestored = portObj.deserialize();
+
+        assert objRestored != null;
+
+        assert Arrays.equals(obj.field1, objRestored.field1);
+        assert obj.field2 == objRestored.field2;
+    }
+
+    /**
+     * Convert object to portable object.
+     *
+     * @param marsh Marshaller.
+     * @param obj Object.
+     * @return Portable object.
+     * @throws Exception If failed.
+     */
+    protected abstract BinaryObjectExImpl toPortable(BinaryMarshaller marsh, Object obj) throws Exception;
+
+    /**
+     * Test object.
+     */
+    public static class TestObject {
+        /** First field with variable length. */
+        public byte[] field1;
+
+        /** Second field. */
+        public int field2;
+
+        /**
+         * Default constructor.
+         */
+        public TestObject() {
+            // No-op.
+        }
+
+        /**
+         * Constructor.
+         *
+         * @param len Array length.
+         */
+        public TestObject(int len) {
+            field1 = new byte[len];
+
+            field1[0] = 1;
+            field1[len - 1] = 2;
+
+            field2 = len;
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/1dbf20e0/modules/core/src/test/java/org/apache/ignite/internal/binary/BinaryFooterOffsetsHeapSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/binary/BinaryFooterOffsetsHeapSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/binary/BinaryFooterOffsetsHeapSelfTest.java
new file mode 100644
index 0000000..68e897e
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/binary/BinaryFooterOffsetsHeapSelfTest.java
@@ -0,0 +1,30 @@
+/*
+ * 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.binary;
+
+/**
+ * Compact offsets tests for heap portable objects.
+ */
+public class BinaryFooterOffsetsHeapSelfTest extends BinaryFooterOffsetsAbstractSelfTest {
+    /** {@inheritDoc} */
+    @Override protected BinaryObjectExImpl toPortable(BinaryMarshaller marsh, Object obj) throws Exception {
+        byte[] bytes = marsh.marshal(obj);
+
+        return new BinaryObjectImpl(ctx, bytes, 0);
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/1dbf20e0/modules/core/src/test/java/org/apache/ignite/internal/binary/BinaryFooterOffsetsOffheapSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/binary/BinaryFooterOffsetsOffheapSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/binary/BinaryFooterOffsetsOffheapSelfTest.java
new file mode 100644
index 0000000..f0f0396
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/binary/BinaryFooterOffsetsOffheapSelfTest.java
@@ -0,0 +1,60 @@
+/*
+ * 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.binary;
+
+import org.apache.ignite.internal.util.GridUnsafe;
+import org.eclipse.jetty.util.ConcurrentHashSet;
+import sun.misc.Unsafe;
+
+/**
+ * Compact offsets tests for offheap portable objects.
+ */
+public class BinaryFooterOffsetsOffheapSelfTest extends BinaryFooterOffsetsAbstractSelfTest {
+    /** Unsafe instance. */
+    private static final Unsafe UNSAFE = GridUnsafe.unsafe();
+
+    /** Byte array offset for unsafe mechanics. */
+    protected static final long BYTE_ARR_OFF = UNSAFE.arrayBaseOffset(byte[].class);
+
+    /** Allocated unsafe pointer. */
+    private final ConcurrentHashSet<Long> ptrs = new ConcurrentHashSet<>();
+
+    /** {@inheritDoc} */
+    @Override protected void afterTest() throws Exception {
+        super.afterTest();
+
+        // Cleanup allocated objects.
+        for (Long ptr : ptrs)
+            UNSAFE.freeMemory(ptr);
+
+        ptrs.clear();
+    }
+
+    /** {@inheritDoc} */
+    @Override protected BinaryObjectExImpl toPortable(BinaryMarshaller marsh, Object obj) throws Exception {
+        byte[] arr = marsh.marshal(obj);
+
+        long ptr = UNSAFE.allocateMemory(arr.length);
+
+        ptrs.add(ptr);
+
+        UNSAFE.copyMemory(arr, BYTE_ARR_OFF, null, ptr, arr.length);
+
+        return new BinaryObjectOffheapImpl(ctx, ptr, 0, arr.length);
+    }
+}


[57/59] [abbrv] ignite git commit: ignite-2065: rename "portable" classes to "binary" (in tests)

Posted by ak...@apache.org.
http://git-wip-us.apache.org/repos/asf/ignite/blob/469bf6d6/modules/core/src/test/java/org/apache/ignite/internal/binary/GridBinaryWildcardsSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/binary/GridBinaryWildcardsSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/binary/GridBinaryWildcardsSelfTest.java
new file mode 100644
index 0000000..9cf1242
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/binary/GridBinaryWildcardsSelfTest.java
@@ -0,0 +1,464 @@
+/*
+ * 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.binary;
+
+import java.util.Collection;
+import org.apache.ignite.IgniteCheckedException;
+import org.apache.ignite.binary.BinaryIdMapper;
+import org.apache.ignite.binary.BinarySerializer;
+import org.apache.ignite.binary.BinaryTypeConfiguration;
+import org.apache.ignite.configuration.BinaryConfiguration;
+import org.apache.ignite.configuration.IgniteConfiguration;
+import org.apache.ignite.internal.util.IgniteUtils;
+import org.apache.ignite.internal.util.typedef.internal.U;
+import org.apache.ignite.marshaller.MarshallerContextTestImpl;
+import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
+
+import java.util.Arrays;
+import java.util.Map;
+
+/**
+ * Wildcards test.
+ */
+public class GridBinaryWildcardsSelfTest extends GridCommonAbstractTest {
+    /**
+     * @throws Exception If failed.
+     */
+    public void testClassNames() throws Exception {
+        BinaryMarshaller marsh = portableMarshaller(Arrays.asList(
+            new BinaryTypeConfiguration("org.apache.ignite.internal.binary.test.*"),
+            new BinaryTypeConfiguration("unknown.*")
+        ));
+
+        BinaryContext ctx = portableContext(marsh);
+
+        Map<Integer, Class> typeIds = U.field(ctx, "userTypes");
+
+        assertEquals(3, typeIds.size());
+
+        assertTrue(typeIds.containsKey("gridportabletestclass1".hashCode()));
+        assertTrue(typeIds.containsKey("gridportabletestclass2".hashCode()));
+        assertTrue(typeIds.containsKey("innerclass".hashCode()));
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testClassNamesWithMapper() throws Exception {
+        BinaryMarshaller marsh = portableMarshaller(new BinaryIdMapper() {
+            @SuppressWarnings("IfMayBeConditional")
+            @Override public int typeId(String clsName) {
+                if (clsName.endsWith("1"))
+                    return 300;
+                else if (clsName.endsWith("2"))
+                    return 400;
+                else if (clsName.endsWith("InnerClass"))
+                    return 500;
+                else
+                    return -500;
+            }
+
+            @Override public int fieldId(int typeId, String fieldName) {
+                return 0;
+            }
+        }, Arrays.asList(
+            new BinaryTypeConfiguration("org.apache.ignite.internal.binary.test.*"),
+            new BinaryTypeConfiguration("unknown.*")
+        ));
+
+        BinaryContext ctx = portableContext(marsh);
+
+        Map<String, BinaryIdMapper> typeMappers = U.field(ctx, "typeMappers");
+
+        assertEquals(3, typeMappers.size());
+
+        assertEquals(300, typeMappers.get("GridPortableTestClass1").typeId("GridPortableTestClass1"));
+        assertEquals(400, typeMappers.get("GridPortableTestClass2").typeId("GridPortableTestClass2"));
+        assertEquals(500, typeMappers.get("InnerClass").typeId("InnerClass"));
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testTypeConfigurations() throws Exception {
+        BinaryMarshaller marsh = portableMarshaller(Arrays.asList(
+            new BinaryTypeConfiguration("org.apache.ignite.internal.binary.test.*"),
+            new BinaryTypeConfiguration("unknown.*")
+        ));
+
+        BinaryContext ctx = portableContext(marsh);
+
+        Map<Integer, Class> typeIds = U.field(ctx, "userTypes");
+
+        assertEquals(3, typeIds.size());
+
+        assertTrue(typeIds.containsKey("gridportabletestclass1".hashCode()));
+        assertTrue(typeIds.containsKey("gridportabletestclass2".hashCode()));
+        assertTrue(typeIds.containsKey("innerclass".hashCode()));
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testTypeConfigurationsWithGlobalMapper() throws Exception {
+        BinaryMarshaller marsh = portableMarshaller(new BinaryIdMapper() {
+            @SuppressWarnings("IfMayBeConditional")
+            @Override public int typeId(String clsName) {
+                if (clsName.endsWith("1"))
+                    return 300;
+                else if (clsName.endsWith("2"))
+                    return 400;
+                else if (clsName.endsWith("InnerClass"))
+                    return 500;
+                else
+                    return -500;
+            }
+
+            @Override public int fieldId(int typeId, String fieldName) {
+                return 0;
+            }
+        }, Arrays.asList(
+            new BinaryTypeConfiguration("org.apache.ignite.internal.binary.test.*"),
+            new BinaryTypeConfiguration("unknown.*")
+        ));
+
+        BinaryContext ctx = portableContext(marsh);
+
+        Map<String, BinaryIdMapper> typeMappers = U.field(ctx, "typeMappers");
+
+        assertEquals(3, typeMappers.size());
+
+        assertEquals(300, typeMappers.get("GridPortableTestClass1").typeId("GridPortableTestClass1"));
+        assertEquals(400, typeMappers.get("GridPortableTestClass2").typeId("GridPortableTestClass2"));
+        assertEquals(500, typeMappers.get("InnerClass").typeId("InnerClass"));
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testTypeConfigurationsWithNonGlobalMapper() throws Exception {
+        BinaryMarshaller marsh = portableMarshaller(new BinaryIdMapper() {
+            @SuppressWarnings("IfMayBeConditional")
+            @Override public int typeId(String clsName) {
+                if (clsName.endsWith("1"))
+                    return 300;
+                else if (clsName.endsWith("2"))
+                    return 400;
+                else if (clsName.endsWith("InnerClass"))
+                    return 500;
+                else
+                    return -500;
+            }
+
+            @Override public int fieldId(int typeId, String fieldName) {
+                return 0;
+            }
+        }, Arrays.asList(
+            new BinaryTypeConfiguration("org.apache.ignite.internal.binary.test.*"),
+            new BinaryTypeConfiguration("unknown.*")
+        ));
+
+        BinaryContext ctx = portableContext(marsh);
+
+        Map<String, BinaryIdMapper> typeMappers = U.field(ctx, "typeMappers");
+
+        assertEquals(3, typeMappers.size());
+
+        assertEquals(300, typeMappers.get("GridPortableTestClass1").typeId("GridPortableTestClass1"));
+        assertEquals(400, typeMappers.get("GridPortableTestClass2").typeId("GridPortableTestClass2"));
+        assertEquals(500, typeMappers.get("InnerClass").typeId("InnerClass"));
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testOverride() throws Exception {
+        BinaryTypeConfiguration typeCfg = new BinaryTypeConfiguration();
+
+        typeCfg.setTypeName("GridPortableTestClass2");
+        typeCfg.setIdMapper(new BinaryIdMapper() {
+            @Override public int typeId(String clsName) {
+                return 100;
+            }
+
+            @Override public int fieldId(int typeId, String fieldName) {
+                return 0;
+            }
+        });
+
+        BinaryMarshaller marsh = portableMarshaller(Arrays.asList(
+            new BinaryTypeConfiguration("org.apache.ignite.internal.binary.test.*"),
+            typeCfg));
+
+        BinaryContext ctx = portableContext(marsh);
+
+        Map<Integer, Class> typeIds = U.field(ctx, "userTypes");
+
+        assertEquals(3, typeIds.size());
+
+        assertTrue(typeIds.containsKey("gridportabletestclass1".hashCode()));
+        assertTrue(typeIds.containsKey("innerclass".hashCode()));
+        assertFalse(typeIds.containsKey("gridportabletestclass2".hashCode()));
+
+        Map<String, BinaryIdMapper> typeMappers = U.field(ctx, "typeMappers");
+
+        assertEquals(100, typeMappers.get("GridPortableTestClass2").typeId("GridPortableTestClass2"));
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testClassNamesJar() throws Exception {
+        BinaryMarshaller marsh = portableMarshaller(Arrays.asList(
+            new BinaryTypeConfiguration("org.apache.ignite.binary.testjar.*"),
+            new BinaryTypeConfiguration("unknown.*")
+        ));
+
+        BinaryContext ctx = portableContext(marsh);
+
+        Map<Integer, Class> typeIds = U.field(ctx, "userTypes");
+
+        assertEquals(3, typeIds.size());
+
+        assertTrue(typeIds.containsKey("gridportabletestclass1".hashCode()));
+        assertTrue(typeIds.containsKey("gridportabletestclass2".hashCode()));
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testClassNamesWithMapperJar() throws Exception {
+        BinaryMarshaller marsh = portableMarshaller(new BinaryIdMapper() {
+            @SuppressWarnings("IfMayBeConditional")
+            @Override public int typeId(String clsName) {
+                if (clsName.endsWith("1"))
+                    return 300;
+                else if (clsName.endsWith("2"))
+                    return 400;
+                else
+                    return -500;
+            }
+
+            @Override public int fieldId(int typeId, String fieldName) {
+                return 0;
+            }
+        }, Arrays.asList(
+            new BinaryTypeConfiguration("org.apache.ignite.binary.testjar.*"),
+            new BinaryTypeConfiguration("unknown.*")
+        ));
+
+        BinaryContext ctx = portableContext(marsh);
+
+        Map<String, BinaryIdMapper> typeMappers = U.field(ctx, "typeMappers");
+
+        assertEquals(3, typeMappers.size());
+
+        assertEquals(300, typeMappers.get("GridPortableTestClass1").typeId("GridPortableTestClass1"));
+        assertEquals(400, typeMappers.get("GridPortableTestClass2").typeId("GridPortableTestClass2"));
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testTypeConfigurationsJar() throws Exception {
+        BinaryMarshaller marsh = portableMarshaller(Arrays.asList(
+            new BinaryTypeConfiguration("org.apache.ignite.binary.testjar.*"),
+            new BinaryTypeConfiguration("unknown.*")
+        ));
+
+        BinaryContext ctx = portableContext(marsh);
+
+        Map<Integer, Class> typeIds = U.field(ctx, "userTypes");
+
+        assertEquals(3, typeIds.size());
+
+        assertTrue(typeIds.containsKey("gridportabletestclass1".hashCode()));
+        assertTrue(typeIds.containsKey("gridportabletestclass2".hashCode()));
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testTypeConfigurationsWithGlobalMapperJar() throws Exception {
+        BinaryMarshaller marsh = portableMarshaller(new BinaryIdMapper() {
+            @SuppressWarnings("IfMayBeConditional")
+            @Override public int typeId(String clsName) {
+                if (clsName.endsWith("1"))
+                    return 300;
+                else if (clsName.endsWith("2"))
+                    return 400;
+                else
+                    return -500;
+            }
+
+            @Override public int fieldId(int typeId, String fieldName) {
+                return 0;
+            }
+        }, Arrays.asList(
+            new BinaryTypeConfiguration("org.apache.ignite.binary.testjar.*"),
+            new BinaryTypeConfiguration("unknown.*")
+        ));
+
+        BinaryContext ctx = portableContext(marsh);
+
+        Map<String, BinaryIdMapper> typeMappers = U.field(ctx, "typeMappers");
+
+        assertEquals(3, typeMappers.size());
+
+        assertEquals(300, typeMappers.get("GridPortableTestClass1").typeId("GridPortableTestClass1"));
+        assertEquals(400, typeMappers.get("GridPortableTestClass2").typeId("GridPortableTestClass2"));
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testTypeConfigurationsWithNonGlobalMapperJar() throws Exception {
+        BinaryMarshaller marsh = portableMarshaller(new BinaryIdMapper() {
+            @SuppressWarnings("IfMayBeConditional")
+            @Override public int typeId(String clsName) {
+                if (clsName.endsWith("1"))
+                    return 300;
+                else if (clsName.endsWith("2"))
+                    return 400;
+                else
+                    return -500;
+            }
+
+            @Override public int fieldId(int typeId, String fieldName) {
+                return 0;
+            }
+        }, Arrays.asList(
+            new BinaryTypeConfiguration("org.apache.ignite.binary.testjar.*"),
+            new BinaryTypeConfiguration("unknown.*")
+        ));
+
+        BinaryContext ctx = portableContext(marsh);
+
+        Map<String, BinaryIdMapper> typeMappers = U.field(ctx, "typeMappers");
+
+        assertEquals(3, typeMappers.size());
+
+        assertEquals(300, typeMappers.get("GridPortableTestClass1").typeId("GridPortableTestClass1"));
+        assertEquals(400, typeMappers.get("GridPortableTestClass2").typeId("GridPortableTestClass2"));
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testOverrideJar() throws Exception {
+        BinaryTypeConfiguration typeCfg = new BinaryTypeConfiguration(
+            "org.apache.ignite.binary.testjar.GridPortableTestClass2");
+
+        typeCfg.setIdMapper(new BinaryIdMapper() {
+            @Override public int typeId(String clsName) {
+                return 100;
+            }
+
+            @Override public int fieldId(int typeId, String fieldName) {
+                return 0;
+            }
+        });
+
+        BinaryMarshaller marsh = portableMarshaller(Arrays.asList(
+            new BinaryTypeConfiguration("org.apache.ignite.binary.testjar.*"),
+            typeCfg));
+
+        BinaryContext ctx = portableContext(marsh);
+
+        Map<Integer, Class> typeIds = U.field(ctx, "userTypes");
+
+        assertEquals(3, typeIds.size());
+
+        assertTrue(typeIds.containsKey("gridportabletestclass1".hashCode()));
+
+        Map<String, BinaryIdMapper> typeMappers = U.field(ctx, "typeMappers");
+
+        assertEquals(3, typeMappers.size());
+
+        assertEquals(100, typeMappers.get("GridPortableTestClass2").typeId("GridPortableTestClass2"));
+    }
+
+    /**
+     * @param marsh Marshaller.
+     * @return Portable context.
+     */
+    protected BinaryContext portableContext(BinaryMarshaller marsh) {
+        GridBinaryMarshaller impl = U.field(marsh, "impl");
+
+        return impl.context();
+    }
+
+    /**
+     *
+     */
+    protected BinaryMarshaller portableMarshaller()
+        throws IgniteCheckedException {
+        return portableMarshaller(null, null, null);
+    }
+
+    /**
+     *
+     */
+    protected BinaryMarshaller portableMarshaller(Collection<BinaryTypeConfiguration> cfgs)
+        throws IgniteCheckedException {
+        return portableMarshaller(null, null, cfgs);
+    }
+
+    /**
+     *
+     */
+    protected BinaryMarshaller portableMarshaller(BinaryIdMapper mapper, Collection<BinaryTypeConfiguration> cfgs)
+        throws IgniteCheckedException {
+        return portableMarshaller(mapper, null, cfgs);
+    }
+
+    /**
+     *
+     */
+    protected BinaryMarshaller portableMarshaller(BinarySerializer serializer, Collection<BinaryTypeConfiguration> cfgs)
+        throws IgniteCheckedException {
+        return portableMarshaller(null, serializer, cfgs);
+    }
+
+    protected BinaryMarshaller portableMarshaller(
+        BinaryIdMapper mapper,
+        BinarySerializer serializer,
+        Collection<BinaryTypeConfiguration> cfgs
+    ) throws IgniteCheckedException {
+        IgniteConfiguration iCfg = new IgniteConfiguration();
+
+        BinaryConfiguration bCfg = new BinaryConfiguration();
+
+        bCfg.setIdMapper(mapper);
+        bCfg.setSerializer(serializer);
+
+        bCfg.setTypeConfigurations(cfgs);
+
+        iCfg.setBinaryConfiguration(bCfg);
+
+        BinaryContext ctx = new BinaryContext(BinaryNoopMetadataHandler.instance(), iCfg);
+
+        BinaryMarshaller marsh = new BinaryMarshaller();
+
+        marsh.setContext(new MarshallerContextTestImpl(null));
+
+        IgniteUtils.invoke(BinaryMarshaller.class, marsh, "setPortableContext", ctx, iCfg);
+
+        return marsh;
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/469bf6d6/modules/core/src/test/java/org/apache/ignite/internal/binary/GridPortableMetaDataSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/binary/GridPortableMetaDataSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/binary/GridPortableMetaDataSelfTest.java
deleted file mode 100644
index 5d74e12..0000000
--- a/modules/core/src/test/java/org/apache/ignite/internal/binary/GridPortableMetaDataSelfTest.java
+++ /dev/null
@@ -1,371 +0,0 @@
-/*
- * 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.binary;
-
-import java.math.BigDecimal;
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.Date;
-import java.util.HashMap;
-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.binary.BinaryObjectException;
-import org.apache.ignite.binary.Binarylizable;
-import org.apache.ignite.binary.BinaryType;
-import org.apache.ignite.binary.BinaryObject;
-import org.apache.ignite.binary.BinaryRawWriter;
-import org.apache.ignite.binary.BinaryReader;
-import org.apache.ignite.binary.BinaryWriter;
-import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
-
-/**
- * Portable meta data test.
- */
-public class GridPortableMetaDataSelfTest extends GridCommonAbstractTest {
-    /** */
-    private static int idx;
-
-    /** {@inheritDoc} */
-    @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception {
-        IgniteConfiguration cfg = super.getConfiguration(gridName);
-
-        BinaryConfiguration bCfg = new BinaryConfiguration();
-
-        bCfg.setClassNames(Arrays.asList(TestObject1.class.getName(), TestObject2.class.getName()));
-
-        cfg.setBinaryConfiguration(bCfg);
-
-        cfg.setMarshaller(new BinaryMarshaller());
-
-        CacheConfiguration ccfg = new CacheConfiguration();
-
-        cfg.setCacheConfiguration(ccfg);
-
-        return cfg;
-    }
-
-    /** {@inheritDoc} */
-    @Override protected void beforeTest() throws Exception {
-        idx = 0;
-
-        startGrid();
-    }
-
-    /** {@inheritDoc} */
-    @Override protected void afterTest() throws Exception {
-        stopGrid();
-    }
-
-    /**
-     * @return Portables API.
-     */
-    protected IgniteBinary portables() {
-        return grid().binary();
-    }
-
-    /**
-     * @throws Exception If failed.
-     */
-    public void testGetAll() throws Exception {
-        portables().toBinary(new TestObject2());
-
-        Collection<BinaryType> metas = portables().types();
-
-        assertEquals(2, metas.size());
-
-        for (BinaryType meta : metas) {
-            Collection<String> fields;
-
-            switch (meta.typeName()) {
-                case "TestObject1":
-                    fields = meta.fieldNames();
-
-                    assertEquals(7, fields.size());
-
-                    assertTrue(fields.contains("intVal"));
-                    assertTrue(fields.contains("strVal"));
-                    assertTrue(fields.contains("arrVal"));
-                    assertTrue(fields.contains("obj1Val"));
-                    assertTrue(fields.contains("obj2Val"));
-                    assertTrue(fields.contains("decVal"));
-                    assertTrue(fields.contains("decArrVal"));
-
-                    assertEquals("int", meta.fieldTypeName("intVal"));
-                    assertEquals("String", meta.fieldTypeName("strVal"));
-                    assertEquals("byte[]", meta.fieldTypeName("arrVal"));
-                    assertEquals("Object", meta.fieldTypeName("obj1Val"));
-                    assertEquals("Object", meta.fieldTypeName("obj2Val"));
-                    assertEquals("decimal", meta.fieldTypeName("decVal"));
-                    assertEquals("decimal[]", meta.fieldTypeName("decArrVal"));
-
-                    break;
-
-                case "TestObject2":
-                    fields = meta.fieldNames();
-
-                    assertEquals(7, fields.size());
-
-                    assertTrue(fields.contains("boolVal"));
-                    assertTrue(fields.contains("dateVal"));
-                    assertTrue(fields.contains("uuidArrVal"));
-                    assertTrue(fields.contains("objVal"));
-                    assertTrue(fields.contains("mapVal"));
-                    assertTrue(fields.contains("decVal"));
-                    assertTrue(fields.contains("decArrVal"));
-
-                    assertEquals("boolean", meta.fieldTypeName("boolVal"));
-                    assertEquals("Date", meta.fieldTypeName("dateVal"));
-                    assertEquals("UUID[]", meta.fieldTypeName("uuidArrVal"));
-                    assertEquals("Object", meta.fieldTypeName("objVal"));
-                    assertEquals("Map", meta.fieldTypeName("mapVal"));
-                    assertEquals("decimal", meta.fieldTypeName("decVal"));
-                    assertEquals("decimal[]", meta.fieldTypeName("decArrVal"));
-
-                    break;
-
-                default:
-                    assert false : meta.typeName();
-            }
-        }
-    }
-
-    /**
-     * @throws Exception If failed.
-     */
-    public void testNoConfiguration() throws Exception {
-        portables().toBinary(new TestObject3());
-
-        assertNotNull(portables().type(TestObject3.class));
-    }
-
-    /**
-     * @throws Exception If failed.
-     */
-    public void testReflection() throws Exception {
-        BinaryType meta = portables().type(TestObject1.class);
-
-        assertNotNull(meta);
-
-        assertEquals("TestObject1", meta.typeName());
-
-        Collection<String> fields = meta.fieldNames();
-
-        assertEquals(7, fields.size());
-
-        assertTrue(fields.contains("intVal"));
-        assertTrue(fields.contains("strVal"));
-        assertTrue(fields.contains("arrVal"));
-        assertTrue(fields.contains("obj1Val"));
-        assertTrue(fields.contains("obj2Val"));
-        assertTrue(fields.contains("decVal"));
-        assertTrue(fields.contains("decArrVal"));
-
-        assertEquals("int", meta.fieldTypeName("intVal"));
-        assertEquals("String", meta.fieldTypeName("strVal"));
-        assertEquals("byte[]", meta.fieldTypeName("arrVal"));
-        assertEquals("Object", meta.fieldTypeName("obj1Val"));
-        assertEquals("Object", meta.fieldTypeName("obj2Val"));
-        assertEquals("decimal", meta.fieldTypeName("decVal"));
-        assertEquals("decimal[]", meta.fieldTypeName("decArrVal"));
-    }
-
-    /**
-     * @throws Exception If failed.
-     */
-    public void testPortableMarshalAware() throws Exception {
-        portables().toBinary(new TestObject2());
-
-        BinaryType meta = portables().type(TestObject2.class);
-
-        assertNotNull(meta);
-
-        assertEquals("TestObject2", meta.typeName());
-
-        Collection<String> fields = meta.fieldNames();
-
-        assertEquals(7, fields.size());
-
-        assertTrue(fields.contains("boolVal"));
-        assertTrue(fields.contains("dateVal"));
-        assertTrue(fields.contains("uuidArrVal"));
-        assertTrue(fields.contains("objVal"));
-        assertTrue(fields.contains("mapVal"));
-        assertTrue(fields.contains("decVal"));
-        assertTrue(fields.contains("decArrVal"));
-
-        assertEquals("boolean", meta.fieldTypeName("boolVal"));
-        assertEquals("Date", meta.fieldTypeName("dateVal"));
-        assertEquals("UUID[]", meta.fieldTypeName("uuidArrVal"));
-        assertEquals("Object", meta.fieldTypeName("objVal"));
-        assertEquals("Map", meta.fieldTypeName("mapVal"));
-        assertEquals("decimal", meta.fieldTypeName("decVal"));
-        assertEquals("decimal[]", meta.fieldTypeName("decArrVal"));
-    }
-
-    /**
-     * @throws Exception If failed.
-     */
-    public void testMerge() throws Exception {
-        portables().toBinary(new TestObject2());
-
-        idx = 1;
-
-        portables().toBinary(new TestObject2());
-
-        BinaryType meta = portables().type(TestObject2.class);
-
-        assertNotNull(meta);
-
-        assertEquals("TestObject2", meta.typeName());
-
-        Collection<String> fields = meta.fieldNames();
-
-        assertEquals(9, fields.size());
-
-        assertTrue(fields.contains("boolVal"));
-        assertTrue(fields.contains("dateVal"));
-        assertTrue(fields.contains("uuidArrVal"));
-        assertTrue(fields.contains("objVal"));
-        assertTrue(fields.contains("mapVal"));
-        assertTrue(fields.contains("charVal"));
-        assertTrue(fields.contains("colVal"));
-        assertTrue(fields.contains("decVal"));
-        assertTrue(fields.contains("decArrVal"));
-
-        assertEquals("boolean", meta.fieldTypeName("boolVal"));
-        assertEquals("Date", meta.fieldTypeName("dateVal"));
-        assertEquals("UUID[]", meta.fieldTypeName("uuidArrVal"));
-        assertEquals("Object", meta.fieldTypeName("objVal"));
-        assertEquals("Map", meta.fieldTypeName("mapVal"));
-        assertEquals("char", meta.fieldTypeName("charVal"));
-        assertEquals("Collection", meta.fieldTypeName("colVal"));
-        assertEquals("decimal", meta.fieldTypeName("decVal"));
-        assertEquals("decimal[]", meta.fieldTypeName("decArrVal"));
-    }
-
-    /**
-     * @throws Exception If failed.
-     */
-    public void testSerializedObject() throws Exception {
-        TestObject1 obj = new TestObject1();
-
-        obj.intVal = 10;
-        obj.strVal = "str";
-        obj.arrVal = new byte[] {2, 4, 6};
-        obj.obj1Val = null;
-        obj.obj2Val = new TestObject2();
-        obj.decVal = BigDecimal.ZERO;
-        obj.decArrVal = new BigDecimal[] { BigDecimal.ONE };
-
-        BinaryObject po = portables().toBinary(obj);
-
-        info(po.toString());
-
-        BinaryType meta = po.type();
-
-        assertNotNull(meta);
-
-        assertEquals("TestObject1", meta.typeName());
-
-        Collection<String> fields = meta.fieldNames();
-
-        assertEquals(7, fields.size());
-
-        assertTrue(fields.contains("intVal"));
-        assertTrue(fields.contains("strVal"));
-        assertTrue(fields.contains("arrVal"));
-        assertTrue(fields.contains("obj1Val"));
-        assertTrue(fields.contains("obj2Val"));
-        assertTrue(fields.contains("decVal"));
-        assertTrue(fields.contains("decArrVal"));
-
-        assertEquals("int", meta.fieldTypeName("intVal"));
-        assertEquals("String", meta.fieldTypeName("strVal"));
-        assertEquals("byte[]", meta.fieldTypeName("arrVal"));
-        assertEquals("Object", meta.fieldTypeName("obj1Val"));
-        assertEquals("Object", meta.fieldTypeName("obj2Val"));
-        assertEquals("decimal", meta.fieldTypeName("decVal"));
-        assertEquals("decimal[]", meta.fieldTypeName("decArrVal"));
-    }
-
-    /**
-     */
-    @SuppressWarnings("UnusedDeclaration")
-    private static class TestObject1 {
-        /** */
-        private int intVal;
-
-        /** */
-        private String strVal;
-
-        /** */
-        private byte[] arrVal;
-
-        /** */
-        private TestObject1 obj1Val;
-
-        /** */
-        private TestObject2 obj2Val;
-
-        /** */
-        private BigDecimal decVal;
-
-        /** */
-        private BigDecimal[] decArrVal;
-    }
-
-    /**
-     */
-    private static class TestObject2 implements Binarylizable {
-        /** {@inheritDoc} */
-        @Override public void writeBinary(BinaryWriter writer) throws BinaryObjectException {
-            writer.writeBoolean("boolVal", false);
-            writer.writeDate("dateVal", new Date());
-            writer.writeUuidArray("uuidArrVal", null);
-            writer.writeObject("objVal", null);
-            writer.writeMap("mapVal", new HashMap<>());
-            writer.writeDecimal("decVal", BigDecimal.ZERO);
-            writer.writeDecimalArray("decArrVal", new BigDecimal[] { BigDecimal.ONE });
-
-            if (idx == 1) {
-                writer.writeChar("charVal", (char)0);
-                writer.writeCollection("colVal", null);
-            }
-
-            BinaryRawWriter raw = writer.rawWriter();
-
-            raw.writeChar((char)0);
-            raw.writeCollection(null);
-        }
-
-        /** {@inheritDoc} */
-        @Override public void readBinary(BinaryReader reader) throws BinaryObjectException {
-            // No-op.
-        }
-    }
-
-    /**
-     */
-    @SuppressWarnings("UnusedDeclaration")
-    private static class TestObject3 {
-        /** */
-        private int intVal;
-    }
-}

http://git-wip-us.apache.org/repos/asf/ignite/blob/469bf6d6/modules/core/src/test/java/org/apache/ignite/internal/binary/GridPortableWildcardsSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/binary/GridPortableWildcardsSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/binary/GridPortableWildcardsSelfTest.java
deleted file mode 100644
index 9226272..0000000
--- a/modules/core/src/test/java/org/apache/ignite/internal/binary/GridPortableWildcardsSelfTest.java
+++ /dev/null
@@ -1,464 +0,0 @@
-/*
- * 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.binary;
-
-import java.util.Collection;
-import org.apache.ignite.IgniteCheckedException;
-import org.apache.ignite.binary.BinaryIdMapper;
-import org.apache.ignite.binary.BinarySerializer;
-import org.apache.ignite.binary.BinaryTypeConfiguration;
-import org.apache.ignite.configuration.BinaryConfiguration;
-import org.apache.ignite.configuration.IgniteConfiguration;
-import org.apache.ignite.internal.util.IgniteUtils;
-import org.apache.ignite.internal.util.typedef.internal.U;
-import org.apache.ignite.marshaller.MarshallerContextTestImpl;
-import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
-
-import java.util.Arrays;
-import java.util.Map;
-
-/**
- * Wildcards test.
- */
-public class GridPortableWildcardsSelfTest extends GridCommonAbstractTest {
-    /**
-     * @throws Exception If failed.
-     */
-    public void testClassNames() throws Exception {
-        BinaryMarshaller marsh = portableMarshaller(Arrays.asList(
-            new BinaryTypeConfiguration("org.apache.ignite.internal.binary.test.*"),
-            new BinaryTypeConfiguration("unknown.*")
-        ));
-
-        BinaryContext ctx = portableContext(marsh);
-
-        Map<Integer, Class> typeIds = U.field(ctx, "userTypes");
-
-        assertEquals(3, typeIds.size());
-
-        assertTrue(typeIds.containsKey("gridportabletestclass1".hashCode()));
-        assertTrue(typeIds.containsKey("gridportabletestclass2".hashCode()));
-        assertTrue(typeIds.containsKey("innerclass".hashCode()));
-    }
-
-    /**
-     * @throws Exception If failed.
-     */
-    public void testClassNamesWithMapper() throws Exception {
-        BinaryMarshaller marsh = portableMarshaller(new BinaryIdMapper() {
-            @SuppressWarnings("IfMayBeConditional")
-            @Override public int typeId(String clsName) {
-                if (clsName.endsWith("1"))
-                    return 300;
-                else if (clsName.endsWith("2"))
-                    return 400;
-                else if (clsName.endsWith("InnerClass"))
-                    return 500;
-                else
-                    return -500;
-            }
-
-            @Override public int fieldId(int typeId, String fieldName) {
-                return 0;
-            }
-        }, Arrays.asList(
-            new BinaryTypeConfiguration("org.apache.ignite.internal.binary.test.*"),
-            new BinaryTypeConfiguration("unknown.*")
-        ));
-
-        BinaryContext ctx = portableContext(marsh);
-
-        Map<String, BinaryIdMapper> typeMappers = U.field(ctx, "typeMappers");
-
-        assertEquals(3, typeMappers.size());
-
-        assertEquals(300, typeMappers.get("GridPortableTestClass1").typeId("GridPortableTestClass1"));
-        assertEquals(400, typeMappers.get("GridPortableTestClass2").typeId("GridPortableTestClass2"));
-        assertEquals(500, typeMappers.get("InnerClass").typeId("InnerClass"));
-    }
-
-    /**
-     * @throws Exception If failed.
-     */
-    public void testTypeConfigurations() throws Exception {
-        BinaryMarshaller marsh = portableMarshaller(Arrays.asList(
-            new BinaryTypeConfiguration("org.apache.ignite.internal.binary.test.*"),
-            new BinaryTypeConfiguration("unknown.*")
-        ));
-
-        BinaryContext ctx = portableContext(marsh);
-
-        Map<Integer, Class> typeIds = U.field(ctx, "userTypes");
-
-        assertEquals(3, typeIds.size());
-
-        assertTrue(typeIds.containsKey("gridportabletestclass1".hashCode()));
-        assertTrue(typeIds.containsKey("gridportabletestclass2".hashCode()));
-        assertTrue(typeIds.containsKey("innerclass".hashCode()));
-    }
-
-    /**
-     * @throws Exception If failed.
-     */
-    public void testTypeConfigurationsWithGlobalMapper() throws Exception {
-        BinaryMarshaller marsh = portableMarshaller(new BinaryIdMapper() {
-            @SuppressWarnings("IfMayBeConditional")
-            @Override public int typeId(String clsName) {
-                if (clsName.endsWith("1"))
-                    return 300;
-                else if (clsName.endsWith("2"))
-                    return 400;
-                else if (clsName.endsWith("InnerClass"))
-                    return 500;
-                else
-                    return -500;
-            }
-
-            @Override public int fieldId(int typeId, String fieldName) {
-                return 0;
-            }
-        }, Arrays.asList(
-            new BinaryTypeConfiguration("org.apache.ignite.internal.binary.test.*"),
-            new BinaryTypeConfiguration("unknown.*")
-        ));
-
-        BinaryContext ctx = portableContext(marsh);
-
-        Map<String, BinaryIdMapper> typeMappers = U.field(ctx, "typeMappers");
-
-        assertEquals(3, typeMappers.size());
-
-        assertEquals(300, typeMappers.get("GridPortableTestClass1").typeId("GridPortableTestClass1"));
-        assertEquals(400, typeMappers.get("GridPortableTestClass2").typeId("GridPortableTestClass2"));
-        assertEquals(500, typeMappers.get("InnerClass").typeId("InnerClass"));
-    }
-
-    /**
-     * @throws Exception If failed.
-     */
-    public void testTypeConfigurationsWithNonGlobalMapper() throws Exception {
-        BinaryMarshaller marsh = portableMarshaller(new BinaryIdMapper() {
-            @SuppressWarnings("IfMayBeConditional")
-            @Override public int typeId(String clsName) {
-                if (clsName.endsWith("1"))
-                    return 300;
-                else if (clsName.endsWith("2"))
-                    return 400;
-                else if (clsName.endsWith("InnerClass"))
-                    return 500;
-                else
-                    return -500;
-            }
-
-            @Override public int fieldId(int typeId, String fieldName) {
-                return 0;
-            }
-        }, Arrays.asList(
-            new BinaryTypeConfiguration("org.apache.ignite.internal.binary.test.*"),
-            new BinaryTypeConfiguration("unknown.*")
-        ));
-
-        BinaryContext ctx = portableContext(marsh);
-
-        Map<String, BinaryIdMapper> typeMappers = U.field(ctx, "typeMappers");
-
-        assertEquals(3, typeMappers.size());
-
-        assertEquals(300, typeMappers.get("GridPortableTestClass1").typeId("GridPortableTestClass1"));
-        assertEquals(400, typeMappers.get("GridPortableTestClass2").typeId("GridPortableTestClass2"));
-        assertEquals(500, typeMappers.get("InnerClass").typeId("InnerClass"));
-    }
-
-    /**
-     * @throws Exception If failed.
-     */
-    public void testOverride() throws Exception {
-        BinaryTypeConfiguration typeCfg = new BinaryTypeConfiguration();
-
-        typeCfg.setTypeName("GridPortableTestClass2");
-        typeCfg.setIdMapper(new BinaryIdMapper() {
-            @Override public int typeId(String clsName) {
-                return 100;
-            }
-
-            @Override public int fieldId(int typeId, String fieldName) {
-                return 0;
-            }
-        });
-
-        BinaryMarshaller marsh = portableMarshaller(Arrays.asList(
-            new BinaryTypeConfiguration("org.apache.ignite.internal.binary.test.*"),
-            typeCfg));
-
-        BinaryContext ctx = portableContext(marsh);
-
-        Map<Integer, Class> typeIds = U.field(ctx, "userTypes");
-
-        assertEquals(3, typeIds.size());
-
-        assertTrue(typeIds.containsKey("gridportabletestclass1".hashCode()));
-        assertTrue(typeIds.containsKey("innerclass".hashCode()));
-        assertFalse(typeIds.containsKey("gridportabletestclass2".hashCode()));
-
-        Map<String, BinaryIdMapper> typeMappers = U.field(ctx, "typeMappers");
-
-        assertEquals(100, typeMappers.get("GridPortableTestClass2").typeId("GridPortableTestClass2"));
-    }
-
-    /**
-     * @throws Exception If failed.
-     */
-    public void testClassNamesJar() throws Exception {
-        BinaryMarshaller marsh = portableMarshaller(Arrays.asList(
-            new BinaryTypeConfiguration("org.apache.ignite.binary.testjar.*"),
-            new BinaryTypeConfiguration("unknown.*")
-        ));
-
-        BinaryContext ctx = portableContext(marsh);
-
-        Map<Integer, Class> typeIds = U.field(ctx, "userTypes");
-
-        assertEquals(3, typeIds.size());
-
-        assertTrue(typeIds.containsKey("gridportabletestclass1".hashCode()));
-        assertTrue(typeIds.containsKey("gridportabletestclass2".hashCode()));
-    }
-
-    /**
-     * @throws Exception If failed.
-     */
-    public void testClassNamesWithMapperJar() throws Exception {
-        BinaryMarshaller marsh = portableMarshaller(new BinaryIdMapper() {
-            @SuppressWarnings("IfMayBeConditional")
-            @Override public int typeId(String clsName) {
-                if (clsName.endsWith("1"))
-                    return 300;
-                else if (clsName.endsWith("2"))
-                    return 400;
-                else
-                    return -500;
-            }
-
-            @Override public int fieldId(int typeId, String fieldName) {
-                return 0;
-            }
-        }, Arrays.asList(
-            new BinaryTypeConfiguration("org.apache.ignite.binary.testjar.*"),
-            new BinaryTypeConfiguration("unknown.*")
-        ));
-
-        BinaryContext ctx = portableContext(marsh);
-
-        Map<String, BinaryIdMapper> typeMappers = U.field(ctx, "typeMappers");
-
-        assertEquals(3, typeMappers.size());
-
-        assertEquals(300, typeMappers.get("GridPortableTestClass1").typeId("GridPortableTestClass1"));
-        assertEquals(400, typeMappers.get("GridPortableTestClass2").typeId("GridPortableTestClass2"));
-    }
-
-    /**
-     * @throws Exception If failed.
-     */
-    public void testTypeConfigurationsJar() throws Exception {
-        BinaryMarshaller marsh = portableMarshaller(Arrays.asList(
-            new BinaryTypeConfiguration("org.apache.ignite.binary.testjar.*"),
-            new BinaryTypeConfiguration("unknown.*")
-        ));
-
-        BinaryContext ctx = portableContext(marsh);
-
-        Map<Integer, Class> typeIds = U.field(ctx, "userTypes");
-
-        assertEquals(3, typeIds.size());
-
-        assertTrue(typeIds.containsKey("gridportabletestclass1".hashCode()));
-        assertTrue(typeIds.containsKey("gridportabletestclass2".hashCode()));
-    }
-
-    /**
-     * @throws Exception If failed.
-     */
-    public void testTypeConfigurationsWithGlobalMapperJar() throws Exception {
-        BinaryMarshaller marsh = portableMarshaller(new BinaryIdMapper() {
-            @SuppressWarnings("IfMayBeConditional")
-            @Override public int typeId(String clsName) {
-                if (clsName.endsWith("1"))
-                    return 300;
-                else if (clsName.endsWith("2"))
-                    return 400;
-                else
-                    return -500;
-            }
-
-            @Override public int fieldId(int typeId, String fieldName) {
-                return 0;
-            }
-        }, Arrays.asList(
-            new BinaryTypeConfiguration("org.apache.ignite.binary.testjar.*"),
-            new BinaryTypeConfiguration("unknown.*")
-        ));
-
-        BinaryContext ctx = portableContext(marsh);
-
-        Map<String, BinaryIdMapper> typeMappers = U.field(ctx, "typeMappers");
-
-        assertEquals(3, typeMappers.size());
-
-        assertEquals(300, typeMappers.get("GridPortableTestClass1").typeId("GridPortableTestClass1"));
-        assertEquals(400, typeMappers.get("GridPortableTestClass2").typeId("GridPortableTestClass2"));
-    }
-
-    /**
-     * @throws Exception If failed.
-     */
-    public void testTypeConfigurationsWithNonGlobalMapperJar() throws Exception {
-        BinaryMarshaller marsh = portableMarshaller(new BinaryIdMapper() {
-            @SuppressWarnings("IfMayBeConditional")
-            @Override public int typeId(String clsName) {
-                if (clsName.endsWith("1"))
-                    return 300;
-                else if (clsName.endsWith("2"))
-                    return 400;
-                else
-                    return -500;
-            }
-
-            @Override public int fieldId(int typeId, String fieldName) {
-                return 0;
-            }
-        }, Arrays.asList(
-            new BinaryTypeConfiguration("org.apache.ignite.binary.testjar.*"),
-            new BinaryTypeConfiguration("unknown.*")
-        ));
-
-        BinaryContext ctx = portableContext(marsh);
-
-        Map<String, BinaryIdMapper> typeMappers = U.field(ctx, "typeMappers");
-
-        assertEquals(3, typeMappers.size());
-
-        assertEquals(300, typeMappers.get("GridPortableTestClass1").typeId("GridPortableTestClass1"));
-        assertEquals(400, typeMappers.get("GridPortableTestClass2").typeId("GridPortableTestClass2"));
-    }
-
-    /**
-     * @throws Exception If failed.
-     */
-    public void testOverrideJar() throws Exception {
-        BinaryTypeConfiguration typeCfg = new BinaryTypeConfiguration(
-            "org.apache.ignite.binary.testjar.GridPortableTestClass2");
-
-        typeCfg.setIdMapper(new BinaryIdMapper() {
-            @Override public int typeId(String clsName) {
-                return 100;
-            }
-
-            @Override public int fieldId(int typeId, String fieldName) {
-                return 0;
-            }
-        });
-
-        BinaryMarshaller marsh = portableMarshaller(Arrays.asList(
-            new BinaryTypeConfiguration("org.apache.ignite.binary.testjar.*"),
-            typeCfg));
-
-        BinaryContext ctx = portableContext(marsh);
-
-        Map<Integer, Class> typeIds = U.field(ctx, "userTypes");
-
-        assertEquals(3, typeIds.size());
-
-        assertTrue(typeIds.containsKey("gridportabletestclass1".hashCode()));
-
-        Map<String, BinaryIdMapper> typeMappers = U.field(ctx, "typeMappers");
-
-        assertEquals(3, typeMappers.size());
-
-        assertEquals(100, typeMappers.get("GridPortableTestClass2").typeId("GridPortableTestClass2"));
-    }
-
-    /**
-     * @param marsh Marshaller.
-     * @return Portable context.
-     */
-    protected BinaryContext portableContext(BinaryMarshaller marsh) {
-        GridBinaryMarshaller impl = U.field(marsh, "impl");
-
-        return impl.context();
-    }
-
-    /**
-     *
-     */
-    protected BinaryMarshaller portableMarshaller()
-        throws IgniteCheckedException {
-        return portableMarshaller(null, null, null);
-    }
-
-    /**
-     *
-     */
-    protected BinaryMarshaller portableMarshaller(Collection<BinaryTypeConfiguration> cfgs)
-        throws IgniteCheckedException {
-        return portableMarshaller(null, null, cfgs);
-    }
-
-    /**
-     *
-     */
-    protected BinaryMarshaller portableMarshaller(BinaryIdMapper mapper, Collection<BinaryTypeConfiguration> cfgs)
-        throws IgniteCheckedException {
-        return portableMarshaller(mapper, null, cfgs);
-    }
-
-    /**
-     *
-     */
-    protected BinaryMarshaller portableMarshaller(BinarySerializer serializer, Collection<BinaryTypeConfiguration> cfgs)
-        throws IgniteCheckedException {
-        return portableMarshaller(null, serializer, cfgs);
-    }
-
-    protected BinaryMarshaller portableMarshaller(
-        BinaryIdMapper mapper,
-        BinarySerializer serializer,
-        Collection<BinaryTypeConfiguration> cfgs
-    ) throws IgniteCheckedException {
-        IgniteConfiguration iCfg = new IgniteConfiguration();
-
-        BinaryConfiguration bCfg = new BinaryConfiguration();
-
-        bCfg.setIdMapper(mapper);
-        bCfg.setSerializer(serializer);
-
-        bCfg.setTypeConfigurations(cfgs);
-
-        iCfg.setBinaryConfiguration(bCfg);
-
-        BinaryContext ctx = new BinaryContext(BinaryNoopMetadataHandler.instance(), iCfg);
-
-        BinaryMarshaller marsh = new BinaryMarshaller();
-
-        marsh.setContext(new MarshallerContextTestImpl(null));
-
-        IgniteUtils.invoke(BinaryMarshaller.class, marsh, "setPortableContext", ctx, iCfg);
-
-        return marsh;
-    }
-}

http://git-wip-us.apache.org/repos/asf/ignite/blob/469bf6d6/modules/core/src/test/java/org/apache/ignite/internal/binary/mutabletest/GridBinaryTestClasses.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/binary/mutabletest/GridBinaryTestClasses.java b/modules/core/src/test/java/org/apache/ignite/internal/binary/mutabletest/GridBinaryTestClasses.java
new file mode 100644
index 0000000..0170f99
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/binary/mutabletest/GridBinaryTestClasses.java
@@ -0,0 +1,484 @@
+/*
+ * 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.binary.mutabletest;
+
+import com.google.common.base.Throwables;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.ObjectOutput;
+import java.io.ObjectOutputStream;
+import java.io.Serializable;
+import java.math.BigDecimal;
+import java.sql.Timestamp;
+import java.util.ArrayList;
+import java.util.Date;
+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;
+
+/**
+ *
+ */
+@SuppressWarnings({"PublicInnerClass", "PublicField"})
+public class GridBinaryTestClasses {
+    /**
+     *
+     */
+    public static class TestObjectContainer {
+        /** */
+        public Object foo;
+
+        /**
+         *
+         */
+        public TestObjectContainer() {
+            // No-op.
+        }
+
+        /**
+         * @param foo Object.
+         */
+        public TestObjectContainer(Object foo) {
+            this.foo = foo;
+        }
+    }
+
+    /**
+     *
+     */
+    public static class TestObjectOuter {
+        /** */
+        public TestObjectInner inner;
+
+        /** */
+        public String foo;
+
+        /**
+         *
+         */
+        public TestObjectOuter() {
+
+        }
+
+        /**
+         * @param inner Inner object.
+         */
+        public TestObjectOuter(TestObjectInner inner) {
+            this.inner = inner;
+        }
+    }
+
+    /** */
+    public static class TestObjectInner {
+        /** */
+        public Object foo;
+
+        /** */
+        public TestObjectOuter outer;
+    }
+
+    /** */
+    public static class TestObjectArrayList {
+        /** */
+        public List<String> list = new ArrayList<>();
+    }
+
+    /**
+     *
+     */
+    public static class TestObjectPlainPortable {
+        /** */
+        public BinaryObject plainPortable;
+
+        /**
+         *
+         */
+        public TestObjectPlainPortable() {
+            // No-op.
+        }
+
+        /**
+         * @param plainPortable Object.
+         */
+        public TestObjectPlainPortable(BinaryObject plainPortable) {
+            this.plainPortable = plainPortable;
+        }
+    }
+
+    /**
+     *
+     */
+    public static class TestObjectAllTypes implements Serializable {
+        /** */
+        public Byte b_;
+
+        /** */
+        public Short s_;
+
+        /** */
+        public Integer i_;
+
+        /** */
+        public Long l_;
+
+        /** */
+        public Float f_;
+
+        /** */
+        public Double d_;
+
+        /** */
+        public Character c_;
+
+        /** */
+        public Boolean z_;
+
+        /** */
+        public byte b;
+
+        /** */
+        public short s;
+
+        /** */
+        public int i;
+
+        /** */
+        public long l;
+
+        /** */
+        public float f;
+
+        /** */
+        public double d;
+
+        /** */
+        public char c;
+
+        /** */
+        public boolean z;
+
+        /** */
+        public String str;
+
+        /** */
+        public UUID uuid;
+
+        /** */
+        public Date date;
+
+        /** */
+        public Timestamp ts;
+
+        /** */
+        public byte[] bArr;
+
+        /** */
+        public short[] sArr;
+
+        /** */
+        public int[] iArr;
+
+        /** */
+        public long[] lArr;
+
+        /** */
+        public float[] fArr;
+
+        /** */
+        public double[] dArr;
+
+        /** */
+        public char[] cArr;
+
+        /** */
+        public boolean[] zArr;
+
+        /** */
+        public BigDecimal[] bdArr;
+
+        /** */
+        public String[] strArr;
+
+        /** */
+        public UUID[] uuidArr;
+
+        /** */
+        public Date[] dateArr;
+
+        /** */
+        public Timestamp[] tsArr;
+
+        /** */
+        public TestObjectEnum anEnum;
+
+        /** */
+        public TestObjectEnum[] enumArr;
+
+        /** */
+        public Map.Entry entry;
+
+        /**
+         * @return Array.
+         */
+        private byte[] serialize() {
+            ByteArrayOutputStream byteOut = new ByteArrayOutputStream();
+
+            try {
+                ObjectOutput out = new ObjectOutputStream(byteOut);
+
+                out.writeObject(this);
+
+                out.close();
+            }
+            catch (IOException e) {
+                Throwables.propagate(e);
+            }
+
+            return byteOut.toByteArray();
+        }
+
+        /**
+         *
+         */
+        public void setDefaultData() {
+            b_ = 11;
+            s_ = 22;
+            i_ = 33;
+            l_ = 44L;
+            f_ = 55f;
+            d_ = 66d;
+            c_ = 'e';
+            z_ = true;
+
+            b = 1;
+            s = 2;
+            i = 3;
+            l = 4;
+            f = 5;
+            d = 6;
+            c = 7;
+            z = true;
+
+            str = "abc";
+            uuid = new UUID(1, 1);
+            date = new Date(1000000);
+            ts = new Timestamp(100020003);
+
+            bArr = new byte[] {1, 2, 3};
+            sArr = new short[] {1, 2, 3};
+            iArr = new int[] {1, 2, 3};
+            lArr = new long[] {1, 2, 3};
+            fArr = new float[] {1, 2, 3};
+            dArr = new double[] {1, 2, 3};
+            cArr = new char[] {1, 2, 3};
+            zArr = new boolean[] {true, false};
+
+            strArr = new String[] {"abc", "ab", "a"};
+            uuidArr = new UUID[] {new UUID(1, 1), new UUID(2, 2)};
+            bdArr = new BigDecimal[] {new BigDecimal(1000), BigDecimal.TEN};
+            dateArr = new Date[] {new Date(1000000), new Date(200000)};
+            tsArr = new Timestamp[] {new Timestamp(100020003), new Timestamp(200030004)};
+
+            anEnum = TestObjectEnum.A;
+
+            enumArr = new TestObjectEnum[] {TestObjectEnum.B};
+
+            entry = new GridMapEntry<>(1, "a");
+        }
+    }
+
+    /**
+     *
+     */
+    public enum TestObjectEnum {
+        A, B, C
+    }
+
+    /**
+     *
+     */
+    public static class Address implements Serializable {
+        /** SUID. */
+        private static final long serialVersionUID = 0L;
+
+        /** City. */
+        public String city;
+
+        /** Street. */
+        public String street;
+
+        /** Street number. */
+        public int streetNumber;
+
+        /** Flat number. */
+        public int flatNumber;
+
+        /**
+         * Default constructor.
+         */
+        public Address() {
+            // No-op.
+        }
+
+        /**
+         * Constructor.
+         *
+         * @param city City.
+         * @param street Street.
+         * @param streetNumber Street number.
+         * @param flatNumber Flat number.
+         */
+        public Address(String city, String street, int streetNumber, int flatNumber) {
+            this.city = city;
+            this.street = street;
+            this.streetNumber = streetNumber;
+            this.flatNumber = flatNumber;
+        }
+    }
+
+    /**
+     *
+     */
+    public static class Company implements Serializable {
+        /** SUID. */
+        private static final long serialVersionUID = 0L;
+
+        /** ID. */
+        public int id;
+
+        /** Name. */
+        public String name;
+
+        /** Size. */
+        public int size;
+
+        /** Address. */
+        public Address address;
+
+        /** Occupation. */
+        public String occupation;
+
+        /**
+         * Default constructor.
+         */
+        public Company() {
+            // No-op.
+        }
+
+        /**
+         * Constructor.
+         *
+         * @param id ID.
+         * @param name Name.
+         * @param size Size.
+         * @param address Address.
+         * @param occupation Occupation.
+         */
+        public Company(int id, String name, int size, Address address, String occupation) {
+            this.id = id;
+            this.name = name;
+            this.size = size;
+            this.address = address;
+            this.occupation = occupation;
+        }
+    }
+
+    /**
+     * Companies.
+     */
+    public static class Companies {
+        /** Companies. */
+        private List<Company> companies = new ArrayList<>();
+
+        /**
+         * @param idx Index.
+         * @return Company.
+         */
+        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) {
+            Companies list = companyByStreet.get(company.address.street);
+
+            if (list == null) {
+                list = new Companies();
+
+                companyByStreet.put(company.address.street, list);
+            }
+
+            list.add(company);
+        }
+
+        /**
+         * @return map
+         */
+        public Map<String, Companies> getCompanyByStreet() {
+            return 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<>();
+                }
+            });
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/469bf6d6/modules/core/src/test/java/org/apache/ignite/internal/binary/mutabletest/GridPortableTestClasses.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/binary/mutabletest/GridPortableTestClasses.java b/modules/core/src/test/java/org/apache/ignite/internal/binary/mutabletest/GridPortableTestClasses.java
deleted file mode 100644
index 3a4a4b6..0000000
--- a/modules/core/src/test/java/org/apache/ignite/internal/binary/mutabletest/GridPortableTestClasses.java
+++ /dev/null
@@ -1,484 +0,0 @@
-/*
- * 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.binary.mutabletest;
-
-import com.google.common.base.Throwables;
-import java.io.ByteArrayOutputStream;
-import java.io.IOException;
-import java.io.ObjectOutput;
-import java.io.ObjectOutputStream;
-import java.io.Serializable;
-import java.math.BigDecimal;
-import java.sql.Timestamp;
-import java.util.ArrayList;
-import java.util.Date;
-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;
-
-/**
- *
- */
-@SuppressWarnings({"PublicInnerClass", "PublicField"})
-public class GridPortableTestClasses {
-    /**
-     *
-     */
-    public static class TestObjectContainer {
-        /** */
-        public Object foo;
-
-        /**
-         *
-         */
-        public TestObjectContainer() {
-            // No-op.
-        }
-
-        /**
-         * @param foo Object.
-         */
-        public TestObjectContainer(Object foo) {
-            this.foo = foo;
-        }
-    }
-
-    /**
-     *
-     */
-    public static class TestObjectOuter {
-        /** */
-        public TestObjectInner inner;
-
-        /** */
-        public String foo;
-
-        /**
-         *
-         */
-        public TestObjectOuter() {
-
-        }
-
-        /**
-         * @param inner Inner object.
-         */
-        public TestObjectOuter(TestObjectInner inner) {
-            this.inner = inner;
-        }
-    }
-
-    /** */
-    public static class TestObjectInner {
-        /** */
-        public Object foo;
-
-        /** */
-        public TestObjectOuter outer;
-    }
-
-    /** */
-    public static class TestObjectArrayList {
-        /** */
-        public List<String> list = new ArrayList<>();
-    }
-
-    /**
-     *
-     */
-    public static class TestObjectPlainPortable {
-        /** */
-        public BinaryObject plainPortable;
-
-        /**
-         *
-         */
-        public TestObjectPlainPortable() {
-            // No-op.
-        }
-
-        /**
-         * @param plainPortable Object.
-         */
-        public TestObjectPlainPortable(BinaryObject plainPortable) {
-            this.plainPortable = plainPortable;
-        }
-    }
-
-    /**
-     *
-     */
-    public static class TestObjectAllTypes implements Serializable {
-        /** */
-        public Byte b_;
-
-        /** */
-        public Short s_;
-
-        /** */
-        public Integer i_;
-
-        /** */
-        public Long l_;
-
-        /** */
-        public Float f_;
-
-        /** */
-        public Double d_;
-
-        /** */
-        public Character c_;
-
-        /** */
-        public Boolean z_;
-
-        /** */
-        public byte b;
-
-        /** */
-        public short s;
-
-        /** */
-        public int i;
-
-        /** */
-        public long l;
-
-        /** */
-        public float f;
-
-        /** */
-        public double d;
-
-        /** */
-        public char c;
-
-        /** */
-        public boolean z;
-
-        /** */
-        public String str;
-
-        /** */
-        public UUID uuid;
-
-        /** */
-        public Date date;
-
-        /** */
-        public Timestamp ts;
-
-        /** */
-        public byte[] bArr;
-
-        /** */
-        public short[] sArr;
-
-        /** */
-        public int[] iArr;
-
-        /** */
-        public long[] lArr;
-
-        /** */
-        public float[] fArr;
-
-        /** */
-        public double[] dArr;
-
-        /** */
-        public char[] cArr;
-
-        /** */
-        public boolean[] zArr;
-
-        /** */
-        public BigDecimal[] bdArr;
-
-        /** */
-        public String[] strArr;
-
-        /** */
-        public UUID[] uuidArr;
-
-        /** */
-        public Date[] dateArr;
-
-        /** */
-        public Timestamp[] tsArr;
-
-        /** */
-        public TestObjectEnum anEnum;
-
-        /** */
-        public TestObjectEnum[] enumArr;
-
-        /** */
-        public Map.Entry entry;
-
-        /**
-         * @return Array.
-         */
-        private byte[] serialize() {
-            ByteArrayOutputStream byteOut = new ByteArrayOutputStream();
-
-            try {
-                ObjectOutput out = new ObjectOutputStream(byteOut);
-
-                out.writeObject(this);
-
-                out.close();
-            }
-            catch (IOException e) {
-                Throwables.propagate(e);
-            }
-
-            return byteOut.toByteArray();
-        }
-
-        /**
-         *
-         */
-        public void setDefaultData() {
-            b_ = 11;
-            s_ = 22;
-            i_ = 33;
-            l_ = 44L;
-            f_ = 55f;
-            d_ = 66d;
-            c_ = 'e';
-            z_ = true;
-
-            b = 1;
-            s = 2;
-            i = 3;
-            l = 4;
-            f = 5;
-            d = 6;
-            c = 7;
-            z = true;
-
-            str = "abc";
-            uuid = new UUID(1, 1);
-            date = new Date(1000000);
-            ts = new Timestamp(100020003);
-
-            bArr = new byte[] {1, 2, 3};
-            sArr = new short[] {1, 2, 3};
-            iArr = new int[] {1, 2, 3};
-            lArr = new long[] {1, 2, 3};
-            fArr = new float[] {1, 2, 3};
-            dArr = new double[] {1, 2, 3};
-            cArr = new char[] {1, 2, 3};
-            zArr = new boolean[] {true, false};
-
-            strArr = new String[] {"abc", "ab", "a"};
-            uuidArr = new UUID[] {new UUID(1, 1), new UUID(2, 2)};
-            bdArr = new BigDecimal[] {new BigDecimal(1000), BigDecimal.TEN};
-            dateArr = new Date[] {new Date(1000000), new Date(200000)};
-            tsArr = new Timestamp[] {new Timestamp(100020003), new Timestamp(200030004)};
-
-            anEnum = TestObjectEnum.A;
-
-            enumArr = new TestObjectEnum[] {TestObjectEnum.B};
-
-            entry = new GridMapEntry<>(1, "a");
-        }
-    }
-
-    /**
-     *
-     */
-    public enum TestObjectEnum {
-        A, B, C
-    }
-
-    /**
-     *
-     */
-    public static class Address implements Serializable {
-        /** SUID. */
-        private static final long serialVersionUID = 0L;
-
-        /** City. */
-        public String city;
-
-        /** Street. */
-        public String street;
-
-        /** Street number. */
-        public int streetNumber;
-
-        /** Flat number. */
-        public int flatNumber;
-
-        /**
-         * Default constructor.
-         */
-        public Address() {
-            // No-op.
-        }
-
-        /**
-         * Constructor.
-         *
-         * @param city City.
-         * @param street Street.
-         * @param streetNumber Street number.
-         * @param flatNumber Flat number.
-         */
-        public Address(String city, String street, int streetNumber, int flatNumber) {
-            this.city = city;
-            this.street = street;
-            this.streetNumber = streetNumber;
-            this.flatNumber = flatNumber;
-        }
-    }
-
-    /**
-     *
-     */
-    public static class Company implements Serializable {
-        /** SUID. */
-        private static final long serialVersionUID = 0L;
-
-        /** ID. */
-        public int id;
-
-        /** Name. */
-        public String name;
-
-        /** Size. */
-        public int size;
-
-        /** Address. */
-        public Address address;
-
-        /** Occupation. */
-        public String occupation;
-
-        /**
-         * Default constructor.
-         */
-        public Company() {
-            // No-op.
-        }
-
-        /**
-         * Constructor.
-         *
-         * @param id ID.
-         * @param name Name.
-         * @param size Size.
-         * @param address Address.
-         * @param occupation Occupation.
-         */
-        public Company(int id, String name, int size, Address address, String occupation) {
-            this.id = id;
-            this.name = name;
-            this.size = size;
-            this.address = address;
-            this.occupation = occupation;
-        }
-    }
-
-    /**
-     * Companies.
-     */
-    public static class Companies {
-        /** Companies. */
-        private List<Company> companies = new ArrayList<>();
-
-        /**
-         * @param idx Index.
-         * @return Company.
-         */
-        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) {
-            Companies list = companyByStreet.get(company.address.street);
-
-            if (list == null) {
-                list = new Companies();
-
-                companyByStreet.put(company.address.street, list);
-            }
-
-            list.add(company);
-        }
-
-        /**
-         * @return map
-         */
-        public Map<String, Companies> getCompanyByStreet() {
-            return 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<>();
-                }
-            });
-        }
-    }
-}

http://git-wip-us.apache.org/repos/asf/ignite/blob/469bf6d6/modules/core/src/test/java/org/apache/ignite/internal/binary/test/GridBinaryTestClass1.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/binary/test/GridBinaryTestClass1.java b/modules/core/src/test/java/org/apache/ignite/internal/binary/test/GridBinaryTestClass1.java
new file mode 100644
index 0000000..b861a75
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/binary/test/GridBinaryTestClass1.java
@@ -0,0 +1,28 @@
+/*
+ * 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.binary.test;
+
+/**
+ */
+public class GridBinaryTestClass1 {
+    /**
+     */
+    private static class InnerClass {
+        // No-op.
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/469bf6d6/modules/core/src/test/java/org/apache/ignite/internal/binary/test/GridBinaryTestClass2.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/binary/test/GridBinaryTestClass2.java b/modules/core/src/test/java/org/apache/ignite/internal/binary/test/GridBinaryTestClass2.java
new file mode 100644
index 0000000..fc5e88c
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/binary/test/GridBinaryTestClass2.java
@@ -0,0 +1,24 @@
+/*
+ * 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.binary.test;
+
+/**
+ */
+public class GridBinaryTestClass2 {
+    // No-op.
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/469bf6d6/modules/core/src/test/java/org/apache/ignite/internal/binary/test/GridPortableTestClass1.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/binary/test/GridPortableTestClass1.java b/modules/core/src/test/java/org/apache/ignite/internal/binary/test/GridPortableTestClass1.java
deleted file mode 100644
index 887134a..0000000
--- a/modules/core/src/test/java/org/apache/ignite/internal/binary/test/GridPortableTestClass1.java
+++ /dev/null
@@ -1,28 +0,0 @@
-/*
- * 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.binary.test;
-
-/**
- */
-public class GridPortableTestClass1 {
-    /**
-     */
-    private static class InnerClass {
-        // No-op.
-    }
-}

http://git-wip-us.apache.org/repos/asf/ignite/blob/469bf6d6/modules/core/src/test/java/org/apache/ignite/internal/binary/test/GridPortableTestClass2.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/binary/test/GridPortableTestClass2.java b/modules/core/src/test/java/org/apache/ignite/internal/binary/test/GridPortableTestClass2.java
deleted file mode 100644
index 3c1c506..0000000
--- a/modules/core/src/test/java/org/apache/ignite/internal/binary/test/GridPortableTestClass2.java
+++ /dev/null
@@ -1,24 +0,0 @@
-/*
- * 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.binary.test;
-
-/**
- */
-public class GridPortableTestClass2 {
-    // No-op.
-}

http://git-wip-us.apache.org/repos/asf/ignite/blob/469bf6d6/modules/core/src/test/java/org/apache/ignite/internal/binary/test/subpackage/GridBinaryTestClass3.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/binary/test/subpackage/GridBinaryTestClass3.java b/modules/core/src/test/java/org/apache/ignite/internal/binary/test/subpackage/GridBinaryTestClass3.java
new file mode 100644
index 0000000..72a5a1e
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/binary/test/subpackage/GridBinaryTestClass3.java
@@ -0,0 +1,24 @@
+/*
+ * 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.binary.test.subpackage;
+
+/**
+ */
+public class GridBinaryTestClass3 {
+    // No-op.
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/469bf6d6/modules/core/src/test/java/org/apache/ignite/internal/binary/test/subpackage/GridPortableTestClass3.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/binary/test/subpackage/GridPortableTestClass3.java b/modules/core/src/test/java/org/apache/ignite/internal/binary/test/subpackage/GridPortableTestClass3.java
deleted file mode 100644
index a04b586..0000000
--- a/modules/core/src/test/java/org/apache/ignite/internal/binary/test/subpackage/GridPortableTestClass3.java
+++ /dev/null
@@ -1,24 +0,0 @@
-/*
- * 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.binary.test.subpackage;
-
-/**
- */
-public class GridPortableTestClass3 {
-    // No-op.
-}

http://git-wip-us.apache.org/repos/asf/ignite/blob/469bf6d6/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/binary/GridCacheBinaryStoreBinariesSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/binary/GridCacheBinaryStoreBinariesSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/binary/GridCacheBinaryStoreBinariesSelfTest.java
new file mode 100644
index 0000000..55f2da0
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/binary/GridCacheBinaryStoreBinariesSelfTest.java
@@ -0,0 +1,66 @@
+/*
+ * 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.processors.cache.binary;
+
+import java.util.Map;
+import org.apache.ignite.binary.BinaryObject;
+
+/**
+ * Tests for cache store with binary.
+ */
+public class GridCacheBinaryStoreBinariesSelfTest extends GridCacheBinaryStoreAbstractSelfTest {
+    /** {@inheritDoc} */
+    @Override protected boolean keepPortableInStore() {
+        return true;
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void populateMap(Map<Object, Object> map, int... idxs) {
+        assert map != null;
+        assert idxs != null;
+
+        for (int idx : idxs)
+            map.put(portable(new Key(idx)), portable(new Value(idx)));
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void checkMap(Map<Object, Object> map, int... idxs) {
+        assert map != null;
+        assert idxs != null;
+
+        assertEquals(idxs.length, map.size());
+
+        for (int idx : idxs) {
+            Object val = map.get(portable(new Key(idx)));
+
+            assertTrue(String.valueOf(val), val instanceof BinaryObject);
+
+            BinaryObject po = (BinaryObject)val;
+
+            assertEquals("Value", po.type().typeName());
+            assertEquals(new Integer(idx), po.field("idx"));
+        }
+    }
+
+    /**
+     * @param obj Object.
+     * @return Portable object.
+     */
+    private Object portable(Object obj) {
+        return grid().binary().toBinary(obj);
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/469bf6d6/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/binary/GridCacheBinaryStorePortablesSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/binary/GridCacheBinaryStorePortablesSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/binary/GridCacheBinaryStorePortablesSelfTest.java
deleted file mode 100644
index db15f08..0000000
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/binary/GridCacheBinaryStorePortablesSelfTest.java
+++ /dev/null
@@ -1,66 +0,0 @@
-/*
- * 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.processors.cache.binary;
-
-import java.util.Map;
-import org.apache.ignite.binary.BinaryObject;
-
-/**
- * Tests for cache store with binary.
- */
-public class GridCacheBinaryStorePortablesSelfTest extends GridCacheBinaryStoreAbstractSelfTest {
-    /** {@inheritDoc} */
-    @Override protected boolean keepPortableInStore() {
-        return true;
-    }
-
-    /** {@inheritDoc} */
-    @Override protected void populateMap(Map<Object, Object> map, int... idxs) {
-        assert map != null;
-        assert idxs != null;
-
-        for (int idx : idxs)
-            map.put(portable(new Key(idx)), portable(new Value(idx)));
-    }
-
-    /** {@inheritDoc} */
-    @Override protected void checkMap(Map<Object, Object> map, int... idxs) {
-        assert map != null;
-        assert idxs != null;
-
-        assertEquals(idxs.length, map.size());
-
-        for (int idx : idxs) {
-            Object val = map.get(portable(new Key(idx)));
-
-            assertTrue(String.valueOf(val), val instanceof BinaryObject);
-
-            BinaryObject po = (BinaryObject)val;
-
-            assertEquals("Value", po.type().typeName());
-            assertEquals(new Integer(idx), po.field("idx"));
-        }
-    }
-
-    /**
-     * @param obj Object.
-     * @return Portable object.
-     */
-    private Object portable(Object obj) {
-        return grid().binary().toBinary(obj);
-    }
-}


[38/59] [abbrv] ignite git commit: ignite-2136 Added test reproducing issue, modified GridCacheJdbcBlobStoreMultithreadedSelfTest to do not fail because of this bug.

Posted by ak...@apache.org.
ignite-2136 Added test reproducing issue, modified GridCacheJdbcBlobStoreMultithreadedSelfTest to do not fail because of this bug.


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

Branch: refs/heads/ignite-843-rc2
Commit: 91760b9ebc83b994531fc4635a7d821bfc71d77c
Parents: 6e0ef34
Author: sboikov <sb...@gridgain.com>
Authored: Fri Dec 11 15:31:56 2015 +0300
Committer: sboikov <sb...@gridgain.com>
Committed: Fri Dec 11 15:31:56 2015 +0300

----------------------------------------------------------------------
 ...eJdbcStoreAbstractMultithreadedSelfTest.java |   5 +-
 ...CacheJdbcBlobStoreMultithreadedSelfTest.java |   2 +-
 .../near/NearCachePutAllMultinodeTest.java      | 167 +++++++++++++++++++
 3 files changed, 172 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/91760b9e/modules/core/src/test/java/org/apache/ignite/cache/store/jdbc/CacheJdbcStoreAbstractMultithreadedSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/cache/store/jdbc/CacheJdbcStoreAbstractMultithreadedSelfTest.java b/modules/core/src/test/java/org/apache/ignite/cache/store/jdbc/CacheJdbcStoreAbstractMultithreadedSelfTest.java
index 4c4bd58..592d1cb 100644
--- a/modules/core/src/test/java/org/apache/ignite/cache/store/jdbc/CacheJdbcStoreAbstractMultithreadedSelfTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/cache/store/jdbc/CacheJdbcStoreAbstractMultithreadedSelfTest.java
@@ -137,7 +137,10 @@ public abstract class CacheJdbcStoreAbstractMultithreadedSelfTest<T extends Cach
         return c;
     }
 
-    /** */
+    /**
+     * @return Cache configuration.
+     * @throws Exception If failed.
+     */
     protected CacheConfiguration cacheConfiguration() throws Exception {
         CacheConfiguration cc = defaultCacheConfiguration();
 

http://git-wip-us.apache.org/repos/asf/ignite/blob/91760b9e/modules/core/src/test/java/org/apache/ignite/cache/store/jdbc/GridCacheJdbcBlobStoreMultithreadedSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/cache/store/jdbc/GridCacheJdbcBlobStoreMultithreadedSelfTest.java b/modules/core/src/test/java/org/apache/ignite/cache/store/jdbc/GridCacheJdbcBlobStoreMultithreadedSelfTest.java
index 4396549..cceb55f 100644
--- a/modules/core/src/test/java/org/apache/ignite/cache/store/jdbc/GridCacheJdbcBlobStoreMultithreadedSelfTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/cache/store/jdbc/GridCacheJdbcBlobStoreMultithreadedSelfTest.java
@@ -168,7 +168,7 @@ public class GridCacheJdbcBlobStoreMultithreadedSelfTest extends GridCommonAbstr
                     Map<Integer, String> map = new TreeMap<>();
 
                     for (int j = 0; j < 10; j++)
-                        map.put(rnd.nextInt(1000), "value");
+                        map.put(j, "value");
 
                     IgniteCache<Object, Object> cache = jcache(rnd.nextInt(GRID_CNT));
 

http://git-wip-us.apache.org/repos/asf/ignite/blob/91760b9e/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/near/NearCachePutAllMultinodeTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/near/NearCachePutAllMultinodeTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/near/NearCachePutAllMultinodeTest.java
new file mode 100644
index 0000000..bd6355a
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/near/NearCachePutAllMultinodeTest.java
@@ -0,0 +1,167 @@
+/*
+ * 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.processors.cache.distributed.near;
+
+import java.util.Map;
+import java.util.Random;
+import java.util.TreeMap;
+import java.util.concurrent.Callable;
+import java.util.concurrent.atomic.AtomicInteger;
+import javax.cache.Cache;
+import javax.cache.configuration.Factory;
+import org.apache.ignite.Ignite;
+import org.apache.ignite.IgniteCache;
+import org.apache.ignite.cache.store.CacheStore;
+import org.apache.ignite.cache.store.CacheStoreAdapter;
+import org.apache.ignite.configuration.CacheConfiguration;
+import org.apache.ignite.configuration.IgniteConfiguration;
+import org.apache.ignite.configuration.NearCacheConfiguration;
+import org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi;
+import org.apache.ignite.spi.discovery.tcp.ipfinder.TcpDiscoveryIpFinder;
+import org.apache.ignite.spi.discovery.tcp.ipfinder.vm.TcpDiscoveryVmIpFinder;
+import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
+
+import static org.apache.ignite.cache.CacheAtomicityMode.TRANSACTIONAL;
+import static org.apache.ignite.cache.CacheMode.PARTITIONED;
+import static org.apache.ignite.cache.CacheWriteSynchronizationMode.FULL_SYNC;
+import static org.apache.ignite.testframework.GridTestUtils.runMultiThreaded;
+
+/**
+ *
+ */
+public class NearCachePutAllMultinodeTest extends GridCommonAbstractTest {
+    /** IP finder. */
+    private static final TcpDiscoveryIpFinder IP_FINDER = new TcpDiscoveryVmIpFinder(true);
+
+    /** Number of grids to start. */
+    private static final int GRID_CNT = 3;
+
+    /** Number of transactions. */
+    private static final int TX_CNT = 10_000;
+
+    /** Client flag. */
+    private boolean client;
+
+    /** {@inheritDoc} */
+    @SuppressWarnings("unchecked")
+    @Override protected final IgniteConfiguration getConfiguration(String gridName) throws Exception {
+        IgniteConfiguration c = super.getConfiguration(gridName);
+
+        TcpDiscoverySpi disco = new TcpDiscoverySpi();
+
+        disco.setIpFinder(IP_FINDER);
+
+        c.setDiscoverySpi(disco);
+
+        if (!client) {
+            CacheConfiguration cc = defaultCacheConfiguration();
+
+            cc.setCacheMode(PARTITIONED);
+            cc.setWriteSynchronizationMode(FULL_SYNC);
+            cc.setSwapEnabled(false);
+            cc.setAtomicityMode(TRANSACTIONAL);
+            cc.setBackups(1);
+
+            // Set store to disable one-phase commit.
+            cc.setCacheStoreFactory(new TestFactory());
+
+            c.setCacheConfiguration(cc);
+        }
+        else
+            c.setClientMode(true);
+
+        return c;
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void beforeTest() throws Exception {
+        startGridsMultiThreaded(GRID_CNT - 2);
+
+        client = true;
+
+        Ignite grid = startGrid(GRID_CNT - 2);
+
+        grid.createNearCache(null, new NearCacheConfiguration());
+
+        grid = startGrid(GRID_CNT - 1);
+
+        grid.cache(null);
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void afterTest() throws Exception {
+        stopAllGrids();
+
+        super.afterTest();
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testMultithreadedPutAll() throws Exception {
+        final AtomicInteger idx = new AtomicInteger();
+
+        runMultiThreaded(new Callable<Object>() {
+            private final Random rnd = new Random();
+
+            @Override public Object call() throws Exception {
+                int threadIdx = idx.getAndIncrement();
+
+                int node = threadIdx % 2 + (GRID_CNT - 2);
+
+                IgniteCache<Object, Object> cache = jcache(node);
+
+                for (int i = 0; i < TX_CNT; i++) {
+                    Map<Integer, String> map = new TreeMap<>();
+
+                    for (int j = 0; j < 3; j++)
+                        map.put(rnd.nextInt(10), "value");
+
+                    cache.putAll(map);
+
+                    if (i % 100 == 0)
+                        log.info("Iteration: " + i + " " + node);
+                }
+
+                return null;
+            }
+        }, 8, "putAll");
+    }
+
+    /**
+     *
+     */
+    static class TestFactory implements Factory<CacheStore> {
+        /** {@inheritDoc} */
+        @Override public CacheStore create() {
+            return new CacheStoreAdapter() {
+                @Override public Object load(Object key) {
+                    return null;
+                }
+
+                @Override public void write(Cache.Entry entry) {
+                    // No-op.
+                }
+
+                @Override public void delete(Object key) {
+                    // No-op.
+                }
+            };
+        }
+    }
+}
\ No newline at end of file


[16/59] [abbrv] ignite git commit: ignite-2065: rename "portable" packages to "binary"

Posted by ak...@apache.org.
http://git-wip-us.apache.org/repos/asf/ignite/blob/1dbf20e0/modules/core/src/main/java/org/apache/ignite/internal/portable/builder/PortableLazyValue.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/portable/builder/PortableLazyValue.java b/modules/core/src/main/java/org/apache/ignite/internal/portable/builder/PortableLazyValue.java
deleted file mode 100644
index 5d8d586..0000000
--- a/modules/core/src/main/java/org/apache/ignite/internal/portable/builder/PortableLazyValue.java
+++ /dev/null
@@ -1,28 +0,0 @@
-/*
- * 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.portable.builder;
-
-/**
- *
- */
-public interface PortableLazyValue extends PortableBuilderSerializationAware {
-    /**
-     * @return Value.
-     */
-    public Object value();
-}

http://git-wip-us.apache.org/repos/asf/ignite/blob/1dbf20e0/modules/core/src/main/java/org/apache/ignite/internal/portable/builder/PortableModifiableLazyValue.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/portable/builder/PortableModifiableLazyValue.java b/modules/core/src/main/java/org/apache/ignite/internal/portable/builder/PortableModifiableLazyValue.java
deleted file mode 100644
index 2b439c8..0000000
--- a/modules/core/src/main/java/org/apache/ignite/internal/portable/builder/PortableModifiableLazyValue.java
+++ /dev/null
@@ -1,52 +0,0 @@
-/*
- * 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.portable.builder;
-
-import org.apache.ignite.internal.portable.*;
-
-/**
- *
- */
-public class PortableModifiableLazyValue extends PortableAbstractLazyValue {
-    /** */
-    protected final int len;
-
-    /**
-     * @param reader
-     * @param valOff
-     * @param len
-     */
-    public PortableModifiableLazyValue(PortableBuilderReader reader, int valOff, int len) {
-        super(reader, valOff);
-
-        this.len = len;
-    }
-
-    /** {@inheritDoc} */
-    @Override protected Object init() {
-        return reader.reader().unmarshal(valOff);
-    }
-
-    /** {@inheritDoc} */
-    @Override public void writeTo(BinaryWriterExImpl writer, PortableBuilderSerializer ctx) {
-        if (val == null)
-            writer.write(reader.array(), valOff, len);
-        else
-            writer.writeObject(val);
-    }
-}

http://git-wip-us.apache.org/repos/asf/ignite/blob/1dbf20e0/modules/core/src/main/java/org/apache/ignite/internal/portable/builder/PortableObjectArrayLazyValue.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/portable/builder/PortableObjectArrayLazyValue.java b/modules/core/src/main/java/org/apache/ignite/internal/portable/builder/PortableObjectArrayLazyValue.java
deleted file mode 100644
index 8c8022b..0000000
--- a/modules/core/src/main/java/org/apache/ignite/internal/portable/builder/PortableObjectArrayLazyValue.java
+++ /dev/null
@@ -1,91 +0,0 @@
-/*
- * 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.portable.builder;
-
-import org.apache.ignite.internal.portable.GridPortableMarshaller;
-import org.apache.ignite.internal.portable.BinaryWriterExImpl;
-import org.apache.ignite.internal.util.typedef.internal.U;
-import org.apache.ignite.binary.BinaryInvalidTypeException;
-
-/**
- *
- */
-class PortableObjectArrayLazyValue extends PortableAbstractLazyValue {
-    /** */
-    private Object[] lazyValsArr;
-
-    /** */
-    private int compTypeId;
-
-    /** */
-    private String clsName;
-
-    /**
-     * @param reader Reader.
-     */
-    protected PortableObjectArrayLazyValue(PortableBuilderReader reader) {
-        super(reader, reader.position() - 1);
-
-        int typeId = reader.readInt();
-
-        if (typeId == GridPortableMarshaller.UNREGISTERED_TYPE_ID) {
-            clsName = reader.readString();
-
-            Class cls;
-
-            try {
-                // TODO: IGNITE-1272 - Is class loader needed here?
-                cls = U.forName(reader.readString(), null);
-            }
-            catch (ClassNotFoundException e) {
-                throw new BinaryInvalidTypeException("Failed to load the class: " + clsName, e);
-            }
-
-            compTypeId = reader.portableContext().descriptorForClass(cls, true).typeId();
-        }
-        else {
-            compTypeId = typeId;
-            clsName = null;
-        }
-
-        int size = reader.readInt();
-
-        lazyValsArr = new Object[size];
-
-        for (int i = 0; i < size; i++)
-            lazyValsArr[i] = reader.parseValue();
-    }
-
-    /** {@inheritDoc} */
-    @Override protected Object init() {
-        for (int i = 0; i < lazyValsArr.length; i++) {
-            if (lazyValsArr[i] instanceof PortableLazyValue)
-                lazyValsArr[i] = ((PortableLazyValue)lazyValsArr[i]).value();
-        }
-
-        return lazyValsArr;
-    }
-
-    /** {@inheritDoc} */
-    @Override public void writeTo(BinaryWriterExImpl writer, PortableBuilderSerializer ctx) {
-        if (clsName == null)
-            ctx.writeArray(writer, GridPortableMarshaller.OBJ_ARR, lazyValsArr, compTypeId);
-        else
-            ctx.writeArray(writer, GridPortableMarshaller.OBJ_ARR, lazyValsArr, clsName);
-    }
-}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ignite/blob/1dbf20e0/modules/core/src/main/java/org/apache/ignite/internal/portable/builder/PortablePlainLazyValue.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/portable/builder/PortablePlainLazyValue.java b/modules/core/src/main/java/org/apache/ignite/internal/portable/builder/PortablePlainLazyValue.java
deleted file mode 100644
index 14c182b..0000000
--- a/modules/core/src/main/java/org/apache/ignite/internal/portable/builder/PortablePlainLazyValue.java
+++ /dev/null
@@ -1,49 +0,0 @@
-/*
- * 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.portable.builder;
-
-import org.apache.ignite.internal.portable.*;
-
-/**
- *
- */
-class PortablePlainLazyValue extends PortableAbstractLazyValue {
-    /** */
-    protected final int len;
-
-    /**
-     * @param reader Reader
-     * @param valOff Offset
-     * @param len Length.
-     */
-    protected PortablePlainLazyValue(PortableBuilderReader reader, int valOff, int len) {
-        super(reader, valOff);
-
-        this.len = len;
-    }
-
-    /** {@inheritDoc} */
-    @Override protected Object init() {
-        return reader.reader().unmarshal(valOff);
-    }
-
-    /** {@inheritDoc} */
-    @Override public void writeTo(BinaryWriterExImpl writer, PortableBuilderSerializer ctx) {
-        writer.write(reader.array(), valOff, len);
-    }
-}

http://git-wip-us.apache.org/repos/asf/ignite/blob/1dbf20e0/modules/core/src/main/java/org/apache/ignite/internal/portable/builder/PortablePlainPortableObject.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/portable/builder/PortablePlainPortableObject.java b/modules/core/src/main/java/org/apache/ignite/internal/portable/builder/PortablePlainPortableObject.java
deleted file mode 100644
index 1512b44..0000000
--- a/modules/core/src/main/java/org/apache/ignite/internal/portable/builder/PortablePlainPortableObject.java
+++ /dev/null
@@ -1,53 +0,0 @@
-/*
- * 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.portable.builder;
-
-import org.apache.ignite.internal.portable.BinaryObjectImpl;
-import org.apache.ignite.internal.portable.BinaryObjectOffheapImpl;
-import org.apache.ignite.internal.portable.BinaryWriterExImpl;
-import org.apache.ignite.binary.BinaryObject;
-
-/**
- *
- */
-public class PortablePlainPortableObject implements PortableLazyValue {
-    /** */
-    private final BinaryObject portableObj;
-
-    /**
-     * @param portableObj Portable object.
-     */
-    public PortablePlainPortableObject(BinaryObject portableObj) {
-        this.portableObj = portableObj;
-    }
-
-    /** {@inheritDoc} */
-    @Override public Object value() {
-        return portableObj;
-    }
-
-    /** {@inheritDoc} */
-    @Override public void writeTo(BinaryWriterExImpl writer, PortableBuilderSerializer ctx) {
-        BinaryObject val = portableObj;
-
-        if (val instanceof BinaryObjectOffheapImpl)
-            val = ((BinaryObjectOffheapImpl)val).heapCopy();
-
-        writer.doWritePortableObject((BinaryObjectImpl)val);
-    }
-}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ignite/blob/1dbf20e0/modules/core/src/main/java/org/apache/ignite/internal/portable/builder/PortableValueWithType.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/portable/builder/PortableValueWithType.java b/modules/core/src/main/java/org/apache/ignite/internal/portable/builder/PortableValueWithType.java
deleted file mode 100644
index 5d66328..0000000
--- a/modules/core/src/main/java/org/apache/ignite/internal/portable/builder/PortableValueWithType.java
+++ /dev/null
@@ -1,76 +0,0 @@
-/*
- * 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.portable.builder;
-
-import org.apache.ignite.internal.portable.BinaryWriterExImpl;
-import org.apache.ignite.internal.util.typedef.internal.S;
-
-/**
- *
- */
-class PortableValueWithType implements PortableLazyValue {
-    /** */
-    private byte type;
-
-    /** */
-    private Object val;
-
-    /**
-     * @param type Type
-     * @param val Value.
-     */
-    PortableValueWithType(byte type, Object val) {
-        this.type = type;
-        this.val = val;
-    }
-
-    /** {@inheritDoc} */
-    @Override public void writeTo(BinaryWriterExImpl writer, PortableBuilderSerializer ctx) {
-        if (val instanceof PortableBuilderSerializationAware)
-            ((PortableBuilderSerializationAware)val).writeTo(writer, ctx);
-        else
-            ctx.writeValue(writer, val);
-    }
-
-    /**
-     * @return Type ID.
-     */
-    public int typeId() {
-        return type;
-    }
-
-    /** {@inheritDoc} */
-    @Override public Object value() {
-        if (val instanceof PortableLazyValue)
-            return ((PortableLazyValue)val).value();
-
-        return val;
-    }
-
-    /**
-     * @param val New value.
-     */
-    public void value(Object val) {
-        this.val = val;
-    }
-
-    /** {@inheritDoc} */
-    @Override public String toString() {
-        return S.toString(PortableValueWithType.class, this);
-    }
-}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ignite/blob/1dbf20e0/modules/core/src/main/java/org/apache/ignite/internal/portable/builder/package-info.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/portable/builder/package-info.java b/modules/core/src/main/java/org/apache/ignite/internal/portable/builder/package-info.java
deleted file mode 100644
index e069f3e..0000000
--- a/modules/core/src/main/java/org/apache/ignite/internal/portable/builder/package-info.java
+++ /dev/null
@@ -1,22 +0,0 @@
-/*
- * 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 description. -->
- * Contains classes specific to portable builder API.
- */
-package org.apache.ignite.internal.portable.builder;
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ignite/blob/1dbf20e0/modules/core/src/main/java/org/apache/ignite/internal/portable/package-info.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/portable/package-info.java b/modules/core/src/main/java/org/apache/ignite/internal/portable/package-info.java
deleted file mode 100644
index ccf9fad..0000000
--- a/modules/core/src/main/java/org/apache/ignite/internal/portable/package-info.java
+++ /dev/null
@@ -1,22 +0,0 @@
-/*
- * 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 description. -->
- * Contains portable APIs internal implementation.
- */
-package org.apache.ignite.internal.portable;
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ignite/blob/1dbf20e0/modules/core/src/main/java/org/apache/ignite/internal/portable/streams/PortableAbstractInputStream.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/portable/streams/PortableAbstractInputStream.java b/modules/core/src/main/java/org/apache/ignite/internal/portable/streams/PortableAbstractInputStream.java
deleted file mode 100644
index 2c4864e..0000000
--- a/modules/core/src/main/java/org/apache/ignite/internal/portable/streams/PortableAbstractInputStream.java
+++ /dev/null
@@ -1,379 +0,0 @@
-/*
- * 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.portable.streams;
-
-import org.apache.ignite.binary.BinaryObjectException;
-
-/**
- * Portable abstract input stream.
- */
-public abstract class PortableAbstractInputStream extends PortableAbstractStream
-    implements PortableInputStream {
-    /** Length of data inside array. */
-    protected int len;
-
-    /** {@inheritDoc} */
-    @Override public byte readByte() {
-        ensureEnoughData(1);
-
-        return readByteAndShift();
-    }
-
-    /** {@inheritDoc} */
-    @Override public byte[] readByteArray(int cnt) {
-        ensureEnoughData(cnt);
-
-        byte[] res = new byte[cnt];
-
-        copyAndShift(res, BYTE_ARR_OFF, cnt);
-
-        return res;
-    }
-
-    /** {@inheritDoc} */
-    @Override public boolean readBoolean() {
-        return readByte() == BYTE_ONE;
-    }
-
-    /** {@inheritDoc} */
-    @Override public boolean[] readBooleanArray(int cnt) {
-        ensureEnoughData(cnt);
-
-        boolean[] res = new boolean[cnt];
-
-        copyAndShift(res, BOOLEAN_ARR_OFF, cnt);
-
-        return res;
-    }
-
-    /** {@inheritDoc} */
-    @Override public short readShort() {
-        ensureEnoughData(2);
-
-        short res = readShortFast();
-
-        shift(2);
-
-        if (!LITTLE_ENDIAN)
-            res = Short.reverseBytes(res);
-
-        return res;
-    }
-
-    /** {@inheritDoc} */
-    @Override public short[] readShortArray(int cnt) {
-        int len = cnt << 1;
-
-        ensureEnoughData(len);
-
-        short[] res = new short[cnt];
-
-        copyAndShift(res, SHORT_ARR_OFF, len);
-
-        if (!LITTLE_ENDIAN) {
-            for (int i = 0; i < res.length; i++)
-                res[i] = Short.reverseBytes(res[i]);
-        }
-
-        return res;
-    }
-
-    /** {@inheritDoc} */
-    @Override public char readChar() {
-        ensureEnoughData(2);
-
-        char res = readCharFast();
-
-        shift(2);
-
-        if (!LITTLE_ENDIAN)
-            res = Character.reverseBytes(res);
-
-        return res;
-    }
-
-    /** {@inheritDoc} */
-    @Override public char[] readCharArray(int cnt) {
-        int len = cnt << 1;
-
-        ensureEnoughData(len);
-
-        char[] res = new char[cnt];
-
-        copyAndShift(res, CHAR_ARR_OFF, len);
-
-        if (!LITTLE_ENDIAN) {
-            for (int i = 0; i < res.length; i++)
-                res[i] = Character.reverseBytes(res[i]);
-        }
-
-        return res;
-    }
-
-    /** {@inheritDoc} */
-    @Override public int readInt() {
-        ensureEnoughData(4);
-
-        int res = readIntFast();
-
-        shift(4);
-
-        if (!LITTLE_ENDIAN)
-            res = Integer.reverseBytes(res);
-
-        return res;
-    }
-
-    /** {@inheritDoc} */
-    @Override public int[] readIntArray(int cnt) {
-        int len = cnt << 2;
-
-        ensureEnoughData(len);
-
-        int[] res = new int[cnt];
-
-        copyAndShift(res, INT_ARR_OFF, len);
-
-        if (!LITTLE_ENDIAN) {
-            for (int i = 0; i < res.length; i++)
-                res[i] = Integer.reverseBytes(res[i]);
-        }
-
-        return res;
-    }
-
-    /** {@inheritDoc} */
-    @Override public byte readBytePositioned(int pos) {
-        int delta = pos + 1 - this.pos;
-
-        if (delta > 0)
-            ensureEnoughData(delta);
-
-        return readBytePositioned0(pos);
-    }
-
-    /** {@inheritDoc} */
-    @Override public short readShortPositioned(int pos) {
-        int delta = pos + 2 - this.pos;
-
-        if (delta > 0)
-            ensureEnoughData(delta);
-
-        return readShortPositioned0(pos);
-    }
-
-    /** {@inheritDoc} */
-    @Override public int readIntPositioned(int pos) {
-        int delta = pos + 4 - this.pos;
-
-        if (delta > 0)
-            ensureEnoughData(delta);
-
-        return readIntPositioned0(pos);
-    }
-
-    /** {@inheritDoc} */
-    @Override public float readFloat() {
-        return Float.intBitsToFloat(readInt());
-    }
-
-    /** {@inheritDoc} */
-    @Override public float[] readFloatArray(int cnt) {
-        int len = cnt << 2;
-
-        ensureEnoughData(len);
-
-        float[] res = new float[cnt];
-
-        if (LITTLE_ENDIAN)
-            copyAndShift(res, FLOAT_ARR_OFF, len);
-        else {
-            for (int i = 0; i < res.length; i++) {
-                int x = readIntFast();
-
-                shift(4);
-
-                res[i] = Float.intBitsToFloat(Integer.reverseBytes(x));
-            }
-        }
-
-        return res;
-    }
-
-    /** {@inheritDoc} */
-    @Override public long readLong() {
-        ensureEnoughData(8);
-
-        long res = readLongFast();
-
-        shift(8);
-
-        if (!LITTLE_ENDIAN)
-            res = Long.reverseBytes(res);
-
-        return res;
-    }
-
-    /** {@inheritDoc} */
-    @Override public long[] readLongArray(int cnt) {
-        int len = cnt << 3;
-
-        ensureEnoughData(len);
-
-        long[] res = new long[cnt];
-
-        copyAndShift(res, LONG_ARR_OFF, len);
-
-        if (!LITTLE_ENDIAN) {
-            for (int i = 0; i < res.length; i++)
-                res[i] = Long.reverseBytes(res[i]);
-        }
-
-        return res;
-    }
-
-    /** {@inheritDoc} */
-    @Override public double readDouble() {
-        return Double.longBitsToDouble(readLong());
-    }
-
-    /** {@inheritDoc} */
-    @Override public double[] readDoubleArray(int cnt) {
-        int len = cnt << 3;
-
-        ensureEnoughData(len);
-
-        double[] res = new double[cnt];
-
-        if (LITTLE_ENDIAN)
-            copyAndShift(res, DOUBLE_ARR_OFF, len);
-        else {
-            for (int i = 0; i < res.length; i++) {
-                long x = readLongFast();
-
-                shift(8);
-
-                res[i] = Double.longBitsToDouble(Long.reverseBytes(x));
-            }
-        }
-
-        return res;
-    }
-
-    /** {@inheritDoc} */
-    @Override public int read(byte[] arr, int off, int len) {
-        if (len > remaining())
-            len = remaining();
-
-        copyAndShift(arr, BYTE_ARR_OFF + off, len);
-
-        return len;
-    }
-
-    /** {@inheritDoc} */
-    @Override public void position(int pos) {
-        if (remaining() + this.pos < pos)
-            throw new BinaryObjectException("Position is out of bounds: " + pos);
-        else
-            this.pos = pos;
-    }
-
-    /** {@inheritDoc} */
-    @Override public long offheapPointer() {
-        return 0;
-    }
-
-    /**
-     * Ensure that there is enough data.
-     *
-     * @param cnt Length.
-     */
-    protected void ensureEnoughData(int cnt) {
-        if (remaining() < cnt)
-            throw new BinaryObjectException("Not enough data to read the value [position=" + pos +
-                ", requiredBytes=" + cnt + ", remainingBytes=" + remaining() + ']');
-    }
-
-    /**
-     * Read next byte from the stream and perform shift.
-     *
-     * @return Next byte.
-     */
-    protected abstract byte readByteAndShift();
-
-    /**
-     * Copy data to target object shift position afterwards.
-     *
-     * @param target Target.
-     * @param off Offset.
-     * @param len Length.
-     */
-    protected abstract void copyAndShift(Object target, long off, int len);
-
-    /**
-     * Read short value (fast path).
-     *
-     * @return Short value.
-     */
-    protected abstract short readShortFast();
-
-    /**
-     * Read char value (fast path).
-     *
-     * @return Char value.
-     */
-    protected abstract char readCharFast();
-
-    /**
-     * Read int value (fast path).
-     *
-     * @return Int value.
-     */
-    protected abstract int readIntFast();
-
-    /**
-     * Read long value (fast path).
-     *
-     * @return Long value.
-     */
-    protected abstract long readLongFast();
-
-    /**
-     * Internal routine for positioned byte value read.
-     *
-     * @param pos Position.
-     * @return Int value.
-     */
-    protected abstract byte readBytePositioned0(int pos);
-
-    /**
-     * Internal routine for positioned short value read.
-     *
-     * @param pos Position.
-     * @return Int value.
-     */
-    protected abstract short readShortPositioned0(int pos);
-
-    /**
-     * Internal routine for positioned int value read.
-     *
-     * @param pos Position.
-     * @return Int value.
-     */
-    protected abstract int readIntPositioned0(int pos);
-}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ignite/blob/1dbf20e0/modules/core/src/main/java/org/apache/ignite/internal/portable/streams/PortableAbstractOutputStream.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/portable/streams/PortableAbstractOutputStream.java b/modules/core/src/main/java/org/apache/ignite/internal/portable/streams/PortableAbstractOutputStream.java
deleted file mode 100644
index 7efc942..0000000
--- a/modules/core/src/main/java/org/apache/ignite/internal/portable/streams/PortableAbstractOutputStream.java
+++ /dev/null
@@ -1,347 +0,0 @@
-/*
- * 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.portable.streams;
-
-/**
- * Base portable output stream.
- */
-public abstract class PortableAbstractOutputStream extends PortableAbstractStream
-    implements PortableOutputStream {
-    /** Minimal capacity when it is reasonable to start doubling resize. */
-    private static final int MIN_CAP = 256;
-
-    /** {@inheritDoc} */
-    @Override public void writeByte(byte val) {
-        ensureCapacity(pos + 1);
-
-        writeByteAndShift(val);
-    }
-
-    /** {@inheritDoc} */
-    @Override public void writeByteArray(byte[] val) {
-        ensureCapacity(pos + val.length);
-
-        copyAndShift(val, BYTE_ARR_OFF, val.length);
-    }
-
-    /** {@inheritDoc} */
-    @Override public void writeBoolean(boolean val) {
-        writeByte(val ? BYTE_ONE : BYTE_ZERO);
-    }
-
-    /** {@inheritDoc} */
-    @Override public void writeBooleanArray(boolean[] val) {
-        ensureCapacity(pos + val.length);
-
-        copyAndShift(val, BOOLEAN_ARR_OFF, val.length);
-    }
-
-    /** {@inheritDoc} */
-    @Override public void writeShort(short val) {
-        ensureCapacity(pos + 2);
-
-        if (!LITTLE_ENDIAN)
-            val = Short.reverseBytes(val);
-
-        writeShortFast(val);
-
-        shift(2);
-    }
-
-    /** {@inheritDoc} */
-    @Override public void writeShortArray(short[] val) {
-        int cnt = val.length << 1;
-
-        ensureCapacity(pos + cnt);
-
-        if (LITTLE_ENDIAN)
-            copyAndShift(val, SHORT_ARR_OFF, cnt);
-        else {
-            for (short item : val)
-                writeShortFast(Short.reverseBytes(item));
-
-            shift(cnt);
-        }
-    }
-
-    /** {@inheritDoc} */
-    @Override public void writeChar(char val) {
-        ensureCapacity(pos + 2);
-
-        if (!LITTLE_ENDIAN)
-            val = Character.reverseBytes(val);
-
-        writeCharFast(val);
-
-        shift(2);
-    }
-
-    /** {@inheritDoc} */
-    @Override public void writeCharArray(char[] val) {
-        int cnt = val.length << 1;
-
-        ensureCapacity(pos + cnt);
-
-        if (LITTLE_ENDIAN)
-            copyAndShift(val, CHAR_ARR_OFF, cnt);
-        else {
-            for (char item : val)
-                writeCharFast(Character.reverseBytes(item));
-
-            shift(cnt);
-        }
-    }
-
-    /** {@inheritDoc} */
-    @Override public void writeInt(int val) {
-        ensureCapacity(pos + 4);
-
-        if (!LITTLE_ENDIAN)
-            val = Integer.reverseBytes(val);
-
-        writeIntFast(val);
-
-        shift(4);
-    }
-
-    /** {@inheritDoc} */
-    @Override public void writeShort(int pos, short val) {
-        ensureCapacity(pos + 2);
-
-        unsafeWriteShort(pos, val);
-    }
-
-    /** {@inheritDoc} */
-    @Override public void writeInt(int pos, int val) {
-        ensureCapacity(pos + 4);
-
-        unsafeWriteInt(pos, val);
-    }
-
-    /** {@inheritDoc} */
-    @Override public void writeIntArray(int[] val) {
-        int cnt = val.length << 2;
-
-        ensureCapacity(pos + cnt);
-
-        if (LITTLE_ENDIAN)
-            copyAndShift(val, INT_ARR_OFF, cnt);
-        else {
-            for (int item : val)
-                writeIntFast(Integer.reverseBytes(item));
-
-            shift(cnt);
-        }
-    }
-
-    /** {@inheritDoc} */
-    @Override public void writeFloat(float val) {
-        writeInt(Float.floatToIntBits(val));
-    }
-
-    /** {@inheritDoc} */
-    @Override public void writeFloatArray(float[] val) {
-        int cnt = val.length << 2;
-
-        ensureCapacity(pos + cnt);
-
-        if (LITTLE_ENDIAN)
-            copyAndShift(val, FLOAT_ARR_OFF, cnt);
-        else {
-            for (float item : val) {
-                writeIntFast(Integer.reverseBytes(Float.floatToIntBits(item)));
-
-                shift(4);
-            }
-        }
-    }
-
-    /** {@inheritDoc} */
-    @Override public void writeLong(long val) {
-        ensureCapacity(pos + 8);
-
-        if (!LITTLE_ENDIAN)
-            val = Long.reverseBytes(val);
-
-        writeLongFast(val);
-
-        shift(8);
-    }
-
-    /** {@inheritDoc} */
-    @Override public void writeLongArray(long[] val) {
-        int cnt = val.length << 3;
-
-        ensureCapacity(pos + cnt);
-
-        if (LITTLE_ENDIAN)
-            copyAndShift(val, LONG_ARR_OFF, cnt);
-        else {
-            for (long item : val)
-                writeLongFast(Long.reverseBytes(item));
-
-            shift(cnt);
-        }
-    }
-
-    /** {@inheritDoc} */
-    @Override public void writeDouble(double val) {
-        writeLong(Double.doubleToLongBits(val));
-    }
-
-    /** {@inheritDoc} */
-    @Override public void writeDoubleArray(double[] val) {
-        int cnt = val.length << 3;
-
-        ensureCapacity(pos + cnt);
-
-        if (LITTLE_ENDIAN)
-            copyAndShift(val, DOUBLE_ARR_OFF, cnt);
-        else {
-            for (double item : val) {
-                writeLongFast(Long.reverseBytes(Double.doubleToLongBits(item)));
-
-                shift(8);
-            }
-        }
-    }
-
-    /** {@inheritDoc} */
-    @Override public void write(byte[] arr, int off, int len) {
-        ensureCapacity(pos + len);
-
-        copyAndShift(arr, BYTE_ARR_OFF + off, len);
-    }
-
-    /** {@inheritDoc} */
-    @Override public void write(long addr, int cnt) {
-        ensureCapacity(pos + cnt);
-
-        copyAndShift(null, addr, cnt);
-    }
-
-    /** {@inheritDoc} */
-    @Override public void position(int pos) {
-        ensureCapacity(pos);
-
-        unsafePosition(pos);
-    }
-
-    /** {@inheritDoc} */
-    @Override public long offheapPointer() {
-        return 0;
-    }
-
-    /** {@inheritDoc} */
-    @Override public void unsafeEnsure(int cap) {
-        ensureCapacity(pos + cap);
-    }
-
-    /** {@inheritDoc} */
-    @Override public void unsafePosition(int pos) {
-        this.pos = pos;
-    }
-
-    /** {@inheritDoc} */
-    @Override public void unsafeWriteBoolean(boolean val) {
-        unsafeWriteByte(val ? BYTE_ONE : BYTE_ZERO);
-    }
-
-    /** {@inheritDoc} */
-    @Override public void unsafeWriteFloat(float val) {
-        unsafeWriteInt(Float.floatToIntBits(val));
-    }
-
-    /** {@inheritDoc} */
-    @Override public void unsafeWriteDouble(double val) {
-        unsafeWriteLong(Double.doubleToLongBits(val));
-    }
-
-    /**
-     * Calculate new capacity.
-     *
-     * @param curCap Current capacity.
-     * @param reqCap Required capacity.
-     * @return New capacity.
-     */
-    protected static int capacity(int curCap, int reqCap) {
-        int newCap;
-
-        if (reqCap < MIN_CAP)
-            newCap = MIN_CAP;
-        else {
-            newCap = curCap << 1;
-
-            if (newCap < reqCap)
-                newCap = reqCap;
-        }
-
-        return newCap;
-    }
-
-    /**
-     * Write next byte to the stream.
-     *
-     * @param val Value.
-     */
-    protected abstract void writeByteAndShift(byte val);
-
-    /**
-     * Copy source object to the stream shift position afterwards.
-     *
-     * @param src Source.
-     * @param off Offset.
-     * @param len Length.
-     */
-    protected abstract void copyAndShift(Object src, long off, int len);
-
-    /**
-     * Write short value (fast path).
-     *
-     * @param val Short value.
-     */
-    protected abstract void writeShortFast(short val);
-
-    /**
-     * Write char value (fast path).
-     *
-     * @param val Char value.
-     */
-    protected abstract void writeCharFast(char val);
-
-    /**
-     * Write int value (fast path).
-     *
-     * @param val Int value.
-     */
-    protected abstract void writeIntFast(int val);
-
-    /**
-     * Write long value (fast path).
-     *
-     * @param val Long value.
-     */
-    protected abstract void writeLongFast(long val);
-
-    /**
-     * Ensure capacity.
-     *
-     * @param cnt Required byte count.
-     */
-    protected abstract void ensureCapacity(int cnt);
-}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ignite/blob/1dbf20e0/modules/core/src/main/java/org/apache/ignite/internal/portable/streams/PortableAbstractStream.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/portable/streams/PortableAbstractStream.java b/modules/core/src/main/java/org/apache/ignite/internal/portable/streams/PortableAbstractStream.java
deleted file mode 100644
index b2cd8b5..0000000
--- a/modules/core/src/main/java/org/apache/ignite/internal/portable/streams/PortableAbstractStream.java
+++ /dev/null
@@ -1,80 +0,0 @@
-/*
- * 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.portable.streams;
-
-import java.nio.ByteOrder;
-import org.apache.ignite.internal.util.GridUnsafe;
-import sun.misc.Unsafe;
-
-/**
- * Portable abstract stream.
- */
-public abstract class PortableAbstractStream implements PortableStream {
-    /** Byte: zero. */
-    protected static final byte BYTE_ZERO = 0;
-
-    /** Byte: one. */
-    protected static final byte BYTE_ONE = 1;
-
-    /** Whether little endian is used on the platform. */
-    protected static final boolean LITTLE_ENDIAN = ByteOrder.nativeOrder() == ByteOrder.LITTLE_ENDIAN;
-
-    /** Unsafe instance. */
-    protected static final Unsafe UNSAFE = GridUnsafe.unsafe();
-
-    /** Array offset: boolean. */
-    protected static final long BOOLEAN_ARR_OFF = UNSAFE.arrayBaseOffset(boolean[].class);
-
-    /** Array offset: byte. */
-    protected static final long BYTE_ARR_OFF = UNSAFE.arrayBaseOffset(byte[].class);
-
-    /** Array offset: short. */
-    protected static final long SHORT_ARR_OFF = UNSAFE.arrayBaseOffset(short[].class);
-
-    /** Array offset: char. */
-    protected static final long CHAR_ARR_OFF = UNSAFE.arrayBaseOffset(char[].class);
-
-    /** Array offset: int. */
-    protected static final long INT_ARR_OFF = UNSAFE.arrayBaseOffset(int[].class);
-
-    /** Array offset: float. */
-    protected static final long FLOAT_ARR_OFF = UNSAFE.arrayBaseOffset(float[].class);
-
-    /** Array offset: long. */
-    protected static final long LONG_ARR_OFF = UNSAFE.arrayBaseOffset(long[].class);
-
-    /** Array offset: double. */
-    protected static final long DOUBLE_ARR_OFF = UNSAFE.arrayBaseOffset(double[].class);
-
-    /** Position. */
-    protected int pos;
-
-    /** {@inheritDoc} */
-    @Override public int position() {
-        return pos;
-    }
-
-    /**
-     * Shift position.
-     *
-     * @param cnt Byte count.
-     */
-    protected void shift(int cnt) {
-        pos += cnt;
-    }
-}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ignite/blob/1dbf20e0/modules/core/src/main/java/org/apache/ignite/internal/portable/streams/PortableHeapInputStream.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/portable/streams/PortableHeapInputStream.java b/modules/core/src/main/java/org/apache/ignite/internal/portable/streams/PortableHeapInputStream.java
deleted file mode 100644
index 1b39950..0000000
--- a/modules/core/src/main/java/org/apache/ignite/internal/portable/streams/PortableHeapInputStream.java
+++ /dev/null
@@ -1,166 +0,0 @@
-/*
- * 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.portable.streams;
-
-import java.util.Arrays;
-
-/**
- * Portable off-heap input stream.
- */
-public final class PortableHeapInputStream extends PortableAbstractInputStream {
-    /**
-     * Create stream with pointer set at the given position.
-     *
-     * @param data Data.
-     * @param pos Position.
-     * @return Stream.
-     */
-    public static PortableHeapInputStream create(byte[] data, int pos) {
-        assert pos < data.length;
-
-        PortableHeapInputStream stream = new PortableHeapInputStream(data);
-
-        stream.pos = pos;
-
-        return stream;
-    }
-
-    /** Data. */
-    private byte[] data;
-
-    /**
-     * Constructor.
-     *
-     * @param data Data.
-     */
-    public PortableHeapInputStream(byte[] data) {
-        this.data = data;
-
-        len = data.length;
-    }
-
-    /**
-     * @return Copy of this stream.
-     */
-    public PortableHeapInputStream copy() {
-        PortableHeapInputStream in = new PortableHeapInputStream(Arrays.copyOf(data, data.length));
-
-        in.position(pos);
-
-        return in;
-    }
-
-    /**
-     * Method called from JNI to resize stream.
-     *
-     * @param len Required length.
-     * @return Underlying byte array.
-     */
-    public byte[] resize(int len) {
-        if (data.length < len) {
-            byte[] data0 = new byte[len];
-
-            UNSAFE.copyMemory(data, BYTE_ARR_OFF, data0, BYTE_ARR_OFF, data.length);
-
-            data = data0;
-        }
-
-        return data;
-    }
-
-    /** {@inheritDoc} */
-    @Override public int remaining() {
-        return data.length - pos;
-    }
-
-    /** {@inheritDoc} */
-    @Override public byte[] array() {
-        return data;
-    }
-
-    /** {@inheritDoc} */
-    @Override public byte[] arrayCopy() {
-        byte[] res = new byte[len];
-
-        UNSAFE.copyMemory(data, BYTE_ARR_OFF, res, BYTE_ARR_OFF, res.length);
-
-        return res;
-    }
-
-    /** {@inheritDoc} */
-    @Override public boolean hasArray() {
-        return true;
-    }
-
-    /** {@inheritDoc} */
-    @Override protected byte readByteAndShift() {
-        return data[pos++];
-    }
-
-    /** {@inheritDoc} */
-    @Override protected void copyAndShift(Object target, long off, int len) {
-        UNSAFE.copyMemory(data, BYTE_ARR_OFF + pos, target, off, len);
-
-        shift(len);
-    }
-
-    /** {@inheritDoc} */
-    @Override protected short readShortFast() {
-        return UNSAFE.getShort(data, BYTE_ARR_OFF + pos);
-    }
-
-    /** {@inheritDoc} */
-    @Override protected char readCharFast() {
-        return UNSAFE.getChar(data, BYTE_ARR_OFF + pos);
-    }
-
-    /** {@inheritDoc} */
-    @Override protected int readIntFast() {
-        return UNSAFE.getInt(data, BYTE_ARR_OFF + pos);
-    }
-
-    /** {@inheritDoc} */
-    @Override protected long readLongFast() {
-        return UNSAFE.getLong(data, BYTE_ARR_OFF + pos);
-    }
-
-    /** {@inheritDoc} */
-    @Override protected byte readBytePositioned0(int pos) {
-        return UNSAFE.getByte(data, BYTE_ARR_OFF + pos);
-    }
-
-    /** {@inheritDoc} */
-    @Override protected short readShortPositioned0(int pos) {
-        short res = UNSAFE.getShort(data, BYTE_ARR_OFF + pos);
-
-        if (!LITTLE_ENDIAN)
-            res = Short.reverseBytes(res);
-
-        return res;
-    }
-
-    /** {@inheritDoc} */
-    @Override protected int readIntPositioned0(int pos) {
-        int res = UNSAFE.getInt(data, BYTE_ARR_OFF + pos);
-
-        if (!LITTLE_ENDIAN)
-            res = Integer.reverseBytes(res);
-
-        return res;
-    }
-}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ignite/blob/1dbf20e0/modules/core/src/main/java/org/apache/ignite/internal/portable/streams/PortableHeapOutputStream.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/portable/streams/PortableHeapOutputStream.java b/modules/core/src/main/java/org/apache/ignite/internal/portable/streams/PortableHeapOutputStream.java
deleted file mode 100644
index 062a359..0000000
--- a/modules/core/src/main/java/org/apache/ignite/internal/portable/streams/PortableHeapOutputStream.java
+++ /dev/null
@@ -1,176 +0,0 @@
-/*
- * 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.portable.streams;
-
-/**
- * Portable heap output stream.
- */
-public final class PortableHeapOutputStream extends PortableAbstractOutputStream {
-    /** Allocator. */
-    private final PortableMemoryAllocatorChunk chunk;
-
-    /** Data. */
-    private byte[] data;
-
-    /**
-     * Constructor.
-     *
-     * @param cap Initial capacity.
-     */
-    public PortableHeapOutputStream(int cap) {
-        this(cap, PortableMemoryAllocator.INSTANCE.chunk());
-    }
-
-    /**
-     * Constructor.
-     *
-     * @param cap Capacity.
-     * @param chunk Chunk.
-     */
-    public PortableHeapOutputStream(int cap, PortableMemoryAllocatorChunk chunk) {
-        this.chunk = chunk;
-
-        data = chunk.allocate(cap);
-    }
-
-    /** {@inheritDoc} */
-    @Override public void close() {
-        chunk.release(data, pos);
-    }
-
-    /** {@inheritDoc} */
-    @Override public void ensureCapacity(int cnt) {
-        if (cnt > data.length) {
-            int newCap = capacity(data.length, cnt);
-
-            data = chunk.reallocate(data, newCap);
-        }
-    }
-
-    /** {@inheritDoc} */
-    @Override public byte[] array() {
-        return data;
-    }
-
-    /** {@inheritDoc} */
-    @Override public byte[] arrayCopy() {
-        byte[] res = new byte[pos];
-
-        UNSAFE.copyMemory(data, BYTE_ARR_OFF, res, BYTE_ARR_OFF, pos);
-
-        return res;
-    }
-
-    /** {@inheritDoc} */
-    @Override public boolean hasArray() {
-        return true;
-    }
-
-    /** {@inheritDoc} */
-    @Override protected void writeByteAndShift(byte val) {
-        data[pos++] = val;
-    }
-
-    /** {@inheritDoc} */
-    @Override protected void copyAndShift(Object src, long off, int len) {
-        UNSAFE.copyMemory(src, off, data, BYTE_ARR_OFF + pos, len);
-
-        shift(len);
-    }
-
-    /** {@inheritDoc} */
-    @Override protected void writeShortFast(short val) {
-        UNSAFE.putShort(data, BYTE_ARR_OFF + pos, val);
-    }
-
-    /** {@inheritDoc} */
-    @Override protected void writeCharFast(char val) {
-        UNSAFE.putChar(data, BYTE_ARR_OFF + pos, val);
-    }
-
-    /** {@inheritDoc} */
-    @Override protected void writeIntFast(int val) {
-        UNSAFE.putInt(data, BYTE_ARR_OFF + pos, val);
-    }
-
-    /** {@inheritDoc} */
-    @Override protected void writeLongFast(long val) {
-        UNSAFE.putLong(data, BYTE_ARR_OFF + pos, val);
-    }
-
-    /** {@inheritDoc} */
-    @Override public void unsafeWriteByte(byte val) {
-        UNSAFE.putByte(data, BYTE_ARR_OFF + pos++, val);
-    }
-
-    /** {@inheritDoc} */
-    @Override public void unsafeWriteShort(short val) {
-        if (!LITTLE_ENDIAN)
-            val = Short.reverseBytes(val);
-
-        UNSAFE.putShort(data, BYTE_ARR_OFF + pos, val);
-
-        shift(2);
-    }
-
-    /** {@inheritDoc} */
-    @Override public void unsafeWriteShort(int pos, short val) {
-        if (!LITTLE_ENDIAN)
-            val = Short.reverseBytes(val);
-
-        UNSAFE.putShort(data, BYTE_ARR_OFF + pos, val);
-    }
-
-    /** {@inheritDoc} */
-    @Override public void unsafeWriteChar(char val) {
-        if (!LITTLE_ENDIAN)
-            val = Character.reverseBytes(val);
-
-        UNSAFE.putChar(data, BYTE_ARR_OFF + pos, val);
-
-        shift(2);
-    }
-
-    /** {@inheritDoc} */
-    @Override public void unsafeWriteInt(int val) {
-        if (!LITTLE_ENDIAN)
-            val = Integer.reverseBytes(val);
-
-        UNSAFE.putInt(data, BYTE_ARR_OFF + pos, val);
-
-        shift(4);
-    }
-
-    /** {@inheritDoc} */
-    @Override public void unsafeWriteInt(int pos, int val) {
-        if (!LITTLE_ENDIAN)
-            val = Integer.reverseBytes(val);
-
-        UNSAFE.putInt(data, BYTE_ARR_OFF + pos, val);
-    }
-
-    /** {@inheritDoc} */
-    @Override public void unsafeWriteLong(long val) {
-        if (!LITTLE_ENDIAN)
-            val = Long.reverseBytes(val);
-
-        UNSAFE.putLong(data, BYTE_ARR_OFF + pos, val);
-
-        shift(8);
-    }
-}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ignite/blob/1dbf20e0/modules/core/src/main/java/org/apache/ignite/internal/portable/streams/PortableInputStream.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/portable/streams/PortableInputStream.java b/modules/core/src/main/java/org/apache/ignite/internal/portable/streams/PortableInputStream.java
deleted file mode 100644
index a2273d1..0000000
--- a/modules/core/src/main/java/org/apache/ignite/internal/portable/streams/PortableInputStream.java
+++ /dev/null
@@ -1,162 +0,0 @@
-/*
- * 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.portable.streams;
-
-import org.apache.ignite.internal.portable.PortablePositionReadable;
-
-/**
- * Portable input stream.
- */
-public interface PortableInputStream extends PortableStream, PortablePositionReadable {
-    /**
-     * Read byte value.
-     *
-     * @return Byte value.
-     */
-    public byte readByte();
-
-    /**
-     * Read byte array.
-     *
-     * @param cnt Expected item count.
-     * @return Byte array.
-     */
-    public byte[] readByteArray(int cnt);
-
-    /**
-     * Reads {@code cnt} of bytes into byte array.
-     *
-     * @param arr Expected item count.
-     * @param off offset
-     * @param cnt number of bytes to read.
-     * @return actual length read.
-     */
-    public int read(byte[] arr, int off, int cnt);
-
-    /**
-     * Read boolean value.
-     *
-     * @return Boolean value.
-     */
-    public boolean readBoolean();
-
-    /**
-     * Read boolean array.
-     *
-     * @param cnt Expected item count.
-     * @return Boolean array.
-     */
-    public boolean[] readBooleanArray(int cnt);
-
-    /**
-     * Read short value.
-     *
-     * @return Short value.
-     */
-    public short readShort();
-
-    /**
-     * Read short array.
-     *
-     * @param cnt Expected item count.
-     * @return Short array.
-     */
-    public short[] readShortArray(int cnt);
-
-    /**
-     * Read char value.
-     *
-     * @return Char value.
-     */
-    public char readChar();
-
-    /**
-     * Read char array.
-     *
-     * @param cnt Expected item count.
-     * @return Char array.
-     */
-    public char[] readCharArray(int cnt);
-
-    /**
-     * Read int value.
-     *
-     * @return Int value.
-     */
-    public int readInt();
-
-    /**
-     * Read int array.
-     *
-     * @param cnt Expected item count.
-     * @return Int array.
-     */
-    public int[] readIntArray(int cnt);
-
-    /**
-     * Read float value.
-     *
-     * @return Float value.
-     */
-    public float readFloat();
-
-    /**
-     * Read float array.
-     *
-     * @param cnt Expected item count.
-     * @return Float array.
-     */
-    public float[] readFloatArray(int cnt);
-
-    /**
-     * Read long value.
-     *
-     * @return Long value.
-     */
-    public long readLong();
-
-    /**
-     * Read long array.
-     *
-     * @param cnt Expected item count.
-     * @return Long array.
-     */
-    public long[] readLongArray(int cnt);
-
-    /**
-     * Read double value.
-     *
-     * @return Double value.
-     */
-    public double readDouble();
-
-    /**
-     * Read double array.
-     *
-     * @param cnt Expected item count.
-     * @return Double array.
-     */
-    public double[] readDoubleArray(int cnt);
-
-    /**
-     * Gets amount of remaining data in bytes.
-     *
-     * @return Remaining data.
-     */
-    public int remaining();
-}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ignite/blob/1dbf20e0/modules/core/src/main/java/org/apache/ignite/internal/portable/streams/PortableMemoryAllocator.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/portable/streams/PortableMemoryAllocator.java b/modules/core/src/main/java/org/apache/ignite/internal/portable/streams/PortableMemoryAllocator.java
deleted file mode 100644
index e16747b..0000000
--- a/modules/core/src/main/java/org/apache/ignite/internal/portable/streams/PortableMemoryAllocator.java
+++ /dev/null
@@ -1,57 +0,0 @@
-/*
- * 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.portable.streams;
-
-/**
- * Thread-local memory allocator.
- */
-public final class PortableMemoryAllocator {
-    /** Memory allocator instance. */
-    public static final PortableMemoryAllocator INSTANCE = new PortableMemoryAllocator();
-
-    /** Holders. */
-    private static final ThreadLocal<PortableMemoryAllocatorChunk> holders = new ThreadLocal<>();
-
-    /**
-     * Ensures singleton.
-     */
-    private PortableMemoryAllocator() {
-        // No-op.
-    }
-
-    public PortableMemoryAllocatorChunk chunk() {
-        PortableMemoryAllocatorChunk holder = holders.get();
-
-        if (holder == null)
-            holders.set(holder = new PortableMemoryAllocatorChunk());
-
-        return holder;
-    }
-
-    /**
-     * Checks whether a thread-local array is acquired or not.
-     * The function is used by Unit tests.
-     *
-     * @return {@code true} if acquired {@code false} otherwise.
-     */
-    public boolean isAcquired() {
-        PortableMemoryAllocatorChunk holder = holders.get();
-
-        return holder != null && holder.isAcquired();
-    }
-}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ignite/blob/1dbf20e0/modules/core/src/main/java/org/apache/ignite/internal/portable/streams/PortableMemoryAllocatorChunk.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/portable/streams/PortableMemoryAllocatorChunk.java b/modules/core/src/main/java/org/apache/ignite/internal/portable/streams/PortableMemoryAllocatorChunk.java
deleted file mode 100644
index 35d58f7..0000000
--- a/modules/core/src/main/java/org/apache/ignite/internal/portable/streams/PortableMemoryAllocatorChunk.java
+++ /dev/null
@@ -1,117 +0,0 @@
-/*
- * 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.portable.streams;
-
-import org.apache.ignite.internal.util.GridUnsafe;
-import org.apache.ignite.internal.util.typedef.internal.U;
-import sun.misc.Unsafe;
-
-import static org.apache.ignite.IgniteSystemProperties.IGNITE_MARSHAL_BUFFERS_RECHECK;
-
-/**
- * Memory allocator chunk.
- */
-public class PortableMemoryAllocatorChunk {
-    /** Unsafe instance. */
-    protected static final Unsafe UNSAFE = GridUnsafe.unsafe();
-
-    /** Array offset: byte. */
-    protected static final long BYTE_ARR_OFF = UNSAFE.arrayBaseOffset(byte[].class);
-
-    /** Buffer size re-check frequency. */
-    private static final Long CHECK_FREQ = Long.getLong(IGNITE_MARSHAL_BUFFERS_RECHECK, 10000);
-
-    /** Data array */
-    private byte[] data;
-
-    /** Max message size detected between checks. */
-    private int maxMsgSize;
-
-    /** Last time array size is checked. */
-    private long lastCheck = U.currentTimeMillis();
-
-    /** Whether the holder is acquired or not. */
-    private boolean acquired;
-
-    /**
-     * Allocate.
-     *
-     * @param size Desired size.
-     * @return Data.
-     */
-    public byte[] allocate(int size) {
-        if (acquired)
-            return new byte[size];
-
-        acquired = true;
-
-        if (data == null || size > data.length)
-            data = new byte[size];
-
-        return data;
-    }
-
-    /**
-     * Reallocate.
-     *
-     * @param data Old data.
-     * @param size Size.
-     * @return New data.
-     */
-    public byte[] reallocate(byte[] data, int size) {
-        byte[] newData = new byte[size];
-
-        if (this.data == data)
-            this.data = newData;
-
-        UNSAFE.copyMemory(data, BYTE_ARR_OFF, newData, BYTE_ARR_OFF, data.length);
-
-        return newData;
-    }
-
-    /**
-     * Shrinks array size if needed.
-     */
-    public void release(byte[] data, int maxMsgSize) {
-        if (this.data != data)
-            return;
-
-        if (maxMsgSize > this.maxMsgSize)
-            this.maxMsgSize = maxMsgSize;
-
-        this.acquired = false;
-
-        long now = U.currentTimeMillis();
-
-        if (now - this.lastCheck >= CHECK_FREQ) {
-            int halfSize = data.length >> 1;
-
-            if (this.maxMsgSize < halfSize)
-                this.data = new byte[halfSize];
-
-            this.lastCheck = now;
-        }
-    }
-
-    /**
-     * @return {@code True} if acquired.
-     */
-    public boolean isAcquired() {
-        return acquired;
-    }
-}

http://git-wip-us.apache.org/repos/asf/ignite/blob/1dbf20e0/modules/core/src/main/java/org/apache/ignite/internal/portable/streams/PortableOffheapInputStream.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/portable/streams/PortableOffheapInputStream.java b/modules/core/src/main/java/org/apache/ignite/internal/portable/streams/PortableOffheapInputStream.java
deleted file mode 100644
index 1dc9b5b..0000000
--- a/modules/core/src/main/java/org/apache/ignite/internal/portable/streams/PortableOffheapInputStream.java
+++ /dev/null
@@ -1,144 +0,0 @@
-/*
- * 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.portable.streams;
-
-/**
- * Portable off-heap input stream.
- */
-public class PortableOffheapInputStream extends PortableAbstractInputStream {
-    /** Pointer. */
-    private final long ptr;
-
-    /** Capacity. */
-    private final int cap;
-
-    /** */
-    private boolean forceHeap;
-
-    /**
-     * Constructor.
-     *
-     * @param ptr Pointer.
-     * @param cap Capacity.
-     */
-    public PortableOffheapInputStream(long ptr, int cap) {
-        this(ptr, cap, false);
-    }
-
-    /**
-     * Constructor.
-     *
-     * @param ptr Pointer.
-     * @param cap Capacity.
-     * @param forceHeap If {@code true} method {@link #offheapPointer} returns 0 and unmarshalling will
-     *        create heap-based objects.
-     */
-    public PortableOffheapInputStream(long ptr, int cap, boolean forceHeap) {
-        this.ptr = ptr;
-        this.cap = cap;
-        this.forceHeap = forceHeap;
-
-        len = cap;
-    }
-
-    /** {@inheritDoc} */
-    @Override public int remaining() {
-        return cap - pos;
-    }
-
-    /** {@inheritDoc} */
-    @Override public byte[] array() {
-        return arrayCopy();
-    }
-
-    /** {@inheritDoc} */
-    @Override public byte[] arrayCopy() {
-        byte[] res = new byte[len];
-
-        UNSAFE.copyMemory(null, ptr, res, BYTE_ARR_OFF, res.length);
-
-        return res;
-    }
-
-    /** {@inheritDoc} */
-    @Override public boolean hasArray() {
-        return false;
-    }
-
-    /** {@inheritDoc} */
-    @Override protected byte readByteAndShift() {
-        return UNSAFE.getByte(ptr + pos++);
-    }
-
-    /** {@inheritDoc} */
-    @Override protected void copyAndShift(Object target, long off, int len) {
-        UNSAFE.copyMemory(null, ptr + pos, target, off, len);
-
-        shift(len);
-    }
-
-    /** {@inheritDoc} */
-    @Override protected short readShortFast() {
-        return UNSAFE.getShort(ptr + pos);
-    }
-
-    /** {@inheritDoc} */
-    @Override protected char readCharFast() {
-        return UNSAFE.getChar(ptr + pos);
-    }
-
-    /** {@inheritDoc} */
-    @Override protected int readIntFast() {
-        return UNSAFE.getInt(ptr + pos);
-    }
-
-    /** {@inheritDoc} */
-    @Override protected long readLongFast() {
-        return UNSAFE.getLong(ptr + pos);
-    }
-
-    /** {@inheritDoc} */
-    @Override protected byte readBytePositioned0(int pos) {
-        return UNSAFE.getByte(ptr + pos);
-    }
-
-    /** {@inheritDoc} */
-    @Override protected short readShortPositioned0(int pos) {
-        short res = UNSAFE.getShort(ptr + pos);
-
-        if (!LITTLE_ENDIAN)
-            res = Short.reverseBytes(res);
-
-        return res;
-    }
-
-    /** {@inheritDoc} */
-    @Override protected int readIntPositioned0(int pos) {
-        int res = UNSAFE.getInt(ptr + pos);
-
-        if (!LITTLE_ENDIAN)
-            res = Integer.reverseBytes(res);
-
-        return res;
-    }
-
-    /** {@inheritDoc} */
-    @Override public long offheapPointer() {
-        return forceHeap ? 0 : ptr;
-    }
-}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ignite/blob/1dbf20e0/modules/core/src/main/java/org/apache/ignite/internal/portable/streams/PortableOffheapOutputStream.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/portable/streams/PortableOffheapOutputStream.java b/modules/core/src/main/java/org/apache/ignite/internal/portable/streams/PortableOffheapOutputStream.java
deleted file mode 100644
index cadd244..0000000
--- a/modules/core/src/main/java/org/apache/ignite/internal/portable/streams/PortableOffheapOutputStream.java
+++ /dev/null
@@ -1,222 +0,0 @@
-/*
- * 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.portable.streams;
-
-/**
- * Portable offheap output stream.
- */
-public class PortableOffheapOutputStream extends PortableAbstractOutputStream {
-    /** Pointer. */
-    private long ptr;
-
-    /** Length of bytes that cen be used before resize is necessary. */
-    private int cap;
-
-    /**
-     * Constructor.
-     *
-     * @param cap Capacity.
-     */
-    public PortableOffheapOutputStream(int cap) {
-        this(0, cap);
-    }
-
-    /**
-     * Constructor.
-     *
-     * @param ptr Pointer to existing address.
-     * @param cap Capacity.
-     */
-    public PortableOffheapOutputStream(long ptr, int cap) {
-        this.ptr = ptr == 0 ? allocate(cap) : ptr;
-
-        this.cap = cap;
-    }
-
-    /** {@inheritDoc} */
-    @Override public void close() {
-        release(ptr);
-    }
-
-    /** {@inheritDoc} */
-    @Override public void ensureCapacity(int cnt) {
-        if (cnt > cap) {
-            int newCap = capacity(cap, cnt);
-
-            ptr = reallocate(ptr, newCap);
-
-            cap = newCap;
-        }
-    }
-
-    /** {@inheritDoc} */
-    @Override public byte[] array() {
-        return arrayCopy();
-    }
-
-    /** {@inheritDoc} */
-    @Override public byte[] arrayCopy() {
-        byte[] res = new byte[pos];
-
-        UNSAFE.copyMemory(null, ptr, res, BYTE_ARR_OFF, pos);
-
-        return res;
-    }
-
-    /**
-     * @return Pointer.
-     */
-    public long pointer() {
-        return ptr;
-    }
-
-    /**
-     * @return Capacity.
-     */
-    public int capacity() {
-        return cap;
-    }
-
-    /** {@inheritDoc} */
-    @Override protected void writeByteAndShift(byte val) {
-        UNSAFE.putByte(ptr + pos++, val);
-    }
-
-    /** {@inheritDoc} */
-    @Override protected void copyAndShift(Object src, long offset, int len) {
-        UNSAFE.copyMemory(src, offset, null, ptr + pos, len);
-
-        shift(len);
-    }
-
-    /** {@inheritDoc} */
-    @Override protected void writeShortFast(short val) {
-        UNSAFE.putShort(ptr + pos, val);
-    }
-
-    /** {@inheritDoc} */
-    @Override protected void writeCharFast(char val) {
-        UNSAFE.putChar(ptr + pos, val);
-    }
-
-    /** {@inheritDoc} */
-    @Override protected void writeIntFast(int val) {
-        UNSAFE.putInt(ptr + pos, val);
-    }
-
-    /** {@inheritDoc} */
-    @Override protected void writeLongFast(long val) {
-        UNSAFE.putLong(ptr + pos, val);
-    }
-
-    /** {@inheritDoc} */
-    @Override public boolean hasArray() {
-        return false;
-    }
-
-    /** {@inheritDoc} */
-    @Override public void unsafeWriteByte(byte val) {
-        UNSAFE.putByte(ptr + pos++, val);
-    }
-
-    /** {@inheritDoc} */
-    @Override public void unsafeWriteShort(short val) {
-        if (!LITTLE_ENDIAN)
-            val = Short.reverseBytes(val);
-
-        UNSAFE.putShort(ptr + pos, val);
-
-        shift(2);
-    }
-
-    /** {@inheritDoc} */
-    @Override public void unsafeWriteShort(int pos, short val) {
-        if (!LITTLE_ENDIAN)
-            val = Short.reverseBytes(val);
-
-        UNSAFE.putShort(ptr + pos, val);
-    }
-
-    /** {@inheritDoc} */
-    @Override public void unsafeWriteChar(char val) {
-        if (!LITTLE_ENDIAN)
-            val = Character.reverseBytes(val);
-
-        UNSAFE.putChar(ptr + pos, val);
-
-        shift(2);
-    }
-
-    /** {@inheritDoc} */
-    @Override public void unsafeWriteInt(int val) {
-        if (!LITTLE_ENDIAN)
-            val = Integer.reverseBytes(val);
-
-        UNSAFE.putInt(ptr + pos, val);
-
-        shift(4);
-    }
-
-    /** {@inheritDoc} */
-    @Override public void unsafeWriteInt(int pos, int val) {
-        if (!LITTLE_ENDIAN)
-            val = Integer.reverseBytes(val);
-
-        UNSAFE.putInt(ptr + pos, val);
-    }
-
-    /** {@inheritDoc} */
-    @Override public void unsafeWriteLong(long val) {
-        if (!LITTLE_ENDIAN)
-            val = Long.reverseBytes(val);
-
-        UNSAFE.putLong(ptr + pos, val);
-
-        shift(8);
-    }
-
-    /**
-     * Allocate memory.
-     *
-     * @param cap Capacity.
-     * @return Pointer.
-     */
-    protected long allocate(int cap) {
-        return UNSAFE.allocateMemory(cap);
-    }
-
-    /**
-     * Reallocate memory.
-     *
-     * @param ptr Old pointer.
-     * @param cap Capacity.
-     * @return New pointer.
-     */
-    protected long reallocate(long ptr, int cap) {
-        return UNSAFE.reallocateMemory(ptr, cap);
-    }
-
-    /**
-     * Release memory.
-     *
-     * @param ptr Pointer.
-     */
-    protected void release(long ptr) {
-        UNSAFE.freeMemory(ptr);
-    }
-}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ignite/blob/1dbf20e0/modules/core/src/main/java/org/apache/ignite/internal/portable/streams/PortableOutputStream.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/portable/streams/PortableOutputStream.java b/modules/core/src/main/java/org/apache/ignite/internal/portable/streams/PortableOutputStream.java
deleted file mode 100644
index e516ff5..0000000
--- a/modules/core/src/main/java/org/apache/ignite/internal/portable/streams/PortableOutputStream.java
+++ /dev/null
@@ -1,259 +0,0 @@
-/*
- * 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.portable.streams;
-
-/**
- * Portable output stream.
- */
-public interface PortableOutputStream extends PortableStream, AutoCloseable {
-    /**
-     * Write byte value.
-     *
-     * @param val Byte value.
-     */
-    public void writeByte(byte val);
-
-    /**
-     * Write byte array.
-     *
-     * @param val Byte array.
-     */
-    public void writeByteArray(byte[] val);
-
-    /**
-     * Write boolean value.
-     *
-     * @param val Boolean value.
-     */
-    public void writeBoolean(boolean val);
-
-    /**
-     * Write boolean array.
-     *
-     * @param val Boolean array.
-     */
-    public void writeBooleanArray(boolean[] val);
-
-    /**
-     * Write short value.
-     *
-     * @param val Short value.
-     */
-    public void writeShort(short val);
-
-    /**
-     * Write short array.
-     *
-     * @param val Short array.
-     */
-    public void writeShortArray(short[] val);
-
-    /**
-     * Write char value.
-     *
-     * @param val Char value.
-     */
-    public void writeChar(char val);
-
-    /**
-     * Write char array.
-     *
-     * @param val Char array.
-     */
-    public void writeCharArray(char[] val);
-
-    /**
-     * Write int value.
-     *
-     * @param val Int value.
-     */
-    public void writeInt(int val);
-
-    /**
-     * Write short value at the given position.
-     *
-     * @param pos Position.
-     * @param val Value.
-     */
-    public void writeShort(int pos, short val);
-
-    /**
-     * Write int value to the given position.
-     *
-     * @param pos Position.
-     * @param val Value.
-     */
-    public void writeInt(int pos, int val);
-
-    /**
-     * Write int array.
-     *
-     * @param val Int array.
-     */
-    public void writeIntArray(int[] val);
-
-    /**
-     * Write float value.
-     *
-     * @param val Float value.
-     */
-    public void writeFloat(float val);
-
-    /**
-     * Write float array.
-     *
-     * @param val Float array.
-     */
-    public void writeFloatArray(float[] val);
-
-    /**
-     * Write long value.
-     *
-     * @param val Long value.
-     */
-    public void writeLong(long val);
-
-    /**
-     * Write long array.
-     *
-     * @param val Long array.
-     */
-    public void writeLongArray(long[] val);
-
-    /**
-     * Write double value.
-     *
-     * @param val Double value.
-     */
-    public void writeDouble(double val);
-
-    /**
-     * Write double array.
-     *
-     * @param val Double array.
-     */
-    public void writeDoubleArray(double[] val);
-
-    /**
-     * Write byte array.
-     *
-     * @param arr Array.
-     * @param off Offset.
-     * @param len Length.
-     */
-    public void write(byte[] arr, int off, int len);
-
-    /**
-     * Write data from unmanaged memory.
-     *
-     * @param addr Address.
-     * @param cnt Count.
-     */
-    public void write(long addr, int cnt);
-
-    /**
-     * Close the stream releasing resources.
-     */
-    @Override public void close();
-
-    /**
-     * Set position in unsafe mode.
-     *
-     * @param pos Position.
-     */
-    public void unsafePosition(int pos);
-
-    /**
-     * Ensure capacity for unsafe writes.
-     *
-     * @param cap Capacity.
-     */
-    public void unsafeEnsure(int cap);
-
-    /**
-     * Write byte in unsafe mode.
-     *
-     * @param val Value.
-     */
-    public void unsafeWriteByte(byte val);
-
-    /**
-     * Write boolean in unsafe mode.
-     *
-     * @param val Value.
-     */
-    public void unsafeWriteBoolean(boolean val);
-
-    /**
-     * Write short in unsafe mode.
-     *
-     * @param val Value.
-     */
-    public void unsafeWriteShort(short val);
-
-    /**
-     * Write short in unsafe mode.
-     *
-     * @param pos Position.
-     * @param val Value.
-     */
-    public void unsafeWriteShort(int pos, short val);
-
-    /**
-     * Write char in unsafe mode.
-     *
-     * @param val Value.
-     */
-    public void unsafeWriteChar(char val);
-
-    /**
-     * Write int in unsafe mode.
-     *
-     * @param val Value.
-     */
-    public void unsafeWriteInt(int val);
-
-    /**
-     * Write int in unsafe mode.
-     *
-     * @param pos Position.
-     * @param val Value.
-     */
-    public void unsafeWriteInt(int pos, int val);
-
-    /**
-     * Write long in unsafe mode.
-     *
-     * @param val Value.
-     */
-    public void unsafeWriteLong(long val);
-
-    /**
-     * Write float in unsafe mode.
-     *
-     * @param val Value.
-     */
-    public void unsafeWriteFloat(float val);
-
-    /**
-     * Write double in unsafe mode.
-     *
-     * @param val Value.
-     */
-    public void unsafeWriteDouble(double val);
-}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ignite/blob/1dbf20e0/modules/core/src/main/java/org/apache/ignite/internal/portable/streams/PortableStream.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/portable/streams/PortableStream.java b/modules/core/src/main/java/org/apache/ignite/internal/portable/streams/PortableStream.java
deleted file mode 100644
index bdc39f9..0000000
--- a/modules/core/src/main/java/org/apache/ignite/internal/portable/streams/PortableStream.java
+++ /dev/null
@@ -1,53 +0,0 @@
-/*
- * 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.portable.streams;
-
-/**
- * Portable stream.
- */
-public interface PortableStream {
-    /**
-     * @return Position.
-     */
-    public int position();
-
-    /**
-     * @param pos Position.
-     */
-    public void position(int pos);
-
-    /**
-     * @return Underlying array.
-     */
-    public byte[] array();
-
-    /**
-     * @return Copy of data in the stream.
-     */
-    public byte[] arrayCopy();
-
-    /**
-     * @return Offheap pointer if stream is offheap based, otherwise {@code 0}.
-     */
-    public long offheapPointer();
-
-    /**
-     * @return {@code True} is stream is array based.
-     */
-    public boolean hasArray();
-}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ignite/blob/1dbf20e0/modules/core/src/main/java/org/apache/ignite/internal/portable/streams/package-info.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/portable/streams/package-info.java b/modules/core/src/main/java/org/apache/ignite/internal/portable/streams/package-info.java
deleted file mode 100644
index 1d39a70..0000000
--- a/modules/core/src/main/java/org/apache/ignite/internal/portable/streams/package-info.java
+++ /dev/null
@@ -1,22 +0,0 @@
-/*
- * 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 description. -->
- * Contains portable APIs implementation for streams.
- */
-package org.apache.ignite.internal.portable.streams;
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ignite/blob/1dbf20e0/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheDefaultBinaryAffinityKeyMapper.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheDefaultBinaryAffinityKeyMapper.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheDefaultBinaryAffinityKeyMapper.java
index 828e2ff..4f9c188 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheDefaultBinaryAffinityKeyMapper.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheDefaultBinaryAffinityKeyMapper.java
@@ -21,7 +21,7 @@ import org.apache.ignite.Ignite;
 import org.apache.ignite.IgniteException;
 import org.apache.ignite.binary.BinaryObject;
 import org.apache.ignite.internal.IgniteKernal;
-import org.apache.ignite.internal.processors.cache.portable.CacheObjectBinaryProcessorImpl;
+import org.apache.ignite.internal.processors.cache.binary.CacheObjectBinaryProcessorImpl;
 import org.apache.ignite.internal.util.typedef.internal.U;
 
 /**
@@ -59,4 +59,4 @@ public class CacheDefaultBinaryAffinityKeyMapper extends GridCacheDefaultAffinit
             proc = (CacheObjectBinaryProcessorImpl)kernal.context().cacheObjects();
         }
     }
-}
\ No newline at end of file
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/1dbf20e0/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheObjectContext.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheObjectContext.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheObjectContext.java
index fe650f3..6c6c0d2 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheObjectContext.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/CacheObjectContext.java
@@ -23,7 +23,7 @@ import java.util.Map;
 import java.util.Set;
 import org.apache.ignite.cache.affinity.AffinityKeyMapper;
 import org.apache.ignite.internal.GridKernalContext;
-import org.apache.ignite.internal.portable.PortableUtils;
+import org.apache.ignite.internal.binary.PortableUtils;
 import org.apache.ignite.internal.processors.cacheobject.IgniteCacheObjectProcessor;
 import org.apache.ignite.internal.util.typedef.F;
 

http://git-wip-us.apache.org/repos/asf/ignite/blob/1dbf20e0/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheContext.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheContext.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheContext.java
index 07f6b9a..6645d8a 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheContext.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheContext.java
@@ -54,7 +54,7 @@ import org.apache.ignite.internal.managers.deployment.GridDeploymentManager;
 import org.apache.ignite.internal.managers.discovery.GridDiscoveryManager;
 import org.apache.ignite.internal.managers.eventstorage.GridEventStorageManager;
 import org.apache.ignite.internal.managers.swapspace.GridSwapSpaceManager;
-import org.apache.ignite.internal.portable.BinaryMarshaller;
+import org.apache.ignite.internal.binary.BinaryMarshaller;
 import org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion;
 import org.apache.ignite.internal.processors.cache.datastructures.CacheDataStructuresManager;
 import org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtCacheAdapter;

http://git-wip-us.apache.org/repos/asf/ignite/blob/1dbf20e0/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheProcessor.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheProcessor.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheProcessor.java
index 84b9960..1bbef62 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheProcessor.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheProcessor.java
@@ -70,7 +70,7 @@ import org.apache.ignite.internal.IgniteInternalFuture;
 import org.apache.ignite.internal.IgniteNodeAttributes;
 import org.apache.ignite.internal.IgniteTransactionsEx;
 import org.apache.ignite.internal.managers.discovery.CustomEventListener;
-import org.apache.ignite.internal.portable.BinaryMarshaller;
+import org.apache.ignite.internal.binary.BinaryMarshaller;
 import org.apache.ignite.internal.processors.GridProcessorAdapter;
 import org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion;
 import org.apache.ignite.internal.processors.cache.datastructures.CacheDataStructuresManager;


[28/59] [abbrv] ignite git commit: ignite-2065: rename "portable" packages to "binary"

Posted by ak...@apache.org.
http://git-wip-us.apache.org/repos/asf/ignite/blob/1dbf20e0/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryWriterExImpl.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryWriterExImpl.java b/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryWriterExImpl.java
new file mode 100644
index 0000000..25f4d70
--- /dev/null
+++ b/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryWriterExImpl.java
@@ -0,0 +1,1808 @@
+/*
+ * 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.binary;
+
+import org.apache.ignite.IgniteCheckedException;
+import org.apache.ignite.binary.BinaryIdMapper;
+import org.apache.ignite.binary.BinaryObjectException;
+import org.apache.ignite.binary.BinaryRawWriter;
+import org.apache.ignite.binary.BinaryWriter;
+import org.apache.ignite.internal.binary.streams.PortableOutputStream;
+import org.apache.ignite.internal.binary.streams.PortableHeapOutputStream;
+import org.apache.ignite.internal.binary.streams.PortableOutputStream;
+import org.apache.ignite.internal.util.typedef.internal.A;
+import org.jetbrains.annotations.Nullable;
+
+import java.io.IOException;
+import java.io.ObjectOutput;
+import java.lang.reflect.InvocationTargetException;
+import java.math.BigDecimal;
+import java.math.BigInteger;
+import java.sql.Timestamp;
+import java.util.Collection;
+import java.util.Date;
+import java.util.Map;
+import java.util.UUID;
+
+import static java.nio.charset.StandardCharsets.UTF_8;
+import static org.apache.ignite.internal.binary.GridPortableMarshaller.BOOLEAN;
+import static org.apache.ignite.internal.binary.GridPortableMarshaller.BOOLEAN_ARR;
+import static org.apache.ignite.internal.binary.GridPortableMarshaller.BYTE;
+import static org.apache.ignite.internal.binary.GridPortableMarshaller.BYTE_ARR;
+import static org.apache.ignite.internal.binary.GridPortableMarshaller.CHAR;
+import static org.apache.ignite.internal.binary.GridPortableMarshaller.CHAR_ARR;
+import static org.apache.ignite.internal.binary.GridPortableMarshaller.CLASS;
+import static org.apache.ignite.internal.binary.GridPortableMarshaller.COL;
+import static org.apache.ignite.internal.binary.GridPortableMarshaller.DATE;
+import static org.apache.ignite.internal.binary.GridPortableMarshaller.DATE_ARR;
+import static org.apache.ignite.internal.binary.GridPortableMarshaller.DECIMAL;
+import static org.apache.ignite.internal.binary.GridPortableMarshaller.DECIMAL_ARR;
+import static org.apache.ignite.internal.binary.GridPortableMarshaller.DFLT_HDR_LEN;
+import static org.apache.ignite.internal.binary.GridPortableMarshaller.DOUBLE;
+import static org.apache.ignite.internal.binary.GridPortableMarshaller.DOUBLE_ARR;
+import static org.apache.ignite.internal.binary.GridPortableMarshaller.ENUM;
+import static org.apache.ignite.internal.binary.GridPortableMarshaller.ENUM_ARR;
+import static org.apache.ignite.internal.binary.GridPortableMarshaller.FLOAT;
+import static org.apache.ignite.internal.binary.GridPortableMarshaller.FLOAT_ARR;
+import static org.apache.ignite.internal.binary.GridPortableMarshaller.INT;
+import static org.apache.ignite.internal.binary.GridPortableMarshaller.INT_ARR;
+import static org.apache.ignite.internal.binary.GridPortableMarshaller.LONG;
+import static org.apache.ignite.internal.binary.GridPortableMarshaller.LONG_ARR;
+import static org.apache.ignite.internal.binary.GridPortableMarshaller.MAP;
+import static org.apache.ignite.internal.binary.GridPortableMarshaller.NULL;
+import static org.apache.ignite.internal.binary.GridPortableMarshaller.OBJ;
+import static org.apache.ignite.internal.binary.GridPortableMarshaller.OBJ_ARR;
+import static org.apache.ignite.internal.binary.GridPortableMarshaller.OPTM_MARSH;
+import static org.apache.ignite.internal.binary.GridPortableMarshaller.PORTABLE_OBJ;
+import static org.apache.ignite.internal.binary.GridPortableMarshaller.PROTO_VER;
+import static org.apache.ignite.internal.binary.GridPortableMarshaller.SHORT;
+import static org.apache.ignite.internal.binary.GridPortableMarshaller.SHORT_ARR;
+import static org.apache.ignite.internal.binary.GridPortableMarshaller.STRING;
+import static org.apache.ignite.internal.binary.GridPortableMarshaller.STRING_ARR;
+import static org.apache.ignite.internal.binary.GridPortableMarshaller.TIMESTAMP;
+import static org.apache.ignite.internal.binary.GridPortableMarshaller.TIMESTAMP_ARR;
+import static org.apache.ignite.internal.binary.GridPortableMarshaller.UNREGISTERED_TYPE_ID;
+import static org.apache.ignite.internal.binary.GridPortableMarshaller.UUID;
+import static org.apache.ignite.internal.binary.GridPortableMarshaller.UUID_ARR;
+
+/**
+ * Portable writer implementation.
+ */
+public class BinaryWriterExImpl implements BinaryWriter, BinaryRawWriterEx, ObjectOutput {
+    /** Length: integer. */
+    private static final int LEN_INT = 4;
+
+    /** Initial capacity. */
+    private static final int INIT_CAP = 1024;
+
+    /** */
+    private final PortableContext ctx;
+
+    /** Output stream. */
+    private final PortableOutputStream out;
+
+    /** Schema. */
+    private final BinaryWriterSchemaHolder schema;
+
+    /** */
+    private int typeId;
+
+    /** */
+    private final int start;
+
+    /** Raw offset position. */
+    private int rawOffPos;
+
+    /** Handles. */
+    private BinaryWriterHandles handles;
+
+    /** Schema ID. */
+    private int schemaId = PortableUtils.schemaInitialId();
+
+    /** Amount of written fields. */
+    private int fieldCnt;
+
+    /** ID mapper. */
+    private BinaryIdMapper idMapper;
+
+    /**
+     * @param ctx Context.
+     */
+    public BinaryWriterExImpl(PortableContext ctx) {
+        this(ctx, BinaryThreadLocalContext.get());
+    }
+
+    /**
+     * @param ctx Context.
+     * @param tlsCtx TLS context.
+     */
+    public BinaryWriterExImpl(PortableContext ctx, BinaryThreadLocalContext tlsCtx) {
+        this(ctx, new PortableHeapOutputStream(INIT_CAP, tlsCtx.chunk()), tlsCtx.schemaHolder(), null);
+    }
+
+    /**
+     * @param ctx Context.
+     * @param out Output stream.
+     * @param handles Handles.
+     */
+    public BinaryWriterExImpl(PortableContext ctx, PortableOutputStream out, BinaryWriterSchemaHolder schema,
+        BinaryWriterHandles handles) {
+        this.ctx = ctx;
+        this.out = out;
+        this.schema = schema;
+        this.handles = handles;
+
+        start = out.position();
+    }
+
+    /**
+     * @param typeId Type ID.
+     */
+    public void typeId(int typeId) {
+        this.typeId = typeId;
+    }
+
+    /**
+     * Close the writer releasing resources if necessary.
+     */
+    @Override public void close() {
+        out.close();
+    }
+
+    /**
+     * @param obj Object.
+     * @throws org.apache.ignite.binary.BinaryObjectException In case of error.
+     */
+    void marshal(Object obj) throws BinaryObjectException {
+        marshal(obj, true);
+    }
+
+    /**
+     * @param obj Object.
+     * @param enableReplace Object replacing enabled flag.
+     * @throws org.apache.ignite.binary.BinaryObjectException In case of error.
+     */
+    void marshal(Object obj, boolean enableReplace) throws BinaryObjectException {
+        assert obj != null;
+
+        Class<?> cls = obj.getClass();
+
+        PortableClassDescriptor desc = ctx.descriptorForClass(cls, false);
+
+        if (desc == null)
+            throw new BinaryObjectException("Object is not portable: [class=" + cls + ']');
+
+        if (desc.excluded()) {
+            out.writeByte(GridPortableMarshaller.NULL);
+
+            return;
+        }
+
+        if (desc.useOptimizedMarshaller()) {
+            out.writeByte(GridPortableMarshaller.OPTM_MARSH);
+
+            try {
+                byte[] arr = ctx.optimizedMarsh().marshal(obj);
+
+                writeInt(arr.length);
+
+                write(arr);
+            }
+            catch (IgniteCheckedException e) {
+                throw new BinaryObjectException("Failed to marshal object with optimized marshaller: " + obj, e);
+            }
+
+            return;
+        }
+
+        if (enableReplace && desc.getWriteReplaceMethod() != null) {
+            Object replacedObj;
+
+            try {
+                replacedObj = desc.getWriteReplaceMethod().invoke(obj);
+            }
+            catch (IllegalAccessException e) {
+                throw new RuntimeException(e);
+            }
+            catch (InvocationTargetException e) {
+                if (e.getTargetException() instanceof BinaryObjectException)
+                    throw (BinaryObjectException)e.getTargetException();
+
+                throw new BinaryObjectException("Failed to execute writeReplace() method on " + obj, e);
+            }
+
+            if (replacedObj == null) {
+                out.writeByte(GridPortableMarshaller.NULL);
+
+                return;
+            }
+
+            marshal(replacedObj, false);
+
+            return;
+        }
+
+        desc.write(obj, this);
+    }
+
+    /**
+     * @return Array.
+     */
+    public byte[] array() {
+        return out.arrayCopy();
+    }
+
+    /**
+     * @return Stream current position.
+     */
+    int position() {
+        return out.position();
+    }
+
+    /**
+     * Sets new position.
+     *
+     * @param pos Position.
+     */
+    void position(int pos) {
+        out.position(pos);
+    }
+
+    /**
+     * Perform pre-write. Reserves space for header and writes class name if needed.
+     *
+     * @param clsName Class name (optional).
+     */
+    public void preWrite(@Nullable String clsName) {
+        out.position(out.position() + GridPortableMarshaller.DFLT_HDR_LEN);
+
+        if (clsName != null)
+            doWriteString(clsName);
+    }
+
+    /**
+     * Perform post-write. Fills object header.
+     *
+     * @param userType User type flag.
+     * @param registered Whether type is registered.
+     * @param hashCode Hash code.
+     */
+    public void postWrite(boolean userType, boolean registered, int hashCode) {
+        short flags;
+        boolean useCompactFooter;
+
+        if (userType) {
+            if (ctx.isCompactFooter()) {
+                flags = PortableUtils.FLAG_USR_TYP | PortableUtils.FLAG_COMPACT_FOOTER;
+                useCompactFooter = true;
+            }
+            else {
+                flags = PortableUtils.FLAG_USR_TYP;
+                useCompactFooter = false;
+            }
+        }
+        else {
+            flags = 0;
+            useCompactFooter = false;
+        }
+
+        int finalSchemaId;
+        int offset;
+
+        if (fieldCnt != 0) {
+            finalSchemaId = schemaId;
+            offset = out.position() - start;
+
+            // Write the schema.
+            flags |= PortableUtils.FLAG_HAS_SCHEMA;
+
+            int offsetByteCnt = schema.write(out, fieldCnt, useCompactFooter);
+
+            if (offsetByteCnt == PortableUtils.OFFSET_1)
+                flags |= PortableUtils.FLAG_OFFSET_ONE_BYTE;
+            else if (offsetByteCnt == PortableUtils.OFFSET_2)
+                flags |= PortableUtils.FLAG_OFFSET_TWO_BYTES;
+
+            // Write raw offset if needed.
+            if (rawOffPos != 0) {
+                flags |= PortableUtils.FLAG_HAS_RAW;
+
+                out.writeInt(rawOffPos - start);
+            }
+        }
+        else {
+            if (rawOffPos != 0) {
+                finalSchemaId = 0;
+                offset = rawOffPos - start;
+
+                // If there is no schema, we are free to write raw offset to schema offset.
+                flags |= PortableUtils.FLAG_HAS_RAW;
+            }
+            else {
+                finalSchemaId = 0;
+                offset = 0;
+            }
+        }
+
+        // Actual write.
+        int retPos = out.position();
+
+        out.unsafePosition(start);
+
+        out.unsafeWriteByte(GridPortableMarshaller.OBJ);
+        out.unsafeWriteByte(GridPortableMarshaller.PROTO_VER);
+        out.unsafeWriteShort(flags);
+        out.unsafeWriteInt(registered ? typeId : GridPortableMarshaller.UNREGISTERED_TYPE_ID);
+        out.unsafeWriteInt(hashCode);
+        out.unsafeWriteInt(retPos - start);
+        out.unsafeWriteInt(finalSchemaId);
+        out.unsafeWriteInt(offset);
+
+        out.unsafePosition(retPos);
+    }
+
+    /**
+     * Pop schema.
+     */
+    public void popSchema() {
+        if (fieldCnt > 0)
+            schema.pop(fieldCnt);
+    }
+
+    /**
+     * @param val Byte array.
+     */
+    public void write(byte[] val) {
+        assert val != null;
+
+        out.writeByteArray(val);
+    }
+
+    /**
+     * @param val Byte array.
+     * @param off Offset.
+     * @param len Length.
+     */
+    public void write(byte[] val, int off, int len) {
+        assert val != null;
+
+        out.write(val, off, len);
+    }
+
+    /**
+     * @param val String value.
+     */
+    public void doWriteDecimal(@Nullable BigDecimal val) {
+        if (val == null)
+            out.writeByte(GridPortableMarshaller.NULL);
+        else {
+            out.unsafeEnsure(1 + 4 + 4);
+
+            out.unsafeWriteByte(GridPortableMarshaller.DECIMAL);
+
+            BigInteger intVal = val.unscaledValue();
+
+            if (intVal.signum() == -1) {
+                intVal = intVal.negate();
+
+                out.unsafeWriteInt(val.scale() | 0x80000000);
+            }
+            else
+                out.unsafeWriteInt(val.scale());
+
+            byte[] vals = intVal.toByteArray();
+
+            out.unsafeWriteInt(vals.length);
+            out.writeByteArray(vals);
+        }
+    }
+
+    /**
+     * @param val String value.
+     */
+    public void doWriteString(@Nullable String val) {
+        if (val == null)
+            out.writeByte(GridPortableMarshaller.NULL);
+        else {
+            byte[] strArr = val.getBytes(UTF_8);
+
+            out.unsafeEnsure(1 + 4);
+            out.unsafeWriteByte(GridPortableMarshaller.STRING);
+            out.unsafeWriteInt(strArr.length);
+
+            out.writeByteArray(strArr);
+        }
+    }
+
+    /**
+     * @param uuid UUID.
+     */
+    public void doWriteUuid(@Nullable UUID uuid) {
+        if (uuid == null)
+            out.writeByte(GridPortableMarshaller.NULL);
+        else {
+            out.unsafeEnsure(1 + 8 + 8);
+            out.unsafeWriteByte(GridPortableMarshaller.UUID);
+            out.unsafeWriteLong(uuid.getMostSignificantBits());
+            out.unsafeWriteLong(uuid.getLeastSignificantBits());
+        }
+    }
+
+    /**
+     * @param date Date.
+     */
+    public void doWriteDate(@Nullable Date date) {
+        if (date == null)
+            out.writeByte(GridPortableMarshaller.NULL);
+        else {
+            out.unsafeEnsure(1 + 8);
+            out.unsafeWriteByte(GridPortableMarshaller.DATE);
+            out.unsafeWriteLong(date.getTime());
+        }
+    }
+
+    /**
+     * @param ts Timestamp.
+     */
+    public void doWriteTimestamp(@Nullable Timestamp ts) {
+        if (ts== null)
+            out.writeByte(GridPortableMarshaller.NULL);
+        else {
+            out.unsafeEnsure(1 + 8 + 4);
+            out.unsafeWriteByte(GridPortableMarshaller.TIMESTAMP);
+            out.unsafeWriteLong(ts.getTime());
+            out.unsafeWriteInt(ts.getNanos() % 1000000);
+        }
+    }
+
+    /**
+     * Write object.
+     *
+     * @param obj Object.
+     * @throws org.apache.ignite.binary.BinaryObjectException In case of error.
+     */
+    public void doWriteObject(@Nullable Object obj) throws BinaryObjectException {
+        if (obj == null)
+            out.writeByte(GridPortableMarshaller.NULL);
+        else {
+            BinaryWriterExImpl writer = new BinaryWriterExImpl(ctx, out, schema, handles());
+
+            writer.marshal(obj);
+        }
+    }
+
+    /**
+     * @param val Byte array.
+     */
+    void doWriteByteArray(@Nullable byte[] val) {
+        if (val == null)
+            out.writeByte(GridPortableMarshaller.NULL);
+        else {
+            out.unsafeEnsure(1 + 4);
+            out.unsafeWriteByte(GridPortableMarshaller.BYTE_ARR);
+            out.unsafeWriteInt(val.length);
+
+            out.writeByteArray(val);
+        }
+    }
+
+    /**
+     * @param val Short array.
+     */
+    void doWriteShortArray(@Nullable short[] val) {
+        if (val == null)
+            out.writeByte(GridPortableMarshaller.NULL);
+        else {
+            out.unsafeEnsure(1 + 4);
+            out.unsafeWriteByte(GridPortableMarshaller.SHORT_ARR);
+            out.unsafeWriteInt(val.length);
+
+            out.writeShortArray(val);
+        }
+    }
+
+    /**
+     * @param val Integer array.
+     */
+    void doWriteIntArray(@Nullable int[] val) {
+        if (val == null)
+            out.writeByte(GridPortableMarshaller.NULL);
+        else {
+            out.unsafeEnsure(1 + 4);
+            out.unsafeWriteByte(GridPortableMarshaller.INT_ARR);
+            out.unsafeWriteInt(val.length);
+
+            out.writeIntArray(val);
+        }
+    }
+
+    /**
+     * @param val Long array.
+     */
+    void doWriteLongArray(@Nullable long[] val) {
+        if (val == null)
+            out.writeByte(GridPortableMarshaller.NULL);
+        else {
+            out.unsafeEnsure(1 + 4);
+            out.unsafeWriteByte(GridPortableMarshaller.LONG_ARR);
+            out.unsafeWriteInt(val.length);
+
+            out.writeLongArray(val);
+        }
+    }
+
+    /**
+     * @param val Float array.
+     */
+    void doWriteFloatArray(@Nullable float[] val) {
+        if (val == null)
+            out.writeByte(GridPortableMarshaller.NULL);
+        else {
+            out.unsafeEnsure(1 + 4);
+            out.unsafeWriteByte(GridPortableMarshaller.FLOAT_ARR);
+            out.unsafeWriteInt(val.length);
+
+            out.writeFloatArray(val);
+        }
+    }
+
+    /**
+     * @param val Double array.
+     */
+    void doWriteDoubleArray(@Nullable double[] val) {
+        if (val == null)
+            out.writeByte(GridPortableMarshaller.NULL);
+        else {
+            out.unsafeEnsure(1 + 4);
+            out.unsafeWriteByte(GridPortableMarshaller.DOUBLE_ARR);
+            out.unsafeWriteInt(val.length);
+
+            out.writeDoubleArray(val);
+        }
+    }
+
+    /**
+     * @param val Char array.
+     */
+    void doWriteCharArray(@Nullable char[] val) {
+        if (val == null)
+            out.writeByte(GridPortableMarshaller.NULL);
+        else {
+            out.unsafeEnsure(1 + 4);
+            out.unsafeWriteByte(GridPortableMarshaller.CHAR_ARR);
+            out.unsafeWriteInt(val.length);
+
+            out.writeCharArray(val);
+        }
+    }
+
+    /**
+     * @param val Boolean array.
+     */
+    void doWriteBooleanArray(@Nullable boolean[] val) {
+        if (val == null)
+            out.writeByte(GridPortableMarshaller.NULL);
+        else {
+            out.unsafeEnsure(1 + 4);
+            out.unsafeWriteByte(GridPortableMarshaller.BOOLEAN_ARR);
+            out.unsafeWriteInt(val.length);
+
+            out.writeBooleanArray(val);
+        }
+    }
+
+    /**
+     * @param val Array of strings.
+     */
+    void doWriteDecimalArray(@Nullable BigDecimal[] val) {
+        if (val == null)
+            out.writeByte(GridPortableMarshaller.NULL);
+        else {
+            out.unsafeEnsure(1 + 4);
+            out.unsafeWriteByte(GridPortableMarshaller.DECIMAL_ARR);
+            out.unsafeWriteInt(val.length);
+
+            for (BigDecimal str : val)
+                doWriteDecimal(str);
+        }
+    }
+
+    /**
+     * @param val Array of strings.
+     */
+    void doWriteStringArray(@Nullable String[] val) {
+        if (val == null)
+            out.writeByte(GridPortableMarshaller.NULL);
+        else {
+            out.unsafeEnsure(1 + 4);
+            out.unsafeWriteByte(GridPortableMarshaller.STRING_ARR);
+            out.unsafeWriteInt(val.length);
+
+            for (String str : val)
+                doWriteString(str);
+        }
+    }
+
+    /**
+     * @param val Array of UUIDs.
+     */
+    void doWriteUuidArray(@Nullable UUID[] val) {
+        if (val == null)
+            out.writeByte(GridPortableMarshaller.NULL);
+        else {
+            out.unsafeEnsure(1 + 4);
+            out.unsafeWriteByte(GridPortableMarshaller.UUID_ARR);
+            out.unsafeWriteInt(val.length);
+
+            for (UUID uuid : val)
+                doWriteUuid(uuid);
+        }
+    }
+
+    /**
+     * @param val Array of dates.
+     */
+    void doWriteDateArray(@Nullable Date[] val) {
+        if (val == null)
+            out.writeByte(GridPortableMarshaller.NULL);
+        else {
+            out.unsafeEnsure(1 + 4);
+            out.unsafeWriteByte(GridPortableMarshaller.DATE_ARR);
+            out.unsafeWriteInt(val.length);
+
+            for (Date date : val)
+                doWriteDate(date);
+        }
+    }
+
+     /**
+      * @param val Array of timestamps.
+      */
+     void doWriteTimestampArray(@Nullable Timestamp[] val) {
+         if (val == null)
+             out.writeByte(GridPortableMarshaller.NULL);
+         else {
+             out.unsafeEnsure(1 + 4);
+             out.unsafeWriteByte(GridPortableMarshaller.TIMESTAMP_ARR);
+             out.unsafeWriteInt(val.length);
+
+             for (Timestamp ts : val)
+                 doWriteTimestamp(ts);
+         }
+     }
+
+    /**
+     * @param val Array of objects.
+     * @throws org.apache.ignite.binary.BinaryObjectException In case of error.
+     */
+    void doWriteObjectArray(@Nullable Object[] val) throws BinaryObjectException {
+        if (val == null)
+            out.writeByte(GridPortableMarshaller.NULL);
+        else {
+            if (tryWriteAsHandle(val))
+                return;
+
+            PortableClassDescriptor desc = ctx.descriptorForClass(val.getClass().getComponentType(), false);
+
+            out.unsafeEnsure(1 + 4);
+            out.unsafeWriteByte(GridPortableMarshaller.OBJ_ARR);
+
+            if (desc.registered())
+                out.unsafeWriteInt(desc.typeId());
+            else {
+                out.unsafeWriteInt(GridPortableMarshaller.UNREGISTERED_TYPE_ID);
+
+                doWriteString(val.getClass().getComponentType().getName());
+            }
+
+            out.writeInt(val.length);
+
+            for (Object obj : val)
+                doWriteObject(obj);
+        }
+    }
+
+    /**
+     * @param col Collection.
+     * @throws org.apache.ignite.binary.BinaryObjectException In case of error.
+     */
+    void doWriteCollection(@Nullable Collection<?> col) throws BinaryObjectException {
+        if (col == null)
+            out.writeByte(GridPortableMarshaller.NULL);
+        else {
+            if (tryWriteAsHandle(col))
+                return;
+
+            out.unsafeEnsure(1 + 4 + 1);
+            out.unsafeWriteByte(GridPortableMarshaller.COL);
+            out.unsafeWriteInt(col.size());
+            out.unsafeWriteByte(ctx.collectionType(col.getClass()));
+
+            for (Object obj : col)
+                doWriteObject(obj);
+        }
+    }
+
+    /**
+     * @param map Map.
+     * @throws org.apache.ignite.binary.BinaryObjectException In case of error.
+     */
+    void doWriteMap(@Nullable Map<?, ?> map) throws BinaryObjectException {
+        if (map == null)
+            out.writeByte(GridPortableMarshaller.NULL);
+        else {
+            if (tryWriteAsHandle(map))
+                return;
+
+            out.unsafeEnsure(1 + 4 + 1);
+            out.unsafeWriteByte(GridPortableMarshaller.MAP);
+            out.unsafeWriteInt(map.size());
+            out.unsafeWriteByte(ctx.mapType(map.getClass()));
+
+            for (Map.Entry<?, ?> e : map.entrySet()) {
+                doWriteObject(e.getKey());
+                doWriteObject(e.getValue());
+            }
+        }
+    }
+
+    /**
+     * @param val Value.
+     */
+    void doWriteEnum(@Nullable Enum<?> val) {
+        if (val == null)
+            out.writeByte(GridPortableMarshaller.NULL);
+        else {
+            PortableClassDescriptor desc = ctx.descriptorForClass(val.getClass(), false);
+
+            out.unsafeEnsure(1 + 4);
+
+            out.unsafeWriteByte(GridPortableMarshaller.ENUM);
+
+            if (desc.registered())
+                out.unsafeWriteInt(desc.typeId());
+            else {
+                out.unsafeWriteInt(GridPortableMarshaller.UNREGISTERED_TYPE_ID);
+                doWriteString(val.getClass().getName());
+            }
+
+            out.writeInt(val.ordinal());
+        }
+    }
+
+    /**
+     * @param val Value.
+     */
+    void doWritePortableEnum(BinaryEnumObjectImpl val) {
+        assert val != null;
+
+        int typeId = val.typeId();
+
+        out.unsafeEnsure(1 + 4);
+
+        out.unsafeWriteByte(GridPortableMarshaller.ENUM);
+        out.unsafeWriteInt(typeId);
+
+        if (typeId == GridPortableMarshaller.UNREGISTERED_TYPE_ID)
+            doWriteString(val.className());
+
+        out.writeInt(val.enumOrdinal());
+    }
+
+    /**
+     * @param val Array.
+     */
+    void doWriteEnumArray(@Nullable Object[] val) {
+        assert val == null || val.getClass().getComponentType().isEnum();
+
+        if (val == null)
+            out.writeByte(GridPortableMarshaller.NULL);
+        else {
+            PortableClassDescriptor desc = ctx.descriptorForClass(val.getClass().getComponentType(), false);
+
+            out.unsafeEnsure(1 + 4);
+
+            out.unsafeWriteByte(GridPortableMarshaller.ENUM_ARR);
+
+            if (desc.registered())
+                out.unsafeWriteInt(desc.typeId());
+            else {
+                out.unsafeWriteInt(GridPortableMarshaller.UNREGISTERED_TYPE_ID);
+
+                doWriteString(val.getClass().getComponentType().getName());
+            }
+
+            out.writeInt(val.length);
+
+            // TODO: Denis: Redundant data for each element of the array.
+            for (Object o : val)
+                doWriteEnum((Enum<?>)o);
+        }
+    }
+
+    /**
+     * @param val Class.
+     */
+    void doWriteClass(@Nullable Class val) {
+        if (val == null)
+            out.writeByte(GridPortableMarshaller.NULL);
+        else {
+            PortableClassDescriptor desc = ctx.descriptorForClass(val, false);
+
+            out.unsafeEnsure(1 + 4);
+
+            out.unsafeWriteByte(GridPortableMarshaller.CLASS);
+
+            if (desc.registered())
+                out.unsafeWriteInt(desc.typeId());
+            else {
+                out.unsafeWriteInt(GridPortableMarshaller.UNREGISTERED_TYPE_ID);
+
+                doWriteString(val.getClass().getName());
+            }
+        }
+    }
+
+    /**
+     * @param po Portable object.
+     */
+    public void doWritePortableObject(@Nullable BinaryObjectImpl po) {
+        if (po == null)
+            out.writeByte(GridPortableMarshaller.NULL);
+        else {
+            byte[] poArr = po.array();
+
+            out.unsafeEnsure(1 + 4 + poArr.length + 4);
+
+            out.unsafeWriteByte(GridPortableMarshaller.PORTABLE_OBJ);
+            out.unsafeWriteInt(poArr.length);
+            out.writeByteArray(poArr);
+            out.unsafeWriteInt(po.start());
+        }
+    }
+
+    /**
+     * @param val Value.
+     */
+    void writeByteFieldPrimitive(byte val) {
+        out.unsafeEnsure(1 + 1);
+
+        out.unsafeWriteByte(GridPortableMarshaller.BYTE);
+        out.unsafeWriteByte(val);
+    }
+
+    /**
+     * @param val Value.
+     */
+    void writeByteField(@Nullable Byte val) {
+        if (val == null)
+            out.writeByte(GridPortableMarshaller.NULL);
+        else
+            writeByteFieldPrimitive(val);
+    }
+
+    /**
+     * @param val Class.
+     */
+    void writeClassField(@Nullable Class val) {
+        doWriteClass(val);
+    }
+
+    /**
+     * @param val Value.
+     */
+    void writeShortFieldPrimitive(short val) {
+        out.unsafeEnsure(1 + 2);
+
+        out.unsafeWriteByte(GridPortableMarshaller.SHORT);
+        out.unsafeWriteShort(val);
+    }
+
+    /**
+     * @param val Value.
+     */
+    void writeShortField(@Nullable Short val) {
+        if (val == null)
+            out.writeByte(GridPortableMarshaller.NULL);
+        else
+            writeShortFieldPrimitive(val);
+    }
+
+    /**
+     * @param val Value.
+     */
+    void writeIntFieldPrimitive(int val) {
+        out.unsafeEnsure(1 + 4);
+
+        out.unsafeWriteByte(GridPortableMarshaller.INT);
+        out.unsafeWriteInt(val);
+    }
+
+    /**
+     * @param val Value.
+     */
+    void writeIntField(@Nullable Integer val) {
+        if (val == null)
+            out.writeByte(GridPortableMarshaller.NULL);
+        else
+            writeIntFieldPrimitive(val);
+    }
+
+    /**
+     * @param val Value.
+     */
+    void writeLongFieldPrimitive(long val) {
+        out.unsafeEnsure(1 + 8);
+
+        out.unsafeWriteByte(GridPortableMarshaller.LONG);
+        out.unsafeWriteLong(val);
+    }
+
+    /**
+     * @param val Value.
+     */
+    void writeLongField(@Nullable Long val) {
+        if (val == null)
+            out.writeByte(GridPortableMarshaller.NULL);
+        else
+            writeLongFieldPrimitive(val);
+    }
+
+    /**
+     * @param val Value.
+     */
+    void writeFloatFieldPrimitive(float val) {
+        out.unsafeEnsure(1 + 4);
+
+        out.unsafeWriteByte(GridPortableMarshaller.FLOAT);
+        out.unsafeWriteFloat(val);
+    }
+
+    /**
+     * @param val Value.
+     */
+    void writeFloatField(@Nullable Float val) {
+        if (val == null)
+            out.writeByte(GridPortableMarshaller.NULL);
+        else
+            writeFloatFieldPrimitive(val);
+    }
+
+    /**
+     * @param val Value.
+     */
+    void writeDoubleFieldPrimitive(double val) {
+        out.unsafeEnsure(1 + 8);
+
+        out.unsafeWriteByte(GridPortableMarshaller.DOUBLE);
+        out.unsafeWriteDouble(val);
+    }
+
+    /**
+     * @param val Value.
+     */
+    void writeDoubleField(@Nullable Double val) {
+        if (val == null)
+            out.writeByte(GridPortableMarshaller.NULL);
+        else
+            writeDoubleFieldPrimitive(val);
+    }
+
+    /**
+     * @param val Value.
+     */
+    void writeCharFieldPrimitive(char val) {
+        out.unsafeEnsure(1 + 2);
+
+        out.unsafeWriteByte(GridPortableMarshaller.CHAR);
+        out.unsafeWriteChar(val);
+    }
+
+    /**
+     * @param val Value.
+     */
+    void writeCharField(@Nullable Character val) {
+        if (val == null)
+            out.writeByte(GridPortableMarshaller.NULL);
+        else
+            writeCharFieldPrimitive(val);
+    }
+
+    /**
+     * @param val Value.
+     */
+    void writeBooleanFieldPrimitive(boolean val) {
+        out.unsafeEnsure(1 + 1);
+
+        out.unsafeWriteByte(GridPortableMarshaller.BOOLEAN);
+        out.unsafeWriteBoolean(val);
+    }
+
+    /**
+     * @param val Value.
+     */
+    void writeBooleanField(@Nullable Boolean val) {
+        if (val == null)
+            out.writeByte(GridPortableMarshaller.NULL);
+        else
+            writeBooleanFieldPrimitive(val);
+    }
+
+    /**
+     * @param val Value.
+     */
+    void writeDecimalField(@Nullable BigDecimal val) {
+        doWriteDecimal(val);
+    }
+
+    /**
+     * @param val Value.
+     */
+    void writeStringField(@Nullable String val) {
+        doWriteString(val);
+    }
+
+    /**
+     * @param val Value.
+     */
+    void writeUuidField(@Nullable UUID val) {
+        doWriteUuid(val);
+    }
+
+    /**
+     * @param val Value.
+     */
+    void writeDateField(@Nullable Date val) {
+        doWriteDate(val);
+    }
+
+    /**
+     * @param val Value.
+     */
+    void writeTimestampField(@Nullable Timestamp val) {
+        doWriteTimestamp(val);
+    }
+
+    /**
+     * @param obj Object.
+     * @throws org.apache.ignite.binary.BinaryObjectException In case of error.
+     */
+    void writeObjectField(@Nullable Object obj) throws BinaryObjectException {
+        doWriteObject(obj);
+    }
+
+    /**
+     * @param val Value.
+     */
+    void writeByteArrayField(@Nullable byte[] val) {
+        doWriteByteArray(val);
+    }
+
+    /**
+     * @param val Value.
+     */
+    void writeShortArrayField(@Nullable short[] val) {
+        doWriteShortArray(val);
+    }
+
+    /**
+     * @param val Value.
+     */
+    void writeIntArrayField(@Nullable int[] val) {
+        doWriteIntArray(val);
+    }
+
+    /**
+     * @param val Value.
+     */
+    void writeLongArrayField(@Nullable long[] val) {
+        doWriteLongArray(val);
+    }
+
+    /**
+     * @param val Value.
+     */
+    void writeFloatArrayField(@Nullable float[] val) {
+        doWriteFloatArray(val);
+    }
+
+    /**
+     * @param val Value.
+     */
+    void writeDoubleArrayField(@Nullable double[] val) {
+        doWriteDoubleArray(val);
+    }
+
+    /**
+     * @param val Value.
+     */
+    void writeCharArrayField(@Nullable char[] val) {
+        doWriteCharArray(val);
+    }
+
+    /**
+     * @param val Value.
+     */
+    void writeBooleanArrayField(@Nullable boolean[] val) {
+        doWriteBooleanArray(val);
+    }
+
+    /**
+     * @param val Value.
+     */
+    void writeDecimalArrayField(@Nullable BigDecimal[] val) {
+        doWriteDecimalArray(val);
+    }
+
+    /**
+     * @param val Value.
+     */
+    void writeStringArrayField(@Nullable String[] val) {
+        doWriteStringArray(val);
+    }
+
+    /**
+     * @param val Value.
+     */
+    void writeUuidArrayField(@Nullable UUID[] val) {
+        doWriteUuidArray(val);
+    }
+
+    /**
+     * @param val Value.
+     */
+    void writeDateArrayField(@Nullable Date[] val) {
+        doWriteDateArray(val);
+    }
+
+    /**
+     * @param val Value.
+     */
+    void writeTimestampArrayField(@Nullable Timestamp[] val) {
+        doWriteTimestampArray(val);
+    }
+
+    /**
+     * @param val Value.
+     * @throws org.apache.ignite.binary.BinaryObjectException In case of error.
+     */
+    void writeObjectArrayField(@Nullable Object[] val) throws BinaryObjectException {
+        doWriteObjectArray(val);
+    }
+
+    /**
+     * @param col Collection.
+     * @throws org.apache.ignite.binary.BinaryObjectException In case of error.
+     */
+    void writeCollectionField(@Nullable Collection<?> col) throws BinaryObjectException {
+        doWriteCollection(col);
+    }
+
+    /**
+     * @param map Map.
+     * @throws org.apache.ignite.binary.BinaryObjectException In case of error.
+     */
+    void writeMapField(@Nullable Map<?, ?> map) throws BinaryObjectException {
+        doWriteMap(map);
+    }
+
+    /**
+     * @param val Value.
+     */
+    void writeEnumField(@Nullable Enum<?> val) {
+        doWriteEnum(val);
+    }
+
+    /**
+     * @param val Value.
+     */
+    void writeEnumArrayField(@Nullable Object[] val) {
+        doWriteEnumArray(val);
+    }
+
+    /**
+     * @param po Portable object.
+     * @throws org.apache.ignite.binary.BinaryObjectException In case of error.
+     */
+    void writePortableObjectField(@Nullable BinaryObjectImpl po) throws BinaryObjectException {
+        doWritePortableObject(po);
+    }
+
+    /** {@inheritDoc} */
+    @Override public void writeByte(String fieldName, byte val) throws BinaryObjectException {
+        writeFieldId(fieldName);
+        writeByteField(val);
+    }
+
+    /** {@inheritDoc} */
+    @Override public void writeByte(byte val) throws BinaryObjectException {
+        out.writeByte(val);
+    }
+
+    /** {@inheritDoc} */
+    @Override public void writeShort(String fieldName, short val) throws BinaryObjectException {
+        writeFieldId(fieldName);
+        writeShortField(val);
+    }
+
+    /** {@inheritDoc} */
+    @Override public void writeShort(short val) throws BinaryObjectException {
+        out.writeShort(val);
+    }
+
+    /** {@inheritDoc} */
+    @Override public void writeInt(String fieldName, int val) throws BinaryObjectException {
+        writeFieldId(fieldName);
+        writeIntField(val);
+    }
+
+    /** {@inheritDoc} */
+    @Override public void writeInt(int val) throws BinaryObjectException {
+        out.writeInt(val);
+    }
+
+    /** {@inheritDoc} */
+    @Override public void writeLong(String fieldName, long val) throws BinaryObjectException {
+        writeFieldId(fieldName);
+        writeLongField(val);
+    }
+
+    /** {@inheritDoc} */
+    @Override public void writeLong(long val) throws BinaryObjectException {
+        out.writeLong(val);
+    }
+
+    /** {@inheritDoc} */
+    @Override public void writeFloat(String fieldName, float val) throws BinaryObjectException {
+        writeFieldId(fieldName);
+        writeFloatField(val);
+    }
+
+    /** {@inheritDoc} */
+    @Override public void writeFloat(float val) throws BinaryObjectException {
+        out.writeFloat(val);
+    }
+
+    /** {@inheritDoc} */
+    @Override public void writeDouble(String fieldName, double val) throws BinaryObjectException {
+        writeFieldId(fieldName);
+        writeDoubleField(val);
+    }
+
+    /** {@inheritDoc} */
+    @Override public void writeDouble(double val) throws BinaryObjectException {
+        out.writeDouble(val);
+    }
+
+    /** {@inheritDoc} */
+    @Override public void writeChar(String fieldName, char val) throws BinaryObjectException {
+        writeFieldId(fieldName);
+        writeCharField(val);
+    }
+
+    /** {@inheritDoc} */
+    @Override public void writeChar(char val) throws BinaryObjectException {
+        out.writeChar(val);
+    }
+
+    /** {@inheritDoc} */
+    @Override public void writeBoolean(String fieldName, boolean val) throws BinaryObjectException {
+        writeFieldId(fieldName);
+        writeBooleanField(val);
+    }
+
+    /** {@inheritDoc} */
+    @Override public void writeBoolean(boolean val) throws BinaryObjectException {
+        out.writeBoolean(val);
+    }
+
+    /** {@inheritDoc} */
+    @Override public void writeDecimal(String fieldName, @Nullable BigDecimal val) throws BinaryObjectException {
+        writeFieldId(fieldName);
+        writeDecimalField(val);
+    }
+
+    /** {@inheritDoc} */
+    @Override public void writeDecimal(@Nullable BigDecimal val) throws BinaryObjectException {
+        doWriteDecimal(val);
+    }
+
+    /** {@inheritDoc} */
+    @Override public void writeString(String fieldName, @Nullable String val) throws BinaryObjectException {
+        writeFieldId(fieldName);
+        writeStringField(val);
+    }
+
+    /** {@inheritDoc} */
+    @Override public void writeString(@Nullable String val) throws BinaryObjectException {
+        doWriteString(val);
+    }
+
+    /** {@inheritDoc} */
+    @Override public void writeUuid(String fieldName, @Nullable UUID val) throws BinaryObjectException {
+        writeFieldId(fieldName);
+        writeUuidField(val);
+    }
+
+    /** {@inheritDoc} */
+    @Override public void writeUuid(@Nullable UUID val) throws BinaryObjectException {
+        doWriteUuid(val);
+    }
+
+    /** {@inheritDoc} */
+    @Override public void writeDate(String fieldName, @Nullable Date val) throws BinaryObjectException {
+        writeFieldId(fieldName);
+        writeDateField(val);
+    }
+
+    /** {@inheritDoc} */
+    @Override public void writeDate(@Nullable Date val) throws BinaryObjectException {
+        doWriteDate(val);
+    }
+
+    /** {@inheritDoc} */
+    @Override public void writeTimestamp(String fieldName, @Nullable Timestamp val) throws BinaryObjectException {
+        writeFieldId(fieldName);
+        writeTimestampField(val);
+    }
+
+    /** {@inheritDoc} */
+    @Override public void writeTimestamp(@Nullable Timestamp val) throws BinaryObjectException {
+        doWriteTimestamp(val);
+    }
+
+    /** {@inheritDoc} */
+    @Override public void writeObject(String fieldName, @Nullable Object obj) throws BinaryObjectException {
+        writeFieldId(fieldName);
+        writeObjectField(obj);
+    }
+
+    /** {@inheritDoc} */
+    @Override public void writeObject(@Nullable Object obj) throws BinaryObjectException {
+        doWriteObject(obj);
+    }
+
+    /** {@inheritDoc} */
+    @Override public void writeObjectDetached(@Nullable Object obj) throws BinaryObjectException {
+        if (obj == null)
+            out.writeByte(GridPortableMarshaller.NULL);
+        else {
+            BinaryWriterExImpl writer = new BinaryWriterExImpl(ctx, out, schema, null);
+
+            writer.marshal(obj);
+        }
+    }
+
+    /** {@inheritDoc} */
+    @Override public void writeByteArray(String fieldName, @Nullable byte[] val) throws BinaryObjectException {
+        writeFieldId(fieldName);
+        writeByteArrayField(val);
+    }
+
+    /** {@inheritDoc} */
+    @Override public void writeByteArray(@Nullable byte[] val) throws BinaryObjectException {
+        doWriteByteArray(val);
+    }
+
+    /** {@inheritDoc} */
+    @Override public void writeShortArray(String fieldName, @Nullable short[] val) throws BinaryObjectException {
+        writeFieldId(fieldName);
+        writeShortArrayField(val);
+    }
+
+    /** {@inheritDoc} */
+    @Override public void writeShortArray(@Nullable short[] val) throws BinaryObjectException {
+        doWriteShortArray(val);
+    }
+
+    /** {@inheritDoc} */
+    @Override public void writeIntArray(String fieldName, @Nullable int[] val) throws BinaryObjectException {
+        writeFieldId(fieldName);
+        writeIntArrayField(val);
+    }
+
+    /** {@inheritDoc} */
+    @Override public void writeIntArray(@Nullable int[] val) throws BinaryObjectException {
+        doWriteIntArray(val);
+    }
+
+    /** {@inheritDoc} */
+    @Override public void writeLongArray(String fieldName, @Nullable long[] val) throws BinaryObjectException {
+        writeFieldId(fieldName);
+        writeLongArrayField(val);
+    }
+
+    /** {@inheritDoc} */
+    @Override public void writeLongArray(@Nullable long[] val) throws BinaryObjectException {
+        doWriteLongArray(val);
+    }
+
+    /** {@inheritDoc} */
+    @Override public void writeFloatArray(String fieldName, @Nullable float[] val) throws BinaryObjectException {
+        writeFieldId(fieldName);
+        writeFloatArrayField(val);
+    }
+
+    /** {@inheritDoc} */
+    @Override public void writeFloatArray(@Nullable float[] val) throws BinaryObjectException {
+        doWriteFloatArray(val);
+    }
+
+    /** {@inheritDoc} */
+    @Override public void writeDoubleArray(String fieldName, @Nullable double[] val)
+        throws BinaryObjectException {
+        writeFieldId(fieldName);
+        writeDoubleArrayField(val);
+    }
+
+    /** {@inheritDoc} */
+    @Override public void writeDoubleArray(@Nullable double[] val) throws BinaryObjectException {
+        doWriteDoubleArray(val);
+    }
+
+    /** {@inheritDoc} */
+    @Override public void writeCharArray(String fieldName, @Nullable char[] val) throws BinaryObjectException {
+        writeFieldId(fieldName);
+        writeCharArrayField(val);
+    }
+
+    /** {@inheritDoc} */
+    @Override public void writeCharArray(@Nullable char[] val) throws BinaryObjectException {
+        doWriteCharArray(val);
+    }
+
+    /** {@inheritDoc} */
+    @Override public void writeBooleanArray(String fieldName, @Nullable boolean[] val)
+        throws BinaryObjectException {
+        writeFieldId(fieldName);
+        writeBooleanArrayField(val);
+    }
+
+    /** {@inheritDoc} */
+    @Override public void writeBooleanArray(@Nullable boolean[] val) throws BinaryObjectException {
+        doWriteBooleanArray(val);
+    }
+
+    /** {@inheritDoc} */
+    @Override public void writeDecimalArray(String fieldName, @Nullable BigDecimal[] val)
+        throws BinaryObjectException {
+        writeFieldId(fieldName);
+        writeDecimalArrayField(val);
+    }
+
+    /** {@inheritDoc} */
+    @Override public void writeDecimalArray(@Nullable BigDecimal[] val) throws BinaryObjectException {
+        doWriteDecimalArray(val);
+    }
+
+    /** {@inheritDoc} */
+    @Override public void writeStringArray(String fieldName, @Nullable String[] val)
+        throws BinaryObjectException {
+        writeFieldId(fieldName);
+        writeStringArrayField(val);
+    }
+
+    /** {@inheritDoc} */
+    @Override public void writeStringArray(@Nullable String[] val) throws BinaryObjectException {
+        doWriteStringArray(val);
+    }
+
+    /** {@inheritDoc} */
+    @Override public void writeUuidArray(String fieldName, @Nullable UUID[] val) throws BinaryObjectException {
+        writeFieldId(fieldName);
+        writeUuidArrayField(val);
+    }
+
+    /** {@inheritDoc} */
+    @Override public void writeUuidArray(@Nullable UUID[] val) throws BinaryObjectException {
+        doWriteUuidArray(val);
+    }
+
+    /** {@inheritDoc} */
+    @Override public void writeDateArray(String fieldName, @Nullable Date[] val) throws BinaryObjectException {
+        writeFieldId(fieldName);
+        writeDateArrayField(val);
+    }
+
+    /** {@inheritDoc} */
+    @Override public void writeDateArray(@Nullable Date[] val) throws BinaryObjectException {
+        doWriteDateArray(val);
+    }
+
+    /** {@inheritDoc} */
+    @Override public void writeTimestampArray(String fieldName, @Nullable Timestamp[] val) throws BinaryObjectException {
+        writeFieldId(fieldName);
+        writeTimestampArrayField(val);
+    }
+
+    /** {@inheritDoc} */
+    @Override public void writeTimestampArray(@Nullable Timestamp[] val) throws BinaryObjectException {
+        doWriteTimestampArray(val);
+    }
+
+     /** {@inheritDoc} */
+    @Override public void writeObjectArray(String fieldName, @Nullable Object[] val) throws BinaryObjectException {
+        writeFieldId(fieldName);
+        writeObjectArrayField(val);
+    }
+
+    /** {@inheritDoc} */
+    @Override public void writeObjectArray(@Nullable Object[] val) throws BinaryObjectException {
+        doWriteObjectArray(val);
+    }
+
+    /** {@inheritDoc} */
+    @Override public <T> void writeCollection(String fieldName, @Nullable Collection<T> col)
+        throws BinaryObjectException {
+        writeFieldId(fieldName);
+        writeCollectionField(col);
+    }
+
+    /** {@inheritDoc} */
+    @Override public <T> void writeCollection(@Nullable Collection<T> col) throws BinaryObjectException {
+        doWriteCollection(col);
+    }
+
+    /** {@inheritDoc} */
+    @Override public <K, V> void writeMap(String fieldName, @Nullable Map<K, V> map)
+        throws BinaryObjectException {
+        writeFieldId(fieldName);
+        writeMapField(map);
+    }
+
+    /** {@inheritDoc} */
+    @Override public <K, V> void writeMap(@Nullable Map<K, V> map) throws BinaryObjectException {
+        doWriteMap(map);
+    }
+
+    /** {@inheritDoc} */
+    @Override public <T extends Enum<?>> void writeEnum(String fieldName, T val) throws BinaryObjectException {
+        writeFieldId(fieldName);
+        writeEnumField(val);
+    }
+
+    /** {@inheritDoc} */
+    @Override public <T extends Enum<?>> void writeEnum(T val) throws BinaryObjectException {
+        doWriteEnum(val);
+    }
+
+    /** {@inheritDoc} */
+    @Override public <T extends Enum<?>> void writeEnumArray(String fieldName, T[] val) throws BinaryObjectException {
+        writeFieldId(fieldName);
+        writeEnumArrayField(val);
+    }
+
+    /** {@inheritDoc} */
+    @Override public <T extends Enum<?>> void writeEnumArray(T[] val) throws BinaryObjectException {
+        doWriteEnumArray(val);
+    }
+
+    /** {@inheritDoc} */
+    @Override public BinaryRawWriter rawWriter() {
+        if (rawOffPos == 0)
+            rawOffPos = out.position();
+
+        return this;
+    }
+
+    /** {@inheritDoc} */
+    @Override public PortableOutputStream out() {
+        return out;
+    }
+
+    /** {@inheritDoc} */
+    @SuppressWarnings("NullableProblems")
+    @Override public void writeBytes(String s) throws IOException {
+        int len = s.length();
+
+        writeInt(len);
+
+        for (int i = 0; i < len; i++)
+            writeByte(s.charAt(i));
+    }
+
+    /** {@inheritDoc} */
+    @SuppressWarnings("NullableProblems")
+    @Override public void writeChars(String s) throws IOException {
+        int len = s.length();
+
+        writeInt(len);
+
+        for (int i = 0; i < len; i++)
+            writeChar(s.charAt(i));
+    }
+
+    /** {@inheritDoc} */
+    @SuppressWarnings("NullableProblems")
+    @Override public void writeUTF(String s) throws IOException {
+        writeString(s);
+    }
+
+    /** {@inheritDoc} */
+    @Override public void writeByte(int v) throws IOException {
+        out.writeByte((byte) v);
+    }
+
+    /** {@inheritDoc} */
+    @Override public void writeShort(int v) throws IOException {
+        out.writeShort((short) v);
+    }
+
+    /** {@inheritDoc} */
+    @Override public void writeChar(int v) throws IOException {
+        out.writeChar((char) v);
+    }
+
+    /** {@inheritDoc} */
+    @Override public void write(int b) throws IOException {
+        out.writeByte((byte) b);
+    }
+
+    /** {@inheritDoc} */
+    @Override public void flush() throws IOException {
+        // No-op.
+    }
+
+    /** {@inheritDoc} */
+    @Override public int reserveInt() {
+        int pos = out.position();
+
+        out.position(pos + LEN_INT);
+
+        return pos;
+    }
+
+    /** {@inheritDoc} */
+    @Override public void writeInt(int pos, int val) throws BinaryObjectException {
+        out.writeInt(pos, val);
+    }
+
+    /**
+     * @param fieldName Field name.
+     * @throws org.apache.ignite.binary.BinaryObjectException If fields are not allowed.
+     */
+    private void writeFieldId(String fieldName) throws BinaryObjectException {
+        A.notNull(fieldName, "fieldName");
+
+        if (rawOffPos != 0)
+            throw new BinaryObjectException("Individual field can't be written after raw writer is acquired.");
+
+        if (idMapper == null)
+            idMapper = ctx.userTypeIdMapper(typeId);
+
+        int id = idMapper.fieldId(typeId, fieldName);
+
+        writeFieldId(id);
+    }
+
+    /**
+     * Write field ID.
+     * @param fieldId Field ID.
+     */
+    public void writeFieldId(int fieldId) {
+        int fieldOff = out.position() - start;
+
+        // Advance schema hash.
+        schemaId = PortableUtils.updateSchemaId(schemaId, fieldId);
+
+        schema.push(fieldId, fieldOff);
+
+        fieldCnt++;
+    }
+
+    /**
+     * Write field ID without schema ID update. This method should be used when schema ID is stable because class
+     * is seializable.
+     *
+     * @param fieldId Field ID.
+     */
+    public void writeFieldIdNoSchemaUpdate(int fieldId) {
+        int fieldOff = out.position() - start;
+
+        schema.push(fieldId, fieldOff);
+
+        fieldCnt++;
+    }
+
+    /**
+     * @param schemaId Schema ID.
+     */
+    public void schemaId(int schemaId) {
+        this.schemaId = schemaId;
+    }
+
+    /**
+     * @return Schema ID.
+     */
+    public int schemaId() {
+        return schemaId;
+    }
+
+    /**
+     * @return Current writer's schema.
+     */
+    public PortableSchema currentSchema() {
+        PortableSchema.Builder builder = PortableSchema.Builder.newBuilder();
+
+        if (schema != null)
+            schema.build(builder, fieldCnt);
+
+        return builder.build();
+    }
+
+    /**
+     * Get current handles. If they are {@code null}, then we should create them. Otherwise we will not see updates
+     * performed by child writers.
+     *
+     * @return Handles.
+     */
+    private BinaryWriterHandles handles() {
+        if (handles == null)
+            handles = new BinaryWriterHandles();
+
+        return handles;
+    }
+
+    /**
+     * Attempts to write the object as a handle.
+     *
+     * @param obj Object to write.
+     * @return {@code true} if the object has been written as a handle.
+     */
+    boolean tryWriteAsHandle(Object obj) {
+        assert obj != null;
+
+        int pos = out.position();
+
+        BinaryWriterHandles handles0 = handles();
+
+        int old = handles0.put(obj, pos);
+
+        if (old == BinaryWriterHandles.POS_NULL)
+            return false;
+        else {
+            out.unsafeEnsure(1 + 4);
+
+            out.unsafeWriteByte(GridPortableMarshaller.HANDLE);
+            out.unsafeWriteInt(pos - old);
+
+            return true;
+        }
+    }
+
+    /**
+     * Create new writer with same context.
+     *
+     * @param typeId type
+     * @return New writer.
+     */
+    public BinaryWriterExImpl newWriter(int typeId) {
+        BinaryWriterExImpl res = new BinaryWriterExImpl(ctx, out, schema, handles());
+
+        res.typeId(typeId);
+
+        return res;
+    }
+
+    /**
+     * @return Portable context.
+     */
+    public PortableContext context() {
+        return ctx;
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/1dbf20e0/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryWriterHandles.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryWriterHandles.java b/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryWriterHandles.java
new file mode 100644
index 0000000..3be3898
--- /dev/null
+++ b/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryWriterHandles.java
@@ -0,0 +1,101 @@
+/*
+ * 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.binary;
+
+import java.util.IdentityHashMap;
+
+/**
+ * Writer handles. Aimed to delay hash map allocation for some time until it is clearly evident that it is needed.
+ */
+public class BinaryWriterHandles {
+    /** Value denoting null position. */
+    public static final int POS_NULL = -1;
+
+    /** Mode: empty. */
+    private static final int MODE_EMPTY = 0;
+
+    /** Mode: single object. */
+    private static final int MODE_SINGLE = 1;
+
+    /** Mode: multiple objects. */
+    private static final int MODE_MULTIPLE = 2;
+
+    /** Data. This is either an object or a map. */
+    private Object data;
+
+    /** Position.  */
+    private int singlePos;
+
+    /** Mode. */
+    private int mode = MODE_EMPTY;
+
+    /**
+     * Put object to registry and return previous position (if any).
+     *
+     * @param obj Object.
+     * @param pos Position.
+     * @return Old position.
+     */
+    @SuppressWarnings("unchecked")
+    public int put(Object obj, int pos) {
+        assert obj != null;
+        assert pos >= 0;
+
+        switch (mode) {
+            case MODE_EMPTY:
+                this.data = obj;
+                this.singlePos = pos;
+                this.mode = MODE_SINGLE;
+
+                return POS_NULL;
+
+            case MODE_SINGLE:
+                if (this.data == obj)
+                    return singlePos;
+                else {
+                    IdentityHashMap<Object, Integer> newData = new IdentityHashMap<>(2);
+
+                    newData.put(data, singlePos);
+                    newData.put(obj, pos);
+
+                    this.data = newData;
+                    this.singlePos = -1;
+                    this.mode = MODE_MULTIPLE;
+
+                    return POS_NULL;
+                }
+
+            default:
+                assert mode == MODE_MULTIPLE;
+
+                IdentityHashMap<Object, Integer> data0 = (IdentityHashMap<Object, Integer>)data;
+
+                Integer oldPos = data0.put(obj, pos);
+
+                if (oldPos != null) {
+                    // Restore initial position and return it.
+                    data0.put(obj, oldPos);
+
+                    return oldPos;
+                }
+                else
+                    return POS_NULL;
+
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/1dbf20e0/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryWriterSchemaHolder.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryWriterSchemaHolder.java b/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryWriterSchemaHolder.java
new file mode 100644
index 0000000..7fd6442
--- /dev/null
+++ b/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryWriterSchemaHolder.java
@@ -0,0 +1,149 @@
+/*
+ * 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.binary;
+
+import org.apache.ignite.internal.binary.streams.PortableOutputStream;
+import org.apache.ignite.internal.binary.streams.PortableOutputStream;
+
+/**
+ * Binary writer schema holder.
+ */
+public class BinaryWriterSchemaHolder {
+    /** Maximum offset which fits in 1 byte. */
+    private static final int MAX_OFFSET_1 = 1 << 8;
+
+    /** Maximum offset which fits in 2 bytes. */
+    private static final int MAX_OFFSET_2 = 1 << 16;
+
+    /** Grow step. */
+    private static final int GROW_STEP = 64;
+
+    /** Data. */
+    private int[] data = new int[GROW_STEP];
+
+    /** Index. */
+    private int idx;
+
+    /**
+     * Push another frame.
+     *
+     * @param id Field ID.
+     * @param off Field offset.
+     */
+    public void push(int id, int off) {
+        if (idx == data.length) {
+            int[] data0 = new int[data.length + GROW_STEP];
+
+            System.arraycopy(data, 0, data0, 0, data.length);
+
+            data = data0;
+        }
+
+        data[idx] = id;
+        data[idx + 1] = off;
+
+        idx += 2;
+    }
+
+    /**
+     * Build the schema.
+     *
+     * @param builder Builder.
+     * @param fieldCnt Fields count.
+     */
+    public void build(PortableSchema.Builder builder, int fieldCnt) {
+        for (int curIdx = idx - fieldCnt * 2; curIdx < idx; curIdx += 2)
+            builder.addField(data[curIdx]);
+    }
+
+    /**
+     * Write collected frames and pop them.
+     *
+     * @param out Output stream.
+     * @param fieldCnt Count.
+     * @param compactFooter Whether footer should be written in compact form.
+     * @return Amount of bytes dedicated to each field offset. Could be 1, 2 or 4.
+     */
+    public int write(PortableOutputStream out, int fieldCnt, boolean compactFooter) {
+        int startIdx = idx - fieldCnt * 2;
+        assert startIdx >= 0;
+
+        // Ensure there are at least 8 bytes for each field to allow for unsafe writes.
+        out.unsafeEnsure(fieldCnt << 3);
+
+        int lastOffset = data[idx - 1];
+
+        int res;
+
+        if (compactFooter) {
+            if (lastOffset < MAX_OFFSET_1) {
+                for (int curIdx = startIdx + 1; curIdx < idx; curIdx += 2)
+                    out.unsafeWriteByte((byte)data[curIdx]);
+
+                res = PortableUtils.OFFSET_1;
+            }
+            else if (lastOffset < MAX_OFFSET_2) {
+                for (int curIdx = startIdx + 1; curIdx < idx; curIdx += 2)
+                    out.unsafeWriteShort((short) data[curIdx]);
+
+                res = PortableUtils.OFFSET_2;
+            }
+            else {
+                for (int curIdx = startIdx + 1; curIdx < idx; curIdx += 2)
+                    out.unsafeWriteInt(data[curIdx]);
+
+                res = PortableUtils.OFFSET_4;
+            }
+        }
+        else {
+            if (lastOffset < MAX_OFFSET_1) {
+                for (int curIdx = startIdx; curIdx < idx;) {
+                    out.unsafeWriteInt(data[curIdx++]);
+                    out.unsafeWriteByte((byte) data[curIdx++]);
+                }
+
+                res = PortableUtils.OFFSET_1;
+            }
+            else if (lastOffset < MAX_OFFSET_2) {
+                for (int curIdx = startIdx; curIdx < idx;) {
+                    out.unsafeWriteInt(data[curIdx++]);
+                    out.unsafeWriteShort((short) data[curIdx++]);
+                }
+
+                res = PortableUtils.OFFSET_2;
+            }
+            else {
+                for (int curIdx = startIdx; curIdx < idx;) {
+                    out.unsafeWriteInt(data[curIdx++]);
+                    out.unsafeWriteInt(data[curIdx++]);
+                }
+
+                res = PortableUtils.OFFSET_4;
+            }
+        }
+
+        return res;
+    }
+
+    /**
+     * Pop current object's frame.
+     */
+    public void pop(int fieldCnt) {
+        idx = idx - fieldCnt * 2;
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/1dbf20e0/modules/core/src/main/java/org/apache/ignite/internal/binary/GridPortableMarshaller.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/binary/GridPortableMarshaller.java b/modules/core/src/main/java/org/apache/ignite/internal/binary/GridPortableMarshaller.java
new file mode 100644
index 0000000..a57bb55
--- /dev/null
+++ b/modules/core/src/main/java/org/apache/ignite/internal/binary/GridPortableMarshaller.java
@@ -0,0 +1,289 @@
+/*
+ * 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.binary;
+
+import org.apache.ignite.internal.binary.streams.PortableHeapInputStream;
+import org.apache.ignite.internal.binary.streams.PortableInputStream;
+import org.apache.ignite.internal.binary.streams.PortableOutputStream;
+import org.apache.ignite.internal.binary.streams.PortableHeapInputStream;
+import org.apache.ignite.internal.binary.streams.PortableInputStream;
+import org.apache.ignite.internal.binary.streams.PortableOutputStream;
+import org.apache.ignite.binary.BinaryObjectException;
+import org.jetbrains.annotations.Nullable;
+
+/**
+ * Portable objects marshaller.
+ */
+public class GridPortableMarshaller {
+    /** */
+    public static final ThreadLocal<Boolean> KEEP_PORTABLES = new ThreadLocal<Boolean>() {
+        @Override protected Boolean initialValue() {
+            return true;
+        }
+    };
+
+    /** */
+    static final byte OPTM_MARSH = -2;
+
+    /** */
+    public static final byte BYTE = 1;
+
+    /** */
+    public static final byte SHORT = 2;
+
+    /** */
+    public static final byte INT = 3;
+
+    /** */
+    public static final byte LONG = 4;
+
+    /** */
+    public static final byte FLOAT = 5;
+
+    /** */
+    public static final byte DOUBLE = 6;
+
+    /** */
+    public static final byte CHAR = 7;
+
+    /** */
+    public static final byte BOOLEAN = 8;
+
+    /** */
+    public static final byte DECIMAL = 30;
+
+    /** */
+    public static final byte STRING = 9;
+
+    /** */
+    public static final byte UUID = 10;
+
+    /** */
+    public static final byte DATE = 11;
+
+    /** */
+    public static final byte BYTE_ARR = 12;
+
+    /** */
+    public static final byte SHORT_ARR = 13;
+
+    /** */
+    public static final byte INT_ARR = 14;
+
+    /** */
+    public static final byte LONG_ARR = 15;
+
+    /** */
+    public static final byte FLOAT_ARR = 16;
+
+    /** */
+    public static final byte DOUBLE_ARR = 17;
+
+    /** */
+    public static final byte CHAR_ARR = 18;
+
+    /** */
+    public static final byte BOOLEAN_ARR = 19;
+
+    /** */
+    public static final byte DECIMAL_ARR = 31;
+
+    /** */
+    public static final byte STRING_ARR = 20;
+
+    /** */
+    public static final byte UUID_ARR = 21;
+
+    /** */
+    public static final byte DATE_ARR = 22;
+
+    /** */
+    public static final byte OBJ_ARR = 23;
+
+    /** */
+    public static final byte COL = 24;
+
+    /** */
+    public static final byte MAP = 25;
+
+    /** */
+    public static final byte PORTABLE_OBJ = 27;
+
+    /** */
+    public static final byte ENUM = 28;
+
+    /** */
+    public static final byte ENUM_ARR = 29;
+
+    /** */
+    public static final byte CLASS = 32;
+
+    /** Timestamp. */
+    public static final byte TIMESTAMP = 33;
+
+    /** Timestamp array. */
+    public static final byte TIMESTAMP_ARR = 34;
+
+    /** */
+    public static final byte NULL = (byte)101;
+
+    /** */
+    public static final byte HANDLE = (byte)102;
+
+    /** */
+    public static final byte OBJ = (byte)103;
+
+    /** */
+    public static final byte USER_SET = -1;
+
+    /** */
+    public static final byte USER_COL = 0;
+
+    /** */
+    public static final byte ARR_LIST = 1;
+
+    /** */
+    public static final byte LINKED_LIST = 2;
+
+    /** */
+    public static final byte HASH_SET = 3;
+
+    /** */
+    public static final byte LINKED_HASH_SET = 4;
+
+    /** */
+    public static final byte HASH_MAP = 1;
+
+    /** */
+    public static final byte LINKED_HASH_MAP = 2;
+
+    /** */
+    public static final int OBJECT_TYPE_ID = -1;
+
+    /** */
+    public static final int UNREGISTERED_TYPE_ID = 0;
+
+    /** Protocol version. */
+    public static final byte PROTO_VER = 1;
+
+    /** Protocol version position. */
+    public static final int PROTO_VER_POS = 1;
+
+    /** Flags position in header. */
+    public static final int FLAGS_POS = 2;
+
+    /** */
+    public static final int TYPE_ID_POS = 4;
+
+    /** */
+    public static final int HASH_CODE_POS = 8;
+
+    /** */
+    public static final int TOTAL_LEN_POS = 12;
+
+    /** */
+    public static final int SCHEMA_ID_POS = 16;
+
+    /** Schema or raw offset position. */
+    public static final int SCHEMA_OR_RAW_OFF_POS = 20;
+
+    /** */
+    public static final byte DFLT_HDR_LEN = 24;
+
+    /** */
+    private final PortableContext ctx;
+
+    /**
+     * @param ctx Context.
+     */
+    public GridPortableMarshaller(PortableContext ctx) {
+        this.ctx = ctx;
+    }
+
+    /**
+     * @param obj Object to marshal.
+     * @return Byte array.
+     * @throws org.apache.ignite.binary.BinaryObjectException In case of error.
+     */
+    public byte[] marshal(@Nullable Object obj) throws BinaryObjectException {
+        if (obj == null)
+            return new byte[] { NULL };
+
+        try (BinaryWriterExImpl writer = new BinaryWriterExImpl(ctx)) {
+            writer.marshal(obj);
+
+            return writer.array();
+        }
+    }
+
+    /**
+     * @param bytes Bytes array.
+     * @return Portable object.
+     * @throws org.apache.ignite.binary.BinaryObjectException In case of error.
+     */
+    @SuppressWarnings("unchecked")
+    @Nullable public <T> T unmarshal(byte[] bytes, @Nullable ClassLoader clsLdr) throws BinaryObjectException {
+        assert bytes != null;
+
+        return (T)PortableUtils.unmarshal(PortableHeapInputStream.create(bytes, 0), ctx, clsLdr);
+    }
+
+    /**
+     * @param in Input stream.
+     * @return Portable object.
+     * @throws org.apache.ignite.binary.BinaryObjectException In case of error.
+     */
+    @SuppressWarnings("unchecked")
+    @Nullable public <T> T unmarshal(PortableInputStream in) throws BinaryObjectException {
+        return (T)PortableUtils.unmarshal(in, ctx, null);
+    }
+
+    /**
+     * @param arr Byte array.
+     * @param ldr Class loader.
+     * @return Deserialized object.
+     * @throws org.apache.ignite.binary.BinaryObjectException In case of error.
+     */
+    @SuppressWarnings("unchecked")
+    @Nullable public <T> T deserialize(byte[] arr, @Nullable ClassLoader ldr) throws BinaryObjectException {
+        assert arr != null;
+        assert arr.length > 0;
+
+        if (arr[0] == NULL)
+            return null;
+
+        return (T)new BinaryReaderExImpl(ctx, PortableHeapInputStream.create(arr, 0), ldr).deserialize();
+    }
+
+    /**
+     * Gets writer for the given output stream.
+     *
+     * @param out Output stream.
+     * @return Writer.
+     */
+    public BinaryWriterExImpl writer(PortableOutputStream out) {
+        return new BinaryWriterExImpl(ctx, out, BinaryThreadLocalContext.get().schemaHolder(), null);
+    }
+
+    /**
+     * @return Context.
+     */
+    public PortableContext context() {
+        return ctx;
+    }
+}


[34/59] [abbrv] ignite git commit: IGNITE-1932 Fixed busy time calculations after ignite.cluster().resetMetrics(). - Fixes #242.

Posted by ak...@apache.org.
IGNITE-1932 Fixed busy time calculations after ignite.cluster().resetMetrics(). - Fixes #242.

Signed-off-by: Alexey Kuznetsov <ak...@apache.org>


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

Branch: refs/heads/ignite-843-rc2
Commit: 69a6b0f93b4ce55e9693620666cd016f527dd838
Parents: 0ac39c9
Author: AKuznetsov <ak...@gridgain.com>
Authored: Fri Dec 11 17:11:38 2015 +0700
Committer: Alexey Kuznetsov <ak...@apache.org>
Committed: Fri Dec 11 17:11:38 2015 +0700

----------------------------------------------------------------------
 .../processors/jobmetrics/GridJobMetricsProcessor.java       | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/69a6b0f9/modules/core/src/main/java/org/apache/ignite/internal/processors/jobmetrics/GridJobMetricsProcessor.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/jobmetrics/GridJobMetricsProcessor.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/jobmetrics/GridJobMetricsProcessor.java
index 06b9383..72ffe23 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/jobmetrics/GridJobMetricsProcessor.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/jobmetrics/GridJobMetricsProcessor.java
@@ -108,7 +108,13 @@ public class GridJobMetricsProcessor extends GridProcessorAdapter {
      * Resets metrics.
      */
     public void reset() {
+        InternalMetrics prevMetrics = metrics;
+
         metrics = new InternalMetrics();
+
+        // Preserve totalIdleTime, because it is used for busy / idle time calculations.
+        if (prevMetrics != null)
+            metrics.totalIdleTime = prevMetrics.totalIdleTime;
     }
 
     /**
@@ -400,4 +406,4 @@ public class GridJobMetricsProcessor extends GridProcessorAdapter {
             return m;
         }
     }
-}
\ No newline at end of file
+}


[24/59] [abbrv] ignite git commit: ignite-2065: rename "portable" packages to "binary"

Posted by ak...@apache.org.
http://git-wip-us.apache.org/repos/asf/ignite/blob/1dbf20e0/modules/core/src/main/java/org/apache/ignite/internal/binary/builder/PortableLazySet.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/binary/builder/PortableLazySet.java b/modules/core/src/main/java/org/apache/ignite/internal/binary/builder/PortableLazySet.java
new file mode 100644
index 0000000..3548f1f
--- /dev/null
+++ b/modules/core/src/main/java/org/apache/ignite/internal/binary/builder/PortableLazySet.java
@@ -0,0 +1,94 @@
+/*
+ * 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.binary.builder;
+
+import java.util.Collection;
+import java.util.Set;
+import org.apache.ignite.internal.binary.BinaryWriterExImpl;
+import org.apache.ignite.internal.binary.GridPortableMarshaller;
+import org.apache.ignite.internal.binary.GridPortableMarshaller;
+import org.apache.ignite.internal.binary.PortableUtils;
+import org.apache.ignite.internal.binary.BinaryWriterExImpl;
+import org.apache.ignite.internal.util.typedef.internal.U;
+
+/**
+ *
+ */
+class PortableLazySet extends PortableAbstractLazyValue {
+    /** */
+    private final int off;
+
+    /**
+     * @param reader Reader.
+     * @param size Size.
+     */
+    PortableLazySet(PortableBuilderReader reader, int size) {
+        super(reader, reader.position() - 1);
+
+        off = reader.position() - 1/* flag */ - 4/* size */ - 1/* col type */;
+
+        assert size >= 0;
+
+        for (int i = 0; i < size; i++)
+            reader.skipValue();
+    }
+
+    /** {@inheritDoc} */
+    @Override public void writeTo(BinaryWriterExImpl writer, PortableBuilderSerializer ctx) {
+        if (val == null) {
+            int size = reader.readIntPositioned(off + 1);
+
+            int hdrSize = 1 /* flag */ + 4 /* size */ + 1 /* col type */;
+            writer.write(reader.array(), off, hdrSize);
+
+            reader.position(off + hdrSize);
+
+            for (int i = 0; i < size; i++) {
+                Object o = reader.parseValue();
+
+                ctx.writeValue(writer, o);
+            }
+        }
+        else {
+            Collection<Object> c = (Collection<Object>)val;
+
+            writer.writeByte(GridPortableMarshaller.COL);
+            writer.writeInt(c.size());
+
+            byte colType = reader.array()[off + 1 /* flag */ + 4 /* size */];
+            writer.writeByte(colType);
+
+            for (Object o : c)
+                ctx.writeValue(writer, o);
+        }
+    }
+
+    /** {@inheritDoc} */
+    @Override protected Object init() {
+        int size = reader.readIntPositioned(off + 1);
+
+        reader.position(off + 1/* flag */ + 4/* size */ + 1/* col type */);
+
+        Set<Object> res = U.newLinkedHashSet(size);
+
+        for (int i = 0; i < size; i++)
+            res.add(PortableUtils.unwrapLazy(reader.parseValue()));
+
+        return res;
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/1dbf20e0/modules/core/src/main/java/org/apache/ignite/internal/binary/builder/PortableLazyValue.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/binary/builder/PortableLazyValue.java b/modules/core/src/main/java/org/apache/ignite/internal/binary/builder/PortableLazyValue.java
new file mode 100644
index 0000000..51c6d7e
--- /dev/null
+++ b/modules/core/src/main/java/org/apache/ignite/internal/binary/builder/PortableLazyValue.java
@@ -0,0 +1,28 @@
+/*
+ * 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.binary.builder;
+
+/**
+ *
+ */
+public interface PortableLazyValue extends PortableBuilderSerializationAware {
+    /**
+     * @return Value.
+     */
+    public Object value();
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/1dbf20e0/modules/core/src/main/java/org/apache/ignite/internal/binary/builder/PortableModifiableLazyValue.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/binary/builder/PortableModifiableLazyValue.java b/modules/core/src/main/java/org/apache/ignite/internal/binary/builder/PortableModifiableLazyValue.java
new file mode 100644
index 0000000..b00157e
--- /dev/null
+++ b/modules/core/src/main/java/org/apache/ignite/internal/binary/builder/PortableModifiableLazyValue.java
@@ -0,0 +1,52 @@
+/*
+ * 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.binary.builder;
+
+import org.apache.ignite.internal.binary.BinaryWriterExImpl;
+
+/**
+ *
+ */
+public class PortableModifiableLazyValue extends PortableAbstractLazyValue {
+    /** */
+    protected final int len;
+
+    /**
+     * @param reader
+     * @param valOff
+     * @param len
+     */
+    public PortableModifiableLazyValue(PortableBuilderReader reader, int valOff, int len) {
+        super(reader, valOff);
+
+        this.len = len;
+    }
+
+    /** {@inheritDoc} */
+    @Override protected Object init() {
+        return reader.reader().unmarshal(valOff);
+    }
+
+    /** {@inheritDoc} */
+    @Override public void writeTo(BinaryWriterExImpl writer, PortableBuilderSerializer ctx) {
+        if (val == null)
+            writer.write(reader.array(), valOff, len);
+        else
+            writer.writeObject(val);
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/1dbf20e0/modules/core/src/main/java/org/apache/ignite/internal/binary/builder/PortableObjectArrayLazyValue.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/binary/builder/PortableObjectArrayLazyValue.java b/modules/core/src/main/java/org/apache/ignite/internal/binary/builder/PortableObjectArrayLazyValue.java
new file mode 100644
index 0000000..537a25f
--- /dev/null
+++ b/modules/core/src/main/java/org/apache/ignite/internal/binary/builder/PortableObjectArrayLazyValue.java
@@ -0,0 +1,91 @@
+/*
+ * 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.binary.builder;
+
+import org.apache.ignite.internal.binary.GridPortableMarshaller;
+import org.apache.ignite.internal.binary.BinaryWriterExImpl;
+import org.apache.ignite.internal.util.typedef.internal.U;
+import org.apache.ignite.binary.BinaryInvalidTypeException;
+
+/**
+ *
+ */
+class PortableObjectArrayLazyValue extends PortableAbstractLazyValue {
+    /** */
+    private Object[] lazyValsArr;
+
+    /** */
+    private int compTypeId;
+
+    /** */
+    private String clsName;
+
+    /**
+     * @param reader Reader.
+     */
+    protected PortableObjectArrayLazyValue(PortableBuilderReader reader) {
+        super(reader, reader.position() - 1);
+
+        int typeId = reader.readInt();
+
+        if (typeId == GridPortableMarshaller.UNREGISTERED_TYPE_ID) {
+            clsName = reader.readString();
+
+            Class cls;
+
+            try {
+                // TODO: IGNITE-1272 - Is class loader needed here?
+                cls = U.forName(reader.readString(), null);
+            }
+            catch (ClassNotFoundException e) {
+                throw new BinaryInvalidTypeException("Failed to load the class: " + clsName, e);
+            }
+
+            compTypeId = reader.portableContext().descriptorForClass(cls, true).typeId();
+        }
+        else {
+            compTypeId = typeId;
+            clsName = null;
+        }
+
+        int size = reader.readInt();
+
+        lazyValsArr = new Object[size];
+
+        for (int i = 0; i < size; i++)
+            lazyValsArr[i] = reader.parseValue();
+    }
+
+    /** {@inheritDoc} */
+    @Override protected Object init() {
+        for (int i = 0; i < lazyValsArr.length; i++) {
+            if (lazyValsArr[i] instanceof PortableLazyValue)
+                lazyValsArr[i] = ((PortableLazyValue)lazyValsArr[i]).value();
+        }
+
+        return lazyValsArr;
+    }
+
+    /** {@inheritDoc} */
+    @Override public void writeTo(BinaryWriterExImpl writer, PortableBuilderSerializer ctx) {
+        if (clsName == null)
+            ctx.writeArray(writer, GridPortableMarshaller.OBJ_ARR, lazyValsArr, compTypeId);
+        else
+            ctx.writeArray(writer, GridPortableMarshaller.OBJ_ARR, lazyValsArr, clsName);
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/1dbf20e0/modules/core/src/main/java/org/apache/ignite/internal/binary/builder/PortablePlainLazyValue.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/binary/builder/PortablePlainLazyValue.java b/modules/core/src/main/java/org/apache/ignite/internal/binary/builder/PortablePlainLazyValue.java
new file mode 100644
index 0000000..f572415
--- /dev/null
+++ b/modules/core/src/main/java/org/apache/ignite/internal/binary/builder/PortablePlainLazyValue.java
@@ -0,0 +1,49 @@
+/*
+ * 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.binary.builder;
+
+import org.apache.ignite.internal.binary.BinaryWriterExImpl;
+
+/**
+ *
+ */
+class PortablePlainLazyValue extends PortableAbstractLazyValue {
+    /** */
+    protected final int len;
+
+    /**
+     * @param reader Reader
+     * @param valOff Offset
+     * @param len Length.
+     */
+    protected PortablePlainLazyValue(PortableBuilderReader reader, int valOff, int len) {
+        super(reader, valOff);
+
+        this.len = len;
+    }
+
+    /** {@inheritDoc} */
+    @Override protected Object init() {
+        return reader.reader().unmarshal(valOff);
+    }
+
+    /** {@inheritDoc} */
+    @Override public void writeTo(BinaryWriterExImpl writer, PortableBuilderSerializer ctx) {
+        writer.write(reader.array(), valOff, len);
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/1dbf20e0/modules/core/src/main/java/org/apache/ignite/internal/binary/builder/PortablePlainPortableObject.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/binary/builder/PortablePlainPortableObject.java b/modules/core/src/main/java/org/apache/ignite/internal/binary/builder/PortablePlainPortableObject.java
new file mode 100644
index 0000000..3b77a52
--- /dev/null
+++ b/modules/core/src/main/java/org/apache/ignite/internal/binary/builder/PortablePlainPortableObject.java
@@ -0,0 +1,56 @@
+/*
+ * 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.binary.builder;
+
+import org.apache.ignite.internal.binary.BinaryObjectImpl;
+import org.apache.ignite.internal.binary.BinaryObjectOffheapImpl;
+import org.apache.ignite.internal.binary.BinaryWriterExImpl;
+import org.apache.ignite.internal.binary.BinaryObjectImpl;
+import org.apache.ignite.internal.binary.BinaryObjectOffheapImpl;
+import org.apache.ignite.internal.binary.BinaryWriterExImpl;
+import org.apache.ignite.binary.BinaryObject;
+
+/**
+ *
+ */
+public class PortablePlainPortableObject implements PortableLazyValue {
+    /** */
+    private final BinaryObject portableObj;
+
+    /**
+     * @param portableObj Portable object.
+     */
+    public PortablePlainPortableObject(BinaryObject portableObj) {
+        this.portableObj = portableObj;
+    }
+
+    /** {@inheritDoc} */
+    @Override public Object value() {
+        return portableObj;
+    }
+
+    /** {@inheritDoc} */
+    @Override public void writeTo(BinaryWriterExImpl writer, PortableBuilderSerializer ctx) {
+        BinaryObject val = portableObj;
+
+        if (val instanceof BinaryObjectOffheapImpl)
+            val = ((BinaryObjectOffheapImpl)val).heapCopy();
+
+        writer.doWritePortableObject((BinaryObjectImpl)val);
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/1dbf20e0/modules/core/src/main/java/org/apache/ignite/internal/binary/builder/PortableValueWithType.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/binary/builder/PortableValueWithType.java b/modules/core/src/main/java/org/apache/ignite/internal/binary/builder/PortableValueWithType.java
new file mode 100644
index 0000000..6c5ddfe
--- /dev/null
+++ b/modules/core/src/main/java/org/apache/ignite/internal/binary/builder/PortableValueWithType.java
@@ -0,0 +1,77 @@
+/*
+ * 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.binary.builder;
+
+import org.apache.ignite.internal.binary.BinaryWriterExImpl;
+import org.apache.ignite.internal.binary.BinaryWriterExImpl;
+import org.apache.ignite.internal.util.typedef.internal.S;
+
+/**
+ *
+ */
+class PortableValueWithType implements PortableLazyValue {
+    /** */
+    private byte type;
+
+    /** */
+    private Object val;
+
+    /**
+     * @param type Type
+     * @param val Value.
+     */
+    PortableValueWithType(byte type, Object val) {
+        this.type = type;
+        this.val = val;
+    }
+
+    /** {@inheritDoc} */
+    @Override public void writeTo(BinaryWriterExImpl writer, PortableBuilderSerializer ctx) {
+        if (val instanceof PortableBuilderSerializationAware)
+            ((PortableBuilderSerializationAware)val).writeTo(writer, ctx);
+        else
+            ctx.writeValue(writer, val);
+    }
+
+    /**
+     * @return Type ID.
+     */
+    public int typeId() {
+        return type;
+    }
+
+    /** {@inheritDoc} */
+    @Override public Object value() {
+        if (val instanceof PortableLazyValue)
+            return ((PortableLazyValue)val).value();
+
+        return val;
+    }
+
+    /**
+     * @param val New value.
+     */
+    public void value(Object val) {
+        this.val = val;
+    }
+
+    /** {@inheritDoc} */
+    @Override public String toString() {
+        return S.toString(PortableValueWithType.class, this);
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/1dbf20e0/modules/core/src/main/java/org/apache/ignite/internal/binary/builder/package-info.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/binary/builder/package-info.java b/modules/core/src/main/java/org/apache/ignite/internal/binary/builder/package-info.java
new file mode 100644
index 0000000..f2c4b55
--- /dev/null
+++ b/modules/core/src/main/java/org/apache/ignite/internal/binary/builder/package-info.java
@@ -0,0 +1,22 @@
+/*
+ * 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 description. -->
+ * Contains classes specific to portable builder API.
+ */
+package org.apache.ignite.internal.binary.builder;

http://git-wip-us.apache.org/repos/asf/ignite/blob/1dbf20e0/modules/core/src/main/java/org/apache/ignite/internal/binary/package-info.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/binary/package-info.java b/modules/core/src/main/java/org/apache/ignite/internal/binary/package-info.java
new file mode 100644
index 0000000..4bb0fb1
--- /dev/null
+++ b/modules/core/src/main/java/org/apache/ignite/internal/binary/package-info.java
@@ -0,0 +1,22 @@
+/*
+ * 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 description. -->
+ * Contains portable APIs internal implementation.
+ */
+package org.apache.ignite.internal.binary;

http://git-wip-us.apache.org/repos/asf/ignite/blob/1dbf20e0/modules/core/src/main/java/org/apache/ignite/internal/binary/streams/PortableAbstractInputStream.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/binary/streams/PortableAbstractInputStream.java b/modules/core/src/main/java/org/apache/ignite/internal/binary/streams/PortableAbstractInputStream.java
new file mode 100644
index 0000000..9d36b47
--- /dev/null
+++ b/modules/core/src/main/java/org/apache/ignite/internal/binary/streams/PortableAbstractInputStream.java
@@ -0,0 +1,379 @@
+/*
+ * 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.binary.streams;
+
+import org.apache.ignite.binary.BinaryObjectException;
+
+/**
+ * Portable abstract input stream.
+ */
+public abstract class PortableAbstractInputStream extends PortableAbstractStream
+    implements PortableInputStream {
+    /** Length of data inside array. */
+    protected int len;
+
+    /** {@inheritDoc} */
+    @Override public byte readByte() {
+        ensureEnoughData(1);
+
+        return readByteAndShift();
+    }
+
+    /** {@inheritDoc} */
+    @Override public byte[] readByteArray(int cnt) {
+        ensureEnoughData(cnt);
+
+        byte[] res = new byte[cnt];
+
+        copyAndShift(res, BYTE_ARR_OFF, cnt);
+
+        return res;
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean readBoolean() {
+        return readByte() == BYTE_ONE;
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean[] readBooleanArray(int cnt) {
+        ensureEnoughData(cnt);
+
+        boolean[] res = new boolean[cnt];
+
+        copyAndShift(res, BOOLEAN_ARR_OFF, cnt);
+
+        return res;
+    }
+
+    /** {@inheritDoc} */
+    @Override public short readShort() {
+        ensureEnoughData(2);
+
+        short res = readShortFast();
+
+        shift(2);
+
+        if (!LITTLE_ENDIAN)
+            res = Short.reverseBytes(res);
+
+        return res;
+    }
+
+    /** {@inheritDoc} */
+    @Override public short[] readShortArray(int cnt) {
+        int len = cnt << 1;
+
+        ensureEnoughData(len);
+
+        short[] res = new short[cnt];
+
+        copyAndShift(res, SHORT_ARR_OFF, len);
+
+        if (!LITTLE_ENDIAN) {
+            for (int i = 0; i < res.length; i++)
+                res[i] = Short.reverseBytes(res[i]);
+        }
+
+        return res;
+    }
+
+    /** {@inheritDoc} */
+    @Override public char readChar() {
+        ensureEnoughData(2);
+
+        char res = readCharFast();
+
+        shift(2);
+
+        if (!LITTLE_ENDIAN)
+            res = Character.reverseBytes(res);
+
+        return res;
+    }
+
+    /** {@inheritDoc} */
+    @Override public char[] readCharArray(int cnt) {
+        int len = cnt << 1;
+
+        ensureEnoughData(len);
+
+        char[] res = new char[cnt];
+
+        copyAndShift(res, CHAR_ARR_OFF, len);
+
+        if (!LITTLE_ENDIAN) {
+            for (int i = 0; i < res.length; i++)
+                res[i] = Character.reverseBytes(res[i]);
+        }
+
+        return res;
+    }
+
+    /** {@inheritDoc} */
+    @Override public int readInt() {
+        ensureEnoughData(4);
+
+        int res = readIntFast();
+
+        shift(4);
+
+        if (!LITTLE_ENDIAN)
+            res = Integer.reverseBytes(res);
+
+        return res;
+    }
+
+    /** {@inheritDoc} */
+    @Override public int[] readIntArray(int cnt) {
+        int len = cnt << 2;
+
+        ensureEnoughData(len);
+
+        int[] res = new int[cnt];
+
+        copyAndShift(res, INT_ARR_OFF, len);
+
+        if (!LITTLE_ENDIAN) {
+            for (int i = 0; i < res.length; i++)
+                res[i] = Integer.reverseBytes(res[i]);
+        }
+
+        return res;
+    }
+
+    /** {@inheritDoc} */
+    @Override public byte readBytePositioned(int pos) {
+        int delta = pos + 1 - this.pos;
+
+        if (delta > 0)
+            ensureEnoughData(delta);
+
+        return readBytePositioned0(pos);
+    }
+
+    /** {@inheritDoc} */
+    @Override public short readShortPositioned(int pos) {
+        int delta = pos + 2 - this.pos;
+
+        if (delta > 0)
+            ensureEnoughData(delta);
+
+        return readShortPositioned0(pos);
+    }
+
+    /** {@inheritDoc} */
+    @Override public int readIntPositioned(int pos) {
+        int delta = pos + 4 - this.pos;
+
+        if (delta > 0)
+            ensureEnoughData(delta);
+
+        return readIntPositioned0(pos);
+    }
+
+    /** {@inheritDoc} */
+    @Override public float readFloat() {
+        return Float.intBitsToFloat(readInt());
+    }
+
+    /** {@inheritDoc} */
+    @Override public float[] readFloatArray(int cnt) {
+        int len = cnt << 2;
+
+        ensureEnoughData(len);
+
+        float[] res = new float[cnt];
+
+        if (LITTLE_ENDIAN)
+            copyAndShift(res, FLOAT_ARR_OFF, len);
+        else {
+            for (int i = 0; i < res.length; i++) {
+                int x = readIntFast();
+
+                shift(4);
+
+                res[i] = Float.intBitsToFloat(Integer.reverseBytes(x));
+            }
+        }
+
+        return res;
+    }
+
+    /** {@inheritDoc} */
+    @Override public long readLong() {
+        ensureEnoughData(8);
+
+        long res = readLongFast();
+
+        shift(8);
+
+        if (!LITTLE_ENDIAN)
+            res = Long.reverseBytes(res);
+
+        return res;
+    }
+
+    /** {@inheritDoc} */
+    @Override public long[] readLongArray(int cnt) {
+        int len = cnt << 3;
+
+        ensureEnoughData(len);
+
+        long[] res = new long[cnt];
+
+        copyAndShift(res, LONG_ARR_OFF, len);
+
+        if (!LITTLE_ENDIAN) {
+            for (int i = 0; i < res.length; i++)
+                res[i] = Long.reverseBytes(res[i]);
+        }
+
+        return res;
+    }
+
+    /** {@inheritDoc} */
+    @Override public double readDouble() {
+        return Double.longBitsToDouble(readLong());
+    }
+
+    /** {@inheritDoc} */
+    @Override public double[] readDoubleArray(int cnt) {
+        int len = cnt << 3;
+
+        ensureEnoughData(len);
+
+        double[] res = new double[cnt];
+
+        if (LITTLE_ENDIAN)
+            copyAndShift(res, DOUBLE_ARR_OFF, len);
+        else {
+            for (int i = 0; i < res.length; i++) {
+                long x = readLongFast();
+
+                shift(8);
+
+                res[i] = Double.longBitsToDouble(Long.reverseBytes(x));
+            }
+        }
+
+        return res;
+    }
+
+    /** {@inheritDoc} */
+    @Override public int read(byte[] arr, int off, int len) {
+        if (len > remaining())
+            len = remaining();
+
+        copyAndShift(arr, BYTE_ARR_OFF + off, len);
+
+        return len;
+    }
+
+    /** {@inheritDoc} */
+    @Override public void position(int pos) {
+        if (remaining() + this.pos < pos)
+            throw new BinaryObjectException("Position is out of bounds: " + pos);
+        else
+            this.pos = pos;
+    }
+
+    /** {@inheritDoc} */
+    @Override public long offheapPointer() {
+        return 0;
+    }
+
+    /**
+     * Ensure that there is enough data.
+     *
+     * @param cnt Length.
+     */
+    protected void ensureEnoughData(int cnt) {
+        if (remaining() < cnt)
+            throw new BinaryObjectException("Not enough data to read the value [position=" + pos +
+                ", requiredBytes=" + cnt + ", remainingBytes=" + remaining() + ']');
+    }
+
+    /**
+     * Read next byte from the stream and perform shift.
+     *
+     * @return Next byte.
+     */
+    protected abstract byte readByteAndShift();
+
+    /**
+     * Copy data to target object shift position afterwards.
+     *
+     * @param target Target.
+     * @param off Offset.
+     * @param len Length.
+     */
+    protected abstract void copyAndShift(Object target, long off, int len);
+
+    /**
+     * Read short value (fast path).
+     *
+     * @return Short value.
+     */
+    protected abstract short readShortFast();
+
+    /**
+     * Read char value (fast path).
+     *
+     * @return Char value.
+     */
+    protected abstract char readCharFast();
+
+    /**
+     * Read int value (fast path).
+     *
+     * @return Int value.
+     */
+    protected abstract int readIntFast();
+
+    /**
+     * Read long value (fast path).
+     *
+     * @return Long value.
+     */
+    protected abstract long readLongFast();
+
+    /**
+     * Internal routine for positioned byte value read.
+     *
+     * @param pos Position.
+     * @return Int value.
+     */
+    protected abstract byte readBytePositioned0(int pos);
+
+    /**
+     * Internal routine for positioned short value read.
+     *
+     * @param pos Position.
+     * @return Int value.
+     */
+    protected abstract short readShortPositioned0(int pos);
+
+    /**
+     * Internal routine for positioned int value read.
+     *
+     * @param pos Position.
+     * @return Int value.
+     */
+    protected abstract int readIntPositioned0(int pos);
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/1dbf20e0/modules/core/src/main/java/org/apache/ignite/internal/binary/streams/PortableAbstractOutputStream.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/binary/streams/PortableAbstractOutputStream.java b/modules/core/src/main/java/org/apache/ignite/internal/binary/streams/PortableAbstractOutputStream.java
new file mode 100644
index 0000000..85064c5
--- /dev/null
+++ b/modules/core/src/main/java/org/apache/ignite/internal/binary/streams/PortableAbstractOutputStream.java
@@ -0,0 +1,347 @@
+/*
+ * 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.binary.streams;
+
+/**
+ * Base portable output stream.
+ */
+public abstract class PortableAbstractOutputStream extends PortableAbstractStream
+    implements PortableOutputStream {
+    /** Minimal capacity when it is reasonable to start doubling resize. */
+    private static final int MIN_CAP = 256;
+
+    /** {@inheritDoc} */
+    @Override public void writeByte(byte val) {
+        ensureCapacity(pos + 1);
+
+        writeByteAndShift(val);
+    }
+
+    /** {@inheritDoc} */
+    @Override public void writeByteArray(byte[] val) {
+        ensureCapacity(pos + val.length);
+
+        copyAndShift(val, BYTE_ARR_OFF, val.length);
+    }
+
+    /** {@inheritDoc} */
+    @Override public void writeBoolean(boolean val) {
+        writeByte(val ? BYTE_ONE : BYTE_ZERO);
+    }
+
+    /** {@inheritDoc} */
+    @Override public void writeBooleanArray(boolean[] val) {
+        ensureCapacity(pos + val.length);
+
+        copyAndShift(val, BOOLEAN_ARR_OFF, val.length);
+    }
+
+    /** {@inheritDoc} */
+    @Override public void writeShort(short val) {
+        ensureCapacity(pos + 2);
+
+        if (!LITTLE_ENDIAN)
+            val = Short.reverseBytes(val);
+
+        writeShortFast(val);
+
+        shift(2);
+    }
+
+    /** {@inheritDoc} */
+    @Override public void writeShortArray(short[] val) {
+        int cnt = val.length << 1;
+
+        ensureCapacity(pos + cnt);
+
+        if (LITTLE_ENDIAN)
+            copyAndShift(val, SHORT_ARR_OFF, cnt);
+        else {
+            for (short item : val)
+                writeShortFast(Short.reverseBytes(item));
+
+            shift(cnt);
+        }
+    }
+
+    /** {@inheritDoc} */
+    @Override public void writeChar(char val) {
+        ensureCapacity(pos + 2);
+
+        if (!LITTLE_ENDIAN)
+            val = Character.reverseBytes(val);
+
+        writeCharFast(val);
+
+        shift(2);
+    }
+
+    /** {@inheritDoc} */
+    @Override public void writeCharArray(char[] val) {
+        int cnt = val.length << 1;
+
+        ensureCapacity(pos + cnt);
+
+        if (LITTLE_ENDIAN)
+            copyAndShift(val, CHAR_ARR_OFF, cnt);
+        else {
+            for (char item : val)
+                writeCharFast(Character.reverseBytes(item));
+
+            shift(cnt);
+        }
+    }
+
+    /** {@inheritDoc} */
+    @Override public void writeInt(int val) {
+        ensureCapacity(pos + 4);
+
+        if (!LITTLE_ENDIAN)
+            val = Integer.reverseBytes(val);
+
+        writeIntFast(val);
+
+        shift(4);
+    }
+
+    /** {@inheritDoc} */
+    @Override public void writeShort(int pos, short val) {
+        ensureCapacity(pos + 2);
+
+        unsafeWriteShort(pos, val);
+    }
+
+    /** {@inheritDoc} */
+    @Override public void writeInt(int pos, int val) {
+        ensureCapacity(pos + 4);
+
+        unsafeWriteInt(pos, val);
+    }
+
+    /** {@inheritDoc} */
+    @Override public void writeIntArray(int[] val) {
+        int cnt = val.length << 2;
+
+        ensureCapacity(pos + cnt);
+
+        if (LITTLE_ENDIAN)
+            copyAndShift(val, INT_ARR_OFF, cnt);
+        else {
+            for (int item : val)
+                writeIntFast(Integer.reverseBytes(item));
+
+            shift(cnt);
+        }
+    }
+
+    /** {@inheritDoc} */
+    @Override public void writeFloat(float val) {
+        writeInt(Float.floatToIntBits(val));
+    }
+
+    /** {@inheritDoc} */
+    @Override public void writeFloatArray(float[] val) {
+        int cnt = val.length << 2;
+
+        ensureCapacity(pos + cnt);
+
+        if (LITTLE_ENDIAN)
+            copyAndShift(val, FLOAT_ARR_OFF, cnt);
+        else {
+            for (float item : val) {
+                writeIntFast(Integer.reverseBytes(Float.floatToIntBits(item)));
+
+                shift(4);
+            }
+        }
+    }
+
+    /** {@inheritDoc} */
+    @Override public void writeLong(long val) {
+        ensureCapacity(pos + 8);
+
+        if (!LITTLE_ENDIAN)
+            val = Long.reverseBytes(val);
+
+        writeLongFast(val);
+
+        shift(8);
+    }
+
+    /** {@inheritDoc} */
+    @Override public void writeLongArray(long[] val) {
+        int cnt = val.length << 3;
+
+        ensureCapacity(pos + cnt);
+
+        if (LITTLE_ENDIAN)
+            copyAndShift(val, LONG_ARR_OFF, cnt);
+        else {
+            for (long item : val)
+                writeLongFast(Long.reverseBytes(item));
+
+            shift(cnt);
+        }
+    }
+
+    /** {@inheritDoc} */
+    @Override public void writeDouble(double val) {
+        writeLong(Double.doubleToLongBits(val));
+    }
+
+    /** {@inheritDoc} */
+    @Override public void writeDoubleArray(double[] val) {
+        int cnt = val.length << 3;
+
+        ensureCapacity(pos + cnt);
+
+        if (LITTLE_ENDIAN)
+            copyAndShift(val, DOUBLE_ARR_OFF, cnt);
+        else {
+            for (double item : val) {
+                writeLongFast(Long.reverseBytes(Double.doubleToLongBits(item)));
+
+                shift(8);
+            }
+        }
+    }
+
+    /** {@inheritDoc} */
+    @Override public void write(byte[] arr, int off, int len) {
+        ensureCapacity(pos + len);
+
+        copyAndShift(arr, BYTE_ARR_OFF + off, len);
+    }
+
+    /** {@inheritDoc} */
+    @Override public void write(long addr, int cnt) {
+        ensureCapacity(pos + cnt);
+
+        copyAndShift(null, addr, cnt);
+    }
+
+    /** {@inheritDoc} */
+    @Override public void position(int pos) {
+        ensureCapacity(pos);
+
+        unsafePosition(pos);
+    }
+
+    /** {@inheritDoc} */
+    @Override public long offheapPointer() {
+        return 0;
+    }
+
+    /** {@inheritDoc} */
+    @Override public void unsafeEnsure(int cap) {
+        ensureCapacity(pos + cap);
+    }
+
+    /** {@inheritDoc} */
+    @Override public void unsafePosition(int pos) {
+        this.pos = pos;
+    }
+
+    /** {@inheritDoc} */
+    @Override public void unsafeWriteBoolean(boolean val) {
+        unsafeWriteByte(val ? BYTE_ONE : BYTE_ZERO);
+    }
+
+    /** {@inheritDoc} */
+    @Override public void unsafeWriteFloat(float val) {
+        unsafeWriteInt(Float.floatToIntBits(val));
+    }
+
+    /** {@inheritDoc} */
+    @Override public void unsafeWriteDouble(double val) {
+        unsafeWriteLong(Double.doubleToLongBits(val));
+    }
+
+    /**
+     * Calculate new capacity.
+     *
+     * @param curCap Current capacity.
+     * @param reqCap Required capacity.
+     * @return New capacity.
+     */
+    protected static int capacity(int curCap, int reqCap) {
+        int newCap;
+
+        if (reqCap < MIN_CAP)
+            newCap = MIN_CAP;
+        else {
+            newCap = curCap << 1;
+
+            if (newCap < reqCap)
+                newCap = reqCap;
+        }
+
+        return newCap;
+    }
+
+    /**
+     * Write next byte to the stream.
+     *
+     * @param val Value.
+     */
+    protected abstract void writeByteAndShift(byte val);
+
+    /**
+     * Copy source object to the stream shift position afterwards.
+     *
+     * @param src Source.
+     * @param off Offset.
+     * @param len Length.
+     */
+    protected abstract void copyAndShift(Object src, long off, int len);
+
+    /**
+     * Write short value (fast path).
+     *
+     * @param val Short value.
+     */
+    protected abstract void writeShortFast(short val);
+
+    /**
+     * Write char value (fast path).
+     *
+     * @param val Char value.
+     */
+    protected abstract void writeCharFast(char val);
+
+    /**
+     * Write int value (fast path).
+     *
+     * @param val Int value.
+     */
+    protected abstract void writeIntFast(int val);
+
+    /**
+     * Write long value (fast path).
+     *
+     * @param val Long value.
+     */
+    protected abstract void writeLongFast(long val);
+
+    /**
+     * Ensure capacity.
+     *
+     * @param cnt Required byte count.
+     */
+    protected abstract void ensureCapacity(int cnt);
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/1dbf20e0/modules/core/src/main/java/org/apache/ignite/internal/binary/streams/PortableAbstractStream.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/binary/streams/PortableAbstractStream.java b/modules/core/src/main/java/org/apache/ignite/internal/binary/streams/PortableAbstractStream.java
new file mode 100644
index 0000000..fcc32cb
--- /dev/null
+++ b/modules/core/src/main/java/org/apache/ignite/internal/binary/streams/PortableAbstractStream.java
@@ -0,0 +1,80 @@
+/*
+ * 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.binary.streams;
+
+import java.nio.ByteOrder;
+import org.apache.ignite.internal.util.GridUnsafe;
+import sun.misc.Unsafe;
+
+/**
+ * Portable abstract stream.
+ */
+public abstract class PortableAbstractStream implements PortableStream {
+    /** Byte: zero. */
+    protected static final byte BYTE_ZERO = 0;
+
+    /** Byte: one. */
+    protected static final byte BYTE_ONE = 1;
+
+    /** Whether little endian is used on the platform. */
+    protected static final boolean LITTLE_ENDIAN = ByteOrder.nativeOrder() == ByteOrder.LITTLE_ENDIAN;
+
+    /** Unsafe instance. */
+    protected static final Unsafe UNSAFE = GridUnsafe.unsafe();
+
+    /** Array offset: boolean. */
+    protected static final long BOOLEAN_ARR_OFF = UNSAFE.arrayBaseOffset(boolean[].class);
+
+    /** Array offset: byte. */
+    protected static final long BYTE_ARR_OFF = UNSAFE.arrayBaseOffset(byte[].class);
+
+    /** Array offset: short. */
+    protected static final long SHORT_ARR_OFF = UNSAFE.arrayBaseOffset(short[].class);
+
+    /** Array offset: char. */
+    protected static final long CHAR_ARR_OFF = UNSAFE.arrayBaseOffset(char[].class);
+
+    /** Array offset: int. */
+    protected static final long INT_ARR_OFF = UNSAFE.arrayBaseOffset(int[].class);
+
+    /** Array offset: float. */
+    protected static final long FLOAT_ARR_OFF = UNSAFE.arrayBaseOffset(float[].class);
+
+    /** Array offset: long. */
+    protected static final long LONG_ARR_OFF = UNSAFE.arrayBaseOffset(long[].class);
+
+    /** Array offset: double. */
+    protected static final long DOUBLE_ARR_OFF = UNSAFE.arrayBaseOffset(double[].class);
+
+    /** Position. */
+    protected int pos;
+
+    /** {@inheritDoc} */
+    @Override public int position() {
+        return pos;
+    }
+
+    /**
+     * Shift position.
+     *
+     * @param cnt Byte count.
+     */
+    protected void shift(int cnt) {
+        pos += cnt;
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/1dbf20e0/modules/core/src/main/java/org/apache/ignite/internal/binary/streams/PortableHeapInputStream.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/binary/streams/PortableHeapInputStream.java b/modules/core/src/main/java/org/apache/ignite/internal/binary/streams/PortableHeapInputStream.java
new file mode 100644
index 0000000..d8717ce
--- /dev/null
+++ b/modules/core/src/main/java/org/apache/ignite/internal/binary/streams/PortableHeapInputStream.java
@@ -0,0 +1,166 @@
+/*
+ * 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.binary.streams;
+
+import java.util.Arrays;
+
+/**
+ * Portable off-heap input stream.
+ */
+public final class PortableHeapInputStream extends PortableAbstractInputStream {
+    /**
+     * Create stream with pointer set at the given position.
+     *
+     * @param data Data.
+     * @param pos Position.
+     * @return Stream.
+     */
+    public static PortableHeapInputStream create(byte[] data, int pos) {
+        assert pos < data.length;
+
+        PortableHeapInputStream stream = new PortableHeapInputStream(data);
+
+        stream.pos = pos;
+
+        return stream;
+    }
+
+    /** Data. */
+    private byte[] data;
+
+    /**
+     * Constructor.
+     *
+     * @param data Data.
+     */
+    public PortableHeapInputStream(byte[] data) {
+        this.data = data;
+
+        len = data.length;
+    }
+
+    /**
+     * @return Copy of this stream.
+     */
+    public PortableHeapInputStream copy() {
+        PortableHeapInputStream in = new PortableHeapInputStream(Arrays.copyOf(data, data.length));
+
+        in.position(pos);
+
+        return in;
+    }
+
+    /**
+     * Method called from JNI to resize stream.
+     *
+     * @param len Required length.
+     * @return Underlying byte array.
+     */
+    public byte[] resize(int len) {
+        if (data.length < len) {
+            byte[] data0 = new byte[len];
+
+            UNSAFE.copyMemory(data, BYTE_ARR_OFF, data0, BYTE_ARR_OFF, data.length);
+
+            data = data0;
+        }
+
+        return data;
+    }
+
+    /** {@inheritDoc} */
+    @Override public int remaining() {
+        return data.length - pos;
+    }
+
+    /** {@inheritDoc} */
+    @Override public byte[] array() {
+        return data;
+    }
+
+    /** {@inheritDoc} */
+    @Override public byte[] arrayCopy() {
+        byte[] res = new byte[len];
+
+        UNSAFE.copyMemory(data, BYTE_ARR_OFF, res, BYTE_ARR_OFF, res.length);
+
+        return res;
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean hasArray() {
+        return true;
+    }
+
+    /** {@inheritDoc} */
+    @Override protected byte readByteAndShift() {
+        return data[pos++];
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void copyAndShift(Object target, long off, int len) {
+        UNSAFE.copyMemory(data, BYTE_ARR_OFF + pos, target, off, len);
+
+        shift(len);
+    }
+
+    /** {@inheritDoc} */
+    @Override protected short readShortFast() {
+        return UNSAFE.getShort(data, BYTE_ARR_OFF + pos);
+    }
+
+    /** {@inheritDoc} */
+    @Override protected char readCharFast() {
+        return UNSAFE.getChar(data, BYTE_ARR_OFF + pos);
+    }
+
+    /** {@inheritDoc} */
+    @Override protected int readIntFast() {
+        return UNSAFE.getInt(data, BYTE_ARR_OFF + pos);
+    }
+
+    /** {@inheritDoc} */
+    @Override protected long readLongFast() {
+        return UNSAFE.getLong(data, BYTE_ARR_OFF + pos);
+    }
+
+    /** {@inheritDoc} */
+    @Override protected byte readBytePositioned0(int pos) {
+        return UNSAFE.getByte(data, BYTE_ARR_OFF + pos);
+    }
+
+    /** {@inheritDoc} */
+    @Override protected short readShortPositioned0(int pos) {
+        short res = UNSAFE.getShort(data, BYTE_ARR_OFF + pos);
+
+        if (!LITTLE_ENDIAN)
+            res = Short.reverseBytes(res);
+
+        return res;
+    }
+
+    /** {@inheritDoc} */
+    @Override protected int readIntPositioned0(int pos) {
+        int res = UNSAFE.getInt(data, BYTE_ARR_OFF + pos);
+
+        if (!LITTLE_ENDIAN)
+            res = Integer.reverseBytes(res);
+
+        return res;
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/1dbf20e0/modules/core/src/main/java/org/apache/ignite/internal/binary/streams/PortableHeapOutputStream.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/binary/streams/PortableHeapOutputStream.java b/modules/core/src/main/java/org/apache/ignite/internal/binary/streams/PortableHeapOutputStream.java
new file mode 100644
index 0000000..8f9ca4a
--- /dev/null
+++ b/modules/core/src/main/java/org/apache/ignite/internal/binary/streams/PortableHeapOutputStream.java
@@ -0,0 +1,176 @@
+/*
+ * 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.binary.streams;
+
+/**
+ * Portable heap output stream.
+ */
+public final class PortableHeapOutputStream extends PortableAbstractOutputStream {
+    /** Allocator. */
+    private final PortableMemoryAllocatorChunk chunk;
+
+    /** Data. */
+    private byte[] data;
+
+    /**
+     * Constructor.
+     *
+     * @param cap Initial capacity.
+     */
+    public PortableHeapOutputStream(int cap) {
+        this(cap, PortableMemoryAllocator.INSTANCE.chunk());
+    }
+
+    /**
+     * Constructor.
+     *
+     * @param cap Capacity.
+     * @param chunk Chunk.
+     */
+    public PortableHeapOutputStream(int cap, PortableMemoryAllocatorChunk chunk) {
+        this.chunk = chunk;
+
+        data = chunk.allocate(cap);
+    }
+
+    /** {@inheritDoc} */
+    @Override public void close() {
+        chunk.release(data, pos);
+    }
+
+    /** {@inheritDoc} */
+    @Override public void ensureCapacity(int cnt) {
+        if (cnt > data.length) {
+            int newCap = capacity(data.length, cnt);
+
+            data = chunk.reallocate(data, newCap);
+        }
+    }
+
+    /** {@inheritDoc} */
+    @Override public byte[] array() {
+        return data;
+    }
+
+    /** {@inheritDoc} */
+    @Override public byte[] arrayCopy() {
+        byte[] res = new byte[pos];
+
+        UNSAFE.copyMemory(data, BYTE_ARR_OFF, res, BYTE_ARR_OFF, pos);
+
+        return res;
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean hasArray() {
+        return true;
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void writeByteAndShift(byte val) {
+        data[pos++] = val;
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void copyAndShift(Object src, long off, int len) {
+        UNSAFE.copyMemory(src, off, data, BYTE_ARR_OFF + pos, len);
+
+        shift(len);
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void writeShortFast(short val) {
+        UNSAFE.putShort(data, BYTE_ARR_OFF + pos, val);
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void writeCharFast(char val) {
+        UNSAFE.putChar(data, BYTE_ARR_OFF + pos, val);
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void writeIntFast(int val) {
+        UNSAFE.putInt(data, BYTE_ARR_OFF + pos, val);
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void writeLongFast(long val) {
+        UNSAFE.putLong(data, BYTE_ARR_OFF + pos, val);
+    }
+
+    /** {@inheritDoc} */
+    @Override public void unsafeWriteByte(byte val) {
+        UNSAFE.putByte(data, BYTE_ARR_OFF + pos++, val);
+    }
+
+    /** {@inheritDoc} */
+    @Override public void unsafeWriteShort(short val) {
+        if (!LITTLE_ENDIAN)
+            val = Short.reverseBytes(val);
+
+        UNSAFE.putShort(data, BYTE_ARR_OFF + pos, val);
+
+        shift(2);
+    }
+
+    /** {@inheritDoc} */
+    @Override public void unsafeWriteShort(int pos, short val) {
+        if (!LITTLE_ENDIAN)
+            val = Short.reverseBytes(val);
+
+        UNSAFE.putShort(data, BYTE_ARR_OFF + pos, val);
+    }
+
+    /** {@inheritDoc} */
+    @Override public void unsafeWriteChar(char val) {
+        if (!LITTLE_ENDIAN)
+            val = Character.reverseBytes(val);
+
+        UNSAFE.putChar(data, BYTE_ARR_OFF + pos, val);
+
+        shift(2);
+    }
+
+    /** {@inheritDoc} */
+    @Override public void unsafeWriteInt(int val) {
+        if (!LITTLE_ENDIAN)
+            val = Integer.reverseBytes(val);
+
+        UNSAFE.putInt(data, BYTE_ARR_OFF + pos, val);
+
+        shift(4);
+    }
+
+    /** {@inheritDoc} */
+    @Override public void unsafeWriteInt(int pos, int val) {
+        if (!LITTLE_ENDIAN)
+            val = Integer.reverseBytes(val);
+
+        UNSAFE.putInt(data, BYTE_ARR_OFF + pos, val);
+    }
+
+    /** {@inheritDoc} */
+    @Override public void unsafeWriteLong(long val) {
+        if (!LITTLE_ENDIAN)
+            val = Long.reverseBytes(val);
+
+        UNSAFE.putLong(data, BYTE_ARR_OFF + pos, val);
+
+        shift(8);
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/1dbf20e0/modules/core/src/main/java/org/apache/ignite/internal/binary/streams/PortableInputStream.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/binary/streams/PortableInputStream.java b/modules/core/src/main/java/org/apache/ignite/internal/binary/streams/PortableInputStream.java
new file mode 100644
index 0000000..cf71dc7
--- /dev/null
+++ b/modules/core/src/main/java/org/apache/ignite/internal/binary/streams/PortableInputStream.java
@@ -0,0 +1,163 @@
+/*
+ * 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.binary.streams;
+
+import org.apache.ignite.internal.binary.PortablePositionReadable;
+import org.apache.ignite.internal.binary.PortablePositionReadable;
+
+/**
+ * Portable input stream.
+ */
+public interface PortableInputStream extends PortableStream, PortablePositionReadable {
+    /**
+     * Read byte value.
+     *
+     * @return Byte value.
+     */
+    public byte readByte();
+
+    /**
+     * Read byte array.
+     *
+     * @param cnt Expected item count.
+     * @return Byte array.
+     */
+    public byte[] readByteArray(int cnt);
+
+    /**
+     * Reads {@code cnt} of bytes into byte array.
+     *
+     * @param arr Expected item count.
+     * @param off offset
+     * @param cnt number of bytes to read.
+     * @return actual length read.
+     */
+    public int read(byte[] arr, int off, int cnt);
+
+    /**
+     * Read boolean value.
+     *
+     * @return Boolean value.
+     */
+    public boolean readBoolean();
+
+    /**
+     * Read boolean array.
+     *
+     * @param cnt Expected item count.
+     * @return Boolean array.
+     */
+    public boolean[] readBooleanArray(int cnt);
+
+    /**
+     * Read short value.
+     *
+     * @return Short value.
+     */
+    public short readShort();
+
+    /**
+     * Read short array.
+     *
+     * @param cnt Expected item count.
+     * @return Short array.
+     */
+    public short[] readShortArray(int cnt);
+
+    /**
+     * Read char value.
+     *
+     * @return Char value.
+     */
+    public char readChar();
+
+    /**
+     * Read char array.
+     *
+     * @param cnt Expected item count.
+     * @return Char array.
+     */
+    public char[] readCharArray(int cnt);
+
+    /**
+     * Read int value.
+     *
+     * @return Int value.
+     */
+    public int readInt();
+
+    /**
+     * Read int array.
+     *
+     * @param cnt Expected item count.
+     * @return Int array.
+     */
+    public int[] readIntArray(int cnt);
+
+    /**
+     * Read float value.
+     *
+     * @return Float value.
+     */
+    public float readFloat();
+
+    /**
+     * Read float array.
+     *
+     * @param cnt Expected item count.
+     * @return Float array.
+     */
+    public float[] readFloatArray(int cnt);
+
+    /**
+     * Read long value.
+     *
+     * @return Long value.
+     */
+    public long readLong();
+
+    /**
+     * Read long array.
+     *
+     * @param cnt Expected item count.
+     * @return Long array.
+     */
+    public long[] readLongArray(int cnt);
+
+    /**
+     * Read double value.
+     *
+     * @return Double value.
+     */
+    public double readDouble();
+
+    /**
+     * Read double array.
+     *
+     * @param cnt Expected item count.
+     * @return Double array.
+     */
+    public double[] readDoubleArray(int cnt);
+
+    /**
+     * Gets amount of remaining data in bytes.
+     *
+     * @return Remaining data.
+     */
+    public int remaining();
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/1dbf20e0/modules/core/src/main/java/org/apache/ignite/internal/binary/streams/PortableMemoryAllocator.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/binary/streams/PortableMemoryAllocator.java b/modules/core/src/main/java/org/apache/ignite/internal/binary/streams/PortableMemoryAllocator.java
new file mode 100644
index 0000000..f20a7bc
--- /dev/null
+++ b/modules/core/src/main/java/org/apache/ignite/internal/binary/streams/PortableMemoryAllocator.java
@@ -0,0 +1,57 @@
+/*
+ * 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.binary.streams;
+
+/**
+ * Thread-local memory allocator.
+ */
+public final class PortableMemoryAllocator {
+    /** Memory allocator instance. */
+    public static final PortableMemoryAllocator INSTANCE = new PortableMemoryAllocator();
+
+    /** Holders. */
+    private static final ThreadLocal<PortableMemoryAllocatorChunk> holders = new ThreadLocal<>();
+
+    /**
+     * Ensures singleton.
+     */
+    private PortableMemoryAllocator() {
+        // No-op.
+    }
+
+    public PortableMemoryAllocatorChunk chunk() {
+        PortableMemoryAllocatorChunk holder = holders.get();
+
+        if (holder == null)
+            holders.set(holder = new PortableMemoryAllocatorChunk());
+
+        return holder;
+    }
+
+    /**
+     * Checks whether a thread-local array is acquired or not.
+     * The function is used by Unit tests.
+     *
+     * @return {@code true} if acquired {@code false} otherwise.
+     */
+    public boolean isAcquired() {
+        PortableMemoryAllocatorChunk holder = holders.get();
+
+        return holder != null && holder.isAcquired();
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/1dbf20e0/modules/core/src/main/java/org/apache/ignite/internal/binary/streams/PortableMemoryAllocatorChunk.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/binary/streams/PortableMemoryAllocatorChunk.java b/modules/core/src/main/java/org/apache/ignite/internal/binary/streams/PortableMemoryAllocatorChunk.java
new file mode 100644
index 0000000..749a0b4
--- /dev/null
+++ b/modules/core/src/main/java/org/apache/ignite/internal/binary/streams/PortableMemoryAllocatorChunk.java
@@ -0,0 +1,117 @@
+/*
+ * 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.binary.streams;
+
+import org.apache.ignite.internal.util.GridUnsafe;
+import org.apache.ignite.internal.util.typedef.internal.U;
+import sun.misc.Unsafe;
+
+import static org.apache.ignite.IgniteSystemProperties.IGNITE_MARSHAL_BUFFERS_RECHECK;
+
+/**
+ * Memory allocator chunk.
+ */
+public class PortableMemoryAllocatorChunk {
+    /** Unsafe instance. */
+    protected static final Unsafe UNSAFE = GridUnsafe.unsafe();
+
+    /** Array offset: byte. */
+    protected static final long BYTE_ARR_OFF = UNSAFE.arrayBaseOffset(byte[].class);
+
+    /** Buffer size re-check frequency. */
+    private static final Long CHECK_FREQ = Long.getLong(IGNITE_MARSHAL_BUFFERS_RECHECK, 10000);
+
+    /** Data array */
+    private byte[] data;
+
+    /** Max message size detected between checks. */
+    private int maxMsgSize;
+
+    /** Last time array size is checked. */
+    private long lastCheck = U.currentTimeMillis();
+
+    /** Whether the holder is acquired or not. */
+    private boolean acquired;
+
+    /**
+     * Allocate.
+     *
+     * @param size Desired size.
+     * @return Data.
+     */
+    public byte[] allocate(int size) {
+        if (acquired)
+            return new byte[size];
+
+        acquired = true;
+
+        if (data == null || size > data.length)
+            data = new byte[size];
+
+        return data;
+    }
+
+    /**
+     * Reallocate.
+     *
+     * @param data Old data.
+     * @param size Size.
+     * @return New data.
+     */
+    public byte[] reallocate(byte[] data, int size) {
+        byte[] newData = new byte[size];
+
+        if (this.data == data)
+            this.data = newData;
+
+        UNSAFE.copyMemory(data, BYTE_ARR_OFF, newData, BYTE_ARR_OFF, data.length);
+
+        return newData;
+    }
+
+    /**
+     * Shrinks array size if needed.
+     */
+    public void release(byte[] data, int maxMsgSize) {
+        if (this.data != data)
+            return;
+
+        if (maxMsgSize > this.maxMsgSize)
+            this.maxMsgSize = maxMsgSize;
+
+        this.acquired = false;
+
+        long now = U.currentTimeMillis();
+
+        if (now - this.lastCheck >= CHECK_FREQ) {
+            int halfSize = data.length >> 1;
+
+            if (this.maxMsgSize < halfSize)
+                this.data = new byte[halfSize];
+
+            this.lastCheck = now;
+        }
+    }
+
+    /**
+     * @return {@code True} if acquired.
+     */
+    public boolean isAcquired() {
+        return acquired;
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/1dbf20e0/modules/core/src/main/java/org/apache/ignite/internal/binary/streams/PortableOffheapInputStream.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/binary/streams/PortableOffheapInputStream.java b/modules/core/src/main/java/org/apache/ignite/internal/binary/streams/PortableOffheapInputStream.java
new file mode 100644
index 0000000..2a4d7d7
--- /dev/null
+++ b/modules/core/src/main/java/org/apache/ignite/internal/binary/streams/PortableOffheapInputStream.java
@@ -0,0 +1,144 @@
+/*
+ * 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.binary.streams;
+
+/**
+ * Portable off-heap input stream.
+ */
+public class PortableOffheapInputStream extends PortableAbstractInputStream {
+    /** Pointer. */
+    private final long ptr;
+
+    /** Capacity. */
+    private final int cap;
+
+    /** */
+    private boolean forceHeap;
+
+    /**
+     * Constructor.
+     *
+     * @param ptr Pointer.
+     * @param cap Capacity.
+     */
+    public PortableOffheapInputStream(long ptr, int cap) {
+        this(ptr, cap, false);
+    }
+
+    /**
+     * Constructor.
+     *
+     * @param ptr Pointer.
+     * @param cap Capacity.
+     * @param forceHeap If {@code true} method {@link #offheapPointer} returns 0 and unmarshalling will
+     *        create heap-based objects.
+     */
+    public PortableOffheapInputStream(long ptr, int cap, boolean forceHeap) {
+        this.ptr = ptr;
+        this.cap = cap;
+        this.forceHeap = forceHeap;
+
+        len = cap;
+    }
+
+    /** {@inheritDoc} */
+    @Override public int remaining() {
+        return cap - pos;
+    }
+
+    /** {@inheritDoc} */
+    @Override public byte[] array() {
+        return arrayCopy();
+    }
+
+    /** {@inheritDoc} */
+    @Override public byte[] arrayCopy() {
+        byte[] res = new byte[len];
+
+        UNSAFE.copyMemory(null, ptr, res, BYTE_ARR_OFF, res.length);
+
+        return res;
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean hasArray() {
+        return false;
+    }
+
+    /** {@inheritDoc} */
+    @Override protected byte readByteAndShift() {
+        return UNSAFE.getByte(ptr + pos++);
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void copyAndShift(Object target, long off, int len) {
+        UNSAFE.copyMemory(null, ptr + pos, target, off, len);
+
+        shift(len);
+    }
+
+    /** {@inheritDoc} */
+    @Override protected short readShortFast() {
+        return UNSAFE.getShort(ptr + pos);
+    }
+
+    /** {@inheritDoc} */
+    @Override protected char readCharFast() {
+        return UNSAFE.getChar(ptr + pos);
+    }
+
+    /** {@inheritDoc} */
+    @Override protected int readIntFast() {
+        return UNSAFE.getInt(ptr + pos);
+    }
+
+    /** {@inheritDoc} */
+    @Override protected long readLongFast() {
+        return UNSAFE.getLong(ptr + pos);
+    }
+
+    /** {@inheritDoc} */
+    @Override protected byte readBytePositioned0(int pos) {
+        return UNSAFE.getByte(ptr + pos);
+    }
+
+    /** {@inheritDoc} */
+    @Override protected short readShortPositioned0(int pos) {
+        short res = UNSAFE.getShort(ptr + pos);
+
+        if (!LITTLE_ENDIAN)
+            res = Short.reverseBytes(res);
+
+        return res;
+    }
+
+    /** {@inheritDoc} */
+    @Override protected int readIntPositioned0(int pos) {
+        int res = UNSAFE.getInt(ptr + pos);
+
+        if (!LITTLE_ENDIAN)
+            res = Integer.reverseBytes(res);
+
+        return res;
+    }
+
+    /** {@inheritDoc} */
+    @Override public long offheapPointer() {
+        return forceHeap ? 0 : ptr;
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/1dbf20e0/modules/core/src/main/java/org/apache/ignite/internal/binary/streams/PortableOffheapOutputStream.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/binary/streams/PortableOffheapOutputStream.java b/modules/core/src/main/java/org/apache/ignite/internal/binary/streams/PortableOffheapOutputStream.java
new file mode 100644
index 0000000..9bcb1f4
--- /dev/null
+++ b/modules/core/src/main/java/org/apache/ignite/internal/binary/streams/PortableOffheapOutputStream.java
@@ -0,0 +1,222 @@
+/*
+ * 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.binary.streams;
+
+/**
+ * Portable offheap output stream.
+ */
+public class PortableOffheapOutputStream extends PortableAbstractOutputStream {
+    /** Pointer. */
+    private long ptr;
+
+    /** Length of bytes that cen be used before resize is necessary. */
+    private int cap;
+
+    /**
+     * Constructor.
+     *
+     * @param cap Capacity.
+     */
+    public PortableOffheapOutputStream(int cap) {
+        this(0, cap);
+    }
+
+    /**
+     * Constructor.
+     *
+     * @param ptr Pointer to existing address.
+     * @param cap Capacity.
+     */
+    public PortableOffheapOutputStream(long ptr, int cap) {
+        this.ptr = ptr == 0 ? allocate(cap) : ptr;
+
+        this.cap = cap;
+    }
+
+    /** {@inheritDoc} */
+    @Override public void close() {
+        release(ptr);
+    }
+
+    /** {@inheritDoc} */
+    @Override public void ensureCapacity(int cnt) {
+        if (cnt > cap) {
+            int newCap = capacity(cap, cnt);
+
+            ptr = reallocate(ptr, newCap);
+
+            cap = newCap;
+        }
+    }
+
+    /** {@inheritDoc} */
+    @Override public byte[] array() {
+        return arrayCopy();
+    }
+
+    /** {@inheritDoc} */
+    @Override public byte[] arrayCopy() {
+        byte[] res = new byte[pos];
+
+        UNSAFE.copyMemory(null, ptr, res, BYTE_ARR_OFF, pos);
+
+        return res;
+    }
+
+    /**
+     * @return Pointer.
+     */
+    public long pointer() {
+        return ptr;
+    }
+
+    /**
+     * @return Capacity.
+     */
+    public int capacity() {
+        return cap;
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void writeByteAndShift(byte val) {
+        UNSAFE.putByte(ptr + pos++, val);
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void copyAndShift(Object src, long offset, int len) {
+        UNSAFE.copyMemory(src, offset, null, ptr + pos, len);
+
+        shift(len);
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void writeShortFast(short val) {
+        UNSAFE.putShort(ptr + pos, val);
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void writeCharFast(char val) {
+        UNSAFE.putChar(ptr + pos, val);
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void writeIntFast(int val) {
+        UNSAFE.putInt(ptr + pos, val);
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void writeLongFast(long val) {
+        UNSAFE.putLong(ptr + pos, val);
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean hasArray() {
+        return false;
+    }
+
+    /** {@inheritDoc} */
+    @Override public void unsafeWriteByte(byte val) {
+        UNSAFE.putByte(ptr + pos++, val);
+    }
+
+    /** {@inheritDoc} */
+    @Override public void unsafeWriteShort(short val) {
+        if (!LITTLE_ENDIAN)
+            val = Short.reverseBytes(val);
+
+        UNSAFE.putShort(ptr + pos, val);
+
+        shift(2);
+    }
+
+    /** {@inheritDoc} */
+    @Override public void unsafeWriteShort(int pos, short val) {
+        if (!LITTLE_ENDIAN)
+            val = Short.reverseBytes(val);
+
+        UNSAFE.putShort(ptr + pos, val);
+    }
+
+    /** {@inheritDoc} */
+    @Override public void unsafeWriteChar(char val) {
+        if (!LITTLE_ENDIAN)
+            val = Character.reverseBytes(val);
+
+        UNSAFE.putChar(ptr + pos, val);
+
+        shift(2);
+    }
+
+    /** {@inheritDoc} */
+    @Override public void unsafeWriteInt(int val) {
+        if (!LITTLE_ENDIAN)
+            val = Integer.reverseBytes(val);
+
+        UNSAFE.putInt(ptr + pos, val);
+
+        shift(4);
+    }
+
+    /** {@inheritDoc} */
+    @Override public void unsafeWriteInt(int pos, int val) {
+        if (!LITTLE_ENDIAN)
+            val = Integer.reverseBytes(val);
+
+        UNSAFE.putInt(ptr + pos, val);
+    }
+
+    /** {@inheritDoc} */
+    @Override public void unsafeWriteLong(long val) {
+        if (!LITTLE_ENDIAN)
+            val = Long.reverseBytes(val);
+
+        UNSAFE.putLong(ptr + pos, val);
+
+        shift(8);
+    }
+
+    /**
+     * Allocate memory.
+     *
+     * @param cap Capacity.
+     * @return Pointer.
+     */
+    protected long allocate(int cap) {
+        return UNSAFE.allocateMemory(cap);
+    }
+
+    /**
+     * Reallocate memory.
+     *
+     * @param ptr Old pointer.
+     * @param cap Capacity.
+     * @return New pointer.
+     */
+    protected long reallocate(long ptr, int cap) {
+        return UNSAFE.reallocateMemory(ptr, cap);
+    }
+
+    /**
+     * Release memory.
+     *
+     * @param ptr Pointer.
+     */
+    protected void release(long ptr) {
+        UNSAFE.freeMemory(ptr);
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/1dbf20e0/modules/core/src/main/java/org/apache/ignite/internal/binary/streams/PortableOutputStream.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/binary/streams/PortableOutputStream.java b/modules/core/src/main/java/org/apache/ignite/internal/binary/streams/PortableOutputStream.java
new file mode 100644
index 0000000..a686e54
--- /dev/null
+++ b/modules/core/src/main/java/org/apache/ignite/internal/binary/streams/PortableOutputStream.java
@@ -0,0 +1,259 @@
+/*
+ * 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.binary.streams;
+
+/**
+ * Portable output stream.
+ */
+public interface PortableOutputStream extends PortableStream, AutoCloseable {
+    /**
+     * Write byte value.
+     *
+     * @param val Byte value.
+     */
+    public void writeByte(byte val);
+
+    /**
+     * Write byte array.
+     *
+     * @param val Byte array.
+     */
+    public void writeByteArray(byte[] val);
+
+    /**
+     * Write boolean value.
+     *
+     * @param val Boolean value.
+     */
+    public void writeBoolean(boolean val);
+
+    /**
+     * Write boolean array.
+     *
+     * @param val Boolean array.
+     */
+    public void writeBooleanArray(boolean[] val);
+
+    /**
+     * Write short value.
+     *
+     * @param val Short value.
+     */
+    public void writeShort(short val);
+
+    /**
+     * Write short array.
+     *
+     * @param val Short array.
+     */
+    public void writeShortArray(short[] val);
+
+    /**
+     * Write char value.
+     *
+     * @param val Char value.
+     */
+    public void writeChar(char val);
+
+    /**
+     * Write char array.
+     *
+     * @param val Char array.
+     */
+    public void writeCharArray(char[] val);
+
+    /**
+     * Write int value.
+     *
+     * @param val Int value.
+     */
+    public void writeInt(int val);
+
+    /**
+     * Write short value at the given position.
+     *
+     * @param pos Position.
+     * @param val Value.
+     */
+    public void writeShort(int pos, short val);
+
+    /**
+     * Write int value to the given position.
+     *
+     * @param pos Position.
+     * @param val Value.
+     */
+    public void writeInt(int pos, int val);
+
+    /**
+     * Write int array.
+     *
+     * @param val Int array.
+     */
+    public void writeIntArray(int[] val);
+
+    /**
+     * Write float value.
+     *
+     * @param val Float value.
+     */
+    public void writeFloat(float val);
+
+    /**
+     * Write float array.
+     *
+     * @param val Float array.
+     */
+    public void writeFloatArray(float[] val);
+
+    /**
+     * Write long value.
+     *
+     * @param val Long value.
+     */
+    public void writeLong(long val);
+
+    /**
+     * Write long array.
+     *
+     * @param val Long array.
+     */
+    public void writeLongArray(long[] val);
+
+    /**
+     * Write double value.
+     *
+     * @param val Double value.
+     */
+    public void writeDouble(double val);
+
+    /**
+     * Write double array.
+     *
+     * @param val Double array.
+     */
+    public void writeDoubleArray(double[] val);
+
+    /**
+     * Write byte array.
+     *
+     * @param arr Array.
+     * @param off Offset.
+     * @param len Length.
+     */
+    public void write(byte[] arr, int off, int len);
+
+    /**
+     * Write data from unmanaged memory.
+     *
+     * @param addr Address.
+     * @param cnt Count.
+     */
+    public void write(long addr, int cnt);
+
+    /**
+     * Close the stream releasing resources.
+     */
+    @Override public void close();
+
+    /**
+     * Set position in unsafe mode.
+     *
+     * @param pos Position.
+     */
+    public void unsafePosition(int pos);
+
+    /**
+     * Ensure capacity for unsafe writes.
+     *
+     * @param cap Capacity.
+     */
+    public void unsafeEnsure(int cap);
+
+    /**
+     * Write byte in unsafe mode.
+     *
+     * @param val Value.
+     */
+    public void unsafeWriteByte(byte val);
+
+    /**
+     * Write boolean in unsafe mode.
+     *
+     * @param val Value.
+     */
+    public void unsafeWriteBoolean(boolean val);
+
+    /**
+     * Write short in unsafe mode.
+     *
+     * @param val Value.
+     */
+    public void unsafeWriteShort(short val);
+
+    /**
+     * Write short in unsafe mode.
+     *
+     * @param pos Position.
+     * @param val Value.
+     */
+    public void unsafeWriteShort(int pos, short val);
+
+    /**
+     * Write char in unsafe mode.
+     *
+     * @param val Value.
+     */
+    public void unsafeWriteChar(char val);
+
+    /**
+     * Write int in unsafe mode.
+     *
+     * @param val Value.
+     */
+    public void unsafeWriteInt(int val);
+
+    /**
+     * Write int in unsafe mode.
+     *
+     * @param pos Position.
+     * @param val Value.
+     */
+    public void unsafeWriteInt(int pos, int val);
+
+    /**
+     * Write long in unsafe mode.
+     *
+     * @param val Value.
+     */
+    public void unsafeWriteLong(long val);
+
+    /**
+     * Write float in unsafe mode.
+     *
+     * @param val Value.
+     */
+    public void unsafeWriteFloat(float val);
+
+    /**
+     * Write double in unsafe mode.
+     *
+     * @param val Value.
+     */
+    public void unsafeWriteDouble(double val);
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/1dbf20e0/modules/core/src/main/java/org/apache/ignite/internal/binary/streams/PortableStream.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/binary/streams/PortableStream.java b/modules/core/src/main/java/org/apache/ignite/internal/binary/streams/PortableStream.java
new file mode 100644
index 0000000..18d4609
--- /dev/null
+++ b/modules/core/src/main/java/org/apache/ignite/internal/binary/streams/PortableStream.java
@@ -0,0 +1,53 @@
+/*
+ * 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.binary.streams;
+
+/**
+ * Portable stream.
+ */
+public interface PortableStream {
+    /**
+     * @return Position.
+     */
+    public int position();
+
+    /**
+     * @param pos Position.
+     */
+    public void position(int pos);
+
+    /**
+     * @return Underlying array.
+     */
+    public byte[] array();
+
+    /**
+     * @return Copy of data in the stream.
+     */
+    public byte[] arrayCopy();
+
+    /**
+     * @return Offheap pointer if stream is offheap based, otherwise {@code 0}.
+     */
+    public long offheapPointer();
+
+    /**
+     * @return {@code True} is stream is array based.
+     */
+    public boolean hasArray();
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/1dbf20e0/modules/core/src/main/java/org/apache/ignite/internal/binary/streams/package-info.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/binary/streams/package-info.java b/modules/core/src/main/java/org/apache/ignite/internal/binary/streams/package-info.java
new file mode 100644
index 0000000..2a6ad62
--- /dev/null
+++ b/modules/core/src/main/java/org/apache/ignite/internal/binary/streams/package-info.java
@@ -0,0 +1,22 @@
+/*
+ * 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 description. -->
+ * Contains portable APIs implementation for streams.
+ */
+package org.apache.ignite.internal.binary.streams;

http://git-wip-us.apache.org/repos/asf/ignite/blob/1dbf20e0/modules/core/src/main/java/org/apache/ignite/internal/managers/communication/GridIoMessageFactory.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/managers/communication/GridIoMessageFactory.java b/modules/core/src/main/java/org/apache/ignite/internal/managers/communication/GridIoMessageFactory.java
index b0ef3f4..3c7f378 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/managers/communication/GridIoMessageFactory.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/managers/communication/GridIoMessageFactory.java
@@ -31,8 +31,8 @@ import org.apache.ignite.internal.managers.deployment.GridDeploymentInfoBean;
 import org.apache.ignite.internal.managers.deployment.GridDeploymentRequest;
 import org.apache.ignite.internal.managers.deployment.GridDeploymentResponse;
 import org.apache.ignite.internal.managers.eventstorage.GridEventStorageMessage;
-import org.apache.ignite.internal.portable.BinaryEnumObjectImpl;
-import org.apache.ignite.internal.portable.BinaryObjectImpl;
+import org.apache.ignite.internal.binary.BinaryEnumObjectImpl;
+import org.apache.ignite.internal.binary.BinaryObjectImpl;
 import org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion;
 import org.apache.ignite.internal.processors.cache.CacheEntryInfoCollection;
 import org.apache.ignite.internal.processors.cache.CacheEntryPredicateContainsValue;


[59/59] [abbrv] ignite git commit: Merge ignite-1.5 into ignite-843-rc2

Posted by ak...@apache.org.
Merge ignite-1.5 into ignite-843-rc2


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

Branch: refs/heads/ignite-843-rc2
Commit: 4ad4f76d972d4a152aa9c3175c05581607095f26
Parents: 330ba1a 469bf6d
Author: AKuznetsov <ak...@gridgain.com>
Authored: Fri Dec 11 22:54:51 2015 +0700
Committer: AKuznetsov <ak...@gridgain.com>
Committed: Fri Dec 11 22:54:51 2015 +0700

----------------------------------------------------------------------
 .gitignore                                      |    1 +
 assembly/release-fabric-base.xml                |    6 +
 bin/ignite.bat                                  |    4 +-
 bin/include/parseargs.bat                       |    4 +-
 examples/schema-import/README.txt               |    2 +-
 .../examples/datagrid/CacheQueryExample.java    |    6 +
 .../examples/CacheClientBinaryExampleTest.java  |   46 +
 .../CacheClientPortableExampleTest.java         |   46 -
 .../ComputeClientBinaryExampleTest.java         |   37 +
 .../ComputeClientPortableExampleTest.java       |   37 -
 .../testsuites/IgniteExamplesSelfTestSuite.java |   13 +-
 modules/core/pom.xml                            |    4 +-
 .../java/org/apache/ignite/IgniteBinary.java    |    2 +-
 .../java/org/apache/ignite/IgniteCache.java     |    2 +-
 .../org/apache/ignite/cache/QueryEntity.java    |    3 +-
 .../store/jdbc/CacheAbstractJdbcStore.java      |    2 +-
 .../cache/store/jdbc/CacheJdbcPojoStore.java    |    2 +-
 .../ignite/internal/GridKernalContextImpl.java  |    2 +-
 .../apache/ignite/internal/IgniteKernal.java    |    6 +-
 .../org/apache/ignite/internal/IgnitionEx.java  |    2 +-
 .../binary/BinaryCachingMetadataHandler.java    |   70 +
 .../internal/binary/BinaryClassDescriptor.java  |  813 ++++
 .../ignite/internal/binary/BinaryContext.java   | 1102 +++++
 .../ignite/internal/binary/BinaryEnumCache.java |   69 +
 .../internal/binary/BinaryEnumObjectImpl.java   |  311 ++
 .../internal/binary/BinaryFieldAccessor.java    |  856 ++++
 .../ignite/internal/binary/BinaryFieldImpl.java |  116 +
 .../internal/binary/BinaryInternalIdMapper.java |  161 +
 .../internal/binary/BinaryMarshaller.java       |  142 +
 .../ignite/internal/binary/BinaryMetadata.java  |  180 +
 .../binary/BinaryMetadataCollector.java         |  277 ++
 .../internal/binary/BinaryMetadataHandler.java  |   44 +
 .../binary/BinaryNoopMetadataHandler.java       |   53 +
 .../ignite/internal/binary/BinaryObjectEx.java  |   30 +
 .../internal/binary/BinaryObjectExImpl.java     |  251 ++
 .../internal/binary/BinaryObjectImpl.java       |  569 +++
 .../binary/BinaryObjectOffheapImpl.java         |  417 ++
 .../internal/binary/BinaryPositionReadable.java |   47 +
 .../internal/binary/BinaryPrimitives.java       |  382 ++
 .../internal/binary/BinaryRawReaderEx.java      |   33 +
 .../internal/binary/BinaryRawWriterEx.java      |   60 +
 .../internal/binary/BinaryReaderExImpl.java     | 2028 +++++++++
 .../internal/binary/BinaryReaderHandles.java    |  108 +
 .../binary/BinaryReaderHandlesHolder.java       |   46 +
 .../binary/BinaryReaderHandlesHolderImpl.java   |   44 +
 .../ignite/internal/binary/BinarySchema.java    |  466 ++
 .../internal/binary/BinarySchemaRegistry.java   |  172 +
 .../binary/BinaryThreadLocalContext.java        |   69 +
 .../ignite/internal/binary/BinaryTypeImpl.java  |   93 +
 .../ignite/internal/binary/BinaryUtils.java     | 1859 ++++++++
 .../ignite/internal/binary/BinaryWriteMode.java |  178 +
 .../internal/binary/BinaryWriterExImpl.java     | 1768 ++++++++
 .../internal/binary/BinaryWriterHandles.java    |  101 +
 .../binary/BinaryWriterSchemaHolder.java        |  148 +
 .../internal/binary/GridBinaryMarshaller.java   |  286 ++
 .../binary/builder/BinaryAbstractLazyValue.java |   57 +
 .../binary/builder/BinaryBuilderEnum.java       |  115 +
 .../binary/builder/BinaryBuilderReader.java     |  846 ++++
 .../BinaryBuilderSerializationAware.java        |   31 +
 .../binary/builder/BinaryBuilderSerializer.java |  217 +
 .../builder/BinaryEnumArrayLazyValue.java       |  113 +
 .../binary/builder/BinaryLazyArrayList.java     |  167 +
 .../binary/builder/BinaryLazyLinkedList.java    |  218 +
 .../internal/binary/builder/BinaryLazyMap.java  |  221 +
 .../internal/binary/builder/BinaryLazySet.java  |   92 +
 .../binary/builder/BinaryLazyValue.java         |   28 +
 .../builder/BinaryModifiableLazyValue.java      |   52 +
 .../builder/BinaryObjectArrayLazyValue.java     |   90 +
 .../binary/builder/BinaryObjectBuilderImpl.java |  572 +++
 .../binary/builder/BinaryPlainBinaryObject.java |   53 +
 .../binary/builder/BinaryPlainLazyValue.java    |   49 +
 .../binary/builder/BinaryValueWithType.java     |   76 +
 .../internal/binary/builder/package-info.java   |   22 +
 .../ignite/internal/binary/package-info.java    |   22 +
 .../streams/BinaryAbstractInputStream.java      |  379 ++
 .../streams/BinaryAbstractOutputStream.java     |  347 ++
 .../binary/streams/BinaryAbstractStream.java    |   80 +
 .../binary/streams/BinaryHeapInputStream.java   |  166 +
 .../binary/streams/BinaryHeapOutputStream.java  |  176 +
 .../binary/streams/BinaryInputStream.java       |  162 +
 .../binary/streams/BinaryMemoryAllocator.java   |   57 +
 .../streams/BinaryMemoryAllocatorChunk.java     |  117 +
 .../streams/BinaryOffheapInputStream.java       |  144 +
 .../streams/BinaryOffheapOutputStream.java      |  222 +
 .../binary/streams/BinaryOutputStream.java      |  259 ++
 .../internal/binary/streams/BinaryStream.java   |   53 +
 .../internal/binary/streams/package-info.java   |   22 +
 .../communication/GridIoMessageFactory.java     |    4 +-
 .../portable/BinaryCachingMetadataHandler.java  |   70 -
 .../internal/portable/BinaryEnumCache.java      |   69 -
 .../internal/portable/BinaryEnumObjectImpl.java |  311 --
 .../internal/portable/BinaryFieldAccessor.java  |  856 ----
 .../internal/portable/BinaryFieldImpl.java      |  116 -
 .../portable/BinaryInternalIdMapper.java        |  161 -
 .../internal/portable/BinaryMarshaller.java     |  142 -
 .../internal/portable/BinaryMetadata.java       |  180 -
 .../portable/BinaryMetadataCollector.java       |  277 --
 .../portable/BinaryMetadataHandler.java         |   44 -
 .../portable/BinaryNoopMetadataHandler.java     |   53 -
 .../internal/portable/BinaryObjectEx.java       |   30 -
 .../internal/portable/BinaryObjectExImpl.java   |  251 --
 .../internal/portable/BinaryObjectImpl.java     |  584 ---
 .../portable/BinaryObjectOffheapImpl.java       |  429 --
 .../internal/portable/BinaryRawReaderEx.java    |   33 -
 .../internal/portable/BinaryRawWriterEx.java    |   60 -
 .../internal/portable/BinaryReaderExImpl.java   | 2028 ---------
 .../internal/portable/BinaryReaderHandles.java  |  108 -
 .../portable/BinaryReaderHandlesHolder.java     |   46 -
 .../portable/BinaryReaderHandlesHolderImpl.java |   44 -
 .../portable/BinaryThreadLocalContext.java      |   69 -
 .../internal/portable/BinaryTypeImpl.java       |   93 -
 .../internal/portable/BinaryWriteMode.java      |  178 -
 .../internal/portable/BinaryWriterExImpl.java   | 1807 --------
 .../internal/portable/BinaryWriterHandles.java  |  101 -
 .../portable/BinaryWriterSchemaHolder.java      |  148 -
 .../portable/GridPortableMarshaller.java        |  286 --
 .../portable/PortableClassDescriptor.java       |  813 ----
 .../internal/portable/PortableContext.java      | 1102 -----
 .../portable/PortablePositionReadable.java      |   47 -
 .../internal/portable/PortablePrimitives.java   |  382 --
 .../internal/portable/PortableSchema.java       |  466 --
 .../portable/PortableSchemaRegistry.java        |  172 -
 .../ignite/internal/portable/PortableUtils.java | 1907 --------
 .../builder/BinaryObjectBuilderImpl.java        |  580 ---
 .../builder/PortableAbstractLazyValue.java      |   57 -
 .../portable/builder/PortableBuilderEnum.java   |  116 -
 .../portable/builder/PortableBuilderReader.java |  847 ----
 .../PortableBuilderSerializationAware.java      |   31 -
 .../builder/PortableBuilderSerializer.java      |  217 -
 .../builder/PortableEnumArrayLazyValue.java     |  114 -
 .../portable/builder/PortableLazyArrayList.java |  166 -
 .../builder/PortableLazyLinkedList.java         |  217 -
 .../portable/builder/PortableLazyMap.java       |  220 -
 .../portable/builder/PortableLazySet.java       |   92 -
 .../portable/builder/PortableLazyValue.java     |   28 -
 .../builder/PortableModifiableLazyValue.java    |   52 -
 .../builder/PortableObjectArrayLazyValue.java   |   91 -
 .../builder/PortablePlainLazyValue.java         |   49 -
 .../builder/PortablePlainPortableObject.java    |   53 -
 .../portable/builder/PortableValueWithType.java |   76 -
 .../internal/portable/builder/package-info.java |   22 -
 .../ignite/internal/portable/package-info.java  |   22 -
 .../streams/PortableAbstractInputStream.java    |  379 --
 .../streams/PortableAbstractOutputStream.java   |  347 --
 .../streams/PortableAbstractStream.java         |   80 -
 .../streams/PortableHeapInputStream.java        |  166 -
 .../streams/PortableHeapOutputStream.java       |  176 -
 .../portable/streams/PortableInputStream.java   |  162 -
 .../streams/PortableMemoryAllocator.java        |   57 -
 .../streams/PortableMemoryAllocatorChunk.java   |  117 -
 .../streams/PortableOffheapInputStream.java     |  144 -
 .../streams/PortableOffheapOutputStream.java    |  222 -
 .../portable/streams/PortableOutputStream.java  |  259 --
 .../portable/streams/PortableStream.java        |   53 -
 .../internal/portable/streams/package-info.java |   22 -
 .../CacheDefaultBinaryAffinityKeyMapper.java    |    4 +-
 .../processors/cache/CacheObjectContext.java    |    6 +-
 .../processors/cache/GridCacheContext.java      |    2 +-
 .../processors/cache/GridCacheProcessor.java    |    2 +-
 .../cache/binary/BinaryMetadataKey.java         |   82 +
 .../CacheDefaultBinaryAffinityKeyMapper.java    |   51 +
 .../cache/binary/CacheObjectBinaryContext.java  |   56 +
 .../binary/CacheObjectBinaryProcessor.java      |  106 +
 .../binary/CacheObjectBinaryProcessorImpl.java  |  903 ++++
 .../cache/binary/IgniteBinaryImpl.java          |  178 +
 .../processors/cache/binary/package-info.java   |   22 +
 .../CacheDataStructuresManager.java             |    5 +
 .../GridDhtPartitionsExchangeFuture.java        |    4 +-
 .../preloader/GridDhtPartitionsFullMessage.java |    8 +-
 .../CacheDefaultPortableAffinityKeyMapper.java  |   51 -
 .../portable/CacheObjectBinaryProcessor.java    |  106 -
 .../CacheObjectBinaryProcessorImpl.java         |  895 ----
 .../portable/CacheObjectPortableContext.java    |   56 -
 .../cache/portable/IgniteBinaryImpl.java        |  178 -
 .../cache/portable/PortableMetadataKey.java     |   82 -
 .../processors/cache/portable/package-info.java |   22 -
 .../cache/store/CacheOsStoreManager.java        |    4 +-
 .../datastructures/DataStructuresProcessor.java |  161 +-
 .../jobmetrics/GridJobMetricsProcessor.java     |    8 +-
 .../platform/PlatformAbstractTarget.java        |    6 +-
 .../processors/platform/PlatformContext.java    |    6 +-
 .../platform/PlatformContextImpl.java           |   21 +-
 .../platform/PlatformExtendedException.java     |    4 +-
 .../platform/PlatformProcessorImpl.java         |    4 +-
 .../platform/cache/PlatformCache.java           |    6 +-
 .../cache/PlatformCacheEntryFilterImpl.java     |    4 +-
 .../cache/PlatformCacheEntryProcessorImpl.java  |    6 +-
 .../platform/cache/PlatformCacheIterator.java   |    4 +-
 .../PlatformCachePartialUpdateException.java    |    4 +-
 .../cache/affinity/PlatformAffinity.java        |    6 +-
 .../query/PlatformAbstractQueryCursor.java      |    4 +-
 .../PlatformContinuousQueryRemoteFilter.java    |    4 +-
 .../cache/query/PlatformFieldsQueryCursor.java  |    4 +-
 .../cache/query/PlatformQueryCursor.java        |    4 +-
 .../cache/store/PlatformCacheStoreCallback.java |    4 +-
 .../platform/cluster/PlatformClusterGroup.java  |    6 +-
 .../cluster/PlatformClusterNodeFilterImpl.java  |    4 +-
 .../platform/compute/PlatformAbstractJob.java   |    4 +-
 .../platform/compute/PlatformAbstractTask.java  |    4 +-
 .../platform/compute/PlatformClosureJob.java    |    4 +-
 .../platform/compute/PlatformCompute.java       |    8 +-
 .../platform/compute/PlatformFullJob.java       |    4 +-
 .../platform/compute/PlatformFullTask.java      |    6 +-
 .../cpp/PlatformCppConfigurationClosure.java    |    4 +-
 .../datastreamer/PlatformDataStreamer.java      |    5 +-
 .../PlatformStreamReceiverImpl.java             |    4 +-
 .../dotnet/PlatformDotNetCacheStore.java        |    6 +-
 .../PlatformDotNetConfigurationClosure.java     |   18 +-
 .../events/PlatformEventFilterListenerImpl.java |    4 +-
 .../platform/events/PlatformEvents.java         |    4 +-
 .../platform/memory/PlatformInputStream.java    |    6 +-
 .../platform/memory/PlatformOutputStream.java   |    6 +-
 .../messaging/PlatformMessageFilterImpl.java    |    4 +-
 .../messaging/PlatformMessageLocalFilter.java   |    2 +-
 .../platform/messaging/PlatformMessaging.java   |    6 +-
 .../services/PlatformAbstractService.java       |    6 +-
 .../platform/services/PlatformServices.java     |    6 +-
 .../transactions/PlatformTransactions.java      |    4 +-
 .../platform/utils/PlatformFutureUtils.java     |    4 +-
 .../platform/utils/PlatformReaderBiClosure.java |    4 +-
 .../platform/utils/PlatformReaderClosure.java   |    4 +-
 .../platform/utils/PlatformUtils.java           |    6 +-
 .../platform/utils/PlatformWriterBiClosure.java |    4 +-
 .../platform/utils/PlatformWriterClosure.java   |    4 +-
 .../processors/query/GridQueryProcessor.java    |   21 +-
 .../message/GridClientBinaryMetaData.java       |   71 +
 .../message/GridClientPortableMetaData.java     |   71 -
 .../sharedfs/SharedFsCheckpointSpi.java         |    4 +-
 .../ignite/spi/discovery/tcp/ServerImpl.java    |    2 +-
 .../resources/META-INF/classnames.properties    |   36 +-
 ...heJdbcPojoStoreBinaryMarshallerSelfTest.java |    2 +-
 ...eJdbcStoreAbstractMultithreadedSelfTest.java |    5 +-
 ...CacheJdbcBlobStoreMultithreadedSelfTest.java |    2 +-
 .../internal/binary/BinaryEnumsSelfTest.java    |  446 ++
 .../binary/BinaryFieldsAbstractSelfTest.java    |  718 +++
 .../binary/BinaryFieldsHeapSelfTest.java        |   30 +
 .../binary/BinaryFieldsOffheapSelfTest.java     |   60 +
 .../BinaryFooterOffsetsAbstractSelfTest.java    |  205 +
 .../binary/BinaryFooterOffsetsHeapSelfTest.java |   30 +
 .../BinaryFooterOffsetsOffheapSelfTest.java     |   60 +
 .../binary/BinaryMarshallerSelfTest.java        | 4209 +++++++++++++++++
 .../BinaryObjectBuilderAdditionalSelfTest.java  | 1264 ++++++
 .../binary/BinaryObjectBuilderSelfTest.java     | 1100 +++++
 .../binary/GridBinaryAffinityKeySelfTest.java   |  234 +
 ...GridBinaryMarshallerCtxDisabledSelfTest.java |  247 +
 .../binary/GridBinaryMetaDataSelfTest.java      |  371 ++
 .../binary/GridBinaryWildcardsSelfTest.java     |  464 ++
 .../binary/TestCachingMetadataHandler.java      |   45 +
 .../GridBinaryMarshalerAwareTestClass.java      |   67 +
 .../mutabletest/GridBinaryTestClasses.java      |  484 ++
 .../binary/mutabletest/package-info.java        |   22 +
 .../BinaryFieldsHeapNonCompactSelfTest.java     |   30 +
 .../BinaryFieldsOffheapNonCompactSelfTest.java  |   30 +
 ...naryFooterOffsetsHeapNonCompactSelfTest.java |   30 +
 ...yFooterOffsetsOffheapNonCompactSelfTest.java |   30 +
 .../BinaryMarshallerNonCompactSelfTest.java     |   30 +
 ...jectBuilderAdditionalNonCompactSelfTest.java |   30 +
 .../BinaryObjectBuilderNonCompactSelfTest.java  |   30 +
 .../ignite/internal/binary/package-info.java    |   22 +
 .../binary/test/GridBinaryTestClass1.java       |   28 +
 .../binary/test/GridBinaryTestClass2.java       |   24 +
 .../internal/binary/test/package-info.java      |   22 +
 .../test/subpackage/GridBinaryTestClass3.java   |   24 +
 .../binary/test/subpackage/package-info.java    |   22 +
 .../internal/portable/BinaryEnumsSelfTest.java  |  446 --
 .../portable/BinaryFieldsAbstractSelfTest.java  |  718 ---
 .../portable/BinaryFieldsHeapSelfTest.java      |   30 -
 .../portable/BinaryFieldsOffheapSelfTest.java   |   60 -
 .../BinaryFooterOffsetsAbstractSelfTest.java    |  205 -
 .../BinaryFooterOffsetsHeapSelfTest.java        |   30 -
 .../BinaryFooterOffsetsOffheapSelfTest.java     |   60 -
 .../portable/BinaryMarshallerSelfTest.java      | 4210 ------------------
 .../BinaryObjectBuilderAdditionalSelfTest.java  | 1272 ------
 .../portable/BinaryObjectBuilderSelfTest.java   | 1103 -----
 .../GridPortableAffinityKeySelfTest.java        |  234 -
 ...idPortableMarshallerCtxDisabledSelfTest.java |  247 -
 .../portable/GridPortableMetaDataSelfTest.java  |  371 --
 .../portable/GridPortableWildcardsSelfTest.java |  464 --
 .../portable/TestCachingMetadataHandler.java    |   45 -
 .../GridBinaryMarshalerAwareTestClass.java      |   67 -
 .../mutabletest/GridPortableTestClasses.java    |  484 --
 .../portable/mutabletest/package-info.java      |   22 -
 .../BinaryFieldsHeapNonCompactSelfTest.java     |   30 -
 .../BinaryFieldsOffheapNonCompactSelfTest.java  |   30 -
 ...naryFooterOffsetsHeapNonCompactSelfTest.java |   30 -
 ...yFooterOffsetsOffheapNonCompactSelfTest.java |   30 -
 .../BinaryMarshallerNonCompactSelfTest.java     |   30 -
 ...jectBuilderAdditionalNonCompactSelfTest.java |   30 -
 .../BinaryObjectBuilderNonCompactSelfTest.java  |   30 -
 .../ignite/internal/portable/package-info.java  |   22 -
 .../portable/test/GridPortableTestClass1.java   |   28 -
 .../portable/test/GridPortableTestClass2.java   |   24 -
 .../internal/portable/test/package-info.java    |   22 -
 .../test/subpackage/GridPortableTestClass3.java |   24 -
 .../portable/test/subpackage/package-info.java  |   22 -
 .../GridCacheConditionalDeploymentSelfTest.java |    2 +-
 .../cache/GridCacheDeploymentSelfTest.java      |    2 +-
 .../IgniteCacheStoreValueAbstractTest.java      |    6 +-
 .../GridBinaryCacheEntryMemorySizeSelfTest.java |   48 +
 ...ryDuplicateIndexObjectsAbstractSelfTest.java |  161 +
 ...yAtomicEntryProcessorDeploymentSelfTest.java |  129 +
 ...naryObjectsAbstractDataStreamerSelfTest.java |  192 +
 ...aryObjectsAbstractMultiThreadedSelfTest.java |  241 +
 .../GridCacheBinaryObjectsAbstractSelfTest.java |  981 ++++
 .../GridCacheBinaryStoreAbstractSelfTest.java   |  300 ++
 .../GridCacheBinaryStoreBinariesSelfTest.java   |   66 +
 .../GridCacheBinaryStoreObjectsSelfTest.java    |   55 +
 ...ctionalEntryProcessorDeploymentSelfTest.java |   31 +
 ...ntNodeBinaryObjectMetadataMultinodeTest.java |  295 ++
 ...CacheClientNodeBinaryObjectMetadataTest.java |  221 +
 .../DataStreamProcessorBinarySelfTest.java      |   71 +
 .../GridDataStreamerImplSelfTest.java           |  345 ++
 .../GridCacheAffinityRoutingBinarySelfTest.java |   54 +
 ...OnlyBinaryDataStreamerMultiNodeSelfTest.java |   29 +
 ...BinaryDataStreamerMultithreadedSelfTest.java |   47 +
 ...cPartitionedOnlyBinaryMultiNodeSelfTest.java |   28 +
 ...titionedOnlyBinaryMultithreadedSelfTest.java |   47 +
 ...sNearPartitionedByteArrayValuesSelfTest.java |   41 +
 ...sPartitionedOnlyByteArrayValuesSelfTest.java |   42 +
 ...ateIndexObjectPartitionedAtomicSelfTest.java |   38 +
 ...xObjectPartitionedTransactionalSelfTest.java |   41 +
 ...AtomicNearDisabledOffheapTieredSelfTest.java |   29 +
 ...BinaryObjectsAtomicNearDisabledSelfTest.java |   51 +
 ...inaryObjectsAtomicOffheapTieredSelfTest.java |   29 +
 .../GridCacheBinaryObjectsAtomicSelfTest.java   |   51 +
 ...tionedNearDisabledOffheapTieredSelfTest.java |   30 +
 ...yObjectsPartitionedNearDisabledSelfTest.java |   51 +
 ...ObjectsPartitionedOffheapTieredSelfTest.java |   30 +
 ...idCacheBinaryObjectsPartitionedSelfTest.java |   51 +
 .../dht/GridCacheMemoryModeBinarySelfTest.java  |   36 +
 ...dCacheOffHeapTieredAtomicBinarySelfTest.java |   48 +
 .../GridCacheOffHeapTieredBinarySelfTest.java   |   48 +
 ...fHeapTieredEvictionAtomicBinarySelfTest.java |   96 +
 ...acheOffHeapTieredEvictionBinarySelfTest.java |   96 +
 ...ridCacheBinaryObjectsReplicatedSelfTest.java |   51 +
 ...idCacheBinaryObjectsAtomicLocalSelfTest.java |   32 +
 ...BinaryObjectsLocalOffheapTieredSelfTest.java |   29 +
 .../GridCacheBinaryObjectsLocalSelfTest.java    |   51 +
 ...IgniteCacheAbstractExecutionContextTest.java |    7 +-
 .../near/NearCachePutAllMultinodeTest.java      |  167 +
 ...eRebalancingUnmarshallingFailedSelfTest.java |    2 +-
 ...idCacheReplicatedUnswapAdvancedSelfTest.java |    4 +-
 .../GridCacheReplicatedPreloadSelfTest.java     |    2 +-
 ...yAtomicEntryProcessorDeploymentSelfTest.java |  129 -
 ...naryObjectsAbstractDataStreamerSelfTest.java |  192 -
 ...aryObjectsAbstractMultiThreadedSelfTest.java |  241 -
 .../GridCacheBinaryObjectsAbstractSelfTest.java |  981 ----
 ...ctionalEntryProcessorDeploymentSelfTest.java |   31 -
 ...ntNodeBinaryObjectMetadataMultinodeTest.java |  295 --
 ...CacheClientNodeBinaryObjectMetadataTest.java |  221 -
 .../GridCachePortableStoreAbstractSelfTest.java |  300 --
 .../GridCachePortableStoreObjectsSelfTest.java  |   55 -
 ...GridCachePortableStorePortablesSelfTest.java |   66 -
 ...ridPortableCacheEntryMemorySizeSelfTest.java |   48 -
 ...leDuplicateIndexObjectsAbstractSelfTest.java |  161 -
 .../DataStreamProcessorPortableSelfTest.java    |   71 -
 .../GridDataStreamerImplSelfTest.java           |  345 --
 ...ridCacheAffinityRoutingPortableSelfTest.java |   54 -
 ...lyPortableDataStreamerMultiNodeSelfTest.java |   29 -
 ...rtableDataStreamerMultithreadedSelfTest.java |   47 -
 ...artitionedOnlyPortableMultiNodeSelfTest.java |   28 -
 ...tionedOnlyPortableMultithreadedSelfTest.java |   47 -
 ...AtomicNearDisabledOffheapTieredSelfTest.java |   29 -
 ...BinaryObjectsAtomicNearDisabledSelfTest.java |   51 -
 ...inaryObjectsAtomicOffheapTieredSelfTest.java |   29 -
 .../GridCacheBinaryObjectsAtomicSelfTest.java   |   51 -
 ...tionedNearDisabledOffheapTieredSelfTest.java |   30 -
 ...yObjectsPartitionedNearDisabledSelfTest.java |   51 -
 ...ObjectsPartitionedOffheapTieredSelfTest.java |   30 -
 ...idCacheBinaryObjectsPartitionedSelfTest.java |   51 -
 .../GridCacheMemoryModePortableSelfTest.java    |   36 -
 ...acheOffHeapTieredAtomicPortableSelfTest.java |   48 -
 ...eapTieredEvictionAtomicPortableSelfTest.java |   96 -
 ...heOffHeapTieredEvictionPortableSelfTest.java |   96 -
 .../GridCacheOffHeapTieredPortableSelfTest.java |   48 -
 ...ateIndexObjectPartitionedAtomicSelfTest.java |   38 -
 ...xObjectPartitionedTransactionalSelfTest.java |   41 -
 ...sNearPartitionedByteArrayValuesSelfTest.java |   41 -
 ...sPartitionedOnlyByteArrayValuesSelfTest.java |   42 -
 ...ridCacheBinaryObjectsReplicatedSelfTest.java |   51 -
 ...idCacheBinaryObjectsAtomicLocalSelfTest.java |   32 -
 ...BinaryObjectsLocalOffheapTieredSelfTest.java |   29 -
 .../GridCacheBinaryObjectsLocalSelfTest.java    |   51 -
 .../PlatformComputeBinarizableArgTask.java      |    4 +-
 .../platform/PlatformEventsWriteEventTask.java  |    4 +-
 .../session/GridSessionCheckpointSelfTest.java  |   10 +-
 .../spi/discovery/tcp/TcpDiscoverySelfTest.java |   67 +
 .../testframework/junits/GridAbstractTest.java  |    4 +-
 .../ignite/testframework/junits/IgniteMock.java |   10 +-
 .../junits/IgniteTestResources.java             |   10 +-
 .../IgniteBinaryCacheFullApiTestSuite.java      |   37 +
 .../testsuites/IgniteBinaryCacheTestSuite.java  |  101 +
 ...ObjectsCacheDataStructuresSelfTestSuite.java |    2 +-
 ...BinaryObjectsCacheExpiryPolicyTestSuite.java |    2 +-
 ...gniteBinaryObjectsCacheRestartTestSuite.java |    2 +-
 .../IgniteBinaryObjectsCacheTestSuite2.java     |    2 +-
 .../IgniteBinaryObjectsCacheTestSuite3.java     |    6 +-
 .../IgniteBinaryObjectsCacheTestSuite4.java     |    2 +-
 ...IgniteBinaryObjectsComputeGridTestSuite.java |    2 +-
 .../IgniteBinaryObjectsTestSuite.java           |  114 +
 .../IgnitePortableCacheFullApiTestSuite.java    |   37 -
 .../IgnitePortableCacheTestSuite.java           |  101 -
 .../IgnitePortableObjectsTestSuite.java         |  114 -
 .../ignite/binary/test1/1.1/test1-1.1.jar       |  Bin 0 -> 2548 bytes
 .../ignite/binary/test1/1.1/test1-1.1.pom       |    9 +
 .../binary/test1/maven-metadata-local.xml       |   12 +
 .../ignite/binary/test2/1.1/test2-1.1.jar       |  Bin 0 -> 1361 bytes
 .../ignite/binary/test2/1.1/test2-1.1.pom       |    9 +
 .../binary/test2/maven-metadata-local.xml       |   12 +
 .../ignite/portable/test1/1.1/test1-1.1.jar     |  Bin 2548 -> 0 bytes
 .../ignite/portable/test1/1.1/test1-1.1.pom     |    9 -
 .../portable/test1/maven-metadata-local.xml     |   12 -
 .../ignite/portable/test2/1.1/test2-1.1.jar     |  Bin 1361 -> 0 bytes
 .../ignite/portable/test2/1.1/test2-1.1.pom     |    9 -
 .../portable/test2/maven-metadata-local.xml     |   12 -
 modules/docker/1.0.0/Dockerfile                 |   40 +
 modules/docker/1.0.0/run.sh                     |   50 +
 modules/docker/1.1.0/Dockerfile                 |   40 +
 modules/docker/1.1.0/run.sh                     |   50 +
 modules/docker/1.2.0/Dockerfile                 |   40 +
 modules/docker/1.2.0/run.sh                     |   50 +
 modules/docker/1.3.0/Dockerfile                 |   40 +
 modules/docker/1.3.0/run.sh                     |   50 +
 modules/docker/1.4.0/Dockerfile                 |   40 +
 modules/docker/1.4.0/run.sh                     |   50 +
 modules/docker/Dockerfile                       |   41 +-
 modules/docker/build_users_libs.sh              |   39 -
 modules/docker/download_ignite.sh               |   49 -
 modules/docker/execute.sh                       |   62 -
 modules/docker/run.sh                           |   36 +-
 .../CacheDeploymentBinaryEntryProcessor.java    |   35 +
 .../CacheDeploymentPortableEntryProcessor.java  |   35 -
 .../apache/ignite/tests/p2p/cache/Person.java   |   77 +
 .../ignite/tests/p2p/cache/PersonKey.java       |   74 +
 .../IgniteBinaryObjectFieldsQuerySelfTest.java  |  246 +
 .../IgniteBinaryCacheQueryTestSuite.java        |  119 +
 .../IgnitePortableCacheQueryTestSuite.java      |  117 -
 modules/platforms/cpp/cpp.dxg                   | 1722 +++++++
 .../Config/marshaller-explicit.xml              |    2 +-
 .../ignite-int-max-values-offheap-config.xml    |    2 +-
 .../ignite-int-max-values-onheap-config.xml     |    2 +-
 .../ignite-int-max-values-swap-config.xml       |    2 +-
 parent/pom.xml                                  |    8 +-
 443 files changed, 38501 insertions(+), 35926 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/4ad4f76d/parent/pom.xml
----------------------------------------------------------------------
diff --cc parent/pom.xml
index c6ccf44,0f2d363..6f377c8
--- a/parent/pom.xml
+++ b/parent/pom.xml
@@@ -846,11 -846,10 +846,11 @@@
                                          <exclude>dev-tools/.gradle/**/*</exclude>
                                          <exclude>dev-tools/gradle/wrapper/**/*</exclude>
                                          <exclude>dev-tools/gradlew</exclude>
-                                         <exclude>src/test/portables/repo/org/apache/ignite/portable/test2/1.1/test2-1.1.pom</exclude>
-                                         <exclude>src/test/portables/repo/org/apache/ignite/portable/test2/maven-metadata-local.xml</exclude>
-                                         <exclude>src/test/portables/repo/org/apache/ignite/portable/test1/1.1/test1-1.1.pom</exclude>
-                                         <exclude>src/test/portables/repo/org/apache/ignite/portable/test1/maven-metadata-local.xml</exclude>
+                                         <exclude>src/test/portables/repo/org/apache/ignite/binary/test2/1.1/test2-1.1.pom</exclude>
+                                         <exclude>src/test/portables/repo/org/apache/ignite/binary/test2/maven-metadata-local.xml</exclude>
+                                         <exclude>src/test/portables/repo/org/apache/ignite/binary/test1/1.1/test1-1.1.pom</exclude>
+                                         <exclude>src/test/portables/repo/org/apache/ignite/binary/test1/maven-metadata-local.xml</exclude>
 +                                        <exclude>src/main/js/package.json</exclude>
                                          <!--shmem-->
                                          <exclude>ipc/shmem/**/Makefile.in</exclude><!--auto generated files-->
                                          <exclude>ipc/shmem/**/Makefile</exclude><!--auto generated files-->


[52/59] [abbrv] ignite git commit: ignite-2065: rename "portable" classes to "binary"

Posted by ak...@apache.org.
http://git-wip-us.apache.org/repos/asf/ignite/blob/71ad9cea/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryWriteMode.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryWriteMode.java b/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryWriteMode.java
index a20b5ed..9a37bdb 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryWriteMode.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryWriteMode.java
@@ -22,142 +22,142 @@ package org.apache.ignite.internal.binary;
  */
 public enum BinaryWriteMode {
     /** Primitive byte. */
-    P_BYTE(GridPortableMarshaller.BYTE),
+    P_BYTE(GridBinaryMarshaller.BYTE),
 
     /** Primitive boolean. */
-    P_BOOLEAN(GridPortableMarshaller.BOOLEAN),
+    P_BOOLEAN(GridBinaryMarshaller.BOOLEAN),
 
     /** Primitive short. */
-    P_SHORT(GridPortableMarshaller.SHORT),
+    P_SHORT(GridBinaryMarshaller.SHORT),
 
     /** Primitive char. */
-    P_CHAR(GridPortableMarshaller.CHAR),
+    P_CHAR(GridBinaryMarshaller.CHAR),
 
     /** Primitive int. */
-    P_INT(GridPortableMarshaller.INT),
+    P_INT(GridBinaryMarshaller.INT),
 
     /** Primitive long. */
-    P_LONG(GridPortableMarshaller.LONG),
+    P_LONG(GridBinaryMarshaller.LONG),
 
     /** Primitive float. */
-    P_FLOAT(GridPortableMarshaller.FLOAT),
+    P_FLOAT(GridBinaryMarshaller.FLOAT),
 
     /** Primitive int. */
-    P_DOUBLE(GridPortableMarshaller.DOUBLE),
+    P_DOUBLE(GridBinaryMarshaller.DOUBLE),
 
     /** */
-    BYTE(GridPortableMarshaller.BYTE),
+    BYTE(GridBinaryMarshaller.BYTE),
 
     /** */
-    SHORT(GridPortableMarshaller.SHORT),
+    SHORT(GridBinaryMarshaller.SHORT),
 
     /** */
-    INT(GridPortableMarshaller.INT),
+    INT(GridBinaryMarshaller.INT),
 
     /** */
-    LONG(GridPortableMarshaller.LONG),
+    LONG(GridBinaryMarshaller.LONG),
 
     /** */
-    FLOAT(GridPortableMarshaller.FLOAT),
+    FLOAT(GridBinaryMarshaller.FLOAT),
 
     /** */
-    DOUBLE(GridPortableMarshaller.DOUBLE),
+    DOUBLE(GridBinaryMarshaller.DOUBLE),
 
     /** */
-    CHAR(GridPortableMarshaller.CHAR),
+    CHAR(GridBinaryMarshaller.CHAR),
 
     /** */
-    BOOLEAN(GridPortableMarshaller.BOOLEAN),
+    BOOLEAN(GridBinaryMarshaller.BOOLEAN),
 
     /** */
-    DECIMAL(GridPortableMarshaller.DECIMAL),
+    DECIMAL(GridBinaryMarshaller.DECIMAL),
 
     /** */
-    STRING(GridPortableMarshaller.STRING),
+    STRING(GridBinaryMarshaller.STRING),
 
     /** */
-    UUID(GridPortableMarshaller.UUID),
+    UUID(GridBinaryMarshaller.UUID),
 
     /** */
-    DATE(GridPortableMarshaller.DATE),
+    DATE(GridBinaryMarshaller.DATE),
 
     /** */
-    TIMESTAMP(GridPortableMarshaller.TIMESTAMP),
+    TIMESTAMP(GridBinaryMarshaller.TIMESTAMP),
 
     /** */
-    BYTE_ARR(GridPortableMarshaller.BYTE_ARR),
+    BYTE_ARR(GridBinaryMarshaller.BYTE_ARR),
 
     /** */
-    SHORT_ARR(GridPortableMarshaller.SHORT_ARR),
+    SHORT_ARR(GridBinaryMarshaller.SHORT_ARR),
 
     /** */
-    INT_ARR(GridPortableMarshaller.INT_ARR),
+    INT_ARR(GridBinaryMarshaller.INT_ARR),
 
     /** */
-    LONG_ARR(GridPortableMarshaller.LONG_ARR),
+    LONG_ARR(GridBinaryMarshaller.LONG_ARR),
 
     /** */
-    FLOAT_ARR(GridPortableMarshaller.FLOAT_ARR),
+    FLOAT_ARR(GridBinaryMarshaller.FLOAT_ARR),
 
     /** */
-    DOUBLE_ARR(GridPortableMarshaller.DOUBLE_ARR),
+    DOUBLE_ARR(GridBinaryMarshaller.DOUBLE_ARR),
 
     /** */
-    CHAR_ARR(GridPortableMarshaller.CHAR_ARR),
+    CHAR_ARR(GridBinaryMarshaller.CHAR_ARR),
 
     /** */
-    BOOLEAN_ARR(GridPortableMarshaller.BOOLEAN_ARR),
+    BOOLEAN_ARR(GridBinaryMarshaller.BOOLEAN_ARR),
 
     /** */
-    DECIMAL_ARR(GridPortableMarshaller.DECIMAL_ARR),
+    DECIMAL_ARR(GridBinaryMarshaller.DECIMAL_ARR),
 
     /** */
-    STRING_ARR(GridPortableMarshaller.STRING_ARR),
+    STRING_ARR(GridBinaryMarshaller.STRING_ARR),
 
     /** */
-    UUID_ARR(GridPortableMarshaller.UUID_ARR),
+    UUID_ARR(GridBinaryMarshaller.UUID_ARR),
 
     /** */
-    DATE_ARR(GridPortableMarshaller.DATE_ARR),
+    DATE_ARR(GridBinaryMarshaller.DATE_ARR),
 
     /** */
-    TIMESTAMP_ARR(GridPortableMarshaller.TIMESTAMP_ARR),
+    TIMESTAMP_ARR(GridBinaryMarshaller.TIMESTAMP_ARR),
 
     /** */
-    OBJECT_ARR(GridPortableMarshaller.OBJ_ARR),
+    OBJECT_ARR(GridBinaryMarshaller.OBJ_ARR),
 
     /** */
-    COL(GridPortableMarshaller.COL),
+    COL(GridBinaryMarshaller.COL),
 
     /** */
-    MAP(GridPortableMarshaller.MAP),
+    MAP(GridBinaryMarshaller.MAP),
 
     /** */
-    PORTABLE_OBJ(GridPortableMarshaller.OBJ),
+    PORTABLE_OBJ(GridBinaryMarshaller.OBJ),
 
     /** */
-    ENUM(GridPortableMarshaller.ENUM),
+    ENUM(GridBinaryMarshaller.ENUM),
 
     /** Portable enum. */
-    PORTABLE_ENUM(GridPortableMarshaller.ENUM),
+    PORTABLE_ENUM(GridBinaryMarshaller.ENUM),
 
     /** */
-    ENUM_ARR(GridPortableMarshaller.ENUM_ARR),
+    ENUM_ARR(GridBinaryMarshaller.ENUM_ARR),
 
     /** */
-    CLASS(GridPortableMarshaller.CLASS),
+    CLASS(GridBinaryMarshaller.CLASS),
 
     /** */
-    PORTABLE(GridPortableMarshaller.PORTABLE_OBJ),
+    PORTABLE(GridBinaryMarshaller.PORTABLE_OBJ),
 
     /** */
-    EXTERNALIZABLE(GridPortableMarshaller.OBJ),
+    EXTERNALIZABLE(GridBinaryMarshaller.OBJ),
 
     /** */
-    OBJECT(GridPortableMarshaller.OBJ),
+    OBJECT(GridBinaryMarshaller.OBJ),
 
     /** */
-    EXCLUSION(GridPortableMarshaller.OBJ);
+    EXCLUSION(GridBinaryMarshaller.OBJ);
 
     /** Type ID. */
     private final int typeId;

http://git-wip-us.apache.org/repos/asf/ignite/blob/71ad9cea/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryWriterExImpl.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryWriterExImpl.java b/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryWriterExImpl.java
index 25f4d70..f073dd0 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryWriterExImpl.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryWriterExImpl.java
@@ -22,9 +22,8 @@ import org.apache.ignite.binary.BinaryIdMapper;
 import org.apache.ignite.binary.BinaryObjectException;
 import org.apache.ignite.binary.BinaryRawWriter;
 import org.apache.ignite.binary.BinaryWriter;
-import org.apache.ignite.internal.binary.streams.PortableOutputStream;
-import org.apache.ignite.internal.binary.streams.PortableHeapOutputStream;
-import org.apache.ignite.internal.binary.streams.PortableOutputStream;
+import org.apache.ignite.internal.binary.streams.BinaryOutputStream;
+import org.apache.ignite.internal.binary.streams.BinaryHeapOutputStream;
 import org.apache.ignite.internal.util.typedef.internal.A;
 import org.jetbrains.annotations.Nullable;
 
@@ -40,45 +39,6 @@ import java.util.Map;
 import java.util.UUID;
 
 import static java.nio.charset.StandardCharsets.UTF_8;
-import static org.apache.ignite.internal.binary.GridPortableMarshaller.BOOLEAN;
-import static org.apache.ignite.internal.binary.GridPortableMarshaller.BOOLEAN_ARR;
-import static org.apache.ignite.internal.binary.GridPortableMarshaller.BYTE;
-import static org.apache.ignite.internal.binary.GridPortableMarshaller.BYTE_ARR;
-import static org.apache.ignite.internal.binary.GridPortableMarshaller.CHAR;
-import static org.apache.ignite.internal.binary.GridPortableMarshaller.CHAR_ARR;
-import static org.apache.ignite.internal.binary.GridPortableMarshaller.CLASS;
-import static org.apache.ignite.internal.binary.GridPortableMarshaller.COL;
-import static org.apache.ignite.internal.binary.GridPortableMarshaller.DATE;
-import static org.apache.ignite.internal.binary.GridPortableMarshaller.DATE_ARR;
-import static org.apache.ignite.internal.binary.GridPortableMarshaller.DECIMAL;
-import static org.apache.ignite.internal.binary.GridPortableMarshaller.DECIMAL_ARR;
-import static org.apache.ignite.internal.binary.GridPortableMarshaller.DFLT_HDR_LEN;
-import static org.apache.ignite.internal.binary.GridPortableMarshaller.DOUBLE;
-import static org.apache.ignite.internal.binary.GridPortableMarshaller.DOUBLE_ARR;
-import static org.apache.ignite.internal.binary.GridPortableMarshaller.ENUM;
-import static org.apache.ignite.internal.binary.GridPortableMarshaller.ENUM_ARR;
-import static org.apache.ignite.internal.binary.GridPortableMarshaller.FLOAT;
-import static org.apache.ignite.internal.binary.GridPortableMarshaller.FLOAT_ARR;
-import static org.apache.ignite.internal.binary.GridPortableMarshaller.INT;
-import static org.apache.ignite.internal.binary.GridPortableMarshaller.INT_ARR;
-import static org.apache.ignite.internal.binary.GridPortableMarshaller.LONG;
-import static org.apache.ignite.internal.binary.GridPortableMarshaller.LONG_ARR;
-import static org.apache.ignite.internal.binary.GridPortableMarshaller.MAP;
-import static org.apache.ignite.internal.binary.GridPortableMarshaller.NULL;
-import static org.apache.ignite.internal.binary.GridPortableMarshaller.OBJ;
-import static org.apache.ignite.internal.binary.GridPortableMarshaller.OBJ_ARR;
-import static org.apache.ignite.internal.binary.GridPortableMarshaller.OPTM_MARSH;
-import static org.apache.ignite.internal.binary.GridPortableMarshaller.PORTABLE_OBJ;
-import static org.apache.ignite.internal.binary.GridPortableMarshaller.PROTO_VER;
-import static org.apache.ignite.internal.binary.GridPortableMarshaller.SHORT;
-import static org.apache.ignite.internal.binary.GridPortableMarshaller.SHORT_ARR;
-import static org.apache.ignite.internal.binary.GridPortableMarshaller.STRING;
-import static org.apache.ignite.internal.binary.GridPortableMarshaller.STRING_ARR;
-import static org.apache.ignite.internal.binary.GridPortableMarshaller.TIMESTAMP;
-import static org.apache.ignite.internal.binary.GridPortableMarshaller.TIMESTAMP_ARR;
-import static org.apache.ignite.internal.binary.GridPortableMarshaller.UNREGISTERED_TYPE_ID;
-import static org.apache.ignite.internal.binary.GridPortableMarshaller.UUID;
-import static org.apache.ignite.internal.binary.GridPortableMarshaller.UUID_ARR;
 
 /**
  * Portable writer implementation.
@@ -91,10 +51,10 @@ public class BinaryWriterExImpl implements BinaryWriter, BinaryRawWriterEx, Obje
     private static final int INIT_CAP = 1024;
 
     /** */
-    private final PortableContext ctx;
+    private final BinaryContext ctx;
 
     /** Output stream. */
-    private final PortableOutputStream out;
+    private final BinaryOutputStream out;
 
     /** Schema. */
     private final BinaryWriterSchemaHolder schema;
@@ -112,7 +72,7 @@ public class BinaryWriterExImpl implements BinaryWriter, BinaryRawWriterEx, Obje
     private BinaryWriterHandles handles;
 
     /** Schema ID. */
-    private int schemaId = PortableUtils.schemaInitialId();
+    private int schemaId = BinaryUtils.schemaInitialId();
 
     /** Amount of written fields. */
     private int fieldCnt;
@@ -123,7 +83,7 @@ public class BinaryWriterExImpl implements BinaryWriter, BinaryRawWriterEx, Obje
     /**
      * @param ctx Context.
      */
-    public BinaryWriterExImpl(PortableContext ctx) {
+    public BinaryWriterExImpl(BinaryContext ctx) {
         this(ctx, BinaryThreadLocalContext.get());
     }
 
@@ -131,8 +91,8 @@ public class BinaryWriterExImpl implements BinaryWriter, BinaryRawWriterEx, Obje
      * @param ctx Context.
      * @param tlsCtx TLS context.
      */
-    public BinaryWriterExImpl(PortableContext ctx, BinaryThreadLocalContext tlsCtx) {
-        this(ctx, new PortableHeapOutputStream(INIT_CAP, tlsCtx.chunk()), tlsCtx.schemaHolder(), null);
+    public BinaryWriterExImpl(BinaryContext ctx, BinaryThreadLocalContext tlsCtx) {
+        this(ctx, new BinaryHeapOutputStream(INIT_CAP, tlsCtx.chunk()), tlsCtx.schemaHolder(), null);
     }
 
     /**
@@ -140,7 +100,7 @@ public class BinaryWriterExImpl implements BinaryWriter, BinaryRawWriterEx, Obje
      * @param out Output stream.
      * @param handles Handles.
      */
-    public BinaryWriterExImpl(PortableContext ctx, PortableOutputStream out, BinaryWriterSchemaHolder schema,
+    public BinaryWriterExImpl(BinaryContext ctx, BinaryOutputStream out, BinaryWriterSchemaHolder schema,
         BinaryWriterHandles handles) {
         this.ctx = ctx;
         this.out = out;
@@ -182,19 +142,19 @@ public class BinaryWriterExImpl implements BinaryWriter, BinaryRawWriterEx, Obje
 
         Class<?> cls = obj.getClass();
 
-        PortableClassDescriptor desc = ctx.descriptorForClass(cls, false);
+        BinaryClassDescriptor desc = ctx.descriptorForClass(cls, false);
 
         if (desc == null)
             throw new BinaryObjectException("Object is not portable: [class=" + cls + ']');
 
         if (desc.excluded()) {
-            out.writeByte(GridPortableMarshaller.NULL);
+            out.writeByte(GridBinaryMarshaller.NULL);
 
             return;
         }
 
         if (desc.useOptimizedMarshaller()) {
-            out.writeByte(GridPortableMarshaller.OPTM_MARSH);
+            out.writeByte(GridBinaryMarshaller.OPTM_MARSH);
 
             try {
                 byte[] arr = ctx.optimizedMarsh().marshal(obj);
@@ -227,7 +187,7 @@ public class BinaryWriterExImpl implements BinaryWriter, BinaryRawWriterEx, Obje
             }
 
             if (replacedObj == null) {
-                out.writeByte(GridPortableMarshaller.NULL);
+                out.writeByte(GridBinaryMarshaller.NULL);
 
                 return;
             }
@@ -269,7 +229,7 @@ public class BinaryWriterExImpl implements BinaryWriter, BinaryRawWriterEx, Obje
      * @param clsName Class name (optional).
      */
     public void preWrite(@Nullable String clsName) {
-        out.position(out.position() + GridPortableMarshaller.DFLT_HDR_LEN);
+        out.position(out.position() + GridBinaryMarshaller.DFLT_HDR_LEN);
 
         if (clsName != null)
             doWriteString(clsName);
@@ -288,11 +248,11 @@ public class BinaryWriterExImpl implements BinaryWriter, BinaryRawWriterEx, Obje
 
         if (userType) {
             if (ctx.isCompactFooter()) {
-                flags = PortableUtils.FLAG_USR_TYP | PortableUtils.FLAG_COMPACT_FOOTER;
+                flags = BinaryUtils.FLAG_USR_TYP | BinaryUtils.FLAG_COMPACT_FOOTER;
                 useCompactFooter = true;
             }
             else {
-                flags = PortableUtils.FLAG_USR_TYP;
+                flags = BinaryUtils.FLAG_USR_TYP;
                 useCompactFooter = false;
             }
         }
@@ -309,18 +269,18 @@ public class BinaryWriterExImpl implements BinaryWriter, BinaryRawWriterEx, Obje
             offset = out.position() - start;
 
             // Write the schema.
-            flags |= PortableUtils.FLAG_HAS_SCHEMA;
+            flags |= BinaryUtils.FLAG_HAS_SCHEMA;
 
             int offsetByteCnt = schema.write(out, fieldCnt, useCompactFooter);
 
-            if (offsetByteCnt == PortableUtils.OFFSET_1)
-                flags |= PortableUtils.FLAG_OFFSET_ONE_BYTE;
-            else if (offsetByteCnt == PortableUtils.OFFSET_2)
-                flags |= PortableUtils.FLAG_OFFSET_TWO_BYTES;
+            if (offsetByteCnt == BinaryUtils.OFFSET_1)
+                flags |= BinaryUtils.FLAG_OFFSET_ONE_BYTE;
+            else if (offsetByteCnt == BinaryUtils.OFFSET_2)
+                flags |= BinaryUtils.FLAG_OFFSET_TWO_BYTES;
 
             // Write raw offset if needed.
             if (rawOffPos != 0) {
-                flags |= PortableUtils.FLAG_HAS_RAW;
+                flags |= BinaryUtils.FLAG_HAS_RAW;
 
                 out.writeInt(rawOffPos - start);
             }
@@ -331,7 +291,7 @@ public class BinaryWriterExImpl implements BinaryWriter, BinaryRawWriterEx, Obje
                 offset = rawOffPos - start;
 
                 // If there is no schema, we are free to write raw offset to schema offset.
-                flags |= PortableUtils.FLAG_HAS_RAW;
+                flags |= BinaryUtils.FLAG_HAS_RAW;
             }
             else {
                 finalSchemaId = 0;
@@ -344,10 +304,10 @@ public class BinaryWriterExImpl implements BinaryWriter, BinaryRawWriterEx, Obje
 
         out.unsafePosition(start);
 
-        out.unsafeWriteByte(GridPortableMarshaller.OBJ);
-        out.unsafeWriteByte(GridPortableMarshaller.PROTO_VER);
+        out.unsafeWriteByte(GridBinaryMarshaller.OBJ);
+        out.unsafeWriteByte(GridBinaryMarshaller.PROTO_VER);
         out.unsafeWriteShort(flags);
-        out.unsafeWriteInt(registered ? typeId : GridPortableMarshaller.UNREGISTERED_TYPE_ID);
+        out.unsafeWriteInt(registered ? typeId : GridBinaryMarshaller.UNREGISTERED_TYPE_ID);
         out.unsafeWriteInt(hashCode);
         out.unsafeWriteInt(retPos - start);
         out.unsafeWriteInt(finalSchemaId);
@@ -389,11 +349,11 @@ public class BinaryWriterExImpl implements BinaryWriter, BinaryRawWriterEx, Obje
      */
     public void doWriteDecimal(@Nullable BigDecimal val) {
         if (val == null)
-            out.writeByte(GridPortableMarshaller.NULL);
+            out.writeByte(GridBinaryMarshaller.NULL);
         else {
             out.unsafeEnsure(1 + 4 + 4);
 
-            out.unsafeWriteByte(GridPortableMarshaller.DECIMAL);
+            out.unsafeWriteByte(GridBinaryMarshaller.DECIMAL);
 
             BigInteger intVal = val.unscaledValue();
 
@@ -417,12 +377,12 @@ public class BinaryWriterExImpl implements BinaryWriter, BinaryRawWriterEx, Obje
      */
     public void doWriteString(@Nullable String val) {
         if (val == null)
-            out.writeByte(GridPortableMarshaller.NULL);
+            out.writeByte(GridBinaryMarshaller.NULL);
         else {
             byte[] strArr = val.getBytes(UTF_8);
 
             out.unsafeEnsure(1 + 4);
-            out.unsafeWriteByte(GridPortableMarshaller.STRING);
+            out.unsafeWriteByte(GridBinaryMarshaller.STRING);
             out.unsafeWriteInt(strArr.length);
 
             out.writeByteArray(strArr);
@@ -434,10 +394,10 @@ public class BinaryWriterExImpl implements BinaryWriter, BinaryRawWriterEx, Obje
      */
     public void doWriteUuid(@Nullable UUID uuid) {
         if (uuid == null)
-            out.writeByte(GridPortableMarshaller.NULL);
+            out.writeByte(GridBinaryMarshaller.NULL);
         else {
             out.unsafeEnsure(1 + 8 + 8);
-            out.unsafeWriteByte(GridPortableMarshaller.UUID);
+            out.unsafeWriteByte(GridBinaryMarshaller.UUID);
             out.unsafeWriteLong(uuid.getMostSignificantBits());
             out.unsafeWriteLong(uuid.getLeastSignificantBits());
         }
@@ -448,10 +408,10 @@ public class BinaryWriterExImpl implements BinaryWriter, BinaryRawWriterEx, Obje
      */
     public void doWriteDate(@Nullable Date date) {
         if (date == null)
-            out.writeByte(GridPortableMarshaller.NULL);
+            out.writeByte(GridBinaryMarshaller.NULL);
         else {
             out.unsafeEnsure(1 + 8);
-            out.unsafeWriteByte(GridPortableMarshaller.DATE);
+            out.unsafeWriteByte(GridBinaryMarshaller.DATE);
             out.unsafeWriteLong(date.getTime());
         }
     }
@@ -461,10 +421,10 @@ public class BinaryWriterExImpl implements BinaryWriter, BinaryRawWriterEx, Obje
      */
     public void doWriteTimestamp(@Nullable Timestamp ts) {
         if (ts== null)
-            out.writeByte(GridPortableMarshaller.NULL);
+            out.writeByte(GridBinaryMarshaller.NULL);
         else {
             out.unsafeEnsure(1 + 8 + 4);
-            out.unsafeWriteByte(GridPortableMarshaller.TIMESTAMP);
+            out.unsafeWriteByte(GridBinaryMarshaller.TIMESTAMP);
             out.unsafeWriteLong(ts.getTime());
             out.unsafeWriteInt(ts.getNanos() % 1000000);
         }
@@ -478,7 +438,7 @@ public class BinaryWriterExImpl implements BinaryWriter, BinaryRawWriterEx, Obje
      */
     public void doWriteObject(@Nullable Object obj) throws BinaryObjectException {
         if (obj == null)
-            out.writeByte(GridPortableMarshaller.NULL);
+            out.writeByte(GridBinaryMarshaller.NULL);
         else {
             BinaryWriterExImpl writer = new BinaryWriterExImpl(ctx, out, schema, handles());
 
@@ -491,10 +451,10 @@ public class BinaryWriterExImpl implements BinaryWriter, BinaryRawWriterEx, Obje
      */
     void doWriteByteArray(@Nullable byte[] val) {
         if (val == null)
-            out.writeByte(GridPortableMarshaller.NULL);
+            out.writeByte(GridBinaryMarshaller.NULL);
         else {
             out.unsafeEnsure(1 + 4);
-            out.unsafeWriteByte(GridPortableMarshaller.BYTE_ARR);
+            out.unsafeWriteByte(GridBinaryMarshaller.BYTE_ARR);
             out.unsafeWriteInt(val.length);
 
             out.writeByteArray(val);
@@ -506,10 +466,10 @@ public class BinaryWriterExImpl implements BinaryWriter, BinaryRawWriterEx, Obje
      */
     void doWriteShortArray(@Nullable short[] val) {
         if (val == null)
-            out.writeByte(GridPortableMarshaller.NULL);
+            out.writeByte(GridBinaryMarshaller.NULL);
         else {
             out.unsafeEnsure(1 + 4);
-            out.unsafeWriteByte(GridPortableMarshaller.SHORT_ARR);
+            out.unsafeWriteByte(GridBinaryMarshaller.SHORT_ARR);
             out.unsafeWriteInt(val.length);
 
             out.writeShortArray(val);
@@ -521,10 +481,10 @@ public class BinaryWriterExImpl implements BinaryWriter, BinaryRawWriterEx, Obje
      */
     void doWriteIntArray(@Nullable int[] val) {
         if (val == null)
-            out.writeByte(GridPortableMarshaller.NULL);
+            out.writeByte(GridBinaryMarshaller.NULL);
         else {
             out.unsafeEnsure(1 + 4);
-            out.unsafeWriteByte(GridPortableMarshaller.INT_ARR);
+            out.unsafeWriteByte(GridBinaryMarshaller.INT_ARR);
             out.unsafeWriteInt(val.length);
 
             out.writeIntArray(val);
@@ -536,10 +496,10 @@ public class BinaryWriterExImpl implements BinaryWriter, BinaryRawWriterEx, Obje
      */
     void doWriteLongArray(@Nullable long[] val) {
         if (val == null)
-            out.writeByte(GridPortableMarshaller.NULL);
+            out.writeByte(GridBinaryMarshaller.NULL);
         else {
             out.unsafeEnsure(1 + 4);
-            out.unsafeWriteByte(GridPortableMarshaller.LONG_ARR);
+            out.unsafeWriteByte(GridBinaryMarshaller.LONG_ARR);
             out.unsafeWriteInt(val.length);
 
             out.writeLongArray(val);
@@ -551,10 +511,10 @@ public class BinaryWriterExImpl implements BinaryWriter, BinaryRawWriterEx, Obje
      */
     void doWriteFloatArray(@Nullable float[] val) {
         if (val == null)
-            out.writeByte(GridPortableMarshaller.NULL);
+            out.writeByte(GridBinaryMarshaller.NULL);
         else {
             out.unsafeEnsure(1 + 4);
-            out.unsafeWriteByte(GridPortableMarshaller.FLOAT_ARR);
+            out.unsafeWriteByte(GridBinaryMarshaller.FLOAT_ARR);
             out.unsafeWriteInt(val.length);
 
             out.writeFloatArray(val);
@@ -566,10 +526,10 @@ public class BinaryWriterExImpl implements BinaryWriter, BinaryRawWriterEx, Obje
      */
     void doWriteDoubleArray(@Nullable double[] val) {
         if (val == null)
-            out.writeByte(GridPortableMarshaller.NULL);
+            out.writeByte(GridBinaryMarshaller.NULL);
         else {
             out.unsafeEnsure(1 + 4);
-            out.unsafeWriteByte(GridPortableMarshaller.DOUBLE_ARR);
+            out.unsafeWriteByte(GridBinaryMarshaller.DOUBLE_ARR);
             out.unsafeWriteInt(val.length);
 
             out.writeDoubleArray(val);
@@ -581,10 +541,10 @@ public class BinaryWriterExImpl implements BinaryWriter, BinaryRawWriterEx, Obje
      */
     void doWriteCharArray(@Nullable char[] val) {
         if (val == null)
-            out.writeByte(GridPortableMarshaller.NULL);
+            out.writeByte(GridBinaryMarshaller.NULL);
         else {
             out.unsafeEnsure(1 + 4);
-            out.unsafeWriteByte(GridPortableMarshaller.CHAR_ARR);
+            out.unsafeWriteByte(GridBinaryMarshaller.CHAR_ARR);
             out.unsafeWriteInt(val.length);
 
             out.writeCharArray(val);
@@ -596,10 +556,10 @@ public class BinaryWriterExImpl implements BinaryWriter, BinaryRawWriterEx, Obje
      */
     void doWriteBooleanArray(@Nullable boolean[] val) {
         if (val == null)
-            out.writeByte(GridPortableMarshaller.NULL);
+            out.writeByte(GridBinaryMarshaller.NULL);
         else {
             out.unsafeEnsure(1 + 4);
-            out.unsafeWriteByte(GridPortableMarshaller.BOOLEAN_ARR);
+            out.unsafeWriteByte(GridBinaryMarshaller.BOOLEAN_ARR);
             out.unsafeWriteInt(val.length);
 
             out.writeBooleanArray(val);
@@ -611,10 +571,10 @@ public class BinaryWriterExImpl implements BinaryWriter, BinaryRawWriterEx, Obje
      */
     void doWriteDecimalArray(@Nullable BigDecimal[] val) {
         if (val == null)
-            out.writeByte(GridPortableMarshaller.NULL);
+            out.writeByte(GridBinaryMarshaller.NULL);
         else {
             out.unsafeEnsure(1 + 4);
-            out.unsafeWriteByte(GridPortableMarshaller.DECIMAL_ARR);
+            out.unsafeWriteByte(GridBinaryMarshaller.DECIMAL_ARR);
             out.unsafeWriteInt(val.length);
 
             for (BigDecimal str : val)
@@ -627,10 +587,10 @@ public class BinaryWriterExImpl implements BinaryWriter, BinaryRawWriterEx, Obje
      */
     void doWriteStringArray(@Nullable String[] val) {
         if (val == null)
-            out.writeByte(GridPortableMarshaller.NULL);
+            out.writeByte(GridBinaryMarshaller.NULL);
         else {
             out.unsafeEnsure(1 + 4);
-            out.unsafeWriteByte(GridPortableMarshaller.STRING_ARR);
+            out.unsafeWriteByte(GridBinaryMarshaller.STRING_ARR);
             out.unsafeWriteInt(val.length);
 
             for (String str : val)
@@ -643,10 +603,10 @@ public class BinaryWriterExImpl implements BinaryWriter, BinaryRawWriterEx, Obje
      */
     void doWriteUuidArray(@Nullable UUID[] val) {
         if (val == null)
-            out.writeByte(GridPortableMarshaller.NULL);
+            out.writeByte(GridBinaryMarshaller.NULL);
         else {
             out.unsafeEnsure(1 + 4);
-            out.unsafeWriteByte(GridPortableMarshaller.UUID_ARR);
+            out.unsafeWriteByte(GridBinaryMarshaller.UUID_ARR);
             out.unsafeWriteInt(val.length);
 
             for (UUID uuid : val)
@@ -659,10 +619,10 @@ public class BinaryWriterExImpl implements BinaryWriter, BinaryRawWriterEx, Obje
      */
     void doWriteDateArray(@Nullable Date[] val) {
         if (val == null)
-            out.writeByte(GridPortableMarshaller.NULL);
+            out.writeByte(GridBinaryMarshaller.NULL);
         else {
             out.unsafeEnsure(1 + 4);
-            out.unsafeWriteByte(GridPortableMarshaller.DATE_ARR);
+            out.unsafeWriteByte(GridBinaryMarshaller.DATE_ARR);
             out.unsafeWriteInt(val.length);
 
             for (Date date : val)
@@ -675,10 +635,10 @@ public class BinaryWriterExImpl implements BinaryWriter, BinaryRawWriterEx, Obje
       */
      void doWriteTimestampArray(@Nullable Timestamp[] val) {
          if (val == null)
-             out.writeByte(GridPortableMarshaller.NULL);
+             out.writeByte(GridBinaryMarshaller.NULL);
          else {
              out.unsafeEnsure(1 + 4);
-             out.unsafeWriteByte(GridPortableMarshaller.TIMESTAMP_ARR);
+             out.unsafeWriteByte(GridBinaryMarshaller.TIMESTAMP_ARR);
              out.unsafeWriteInt(val.length);
 
              for (Timestamp ts : val)
@@ -692,20 +652,20 @@ public class BinaryWriterExImpl implements BinaryWriter, BinaryRawWriterEx, Obje
      */
     void doWriteObjectArray(@Nullable Object[] val) throws BinaryObjectException {
         if (val == null)
-            out.writeByte(GridPortableMarshaller.NULL);
+            out.writeByte(GridBinaryMarshaller.NULL);
         else {
             if (tryWriteAsHandle(val))
                 return;
 
-            PortableClassDescriptor desc = ctx.descriptorForClass(val.getClass().getComponentType(), false);
+            BinaryClassDescriptor desc = ctx.descriptorForClass(val.getClass().getComponentType(), false);
 
             out.unsafeEnsure(1 + 4);
-            out.unsafeWriteByte(GridPortableMarshaller.OBJ_ARR);
+            out.unsafeWriteByte(GridBinaryMarshaller.OBJ_ARR);
 
             if (desc.registered())
                 out.unsafeWriteInt(desc.typeId());
             else {
-                out.unsafeWriteInt(GridPortableMarshaller.UNREGISTERED_TYPE_ID);
+                out.unsafeWriteInt(GridBinaryMarshaller.UNREGISTERED_TYPE_ID);
 
                 doWriteString(val.getClass().getComponentType().getName());
             }
@@ -723,13 +683,13 @@ public class BinaryWriterExImpl implements BinaryWriter, BinaryRawWriterEx, Obje
      */
     void doWriteCollection(@Nullable Collection<?> col) throws BinaryObjectException {
         if (col == null)
-            out.writeByte(GridPortableMarshaller.NULL);
+            out.writeByte(GridBinaryMarshaller.NULL);
         else {
             if (tryWriteAsHandle(col))
                 return;
 
             out.unsafeEnsure(1 + 4 + 1);
-            out.unsafeWriteByte(GridPortableMarshaller.COL);
+            out.unsafeWriteByte(GridBinaryMarshaller.COL);
             out.unsafeWriteInt(col.size());
             out.unsafeWriteByte(ctx.collectionType(col.getClass()));
 
@@ -744,13 +704,13 @@ public class BinaryWriterExImpl implements BinaryWriter, BinaryRawWriterEx, Obje
      */
     void doWriteMap(@Nullable Map<?, ?> map) throws BinaryObjectException {
         if (map == null)
-            out.writeByte(GridPortableMarshaller.NULL);
+            out.writeByte(GridBinaryMarshaller.NULL);
         else {
             if (tryWriteAsHandle(map))
                 return;
 
             out.unsafeEnsure(1 + 4 + 1);
-            out.unsafeWriteByte(GridPortableMarshaller.MAP);
+            out.unsafeWriteByte(GridBinaryMarshaller.MAP);
             out.unsafeWriteInt(map.size());
             out.unsafeWriteByte(ctx.mapType(map.getClass()));
 
@@ -766,18 +726,18 @@ public class BinaryWriterExImpl implements BinaryWriter, BinaryRawWriterEx, Obje
      */
     void doWriteEnum(@Nullable Enum<?> val) {
         if (val == null)
-            out.writeByte(GridPortableMarshaller.NULL);
+            out.writeByte(GridBinaryMarshaller.NULL);
         else {
-            PortableClassDescriptor desc = ctx.descriptorForClass(val.getClass(), false);
+            BinaryClassDescriptor desc = ctx.descriptorForClass(val.getClass(), false);
 
             out.unsafeEnsure(1 + 4);
 
-            out.unsafeWriteByte(GridPortableMarshaller.ENUM);
+            out.unsafeWriteByte(GridBinaryMarshaller.ENUM);
 
             if (desc.registered())
                 out.unsafeWriteInt(desc.typeId());
             else {
-                out.unsafeWriteInt(GridPortableMarshaller.UNREGISTERED_TYPE_ID);
+                out.unsafeWriteInt(GridBinaryMarshaller.UNREGISTERED_TYPE_ID);
                 doWriteString(val.getClass().getName());
             }
 
@@ -795,10 +755,10 @@ public class BinaryWriterExImpl implements BinaryWriter, BinaryRawWriterEx, Obje
 
         out.unsafeEnsure(1 + 4);
 
-        out.unsafeWriteByte(GridPortableMarshaller.ENUM);
+        out.unsafeWriteByte(GridBinaryMarshaller.ENUM);
         out.unsafeWriteInt(typeId);
 
-        if (typeId == GridPortableMarshaller.UNREGISTERED_TYPE_ID)
+        if (typeId == GridBinaryMarshaller.UNREGISTERED_TYPE_ID)
             doWriteString(val.className());
 
         out.writeInt(val.enumOrdinal());
@@ -811,18 +771,18 @@ public class BinaryWriterExImpl implements BinaryWriter, BinaryRawWriterEx, Obje
         assert val == null || val.getClass().getComponentType().isEnum();
 
         if (val == null)
-            out.writeByte(GridPortableMarshaller.NULL);
+            out.writeByte(GridBinaryMarshaller.NULL);
         else {
-            PortableClassDescriptor desc = ctx.descriptorForClass(val.getClass().getComponentType(), false);
+            BinaryClassDescriptor desc = ctx.descriptorForClass(val.getClass().getComponentType(), false);
 
             out.unsafeEnsure(1 + 4);
 
-            out.unsafeWriteByte(GridPortableMarshaller.ENUM_ARR);
+            out.unsafeWriteByte(GridBinaryMarshaller.ENUM_ARR);
 
             if (desc.registered())
                 out.unsafeWriteInt(desc.typeId());
             else {
-                out.unsafeWriteInt(GridPortableMarshaller.UNREGISTERED_TYPE_ID);
+                out.unsafeWriteInt(GridBinaryMarshaller.UNREGISTERED_TYPE_ID);
 
                 doWriteString(val.getClass().getComponentType().getName());
             }
@@ -840,18 +800,18 @@ public class BinaryWriterExImpl implements BinaryWriter, BinaryRawWriterEx, Obje
      */
     void doWriteClass(@Nullable Class val) {
         if (val == null)
-            out.writeByte(GridPortableMarshaller.NULL);
+            out.writeByte(GridBinaryMarshaller.NULL);
         else {
-            PortableClassDescriptor desc = ctx.descriptorForClass(val, false);
+            BinaryClassDescriptor desc = ctx.descriptorForClass(val, false);
 
             out.unsafeEnsure(1 + 4);
 
-            out.unsafeWriteByte(GridPortableMarshaller.CLASS);
+            out.unsafeWriteByte(GridBinaryMarshaller.CLASS);
 
             if (desc.registered())
                 out.unsafeWriteInt(desc.typeId());
             else {
-                out.unsafeWriteInt(GridPortableMarshaller.UNREGISTERED_TYPE_ID);
+                out.unsafeWriteInt(GridBinaryMarshaller.UNREGISTERED_TYPE_ID);
 
                 doWriteString(val.getClass().getName());
             }
@@ -863,13 +823,13 @@ public class BinaryWriterExImpl implements BinaryWriter, BinaryRawWriterEx, Obje
      */
     public void doWritePortableObject(@Nullable BinaryObjectImpl po) {
         if (po == null)
-            out.writeByte(GridPortableMarshaller.NULL);
+            out.writeByte(GridBinaryMarshaller.NULL);
         else {
             byte[] poArr = po.array();
 
             out.unsafeEnsure(1 + 4 + poArr.length + 4);
 
-            out.unsafeWriteByte(GridPortableMarshaller.PORTABLE_OBJ);
+            out.unsafeWriteByte(GridBinaryMarshaller.PORTABLE_OBJ);
             out.unsafeWriteInt(poArr.length);
             out.writeByteArray(poArr);
             out.unsafeWriteInt(po.start());
@@ -882,7 +842,7 @@ public class BinaryWriterExImpl implements BinaryWriter, BinaryRawWriterEx, Obje
     void writeByteFieldPrimitive(byte val) {
         out.unsafeEnsure(1 + 1);
 
-        out.unsafeWriteByte(GridPortableMarshaller.BYTE);
+        out.unsafeWriteByte(GridBinaryMarshaller.BYTE);
         out.unsafeWriteByte(val);
     }
 
@@ -891,7 +851,7 @@ public class BinaryWriterExImpl implements BinaryWriter, BinaryRawWriterEx, Obje
      */
     void writeByteField(@Nullable Byte val) {
         if (val == null)
-            out.writeByte(GridPortableMarshaller.NULL);
+            out.writeByte(GridBinaryMarshaller.NULL);
         else
             writeByteFieldPrimitive(val);
     }
@@ -909,7 +869,7 @@ public class BinaryWriterExImpl implements BinaryWriter, BinaryRawWriterEx, Obje
     void writeShortFieldPrimitive(short val) {
         out.unsafeEnsure(1 + 2);
 
-        out.unsafeWriteByte(GridPortableMarshaller.SHORT);
+        out.unsafeWriteByte(GridBinaryMarshaller.SHORT);
         out.unsafeWriteShort(val);
     }
 
@@ -918,7 +878,7 @@ public class BinaryWriterExImpl implements BinaryWriter, BinaryRawWriterEx, Obje
      */
     void writeShortField(@Nullable Short val) {
         if (val == null)
-            out.writeByte(GridPortableMarshaller.NULL);
+            out.writeByte(GridBinaryMarshaller.NULL);
         else
             writeShortFieldPrimitive(val);
     }
@@ -929,7 +889,7 @@ public class BinaryWriterExImpl implements BinaryWriter, BinaryRawWriterEx, Obje
     void writeIntFieldPrimitive(int val) {
         out.unsafeEnsure(1 + 4);
 
-        out.unsafeWriteByte(GridPortableMarshaller.INT);
+        out.unsafeWriteByte(GridBinaryMarshaller.INT);
         out.unsafeWriteInt(val);
     }
 
@@ -938,7 +898,7 @@ public class BinaryWriterExImpl implements BinaryWriter, BinaryRawWriterEx, Obje
      */
     void writeIntField(@Nullable Integer val) {
         if (val == null)
-            out.writeByte(GridPortableMarshaller.NULL);
+            out.writeByte(GridBinaryMarshaller.NULL);
         else
             writeIntFieldPrimitive(val);
     }
@@ -949,7 +909,7 @@ public class BinaryWriterExImpl implements BinaryWriter, BinaryRawWriterEx, Obje
     void writeLongFieldPrimitive(long val) {
         out.unsafeEnsure(1 + 8);
 
-        out.unsafeWriteByte(GridPortableMarshaller.LONG);
+        out.unsafeWriteByte(GridBinaryMarshaller.LONG);
         out.unsafeWriteLong(val);
     }
 
@@ -958,7 +918,7 @@ public class BinaryWriterExImpl implements BinaryWriter, BinaryRawWriterEx, Obje
      */
     void writeLongField(@Nullable Long val) {
         if (val == null)
-            out.writeByte(GridPortableMarshaller.NULL);
+            out.writeByte(GridBinaryMarshaller.NULL);
         else
             writeLongFieldPrimitive(val);
     }
@@ -969,7 +929,7 @@ public class BinaryWriterExImpl implements BinaryWriter, BinaryRawWriterEx, Obje
     void writeFloatFieldPrimitive(float val) {
         out.unsafeEnsure(1 + 4);
 
-        out.unsafeWriteByte(GridPortableMarshaller.FLOAT);
+        out.unsafeWriteByte(GridBinaryMarshaller.FLOAT);
         out.unsafeWriteFloat(val);
     }
 
@@ -978,7 +938,7 @@ public class BinaryWriterExImpl implements BinaryWriter, BinaryRawWriterEx, Obje
      */
     void writeFloatField(@Nullable Float val) {
         if (val == null)
-            out.writeByte(GridPortableMarshaller.NULL);
+            out.writeByte(GridBinaryMarshaller.NULL);
         else
             writeFloatFieldPrimitive(val);
     }
@@ -989,7 +949,7 @@ public class BinaryWriterExImpl implements BinaryWriter, BinaryRawWriterEx, Obje
     void writeDoubleFieldPrimitive(double val) {
         out.unsafeEnsure(1 + 8);
 
-        out.unsafeWriteByte(GridPortableMarshaller.DOUBLE);
+        out.unsafeWriteByte(GridBinaryMarshaller.DOUBLE);
         out.unsafeWriteDouble(val);
     }
 
@@ -998,7 +958,7 @@ public class BinaryWriterExImpl implements BinaryWriter, BinaryRawWriterEx, Obje
      */
     void writeDoubleField(@Nullable Double val) {
         if (val == null)
-            out.writeByte(GridPortableMarshaller.NULL);
+            out.writeByte(GridBinaryMarshaller.NULL);
         else
             writeDoubleFieldPrimitive(val);
     }
@@ -1009,7 +969,7 @@ public class BinaryWriterExImpl implements BinaryWriter, BinaryRawWriterEx, Obje
     void writeCharFieldPrimitive(char val) {
         out.unsafeEnsure(1 + 2);
 
-        out.unsafeWriteByte(GridPortableMarshaller.CHAR);
+        out.unsafeWriteByte(GridBinaryMarshaller.CHAR);
         out.unsafeWriteChar(val);
     }
 
@@ -1018,7 +978,7 @@ public class BinaryWriterExImpl implements BinaryWriter, BinaryRawWriterEx, Obje
      */
     void writeCharField(@Nullable Character val) {
         if (val == null)
-            out.writeByte(GridPortableMarshaller.NULL);
+            out.writeByte(GridBinaryMarshaller.NULL);
         else
             writeCharFieldPrimitive(val);
     }
@@ -1029,7 +989,7 @@ public class BinaryWriterExImpl implements BinaryWriter, BinaryRawWriterEx, Obje
     void writeBooleanFieldPrimitive(boolean val) {
         out.unsafeEnsure(1 + 1);
 
-        out.unsafeWriteByte(GridPortableMarshaller.BOOLEAN);
+        out.unsafeWriteByte(GridBinaryMarshaller.BOOLEAN);
         out.unsafeWriteBoolean(val);
     }
 
@@ -1038,7 +998,7 @@ public class BinaryWriterExImpl implements BinaryWriter, BinaryRawWriterEx, Obje
      */
     void writeBooleanField(@Nullable Boolean val) {
         if (val == null)
-            out.writeByte(GridPortableMarshaller.NULL);
+            out.writeByte(GridBinaryMarshaller.NULL);
         else
             writeBooleanFieldPrimitive(val);
     }
@@ -1380,7 +1340,7 @@ public class BinaryWriterExImpl implements BinaryWriter, BinaryRawWriterEx, Obje
     /** {@inheritDoc} */
     @Override public void writeObjectDetached(@Nullable Object obj) throws BinaryObjectException {
         if (obj == null)
-            out.writeByte(GridPortableMarshaller.NULL);
+            out.writeByte(GridBinaryMarshaller.NULL);
         else {
             BinaryWriterExImpl writer = new BinaryWriterExImpl(ctx, out, schema, null);
 
@@ -1601,7 +1561,7 @@ public class BinaryWriterExImpl implements BinaryWriter, BinaryRawWriterEx, Obje
     }
 
     /** {@inheritDoc} */
-    @Override public PortableOutputStream out() {
+    @Override public BinaryOutputStream out() {
         return out;
     }
 
@@ -1698,7 +1658,7 @@ public class BinaryWriterExImpl implements BinaryWriter, BinaryRawWriterEx, Obje
         int fieldOff = out.position() - start;
 
         // Advance schema hash.
-        schemaId = PortableUtils.updateSchemaId(schemaId, fieldId);
+        schemaId = BinaryUtils.updateSchemaId(schemaId, fieldId);
 
         schema.push(fieldId, fieldOff);
 
@@ -1736,8 +1696,8 @@ public class BinaryWriterExImpl implements BinaryWriter, BinaryRawWriterEx, Obje
     /**
      * @return Current writer's schema.
      */
-    public PortableSchema currentSchema() {
-        PortableSchema.Builder builder = PortableSchema.Builder.newBuilder();
+    public BinarySchema currentSchema() {
+        BinarySchema.Builder builder = BinarySchema.Builder.newBuilder();
 
         if (schema != null)
             schema.build(builder, fieldCnt);
@@ -1778,7 +1738,7 @@ public class BinaryWriterExImpl implements BinaryWriter, BinaryRawWriterEx, Obje
         else {
             out.unsafeEnsure(1 + 4);
 
-            out.unsafeWriteByte(GridPortableMarshaller.HANDLE);
+            out.unsafeWriteByte(GridBinaryMarshaller.HANDLE);
             out.unsafeWriteInt(pos - old);
 
             return true;
@@ -1802,7 +1762,7 @@ public class BinaryWriterExImpl implements BinaryWriter, BinaryRawWriterEx, Obje
     /**
      * @return Portable context.
      */
-    public PortableContext context() {
+    public BinaryContext context() {
         return ctx;
     }
 }

http://git-wip-us.apache.org/repos/asf/ignite/blob/71ad9cea/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryWriterSchemaHolder.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryWriterSchemaHolder.java b/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryWriterSchemaHolder.java
index 7fd6442..22ae8e3 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryWriterSchemaHolder.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryWriterSchemaHolder.java
@@ -17,8 +17,7 @@
 
 package org.apache.ignite.internal.binary;
 
-import org.apache.ignite.internal.binary.streams.PortableOutputStream;
-import org.apache.ignite.internal.binary.streams.PortableOutputStream;
+import org.apache.ignite.internal.binary.streams.BinaryOutputStream;
 
 /**
  * Binary writer schema holder.
@@ -66,7 +65,7 @@ public class BinaryWriterSchemaHolder {
      * @param builder Builder.
      * @param fieldCnt Fields count.
      */
-    public void build(PortableSchema.Builder builder, int fieldCnt) {
+    public void build(BinarySchema.Builder builder, int fieldCnt) {
         for (int curIdx = idx - fieldCnt * 2; curIdx < idx; curIdx += 2)
             builder.addField(data[curIdx]);
     }
@@ -79,7 +78,7 @@ public class BinaryWriterSchemaHolder {
      * @param compactFooter Whether footer should be written in compact form.
      * @return Amount of bytes dedicated to each field offset. Could be 1, 2 or 4.
      */
-    public int write(PortableOutputStream out, int fieldCnt, boolean compactFooter) {
+    public int write(BinaryOutputStream out, int fieldCnt, boolean compactFooter) {
         int startIdx = idx - fieldCnt * 2;
         assert startIdx >= 0;
 
@@ -95,19 +94,19 @@ public class BinaryWriterSchemaHolder {
                 for (int curIdx = startIdx + 1; curIdx < idx; curIdx += 2)
                     out.unsafeWriteByte((byte)data[curIdx]);
 
-                res = PortableUtils.OFFSET_1;
+                res = BinaryUtils.OFFSET_1;
             }
             else if (lastOffset < MAX_OFFSET_2) {
                 for (int curIdx = startIdx + 1; curIdx < idx; curIdx += 2)
                     out.unsafeWriteShort((short) data[curIdx]);
 
-                res = PortableUtils.OFFSET_2;
+                res = BinaryUtils.OFFSET_2;
             }
             else {
                 for (int curIdx = startIdx + 1; curIdx < idx; curIdx += 2)
                     out.unsafeWriteInt(data[curIdx]);
 
-                res = PortableUtils.OFFSET_4;
+                res = BinaryUtils.OFFSET_4;
             }
         }
         else {
@@ -117,7 +116,7 @@ public class BinaryWriterSchemaHolder {
                     out.unsafeWriteByte((byte) data[curIdx++]);
                 }
 
-                res = PortableUtils.OFFSET_1;
+                res = BinaryUtils.OFFSET_1;
             }
             else if (lastOffset < MAX_OFFSET_2) {
                 for (int curIdx = startIdx; curIdx < idx;) {
@@ -125,7 +124,7 @@ public class BinaryWriterSchemaHolder {
                     out.unsafeWriteShort((short) data[curIdx++]);
                 }
 
-                res = PortableUtils.OFFSET_2;
+                res = BinaryUtils.OFFSET_2;
             }
             else {
                 for (int curIdx = startIdx; curIdx < idx;) {
@@ -133,7 +132,7 @@ public class BinaryWriterSchemaHolder {
                     out.unsafeWriteInt(data[curIdx++]);
                 }
 
-                res = PortableUtils.OFFSET_4;
+                res = BinaryUtils.OFFSET_4;
             }
         }
 

http://git-wip-us.apache.org/repos/asf/ignite/blob/71ad9cea/modules/core/src/main/java/org/apache/ignite/internal/binary/GridBinaryMarshaller.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/binary/GridBinaryMarshaller.java b/modules/core/src/main/java/org/apache/ignite/internal/binary/GridBinaryMarshaller.java
new file mode 100644
index 0000000..277abd0
--- /dev/null
+++ b/modules/core/src/main/java/org/apache/ignite/internal/binary/GridBinaryMarshaller.java
@@ -0,0 +1,286 @@
+/*
+ * 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.binary;
+
+import org.apache.ignite.internal.binary.streams.BinaryHeapInputStream;
+import org.apache.ignite.internal.binary.streams.BinaryInputStream;
+import org.apache.ignite.internal.binary.streams.BinaryOutputStream;
+import org.apache.ignite.binary.BinaryObjectException;
+import org.jetbrains.annotations.Nullable;
+
+/**
+ * Portable objects marshaller.
+ */
+public class GridBinaryMarshaller {
+    /** */
+    public static final ThreadLocal<Boolean> KEEP_PORTABLES = new ThreadLocal<Boolean>() {
+        @Override protected Boolean initialValue() {
+            return true;
+        }
+    };
+
+    /** */
+    static final byte OPTM_MARSH = -2;
+
+    /** */
+    public static final byte BYTE = 1;
+
+    /** */
+    public static final byte SHORT = 2;
+
+    /** */
+    public static final byte INT = 3;
+
+    /** */
+    public static final byte LONG = 4;
+
+    /** */
+    public static final byte FLOAT = 5;
+
+    /** */
+    public static final byte DOUBLE = 6;
+
+    /** */
+    public static final byte CHAR = 7;
+
+    /** */
+    public static final byte BOOLEAN = 8;
+
+    /** */
+    public static final byte DECIMAL = 30;
+
+    /** */
+    public static final byte STRING = 9;
+
+    /** */
+    public static final byte UUID = 10;
+
+    /** */
+    public static final byte DATE = 11;
+
+    /** */
+    public static final byte BYTE_ARR = 12;
+
+    /** */
+    public static final byte SHORT_ARR = 13;
+
+    /** */
+    public static final byte INT_ARR = 14;
+
+    /** */
+    public static final byte LONG_ARR = 15;
+
+    /** */
+    public static final byte FLOAT_ARR = 16;
+
+    /** */
+    public static final byte DOUBLE_ARR = 17;
+
+    /** */
+    public static final byte CHAR_ARR = 18;
+
+    /** */
+    public static final byte BOOLEAN_ARR = 19;
+
+    /** */
+    public static final byte DECIMAL_ARR = 31;
+
+    /** */
+    public static final byte STRING_ARR = 20;
+
+    /** */
+    public static final byte UUID_ARR = 21;
+
+    /** */
+    public static final byte DATE_ARR = 22;
+
+    /** */
+    public static final byte OBJ_ARR = 23;
+
+    /** */
+    public static final byte COL = 24;
+
+    /** */
+    public static final byte MAP = 25;
+
+    /** */
+    public static final byte PORTABLE_OBJ = 27;
+
+    /** */
+    public static final byte ENUM = 28;
+
+    /** */
+    public static final byte ENUM_ARR = 29;
+
+    /** */
+    public static final byte CLASS = 32;
+
+    /** Timestamp. */
+    public static final byte TIMESTAMP = 33;
+
+    /** Timestamp array. */
+    public static final byte TIMESTAMP_ARR = 34;
+
+    /** */
+    public static final byte NULL = (byte)101;
+
+    /** */
+    public static final byte HANDLE = (byte)102;
+
+    /** */
+    public static final byte OBJ = (byte)103;
+
+    /** */
+    public static final byte USER_SET = -1;
+
+    /** */
+    public static final byte USER_COL = 0;
+
+    /** */
+    public static final byte ARR_LIST = 1;
+
+    /** */
+    public static final byte LINKED_LIST = 2;
+
+    /** */
+    public static final byte HASH_SET = 3;
+
+    /** */
+    public static final byte LINKED_HASH_SET = 4;
+
+    /** */
+    public static final byte HASH_MAP = 1;
+
+    /** */
+    public static final byte LINKED_HASH_MAP = 2;
+
+    /** */
+    public static final int OBJECT_TYPE_ID = -1;
+
+    /** */
+    public static final int UNREGISTERED_TYPE_ID = 0;
+
+    /** Protocol version. */
+    public static final byte PROTO_VER = 1;
+
+    /** Protocol version position. */
+    public static final int PROTO_VER_POS = 1;
+
+    /** Flags position in header. */
+    public static final int FLAGS_POS = 2;
+
+    /** */
+    public static final int TYPE_ID_POS = 4;
+
+    /** */
+    public static final int HASH_CODE_POS = 8;
+
+    /** */
+    public static final int TOTAL_LEN_POS = 12;
+
+    /** */
+    public static final int SCHEMA_ID_POS = 16;
+
+    /** Schema or raw offset position. */
+    public static final int SCHEMA_OR_RAW_OFF_POS = 20;
+
+    /** */
+    public static final byte DFLT_HDR_LEN = 24;
+
+    /** */
+    private final BinaryContext ctx;
+
+    /**
+     * @param ctx Context.
+     */
+    public GridBinaryMarshaller(BinaryContext ctx) {
+        this.ctx = ctx;
+    }
+
+    /**
+     * @param obj Object to marshal.
+     * @return Byte array.
+     * @throws org.apache.ignite.binary.BinaryObjectException In case of error.
+     */
+    public byte[] marshal(@Nullable Object obj) throws BinaryObjectException {
+        if (obj == null)
+            return new byte[] { NULL };
+
+        try (BinaryWriterExImpl writer = new BinaryWriterExImpl(ctx)) {
+            writer.marshal(obj);
+
+            return writer.array();
+        }
+    }
+
+    /**
+     * @param bytes Bytes array.
+     * @return Portable object.
+     * @throws org.apache.ignite.binary.BinaryObjectException In case of error.
+     */
+    @SuppressWarnings("unchecked")
+    @Nullable public <T> T unmarshal(byte[] bytes, @Nullable ClassLoader clsLdr) throws BinaryObjectException {
+        assert bytes != null;
+
+        return (T)BinaryUtils.unmarshal(BinaryHeapInputStream.create(bytes, 0), ctx, clsLdr);
+    }
+
+    /**
+     * @param in Input stream.
+     * @return Portable object.
+     * @throws org.apache.ignite.binary.BinaryObjectException In case of error.
+     */
+    @SuppressWarnings("unchecked")
+    @Nullable public <T> T unmarshal(BinaryInputStream in) throws BinaryObjectException {
+        return (T)BinaryUtils.unmarshal(in, ctx, null);
+    }
+
+    /**
+     * @param arr Byte array.
+     * @param ldr Class loader.
+     * @return Deserialized object.
+     * @throws org.apache.ignite.binary.BinaryObjectException In case of error.
+     */
+    @SuppressWarnings("unchecked")
+    @Nullable public <T> T deserialize(byte[] arr, @Nullable ClassLoader ldr) throws BinaryObjectException {
+        assert arr != null;
+        assert arr.length > 0;
+
+        if (arr[0] == NULL)
+            return null;
+
+        return (T)new BinaryReaderExImpl(ctx, BinaryHeapInputStream.create(arr, 0), ldr).deserialize();
+    }
+
+    /**
+     * Gets writer for the given output stream.
+     *
+     * @param out Output stream.
+     * @return Writer.
+     */
+    public BinaryWriterExImpl writer(BinaryOutputStream out) {
+        return new BinaryWriterExImpl(ctx, out, BinaryThreadLocalContext.get().schemaHolder(), null);
+    }
+
+    /**
+     * @return Context.
+     */
+    public BinaryContext context() {
+        return ctx;
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/71ad9cea/modules/core/src/main/java/org/apache/ignite/internal/binary/GridPortableMarshaller.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/binary/GridPortableMarshaller.java b/modules/core/src/main/java/org/apache/ignite/internal/binary/GridPortableMarshaller.java
deleted file mode 100644
index a57bb55..0000000
--- a/modules/core/src/main/java/org/apache/ignite/internal/binary/GridPortableMarshaller.java
+++ /dev/null
@@ -1,289 +0,0 @@
-/*
- * 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.binary;
-
-import org.apache.ignite.internal.binary.streams.PortableHeapInputStream;
-import org.apache.ignite.internal.binary.streams.PortableInputStream;
-import org.apache.ignite.internal.binary.streams.PortableOutputStream;
-import org.apache.ignite.internal.binary.streams.PortableHeapInputStream;
-import org.apache.ignite.internal.binary.streams.PortableInputStream;
-import org.apache.ignite.internal.binary.streams.PortableOutputStream;
-import org.apache.ignite.binary.BinaryObjectException;
-import org.jetbrains.annotations.Nullable;
-
-/**
- * Portable objects marshaller.
- */
-public class GridPortableMarshaller {
-    /** */
-    public static final ThreadLocal<Boolean> KEEP_PORTABLES = new ThreadLocal<Boolean>() {
-        @Override protected Boolean initialValue() {
-            return true;
-        }
-    };
-
-    /** */
-    static final byte OPTM_MARSH = -2;
-
-    /** */
-    public static final byte BYTE = 1;
-
-    /** */
-    public static final byte SHORT = 2;
-
-    /** */
-    public static final byte INT = 3;
-
-    /** */
-    public static final byte LONG = 4;
-
-    /** */
-    public static final byte FLOAT = 5;
-
-    /** */
-    public static final byte DOUBLE = 6;
-
-    /** */
-    public static final byte CHAR = 7;
-
-    /** */
-    public static final byte BOOLEAN = 8;
-
-    /** */
-    public static final byte DECIMAL = 30;
-
-    /** */
-    public static final byte STRING = 9;
-
-    /** */
-    public static final byte UUID = 10;
-
-    /** */
-    public static final byte DATE = 11;
-
-    /** */
-    public static final byte BYTE_ARR = 12;
-
-    /** */
-    public static final byte SHORT_ARR = 13;
-
-    /** */
-    public static final byte INT_ARR = 14;
-
-    /** */
-    public static final byte LONG_ARR = 15;
-
-    /** */
-    public static final byte FLOAT_ARR = 16;
-
-    /** */
-    public static final byte DOUBLE_ARR = 17;
-
-    /** */
-    public static final byte CHAR_ARR = 18;
-
-    /** */
-    public static final byte BOOLEAN_ARR = 19;
-
-    /** */
-    public static final byte DECIMAL_ARR = 31;
-
-    /** */
-    public static final byte STRING_ARR = 20;
-
-    /** */
-    public static final byte UUID_ARR = 21;
-
-    /** */
-    public static final byte DATE_ARR = 22;
-
-    /** */
-    public static final byte OBJ_ARR = 23;
-
-    /** */
-    public static final byte COL = 24;
-
-    /** */
-    public static final byte MAP = 25;
-
-    /** */
-    public static final byte PORTABLE_OBJ = 27;
-
-    /** */
-    public static final byte ENUM = 28;
-
-    /** */
-    public static final byte ENUM_ARR = 29;
-
-    /** */
-    public static final byte CLASS = 32;
-
-    /** Timestamp. */
-    public static final byte TIMESTAMP = 33;
-
-    /** Timestamp array. */
-    public static final byte TIMESTAMP_ARR = 34;
-
-    /** */
-    public static final byte NULL = (byte)101;
-
-    /** */
-    public static final byte HANDLE = (byte)102;
-
-    /** */
-    public static final byte OBJ = (byte)103;
-
-    /** */
-    public static final byte USER_SET = -1;
-
-    /** */
-    public static final byte USER_COL = 0;
-
-    /** */
-    public static final byte ARR_LIST = 1;
-
-    /** */
-    public static final byte LINKED_LIST = 2;
-
-    /** */
-    public static final byte HASH_SET = 3;
-
-    /** */
-    public static final byte LINKED_HASH_SET = 4;
-
-    /** */
-    public static final byte HASH_MAP = 1;
-
-    /** */
-    public static final byte LINKED_HASH_MAP = 2;
-
-    /** */
-    public static final int OBJECT_TYPE_ID = -1;
-
-    /** */
-    public static final int UNREGISTERED_TYPE_ID = 0;
-
-    /** Protocol version. */
-    public static final byte PROTO_VER = 1;
-
-    /** Protocol version position. */
-    public static final int PROTO_VER_POS = 1;
-
-    /** Flags position in header. */
-    public static final int FLAGS_POS = 2;
-
-    /** */
-    public static final int TYPE_ID_POS = 4;
-
-    /** */
-    public static final int HASH_CODE_POS = 8;
-
-    /** */
-    public static final int TOTAL_LEN_POS = 12;
-
-    /** */
-    public static final int SCHEMA_ID_POS = 16;
-
-    /** Schema or raw offset position. */
-    public static final int SCHEMA_OR_RAW_OFF_POS = 20;
-
-    /** */
-    public static final byte DFLT_HDR_LEN = 24;
-
-    /** */
-    private final PortableContext ctx;
-
-    /**
-     * @param ctx Context.
-     */
-    public GridPortableMarshaller(PortableContext ctx) {
-        this.ctx = ctx;
-    }
-
-    /**
-     * @param obj Object to marshal.
-     * @return Byte array.
-     * @throws org.apache.ignite.binary.BinaryObjectException In case of error.
-     */
-    public byte[] marshal(@Nullable Object obj) throws BinaryObjectException {
-        if (obj == null)
-            return new byte[] { NULL };
-
-        try (BinaryWriterExImpl writer = new BinaryWriterExImpl(ctx)) {
-            writer.marshal(obj);
-
-            return writer.array();
-        }
-    }
-
-    /**
-     * @param bytes Bytes array.
-     * @return Portable object.
-     * @throws org.apache.ignite.binary.BinaryObjectException In case of error.
-     */
-    @SuppressWarnings("unchecked")
-    @Nullable public <T> T unmarshal(byte[] bytes, @Nullable ClassLoader clsLdr) throws BinaryObjectException {
-        assert bytes != null;
-
-        return (T)PortableUtils.unmarshal(PortableHeapInputStream.create(bytes, 0), ctx, clsLdr);
-    }
-
-    /**
-     * @param in Input stream.
-     * @return Portable object.
-     * @throws org.apache.ignite.binary.BinaryObjectException In case of error.
-     */
-    @SuppressWarnings("unchecked")
-    @Nullable public <T> T unmarshal(PortableInputStream in) throws BinaryObjectException {
-        return (T)PortableUtils.unmarshal(in, ctx, null);
-    }
-
-    /**
-     * @param arr Byte array.
-     * @param ldr Class loader.
-     * @return Deserialized object.
-     * @throws org.apache.ignite.binary.BinaryObjectException In case of error.
-     */
-    @SuppressWarnings("unchecked")
-    @Nullable public <T> T deserialize(byte[] arr, @Nullable ClassLoader ldr) throws BinaryObjectException {
-        assert arr != null;
-        assert arr.length > 0;
-
-        if (arr[0] == NULL)
-            return null;
-
-        return (T)new BinaryReaderExImpl(ctx, PortableHeapInputStream.create(arr, 0), ldr).deserialize();
-    }
-
-    /**
-     * Gets writer for the given output stream.
-     *
-     * @param out Output stream.
-     * @return Writer.
-     */
-    public BinaryWriterExImpl writer(PortableOutputStream out) {
-        return new BinaryWriterExImpl(ctx, out, BinaryThreadLocalContext.get().schemaHolder(), null);
-    }
-
-    /**
-     * @return Context.
-     */
-    public PortableContext context() {
-        return ctx;
-    }
-}

http://git-wip-us.apache.org/repos/asf/ignite/blob/71ad9cea/modules/core/src/main/java/org/apache/ignite/internal/binary/PortableClassDescriptor.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/binary/PortableClassDescriptor.java b/modules/core/src/main/java/org/apache/ignite/internal/binary/PortableClassDescriptor.java
deleted file mode 100644
index 9b4d444..0000000
--- a/modules/core/src/main/java/org/apache/ignite/internal/binary/PortableClassDescriptor.java
+++ /dev/null
@@ -1,813 +0,0 @@
-/*
- * 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.binary;
-
-import java.io.Externalizable;
-import java.io.IOException;
-import java.io.ObjectInputStream;
-import java.io.ObjectOutputStream;
-import java.lang.reflect.Constructor;
-import java.lang.reflect.Field;
-import java.lang.reflect.InvocationTargetException;
-import java.lang.reflect.Method;
-import java.lang.reflect.Modifier;
-import java.math.BigDecimal;
-import java.sql.Timestamp;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.Date;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Map;
-import java.util.UUID;
-import org.apache.ignite.IgniteCheckedException;
-import org.apache.ignite.binary.BinaryIdMapper;
-import org.apache.ignite.binary.BinaryObjectException;
-import org.apache.ignite.binary.BinarySerializer;
-import org.apache.ignite.binary.Binarylizable;
-import org.apache.ignite.internal.processors.cache.CacheObjectImpl;
-import org.apache.ignite.internal.util.GridUnsafe;
-import org.apache.ignite.internal.util.typedef.internal.U;
-import org.apache.ignite.marshaller.MarshallerExclusions;
-import org.apache.ignite.marshaller.optimized.OptimizedMarshaller;
-import org.jetbrains.annotations.Nullable;
-import sun.misc.Unsafe;
-
-import static java.lang.reflect.Modifier.isStatic;
-import static java.lang.reflect.Modifier.isTransient;
-
-/**
- * Portable class descriptor.
- */
-public class PortableClassDescriptor {
-    /** */
-    public static final Unsafe UNSAFE = GridUnsafe.unsafe();
-
-    /** */
-    private final PortableContext ctx;
-
-    /** */
-    private final Class<?> cls;
-
-    /** */
-    private final BinarySerializer serializer;
-
-    /** ID mapper. */
-    private final BinaryIdMapper idMapper;
-
-    /** */
-    private final BinaryWriteMode mode;
-
-    /** */
-    private final boolean userType;
-
-    /** */
-    private final int typeId;
-
-    /** */
-    private final String typeName;
-
-    /** Affinity key field name. */
-    private final String affKeyFieldName;
-
-    /** */
-    private final Constructor<?> ctor;
-
-    /** */
-    private final BinaryFieldAccessor[] fields;
-
-    /** */
-    private final Method writeReplaceMtd;
-
-    /** */
-    private final Method readResolveMtd;
-
-    /** */
-    private final Map<String, Integer> stableFieldsMeta;
-
-    /** Object schemas. Initialized only for serializable classes and contains only 1 entry. */
-    private final PortableSchema stableSchema;
-
-    /** Schema registry. */
-    private final PortableSchemaRegistry schemaReg;
-
-    /** */
-    private final boolean registered;
-
-    /** */
-    private final boolean useOptMarshaller;
-
-    /** */
-    private final boolean excluded;
-
-    /**
-     * @param ctx Context.
-     * @param cls Class.
-     * @param userType User type flag.
-     * @param typeId Type ID.
-     * @param typeName Type name.
-     * @param affKeyFieldName Affinity key field name.
-     * @param idMapper ID mapper.
-     * @param serializer Serializer.
-     * @param metaDataEnabled Metadata enabled flag.
-     * @param registered Whether typeId has been successfully registered by MarshallerContext or not.
-     * @param predefined Whether the class is predefined or not.
-     * @throws BinaryObjectException In case of error.
-     */
-    PortableClassDescriptor(
-        PortableContext ctx,
-        Class<?> cls,
-        boolean userType,
-        int typeId,
-        String typeName,
-        @Nullable String affKeyFieldName,
-        @Nullable BinaryIdMapper idMapper,
-        @Nullable BinarySerializer serializer,
-        boolean metaDataEnabled,
-        boolean registered,
-        boolean predefined
-    ) throws BinaryObjectException {
-        assert ctx != null;
-        assert cls != null;
-        assert idMapper != null;
-
-        this.ctx = ctx;
-        this.cls = cls;
-        this.typeId = typeId;
-        this.userType = userType;
-        this.typeName = typeName;
-        this.affKeyFieldName = affKeyFieldName;
-        this.serializer = serializer;
-        this.idMapper = idMapper;
-        this.registered = registered;
-
-        schemaReg = ctx.schemaRegistry(typeId);
-
-        excluded = MarshallerExclusions.isExcluded(cls);
-
-        useOptMarshaller = !predefined && initUseOptimizedMarshallerFlag();
-
-        if (excluded)
-            mode = BinaryWriteMode.EXCLUSION;
-        else {
-            if (cls == BinaryEnumObjectImpl.class)
-                mode = BinaryWriteMode.PORTABLE_ENUM;
-            else
-                mode = serializer != null ? BinaryWriteMode.PORTABLE : PortableUtils.mode(cls);
-        }
-
-        switch (mode) {
-            case P_BYTE:
-            case P_BOOLEAN:
-            case P_SHORT:
-            case P_CHAR:
-            case P_INT:
-            case P_LONG:
-            case P_FLOAT:
-            case P_DOUBLE:
-            case BYTE:
-            case SHORT:
-            case INT:
-            case LONG:
-            case FLOAT:
-            case DOUBLE:
-            case CHAR:
-            case BOOLEAN:
-            case DECIMAL:
-            case STRING:
-            case UUID:
-            case DATE:
-            case TIMESTAMP:
-            case BYTE_ARR:
-            case SHORT_ARR:
-            case INT_ARR:
-            case LONG_ARR:
-            case FLOAT_ARR:
-            case DOUBLE_ARR:
-            case CHAR_ARR:
-            case BOOLEAN_ARR:
-            case DECIMAL_ARR:
-            case STRING_ARR:
-            case UUID_ARR:
-            case DATE_ARR:
-            case TIMESTAMP_ARR:
-            case OBJECT_ARR:
-            case COL:
-            case MAP:
-            case PORTABLE_OBJ:
-            case ENUM:
-            case PORTABLE_ENUM:
-            case ENUM_ARR:
-            case CLASS:
-            case EXCLUSION:
-                ctor = null;
-                fields = null;
-                stableFieldsMeta = null;
-                stableSchema = null;
-
-                break;
-
-            case PORTABLE:
-            case EXTERNALIZABLE:
-                ctor = constructor(cls);
-                fields = null;
-                stableFieldsMeta = null;
-                stableSchema = null;
-
-                break;
-
-            case OBJECT:
-                // Must not use constructor to honor transient fields semantics.
-                ctor = null;
-                ArrayList<BinaryFieldAccessor> fields0 = new ArrayList<>();
-                stableFieldsMeta = metaDataEnabled ? new HashMap<String, Integer>() : null;
-
-                PortableSchema.Builder schemaBuilder = PortableSchema.Builder.newBuilder();
-
-                Collection<String> names = new HashSet<>();
-                Collection<Integer> ids = new HashSet<>();
-
-                for (Class<?> c = cls; c != null && !c.equals(Object.class); c = c.getSuperclass()) {
-                    for (Field f : c.getDeclaredFields()) {
-                        int mod = f.getModifiers();
-
-                        if (!isStatic(mod) && !isTransient(mod)) {
-                            f.setAccessible(true);
-
-                            String name = f.getName();
-
-                            if (!names.add(name))
-                                throw new BinaryObjectException("Duplicate field name [fieldName=" + name +
-                                    ", cls=" + cls.getName() + ']');
-
-                            int fieldId = idMapper.fieldId(typeId, name);
-
-                            if (!ids.add(fieldId))
-                                throw new BinaryObjectException("Duplicate field ID: " + name);
-
-                            BinaryFieldAccessor fieldInfo = BinaryFieldAccessor.create(f, fieldId);
-
-                            fields0.add(fieldInfo);
-
-                            schemaBuilder.addField(fieldId);
-
-                            if (metaDataEnabled)
-                                stableFieldsMeta.put(name, fieldInfo.mode().typeId());
-                        }
-                    }
-                }
-
-                fields = fields0.toArray(new BinaryFieldAccessor[fields0.size()]);
-
-                stableSchema = schemaBuilder.build();
-
-                break;
-
-            default:
-                // Should never happen.
-                throw new BinaryObjectException("Invalid mode: " + mode);
-        }
-
-        if (mode == BinaryWriteMode.PORTABLE || mode == BinaryWriteMode.EXTERNALIZABLE ||
-            mode == BinaryWriteMode.OBJECT) {
-            readResolveMtd = U.findNonPublicMethod(cls, "readResolve");
-            writeReplaceMtd = U.findNonPublicMethod(cls, "writeReplace");
-        }
-        else {
-            readResolveMtd = null;
-            writeReplaceMtd = null;
-        }
-    }
-
-    /**
-     * @return {@code True} if enum.
-     */
-    boolean isEnum() {
-        return mode == BinaryWriteMode.ENUM;
-    }
-
-    /**
-     * @return Described class.
-     */
-    Class<?> describedClass() {
-        return cls;
-    }
-
-    /**
-     * @return Type ID.
-     */
-    public int typeId() {
-        return typeId;
-    }
-
-    /**
-     * @return User type flag.
-     */
-    public boolean userType() {
-        return userType;
-    }
-
-    /**
-     * @return Fields meta data.
-     */
-    Map<String, Integer> fieldsMeta() {
-        return stableFieldsMeta;
-    }
-
-    /**
-     * @return Schema.
-     */
-    PortableSchema schema() {
-        return stableSchema;
-    }
-
-    /**
-     * @return Whether typeId has been successfully registered by MarshallerContext or not.
-     */
-    public boolean registered() {
-        return registered;
-    }
-
-    /**
-     * @return {@code true} if {@link OptimizedMarshaller} must be used instead of {@link BinaryMarshaller}
-     * for object serialization and deserialization.
-     */
-    public boolean useOptimizedMarshaller() {
-        return useOptMarshaller;
-    }
-
-    /**
-     * Checks whether the class values are explicitly excluded from marshalling.
-     *
-     * @return {@code true} if excluded, {@code false} otherwise.
-     */
-    public boolean excluded() {
-        return excluded;
-    }
-
-    /**
-     * @return portableWriteReplace() method
-     */
-    @Nullable Method getWriteReplaceMethod() {
-        return writeReplaceMtd;
-    }
-
-    /**
-     * @return portableReadResolve() method
-     */
-    @SuppressWarnings("UnusedDeclaration")
-    @Nullable Method getReadResolveMethod() {
-        return readResolveMtd;
-    }
-
-    /**
-     * @param obj Object.
-     * @param writer Writer.
-     * @throws BinaryObjectException In case of error.
-     */
-    void write(Object obj, BinaryWriterExImpl writer) throws BinaryObjectException {
-        assert obj != null;
-        assert writer != null;
-
-        writer.typeId(typeId);
-
-        switch (mode) {
-            case P_BYTE:
-            case BYTE:
-                writer.writeByteFieldPrimitive((byte) obj);
-
-                break;
-
-            case P_SHORT:
-            case SHORT:
-                writer.writeShortFieldPrimitive((short)obj);
-
-                break;
-
-            case P_INT:
-            case INT:
-                writer.writeIntFieldPrimitive((int) obj);
-
-                break;
-
-            case P_LONG:
-            case LONG:
-                writer.writeLongFieldPrimitive((long) obj);
-
-                break;
-
-            case P_FLOAT:
-            case FLOAT:
-                writer.writeFloatFieldPrimitive((float) obj);
-
-                break;
-
-            case P_DOUBLE:
-            case DOUBLE:
-                writer.writeDoubleFieldPrimitive((double) obj);
-
-                break;
-
-            case P_CHAR:
-            case CHAR:
-                writer.writeCharFieldPrimitive((char) obj);
-
-                break;
-
-            case P_BOOLEAN:
-            case BOOLEAN:
-                writer.writeBooleanFieldPrimitive((boolean) obj);
-
-                break;
-
-            case DECIMAL:
-                writer.doWriteDecimal((BigDecimal)obj);
-
-                break;
-
-            case STRING:
-                writer.doWriteString((String)obj);
-
-                break;
-
-            case UUID:
-                writer.doWriteUuid((UUID)obj);
-
-                break;
-
-            case DATE:
-                writer.doWriteDate((Date)obj);
-
-                break;
-
-            case TIMESTAMP:
-                writer.doWriteTimestamp((Timestamp)obj);
-
-                break;
-
-            case BYTE_ARR:
-                writer.doWriteByteArray((byte[])obj);
-
-                break;
-
-            case SHORT_ARR:
-                writer.doWriteShortArray((short[]) obj);
-
-                break;
-
-            case INT_ARR:
-                writer.doWriteIntArray((int[]) obj);
-
-                break;
-
-            case LONG_ARR:
-                writer.doWriteLongArray((long[]) obj);
-
-                break;
-
-            case FLOAT_ARR:
-                writer.doWriteFloatArray((float[]) obj);
-
-                break;
-
-            case DOUBLE_ARR:
-                writer.doWriteDoubleArray((double[]) obj);
-
-                break;
-
-            case CHAR_ARR:
-                writer.doWriteCharArray((char[]) obj);
-
-                break;
-
-            case BOOLEAN_ARR:
-                writer.doWriteBooleanArray((boolean[]) obj);
-
-                break;
-
-            case DECIMAL_ARR:
-                writer.doWriteDecimalArray((BigDecimal[]) obj);
-
-                break;
-
-            case STRING_ARR:
-                writer.doWriteStringArray((String[]) obj);
-
-                break;
-
-            case UUID_ARR:
-                writer.doWriteUuidArray((UUID[]) obj);
-
-                break;
-
-            case DATE_ARR:
-                writer.doWriteDateArray((Date[]) obj);
-
-                break;
-
-            case TIMESTAMP_ARR:
-                writer.doWriteTimestampArray((Timestamp[]) obj);
-
-                break;
-
-            case OBJECT_ARR:
-                writer.doWriteObjectArray((Object[])obj);
-
-                break;
-
-            case COL:
-                writer.doWriteCollection((Collection<?>)obj);
-
-                break;
-
-            case MAP:
-                writer.doWriteMap((Map<?, ?>)obj);
-
-                break;
-
-            case ENUM:
-                writer.doWriteEnum((Enum<?>)obj);
-
-                break;
-
-            case PORTABLE_ENUM:
-                writer.doWritePortableEnum((BinaryEnumObjectImpl)obj);
-
-                break;
-
-            case ENUM_ARR:
-                writer.doWriteEnumArray((Object[])obj);
-
-                break;
-
-            case CLASS:
-                writer.doWriteClass((Class)obj);
-
-                break;
-
-            case PORTABLE_OBJ:
-                writer.doWritePortableObject((BinaryObjectImpl)obj);
-
-                break;
-
-            case PORTABLE:
-                if (preWrite(writer, obj)) {
-                    try {
-                        if (serializer != null)
-                            serializer.writeBinary(obj, writer);
-                        else
-                            ((Binarylizable)obj).writeBinary(writer);
-
-                        postWrite(writer, obj);
-
-                        // Check whether we need to update metadata.
-                        if (obj.getClass() != BinaryMetadata.class) {
-                            int schemaId = writer.schemaId();
-
-                            if (schemaReg.schema(schemaId) == null) {
-                                // This is new schema, let's update metadata.
-                                BinaryMetadataCollector collector =
-                                    new BinaryMetadataCollector(typeId, typeName, idMapper);
-
-                                if (serializer != null)
-                                    serializer.writeBinary(obj, collector);
-                                else
-                                    ((Binarylizable)obj).writeBinary(collector);
-
-                                PortableSchema newSchema = collector.schema();
-
-                                BinaryMetadata meta = new BinaryMetadata(typeId, typeName, collector.meta(),
-                                    affKeyFieldName, Collections.singleton(newSchema), false);
-
-                                ctx.updateMetadata(typeId, meta);
-
-                                schemaReg.addSchema(newSchema.schemaId(), newSchema);
-                            }
-                        }
-                    }
-                    finally {
-                        writer.popSchema();
-                    }
-                }
-
-                break;
-
-            case EXTERNALIZABLE:
-                if (preWrite(writer, obj)) {
-                    writer.rawWriter();
-
-                    try {
-                        ((Externalizable)obj).writeExternal(writer);
-
-                        postWrite(writer, obj);
-                    }
-                    catch (IOException e) {
-                        throw new BinaryObjectException("Failed to write Externalizable object: " + obj, e);
-                    }
-                    finally {
-                        writer.popSchema();
-                    }
-                }
-
-                break;
-
-            case OBJECT:
-                if (preWrite(writer, obj)) {
-                    try {
-                        for (BinaryFieldAccessor info : fields)
-                            info.write(obj, writer);
-
-                        writer.schemaId(stableSchema.schemaId());
-
-                        postWrite(writer, obj);
-                    }
-                    finally {
-                        writer.popSchema();
-                    }
-                }
-
-                break;
-
-            default:
-                assert false : "Invalid mode: " + mode;
-        }
-    }
-
-    /**
-     * @param reader Reader.
-     * @return Object.
-     * @throws BinaryObjectException If failed.
-     */
-    Object read(BinaryReaderExImpl reader) throws BinaryObjectException {
-        assert reader != null;
-
-        Object res;
-
-        switch (mode) {
-            case PORTABLE:
-                res = newInstance();
-
-                reader.setHandle(res);
-
-                if (serializer != null)
-                    serializer.readBinary(res, reader);
-                else
-                    ((Binarylizable)res).readBinary(reader);
-
-                break;
-
-            case EXTERNALIZABLE:
-                res = newInstance();
-
-                reader.setHandle(res);
-
-                try {
-                    ((Externalizable)res).readExternal(reader);
-                }
-                catch (IOException | ClassNotFoundException e) {
-                    throw new BinaryObjectException("Failed to read Externalizable object: " +
-                        res.getClass().getName(), e);
-                }
-
-                break;
-
-            case OBJECT:
-                res = newInstance();
-
-                reader.setHandle(res);
-
-                for (BinaryFieldAccessor info : fields)
-                    info.read(res, reader);
-
-                break;
-
-            default:
-                assert false : "Invalid mode: " + mode;
-
-                return null;
-        }
-
-        if (readResolveMtd != null) {
-            try {
-                res = readResolveMtd.invoke(res);
-
-                reader.setHandle(res);
-            }
-            catch (IllegalAccessException e) {
-                throw new RuntimeException(e);
-            }
-            catch (InvocationTargetException e) {
-                if (e.getTargetException() instanceof BinaryObjectException)
-                    throw (BinaryObjectException)e.getTargetException();
-
-                throw new BinaryObjectException("Failed to execute readResolve() method on " + res, e);
-            }
-        }
-
-        return res;
-    }
-
-    /**
-     * Pre-write phase.
-     *
-     * @param writer Writer.
-     * @param obj Object.
-     * @return Whether further write is needed.
-     */
-    private boolean preWrite(BinaryWriterExImpl writer, Object obj) {
-        if (writer.tryWriteAsHandle(obj))
-            return false;
-
-        writer.preWrite(registered ? null : cls.getName());
-
-        return true;
-    }
-
-    /**
-     * Post-write phase.
-     *
-     * @param writer Writer.
-     * @param obj Object.
-     */
-    private void postWrite(BinaryWriterExImpl writer, Object obj) {
-        writer.postWrite(userType, registered, obj instanceof CacheObjectImpl ? 0 : obj.hashCode());
-    }
-
-    /**
-     * @return Instance.
-     * @throws BinaryObjectException In case of error.
-     */
-    private Object newInstance() throws BinaryObjectException {
-        try {
-            return ctor != null ? ctor.newInstance() : UNSAFE.allocateInstance(cls);
-        }
-        catch (InstantiationException | InvocationTargetException | IllegalAccessException e) {
-            throw new BinaryObjectException("Failed to instantiate instance: " + cls, e);
-        }
-    }
-
-    /**
-     * @param cls Class.
-     * @return Constructor.
-     * @throws BinaryObjectException If constructor doesn't exist.
-     */
-    @SuppressWarnings("ConstantConditions")
-    @Nullable private static Constructor<?> constructor(Class<?> cls) throws BinaryObjectException {
-        assert cls != null;
-
-        try {
-            Constructor<?> ctor = U.forceEmptyConstructor(cls);
-
-            if (ctor == null)
-                throw new BinaryObjectException("Failed to find empty constructor for class: " + cls.getName());
-
-            ctor.setAccessible(true);
-
-            return ctor;
-        }
-        catch (IgniteCheckedException e) {
-            throw new BinaryObjectException("Failed to get constructor for class: " + cls.getName(), e);
-        }
-    }
-
-    /**
-     * Determines whether to use {@link OptimizedMarshaller} for serialization or
-     * not.
-     *
-     * @return {@code true} if to use, {@code false} otherwise.
-     */
-    @SuppressWarnings("unchecked")
-    private boolean initUseOptimizedMarshallerFlag() {
-        for (Class c = cls; c != null && !c.equals(Object.class); c = c.getSuperclass()) {
-            try {
-                Method writeObj = c.getDeclaredMethod("writeObject", ObjectOutputStream.class);
-                Method readObj = c.getDeclaredMethod("readObject", ObjectInputStream.class);
-
-                if (!Modifier.isStatic(writeObj.getModifiers()) && !Modifier.isStatic(readObj.getModifiers()) &&
-                    writeObj.getReturnType() == void.class && readObj.getReturnType() == void.class)
-                    return true;
-            }
-            catch (NoSuchMethodException ignored) {
-                // No-op.
-            }
-        }
-
-        return false;
-    }
-}


[33/59] [abbrv] ignite git commit: Merge branch 'ignite-2064-4' into ignite-1.5

Posted by ak...@apache.org.
Merge branch 'ignite-2064-4' into ignite-1.5

2

(cherry picked from commit 599d2edc6c4f3ce60654a53bb431d36db982bc87)


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

Branch: refs/heads/ignite-843-rc2
Commit: 0ac39c976116b655304699d2477f207802cb5f8e
Parents: 1dbf20e 599d2ed
Author: Anton Vinogradov <av...@apache.org>
Authored: Fri Dec 11 12:54:50 2015 +0300
Committer: Anton Vinogradov <av...@apache.org>
Committed: Fri Dec 11 12:54:50 2015 +0300

----------------------------------------------------------------------
 .../org/apache/ignite/internal/binary/BinaryObjectImpl.java   | 1 -
 .../ignite/internal/binary/BinaryObjectOffheapImpl.java       | 6 ++++--
 .../internal/binary/builder/BinaryObjectBuilderImpl.java      | 3 +--
 .../ignite/internal/binary/builder/PortableBuilderEnum.java   | 3 +--
 .../ignite/internal/binary/builder/PortableBuilderReader.java | 5 +++--
 .../internal/binary/builder/PortableEnumArrayLazyValue.java   | 3 +--
 .../internal/binary/builder/PortableObjectArrayLazyValue.java | 3 +--
 .../internal/processors/platform/PlatformContextImpl.java     | 7 +++++--
 .../context/IgniteCacheAbstractExecutionContextTest.java      | 3 ---
 9 files changed, 16 insertions(+), 18 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/0ac39c97/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryObjectImpl.java
----------------------------------------------------------------------
diff --cc modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryObjectImpl.java
index a23330e,0000000..18adbc1
mode 100644,000000..100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryObjectImpl.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryObjectImpl.java
@@@ -1,570 -1,0 +1,569 @@@
 +/*
 + * 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.binary;
 +
 +import java.io.Externalizable;
 +import java.io.IOException;
 +import java.io.ObjectInput;
 +import java.io.ObjectOutput;
 +import java.math.BigDecimal;
 +import java.math.BigInteger;
 +import java.nio.ByteBuffer;
 +import java.sql.Timestamp;
 +import java.util.Date;
 +import java.util.UUID;
 +import org.apache.ignite.IgniteCheckedException;
 +import org.apache.ignite.binary.BinaryObject;
 +import org.apache.ignite.binary.BinaryObjectException;
 +import org.apache.ignite.binary.BinaryType;
 +import org.apache.ignite.internal.GridDirectTransient;
 +import org.apache.ignite.internal.IgniteCodeGeneratingFail;
 +import org.apache.ignite.internal.binary.streams.PortableHeapInputStream;
 +import org.apache.ignite.internal.processors.cache.CacheObject;
 +import org.apache.ignite.internal.processors.cache.CacheObjectContext;
 +import org.apache.ignite.internal.processors.cache.KeyCacheObject;
 +import org.apache.ignite.internal.processors.cache.binary.CacheObjectBinaryProcessorImpl;
 +import org.apache.ignite.internal.util.typedef.internal.U;
 +import org.apache.ignite.plugin.extensions.communication.MessageReader;
 +import org.apache.ignite.plugin.extensions.communication.MessageWriter;
 +import org.jetbrains.annotations.Nullable;
 +
 +import static java.nio.charset.StandardCharsets.UTF_8;
 +
 +/**
 + * Portable object implementation.
 + */
 +@IgniteCodeGeneratingFail // Fields arr and start should not be generated by MessageCodeGenerator.
 +public final class BinaryObjectImpl extends BinaryObjectExImpl implements Externalizable, KeyCacheObject {
 +    /** */
 +    private static final long serialVersionUID = 0L;
 +
 +    /** */
 +    @GridDirectTransient
 +    private PortableContext ctx;
 +
 +    /** */
 +    private byte[] arr;
 +
 +    /** */
 +    private int start;
 +
 +    /** */
 +    @GridDirectTransient
 +    private Object obj;
 +
 +    /** */
 +    @GridDirectTransient
 +    private boolean detachAllowed;
 +
 +    /**
 +     * For {@link Externalizable}.
 +     */
 +    public BinaryObjectImpl() {
 +        // No-op.
 +    }
 +
 +    /**
 +     * @param ctx Context.
 +     * @param arr Array.
 +     * @param start Start.
 +     */
 +    public BinaryObjectImpl(PortableContext ctx, byte[] arr, int start) {
 +        assert ctx != null;
 +        assert arr != null;
 +
 +        this.ctx = ctx;
 +        this.arr = arr;
 +        this.start = start;
 +    }
 +
 +    /** {@inheritDoc} */
 +    @Override public byte cacheObjectType() {
 +        return TYPE_BINARY;
 +    }
 +
 +    /** {@inheritDoc} */
 +    @Override public boolean isPlatformType() {
 +        return false;
 +    }
 +
 +    /** {@inheritDoc} */
 +    @Override public boolean internal() {
 +        return false;
 +    }
 +
 +    /** {@inheritDoc} */
 +    @SuppressWarnings("unchecked")
 +    @Nullable @Override public <T> T value(CacheObjectContext ctx, boolean cpy) {
 +        Object obj0 = obj;
 +
 +        if (obj0 == null || (cpy && needCopy(ctx)))
 +            obj0 = deserializeValue(ctx);
 +
 +        return (T)obj0;
 +    }
 +
 +    /** {@inheritDoc} */
 +    @Override public byte[] valueBytes(CacheObjectContext ctx) throws IgniteCheckedException {
 +        if (detached())
 +            return array();
 +
 +        int len = length();
 +
 +        byte[] arr0 = new byte[len];
 +
 +        U.arrayCopy(arr, start, arr0, 0, len);
 +
 +        return arr0;
 +    }
 +
 +    /** {@inheritDoc} */
 +    @Override public CacheObject prepareForCache(CacheObjectContext ctx) {
 +        if (detached())
 +            return this;
 +
 +        return (BinaryObjectImpl)detach();
 +    }
 +
 +    /** {@inheritDoc} */
 +    @Override public void finishUnmarshal(CacheObjectContext ctx, ClassLoader ldr) throws IgniteCheckedException {
 +        this.ctx = ((CacheObjectBinaryProcessorImpl)ctx.processor()).portableContext();
 +    }
 +
 +    /** {@inheritDoc} */
 +    @Override public void prepareMarshal(CacheObjectContext ctx) throws IgniteCheckedException {
 +        // No-op.
 +    }
 +
 +    /** {@inheritDoc} */
 +    @Override public int length() {
 +        return PortablePrimitives.readInt(arr, start + GridPortableMarshaller.TOTAL_LEN_POS);
 +    }
 +
 +    /**
 +     * @return Detached portable object.
 +     */
 +    public BinaryObject detach() {
 +        if (!detachAllowed || detached())
 +            return this;
 +
 +        int len = length();
 +
 +        byte[] arr0 = new byte[len];
 +
 +        U.arrayCopy(arr, start, arr0, 0, len);
 +
 +        return new BinaryObjectImpl(ctx, arr0, 0);
 +    }
 +
 +    /**
 +     * @return Detached or not.
 +     */
 +    public boolean detached() {
 +        return start == 0 && length() == arr.length;
 +    }
 +
 +    /**
 +     * @param detachAllowed Detach allowed flag.
 +     */
 +    public void detachAllowed(boolean detachAllowed) {
 +        this.detachAllowed = detachAllowed;
 +    }
 +
 +    /**
 +     * @return Context.
 +     */
 +    public PortableContext context() {
 +        return ctx;
 +    }
 +
 +    /**
 +     * @param ctx Context.
 +     */
 +    public void context(PortableContext ctx) {
 +        this.ctx = ctx;
 +    }
 +
 +    /** {@inheritDoc} */
 +    @Override public byte[] array() {
 +        return arr;
 +    }
 +
 +    /** {@inheritDoc} */
 +    @Override public int start() {
 +        return start;
 +    }
 +
 +    /** {@inheritDoc} */
 +    @Override public long offheapAddress() {
 +        return 0;
 +    }
 +
 +    /** {@inheritDoc} */
 +    @Override protected boolean hasArray() {
 +        return true;
 +    }
 +
 +    /** {@inheritDoc} */
 +    @Override public int typeId() {
 +        return PortablePrimitives.readInt(arr, start + GridPortableMarshaller.TYPE_ID_POS);
 +    }
 +
 +    /** {@inheritDoc} */
 +    @Nullable @Override public BinaryType type() throws BinaryObjectException {
 +        if (ctx == null)
 +            throw new BinaryObjectException("PortableContext is not set for the object.");
 +
 +        return ctx.metadata(typeId());
 +    }
 +
 +    /** {@inheritDoc} */
 +    @SuppressWarnings("unchecked")
 +    @Nullable @Override public <F> F field(String fieldName) throws BinaryObjectException {
 +        return (F) reader(null).unmarshalField(fieldName);
 +    }
 +
 +    /** {@inheritDoc} */
 +    @SuppressWarnings("unchecked")
 +    @Nullable @Override public <F> F field(int fieldId) throws BinaryObjectException {
 +        return (F) reader(null).unmarshalField(fieldId);
 +    }
 +
 +    /** {@inheritDoc} */
 +    @SuppressWarnings("unchecked")
 +    @Nullable @Override protected <F> F fieldByOrder(int order) {
 +        Object val;
 +
 +        // Calculate field position.
 +        int schemaOffset = PortablePrimitives.readInt(arr, start + GridPortableMarshaller.SCHEMA_OR_RAW_OFF_POS);
 +
 +        short flags = PortablePrimitives.readShort(arr, start + GridPortableMarshaller.FLAGS_POS);
 +
 +        int fieldIdLen = PortableUtils.isCompactFooter(flags) ? 0 : PortableUtils.FIELD_ID_LEN;
 +        int fieldOffsetLen = PortableUtils.fieldOffsetLength(flags);
 +
 +        int fieldOffsetPos = start + schemaOffset + order * (fieldIdLen + fieldOffsetLen) + fieldIdLen;
 +
 +        int fieldPos;
 +
 +        if (fieldOffsetLen == PortableUtils.OFFSET_1)
 +            fieldPos = start + ((int)PortablePrimitives.readByte(arr, fieldOffsetPos) & 0xFF);
 +        else if (fieldOffsetLen == PortableUtils.OFFSET_2)
 +            fieldPos = start + ((int)PortablePrimitives.readShort(arr, fieldOffsetPos) & 0xFFFF);
 +        else
 +            fieldPos = start + PortablePrimitives.readInt(arr, fieldOffsetPos);
 +
 +        // Read header and try performing fast lookup for well-known types (the most common types go first).
 +        byte hdr = PortablePrimitives.readByte(arr, fieldPos);
 +
 +        switch (hdr) {
 +            case GridPortableMarshaller.INT:
 +                val = PortablePrimitives.readInt(arr, fieldPos + 1);
 +
 +                break;
 +
 +            case GridPortableMarshaller.LONG:
 +                val = PortablePrimitives.readLong(arr, fieldPos + 1);
 +
 +                break;
 +
 +            case GridPortableMarshaller.BOOLEAN:
 +                val = PortablePrimitives.readBoolean(arr, fieldPos + 1);
 +
 +                break;
 +
 +            case GridPortableMarshaller.SHORT:
 +                val = PortablePrimitives.readShort(arr, fieldPos + 1);
 +
 +                break;
 +
 +            case GridPortableMarshaller.BYTE:
 +                val = PortablePrimitives.readByte(arr, fieldPos + 1);
 +
 +                break;
 +
 +            case GridPortableMarshaller.CHAR:
 +                val = PortablePrimitives.readChar(arr, fieldPos + 1);
 +
 +                break;
 +
 +            case GridPortableMarshaller.FLOAT:
 +                val = PortablePrimitives.readFloat(arr, fieldPos + 1);
 +
 +                break;
 +
 +            case GridPortableMarshaller.DOUBLE:
 +                val = PortablePrimitives.readDouble(arr, fieldPos + 1);
 +
 +                break;
 +
 +            case GridPortableMarshaller.STRING: {
 +                int dataLen = PortablePrimitives.readInt(arr, fieldPos + 1);
 +
 +                val = new String(arr, fieldPos + 5, dataLen, UTF_8);
 +
 +                break;
 +            }
 +
 +            case GridPortableMarshaller.DATE: {
 +                long time = PortablePrimitives.readLong(arr, fieldPos + 1);
 +
 +                val = new Date(time);
 +
 +                break;
 +            }
 +
 +            case GridPortableMarshaller.TIMESTAMP: {
 +                long time = PortablePrimitives.readLong(arr, fieldPos + 1);
 +                int nanos = PortablePrimitives.readInt(arr, fieldPos + 1 + 8);
 +
 +                Timestamp ts = new Timestamp(time);
 +
 +                ts.setNanos(ts.getNanos() + nanos);
 +
 +                val = ts;
 +
 +                break;
 +            }
 +
 +            case GridPortableMarshaller.UUID: {
 +                long most = PortablePrimitives.readLong(arr, fieldPos + 1);
 +                long least = PortablePrimitives.readLong(arr, fieldPos + 1 + 8);
 +
 +                val = new UUID(most, least);
 +
 +                break;
 +            }
 +
 +            case GridPortableMarshaller.DECIMAL: {
 +                int scale = PortablePrimitives.readInt(arr, fieldPos + 1);
 +
 +                int dataLen = PortablePrimitives.readInt(arr, fieldPos + 5);
 +                byte[] data = PortablePrimitives.readByteArray(arr, fieldPos + 9, dataLen);
 +
 +                BigInteger intVal = new BigInteger(data);
 +
 +                if (scale < 0) {
 +                    scale &= 0x7FFFFFFF;
 +
 +                    intVal = intVal.negate();
 +                }
 +
 +                val = new BigDecimal(intVal, scale);
 +
 +                break;
 +            }
 +
 +            case GridPortableMarshaller.NULL:
 +                val = null;
 +
 +                break;
 +
 +            default:
 +                val = PortableUtils.unmarshal(PortableHeapInputStream.create(arr, fieldPos), ctx, null);
 +
 +                break;
 +        }
 +
 +        return (F)val;
 +    }
 +
 +    /** {@inheritDoc} */
 +    @SuppressWarnings("unchecked")
 +    @Nullable @Override protected <F> F field(BinaryReaderHandles rCtx, String fieldName) {
 +        return (F)reader(rCtx).unmarshalField(fieldName);
 +    }
 +
 +    /** {@inheritDoc} */
 +    @Override public boolean hasField(String fieldName) {
 +        return reader(null).findFieldByName(fieldName);
 +    }
 +
 +    /** {@inheritDoc} */
 +    @SuppressWarnings("unchecked")
 +    @Nullable @Override public <T> T deserialize() throws BinaryObjectException {
 +        Object obj0 = obj;
 +
 +        if (obj0 == null)
 +            obj0 = deserializeValue(null);
 +
 +        return (T)obj0;
 +    }
 +
 +    /** {@inheritDoc} */
 +    @Override public BinaryObject clone() throws CloneNotSupportedException {
 +        return super.clone();
 +    }
 +
 +    /** {@inheritDoc} */
 +    @Override public int hashCode() {
 +        return PortablePrimitives.readInt(arr, start + GridPortableMarshaller.HASH_CODE_POS);
 +    }
 +
 +    /** {@inheritDoc} */
 +    @Override protected int schemaId() {
 +        return PortablePrimitives.readInt(arr, start + GridPortableMarshaller.SCHEMA_ID_POS);
 +    }
 +
 +    /** {@inheritDoc} */
 +    @Override protected PortableSchema createSchema() {
 +        return reader(null).getOrCreateSchema();
 +    }
 +
 +    /** {@inheritDoc} */
 +    @Override public void writeExternal(ObjectOutput out) throws IOException {
 +        out.writeObject(ctx);
 +
 +        if (detachAllowed) {
 +            int len = length();
 +
 +            out.writeInt(len);
 +            out.write(arr, start, len);
 +            out.writeInt(0);
 +        }
 +        else {
 +            out.writeInt(arr.length);
 +            out.write(arr);
 +            out.writeInt(start);
 +        }
 +    }
 +
 +    /** {@inheritDoc} */
 +    @Override public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
 +        ctx = (PortableContext)in.readObject();
 +
 +        arr = new byte[in.readInt()];
 +
 +        in.readFully(arr);
 +
 +        start = in.readInt();
 +    }
 +
 +    /** {@inheritDoc} */
 +    @Override public boolean writeTo(ByteBuffer buf, MessageWriter writer) {
 +        writer.setBuffer(buf);
 +
 +        if (!writer.isHeaderWritten()) {
 +            if (!writer.writeHeader(directType(), fieldsCount()))
 +                return false;
 +
 +            writer.onHeaderWritten();
 +        }
 +
 +        switch (writer.state()) {
 +            case 0:
 +                if (!writer.writeByteArray("arr",
 +                    arr,
 +                    detachAllowed ? start : 0,
 +                    detachAllowed ? length() : arr.length))
 +                    return false;
 +
 +                writer.incrementState();
 +
 +            case 1:
 +                if (!writer.writeInt("start", detachAllowed ? 0 : start))
 +                    return false;
 +
 +                writer.incrementState();
 +
 +        }
 +
 +        return true;
 +    }
 +
 +    /** {@inheritDoc} */
 +    @Override public boolean readFrom(ByteBuffer buf, MessageReader reader) {
 +        reader.setBuffer(buf);
 +
 +        if (!reader.beforeMessageRead())
 +            return false;
 +
 +        switch (reader.state()) {
 +            case 0:
 +                arr = reader.readByteArray("arr");
 +
 +                if (!reader.isLastRead())
 +                    return false;
 +
 +                reader.incrementState();
 +
 +            case 1:
 +                start = reader.readInt("start");
 +
 +                if (!reader.isLastRead())
 +                    return false;
 +
 +                reader.incrementState();
 +
 +        }
 +
 +        return true;
 +    }
 +
 +    /** {@inheritDoc} */
 +    @Override public byte directType() {
 +        return 113;
 +    }
 +
 +    /** {@inheritDoc} */
 +    @Override public byte fieldsCount() {
 +        return 3;
 +    }
 +
 +    /**
 +     * Runs value deserialization regardless of whether obj already has the deserialized value.
 +     * Will set obj if descriptor is configured to keep deserialized values.
 +     * @param coCtx CacheObjectContext.
 +     * @return Object.
 +     */
 +    private Object deserializeValue(@Nullable CacheObjectContext coCtx) {
-         // TODO: IGNITE-1272 - Deserialize with proper class loader.
 +        BinaryReaderExImpl reader = reader(null);
 +
 +        Object obj0 = reader.deserialize();
 +
 +        PortableClassDescriptor desc = reader.descriptor();
 +
 +        assert desc != null;
 +
 +        if (coCtx != null && coCtx.storeValue())
 +            obj = obj0;
 +
 +        return obj0;
 +    }
 +
 +    /**
 +     * @param ctx Context.
 +     * @return {@code True} need to copy value returned to user.
 +     */
 +    private boolean needCopy(CacheObjectContext ctx) {
 +        return ctx.copyOnGet() && obj != null && !ctx.processor().immutable(obj);
 +    }
 +
 +    /**
 +     * Create new reader for this object.
 +     *
 +     * @param rCtx Reader context.
 +     * @return Reader.
 +     */
 +    private BinaryReaderExImpl reader(@Nullable BinaryReaderHandles rCtx) {
 +        return new BinaryReaderExImpl(ctx,
 +            PortableHeapInputStream.create(arr, start),
 +            ctx.configuration().getClassLoader(),
 +            rCtx);
 +    }
 +}

http://git-wip-us.apache.org/repos/asf/ignite/blob/0ac39c97/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryObjectOffheapImpl.java
----------------------------------------------------------------------
diff --cc modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryObjectOffheapImpl.java
index 27b46c1,0000000..2944099
mode 100644,000000..100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryObjectOffheapImpl.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryObjectOffheapImpl.java
@@@ -1,430 -1,0 +1,432 @@@
 +/*
 + * 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.binary;
 +
 +import org.apache.ignite.IgniteCheckedException;
 +import org.apache.ignite.binary.BinaryObject;
 +import org.apache.ignite.binary.BinaryObjectException;
 +import org.apache.ignite.binary.BinaryType;
 +import org.apache.ignite.internal.binary.streams.PortableOffheapInputStream;
 +import org.apache.ignite.internal.binary.streams.PortableOffheapInputStream;
 +import org.apache.ignite.internal.processors.cache.CacheObject;
 +import org.apache.ignite.internal.processors.cache.CacheObjectContext;
 +import org.apache.ignite.internal.util.GridUnsafe;
 +import org.apache.ignite.internal.util.typedef.internal.U;
 +import org.apache.ignite.plugin.extensions.communication.MessageReader;
 +import org.apache.ignite.plugin.extensions.communication.MessageWriter;
 +import org.jetbrains.annotations.Nullable;
 +import sun.misc.Unsafe;
 +
 +import java.io.Externalizable;
 +import java.io.IOException;
 +import java.io.ObjectInput;
 +import java.io.ObjectOutput;
 +import java.math.BigDecimal;
 +import java.math.BigInteger;
 +import java.nio.ByteBuffer;
 +import java.sql.Timestamp;
 +import java.util.Date;
 +import java.util.UUID;
 +
 +import static java.nio.charset.StandardCharsets.UTF_8;
 +import static org.apache.ignite.internal.binary.GridPortableMarshaller.BOOLEAN;
 +import static org.apache.ignite.internal.binary.GridPortableMarshaller.BYTE;
 +import static org.apache.ignite.internal.binary.GridPortableMarshaller.CHAR;
 +import static org.apache.ignite.internal.binary.GridPortableMarshaller.DATE;
 +import static org.apache.ignite.internal.binary.GridPortableMarshaller.DECIMAL;
 +import static org.apache.ignite.internal.binary.GridPortableMarshaller.DOUBLE;
 +import static org.apache.ignite.internal.binary.GridPortableMarshaller.FLOAT;
 +import static org.apache.ignite.internal.binary.GridPortableMarshaller.INT;
 +import static org.apache.ignite.internal.binary.GridPortableMarshaller.LONG;
 +import static org.apache.ignite.internal.binary.GridPortableMarshaller.NULL;
 +import static org.apache.ignite.internal.binary.GridPortableMarshaller.SHORT;
 +import static org.apache.ignite.internal.binary.GridPortableMarshaller.STRING;
 +import static org.apache.ignite.internal.binary.GridPortableMarshaller.TIMESTAMP;
 +import static org.apache.ignite.internal.binary.GridPortableMarshaller.UUID;
 +
 +/**
 + *  Portable object implementation over offheap memory
 + */
 +public class BinaryObjectOffheapImpl extends BinaryObjectExImpl implements Externalizable, CacheObject {
 +    /** */
 +    private static final long serialVersionUID = 0L;
 +
 +    /** */
 +    private static final Unsafe UNSAFE = GridUnsafe.unsafe();
 +
 +    /** */
 +    private final PortableContext ctx;
 +
 +    /** */
 +    private final long ptr;
 +
 +    /** */
 +    private final int start;
 +
 +    /** */
 +    private final int size;
 +
 +    /**
 +     * For {@link Externalizable} (not supported).
 +     */
 +    public BinaryObjectOffheapImpl() {
 +        throw new UnsupportedOperationException();
 +    }
 +
 +    /**
 +     * @param ctx Context.
 +     * @param ptr Memory address.
 +     * @param start Object start.
 +     * @param size Memory size.
 +     */
 +    public BinaryObjectOffheapImpl(PortableContext ctx, long ptr, int start, int size) {
 +        this.ctx = ctx;
 +        this.ptr = ptr;
 +        this.start = start;
 +        this.size = size;
 +    }
 +
 +    /**
 +     * @return Heap-based copy.
 +     */
 +    public BinaryObject heapCopy() {
 +        return new BinaryObjectImpl(ctx, U.copyMemory(ptr, size), start);
 +    }
 +
 +    /** {@inheritDoc} */
 +    @Override public int typeId() {
 +        return UNSAFE.getInt(ptr + start + GridPortableMarshaller.TYPE_ID_POS);
 +    }
 +
 +    /** {@inheritDoc} */
 +    @Override public int length() {
 +        return UNSAFE.getInt(ptr + start + GridPortableMarshaller.TOTAL_LEN_POS);
 +    }
 +
 +    /** {@inheritDoc} */
 +    @Override public int hashCode() {
 +        return UNSAFE.getInt(ptr + start + GridPortableMarshaller.HASH_CODE_POS);
 +    }
 +
 +    /** {@inheritDoc} */
 +    @Override protected int schemaId() {
 +        return UNSAFE.getInt(ptr + start + GridPortableMarshaller.SCHEMA_ID_POS);
 +    }
 +
 +    /** {@inheritDoc} */
 +    @Override protected PortableSchema createSchema() {
 +        return reader(null).getOrCreateSchema();
 +    }
 +
 +    /** {@inheritDoc} */
 +    @Override public int start() {
 +        return start;
 +    }
 +
 +    /** {@inheritDoc} */
 +    @Override public byte[] array() {
 +        return null;
 +    }
 +
 +    /** {@inheritDoc} */
 +    @Override public long offheapAddress() {
 +        return ptr;
 +    }
 +
 +    /** {@inheritDoc} */
 +    @Override protected boolean hasArray() {
 +        return false;
 +    }
 +
 +    /** {@inheritDoc} */
 +    @Nullable @Override public BinaryType type() throws BinaryObjectException {
 +        if (ctx == null)
 +            throw new BinaryObjectException("PortableContext is not set for the object.");
 +
 +        return ctx.metadata(typeId());
 +    }
 +
 +    /** {@inheritDoc} */
 +    @SuppressWarnings("unchecked")
 +    @Nullable @Override public <F> F field(String fieldName) throws BinaryObjectException {
 +        return (F) reader(null).unmarshalField(fieldName);
 +    }
 +
 +    /** {@inheritDoc} */
 +    @SuppressWarnings("unchecked")
 +    @Nullable @Override public <F> F field(int fieldId) throws BinaryObjectException {
 +        return (F) reader(null).unmarshalField(fieldId);
 +    }
 +
 +    /** {@inheritDoc} */
 +    @SuppressWarnings("unchecked")
 +    @Nullable @Override protected <F> F fieldByOrder(int order) {
 +        Object val;
 +
 +        // Calculate field position.
 +        int schemaOffset = PortablePrimitives.readInt(ptr, start + GridPortableMarshaller.SCHEMA_OR_RAW_OFF_POS);
 +
 +        short flags = PortablePrimitives.readShort(ptr, start + GridPortableMarshaller.FLAGS_POS);
 +
 +        int fieldIdLen = PortableUtils.isCompactFooter(flags) ? 0 : PortableUtils.FIELD_ID_LEN;
 +        int fieldOffsetLen = PortableUtils.fieldOffsetLength(flags);
 +
 +        int fieldOffsetPos = start + schemaOffset + order * (fieldIdLen + fieldOffsetLen) + fieldIdLen;
 +
 +        int fieldPos;
 +
 +        if (fieldOffsetLen == PortableUtils.OFFSET_1)
 +            fieldPos = start + ((int)PortablePrimitives.readByte(ptr, fieldOffsetPos) & 0xFF);
 +        else if (fieldOffsetLen == PortableUtils.OFFSET_2)
 +            fieldPos = start + ((int)PortablePrimitives.readShort(ptr, fieldOffsetPos) & 0xFFFF);
 +        else
 +            fieldPos = start + PortablePrimitives.readInt(ptr, fieldOffsetPos);
 +
 +        // Read header and try performing fast lookup for well-known types (the most common types go first).
 +        byte hdr = PortablePrimitives.readByte(ptr, fieldPos);
 +
 +        switch (hdr) {
 +            case GridPortableMarshaller.INT:
 +                val = PortablePrimitives.readInt(ptr, fieldPos + 1);
 +
 +                break;
 +
 +            case GridPortableMarshaller.LONG:
 +                val = PortablePrimitives.readLong(ptr, fieldPos + 1);
 +
 +                break;
 +
 +            case GridPortableMarshaller.BOOLEAN:
 +                val = PortablePrimitives.readBoolean(ptr, fieldPos + 1);
 +
 +                break;
 +
 +            case GridPortableMarshaller.SHORT:
 +                val = PortablePrimitives.readShort(ptr, fieldPos + 1);
 +
 +                break;
 +
 +            case GridPortableMarshaller.BYTE:
 +                val = PortablePrimitives.readByte(ptr, fieldPos + 1);
 +
 +                break;
 +
 +            case GridPortableMarshaller.CHAR:
 +                val = PortablePrimitives.readChar(ptr, fieldPos + 1);
 +
 +                break;
 +
 +            case GridPortableMarshaller.FLOAT:
 +                val = PortablePrimitives.readFloat(ptr, fieldPos + 1);
 +
 +                break;
 +
 +            case GridPortableMarshaller.DOUBLE:
 +                val = PortablePrimitives.readDouble(ptr, fieldPos + 1);
 +
 +                break;
 +
 +            case GridPortableMarshaller.STRING: {
 +                int dataLen = PortablePrimitives.readInt(ptr, fieldPos + 1);
 +                byte[] data = PortablePrimitives.readByteArray(ptr, fieldPos + 5, dataLen);
 +
 +                val = new String(data, UTF_8);
 +
 +                break;
 +            }
 +
 +            case GridPortableMarshaller.DATE: {
 +                long time = PortablePrimitives.readLong(ptr, fieldPos + 1);
 +
 +                val = new Date(time);
 +
 +                break;
 +            }
 +
 +            case GridPortableMarshaller.TIMESTAMP: {
 +                long time = PortablePrimitives.readLong(ptr, fieldPos + 1);
 +                int nanos = PortablePrimitives.readInt(ptr, fieldPos + 1 + 8);
 +
 +                Timestamp ts = new Timestamp(time);
 +
 +                ts.setNanos(ts.getNanos() + nanos);
 +
 +                val = ts;
 +
 +                break;
 +            }
 +
 +            case GridPortableMarshaller.UUID: {
 +                long most = PortablePrimitives.readLong(ptr, fieldPos + 1);
 +                long least = PortablePrimitives.readLong(ptr, fieldPos + 1 + 8);
 +
 +                val = new UUID(most, least);
 +
 +                break;
 +            }
 +
 +            case GridPortableMarshaller.DECIMAL: {
 +                int scale = PortablePrimitives.readInt(ptr, fieldPos + 1);
 +
 +                int dataLen = PortablePrimitives.readInt(ptr, fieldPos + 5);
 +                byte[] data = PortablePrimitives.readByteArray(ptr, fieldPos + 9, dataLen);
 +
 +                BigInteger intVal = new BigInteger(data);
 +
 +                if (scale < 0) {
 +                    scale &= 0x7FFFFFFF;
 +
 +                    intVal = intVal.negate();
 +                }
 +
 +                val = new BigDecimal(intVal, scale);
 +
 +                break;
 +            }
 +
 +            case GridPortableMarshaller.NULL:
 +                val = null;
 +
 +                break;
 +
 +            default:
 +                PortableOffheapInputStream stream = new PortableOffheapInputStream(ptr, size, false);
 +
 +                stream.position(fieldPos);
 +
 +                val = PortableUtils.unmarshal(stream, ctx, null);
 +
 +                break;
 +        }
 +
 +        return (F)val;
 +    }
 +
 +    /** {@inheritDoc} */
 +    @SuppressWarnings("unchecked")
 +    @Nullable @Override protected <F> F field(BinaryReaderHandles rCtx, String fieldName) {
 +        return (F)reader(rCtx).unmarshalField(fieldName);
 +    }
 +
 +    /** {@inheritDoc} */
 +    @Override public boolean hasField(String fieldName) {
 +        return reader(null).findFieldByName(fieldName);
 +    }
 +
 +    /** {@inheritDoc} */
 +    @SuppressWarnings("unchecked")
 +    @Nullable @Override public <T> T deserialize() throws BinaryObjectException {
 +        return (T)deserializeValue();
 +    }
 +
 +    /** {@inheritDoc} */
 +    @SuppressWarnings("CloneDoesntCallSuperClone")
 +    @Override public BinaryObject clone() throws CloneNotSupportedException {
 +        return heapCopy();
 +    }
 +
 +    /** {@inheritDoc} */
 +    @Override public byte cacheObjectType() {
 +        throw new UnsupportedOperationException();
 +    }
 +
 +    /** {@inheritDoc} */
 +    @Override public boolean isPlatformType() {
 +        return false;
 +    }
 +
 +    /** {@inheritDoc} */
 +    @SuppressWarnings("unchecked")
 +    @Nullable @Override public <T> T value(CacheObjectContext ctx, boolean cpy) {
 +        return (T)deserializeValue();
 +    }
 +
 +    /** {@inheritDoc} */
 +    @Override public byte[] valueBytes(CacheObjectContext ctx) throws IgniteCheckedException {
 +        throw new UnsupportedOperationException();
 +    }
 +
 +    /** {@inheritDoc} */
 +    @Override public CacheObject prepareForCache(CacheObjectContext ctx) {
 +        throw new UnsupportedOperationException();
 +    }
 +
 +    /** {@inheritDoc} */
 +    @Override public void finishUnmarshal(CacheObjectContext ctx, ClassLoader ldr) throws IgniteCheckedException {
 +        throw new UnsupportedOperationException();
 +    }
 +
 +    /** {@inheritDoc} */
 +    @Override public void prepareMarshal(CacheObjectContext ctx) throws IgniteCheckedException {
 +        throw new UnsupportedOperationException();
 +    }
 +
 +    /** {@inheritDoc} */
 +    @Override public boolean writeTo(ByteBuffer buf, MessageWriter writer) {
 +        throw new UnsupportedOperationException();
 +    }
 +
 +    /** {@inheritDoc} */
 +    @Override public boolean readFrom(ByteBuffer buf, MessageReader reader) {
 +        throw new UnsupportedOperationException();
 +    }
 +
 +    /** {@inheritDoc} */
 +    @Override public byte directType() {
 +        throw new UnsupportedOperationException();
 +    }
 +
 +    /** {@inheritDoc} */
 +    @Override public byte fieldsCount() {
 +        throw new UnsupportedOperationException();
 +    }
 +
 +    /** {@inheritDoc} */
 +    @Override public void writeExternal(ObjectOutput out) throws IOException {
 +        throw new UnsupportedOperationException(); // To make sure it is not marshalled.
 +    }
 +
 +    /** {@inheritDoc} */
 +    @Override public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
 +        throw new UnsupportedOperationException(); // To make sure it is not marshalled.
 +    }
 +
 +    /**
 +     * @return Deserialized value.
 +     */
 +    private Object deserializeValue() {
-         // TODO: IGNITE-1272 - Deserialize with proper class loader.
 +        return reader(null).deserialize();
 +    }
 +
 +    /**
 +     * Create new reader for this object.
 +     *
 +     * @param rCtx Reader context.
 +     * @return Reader.
 +     */
 +    private BinaryReaderExImpl reader(@Nullable BinaryReaderHandles rCtx) {
 +        PortableOffheapInputStream stream = new PortableOffheapInputStream(ptr, size, false);
 +
 +        stream.position(start);
 +
-         return new BinaryReaderExImpl(ctx, stream, null, rCtx);
++        return new BinaryReaderExImpl(ctx,
++            stream,
++            ctx.configuration().getClassLoader(),
++            rCtx);
 +    }
 +}

http://git-wip-us.apache.org/repos/asf/ignite/blob/0ac39c97/modules/core/src/main/java/org/apache/ignite/internal/binary/builder/BinaryObjectBuilderImpl.java
----------------------------------------------------------------------
diff --cc modules/core/src/main/java/org/apache/ignite/internal/binary/builder/BinaryObjectBuilderImpl.java
index f5e4e06,0000000..f1d4185
mode 100644,000000..100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/binary/builder/BinaryObjectBuilderImpl.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/binary/builder/BinaryObjectBuilderImpl.java
@@@ -1,587 -1,0 +1,586 @@@
 +/*
 + * 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.binary.builder;
 +
 +import org.apache.ignite.binary.BinaryInvalidTypeException;
 +import org.apache.ignite.binary.BinaryObject;
 +import org.apache.ignite.binary.BinaryObjectBuilder;
 +import org.apache.ignite.binary.BinaryObjectException;
 +import org.apache.ignite.binary.BinaryType;
 +import org.apache.ignite.internal.binary.BinaryMetadata;
 +import org.apache.ignite.internal.binary.BinaryObjectImpl;
 +import org.apache.ignite.internal.binary.BinaryWriterExImpl;
 +import org.apache.ignite.internal.binary.GridPortableMarshaller;
 +import org.apache.ignite.internal.binary.PortableContext;
 +import org.apache.ignite.internal.binary.PortableSchema;
 +import org.apache.ignite.internal.binary.PortableSchemaRegistry;
 +import org.apache.ignite.internal.binary.BinaryMetadata;
 +import org.apache.ignite.internal.binary.BinaryObjectImpl;
 +import org.apache.ignite.internal.binary.BinaryObjectOffheapImpl;
 +import org.apache.ignite.internal.binary.BinaryWriterExImpl;
 +import org.apache.ignite.internal.binary.GridPortableMarshaller;
 +import org.apache.ignite.internal.binary.PortableContext;
 +import org.apache.ignite.internal.binary.PortableSchema;
 +import org.apache.ignite.internal.binary.PortableSchemaRegistry;
 +import org.apache.ignite.internal.binary.PortableUtils;
 +import org.apache.ignite.internal.util.typedef.F;
 +import org.apache.ignite.internal.util.typedef.internal.U;
 +import org.apache.ignite.lang.IgniteBiTuple;
 +import org.jetbrains.annotations.Nullable;
 +
 +import java.util.Collections;
 +import java.util.HashMap;
 +import java.util.LinkedHashMap;
 +import java.util.Map;
 +import java.util.Set;
 +
 +import static org.apache.ignite.internal.binary.GridPortableMarshaller.DFLT_HDR_LEN;
 +import static org.apache.ignite.internal.binary.GridPortableMarshaller.FLAGS_POS;
 +import static org.apache.ignite.internal.binary.GridPortableMarshaller.HASH_CODE_POS;
 +import static org.apache.ignite.internal.binary.GridPortableMarshaller.PROTO_VER_POS;
 +import static org.apache.ignite.internal.binary.GridPortableMarshaller.TYPE_ID_POS;
 +import static org.apache.ignite.internal.binary.GridPortableMarshaller.UNREGISTERED_TYPE_ID;
 +
 +/**
 + *
 + */
 +public class BinaryObjectBuilderImpl implements BinaryObjectBuilder {
 +    /** */
 +    private static final Object REMOVED_FIELD_MARKER = new Object();
 +
 +    /** */
 +    private final PortableContext ctx;
 +
 +    /** */
 +    private final int typeId;
 +
 +    /** May be null. */
 +    private String typeName;
 +
 +    /** May be null. */
 +    private String clsNameToWrite;
 +
 +    /** */
 +    private boolean registeredType = true;
 +
 +    /** */
 +    private Map<String, Object> assignedVals;
 +
 +    /** */
 +    private Map<Integer, Object> readCache;
 +
 +    /** Position of object in source array, or -1 if object is not created from PortableObject. */
 +    private final int start;
 +
 +    /** Flags. */
 +    private final short flags;
 +
 +    /** Total header length */
 +    private final int hdrLen;
 +
 +    /** Context of PortableObject reading process. Or {@code null} if object is not created from PortableObject. */
 +    private final PortableBuilderReader reader;
 +
 +    /** */
 +    private int hashCode;
 +
 +    /**
 +     * @param clsName Class name.
 +     * @param ctx Portable context.
 +     */
 +    public BinaryObjectBuilderImpl(PortableContext ctx, String clsName) {
 +        this(ctx, ctx.typeId(clsName), PortableContext.typeName(clsName));
 +    }
 +
 +    /**
 +     * @param typeName Type name.
 +     * @param ctx Context.
 +     * @param typeId Type id.
 +     */
 +    public BinaryObjectBuilderImpl(PortableContext ctx, int typeId, String typeName) {
 +        this.typeId = typeId;
 +        this.typeName = typeName;
 +        this.ctx = ctx;
 +
 +        start = -1;
 +        flags = -1;
 +        reader = null;
 +        hdrLen = GridPortableMarshaller.DFLT_HDR_LEN;
 +
 +        readCache = Collections.emptyMap();
 +    }
 +
 +    /**
 +     * @param obj Object to wrap.
 +     */
 +    public BinaryObjectBuilderImpl(BinaryObjectImpl obj) {
 +        this(new PortableBuilderReader(obj), obj.start());
 +
 +        reader.registerObject(this);
 +    }
 +
 +    /**
 +     * @param reader ctx
 +     * @param start Start.
 +     */
 +    BinaryObjectBuilderImpl(PortableBuilderReader reader, int start) {
 +        this.reader = reader;
 +        this.start = start;
 +        this.flags = reader.readShortPositioned(start + GridPortableMarshaller.FLAGS_POS);
 +
 +        byte ver = reader.readBytePositioned(start + GridPortableMarshaller.PROTO_VER_POS);
 +
 +        PortableUtils.checkProtocolVersion(ver);
 +
 +        int typeId = reader.readIntPositioned(start + GridPortableMarshaller.TYPE_ID_POS);
 +        ctx = reader.portableContext();
 +        hashCode = reader.readIntPositioned(start + GridPortableMarshaller.HASH_CODE_POS);
 +
 +        if (typeId == GridPortableMarshaller.UNREGISTERED_TYPE_ID) {
 +            int mark = reader.position();
 +
 +            reader.position(start + GridPortableMarshaller.DFLT_HDR_LEN);
 +
 +            clsNameToWrite = reader.readString();
 +
 +            Class cls;
 +
 +            try {
-                 // TODO: IGNITE-1272 - Is class loader needed here?
-                 cls = U.forName(clsNameToWrite, null);
++                cls = U.forName(clsNameToWrite, ctx.configuration().getClassLoader());
 +            }
 +            catch (ClassNotFoundException e) {
 +                throw new BinaryInvalidTypeException("Failed to load the class: " + clsNameToWrite, e);
 +            }
 +
 +            this.typeId = ctx.descriptorForClass(cls, false).typeId();
 +
 +            registeredType = false;
 +
 +            hdrLen = reader.position() - mark;
 +
 +            reader.position(mark);
 +        }
 +        else {
 +            this.typeId = typeId;
 +            hdrLen = GridPortableMarshaller.DFLT_HDR_LEN;
 +        }
 +    }
 +
 +    /** {@inheritDoc} */
 +    @Override public BinaryObject build() {
 +        try (BinaryWriterExImpl writer = new BinaryWriterExImpl(ctx)) {
 +            writer.typeId(typeId);
 +
 +            PortableBuilderSerializer serializationCtx = new PortableBuilderSerializer();
 +
 +            serializationCtx.registerObjectWriting(this, 0);
 +
 +            serializeTo(writer, serializationCtx);
 +
 +            byte[] arr = writer.array();
 +
 +            return new BinaryObjectImpl(ctx, arr, 0);
 +        }
 +    }
 +
 +    /**
 +     * @param writer Writer.
 +     * @param serializer Serializer.
 +     */
 +    void serializeTo(BinaryWriterExImpl writer, PortableBuilderSerializer serializer) {
 +        try {
 +            writer.preWrite(registeredType ? null : clsNameToWrite);
 +
 +            Set<Integer> remainsFlds = null;
 +
 +            if (reader != null) {
 +                PortableSchema schema = reader.schema();
 +
 +                Map<Integer, Object> assignedFldsById;
 +
 +                if (assignedVals != null) {
 +                    assignedFldsById = U.newHashMap(assignedVals.size());
 +
 +                    for (Map.Entry<String, Object> entry : assignedVals.entrySet()) {
 +                        int fieldId = ctx.fieldId(typeId, entry.getKey());
 +
 +                        assignedFldsById.put(fieldId, entry.getValue());
 +                    }
 +
 +                    remainsFlds = assignedFldsById.keySet();
 +                }
 +                else
 +                    assignedFldsById = Collections.emptyMap();
 +
 +                // Get footer details.
 +                int fieldIdLen = PortableUtils.fieldIdLength(flags);
 +                int fieldOffsetLen = PortableUtils.fieldOffsetLength(flags);
 +
 +                IgniteBiTuple<Integer, Integer> footer = PortableUtils.footerAbsolute(reader, start);
 +
 +                int footerPos = footer.get1();
 +                int footerEnd = footer.get2();
 +
 +                // Get raw position.
 +                int rawPos = PortableUtils.rawOffsetAbsolute(reader, start);
 +
 +                // Position reader on data.
 +                reader.position(start + hdrLen);
 +
 +                int idx = 0;
 +
 +                while (reader.position() < rawPos) {
 +                    int fieldId = schema.fieldId(idx++);
 +                    int fieldLen =
 +                        fieldPositionAndLength(footerPos, footerEnd, rawPos, fieldIdLen, fieldOffsetLen).get2();
 +
 +                    int postPos = reader.position() + fieldLen; // Position where reader will be placed afterwards.
 +
 +                    footerPos += fieldIdLen + fieldOffsetLen;
 +
 +                    if (assignedFldsById.containsKey(fieldId)) {
 +                        Object assignedVal = assignedFldsById.remove(fieldId);
 +
 +                        if (assignedVal != REMOVED_FIELD_MARKER) {
 +                            writer.writeFieldId(fieldId);
 +
 +                            serializer.writeValue(writer, assignedVal);
 +                        }
 +                    }
 +                    else {
 +                        int type = fieldLen != 0 ? reader.readByte(0) : 0;
 +
 +                        if (fieldLen != 0 && !PortableUtils.isPlainArrayType(type) && PortableUtils.isPlainType(type)) {
 +                            writer.writeFieldId(fieldId);
 +
 +                            writer.write(reader.array(), reader.position(), fieldLen);
 +                        }
 +                        else {
 +                            writer.writeFieldId(fieldId);
 +
 +                            Object val;
 +
 +                            if (fieldLen == 0)
 +                                val = null;
 +                            else if (readCache == null) {
 +                                val = reader.parseValue();
 +
 +                                assert reader.position() == postPos;
 +                            }
 +                            else
 +                                val = readCache.get(fieldId);
 +
 +                            serializer.writeValue(writer, val);
 +                        }
 +                    }
 +
 +                    reader.position(postPos);
 +                }
 +            }
 +
 +            BinaryType meta = ctx.metadata(typeId);
 +
 +            Map<String, Integer> fieldsMeta = null;
 +
 +            if (assignedVals != null && (remainsFlds == null || !remainsFlds.isEmpty())) {
 +                for (Map.Entry<String, Object> entry : assignedVals.entrySet()) {
 +                    Object val = entry.getValue();
 +
 +                    if (val == REMOVED_FIELD_MARKER)
 +                        continue;
 +
 +                    String name = entry.getKey();
 +
 +                    int fieldId = ctx.fieldId(typeId, name);
 +
 +                    if (remainsFlds != null && !remainsFlds.contains(fieldId))
 +                        continue;
 +
 +                    writer.writeFieldId(fieldId);
 +
 +                    serializer.writeValue(writer, val);
 +
 +                    String oldFldTypeName = meta == null ? null : meta.fieldTypeName(name);
 +
 +                    boolean nullObjField = false;
 +
 +                    int newFldTypeId;
 +
 +                    if (val instanceof PortableValueWithType) {
 +                        newFldTypeId = ((PortableValueWithType)val).typeId();
 +
 +                        if (newFldTypeId == GridPortableMarshaller.OBJ && ((PortableValueWithType)val).value() == null)
 +                            nullObjField = true;
 +                    }
 +                    else
 +                        newFldTypeId = PortableUtils.typeByClass(val.getClass());
 +
 +                    String newFldTypeName = PortableUtils.fieldTypeName(newFldTypeId);
 +
 +                    if (oldFldTypeName == null) {
 +                        // It's a new field, we have to add it to metadata.
 +                        if (fieldsMeta == null)
 +                            fieldsMeta = new HashMap<>();
 +
 +                        fieldsMeta.put(name, PortableUtils.fieldTypeId(newFldTypeName));
 +                    }
 +                    else if (!nullObjField) {
 +                        String objTypeName = PortableUtils.fieldTypeName(GridPortableMarshaller.OBJ);
 +
 +                        if (!objTypeName.equals(oldFldTypeName) && !oldFldTypeName.equals(newFldTypeName)) {
 +                            throw new BinaryObjectException(
 +                                "Wrong value has been set [" +
 +                                    "typeName=" + (typeName == null ? meta.typeName() : typeName) +
 +                                    ", fieldName=" + name +
 +                                    ", fieldType=" + oldFldTypeName +
 +                                    ", assignedValueType=" + newFldTypeName + ']'
 +                            );
 +                        }
 +                    }
 +                }
 +            }
 +
 +            if (reader != null) {
 +                // Write raw data if any.
 +                int rawOff = PortableUtils.rawOffsetAbsolute(reader, start);
 +                int footerStart = PortableUtils.footerStartAbsolute(reader, start);
 +
 +                if (rawOff < footerStart) {
 +                    writer.rawWriter();
 +
 +                    writer.write(reader.array(), rawOff, footerStart - rawOff);
 +                }
 +
 +                // Shift reader to the end of the object.
 +                reader.position(start + PortableUtils.length(reader, start));
 +            }
 +
 +            writer.postWrite(true, registeredType, hashCode);
 +
 +            // Update metadata if needed.
 +            int schemaId = writer.schemaId();
 +
 +            PortableSchemaRegistry schemaReg = ctx.schemaRegistry(typeId);
 +
 +            if (schemaReg.schema(schemaId) == null) {
 +                String typeName = this.typeName;
 +
 +                if (typeName == null) {
 +                    assert meta != null;
 +
 +                    typeName = meta.typeName();
 +                }
 +
 +                PortableSchema curSchema = writer.currentSchema();
 +
 +                ctx.updateMetadata(typeId, new BinaryMetadata(typeId, typeName, fieldsMeta,
 +                    ctx.affinityKeyFieldName(typeId), Collections.singleton(curSchema), false));
 +
 +                schemaReg.addSchema(curSchema.schemaId(), curSchema);
 +            }
 +        }
 +        finally {
 +            writer.popSchema();
 +        }
 +    }
 +
 +    /** {@inheritDoc} */
 +    @Override public BinaryObjectBuilderImpl hashCode(int hashCode) {
 +        this.hashCode = hashCode;
 +
 +        return this;
 +    }
 +
 +    /**
 +     * Get field position and length.
 +     *
 +     * @param footerPos Field position inside the footer (absolute).
 +     * @param footerEnd Footer end (absolute).
 +     * @param rawPos Raw data position (absolute).
 +     * @param fieldIdLen Field ID length.
 +     * @param fieldOffsetLen Field offset length.
 +     * @return Tuple with field position and length.
 +     */
 +    private IgniteBiTuple<Integer, Integer> fieldPositionAndLength(int footerPos, int footerEnd, int rawPos,
 +        int fieldIdLen, int fieldOffsetLen) {
 +        // Get field offset first.
 +        int fieldOffset = PortableUtils.fieldOffsetRelative(reader, footerPos + fieldIdLen, fieldOffsetLen);
 +        int fieldPos = start + fieldOffset;
 +
 +        // Get field length.
 +        int fieldLen;
 +
 +        if (footerPos + fieldIdLen + fieldOffsetLen == footerEnd)
 +            // This is the last field, compare to raw offset.
 +            fieldLen = rawPos - fieldPos;
 +        else {
 +            // Field is somewhere in the middle, get difference with the next offset.
 +            int nextFieldOffset = PortableUtils.fieldOffsetRelative(reader,
 +                footerPos + fieldIdLen + fieldOffsetLen + fieldIdLen, fieldOffsetLen);
 +
 +            fieldLen = nextFieldOffset - fieldOffset;
 +        }
 +
 +        return F.t(fieldPos, fieldLen);
 +    }
 +
 +    /**
 +     * Initialize read cache if needed.
 +     */
 +    private void ensureReadCacheInit() {
 +        assert reader != null;
 +
 +        if (readCache == null) {
 +            int fieldIdLen = PortableUtils.fieldIdLength(flags);
 +            int fieldOffsetLen = PortableUtils.fieldOffsetLength(flags);
 +
 +            PortableSchema schema = reader.schema();
 +
 +            Map<Integer, Object> readCache = new HashMap<>();
 +
 +            IgniteBiTuple<Integer, Integer> footer = PortableUtils.footerAbsolute(reader, start);
 +
 +            int footerPos = footer.get1();
 +            int footerEnd = footer.get2();
 +
 +            int rawPos = PortableUtils.rawOffsetAbsolute(reader, start);
 +
 +            int idx = 0;
 +
 +            while (footerPos + fieldIdLen < footerEnd) {
 +                int fieldId = schema.fieldId(idx++);
 +
 +                IgniteBiTuple<Integer, Integer> posAndLen =
 +                    fieldPositionAndLength(footerPos, footerEnd, rawPos, fieldIdLen, fieldOffsetLen);
 +
 +                Object val = reader.getValueQuickly(posAndLen.get1(), posAndLen.get2());
 +
 +                readCache.put(fieldId, val);
 +
 +                // Shift current footer position.
 +                footerPos += fieldIdLen + fieldOffsetLen;
 +            }
 +
 +            this.readCache = readCache;
 +        }
 +    }
 +
 +    /** {@inheritDoc} */
 +    @SuppressWarnings("unchecked")
 +    @Override public <T> T getField(String name) {
 +        Object val;
 +
 +        if (assignedVals != null && assignedVals.containsKey(name)) {
 +            val = assignedVals.get(name);
 +
 +            if (val == REMOVED_FIELD_MARKER)
 +                return null;
 +        }
 +        else {
 +            ensureReadCacheInit();
 +
 +            int fldId = ctx.fieldId(typeId, name);
 +
 +            val = readCache.get(fldId);
 +        }
 +
 +        return (T)PortableUtils.unwrapLazy(val);
 +    }
 +
 +    /** {@inheritDoc} */
 +    @Override public BinaryObjectBuilder setField(String name, Object val0) {
 +        Object val = val0 == null ? new PortableValueWithType(PortableUtils.typeByClass(Object.class), null) : val0;
 +
 +        if (assignedVals == null)
 +            assignedVals = new LinkedHashMap<>();
 +
 +        Object oldVal = assignedVals.put(name, val);
 +
 +        if (oldVal instanceof PortableValueWithType && val0 != null) {
 +            ((PortableValueWithType)oldVal).value(val);
 +
 +            assignedVals.put(name, oldVal);
 +        }
 +
 +        return this;
 +    }
 +
 +    /** {@inheritDoc} */
 +    @Override public <T> BinaryObjectBuilder setField(String name, @Nullable T val, Class<? super T> type) {
 +        if (assignedVals == null)
 +            assignedVals = new LinkedHashMap<>();
 +
 +        assignedVals.put(name, new PortableValueWithType(PortableUtils.typeByClass(type), val));
 +
 +        return this;
 +    }
 +
 +    /** {@inheritDoc} */
 +    @Override public BinaryObjectBuilder setField(String name, @Nullable BinaryObjectBuilder builder) {
 +        if (builder == null)
 +            return setField(name, null, Object.class);
 +        else
 +            return setField(name, (Object)builder);
 +    }
 +
 +    /**
 +     * Removes field from portable object.
 +     *
 +     * @param name Field name.
 +     * @return {@code this} instance for chaining.
 +     */
 +    @Override public BinaryObjectBuilderImpl removeField(String name) {
 +        if (assignedVals == null)
 +            assignedVals = new LinkedHashMap<>();
 +
 +        assignedVals.put(name, REMOVED_FIELD_MARKER);
 +
 +        return this;
 +    }
 +
 +    /**
 +     * Creates builder initialized by specified portable object.
 +     *
 +     * @param obj Portable object to initialize builder.
 +     * @return New builder.
 +     */
 +    public static BinaryObjectBuilderImpl wrap(BinaryObject obj) {
 +        BinaryObjectImpl heapObj;
 +
 +        if (obj instanceof BinaryObjectOffheapImpl)
 +            heapObj = (BinaryObjectImpl)((BinaryObjectOffheapImpl)obj).heapCopy();
 +        else
 +            heapObj = (BinaryObjectImpl)obj;
 +
 +        return new BinaryObjectBuilderImpl(heapObj);
 +    }
 +
 +    /**
 +     * @return Object start position in source array.
 +     */
 +    int start() {
 +        return start;
 +    }
 +
 +    /**
 +     * @return Object type id.
 +     */
 +    public int typeId() {
 +        return typeId;
 +    }
 +}

http://git-wip-us.apache.org/repos/asf/ignite/blob/0ac39c97/modules/core/src/main/java/org/apache/ignite/internal/binary/builder/PortableBuilderEnum.java
----------------------------------------------------------------------
diff --cc modules/core/src/main/java/org/apache/ignite/internal/binary/builder/PortableBuilderEnum.java
index 3bb8194,0000000..779c514
mode 100644,000000..100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/binary/builder/PortableBuilderEnum.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/binary/builder/PortableBuilderEnum.java
@@@ -1,116 -1,0 +1,115 @@@
 +/*
 + * 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.binary.builder;
 +
 +import org.apache.ignite.internal.binary.GridPortableMarshaller;
 +import org.apache.ignite.internal.binary.BinaryWriterExImpl;
 +import org.apache.ignite.internal.util.typedef.internal.U;
 +import org.apache.ignite.binary.BinaryInvalidTypeException;
 +
 +/**
 + *
 + */
 +public class PortableBuilderEnum implements PortableBuilderSerializationAware {
 +    /** */
 +    private final int ordinal;
 +
 +    /** */
 +    private final int typeId;
 +
 +    /** */
 +    private final String clsName;
 +
 +    /**
 +     * @param typeId Type ID.
 +     * @param anEnum Enum instance.
 +     */
 +    public PortableBuilderEnum(int typeId, Enum anEnum) {
 +        ordinal = anEnum.ordinal();
 +        this.typeId = typeId;
 +        clsName = null;
 +    }
 +
 +    /**
 +     * @param reader PortableBuilderReader.
 +     */
 +    public PortableBuilderEnum(PortableBuilderReader reader) {
 +        int typeId = reader.readInt();
 +
 +        if (typeId == GridPortableMarshaller.UNREGISTERED_TYPE_ID) {
 +            clsName = reader.readString();
 +
 +            Class cls;
 +
 +            try {
-                 // TODO: IGNITE-1272 - Is class loader needed here?
-                 cls = U.forName(reader.readString(), null);
++                cls = U.forName(reader.readString(), reader.portableContext().configuration().getClassLoader());
 +            }
 +            catch (ClassNotFoundException e) {
 +                throw new BinaryInvalidTypeException("Failed to load the class: " + clsName, e);
 +            }
 +
 +            this.typeId = reader.portableContext().descriptorForClass(cls, false).typeId();
 +        }
 +        else {
 +            this.typeId = typeId;
 +            this.clsName = null;
 +        }
 +
 +        ordinal = reader.readInt();
 +    }
 +
 +    /**
 +     * @return Ordinal.
 +     */
 +    public int getOrdinal() {
 +        return ordinal;
 +    }
 +
 +    /** {@inheritDoc} */
 +    @Override public void writeTo(BinaryWriterExImpl writer, PortableBuilderSerializer ctx) {
 +        writer.writeByte(GridPortableMarshaller.ENUM);
 +
 +        if (typeId == GridPortableMarshaller.UNREGISTERED_TYPE_ID) {
 +            writer.writeInt(GridPortableMarshaller.UNREGISTERED_TYPE_ID);
 +            writer.writeString(clsName);
 +        }
 +        else
 +            writer.writeInt(typeId);
 +
 +        writer.writeInt(ordinal);
 +    }
 +
 +    /** {@inheritDoc} */
 +    @Override public boolean equals(Object o) {
 +        if (o == null || getClass() != o.getClass())
 +            return false;
 +
 +        PortableBuilderEnum that = (PortableBuilderEnum)o;
 +
 +        return ordinal == that.ordinal && typeId == that.typeId;
 +    }
 +
 +    /** {@inheritDoc} */
 +    @Override public int hashCode() {
 +        int result = ordinal;
 +
 +        result = 31 * result + typeId;
 +
 +        return result;
 +    }
 +}

http://git-wip-us.apache.org/repos/asf/ignite/blob/0ac39c97/modules/core/src/main/java/org/apache/ignite/internal/binary/builder/PortableBuilderReader.java
----------------------------------------------------------------------
diff --cc modules/core/src/main/java/org/apache/ignite/internal/binary/builder/PortableBuilderReader.java
index 2b28e3d,0000000..c86fb95
mode 100644,000000..100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/binary/builder/PortableBuilderReader.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/binary/builder/PortableBuilderReader.java
@@@ -1,856 -1,0 +1,857 @@@
 +/*
 + * 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.binary.builder;
 +
 +import org.apache.ignite.binary.BinaryObjectException;
 +import org.apache.ignite.internal.binary.BinaryObjectImpl;
 +import org.apache.ignite.internal.binary.BinaryReaderExImpl;
 +import org.apache.ignite.internal.binary.BinaryWriterExImpl;
 +import org.apache.ignite.internal.binary.GridPortableMarshaller;
 +import org.apache.ignite.internal.binary.PortableContext;
 +import org.apache.ignite.internal.binary.PortablePositionReadable;
 +import org.apache.ignite.internal.binary.PortablePrimitives;
 +import org.apache.ignite.internal.binary.PortableSchema;
 +import org.apache.ignite.internal.binary.streams.PortableHeapInputStream;
 +import org.apache.ignite.internal.binary.BinaryObjectImpl;
 +import org.apache.ignite.internal.binary.BinaryReaderExImpl;
 +import org.apache.ignite.internal.binary.BinaryWriterExImpl;
 +import org.apache.ignite.internal.binary.GridPortableMarshaller;
 +import org.apache.ignite.internal.binary.PortableContext;
 +import org.apache.ignite.internal.binary.PortablePositionReadable;
 +import org.apache.ignite.internal.binary.PortablePrimitives;
 +import org.apache.ignite.internal.binary.PortableSchema;
 +import org.apache.ignite.internal.binary.PortableUtils;
 +import org.apache.ignite.internal.binary.streams.PortableHeapInputStream;
 +
 +import java.sql.Timestamp;
 +import java.util.Date;
 +import java.util.HashMap;
 +import java.util.Map;
 +
 +import static java.nio.charset.StandardCharsets.UTF_8;
 +import static org.apache.ignite.internal.binary.GridPortableMarshaller.NULL;
 +import static org.apache.ignite.internal.binary.GridPortableMarshaller.STRING;
 +
 +/**
 + *
 + */
 +public class PortableBuilderReader implements PortablePositionReadable {
 +    /** */
 +    private final PortableContext ctx;
 +
 +    /** */
 +    private final byte[] arr;
 +
 +    /** */
 +    private final BinaryReaderExImpl reader;
 +
 +    /** */
 +    private final Map<Integer, BinaryObjectBuilderImpl> objMap;
 +
 +    /** */
 +    private int pos;
 +
 +    /*
 +     * Constructor.
 +     *
 +     * @param objImpl Portable object
 +     */
 +    PortableBuilderReader(BinaryObjectImpl objImpl) {
 +        ctx = objImpl.context();
 +        arr = objImpl.array();
 +        pos = objImpl.start();
 +
-         // TODO: IGNITE-1272 - Is class loader needed here?
-         reader = new BinaryReaderExImpl(ctx, PortableHeapInputStream.create(arr, pos), null);
++        reader = new BinaryReaderExImpl(ctx,
++            PortableHeapInputStream.create(arr, pos),
++            ctx.configuration().getClassLoader());
 +
 +        objMap = new HashMap<>();
 +    }
 +
 +    /**
 +     * Copying constructor.
 +     *
 +     * @param other Other reader.
 +     * @param start Start position.
 +     */
 +    PortableBuilderReader(PortableBuilderReader other, int start) {
 +        this.ctx = other.ctx;
 +        this.arr = other.arr;
 +        this.pos = start;
 +
 +        reader = new BinaryReaderExImpl(ctx, PortableHeapInputStream.create(arr, start), null, other.reader.handles());
 +
 +        this.objMap = other.objMap;
 +    }
 +
 +    /**
 +     * @return Portable context.
 +     */
 +    public PortableContext portableContext() {
 +        return ctx;
 +    }
 +
 +    /**
 +     * @param obj Mutable portable object.
 +     */
 +    public void registerObject(BinaryObjectBuilderImpl obj) {
 +        objMap.put(obj.start(), obj);
 +    }
 +
 +    /**
 +     * Get schema of the object, starting at the given position.
 +     *
 +     * @return Object's schema.
 +     */
 +    public PortableSchema schema() {
 +        return reader.getOrCreateSchema();
 +    }
 +
 +    /**
 +     * @return Read int value.
 +     */
 +    public int readInt() {
 +        int res = readInt(0);
 +
 +        pos += 4;
 +
 +        return res;
 +    }
 +
 +    /**
 +     * @return Read int value.
 +     */
 +    public byte readByte() {
 +        return arr[pos++];
 +    }
 +
 +    /**
 +     * @return Read boolean value.
 +     */
 +    public boolean readBoolean() {
 +        return readByte() == 1;
 +    }
 +
 +    /**
 +     * @return Read int value.
 +     */
 +    public byte readByte(int off) {
 +        return arr[pos + off];
 +    }
 +
 +    /**
 +     * @param off Offset related to {@link #pos}
 +     * @return Read int value.
 +     */
 +    public int readInt(int off) {
 +        return PortablePrimitives.readInt(arr, pos + off);
 +    }
 +
 +    /**
 +     * @param pos Position in the source array.
 +     * @return Read byte value.
 +     */
 +    public byte readBytePositioned(int pos) {
 +        return PortablePrimitives.readByte(arr, pos);
 +    }
 +
 +    /** {@inheritDoc} */
 +    @Override public short readShortPositioned(int pos) {
 +        return PortablePrimitives.readShort(arr, pos);
 +    }
 +
 +    /** {@inheritDoc} */
 +    @Override public int readIntPositioned(int pos) {
 +        return PortablePrimitives.readInt(arr, pos);
 +    }
 +
 +    /**
 +     * @return Read length of array.
 +     */
 +    public int readLength() {
 +        return PortablePrimitives.readInt(arr, pos);
 +    }
 +
 +    /**
 +     * Read string length.
 +     *
 +     * @return String length.
 +     */
 +    public int readStringLength() {
 +        return PortablePrimitives.readInt(arr, pos);
 +    }
 +
 +    /**
 +     * Reads string.
 +     *
 +     * @return String.
 +     */
 +    public String readString() {
 +        byte flag = readByte();
 +
 +        if (flag == GridPortableMarshaller.NULL)
 +            return null;
 +
 +        if (flag != GridPortableMarshaller.STRING)
 +            throw new BinaryObjectException("Failed to deserialize String.");
 +
 +        int len = readInt();
 +
 +        String str = new String(arr, pos, len, UTF_8);
 +
 +        pos += len;
 +
 +        return str;
 +    }
 +
 +    /**
 +     *
 +     */
 +    public void skipValue() {
 +        byte type = arr[pos++];
 +
 +        int len;
 +
 +        switch (type) {
 +            case GridPortableMarshaller.NULL:
 +                return;
 +
 +            case GridPortableMarshaller.OBJ:
 +                pos += readInt(GridPortableMarshaller.TOTAL_LEN_POS - 1) - 1;
 +
 +                return;
 +
 +            case GridPortableMarshaller.BOOLEAN:
 +            case GridPortableMarshaller.BYTE:
 +                len = 1;
 +                break;
 +
 +            case GridPortableMarshaller.CHAR:
 +            case GridPortableMarshaller.SHORT:
 +                len = 2;
 +
 +                break;
 +
 +            case GridPortableMarshaller.HANDLE:
 +            case GridPortableMarshaller.FLOAT:
 +            case GridPortableMarshaller.INT:
 +                len = 4;
 +
 +                break;
 +
 +            case GridPortableMarshaller.ENUM:
 +                //skipping type id and ordinal value
 +                len = 8;
 +
 +                break;
 +
 +            case GridPortableMarshaller.LONG:
 +            case GridPortableMarshaller.DOUBLE:
 +                len = 8;
 +
 +                break;
 +
 +            case GridPortableMarshaller.BYTE_ARR:
 +            case GridPortableMarshaller.BOOLEAN_ARR:
 +                len = 4 + readLength();
 +
 +                break;
 +
 +            case GridPortableMarshaller.STRING:
 +                len = 4 + readStringLength();
 +
 +                break;
 +
 +            case GridPortableMarshaller.DECIMAL:
 +                len = /** scale */ 4  + /** mag len */ 4  + /** mag bytes count */ readInt(4);
 +
 +                break;
 +
 +            case GridPortableMarshaller.UUID:
 +                len = 8 + 8;
 +
 +                break;
 +
 +            case GridPortableMarshaller.DATE:
 +                len = 8;
 +
 +                break;
 +
 +            case GridPortableMarshaller.TIMESTAMP:
 +                len = 8 + 4;
 +
 +                break;
 +
 +            case GridPortableMarshaller.CHAR_ARR:
 +            case GridPortableMarshaller.SHORT_ARR:
 +                len = 4 + readLength() * 2;
 +
 +                break;
 +
 +            case GridPortableMarshaller.INT_ARR:
 +            case GridPortableMarshaller.FLOAT_ARR:
 +                len = 4 + readLength() * 4;
 +
 +                break;
 +
 +            case GridPortableMarshaller.LONG_ARR:
 +            case GridPortableMarshaller.DOUBLE_ARR:
 +                len = 4 + readLength() * 8;
 +
 +                break;
 +
 +            case GridPortableMarshaller.DECIMAL_ARR:
 +            case GridPortableMarshaller.DATE_ARR:
 +            case GridPortableMarshaller.TIMESTAMP_ARR:
 +            case GridPortableMarshaller.OBJ_ARR:
 +            case GridPortableMarshaller.ENUM_ARR:
 +            case GridPortableMarshaller.UUID_ARR:
 +            case GridPortableMarshaller.STRING_ARR: {
 +                int size = readInt();
 +
 +                for (int i = 0; i < size; i++)
 +                    skipValue();
 +
 +                return;
 +            }
 +
 +            case GridPortableMarshaller.COL: {
 +                int size = readInt();
 +
 +                pos++; // skip collection type
 +
 +                for (int i = 0; i < size; i++)
 +                    skipValue();
 +
 +                return;
 +            }
 +
 +            case GridPortableMarshaller.MAP: {
 +                int size = readInt();
 +
 +                pos++; // skip collection type
 +
 +                for (int i = 0; i < size; i++) {
 +                    skipValue(); // skip key.
 +                    skipValue(); // skip value.
 +                }
 +
 +                return;
 +            }
 +
 +            case GridPortableMarshaller.PORTABLE_OBJ:
 +                len = readInt() + 4;
 +
 +                break;
 +
 +            default:
 +                throw new BinaryObjectException("Invalid flag value: " + type);
 +        }
 +
 +        pos += len;
 +    }
 +
 +    /**
 +     * @param pos Position.
 +     * @param len Length.
 +     * @return Object.
 +     */
 +    public Object getValueQuickly(int pos, int len) {
 +        byte type = arr[pos];
 +
 +        switch (type) {
 +            case GridPortableMarshaller.NULL:
 +                return null;
 +
 +            case GridPortableMarshaller.HANDLE: {
 +                int objStart = pos - readIntPositioned(pos + 1);
 +
 +                BinaryObjectBuilderImpl res = objMap.get(objStart);
 +
 +                if (res == null) {
 +                    res = new BinaryObjectBuilderImpl(new PortableBuilderReader(this, objStart), objStart);
 +
 +                    objMap.put(objStart, res);
 +                }
 +
 +                return res;
 +            }
 +
 +            case GridPortableMarshaller.OBJ: {
 +                BinaryObjectBuilderImpl res = objMap.get(pos);
 +
 +                if (res == null) {
 +                    res = new BinaryObjectBuilderImpl(new PortableBuilderReader(this, pos), pos);
 +
 +                    objMap.put(pos, res);
 +                }
 +
 +                return res;
 +            }
 +
 +            case GridPortableMarshaller.BYTE:
 +                return arr[pos + 1];
 +
 +            case GridPortableMarshaller.SHORT:
 +                return PortablePrimitives.readShort(arr, pos + 1);
 +
 +            case GridPortableMarshaller.INT:
 +                return PortablePrimitives.readInt(arr, pos + 1);
 +
 +            case GridPortableMarshaller.LONG:
 +                return PortablePrimitives.readLong(arr, pos + 1);
 +
 +            case GridPortableMarshaller.FLOAT:
 +                return PortablePrimitives.readFloat(arr, pos + 1);
 +
 +            case GridPortableMarshaller.DOUBLE:
 +                return PortablePrimitives.readDouble(arr, pos + 1);
 +
 +            case GridPortableMarshaller.CHAR:
 +                return PortablePrimitives.readChar(arr, pos + 1);
 +
 +            case GridPortableMarshaller.BOOLEAN:
 +                return arr[pos + 1] != 0;
 +
 +            case GridPortableMarshaller.DECIMAL:
 +            case GridPortableMarshaller.STRING:
 +            case GridPortableMarshaller.UUID:
 +            case GridPortableMarshaller.DATE:
 +            case GridPortableMarshaller.TIMESTAMP:
 +                return new PortablePlainLazyValue(this, pos, len);
 +
 +            case GridPortableMarshaller.BYTE_ARR:
 +            case GridPortableMarshaller.SHORT_ARR:
 +            case GridPortableMarshaller.INT_ARR:
 +            case GridPortableMarshaller.LONG_ARR:
 +            case GridPortableMarshaller.FLOAT_ARR:
 +            case GridPortableMarshaller.DOUBLE_ARR:
 +            case GridPortableMarshaller.CHAR_ARR:
 +            case GridPortableMarshaller.BOOLEAN_ARR:
 +            case GridPortableMarshaller.DECIMAL_ARR:
 +            case GridPortableMarshaller.DATE_ARR:
 +            case GridPortableMarshaller.TIMESTAMP_ARR:
 +            case GridPortableMarshaller.UUID_ARR:
 +            case GridPortableMarshaller.STRING_ARR:
 +            case GridPortableMarshaller.ENUM_ARR:
 +            case GridPortableMarshaller.OBJ_ARR:
 +            case GridPortableMarshaller.COL:
 +            case GridPortableMarshaller.MAP:
 +                return new LazyCollection(pos);
 +
 +            case GridPortableMarshaller.ENUM: {
 +                if (len == 1) {
 +                    assert readByte(pos) == GridPortableMarshaller.NULL;
 +
 +                    return null;
 +                }
 +
 +                int mark = position();
 +                position(pos + 1);
 +
 +                PortableBuilderEnum builderEnum = new PortableBuilderEnum(this);
 +
 +                position(mark);
 +
 +                return builderEnum;
 +            }
 +
 +            case GridPortableMarshaller.PORTABLE_OBJ: {
 +                int size = readIntPositioned(pos + 1);
 +
 +                int start = readIntPositioned(pos + 4 + size);
 +
 +                BinaryObjectImpl portableObj = new BinaryObjectImpl(ctx, arr, pos + 4 + start);
 +
 +                return new PortablePlainPortableObject(portableObj);
 +            }
 +
 +            default:
 +                throw new BinaryObjectException("Invalid flag value: " + type);
 +        }
 +    }
 +
 +    /**
 +     * @return Parsed value.
 +     */
 +    public Object parseValue() {
 +        int valPos = pos;
 +
 +        byte type = arr[pos++];
 +
 +        int plainLazyValLen;
 +
 +        boolean modifiableLazyVal = false;
 +
 +        switch (type) {
 +            case GridPortableMarshaller.NULL:
 +                return null;
 +
 +            case GridPortableMarshaller.HANDLE: {
 +                int objStart = pos - 1 - readInt();
 +
 +                BinaryObjectBuilderImpl res = objMap.get(objStart);
 +
 +                if (res == null) {
 +                    res = new BinaryObjectBuilderImpl(new PortableBuilderReader(this, objStart), objStart);
 +
 +                    objMap.put(objStart, res);
 +                }
 +
 +                return res;
 +            }
 +
 +            case GridPortableMarshaller.OBJ: {
 +                pos--;
 +
 +                BinaryObjectBuilderImpl res = objMap.get(pos);
 +
 +                if (res == null) {
 +                    res = new BinaryObjectBuilderImpl(new PortableBuilderReader(this, pos), pos);
 +
 +                    objMap.put(pos, res);
 +                }
 +
 +                pos += readInt(GridPortableMarshaller.TOTAL_LEN_POS);
 +
 +                return res;
 +            }
 +
 +            case GridPortableMarshaller.BYTE:
 +                return arr[pos++];
 +
 +            case GridPortableMarshaller.SHORT: {
 +                Object res = PortablePrimitives.readShort(arr, pos);
 +                pos += 2;
 +                return res;
 +            }
 +
 +            case GridPortableMarshaller.INT:
 +                return readInt();
 +
 +            case GridPortableMarshaller.LONG:
 +                plainLazyValLen = 8;
 +
 +                break;
 +
 +            case GridPortableMarshaller.FLOAT:
 +                plainLazyValLen = 4;
 +
 +                break;
 +
 +            case GridPortableMarshaller.DOUBLE:
 +                plainLazyValLen = 8;
 +
 +                break;
 +
 +            case GridPortableMarshaller.CHAR:
 +                plainLazyValLen = 2;
 +
 +                break;
 +
 +            case GridPortableMarshaller.BOOLEAN:
 +                return arr[pos++] != 0;
 +
 +            case GridPortableMarshaller.DECIMAL:
 +                plainLazyValLen = /** scale */ 4  + /** mag len */ 4  + /** mag bytes count */ readInt(4);
 +
 +                break;
 +
 +            case GridPortableMarshaller.STRING:
 +                plainLazyValLen = 4 + readStringLength();
 +
 +                break;
 +
 +            case GridPortableMarshaller.UUID:
 +                plainLazyValLen = 8 + 8;
 +
 +                break;
 +
 +            case GridPortableMarshaller.DATE:
 +                plainLazyValLen = 8;
 +
 +                break;
 +
 +            case GridPortableMarshaller.TIMESTAMP:
 +                plainLazyValLen = 8 + 4;
 +
 +                break;
 +
 +            case GridPortableMarshaller.BYTE_ARR:
 +                plainLazyValLen = 4 + readLength();
 +                modifiableLazyVal = true;
 +
 +                break;
 +
 +            case GridPortableMarshaller.SHORT_ARR:
 +                plainLazyValLen = 4 + readLength() * 2;
 +                modifiableLazyVal = true;
 +
 +                break;
 +
 +            case GridPortableMarshaller.INT_ARR:
 +                plainLazyValLen = 4 + readLength() * 4;
 +                modifiableLazyVal = true;
 +
 +                break;
 +
 +            case GridPortableMarshaller.LONG_ARR:
 +                plainLazyValLen = 4 + readLength() * 8;
 +                modifiableLazyVal = true;
 +
 +                break;
 +
 +            case GridPortableMarshaller.FLOAT_ARR:
 +                plainLazyValLen = 4 + readLength() * 4;
 +                modifiableLazyVal = true;
 +
 +                break;
 +
 +            case GridPortableMarshaller.DOUBLE_ARR:
 +                plainLazyValLen = 4 + readLength() * 8;
 +                modifiableLazyVal = true;
 +
 +                break;
 +
 +            case GridPortableMarshaller.CHAR_ARR:
 +                plainLazyValLen = 4 + readLength() * 2;
 +                modifiableLazyVal = true;
 +
 +                break;
 +
 +            case GridPortableMarshaller.BOOLEAN_ARR:
 +                plainLazyValLen = 4 + readLength();
 +                modifiableLazyVal = true;
 +
 +                break;
 +
 +            case GridPortableMarshaller.OBJ_ARR:
 +                return new PortableObjectArrayLazyValue(this);
 +
 +            case GridPortableMarshaller.DATE_ARR: {
 +                int size = readInt();
 +
 +                Date[] res = new Date[size];
 +
 +                for (int i = 0; i < res.length; i++) {
 +                    byte flag = arr[pos++];
 +
 +                    if (flag == GridPortableMarshaller.NULL) continue;
 +
 +                    if (flag != GridPortableMarshaller.DATE)
 +                        throw new BinaryObjectException("Invalid flag value: " + flag);
 +
 +                    long time = PortablePrimitives.readLong(arr, pos);
 +
 +                    pos += 8;
 +
 +                    res[i] = new Date(time);
 +                }
 +
 +                return res;
 +            }
 +
 +            case GridPortableMarshaller.TIMESTAMP_ARR: {
 +                int size = readInt();
 +
 +                Timestamp[] res = new Timestamp[size];
 +
 +                for (int i = 0; i < res.length; i++) {
 +                    byte flag = arr[pos++];
 +
 +                    if (flag == GridPortableMarshaller.NULL)
 +                        continue;
 +
 +                    if (flag != GridPortableMarshaller.TIMESTAMP)
 +                        throw new BinaryObjectException("Invalid flag value: " + flag);
 +
 +                    long time = PortablePrimitives.readLong(arr, pos);
 +
 +                    pos += 8;
 +
 +                    int nano = PortablePrimitives.readInt(arr, pos);
 +
 +                    pos += 4;
 +
 +                    Timestamp ts = new Timestamp(time);
 +
 +                    ts.setNanos(ts.getNanos() + nano);
 +
 +                    res[i] = ts;
 +                }
 +
 +                return res;
 +            }
 +
 +            case GridPortableMarshaller.UUID_ARR:
 +            case GridPortableMarshaller.STRING_ARR:
 +            case GridPortableMarshaller.DECIMAL_ARR: {
 +                int size = readInt();
 +
 +                for (int i = 0; i < size; i++) {
 +                    byte flag = arr[pos++];
 +
 +                    if (flag == GridPortableMarshaller.UUID)
 +                        pos += 8 + 8;
 +                    else if (flag == GridPortableMarshaller.STRING)
 +                        pos += 4 + readStringLength();
 +                    else if (flag == GridPortableMarshaller.DECIMAL) {
 +                        pos += 4; // scale value
 +                        pos += 4 + readLength();
 +                    }
 +                    else
 +                        assert flag == GridPortableMarshaller.NULL;
 +                }
 +
 +                return new PortableModifiableLazyValue(this, valPos, pos - valPos);
 +            }
 +
 +            case GridPortableMarshaller.COL: {
 +                int size = readInt();
 +                byte colType = arr[pos++];
 +
 +                switch (colType) {
 +                    case GridPortableMarshaller.USER_COL:
 +                    case GridPortableMarshaller.ARR_LIST:
 +                        return new PortableLazyArrayList(this, size);
 +
 +                    case GridPortableMarshaller.LINKED_LIST:
 +                        return new PortableLazyLinkedList(this, size);
 +
 +                    case GridPortableMarshaller.HASH_SET:
 +                    case GridPortableMarshaller.LINKED_HASH_SET:
 +                        return new PortableLazySet(this, size);
 +                }
 +
 +                throw new BinaryObjectException("Unknown collection type: " + colType);
 +            }
 +
 +            case GridPortableMarshaller.MAP:
 +                return PortableLazyMap.parseMap(this);
 +
 +            case GridPortableMarshaller.ENUM:
 +                return new PortableBuilderEnum(this);
 +
 +            case GridPortableMarshaller.ENUM_ARR:
 +                return new PortableEnumArrayLazyValue(this);
 +
 +            case GridPortableMarshaller.PORTABLE_OBJ: {
 +                int size = readInt();
 +
 +                pos += size;
 +
 +                int start = readInt();
 +
 +                BinaryObjectImpl portableObj = new BinaryObjectImpl(ctx, arr,
 +                    pos - 4 - size + start);
 +
 +                return new PortablePlainPortableObject(portableObj);
 +            }
 +
 +            default:
 +                throw new BinaryObjectException("Invalid flag value: " + type);
 +        }
 +
 +        PortableAbstractLazyValue res;
 +
 +        if (modifiableLazyVal)
 +            res = new PortableModifiableLazyValue(this, valPos, 1 + plainLazyValLen);
 +        else
 +            res = new PortablePlainLazyValue(this, valPos, 1 + plainLazyValLen);
 +
 +        pos += plainLazyValLen;
 +
 +        return res;
 +    }
 +
 +    /**
 +     * @return Array.
 +     */
 +    public byte[] array() {
 +        return arr;
 +    }
 +
 +    /**
 +     * @return Position of reader.
 +     */
 +    public int position() {
 +        return pos;
 +    }
 +
 +    /**
 +     * @param pos New pos.
 +     */
 +    public void position(int pos) {
 +        this.pos = pos;
 +    }
 +
 +    /**
 +     * @param n Number of bytes to skip.
 +     */
 +    public void skip(int n) {
 +        pos += n;
 +    }
 +
 +    /**
 +     * @return Reader.
 +     */
 +    BinaryReaderExImpl reader() {
 +        return reader;
 +    }
 +
 +    /**
 +     *
 +     */
 +    private class LazyCollection implements PortableLazyValue {
 +        /** */
 +        private final int valOff;
 +
 +        /** */
 +        private Object col;
 +
 +        /**
 +         * @param valOff Value.
 +         */
 +        protected LazyCollection(int valOff) {
 +            this.valOff = valOff;
 +        }
 +
 +        /**
 +         * @return Object.
 +         */
 +        private Object wrappedCollection() {
 +            if (col == null) {
 +                position(valOff);
 +
 +                col = parseValue();
 +            }
 +
 +            return col;
 +        }
 +
 +        /** {@inheritDoc} */
 +        @Override public void writeTo(BinaryWriterExImpl writer, PortableBuilderSerializer ctx) {
 +            ctx.writeValue(writer, wrappedCollection());
 +        }
 +
 +        /** {@inheritDoc} */
 +        @Override public Object value() {
 +            return PortableUtils.unwrapLazy(wrappedCollection());
 +        }
 +    }
 +}


[15/59] [abbrv] ignite git commit: ignite-2065: rename "portable" packages to "binary"

Posted by ak...@apache.org.
http://git-wip-us.apache.org/repos/asf/ignite/blob/1dbf20e0/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/binary/CacheDefaultPortableAffinityKeyMapper.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/binary/CacheDefaultPortableAffinityKeyMapper.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/binary/CacheDefaultPortableAffinityKeyMapper.java
new file mode 100644
index 0000000..698cd7b
--- /dev/null
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/binary/CacheDefaultPortableAffinityKeyMapper.java
@@ -0,0 +1,51 @@
+/*
+ * 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.processors.cache.binary;
+
+import org.apache.ignite.IgniteException;
+import org.apache.ignite.internal.IgniteKernal;
+import org.apache.ignite.internal.processors.cache.GridCacheDefaultAffinityKeyMapper;
+import org.apache.ignite.internal.util.typedef.internal.U;
+import org.apache.ignite.binary.BinaryObject;
+
+/**
+ *
+ */
+public class CacheDefaultPortableAffinityKeyMapper extends GridCacheDefaultAffinityKeyMapper {
+    /** */
+    private static final long serialVersionUID = 0L;
+
+    /** {@inheritDoc} */
+    @Override public Object affinityKey(Object key) {
+        IgniteKernal kernal = (IgniteKernal)ignite;
+
+        CacheObjectBinaryProcessorImpl proc = (CacheObjectBinaryProcessorImpl)kernal.context().cacheObjects();
+
+        try {
+            key = proc.toPortable(key);
+        }
+        catch (IgniteException e) {
+            U.error(log, "Failed to marshal key to portable: " + key, e);
+        }
+
+        if (key instanceof BinaryObject)
+            return proc.affinityKey((BinaryObject)key);
+        else
+            return super.affinityKey(key);
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/1dbf20e0/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/binary/CacheObjectBinaryProcessor.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/binary/CacheObjectBinaryProcessor.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/binary/CacheObjectBinaryProcessor.java
new file mode 100644
index 0000000..d5638a5
--- /dev/null
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/binary/CacheObjectBinaryProcessor.java
@@ -0,0 +1,106 @@
+/*
+ * 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.processors.cache.binary;
+
+import java.util.Collection;
+import java.util.Map;
+import org.apache.ignite.IgniteException;
+import org.apache.ignite.IgniteBinary;
+import org.apache.ignite.internal.processors.cacheobject.IgniteCacheObjectProcessor;
+import org.apache.ignite.binary.BinaryObjectBuilder;
+import org.apache.ignite.binary.BinaryType;
+import org.apache.ignite.binary.BinaryObject;
+import org.jetbrains.annotations.Nullable;
+
+/**
+ * Extended cache object processor interface with additional methods for binary.
+ */
+public interface CacheObjectBinaryProcessor extends IgniteCacheObjectProcessor {
+    /**
+     * @param clsName Class name.
+     * @return Builder.
+     */
+    public BinaryObjectBuilder builder(String clsName);
+
+    /**
+     * Creates builder initialized by existing portable object.
+     *
+     * @param portableObj Portable object to edit.
+     * @return Portable builder.
+     */
+    public BinaryObjectBuilder builder(BinaryObject portableObj);
+
+    /**
+     * @param typeId Type ID.
+     * @param newMeta New meta data.
+     * @throws IgniteException In case of error.
+     */
+    public void addMeta(int typeId, final BinaryType newMeta) throws IgniteException;
+
+    /**
+     * @param typeId Type ID.
+     * @param typeName Type name.
+     * @param affKeyFieldName Affinity key field name.
+     * @param fieldTypeIds Fields map.
+     * @param isEnum Enum flag.
+     * @throws IgniteException In case of error.
+     */
+    public void updateMetadata(int typeId, String typeName, @Nullable String affKeyFieldName,
+        Map<String, Integer> fieldTypeIds, boolean isEnum) throws IgniteException;
+
+    /**
+     * @param typeId Type ID.
+     * @return Meta data.
+     * @throws IgniteException In case of error.
+     */
+    @Nullable public BinaryType metadata(int typeId) throws IgniteException;
+
+    /**
+     * @param typeIds Type ID.
+     * @return Meta data.
+     * @throws IgniteException In case of error.
+     */
+    public Map<Integer, BinaryType> metadata(Collection<Integer> typeIds) throws IgniteException;
+
+    /**
+     * @return Metadata for all types.
+     * @throws IgniteException In case of error.
+     */
+    public Collection<BinaryType> metadata() throws IgniteException;
+
+    /**
+     * @param typeName Type name.
+     * @param ord ordinal.
+     * @return Enum object.
+     * @throws IgniteException If failed.
+     */
+    public BinaryObject buildEnum(String typeName, int ord) throws IgniteException;
+
+    /**
+     * @return Portables interface.
+     * @throws IgniteException If failed.
+     */
+    public IgniteBinary binary() throws IgniteException;
+
+    /**
+     * @param obj Original object.
+     * @return Portable object (in case portable marshaller is used).
+     * @throws IgniteException If failed.
+     */
+    public Object marshalToPortable(Object obj) throws IgniteException;
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/1dbf20e0/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/binary/CacheObjectBinaryProcessorImpl.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/binary/CacheObjectBinaryProcessorImpl.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/binary/CacheObjectBinaryProcessorImpl.java
new file mode 100644
index 0000000..9ae8a62
--- /dev/null
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/binary/CacheObjectBinaryProcessorImpl.java
@@ -0,0 +1,895 @@
+/*
+ * 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.processors.cache.binary;
+
+import java.io.Externalizable;
+import java.io.IOException;
+import java.io.ObjectInput;
+import java.io.ObjectOutput;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Map;
+import java.util.Set;
+import java.util.UUID;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.CountDownLatch;
+import javax.cache.Cache;
+import javax.cache.CacheException;
+import javax.cache.event.CacheEntryEvent;
+import javax.cache.event.CacheEntryListenerException;
+import javax.cache.event.CacheEntryUpdatedListener;
+import javax.cache.event.EventType;
+import javax.cache.processor.EntryProcessor;
+import javax.cache.processor.MutableEntry;
+import org.apache.ignite.IgniteBinary;
+import org.apache.ignite.IgniteCheckedException;
+import org.apache.ignite.IgniteException;
+import org.apache.ignite.binary.BinaryObject;
+import org.apache.ignite.binary.BinaryObjectBuilder;
+import org.apache.ignite.binary.BinaryObjectException;
+import org.apache.ignite.binary.BinaryType;
+import org.apache.ignite.cache.CacheEntryEventSerializableFilter;
+import org.apache.ignite.cluster.ClusterNode;
+import org.apache.ignite.cluster.ClusterTopologyException;
+import org.apache.ignite.configuration.CacheConfiguration;
+import org.apache.ignite.internal.GridKernalContext;
+import org.apache.ignite.internal.cluster.ClusterTopologyCheckedException;
+import org.apache.ignite.internal.binary.BinaryEnumObjectImpl;
+import org.apache.ignite.internal.binary.BinaryMarshaller;
+import org.apache.ignite.internal.binary.BinaryMetadata;
+import org.apache.ignite.internal.binary.BinaryMetadataHandler;
+import org.apache.ignite.internal.binary.BinaryObjectEx;
+import org.apache.ignite.internal.binary.BinaryObjectImpl;
+import org.apache.ignite.internal.binary.BinaryObjectOffheapImpl;
+import org.apache.ignite.internal.binary.BinaryTypeImpl;
+import org.apache.ignite.internal.binary.GridPortableMarshaller;
+import org.apache.ignite.internal.binary.PortableContext;
+import org.apache.ignite.internal.binary.PortableUtils;
+import org.apache.ignite.internal.binary.builder.BinaryObjectBuilderImpl;
+import org.apache.ignite.internal.binary.streams.PortableInputStream;
+import org.apache.ignite.internal.binary.streams.PortableOffheapInputStream;
+import org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion;
+import org.apache.ignite.internal.processors.cache.CacheEntryPredicate;
+import org.apache.ignite.internal.processors.cache.CacheEntryPredicateAdapter;
+import org.apache.ignite.internal.processors.cache.CacheObject;
+import org.apache.ignite.internal.processors.cache.CacheObjectContext;
+import org.apache.ignite.internal.processors.cache.CacheObjectImpl;
+import org.apache.ignite.internal.processors.cache.GridCacheContext;
+import org.apache.ignite.internal.processors.cache.GridCacheEntryEx;
+import org.apache.ignite.internal.processors.cache.GridCacheUtils;
+import org.apache.ignite.internal.processors.cache.IgniteCacheProxy;
+import org.apache.ignite.internal.processors.cache.KeyCacheObject;
+import org.apache.ignite.internal.processors.cache.query.CacheQuery;
+import org.apache.ignite.internal.processors.cache.query.CacheQueryFuture;
+import org.apache.ignite.internal.processors.cache.query.GridCacheQueryManager;
+import org.apache.ignite.internal.processors.cacheobject.IgniteCacheObjectProcessorImpl;
+import org.apache.ignite.internal.util.GridUnsafe;
+import org.apache.ignite.internal.util.IgniteUtils;
+import org.apache.ignite.internal.util.lang.GridMapEntry;
+import org.apache.ignite.internal.util.tostring.GridToStringExclude;
+import org.apache.ignite.internal.util.typedef.C1;
+import org.apache.ignite.internal.util.typedef.F;
+import org.apache.ignite.internal.util.typedef.T2;
+import org.apache.ignite.internal.util.typedef.X;
+import org.apache.ignite.internal.util.typedef.internal.CU;
+import org.apache.ignite.internal.util.typedef.internal.S;
+import org.apache.ignite.internal.util.typedef.internal.U;
+import org.apache.ignite.lang.IgniteBiPredicate;
+import org.apache.ignite.lang.IgniteBiTuple;
+import org.apache.ignite.lang.IgniteClosure;
+import org.apache.ignite.marshaller.Marshaller;
+import org.jetbrains.annotations.Nullable;
+import org.jsr166.ConcurrentHashMap8;
+import sun.misc.Unsafe;
+
+/**
+ * Portable processor implementation.
+ */
+public class CacheObjectBinaryProcessorImpl extends IgniteCacheObjectProcessorImpl implements
+    CacheObjectBinaryProcessor {
+    /** */
+    private static final Unsafe UNSAFE = GridUnsafe.unsafe();
+
+    /** */
+    private final CountDownLatch startLatch = new CountDownLatch(1);
+
+    /** */
+    private final boolean clientNode;
+
+    /** */
+    private volatile IgniteCacheProxy<PortableMetadataKey, BinaryMetadata> metaDataCache;
+
+    /** */
+    private final ConcurrentHashMap8<Integer, BinaryTypeImpl> clientMetaDataCache;
+
+    /** Predicate to filter portable meta data in utility cache. */
+    private final CacheEntryPredicate metaPred = new CacheEntryPredicateAdapter() {
+        private static final long serialVersionUID = 0L;
+
+        @Override public boolean apply(GridCacheEntryEx e) {
+            return e.key().value(e.context().cacheObjectContext(), false) instanceof PortableMetadataKey;
+        }
+    };
+
+    /** */
+    private PortableContext portableCtx;
+
+    /** */
+    private Marshaller marsh;
+
+    /** */
+    private GridPortableMarshaller portableMarsh;
+
+    /** */
+    @GridToStringExclude
+    private IgniteBinary portables;
+
+    /** Metadata updates collected before metadata cache is initialized. */
+    private final Map<Integer, BinaryMetadata> metaBuf = new ConcurrentHashMap<>();
+
+    /** */
+    private UUID metaCacheQryId;
+
+    /**
+     * @param ctx Kernal context.
+     */
+    public CacheObjectBinaryProcessorImpl(GridKernalContext ctx) {
+        super(ctx);
+
+        marsh = ctx.grid().configuration().getMarshaller();
+
+        clientNode = this.ctx.clientNode();
+
+        clientMetaDataCache = clientNode ? new ConcurrentHashMap8<Integer, BinaryTypeImpl>() : null;
+    }
+
+    /** {@inheritDoc} */
+    @Override public void start() throws IgniteCheckedException {
+        if (marsh instanceof BinaryMarshaller) {
+            BinaryMetadataHandler metaHnd = new BinaryMetadataHandler() {
+                @Override public void addMeta(int typeId, BinaryType newMeta) throws BinaryObjectException {
+                    assert newMeta != null;
+                    assert newMeta instanceof BinaryTypeImpl;
+
+                    BinaryMetadata newMeta0 = ((BinaryTypeImpl)newMeta).metadata();
+
+                    if (metaDataCache == null) {
+                        BinaryMetadata oldMeta = metaBuf.get(typeId);
+                        BinaryMetadata mergedMeta = PortableUtils.mergeMetadata(oldMeta, newMeta0);
+
+                        if (oldMeta != mergedMeta) {
+                            synchronized (this) {
+                                mergedMeta = PortableUtils.mergeMetadata(oldMeta, newMeta0);
+
+                                if (oldMeta != mergedMeta)
+                                    metaBuf.put(typeId, mergedMeta);
+                                else
+                                    return;
+                            }
+
+                            if (metaDataCache == null)
+                                return;
+                            else
+                                metaBuf.remove(typeId);
+                        }
+                        else
+                            return;
+                    }
+
+                    assert metaDataCache != null;
+
+                    CacheObjectBinaryProcessorImpl.this.addMeta(typeId, newMeta0.wrap(portableCtx));
+                }
+
+                @Override public BinaryType metadata(int typeId) throws BinaryObjectException {
+                    if (metaDataCache == null)
+                        U.awaitQuiet(startLatch);
+
+                    return CacheObjectBinaryProcessorImpl.this.metadata(typeId);
+                }
+            };
+
+            BinaryMarshaller pMarh0 = (BinaryMarshaller)marsh;
+
+            portableCtx = new PortableContext(metaHnd, ctx.config());
+
+            IgniteUtils.invoke(BinaryMarshaller.class, pMarh0, "setPortableContext", portableCtx,
+                ctx.config());
+
+            portableMarsh = new GridPortableMarshaller(portableCtx);
+
+            portables = new IgniteBinaryImpl(ctx, this);
+        }
+    }
+
+    /** {@inheritDoc} */
+    @SuppressWarnings("unchecked")
+    @Override public void onUtilityCacheStarted() throws IgniteCheckedException {
+        IgniteCacheProxy<Object, Object> proxy = ctx.cache().jcache(CU.UTILITY_CACHE_NAME);
+
+        boolean old = proxy.context().deploy().ignoreOwnership(true);
+
+        try {
+            metaDataCache = (IgniteCacheProxy)proxy.withNoRetries();
+        }
+        finally {
+            proxy.context().deploy().ignoreOwnership(old);
+        }
+
+        if (clientNode) {
+            assert !metaDataCache.context().affinityNode();
+
+            metaCacheQryId = metaDataCache.context().continuousQueries().executeInternalQuery(
+                new MetaDataEntryListener(),
+                new MetaDataEntryFilter(),
+                false,
+                true);
+
+            while (true) {
+                ClusterNode oldestSrvNode =
+                    CU.oldestAliveCacheServerNode(ctx.cache().context(), AffinityTopologyVersion.NONE);
+
+                if (oldestSrvNode == null)
+                    break;
+
+                GridCacheQueryManager qryMgr = metaDataCache.context().queries();
+
+                CacheQuery<Map.Entry<PortableMetadataKey, BinaryMetadata>> qry =
+                    qryMgr.createScanQuery(new MetaDataPredicate(), null, false);
+
+                qry.keepAll(false);
+
+                qry.projection(ctx.cluster().get().forNode(oldestSrvNode));
+
+                try {
+                    CacheQueryFuture<Map.Entry<PortableMetadataKey, BinaryMetadata>> fut = qry.execute();
+
+                    Map.Entry<PortableMetadataKey, BinaryMetadata> next;
+
+                    while ((next = fut.next()) != null) {
+                        assert next.getKey() != null : next;
+                        assert next.getValue() != null : next;
+
+                        addClientCacheMetaData(next.getKey(), next.getValue());
+                    }
+                }
+                catch (IgniteCheckedException e) {
+                    if (!ctx.discovery().alive(oldestSrvNode) || !ctx.discovery().pingNode(oldestSrvNode.id()))
+                        continue;
+                    else
+                        throw e;
+                }
+                catch (CacheException e) {
+                    if (X.hasCause(e, ClusterTopologyCheckedException.class, ClusterTopologyException.class))
+                        continue;
+                    else
+                        throw e;
+                }
+
+                break;
+            }
+        }
+
+        for (Map.Entry<Integer, BinaryMetadata> e : metaBuf.entrySet())
+            addMeta(e.getKey(), e.getValue().wrap(portableCtx));
+
+        metaBuf.clear();
+
+        startLatch.countDown();
+    }
+
+    /** {@inheritDoc} */
+    @Override public void onKernalStop(boolean cancel) {
+        super.onKernalStop(cancel);
+
+        if (metaCacheQryId != null)
+            metaDataCache.context().continuousQueries().cancelInternalQuery(metaCacheQryId);
+    }
+
+    /**
+     * @param key Metadata key.
+     * @param newMeta Metadata.
+     */
+    private void addClientCacheMetaData(PortableMetadataKey key, final BinaryMetadata newMeta) {
+        int key0 = key.typeId();
+
+        clientMetaDataCache.compute(key0, new ConcurrentHashMap8.BiFun<Integer, BinaryTypeImpl, BinaryTypeImpl>() {
+            @Override public BinaryTypeImpl apply(Integer key, BinaryTypeImpl oldMeta) {
+                BinaryMetadata res;
+
+                BinaryMetadata oldMeta0 = oldMeta != null ? oldMeta.metadata() : null;
+
+                try {
+                    res = PortableUtils.mergeMetadata(oldMeta0, newMeta);
+                }
+                catch (BinaryObjectException e) {
+                    res = oldMeta0;
+                }
+
+                return res != null ? res.wrap(portableCtx) : null;
+            }
+        });
+    }
+
+    /** {@inheritDoc} */
+    @Override public int typeId(String typeName) {
+        if (portableCtx == null)
+            return super.typeId(typeName);
+
+        return portableCtx.typeId(typeName);
+    }
+
+    /**
+     * @param obj Object.
+     * @return Bytes.
+     * @throws org.apache.ignite.binary.BinaryObjectException If failed.
+     */
+    public byte[] marshal(@Nullable Object obj) throws BinaryObjectException {
+        byte[] arr = portableMarsh.marshal(obj);
+
+        assert arr.length > 0;
+
+        return arr;
+    }
+
+    /**
+     * @param ptr Off-heap pointer.
+     * @param forceHeap If {@code true} creates heap-based object.
+     * @return Object.
+     * @throws org.apache.ignite.binary.BinaryObjectException If failed.
+     */
+    public Object unmarshal(long ptr, boolean forceHeap) throws BinaryObjectException {
+        assert ptr > 0 : ptr;
+
+        int size = UNSAFE.getInt(ptr);
+
+        ptr += 4;
+
+        byte type = UNSAFE.getByte(ptr++);
+
+        if (type != CacheObject.TYPE_BYTE_ARR) {
+            assert size > 0 : size;
+
+            PortableInputStream in = new PortableOffheapInputStream(ptr, size, forceHeap);
+
+            return portableMarsh.unmarshal(in);
+        }
+        else
+            return U.copyMemory(ptr, size);
+    }
+
+    /** {@inheritDoc} */
+    @SuppressWarnings("unchecked")
+    @Override public Object marshalToPortable(@Nullable Object obj) throws BinaryObjectException {
+        if (obj == null)
+            return null;
+
+        if (PortableUtils.isPortableType(obj.getClass()))
+            return obj;
+
+        if (obj instanceof Object[]) {
+            Object[] arr = (Object[])obj;
+
+            Object[] pArr = new Object[arr.length];
+
+            for (int i = 0; i < arr.length; i++)
+                pArr[i] = marshalToPortable(arr[i]);
+
+            return pArr;
+        }
+
+        if (obj instanceof IgniteBiTuple) {
+            IgniteBiTuple tup = (IgniteBiTuple)obj;
+
+            if (obj instanceof T2)
+                return new T2<>(marshalToPortable(tup.get1()), marshalToPortable(tup.get2()));
+
+            return new IgniteBiTuple<>(marshalToPortable(tup.get1()), marshalToPortable(tup.get2()));
+        }
+
+        if (obj instanceof Collection) {
+            Collection<Object> col = (Collection<Object>)obj;
+
+            Collection<Object> pCol;
+
+            if (col instanceof Set)
+                pCol = (Collection<Object>)PortableUtils.newSet((Set<?>)col);
+            else
+                pCol = new ArrayList<>(col.size());
+
+            for (Object item : col)
+                pCol.add(marshalToPortable(item));
+
+            return pCol;
+        }
+
+        if (obj instanceof Map) {
+            Map<?, ?> map = (Map<?, ?>)obj;
+
+            Map<Object, Object> pMap = PortableUtils.newMap((Map<Object, Object>)obj);
+
+            for (Map.Entry<?, ?> e : map.entrySet())
+                pMap.put(marshalToPortable(e.getKey()), marshalToPortable(e.getValue()));
+
+            return pMap;
+        }
+
+        if (obj instanceof Map.Entry) {
+            Map.Entry<?, ?> e = (Map.Entry<?, ?>)obj;
+
+            return new GridMapEntry<>(marshalToPortable(e.getKey()), marshalToPortable(e.getValue()));
+        }
+
+        byte[] arr = portableMarsh.marshal(obj);
+
+        assert arr.length > 0;
+
+        Object obj0 = portableMarsh.unmarshal(arr, null);
+
+        // Possible if a class has writeObject method.
+        if (obj0 instanceof BinaryObject)
+            ((BinaryObjectImpl)obj0).detachAllowed(true);
+
+        return obj0;
+    }
+
+    /**
+     * @return Marshaller.
+     */
+    public GridPortableMarshaller marshaller() {
+        return portableMarsh;
+    }
+
+    /** {@inheritDoc} */
+    @Override public BinaryObjectBuilder builder(String clsName) {
+        return new BinaryObjectBuilderImpl(portableCtx, clsName);
+    }
+
+    /** {@inheritDoc} */
+    @Override public BinaryObjectBuilder builder(BinaryObject portableObj) {
+        return BinaryObjectBuilderImpl.wrap(portableObj);
+    }
+
+    /** {@inheritDoc} */
+    @Override public void updateMetadata(int typeId, String typeName, @Nullable String affKeyFieldName,
+        Map<String, Integer> fieldTypeIds, boolean isEnum) throws BinaryObjectException {
+        BinaryMetadata meta = new BinaryMetadata(typeId, typeName, fieldTypeIds, affKeyFieldName, null, isEnum);
+
+        portableCtx.updateMetadata(typeId, meta);
+    }
+
+    /** {@inheritDoc} */
+    @Override public void addMeta(final int typeId, final BinaryType newMeta) throws BinaryObjectException {
+        assert newMeta != null;
+        assert newMeta instanceof BinaryTypeImpl;
+
+        BinaryMetadata newMeta0 = ((BinaryTypeImpl)newMeta).metadata();
+
+        final PortableMetadataKey key = new PortableMetadataKey(typeId);
+
+        try {
+            BinaryMetadata oldMeta = metaDataCache.localPeek(key);
+            BinaryMetadata mergedMeta = PortableUtils.mergeMetadata(oldMeta, newMeta0);
+
+            BinaryObjectException err = metaDataCache.invoke(key, new MetadataProcessor(mergedMeta));
+
+            if (err != null)
+                throw err;
+        }
+        catch (CacheException e) {
+            throw new BinaryObjectException("Failed to update meta data for type: " + newMeta.typeName(), e);
+        }
+    }
+
+    /** {@inheritDoc} */
+    @Nullable @Override public BinaryType metadata(final int typeId) throws BinaryObjectException {
+        try {
+            if (clientNode)
+                return clientMetaDataCache.get(typeId);
+            else {
+                PortableMetadataKey key = new PortableMetadataKey(typeId);
+
+                BinaryMetadata meta = metaDataCache.localPeek(key);
+
+                if (meta == null && !metaDataCache.context().preloader().syncFuture().isDone())
+                    meta = metaDataCache.getTopologySafe(key);
+
+                return meta != null ? meta.wrap(portableCtx) : null;
+            }
+        }
+        catch (CacheException e) {
+            throw new BinaryObjectException(e);
+        }
+    }
+
+    /** {@inheritDoc} */
+    @Override public Map<Integer, BinaryType> metadata(Collection<Integer> typeIds)
+        throws BinaryObjectException {
+        try {
+            Collection<PortableMetadataKey> keys = new ArrayList<>(typeIds.size());
+
+            for (Integer typeId : typeIds)
+                keys.add(new PortableMetadataKey(typeId));
+
+            Map<PortableMetadataKey, BinaryMetadata> meta = metaDataCache.getAll(keys);
+
+            Map<Integer, BinaryType> res = U.newHashMap(meta.size());
+
+            for (Map.Entry<PortableMetadataKey, BinaryMetadata> e : meta.entrySet())
+                res.put(e.getKey().typeId(), e.getValue().wrap(portableCtx));
+
+            return res;
+        }
+        catch (CacheException e) {
+            throw new BinaryObjectException(e);
+        }
+    }
+
+    /** {@inheritDoc} */
+    @SuppressWarnings("unchecked")
+    @Override public Collection<BinaryType> metadata() throws BinaryObjectException {
+        if (clientNode)
+            return F.viewReadOnly(clientMetaDataCache.values(), new IgniteClosure<BinaryTypeImpl, BinaryType>() {
+                @Override public BinaryType apply(BinaryTypeImpl meta) {
+                    return meta;
+                }
+            });
+        else {
+            return F.viewReadOnly(metaDataCache.entrySetx(metaPred),
+                new C1<Cache.Entry<PortableMetadataKey, BinaryMetadata>, BinaryType>() {
+                    private static final long serialVersionUID = 0L;
+
+                    @Override public BinaryType apply(Cache.Entry<PortableMetadataKey, BinaryMetadata> e) {
+                        return e.getValue().wrap(portableCtx);
+                    }
+                });
+        }
+    }
+
+    /** {@inheritDoc} */
+    @Override public BinaryObject buildEnum(String typeName, int ord) throws IgniteException {
+        typeName = PortableContext.typeName(typeName);
+
+        int typeId = portableCtx.typeId(typeName);
+
+        updateMetadata(typeId, typeName, null, null, true);
+
+        return new BinaryEnumObjectImpl(portableCtx, typeId, null, ord);
+    }
+
+    /** {@inheritDoc} */
+    @Override public IgniteBinary binary() throws IgniteException {
+        return portables;
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean isPortableObject(Object obj) {
+        return obj instanceof BinaryObject;
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean isPortableEnabled(CacheConfiguration<?, ?> ccfg) {
+        return marsh instanceof BinaryMarshaller;
+    }
+
+    /**
+     * @param po Portable object.
+     * @return Affinity key.
+     */
+    public Object affinityKey(BinaryObject po) {
+        try {
+            BinaryType meta = po.type();
+
+            if (meta != null) {
+                String affKeyFieldName = meta.affinityKeyFieldName();
+
+                if (affKeyFieldName != null)
+                    return po.field(affKeyFieldName);
+            }
+            else if (po instanceof BinaryObjectEx) {
+                int id = ((BinaryObjectEx)po).typeId();
+
+                String affKeyFieldName = portableCtx.affinityKeyFieldName(id);
+
+                if (affKeyFieldName != null)
+                    return po.field(affKeyFieldName);
+            }
+        }
+        catch (BinaryObjectException e) {
+            U.error(log, "Failed to get affinity field from portable object: " + po, e);
+        }
+
+        return po;
+    }
+
+    /** {@inheritDoc} */
+    @Override public int typeId(Object obj) {
+        if (obj == null)
+            return 0;
+
+        return isPortableObject(obj) ? ((BinaryObjectEx)obj).typeId() : typeId(obj.getClass().getSimpleName());
+    }
+
+    /** {@inheritDoc} */
+    @Override public Object field(Object obj, String fieldName) {
+        if (obj == null)
+            return null;
+
+        return isPortableObject(obj) ? ((BinaryObject)obj).field(fieldName) : super.field(obj, fieldName);
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean hasField(Object obj, String fieldName) {
+        return obj != null && ((BinaryObject)obj).hasField(fieldName);
+    }
+
+    /**
+     * @return Portable context.
+     */
+    public PortableContext portableContext() {
+        return portableCtx;
+    }
+
+    /** {@inheritDoc} */
+    @Override public CacheObjectContext contextForCache(CacheConfiguration cfg) throws IgniteCheckedException {
+        assert cfg != null;
+
+        boolean portableEnabled = marsh instanceof BinaryMarshaller && !GridCacheUtils.isSystemCache(cfg.getName()) &&
+            !GridCacheUtils.isIgfsCache(ctx.config(), cfg.getName());
+
+        CacheObjectContext ctx0 = super.contextForCache(cfg);
+
+        CacheObjectContext res = new CacheObjectPortableContext(ctx,
+            ctx0.copyOnGet(),
+            ctx0.storeValue(),
+            portableEnabled,
+            ctx0.addDeploymentInfo());
+
+        ctx.resource().injectGeneric(res.defaultAffMapper());
+
+        return res;
+    }
+
+    /** {@inheritDoc} */
+    @Override public byte[] marshal(CacheObjectContext ctx, Object val) throws IgniteCheckedException {
+        if (!((CacheObjectPortableContext)ctx).portableEnabled() || portableMarsh == null)
+            return super.marshal(ctx, val);
+
+        byte[] arr = portableMarsh.marshal(val);
+
+        assert arr.length > 0;
+
+        return arr;
+    }
+
+    /** {@inheritDoc} */
+    @Override public Object unmarshal(CacheObjectContext ctx, byte[] bytes, ClassLoader clsLdr)
+        throws IgniteCheckedException {
+        if (!((CacheObjectPortableContext)ctx).portableEnabled() || portableMarsh == null)
+            return super.unmarshal(ctx, bytes, clsLdr);
+
+        return portableMarsh.unmarshal(bytes, clsLdr);
+    }
+
+    /** {@inheritDoc} */
+    @Override public KeyCacheObject toCacheKeyObject(CacheObjectContext ctx, Object obj, boolean userObj) {
+        if (!((CacheObjectPortableContext)ctx).portableEnabled())
+            return super.toCacheKeyObject(ctx, obj, userObj);
+
+        if (obj instanceof KeyCacheObject)
+            return (KeyCacheObject)obj;
+
+        if (((CacheObjectPortableContext)ctx).portableEnabled()) {
+            obj = toPortable(obj);
+
+            if (obj instanceof BinaryObject)
+                return (BinaryObjectImpl)obj;
+        }
+
+        return toCacheKeyObject0(obj, userObj);
+    }
+
+    /** {@inheritDoc} */
+    @Nullable @Override public CacheObject toCacheObject(CacheObjectContext ctx, @Nullable Object obj,
+        boolean userObj) {
+        if (!((CacheObjectPortableContext)ctx).portableEnabled())
+            return super.toCacheObject(ctx, obj, userObj);
+
+        if (obj == null || obj instanceof CacheObject)
+            return (CacheObject)obj;
+
+        obj = toPortable(obj);
+
+        if (obj instanceof BinaryObject)
+            return (BinaryObjectImpl)obj;
+
+        return toCacheObject0(obj, userObj);
+    }
+
+    /** {@inheritDoc} */
+    @Override public CacheObject toCacheObject(CacheObjectContext ctx, byte type, byte[] bytes) {
+        if (type == BinaryObjectImpl.TYPE_BINARY)
+            return new BinaryObjectImpl(portableContext(), bytes, 0);
+
+        return super.toCacheObject(ctx, type, bytes);
+    }
+
+    /** {@inheritDoc} */
+    @Override public CacheObject toCacheObject(GridCacheContext ctx, long valPtr, boolean tmp)
+        throws IgniteCheckedException {
+        if (!((CacheObjectPortableContext)ctx.cacheObjectContext()).portableEnabled())
+            return super.toCacheObject(ctx, valPtr, tmp);
+
+        Object val = unmarshal(valPtr, !tmp);
+
+        if (val instanceof BinaryObjectOffheapImpl)
+            return (BinaryObjectOffheapImpl)val;
+
+        return new CacheObjectImpl(val, null);
+    }
+
+    /** {@inheritDoc} */
+    @Override public Object unwrapTemporary(GridCacheContext ctx, Object obj) throws BinaryObjectException {
+        if (!((CacheObjectPortableContext)ctx.cacheObjectContext()).portableEnabled())
+            return obj;
+
+        if (obj instanceof BinaryObjectOffheapImpl)
+            return ((BinaryObjectOffheapImpl)obj).heapCopy();
+
+        return obj;
+    }
+
+    /**
+     * @param obj Object.
+     * @return Portable object.
+     * @throws IgniteException In case of error.
+     */
+    @Nullable public Object toPortable(@Nullable Object obj) throws IgniteException {
+        if (obj == null)
+            return null;
+
+        if (isPortableObject(obj))
+            return obj;
+
+        return marshalToPortable(obj);
+    }
+
+    /**
+     * Processor responsible for metadata update.
+     */
+    private static class MetadataProcessor
+        implements EntryProcessor<PortableMetadataKey, BinaryMetadata, BinaryObjectException>, Externalizable {
+        /** */
+        private static final long serialVersionUID = 0L;
+
+        /** */
+        private BinaryMetadata newMeta;
+
+        /**
+         * For {@link Externalizable}.
+         */
+        public MetadataProcessor() {
+            // No-op.
+        }
+
+        /**
+         * @param newMeta New metadata.
+         */
+        private MetadataProcessor(BinaryMetadata newMeta) {
+            assert newMeta != null;
+
+            this.newMeta = newMeta;
+        }
+
+        /** {@inheritDoc} */
+        @Override public BinaryObjectException process(MutableEntry<PortableMetadataKey, BinaryMetadata> entry,
+            Object... args) {
+            try {
+                BinaryMetadata oldMeta = entry.getValue();
+
+                BinaryMetadata mergedMeta = PortableUtils.mergeMetadata(oldMeta, newMeta);
+
+                if (mergedMeta != oldMeta)
+                    entry.setValue(mergedMeta);
+
+                return null;
+            }
+            catch (BinaryObjectException e) {
+                return e;
+            }
+        }
+
+        /** {@inheritDoc} */
+        @Override public void writeExternal(ObjectOutput out) throws IOException {
+            out.writeObject(newMeta);
+        }
+
+        /** {@inheritDoc} */
+        @Override public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
+            newMeta = (BinaryMetadata)in.readObject();
+        }
+
+        /** {@inheritDoc} */
+        @Override public String toString() {
+            return S.toString(MetadataProcessor.class, this);
+        }
+    }
+
+    /**
+     *
+     */
+    class MetaDataEntryListener implements CacheEntryUpdatedListener<PortableMetadataKey, BinaryMetadata> {
+        /** {@inheritDoc} */
+        @Override public void onUpdated(
+            Iterable<CacheEntryEvent<? extends PortableMetadataKey, ? extends BinaryMetadata>> evts)
+            throws CacheEntryListenerException {
+            for (CacheEntryEvent<? extends PortableMetadataKey, ? extends BinaryMetadata> evt : evts) {
+                assert evt.getEventType() == EventType.CREATED || evt.getEventType() == EventType.UPDATED : evt;
+
+                PortableMetadataKey key = evt.getKey();
+
+                final BinaryMetadata newMeta = evt.getValue();
+
+                assert newMeta != null : evt;
+
+                addClientCacheMetaData(key, newMeta);
+            }
+        }
+
+        /** {@inheritDoc} */
+        @Override public String toString() {
+            return S.toString(MetaDataEntryListener.class, this);
+        }
+    }
+
+    /**
+     *
+     */
+    static class MetaDataEntryFilter implements CacheEntryEventSerializableFilter<Object, Object> {
+        /** */
+        private static final long serialVersionUID = 0L;
+
+        /** {@inheritDoc} */
+        @Override public boolean evaluate(CacheEntryEvent<?, ?> evt) throws CacheEntryListenerException {
+            return evt.getKey() instanceof PortableMetadataKey;
+        }
+
+        /** {@inheritDoc} */
+        @Override public String toString() {
+            return S.toString(MetaDataEntryFilter.class, this);
+        }
+    }
+
+    /**
+     *
+     */
+    static class MetaDataPredicate implements IgniteBiPredicate<Object, Object> {
+        /** */
+        private static final long serialVersionUID = 0L;
+
+        /** {@inheritDoc} */
+        @Override public boolean apply(Object key, Object val) {
+            return key instanceof PortableMetadataKey;
+        }
+
+        /** {@inheritDoc} */
+        @Override public String toString() {
+            return S.toString(MetaDataPredicate.class, this);
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/1dbf20e0/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/binary/CacheObjectPortableContext.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/binary/CacheObjectPortableContext.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/binary/CacheObjectPortableContext.java
new file mode 100644
index 0000000..c2b5261
--- /dev/null
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/binary/CacheObjectPortableContext.java
@@ -0,0 +1,56 @@
+/*
+ * 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.processors.cache.binary;
+
+import org.apache.ignite.internal.GridKernalContext;
+import org.apache.ignite.internal.processors.cache.CacheDefaultBinaryAffinityKeyMapper;
+import org.apache.ignite.internal.processors.cache.CacheObjectContext;
+import org.apache.ignite.internal.processors.cache.GridCacheDefaultAffinityKeyMapper;
+
+/**
+ *
+ */
+public class CacheObjectPortableContext extends CacheObjectContext {
+    /** */
+    private boolean portableEnabled;
+
+    /**
+     * @param kernalCtx Kernal context.
+     * @param portableEnabled Portable enabled flag.
+     * @param cpyOnGet Copy on get flag.
+     * @param storeVal {@code True} if should store unmarshalled value in cache.
+     * @param depEnabled {@code true} if deployment is enabled for the given cache.
+     */
+    public CacheObjectPortableContext(GridKernalContext kernalCtx,
+        boolean cpyOnGet,
+        boolean storeVal,
+        boolean portableEnabled,
+        boolean depEnabled) {
+        super(kernalCtx, portableEnabled ? new CacheDefaultBinaryAffinityKeyMapper() :
+            new GridCacheDefaultAffinityKeyMapper(), cpyOnGet, storeVal, depEnabled);
+
+        this.portableEnabled = portableEnabled;
+    }
+
+    /**
+     * @return Portable enabled flag.
+     */
+    public boolean portableEnabled() {
+        return portableEnabled;
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/1dbf20e0/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/binary/IgniteBinaryImpl.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/binary/IgniteBinaryImpl.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/binary/IgniteBinaryImpl.java
new file mode 100644
index 0000000..4a225a5
--- /dev/null
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/binary/IgniteBinaryImpl.java
@@ -0,0 +1,178 @@
+/*
+ * 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.processors.cache.binary;
+
+import java.util.Collection;
+import org.apache.ignite.IgniteBinary;
+import org.apache.ignite.internal.GridKernalContext;
+import org.apache.ignite.internal.processors.cacheobject.IgniteCacheObjectProcessor;
+import org.apache.ignite.binary.BinaryObjectBuilder;
+import org.apache.ignite.binary.BinaryObjectException;
+import org.apache.ignite.binary.BinaryType;
+import org.apache.ignite.binary.BinaryObject;
+import org.jetbrains.annotations.Nullable;
+
+/**
+ * {@link org.apache.ignite.IgniteBinary} implementation.
+ */
+public class IgniteBinaryImpl implements IgniteBinary {
+    /** */
+    private GridKernalContext ctx;
+
+    /** */
+    private CacheObjectBinaryProcessor proc;
+
+    /**
+     * @param ctx Context.
+     */
+    public IgniteBinaryImpl(GridKernalContext ctx, CacheObjectBinaryProcessor proc) {
+        this.ctx = ctx;
+
+        this.proc = proc;
+    }
+
+    /** {@inheritDoc} */
+    @Override public int typeId(String typeName) {
+        guard();
+
+        try {
+            return proc.typeId(typeName);
+        }
+        finally {
+            unguard();
+        }
+    }
+
+    /** {@inheritDoc} */
+    @SuppressWarnings("unchecked")
+    @Override public <T> T toBinary(@Nullable Object obj) throws BinaryObjectException {
+        guard();
+
+        try {
+            return (T)proc.marshalToPortable(obj);
+        }
+        finally {
+            unguard();
+        }
+    }
+
+    /** {@inheritDoc} */
+    @Override public BinaryObjectBuilder builder(String typeName) {
+        guard();
+
+        try {
+            return proc.builder(typeName);
+        }
+        finally {
+            unguard();
+        }
+    }
+
+    /** {@inheritDoc} */
+    @Override public BinaryObjectBuilder builder(BinaryObject portableObj) {
+        guard();
+
+        try {
+            return proc.builder(portableObj);
+        }
+        finally {
+            unguard();
+        }
+    }
+
+    /** {@inheritDoc} */
+    @Nullable @Override public BinaryType type(Class<?> cls) throws BinaryObjectException {
+        guard();
+
+        try {
+            return proc.metadata(proc.typeId(cls.getName()));
+        }
+        finally {
+            unguard();
+        }
+    }
+
+    /** {@inheritDoc} */
+    @Nullable @Override public BinaryType type(String typeName) throws BinaryObjectException {
+        guard();
+
+        try {
+            return proc.metadata(proc.typeId(typeName));
+        }
+        finally {
+            unguard();
+        }
+    }
+
+    /** {@inheritDoc} */
+    @Nullable @Override public BinaryType type(int typeId) throws BinaryObjectException {
+        guard();
+
+        try {
+            return proc.metadata(typeId);
+        }
+        finally {
+            unguard();
+        }
+    }
+
+    /** {@inheritDoc} */
+    @Override public Collection<BinaryType> types() throws BinaryObjectException {
+        guard();
+
+        try {
+            return proc.metadata();
+        }
+        finally {
+            unguard();
+        }
+    }
+
+    /** {@inheritDoc} */
+    @Override public BinaryObject buildEnum(String typeName, int ord) {
+        guard();
+
+        try {
+            return proc.buildEnum(typeName, ord);
+        }
+        finally {
+            unguard();
+        }
+    }
+
+    /**
+     * @return Portable processor.
+     */
+    public IgniteCacheObjectProcessor processor() {
+        return proc;
+    }
+
+    /**
+     * <tt>ctx.gateway().readLock()</tt>
+     */
+    private void guard() {
+        ctx.gateway().readLock();
+    }
+
+    /**
+     * <tt>ctx.gateway().readUnlock()</tt>
+     */
+    private void unguard() {
+        ctx.gateway().readUnlock();
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/1dbf20e0/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/binary/PortableMetadataKey.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/binary/PortableMetadataKey.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/binary/PortableMetadataKey.java
new file mode 100644
index 0000000..3b0ce8e
--- /dev/null
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/binary/PortableMetadataKey.java
@@ -0,0 +1,82 @@
+/*
+ * 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.processors.cache.binary;
+
+import java.io.Externalizable;
+import java.io.IOException;
+import java.io.ObjectInput;
+import java.io.ObjectOutput;
+import org.apache.ignite.internal.processors.cache.GridCacheUtilityKey;
+import org.apache.ignite.internal.util.typedef.internal.S;
+
+/**
+ * Key for portable meta data.
+ */
+class PortableMetadataKey extends GridCacheUtilityKey<PortableMetadataKey> implements Externalizable {
+    /** */
+    private static final long serialVersionUID = 0L;
+
+    /** */
+    private int typeId;
+
+    /**
+     * For {@link Externalizable}.
+     */
+    public PortableMetadataKey() {
+        // No-op.
+    }
+
+    /**
+     * @param typeId Type ID.
+     */
+    PortableMetadataKey(int typeId) {
+        this.typeId = typeId;
+    }
+
+    /**
+     * @return Type id.
+     */
+    public int typeId() {
+        return typeId;
+    }
+
+    /** {@inheritDoc} */
+    @Override public void writeExternal(ObjectOutput out) throws IOException {
+        out.writeInt(typeId);
+    }
+
+    /** {@inheritDoc} */
+    @Override public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
+        typeId = in.readInt();
+    }
+
+    /** {@inheritDoc} */
+    @Override protected boolean equalsx(PortableMetadataKey key) {
+        return typeId == key.typeId;
+    }
+
+    /** {@inheritDoc} */
+    @Override public int hashCode() {
+        return typeId;
+    }
+
+    /** {@inheritDoc} */
+    @Override public String toString() {
+        return S.toString(PortableMetadataKey.class, this);
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/1dbf20e0/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/binary/package-info.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/binary/package-info.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/binary/package-info.java
new file mode 100644
index 0000000..b0e5c2f
--- /dev/null
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/binary/package-info.java
@@ -0,0 +1,22 @@
+/*
+ * 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 description. -->
+ * Implementation of portable processor.
+ */
+package org.apache.ignite.internal.processors.cache.binary;

http://git-wip-us.apache.org/repos/asf/ignite/blob/1dbf20e0/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/portable/CacheDefaultPortableAffinityKeyMapper.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/portable/CacheDefaultPortableAffinityKeyMapper.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/portable/CacheDefaultPortableAffinityKeyMapper.java
deleted file mode 100644
index 1a2ef7b..0000000
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/portable/CacheDefaultPortableAffinityKeyMapper.java
+++ /dev/null
@@ -1,51 +0,0 @@
-/*
- * 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.processors.cache.portable;
-
-import org.apache.ignite.IgniteException;
-import org.apache.ignite.internal.IgniteKernal;
-import org.apache.ignite.internal.processors.cache.GridCacheDefaultAffinityKeyMapper;
-import org.apache.ignite.internal.util.typedef.internal.U;
-import org.apache.ignite.binary.BinaryObject;
-
-/**
- *
- */
-public class CacheDefaultPortableAffinityKeyMapper extends GridCacheDefaultAffinityKeyMapper {
-    /** */
-    private static final long serialVersionUID = 0L;
-
-    /** {@inheritDoc} */
-    @Override public Object affinityKey(Object key) {
-        IgniteKernal kernal = (IgniteKernal)ignite;
-
-        CacheObjectBinaryProcessorImpl proc = (CacheObjectBinaryProcessorImpl)kernal.context().cacheObjects();
-
-        try {
-            key = proc.toPortable(key);
-        }
-        catch (IgniteException e) {
-            U.error(log, "Failed to marshal key to portable: " + key, e);
-        }
-
-        if (key instanceof BinaryObject)
-            return proc.affinityKey((BinaryObject)key);
-        else
-            return super.affinityKey(key);
-    }
-}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ignite/blob/1dbf20e0/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/portable/CacheObjectBinaryProcessor.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/portable/CacheObjectBinaryProcessor.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/portable/CacheObjectBinaryProcessor.java
deleted file mode 100644
index 7ef4b91..0000000
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/portable/CacheObjectBinaryProcessor.java
+++ /dev/null
@@ -1,106 +0,0 @@
-/*
- * 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.processors.cache.portable;
-
-import java.util.Collection;
-import java.util.Map;
-import org.apache.ignite.IgniteException;
-import org.apache.ignite.IgniteBinary;
-import org.apache.ignite.internal.processors.cacheobject.IgniteCacheObjectProcessor;
-import org.apache.ignite.binary.BinaryObjectBuilder;
-import org.apache.ignite.binary.BinaryType;
-import org.apache.ignite.binary.BinaryObject;
-import org.jetbrains.annotations.Nullable;
-
-/**
- * Extended cache object processor interface with additional methods for binary.
- */
-public interface CacheObjectBinaryProcessor extends IgniteCacheObjectProcessor {
-    /**
-     * @param clsName Class name.
-     * @return Builder.
-     */
-    public BinaryObjectBuilder builder(String clsName);
-
-    /**
-     * Creates builder initialized by existing portable object.
-     *
-     * @param portableObj Portable object to edit.
-     * @return Portable builder.
-     */
-    public BinaryObjectBuilder builder(BinaryObject portableObj);
-
-    /**
-     * @param typeId Type ID.
-     * @param newMeta New meta data.
-     * @throws IgniteException In case of error.
-     */
-    public void addMeta(int typeId, final BinaryType newMeta) throws IgniteException;
-
-    /**
-     * @param typeId Type ID.
-     * @param typeName Type name.
-     * @param affKeyFieldName Affinity key field name.
-     * @param fieldTypeIds Fields map.
-     * @param isEnum Enum flag.
-     * @throws IgniteException In case of error.
-     */
-    public void updateMetadata(int typeId, String typeName, @Nullable String affKeyFieldName,
-        Map<String, Integer> fieldTypeIds, boolean isEnum) throws IgniteException;
-
-    /**
-     * @param typeId Type ID.
-     * @return Meta data.
-     * @throws IgniteException In case of error.
-     */
-    @Nullable public BinaryType metadata(int typeId) throws IgniteException;
-
-    /**
-     * @param typeIds Type ID.
-     * @return Meta data.
-     * @throws IgniteException In case of error.
-     */
-    public Map<Integer, BinaryType> metadata(Collection<Integer> typeIds) throws IgniteException;
-
-    /**
-     * @return Metadata for all types.
-     * @throws IgniteException In case of error.
-     */
-    public Collection<BinaryType> metadata() throws IgniteException;
-
-    /**
-     * @param typeName Type name.
-     * @param ord ordinal.
-     * @return Enum object.
-     * @throws IgniteException If failed.
-     */
-    public BinaryObject buildEnum(String typeName, int ord) throws IgniteException;
-
-    /**
-     * @return Portables interface.
-     * @throws IgniteException If failed.
-     */
-    public IgniteBinary binary() throws IgniteException;
-
-    /**
-     * @param obj Original object.
-     * @return Portable object (in case portable marshaller is used).
-     * @throws IgniteException If failed.
-     */
-    public Object marshalToPortable(Object obj) throws IgniteException;
-}
\ No newline at end of file


[39/59] [abbrv] ignite git commit: IGNITE-2124 - Fixed key deserialization on server node. - Fixes #313.

Posted by ak...@apache.org.
IGNITE-2124 - Fixed key deserialization on server node. - Fixes #313.

Signed-off-by: Alexey Goncharuk <al...@gmail.com>


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

Branch: refs/heads/ignite-843-rc2
Commit: 9a02acbe5bc1deeefe1b79063c6938984a25baae
Parents: 91760b9
Author: Alexey Goncharuk <al...@gmail.com>
Authored: Fri Dec 11 16:11:32 2015 +0300
Committer: Alexey Goncharuk <al...@gmail.com>
Committed: Fri Dec 11 16:11:32 2015 +0300

----------------------------------------------------------------------
 .../org/apache/ignite/cache/QueryEntity.java    |   3 +-
 .../CacheDataStructuresManager.java             |   5 +
 .../processors/query/GridQueryProcessor.java    |  21 +-
 .../apache/ignite/tests/p2p/cache/Person.java   |  77 ++++++
 .../ignite/tests/p2p/cache/PersonKey.java       |  74 ++++++
 .../IgniteBinaryObjectFieldsQuerySelfTest.java  | 246 +++++++++++++++++++
 .../IgnitePortableCacheQueryTestSuite.java      |   2 +
 7 files changed, 426 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/9a02acbe/modules/core/src/main/java/org/apache/ignite/cache/QueryEntity.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/cache/QueryEntity.java b/modules/core/src/main/java/org/apache/ignite/cache/QueryEntity.java
index cb84c47..7901bec 100644
--- a/modules/core/src/main/java/org/apache/ignite/cache/QueryEntity.java
+++ b/modules/core/src/main/java/org/apache/ignite/cache/QueryEntity.java
@@ -14,6 +14,7 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
+
 package org.apache.ignite.cache;
 
 import java.io.Serializable;
@@ -124,7 +125,7 @@ public class QueryEntity implements Serializable {
     /**
      * Sets mapping from full property name in dot notation to an alias that will be used as SQL column name.
      * Example: {"parent.name" -> "parentName"}.
-
+     *
      * @param aliases Aliases map.
      */
     public void setAliases(Map<String, String> aliases) {

http://git-wip-us.apache.org/repos/asf/ignite/blob/9a02acbe/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/datastructures/CacheDataStructuresManager.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/datastructures/CacheDataStructuresManager.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/datastructures/CacheDataStructuresManager.java
index 6ec29b4..6447194 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/datastructures/CacheDataStructuresManager.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/datastructures/CacheDataStructuresManager.java
@@ -314,6 +314,11 @@ public class CacheDataStructuresManager extends GridCacheManagerAdapter {
      * @param keepPortable Keep portable flag.
      */
     public void onEntryUpdated(KeyCacheObject key, boolean rmv, boolean keepPortable) {
+        // No need to notify data structures manager for a user cache since all DS objects are stored
+        // in system caches.
+        if (cctx.userCache())
+            return;
+
         Object key0 = cctx.cacheObjectContext().unwrapPortableIfNeeded(key, keepPortable, false);
 
         if (key0 instanceof SetItemKey)

http://git-wip-us.apache.org/repos/asf/ignite/blob/9a02acbe/modules/core/src/main/java/org/apache/ignite/internal/processors/query/GridQueryProcessor.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/query/GridQueryProcessor.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/query/GridQueryProcessor.java
index 64f2415..005f617 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/query/GridQueryProcessor.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/query/GridQueryProcessor.java
@@ -205,7 +205,7 @@ public class GridQueryProcessor extends GridProcessorAdapter {
                     Class<?> keyCls = U.classForName(qryEntity.getKeyType(), Object.class);
                     Class<?> valCls = U.classForName(qryEntity.getValueType(), null);
 
-                    String simpleValType = valCls == null ? qryEntity.getValueType() : typeName(valCls);
+                    String simpleValType = valCls == null ? typeName(qryEntity.getValueType()) : typeName(valCls);
 
                     desc.name(simpleValType);
 
@@ -982,6 +982,25 @@ public class GridQueryProcessor extends GridProcessorAdapter {
     }
 
     /**
+     * Gets type name by class.
+     *
+     * @param clsName Class name.
+     * @return Type name.
+     */
+    public static String typeName(String clsName) {
+        int packageEnd = clsName.lastIndexOf('.');
+
+        if (packageEnd >= 0 && packageEnd < clsName.length() - 1)
+            clsName = clsName.substring(packageEnd + 1);
+
+        if (clsName.endsWith("[]")) {
+            clsName = clsName.substring(0, clsName.length() - 2) + "_array";
+        }
+
+        return clsName;
+    }
+
+    /**
      * @param space Space.
      * @param clause Clause.
      * @param resType Result type.

http://git-wip-us.apache.org/repos/asf/ignite/blob/9a02acbe/modules/extdata/p2p/src/main/java/org/apache/ignite/tests/p2p/cache/Person.java
----------------------------------------------------------------------
diff --git a/modules/extdata/p2p/src/main/java/org/apache/ignite/tests/p2p/cache/Person.java b/modules/extdata/p2p/src/main/java/org/apache/ignite/tests/p2p/cache/Person.java
index 3452cea..7cb7dd2 100644
--- a/modules/extdata/p2p/src/main/java/org/apache/ignite/tests/p2p/cache/Person.java
+++ b/modules/extdata/p2p/src/main/java/org/apache/ignite/tests/p2p/cache/Person.java
@@ -18,14 +18,35 @@
 package org.apache.ignite.tests.p2p.cache;
 
 import java.io.Serializable;
+import org.apache.ignite.cache.query.annotations.QuerySqlField;
 
 /**
  *
  */
 public class Person implements Serializable {
     /** */
+    @QuerySqlField
     private String name;
 
+    /** */
+    @QuerySqlField(index = true)
+    private int id;
+
+    /** */
+    @QuerySqlField
+    private String lastName;
+
+    /** */
+    @QuerySqlField
+    private double salary;
+
+    /**
+     *
+     */
+    public Person() {
+        // No-op.
+    }
+
     /**
      * @param name Name.
      */
@@ -39,4 +60,60 @@ public class Person implements Serializable {
     public String name() {
         return name;
     }
+
+    /**
+     * @return Name.
+     */
+    public String getName() {
+        return name;
+    }
+
+    /**
+     * @param name Name.
+     */
+    public void setName(String name) {
+        this.name = name;
+    }
+
+    /**
+     * @return ID.
+     */
+    public int getId() {
+        return id;
+    }
+
+    /**
+     * @param id ID.
+     */
+    public void setId(int id) {
+        this.id = id;
+    }
+
+    /**
+     * @return Last name.
+     */
+    public String getLastName() {
+        return lastName;
+    }
+
+    /**
+     * @param lastName Last name.
+     */
+    public void setLastName(String lastName) {
+        this.lastName = lastName;
+    }
+
+    /**
+     * @return Salary.
+     */
+    public double getSalary() {
+        return salary;
+    }
+
+    /**
+     * @param salary Salary.
+     */
+    public void setSalary(double salary) {
+        this.salary = salary;
+    }
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ignite/blob/9a02acbe/modules/extdata/p2p/src/main/java/org/apache/ignite/tests/p2p/cache/PersonKey.java
----------------------------------------------------------------------
diff --git a/modules/extdata/p2p/src/main/java/org/apache/ignite/tests/p2p/cache/PersonKey.java b/modules/extdata/p2p/src/main/java/org/apache/ignite/tests/p2p/cache/PersonKey.java
new file mode 100644
index 0000000..3233f9b
--- /dev/null
+++ b/modules/extdata/p2p/src/main/java/org/apache/ignite/tests/p2p/cache/PersonKey.java
@@ -0,0 +1,74 @@
+/*
+ * 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.tests.p2p.cache;
+
+import java.io.Serializable;
+
+/**
+ * Person key.
+ */
+public class PersonKey implements Serializable {
+    /** */
+    private int id;
+
+    /**
+     * Empty constructor for tests.
+     */
+    public PersonKey() {
+        // No-op.
+    }
+
+    /**
+     * @param id ID.
+     */
+    public PersonKey(int id) {
+        this.id = id;
+    }
+
+    /**
+     * @return ID.
+     */
+    public int id() {
+        return id;
+    }
+
+    /**
+     * @param id ID.
+     */
+    public void id(int id) {
+        this.id = id;
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean equals(Object o) {
+        if (this == o)
+            return true;
+
+        if (!(o instanceof PersonKey))
+            return false;
+
+        PersonKey key = (PersonKey)o;
+
+        return id == key.id;
+    }
+
+    /** {@inheritDoc} */
+    @Override public int hashCode() {
+        return id;
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/9a02acbe/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/IgniteBinaryObjectFieldsQuerySelfTest.java
----------------------------------------------------------------------
diff --git a/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/IgniteBinaryObjectFieldsQuerySelfTest.java b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/IgniteBinaryObjectFieldsQuerySelfTest.java
new file mode 100644
index 0000000..3a08824
--- /dev/null
+++ b/modules/indexing/src/test/java/org/apache/ignite/internal/processors/cache/IgniteBinaryObjectFieldsQuerySelfTest.java
@@ -0,0 +1,246 @@
+/*
+ * 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.processors.cache;
+
+import java.util.List;
+import javax.cache.Cache;
+import org.apache.ignite.IgniteCache;
+import org.apache.ignite.cache.CacheAtomicityMode;
+import org.apache.ignite.cache.CacheMode;
+import org.apache.ignite.cache.CacheRebalanceMode;
+import org.apache.ignite.cache.CacheWriteSynchronizationMode;
+import org.apache.ignite.cache.query.QueryCursor;
+import org.apache.ignite.cache.query.SqlFieldsQuery;
+import org.apache.ignite.cache.query.SqlQuery;
+import org.apache.ignite.configuration.CacheConfiguration;
+import org.apache.ignite.configuration.IgniteConfiguration;
+import org.apache.ignite.internal.util.typedef.internal.U;
+import org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi;
+import org.apache.ignite.spi.discovery.tcp.ipfinder.TcpDiscoveryIpFinder;
+import org.apache.ignite.spi.discovery.tcp.ipfinder.vm.TcpDiscoveryVmIpFinder;
+import org.apache.ignite.testframework.GridTestUtils;
+import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
+
+/**
+ * Tests that server nodes do not need class definitions to execute queries.
+ */
+public class IgniteBinaryObjectFieldsQuerySelfTest extends GridCommonAbstractTest {
+    /** */
+    public static final String PERSON_KEY_CLS_NAME = "org.apache.ignite.tests.p2p.cache.PersonKey";
+
+    /** */
+    public static final String PERSON_CLS_NAME = "org.apache.ignite.tests.p2p.cache.Person";
+
+    /** IP finder. */
+    private static final TcpDiscoveryIpFinder IP_FINDER = new TcpDiscoveryVmIpFinder(true);
+
+    /** */
+    private static ClassLoader extClassLoader;
+
+    /** {@inheritDoc} */
+    @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception {
+        IgniteConfiguration cfg = super.getConfiguration(gridName);
+
+        cfg.setPeerClassLoadingEnabled(false);
+
+        TcpDiscoverySpi discoSpi = new TcpDiscoverySpi();
+
+        discoSpi.setIpFinder(IP_FINDER);
+
+        cfg.setDiscoverySpi(discoSpi);
+
+        cfg.setMarshaller(null);
+
+        if (getTestGridName(3).equals(gridName)) {
+            cfg.setClientMode(true);
+            cfg.setClassLoader(extClassLoader);
+        }
+
+        return cfg;
+    }
+
+    /**
+     * @return Cache.
+     */
+    protected CacheConfiguration cache(CacheMode cacheMode, CacheAtomicityMode atomicity) throws Exception {
+        CacheConfiguration cache = defaultCacheConfiguration();
+
+        cache.setName(null);
+        cache.setWriteSynchronizationMode(CacheWriteSynchronizationMode.FULL_SYNC);
+        cache.setRebalanceMode(CacheRebalanceMode.SYNC);
+        cache.setCacheMode(cacheMode);
+        cache.setAtomicityMode(atomicity);
+
+        cache.setIndexedTypes(extClassLoader.loadClass(PERSON_KEY_CLS_NAME), extClassLoader.loadClass(PERSON_CLS_NAME));
+
+        return cache;
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void beforeTestsStarted() throws Exception {
+        extClassLoader = getExternalClassLoader();
+
+        startGrids(4);
+
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void afterTestsStopped() throws Exception {
+        stopAllGrids();
+
+        extClassLoader = null;
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testQueryPartitionedAtomic() throws Exception {
+        checkQuery(CacheMode.PARTITIONED, CacheAtomicityMode.ATOMIC);
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testQueryReplicatedAtomic() throws Exception {
+        checkQuery(CacheMode.REPLICATED, CacheAtomicityMode.ATOMIC);
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testQueryPartitionedTransactional() throws Exception {
+        checkQuery(CacheMode.PARTITIONED, CacheAtomicityMode.TRANSACTIONAL);
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testQueryReplicatedTransactional() throws Exception {
+        checkQuery(CacheMode.REPLICATED, CacheAtomicityMode.TRANSACTIONAL);
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testFieldsQueryPartitionedAtomic() throws Exception {
+        checkFieldsQuery(CacheMode.PARTITIONED, CacheAtomicityMode.ATOMIC);
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testFieldsQueryReplicatedAtomic() throws Exception {
+        checkFieldsQuery(CacheMode.REPLICATED, CacheAtomicityMode.ATOMIC);
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testFieldsQueryPartitionedTransactional() throws Exception {
+        checkFieldsQuery(CacheMode.PARTITIONED, CacheAtomicityMode.TRANSACTIONAL);
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testFieldsQueryReplicatedTransactional() throws Exception {
+        checkFieldsQuery(CacheMode.REPLICATED, CacheAtomicityMode.TRANSACTIONAL);
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    private void checkFieldsQuery(CacheMode cacheMode, CacheAtomicityMode atomicity) throws Exception {
+        IgniteCache<Object, Object>cache = grid(3).getOrCreateCache(cache(cacheMode, atomicity));
+
+        try {
+            populate(cache);
+
+            QueryCursor<List<?>> cur = cache.query(new SqlFieldsQuery("select id, name, lastName, salary from " +
+                "Person order by id asc"));
+
+            List<List<?>> all = cur.getAll();
+
+            assertEquals(100, all.size());
+
+            for (int i = 0; i < 100; i++) {
+                List<?> row = all.get(i);
+
+                assertEquals(i, row.get(0));
+                assertEquals("person-" + i, row.get(1));
+                assertEquals("person-last-" + i, row.get(2));
+                assertEquals((double)(i * 25), row.get(3));
+            }
+        }
+        finally {
+            grid(3).destroyCache(null);
+        }
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    private void checkQuery(CacheMode cacheMode, CacheAtomicityMode atomicity) throws Exception {
+        IgniteCache<Object, Object> cache = grid(3).getOrCreateCache(cache(cacheMode, atomicity));
+
+        try {
+            populate(cache);
+
+            QueryCursor<Cache.Entry<Object, Object>> cur = cache.query(new SqlQuery("Person", "order " +
+                "by id asc"));
+
+            List<Cache.Entry<Object, Object>> all = cur.getAll();
+
+            assertEquals(100, all.size());
+
+            for (int i = 0; i < 100; i++) {
+                Object person = all.get(i).getValue();
+
+                assertEquals(i, U.field(person, "id"));
+                assertEquals("person-" + i, U.field(person, "name"));
+                assertEquals("person-last-" + i, U.field(person, "lastName"));
+                assertEquals((double)(i * 25), U.field(person, "salary"));
+            }
+        }
+        finally {
+            grid(3).destroyCache(null);
+        }
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    private void populate(IgniteCache<Object, Object> cache) throws Exception {
+        Class<?> keyCls = extClassLoader.loadClass(PERSON_KEY_CLS_NAME);
+        Class<?> cls = extClassLoader.loadClass(PERSON_CLS_NAME);
+
+        for (int i = 0; i < 100; i++) {
+            Object key = keyCls.newInstance();
+
+            GridTestUtils.setFieldValue(key, "id", i);
+
+            Object person = cls.newInstance();
+
+            GridTestUtils.setFieldValue(person, "id", i);
+            GridTestUtils.setFieldValue(person, "name", "person-" + i);
+            GridTestUtils.setFieldValue(person, "lastName", "person-last-" + i);
+            GridTestUtils.setFieldValue(person, "salary", (double)(i * 25));
+
+            cache.put(key, person);
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/9a02acbe/modules/indexing/src/test/java/org/apache/ignite/testsuites/IgnitePortableCacheQueryTestSuite.java
----------------------------------------------------------------------
diff --git a/modules/indexing/src/test/java/org/apache/ignite/testsuites/IgnitePortableCacheQueryTestSuite.java b/modules/indexing/src/test/java/org/apache/ignite/testsuites/IgnitePortableCacheQueryTestSuite.java
index da34d75..3773f8c 100644
--- a/modules/indexing/src/test/java/org/apache/ignite/testsuites/IgnitePortableCacheQueryTestSuite.java
+++ b/modules/indexing/src/test/java/org/apache/ignite/testsuites/IgnitePortableCacheQueryTestSuite.java
@@ -26,6 +26,7 @@ import org.apache.ignite.internal.processors.cache.CacheReplicatedQueryMetricsLo
 import org.apache.ignite.internal.processors.cache.GridCacheQueryIndexDisabledSelfTest;
 import org.apache.ignite.internal.processors.cache.GridCacheQueryIndexingDisabledSelfTest;
 import org.apache.ignite.internal.processors.cache.GridCacheReduceQueryMultithreadedSelfTest;
+import org.apache.ignite.internal.processors.cache.IgniteBinaryObjectFieldsQuerySelfTest;
 import org.apache.ignite.internal.processors.cache.IgniteCacheFieldsQueryNoDataSelfTest;
 import org.apache.ignite.internal.processors.cache.IgniteCacheLargeResultSelfTest;
 import org.apache.ignite.internal.processors.cache.IgniteCacheOffheapTieredMultithreadedSelfTest;
@@ -79,6 +80,7 @@ public class IgnitePortableCacheQueryTestSuite extends TestSuite {
 
         // Fields queries.
         suite.addTestSuite(IgniteCacheFieldsQueryNoDataSelfTest.class);
+        suite.addTestSuite(IgniteBinaryObjectFieldsQuerySelfTest.class);
 
         // Continuous queries.
         suite.addTestSuite(GridCacheContinuousQueryLocalAtomicSelfTest.class);


[20/59] [abbrv] ignite git commit: ignite-2065: rename "portable" packages to "binary"

Posted by ak...@apache.org.
http://git-wip-us.apache.org/repos/asf/ignite/blob/1dbf20e0/modules/core/src/main/java/org/apache/ignite/internal/portable/BinaryWriterExImpl.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/portable/BinaryWriterExImpl.java b/modules/core/src/main/java/org/apache/ignite/internal/portable/BinaryWriterExImpl.java
deleted file mode 100644
index 4139b8f..0000000
--- a/modules/core/src/main/java/org/apache/ignite/internal/portable/BinaryWriterExImpl.java
+++ /dev/null
@@ -1,1807 +0,0 @@
-/*
- * 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.portable;
-
-import org.apache.ignite.IgniteCheckedException;
-import org.apache.ignite.binary.BinaryIdMapper;
-import org.apache.ignite.binary.BinaryObjectException;
-import org.apache.ignite.binary.BinaryRawWriter;
-import org.apache.ignite.binary.BinaryWriter;
-import org.apache.ignite.internal.portable.streams.PortableHeapOutputStream;
-import org.apache.ignite.internal.portable.streams.PortableOutputStream;
-import org.apache.ignite.internal.util.typedef.internal.A;
-import org.jetbrains.annotations.Nullable;
-
-import java.io.IOException;
-import java.io.ObjectOutput;
-import java.lang.reflect.InvocationTargetException;
-import java.math.BigDecimal;
-import java.math.BigInteger;
-import java.sql.Timestamp;
-import java.util.Collection;
-import java.util.Date;
-import java.util.Map;
-import java.util.UUID;
-
-import static java.nio.charset.StandardCharsets.UTF_8;
-import static org.apache.ignite.internal.portable.GridPortableMarshaller.BOOLEAN;
-import static org.apache.ignite.internal.portable.GridPortableMarshaller.BOOLEAN_ARR;
-import static org.apache.ignite.internal.portable.GridPortableMarshaller.BYTE;
-import static org.apache.ignite.internal.portable.GridPortableMarshaller.BYTE_ARR;
-import static org.apache.ignite.internal.portable.GridPortableMarshaller.CHAR;
-import static org.apache.ignite.internal.portable.GridPortableMarshaller.CHAR_ARR;
-import static org.apache.ignite.internal.portable.GridPortableMarshaller.CLASS;
-import static org.apache.ignite.internal.portable.GridPortableMarshaller.COL;
-import static org.apache.ignite.internal.portable.GridPortableMarshaller.DATE;
-import static org.apache.ignite.internal.portable.GridPortableMarshaller.DATE_ARR;
-import static org.apache.ignite.internal.portable.GridPortableMarshaller.DECIMAL;
-import static org.apache.ignite.internal.portable.GridPortableMarshaller.DECIMAL_ARR;
-import static org.apache.ignite.internal.portable.GridPortableMarshaller.DFLT_HDR_LEN;
-import static org.apache.ignite.internal.portable.GridPortableMarshaller.DOUBLE;
-import static org.apache.ignite.internal.portable.GridPortableMarshaller.DOUBLE_ARR;
-import static org.apache.ignite.internal.portable.GridPortableMarshaller.ENUM;
-import static org.apache.ignite.internal.portable.GridPortableMarshaller.ENUM_ARR;
-import static org.apache.ignite.internal.portable.GridPortableMarshaller.FLOAT;
-import static org.apache.ignite.internal.portable.GridPortableMarshaller.FLOAT_ARR;
-import static org.apache.ignite.internal.portable.GridPortableMarshaller.INT;
-import static org.apache.ignite.internal.portable.GridPortableMarshaller.INT_ARR;
-import static org.apache.ignite.internal.portable.GridPortableMarshaller.LONG;
-import static org.apache.ignite.internal.portable.GridPortableMarshaller.LONG_ARR;
-import static org.apache.ignite.internal.portable.GridPortableMarshaller.MAP;
-import static org.apache.ignite.internal.portable.GridPortableMarshaller.NULL;
-import static org.apache.ignite.internal.portable.GridPortableMarshaller.OBJ;
-import static org.apache.ignite.internal.portable.GridPortableMarshaller.OBJ_ARR;
-import static org.apache.ignite.internal.portable.GridPortableMarshaller.OPTM_MARSH;
-import static org.apache.ignite.internal.portable.GridPortableMarshaller.PORTABLE_OBJ;
-import static org.apache.ignite.internal.portable.GridPortableMarshaller.PROTO_VER;
-import static org.apache.ignite.internal.portable.GridPortableMarshaller.SHORT;
-import static org.apache.ignite.internal.portable.GridPortableMarshaller.SHORT_ARR;
-import static org.apache.ignite.internal.portable.GridPortableMarshaller.STRING;
-import static org.apache.ignite.internal.portable.GridPortableMarshaller.STRING_ARR;
-import static org.apache.ignite.internal.portable.GridPortableMarshaller.TIMESTAMP;
-import static org.apache.ignite.internal.portable.GridPortableMarshaller.TIMESTAMP_ARR;
-import static org.apache.ignite.internal.portable.GridPortableMarshaller.UNREGISTERED_TYPE_ID;
-import static org.apache.ignite.internal.portable.GridPortableMarshaller.UUID;
-import static org.apache.ignite.internal.portable.GridPortableMarshaller.UUID_ARR;
-
-/**
- * Portable writer implementation.
- */
-public class BinaryWriterExImpl implements BinaryWriter, BinaryRawWriterEx, ObjectOutput {
-    /** Length: integer. */
-    private static final int LEN_INT = 4;
-
-    /** Initial capacity. */
-    private static final int INIT_CAP = 1024;
-
-    /** */
-    private final PortableContext ctx;
-
-    /** Output stream. */
-    private final PortableOutputStream out;
-
-    /** Schema. */
-    private final BinaryWriterSchemaHolder schema;
-
-    /** */
-    private int typeId;
-
-    /** */
-    private final int start;
-
-    /** Raw offset position. */
-    private int rawOffPos;
-
-    /** Handles. */
-    private BinaryWriterHandles handles;
-
-    /** Schema ID. */
-    private int schemaId = PortableUtils.schemaInitialId();
-
-    /** Amount of written fields. */
-    private int fieldCnt;
-
-    /** ID mapper. */
-    private BinaryIdMapper idMapper;
-
-    /**
-     * @param ctx Context.
-     */
-    public BinaryWriterExImpl(PortableContext ctx) {
-        this(ctx, BinaryThreadLocalContext.get());
-    }
-
-    /**
-     * @param ctx Context.
-     * @param tlsCtx TLS context.
-     */
-    public BinaryWriterExImpl(PortableContext ctx, BinaryThreadLocalContext tlsCtx) {
-        this(ctx, new PortableHeapOutputStream(INIT_CAP, tlsCtx.chunk()), tlsCtx.schemaHolder(), null);
-    }
-
-    /**
-     * @param ctx Context.
-     * @param out Output stream.
-     * @param handles Handles.
-     */
-    public BinaryWriterExImpl(PortableContext ctx, PortableOutputStream out, BinaryWriterSchemaHolder schema,
-        BinaryWriterHandles handles) {
-        this.ctx = ctx;
-        this.out = out;
-        this.schema = schema;
-        this.handles = handles;
-
-        start = out.position();
-    }
-
-    /**
-     * @param typeId Type ID.
-     */
-    public void typeId(int typeId) {
-        this.typeId = typeId;
-    }
-
-    /**
-     * Close the writer releasing resources if necessary.
-     */
-    @Override public void close() {
-        out.close();
-    }
-
-    /**
-     * @param obj Object.
-     * @throws org.apache.ignite.binary.BinaryObjectException In case of error.
-     */
-    void marshal(Object obj) throws BinaryObjectException {
-        marshal(obj, true);
-    }
-
-    /**
-     * @param obj Object.
-     * @param enableReplace Object replacing enabled flag.
-     * @throws org.apache.ignite.binary.BinaryObjectException In case of error.
-     */
-    void marshal(Object obj, boolean enableReplace) throws BinaryObjectException {
-        assert obj != null;
-
-        Class<?> cls = obj.getClass();
-
-        PortableClassDescriptor desc = ctx.descriptorForClass(cls, false);
-
-        if (desc == null)
-            throw new BinaryObjectException("Object is not portable: [class=" + cls + ']');
-
-        if (desc.excluded()) {
-            out.writeByte(NULL);
-
-            return;
-        }
-
-        if (desc.useOptimizedMarshaller()) {
-            out.writeByte(OPTM_MARSH);
-
-            try {
-                byte[] arr = ctx.optimizedMarsh().marshal(obj);
-
-                writeInt(arr.length);
-
-                write(arr);
-            }
-            catch (IgniteCheckedException e) {
-                throw new BinaryObjectException("Failed to marshal object with optimized marshaller: " + obj, e);
-            }
-
-            return;
-        }
-
-        if (enableReplace && desc.getWriteReplaceMethod() != null) {
-            Object replacedObj;
-
-            try {
-                replacedObj = desc.getWriteReplaceMethod().invoke(obj);
-            }
-            catch (IllegalAccessException e) {
-                throw new RuntimeException(e);
-            }
-            catch (InvocationTargetException e) {
-                if (e.getTargetException() instanceof BinaryObjectException)
-                    throw (BinaryObjectException)e.getTargetException();
-
-                throw new BinaryObjectException("Failed to execute writeReplace() method on " + obj, e);
-            }
-
-            if (replacedObj == null) {
-                out.writeByte(NULL);
-
-                return;
-            }
-
-            marshal(replacedObj, false);
-
-            return;
-        }
-
-        desc.write(obj, this);
-    }
-
-    /**
-     * @return Array.
-     */
-    public byte[] array() {
-        return out.arrayCopy();
-    }
-
-    /**
-     * @return Stream current position.
-     */
-    int position() {
-        return out.position();
-    }
-
-    /**
-     * Sets new position.
-     *
-     * @param pos Position.
-     */
-    void position(int pos) {
-        out.position(pos);
-    }
-
-    /**
-     * Perform pre-write. Reserves space for header and writes class name if needed.
-     *
-     * @param clsName Class name (optional).
-     */
-    public void preWrite(@Nullable String clsName) {
-        out.position(out.position() + DFLT_HDR_LEN);
-
-        if (clsName != null)
-            doWriteString(clsName);
-    }
-
-    /**
-     * Perform post-write. Fills object header.
-     *
-     * @param userType User type flag.
-     * @param registered Whether type is registered.
-     * @param hashCode Hash code.
-     */
-    public void postWrite(boolean userType, boolean registered, int hashCode) {
-        short flags;
-        boolean useCompactFooter;
-
-        if (userType) {
-            if (ctx.isCompactFooter()) {
-                flags = PortableUtils.FLAG_USR_TYP | PortableUtils.FLAG_COMPACT_FOOTER;
-                useCompactFooter = true;
-            }
-            else {
-                flags = PortableUtils.FLAG_USR_TYP;
-                useCompactFooter = false;
-            }
-        }
-        else {
-            flags = 0;
-            useCompactFooter = false;
-        }
-
-        int finalSchemaId;
-        int offset;
-
-        if (fieldCnt != 0) {
-            finalSchemaId = schemaId;
-            offset = out.position() - start;
-
-            // Write the schema.
-            flags |= PortableUtils.FLAG_HAS_SCHEMA;
-
-            int offsetByteCnt = schema.write(out, fieldCnt, useCompactFooter);
-
-            if (offsetByteCnt == PortableUtils.OFFSET_1)
-                flags |= PortableUtils.FLAG_OFFSET_ONE_BYTE;
-            else if (offsetByteCnt == PortableUtils.OFFSET_2)
-                flags |= PortableUtils.FLAG_OFFSET_TWO_BYTES;
-
-            // Write raw offset if needed.
-            if (rawOffPos != 0) {
-                flags |= PortableUtils.FLAG_HAS_RAW;
-
-                out.writeInt(rawOffPos - start);
-            }
-        }
-        else {
-            if (rawOffPos != 0) {
-                finalSchemaId = 0;
-                offset = rawOffPos - start;
-
-                // If there is no schema, we are free to write raw offset to schema offset.
-                flags |= PortableUtils.FLAG_HAS_RAW;
-            }
-            else {
-                finalSchemaId = 0;
-                offset = 0;
-            }
-        }
-
-        // Actual write.
-        int retPos = out.position();
-
-        out.unsafePosition(start);
-
-        out.unsafeWriteByte(OBJ);
-        out.unsafeWriteByte(PROTO_VER);
-        out.unsafeWriteShort(flags);
-        out.unsafeWriteInt(registered ? typeId : UNREGISTERED_TYPE_ID);
-        out.unsafeWriteInt(hashCode);
-        out.unsafeWriteInt(retPos - start);
-        out.unsafeWriteInt(finalSchemaId);
-        out.unsafeWriteInt(offset);
-
-        out.unsafePosition(retPos);
-    }
-
-    /**
-     * Pop schema.
-     */
-    public void popSchema() {
-        if (fieldCnt > 0)
-            schema.pop(fieldCnt);
-    }
-
-    /**
-     * @param val Byte array.
-     */
-    public void write(byte[] val) {
-        assert val != null;
-
-        out.writeByteArray(val);
-    }
-
-    /**
-     * @param val Byte array.
-     * @param off Offset.
-     * @param len Length.
-     */
-    public void write(byte[] val, int off, int len) {
-        assert val != null;
-
-        out.write(val, off, len);
-    }
-
-    /**
-     * @param val String value.
-     */
-    public void doWriteDecimal(@Nullable BigDecimal val) {
-        if (val == null)
-            out.writeByte(NULL);
-        else {
-            out.unsafeEnsure(1 + 4 + 4);
-
-            out.unsafeWriteByte(DECIMAL);
-
-            BigInteger intVal = val.unscaledValue();
-
-            if (intVal.signum() == -1) {
-                intVal = intVal.negate();
-
-                out.unsafeWriteInt(val.scale() | 0x80000000);
-            }
-            else
-                out.unsafeWriteInt(val.scale());
-
-            byte[] vals = intVal.toByteArray();
-
-            out.unsafeWriteInt(vals.length);
-            out.writeByteArray(vals);
-        }
-    }
-
-    /**
-     * @param val String value.
-     */
-    public void doWriteString(@Nullable String val) {
-        if (val == null)
-            out.writeByte(NULL);
-        else {
-            byte[] strArr = val.getBytes(UTF_8);
-
-            out.unsafeEnsure(1 + 4);
-            out.unsafeWriteByte(STRING);
-            out.unsafeWriteInt(strArr.length);
-
-            out.writeByteArray(strArr);
-        }
-    }
-
-    /**
-     * @param uuid UUID.
-     */
-    public void doWriteUuid(@Nullable UUID uuid) {
-        if (uuid == null)
-            out.writeByte(NULL);
-        else {
-            out.unsafeEnsure(1 + 8 + 8);
-            out.unsafeWriteByte(UUID);
-            out.unsafeWriteLong(uuid.getMostSignificantBits());
-            out.unsafeWriteLong(uuid.getLeastSignificantBits());
-        }
-    }
-
-    /**
-     * @param date Date.
-     */
-    public void doWriteDate(@Nullable Date date) {
-        if (date == null)
-            out.writeByte(NULL);
-        else {
-            out.unsafeEnsure(1 + 8);
-            out.unsafeWriteByte(DATE);
-            out.unsafeWriteLong(date.getTime());
-        }
-    }
-
-    /**
-     * @param ts Timestamp.
-     */
-    public void doWriteTimestamp(@Nullable Timestamp ts) {
-        if (ts== null)
-            out.writeByte(NULL);
-        else {
-            out.unsafeEnsure(1 + 8 + 4);
-            out.unsafeWriteByte(TIMESTAMP);
-            out.unsafeWriteLong(ts.getTime());
-            out.unsafeWriteInt(ts.getNanos() % 1000000);
-        }
-    }
-
-    /**
-     * Write object.
-     *
-     * @param obj Object.
-     * @throws org.apache.ignite.binary.BinaryObjectException In case of error.
-     */
-    public void doWriteObject(@Nullable Object obj) throws BinaryObjectException {
-        if (obj == null)
-            out.writeByte(NULL);
-        else {
-            BinaryWriterExImpl writer = new BinaryWriterExImpl(ctx, out, schema, handles());
-
-            writer.marshal(obj);
-        }
-    }
-
-    /**
-     * @param val Byte array.
-     */
-    void doWriteByteArray(@Nullable byte[] val) {
-        if (val == null)
-            out.writeByte(NULL);
-        else {
-            out.unsafeEnsure(1 + 4);
-            out.unsafeWriteByte(BYTE_ARR);
-            out.unsafeWriteInt(val.length);
-
-            out.writeByteArray(val);
-        }
-    }
-
-    /**
-     * @param val Short array.
-     */
-    void doWriteShortArray(@Nullable short[] val) {
-        if (val == null)
-            out.writeByte(NULL);
-        else {
-            out.unsafeEnsure(1 + 4);
-            out.unsafeWriteByte(SHORT_ARR);
-            out.unsafeWriteInt(val.length);
-
-            out.writeShortArray(val);
-        }
-    }
-
-    /**
-     * @param val Integer array.
-     */
-    void doWriteIntArray(@Nullable int[] val) {
-        if (val == null)
-            out.writeByte(NULL);
-        else {
-            out.unsafeEnsure(1 + 4);
-            out.unsafeWriteByte(INT_ARR);
-            out.unsafeWriteInt(val.length);
-
-            out.writeIntArray(val);
-        }
-    }
-
-    /**
-     * @param val Long array.
-     */
-    void doWriteLongArray(@Nullable long[] val) {
-        if (val == null)
-            out.writeByte(NULL);
-        else {
-            out.unsafeEnsure(1 + 4);
-            out.unsafeWriteByte(LONG_ARR);
-            out.unsafeWriteInt(val.length);
-
-            out.writeLongArray(val);
-        }
-    }
-
-    /**
-     * @param val Float array.
-     */
-    void doWriteFloatArray(@Nullable float[] val) {
-        if (val == null)
-            out.writeByte(NULL);
-        else {
-            out.unsafeEnsure(1 + 4);
-            out.unsafeWriteByte(FLOAT_ARR);
-            out.unsafeWriteInt(val.length);
-
-            out.writeFloatArray(val);
-        }
-    }
-
-    /**
-     * @param val Double array.
-     */
-    void doWriteDoubleArray(@Nullable double[] val) {
-        if (val == null)
-            out.writeByte(NULL);
-        else {
-            out.unsafeEnsure(1 + 4);
-            out.unsafeWriteByte(DOUBLE_ARR);
-            out.unsafeWriteInt(val.length);
-
-            out.writeDoubleArray(val);
-        }
-    }
-
-    /**
-     * @param val Char array.
-     */
-    void doWriteCharArray(@Nullable char[] val) {
-        if (val == null)
-            out.writeByte(NULL);
-        else {
-            out.unsafeEnsure(1 + 4);
-            out.unsafeWriteByte(CHAR_ARR);
-            out.unsafeWriteInt(val.length);
-
-            out.writeCharArray(val);
-        }
-    }
-
-    /**
-     * @param val Boolean array.
-     */
-    void doWriteBooleanArray(@Nullable boolean[] val) {
-        if (val == null)
-            out.writeByte(NULL);
-        else {
-            out.unsafeEnsure(1 + 4);
-            out.unsafeWriteByte(BOOLEAN_ARR);
-            out.unsafeWriteInt(val.length);
-
-            out.writeBooleanArray(val);
-        }
-    }
-
-    /**
-     * @param val Array of strings.
-     */
-    void doWriteDecimalArray(@Nullable BigDecimal[] val) {
-        if (val == null)
-            out.writeByte(NULL);
-        else {
-            out.unsafeEnsure(1 + 4);
-            out.unsafeWriteByte(DECIMAL_ARR);
-            out.unsafeWriteInt(val.length);
-
-            for (BigDecimal str : val)
-                doWriteDecimal(str);
-        }
-    }
-
-    /**
-     * @param val Array of strings.
-     */
-    void doWriteStringArray(@Nullable String[] val) {
-        if (val == null)
-            out.writeByte(NULL);
-        else {
-            out.unsafeEnsure(1 + 4);
-            out.unsafeWriteByte(STRING_ARR);
-            out.unsafeWriteInt(val.length);
-
-            for (String str : val)
-                doWriteString(str);
-        }
-    }
-
-    /**
-     * @param val Array of UUIDs.
-     */
-    void doWriteUuidArray(@Nullable UUID[] val) {
-        if (val == null)
-            out.writeByte(NULL);
-        else {
-            out.unsafeEnsure(1 + 4);
-            out.unsafeWriteByte(UUID_ARR);
-            out.unsafeWriteInt(val.length);
-
-            for (UUID uuid : val)
-                doWriteUuid(uuid);
-        }
-    }
-
-    /**
-     * @param val Array of dates.
-     */
-    void doWriteDateArray(@Nullable Date[] val) {
-        if (val == null)
-            out.writeByte(NULL);
-        else {
-            out.unsafeEnsure(1 + 4);
-            out.unsafeWriteByte(DATE_ARR);
-            out.unsafeWriteInt(val.length);
-
-            for (Date date : val)
-                doWriteDate(date);
-        }
-    }
-
-     /**
-      * @param val Array of timestamps.
-      */
-     void doWriteTimestampArray(@Nullable Timestamp[] val) {
-         if (val == null)
-             out.writeByte(NULL);
-         else {
-             out.unsafeEnsure(1 + 4);
-             out.unsafeWriteByte(TIMESTAMP_ARR);
-             out.unsafeWriteInt(val.length);
-
-             for (Timestamp ts : val)
-                 doWriteTimestamp(ts);
-         }
-     }
-
-    /**
-     * @param val Array of objects.
-     * @throws org.apache.ignite.binary.BinaryObjectException In case of error.
-     */
-    void doWriteObjectArray(@Nullable Object[] val) throws BinaryObjectException {
-        if (val == null)
-            out.writeByte(NULL);
-        else {
-            if (tryWriteAsHandle(val))
-                return;
-
-            PortableClassDescriptor desc = ctx.descriptorForClass(val.getClass().getComponentType(), false);
-
-            out.unsafeEnsure(1 + 4);
-            out.unsafeWriteByte(OBJ_ARR);
-
-            if (desc.registered())
-                out.unsafeWriteInt(desc.typeId());
-            else {
-                out.unsafeWriteInt(UNREGISTERED_TYPE_ID);
-
-                doWriteString(val.getClass().getComponentType().getName());
-            }
-
-            out.writeInt(val.length);
-
-            for (Object obj : val)
-                doWriteObject(obj);
-        }
-    }
-
-    /**
-     * @param col Collection.
-     * @throws org.apache.ignite.binary.BinaryObjectException In case of error.
-     */
-    void doWriteCollection(@Nullable Collection<?> col) throws BinaryObjectException {
-        if (col == null)
-            out.writeByte(NULL);
-        else {
-            if (tryWriteAsHandle(col))
-                return;
-
-            out.unsafeEnsure(1 + 4 + 1);
-            out.unsafeWriteByte(COL);
-            out.unsafeWriteInt(col.size());
-            out.unsafeWriteByte(ctx.collectionType(col.getClass()));
-
-            for (Object obj : col)
-                doWriteObject(obj);
-        }
-    }
-
-    /**
-     * @param map Map.
-     * @throws org.apache.ignite.binary.BinaryObjectException In case of error.
-     */
-    void doWriteMap(@Nullable Map<?, ?> map) throws BinaryObjectException {
-        if (map == null)
-            out.writeByte(NULL);
-        else {
-            if (tryWriteAsHandle(map))
-                return;
-
-            out.unsafeEnsure(1 + 4 + 1);
-            out.unsafeWriteByte(MAP);
-            out.unsafeWriteInt(map.size());
-            out.unsafeWriteByte(ctx.mapType(map.getClass()));
-
-            for (Map.Entry<?, ?> e : map.entrySet()) {
-                doWriteObject(e.getKey());
-                doWriteObject(e.getValue());
-            }
-        }
-    }
-
-    /**
-     * @param val Value.
-     */
-    void doWriteEnum(@Nullable Enum<?> val) {
-        if (val == null)
-            out.writeByte(NULL);
-        else {
-            PortableClassDescriptor desc = ctx.descriptorForClass(val.getClass(), false);
-
-            out.unsafeEnsure(1 + 4);
-
-            out.unsafeWriteByte(ENUM);
-
-            if (desc.registered())
-                out.unsafeWriteInt(desc.typeId());
-            else {
-                out.unsafeWriteInt(UNREGISTERED_TYPE_ID);
-                doWriteString(val.getClass().getName());
-            }
-
-            out.writeInt(val.ordinal());
-        }
-    }
-
-    /**
-     * @param val Value.
-     */
-    void doWritePortableEnum(BinaryEnumObjectImpl val) {
-        assert val != null;
-
-        int typeId = val.typeId();
-
-        out.unsafeEnsure(1 + 4);
-
-        out.unsafeWriteByte(ENUM);
-        out.unsafeWriteInt(typeId);
-
-        if (typeId == UNREGISTERED_TYPE_ID)
-            doWriteString(val.className());
-
-        out.writeInt(val.enumOrdinal());
-    }
-
-    /**
-     * @param val Array.
-     */
-    void doWriteEnumArray(@Nullable Object[] val) {
-        assert val == null || val.getClass().getComponentType().isEnum();
-
-        if (val == null)
-            out.writeByte(NULL);
-        else {
-            PortableClassDescriptor desc = ctx.descriptorForClass(val.getClass().getComponentType(), false);
-
-            out.unsafeEnsure(1 + 4);
-
-            out.unsafeWriteByte(ENUM_ARR);
-
-            if (desc.registered())
-                out.unsafeWriteInt(desc.typeId());
-            else {
-                out.unsafeWriteInt(UNREGISTERED_TYPE_ID);
-
-                doWriteString(val.getClass().getComponentType().getName());
-            }
-
-            out.writeInt(val.length);
-
-            // TODO: Denis: Redundant data for each element of the array.
-            for (Object o : val)
-                doWriteEnum((Enum<?>)o);
-        }
-    }
-
-    /**
-     * @param val Class.
-     */
-    void doWriteClass(@Nullable Class val) {
-        if (val == null)
-            out.writeByte(NULL);
-        else {
-            PortableClassDescriptor desc = ctx.descriptorForClass(val, false);
-
-            out.unsafeEnsure(1 + 4);
-
-            out.unsafeWriteByte(CLASS);
-
-            if (desc.registered())
-                out.unsafeWriteInt(desc.typeId());
-            else {
-                out.unsafeWriteInt(UNREGISTERED_TYPE_ID);
-
-                doWriteString(val.getClass().getName());
-            }
-        }
-    }
-
-    /**
-     * @param po Portable object.
-     */
-    public void doWritePortableObject(@Nullable BinaryObjectImpl po) {
-        if (po == null)
-            out.writeByte(NULL);
-        else {
-            byte[] poArr = po.array();
-
-            out.unsafeEnsure(1 + 4 + poArr.length + 4);
-
-            out.unsafeWriteByte(PORTABLE_OBJ);
-            out.unsafeWriteInt(poArr.length);
-            out.writeByteArray(poArr);
-            out.unsafeWriteInt(po.start());
-        }
-    }
-
-    /**
-     * @param val Value.
-     */
-    void writeByteFieldPrimitive(byte val) {
-        out.unsafeEnsure(1 + 1);
-
-        out.unsafeWriteByte(BYTE);
-        out.unsafeWriteByte(val);
-    }
-
-    /**
-     * @param val Value.
-     */
-    void writeByteField(@Nullable Byte val) {
-        if (val == null)
-            out.writeByte(NULL);
-        else
-            writeByteFieldPrimitive(val);
-    }
-
-    /**
-     * @param val Class.
-     */
-    void writeClassField(@Nullable Class val) {
-        doWriteClass(val);
-    }
-
-    /**
-     * @param val Value.
-     */
-    void writeShortFieldPrimitive(short val) {
-        out.unsafeEnsure(1 + 2);
-
-        out.unsafeWriteByte(SHORT);
-        out.unsafeWriteShort(val);
-    }
-
-    /**
-     * @param val Value.
-     */
-    void writeShortField(@Nullable Short val) {
-        if (val == null)
-            out.writeByte(NULL);
-        else
-            writeShortFieldPrimitive(val);
-    }
-
-    /**
-     * @param val Value.
-     */
-    void writeIntFieldPrimitive(int val) {
-        out.unsafeEnsure(1 + 4);
-
-        out.unsafeWriteByte(INT);
-        out.unsafeWriteInt(val);
-    }
-
-    /**
-     * @param val Value.
-     */
-    void writeIntField(@Nullable Integer val) {
-        if (val == null)
-            out.writeByte(NULL);
-        else
-            writeIntFieldPrimitive(val);
-    }
-
-    /**
-     * @param val Value.
-     */
-    void writeLongFieldPrimitive(long val) {
-        out.unsafeEnsure(1 + 8);
-
-        out.unsafeWriteByte(LONG);
-        out.unsafeWriteLong(val);
-    }
-
-    /**
-     * @param val Value.
-     */
-    void writeLongField(@Nullable Long val) {
-        if (val == null)
-            out.writeByte(NULL);
-        else
-            writeLongFieldPrimitive(val);
-    }
-
-    /**
-     * @param val Value.
-     */
-    void writeFloatFieldPrimitive(float val) {
-        out.unsafeEnsure(1 + 4);
-
-        out.unsafeWriteByte(FLOAT);
-        out.unsafeWriteFloat(val);
-    }
-
-    /**
-     * @param val Value.
-     */
-    void writeFloatField(@Nullable Float val) {
-        if (val == null)
-            out.writeByte(NULL);
-        else
-            writeFloatFieldPrimitive(val);
-    }
-
-    /**
-     * @param val Value.
-     */
-    void writeDoubleFieldPrimitive(double val) {
-        out.unsafeEnsure(1 + 8);
-
-        out.unsafeWriteByte(DOUBLE);
-        out.unsafeWriteDouble(val);
-    }
-
-    /**
-     * @param val Value.
-     */
-    void writeDoubleField(@Nullable Double val) {
-        if (val == null)
-            out.writeByte(NULL);
-        else
-            writeDoubleFieldPrimitive(val);
-    }
-
-    /**
-     * @param val Value.
-     */
-    void writeCharFieldPrimitive(char val) {
-        out.unsafeEnsure(1 + 2);
-
-        out.unsafeWriteByte(CHAR);
-        out.unsafeWriteChar(val);
-    }
-
-    /**
-     * @param val Value.
-     */
-    void writeCharField(@Nullable Character val) {
-        if (val == null)
-            out.writeByte(NULL);
-        else
-            writeCharFieldPrimitive(val);
-    }
-
-    /**
-     * @param val Value.
-     */
-    void writeBooleanFieldPrimitive(boolean val) {
-        out.unsafeEnsure(1 + 1);
-
-        out.unsafeWriteByte(BOOLEAN);
-        out.unsafeWriteBoolean(val);
-    }
-
-    /**
-     * @param val Value.
-     */
-    void writeBooleanField(@Nullable Boolean val) {
-        if (val == null)
-            out.writeByte(NULL);
-        else
-            writeBooleanFieldPrimitive(val);
-    }
-
-    /**
-     * @param val Value.
-     */
-    void writeDecimalField(@Nullable BigDecimal val) {
-        doWriteDecimal(val);
-    }
-
-    /**
-     * @param val Value.
-     */
-    void writeStringField(@Nullable String val) {
-        doWriteString(val);
-    }
-
-    /**
-     * @param val Value.
-     */
-    void writeUuidField(@Nullable UUID val) {
-        doWriteUuid(val);
-    }
-
-    /**
-     * @param val Value.
-     */
-    void writeDateField(@Nullable Date val) {
-        doWriteDate(val);
-    }
-
-    /**
-     * @param val Value.
-     */
-    void writeTimestampField(@Nullable Timestamp val) {
-        doWriteTimestamp(val);
-    }
-
-    /**
-     * @param obj Object.
-     * @throws org.apache.ignite.binary.BinaryObjectException In case of error.
-     */
-    void writeObjectField(@Nullable Object obj) throws BinaryObjectException {
-        doWriteObject(obj);
-    }
-
-    /**
-     * @param val Value.
-     */
-    void writeByteArrayField(@Nullable byte[] val) {
-        doWriteByteArray(val);
-    }
-
-    /**
-     * @param val Value.
-     */
-    void writeShortArrayField(@Nullable short[] val) {
-        doWriteShortArray(val);
-    }
-
-    /**
-     * @param val Value.
-     */
-    void writeIntArrayField(@Nullable int[] val) {
-        doWriteIntArray(val);
-    }
-
-    /**
-     * @param val Value.
-     */
-    void writeLongArrayField(@Nullable long[] val) {
-        doWriteLongArray(val);
-    }
-
-    /**
-     * @param val Value.
-     */
-    void writeFloatArrayField(@Nullable float[] val) {
-        doWriteFloatArray(val);
-    }
-
-    /**
-     * @param val Value.
-     */
-    void writeDoubleArrayField(@Nullable double[] val) {
-        doWriteDoubleArray(val);
-    }
-
-    /**
-     * @param val Value.
-     */
-    void writeCharArrayField(@Nullable char[] val) {
-        doWriteCharArray(val);
-    }
-
-    /**
-     * @param val Value.
-     */
-    void writeBooleanArrayField(@Nullable boolean[] val) {
-        doWriteBooleanArray(val);
-    }
-
-    /**
-     * @param val Value.
-     */
-    void writeDecimalArrayField(@Nullable BigDecimal[] val) {
-        doWriteDecimalArray(val);
-    }
-
-    /**
-     * @param val Value.
-     */
-    void writeStringArrayField(@Nullable String[] val) {
-        doWriteStringArray(val);
-    }
-
-    /**
-     * @param val Value.
-     */
-    void writeUuidArrayField(@Nullable UUID[] val) {
-        doWriteUuidArray(val);
-    }
-
-    /**
-     * @param val Value.
-     */
-    void writeDateArrayField(@Nullable Date[] val) {
-        doWriteDateArray(val);
-    }
-
-    /**
-     * @param val Value.
-     */
-    void writeTimestampArrayField(@Nullable Timestamp[] val) {
-        doWriteTimestampArray(val);
-    }
-
-    /**
-     * @param val Value.
-     * @throws org.apache.ignite.binary.BinaryObjectException In case of error.
-     */
-    void writeObjectArrayField(@Nullable Object[] val) throws BinaryObjectException {
-        doWriteObjectArray(val);
-    }
-
-    /**
-     * @param col Collection.
-     * @throws org.apache.ignite.binary.BinaryObjectException In case of error.
-     */
-    void writeCollectionField(@Nullable Collection<?> col) throws BinaryObjectException {
-        doWriteCollection(col);
-    }
-
-    /**
-     * @param map Map.
-     * @throws org.apache.ignite.binary.BinaryObjectException In case of error.
-     */
-    void writeMapField(@Nullable Map<?, ?> map) throws BinaryObjectException {
-        doWriteMap(map);
-    }
-
-    /**
-     * @param val Value.
-     */
-    void writeEnumField(@Nullable Enum<?> val) {
-        doWriteEnum(val);
-    }
-
-    /**
-     * @param val Value.
-     */
-    void writeEnumArrayField(@Nullable Object[] val) {
-        doWriteEnumArray(val);
-    }
-
-    /**
-     * @param po Portable object.
-     * @throws org.apache.ignite.binary.BinaryObjectException In case of error.
-     */
-    void writePortableObjectField(@Nullable BinaryObjectImpl po) throws BinaryObjectException {
-        doWritePortableObject(po);
-    }
-
-    /** {@inheritDoc} */
-    @Override public void writeByte(String fieldName, byte val) throws BinaryObjectException {
-        writeFieldId(fieldName);
-        writeByteField(val);
-    }
-
-    /** {@inheritDoc} */
-    @Override public void writeByte(byte val) throws BinaryObjectException {
-        out.writeByte(val);
-    }
-
-    /** {@inheritDoc} */
-    @Override public void writeShort(String fieldName, short val) throws BinaryObjectException {
-        writeFieldId(fieldName);
-        writeShortField(val);
-    }
-
-    /** {@inheritDoc} */
-    @Override public void writeShort(short val) throws BinaryObjectException {
-        out.writeShort(val);
-    }
-
-    /** {@inheritDoc} */
-    @Override public void writeInt(String fieldName, int val) throws BinaryObjectException {
-        writeFieldId(fieldName);
-        writeIntField(val);
-    }
-
-    /** {@inheritDoc} */
-    @Override public void writeInt(int val) throws BinaryObjectException {
-        out.writeInt(val);
-    }
-
-    /** {@inheritDoc} */
-    @Override public void writeLong(String fieldName, long val) throws BinaryObjectException {
-        writeFieldId(fieldName);
-        writeLongField(val);
-    }
-
-    /** {@inheritDoc} */
-    @Override public void writeLong(long val) throws BinaryObjectException {
-        out.writeLong(val);
-    }
-
-    /** {@inheritDoc} */
-    @Override public void writeFloat(String fieldName, float val) throws BinaryObjectException {
-        writeFieldId(fieldName);
-        writeFloatField(val);
-    }
-
-    /** {@inheritDoc} */
-    @Override public void writeFloat(float val) throws BinaryObjectException {
-        out.writeFloat(val);
-    }
-
-    /** {@inheritDoc} */
-    @Override public void writeDouble(String fieldName, double val) throws BinaryObjectException {
-        writeFieldId(fieldName);
-        writeDoubleField(val);
-    }
-
-    /** {@inheritDoc} */
-    @Override public void writeDouble(double val) throws BinaryObjectException {
-        out.writeDouble(val);
-    }
-
-    /** {@inheritDoc} */
-    @Override public void writeChar(String fieldName, char val) throws BinaryObjectException {
-        writeFieldId(fieldName);
-        writeCharField(val);
-    }
-
-    /** {@inheritDoc} */
-    @Override public void writeChar(char val) throws BinaryObjectException {
-        out.writeChar(val);
-    }
-
-    /** {@inheritDoc} */
-    @Override public void writeBoolean(String fieldName, boolean val) throws BinaryObjectException {
-        writeFieldId(fieldName);
-        writeBooleanField(val);
-    }
-
-    /** {@inheritDoc} */
-    @Override public void writeBoolean(boolean val) throws BinaryObjectException {
-        out.writeBoolean(val);
-    }
-
-    /** {@inheritDoc} */
-    @Override public void writeDecimal(String fieldName, @Nullable BigDecimal val) throws BinaryObjectException {
-        writeFieldId(fieldName);
-        writeDecimalField(val);
-    }
-
-    /** {@inheritDoc} */
-    @Override public void writeDecimal(@Nullable BigDecimal val) throws BinaryObjectException {
-        doWriteDecimal(val);
-    }
-
-    /** {@inheritDoc} */
-    @Override public void writeString(String fieldName, @Nullable String val) throws BinaryObjectException {
-        writeFieldId(fieldName);
-        writeStringField(val);
-    }
-
-    /** {@inheritDoc} */
-    @Override public void writeString(@Nullable String val) throws BinaryObjectException {
-        doWriteString(val);
-    }
-
-    /** {@inheritDoc} */
-    @Override public void writeUuid(String fieldName, @Nullable UUID val) throws BinaryObjectException {
-        writeFieldId(fieldName);
-        writeUuidField(val);
-    }
-
-    /** {@inheritDoc} */
-    @Override public void writeUuid(@Nullable UUID val) throws BinaryObjectException {
-        doWriteUuid(val);
-    }
-
-    /** {@inheritDoc} */
-    @Override public void writeDate(String fieldName, @Nullable Date val) throws BinaryObjectException {
-        writeFieldId(fieldName);
-        writeDateField(val);
-    }
-
-    /** {@inheritDoc} */
-    @Override public void writeDate(@Nullable Date val) throws BinaryObjectException {
-        doWriteDate(val);
-    }
-
-    /** {@inheritDoc} */
-    @Override public void writeTimestamp(String fieldName, @Nullable Timestamp val) throws BinaryObjectException {
-        writeFieldId(fieldName);
-        writeTimestampField(val);
-    }
-
-    /** {@inheritDoc} */
-    @Override public void writeTimestamp(@Nullable Timestamp val) throws BinaryObjectException {
-        doWriteTimestamp(val);
-    }
-
-    /** {@inheritDoc} */
-    @Override public void writeObject(String fieldName, @Nullable Object obj) throws BinaryObjectException {
-        writeFieldId(fieldName);
-        writeObjectField(obj);
-    }
-
-    /** {@inheritDoc} */
-    @Override public void writeObject(@Nullable Object obj) throws BinaryObjectException {
-        doWriteObject(obj);
-    }
-
-    /** {@inheritDoc} */
-    @Override public void writeObjectDetached(@Nullable Object obj) throws BinaryObjectException {
-        if (obj == null)
-            out.writeByte(NULL);
-        else {
-            BinaryWriterExImpl writer = new BinaryWriterExImpl(ctx, out, schema, null);
-
-            writer.marshal(obj);
-        }
-    }
-
-    /** {@inheritDoc} */
-    @Override public void writeByteArray(String fieldName, @Nullable byte[] val) throws BinaryObjectException {
-        writeFieldId(fieldName);
-        writeByteArrayField(val);
-    }
-
-    /** {@inheritDoc} */
-    @Override public void writeByteArray(@Nullable byte[] val) throws BinaryObjectException {
-        doWriteByteArray(val);
-    }
-
-    /** {@inheritDoc} */
-    @Override public void writeShortArray(String fieldName, @Nullable short[] val) throws BinaryObjectException {
-        writeFieldId(fieldName);
-        writeShortArrayField(val);
-    }
-
-    /** {@inheritDoc} */
-    @Override public void writeShortArray(@Nullable short[] val) throws BinaryObjectException {
-        doWriteShortArray(val);
-    }
-
-    /** {@inheritDoc} */
-    @Override public void writeIntArray(String fieldName, @Nullable int[] val) throws BinaryObjectException {
-        writeFieldId(fieldName);
-        writeIntArrayField(val);
-    }
-
-    /** {@inheritDoc} */
-    @Override public void writeIntArray(@Nullable int[] val) throws BinaryObjectException {
-        doWriteIntArray(val);
-    }
-
-    /** {@inheritDoc} */
-    @Override public void writeLongArray(String fieldName, @Nullable long[] val) throws BinaryObjectException {
-        writeFieldId(fieldName);
-        writeLongArrayField(val);
-    }
-
-    /** {@inheritDoc} */
-    @Override public void writeLongArray(@Nullable long[] val) throws BinaryObjectException {
-        doWriteLongArray(val);
-    }
-
-    /** {@inheritDoc} */
-    @Override public void writeFloatArray(String fieldName, @Nullable float[] val) throws BinaryObjectException {
-        writeFieldId(fieldName);
-        writeFloatArrayField(val);
-    }
-
-    /** {@inheritDoc} */
-    @Override public void writeFloatArray(@Nullable float[] val) throws BinaryObjectException {
-        doWriteFloatArray(val);
-    }
-
-    /** {@inheritDoc} */
-    @Override public void writeDoubleArray(String fieldName, @Nullable double[] val)
-        throws BinaryObjectException {
-        writeFieldId(fieldName);
-        writeDoubleArrayField(val);
-    }
-
-    /** {@inheritDoc} */
-    @Override public void writeDoubleArray(@Nullable double[] val) throws BinaryObjectException {
-        doWriteDoubleArray(val);
-    }
-
-    /** {@inheritDoc} */
-    @Override public void writeCharArray(String fieldName, @Nullable char[] val) throws BinaryObjectException {
-        writeFieldId(fieldName);
-        writeCharArrayField(val);
-    }
-
-    /** {@inheritDoc} */
-    @Override public void writeCharArray(@Nullable char[] val) throws BinaryObjectException {
-        doWriteCharArray(val);
-    }
-
-    /** {@inheritDoc} */
-    @Override public void writeBooleanArray(String fieldName, @Nullable boolean[] val)
-        throws BinaryObjectException {
-        writeFieldId(fieldName);
-        writeBooleanArrayField(val);
-    }
-
-    /** {@inheritDoc} */
-    @Override public void writeBooleanArray(@Nullable boolean[] val) throws BinaryObjectException {
-        doWriteBooleanArray(val);
-    }
-
-    /** {@inheritDoc} */
-    @Override public void writeDecimalArray(String fieldName, @Nullable BigDecimal[] val)
-        throws BinaryObjectException {
-        writeFieldId(fieldName);
-        writeDecimalArrayField(val);
-    }
-
-    /** {@inheritDoc} */
-    @Override public void writeDecimalArray(@Nullable BigDecimal[] val) throws BinaryObjectException {
-        doWriteDecimalArray(val);
-    }
-
-    /** {@inheritDoc} */
-    @Override public void writeStringArray(String fieldName, @Nullable String[] val)
-        throws BinaryObjectException {
-        writeFieldId(fieldName);
-        writeStringArrayField(val);
-    }
-
-    /** {@inheritDoc} */
-    @Override public void writeStringArray(@Nullable String[] val) throws BinaryObjectException {
-        doWriteStringArray(val);
-    }
-
-    /** {@inheritDoc} */
-    @Override public void writeUuidArray(String fieldName, @Nullable UUID[] val) throws BinaryObjectException {
-        writeFieldId(fieldName);
-        writeUuidArrayField(val);
-    }
-
-    /** {@inheritDoc} */
-    @Override public void writeUuidArray(@Nullable UUID[] val) throws BinaryObjectException {
-        doWriteUuidArray(val);
-    }
-
-    /** {@inheritDoc} */
-    @Override public void writeDateArray(String fieldName, @Nullable Date[] val) throws BinaryObjectException {
-        writeFieldId(fieldName);
-        writeDateArrayField(val);
-    }
-
-    /** {@inheritDoc} */
-    @Override public void writeDateArray(@Nullable Date[] val) throws BinaryObjectException {
-        doWriteDateArray(val);
-    }
-
-    /** {@inheritDoc} */
-    @Override public void writeTimestampArray(String fieldName, @Nullable Timestamp[] val) throws BinaryObjectException {
-        writeFieldId(fieldName);
-        writeTimestampArrayField(val);
-    }
-
-    /** {@inheritDoc} */
-    @Override public void writeTimestampArray(@Nullable Timestamp[] val) throws BinaryObjectException {
-        doWriteTimestampArray(val);
-    }
-
-     /** {@inheritDoc} */
-    @Override public void writeObjectArray(String fieldName, @Nullable Object[] val) throws BinaryObjectException {
-        writeFieldId(fieldName);
-        writeObjectArrayField(val);
-    }
-
-    /** {@inheritDoc} */
-    @Override public void writeObjectArray(@Nullable Object[] val) throws BinaryObjectException {
-        doWriteObjectArray(val);
-    }
-
-    /** {@inheritDoc} */
-    @Override public <T> void writeCollection(String fieldName, @Nullable Collection<T> col)
-        throws BinaryObjectException {
-        writeFieldId(fieldName);
-        writeCollectionField(col);
-    }
-
-    /** {@inheritDoc} */
-    @Override public <T> void writeCollection(@Nullable Collection<T> col) throws BinaryObjectException {
-        doWriteCollection(col);
-    }
-
-    /** {@inheritDoc} */
-    @Override public <K, V> void writeMap(String fieldName, @Nullable Map<K, V> map)
-        throws BinaryObjectException {
-        writeFieldId(fieldName);
-        writeMapField(map);
-    }
-
-    /** {@inheritDoc} */
-    @Override public <K, V> void writeMap(@Nullable Map<K, V> map) throws BinaryObjectException {
-        doWriteMap(map);
-    }
-
-    /** {@inheritDoc} */
-    @Override public <T extends Enum<?>> void writeEnum(String fieldName, T val) throws BinaryObjectException {
-        writeFieldId(fieldName);
-        writeEnumField(val);
-    }
-
-    /** {@inheritDoc} */
-    @Override public <T extends Enum<?>> void writeEnum(T val) throws BinaryObjectException {
-        doWriteEnum(val);
-    }
-
-    /** {@inheritDoc} */
-    @Override public <T extends Enum<?>> void writeEnumArray(String fieldName, T[] val) throws BinaryObjectException {
-        writeFieldId(fieldName);
-        writeEnumArrayField(val);
-    }
-
-    /** {@inheritDoc} */
-    @Override public <T extends Enum<?>> void writeEnumArray(T[] val) throws BinaryObjectException {
-        doWriteEnumArray(val);
-    }
-
-    /** {@inheritDoc} */
-    @Override public BinaryRawWriter rawWriter() {
-        if (rawOffPos == 0)
-            rawOffPos = out.position();
-
-        return this;
-    }
-
-    /** {@inheritDoc} */
-    @Override public PortableOutputStream out() {
-        return out;
-    }
-
-    /** {@inheritDoc} */
-    @SuppressWarnings("NullableProblems")
-    @Override public void writeBytes(String s) throws IOException {
-        int len = s.length();
-
-        writeInt(len);
-
-        for (int i = 0; i < len; i++)
-            writeByte(s.charAt(i));
-    }
-
-    /** {@inheritDoc} */
-    @SuppressWarnings("NullableProblems")
-    @Override public void writeChars(String s) throws IOException {
-        int len = s.length();
-
-        writeInt(len);
-
-        for (int i = 0; i < len; i++)
-            writeChar(s.charAt(i));
-    }
-
-    /** {@inheritDoc} */
-    @SuppressWarnings("NullableProblems")
-    @Override public void writeUTF(String s) throws IOException {
-        writeString(s);
-    }
-
-    /** {@inheritDoc} */
-    @Override public void writeByte(int v) throws IOException {
-        out.writeByte((byte) v);
-    }
-
-    /** {@inheritDoc} */
-    @Override public void writeShort(int v) throws IOException {
-        out.writeShort((short) v);
-    }
-
-    /** {@inheritDoc} */
-    @Override public void writeChar(int v) throws IOException {
-        out.writeChar((char) v);
-    }
-
-    /** {@inheritDoc} */
-    @Override public void write(int b) throws IOException {
-        out.writeByte((byte) b);
-    }
-
-    /** {@inheritDoc} */
-    @Override public void flush() throws IOException {
-        // No-op.
-    }
-
-    /** {@inheritDoc} */
-    @Override public int reserveInt() {
-        int pos = out.position();
-
-        out.position(pos + LEN_INT);
-
-        return pos;
-    }
-
-    /** {@inheritDoc} */
-    @Override public void writeInt(int pos, int val) throws BinaryObjectException {
-        out.writeInt(pos, val);
-    }
-
-    /**
-     * @param fieldName Field name.
-     * @throws org.apache.ignite.binary.BinaryObjectException If fields are not allowed.
-     */
-    private void writeFieldId(String fieldName) throws BinaryObjectException {
-        A.notNull(fieldName, "fieldName");
-
-        if (rawOffPos != 0)
-            throw new BinaryObjectException("Individual field can't be written after raw writer is acquired.");
-
-        if (idMapper == null)
-            idMapper = ctx.userTypeIdMapper(typeId);
-
-        int id = idMapper.fieldId(typeId, fieldName);
-
-        writeFieldId(id);
-    }
-
-    /**
-     * Write field ID.
-     * @param fieldId Field ID.
-     */
-    public void writeFieldId(int fieldId) {
-        int fieldOff = out.position() - start;
-
-        // Advance schema hash.
-        schemaId = PortableUtils.updateSchemaId(schemaId, fieldId);
-
-        schema.push(fieldId, fieldOff);
-
-        fieldCnt++;
-    }
-
-    /**
-     * Write field ID without schema ID update. This method should be used when schema ID is stable because class
-     * is seializable.
-     *
-     * @param fieldId Field ID.
-     */
-    public void writeFieldIdNoSchemaUpdate(int fieldId) {
-        int fieldOff = out.position() - start;
-
-        schema.push(fieldId, fieldOff);
-
-        fieldCnt++;
-    }
-
-    /**
-     * @param schemaId Schema ID.
-     */
-    public void schemaId(int schemaId) {
-        this.schemaId = schemaId;
-    }
-
-    /**
-     * @return Schema ID.
-     */
-    public int schemaId() {
-        return schemaId;
-    }
-
-    /**
-     * @return Current writer's schema.
-     */
-    public PortableSchema currentSchema() {
-        PortableSchema.Builder builder = PortableSchema.Builder.newBuilder();
-
-        if (schema != null)
-            schema.build(builder, fieldCnt);
-
-        return builder.build();
-    }
-
-    /**
-     * Get current handles. If they are {@code null}, then we should create them. Otherwise we will not see updates
-     * performed by child writers.
-     *
-     * @return Handles.
-     */
-    private BinaryWriterHandles handles() {
-        if (handles == null)
-            handles = new BinaryWriterHandles();
-
-        return handles;
-    }
-
-    /**
-     * Attempts to write the object as a handle.
-     *
-     * @param obj Object to write.
-     * @return {@code true} if the object has been written as a handle.
-     */
-    boolean tryWriteAsHandle(Object obj) {
-        assert obj != null;
-
-        int pos = out.position();
-
-        BinaryWriterHandles handles0 = handles();
-
-        int old = handles0.put(obj, pos);
-
-        if (old == BinaryWriterHandles.POS_NULL)
-            return false;
-        else {
-            out.unsafeEnsure(1 + 4);
-
-            out.unsafeWriteByte(GridPortableMarshaller.HANDLE);
-            out.unsafeWriteInt(pos - old);
-
-            return true;
-        }
-    }
-
-    /**
-     * Create new writer with same context.
-     *
-     * @param typeId type
-     * @return New writer.
-     */
-    public BinaryWriterExImpl newWriter(int typeId) {
-        BinaryWriterExImpl res = new BinaryWriterExImpl(ctx, out, schema, handles());
-
-        res.typeId(typeId);
-
-        return res;
-    }
-
-    /**
-     * @return Portable context.
-     */
-    public PortableContext context() {
-        return ctx;
-    }
-}

http://git-wip-us.apache.org/repos/asf/ignite/blob/1dbf20e0/modules/core/src/main/java/org/apache/ignite/internal/portable/BinaryWriterHandles.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/portable/BinaryWriterHandles.java b/modules/core/src/main/java/org/apache/ignite/internal/portable/BinaryWriterHandles.java
deleted file mode 100644
index 2a47a2b..0000000
--- a/modules/core/src/main/java/org/apache/ignite/internal/portable/BinaryWriterHandles.java
+++ /dev/null
@@ -1,101 +0,0 @@
-/*
- * 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.portable;
-
-import java.util.IdentityHashMap;
-
-/**
- * Writer handles. Aimed to delay hash map allocation for some time until it is clearly evident that it is needed.
- */
-public class BinaryWriterHandles {
-    /** Value denoting null position. */
-    public static final int POS_NULL = -1;
-
-    /** Mode: empty. */
-    private static final int MODE_EMPTY = 0;
-
-    /** Mode: single object. */
-    private static final int MODE_SINGLE = 1;
-
-    /** Mode: multiple objects. */
-    private static final int MODE_MULTIPLE = 2;
-
-    /** Data. This is either an object or a map. */
-    private Object data;
-
-    /** Position.  */
-    private int singlePos;
-
-    /** Mode. */
-    private int mode = MODE_EMPTY;
-
-    /**
-     * Put object to registry and return previous position (if any).
-     *
-     * @param obj Object.
-     * @param pos Position.
-     * @return Old position.
-     */
-    @SuppressWarnings("unchecked")
-    public int put(Object obj, int pos) {
-        assert obj != null;
-        assert pos >= 0;
-
-        switch (mode) {
-            case MODE_EMPTY:
-                this.data = obj;
-                this.singlePos = pos;
-                this.mode = MODE_SINGLE;
-
-                return POS_NULL;
-
-            case MODE_SINGLE:
-                if (this.data == obj)
-                    return singlePos;
-                else {
-                    IdentityHashMap<Object, Integer> newData = new IdentityHashMap<>(2);
-
-                    newData.put(data, singlePos);
-                    newData.put(obj, pos);
-
-                    this.data = newData;
-                    this.singlePos = -1;
-                    this.mode = MODE_MULTIPLE;
-
-                    return POS_NULL;
-                }
-
-            default:
-                assert mode == MODE_MULTIPLE;
-
-                IdentityHashMap<Object, Integer> data0 = (IdentityHashMap<Object, Integer>)data;
-
-                Integer oldPos = data0.put(obj, pos);
-
-                if (oldPos != null) {
-                    // Restore initial position and return it.
-                    data0.put(obj, oldPos);
-
-                    return oldPos;
-                }
-                else
-                    return POS_NULL;
-
-        }
-    }
-}

http://git-wip-us.apache.org/repos/asf/ignite/blob/1dbf20e0/modules/core/src/main/java/org/apache/ignite/internal/portable/BinaryWriterSchemaHolder.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/portable/BinaryWriterSchemaHolder.java b/modules/core/src/main/java/org/apache/ignite/internal/portable/BinaryWriterSchemaHolder.java
deleted file mode 100644
index c7400d0..0000000
--- a/modules/core/src/main/java/org/apache/ignite/internal/portable/BinaryWriterSchemaHolder.java
+++ /dev/null
@@ -1,148 +0,0 @@
-/*
- * 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.portable;
-
-import org.apache.ignite.internal.portable.streams.PortableOutputStream;
-
-/**
- * Binary writer schema holder.
- */
-public class BinaryWriterSchemaHolder {
-    /** Maximum offset which fits in 1 byte. */
-    private static final int MAX_OFFSET_1 = 1 << 8;
-
-    /** Maximum offset which fits in 2 bytes. */
-    private static final int MAX_OFFSET_2 = 1 << 16;
-
-    /** Grow step. */
-    private static final int GROW_STEP = 64;
-
-    /** Data. */
-    private int[] data = new int[GROW_STEP];
-
-    /** Index. */
-    private int idx;
-
-    /**
-     * Push another frame.
-     *
-     * @param id Field ID.
-     * @param off Field offset.
-     */
-    public void push(int id, int off) {
-        if (idx == data.length) {
-            int[] data0 = new int[data.length + GROW_STEP];
-
-            System.arraycopy(data, 0, data0, 0, data.length);
-
-            data = data0;
-        }
-
-        data[idx] = id;
-        data[idx + 1] = off;
-
-        idx += 2;
-    }
-
-    /**
-     * Build the schema.
-     *
-     * @param builder Builder.
-     * @param fieldCnt Fields count.
-     */
-    public void build(PortableSchema.Builder builder, int fieldCnt) {
-        for (int curIdx = idx - fieldCnt * 2; curIdx < idx; curIdx += 2)
-            builder.addField(data[curIdx]);
-    }
-
-    /**
-     * Write collected frames and pop them.
-     *
-     * @param out Output stream.
-     * @param fieldCnt Count.
-     * @param compactFooter Whether footer should be written in compact form.
-     * @return Amount of bytes dedicated to each field offset. Could be 1, 2 or 4.
-     */
-    public int write(PortableOutputStream out, int fieldCnt, boolean compactFooter) {
-        int startIdx = idx - fieldCnt * 2;
-        assert startIdx >= 0;
-
-        // Ensure there are at least 8 bytes for each field to allow for unsafe writes.
-        out.unsafeEnsure(fieldCnt << 3);
-
-        int lastOffset = data[idx - 1];
-
-        int res;
-
-        if (compactFooter) {
-            if (lastOffset < MAX_OFFSET_1) {
-                for (int curIdx = startIdx + 1; curIdx < idx; curIdx += 2)
-                    out.unsafeWriteByte((byte)data[curIdx]);
-
-                res = PortableUtils.OFFSET_1;
-            }
-            else if (lastOffset < MAX_OFFSET_2) {
-                for (int curIdx = startIdx + 1; curIdx < idx; curIdx += 2)
-                    out.unsafeWriteShort((short) data[curIdx]);
-
-                res = PortableUtils.OFFSET_2;
-            }
-            else {
-                for (int curIdx = startIdx + 1; curIdx < idx; curIdx += 2)
-                    out.unsafeWriteInt(data[curIdx]);
-
-                res = PortableUtils.OFFSET_4;
-            }
-        }
-        else {
-            if (lastOffset < MAX_OFFSET_1) {
-                for (int curIdx = startIdx; curIdx < idx;) {
-                    out.unsafeWriteInt(data[curIdx++]);
-                    out.unsafeWriteByte((byte) data[curIdx++]);
-                }
-
-                res = PortableUtils.OFFSET_1;
-            }
-            else if (lastOffset < MAX_OFFSET_2) {
-                for (int curIdx = startIdx; curIdx < idx;) {
-                    out.unsafeWriteInt(data[curIdx++]);
-                    out.unsafeWriteShort((short) data[curIdx++]);
-                }
-
-                res = PortableUtils.OFFSET_2;
-            }
-            else {
-                for (int curIdx = startIdx; curIdx < idx;) {
-                    out.unsafeWriteInt(data[curIdx++]);
-                    out.unsafeWriteInt(data[curIdx++]);
-                }
-
-                res = PortableUtils.OFFSET_4;
-            }
-        }
-
-        return res;
-    }
-
-    /**
-     * Pop current object's frame.
-     */
-    public void pop(int fieldCnt) {
-        idx = idx - fieldCnt * 2;
-    }
-}

http://git-wip-us.apache.org/repos/asf/ignite/blob/1dbf20e0/modules/core/src/main/java/org/apache/ignite/internal/portable/GridPortableMarshaller.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/portable/GridPortableMarshaller.java b/modules/core/src/main/java/org/apache/ignite/internal/portable/GridPortableMarshaller.java
deleted file mode 100644
index 5063a1e..0000000
--- a/modules/core/src/main/java/org/apache/ignite/internal/portable/GridPortableMarshaller.java
+++ /dev/null
@@ -1,286 +0,0 @@
-/*
- * 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.portable;
-
-import org.apache.ignite.internal.portable.streams.PortableHeapInputStream;
-import org.apache.ignite.internal.portable.streams.PortableInputStream;
-import org.apache.ignite.internal.portable.streams.PortableOutputStream;
-import org.apache.ignite.binary.BinaryObjectException;
-import org.jetbrains.annotations.Nullable;
-
-/**
- * Portable objects marshaller.
- */
-public class GridPortableMarshaller {
-    /** */
-    public static final ThreadLocal<Boolean> KEEP_PORTABLES = new ThreadLocal<Boolean>() {
-        @Override protected Boolean initialValue() {
-            return true;
-        }
-    };
-
-    /** */
-    static final byte OPTM_MARSH = -2;
-
-    /** */
-    public static final byte BYTE = 1;
-
-    /** */
-    public static final byte SHORT = 2;
-
-    /** */
-    public static final byte INT = 3;
-
-    /** */
-    public static final byte LONG = 4;
-
-    /** */
-    public static final byte FLOAT = 5;
-
-    /** */
-    public static final byte DOUBLE = 6;
-
-    /** */
-    public static final byte CHAR = 7;
-
-    /** */
-    public static final byte BOOLEAN = 8;
-
-    /** */
-    public static final byte DECIMAL = 30;
-
-    /** */
-    public static final byte STRING = 9;
-
-    /** */
-    public static final byte UUID = 10;
-
-    /** */
-    public static final byte DATE = 11;
-
-    /** */
-    public static final byte BYTE_ARR = 12;
-
-    /** */
-    public static final byte SHORT_ARR = 13;
-
-    /** */
-    public static final byte INT_ARR = 14;
-
-    /** */
-    public static final byte LONG_ARR = 15;
-
-    /** */
-    public static final byte FLOAT_ARR = 16;
-
-    /** */
-    public static final byte DOUBLE_ARR = 17;
-
-    /** */
-    public static final byte CHAR_ARR = 18;
-
-    /** */
-    public static final byte BOOLEAN_ARR = 19;
-
-    /** */
-    public static final byte DECIMAL_ARR = 31;
-
-    /** */
-    public static final byte STRING_ARR = 20;
-
-    /** */
-    public static final byte UUID_ARR = 21;
-
-    /** */
-    public static final byte DATE_ARR = 22;
-
-    /** */
-    public static final byte OBJ_ARR = 23;
-
-    /** */
-    public static final byte COL = 24;
-
-    /** */
-    public static final byte MAP = 25;
-
-    /** */
-    public static final byte PORTABLE_OBJ = 27;
-
-    /** */
-    public static final byte ENUM = 28;
-
-    /** */
-    public static final byte ENUM_ARR = 29;
-
-    /** */
-    public static final byte CLASS = 32;
-
-    /** Timestamp. */
-    public static final byte TIMESTAMP = 33;
-
-    /** Timestamp array. */
-    public static final byte TIMESTAMP_ARR = 34;
-
-    /** */
-    public static final byte NULL = (byte)101;
-
-    /** */
-    public static final byte HANDLE = (byte)102;
-
-    /** */
-    public static final byte OBJ = (byte)103;
-
-    /** */
-    public static final byte USER_SET = -1;
-
-    /** */
-    public static final byte USER_COL = 0;
-
-    /** */
-    public static final byte ARR_LIST = 1;
-
-    /** */
-    public static final byte LINKED_LIST = 2;
-
-    /** */
-    public static final byte HASH_SET = 3;
-
-    /** */
-    public static final byte LINKED_HASH_SET = 4;
-
-    /** */
-    public static final byte HASH_MAP = 1;
-
-    /** */
-    public static final byte LINKED_HASH_MAP = 2;
-
-    /** */
-    public static final int OBJECT_TYPE_ID = -1;
-
-    /** */
-    public static final int UNREGISTERED_TYPE_ID = 0;
-
-    /** Protocol version. */
-    public static final byte PROTO_VER = 1;
-
-    /** Protocol version position. */
-    public static final int PROTO_VER_POS = 1;
-
-    /** Flags position in header. */
-    public static final int FLAGS_POS = 2;
-
-    /** */
-    public static final int TYPE_ID_POS = 4;
-
-    /** */
-    public static final int HASH_CODE_POS = 8;
-
-    /** */
-    public static final int TOTAL_LEN_POS = 12;
-
-    /** */
-    public static final int SCHEMA_ID_POS = 16;
-
-    /** Schema or raw offset position. */
-    public static final int SCHEMA_OR_RAW_OFF_POS = 20;
-
-    /** */
-    public static final byte DFLT_HDR_LEN = 24;
-
-    /** */
-    private final PortableContext ctx;
-
-    /**
-     * @param ctx Context.
-     */
-    public GridPortableMarshaller(PortableContext ctx) {
-        this.ctx = ctx;
-    }
-
-    /**
-     * @param obj Object to marshal.
-     * @return Byte array.
-     * @throws org.apache.ignite.binary.BinaryObjectException In case of error.
-     */
-    public byte[] marshal(@Nullable Object obj) throws BinaryObjectException {
-        if (obj == null)
-            return new byte[] { NULL };
-
-        try (BinaryWriterExImpl writer = new BinaryWriterExImpl(ctx)) {
-            writer.marshal(obj);
-
-            return writer.array();
-        }
-    }
-
-    /**
-     * @param bytes Bytes array.
-     * @return Portable object.
-     * @throws org.apache.ignite.binary.BinaryObjectException In case of error.
-     */
-    @SuppressWarnings("unchecked")
-    @Nullable public <T> T unmarshal(byte[] bytes, @Nullable ClassLoader clsLdr) throws BinaryObjectException {
-        assert bytes != null;
-
-        return (T)PortableUtils.unmarshal(PortableHeapInputStream.create(bytes, 0), ctx, clsLdr);
-    }
-
-    /**
-     * @param in Input stream.
-     * @return Portable object.
-     * @throws org.apache.ignite.binary.BinaryObjectException In case of error.
-     */
-    @SuppressWarnings("unchecked")
-    @Nullable public <T> T unmarshal(PortableInputStream in) throws BinaryObjectException {
-        return (T)PortableUtils.unmarshal(in, ctx, null);
-    }
-
-    /**
-     * @param arr Byte array.
-     * @param ldr Class loader.
-     * @return Deserialized object.
-     * @throws org.apache.ignite.binary.BinaryObjectException In case of error.
-     */
-    @SuppressWarnings("unchecked")
-    @Nullable public <T> T deserialize(byte[] arr, @Nullable ClassLoader ldr) throws BinaryObjectException {
-        assert arr != null;
-        assert arr.length > 0;
-
-        if (arr[0] == NULL)
-            return null;
-
-        return (T)new BinaryReaderExImpl(ctx, PortableHeapInputStream.create(arr, 0), ldr).deserialize();
-    }
-
-    /**
-     * Gets writer for the given output stream.
-     *
-     * @param out Output stream.
-     * @return Writer.
-     */
-    public BinaryWriterExImpl writer(PortableOutputStream out) {
-        return new BinaryWriterExImpl(ctx, out, BinaryThreadLocalContext.get().schemaHolder(), null);
-    }
-
-    /**
-     * @return Context.
-     */
-    public PortableContext context() {
-        return ctx;
-    }
-}


[50/59] [abbrv] ignite git commit: ignite-2065: rename "portable" classes to "binary"

Posted by ak...@apache.org.
http://git-wip-us.apache.org/repos/asf/ignite/blob/71ad9cea/modules/core/src/main/java/org/apache/ignite/internal/binary/PortableUtils.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/binary/PortableUtils.java b/modules/core/src/main/java/org/apache/ignite/internal/binary/PortableUtils.java
deleted file mode 100644
index 979b70c..0000000
--- a/modules/core/src/main/java/org/apache/ignite/internal/binary/PortableUtils.java
+++ /dev/null
@@ -1,1909 +0,0 @@
-/*
- * 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.binary;
-
-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;
-import org.apache.ignite.internal.binary.builder.PortableLazyValue;
-import org.apache.ignite.internal.binary.streams.PortableInputStream;
-import org.apache.ignite.internal.binary.builder.PortableLazyValue;
-import org.apache.ignite.internal.binary.streams.PortableInputStream;
-import org.apache.ignite.internal.util.typedef.F;
-import org.apache.ignite.internal.util.typedef.internal.U;
-import org.apache.ignite.lang.IgniteBiTuple;
-import org.jetbrains.annotations.Nullable;
-import org.jsr166.ConcurrentHashMap8;
-
-import java.io.ByteArrayInputStream;
-import java.io.Externalizable;
-import java.lang.reflect.Array;
-import java.math.BigDecimal;
-import java.math.BigInteger;
-import java.sql.Timestamp;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Date;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.LinkedHashMap;
-import java.util.LinkedHashSet;
-import java.util.LinkedList;
-import java.util.Map;
-import java.util.Set;
-import java.util.TreeMap;
-import java.util.TreeSet;
-import java.util.UUID;
-import java.util.concurrent.ConcurrentHashMap;
-import java.util.concurrent.ConcurrentSkipListSet;
-
-import static java.nio.charset.StandardCharsets.UTF_8;
-import static org.apache.ignite.internal.binary.GridPortableMarshaller.ARR_LIST;
-import static org.apache.ignite.internal.binary.GridPortableMarshaller.BOOLEAN;
-import static org.apache.ignite.internal.binary.GridPortableMarshaller.BOOLEAN_ARR;
-import static org.apache.ignite.internal.binary.GridPortableMarshaller.BYTE;
-import static org.apache.ignite.internal.binary.GridPortableMarshaller.BYTE_ARR;
-import static org.apache.ignite.internal.binary.GridPortableMarshaller.CHAR;
-import static org.apache.ignite.internal.binary.GridPortableMarshaller.CHAR_ARR;
-import static org.apache.ignite.internal.binary.GridPortableMarshaller.CLASS;
-import static org.apache.ignite.internal.binary.GridPortableMarshaller.COL;
-import static org.apache.ignite.internal.binary.GridPortableMarshaller.DATE;
-import static org.apache.ignite.internal.binary.GridPortableMarshaller.DATE_ARR;
-import static org.apache.ignite.internal.binary.GridPortableMarshaller.DECIMAL;
-import static org.apache.ignite.internal.binary.GridPortableMarshaller.DECIMAL_ARR;
-import static org.apache.ignite.internal.binary.GridPortableMarshaller.DOUBLE;
-import static org.apache.ignite.internal.binary.GridPortableMarshaller.DOUBLE_ARR;
-import static org.apache.ignite.internal.binary.GridPortableMarshaller.ENUM;
-import static org.apache.ignite.internal.binary.GridPortableMarshaller.ENUM_ARR;
-import static org.apache.ignite.internal.binary.GridPortableMarshaller.FLOAT;
-import static org.apache.ignite.internal.binary.GridPortableMarshaller.FLOAT_ARR;
-import static org.apache.ignite.internal.binary.GridPortableMarshaller.HANDLE;
-import static org.apache.ignite.internal.binary.GridPortableMarshaller.HASH_MAP;
-import static org.apache.ignite.internal.binary.GridPortableMarshaller.HASH_SET;
-import static org.apache.ignite.internal.binary.GridPortableMarshaller.INT;
-import static org.apache.ignite.internal.binary.GridPortableMarshaller.INT_ARR;
-import static org.apache.ignite.internal.binary.GridPortableMarshaller.LINKED_HASH_MAP;
-import static org.apache.ignite.internal.binary.GridPortableMarshaller.LINKED_HASH_SET;
-import static org.apache.ignite.internal.binary.GridPortableMarshaller.LINKED_LIST;
-import static org.apache.ignite.internal.binary.GridPortableMarshaller.LONG;
-import static org.apache.ignite.internal.binary.GridPortableMarshaller.LONG_ARR;
-import static org.apache.ignite.internal.binary.GridPortableMarshaller.MAP;
-import static org.apache.ignite.internal.binary.GridPortableMarshaller.NULL;
-import static org.apache.ignite.internal.binary.GridPortableMarshaller.OBJ;
-import static org.apache.ignite.internal.binary.GridPortableMarshaller.OBJECT_TYPE_ID;
-import static org.apache.ignite.internal.binary.GridPortableMarshaller.OBJ_ARR;
-import static org.apache.ignite.internal.binary.GridPortableMarshaller.OPTM_MARSH;
-import static org.apache.ignite.internal.binary.GridPortableMarshaller.PORTABLE_OBJ;
-import static org.apache.ignite.internal.binary.GridPortableMarshaller.PROTO_VER;
-import static org.apache.ignite.internal.binary.GridPortableMarshaller.SHORT;
-import static org.apache.ignite.internal.binary.GridPortableMarshaller.SHORT_ARR;
-import static org.apache.ignite.internal.binary.GridPortableMarshaller.STRING;
-import static org.apache.ignite.internal.binary.GridPortableMarshaller.STRING_ARR;
-import static org.apache.ignite.internal.binary.GridPortableMarshaller.TIMESTAMP;
-import static org.apache.ignite.internal.binary.GridPortableMarshaller.TIMESTAMP_ARR;
-import static org.apache.ignite.internal.binary.GridPortableMarshaller.UNREGISTERED_TYPE_ID;
-import static org.apache.ignite.internal.binary.GridPortableMarshaller.USER_COL;
-import static org.apache.ignite.internal.binary.GridPortableMarshaller.USER_SET;
-import static org.apache.ignite.internal.binary.GridPortableMarshaller.UUID;
-import static org.apache.ignite.internal.binary.GridPortableMarshaller.UUID_ARR;
-
-/**
- * Portable utils.
- */
-public class PortableUtils {
-    /** */
-    public static final Map<Class<?>, Byte> PLAIN_CLASS_TO_FLAG = new HashMap<>();
-
-    /** */
-    public static final Map<Byte, Class<?>> FLAG_TO_CLASS = new HashMap<>();
-
-    /** {@code true} if serialized value of this type cannot contain references to objects. */
-    private static final boolean[] PLAIN_TYPE_FLAG = new boolean[102];
-
-    /** Portable classes. */
-    private static final Collection<Class<?>> PORTABLE_CLS = new HashSet<>();
-
-    /** Flag: user type. */
-    public static final short FLAG_USR_TYP = 0x0001;
-
-    /** Flag: only raw data exists. */
-    public static final short FLAG_HAS_SCHEMA = 0x0002;
-
-    /** Flag indicating that object has raw data. */
-    public static final short FLAG_HAS_RAW = 0x0004;
-
-    /** Flag: offsets take 1 byte. */
-    public static final short FLAG_OFFSET_ONE_BYTE = 0x0008;
-
-    /** Flag: offsets take 2 bytes. */
-    public static final short FLAG_OFFSET_TWO_BYTES = 0x0010;
-
-    /** Flag: compact footer, no field IDs. */
-    public static final short FLAG_COMPACT_FOOTER = 0x0020;
-
-    /** Offset which fits into 1 byte. */
-    public static final int OFFSET_1 = 1;
-
-    /** Offset which fits into 2 bytes. */
-    public static final int OFFSET_2 = 2;
-
-    /** Offset which fits into 4 bytes. */
-    public static final int OFFSET_4 = 4;
-
-    /** Field ID length. */
-    public static final int FIELD_ID_LEN = 4;
-
-    /** Field type names. */
-    private static final String[] FIELD_TYPE_NAMES;
-
-    /** FNV1 hash offset basis. */
-    private static final int FNV1_OFFSET_BASIS = 0x811C9DC5;
-
-    /** FNV1 hash prime. */
-    private static final int FNV1_PRIME = 0x01000193;
-
-    /**
-     * Static class initializer.
-     */
-    static {
-        PLAIN_CLASS_TO_FLAG.put(Byte.class, GridPortableMarshaller.BYTE);
-        PLAIN_CLASS_TO_FLAG.put(Short.class, GridPortableMarshaller.SHORT);
-        PLAIN_CLASS_TO_FLAG.put(Integer.class, GridPortableMarshaller.INT);
-        PLAIN_CLASS_TO_FLAG.put(Long.class, GridPortableMarshaller.LONG);
-        PLAIN_CLASS_TO_FLAG.put(Float.class, GridPortableMarshaller.FLOAT);
-        PLAIN_CLASS_TO_FLAG.put(Double.class, GridPortableMarshaller.DOUBLE);
-        PLAIN_CLASS_TO_FLAG.put(Character.class, GridPortableMarshaller.CHAR);
-        PLAIN_CLASS_TO_FLAG.put(Boolean.class, GridPortableMarshaller.BOOLEAN);
-        PLAIN_CLASS_TO_FLAG.put(BigDecimal.class, GridPortableMarshaller.DECIMAL);
-        PLAIN_CLASS_TO_FLAG.put(String.class, GridPortableMarshaller.STRING);
-        PLAIN_CLASS_TO_FLAG.put(UUID.class, GridPortableMarshaller.UUID);
-        PLAIN_CLASS_TO_FLAG.put(Date.class, GridPortableMarshaller.DATE);
-        PLAIN_CLASS_TO_FLAG.put(Timestamp.class, GridPortableMarshaller.TIMESTAMP);
-
-        PLAIN_CLASS_TO_FLAG.put(byte[].class, GridPortableMarshaller.BYTE_ARR);
-        PLAIN_CLASS_TO_FLAG.put(short[].class, GridPortableMarshaller.SHORT_ARR);
-        PLAIN_CLASS_TO_FLAG.put(int[].class, GridPortableMarshaller.INT_ARR);
-        PLAIN_CLASS_TO_FLAG.put(long[].class, GridPortableMarshaller.LONG_ARR);
-        PLAIN_CLASS_TO_FLAG.put(float[].class, GridPortableMarshaller.FLOAT_ARR);
-        PLAIN_CLASS_TO_FLAG.put(double[].class, GridPortableMarshaller.DOUBLE_ARR);
-        PLAIN_CLASS_TO_FLAG.put(char[].class, GridPortableMarshaller.CHAR_ARR);
-        PLAIN_CLASS_TO_FLAG.put(boolean[].class, GridPortableMarshaller.BOOLEAN_ARR);
-        PLAIN_CLASS_TO_FLAG.put(BigDecimal[].class, GridPortableMarshaller.DECIMAL_ARR);
-        PLAIN_CLASS_TO_FLAG.put(String[].class, GridPortableMarshaller.STRING_ARR);
-        PLAIN_CLASS_TO_FLAG.put(UUID[].class, GridPortableMarshaller.UUID_ARR);
-        PLAIN_CLASS_TO_FLAG.put(Date[].class, GridPortableMarshaller.DATE_ARR);
-        PLAIN_CLASS_TO_FLAG.put(Timestamp[].class, GridPortableMarshaller.TIMESTAMP_ARR);
-
-        for (Map.Entry<Class<?>, Byte> entry : PLAIN_CLASS_TO_FLAG.entrySet())
-            FLAG_TO_CLASS.put(entry.getValue(), entry.getKey());
-
-        PLAIN_CLASS_TO_FLAG.put(byte.class, GridPortableMarshaller.BYTE);
-        PLAIN_CLASS_TO_FLAG.put(short.class, GridPortableMarshaller.SHORT);
-        PLAIN_CLASS_TO_FLAG.put(int.class, GridPortableMarshaller.INT);
-        PLAIN_CLASS_TO_FLAG.put(long.class, GridPortableMarshaller.LONG);
-        PLAIN_CLASS_TO_FLAG.put(float.class, GridPortableMarshaller.FLOAT);
-        PLAIN_CLASS_TO_FLAG.put(double.class, GridPortableMarshaller.DOUBLE);
-        PLAIN_CLASS_TO_FLAG.put(char.class, GridPortableMarshaller.CHAR);
-        PLAIN_CLASS_TO_FLAG.put(boolean.class, GridPortableMarshaller.BOOLEAN);
-
-        for (byte b : new byte[] {
-            GridPortableMarshaller.BYTE, GridPortableMarshaller.SHORT, GridPortableMarshaller.INT, GridPortableMarshaller.LONG, GridPortableMarshaller.FLOAT, GridPortableMarshaller.DOUBLE,
-            GridPortableMarshaller.CHAR, GridPortableMarshaller.BOOLEAN, GridPortableMarshaller.DECIMAL, GridPortableMarshaller.STRING, GridPortableMarshaller.UUID, GridPortableMarshaller.DATE, GridPortableMarshaller.TIMESTAMP,
-            GridPortableMarshaller.BYTE_ARR, GridPortableMarshaller.SHORT_ARR, GridPortableMarshaller.INT_ARR, GridPortableMarshaller.LONG_ARR, GridPortableMarshaller.FLOAT_ARR, GridPortableMarshaller.DOUBLE_ARR,
-            GridPortableMarshaller.CHAR_ARR, GridPortableMarshaller.BOOLEAN_ARR, GridPortableMarshaller.DECIMAL_ARR, GridPortableMarshaller.STRING_ARR, GridPortableMarshaller.UUID_ARR, GridPortableMarshaller.DATE_ARR, GridPortableMarshaller.TIMESTAMP_ARR,
-            GridPortableMarshaller.ENUM, GridPortableMarshaller.ENUM_ARR, GridPortableMarshaller.NULL}) {
-
-            PLAIN_TYPE_FLAG[b] = true;
-        }
-
-        PORTABLE_CLS.add(Byte.class);
-        PORTABLE_CLS.add(Short.class);
-        PORTABLE_CLS.add(Integer.class);
-        PORTABLE_CLS.add(Long.class);
-        PORTABLE_CLS.add(Float.class);
-        PORTABLE_CLS.add(Double.class);
-        PORTABLE_CLS.add(Character.class);
-        PORTABLE_CLS.add(Boolean.class);
-        PORTABLE_CLS.add(String.class);
-        PORTABLE_CLS.add(UUID.class);
-        PORTABLE_CLS.add(Date.class);
-        PORTABLE_CLS.add(Timestamp.class);
-        PORTABLE_CLS.add(BigDecimal.class);
-        PORTABLE_CLS.add(byte[].class);
-        PORTABLE_CLS.add(short[].class);
-        PORTABLE_CLS.add(int[].class);
-        PORTABLE_CLS.add(long[].class);
-        PORTABLE_CLS.add(float[].class);
-        PORTABLE_CLS.add(double[].class);
-        PORTABLE_CLS.add(char[].class);
-        PORTABLE_CLS.add(boolean[].class);
-        PORTABLE_CLS.add(String[].class);
-        PORTABLE_CLS.add(UUID[].class);
-        PORTABLE_CLS.add(Date[].class);
-        PORTABLE_CLS.add(Timestamp[].class);
-        PORTABLE_CLS.add(BigDecimal[].class);
-
-        FIELD_TYPE_NAMES = new String[104];
-
-        FIELD_TYPE_NAMES[GridPortableMarshaller.BYTE] = "byte";
-        FIELD_TYPE_NAMES[GridPortableMarshaller.SHORT] = "short";
-        FIELD_TYPE_NAMES[GridPortableMarshaller.INT] = "int";
-        FIELD_TYPE_NAMES[GridPortableMarshaller.LONG] = "long";
-        FIELD_TYPE_NAMES[GridPortableMarshaller.BOOLEAN] = "boolean";
-        FIELD_TYPE_NAMES[GridPortableMarshaller.FLOAT] = "float";
-        FIELD_TYPE_NAMES[GridPortableMarshaller.DOUBLE] = "double";
-        FIELD_TYPE_NAMES[GridPortableMarshaller.CHAR] = "char";
-        FIELD_TYPE_NAMES[GridPortableMarshaller.UUID] = "UUID";
-        FIELD_TYPE_NAMES[GridPortableMarshaller.DECIMAL] = "decimal";
-        FIELD_TYPE_NAMES[GridPortableMarshaller.STRING] = "String";
-        FIELD_TYPE_NAMES[GridPortableMarshaller.DATE] = "Date";
-        FIELD_TYPE_NAMES[GridPortableMarshaller.TIMESTAMP] = "Timestamp";
-        FIELD_TYPE_NAMES[GridPortableMarshaller.ENUM] = "Enum";
-        FIELD_TYPE_NAMES[GridPortableMarshaller.OBJ] = "Object";
-        FIELD_TYPE_NAMES[GridPortableMarshaller.PORTABLE_OBJ] = "Object";
-        FIELD_TYPE_NAMES[GridPortableMarshaller.COL] = "Collection";
-        FIELD_TYPE_NAMES[GridPortableMarshaller.MAP] = "Map";
-        FIELD_TYPE_NAMES[GridPortableMarshaller.CLASS] = "Class";
-        FIELD_TYPE_NAMES[GridPortableMarshaller.BYTE_ARR] = "byte[]";
-        FIELD_TYPE_NAMES[GridPortableMarshaller.SHORT_ARR] = "short[]";
-        FIELD_TYPE_NAMES[GridPortableMarshaller.INT_ARR] = "int[]";
-        FIELD_TYPE_NAMES[GridPortableMarshaller.LONG_ARR] = "long[]";
-        FIELD_TYPE_NAMES[GridPortableMarshaller.BOOLEAN_ARR] = "boolean[]";
-        FIELD_TYPE_NAMES[GridPortableMarshaller.FLOAT_ARR] = "float[]";
-        FIELD_TYPE_NAMES[GridPortableMarshaller.DOUBLE_ARR] = "double[]";
-        FIELD_TYPE_NAMES[GridPortableMarshaller.CHAR_ARR] = "char[]";
-        FIELD_TYPE_NAMES[GridPortableMarshaller.UUID_ARR] = "UUID[]";
-        FIELD_TYPE_NAMES[GridPortableMarshaller.DECIMAL_ARR] = "decimal[]";
-        FIELD_TYPE_NAMES[GridPortableMarshaller.STRING_ARR] = "String[]";
-        FIELD_TYPE_NAMES[GridPortableMarshaller.DATE_ARR] = "Date[]";
-        FIELD_TYPE_NAMES[GridPortableMarshaller.TIMESTAMP_ARR] = "Timestamp[]";
-        FIELD_TYPE_NAMES[GridPortableMarshaller.OBJ_ARR] = "Object[]";
-        FIELD_TYPE_NAMES[GridPortableMarshaller.ENUM_ARR] = "Enum[]";
-    }
-
-    /**
-     * Check if user type flag is set.
-     *
-     * @param flags Flags.
-     * @return {@code True} if set.
-     */
-    public static boolean isUserType(short flags) {
-        return isFlagSet(flags, FLAG_USR_TYP);
-    }
-
-    /**
-     * Check if raw-only flag is set.
-     *
-     * @param flags Flags.
-     * @return {@code True} if set.
-     */
-    public static boolean hasSchema(short flags) {
-        return isFlagSet(flags, FLAG_HAS_SCHEMA);
-    }
-
-    /**
-     * Check if raw-only flag is set.
-     *
-     * @param flags Flags.
-     * @return {@code True} if set.
-     */
-    public static boolean hasRaw(short flags) {
-        return isFlagSet(flags, FLAG_HAS_RAW);
-    }
-
-    /**
-     * Check if "no-field-ids" flag is set.
-     *
-     * @param flags Flags.
-     * @return {@code True} if set.
-     */
-    public static boolean isCompactFooter(short flags) {
-        return isFlagSet(flags, FLAG_COMPACT_FOOTER);
-    }
-
-    /**
-     * Check whether particular flag is set.
-     *
-     * @param flags Flags.
-     * @param flag Flag.
-     * @return {@code True} if flag is set in flags.
-     */
-    private static boolean isFlagSet(short flags, short flag) {
-        return (flags & flag) == flag;
-    }
-
-    /**
-     * Schema initial ID.
-     *
-     * @return ID.
-     */
-    public static int schemaInitialId() {
-        return FNV1_OFFSET_BASIS;
-    }
-
-    /**
-     * Update schema ID when new field is added.
-     *
-     * @param schemaId Current schema ID.
-     * @param fieldId Field ID.
-     * @return New schema ID.
-     */
-    public static int updateSchemaId(int schemaId, int fieldId) {
-        schemaId = schemaId ^ (fieldId & 0xFF);
-        schemaId = schemaId * FNV1_PRIME;
-        schemaId = schemaId ^ ((fieldId >> 8) & 0xFF);
-        schemaId = schemaId * FNV1_PRIME;
-        schemaId = schemaId ^ ((fieldId >> 16) & 0xFF);
-        schemaId = schemaId * FNV1_PRIME;
-        schemaId = schemaId ^ ((fieldId >> 24) & 0xFF);
-        schemaId = schemaId * FNV1_PRIME;
-
-        return schemaId;
-    }
-
-    /**
-     * @param typeName Field type name.
-     * @return Field type ID;
-     */
-    @SuppressWarnings("StringEquality")
-    public static int fieldTypeId(String typeName) {
-        for (int i = 0; i < FIELD_TYPE_NAMES.length; i++) {
-            String typeName0 = FIELD_TYPE_NAMES[i];
-
-            if (typeName.equals(typeName0))
-                return i;
-        }
-
-        throw new IllegalArgumentException("Invalid metadata type name: " + typeName);
-    }
-
-    /**
-     * @param typeId Field type ID.
-     * @return Field type name.
-     */
-    public static String fieldTypeName(int typeId) {
-        assert typeId >= 0 && typeId < FIELD_TYPE_NAMES.length : typeId;
-
-        String typeName = FIELD_TYPE_NAMES[typeId];
-
-        assert typeName != null : typeId;
-
-        return typeName;
-    }
-
-    /**
-     * Write value with flag. e.g. writePlainObject(writer, (byte)77) will write two byte: {BYTE, 77}.
-     *
-     * @param writer W
-     * @param val Value.
-     */
-    public static void writePlainObject(BinaryWriterExImpl writer, Object val) {
-        Byte flag = PLAIN_CLASS_TO_FLAG.get(val.getClass());
-
-        if (flag == null)
-            throw new IllegalArgumentException("Can't write object with type: " + val.getClass());
-
-        switch (flag) {
-            case GridPortableMarshaller.BYTE:
-                writer.writeByte(flag);
-                writer.writeByte((Byte)val);
-
-                break;
-
-            case GridPortableMarshaller.SHORT:
-                writer.writeByte(flag);
-                writer.writeShort((Short)val);
-
-                break;
-
-            case GridPortableMarshaller.INT:
-                writer.writeByte(flag);
-                writer.writeInt((Integer)val);
-
-                break;
-
-            case GridPortableMarshaller.LONG:
-                writer.writeByte(flag);
-                writer.writeLong((Long)val);
-
-                break;
-
-            case GridPortableMarshaller.FLOAT:
-                writer.writeByte(flag);
-                writer.writeFloat((Float)val);
-
-                break;
-
-            case GridPortableMarshaller.DOUBLE:
-                writer.writeByte(flag);
-                writer.writeDouble((Double)val);
-
-                break;
-
-            case GridPortableMarshaller.CHAR:
-                writer.writeByte(flag);
-                writer.writeChar((Character)val);
-
-                break;
-
-            case GridPortableMarshaller.BOOLEAN:
-                writer.writeByte(flag);
-                writer.writeBoolean((Boolean)val);
-
-                break;
-
-            case GridPortableMarshaller.DECIMAL:
-                writer.doWriteDecimal((BigDecimal)val);
-
-                break;
-
-            case GridPortableMarshaller.STRING:
-                writer.doWriteString((String)val);
-
-                break;
-
-            case GridPortableMarshaller.UUID:
-                writer.doWriteUuid((UUID)val);
-
-                break;
-
-            case GridPortableMarshaller.DATE:
-                writer.doWriteDate((Date)val);
-
-                break;
-
-            case GridPortableMarshaller.TIMESTAMP:
-                writer.doWriteTimestamp((Timestamp) val);
-
-                break;
-
-            case GridPortableMarshaller.BYTE_ARR:
-                writer.doWriteByteArray((byte[])val);
-
-                break;
-
-            case GridPortableMarshaller.SHORT_ARR:
-                writer.doWriteShortArray((short[])val);
-
-                break;
-
-            case GridPortableMarshaller.INT_ARR:
-                writer.doWriteIntArray((int[])val);
-
-                break;
-
-            case GridPortableMarshaller.LONG_ARR:
-                writer.doWriteLongArray((long[])val);
-
-                break;
-
-            case GridPortableMarshaller.FLOAT_ARR:
-                writer.doWriteFloatArray((float[])val);
-
-                break;
-
-            case GridPortableMarshaller.DOUBLE_ARR:
-                writer.doWriteDoubleArray((double[])val);
-
-                break;
-
-            case GridPortableMarshaller.CHAR_ARR:
-                writer.doWriteCharArray((char[])val);
-
-                break;
-
-            case GridPortableMarshaller.BOOLEAN_ARR:
-                writer.doWriteBooleanArray((boolean[])val);
-
-                break;
-
-            case GridPortableMarshaller.DECIMAL_ARR:
-                writer.doWriteDecimalArray((BigDecimal[])val);
-
-                break;
-
-            case GridPortableMarshaller.STRING_ARR:
-                writer.doWriteStringArray((String[])val);
-
-                break;
-
-            case GridPortableMarshaller.UUID_ARR:
-                writer.doWriteUuidArray((UUID[])val);
-
-                break;
-
-            case GridPortableMarshaller.DATE_ARR:
-                writer.doWriteDateArray((Date[])val);
-
-                break;
-
-            case GridPortableMarshaller.TIMESTAMP_ARR:
-                writer.doWriteTimestampArray((Timestamp[])val);
-
-                break;
-
-            default:
-                throw new IllegalArgumentException("Can't write object with type: " + val.getClass());
-        }
-    }
-
-    /**
-     * @param obj Value to unwrap.
-     * @return Unwrapped value.
-     */
-    public static Object unwrapLazy(@Nullable Object obj) {
-        if (obj instanceof PortableLazyValue)
-            return ((PortableLazyValue)obj).value();
-
-        return obj;
-    }
-
-    /**
-     * @param delegate Iterator to delegate.
-     * @return New iterator.
-     */
-    public static Iterator<Object> unwrapLazyIterator(final Iterator<Object> delegate) {
-        return new Iterator<Object>() {
-            @Override public boolean hasNext() {
-                return delegate.hasNext();
-            }
-
-            @Override public Object next() {
-                return unwrapLazy(delegate.next());
-            }
-
-            @Override public void remove() {
-                delegate.remove();
-            }
-        };
-    }
-
-    /**
-     * @return {@code true} if content of serialized value cannot contain references to other object.
-     */
-    public static boolean isPlainType(int type) {
-        return type > 0 && type < PLAIN_TYPE_FLAG.length && PLAIN_TYPE_FLAG[type];
-    }
-
-    /**
-     * Checks whether an array type values can or can not contain references to other object.
-     *
-     * @param type Array type.
-     * @return {@code true} if content of serialized array value cannot contain references to other object.
-     */
-    public static boolean isPlainArrayType(int type) {
-        return (type >= GridPortableMarshaller.BYTE_ARR && type <= GridPortableMarshaller.DATE_ARR) || type == GridPortableMarshaller.TIMESTAMP_ARR;
-    }
-
-    /**
-     * @param cls Class.
-     * @return Portable field type.
-     */
-    public static byte typeByClass(Class<?> cls) {
-        Byte type = PLAIN_CLASS_TO_FLAG.get(cls);
-
-        if (type != null)
-            return type;
-
-        if (cls.isEnum())
-            return GridPortableMarshaller.ENUM;
-
-        if (cls.isArray())
-            return cls.getComponentType().isEnum() || cls.getComponentType() == Enum.class ? GridPortableMarshaller.ENUM_ARR : GridPortableMarshaller.OBJ_ARR;
-
-        if (isSpecialCollection(cls))
-            return GridPortableMarshaller.COL;
-
-        if (isSpecialMap(cls))
-            return GridPortableMarshaller.MAP;
-
-        return GridPortableMarshaller.OBJ;
-    }
-
-    /**
-     * Tells whether provided type is portable.
-     *
-     * @param cls Class to check.
-     * @return Whether type is portable.
-     */
-    public static boolean isPortableType(Class<?> cls) {
-        assert cls != null;
-
-        return BinaryObject.class.isAssignableFrom(cls) ||
-            PORTABLE_CLS.contains(cls) ||
-            cls.isEnum() ||
-            (cls.isArray() && cls.getComponentType().isEnum());
-    }
-
-    /**
-     * Attempts to create a new map of the same type as {@code map} has. Otherwise returns new {@code HashMap} instance.
-     *
-     * @param map Original map.
-     * @return New map.
-     */
-    public static <K, V> Map<K, V> newMap(Map<K, V> map) {
-        if (map instanceof LinkedHashMap)
-            return U.newLinkedHashMap(map.size());
-        else if (map instanceof TreeMap)
-            return new TreeMap<>(((TreeMap<Object, Object>)map).comparator());
-        else if (map instanceof ConcurrentHashMap8)
-            return new ConcurrentHashMap8<>(U.capacity(map.size()));
-        else if (map instanceof ConcurrentHashMap)
-            return new ConcurrentHashMap<>(U.capacity(map.size()));
-
-        return U.newHashMap(map.size());
-    }
-
-    /**
-     * Attempts to create a new set of the same type as {@code set} has. Otherwise returns new {@code HashSet} instance.
-     *
-     * @param set Original set.
-     * @return New set.
-     */
-    public static <V> Set<V> newSet(Set<V> set) {
-        if (set instanceof LinkedHashSet)
-            return U.newLinkedHashSet(set.size());
-        else if (set instanceof TreeSet)
-            return new TreeSet<>(((TreeSet<Object>)set).comparator());
-        else if (set instanceof ConcurrentSkipListSet)
-            return new ConcurrentSkipListSet<>(((ConcurrentSkipListSet<Object>)set).comparator());
-
-        return U.newHashSet(set.size());
-    }
-
-    /**
-     * Check protocol version.
-     *
-     * @param protoVer Protocol version.
-     */
-    public static void checkProtocolVersion(byte protoVer) {
-        if (GridPortableMarshaller.PROTO_VER != protoVer)
-            throw new BinaryObjectException("Unsupported protocol version: " + protoVer);
-    }
-
-    /**
-     * Get portable object length.
-     *
-     * @param in Input stream.
-     * @param start Start position.
-     * @return Length.
-     */
-    public static int length(PortablePositionReadable in, int start) {
-        return in.readIntPositioned(start + GridPortableMarshaller.TOTAL_LEN_POS);
-    }
-
-    /**
-     * Get footer start of the object.
-     *
-     * @param in Input stream.
-     * @param start Object start position inside the stream.
-     * @return Footer start.
-     */
-    public static int footerStartRelative(PortablePositionReadable in, int start) {
-        short flags = in.readShortPositioned(start + GridPortableMarshaller.FLAGS_POS);
-
-        if (hasSchema(flags))
-            // Schema exists, use offset.
-            return in.readIntPositioned(start + GridPortableMarshaller.SCHEMA_OR_RAW_OFF_POS);
-        else
-            // No schema, footer start equals to object end.
-            return length(in, start);
-    }
-
-    /**
-     * Get object's footer.
-     *
-     * @param in Input stream.
-     * @param start Start position.
-     * @return Footer start.
-     */
-    public static int footerStartAbsolute(PortablePositionReadable in, int start) {
-        return footerStartRelative(in, start) + start;
-    }
-
-    /**
-     * Get object's footer.
-     *
-     * @param in Input stream.
-     * @param start Start position.
-     * @return Footer.
-     */
-    public static IgniteBiTuple<Integer, Integer> footerAbsolute(PortablePositionReadable in, int start) {
-        short flags = in.readShortPositioned(start + GridPortableMarshaller.FLAGS_POS);
-
-        int footerEnd = length(in, start);
-
-        if (hasSchema(flags)) {
-            // Schema exists.
-            int footerStart = in.readIntPositioned(start + GridPortableMarshaller.SCHEMA_OR_RAW_OFF_POS);
-
-            if (hasRaw(flags))
-                footerEnd -= 4;
-
-            assert footerStart <= footerEnd;
-
-            return F.t(start + footerStart, start + footerEnd);
-        }
-        else
-            // No schema.
-            return F.t(start + footerEnd, start + footerEnd);
-    }
-
-    /**
-     * Get relative raw offset of the object.
-     *
-     * @param in Input stream.
-     * @param start Object start position inside the stream.
-     * @return Raw offset.
-     */
-    public static int rawOffsetRelative(PortablePositionReadable in, int start) {
-        short flags = in.readShortPositioned(start + GridPortableMarshaller.FLAGS_POS);
-
-        int len = length(in, start);
-
-        if (hasSchema(flags)){
-            // Schema exists.
-            if (hasRaw(flags))
-                // Raw offset is set, it is at the very end of the object.
-                return in.readIntPositioned(start + len - 4);
-            else
-                // Raw offset is not set, so just return schema offset.
-                return in.readIntPositioned(start + GridPortableMarshaller.SCHEMA_OR_RAW_OFF_POS);
-        }
-        else
-            // No schema, raw offset is located on schema offset position.
-            return in.readIntPositioned(start + GridPortableMarshaller.SCHEMA_OR_RAW_OFF_POS);
-    }
-
-    /**
-     * Get absolute raw offset of the object.
-     *
-     * @param in Input stream.
-     * @param start Object start position inside the stream.
-     * @return Raw offset.
-     */
-    public static int rawOffsetAbsolute(PortablePositionReadable in, int start) {
-        return start + rawOffsetRelative(in, start);
-    }
-
-    /**
-     * Get offset length for the given flags.
-     *
-     * @param flags Flags.
-     * @return Offset size.
-     */
-    public static int fieldOffsetLength(short flags) {
-        if ((flags & FLAG_OFFSET_ONE_BYTE) == FLAG_OFFSET_ONE_BYTE)
-            return OFFSET_1;
-        else if ((flags & FLAG_OFFSET_TWO_BYTES) == FLAG_OFFSET_TWO_BYTES)
-            return OFFSET_2;
-        else
-            return OFFSET_4;
-    }
-
-    /**
-     * Get field ID length.
-     *
-     * @param flags Flags.
-     * @return Field ID length.
-     */
-    public static int fieldIdLength(short flags) {
-        return isCompactFooter(flags) ? 0 : FIELD_ID_LEN;
-    }
-
-    /**
-     * Get relative field offset.
-     *
-     * @param stream Stream.
-     * @param pos Position.
-     * @param fieldOffsetSize Field offset size.
-     * @return Relative field offset.
-     */
-    public static int fieldOffsetRelative(PortablePositionReadable stream, int pos, int fieldOffsetSize) {
-        int res;
-
-        if (fieldOffsetSize == OFFSET_1)
-            res = (int)stream.readBytePositioned(pos) & 0xFF;
-        else if (fieldOffsetSize == OFFSET_2)
-            res = (int)stream.readShortPositioned(pos) & 0xFFFF;
-        else
-            res = stream.readIntPositioned(pos);
-
-        return res;
-    }
-
-    /**
-     * Merge old and new metas.
-     *
-     * @param oldMeta Old meta.
-     * @param newMeta New meta.
-     * @return New meta if old meta was null, old meta if no changes detected, merged meta otherwise.
-     * @throws BinaryObjectException If merge failed due to metadata conflict.
-     */
-    public static BinaryMetadata mergeMetadata(@Nullable BinaryMetadata oldMeta, BinaryMetadata newMeta) {
-        assert newMeta != null;
-
-        if (oldMeta == null)
-            return newMeta;
-        else {
-            assert oldMeta.typeId() == newMeta.typeId();
-
-            // Check type name.
-            if (!F.eq(oldMeta.typeName(), newMeta.typeName())) {
-                throw new BinaryObjectException(
-                    "Two portable types have duplicate type ID [" + "typeId=" + oldMeta.typeId() +
-                        ", typeName1=" + oldMeta.typeName() + ", typeName2=" + newMeta.typeName() + ']'
-                );
-            }
-
-            // Check affinity field names.
-            if (!F.eq(oldMeta.affinityKeyFieldName(), newMeta.affinityKeyFieldName())) {
-                throw new BinaryObjectException(
-                    "Binary type has different affinity key fields [" + "typeName=" + newMeta.typeName() +
-                        ", affKeyFieldName1=" + oldMeta.affinityKeyFieldName() +
-                        ", affKeyFieldName2=" + newMeta.affinityKeyFieldName() + ']'
-                );
-            }
-
-            // Check enum flag.
-            if (oldMeta.isEnum() != newMeta.isEnum()) {
-                if (oldMeta.isEnum())
-                    throw new BinaryObjectException("Binary type already registered as enum: " +
-                        newMeta.typeName());
-                else
-                    throw new BinaryObjectException("Binary type already registered as non-enum: " +
-                        newMeta.typeName());
-            }
-
-            // Check and merge fields.
-            boolean changed = false;
-
-            Map<String, Integer> mergedFields = new HashMap<>(oldMeta.fieldsMap());
-            Map<String, Integer> newFields = newMeta.fieldsMap();
-
-            for (Map.Entry<String, Integer> newField : newFields.entrySet()) {
-                Integer oldFieldType = mergedFields.put(newField.getKey(), newField.getValue());
-
-                if (oldFieldType == null)
-                    changed = true;
-                else if (!F.eq(oldFieldType, newField.getValue())) {
-                    throw new BinaryObjectException(
-                        "Binary type has different field types [" + "typeName=" + oldMeta.typeName() +
-                            ", fieldName=" + newField.getKey() +
-                            ", fieldTypeName1=" + fieldTypeName(oldFieldType) +
-                            ", fieldTypeName2=" + fieldTypeName(newField.getValue()) + ']'
-                    );
-                }
-            }
-
-            // Check and merge schemas.
-            Collection<PortableSchema> mergedSchemas = new HashSet<>(oldMeta.schemas());
-
-            for (PortableSchema newSchema : newMeta.schemas()) {
-                if (mergedSchemas.add(newSchema))
-                    changed = true;
-            }
-
-            // Return either old meta if no changes detected, or new merged meta.
-            return changed ? new BinaryMetadata(oldMeta.typeId(), oldMeta.typeName(), mergedFields,
-                oldMeta.affinityKeyFieldName(), mergedSchemas, oldMeta.isEnum()) : oldMeta;
-        }
-    }
-
-    /**
-     * @param cls Class.
-     * @return Mode.
-     */
-    @SuppressWarnings("IfMayBeConditional")
-    public static BinaryWriteMode mode(Class<?> cls) {
-        assert cls != null;
-
-        /** Primitives. */
-        if (cls == byte.class)
-            return BinaryWriteMode.P_BYTE;
-        else if (cls == boolean.class)
-            return BinaryWriteMode.P_BOOLEAN;
-        else if (cls == short.class)
-            return BinaryWriteMode.P_SHORT;
-        else if (cls == char.class)
-            return BinaryWriteMode.P_CHAR;
-        else if (cls == int.class)
-            return BinaryWriteMode.P_INT;
-        else if (cls == long.class)
-            return BinaryWriteMode.P_LONG;
-        else if (cls == float.class)
-            return BinaryWriteMode.P_FLOAT;
-        else if (cls == double.class)
-            return BinaryWriteMode.P_DOUBLE;
-
-        /** Boxed primitives. */
-        else if (cls == Byte.class)
-            return BinaryWriteMode.BYTE;
-        else if (cls == Boolean.class)
-            return BinaryWriteMode.BOOLEAN;
-        else if (cls == Short.class)
-            return BinaryWriteMode.SHORT;
-        else if (cls == Character.class)
-            return BinaryWriteMode.CHAR;
-        else if (cls == Integer.class)
-            return BinaryWriteMode.INT;
-        else if (cls == Long.class)
-            return BinaryWriteMode.LONG;
-        else if (cls == Float.class)
-            return BinaryWriteMode.FLOAT;
-        else if (cls == Double.class)
-            return BinaryWriteMode.DOUBLE;
-
-        /** The rest types. */
-        else if (cls == BigDecimal.class)
-            return BinaryWriteMode.DECIMAL;
-        else if (cls == String.class)
-            return BinaryWriteMode.STRING;
-        else if (cls == UUID.class)
-            return BinaryWriteMode.UUID;
-        else if (cls == Date.class)
-            return BinaryWriteMode.DATE;
-        else if (cls == Timestamp.class)
-            return BinaryWriteMode.TIMESTAMP;
-        else if (cls == byte[].class)
-            return BinaryWriteMode.BYTE_ARR;
-        else if (cls == short[].class)
-            return BinaryWriteMode.SHORT_ARR;
-        else if (cls == int[].class)
-            return BinaryWriteMode.INT_ARR;
-        else if (cls == long[].class)
-            return BinaryWriteMode.LONG_ARR;
-        else if (cls == float[].class)
-            return BinaryWriteMode.FLOAT_ARR;
-        else if (cls == double[].class)
-            return BinaryWriteMode.DOUBLE_ARR;
-        else if (cls == char[].class)
-            return BinaryWriteMode.CHAR_ARR;
-        else if (cls == boolean[].class)
-            return BinaryWriteMode.BOOLEAN_ARR;
-        else if (cls == BigDecimal[].class)
-            return BinaryWriteMode.DECIMAL_ARR;
-        else if (cls == String[].class)
-            return BinaryWriteMode.STRING_ARR;
-        else if (cls == UUID[].class)
-            return BinaryWriteMode.UUID_ARR;
-        else if (cls == Date[].class)
-            return BinaryWriteMode.DATE_ARR;
-        else if (cls == Timestamp[].class)
-            return BinaryWriteMode.TIMESTAMP_ARR;
-        else if (cls.isArray())
-            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))
-            return BinaryWriteMode.PORTABLE;
-        else if (Externalizable.class.isAssignableFrom(cls))
-            return BinaryWriteMode.EXTERNALIZABLE;
-        else if (isSpecialCollection(cls))
-            return BinaryWriteMode.COL;
-        else if (isSpecialMap(cls))
-            return BinaryWriteMode.MAP;
-        else if (cls.isEnum())
-            return BinaryWriteMode.ENUM;
-        else if (cls == Class.class)
-            return BinaryWriteMode.CLASS;
-        else
-            return BinaryWriteMode.OBJECT;
-    }
-
-    /**
-     * 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) {
-        int len = in.readInt();
-
-        return in.readByteArray(len);
-    }
-
-    /**
-     * @return Value.
-     */
-    public static boolean[] doReadBooleanArray(PortableInputStream in) {
-        int len = in.readInt();
-
-        return in.readBooleanArray(len);
-    }
-
-    /**
-     * @return Value.
-     */
-    public static short[] doReadShortArray(PortableInputStream in) {
-        int len = in.readInt();
-
-        return in.readShortArray(len);
-    }
-
-    /**
-     * @return Value.
-     */
-    public static char[] doReadCharArray(PortableInputStream in) {
-        int len = in.readInt();
-
-        return in.readCharArray(len);
-    }
-
-    /**
-     * @return Value.
-     */
-    public static int[] doReadIntArray(PortableInputStream in) {
-        int len = in.readInt();
-
-        return in.readIntArray(len);
-    }
-
-    /**
-     * @return Value.
-     */
-    public static long[] doReadLongArray(PortableInputStream in) {
-        int len = in.readInt();
-
-        return in.readLongArray(len);
-    }
-
-    /**
-     * @return Value.
-     */
-    public static float[] doReadFloatArray(PortableInputStream in) {
-        int len = in.readInt();
-
-        return in.readFloatArray(len);
-    }
-
-    /**
-     * @return Value.
-     */
-    public static double[] doReadDoubleArray(PortableInputStream in) {
-        int len = in.readInt();
-
-        return in.readDoubleArray(len);
-    }
-
-    /**
-     * @return Value.
-     */
-    public static BigDecimal doReadDecimal(PortableInputStream in) {
-        int scale = in.readInt();
-        byte[] mag = doReadByteArray(in);
-
-        BigInteger intVal = new BigInteger(mag);
-
-        if (scale < 0) {
-            scale &= 0x7FFFFFFF;
-
-            intVal = intVal.negate();
-        }
-
-        return new BigDecimal(intVal, scale);
-    }
-
-    /**
-     * @return Value.
-     */
-    public static String doReadString(PortableInputStream in) {
-        if (!in.hasArray())
-            return new String(doReadByteArray(in), UTF_8);
-
-        int strLen = in.readInt();
-
-        int pos = in.position();
-
-        // String will copy necessary array part for us.
-        String res = new String(in.array(), pos, strLen, UTF_8);
-
-        in.position(pos + strLen);
-
-        return res;
-    }
-
-    /**
-     * @return Value.
-     */
-    public static UUID doReadUuid(PortableInputStream in) {
-        return new UUID(in.readLong(), in.readLong());
-    }
-
-    /**
-     * @return Value.
-     */
-    public static Date doReadDate(PortableInputStream in) {
-        long time = in.readLong();
-
-        return new Date(time);
-    }
-
-    /**
-     * @return Value.
-     */
-    public static Timestamp doReadTimestamp(PortableInputStream in) {
-        long time = in.readLong();
-        int nanos = in.readInt();
-
-        Timestamp ts = new Timestamp(time);
-
-        ts.setNanos(ts.getNanos() + nanos);
-
-        return ts;
-    }
-
-    /**
-     * @return Value.
-     * @throws BinaryObjectException In case of error.
-     */
-    public static BigDecimal[] doReadDecimalArray(PortableInputStream in) throws BinaryObjectException {
-        int len = in.readInt();
-
-        BigDecimal[] arr = new BigDecimal[len];
-
-        for (int i = 0; i < len; i++) {
-            byte flag = in.readByte();
-
-            if (flag == GridPortableMarshaller.NULL)
-                arr[i] = null;
-            else {
-                if (flag != GridPortableMarshaller.DECIMAL)
-                    throw new BinaryObjectException("Invalid flag value: " + flag);
-
-                arr[i] = doReadDecimal(in);
-            }
-        }
-
-        return arr;
-    }
-
-    /**
-     * @return Value.
-     * @throws BinaryObjectException In case of error.
-     */
-    public static String[] doReadStringArray(PortableInputStream in) throws BinaryObjectException {
-        int len = in.readInt();
-
-        String[] arr = new String[len];
-
-        for (int i = 0; i < len; i++) {
-            byte flag = in.readByte();
-
-            if (flag == GridPortableMarshaller.NULL)
-                arr[i] = null;
-            else {
-                if (flag != GridPortableMarshaller.STRING)
-                    throw new BinaryObjectException("Invalid flag value: " + flag);
-
-                arr[i] = doReadString(in);
-            }
-        }
-
-        return arr;
-    }
-
-    /**
-     * @return Value.
-     * @throws BinaryObjectException In case of error.
-     */
-    public static UUID[] doReadUuidArray(PortableInputStream in) throws BinaryObjectException {
-        int len = in.readInt();
-
-        UUID[] arr = new UUID[len];
-
-        for (int i = 0; i < len; i++) {
-            byte flag = in.readByte();
-
-            if (flag == GridPortableMarshaller.NULL)
-                arr[i] = null;
-            else {
-                if (flag != GridPortableMarshaller.UUID)
-                    throw new BinaryObjectException("Invalid flag value: " + flag);
-
-                arr[i] = doReadUuid(in);
-            }
-        }
-
-        return arr;
-    }
-
-    /**
-     * @return Value.
-     * @throws BinaryObjectException In case of error.
-     */
-    public static Date[] doReadDateArray(PortableInputStream in) throws BinaryObjectException {
-        int len = in.readInt();
-
-        Date[] arr = new Date[len];
-
-        for (int i = 0; i < len; i++) {
-            byte flag = in.readByte();
-
-            if (flag == GridPortableMarshaller.NULL)
-                arr[i] = null;
-            else {
-                if (flag != GridPortableMarshaller.DATE)
-                    throw new BinaryObjectException("Invalid flag value: " + flag);
-
-                arr[i] = doReadDate(in);
-            }
-        }
-
-        return arr;
-    }
-
-    /**
-     * @return Value.
-     * @throws BinaryObjectException In case of error.
-     */
-    public static Timestamp[] doReadTimestampArray(PortableInputStream in) throws BinaryObjectException {
-        int len = in.readInt();
-
-        Timestamp[] arr = new Timestamp[len];
-
-        for (int i = 0; i < len; i++) {
-            byte flag = in.readByte();
-
-            if (flag == GridPortableMarshaller.NULL)
-                arr[i] = null;
-            else {
-                if (flag != GridPortableMarshaller.TIMESTAMP)
-                    throw new BinaryObjectException("Invalid flag value: " + flag);
-
-                arr[i] = doReadTimestamp(in);
-            }
-        }
-
-        return arr;
-    }
-
-    /**
-     * @return Value.
-     */
-    public static BinaryObject doReadPortableObject(PortableInputStream in, PortableContext ctx) {
-        if (in.offheapPointer() > 0) {
-            int len = in.readInt();
-
-            int pos = in.position();
-
-            in.position(in.position() + len);
-
-            int start = in.readInt();
-
-            return new BinaryObjectOffheapImpl(ctx, in.offheapPointer() + pos, start, len);
-        }
-        else {
-            byte[] arr = doReadByteArray(in);
-            int start = in.readInt();
-
-            return new BinaryObjectImpl(ctx, arr, start);
-        }
-    }
-
-    /**
-     * @return Value.
-     */
-    public static Class doReadClass(PortableInputStream in, PortableContext ctx, ClassLoader ldr)
-        throws BinaryObjectException {
-        int typeId = in.readInt();
-
-        return doReadClass(in, ctx, ldr, typeId);
-    }
-
-    /**
-     * Read plain type.
-     *
-     * @param in Input stream.
-     * @return Plain type.
-     */
-    private static EnumType doReadEnumType(PortableInputStream in) {
-        int typeId = in.readInt();
-
-        if (typeId != GridPortableMarshaller.UNREGISTERED_TYPE_ID)
-            return new EnumType(typeId, null);
-        else {
-            String clsName = doReadClassName(in);
-
-            return new EnumType(GridPortableMarshaller.UNREGISTERED_TYPE_ID, clsName);
-        }
-    }
-
-    /**
-     * @param in Input stream.
-     * @return Class name.
-     */
-    private static String doReadClassName(PortableInputStream in) {
-        byte flag = in.readByte();
-
-        if (flag != GridPortableMarshaller.STRING)
-            throw new BinaryObjectException("Failed to read class name [position=" + (in.position() - 1) + ']');
-
-        return doReadString(in);
-    }
-
-    /**
-     * @param typeId Type id.
-     * @return Value.
-     */
-    public static Class doReadClass(PortableInputStream in, PortableContext ctx, ClassLoader ldr, int typeId)
-        throws BinaryObjectException {
-        Class cls;
-
-        if (typeId == GridPortableMarshaller.OBJECT_TYPE_ID)
-            return Object.class;
-
-        if (typeId != GridPortableMarshaller.UNREGISTERED_TYPE_ID)
-            cls = ctx.descriptorForTypeId(true, typeId, ldr, false).describedClass();
-        else {
-            String clsName = doReadClassName(in);
-
-            try {
-                cls = U.forName(clsName, ldr);
-            }
-            catch (ClassNotFoundException e) {
-                throw new BinaryInvalidTypeException("Failed to load the class: " + clsName, e);
-            }
-
-            // forces registering of class by type id, at least locally
-            ctx.descriptorForClass(cls, true);
-        }
-
-        return cls;
-    }
-
-    /**
-     * Resolve the class.
-     *
-     * @param ctx Portable context.
-     * @param typeId Type ID.
-     * @param clsName Class name.
-     * @param ldr Class loaded.
-     * @return Resovled class.
-     */
-    public static Class resolveClass(PortableContext ctx, int typeId, @Nullable String clsName,
-        @Nullable ClassLoader ldr, boolean deserialize) {
-        Class cls;
-
-        if (typeId == GridPortableMarshaller.OBJECT_TYPE_ID)
-            return Object.class;
-
-        if (typeId != GridPortableMarshaller.UNREGISTERED_TYPE_ID)
-            cls = ctx.descriptorForTypeId(true, typeId, ldr, deserialize).describedClass();
-        else {
-            try {
-                cls = U.forName(clsName, ldr);
-            }
-            catch (ClassNotFoundException e) {
-                throw new BinaryInvalidTypeException("Failed to load the class: " + clsName, e);
-            }
-
-            // forces registering of class by type id, at least locally
-            ctx.descriptorForClass(cls, true);
-        }
-
-        return cls;
-    }
-
-    /**
-     * Read portable enum.
-     *
-     * @param in Input stream.
-     * @param ctx Portable context.
-     * @param type Plain type.
-     * @return Enum.
-     */
-    private static BinaryEnumObjectImpl doReadPortableEnum(PortableInputStream in, PortableContext ctx,
-        EnumType type) {
-        return new BinaryEnumObjectImpl(ctx, type.typeId, type.clsName, in.readInt());
-    }
-
-    /**
-     * Read portable enum array.
-     *
-     * @param in Input stream.
-     * @param ctx Portable context.
-     * @return Enum array.
-     */
-    private static Object[] doReadPortableEnumArray(PortableInputStream in, PortableContext ctx) {
-        int len = in.readInt();
-
-        Object[] arr = (Object[]) Array.newInstance(BinaryObject.class, len);
-
-        for (int i = 0; i < len; i++) {
-            byte flag = in.readByte();
-
-            if (flag == GridPortableMarshaller.NULL)
-                arr[i] = null;
-            else
-                arr[i] = doReadPortableEnum(in, ctx, doReadEnumType(in));
-        }
-
-        return arr;
-    }
-
-    /**
-     * Having target class in place we simply read ordinal and create final representation.
-     *
-     * @param cls Enum class.
-     * @return Value.
-     */
-    public static Enum<?> doReadEnum(PortableInputStream in, Class<?> cls) throws BinaryObjectException {
-        assert cls != null;
-
-        if (!cls.isEnum())
-            throw new BinaryObjectException("Class does not represent enum type: " + cls.getName());
-
-        int ord = in.readInt();
-
-        return BinaryEnumCache.get(cls, ord);
-    }
-
-    /**
-     * @param cls Enum class.
-     * @return Value.
-     */
-    public static Object[] doReadEnumArray(PortableInputStream in, PortableContext ctx, ClassLoader ldr, Class<?> cls)
-        throws BinaryObjectException {
-        int len = in.readInt();
-
-        Object[] arr = (Object[]) Array.newInstance(cls, len);
-
-        for (int i = 0; i < len; i++) {
-            byte flag = in.readByte();
-
-            if (flag == GridPortableMarshaller.NULL)
-                arr[i] = null;
-            else
-                arr[i] = doReadEnum(in, doReadClass(in, ctx, ldr));
-        }
-
-        return arr;
-    }
-
-    /**
-     * Read object serialized using optimized marshaller.
-     *
-     * @return Result.
-     */
-    public static Object doReadOptimized(PortableInputStream in, PortableContext ctx, @Nullable ClassLoader clsLdr) {
-        int len = in.readInt();
-
-        ByteArrayInputStream input = new ByteArrayInputStream(in.array(), in.position(), len);
-
-        try {
-            return ctx.optimizedMarsh().unmarshal(input, clsLdr);
-        }
-        catch (IgniteCheckedException e) {
-            throw new BinaryObjectException("Failed to unmarshal object with optimized marshaller", e);
-        }
-        finally {
-            in.position(in.position() + len);
-        }
-    }
-
-    /**
-     * @return Object.
-     * @throws BinaryObjectException In case of error.
-     */
-    @Nullable public static Object doReadObject(PortableInputStream in, PortableContext ctx, ClassLoader ldr,
-        BinaryReaderHandlesHolder handles) throws BinaryObjectException {
-        return new BinaryReaderExImpl(ctx, in, ldr, handles.handles()).deserialize();
-    }
-
-    /**
-     * @return Unmarshalled value.
-     * @throws BinaryObjectException In case of error.
-     */
-    @Nullable public static Object unmarshal(PortableInputStream in, PortableContext ctx, ClassLoader ldr)
-        throws BinaryObjectException {
-        return unmarshal(in, ctx, ldr, new BinaryReaderHandlesHolderImpl());
-    }
-
-    /**
-     * @return Unmarshalled value.
-     * @throws BinaryObjectException In case of error.
-     */
-    @Nullable public static Object unmarshal(PortableInputStream in, PortableContext ctx, ClassLoader ldr,
-        BinaryReaderHandlesHolder handles) throws BinaryObjectException {
-        return unmarshal(in, ctx, ldr, handles, false);
-    }
-
-    /**
-     * @return Unmarshalled value.
-     * @throws BinaryObjectException In case of error.
-     */
-    @Nullable public static Object unmarshal(PortableInputStream in, PortableContext ctx, ClassLoader ldr,
-        BinaryReaderHandlesHolder handles, boolean detach) throws BinaryObjectException {
-        int start = in.position();
-
-        byte flag = in.readByte();
-
-        switch (flag) {
-            case GridPortableMarshaller.NULL:
-                return null;
-
-            case GridPortableMarshaller.HANDLE: {
-                int handlePos = start - in.readInt();
-
-                Object obj = handles.getHandle(handlePos);
-
-                if (obj == null) {
-                    int retPos = in.position();
-
-                    in.position(handlePos);
-
-                    obj = unmarshal(in, ctx, ldr, handles);
-
-                    in.position(retPos);
-                }
-
-                return obj;
-            }
-
-            case GridPortableMarshaller.OBJ: {
-                checkProtocolVersion(in.readByte());
-
-                int len = length(in, start);
-
-                BinaryObjectExImpl po;
-
-                if (detach) {
-                    // In detach mode we simply copy object's content.
-                    in.position(start);
-
-                    po = new BinaryObjectImpl(ctx, in.readByteArray(len), 0);
-                }
-                else {
-                    if (in.offheapPointer() == 0)
-                        po = new BinaryObjectImpl(ctx, in.array(), start);
-                    else
-                        po = new BinaryObjectOffheapImpl(ctx, in.offheapPointer(), start,
-                            in.remaining() + in.position());
-
-                    in.position(start + po.length());
-                }
-
-                handles.setHandle(po, start);
-
-                return po;
-            }
-
-            case GridPortableMarshaller.BYTE:
-                return in.readByte();
-
-            case GridPortableMarshaller.SHORT:
-                return in.readShort();
-
-            case GridPortableMarshaller.INT:
-                return in.readInt();
-
-            case GridPortableMarshaller.LONG:
-                return in.readLong();
-
-            case GridPortableMarshaller.FLOAT:
-                return in.readFloat();
-
-            case GridPortableMarshaller.DOUBLE:
-                return in.readDouble();
-
-            case GridPortableMarshaller.CHAR:
-                return in.readChar();
-
-            case GridPortableMarshaller.BOOLEAN:
-                return in.readBoolean();
-
-            case GridPortableMarshaller.DECIMAL:
-                return doReadDecimal(in);
-
-            case GridPortableMarshaller.STRING:
-                return doReadString(in);
-
-            case GridPortableMarshaller.UUID:
-                return doReadUuid(in);
-
-            case GridPortableMarshaller.DATE:
-                return doReadDate(in);
-
-            case GridPortableMarshaller.TIMESTAMP:
-                return doReadTimestamp(in);
-
-            case GridPortableMarshaller.BYTE_ARR:
-                return doReadByteArray(in);
-
-            case GridPortableMarshaller.SHORT_ARR:
-                return doReadShortArray(in);
-
-            case GridPortableMarshaller.INT_ARR:
-                return doReadIntArray(in);
-
-            case GridPortableMarshaller.LONG_ARR:
-                return doReadLongArray(in);
-
-            case GridPortableMarshaller.FLOAT_ARR:
-                return doReadFloatArray(in);
-
-            case GridPortableMarshaller.DOUBLE_ARR:
-                return doReadDoubleArray(in);
-
-            case GridPortableMarshaller.CHAR_ARR:
-                return doReadCharArray(in);
-
-            case GridPortableMarshaller.BOOLEAN_ARR:
-                return doReadBooleanArray(in);
-
-            case GridPortableMarshaller.DECIMAL_ARR:
-                return doReadDecimalArray(in);
-
-            case GridPortableMarshaller.STRING_ARR:
-                return doReadStringArray(in);
-
-            case GridPortableMarshaller.UUID_ARR:
-                return doReadUuidArray(in);
-
-            case GridPortableMarshaller.DATE_ARR:
-                return doReadDateArray(in);
-
-            case GridPortableMarshaller.TIMESTAMP_ARR:
-                return doReadTimestampArray(in);
-
-            case GridPortableMarshaller.OBJ_ARR:
-                return doReadObjectArray(in, ctx, ldr, handles, false);
-
-            case GridPortableMarshaller.COL:
-                return doReadCollection(in, ctx, ldr, handles, false, null);
-
-            case GridPortableMarshaller.MAP:
-                return doReadMap(in, ctx, ldr, handles, false, null);
-
-            case GridPortableMarshaller.PORTABLE_OBJ:
-                return doReadPortableObject(in, ctx);
-
-            case GridPortableMarshaller.ENUM:
-                return doReadPortableEnum(in, ctx, doReadEnumType(in));
-
-            case GridPortableMarshaller.ENUM_ARR:
-                doReadEnumType(in); // Simply skip this part as we do not need it.
-
-                return doReadPortableEnumArray(in, ctx);
-
-            case GridPortableMarshaller.CLASS:
-                return doReadClass(in, ctx, ldr);
-
-            case GridPortableMarshaller.OPTM_MARSH:
-                return doReadOptimized(in, ctx, ldr);
-
-            default:
-                throw new BinaryObjectException("Invalid flag value: " + flag);
-        }
-    }
-
-    /**
-     * @param deserialize Deep flag.
-     * @return Value.
-     * @throws BinaryObjectException In case of error.
-     */
-    public static Object[] doReadObjectArray(PortableInputStream in, PortableContext ctx, ClassLoader ldr,
-        BinaryReaderHandlesHolder handles, boolean deserialize) throws BinaryObjectException {
-        int hPos = positionForHandle(in);
-
-        Class compType = doReadClass(in, ctx, ldr);
-
-        int len = in.readInt();
-
-        Object[] arr = deserialize ? (Object[])Array.newInstance(compType, len) : new Object[len];
-
-        handles.setHandle(arr, hPos);
-
-        for (int i = 0; i < len; i++)
-            arr[i] = deserializeOrUnmarshal(in, ctx, ldr, handles, deserialize);
-
-        return arr;
-    }
-
-    /**
-     * @param deserialize Deep flag.
-     * @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, BinaryCollectionFactory factory)
-        throws BinaryObjectException {
-        int hPos = positionForHandle(in);
-
-        int size = in.readInt();
-
-        assert size >= 0;
-
-        byte colType = in.readByte();
-
-        Collection<Object> col;
-
-        if (factory != null)
-            col = factory.create(size);
-        else {
-            switch (colType) {
-                case GridPortableMarshaller.ARR_LIST:
-                    col = new ArrayList<>(size);
-
-                    break;
-
-                case GridPortableMarshaller.LINKED_LIST:
-                    col = new LinkedList<>();
-
-                    break;
-
-                case GridPortableMarshaller.HASH_SET:
-                    col = U.newHashSet(size);
-
-                    break;
-
-                case GridPortableMarshaller.LINKED_HASH_SET:
-                    col = U.newLinkedHashSet(size);
-
-                    break;
-
-                case GridPortableMarshaller.USER_SET:
-                    col = U.newHashSet(size);
-
-                    break;
-
-                case GridPortableMarshaller.USER_COL:
-                    col = new ArrayList<>(size);
-
-                    break;
-
-                default:
-                    throw new BinaryObjectException("Invalid collection type: " + colType);
-            }
-        }
-
-        handles.setHandle(col, hPos);
-
-        for (int i = 0; i < size; i++)
-            col.add(deserializeOrUnmarshal(in, ctx, ldr, handles, deserialize));
-
-        return col;
-    }
-
-    /**
-     * @param deserialize Deep flag.
-     * @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, BinaryMapFactory factory)
-        throws BinaryObjectException {
-        int hPos = positionForHandle(in);
-
-        int size = in.readInt();
-
-        assert size >= 0;
-
-        byte mapType = in.readByte();
-
-        Map<Object, Object> map;
-
-        if (factory != null)
-            map = factory.create(size);
-        else {
-            switch (mapType) {
-                case GridPortableMarshaller.HASH_MAP:
-                    map = U.newHashMap(size);
-
-                    break;
-
-                case GridPortableMarshaller.LINKED_HASH_MAP:
-                    map = U.newLinkedHashMap(size);
-
-                    break;
-
-                case GridPortableMarshaller.USER_COL:
-                    map = U.newHashMap(size);
-
-                    break;
-
-                default:
-                    throw new BinaryObjectException("Invalid map type: " + mapType);
-            }
-        }
-
-        handles.setHandle(map, hPos);
-
-        for (int i = 0; i < size; i++) {
-            Object key = deserializeOrUnmarshal(in, ctx, ldr, handles, deserialize);
-            Object val = deserializeOrUnmarshal(in, ctx, ldr, handles, deserialize);
-
-            map.put(key, val);
-        }
-
-        return map;
-    }
-
-    /**
-     * Deserialize or unmarshal the object.
-     *
-     * @param deserialize Deserialize.
-     * @return Result.
-     */
-    private static Object deserializeOrUnmarshal(PortableInputStream in, PortableContext ctx, ClassLoader ldr,
-        BinaryReaderHandlesHolder handles, boolean deserialize) {
-        return deserialize ? doReadObject(in, ctx, ldr, handles) : unmarshal(in, ctx, ldr, handles);
-    }
-
-    /**
-     * Get position to be used for handle. We assume here that the hdr byte was read, hence subtract -1.
-     *
-     * @return Position for handle.
-     */
-    public static int positionForHandle(PortableInputStream in) {
-        return in.position() - 1;
-    }
-
-    /**
-     * Enum type.
-     */
-    private static class EnumType {
-        /** Type ID. */
-        private final int typeId;
-
-        /** Class name. */
-        private final String clsName;
-
-        /**
-         * Constructor.
-         *
-         * @param typeId Type ID.
-         * @param clsName Class name.
-         */
-        public EnumType(int typeId, @Nullable String clsName) {
-            assert typeId != GridPortableMarshaller.UNREGISTERED_TYPE_ID && clsName == null ||
-                typeId == GridPortableMarshaller.UNREGISTERED_TYPE_ID && clsName != null;
-
-            this.typeId = typeId;
-            this.clsName = clsName;
-        }
-    }
-}

http://git-wip-us.apache.org/repos/asf/ignite/blob/71ad9cea/modules/core/src/main/java/org/apache/ignite/internal/binary/builder/BinaryAbstractLazyValue.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/binary/builder/BinaryAbstractLazyValue.java b/modules/core/src/main/java/org/apache/ignite/internal/binary/builder/BinaryAbstractLazyValue.java
new file mode 100644
index 0000000..9c79f36
--- /dev/null
+++ b/modules/core/src/main/java/org/apache/ignite/internal/binary/builder/BinaryAbstractLazyValue.java
@@ -0,0 +1,57 @@
+/*
+ * 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.binary.builder;
+
+/**
+ *
+ */
+abstract class BinaryAbstractLazyValue implements BinaryLazyValue {
+    /** */
+    protected Object val;
+
+    /** */
+    protected final BinaryBuilderReader reader;
+
+    /** */
+    protected final int valOff;
+
+    /**
+     * @param reader Reader.
+     * @param valOff Value.
+     */
+    protected BinaryAbstractLazyValue(BinaryBuilderReader reader, int valOff) {
+        this.reader = reader;
+        this.valOff = valOff;
+    }
+
+    /**
+     * @return Value.
+     */
+    protected abstract Object init();
+
+    /** {@inheritDoc} */
+    @Override public Object value() {
+        if (val == null) {
+            val = init();
+
+            assert val != null;
+        }
+
+        return val;
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/71ad9cea/modules/core/src/main/java/org/apache/ignite/internal/binary/builder/BinaryBuilderEnum.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/binary/builder/BinaryBuilderEnum.java b/modules/core/src/main/java/org/apache/ignite/internal/binary/builder/BinaryBuilderEnum.java
new file mode 100644
index 0000000..d8dd00b
--- /dev/null
+++ b/modules/core/src/main/java/org/apache/ignite/internal/binary/builder/BinaryBuilderEnum.java
@@ -0,0 +1,115 @@
+/*
+ * 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.binary.builder;
+
+import org.apache.ignite.internal.binary.GridBinaryMarshaller;
+import org.apache.ignite.internal.binary.BinaryWriterExImpl;
+import org.apache.ignite.internal.util.typedef.internal.U;
+import org.apache.ignite.binary.BinaryInvalidTypeException;
+
+/**
+ *
+ */
+public class BinaryBuilderEnum implements BinaryBuilderSerializationAware {
+    /** */
+    private final int ordinal;
+
+    /** */
+    private final int typeId;
+
+    /** */
+    private final String clsName;
+
+    /**
+     * @param typeId Type ID.
+     * @param anEnum Enum instance.
+     */
+    public BinaryBuilderEnum(int typeId, Enum anEnum) {
+        ordinal = anEnum.ordinal();
+        this.typeId = typeId;
+        clsName = null;
+    }
+
+    /**
+     * @param reader PortableBuilderReader.
+     */
+    public BinaryBuilderEnum(BinaryBuilderReader reader) {
+        int typeId = reader.readInt();
+
+        if (typeId == GridBinaryMarshaller.UNREGISTERED_TYPE_ID) {
+            clsName = reader.readString();
+
+            Class cls;
+
+            try {
+                cls = U.forName(reader.readString(), reader.portableContext().configuration().getClassLoader());
+            }
+            catch (ClassNotFoundException e) {
+                throw new BinaryInvalidTypeException("Failed to load the class: " + clsName, e);
+            }
+
+            this.typeId = reader.portableContext().descriptorForClass(cls, false).typeId();
+        }
+        else {
+            this.typeId = typeId;
+            this.clsName = null;
+        }
+
+        ordinal = reader.readInt();
+    }
+
+    /**
+     * @return Ordinal.
+     */
+    public int getOrdinal() {
+        return ordinal;
+    }
+
+    /** {@inheritDoc} */
+    @Override public void writeTo(BinaryWriterExImpl writer, BinaryBuilderSerializer ctx) {
+        writer.writeByte(GridBinaryMarshaller.ENUM);
+
+        if (typeId == GridBinaryMarshaller.UNREGISTERED_TYPE_ID) {
+            writer.writeInt(GridBinaryMarshaller.UNREGISTERED_TYPE_ID);
+            writer.writeString(clsName);
+        }
+        else
+            writer.writeInt(typeId);
+
+        writer.writeInt(ordinal);
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean equals(Object o) {
+        if (o == null || getClass() != o.getClass())
+            return false;
+
+        BinaryBuilderEnum that = (BinaryBuilderEnum)o;
+
+        return ordinal == that.ordinal && typeId == that.typeId;
+    }
+
+    /** {@inheritDoc} */
+    @Override public int hashCode() {
+        int result = ordinal;
+
+        result = 31 * result + typeId;
+
+        return result;
+    }
+}


[03/59] [abbrv] ignite git commit: ignite-2065: rename "portable" packages to "binary"

Posted by ak...@apache.org.
http://git-wip-us.apache.org/repos/asf/ignite/blob/1dbf20e0/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/GridCacheBinaryObjectsAbstractDataStreamerSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/GridCacheBinaryObjectsAbstractDataStreamerSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/GridCacheBinaryObjectsAbstractDataStreamerSelfTest.java
deleted file mode 100644
index 3938bc6..0000000
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/GridCacheBinaryObjectsAbstractDataStreamerSelfTest.java
+++ /dev/null
@@ -1,192 +0,0 @@
-/*
- * 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.processors.cache.portable;
-
-import java.io.Serializable;
-import java.util.Arrays;
-import java.util.concurrent.Callable;
-import java.util.concurrent.ThreadLocalRandom;
-import java.util.concurrent.atomic.AtomicBoolean;
-import org.apache.ignite.IgniteDataStreamer;
-import org.apache.ignite.cache.CacheAtomicityMode;
-import org.apache.ignite.cache.CacheMode;
-import org.apache.ignite.cache.CacheWriteSynchronizationMode;
-import org.apache.ignite.configuration.BinaryConfiguration;
-import org.apache.ignite.configuration.CacheConfiguration;
-import org.apache.ignite.configuration.IgniteConfiguration;
-import org.apache.ignite.configuration.NearCacheConfiguration;
-import org.apache.ignite.internal.IgniteInternalFuture;
-import org.apache.ignite.internal.portable.BinaryMarshaller;
-import org.apache.ignite.binary.BinaryObjectException;
-import org.apache.ignite.binary.Binarylizable;
-import org.apache.ignite.binary.BinaryReader;
-import org.apache.ignite.binary.BinaryTypeConfiguration;
-import org.apache.ignite.binary.BinaryWriter;
-import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
-import org.jsr166.LongAdder8;
-
-import static org.apache.ignite.cache.CacheWriteSynchronizationMode.PRIMARY_SYNC;
-
-/**
- * Test for portable objects stored in cache.
- */
-public abstract class GridCacheBinaryObjectsAbstractDataStreamerSelfTest extends GridCommonAbstractTest {
-    /** */
-    private static final int THREAD_CNT = 64;
-
-    /** {@inheritDoc} */
-    @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception {
-        IgniteConfiguration cfg = super.getConfiguration(gridName);
-
-        CacheConfiguration cacheCfg = new CacheConfiguration();
-
-        cacheCfg.setCacheMode(cacheMode());
-        cacheCfg.setAtomicityMode(atomicityMode());
-        cacheCfg.setNearConfiguration(nearConfiguration());
-        cacheCfg.setWriteSynchronizationMode(writeSynchronizationMode());
-
-        cfg.setCacheConfiguration(cacheCfg);
-
-        BinaryConfiguration bCfg = new BinaryConfiguration();
-
-        bCfg.setTypeConfigurations(Arrays.asList(
-            new BinaryTypeConfiguration(TestObject.class.getName())));
-
-        cfg.setBinaryConfiguration(bCfg);
-        cfg.setMarshaller(new BinaryMarshaller());
-
-        return cfg;
-    }
-
-    /**
-     * @return Sync mode.
-     */
-    protected CacheWriteSynchronizationMode writeSynchronizationMode() {
-        return PRIMARY_SYNC;
-    }
-
-    /** {@inheritDoc} */
-    @Override protected void beforeTestsStarted() throws Exception {
-        startGridsMultiThreaded(gridCount());
-    }
-
-    /** {@inheritDoc} */
-    @Override protected void afterTestsStopped() throws Exception {
-        stopAllGrids();
-    }
-
-    /**
-     * @return Cache mode.
-     */
-    protected abstract CacheMode cacheMode();
-
-    /**
-     * @return Atomicity mode.
-     */
-    protected abstract CacheAtomicityMode atomicityMode();
-
-    /**
-     * @return Near configuration.
-     */
-    protected abstract NearCacheConfiguration nearConfiguration();
-
-    /**
-     * @return Grid count.
-     */
-    protected int gridCount() {
-        return 1;
-    }
-
-    /**
-     * @throws Exception If failed.
-     */
-    @SuppressWarnings("BusyWait")
-    public void testGetPut() throws Exception {
-        final AtomicBoolean flag = new AtomicBoolean();
-
-        final LongAdder8 cnt = new LongAdder8();
-
-        try (IgniteDataStreamer<Object, Object> ldr = grid(0).dataStreamer(null)) {
-            IgniteInternalFuture<?> f = multithreadedAsync(
-                new Callable<Object>() {
-                    @Override public Object call() throws Exception {
-                        ThreadLocalRandom rnd = ThreadLocalRandom.current();
-
-                        while (!flag.get()) {
-                            ldr.addData(rnd.nextInt(10000), new TestObject(rnd.nextInt(10000)));
-
-                            cnt.add(1);
-                        }
-
-                        return null;
-                    }
-                },
-                THREAD_CNT
-            );
-
-            for (int i = 0; i < 30 && !f.isDone(); i++)
-                Thread.sleep(1000);
-
-            flag.set(true);
-
-            f.get();
-        }
-
-        info("Operations in 30 sec: " + cnt.sum());
-    }
-
-    /**
-     */
-    private static class TestObject implements Binarylizable, Serializable {
-        /** */
-        private int val;
-
-        /**
-         */
-        private TestObject() {
-            // No-op.
-        }
-
-        /**
-         * @param val Value.
-         */
-        private TestObject(int val) {
-            this.val = val;
-        }
-
-        /** {@inheritDoc} */
-        @Override public int hashCode() {
-            return val;
-        }
-
-        /** {@inheritDoc} */
-        @Override public boolean equals(Object obj) {
-            return obj instanceof TestObject && ((TestObject)obj).val == val;
-        }
-
-        /** {@inheritDoc} */
-        @Override public void writeBinary(BinaryWriter writer) throws BinaryObjectException {
-            writer.writeInt("val", val);
-        }
-
-        /** {@inheritDoc} */
-        @Override public void readBinary(BinaryReader reader) throws BinaryObjectException {
-            val = reader.readInt("val");
-        }
-    }
-}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ignite/blob/1dbf20e0/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/GridCacheBinaryObjectsAbstractMultiThreadedSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/GridCacheBinaryObjectsAbstractMultiThreadedSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/GridCacheBinaryObjectsAbstractMultiThreadedSelfTest.java
deleted file mode 100644
index 321194f..0000000
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/GridCacheBinaryObjectsAbstractMultiThreadedSelfTest.java
+++ /dev/null
@@ -1,241 +0,0 @@
-/*
- * 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.processors.cache.portable;
-
-import java.io.Serializable;
-import java.util.Arrays;
-import java.util.concurrent.Callable;
-import java.util.concurrent.ThreadLocalRandom;
-import java.util.concurrent.atomic.AtomicBoolean;
-import java.util.concurrent.atomic.AtomicInteger;
-import org.apache.ignite.IgniteCache;
-import org.apache.ignite.cache.CacheAtomicityMode;
-import org.apache.ignite.cache.CacheMode;
-import org.apache.ignite.cache.CacheWriteSynchronizationMode;
-import org.apache.ignite.configuration.BinaryConfiguration;
-import org.apache.ignite.configuration.CacheConfiguration;
-import org.apache.ignite.configuration.IgniteConfiguration;
-import org.apache.ignite.configuration.NearCacheConfiguration;
-import org.apache.ignite.internal.IgniteInternalFuture;
-import org.apache.ignite.internal.processors.cache.IgniteCacheProxy;
-import org.apache.ignite.internal.portable.BinaryMarshaller;
-import org.apache.ignite.binary.BinaryObjectException;
-import org.apache.ignite.binary.Binarylizable;
-import org.apache.ignite.binary.BinaryObject;
-import org.apache.ignite.binary.BinaryReader;
-import org.apache.ignite.binary.BinaryTypeConfiguration;
-import org.apache.ignite.binary.BinaryWriter;
-import org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi;
-import org.apache.ignite.spi.discovery.tcp.ipfinder.TcpDiscoveryIpFinder;
-import org.apache.ignite.spi.discovery.tcp.ipfinder.vm.TcpDiscoveryVmIpFinder;
-import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
-import org.jsr166.LongAdder8;
-
-import static org.apache.ignite.cache.CacheWriteSynchronizationMode.PRIMARY_SYNC;
-
-/**
- * Test for portable objects stored in cache.
- */
-public abstract class GridCacheBinaryObjectsAbstractMultiThreadedSelfTest extends GridCommonAbstractTest {
-    /** */
-    private static final TcpDiscoveryIpFinder IP_FINDER = new TcpDiscoveryVmIpFinder(true);
-
-    /** */
-    private static final int THREAD_CNT = 64;
-
-    /** */
-    private static final AtomicInteger idxGen = new AtomicInteger();
-
-    /** {@inheritDoc} */
-    @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception {
-        IgniteConfiguration cfg = super.getConfiguration(gridName);
-
-        ((TcpDiscoverySpi)cfg.getDiscoverySpi()).setIpFinder(IP_FINDER);
-
-        CacheConfiguration cacheCfg = new CacheConfiguration();
-
-        cacheCfg.setCacheMode(cacheMode());
-        cacheCfg.setAtomicityMode(atomicityMode());
-        cacheCfg.setNearConfiguration(nearConfiguration());
-        cacheCfg.setWriteSynchronizationMode(writeSynchronizationMode());
-
-        cfg.setCacheConfiguration(cacheCfg);
-
-        BinaryConfiguration bCfg = new BinaryConfiguration();
-
-        bCfg.setTypeConfigurations(Arrays.asList(
-            new BinaryTypeConfiguration(TestObject.class.getName())));
-
-        cfg.setBinaryConfiguration(bCfg);
-        cfg.setMarshaller(new BinaryMarshaller());
-
-        return cfg;
-    }
-
-    /**
-     * @return Sync mode.
-     */
-    protected CacheWriteSynchronizationMode writeSynchronizationMode() {
-        return PRIMARY_SYNC;
-    }
-
-    /** {@inheritDoc} */
-    @Override protected void beforeTestsStarted() throws Exception {
-        startGridsMultiThreaded(gridCount());
-    }
-
-    /** {@inheritDoc} */
-    @Override protected void afterTestsStopped() throws Exception {
-        stopAllGrids();
-    }
-
-    /**
-     * @return Cache mode.
-     */
-    protected abstract CacheMode cacheMode();
-
-    /**
-     * @return Atomicity mode.
-     */
-    protected abstract CacheAtomicityMode atomicityMode();
-
-    /**
-     * @return Distribution mode.
-     */
-    protected abstract NearCacheConfiguration nearConfiguration();
-
-    /**
-     * @return Grid count.
-     */
-    protected int gridCount() {
-        return 1;
-    }
-
-    /**
-     * @throws Exception If failed.
-     */
-    @SuppressWarnings("BusyWait") public void testGetPut() throws Exception {
-        final AtomicBoolean flag = new AtomicBoolean();
-
-        final LongAdder8 cnt = new LongAdder8();
-
-        IgniteInternalFuture<?> f = multithreadedAsync(
-            new Callable<Object>() {
-                @Override public Object call() throws Exception {
-                    int threadId = idxGen.getAndIncrement() % 2;
-
-                    ThreadLocalRandom rnd = ThreadLocalRandom.current();
-
-                    while (!flag.get()) {
-                        IgniteCache<Object, Object> c = jcache(rnd.nextInt(gridCount()));
-
-                        switch (threadId) {
-                            case 0:
-                                // Put/get/remove portable -> portable.
-
-                                c.put(new TestObject(rnd.nextInt(10000)), new TestObject(rnd.nextInt(10000)));
-
-                                IgniteCache<Object, Object> p2 = ((IgniteCacheProxy<Object, Object>)c).keepPortable();
-
-                                BinaryObject v = (BinaryObject)p2.get(new TestObject(rnd.nextInt(10000)));
-
-                                if (v != null)
-                                    v.deserialize();
-
-                                c.remove(new TestObject(rnd.nextInt(10000)));
-
-                                break;
-
-                            case 1:
-                                // Put/get int -> portable.
-                                c.put(rnd.nextInt(10000), new TestObject(rnd.nextInt(10000)));
-
-                                IgniteCache<Integer, BinaryObject> p4 = ((IgniteCacheProxy<Object, Object>)c).keepPortable();
-
-                                BinaryObject v1 = p4.get(rnd.nextInt(10000));
-
-                                if (v1 != null)
-                                    v1.deserialize();
-
-                                p4.remove(rnd.nextInt(10000));
-
-                                break;
-
-                            default:
-                                assert false;
-                        }
-
-                        cnt.add(3);
-                    }
-
-                    return null;
-                }
-            },
-            THREAD_CNT
-        );
-
-        for (int i = 0; i < 30 && !f.isDone(); i++)
-            Thread.sleep(1000);
-
-        flag.set(true);
-
-        f.get();
-
-        info("Operations in 30 sec: " + cnt.sum());
-    }
-
-    /**
-     */
-    private static class TestObject implements Binarylizable, Serializable {
-        /** */
-        private int val;
-
-        /**
-         */
-        private TestObject() {
-            // No-op.
-        }
-
-        /**
-         * @param val Value.
-         */
-        private TestObject(int val) {
-            this.val = val;
-        }
-
-        /** {@inheritDoc} */
-        @Override public int hashCode() {
-            return val;
-        }
-
-        /** {@inheritDoc} */
-        @Override public boolean equals(Object obj) {
-            return obj instanceof TestObject && ((TestObject)obj).val == val;
-        }
-
-        /** {@inheritDoc} */
-        @Override public void writeBinary(BinaryWriter writer) throws BinaryObjectException {
-            writer.writeInt("val", val);
-        }
-
-        /** {@inheritDoc} */
-        @Override public void readBinary(BinaryReader reader) throws BinaryObjectException {
-            val = reader.readInt("val");
-        }
-    }
-}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ignite/blob/1dbf20e0/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/GridCacheBinaryObjectsAbstractSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/GridCacheBinaryObjectsAbstractSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/GridCacheBinaryObjectsAbstractSelfTest.java
deleted file mode 100644
index 29b7204..0000000
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/GridCacheBinaryObjectsAbstractSelfTest.java
+++ /dev/null
@@ -1,981 +0,0 @@
-/*
- * 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.processors.cache.portable;
-
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.Map;
-import java.util.Set;
-import javax.cache.Cache;
-import javax.cache.processor.EntryProcessor;
-import javax.cache.processor.MutableEntry;
-import org.apache.ignite.Ignite;
-import org.apache.ignite.IgniteCache;
-import org.apache.ignite.IgniteBinary;
-import org.apache.ignite.cache.CacheAtomicityMode;
-import org.apache.ignite.cache.CacheMode;
-import org.apache.ignite.cache.CachePeekMode;
-import org.apache.ignite.cache.store.CacheStoreAdapter;
-import org.apache.ignite.configuration.CacheConfiguration;
-import org.apache.ignite.configuration.IgniteConfiguration;
-import org.apache.ignite.configuration.NearCacheConfiguration;
-import org.apache.ignite.internal.IgniteKernal;
-import org.apache.ignite.internal.portable.BinaryObjectImpl;
-import org.apache.ignite.internal.processors.cache.GridCacheAdapter;
-import org.apache.ignite.internal.processors.cache.GridCacheEntryEx;
-import org.apache.ignite.internal.processors.cache.IgniteCacheProxy;
-import org.apache.ignite.internal.util.typedef.P2;
-import org.apache.ignite.internal.util.typedef.internal.CU;
-import org.apache.ignite.internal.util.typedef.internal.U;
-import org.apache.ignite.lang.IgniteBiInClosure;
-import org.apache.ignite.internal.portable.BinaryMarshaller;
-import org.apache.ignite.binary.BinaryObjectBuilder;
-import org.apache.ignite.binary.BinaryObjectException;
-import org.apache.ignite.binary.Binarylizable;
-import org.apache.ignite.binary.BinaryObject;
-import org.apache.ignite.binary.BinaryReader;
-import org.apache.ignite.binary.BinaryWriter;
-import org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi;
-import org.apache.ignite.spi.discovery.tcp.ipfinder.TcpDiscoveryIpFinder;
-import org.apache.ignite.spi.discovery.tcp.ipfinder.vm.TcpDiscoveryVmIpFinder;
-import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
-import org.apache.ignite.transactions.Transaction;
-import org.jetbrains.annotations.Nullable;
-
-import static org.apache.ignite.cache.CacheAtomicityMode.TRANSACTIONAL;
-import static org.apache.ignite.cache.CacheMemoryMode.OFFHEAP_TIERED;
-import static org.apache.ignite.cache.CacheWriteSynchronizationMode.FULL_SYNC;
-import static org.apache.ignite.transactions.TransactionConcurrency.PESSIMISTIC;
-import static org.apache.ignite.transactions.TransactionIsolation.READ_COMMITTED;
-import static org.apache.ignite.transactions.TransactionIsolation.REPEATABLE_READ;
-
-/**
- * Test for portable objects stored in cache.
- */
-public abstract class GridCacheBinaryObjectsAbstractSelfTest extends GridCommonAbstractTest {
-    /** */
-    public static final TcpDiscoveryIpFinder IP_FINDER = new TcpDiscoveryVmIpFinder(true);
-
-    /** */
-    private static final int ENTRY_CNT = 100;
-
-    /** {@inheritDoc} */
-    @SuppressWarnings("unchecked")
-    @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception {
-        IgniteConfiguration cfg = super.getConfiguration(gridName);
-
-        TcpDiscoverySpi disco = new TcpDiscoverySpi();
-
-        disco.setIpFinder(IP_FINDER);
-
-        cfg.setDiscoverySpi(disco);
-
-        CacheConfiguration cacheCfg = new CacheConfiguration();
-
-        cacheCfg.setCacheMode(cacheMode());
-        cacheCfg.setAtomicityMode(atomicityMode());
-        cacheCfg.setNearConfiguration(nearConfiguration());
-        cacheCfg.setWriteSynchronizationMode(FULL_SYNC);
-        cacheCfg.setCacheStoreFactory(singletonFactory(new TestStore()));
-        cacheCfg.setReadThrough(true);
-        cacheCfg.setWriteThrough(true);
-        cacheCfg.setLoadPreviousValue(true);
-        cacheCfg.setBackups(1);
-
-        if (offheapTiered()) {
-            cacheCfg.setMemoryMode(OFFHEAP_TIERED);
-            cacheCfg.setOffHeapMaxMemory(0);
-        }
-
-        cfg.setCacheConfiguration(cacheCfg);
-
-        cfg.setMarshaller(new BinaryMarshaller());
-
-        return cfg;
-    }
-
-    /**
-     * @return {@code True} if should use OFFHEAP_TIERED mode.
-     */
-    protected boolean offheapTiered() {
-        return false;
-    }
-
-    /** {@inheritDoc} */
-    @Override protected void beforeTestsStarted() throws Exception {
-        startGridsMultiThreaded(gridCount());
-    }
-
-    /** {@inheritDoc} */
-    @Override protected void afterTestsStopped() throws Exception {
-        stopAllGrids();
-    }
-
-    /** {@inheritDoc} */
-    @Override protected void afterTest() throws Exception {
-        for (int i = 0; i < gridCount(); i++) {
-            GridCacheAdapter<Object, Object> c = ((IgniteKernal)grid(i)).internalCache();
-
-            for (GridCacheEntryEx e : c.map().entries0()) {
-                Object key = e.key().value(c.context().cacheObjectContext(), false);
-                Object val = CU.value(e.rawGet(), c.context(), false);
-
-                if (key instanceof BinaryObject)
-                    assert ((BinaryObjectImpl)key).detached() : val;
-
-                if (val instanceof BinaryObject)
-                    assert ((BinaryObjectImpl)val).detached() : val;
-            }
-        }
-
-        IgniteCache<Object, Object> c = jcache(0);
-
-        for (int i = 0; i < ENTRY_CNT; i++)
-            c.remove(i);
-
-        if (offheapTiered()) {
-            for (int k = 0; k < 100; k++)
-                c.remove(k);
-        }
-
-        assertEquals(0, c.size());
-    }
-
-    /**
-     * @return Cache mode.
-     */
-    protected abstract CacheMode cacheMode();
-
-    /**
-     * @return Atomicity mode.
-     */
-    protected abstract CacheAtomicityMode atomicityMode();
-
-    /**
-     * @return Distribution mode.
-     */
-    protected abstract NearCacheConfiguration nearConfiguration();
-
-    /**
-     * @return Grid count.
-     */
-    protected abstract int gridCount();
-
-    /**
-     * @throws Exception If failed.
-     */
-    @SuppressWarnings("unchecked")
-    public void testCircularReference() throws Exception {
-        IgniteCache c = keepPortableCache();
-
-        TestReferenceObject obj1 = new TestReferenceObject();
-
-        obj1.obj = new TestReferenceObject(obj1);
-
-        c.put(1, obj1);
-
-        BinaryObject po = (BinaryObject)c.get(1);
-
-        String str = po.toString();
-
-        log.info("toString: " + str);
-
-        assertNotNull(str);
-
-        assertTrue("Unexpected toString: " + str,
-            str.startsWith("TestReferenceObject") && str.contains("obj=TestReferenceObject ["));
-
-        TestReferenceObject obj1_r = po.deserialize();
-
-        assertNotNull(obj1_r);
-
-        TestReferenceObject obj2_r = obj1_r.obj;
-
-        assertNotNull(obj2_r);
-
-        assertSame(obj1_r, obj2_r.obj);
-    }
-
-    /**
-     * @throws Exception If failed.
-     */
-    public void testGet() throws Exception {
-        IgniteCache<Integer, TestObject> c = jcache(0);
-
-        for (int i = 0; i < ENTRY_CNT; i++)
-            c.put(i, new TestObject(i));
-
-        for (int i = 0; i < ENTRY_CNT; i++) {
-            TestObject obj = c.get(i);
-
-            assertEquals(i, obj.val);
-        }
-
-        IgniteCache<Integer, BinaryObject> kpc = keepPortableCache();
-
-        for (int i = 0; i < ENTRY_CNT; i++) {
-            BinaryObject po = kpc.get(i);
-
-            assertEquals(i, (int)po.field("val"));
-        }
-    }
-
-    /**
-     * @throws Exception If failed.
-     */
-    public void testIterator() throws Exception {
-        IgniteCache<Integer, TestObject> c = jcache(0);
-
-        Map<Integer, TestObject> entries = new HashMap<>();
-
-        for (int i = 0; i < ENTRY_CNT; i++) {
-            TestObject val = new TestObject(i);
-
-            c.put(i, val);
-
-            entries.put(i, val);
-        }
-
-        IgniteCache<Integer, BinaryObject> prj = ((IgniteCacheProxy)c).keepPortable();
-
-        Iterator<Cache.Entry<Integer, BinaryObject>> it = prj.iterator();
-
-        assertTrue(it.hasNext());
-
-        while (it.hasNext()) {
-            Cache.Entry<Integer, BinaryObject> entry = it.next();
-
-            assertTrue(entries.containsKey(entry.getKey()));
-
-            TestObject o = entries.get(entry.getKey());
-
-            BinaryObject po = entry.getValue();
-
-            assertEquals(o.val, (int)po.field("val"));
-
-            entries.remove(entry.getKey());
-        }
-
-        assertEquals(0, entries.size());
-    }
-
-    /**
-     * @throws Exception If failed.
-     */
-    public void testCollection() throws Exception {
-        IgniteCache<Integer, Collection<TestObject>> c = jcache(0);
-
-        for (int i = 0; i < ENTRY_CNT; i++) {
-            Collection<TestObject> col = new ArrayList<>(3);
-
-            for (int j = 0; j < 3; j++)
-                col.add(new TestObject(i * 10 + j));
-
-            c.put(i, col);
-        }
-
-        for (int i = 0; i < ENTRY_CNT; i++) {
-            Collection<TestObject> col = c.get(i);
-
-            assertEquals(3, col.size());
-
-            Iterator<TestObject> it = col.iterator();
-
-            for (int j = 0; j < 3; j++) {
-                assertTrue(it.hasNext());
-
-                assertEquals(i * 10 + j, it.next().val);
-            }
-        }
-
-        IgniteCache<Integer, Collection<BinaryObject>> kpc = keepPortableCache();
-
-        for (int i = 0; i < ENTRY_CNT; i++) {
-            Collection<BinaryObject> col = kpc.get(i);
-
-            assertEquals(3, col.size());
-
-            Iterator<BinaryObject> it = col.iterator();
-
-            for (int j = 0; j < 3; j++) {
-                assertTrue(it.hasNext());
-
-                assertEquals(i * 10 + j, (int)it.next().field("val"));
-            }
-        }
-    }
-
-    /**
-     * @throws Exception If failed.
-     */
-    public void testMap() throws Exception {
-        IgniteCache<Integer, Map<Integer, TestObject>> c = jcache(0);
-
-        for (int i = 0; i < ENTRY_CNT; i++) {
-            Map<Integer, TestObject> map = U.newHashMap(3);
-
-            for (int j = 0; j < 3; j++) {
-                int idx = i * 10 + j;
-
-                map.put(idx, new TestObject(idx));
-            }
-
-            c.put(i, map);
-        }
-
-        for (int i = 0; i < ENTRY_CNT; i++) {
-            Map<Integer, TestObject> map = c.get(i);
-
-            assertEquals(3, map.size());
-
-            for (int j = 0; j < 3; j++) {
-                int idx = i * 10 + j;
-
-                assertEquals(idx, map.get(idx).val);
-            }
-        }
-
-        IgniteCache<Integer, Map<Integer, BinaryObject>> kpc = keepPortableCache();
-
-        for (int i = 0; i < ENTRY_CNT; i++) {
-            Map<Integer, BinaryObject> map = kpc.get(i);
-
-            assertEquals(3, map.size());
-
-            for (int j = 0; j < 3; j++) {
-                int idx = i * 10 + j;
-
-                assertEquals(idx, (int)map.get(idx).field("val"));
-            }
-        }
-    }
-
-    /**
-     * @throws Exception If failed.
-     */
-    public void testGetAsync() throws Exception {
-        IgniteCache<Integer, TestObject> c = jcache(0);
-
-        IgniteCache<Integer, TestObject> cacheAsync = c.withAsync();
-
-        for (int i = 0; i < ENTRY_CNT; i++)
-            c.put(i, new TestObject(i));
-
-        for (int i = 0; i < ENTRY_CNT; i++) {
-            cacheAsync.get(i);
-
-            TestObject obj = cacheAsync.<TestObject>future().get();
-
-            assertNotNull(obj);
-
-            assertEquals(i, obj.val);
-        }
-
-        IgniteCache<Integer, BinaryObject> kpc = keepPortableCache();
-
-        IgniteCache<Integer, BinaryObject> cachePortableAsync = kpc.withAsync();
-
-        for (int i = 0; i < ENTRY_CNT; i++) {
-            cachePortableAsync.get(i);
-
-            BinaryObject po = cachePortableAsync.<BinaryObject>future().get();
-
-            assertEquals(i, (int)po.field("val"));
-        }
-    }
-
-    /**
-     * @throws Exception If failed.
-     */
-    public void testGetTx() throws Exception {
-        if (atomicityMode() != TRANSACTIONAL)
-            return;
-
-        IgniteCache<Integer, TestObject> c = jcache(0);
-
-        for (int i = 0; i < ENTRY_CNT; i++)
-            c.put(i, new TestObject(i));
-
-        for (int i = 0; i < ENTRY_CNT; i++) {
-            try (Transaction tx = grid(0).transactions().txStart(PESSIMISTIC, REPEATABLE_READ)) {
-                TestObject obj = c.get(i);
-
-                assertEquals(i, obj.val);
-
-                tx.commit();
-            }
-        }
-
-        for (int i = 0; i < ENTRY_CNT; i++) {
-            try (Transaction tx = grid(0).transactions().txStart(PESSIMISTIC, READ_COMMITTED)) {
-                TestObject obj = c.get(i);
-
-                assertEquals(i, obj.val);
-
-                tx.commit();
-            }
-        }
-
-        IgniteCache<Integer, BinaryObject> kpc = keepPortableCache();
-
-        for (int i = 0; i < ENTRY_CNT; i++) {
-            try (Transaction tx = grid(0).transactions().txStart(PESSIMISTIC, REPEATABLE_READ)) {
-                BinaryObject po = kpc.get(i);
-
-                assertEquals(i, (int)po.field("val"));
-
-                tx.commit();
-            }
-        }
-
-        for (int i = 0; i < ENTRY_CNT; i++) {
-            try (Transaction tx = grid(0).transactions().txStart(PESSIMISTIC, READ_COMMITTED)) {
-                BinaryObject po = kpc.get(i);
-
-                assertEquals(i, (int)po.field("val"));
-
-                tx.commit();
-            }
-        }
-    }
-
-    /**
-     * @throws Exception If failed.
-     */
-    public void testGetAsyncTx() throws Exception {
-        if (atomicityMode() != TRANSACTIONAL)
-            return;
-
-        IgniteCache<Integer, TestObject> c = jcache(0);
-
-        IgniteCache<Integer, TestObject> cacheAsync = c.withAsync();
-
-        for (int i = 0; i < ENTRY_CNT; i++)
-            c.put(i, new TestObject(i));
-
-        for (int i = 0; i < ENTRY_CNT; i++) {
-            try (Transaction tx = grid(0).transactions().txStart(PESSIMISTIC, REPEATABLE_READ)) {
-                cacheAsync.get(i);
-
-                TestObject obj = cacheAsync.<TestObject>future().get();
-
-                assertEquals(i, obj.val);
-
-                tx.commit();
-            }
-        }
-
-        IgniteCache<Integer, BinaryObject> kpc = keepPortableCache();
-        IgniteCache<Integer, BinaryObject> cachePortableAsync = kpc.withAsync();
-
-        for (int i = 0; i < ENTRY_CNT; i++) {
-            try (Transaction tx = grid(0).transactions().txStart(PESSIMISTIC, REPEATABLE_READ)) {
-                cachePortableAsync.get(i);
-
-                BinaryObject po = cachePortableAsync.<BinaryObject>future().get();
-
-                assertEquals(i, (int)po.field("val"));
-
-                tx.commit();
-            }
-        }
-    }
-
-    /**
-     * @throws Exception If failed.
-     */
-    public void testGetAll() throws Exception {
-        IgniteCache<Integer, TestObject> c = jcache(0);
-
-        for (int i = 0; i < ENTRY_CNT; i++)
-            c.put(i, new TestObject(i));
-
-        for (int i = 0; i < ENTRY_CNT; ) {
-            Set<Integer> keys = new HashSet<>();
-
-            for (int j = 0; j < 10; j++)
-                keys.add(i++);
-
-            Map<Integer, TestObject> objs = c.getAll(keys);
-
-            assertEquals(10, objs.size());
-
-            for (Map.Entry<Integer, TestObject> e : objs.entrySet())
-                assertEquals(e.getKey().intValue(), e.getValue().val);
-        }
-
-        IgniteCache<Integer, BinaryObject> kpc = keepPortableCache();
-
-        for (int i = 0; i < ENTRY_CNT; ) {
-            Set<Integer> keys = new HashSet<>();
-
-            for (int j = 0; j < 10; j++)
-                keys.add(i++);
-
-            Map<Integer, BinaryObject> objs = kpc.getAll(keys);
-
-            assertEquals(10, objs.size());
-
-            for (Map.Entry<Integer, BinaryObject> e : objs.entrySet())
-                assertEquals(new Integer(e.getKey().intValue()), e.getValue().field("val"));
-        }
-    }
-
-    /**
-     * @throws Exception If failed.
-     */
-    public void testGetAllAsync() throws Exception {
-        IgniteCache<Integer, TestObject> c = jcache(0);
-
-        IgniteCache<Integer, TestObject> cacheAsync = c.withAsync();
-
-        for (int i = 0; i < ENTRY_CNT; i++)
-            c.put(i, new TestObject(i));
-
-        for (int i = 0; i < ENTRY_CNT; ) {
-            Set<Integer> keys = new HashSet<>();
-
-            for (int j = 0; j < 10; j++)
-                keys.add(i++);
-
-            cacheAsync.getAll(keys);
-
-            Map<Integer, TestObject> objs = cacheAsync.<Map<Integer, TestObject>>future().get();
-
-            assertEquals(10, objs.size());
-
-            for (Map.Entry<Integer, TestObject> e : objs.entrySet())
-                assertEquals(e.getKey().intValue(), e.getValue().val);
-        }
-
-        IgniteCache<Integer, BinaryObject> kpc = keepPortableCache();
-        IgniteCache<Integer, BinaryObject> cachePortableAsync = kpc.withAsync();
-
-        for (int i = 0; i < ENTRY_CNT; ) {
-            Set<Integer> keys = new HashSet<>();
-
-            for (int j = 0; j < 10; j++)
-                keys.add(i++);
-
-
-            cachePortableAsync.getAll(keys);
-
-            Map<Integer, BinaryObject> objs = cachePortableAsync.<Map<Integer, BinaryObject>>future().get();
-
-            assertEquals(10, objs.size());
-
-            for (Map.Entry<Integer, BinaryObject> e : objs.entrySet())
-                assertEquals(new Integer(e.getKey().intValue()), e.getValue().field("val"));
-        }
-    }
-
-    /**
-     * @throws Exception If failed.
-     */
-    public void testGetAllTx() throws Exception {
-        if (atomicityMode() != TRANSACTIONAL)
-            return;
-
-        IgniteCache<Integer, TestObject> c = jcache(0);
-
-        for (int i = 0; i < ENTRY_CNT; i++)
-            c.put(i, new TestObject(i));
-
-        for (int i = 0; i < ENTRY_CNT; ) {
-            Set<Integer> keys = new HashSet<>();
-
-            for (int j = 0; j < 10; j++)
-                keys.add(i++);
-
-            try (Transaction tx = grid(0).transactions().txStart(PESSIMISTIC, REPEATABLE_READ)) {
-                Map<Integer, TestObject> objs = c.getAll(keys);
-
-                assertEquals(10, objs.size());
-
-                for (Map.Entry<Integer, TestObject> e : objs.entrySet())
-                    assertEquals(e.getKey().intValue(), e.getValue().val);
-
-                tx.commit();
-            }
-
-            try (Transaction tx = grid(0).transactions().txStart(PESSIMISTIC, READ_COMMITTED)) {
-                Map<Integer, TestObject> objs = c.getAll(keys);
-
-                assertEquals(10, objs.size());
-
-                for (Map.Entry<Integer, TestObject> e : objs.entrySet())
-                    assertEquals(e.getKey().intValue(), e.getValue().val);
-
-                tx.commit();
-            }
-        }
-
-        IgniteCache<Integer, BinaryObject> kpc = keepPortableCache();
-
-        for (int i = 0; i < ENTRY_CNT; ) {
-            Set<Integer> keys = new HashSet<>();
-
-            for (int j = 0; j < 10; j++)
-                keys.add(i++);
-
-            try (Transaction tx = grid(0).transactions().txStart(PESSIMISTIC, REPEATABLE_READ)) {
-                Map<Integer, BinaryObject> objs = kpc.getAll(keys);
-
-                assertEquals(10, objs.size());
-
-                for (Map.Entry<Integer, BinaryObject> e : objs.entrySet())
-                    assertEquals(new Integer(e.getKey().intValue()), e.getValue().field("val"));
-
-                tx.commit();
-            }
-
-            try (Transaction tx = grid(0).transactions().txStart(PESSIMISTIC, READ_COMMITTED)) {
-                Map<Integer, BinaryObject> objs = kpc.getAll(keys);
-
-                assertEquals(10, objs.size());
-
-                for (Map.Entry<Integer, BinaryObject> e : objs.entrySet())
-                    assertEquals(new Integer(e.getKey().intValue()), e.getValue().field("val"));
-
-                tx.commit();
-            }
-        }
-    }
-
-    /**
-     * @throws Exception If failed.
-     */
-    public void testGetAllAsyncTx() throws Exception {
-        if (atomicityMode() != TRANSACTIONAL)
-            return;
-
-        IgniteCache<Integer, TestObject> c = jcache(0);
-        IgniteCache<Integer, TestObject> cacheAsync = c.withAsync();
-
-        for (int i = 0; i < ENTRY_CNT; i++)
-            c.put(i, new TestObject(i));
-
-        for (int i = 0; i < ENTRY_CNT; ) {
-            Set<Integer> keys = new HashSet<>();
-
-            for (int j = 0; j < 10; j++)
-                keys.add(i++);
-
-            try (Transaction tx = grid(0).transactions().txStart(PESSIMISTIC, REPEATABLE_READ)) {
-                cacheAsync.getAll(keys);
-
-                Map<Integer, TestObject> objs = cacheAsync.<Map<Integer, TestObject>>future().get();
-
-                assertEquals(10, objs.size());
-
-                for (Map.Entry<Integer, TestObject> e : objs.entrySet())
-                    assertEquals(e.getKey().intValue(), e.getValue().val);
-
-                tx.commit();
-            }
-        }
-
-        IgniteCache<Integer, BinaryObject> cache = keepPortableCache();
-
-        for (int i = 0; i < ENTRY_CNT; ) {
-            Set<Integer> keys = new HashSet<>();
-
-            for (int j = 0; j < 10; j++)
-                keys.add(i++);
-
-            IgniteCache<Integer, BinaryObject> asyncCache = cache.withAsync();
-
-            try (Transaction tx = grid(0).transactions().txStart(PESSIMISTIC, REPEATABLE_READ)) {
-                asyncCache.getAll(keys);
-
-                Map<Integer, BinaryObject> objs = asyncCache.<Map<Integer, BinaryObject>>future().get();
-
-                assertEquals(10, objs.size());
-
-                for (Map.Entry<Integer, BinaryObject> e : objs.entrySet())
-                    assertEquals(new Integer(e.getKey().intValue()), e.getValue().field("val"));
-
-                tx.commit();
-            }
-        }
-    }
-
-    /**
-     * @throws Exception If failed.
-     */
-    public void testLoadCache() throws Exception {
-        for (int i = 0; i < gridCount(); i++)
-            jcache(i).localLoadCache(null);
-
-        IgniteCache<Integer, TestObject> cache = jcache(0);
-
-        assertEquals(3, cache.size(CachePeekMode.PRIMARY));
-
-        assertEquals(1, cache.get(1).val);
-        assertEquals(2, cache.get(2).val);
-        assertEquals(3, cache.get(3).val);
-    }
-
-    /**
-     * @throws Exception If failed.
-     */
-    public void testLoadCacheAsync() throws Exception {
-        for (int i = 0; i < gridCount(); i++) {
-            IgniteCache<Object, Object> jcache = jcache(i).withAsync();
-
-            jcache.loadCache(null);
-
-            jcache.future().get();
-        }
-
-        IgniteCache<Integer, TestObject> cache = jcache(0);
-
-        assertEquals(3, cache.size(CachePeekMode.PRIMARY));
-
-        assertEquals(1, cache.get(1).val);
-        assertEquals(2, cache.get(2).val);
-        assertEquals(3, cache.get(3).val);
-    }
-
-    /**
-     * @throws Exception If failed.
-     */
-    public void testLoadCacheFilteredAsync() throws Exception {
-        for (int i = 0; i < gridCount(); i++) {
-            IgniteCache<Integer, TestObject> c = this.<Integer, TestObject>jcache(i).withAsync();
-
-            c.loadCache(new P2<Integer, TestObject>() {
-                @Override public boolean apply(Integer key, TestObject val) {
-                    return val.val < 3;
-                }
-            });
-
-            c.future().get();
-        }
-
-        IgniteCache<Integer, TestObject> cache = jcache(0);
-
-        assertEquals(2, cache.size(CachePeekMode.PRIMARY));
-
-        assertEquals(1, cache.get(1).val);
-        assertEquals(2, cache.get(2).val);
-
-        assertNull(cache.get(3));
-    }
-
-    /**
-     * @throws Exception If failed.
-     */
-    public void testTransform() throws Exception {
-        IgniteCache<Integer, BinaryObject> c = keepPortableCache();
-
-        checkTransform(primaryKey(c));
-
-        if (cacheMode() != CacheMode.LOCAL) {
-            checkTransform(backupKey(c));
-
-            if (nearConfiguration() != null)
-                checkTransform(nearKey(c));
-        }
-    }
-
-    /**
-     * @return Cache with keep portable flag.
-     */
-    private <K, V> IgniteCache<K, V> keepPortableCache() {
-        return ignite(0).cache(null).withKeepBinary();
-    }
-
-    /**
-     * @param key Key.
-     * @throws Exception If failed.
-     */
-    private void checkTransform(Integer key) throws Exception {
-        log.info("Transform: " + key);
-
-        IgniteCache<Integer, BinaryObject> c = keepPortableCache();
-
-        try {
-            c.invoke(key, new EntryProcessor<Integer, BinaryObject, Void>() {
-                @Override public Void process(MutableEntry<Integer, BinaryObject> e, Object... args) {
-                    BinaryObject val = e.getValue();
-
-                    assertNull("Unexpected value: " + val, val);
-
-                    return null;
-                }
-            });
-
-            jcache(0).put(key, new TestObject(1));
-
-            c.invoke(key, new EntryProcessor<Integer, BinaryObject, Void>() {
-                @Override public Void process(MutableEntry<Integer, BinaryObject> e, Object... args) {
-                    BinaryObject val = e.getValue();
-
-                    assertNotNull("Unexpected value: " + val, val);
-
-                    assertEquals(new Integer(1), val.field("val"));
-
-                    Ignite ignite = e.unwrap(Ignite.class);
-
-                    IgniteBinary portables = ignite.binary();
-
-                    BinaryObjectBuilder builder = portables.builder(val);
-
-                    builder.setField("val", 2);
-
-                    e.setValue(builder.build());
-
-                    return null;
-                }
-            });
-
-            BinaryObject obj = c.get(key);
-
-            assertEquals(new Integer(2), obj.field("val"));
-
-            c.invoke(key, new EntryProcessor<Integer, BinaryObject, Void>() {
-                @Override public Void process(MutableEntry<Integer, BinaryObject> e, Object... args) {
-                    BinaryObject val = e.getValue();
-
-                    assertNotNull("Unexpected value: " + val, val);
-
-                    assertEquals(new Integer(2), val.field("val"));
-
-                    e.setValue(val);
-
-                    return null;
-                }
-            });
-
-            obj = c.get(key);
-
-            assertEquals(new Integer(2), obj.field("val"));
-
-            c.invoke(key, new EntryProcessor<Integer, BinaryObject, Void>() {
-                @Override public Void process(MutableEntry<Integer, BinaryObject> e, Object... args) {
-                    BinaryObject val = e.getValue();
-
-                    assertNotNull("Unexpected value: " + val, val);
-
-                    assertEquals(new Integer(2), val.field("val"));
-
-                    e.remove();
-
-                    return null;
-                }
-            });
-
-            assertNull(c.get(key));
-        }
-        finally {
-            c.remove(key);
-        }
-    }
-
-    /**
-     *
-     */
-    private static class TestObject implements Binarylizable {
-        /** */
-        private int val;
-
-        /**
-         */
-        private TestObject() {
-            // No-op.
-        }
-
-        /**
-         * @param val Value.
-         */
-        private TestObject(int val) {
-            this.val = val;
-        }
-
-        /** {@inheritDoc} */
-        @Override public void writeBinary(BinaryWriter writer) throws BinaryObjectException {
-            writer.writeInt("val", val);
-        }
-
-        /** {@inheritDoc} */
-        @Override public void readBinary(BinaryReader reader) throws BinaryObjectException {
-            val = reader.readInt("val");
-        }
-    }
-
-    /**
-     *
-     */
-    private static class TestReferenceObject implements Binarylizable {
-        /** */
-        private TestReferenceObject obj;
-
-        /**
-         */
-        private TestReferenceObject() {
-            // No-op.
-        }
-
-        /**
-         * @param obj Object.
-         */
-        private TestReferenceObject(TestReferenceObject obj) {
-            this.obj = obj;
-        }
-
-        /** {@inheritDoc} */
-        @Override public void writeBinary(BinaryWriter writer) throws BinaryObjectException {
-            writer.writeObject("obj", obj);
-        }
-
-        /** {@inheritDoc} */
-        @Override public void readBinary(BinaryReader reader) throws BinaryObjectException {
-            obj = reader.readObject("obj");
-        }
-    }
-
-    /**
-     *
-     */
-    private static class TestStore extends CacheStoreAdapter<Integer, Object> {
-        /** {@inheritDoc} */
-        @Override public void loadCache(IgniteBiInClosure<Integer, Object> clo, Object... args) {
-            for (int i = 1; i <= 3; i++)
-                clo.apply(i, new TestObject(i));
-        }
-
-        /** {@inheritDoc} */
-        @Nullable @Override public Object load(Integer key) {
-            return null;
-        }
-
-        /** {@inheritDoc} */
-        @Override public void write(Cache.Entry<? extends Integer, ?> e) {
-            // No-op.
-        }
-
-        /** {@inheritDoc} */
-        @Override public void delete(Object key) {
-            // No-op.
-        }
-    }
-}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ignite/blob/1dbf20e0/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/GridCacheBinaryTransactionalEntryProcessorDeploymentSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/GridCacheBinaryTransactionalEntryProcessorDeploymentSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/GridCacheBinaryTransactionalEntryProcessorDeploymentSelfTest.java
deleted file mode 100644
index c115754..0000000
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/GridCacheBinaryTransactionalEntryProcessorDeploymentSelfTest.java
+++ /dev/null
@@ -1,31 +0,0 @@
-/*
- *  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.processors.cache.portable;
-
-import org.apache.ignite.cache.CacheAtomicityMode;
-
-/**
- * Cache EntryProcessor + Deployment for transactional cache.
- */
-public class GridCacheBinaryTransactionalEntryProcessorDeploymentSelfTest extends
-    GridCacheBinaryAtomicEntryProcessorDeploymentSelfTest {
-    /** {@inheritDoc} */
-    @Override protected CacheAtomicityMode atomicityMode() {
-        return CacheAtomicityMode.TRANSACTIONAL;
-    }
-}

http://git-wip-us.apache.org/repos/asf/ignite/blob/1dbf20e0/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/GridCacheClientNodeBinaryObjectMetadataMultinodeTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/GridCacheClientNodeBinaryObjectMetadataMultinodeTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/GridCacheClientNodeBinaryObjectMetadataMultinodeTest.java
deleted file mode 100644
index 8823776..0000000
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/GridCacheClientNodeBinaryObjectMetadataMultinodeTest.java
+++ /dev/null
@@ -1,295 +0,0 @@
-/*
- * 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.processors.cache.portable;
-
-import java.util.Collection;
-import java.util.HashSet;
-import java.util.Set;
-import java.util.concurrent.Callable;
-import java.util.concurrent.CyclicBarrier;
-import java.util.concurrent.ThreadLocalRandom;
-import java.util.concurrent.atomic.AtomicBoolean;
-import java.util.concurrent.atomic.AtomicInteger;
-import org.apache.ignite.Ignite;
-import org.apache.ignite.IgniteCache;
-import org.apache.ignite.IgniteBinary;
-import org.apache.ignite.configuration.CacheConfiguration;
-import org.apache.ignite.configuration.IgniteConfiguration;
-import org.apache.ignite.internal.IgniteInternalFuture;
-import org.apache.ignite.internal.util.lang.GridAbsPredicate;
-import org.apache.ignite.internal.util.typedef.internal.U;
-import org.apache.ignite.internal.portable.BinaryMarshaller;
-import org.apache.ignite.binary.BinaryObjectBuilder;
-import org.apache.ignite.binary.BinaryType;
-import org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi;
-import org.apache.ignite.spi.discovery.tcp.ipfinder.TcpDiscoveryIpFinder;
-import org.apache.ignite.spi.discovery.tcp.ipfinder.vm.TcpDiscoveryVmIpFinder;
-import org.apache.ignite.testframework.GridTestUtils;
-import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
-import org.eclipse.jetty.util.ConcurrentHashSet;
-
-import static org.apache.ignite.cache.CacheWriteSynchronizationMode.FULL_SYNC;
-
-/**
- *
- */
-public class GridCacheClientNodeBinaryObjectMetadataMultinodeTest extends GridCommonAbstractTest {
-    /** */
-    protected static TcpDiscoveryIpFinder ipFinder = new TcpDiscoveryVmIpFinder(true);
-
-    /** */
-    private boolean client;
-
-    /** {@inheritDoc} */
-    @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception {
-        IgniteConfiguration cfg = super.getConfiguration(gridName);
-
-        cfg.setPeerClassLoadingEnabled(false);
-
-        ((TcpDiscoverySpi)cfg.getDiscoverySpi()).setIpFinder(ipFinder).setForceServerMode(true);
-
-        cfg.setMarshaller(new BinaryMarshaller());
-
-        CacheConfiguration ccfg = new CacheConfiguration();
-
-        ccfg.setWriteSynchronizationMode(FULL_SYNC);
-
-        cfg.setCacheConfiguration(ccfg);
-
-        cfg.setClientMode(client);
-
-        return cfg;
-    }
-
-    /** {@inheritDoc} */
-    @Override protected void afterTest() throws Exception {
-        super.afterTest();
-
-        stopAllGrids();
-    }
-
-    /**
-     * @throws Exception If failed.
-     */
-    public void testClientMetadataInitialization() throws Exception {
-        startGrids(2);
-
-        final AtomicBoolean stop = new AtomicBoolean();
-
-        final ConcurrentHashSet<String> allTypes = new ConcurrentHashSet<>();
-
-        IgniteInternalFuture<?> fut;
-
-        try {
-            // Update portable metadata concurrently with client nodes start.
-            fut = GridTestUtils.runMultiThreadedAsync(new Callable<Object>() {
-                @Override public Object call() throws Exception {
-                    IgniteBinary portables = ignite(0).binary();
-
-                    IgniteCache<Object, Object> cache = ignite(0).cache(null).withKeepBinary();
-
-                    ThreadLocalRandom rnd = ThreadLocalRandom.current();
-
-                    for (int i = 0; i < 1000; i++) {
-                        log.info("Iteration: " + i);
-
-                        String type = "portable-type-" + i;
-
-                        allTypes.add(type);
-
-                        for (int f = 0; f < 10; f++) {
-                            BinaryObjectBuilder builder = portables.builder(type);
-
-                            String fieldName = "f" + f;
-
-                            builder.setField(fieldName, i);
-
-                            cache.put(rnd.nextInt(0, 100_000), builder.build());
-
-                            if (f % 100 == 0)
-                                log.info("Put iteration: " + f);
-                        }
-
-                        if (stop.get())
-                            break;
-                    }
-
-                    return null;
-                }
-            }, 5, "update-thread");
-        }
-        finally {
-            stop.set(true);
-        }
-
-        client = true;
-
-        startGridsMultiThreaded(2, 5);
-
-        fut.get();
-
-        assertFalse(allTypes.isEmpty());
-
-        log.info("Expected portable types: " + allTypes.size());
-
-        assertEquals(7, ignite(0).cluster().nodes().size());
-
-        for (int i = 0; i < 7; i++) {
-            log.info("Check metadata on node: " + i);
-
-            boolean client = i > 1;
-
-            assertEquals((Object)client, ignite(i).configuration().isClientMode());
-
-            IgniteBinary portables = ignite(i).binary();
-
-            Collection<BinaryType> metaCol = portables.types();
-
-            assertEquals(allTypes.size(), metaCol.size());
-
-            Set<String> names = new HashSet<>();
-
-            for (BinaryType meta : metaCol) {
-                assertTrue(names.add(meta.typeName()));
-
-                assertNull(meta.affinityKeyFieldName());
-
-                assertEquals(10, meta.fieldNames().size());
-            }
-
-            assertEquals(allTypes.size(), names.size());
-        }
-    }
-
-    /**
-     * @throws Exception If failed.
-     */
-    public void testFailoverOnStart() throws Exception {
-        startGrids(4);
-
-        IgniteBinary portables = ignite(0).binary();
-
-        IgniteCache<Object, Object> cache = ignite(0).cache(null).withKeepBinary();
-
-        for (int i = 0; i < 1000; i++) {
-            BinaryObjectBuilder builder = portables.builder("type-" + i);
-
-            builder.setField("f0", i);
-
-            cache.put(i, builder.build());
-        }
-
-        client = true;
-
-        final CyclicBarrier barrier = new CyclicBarrier(6);
-
-        final AtomicInteger startIdx = new AtomicInteger(4);
-
-        IgniteInternalFuture<?> fut = GridTestUtils.runMultiThreadedAsync(new Callable<Object>() {
-            @Override public Object call() throws Exception {
-                barrier.await();
-
-                Ignite ignite = startGrid(startIdx.getAndIncrement());
-
-                assertTrue(ignite.configuration().isClientMode());
-
-                log.info("Started node: " + ignite.name());
-
-                return null;
-            }
-        }, 5, "start-thread");
-
-        barrier.await();
-
-        U.sleep(ThreadLocalRandom.current().nextInt(10, 100));
-
-        for (int i = 0; i < 3; i++)
-            stopGrid(i);
-
-        fut.get();
-
-        assertEquals(6, ignite(3).cluster().nodes().size());
-
-        for (int i = 3; i < 7; i++) {
-            log.info("Check metadata on node: " + i);
-
-            boolean client = i > 3;
-
-            assertEquals((Object) client, ignite(i).configuration().isClientMode());
-
-            portables = ignite(i).binary();
-
-            final IgniteBinary p0 = portables;
-
-            GridTestUtils.waitForCondition(new GridAbsPredicate() {
-                @Override public boolean apply() {
-                    Collection<BinaryType> metaCol = p0.types();
-
-                    return metaCol.size() == 1000;
-                }
-            }, getTestTimeout());
-
-            Collection<BinaryType> metaCol = portables.types();
-
-            assertEquals(1000, metaCol.size());
-
-            Set<String> names = new HashSet<>();
-
-            for (BinaryType meta : metaCol) {
-                assertTrue(names.add(meta.typeName()));
-
-                assertNull(meta.affinityKeyFieldName());
-
-                assertEquals(1, meta.fieldNames().size());
-            }
-
-            assertEquals(1000, names.size());
-        }
-    }
-
-    /**
-     * @throws Exception If failed.
-     */
-    public void testClientStartsFirst() throws Exception {
-        client = true;
-
-        Ignite ignite0 = startGrid(0);
-
-        assertTrue(ignite0.configuration().isClientMode());
-
-        client = false;
-
-        Ignite ignite1 = startGrid(1);
-
-        assertFalse(ignite1.configuration().isClientMode());
-
-        IgniteBinary portables = ignite(1).binary();
-
-        IgniteCache<Object, Object> cache = ignite(1).cache(null).withKeepBinary();
-
-        for (int i = 0; i < 100; i++) {
-            BinaryObjectBuilder builder = portables.builder("type-" + i);
-
-            builder.setField("f0", i);
-
-            cache.put(i, builder.build());
-        }
-
-        assertEquals(100, ignite(0).binary().types().size());
-    }
-}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ignite/blob/1dbf20e0/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/GridCacheClientNodeBinaryObjectMetadataTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/GridCacheClientNodeBinaryObjectMetadataTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/GridCacheClientNodeBinaryObjectMetadataTest.java
deleted file mode 100644
index a108f4c..0000000
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/GridCacheClientNodeBinaryObjectMetadataTest.java
+++ /dev/null
@@ -1,221 +0,0 @@
-/*
- * 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.processors.cache.portable;
-
-import java.util.Arrays;
-import java.util.Collection;
-import org.apache.ignite.Ignite;
-import org.apache.ignite.binary.BinaryType;
-import org.apache.ignite.binary.BinaryTypeConfiguration;
-import org.apache.ignite.cache.CacheAtomicityMode;
-import org.apache.ignite.cache.CacheKeyConfiguration;
-import org.apache.ignite.cache.CacheMode;
-import org.apache.ignite.cache.affinity.Affinity;
-import org.apache.ignite.configuration.BinaryConfiguration;
-import org.apache.ignite.configuration.IgniteConfiguration;
-import org.apache.ignite.configuration.NearCacheConfiguration;
-import org.apache.ignite.internal.processors.cache.GridCacheAbstractSelfTest;
-import org.apache.ignite.internal.portable.BinaryMarshaller;
-import org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi;
-
-import static org.apache.ignite.cache.CacheAtomicityMode.ATOMIC;
-
-/**
- *
- */
-public class GridCacheClientNodeBinaryObjectMetadataTest extends GridCacheAbstractSelfTest {
-    /** {@inheritDoc} */
-    @Override protected int gridCount() {
-        return 4;
-    }
-
-    /** {@inheritDoc} */
-    @Override protected CacheMode cacheMode() {
-        return CacheMode.PARTITIONED;
-    }
-
-    /** {@inheritDoc} */
-    @Override protected CacheAtomicityMode atomicityMode() {
-        return ATOMIC;
-    }
-
-    /** {@inheritDoc} */
-    @Override protected NearCacheConfiguration nearConfiguration() {
-        return null;
-    }
-
-    /** {@inheritDoc} */
-    @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception {
-        IgniteConfiguration cfg = super.getConfiguration(gridName);
-
-        BinaryMarshaller marsh = new BinaryMarshaller();
-
-        BinaryConfiguration bCfg = new BinaryConfiguration();
-
-        bCfg.setClassNames(Arrays.asList(TestObject1.class.getName(), TestObject2.class.getName()));
-
-        BinaryTypeConfiguration typeCfg = new BinaryTypeConfiguration();
-
-        typeCfg.setTypeName(TestObject1.class.getName());
-
-        CacheKeyConfiguration keyCfg = new CacheKeyConfiguration(TestObject1.class.getName(), "val2");
-
-        cfg.setCacheKeyConfiguration(keyCfg);
-
-        bCfg.setTypeConfigurations(Arrays.asList(typeCfg));
-
-        cfg.setBinaryConfiguration(bCfg);
-
-        if (gridName.equals(getTestGridName(gridCount() - 1)))
-            cfg.setClientMode(true);
-
-        cfg.setMarshaller(marsh);
-
-        ((TcpDiscoverySpi)cfg.getDiscoverySpi()).setForceServerMode(true);
-
-        return cfg;
-    }
-
-    /**
-     * @throws Exception If failed.
-     */
-    public void testPortableMetadataOnClient() throws Exception {
-        Ignite ignite0 = ignite(gridCount() - 1);
-
-        assertTrue(ignite0.configuration().isClientMode());
-
-        Ignite ignite1 = ignite(0);
-
-        assertFalse(ignite1.configuration().isClientMode());
-
-        Affinity<Object> aff0 = ignite0.affinity(null);
-        Affinity<Object> aff1 = ignite1.affinity(null);
-
-        for (int i = 0 ; i < 100; i++) {
-            TestObject1 obj1 = new TestObject1(i, i + 1);
-
-            assertEquals(aff1.mapKeyToPrimaryAndBackups(obj1),
-                aff0.mapKeyToPrimaryAndBackups(obj1));
-
-            TestObject2 obj2 = new TestObject2(i, i + 1);
-
-            assertEquals(aff1.mapKeyToPrimaryAndBackups(obj2),
-                aff0.mapKeyToPrimaryAndBackups(obj2));
-        }
-
-        Collection<BinaryType> meta1 = ignite1.binary().types();
-        Collection<BinaryType> meta2 = ignite1.binary().types();
-
-        assertEquals(meta1.size(), meta2.size());
-
-        for (BinaryType m1 : meta1) {
-            boolean found = false;
-
-            for (BinaryType m2 : meta1) {
-                if (m1.typeName().equals(m2.typeName())) {
-                    assertEquals(m1.affinityKeyFieldName(), m2.affinityKeyFieldName());
-                    assertEquals(m1.fieldNames(), m2.fieldNames());
-
-                    found = true;
-
-                    break;
-                }
-            }
-
-            assertTrue(found);
-        }
-    }
-
-    /**
-     *
-     */
-    static class TestObject1 {
-        /** */
-        private int val1;
-
-        /** */
-        private int val2;
-
-        /**
-         * @param val1 Value 1.
-         * @param val2 Value 2.
-         */
-        public TestObject1(int val1, int val2) {
-            this.val1 = val1;
-            this.val2 = val2;
-        }
-
-        /** {@inheritDoc} */
-        @Override public boolean equals(Object o) {
-            if (this == o)
-                return true;
-
-            if (o == null || getClass() != o.getClass())
-                return false;
-
-            TestObject1 that = (TestObject1)o;
-
-            return val1 == that.val1;
-
-        }
-
-        /** {@inheritDoc} */
-        @Override public int hashCode() {
-            return val1;
-        }
-    }
-
-    /**
-     *
-     */
-    static class TestObject2 {
-        /** */
-        private int val1;
-
-        /** */
-        private int val2;
-
-        /**
-         * @param val1 Value 1.
-         * @param val2 Value 2.
-         */
-        public TestObject2(int val1, int val2) {
-            this.val1 = val1;
-            this.val2 = val2;
-        }
-
-        /** {@inheritDoc} */
-        @Override public boolean equals(Object o) {
-            if (this == o)
-                return true;
-
-            if (o == null || getClass() != o.getClass())
-                return false;
-
-            TestObject2 that = (TestObject2)o;
-
-            return val2 == that.val2;
-
-        }
-
-        /** {@inheritDoc} */
-        @Override public int hashCode() {
-            return val2;
-        }
-    }
-}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ignite/blob/1dbf20e0/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/GridCachePortableStoreAbstractSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/GridCachePortableStoreAbstractSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/GridCachePortableStoreAbstractSelfTest.java
deleted file mode 100644
index 892a891..0000000
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/GridCachePortableStoreAbstractSelfTest.java
+++ /dev/null
@@ -1,300 +0,0 @@
-/*
- * 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.processors.cache.portable;
-
-import com.google.common.collect.ImmutableSet;
-import java.util.Arrays;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Map;
-import java.util.Set;
-import javax.cache.Cache;
-import org.apache.ignite.cache.store.CacheStoreAdapter;
-import org.apache.ignite.configuration.BinaryConfiguration;
-import org.apache.ignite.configuration.CacheConfiguration;
-import org.apache.ignite.configuration.IgniteConfiguration;
-import org.apache.ignite.internal.portable.BinaryMarshaller;
-import org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi;
-import org.apache.ignite.spi.discovery.tcp.ipfinder.TcpDiscoveryIpFinder;
-import org.apache.ignite.spi.discovery.tcp.ipfinder.vm.TcpDiscoveryVmIpFinder;
-import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
-import org.jetbrains.annotations.Nullable;
-import org.jsr166.ConcurrentHashMap8;
-
-/**
- * Tests for cache store with binary.
- */
-public abstract class GridCachePortableStoreAbstractSelfTest extends GridCommonAbstractTest {
-    /** */
-    private static final TcpDiscoveryIpFinder IP_FINDER = new TcpDiscoveryVmIpFinder(true);
-
-    /** */
-    private static final TestStore STORE = new TestStore();
-
-    /** {@inheritDoc} */
-    @SuppressWarnings("unchecked")
-    @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception {
-        IgniteConfiguration cfg = super.getConfiguration(gridName);
-
-        BinaryConfiguration bCfg = new BinaryConfiguration();
-
-        bCfg.setClassNames(Arrays.asList(Key.class.getName(), Value.class.getName()));
-
-        cfg.setBinaryConfiguration(bCfg);
-
-        cfg.setMarshaller(new BinaryMarshaller());
-
-        CacheConfiguration cacheCfg = new CacheConfiguration();
-
-        cacheCfg.setCacheStoreFactory(singletonFactory(STORE));
-        cacheCfg.setKeepBinaryInStore(keepPortableInStore());
-        cacheCfg.setReadThrough(true);
-        cacheCfg.setWriteThrough(true);
-        cacheCfg.setLoadPreviousValue(true);
-
-        cfg.setCacheConfiguration(cacheCfg);
-
-        TcpDiscoverySpi disco = new TcpDiscoverySpi();
-
-        disco.setIpFinder(IP_FINDER);
-
-        cfg.setDiscoverySpi(disco);
-
-        return cfg;
-    }
-
-    /**
-     * @return Keep binary in store flag.
-     */
-    protected abstract boolean keepPortableInStore();
-
-    /** {@inheritDoc} */
-    @Override protected void beforeTestsStarted() throws Exception {
-        startGrid();
-    }
-
-    /** {@inheritDoc} */
-    @Override protected void afterTestsStopped() throws Exception {
-        stopGrid();
-    }
-
-    /** {@inheritDoc} */
-    @Override protected void beforeTest() throws Exception {
-        STORE.map().clear();
-
-        jcache().clear();
-
-        assert jcache().size() == 0;
-    }
-
-    /**
-     * @throws Exception If failed.
-     */
-    public void testPut() throws Exception {
-        jcache().put(new Key(1), new Value(1));
-
-        checkMap(STORE.map(), 1);
-    }
-
-    /**
-     * @throws Exception If failed.
-     */
-    public void testPutAll() throws Exception {
-        Map<Object, Object> map = new HashMap<>();
-
-        for (int i = 1; i <= 3; i++)
-            map.put(new Key(i), new Value(i));
-
-        jcache().putAll(map);
-
-        checkMap(STORE.map(), 1, 2, 3);
-    }
-
-    /**
-     * @throws Exception If failed.
-     */
-    public void testLoad() throws Exception {
-        populateMap(STORE.map(), 1);
-
-        Object val = jcache().get(new Key(1));
-
-        assertTrue(String.valueOf(val), val instanceof Value);
-
-        assertEquals(1, ((Value)val).index());
-    }
-
-    /**
-     * @throws Exception If failed.
-     */
-    public void testLoadAll() throws Exception {
-        populateMap(STORE.map(), 1, 2, 3);
-
-        Set<Object> keys = new HashSet<>();
-
-        for (int i = 1; i <= 3; i++)
-            keys.add(new Key(i));
-
-        Map<Object, Object> res = jcache().getAll(keys);
-
-        assertEquals(3, res.size());
-
-        for (int i = 1; i <= 3; i++) {
-            Object val = res.get(new Key(i));
-
-            assertTrue(String.valueOf(val), val instanceof Value);
-
-            assertEquals(i, ((Value)val).index());
-        }
-    }
-
-    /**
-     * @throws Exception If failed.
-     */
-    public void testRemove() throws Exception {
-        for (int i = 1; i <= 3; i++)
-            jcache().put(new Key(i), new Value(i));
-
-        jcache().remove(new Key(1));
-
-        checkMap(STORE.map(), 2, 3);
-    }
-
-    /**
-     * @throws Exception If failed.
-     */
-    public void testRemoveAll() throws Exception {
-        for (int i = 1; i <= 3; i++)
-            jcache().put(new Key(i), new Value(i));
-
-        jcache().removeAll(ImmutableSet.of(new Key(1), new Key(2)));
-
-        checkMap(STORE.map(), 3);
-    }
-
-    /**
-     * @param map Map.
-     * @param idxs Indexes.
-     */
-    protected abstract void populateMap(Map<Object, Object> map, int... idxs);
-
-    /**
-     * @param map Map.
-     * @param idxs Indexes.
-     */
-    protected abstract void checkMap(Map<Object, Object> map, int... idxs);
-
-    /**
-     */
-    protected static class Key {
-        /** */
-        private int idx;
-
-        /**
-         * @param idx Index.
-         */
-        public Key(int idx) {
-            this.idx = idx;
-        }
-
-        /**
-         * @return Index.
-         */
-        int index() {
-            return idx;
-        }
-
-        /** {@inheritDoc} */
-        @Override public boolean equals(Object o) {
-            if (this == o)
-                return true;
-
-            if (o == null || getClass() != o.getClass())
-                return false;
-
-            Key key = (Key)o;
-
-            return idx == key.idx;
-        }
-
-        /** {@inheritDoc} */
-        @Override public int hashCode() {
-            return idx;
-        }
-
-        /** {@inheritDoc} */
-        @Override public String toString() {
-            return "Key [idx=" + idx + ']';
-        }
-    }
-
-    /**
-     */
-    protected static class Value {
-        /** */
-        private int idx;
-
-        /**
-         * @param idx Index.
-         */
-        public Value(int idx) {
-            this.idx = idx;
-        }
-
-        /**
-         * @return Index.
-         */
-        int index() {
-            return idx;
-        }
-
-        /** {@inheritDoc} */
-        @Override public String toString() {
-            return "Value [idx=" + idx + ']';
-        }
-    }
-
-    /**
-     *
-     */
-    private static class TestStore extends CacheStoreAdapter<Object, Object> {
-        /** */
-        private final Map<Object, Object> map = new ConcurrentHashMap8<>();
-
-        /** {@inheritDoc} */
-        @Nullable @Override public Object load(Object key) {
-            return map.get(key);
-        }
-
-        /** {@inheritDoc} */
-        @Override public void write(Cache.Entry<?, ?> e) {
-            map.put(e.getKey(), e.getValue());
-        }
-
-        /** {@inheritDoc} */
-        @Override public void delete(Object key) {
-            map.remove(key);
-        }
-
-        /**
-         * @return Map.
-         */
-        Map<Object, Object> map() {
-            return map;
-        }
-    }
-}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ignite/blob/1dbf20e0/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/GridCachePortableStoreObjectsSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/GridCachePortableStoreObjectsSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/GridCachePortableStoreObjectsSelfTest.java
deleted file mode 100644
index 8f81572..0000000
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/GridCachePortableStoreObjectsSelfTest.java
+++ /dev/null
@@ -1,55 +0,0 @@
-/*
- * 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.processors.cache.portable;
-
-import java.util.Map;
-
-/**
- * Tests for cache store with binary.
- */
-public class GridCachePortableStoreObjectsSelfTest extends GridCachePortableStoreAbstractSelfTest {
-    /** {@inheritDoc} */
-    @Override protected boolean keepPortableInStore() {
-        return false;
-    }
-
-    /** {@inheritDoc} */
-    @Override protected void populateMap(Map<Object, Object> map, int... idxs) {
-        assert map != null;
-        assert idxs != null;
-
-        for (int idx : idxs)
-            map.put(new Key(idx), new Value(idx));
-    }
-
-    /** {@inheritDoc} */
-    @Override protected void checkMap(Map<Object, Object> map, int... idxs) {
-        assert map != null;
-        assert idxs != null;
-
-        assertEquals(idxs.length, map.size());
-
-        for (int idx : idxs) {
-            Object val = map.get(new Key(idx));
-
-            assertTrue(String.valueOf(val), val instanceof Value);
-
-            assertEquals(idx, ((Value)val).index());
-        }
-    }
-}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ignite/blob/1dbf20e0/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/GridCachePortableStorePortablesSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/GridCachePortableStorePortablesSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/GridCachePortableStorePortablesSelfTest.java
deleted file mode 100644
index 95101df..0000000
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/GridCachePortableStorePortablesSelfTest.java
+++ /dev/null
@@ -1,66 +0,0 @@
-/*
- * 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.processors.cache.portable;
-
-import java.util.Map;
-import org.apache.ignite.binary.BinaryObject;
-
-/**
- * Tests for cache store with binary.
- */
-public class GridCachePortableStorePortablesSelfTest extends GridCachePortableStoreAbstractSelfTest {
-    /** {@inheritDoc} */
-    @Override protected boolean keepPortableInStore() {
-        return true;
-    }
-
-    /** {@inheritDoc} */
-    @Override protected void populateMap(Map<Object, Object> map, int... idxs) {
-        assert map != null;
-        assert idxs != null;
-
-        for (int idx : idxs)
-            map.put(portable(new Key(idx)), portable(new Value(idx)));
-    }
-
-    /** {@inheritDoc} */
-    @Override protected void checkMap(Map<Object, Object> map, int... idxs) {
-        assert map != null;
-        assert idxs != null;
-
-        assertEquals(idxs.length, map.size());
-
-        for (int idx : idxs) {
-            Object val = map.get(portable(new Key(idx)));
-
-            assertTrue(String.valueOf(val), val instanceof BinaryObject);
-
-            BinaryObject po = (BinaryObject)val;
-
-            assertEquals("Value", po.type().typeName());
-            assertEquals(new Integer(idx), po.field("idx"));
-        }
-    }
-
-    /**
-     * @param obj Object.
-     * @return Portable object.
-     */
-    private Object portable(Object obj) {
-        return grid().binary().toBinary(obj);
-    }
-}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ignite/blob/1dbf20e0/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/GridPortableCacheEntryMemorySizeSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/GridPortableCacheEntryMemorySizeSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/GridPortableCacheEntryMemorySizeSelfTest.java
deleted file mode 100644
index a965588..0000000
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/GridPortableCacheEntryMemorySizeSelfTest.java
+++ /dev/null
@@ -1,48 +0,0 @@
-/*
- * 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.processors.cache.portable;
-
-import org.apache.ignite.IgniteCheckedException;
-import org.apache.ignite.configuration.IgniteConfiguration;
-import org.apache.ignite.internal.portable.BinaryNoopMetadataHandler;
-import org.apache.ignite.internal.portable.PortableContext;
-import org.apache.ignite.internal.processors.cache.GridCacheEntryMemorySizeSelfTest;
-import org.apache.ignite.internal.util.IgniteUtils;
-import org.apache.ignite.marshaller.Marshaller;
-import org.apache.ignite.marshaller.MarshallerContextTestImpl;
-import org.apache.ignite.internal.portable.BinaryMarshaller;
-
-/**
- *
- */
-public class GridPortableCacheEntryMemorySizeSelfTest extends GridCacheEntryMemorySizeSelfTest {
-    /** {@inheritDoc} */
-    @Override protected Marshaller createMarshaller() throws IgniteCheckedException {
-        BinaryMarshaller marsh = new BinaryMarshaller();
-
-        marsh.setContext(new MarshallerContextTestImpl(null));
-
-        IgniteConfiguration iCfg = new IgniteConfiguration();
-
-        PortableContext pCtx = new PortableContext(BinaryNoopMetadataHandler.instance(), iCfg);
-
-        IgniteUtils.invoke(BinaryMarshaller.class, marsh, "setPortableContext", pCtx, iCfg);
-
-        return marsh;
-    }
-}
\ No newline at end of file


[10/59] [abbrv] ignite git commit: ignite-2065: rename "portable" packages to "binary"

Posted by ak...@apache.org.
http://git-wip-us.apache.org/repos/asf/ignite/blob/1dbf20e0/modules/core/src/test/java/org/apache/ignite/internal/binary/GridPortableMarshallerCtxDisabledSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/binary/GridPortableMarshallerCtxDisabledSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/binary/GridPortableMarshallerCtxDisabledSelfTest.java
new file mode 100644
index 0000000..a30d09f
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/binary/GridPortableMarshallerCtxDisabledSelfTest.java
@@ -0,0 +1,247 @@
+/*
+ * 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.binary;
+
+import org.apache.ignite.IgniteCheckedException;
+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.configuration.IgniteConfiguration;
+import org.apache.ignite.internal.MarshallerContextAdapter;
+import org.apache.ignite.internal.util.IgniteUtils;
+import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
+
+import java.io.Externalizable;
+import java.io.IOException;
+import java.io.ObjectInput;
+import java.io.ObjectOutput;
+import java.util.Arrays;
+
+/**
+ *
+ */
+public class GridPortableMarshallerCtxDisabledSelfTest extends GridCommonAbstractTest {
+    /**
+     * @throws Exception If failed.
+     */
+    public void testObjectExchange() throws Exception {
+        BinaryMarshaller marsh = new BinaryMarshaller();
+        marsh.setContext(new MarshallerContextWithNoStorage());
+
+        IgniteConfiguration cfg = new IgniteConfiguration();
+
+        PortableContext context = new PortableContext(BinaryCachingMetadataHandler.create(), cfg);
+
+        IgniteUtils.invoke(BinaryMarshaller.class, marsh, "setPortableContext", context, cfg);
+
+        SimpleObject simpleObj = new SimpleObject();
+
+        simpleObj.b = 2;
+        simpleObj.bArr = new byte[] {2, 3, 4, 5, 5};
+        simpleObj.c = 'A';
+        simpleObj.enumVal = TestEnum.D;
+        simpleObj.objArr = new Object[] {"hello", "world", "from", "me"};
+        simpleObj.enumArr = new TestEnum[] {TestEnum.C, TestEnum.B};
+
+        SimpleObject otherObj = new SimpleObject();
+
+        otherObj.b = 3;
+        otherObj.bArr = new byte[] {5, 3, 4};
+
+        simpleObj.otherObj = otherObj;
+
+        assertEquals(simpleObj, marsh.unmarshal(marsh.marshal(simpleObj), null));
+
+        SimpleBinary simplePortable = new SimpleBinary();
+
+        simplePortable.str = "portable";
+        simplePortable.arr = new long[] {100, 200, 300};
+
+        assertEquals(simplePortable, marsh.unmarshal(marsh.marshal(simplePortable), null));
+
+        SimpleExternalizable simpleExtr = new SimpleExternalizable();
+
+        simpleExtr.str = "externalizable";
+        simpleExtr.arr = new long[] {20000, 300000, 400000};
+
+        assertEquals(simpleExtr, marsh.unmarshal(marsh.marshal(simpleExtr), null));
+    }
+
+    /**
+     * Marshaller context with no storage. Platform has to work in such environment as well by marshalling class name of
+     * a portable object.
+     */
+    private static class MarshallerContextWithNoStorage extends MarshallerContextAdapter {
+        /** */
+        public MarshallerContextWithNoStorage() {
+            super(null);
+        }
+
+        /** {@inheritDoc} */
+        @Override protected boolean registerClassName(int id, String clsName) throws IgniteCheckedException {
+            return false;
+        }
+
+        /** {@inheritDoc} */
+        @Override protected String className(int id) throws IgniteCheckedException {
+            return null;
+        }
+    }
+
+    /**
+     */
+    private enum TestEnum {
+        A, B, C, D, E
+    }
+
+    /**
+     */
+    private static class SimpleObject {
+        /** */
+        private byte b;
+
+        /** */
+        private char c;
+
+        /** */
+        private byte[] bArr;
+
+        /** */
+        private Object[] objArr;
+
+        /** */
+        private TestEnum enumVal;
+
+        /** */
+        private TestEnum[] enumArr;
+
+        private SimpleObject otherObj;
+
+        /** {@inheritDoc} */
+        @Override public boolean equals(Object o) {
+            if (this == o)
+                return true;
+
+            if (o == null || getClass() != o.getClass())
+                return false;
+
+            SimpleObject object = (SimpleObject)o;
+
+            if (b != object.b)
+                return false;
+
+            if (c != object.c)
+                return false;
+
+            if (!Arrays.equals(bArr, object.bArr))
+                return false;
+
+            // Probably incorrect - comparing Object[] arrays with Arrays.equals
+            if (!Arrays.equals(objArr, object.objArr))
+                return false;
+
+            if (enumVal != object.enumVal)
+                return false;
+
+            // Probably incorrect - comparing Object[] arrays with Arrays.equals
+            if (!Arrays.equals(enumArr, object.enumArr))
+                return false;
+
+            return !(otherObj != null ? !otherObj.equals(object.otherObj) : object.otherObj != null);
+        }
+    }
+
+    /**
+     *
+     */
+    private static class SimpleBinary implements Binarylizable {
+        /** */
+        private String str;
+
+        /** */
+        private long[] arr;
+
+        /** {@inheritDoc} */
+        @Override public void writeBinary(BinaryWriter writer) throws BinaryObjectException {
+            writer.writeString("str", str);
+            writer.writeLongArray("longArr", arr);
+        }
+
+        /** {@inheritDoc} */
+        @Override public void readBinary(BinaryReader reader) throws BinaryObjectException {
+            str = reader.readString("str");
+            arr = reader.readLongArray("longArr");
+        }
+
+        /** {@inheritDoc} */
+        @Override public boolean equals(Object o) {
+            if (this == o)
+                return true;
+
+            if (o == null || getClass() != o.getClass())
+                return false;
+
+            SimpleBinary that = (SimpleBinary)o;
+
+            if (str != null ? !str.equals(that.str) : that.str != null)
+                return false;
+
+            return Arrays.equals(arr, that.arr);
+        }
+    }
+
+    /**
+     *
+     */
+    private static class SimpleExternalizable implements Externalizable {
+        /** */
+        private String str;
+
+        /** */
+        private long[] arr;
+
+        /** {@inheritDoc} */
+        @Override public void writeExternal(ObjectOutput out) throws IOException {
+            out.writeUTF(str);
+            out.writeObject(arr);
+        }
+
+        /** {@inheritDoc} */
+        @Override public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
+            str = in.readUTF();
+            arr = (long[])in.readObject();
+        }
+
+        /** {@inheritDoc} */
+        @Override public boolean equals(Object o) {
+            if (this == o)
+                return true;
+
+            if (o == null || getClass() != o.getClass())
+                return false;
+
+            SimpleExternalizable that = (SimpleExternalizable)o;
+
+            if (str != null ? !str.equals(that.str) : that.str != null)
+                return false;
+
+            return Arrays.equals(arr, that.arr);
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/1dbf20e0/modules/core/src/test/java/org/apache/ignite/internal/binary/GridPortableMetaDataSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/binary/GridPortableMetaDataSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/binary/GridPortableMetaDataSelfTest.java
new file mode 100644
index 0000000..5d74e12
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/binary/GridPortableMetaDataSelfTest.java
@@ -0,0 +1,371 @@
+/*
+ * 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.binary;
+
+import java.math.BigDecimal;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Date;
+import java.util.HashMap;
+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.binary.BinaryObjectException;
+import org.apache.ignite.binary.Binarylizable;
+import org.apache.ignite.binary.BinaryType;
+import org.apache.ignite.binary.BinaryObject;
+import org.apache.ignite.binary.BinaryRawWriter;
+import org.apache.ignite.binary.BinaryReader;
+import org.apache.ignite.binary.BinaryWriter;
+import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
+
+/**
+ * Portable meta data test.
+ */
+public class GridPortableMetaDataSelfTest extends GridCommonAbstractTest {
+    /** */
+    private static int idx;
+
+    /** {@inheritDoc} */
+    @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception {
+        IgniteConfiguration cfg = super.getConfiguration(gridName);
+
+        BinaryConfiguration bCfg = new BinaryConfiguration();
+
+        bCfg.setClassNames(Arrays.asList(TestObject1.class.getName(), TestObject2.class.getName()));
+
+        cfg.setBinaryConfiguration(bCfg);
+
+        cfg.setMarshaller(new BinaryMarshaller());
+
+        CacheConfiguration ccfg = new CacheConfiguration();
+
+        cfg.setCacheConfiguration(ccfg);
+
+        return cfg;
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void beforeTest() throws Exception {
+        idx = 0;
+
+        startGrid();
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void afterTest() throws Exception {
+        stopGrid();
+    }
+
+    /**
+     * @return Portables API.
+     */
+    protected IgniteBinary portables() {
+        return grid().binary();
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testGetAll() throws Exception {
+        portables().toBinary(new TestObject2());
+
+        Collection<BinaryType> metas = portables().types();
+
+        assertEquals(2, metas.size());
+
+        for (BinaryType meta : metas) {
+            Collection<String> fields;
+
+            switch (meta.typeName()) {
+                case "TestObject1":
+                    fields = meta.fieldNames();
+
+                    assertEquals(7, fields.size());
+
+                    assertTrue(fields.contains("intVal"));
+                    assertTrue(fields.contains("strVal"));
+                    assertTrue(fields.contains("arrVal"));
+                    assertTrue(fields.contains("obj1Val"));
+                    assertTrue(fields.contains("obj2Val"));
+                    assertTrue(fields.contains("decVal"));
+                    assertTrue(fields.contains("decArrVal"));
+
+                    assertEquals("int", meta.fieldTypeName("intVal"));
+                    assertEquals("String", meta.fieldTypeName("strVal"));
+                    assertEquals("byte[]", meta.fieldTypeName("arrVal"));
+                    assertEquals("Object", meta.fieldTypeName("obj1Val"));
+                    assertEquals("Object", meta.fieldTypeName("obj2Val"));
+                    assertEquals("decimal", meta.fieldTypeName("decVal"));
+                    assertEquals("decimal[]", meta.fieldTypeName("decArrVal"));
+
+                    break;
+
+                case "TestObject2":
+                    fields = meta.fieldNames();
+
+                    assertEquals(7, fields.size());
+
+                    assertTrue(fields.contains("boolVal"));
+                    assertTrue(fields.contains("dateVal"));
+                    assertTrue(fields.contains("uuidArrVal"));
+                    assertTrue(fields.contains("objVal"));
+                    assertTrue(fields.contains("mapVal"));
+                    assertTrue(fields.contains("decVal"));
+                    assertTrue(fields.contains("decArrVal"));
+
+                    assertEquals("boolean", meta.fieldTypeName("boolVal"));
+                    assertEquals("Date", meta.fieldTypeName("dateVal"));
+                    assertEquals("UUID[]", meta.fieldTypeName("uuidArrVal"));
+                    assertEquals("Object", meta.fieldTypeName("objVal"));
+                    assertEquals("Map", meta.fieldTypeName("mapVal"));
+                    assertEquals("decimal", meta.fieldTypeName("decVal"));
+                    assertEquals("decimal[]", meta.fieldTypeName("decArrVal"));
+
+                    break;
+
+                default:
+                    assert false : meta.typeName();
+            }
+        }
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testNoConfiguration() throws Exception {
+        portables().toBinary(new TestObject3());
+
+        assertNotNull(portables().type(TestObject3.class));
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testReflection() throws Exception {
+        BinaryType meta = portables().type(TestObject1.class);
+
+        assertNotNull(meta);
+
+        assertEquals("TestObject1", meta.typeName());
+
+        Collection<String> fields = meta.fieldNames();
+
+        assertEquals(7, fields.size());
+
+        assertTrue(fields.contains("intVal"));
+        assertTrue(fields.contains("strVal"));
+        assertTrue(fields.contains("arrVal"));
+        assertTrue(fields.contains("obj1Val"));
+        assertTrue(fields.contains("obj2Val"));
+        assertTrue(fields.contains("decVal"));
+        assertTrue(fields.contains("decArrVal"));
+
+        assertEquals("int", meta.fieldTypeName("intVal"));
+        assertEquals("String", meta.fieldTypeName("strVal"));
+        assertEquals("byte[]", meta.fieldTypeName("arrVal"));
+        assertEquals("Object", meta.fieldTypeName("obj1Val"));
+        assertEquals("Object", meta.fieldTypeName("obj2Val"));
+        assertEquals("decimal", meta.fieldTypeName("decVal"));
+        assertEquals("decimal[]", meta.fieldTypeName("decArrVal"));
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testPortableMarshalAware() throws Exception {
+        portables().toBinary(new TestObject2());
+
+        BinaryType meta = portables().type(TestObject2.class);
+
+        assertNotNull(meta);
+
+        assertEquals("TestObject2", meta.typeName());
+
+        Collection<String> fields = meta.fieldNames();
+
+        assertEquals(7, fields.size());
+
+        assertTrue(fields.contains("boolVal"));
+        assertTrue(fields.contains("dateVal"));
+        assertTrue(fields.contains("uuidArrVal"));
+        assertTrue(fields.contains("objVal"));
+        assertTrue(fields.contains("mapVal"));
+        assertTrue(fields.contains("decVal"));
+        assertTrue(fields.contains("decArrVal"));
+
+        assertEquals("boolean", meta.fieldTypeName("boolVal"));
+        assertEquals("Date", meta.fieldTypeName("dateVal"));
+        assertEquals("UUID[]", meta.fieldTypeName("uuidArrVal"));
+        assertEquals("Object", meta.fieldTypeName("objVal"));
+        assertEquals("Map", meta.fieldTypeName("mapVal"));
+        assertEquals("decimal", meta.fieldTypeName("decVal"));
+        assertEquals("decimal[]", meta.fieldTypeName("decArrVal"));
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testMerge() throws Exception {
+        portables().toBinary(new TestObject2());
+
+        idx = 1;
+
+        portables().toBinary(new TestObject2());
+
+        BinaryType meta = portables().type(TestObject2.class);
+
+        assertNotNull(meta);
+
+        assertEquals("TestObject2", meta.typeName());
+
+        Collection<String> fields = meta.fieldNames();
+
+        assertEquals(9, fields.size());
+
+        assertTrue(fields.contains("boolVal"));
+        assertTrue(fields.contains("dateVal"));
+        assertTrue(fields.contains("uuidArrVal"));
+        assertTrue(fields.contains("objVal"));
+        assertTrue(fields.contains("mapVal"));
+        assertTrue(fields.contains("charVal"));
+        assertTrue(fields.contains("colVal"));
+        assertTrue(fields.contains("decVal"));
+        assertTrue(fields.contains("decArrVal"));
+
+        assertEquals("boolean", meta.fieldTypeName("boolVal"));
+        assertEquals("Date", meta.fieldTypeName("dateVal"));
+        assertEquals("UUID[]", meta.fieldTypeName("uuidArrVal"));
+        assertEquals("Object", meta.fieldTypeName("objVal"));
+        assertEquals("Map", meta.fieldTypeName("mapVal"));
+        assertEquals("char", meta.fieldTypeName("charVal"));
+        assertEquals("Collection", meta.fieldTypeName("colVal"));
+        assertEquals("decimal", meta.fieldTypeName("decVal"));
+        assertEquals("decimal[]", meta.fieldTypeName("decArrVal"));
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testSerializedObject() throws Exception {
+        TestObject1 obj = new TestObject1();
+
+        obj.intVal = 10;
+        obj.strVal = "str";
+        obj.arrVal = new byte[] {2, 4, 6};
+        obj.obj1Val = null;
+        obj.obj2Val = new TestObject2();
+        obj.decVal = BigDecimal.ZERO;
+        obj.decArrVal = new BigDecimal[] { BigDecimal.ONE };
+
+        BinaryObject po = portables().toBinary(obj);
+
+        info(po.toString());
+
+        BinaryType meta = po.type();
+
+        assertNotNull(meta);
+
+        assertEquals("TestObject1", meta.typeName());
+
+        Collection<String> fields = meta.fieldNames();
+
+        assertEquals(7, fields.size());
+
+        assertTrue(fields.contains("intVal"));
+        assertTrue(fields.contains("strVal"));
+        assertTrue(fields.contains("arrVal"));
+        assertTrue(fields.contains("obj1Val"));
+        assertTrue(fields.contains("obj2Val"));
+        assertTrue(fields.contains("decVal"));
+        assertTrue(fields.contains("decArrVal"));
+
+        assertEquals("int", meta.fieldTypeName("intVal"));
+        assertEquals("String", meta.fieldTypeName("strVal"));
+        assertEquals("byte[]", meta.fieldTypeName("arrVal"));
+        assertEquals("Object", meta.fieldTypeName("obj1Val"));
+        assertEquals("Object", meta.fieldTypeName("obj2Val"));
+        assertEquals("decimal", meta.fieldTypeName("decVal"));
+        assertEquals("decimal[]", meta.fieldTypeName("decArrVal"));
+    }
+
+    /**
+     */
+    @SuppressWarnings("UnusedDeclaration")
+    private static class TestObject1 {
+        /** */
+        private int intVal;
+
+        /** */
+        private String strVal;
+
+        /** */
+        private byte[] arrVal;
+
+        /** */
+        private TestObject1 obj1Val;
+
+        /** */
+        private TestObject2 obj2Val;
+
+        /** */
+        private BigDecimal decVal;
+
+        /** */
+        private BigDecimal[] decArrVal;
+    }
+
+    /**
+     */
+    private static class TestObject2 implements Binarylizable {
+        /** {@inheritDoc} */
+        @Override public void writeBinary(BinaryWriter writer) throws BinaryObjectException {
+            writer.writeBoolean("boolVal", false);
+            writer.writeDate("dateVal", new Date());
+            writer.writeUuidArray("uuidArrVal", null);
+            writer.writeObject("objVal", null);
+            writer.writeMap("mapVal", new HashMap<>());
+            writer.writeDecimal("decVal", BigDecimal.ZERO);
+            writer.writeDecimalArray("decArrVal", new BigDecimal[] { BigDecimal.ONE });
+
+            if (idx == 1) {
+                writer.writeChar("charVal", (char)0);
+                writer.writeCollection("colVal", null);
+            }
+
+            BinaryRawWriter raw = writer.rawWriter();
+
+            raw.writeChar((char)0);
+            raw.writeCollection(null);
+        }
+
+        /** {@inheritDoc} */
+        @Override public void readBinary(BinaryReader reader) throws BinaryObjectException {
+            // No-op.
+        }
+    }
+
+    /**
+     */
+    @SuppressWarnings("UnusedDeclaration")
+    private static class TestObject3 {
+        /** */
+        private int intVal;
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/1dbf20e0/modules/core/src/test/java/org/apache/ignite/internal/binary/GridPortableWildcardsSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/binary/GridPortableWildcardsSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/binary/GridPortableWildcardsSelfTest.java
new file mode 100644
index 0000000..a91e350
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/binary/GridPortableWildcardsSelfTest.java
@@ -0,0 +1,464 @@
+/*
+ * 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.binary;
+
+import java.util.Collection;
+import org.apache.ignite.IgniteCheckedException;
+import org.apache.ignite.binary.BinaryIdMapper;
+import org.apache.ignite.binary.BinarySerializer;
+import org.apache.ignite.binary.BinaryTypeConfiguration;
+import org.apache.ignite.configuration.BinaryConfiguration;
+import org.apache.ignite.configuration.IgniteConfiguration;
+import org.apache.ignite.internal.util.IgniteUtils;
+import org.apache.ignite.internal.util.typedef.internal.U;
+import org.apache.ignite.marshaller.MarshallerContextTestImpl;
+import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
+
+import java.util.Arrays;
+import java.util.Map;
+
+/**
+ * Wildcards test.
+ */
+public class GridPortableWildcardsSelfTest extends GridCommonAbstractTest {
+    /**
+     * @throws Exception If failed.
+     */
+    public void testClassNames() throws Exception {
+        BinaryMarshaller marsh = portableMarshaller(Arrays.asList(
+            new BinaryTypeConfiguration("org.apache.ignite.internal.binary.test.*"),
+            new BinaryTypeConfiguration("unknown.*")
+        ));
+
+        PortableContext ctx = portableContext(marsh);
+
+        Map<Integer, Class> typeIds = U.field(ctx, "userTypes");
+
+        assertEquals(3, typeIds.size());
+
+        assertTrue(typeIds.containsKey("gridportabletestclass1".hashCode()));
+        assertTrue(typeIds.containsKey("gridportabletestclass2".hashCode()));
+        assertTrue(typeIds.containsKey("innerclass".hashCode()));
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testClassNamesWithMapper() throws Exception {
+        BinaryMarshaller marsh = portableMarshaller(new BinaryIdMapper() {
+            @SuppressWarnings("IfMayBeConditional")
+            @Override public int typeId(String clsName) {
+                if (clsName.endsWith("1"))
+                    return 300;
+                else if (clsName.endsWith("2"))
+                    return 400;
+                else if (clsName.endsWith("InnerClass"))
+                    return 500;
+                else
+                    return -500;
+            }
+
+            @Override public int fieldId(int typeId, String fieldName) {
+                return 0;
+            }
+        }, Arrays.asList(
+            new BinaryTypeConfiguration("org.apache.ignite.internal.binary.test.*"),
+            new BinaryTypeConfiguration("unknown.*")
+        ));
+
+        PortableContext ctx = portableContext(marsh);
+
+        Map<String, BinaryIdMapper> typeMappers = U.field(ctx, "typeMappers");
+
+        assertEquals(3, typeMappers.size());
+
+        assertEquals(300, typeMappers.get("GridPortableTestClass1").typeId("GridPortableTestClass1"));
+        assertEquals(400, typeMappers.get("GridPortableTestClass2").typeId("GridPortableTestClass2"));
+        assertEquals(500, typeMappers.get("InnerClass").typeId("InnerClass"));
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testTypeConfigurations() throws Exception {
+        BinaryMarshaller marsh = portableMarshaller(Arrays.asList(
+            new BinaryTypeConfiguration("org.apache.ignite.internal.binary.test.*"),
+            new BinaryTypeConfiguration("unknown.*")
+        ));
+
+        PortableContext ctx = portableContext(marsh);
+
+        Map<Integer, Class> typeIds = U.field(ctx, "userTypes");
+
+        assertEquals(3, typeIds.size());
+
+        assertTrue(typeIds.containsKey("gridportabletestclass1".hashCode()));
+        assertTrue(typeIds.containsKey("gridportabletestclass2".hashCode()));
+        assertTrue(typeIds.containsKey("innerclass".hashCode()));
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testTypeConfigurationsWithGlobalMapper() throws Exception {
+        BinaryMarshaller marsh = portableMarshaller(new BinaryIdMapper() {
+            @SuppressWarnings("IfMayBeConditional")
+            @Override public int typeId(String clsName) {
+                if (clsName.endsWith("1"))
+                    return 300;
+                else if (clsName.endsWith("2"))
+                    return 400;
+                else if (clsName.endsWith("InnerClass"))
+                    return 500;
+                else
+                    return -500;
+            }
+
+            @Override public int fieldId(int typeId, String fieldName) {
+                return 0;
+            }
+        }, Arrays.asList(
+            new BinaryTypeConfiguration("org.apache.ignite.internal.binary.test.*"),
+            new BinaryTypeConfiguration("unknown.*")
+        ));
+
+        PortableContext ctx = portableContext(marsh);
+
+        Map<String, BinaryIdMapper> typeMappers = U.field(ctx, "typeMappers");
+
+        assertEquals(3, typeMappers.size());
+
+        assertEquals(300, typeMappers.get("GridPortableTestClass1").typeId("GridPortableTestClass1"));
+        assertEquals(400, typeMappers.get("GridPortableTestClass2").typeId("GridPortableTestClass2"));
+        assertEquals(500, typeMappers.get("InnerClass").typeId("InnerClass"));
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testTypeConfigurationsWithNonGlobalMapper() throws Exception {
+        BinaryMarshaller marsh = portableMarshaller(new BinaryIdMapper() {
+            @SuppressWarnings("IfMayBeConditional")
+            @Override public int typeId(String clsName) {
+                if (clsName.endsWith("1"))
+                    return 300;
+                else if (clsName.endsWith("2"))
+                    return 400;
+                else if (clsName.endsWith("InnerClass"))
+                    return 500;
+                else
+                    return -500;
+            }
+
+            @Override public int fieldId(int typeId, String fieldName) {
+                return 0;
+            }
+        }, Arrays.asList(
+            new BinaryTypeConfiguration("org.apache.ignite.internal.binary.test.*"),
+            new BinaryTypeConfiguration("unknown.*")
+        ));
+
+        PortableContext ctx = portableContext(marsh);
+
+        Map<String, BinaryIdMapper> typeMappers = U.field(ctx, "typeMappers");
+
+        assertEquals(3, typeMappers.size());
+
+        assertEquals(300, typeMappers.get("GridPortableTestClass1").typeId("GridPortableTestClass1"));
+        assertEquals(400, typeMappers.get("GridPortableTestClass2").typeId("GridPortableTestClass2"));
+        assertEquals(500, typeMappers.get("InnerClass").typeId("InnerClass"));
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testOverride() throws Exception {
+        BinaryTypeConfiguration typeCfg = new BinaryTypeConfiguration();
+
+        typeCfg.setTypeName("GridPortableTestClass2");
+        typeCfg.setIdMapper(new BinaryIdMapper() {
+            @Override public int typeId(String clsName) {
+                return 100;
+            }
+
+            @Override public int fieldId(int typeId, String fieldName) {
+                return 0;
+            }
+        });
+
+        BinaryMarshaller marsh = portableMarshaller(Arrays.asList(
+            new BinaryTypeConfiguration("org.apache.ignite.internal.binary.test.*"),
+            typeCfg));
+
+        PortableContext ctx = portableContext(marsh);
+
+        Map<Integer, Class> typeIds = U.field(ctx, "userTypes");
+
+        assertEquals(3, typeIds.size());
+
+        assertTrue(typeIds.containsKey("gridportabletestclass1".hashCode()));
+        assertTrue(typeIds.containsKey("innerclass".hashCode()));
+        assertFalse(typeIds.containsKey("gridportabletestclass2".hashCode()));
+
+        Map<String, BinaryIdMapper> typeMappers = U.field(ctx, "typeMappers");
+
+        assertEquals(100, typeMappers.get("GridPortableTestClass2").typeId("GridPortableTestClass2"));
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testClassNamesJar() throws Exception {
+        BinaryMarshaller marsh = portableMarshaller(Arrays.asList(
+            new BinaryTypeConfiguration("org.apache.ignite.binary.testjar.*"),
+            new BinaryTypeConfiguration("unknown.*")
+        ));
+
+        PortableContext ctx = portableContext(marsh);
+
+        Map<Integer, Class> typeIds = U.field(ctx, "userTypes");
+
+        assertEquals(3, typeIds.size());
+
+        assertTrue(typeIds.containsKey("gridportabletestclass1".hashCode()));
+        assertTrue(typeIds.containsKey("gridportabletestclass2".hashCode()));
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testClassNamesWithMapperJar() throws Exception {
+        BinaryMarshaller marsh = portableMarshaller(new BinaryIdMapper() {
+            @SuppressWarnings("IfMayBeConditional")
+            @Override public int typeId(String clsName) {
+                if (clsName.endsWith("1"))
+                    return 300;
+                else if (clsName.endsWith("2"))
+                    return 400;
+                else
+                    return -500;
+            }
+
+            @Override public int fieldId(int typeId, String fieldName) {
+                return 0;
+            }
+        }, Arrays.asList(
+            new BinaryTypeConfiguration("org.apache.ignite.binary.testjar.*"),
+            new BinaryTypeConfiguration("unknown.*")
+        ));
+
+        PortableContext ctx = portableContext(marsh);
+
+        Map<String, BinaryIdMapper> typeMappers = U.field(ctx, "typeMappers");
+
+        assertEquals(3, typeMappers.size());
+
+        assertEquals(300, typeMappers.get("GridPortableTestClass1").typeId("GridPortableTestClass1"));
+        assertEquals(400, typeMappers.get("GridPortableTestClass2").typeId("GridPortableTestClass2"));
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testTypeConfigurationsJar() throws Exception {
+        BinaryMarshaller marsh = portableMarshaller(Arrays.asList(
+            new BinaryTypeConfiguration("org.apache.ignite.binary.testjar.*"),
+            new BinaryTypeConfiguration("unknown.*")
+        ));
+
+        PortableContext ctx = portableContext(marsh);
+
+        Map<Integer, Class> typeIds = U.field(ctx, "userTypes");
+
+        assertEquals(3, typeIds.size());
+
+        assertTrue(typeIds.containsKey("gridportabletestclass1".hashCode()));
+        assertTrue(typeIds.containsKey("gridportabletestclass2".hashCode()));
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testTypeConfigurationsWithGlobalMapperJar() throws Exception {
+        BinaryMarshaller marsh = portableMarshaller(new BinaryIdMapper() {
+            @SuppressWarnings("IfMayBeConditional")
+            @Override public int typeId(String clsName) {
+                if (clsName.endsWith("1"))
+                    return 300;
+                else if (clsName.endsWith("2"))
+                    return 400;
+                else
+                    return -500;
+            }
+
+            @Override public int fieldId(int typeId, String fieldName) {
+                return 0;
+            }
+        }, Arrays.asList(
+            new BinaryTypeConfiguration("org.apache.ignite.binary.testjar.*"),
+            new BinaryTypeConfiguration("unknown.*")
+        ));
+
+        PortableContext ctx = portableContext(marsh);
+
+        Map<String, BinaryIdMapper> typeMappers = U.field(ctx, "typeMappers");
+
+        assertEquals(3, typeMappers.size());
+
+        assertEquals(300, typeMappers.get("GridPortableTestClass1").typeId("GridPortableTestClass1"));
+        assertEquals(400, typeMappers.get("GridPortableTestClass2").typeId("GridPortableTestClass2"));
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testTypeConfigurationsWithNonGlobalMapperJar() throws Exception {
+        BinaryMarshaller marsh = portableMarshaller(new BinaryIdMapper() {
+            @SuppressWarnings("IfMayBeConditional")
+            @Override public int typeId(String clsName) {
+                if (clsName.endsWith("1"))
+                    return 300;
+                else if (clsName.endsWith("2"))
+                    return 400;
+                else
+                    return -500;
+            }
+
+            @Override public int fieldId(int typeId, String fieldName) {
+                return 0;
+            }
+        }, Arrays.asList(
+            new BinaryTypeConfiguration("org.apache.ignite.binary.testjar.*"),
+            new BinaryTypeConfiguration("unknown.*")
+        ));
+
+        PortableContext ctx = portableContext(marsh);
+
+        Map<String, BinaryIdMapper> typeMappers = U.field(ctx, "typeMappers");
+
+        assertEquals(3, typeMappers.size());
+
+        assertEquals(300, typeMappers.get("GridPortableTestClass1").typeId("GridPortableTestClass1"));
+        assertEquals(400, typeMappers.get("GridPortableTestClass2").typeId("GridPortableTestClass2"));
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testOverrideJar() throws Exception {
+        BinaryTypeConfiguration typeCfg = new BinaryTypeConfiguration(
+            "org.apache.ignite.binary.testjar.GridPortableTestClass2");
+
+        typeCfg.setIdMapper(new BinaryIdMapper() {
+            @Override public int typeId(String clsName) {
+                return 100;
+            }
+
+            @Override public int fieldId(int typeId, String fieldName) {
+                return 0;
+            }
+        });
+
+        BinaryMarshaller marsh = portableMarshaller(Arrays.asList(
+            new BinaryTypeConfiguration("org.apache.ignite.binary.testjar.*"),
+            typeCfg));
+
+        PortableContext ctx = portableContext(marsh);
+
+        Map<Integer, Class> typeIds = U.field(ctx, "userTypes");
+
+        assertEquals(3, typeIds.size());
+
+        assertTrue(typeIds.containsKey("gridportabletestclass1".hashCode()));
+
+        Map<String, BinaryIdMapper> typeMappers = U.field(ctx, "typeMappers");
+
+        assertEquals(3, typeMappers.size());
+
+        assertEquals(100, typeMappers.get("GridPortableTestClass2").typeId("GridPortableTestClass2"));
+    }
+
+    /**
+     * @param marsh Marshaller.
+     * @return Portable context.
+     */
+    protected PortableContext portableContext(BinaryMarshaller marsh) {
+        GridPortableMarshaller impl = U.field(marsh, "impl");
+
+        return impl.context();
+    }
+
+    /**
+     *
+     */
+    protected BinaryMarshaller portableMarshaller()
+        throws IgniteCheckedException {
+        return portableMarshaller(null, null, null);
+    }
+
+    /**
+     *
+     */
+    protected BinaryMarshaller portableMarshaller(Collection<BinaryTypeConfiguration> cfgs)
+        throws IgniteCheckedException {
+        return portableMarshaller(null, null, cfgs);
+    }
+
+    /**
+     *
+     */
+    protected BinaryMarshaller portableMarshaller(BinaryIdMapper mapper, Collection<BinaryTypeConfiguration> cfgs)
+        throws IgniteCheckedException {
+        return portableMarshaller(mapper, null, cfgs);
+    }
+
+    /**
+     *
+     */
+    protected BinaryMarshaller portableMarshaller(BinarySerializer serializer, Collection<BinaryTypeConfiguration> cfgs)
+        throws IgniteCheckedException {
+        return portableMarshaller(null, serializer, cfgs);
+    }
+
+    protected BinaryMarshaller portableMarshaller(
+        BinaryIdMapper mapper,
+        BinarySerializer serializer,
+        Collection<BinaryTypeConfiguration> cfgs
+    ) throws IgniteCheckedException {
+        IgniteConfiguration iCfg = new IgniteConfiguration();
+
+        BinaryConfiguration bCfg = new BinaryConfiguration();
+
+        bCfg.setIdMapper(mapper);
+        bCfg.setSerializer(serializer);
+
+        bCfg.setTypeConfigurations(cfgs);
+
+        iCfg.setBinaryConfiguration(bCfg);
+
+        PortableContext ctx = new PortableContext(BinaryNoopMetadataHandler.instance(), iCfg);
+
+        BinaryMarshaller marsh = new BinaryMarshaller();
+
+        marsh.setContext(new MarshallerContextTestImpl(null));
+
+        IgniteUtils.invoke(BinaryMarshaller.class, marsh, "setPortableContext", ctx, iCfg);
+
+        return marsh;
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/1dbf20e0/modules/core/src/test/java/org/apache/ignite/internal/binary/TestCachingMetadataHandler.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/binary/TestCachingMetadataHandler.java b/modules/core/src/test/java/org/apache/ignite/internal/binary/TestCachingMetadataHandler.java
new file mode 100644
index 0000000..0f48961
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/binary/TestCachingMetadataHandler.java
@@ -0,0 +1,45 @@
+/*
+ * 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.binary;
+
+import org.apache.ignite.binary.BinaryObjectException;
+import org.apache.ignite.binary.BinaryType;
+
+import java.util.concurrent.ConcurrentHashMap;
+
+/**
+ * Test metadata handler.
+ */
+public class TestCachingMetadataHandler implements BinaryMetadataHandler {
+    /** Cached metadatas. */
+    private final ConcurrentHashMap<Integer, BinaryType> metas = new ConcurrentHashMap<>();
+
+    /** {@inheritDoc} */
+    @Override public void addMeta(int typeId, BinaryType meta) throws BinaryObjectException {
+        BinaryType otherType = metas.put(typeId, meta);
+
+        if (otherType != null)
+            throw new IllegalStateException("Metadata replacement is not allowed in " +
+                TestCachingMetadataHandler.class.getSimpleName() + '.');
+    }
+
+    /** {@inheritDoc} */
+    @Override public BinaryType metadata(int typeId) throws BinaryObjectException {
+        return metas.get(typeId);
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/1dbf20e0/modules/core/src/test/java/org/apache/ignite/internal/binary/mutabletest/GridBinaryMarshalerAwareTestClass.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/binary/mutabletest/GridBinaryMarshalerAwareTestClass.java b/modules/core/src/test/java/org/apache/ignite/internal/binary/mutabletest/GridBinaryMarshalerAwareTestClass.java
new file mode 100644
index 0000000..f48bd1a
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/binary/mutabletest/GridBinaryMarshalerAwareTestClass.java
@@ -0,0 +1,67 @@
+/*
+ * 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.binary.mutabletest;
+
+import org.apache.ignite.internal.util.typedef.internal.S;
+import org.apache.ignite.binary.BinaryObjectException;
+import org.apache.ignite.binary.Binarylizable;
+import org.apache.ignite.binary.BinaryRawReader;
+import org.apache.ignite.binary.BinaryRawWriter;
+import org.apache.ignite.binary.BinaryReader;
+import org.apache.ignite.binary.BinaryWriter;
+import org.apache.ignite.testframework.GridTestUtils;
+
+/**
+ *
+ */
+public class GridBinaryMarshalerAwareTestClass implements Binarylizable {
+    /** */
+    public String s;
+
+    /** */
+    public String sRaw;
+
+    /** {@inheritDoc} */
+    @Override public void writeBinary(BinaryWriter writer) throws BinaryObjectException {
+        writer.writeString("s", s);
+
+        BinaryRawWriter raw = writer.rawWriter();
+
+        raw.writeString(sRaw);
+    }
+
+    /** {@inheritDoc} */
+    @Override public void readBinary(BinaryReader reader) throws BinaryObjectException {
+        s = reader.readString("s");
+
+        BinaryRawReader raw = reader.rawReader();
+
+        sRaw = raw.readString();
+    }
+
+    /** {@inheritDoc} */
+    @SuppressWarnings("FloatingPointEquality")
+    @Override public boolean equals(Object other) {
+        return this == other || GridTestUtils.deepEquals(this, other);
+    }
+
+    /** {@inheritDoc} */
+    @Override public String toString() {
+        return S.toString(GridBinaryMarshalerAwareTestClass.class, this);
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/1dbf20e0/modules/core/src/test/java/org/apache/ignite/internal/binary/mutabletest/GridPortableTestClasses.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/binary/mutabletest/GridPortableTestClasses.java b/modules/core/src/test/java/org/apache/ignite/internal/binary/mutabletest/GridPortableTestClasses.java
new file mode 100644
index 0000000..3a4a4b6
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/binary/mutabletest/GridPortableTestClasses.java
@@ -0,0 +1,484 @@
+/*
+ * 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.binary.mutabletest;
+
+import com.google.common.base.Throwables;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.ObjectOutput;
+import java.io.ObjectOutputStream;
+import java.io.Serializable;
+import java.math.BigDecimal;
+import java.sql.Timestamp;
+import java.util.ArrayList;
+import java.util.Date;
+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;
+
+/**
+ *
+ */
+@SuppressWarnings({"PublicInnerClass", "PublicField"})
+public class GridPortableTestClasses {
+    /**
+     *
+     */
+    public static class TestObjectContainer {
+        /** */
+        public Object foo;
+
+        /**
+         *
+         */
+        public TestObjectContainer() {
+            // No-op.
+        }
+
+        /**
+         * @param foo Object.
+         */
+        public TestObjectContainer(Object foo) {
+            this.foo = foo;
+        }
+    }
+
+    /**
+     *
+     */
+    public static class TestObjectOuter {
+        /** */
+        public TestObjectInner inner;
+
+        /** */
+        public String foo;
+
+        /**
+         *
+         */
+        public TestObjectOuter() {
+
+        }
+
+        /**
+         * @param inner Inner object.
+         */
+        public TestObjectOuter(TestObjectInner inner) {
+            this.inner = inner;
+        }
+    }
+
+    /** */
+    public static class TestObjectInner {
+        /** */
+        public Object foo;
+
+        /** */
+        public TestObjectOuter outer;
+    }
+
+    /** */
+    public static class TestObjectArrayList {
+        /** */
+        public List<String> list = new ArrayList<>();
+    }
+
+    /**
+     *
+     */
+    public static class TestObjectPlainPortable {
+        /** */
+        public BinaryObject plainPortable;
+
+        /**
+         *
+         */
+        public TestObjectPlainPortable() {
+            // No-op.
+        }
+
+        /**
+         * @param plainPortable Object.
+         */
+        public TestObjectPlainPortable(BinaryObject plainPortable) {
+            this.plainPortable = plainPortable;
+        }
+    }
+
+    /**
+     *
+     */
+    public static class TestObjectAllTypes implements Serializable {
+        /** */
+        public Byte b_;
+
+        /** */
+        public Short s_;
+
+        /** */
+        public Integer i_;
+
+        /** */
+        public Long l_;
+
+        /** */
+        public Float f_;
+
+        /** */
+        public Double d_;
+
+        /** */
+        public Character c_;
+
+        /** */
+        public Boolean z_;
+
+        /** */
+        public byte b;
+
+        /** */
+        public short s;
+
+        /** */
+        public int i;
+
+        /** */
+        public long l;
+
+        /** */
+        public float f;
+
+        /** */
+        public double d;
+
+        /** */
+        public char c;
+
+        /** */
+        public boolean z;
+
+        /** */
+        public String str;
+
+        /** */
+        public UUID uuid;
+
+        /** */
+        public Date date;
+
+        /** */
+        public Timestamp ts;
+
+        /** */
+        public byte[] bArr;
+
+        /** */
+        public short[] sArr;
+
+        /** */
+        public int[] iArr;
+
+        /** */
+        public long[] lArr;
+
+        /** */
+        public float[] fArr;
+
+        /** */
+        public double[] dArr;
+
+        /** */
+        public char[] cArr;
+
+        /** */
+        public boolean[] zArr;
+
+        /** */
+        public BigDecimal[] bdArr;
+
+        /** */
+        public String[] strArr;
+
+        /** */
+        public UUID[] uuidArr;
+
+        /** */
+        public Date[] dateArr;
+
+        /** */
+        public Timestamp[] tsArr;
+
+        /** */
+        public TestObjectEnum anEnum;
+
+        /** */
+        public TestObjectEnum[] enumArr;
+
+        /** */
+        public Map.Entry entry;
+
+        /**
+         * @return Array.
+         */
+        private byte[] serialize() {
+            ByteArrayOutputStream byteOut = new ByteArrayOutputStream();
+
+            try {
+                ObjectOutput out = new ObjectOutputStream(byteOut);
+
+                out.writeObject(this);
+
+                out.close();
+            }
+            catch (IOException e) {
+                Throwables.propagate(e);
+            }
+
+            return byteOut.toByteArray();
+        }
+
+        /**
+         *
+         */
+        public void setDefaultData() {
+            b_ = 11;
+            s_ = 22;
+            i_ = 33;
+            l_ = 44L;
+            f_ = 55f;
+            d_ = 66d;
+            c_ = 'e';
+            z_ = true;
+
+            b = 1;
+            s = 2;
+            i = 3;
+            l = 4;
+            f = 5;
+            d = 6;
+            c = 7;
+            z = true;
+
+            str = "abc";
+            uuid = new UUID(1, 1);
+            date = new Date(1000000);
+            ts = new Timestamp(100020003);
+
+            bArr = new byte[] {1, 2, 3};
+            sArr = new short[] {1, 2, 3};
+            iArr = new int[] {1, 2, 3};
+            lArr = new long[] {1, 2, 3};
+            fArr = new float[] {1, 2, 3};
+            dArr = new double[] {1, 2, 3};
+            cArr = new char[] {1, 2, 3};
+            zArr = new boolean[] {true, false};
+
+            strArr = new String[] {"abc", "ab", "a"};
+            uuidArr = new UUID[] {new UUID(1, 1), new UUID(2, 2)};
+            bdArr = new BigDecimal[] {new BigDecimal(1000), BigDecimal.TEN};
+            dateArr = new Date[] {new Date(1000000), new Date(200000)};
+            tsArr = new Timestamp[] {new Timestamp(100020003), new Timestamp(200030004)};
+
+            anEnum = TestObjectEnum.A;
+
+            enumArr = new TestObjectEnum[] {TestObjectEnum.B};
+
+            entry = new GridMapEntry<>(1, "a");
+        }
+    }
+
+    /**
+     *
+     */
+    public enum TestObjectEnum {
+        A, B, C
+    }
+
+    /**
+     *
+     */
+    public static class Address implements Serializable {
+        /** SUID. */
+        private static final long serialVersionUID = 0L;
+
+        /** City. */
+        public String city;
+
+        /** Street. */
+        public String street;
+
+        /** Street number. */
+        public int streetNumber;
+
+        /** Flat number. */
+        public int flatNumber;
+
+        /**
+         * Default constructor.
+         */
+        public Address() {
+            // No-op.
+        }
+
+        /**
+         * Constructor.
+         *
+         * @param city City.
+         * @param street Street.
+         * @param streetNumber Street number.
+         * @param flatNumber Flat number.
+         */
+        public Address(String city, String street, int streetNumber, int flatNumber) {
+            this.city = city;
+            this.street = street;
+            this.streetNumber = streetNumber;
+            this.flatNumber = flatNumber;
+        }
+    }
+
+    /**
+     *
+     */
+    public static class Company implements Serializable {
+        /** SUID. */
+        private static final long serialVersionUID = 0L;
+
+        /** ID. */
+        public int id;
+
+        /** Name. */
+        public String name;
+
+        /** Size. */
+        public int size;
+
+        /** Address. */
+        public Address address;
+
+        /** Occupation. */
+        public String occupation;
+
+        /**
+         * Default constructor.
+         */
+        public Company() {
+            // No-op.
+        }
+
+        /**
+         * Constructor.
+         *
+         * @param id ID.
+         * @param name Name.
+         * @param size Size.
+         * @param address Address.
+         * @param occupation Occupation.
+         */
+        public Company(int id, String name, int size, Address address, String occupation) {
+            this.id = id;
+            this.name = name;
+            this.size = size;
+            this.address = address;
+            this.occupation = occupation;
+        }
+    }
+
+    /**
+     * Companies.
+     */
+    public static class Companies {
+        /** Companies. */
+        private List<Company> companies = new ArrayList<>();
+
+        /**
+         * @param idx Index.
+         * @return Company.
+         */
+        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) {
+            Companies list = companyByStreet.get(company.address.street);
+
+            if (list == null) {
+                list = new Companies();
+
+                companyByStreet.put(company.address.street, list);
+            }
+
+            list.add(company);
+        }
+
+        /**
+         * @return map
+         */
+        public Map<String, Companies> getCompanyByStreet() {
+            return 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<>();
+                }
+            });
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/1dbf20e0/modules/core/src/test/java/org/apache/ignite/internal/binary/mutabletest/package-info.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/binary/mutabletest/package-info.java b/modules/core/src/test/java/org/apache/ignite/internal/binary/mutabletest/package-info.java
new file mode 100644
index 0000000..fecf816
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/binary/mutabletest/package-info.java
@@ -0,0 +1,22 @@
+/*
+ * 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 description. -->
+ * Contains internal tests or test related classes and interfaces.
+ */
+package org.apache.ignite.internal.binary.mutabletest;

http://git-wip-us.apache.org/repos/asf/ignite/blob/1dbf20e0/modules/core/src/test/java/org/apache/ignite/internal/binary/noncompact/BinaryFieldsHeapNonCompactSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/binary/noncompact/BinaryFieldsHeapNonCompactSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/binary/noncompact/BinaryFieldsHeapNonCompactSelfTest.java
new file mode 100644
index 0000000..7687f38
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/binary/noncompact/BinaryFieldsHeapNonCompactSelfTest.java
@@ -0,0 +1,30 @@
+/*
+ * 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.binary.noncompact;
+
+import org.apache.ignite.internal.binary.BinaryFieldsHeapSelfTest;
+
+/**
+ * Field tests for heap-based portables with non-compact footer.
+ */
+public class BinaryFieldsHeapNonCompactSelfTest extends BinaryFieldsHeapSelfTest {
+    /** {@inheritDoc} */
+    @Override protected boolean compactFooter() {
+        return false;
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/1dbf20e0/modules/core/src/test/java/org/apache/ignite/internal/binary/noncompact/BinaryFieldsOffheapNonCompactSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/binary/noncompact/BinaryFieldsOffheapNonCompactSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/binary/noncompact/BinaryFieldsOffheapNonCompactSelfTest.java
new file mode 100644
index 0000000..52bccd8
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/binary/noncompact/BinaryFieldsOffheapNonCompactSelfTest.java
@@ -0,0 +1,30 @@
+/*
+ * 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.binary.noncompact;
+
+import org.apache.ignite.internal.binary.BinaryFieldsOffheapSelfTest;
+
+/**
+ * Field tests for offheap-based portables with non-compact footer.
+ */
+public class BinaryFieldsOffheapNonCompactSelfTest extends BinaryFieldsOffheapSelfTest {
+    /** {@inheritDoc} */
+    @Override protected boolean compactFooter() {
+        return false;
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/1dbf20e0/modules/core/src/test/java/org/apache/ignite/internal/binary/noncompact/BinaryFooterOffsetsHeapNonCompactSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/binary/noncompact/BinaryFooterOffsetsHeapNonCompactSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/binary/noncompact/BinaryFooterOffsetsHeapNonCompactSelfTest.java
new file mode 100644
index 0000000..279e4f0
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/binary/noncompact/BinaryFooterOffsetsHeapNonCompactSelfTest.java
@@ -0,0 +1,30 @@
+/*
+ * 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.binary.noncompact;
+
+import org.apache.ignite.internal.binary.BinaryFooterOffsetsHeapSelfTest;
+
+/**
+ * Compact offsets tests for heap portable objects with non-compact footer.
+ */
+public class BinaryFooterOffsetsHeapNonCompactSelfTest extends BinaryFooterOffsetsHeapSelfTest {
+    /** {@inheritDoc} */
+    @Override protected boolean compactFooter() {
+        return false;
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/1dbf20e0/modules/core/src/test/java/org/apache/ignite/internal/binary/noncompact/BinaryFooterOffsetsOffheapNonCompactSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/binary/noncompact/BinaryFooterOffsetsOffheapNonCompactSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/binary/noncompact/BinaryFooterOffsetsOffheapNonCompactSelfTest.java
new file mode 100644
index 0000000..66a8d1a
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/binary/noncompact/BinaryFooterOffsetsOffheapNonCompactSelfTest.java
@@ -0,0 +1,30 @@
+/*
+ * 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.binary.noncompact;
+
+import org.apache.ignite.internal.binary.BinaryFooterOffsetsOffheapSelfTest;
+
+/**
+ * Compact offsets tests for offheap portable objects with non-compact footer.
+ */
+public class BinaryFooterOffsetsOffheapNonCompactSelfTest extends BinaryFooterOffsetsOffheapSelfTest {
+    /** {@inheritDoc} */
+    @Override protected boolean compactFooter() {
+        return false;
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/1dbf20e0/modules/core/src/test/java/org/apache/ignite/internal/binary/noncompact/BinaryMarshallerNonCompactSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/binary/noncompact/BinaryMarshallerNonCompactSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/binary/noncompact/BinaryMarshallerNonCompactSelfTest.java
new file mode 100644
index 0000000..5cc228d
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/binary/noncompact/BinaryMarshallerNonCompactSelfTest.java
@@ -0,0 +1,30 @@
+/*
+ * 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.binary.noncompact;
+
+import org.apache.ignite.internal.binary.BinaryMarshallerSelfTest;
+
+/**
+ * Basic marshaller test with non-compact footer.
+ */
+public class BinaryMarshallerNonCompactSelfTest extends BinaryMarshallerSelfTest {
+    /** {@inheritDoc} */
+    @Override protected boolean compactFooter() {
+        return false;
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/1dbf20e0/modules/core/src/test/java/org/apache/ignite/internal/binary/noncompact/BinaryObjectBuilderAdditionalNonCompactSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/binary/noncompact/BinaryObjectBuilderAdditionalNonCompactSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/binary/noncompact/BinaryObjectBuilderAdditionalNonCompactSelfTest.java
new file mode 100644
index 0000000..fcf68c5
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/binary/noncompact/BinaryObjectBuilderAdditionalNonCompactSelfTest.java
@@ -0,0 +1,30 @@
+/*
+ * 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.binary.noncompact;
+
+import org.apache.ignite.internal.binary.BinaryObjectBuilderAdditionalSelfTest;
+
+/**
+ *
+ */
+public class BinaryObjectBuilderAdditionalNonCompactSelfTest extends BinaryObjectBuilderAdditionalSelfTest {
+    /** {@inheritDoc} */
+    @Override protected boolean compactFooter() {
+        return false;
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/1dbf20e0/modules/core/src/test/java/org/apache/ignite/internal/binary/noncompact/BinaryObjectBuilderNonCompactSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/binary/noncompact/BinaryObjectBuilderNonCompactSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/binary/noncompact/BinaryObjectBuilderNonCompactSelfTest.java
new file mode 100644
index 0000000..1305b6e
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/binary/noncompact/BinaryObjectBuilderNonCompactSelfTest.java
@@ -0,0 +1,30 @@
+/*
+ * 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.binary.noncompact;
+
+import org.apache.ignite.internal.binary.BinaryObjectBuilderSelfTest;
+
+/**
+ * Portable builder test for objects with non-compact footer.
+ */
+public class BinaryObjectBuilderNonCompactSelfTest extends BinaryObjectBuilderSelfTest {
+    /** {@inheritDoc} */
+    @Override protected boolean compactFooter() {
+        return false;
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/1dbf20e0/modules/core/src/test/java/org/apache/ignite/internal/binary/package-info.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/binary/package-info.java b/modules/core/src/test/java/org/apache/ignite/internal/binary/package-info.java
new file mode 100644
index 0000000..56abcfd
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/binary/package-info.java
@@ -0,0 +1,22 @@
+/*
+ * 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 description. -->
+ * Contains internal tests or test related classes and interfaces.
+ */
+package org.apache.ignite.internal.binary;

http://git-wip-us.apache.org/repos/asf/ignite/blob/1dbf20e0/modules/core/src/test/java/org/apache/ignite/internal/binary/test/GridPortableTestClass1.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/binary/test/GridPortableTestClass1.java b/modules/core/src/test/java/org/apache/ignite/internal/binary/test/GridPortableTestClass1.java
new file mode 100644
index 0000000..887134a
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/binary/test/GridPortableTestClass1.java
@@ -0,0 +1,28 @@
+/*
+ * 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.binary.test;
+
+/**
+ */
+public class GridPortableTestClass1 {
+    /**
+     */
+    private static class InnerClass {
+        // No-op.
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/1dbf20e0/modules/core/src/test/java/org/apache/ignite/internal/binary/test/GridPortableTestClass2.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/binary/test/GridPortableTestClass2.java b/modules/core/src/test/java/org/apache/ignite/internal/binary/test/GridPortableTestClass2.java
new file mode 100644
index 0000000..3c1c506
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/binary/test/GridPortableTestClass2.java
@@ -0,0 +1,24 @@
+/*
+ * 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.binary.test;
+
+/**
+ */
+public class GridPortableTestClass2 {
+    // No-op.
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/1dbf20e0/modules/core/src/test/java/org/apache/ignite/internal/binary/test/package-info.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/binary/test/package-info.java b/modules/core/src/test/java/org/apache/ignite/internal/binary/test/package-info.java
new file mode 100644
index 0000000..78009a6
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/binary/test/package-info.java
@@ -0,0 +1,22 @@
+/*
+ * 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 description. -->
+ * Contains internal tests or test related classes and interfaces.
+ */
+package org.apache.ignite.internal.binary.test;

http://git-wip-us.apache.org/repos/asf/ignite/blob/1dbf20e0/modules/core/src/test/java/org/apache/ignite/internal/binary/test/subpackage/GridPortableTestClass3.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/binary/test/subpackage/GridPortableTestClass3.java b/modules/core/src/test/java/org/apache/ignite/internal/binary/test/subpackage/GridPortableTestClass3.java
new file mode 100644
index 0000000..a04b586
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/binary/test/subpackage/GridPortableTestClass3.java
@@ -0,0 +1,24 @@
+/*
+ * 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.binary.test.subpackage;
+
+/**
+ */
+public class GridPortableTestClass3 {
+    // No-op.
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/1dbf20e0/modules/core/src/test/java/org/apache/ignite/internal/binary/test/subpackage/package-info.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/binary/test/subpackage/package-info.java b/modules/core/src/test/java/org/apache/ignite/internal/binary/test/subpackage/package-info.java
new file mode 100644
index 0000000..f0e0b4c
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/binary/test/subpackage/package-info.java
@@ -0,0 +1,22 @@
+/*
+ * 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 description. -->
+ * Contains internal tests or test related classes and interfaces.
+ */
+package org.apache.ignite.internal.binary.test.subpackage;


[49/59] [abbrv] ignite git commit: ignite-2065: rename "portable" classes to "binary"

Posted by ak...@apache.org.
http://git-wip-us.apache.org/repos/asf/ignite/blob/71ad9cea/modules/core/src/main/java/org/apache/ignite/internal/binary/builder/BinaryBuilderReader.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/binary/builder/BinaryBuilderReader.java b/modules/core/src/main/java/org/apache/ignite/internal/binary/builder/BinaryBuilderReader.java
new file mode 100644
index 0000000..9b9e8b8
--- /dev/null
+++ b/modules/core/src/main/java/org/apache/ignite/internal/binary/builder/BinaryBuilderReader.java
@@ -0,0 +1,846 @@
+/*
+ * 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.binary.builder;
+
+import org.apache.ignite.binary.BinaryObjectException;
+import org.apache.ignite.internal.binary.BinaryObjectImpl;
+import org.apache.ignite.internal.binary.BinaryReaderExImpl;
+import org.apache.ignite.internal.binary.BinaryWriterExImpl;
+import org.apache.ignite.internal.binary.GridBinaryMarshaller;
+import org.apache.ignite.internal.binary.BinaryContext;
+import org.apache.ignite.internal.binary.BinaryPositionReadable;
+import org.apache.ignite.internal.binary.BinaryPrimitives;
+import org.apache.ignite.internal.binary.BinarySchema;
+import org.apache.ignite.internal.binary.streams.BinaryHeapInputStream;
+import org.apache.ignite.internal.binary.BinaryUtils;
+
+import java.sql.Timestamp;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.Map;
+
+import static java.nio.charset.StandardCharsets.UTF_8;
+
+/**
+ *
+ */
+public class BinaryBuilderReader implements BinaryPositionReadable {
+    /** */
+    private final BinaryContext ctx;
+
+    /** */
+    private final byte[] arr;
+
+    /** */
+    private final BinaryReaderExImpl reader;
+
+    /** */
+    private final Map<Integer, BinaryObjectBuilderImpl> objMap;
+
+    /** */
+    private int pos;
+
+    /*
+     * Constructor.
+     *
+     * @param objImpl Portable object
+     */
+    BinaryBuilderReader(BinaryObjectImpl objImpl) {
+        ctx = objImpl.context();
+        arr = objImpl.array();
+        pos = objImpl.start();
+
+        reader = new BinaryReaderExImpl(ctx,
+            BinaryHeapInputStream.create(arr, pos),
+            ctx.configuration().getClassLoader());
+
+        objMap = new HashMap<>();
+    }
+
+    /**
+     * Copying constructor.
+     *
+     * @param other Other reader.
+     * @param start Start position.
+     */
+    BinaryBuilderReader(BinaryBuilderReader other, int start) {
+        this.ctx = other.ctx;
+        this.arr = other.arr;
+        this.pos = start;
+
+        reader = new BinaryReaderExImpl(ctx, BinaryHeapInputStream.create(arr, start), null, other.reader.handles());
+
+        this.objMap = other.objMap;
+    }
+
+    /**
+     * @return Portable context.
+     */
+    public BinaryContext portableContext() {
+        return ctx;
+    }
+
+    /**
+     * @param obj Mutable portable object.
+     */
+    public void registerObject(BinaryObjectBuilderImpl obj) {
+        objMap.put(obj.start(), obj);
+    }
+
+    /**
+     * Get schema of the object, starting at the given position.
+     *
+     * @return Object's schema.
+     */
+    public BinarySchema schema() {
+        return reader.getOrCreateSchema();
+    }
+
+    /**
+     * @return Read int value.
+     */
+    public int readInt() {
+        int res = readInt(0);
+
+        pos += 4;
+
+        return res;
+    }
+
+    /**
+     * @return Read int value.
+     */
+    public byte readByte() {
+        return arr[pos++];
+    }
+
+    /**
+     * @return Read boolean value.
+     */
+    public boolean readBoolean() {
+        return readByte() == 1;
+    }
+
+    /**
+     * @return Read int value.
+     */
+    public byte readByte(int off) {
+        return arr[pos + off];
+    }
+
+    /**
+     * @param off Offset related to {@link #pos}
+     * @return Read int value.
+     */
+    public int readInt(int off) {
+        return BinaryPrimitives.readInt(arr, pos + off);
+    }
+
+    /**
+     * @param pos Position in the source array.
+     * @return Read byte value.
+     */
+    public byte readBytePositioned(int pos) {
+        return BinaryPrimitives.readByte(arr, pos);
+    }
+
+    /** {@inheritDoc} */
+    @Override public short readShortPositioned(int pos) {
+        return BinaryPrimitives.readShort(arr, pos);
+    }
+
+    /** {@inheritDoc} */
+    @Override public int readIntPositioned(int pos) {
+        return BinaryPrimitives.readInt(arr, pos);
+    }
+
+    /**
+     * @return Read length of array.
+     */
+    public int readLength() {
+        return BinaryPrimitives.readInt(arr, pos);
+    }
+
+    /**
+     * Read string length.
+     *
+     * @return String length.
+     */
+    public int readStringLength() {
+        return BinaryPrimitives.readInt(arr, pos);
+    }
+
+    /**
+     * Reads string.
+     *
+     * @return String.
+     */
+    public String readString() {
+        byte flag = readByte();
+
+        if (flag == GridBinaryMarshaller.NULL)
+            return null;
+
+        if (flag != GridBinaryMarshaller.STRING)
+            throw new BinaryObjectException("Failed to deserialize String.");
+
+        int len = readInt();
+
+        String str = new String(arr, pos, len, UTF_8);
+
+        pos += len;
+
+        return str;
+    }
+
+    /**
+     *
+     */
+    public void skipValue() {
+        byte type = arr[pos++];
+
+        int len;
+
+        switch (type) {
+            case GridBinaryMarshaller.NULL:
+                return;
+
+            case GridBinaryMarshaller.OBJ:
+                pos += readInt(GridBinaryMarshaller.TOTAL_LEN_POS - 1) - 1;
+
+                return;
+
+            case GridBinaryMarshaller.BOOLEAN:
+            case GridBinaryMarshaller.BYTE:
+                len = 1;
+                break;
+
+            case GridBinaryMarshaller.CHAR:
+            case GridBinaryMarshaller.SHORT:
+                len = 2;
+
+                break;
+
+            case GridBinaryMarshaller.HANDLE:
+            case GridBinaryMarshaller.FLOAT:
+            case GridBinaryMarshaller.INT:
+                len = 4;
+
+                break;
+
+            case GridBinaryMarshaller.ENUM:
+                //skipping type id and ordinal value
+                len = 8;
+
+                break;
+
+            case GridBinaryMarshaller.LONG:
+            case GridBinaryMarshaller.DOUBLE:
+                len = 8;
+
+                break;
+
+            case GridBinaryMarshaller.BYTE_ARR:
+            case GridBinaryMarshaller.BOOLEAN_ARR:
+                len = 4 + readLength();
+
+                break;
+
+            case GridBinaryMarshaller.STRING:
+                len = 4 + readStringLength();
+
+                break;
+
+            case GridBinaryMarshaller.DECIMAL:
+                len = /** scale */ 4  + /** mag len */ 4  + /** mag bytes count */ readInt(4);
+
+                break;
+
+            case GridBinaryMarshaller.UUID:
+                len = 8 + 8;
+
+                break;
+
+            case GridBinaryMarshaller.DATE:
+                len = 8;
+
+                break;
+
+            case GridBinaryMarshaller.TIMESTAMP:
+                len = 8 + 4;
+
+                break;
+
+            case GridBinaryMarshaller.CHAR_ARR:
+            case GridBinaryMarshaller.SHORT_ARR:
+                len = 4 + readLength() * 2;
+
+                break;
+
+            case GridBinaryMarshaller.INT_ARR:
+            case GridBinaryMarshaller.FLOAT_ARR:
+                len = 4 + readLength() * 4;
+
+                break;
+
+            case GridBinaryMarshaller.LONG_ARR:
+            case GridBinaryMarshaller.DOUBLE_ARR:
+                len = 4 + readLength() * 8;
+
+                break;
+
+            case GridBinaryMarshaller.DECIMAL_ARR:
+            case GridBinaryMarshaller.DATE_ARR:
+            case GridBinaryMarshaller.TIMESTAMP_ARR:
+            case GridBinaryMarshaller.OBJ_ARR:
+            case GridBinaryMarshaller.ENUM_ARR:
+            case GridBinaryMarshaller.UUID_ARR:
+            case GridBinaryMarshaller.STRING_ARR: {
+                int size = readInt();
+
+                for (int i = 0; i < size; i++)
+                    skipValue();
+
+                return;
+            }
+
+            case GridBinaryMarshaller.COL: {
+                int size = readInt();
+
+                pos++; // skip collection type
+
+                for (int i = 0; i < size; i++)
+                    skipValue();
+
+                return;
+            }
+
+            case GridBinaryMarshaller.MAP: {
+                int size = readInt();
+
+                pos++; // skip collection type
+
+                for (int i = 0; i < size; i++) {
+                    skipValue(); // skip key.
+                    skipValue(); // skip value.
+                }
+
+                return;
+            }
+
+            case GridBinaryMarshaller.PORTABLE_OBJ:
+                len = readInt() + 4;
+
+                break;
+
+            default:
+                throw new BinaryObjectException("Invalid flag value: " + type);
+        }
+
+        pos += len;
+    }
+
+    /**
+     * @param pos Position.
+     * @param len Length.
+     * @return Object.
+     */
+    public Object getValueQuickly(int pos, int len) {
+        byte type = arr[pos];
+
+        switch (type) {
+            case GridBinaryMarshaller.NULL:
+                return null;
+
+            case GridBinaryMarshaller.HANDLE: {
+                int objStart = pos - readIntPositioned(pos + 1);
+
+                BinaryObjectBuilderImpl res = objMap.get(objStart);
+
+                if (res == null) {
+                    res = new BinaryObjectBuilderImpl(new BinaryBuilderReader(this, objStart), objStart);
+
+                    objMap.put(objStart, res);
+                }
+
+                return res;
+            }
+
+            case GridBinaryMarshaller.OBJ: {
+                BinaryObjectBuilderImpl res = objMap.get(pos);
+
+                if (res == null) {
+                    res = new BinaryObjectBuilderImpl(new BinaryBuilderReader(this, pos), pos);
+
+                    objMap.put(pos, res);
+                }
+
+                return res;
+            }
+
+            case GridBinaryMarshaller.BYTE:
+                return arr[pos + 1];
+
+            case GridBinaryMarshaller.SHORT:
+                return BinaryPrimitives.readShort(arr, pos + 1);
+
+            case GridBinaryMarshaller.INT:
+                return BinaryPrimitives.readInt(arr, pos + 1);
+
+            case GridBinaryMarshaller.LONG:
+                return BinaryPrimitives.readLong(arr, pos + 1);
+
+            case GridBinaryMarshaller.FLOAT:
+                return BinaryPrimitives.readFloat(arr, pos + 1);
+
+            case GridBinaryMarshaller.DOUBLE:
+                return BinaryPrimitives.readDouble(arr, pos + 1);
+
+            case GridBinaryMarshaller.CHAR:
+                return BinaryPrimitives.readChar(arr, pos + 1);
+
+            case GridBinaryMarshaller.BOOLEAN:
+                return arr[pos + 1] != 0;
+
+            case GridBinaryMarshaller.DECIMAL:
+            case GridBinaryMarshaller.STRING:
+            case GridBinaryMarshaller.UUID:
+            case GridBinaryMarshaller.DATE:
+            case GridBinaryMarshaller.TIMESTAMP:
+                return new BinaryPlainLazyValue(this, pos, len);
+
+            case GridBinaryMarshaller.BYTE_ARR:
+            case GridBinaryMarshaller.SHORT_ARR:
+            case GridBinaryMarshaller.INT_ARR:
+            case GridBinaryMarshaller.LONG_ARR:
+            case GridBinaryMarshaller.FLOAT_ARR:
+            case GridBinaryMarshaller.DOUBLE_ARR:
+            case GridBinaryMarshaller.CHAR_ARR:
+            case GridBinaryMarshaller.BOOLEAN_ARR:
+            case GridBinaryMarshaller.DECIMAL_ARR:
+            case GridBinaryMarshaller.DATE_ARR:
+            case GridBinaryMarshaller.TIMESTAMP_ARR:
+            case GridBinaryMarshaller.UUID_ARR:
+            case GridBinaryMarshaller.STRING_ARR:
+            case GridBinaryMarshaller.ENUM_ARR:
+            case GridBinaryMarshaller.OBJ_ARR:
+            case GridBinaryMarshaller.COL:
+            case GridBinaryMarshaller.MAP:
+                return new LazyCollection(pos);
+
+            case GridBinaryMarshaller.ENUM: {
+                if (len == 1) {
+                    assert readByte(pos) == GridBinaryMarshaller.NULL;
+
+                    return null;
+                }
+
+                int mark = position();
+                position(pos + 1);
+
+                BinaryBuilderEnum builderEnum = new BinaryBuilderEnum(this);
+
+                position(mark);
+
+                return builderEnum;
+            }
+
+            case GridBinaryMarshaller.PORTABLE_OBJ: {
+                int size = readIntPositioned(pos + 1);
+
+                int start = readIntPositioned(pos + 4 + size);
+
+                BinaryObjectImpl portableObj = new BinaryObjectImpl(ctx, arr, pos + 4 + start);
+
+                return new BinaryPlainBinaryObject(portableObj);
+            }
+
+            default:
+                throw new BinaryObjectException("Invalid flag value: " + type);
+        }
+    }
+
+    /**
+     * @return Parsed value.
+     */
+    public Object parseValue() {
+        int valPos = pos;
+
+        byte type = arr[pos++];
+
+        int plainLazyValLen;
+
+        boolean modifiableLazyVal = false;
+
+        switch (type) {
+            case GridBinaryMarshaller.NULL:
+                return null;
+
+            case GridBinaryMarshaller.HANDLE: {
+                int objStart = pos - 1 - readInt();
+
+                BinaryObjectBuilderImpl res = objMap.get(objStart);
+
+                if (res == null) {
+                    res = new BinaryObjectBuilderImpl(new BinaryBuilderReader(this, objStart), objStart);
+
+                    objMap.put(objStart, res);
+                }
+
+                return res;
+            }
+
+            case GridBinaryMarshaller.OBJ: {
+                pos--;
+
+                BinaryObjectBuilderImpl res = objMap.get(pos);
+
+                if (res == null) {
+                    res = new BinaryObjectBuilderImpl(new BinaryBuilderReader(this, pos), pos);
+
+                    objMap.put(pos, res);
+                }
+
+                pos += readInt(GridBinaryMarshaller.TOTAL_LEN_POS);
+
+                return res;
+            }
+
+            case GridBinaryMarshaller.BYTE:
+                return arr[pos++];
+
+            case GridBinaryMarshaller.SHORT: {
+                Object res = BinaryPrimitives.readShort(arr, pos);
+                pos += 2;
+                return res;
+            }
+
+            case GridBinaryMarshaller.INT:
+                return readInt();
+
+            case GridBinaryMarshaller.LONG:
+                plainLazyValLen = 8;
+
+                break;
+
+            case GridBinaryMarshaller.FLOAT:
+                plainLazyValLen = 4;
+
+                break;
+
+            case GridBinaryMarshaller.DOUBLE:
+                plainLazyValLen = 8;
+
+                break;
+
+            case GridBinaryMarshaller.CHAR:
+                plainLazyValLen = 2;
+
+                break;
+
+            case GridBinaryMarshaller.BOOLEAN:
+                return arr[pos++] != 0;
+
+            case GridBinaryMarshaller.DECIMAL:
+                plainLazyValLen = /** scale */ 4  + /** mag len */ 4  + /** mag bytes count */ readInt(4);
+
+                break;
+
+            case GridBinaryMarshaller.STRING:
+                plainLazyValLen = 4 + readStringLength();
+
+                break;
+
+            case GridBinaryMarshaller.UUID:
+                plainLazyValLen = 8 + 8;
+
+                break;
+
+            case GridBinaryMarshaller.DATE:
+                plainLazyValLen = 8;
+
+                break;
+
+            case GridBinaryMarshaller.TIMESTAMP:
+                plainLazyValLen = 8 + 4;
+
+                break;
+
+            case GridBinaryMarshaller.BYTE_ARR:
+                plainLazyValLen = 4 + readLength();
+                modifiableLazyVal = true;
+
+                break;
+
+            case GridBinaryMarshaller.SHORT_ARR:
+                plainLazyValLen = 4 + readLength() * 2;
+                modifiableLazyVal = true;
+
+                break;
+
+            case GridBinaryMarshaller.INT_ARR:
+                plainLazyValLen = 4 + readLength() * 4;
+                modifiableLazyVal = true;
+
+                break;
+
+            case GridBinaryMarshaller.LONG_ARR:
+                plainLazyValLen = 4 + readLength() * 8;
+                modifiableLazyVal = true;
+
+                break;
+
+            case GridBinaryMarshaller.FLOAT_ARR:
+                plainLazyValLen = 4 + readLength() * 4;
+                modifiableLazyVal = true;
+
+                break;
+
+            case GridBinaryMarshaller.DOUBLE_ARR:
+                plainLazyValLen = 4 + readLength() * 8;
+                modifiableLazyVal = true;
+
+                break;
+
+            case GridBinaryMarshaller.CHAR_ARR:
+                plainLazyValLen = 4 + readLength() * 2;
+                modifiableLazyVal = true;
+
+                break;
+
+            case GridBinaryMarshaller.BOOLEAN_ARR:
+                plainLazyValLen = 4 + readLength();
+                modifiableLazyVal = true;
+
+                break;
+
+            case GridBinaryMarshaller.OBJ_ARR:
+                return new BinaryObjectArrayLazyValue(this);
+
+            case GridBinaryMarshaller.DATE_ARR: {
+                int size = readInt();
+
+                Date[] res = new Date[size];
+
+                for (int i = 0; i < res.length; i++) {
+                    byte flag = arr[pos++];
+
+                    if (flag == GridBinaryMarshaller.NULL) continue;
+
+                    if (flag != GridBinaryMarshaller.DATE)
+                        throw new BinaryObjectException("Invalid flag value: " + flag);
+
+                    long time = BinaryPrimitives.readLong(arr, pos);
+
+                    pos += 8;
+
+                    res[i] = new Date(time);
+                }
+
+                return res;
+            }
+
+            case GridBinaryMarshaller.TIMESTAMP_ARR: {
+                int size = readInt();
+
+                Timestamp[] res = new Timestamp[size];
+
+                for (int i = 0; i < res.length; i++) {
+                    byte flag = arr[pos++];
+
+                    if (flag == GridBinaryMarshaller.NULL)
+                        continue;
+
+                    if (flag != GridBinaryMarshaller.TIMESTAMP)
+                        throw new BinaryObjectException("Invalid flag value: " + flag);
+
+                    long time = BinaryPrimitives.readLong(arr, pos);
+
+                    pos += 8;
+
+                    int nano = BinaryPrimitives.readInt(arr, pos);
+
+                    pos += 4;
+
+                    Timestamp ts = new Timestamp(time);
+
+                    ts.setNanos(ts.getNanos() + nano);
+
+                    res[i] = ts;
+                }
+
+                return res;
+            }
+
+            case GridBinaryMarshaller.UUID_ARR:
+            case GridBinaryMarshaller.STRING_ARR:
+            case GridBinaryMarshaller.DECIMAL_ARR: {
+                int size = readInt();
+
+                for (int i = 0; i < size; i++) {
+                    byte flag = arr[pos++];
+
+                    if (flag == GridBinaryMarshaller.UUID)
+                        pos += 8 + 8;
+                    else if (flag == GridBinaryMarshaller.STRING)
+                        pos += 4 + readStringLength();
+                    else if (flag == GridBinaryMarshaller.DECIMAL) {
+                        pos += 4; // scale value
+                        pos += 4 + readLength();
+                    }
+                    else
+                        assert flag == GridBinaryMarshaller.NULL;
+                }
+
+                return new BinaryModifiableLazyValue(this, valPos, pos - valPos);
+            }
+
+            case GridBinaryMarshaller.COL: {
+                int size = readInt();
+                byte colType = arr[pos++];
+
+                switch (colType) {
+                    case GridBinaryMarshaller.USER_COL:
+                    case GridBinaryMarshaller.ARR_LIST:
+                        return new BinaryLazyArrayList(this, size);
+
+                    case GridBinaryMarshaller.LINKED_LIST:
+                        return new BinaryLazyLinkedList(this, size);
+
+                    case GridBinaryMarshaller.HASH_SET:
+                    case GridBinaryMarshaller.LINKED_HASH_SET:
+                        return new BinaryLazySet(this, size);
+                }
+
+                throw new BinaryObjectException("Unknown collection type: " + colType);
+            }
+
+            case GridBinaryMarshaller.MAP:
+                return BinaryLazyMap.parseMap(this);
+
+            case GridBinaryMarshaller.ENUM:
+                return new BinaryBuilderEnum(this);
+
+            case GridBinaryMarshaller.ENUM_ARR:
+                return new BinaryEnumArrayLazyValue(this);
+
+            case GridBinaryMarshaller.PORTABLE_OBJ: {
+                int size = readInt();
+
+                pos += size;
+
+                int start = readInt();
+
+                BinaryObjectImpl portableObj = new BinaryObjectImpl(ctx, arr,
+                    pos - 4 - size + start);
+
+                return new BinaryPlainBinaryObject(portableObj);
+            }
+
+            default:
+                throw new BinaryObjectException("Invalid flag value: " + type);
+        }
+
+        BinaryAbstractLazyValue res;
+
+        if (modifiableLazyVal)
+            res = new BinaryModifiableLazyValue(this, valPos, 1 + plainLazyValLen);
+        else
+            res = new BinaryPlainLazyValue(this, valPos, 1 + plainLazyValLen);
+
+        pos += plainLazyValLen;
+
+        return res;
+    }
+
+    /**
+     * @return Array.
+     */
+    public byte[] array() {
+        return arr;
+    }
+
+    /**
+     * @return Position of reader.
+     */
+    public int position() {
+        return pos;
+    }
+
+    /**
+     * @param pos New pos.
+     */
+    public void position(int pos) {
+        this.pos = pos;
+    }
+
+    /**
+     * @param n Number of bytes to skip.
+     */
+    public void skip(int n) {
+        pos += n;
+    }
+
+    /**
+     * @return Reader.
+     */
+    BinaryReaderExImpl reader() {
+        return reader;
+    }
+
+    /**
+     *
+     */
+    private class LazyCollection implements BinaryLazyValue {
+        /** */
+        private final int valOff;
+
+        /** */
+        private Object col;
+
+        /**
+         * @param valOff Value.
+         */
+        protected LazyCollection(int valOff) {
+            this.valOff = valOff;
+        }
+
+        /**
+         * @return Object.
+         */
+        private Object wrappedCollection() {
+            if (col == null) {
+                position(valOff);
+
+                col = parseValue();
+            }
+
+            return col;
+        }
+
+        /** {@inheritDoc} */
+        @Override public void writeTo(BinaryWriterExImpl writer, BinaryBuilderSerializer ctx) {
+            ctx.writeValue(writer, wrappedCollection());
+        }
+
+        /** {@inheritDoc} */
+        @Override public Object value() {
+            return BinaryUtils.unwrapLazy(wrappedCollection());
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/71ad9cea/modules/core/src/main/java/org/apache/ignite/internal/binary/builder/BinaryBuilderSerializationAware.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/binary/builder/BinaryBuilderSerializationAware.java b/modules/core/src/main/java/org/apache/ignite/internal/binary/builder/BinaryBuilderSerializationAware.java
new file mode 100644
index 0000000..7710ba3
--- /dev/null
+++ b/modules/core/src/main/java/org/apache/ignite/internal/binary/builder/BinaryBuilderSerializationAware.java
@@ -0,0 +1,31 @@
+/*
+ * 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.binary.builder;
+
+import org.apache.ignite.internal.binary.BinaryWriterExImpl;
+
+/**
+ *
+ */
+interface BinaryBuilderSerializationAware {
+    /**
+     * @param writer Writer.
+     * @param ctx Context.
+     */
+    public void writeTo(BinaryWriterExImpl writer, BinaryBuilderSerializer ctx);
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/71ad9cea/modules/core/src/main/java/org/apache/ignite/internal/binary/builder/BinaryBuilderSerializer.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/binary/builder/BinaryBuilderSerializer.java b/modules/core/src/main/java/org/apache/ignite/internal/binary/builder/BinaryBuilderSerializer.java
new file mode 100644
index 0000000..458602d
--- /dev/null
+++ b/modules/core/src/main/java/org/apache/ignite/internal/binary/builder/BinaryBuilderSerializer.java
@@ -0,0 +1,217 @@
+/*
+ * 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.binary.builder;
+
+import org.apache.ignite.binary.BinaryObject;
+import org.apache.ignite.internal.binary.BinaryMetadata;
+import org.apache.ignite.internal.binary.BinaryObjectExImpl;
+import org.apache.ignite.internal.binary.BinaryWriterExImpl;
+import org.apache.ignite.internal.binary.GridBinaryMarshaller;
+import org.apache.ignite.internal.binary.BinaryContext;
+import org.apache.ignite.internal.binary.BinaryUtils;
+
+import java.util.Collection;
+import java.util.IdentityHashMap;
+import java.util.Map;
+
+/**
+ *
+ */
+class BinaryBuilderSerializer {
+    /** */
+    private final Map<BinaryObjectBuilderImpl, Integer> objToPos = new IdentityHashMap<>();
+
+    /** */
+    private Map<BinaryObject, BinaryObjectBuilderImpl> portableObjToWrapper;
+
+    /**
+     * @param obj Mutable object.
+     * @param posInResArr Object position in the array.
+     */
+    public void registerObjectWriting(BinaryObjectBuilderImpl obj, int posInResArr) {
+        objToPos.put(obj, posInResArr);
+    }
+
+    /**
+     * @param writer Writer.
+     * @param val Value.
+     */
+    public void writeValue(BinaryWriterExImpl writer, Object val) {
+        if (val == null) {
+            writer.writeByte(GridBinaryMarshaller.NULL);
+
+            return;
+        }
+
+        if (val instanceof BinaryBuilderSerializationAware) {
+            ((BinaryBuilderSerializationAware)val).writeTo(writer, this);
+
+            return;
+        }
+
+        if (val instanceof BinaryObjectExImpl) {
+            if (portableObjToWrapper == null)
+                portableObjToWrapper = new IdentityHashMap<>();
+
+            BinaryObjectBuilderImpl wrapper = portableObjToWrapper.get(val);
+
+            if (wrapper == null) {
+                wrapper = BinaryObjectBuilderImpl.wrap((BinaryObject)val);
+
+                portableObjToWrapper.put((BinaryObject)val, wrapper);
+            }
+
+            val = wrapper;
+        }
+
+        if (val instanceof BinaryObjectBuilderImpl) {
+            BinaryObjectBuilderImpl obj = (BinaryObjectBuilderImpl)val;
+
+            Integer posInResArr = objToPos.get(obj);
+
+            if (posInResArr == null) {
+                objToPos.put(obj, writer.out().position());
+
+                obj.serializeTo(writer.newWriter(obj.typeId()), this);
+            }
+            else {
+                int handle = writer.out().position() - posInResArr;
+
+                writer.writeByte(GridBinaryMarshaller.HANDLE);
+                writer.writeInt(handle);
+            }
+
+            return;
+        }
+
+        if (val.getClass().isEnum()) {
+            String typeName = BinaryContext.typeName(val.getClass().getName());
+            int typeId = writer.context().typeId(typeName);
+
+            BinaryMetadata meta = new BinaryMetadata(typeId, typeName, null, null, null, true);
+            writer.context().updateMetadata(typeId, meta);
+
+            writer.writeByte(GridBinaryMarshaller.ENUM);
+            writer.writeInt(typeId);
+            writer.writeInt(((Enum)val).ordinal());
+
+            return;
+        }
+
+        if (val instanceof Collection) {
+            Collection<?> c = (Collection<?>)val;
+
+            writer.writeByte(GridBinaryMarshaller.COL);
+            writer.writeInt(c.size());
+
+            byte colType = writer.context().collectionType(c.getClass());
+
+            writer.writeByte(colType);
+
+            for (Object obj : c)
+                writeValue(writer, obj);
+
+            return;
+        }
+
+        if (val instanceof Map) {
+            Map<?, ?> map = (Map<?, ?>)val;
+
+            writer.writeByte(GridBinaryMarshaller.MAP);
+            writer.writeInt(map.size());
+
+            writer.writeByte(writer.context().mapType(map.getClass()));
+
+            for (Map.Entry<?, ?> entry : map.entrySet()) {
+                writeValue(writer, entry.getKey());
+                writeValue(writer, entry.getValue());
+            }
+
+            return;
+        }
+
+        Byte flag = BinaryUtils.PLAIN_CLASS_TO_FLAG.get(val.getClass());
+
+        if (flag != null) {
+            BinaryUtils.writePlainObject(writer, val);
+
+            return;
+        }
+
+        if (val instanceof Object[]) {
+            int compTypeId = writer.context().typeId(((Object[])val).getClass().getComponentType().getName());
+
+            if (val instanceof BinaryBuilderEnum[]) {
+                writeArray(writer, GridBinaryMarshaller.ENUM_ARR, (Object[])val, compTypeId);
+
+                return;
+            }
+
+            if (((Object[])val).getClass().getComponentType().isEnum()) {
+                Enum[] enumArr = (Enum[])val;
+
+                writer.writeByte(GridBinaryMarshaller.ENUM_ARR);
+                writer.writeInt(compTypeId);
+                writer.writeInt(enumArr.length);
+
+                for (Enum anEnum : enumArr)
+                    writeValue(writer, anEnum);
+
+                return;
+            }
+
+            writeArray(writer, GridBinaryMarshaller.OBJ_ARR, (Object[])val, compTypeId);
+
+            return;
+        }
+
+        writer.doWriteObject(val);
+    }
+
+    /**
+     * @param writer Writer.
+     * @param elementType Element type.
+     * @param arr The array.
+     * @param compTypeId Component type ID.
+     */
+    public void writeArray(BinaryWriterExImpl writer, byte elementType, Object[] arr, int compTypeId) {
+        writer.writeByte(elementType);
+        writer.writeInt(compTypeId);
+        writer.writeInt(arr.length);
+
+        for (Object obj : arr)
+            writeValue(writer, obj);
+    }
+
+    /**
+     * @param writer Writer.
+     * @param elementType Element type.
+     * @param arr The array.
+     * @param clsName Component class name.
+     */
+    public void writeArray(BinaryWriterExImpl writer, byte elementType, Object[] arr, String clsName) {
+        writer.writeByte(elementType);
+        writer.writeInt(GridBinaryMarshaller.UNREGISTERED_TYPE_ID);
+        writer.writeString(clsName);
+        writer.writeInt(arr.length);
+
+        for (Object obj : arr)
+            writeValue(writer, obj);
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/71ad9cea/modules/core/src/main/java/org/apache/ignite/internal/binary/builder/BinaryEnumArrayLazyValue.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/binary/builder/BinaryEnumArrayLazyValue.java b/modules/core/src/main/java/org/apache/ignite/internal/binary/builder/BinaryEnumArrayLazyValue.java
new file mode 100644
index 0000000..db55050
--- /dev/null
+++ b/modules/core/src/main/java/org/apache/ignite/internal/binary/builder/BinaryEnumArrayLazyValue.java
@@ -0,0 +1,113 @@
+/*
+ * 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.binary.builder;
+
+import org.apache.ignite.internal.binary.BinaryWriterExImpl;
+import org.apache.ignite.internal.binary.GridBinaryMarshaller;
+import org.apache.ignite.internal.util.typedef.internal.U;
+import org.apache.ignite.binary.BinaryObjectException;
+import org.apache.ignite.binary.BinaryInvalidTypeException;
+
+/**
+ *
+ */
+class BinaryEnumArrayLazyValue extends BinaryAbstractLazyValue {
+    /** */
+    private final int len;
+
+    /** */
+    private final int compTypeId;
+
+    /** */
+    private final String clsName;
+
+    /**
+     * @param reader Reader.
+     */
+    protected BinaryEnumArrayLazyValue(BinaryBuilderReader reader) {
+        super(reader, reader.position() - 1);
+
+        int typeId = reader.readInt();
+
+        if (typeId == GridBinaryMarshaller.UNREGISTERED_TYPE_ID) {
+            clsName = reader.readString();
+
+            Class cls;
+
+            try {
+                cls = U.forName(reader.readString(), reader.portableContext().configuration().getClassLoader());
+            }
+            catch (ClassNotFoundException e) {
+                throw new BinaryInvalidTypeException("Failed to load the class: " + clsName, e);
+            }
+
+            compTypeId = reader.portableContext().descriptorForClass(cls, true).typeId();
+        }
+        else {
+            compTypeId = typeId;
+            clsName = null;
+        }
+
+        int size = reader.readInt();
+
+        for (int i = 0; i < size; i++)
+            reader.skipValue();
+
+        len = reader.position() - valOff;
+    }
+
+    /** {@inheritDoc} */
+    @Override protected Object init() {
+        reader.position(valOff + 1);
+
+        //skipping component type id
+        reader.readInt();
+
+        int size = reader.readInt();
+
+        BinaryBuilderEnum[] res = new BinaryBuilderEnum[size];
+
+        for (int i = 0; i < size; i++) {
+            byte flag = reader.readByte();
+
+            if (flag == GridBinaryMarshaller.NULL)
+                continue;
+
+            if (flag != GridBinaryMarshaller.ENUM)
+                throw new BinaryObjectException("Invalid flag value: " + flag);
+
+            res[i] = new BinaryBuilderEnum(reader);
+        }
+
+        return res;
+    }
+
+    /** {@inheritDoc} */
+    @Override public void writeTo(BinaryWriterExImpl writer, BinaryBuilderSerializer ctx) {
+        if (val != null) {
+            if (clsName != null)
+                ctx.writeArray(writer, GridBinaryMarshaller.ENUM_ARR, (Object[])val, clsName);
+            else
+                ctx.writeArray(writer, GridBinaryMarshaller.ENUM_ARR, (Object[])val, compTypeId);
+
+            return;
+        }
+
+        writer.write(reader.array(), valOff, len);
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/71ad9cea/modules/core/src/main/java/org/apache/ignite/internal/binary/builder/BinaryLazyArrayList.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/binary/builder/BinaryLazyArrayList.java b/modules/core/src/main/java/org/apache/ignite/internal/binary/builder/BinaryLazyArrayList.java
new file mode 100644
index 0000000..3627b1d
--- /dev/null
+++ b/modules/core/src/main/java/org/apache/ignite/internal/binary/builder/BinaryLazyArrayList.java
@@ -0,0 +1,167 @@
+/*
+ * 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.binary.builder;
+
+import java.util.AbstractList;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+import org.apache.ignite.internal.binary.BinaryWriterExImpl;
+import org.apache.ignite.internal.binary.GridBinaryMarshaller;
+import org.apache.ignite.internal.binary.BinaryUtils;
+
+/**
+ *
+ */
+class BinaryLazyArrayList extends AbstractList<Object> implements BinaryBuilderSerializationAware {
+    /** */
+    private final BinaryBuilderReader reader;
+
+    /** */
+    private final int off;
+
+    /** */
+    private List<Object> delegate;
+
+    /**
+     * @param reader Reader.
+     * @param size Size,
+     */
+    BinaryLazyArrayList(BinaryBuilderReader reader, int size) {
+        this.reader = reader;
+        off = reader.position() - 1/* flag */ - 4/* size */ - 1/* col type */;
+
+        assert size >= 0;
+
+        for (int i = 0; i < size; i++)
+            reader.skipValue();
+    }
+
+    /**
+     *
+     */
+    private void ensureDelegateInit() {
+        if (delegate == null) {
+            int size = reader.readIntPositioned(off + 1);
+
+            reader.position(off + 1/* flag */ + 4/* size */ + 1/* col type */);
+
+            delegate = new ArrayList<>(size);
+
+            for (int i = 0; i < size; i++)
+                delegate.add(reader.parseValue());
+        }
+    }
+
+    /** {@inheritDoc} */
+    @Override public Object get(int idx) {
+        ensureDelegateInit();
+
+        return BinaryUtils.unwrapLazy(delegate.get(idx));
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean add(Object o) {
+        ensureDelegateInit();
+
+        return delegate.add(o);
+    }
+
+    /** {@inheritDoc} */
+    @Override public void add(int idx, Object element) {
+        ensureDelegateInit();
+
+        delegate.add(idx, element);
+    }
+
+    /** {@inheritDoc} */
+    @Override public Object set(int idx, Object element) {
+        ensureDelegateInit();
+
+        return BinaryUtils.unwrapLazy(delegate.set(idx, element));
+    }
+
+    /** {@inheritDoc} */
+    @Override public Object remove(int idx) {
+        ensureDelegateInit();
+
+        return BinaryUtils.unwrapLazy(delegate.remove(idx));
+    }
+
+    /** {@inheritDoc} */
+    @Override public void clear() {
+        if (delegate == null)
+            delegate = new ArrayList<>();
+        else
+            delegate.clear();
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean addAll(int idx, Collection<?> c) {
+        return delegate.addAll(idx, c);
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void removeRange(int fromIdx, int toIdx) {
+        ensureDelegateInit();
+
+        delegate.subList(fromIdx, toIdx).clear();
+    }
+
+    /** {@inheritDoc} */
+    @Override public int size() {
+        if (delegate == null)
+            return reader.readIntPositioned(off + 1);
+
+        return delegate.size();
+    }
+
+    /** {@inheritDoc} */
+    @Override public void writeTo(BinaryWriterExImpl writer, BinaryBuilderSerializer ctx) {
+        if (delegate == null) {
+            int size = reader.readIntPositioned(off + 1);
+
+            int hdrSize = 1 /* flag */ + 4 /* size */ + 1 /* col type */;
+
+            writer.write(reader.array(), off, hdrSize);
+
+            reader.position(off + hdrSize);
+
+            for (int i = 0; i < size; i++) {
+                Object o = reader.parseValue();
+
+                ctx.writeValue(writer, o);
+            }
+        }
+        else {
+            writer.writeByte(GridBinaryMarshaller.COL);
+            writer.writeInt(delegate.size());
+
+            byte colType = reader.array()[off + 1 /* flag */ + 4 /* size */];
+            writer.writeByte(colType);
+
+            int oldPos = reader.position();
+
+            for (Object o : delegate)
+                ctx.writeValue(writer, o);
+
+            // PortableBuilderImpl might have been written. It could override reader's position.
+            reader.position(oldPos);
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/71ad9cea/modules/core/src/main/java/org/apache/ignite/internal/binary/builder/BinaryLazyLinkedList.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/binary/builder/BinaryLazyLinkedList.java b/modules/core/src/main/java/org/apache/ignite/internal/binary/builder/BinaryLazyLinkedList.java
new file mode 100644
index 0000000..1813fcc
--- /dev/null
+++ b/modules/core/src/main/java/org/apache/ignite/internal/binary/builder/BinaryLazyLinkedList.java
@@ -0,0 +1,218 @@
+/*
+ * 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.binary.builder;
+
+import java.util.AbstractList;
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.ListIterator;
+import org.apache.ignite.internal.binary.BinaryWriterExImpl;
+import org.apache.ignite.internal.binary.GridBinaryMarshaller;
+import org.apache.ignite.internal.binary.BinaryUtils;
+
+/**
+ *
+ */
+class BinaryLazyLinkedList extends AbstractList<Object> implements BinaryBuilderSerializationAware {
+    /** */
+    private final BinaryBuilderReader reader;
+
+    /** */
+    private final int off;
+
+    /** */
+    private List<Object> delegate;
+
+    /**
+     * @param reader Reader.
+     * @param size Size,
+     */
+    BinaryLazyLinkedList(BinaryBuilderReader reader, int size) {
+        this.reader = reader;
+        off = reader.position() - 1/* flag */ - 4/* size */ - 1/* col type */;
+
+        assert size >= 0;
+
+        for (int i = 0; i < size; i++)
+            reader.skipValue();
+    }
+
+    /**
+     *
+     */
+    private void ensureDelegateInit() {
+        if (delegate == null) {
+            int size = reader.readIntPositioned(off + 1);
+
+            reader.position(off + 1/* flag */ + 4/* size */ + 1/* col type */);
+
+            delegate = new LinkedList<>();
+
+            for (int i = 0; i < size; i++)
+                delegate.add(reader.parseValue());
+        }
+    }
+
+    /** {@inheritDoc} */
+    @Override public Object get(int idx) {
+        ensureDelegateInit();
+
+        return BinaryUtils.unwrapLazy(delegate.get(idx));
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean add(Object o) {
+        ensureDelegateInit();
+
+        return delegate.add(o);
+    }
+
+    /** {@inheritDoc} */
+    @Override public void add(int idx, Object element) {
+        ensureDelegateInit();
+
+        delegate.add(idx, element);
+    }
+
+    /** {@inheritDoc} */
+    @Override public Object set(int idx, Object element) {
+        ensureDelegateInit();
+
+        return BinaryUtils.unwrapLazy(delegate.set(idx, element));
+    }
+
+    /** {@inheritDoc} */
+    @Override public Object remove(int idx) {
+        ensureDelegateInit();
+
+        return BinaryUtils.unwrapLazy(delegate.remove(idx));
+    }
+
+    /** {@inheritDoc} */
+    @Override public void clear() {
+        if (delegate == null)
+            delegate = new LinkedList<>();
+        else
+            delegate.clear();
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean addAll(int idx, Collection<?> c) {
+        ensureDelegateInit();
+
+        return delegate.addAll(idx, c);
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void removeRange(int fromIdx, int toIdx) {
+        ensureDelegateInit();
+
+        delegate.subList(fromIdx, toIdx).clear();
+    }
+
+    /** {@inheritDoc} */
+    @Override public int size() {
+        if (delegate == null)
+            return reader.readIntPositioned(off + 1);
+
+        return delegate.size();
+    }
+
+    /** {@inheritDoc} */
+    @Override public ListIterator<Object> listIterator(final int idx) {
+        ensureDelegateInit();
+
+        return new ListIterator<Object>() {
+            /** */
+            private final ListIterator<Object> delegate = BinaryLazyLinkedList.super.listIterator(idx);
+
+            @Override public boolean hasNext() {
+                return delegate.hasNext();
+            }
+
+            @Override public Object next() {
+                return BinaryUtils.unwrapLazy(delegate.next());
+            }
+
+            @Override public boolean hasPrevious() {
+                return delegate.hasPrevious();
+            }
+
+            @Override public Object previous() {
+                return BinaryUtils.unwrapLazy(delegate.previous());
+            }
+
+            @Override public int nextIndex() {
+                return delegate.nextIndex();
+            }
+
+            @Override public int previousIndex() {
+                return delegate.previousIndex();
+            }
+
+            @Override public void remove() {
+                delegate.remove();
+            }
+
+            @Override public void set(Object o) {
+                delegate.set(o);
+            }
+
+            @Override public void add(Object o) {
+                delegate.add(o);
+            }
+        };
+    }
+
+    /** {@inheritDoc} */
+    @Override public Iterator<Object> iterator() {
+        ensureDelegateInit();
+
+        return BinaryUtils.unwrapLazyIterator(super.iterator());
+    }
+
+    /** {@inheritDoc} */
+    @Override public void writeTo(BinaryWriterExImpl writer, BinaryBuilderSerializer ctx) {
+        if (delegate == null) {
+            int size = reader.readIntPositioned(off + 1);
+
+            int hdrSize = 1 /* flag */ + 4 /* size */ + 1 /* col type */;
+            writer.write(reader.array(), off, hdrSize);
+
+            reader.position(off + hdrSize);
+
+            for (int i = 0; i < size; i++) {
+                Object o = reader.parseValue();
+
+                ctx.writeValue(writer, o);
+            }
+        }
+        else {
+            writer.writeByte(GridBinaryMarshaller.COL);
+            writer.writeInt(delegate.size());
+
+            byte colType = reader.array()[off + 1 /* flag */ + 4 /* size */];
+            writer.writeByte(colType);
+
+            for (Object o : delegate)
+                ctx.writeValue(writer, o);
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/71ad9cea/modules/core/src/main/java/org/apache/ignite/internal/binary/builder/BinaryLazyMap.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/binary/builder/BinaryLazyMap.java b/modules/core/src/main/java/org/apache/ignite/internal/binary/builder/BinaryLazyMap.java
new file mode 100644
index 0000000..c82ff7d
--- /dev/null
+++ b/modules/core/src/main/java/org/apache/ignite/internal/binary/builder/BinaryLazyMap.java
@@ -0,0 +1,221 @@
+/*
+ * 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.binary.builder;
+
+import java.util.AbstractMap;
+import java.util.AbstractSet;
+import java.util.Iterator;
+import java.util.LinkedHashMap;
+import java.util.Map;
+import java.util.Set;
+import org.apache.ignite.internal.binary.BinaryWriterExImpl;
+import org.apache.ignite.internal.binary.GridBinaryMarshaller;
+import org.apache.ignite.internal.binary.BinaryUtils;
+import org.jetbrains.annotations.Nullable;
+
+/**
+ *
+ */
+class BinaryLazyMap extends AbstractMap<Object, Object> implements BinaryBuilderSerializationAware {
+    /** */
+    private final BinaryBuilderReader reader;
+
+    /** */
+    private final int off;
+
+    /** */
+    private Map<Object, Object> delegate;
+
+    /**
+     * @param reader Reader.
+     * @param off Offset.
+     */
+    private BinaryLazyMap(BinaryBuilderReader reader, int off) {
+        this.reader = reader;
+        this.off = off;
+    }
+
+    /**
+     * @param reader Reader.
+     * @return PortableLazyMap.
+     */
+    @Nullable public static BinaryLazyMap parseMap(BinaryBuilderReader reader) {
+        int off = reader.position() - 1;
+
+        int size = reader.readInt();
+
+        reader.skip(1); // map type.
+
+        for (int i = 0; i < size; i++) {
+            reader.skipValue(); // skip key
+            reader.skipValue(); // skip value
+        }
+
+        return new BinaryLazyMap(reader, off);
+    }
+
+    /**
+     *
+     */
+    private void ensureDelegateInit() {
+        if (delegate == null) {
+            int size = reader.readIntPositioned(off + 1);
+
+            reader.position(off + 1/* flag */ + 4/* size */ + 1/* col type */);
+
+            delegate = new LinkedHashMap<>();
+
+            for (int i = 0; i < size; i++)
+                delegate.put(BinaryUtils.unwrapLazy(reader.parseValue()), reader.parseValue());
+        }
+    }
+
+    /** {@inheritDoc} */
+    @Override public void writeTo(BinaryWriterExImpl writer, BinaryBuilderSerializer ctx) {
+        if (delegate == null) {
+            int size = reader.readIntPositioned(off + 1);
+
+            int hdrSize = 1 /* flag */ + 4 /* size */ + 1 /* col type */;
+            writer.write(reader.array(), off, hdrSize);
+
+            reader.position(off + hdrSize);
+
+            for (int i = 0; i < size; i++) {
+                ctx.writeValue(writer, reader.parseValue()); // key
+                ctx.writeValue(writer, reader.parseValue()); // value
+            }
+        }
+        else {
+            writer.writeByte(GridBinaryMarshaller.MAP);
+            writer.writeInt(delegate.size());
+
+            byte colType = reader.array()[off + 1 /* flag */ + 4 /* size */];
+
+            writer.writeByte(colType);
+
+            for (Entry<Object, Object> entry : delegate.entrySet()) {
+                ctx.writeValue(writer, entry.getKey());
+                ctx.writeValue(writer, entry.getValue());
+            }
+        }
+    }
+
+    /** {@inheritDoc} */
+    @Override public int size() {
+        if (delegate == null)
+            return reader.readIntPositioned(off + 1);
+
+        return delegate.size();
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean containsKey(Object key) {
+        ensureDelegateInit();
+
+        return delegate.containsKey(key);
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean containsValue(Object val) {
+        return values().contains(val);
+    }
+
+    /** {@inheritDoc} */
+    @Override public Set<Object> keySet() {
+        ensureDelegateInit();
+
+        return delegate.keySet();
+    }
+
+    /** {@inheritDoc} */
+    @Override public void clear() {
+        if (delegate == null)
+            delegate = new LinkedHashMap<>();
+        else
+            delegate.clear();
+    }
+
+    /** {@inheritDoc} */
+    @Override public Object get(Object key) {
+        ensureDelegateInit();
+
+        return BinaryUtils.unwrapLazy(delegate.get(key));
+    }
+
+    /** {@inheritDoc} */
+    @Override public Object put(Object key, Object val) {
+        ensureDelegateInit();
+
+        return BinaryUtils.unwrapLazy(delegate.put(key, val));
+    }
+
+    /** {@inheritDoc} */
+    @Override public Object remove(Object key) {
+        ensureDelegateInit();
+
+        return BinaryUtils.unwrapLazy(delegate.remove(key));
+    }
+
+    /** {@inheritDoc} */
+    @Override public Set<Entry<Object, Object>> entrySet() {
+        ensureDelegateInit();
+
+        return new AbstractSet<Entry<Object, Object>>() {
+            @Override public boolean contains(Object o) {
+                throw new UnsupportedOperationException();
+            }
+
+            @Override public Iterator<Entry<Object, Object>> iterator() {
+                return new Iterator<Entry<Object, Object>>() {
+                    /** */
+                    private final Iterator<Entry<Object, Object>> itr = delegate.entrySet().iterator();
+
+                    @Override public boolean hasNext() {
+                        return itr.hasNext();
+                    }
+
+                    @Override public Entry<Object, Object> next() {
+                        Entry<Object, Object> res = itr.next();
+
+                        final Object val = res.getValue();
+
+                        if (val instanceof BinaryLazyValue) {
+                            return new SimpleEntry<Object, Object>(res.getKey(), val) {
+                                private static final long serialVersionUID = 0L;
+
+                                @Override public Object getValue() {
+                                    return ((BinaryLazyValue)val).value();
+                                }
+                            };
+                        }
+
+                        return res;
+                    }
+
+                    @Override public void remove() {
+                        itr.remove();
+                    }
+                };
+            }
+
+            @Override public int size() {
+                return delegate.size();
+            }
+        };
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/71ad9cea/modules/core/src/main/java/org/apache/ignite/internal/binary/builder/BinaryLazySet.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/binary/builder/BinaryLazySet.java b/modules/core/src/main/java/org/apache/ignite/internal/binary/builder/BinaryLazySet.java
new file mode 100644
index 0000000..6be4c76
--- /dev/null
+++ b/modules/core/src/main/java/org/apache/ignite/internal/binary/builder/BinaryLazySet.java
@@ -0,0 +1,92 @@
+/*
+ * 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.binary.builder;
+
+import java.util.Collection;
+import java.util.Set;
+import org.apache.ignite.internal.binary.BinaryWriterExImpl;
+import org.apache.ignite.internal.binary.GridBinaryMarshaller;
+import org.apache.ignite.internal.binary.BinaryUtils;
+import org.apache.ignite.internal.util.typedef.internal.U;
+
+/**
+ *
+ */
+class BinaryLazySet extends BinaryAbstractLazyValue {
+    /** */
+    private final int off;
+
+    /**
+     * @param reader Reader.
+     * @param size Size.
+     */
+    BinaryLazySet(BinaryBuilderReader reader, int size) {
+        super(reader, reader.position() - 1);
+
+        off = reader.position() - 1/* flag */ - 4/* size */ - 1/* col type */;
+
+        assert size >= 0;
+
+        for (int i = 0; i < size; i++)
+            reader.skipValue();
+    }
+
+    /** {@inheritDoc} */
+    @Override public void writeTo(BinaryWriterExImpl writer, BinaryBuilderSerializer ctx) {
+        if (val == null) {
+            int size = reader.readIntPositioned(off + 1);
+
+            int hdrSize = 1 /* flag */ + 4 /* size */ + 1 /* col type */;
+            writer.write(reader.array(), off, hdrSize);
+
+            reader.position(off + hdrSize);
+
+            for (int i = 0; i < size; i++) {
+                Object o = reader.parseValue();
+
+                ctx.writeValue(writer, o);
+            }
+        }
+        else {
+            Collection<Object> c = (Collection<Object>)val;
+
+            writer.writeByte(GridBinaryMarshaller.COL);
+            writer.writeInt(c.size());
+
+            byte colType = reader.array()[off + 1 /* flag */ + 4 /* size */];
+            writer.writeByte(colType);
+
+            for (Object o : c)
+                ctx.writeValue(writer, o);
+        }
+    }
+
+    /** {@inheritDoc} */
+    @Override protected Object init() {
+        int size = reader.readIntPositioned(off + 1);
+
+        reader.position(off + 1/* flag */ + 4/* size */ + 1/* col type */);
+
+        Set<Object> res = U.newLinkedHashSet(size);
+
+        for (int i = 0; i < size; i++)
+            res.add(BinaryUtils.unwrapLazy(reader.parseValue()));
+
+        return res;
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/71ad9cea/modules/core/src/main/java/org/apache/ignite/internal/binary/builder/BinaryLazyValue.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/binary/builder/BinaryLazyValue.java b/modules/core/src/main/java/org/apache/ignite/internal/binary/builder/BinaryLazyValue.java
new file mode 100644
index 0000000..f9da84b
--- /dev/null
+++ b/modules/core/src/main/java/org/apache/ignite/internal/binary/builder/BinaryLazyValue.java
@@ -0,0 +1,28 @@
+/*
+ * 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.binary.builder;
+
+/**
+ *
+ */
+public interface BinaryLazyValue extends BinaryBuilderSerializationAware {
+    /**
+     * @return Value.
+     */
+    public Object value();
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/71ad9cea/modules/core/src/main/java/org/apache/ignite/internal/binary/builder/BinaryModifiableLazyValue.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/binary/builder/BinaryModifiableLazyValue.java b/modules/core/src/main/java/org/apache/ignite/internal/binary/builder/BinaryModifiableLazyValue.java
new file mode 100644
index 0000000..070abf3
--- /dev/null
+++ b/modules/core/src/main/java/org/apache/ignite/internal/binary/builder/BinaryModifiableLazyValue.java
@@ -0,0 +1,52 @@
+/*
+ * 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.binary.builder;
+
+import org.apache.ignite.internal.binary.BinaryWriterExImpl;
+
+/**
+ *
+ */
+public class BinaryModifiableLazyValue extends BinaryAbstractLazyValue {
+    /** */
+    protected final int len;
+
+    /**
+     * @param reader
+     * @param valOff
+     * @param len
+     */
+    public BinaryModifiableLazyValue(BinaryBuilderReader reader, int valOff, int len) {
+        super(reader, valOff);
+
+        this.len = len;
+    }
+
+    /** {@inheritDoc} */
+    @Override protected Object init() {
+        return reader.reader().unmarshal(valOff);
+    }
+
+    /** {@inheritDoc} */
+    @Override public void writeTo(BinaryWriterExImpl writer, BinaryBuilderSerializer ctx) {
+        if (val == null)
+            writer.write(reader.array(), valOff, len);
+        else
+            writer.writeObject(val);
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/71ad9cea/modules/core/src/main/java/org/apache/ignite/internal/binary/builder/BinaryObjectArrayLazyValue.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/binary/builder/BinaryObjectArrayLazyValue.java b/modules/core/src/main/java/org/apache/ignite/internal/binary/builder/BinaryObjectArrayLazyValue.java
new file mode 100644
index 0000000..05713b4
--- /dev/null
+++ b/modules/core/src/main/java/org/apache/ignite/internal/binary/builder/BinaryObjectArrayLazyValue.java
@@ -0,0 +1,90 @@
+/*
+ * 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.binary.builder;
+
+import org.apache.ignite.internal.binary.GridBinaryMarshaller;
+import org.apache.ignite.internal.binary.BinaryWriterExImpl;
+import org.apache.ignite.internal.util.typedef.internal.U;
+import org.apache.ignite.binary.BinaryInvalidTypeException;
+
+/**
+ *
+ */
+class BinaryObjectArrayLazyValue extends BinaryAbstractLazyValue {
+    /** */
+    private Object[] lazyValsArr;
+
+    /** */
+    private int compTypeId;
+
+    /** */
+    private String clsName;
+
+    /**
+     * @param reader Reader.
+     */
+    protected BinaryObjectArrayLazyValue(BinaryBuilderReader reader) {
+        super(reader, reader.position() - 1);
+
+        int typeId = reader.readInt();
+
+        if (typeId == GridBinaryMarshaller.UNREGISTERED_TYPE_ID) {
+            clsName = reader.readString();
+
+            Class cls;
+
+            try {
+                cls = U.forName(reader.readString(), reader.portableContext().configuration().getClassLoader());
+            }
+            catch (ClassNotFoundException e) {
+                throw new BinaryInvalidTypeException("Failed to load the class: " + clsName, e);
+            }
+
+            compTypeId = reader.portableContext().descriptorForClass(cls, true).typeId();
+        }
+        else {
+            compTypeId = typeId;
+            clsName = null;
+        }
+
+        int size = reader.readInt();
+
+        lazyValsArr = new Object[size];
+
+        for (int i = 0; i < size; i++)
+            lazyValsArr[i] = reader.parseValue();
+    }
+
+    /** {@inheritDoc} */
+    @Override protected Object init() {
+        for (int i = 0; i < lazyValsArr.length; i++) {
+            if (lazyValsArr[i] instanceof BinaryLazyValue)
+                lazyValsArr[i] = ((BinaryLazyValue)lazyValsArr[i]).value();
+        }
+
+        return lazyValsArr;
+    }
+
+    /** {@inheritDoc} */
+    @Override public void writeTo(BinaryWriterExImpl writer, BinaryBuilderSerializer ctx) {
+        if (clsName == null)
+            ctx.writeArray(writer, GridBinaryMarshaller.OBJ_ARR, lazyValsArr, compTypeId);
+        else
+            ctx.writeArray(writer, GridBinaryMarshaller.OBJ_ARR, lazyValsArr, clsName);
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/71ad9cea/modules/core/src/main/java/org/apache/ignite/internal/binary/builder/BinaryObjectBuilderImpl.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/binary/builder/BinaryObjectBuilderImpl.java b/modules/core/src/main/java/org/apache/ignite/internal/binary/builder/BinaryObjectBuilderImpl.java
index f1d4185..5e60a20 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/binary/builder/BinaryObjectBuilderImpl.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/binary/builder/BinaryObjectBuilderImpl.java
@@ -25,19 +25,12 @@ import org.apache.ignite.binary.BinaryType;
 import org.apache.ignite.internal.binary.BinaryMetadata;
 import org.apache.ignite.internal.binary.BinaryObjectImpl;
 import org.apache.ignite.internal.binary.BinaryWriterExImpl;
-import org.apache.ignite.internal.binary.GridPortableMarshaller;
-import org.apache.ignite.internal.binary.PortableContext;
-import org.apache.ignite.internal.binary.PortableSchema;
-import org.apache.ignite.internal.binary.PortableSchemaRegistry;
-import org.apache.ignite.internal.binary.BinaryMetadata;
-import org.apache.ignite.internal.binary.BinaryObjectImpl;
+import org.apache.ignite.internal.binary.GridBinaryMarshaller;
+import org.apache.ignite.internal.binary.BinaryContext;
+import org.apache.ignite.internal.binary.BinarySchema;
+import org.apache.ignite.internal.binary.BinarySchemaRegistry;
 import org.apache.ignite.internal.binary.BinaryObjectOffheapImpl;
-import org.apache.ignite.internal.binary.BinaryWriterExImpl;
-import org.apache.ignite.internal.binary.GridPortableMarshaller;
-import org.apache.ignite.internal.binary.PortableContext;
-import org.apache.ignite.internal.binary.PortableSchema;
-import org.apache.ignite.internal.binary.PortableSchemaRegistry;
-import org.apache.ignite.internal.binary.PortableUtils;
+import org.apache.ignite.internal.binary.BinaryUtils;
 import org.apache.ignite.internal.util.typedef.F;
 import org.apache.ignite.internal.util.typedef.internal.U;
 import org.apache.ignite.lang.IgniteBiTuple;
@@ -49,13 +42,6 @@ import java.util.LinkedHashMap;
 import java.util.Map;
 import java.util.Set;
 
-import static org.apache.ignite.internal.binary.GridPortableMarshaller.DFLT_HDR_LEN;
-import static org.apache.ignite.internal.binary.GridPortableMarshaller.FLAGS_POS;
-import static org.apache.ignite.internal.binary.GridPortableMarshaller.HASH_CODE_POS;
-import static org.apache.ignite.internal.binary.GridPortableMarshaller.PROTO_VER_POS;
-import static org.apache.ignite.internal.binary.GridPortableMarshaller.TYPE_ID_POS;
-import static org.apache.ignite.internal.binary.GridPortableMarshaller.UNREGISTERED_TYPE_ID;
-
 /**
  *
  */
@@ -64,7 +50,7 @@ public class BinaryObjectBuilderImpl implements BinaryObjectBuilder {
     private static final Object REMOVED_FIELD_MARKER = new Object();
 
     /** */
-    private final PortableContext ctx;
+    private final BinaryContext ctx;
 
     /** */
     private final int typeId;
@@ -94,7 +80,7 @@ public class BinaryObjectBuilderImpl implements BinaryObjectBuilder {
     private final int hdrLen;
 
     /** Context of PortableObject reading process. Or {@code null} if object is not created from PortableObject. */
-    private final PortableBuilderReader reader;
+    private final BinaryBuilderReader reader;
 
     /** */
     private int hashCode;
@@ -103,8 +89,8 @@ public class BinaryObjectBuilderImpl implements BinaryObjectBuilder {
      * @param clsName Class name.
      * @param ctx Portable context.
      */
-    public BinaryObjectBuilderImpl(PortableContext ctx, String clsName) {
-        this(ctx, ctx.typeId(clsName), PortableContext.typeName(clsName));
+    public BinaryObjectBuilderImpl(BinaryContext ctx, String clsName) {
+        this(ctx, ctx.typeId(clsName), BinaryContext.typeName(clsName));
     }
 
     /**
@@ -112,7 +98,7 @@ public class BinaryObjectBuilderImpl implements BinaryObjectBuilder {
      * @param ctx Context.
      * @param typeId Type id.
      */
-    public BinaryObjectBuilderImpl(PortableContext ctx, int typeId, String typeName) {
+    public BinaryObjectBuilderImpl(BinaryContext ctx, int typeId, String typeName) {
         this.typeId = typeId;
         this.typeName = typeName;
         this.ctx = ctx;
@@ -120,7 +106,7 @@ public class BinaryObjectBuilderImpl implements BinaryObjectBuilder {
         start = -1;
         flags = -1;
         reader = null;
-        hdrLen = GridPortableMarshaller.DFLT_HDR_LEN;
+        hdrLen = GridBinaryMarshaller.DFLT_HDR_LEN;
 
         readCache = Collections.emptyMap();
     }
@@ -129,7 +115,7 @@ public class BinaryObjectBuilderImpl implements BinaryObjectBuilder {
      * @param obj Object to wrap.
      */
     public BinaryObjectBuilderImpl(BinaryObjectImpl obj) {
-        this(new PortableBuilderReader(obj), obj.start());
+        this(new BinaryBuilderReader(obj), obj.start());
 
         reader.registerObject(this);
     }
@@ -138,23 +124,23 @@ public class BinaryObjectBuilderImpl implements BinaryObjectBuilder {
      * @param reader ctx
      * @param start Start.
      */
-    BinaryObjectBuilderImpl(PortableBuilderReader reader, int start) {
+    BinaryObjectBuilderImpl(BinaryBuilderReader reader, int start) {
         this.reader = reader;
         this.start = start;
-        this.flags = reader.readShortPositioned(start + GridPortableMarshaller.FLAGS_POS);
+        this.flags = reader.readShortPositioned(start + GridBinaryMarshaller.FLAGS_POS);
 
-        byte ver = reader.readBytePositioned(start + GridPortableMarshaller.PROTO_VER_POS);
+        byte ver = reader.readBytePositioned(start + GridBinaryMarshaller.PROTO_VER_POS);
 
-        PortableUtils.checkProtocolVersion(ver);
+        BinaryUtils.checkProtocolVersion(ver);
 
-        int typeId = reader.readIntPositioned(start + GridPortableMarshaller.TYPE_ID_POS);
+        int typeId = reader.readIntPositioned(start + GridBinaryMarshaller.TYPE_ID_POS);
         ctx = reader.portableContext();
-        hashCode = reader.readIntPositioned(start + GridPortableMarshaller.HASH_CODE_POS);
+        hashCode = reader.readIntPositioned(start + GridBinaryMarshaller.HASH_CODE_POS);
 
-        if (typeId == GridPortableMarshaller.UNREGISTERED_TYPE_ID) {
+        if (typeId == GridBinaryMarshaller.UNREGISTERED_TYPE_ID) {
             int mark = reader.position();
 
-            reader.position(start + GridPortableMarshaller.DFLT_HDR_LEN);
+            reader.position(start + GridBinaryMarshaller.DFLT_HDR_LEN);
 
             clsNameToWrite = reader.readString();
 
@@ -177,7 +163,7 @@ public class BinaryObjectBuilderImpl implements BinaryObjectBuilder {
         }
         else {
             this.typeId = typeId;
-            hdrLen = GridPortableMarshaller.DFLT_HDR_LEN;
+            hdrLen = GridBinaryMarshaller.DFLT_HDR_LEN;
         }
     }
 
@@ -186,7 +172,7 @@ public class BinaryObjectBuilderImpl implements BinaryObjectBuilder {
         try (BinaryWriterExImpl writer = new BinaryWriterExImpl(ctx)) {
             writer.typeId(typeId);
 
-            PortableBuilderSerializer serializationCtx = new PortableBuilderSerializer();
+            BinaryBuilderSerializer serializationCtx = new BinaryBuilderSerializer();
 
             serializationCtx.registerObjectWriting(this, 0);
 
@@ -202,14 +188,14 @@ public class BinaryObjectBuilderImpl implements BinaryObjectBuilder {
      * @param writer Writer.
      * @param serializer Serializer.
      */
-    void serializeTo(BinaryWriterExImpl writer, PortableBuilderSerializer serializer) {
+    void serializeTo(BinaryWriterExImpl writer, BinaryBuilderSerializer serializer) {
         try {
             writer.preWrite(registeredType ? null : clsNameToWrite);
 
             Set<Integer> remainsFlds = null;
 
             if (reader != null) {
-                PortableSchema schema = reader.schema();
+                BinarySchema schema = reader.schema();
 
                 Map<Integer, Object> assignedFldsById;
 
@@ -228,16 +214,16 @@ public class BinaryObjectBuilderImpl implements BinaryObjectBuilder {
                     assignedFldsById = Collections.emptyMap();
 
                 // Get footer details.
-                int fieldIdLen = PortableUtils.fieldIdLength(flags);
-                int fieldOffsetLen = PortableUtils.fieldOffsetLength(flags);
+                int fieldIdLen = BinaryUtils.fieldIdLength(flags);
+                int fieldOffsetLen = BinaryUtils.fieldOffsetLength(flags);
 
-                IgniteBiTuple<Integer, Integer> footer = PortableUtils.footerAbsolute(reader, start);
+                IgniteBiTuple<Integer, Integer> footer = BinaryUtils.footerAbsolute(reader, start);
 
                 int footerPos = footer.get1();
                 int footerEnd = footer.get2();
 
                 // Get raw position.
-                int rawPos = PortableUtils.rawOffsetAbsolute(reader, start);
+                int rawPos = BinaryUtils.rawOffsetAbsolute(reader, start);
 
                 // Position reader on data.
                 reader.position(start + hdrLen);
@@ -265,7 +251,7 @@ public class BinaryObjectBuilderImpl implements BinaryObjectBuilder {
                     else {
                         int type = fieldLen != 0 ? reader.readByte(0) : 0;
 
-                        if (fieldLen != 0 && !PortableUtils.isPlainArrayType(type) && PortableUtils.isPlainType(type)) {
+                        if (fieldLen != 0 && !BinaryUtils.isPlainArrayType(type) && BinaryUtils.isPlainType(type)) {
                             writer.writeFieldId(fieldId);
 
                             writer.write(reader.array(), reader.position(), fieldLen);
@@ -321,26 +307,26 @@ public class BinaryObjectBuilderImpl implements BinaryObjectBuilder {
 
                     int newFldTypeId;
 
-                    if (val instanceof PortableValueWithType) {
-                        newFldTypeId = ((PortableValueWithType)val).typeId();
+                    if (val instanceof BinaryValueWithType) {
+                        newFldTypeId = ((BinaryValueWithType)val).typeId();
 
-                        if (newFldTypeId == GridPortableMarshaller.OBJ && ((PortableValueWithType)val).value() == null)
+                        if (newFldTypeId == GridBinaryMarshaller.OBJ && ((BinaryValueWithType)val).value() == null)
                             nullObjField = true;
                     }
                     else
-                        newFldTypeId = PortableUtils.typeByClass(val.getClass());
+                        newFldTypeId = BinaryUtils.typeByClass(val.getClass());
 
-                    String newFldTypeName = PortableUtils.fieldTypeName(newFldTypeId);
+                    String newFldTypeName = BinaryUtils.fieldTypeName(newFldTypeId);
 
                     if (oldFldTypeName == null) {
                         // It's a new field, we have to add it to metadata.
                         if (fieldsMeta == null)
                             fieldsMeta = new HashMap<>();
 
-                        fieldsMeta.put(name, PortableUtils.fieldTypeId(newFldTypeName));
+                        fieldsMeta.put(name, BinaryUtils.fieldTypeId(newFldTypeName));
                     }
                     else if (!nullObjField) {
-                        String objTypeName = PortableUtils.fieldTypeName(GridPortableMarshaller.OBJ);
+                        String objTypeName = BinaryUtils.fieldTypeName(GridBinaryMarshaller.OBJ);
 
                         if (!objTypeName.equals(oldFldTypeName) && !oldFldTypeName.equals(newFldTypeName)) {
                             throw new BinaryObjectException(
@@ -357,8 +343,8 @@ public class BinaryObjectBuilderImpl implements BinaryObjectBuilder {
 
             if (reader != null) {
                 // Write raw data if any.
-                int rawOff = PortableUtils.rawOffsetAbsolute(reader, start);
-                int footerStart = PortableUtils.footerStartAbsolute(reader, start);
+                int rawOff = BinaryUtils.rawOffsetAbsolute(reader, start);
+                int footerStart = BinaryUtils.footerStartAbsolute(reader, start);
 
                 if (rawOff < footerStart) {
                     writer.rawWriter();
@@ -367,7 +353,7 @@ public class BinaryObjectBuilderImpl implements BinaryObjectBuilder {
                 }
 
                 // Shift reader to the end of the object.
-                reader.position(start + PortableUtils.length(reader, start));
+                reader.position(start + BinaryUtils.length(reader, start));
             }
 
             writer.postWrite(true, registeredType, hashCode);
@@ -375,7 +361,7 @@ public class BinaryObjectBuilderImpl implements BinaryObjectBuilder {
             // Update metadata if needed.
             int schemaId = writer.schemaId();
 
-            PortableSchemaRegistry schemaReg = ctx.schemaRegistry(typeId);
+            BinarySchemaRegistry schemaReg = ctx.schemaRegistry(typeId);
 
             if (schemaReg.schema(schemaId) == null) {
                 String typeName = this.typeName;
@@ -386,7 +372,7 @@ public class BinaryObjectBuilderImpl implements BinaryObjectBuilder {
                     typeName = meta.typeName();
                 }
 
-                PortableSchema curSchema = writer.currentSchema();
+                BinarySchema curSchema = writer.currentSchema();
 
                 ctx.updateMetadata(typeId, new BinaryMetadata(typeId, typeName, fieldsMeta,
                     ctx.affinityKeyFieldName(typeId), Collections.singleton(curSchema), false));
@@ -419,7 +405,7 @@ public class BinaryObjectBuilderImpl implements BinaryObjectBuilder {
     private IgniteBiTuple<Integer, Integer> fieldPositionAndLength(int footerPos, int footerEnd, int rawPos,
         int fieldIdLen, int fieldOffsetLen) {
         // Get field offset first.
-        int fieldOffset = PortableUtils.fieldOffsetRelative(reader, footerPos + fieldIdLen, fieldOffsetLen);
+        int fieldOffset = BinaryUtils.fieldOffsetRelative(reader, footerPos + fieldIdLen, fieldOffsetLen);
         int fieldPos = start + fieldOffset;
 
         // Get field length.
@@ -430,7 +416,7 @@ public class BinaryObjectBuilderImpl implements BinaryObjectBuilder {
             fieldLen = rawPos - fieldPos;
         else {
             // Field is somewhere in the middle, get difference with the next offset.
-            int nextFieldOffset = PortableUtils.fieldOffsetRelative(reader,
+            int nextFieldOffset = BinaryUtils.fieldOffsetRelative(reader,
                 footerPos + fieldIdLen + fieldOffsetLen + fieldIdLen, fieldOffsetLen);
 
             fieldLen = nextFieldOffset - fieldOffset;
@@ -446,19 +432,19 @@ public class BinaryObjectBuilderImpl implements BinaryObjectBuilder {
         assert reader != null;
 
         if (readCache == null) {
-            int fieldIdLen = PortableUtils.fieldIdLength(flags);
-            int fieldOffsetLen = PortableUtils.fieldOffsetLength(flags);
+            int fieldIdLen = BinaryUtils.fieldIdLength(flags);
+            int fieldOffsetLen = BinaryUtils.fieldOffsetLength(flags);
 
-            PortableSchema schema = reader.schema();
+            BinarySchema schema = reader.schema();
 
             Map<Integer, Object> readCache = new HashMap<>();
 
-            IgniteBiTuple<Integer, Integer> footer = PortableUtils.footerAbsolute(reader, start);
+            IgniteBiTuple<Integer, Integer> footer = BinaryUtils.footerAbsolute(reader, start);
 
             int footerPos = footer.get1();
             int footerEnd = footer.get2();
 
-            int rawPos = PortableUtils.rawOffsetAbsolute(reader, start);
+            int rawPos = BinaryUtils.rawOffsetAbsolute(reader, start);
 
             int idx = 0;
 
@@ -499,20 +485,20 @@ public class BinaryObjectBuilderImpl implements BinaryObjectBuilder {
             val = readCache.get(fldId);
         }
 
-        return (T)PortableUtils.unwrapLazy(val);
+        return (T)BinaryUtils.unwrapLazy(val);
     }
 
     /** {@inheritDoc} */
     @Override public BinaryObjectBuilder setField(String name, Object val0) {
-        Object val = val0 == null ? new PortableValueWithType(PortableUtils.typeByClass(Object.class), null) : val0;
+        Object val = val0 == null ? new BinaryValueWithType(BinaryUtils.typeByClass(Object.class), null) : val0;
 
         if (assignedVals == null)
             assignedVals = new LinkedHashMap<>();
 
         Object oldVal = assignedVals.put(name, val);
 
-        if (oldVal instanceof PortableValueWithType && val0 != null) {
-            ((PortableValueWithType)oldVal).value(val);
+        if (oldVal instanceof BinaryValueWithType && val0 != null) {
+            ((BinaryValueWithType)oldVal).value(val);
 
             assignedVals.put(name, oldVal);
         }
@@ -525,7 +511,7 @@ public class BinaryObjectBuilderImpl implements BinaryObjectBuilder {
         if (assignedVals == null)
             assignedVals = new LinkedHashMap<>();
 
-        assignedVals.put(name, new PortableValueWithType(PortableUtils.typeByClass(type), val));
+        assignedVals.put(name, new BinaryValueWithType(BinaryUtils.typeByClass(type), val));
 
         return this;
     }

http://git-wip-us.apache.org/repos/asf/ignite/blob/71ad9cea/modules/core/src/main/java/org/apache/ignite/internal/binary/builder/BinaryPlainBinaryObject.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/binary/builder/BinaryPlainBinaryObject.java b/modules/core/src/main/java/org/apache/ignite/internal/binary/builder/BinaryPlainBinaryObject.java
new file mode 100644
index 0000000..5ac4e97
--- /dev/null
+++ b/modules/core/src/main/java/org/apache/ignite/internal/binary/builder/BinaryPlainBinaryObject.java
@@ -0,0 +1,53 @@
+/*
+ * 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.binary.builder;
+
+import org.apache.ignite.internal.binary.BinaryObjectImpl;
+import org.apache.ignite.internal.binary.BinaryObjectOffheapImpl;
+import org.apache.ignite.internal.binary.BinaryWriterExImpl;
+import org.apache.ignite.binary.BinaryObject;
+
+/**
+ *
+ */
+public class BinaryPlainBinaryObject implements BinaryLazyValue {
+    /** */
+    private final BinaryObject portableObj;
+
+    /**
+     * @param portableObj Portable object.
+     */
+    public BinaryPlainBinaryObject(BinaryObject portableObj) {
+        this.portableObj = portableObj;
+    }
+
+    /** {@inheritDoc} */
+    @Override public Object value() {
+        return portableObj;
+    }
+
+    /** {@inheritDoc} */
+    @Override public void writeTo(BinaryWriterExImpl writer, BinaryBuilderSerializer ctx) {
+        BinaryObject val = portableObj;
+
+        if (val instanceof BinaryObjectOffheapImpl)
+            val = ((BinaryObjectOffheapImpl)val).heapCopy();
+
+        writer.doWritePortableObject((BinaryObjectImpl)val);
+    }
+}


[02/59] [abbrv] ignite git commit: ignite-2065: rename "portable" packages to "binary"

Posted by ak...@apache.org.
http://git-wip-us.apache.org/repos/asf/ignite/blob/1dbf20e0/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/GridPortableDuplicateIndexObjectsAbstractSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/GridPortableDuplicateIndexObjectsAbstractSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/GridPortableDuplicateIndexObjectsAbstractSelfTest.java
deleted file mode 100644
index d15f321..0000000
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/GridPortableDuplicateIndexObjectsAbstractSelfTest.java
+++ /dev/null
@@ -1,161 +0,0 @@
-/*
- * 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.processors.cache.portable;
-
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import org.apache.ignite.IgniteCache;
-import org.apache.ignite.cache.CacheAtomicityMode;
-import org.apache.ignite.cache.CacheMode;
-import org.apache.ignite.cache.CacheTypeMetadata;
-import org.apache.ignite.cache.query.SqlFieldsQuery;
-import org.apache.ignite.configuration.BinaryConfiguration;
-import org.apache.ignite.configuration.CacheConfiguration;
-import org.apache.ignite.configuration.IgniteConfiguration;
-import org.apache.ignite.internal.processors.cache.GridCacheAbstractSelfTest;
-import org.apache.ignite.internal.util.typedef.F;
-import org.apache.ignite.internal.portable.BinaryMarshaller;
-import org.apache.ignite.binary.BinaryObject;
-
-/**
- * Tests that portable object is the same in cache entry and in index.
- */
-public abstract class GridPortableDuplicateIndexObjectsAbstractSelfTest extends GridCacheAbstractSelfTest {
-    /** {@inheritDoc} */
-    @Override protected int gridCount() {
-        return 1;
-    }
-
-    /** {@inheritDoc} */
-    @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception {
-        IgniteConfiguration cfg = super.getConfiguration(gridName);
-
-        BinaryConfiguration bCfg = new BinaryConfiguration();
-
-        bCfg.setClassNames(Collections.singletonList(TestPortable.class.getName()));
-
-        cfg.setBinaryConfiguration(bCfg);
-
-        cfg.setMarshaller(new BinaryMarshaller());
-
-        return cfg;
-    }
-
-    /** {@inheritDoc} */
-    @Override protected CacheConfiguration cacheConfiguration(String gridName) throws Exception {
-        CacheConfiguration ccfg = super.cacheConfiguration(gridName);
-
-        ccfg.setCopyOnRead(false);
-
-        CacheTypeMetadata meta = new CacheTypeMetadata();
-
-        meta.setKeyType(Integer.class);
-        meta.setValueType(TestPortable.class.getName());
-
-        Map<String, Class<?>> idx = new HashMap<>();
-
-        idx.put("fieldOne", String.class);
-        idx.put("fieldTwo", Integer.class);
-
-        meta.setAscendingFields(idx);
-
-        ccfg.setTypeMetadata(Collections.singletonList(meta));
-
-        return ccfg;
-    }
-
-    /** {@inheritDoc} */
-    @Override public abstract CacheAtomicityMode atomicityMode();
-
-    /** {@inheritDoc} */
-    @Override public abstract CacheMode cacheMode();
-
-    /**
-     * @throws Exception If failed.
-     */
-    public void testIndexReferences() throws Exception {
-        IgniteCache<Integer, TestPortable> cache = grid(0).cache(null);
-
-        String fieldOneVal = "123";
-        int fieldTwoVal = 123;
-        int key = 0;
-
-        cache.put(key, new TestPortable(fieldOneVal, fieldTwoVal));
-
-        IgniteCache<Integer, BinaryObject> prj = grid(0).cache(null).withKeepBinary();
-
-        BinaryObject cacheVal = prj.get(key);
-
-        assertEquals(fieldOneVal, cacheVal.field("fieldOne"));
-        assertEquals(new Integer(fieldTwoVal), cacheVal.field("fieldTwo"));
-
-        List<?> row = F.first(prj.query(new SqlFieldsQuery("select _val from " +
-            "TestPortable where _key = ?").setArgs(key)).getAll());
-
-        assertEquals(1, row.size());
-
-        BinaryObject qryVal = (BinaryObject)row.get(0);
-
-        assertEquals(fieldOneVal, qryVal.field("fieldOne"));
-        assertEquals(new Integer(fieldTwoVal), qryVal.field("fieldTwo"));
-        assertSame(cacheVal, qryVal);
-    }
-
-    /**
-     * Test portable object.
-     */
-    private static class TestPortable {
-        /** */
-        private String fieldOne;
-
-        /** */
-        private int fieldTwo;
-
-        /**
-         *
-         */
-        private TestPortable() {
-            // No-op.
-        }
-
-        /**
-         * @param fieldOne Field one.
-         * @param fieldTwo Field two.
-         */
-        private TestPortable(String fieldOne, int fieldTwo) {
-            this.fieldOne = fieldOne;
-            this.fieldTwo = fieldTwo;
-        }
-
-        /**
-         * @return Field one.
-         */
-        public String fieldOne() {
-            return fieldOne;
-        }
-
-        /**
-         * @return Field two.
-         */
-        public int fieldTwo() {
-            return fieldTwo;
-        }
-    }
-}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ignite/blob/1dbf20e0/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/datastreaming/DataStreamProcessorPortableSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/datastreaming/DataStreamProcessorPortableSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/datastreaming/DataStreamProcessorPortableSelfTest.java
deleted file mode 100644
index 0599863..0000000
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/datastreaming/DataStreamProcessorPortableSelfTest.java
+++ /dev/null
@@ -1,71 +0,0 @@
-/*
- * 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.processors.cache.portable.datastreaming;
-
-import java.util.Collection;
-import java.util.Map;
-import org.apache.ignite.IgniteCache;
-import org.apache.ignite.binary.BinaryObject;
-import org.apache.ignite.configuration.IgniteConfiguration;
-import org.apache.ignite.internal.processors.datastreamer.DataStreamProcessorSelfTest;
-import org.apache.ignite.internal.portable.BinaryMarshaller;
-import org.apache.ignite.stream.StreamReceiver;
-
-/**
- *
- */
-public class DataStreamProcessorPortableSelfTest extends DataStreamProcessorSelfTest {
-    /** {@inheritDoc} */
-    @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception {
-        IgniteConfiguration cfg = super.getConfiguration(gridName);
-
-        BinaryMarshaller marsh = new BinaryMarshaller();
-
-        cfg.setMarshaller(marsh);
-
-        return cfg;
-    }
-
-    /** {@inheritDoc} */
-    @Override protected StreamReceiver<String, TestObject> getStreamReceiver() {
-        return new TestDataReceiver();
-    }
-
-    /** {@inheritDoc} */
-    @Override protected boolean customKeepBinary() {
-        return true;
-    }
-
-    /**
-     *
-     */
-    private static class TestDataReceiver implements StreamReceiver<String, TestObject> {
-        /** {@inheritDoc} */
-        @Override public void receive(IgniteCache<String, TestObject> cache,
-            Collection<Map.Entry<String, TestObject>> entries) {
-            for (Map.Entry<String, TestObject> e : entries) {
-                assertTrue(e.getKey() instanceof String);
-                assertTrue(String.valueOf(e.getValue()), e.getValue() instanceof BinaryObject);
-
-                TestObject obj = ((BinaryObject)e.getValue()).deserialize();
-
-                cache.put(e.getKey(), new TestObject(obj.val + 1));
-            }
-        }
-    }
-}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ignite/blob/1dbf20e0/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/datastreaming/GridDataStreamerImplSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/datastreaming/GridDataStreamerImplSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/datastreaming/GridDataStreamerImplSelfTest.java
deleted file mode 100644
index 72f71b6..0000000
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/datastreaming/GridDataStreamerImplSelfTest.java
+++ /dev/null
@@ -1,345 +0,0 @@
-/*
- * 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.processors.cache.portable.datastreaming;
-
-import java.io.Serializable;
-import java.util.Map;
-import java.util.Random;
-import org.apache.ignite.Ignite;
-import org.apache.ignite.IgniteCache;
-import org.apache.ignite.IgniteDataStreamer;
-import org.apache.ignite.cache.CachePeekMode;
-import org.apache.ignite.cluster.ClusterNode;
-import org.apache.ignite.configuration.CacheConfiguration;
-import org.apache.ignite.configuration.IgniteConfiguration;
-import org.apache.ignite.internal.processors.cache.IgniteCacheProxy;
-import org.apache.ignite.internal.util.typedef.G;
-import org.apache.ignite.internal.util.typedef.internal.U;
-import org.apache.ignite.internal.portable.BinaryMarshaller;
-import org.apache.ignite.binary.BinaryObjectException;
-import org.apache.ignite.binary.Binarylizable;
-import org.apache.ignite.binary.BinaryObject;
-import org.apache.ignite.binary.BinaryReader;
-import org.apache.ignite.binary.BinaryWriter;
-import org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi;
-import org.apache.ignite.spi.discovery.tcp.ipfinder.TcpDiscoveryIpFinder;
-import org.apache.ignite.spi.discovery.tcp.ipfinder.vm.TcpDiscoveryVmIpFinder;
-import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
-
-import static org.apache.ignite.cache.CacheMode.PARTITIONED;
-import static org.apache.ignite.cache.CacheWriteSynchronizationMode.FULL_SYNC;
-
-/**
- * Tests for {@code IgniteDataStreamerImpl}.
- */
-public class GridDataStreamerImplSelfTest extends GridCommonAbstractTest {
-    /** IP finder. */
-    private static final TcpDiscoveryIpFinder IP_FINDER = new TcpDiscoveryVmIpFinder(true);
-
-    /** Number of keys to load via data streamer. */
-    private static final int KEYS_COUNT = 1000;
-
-    /** Flag indicating should be cache configured with binary or not.  */
-    private static boolean portables;
-
-    /** {@inheritDoc} */
-    @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception {
-        IgniteConfiguration cfg = super.getConfiguration(gridName);
-
-        TcpDiscoverySpi discoSpi = new TcpDiscoverySpi();
-        discoSpi.setIpFinder(IP_FINDER);
-
-        cfg.setDiscoverySpi(discoSpi);
-
-        if (portables) {
-            BinaryMarshaller marsh = new BinaryMarshaller();
-
-            cfg.setMarshaller(marsh);
-        }
-
-        cfg.setCacheConfiguration(cacheConfiguration());
-
-        return cfg;
-    }
-
-    /**
-     * Gets cache configuration.
-     *
-     * @return Cache configuration.
-     */
-    private CacheConfiguration cacheConfiguration() {
-        CacheConfiguration cacheCfg = defaultCacheConfiguration();
-
-        cacheCfg.setCacheMode(PARTITIONED);
-        cacheCfg.setNearConfiguration(null);
-        cacheCfg.setBackups(0);
-        cacheCfg.setWriteSynchronizationMode(FULL_SYNC);
-
-        return cacheCfg;
-    }
-
-    /**
-     * Data streamer should correctly load entries from HashMap in case of grids with more than one node
-     *  and with GridOptimizedMarshaller that requires serializable.
-     *
-     * @throws Exception If failed.
-     */
-    public void testAddDataFromMap() throws Exception {
-        try {
-            portables = false;
-
-            startGrids(2);
-
-            awaitPartitionMapExchange();
-
-            Ignite g0 = grid(0);
-
-            IgniteDataStreamer<Integer, String> dataLdr = g0.dataStreamer(null);
-
-            Map<Integer, String> map = U.newHashMap(KEYS_COUNT);
-
-            for (int i = 0; i < KEYS_COUNT; i ++)
-                map.put(i, String.valueOf(i));
-
-            dataLdr.addData(map);
-
-            dataLdr.close();
-
-            checkDistribution(grid(0));
-
-            checkDistribution(grid(1));
-
-            // Check several random keys in cache.
-            Random rnd = new Random();
-
-            IgniteCache<Integer, String> c0 = g0.cache(null);
-
-            for (int i = 0; i < 100; i ++) {
-                Integer k = rnd.nextInt(KEYS_COUNT);
-
-                String v = c0.get(k);
-
-                assertEquals(k.toString(), v);
-            }
-        }
-        finally {
-            G.stopAll(true);
-        }
-    }
-
-    /**
-     * Data streamer should add portable object that weren't registered explicitly.
-     *
-     * @throws Exception If failed.
-     */
-    public void testAddMissingPortable() throws Exception {
-        try {
-            portables = true;
-
-            startGrids(2);
-
-            awaitPartitionMapExchange();
-
-            Ignite g0 = grid(0);
-
-            IgniteDataStreamer<Integer, TestObject2> dataLdr = g0.dataStreamer(null);
-
-            dataLdr.perNodeBufferSize(1);
-            dataLdr.autoFlushFrequency(1L);
-
-            Map<Integer, TestObject2> map = U.newHashMap(KEYS_COUNT);
-
-            for (int i = 0; i < KEYS_COUNT; i ++)
-                map.put(i, new TestObject2(i));
-
-            dataLdr.addData(map).get();
-
-            dataLdr.close();
-        }
-        finally {
-            G.stopAll(true);
-        }
-    }
-
-    /**
-     * Data streamer should correctly load portable entries from HashMap in case of grids with more than one node
-     *  and with GridOptimizedMarshaller that requires serializable.
-     *
-     * @throws Exception If failed.
-     */
-    public void testAddPortableDataFromMap() throws Exception {
-        try {
-            portables = true;
-
-            startGrids(2);
-
-            awaitPartitionMapExchange();
-
-            Ignite g0 = grid(0);
-
-            IgniteDataStreamer<Integer, TestObject> dataLdr = g0.dataStreamer(null);
-
-            Map<Integer, TestObject> map = U.newHashMap(KEYS_COUNT);
-
-            for (int i = 0; i < KEYS_COUNT; i ++)
-                map.put(i, new TestObject(i));
-
-            dataLdr.addData(map);
-
-            dataLdr.close(false);
-
-            checkDistribution(grid(0));
-
-            checkDistribution(grid(1));
-
-            // Read random keys. Take values as TestObject.
-            Random rnd = new Random();
-
-            IgniteCache<Integer, TestObject> c = g0.cache(null);
-
-            for (int i = 0; i < 100; i ++) {
-                Integer k = rnd.nextInt(KEYS_COUNT);
-
-                TestObject v = c.get(k);
-
-                assertEquals(k, v.val());
-            }
-
-            // Read random keys. Take values as PortableObject.
-            IgniteCache<Integer, BinaryObject> c2 = ((IgniteCacheProxy)c).keepPortable();
-
-            for (int i = 0; i < 100; i ++) {
-                Integer k = rnd.nextInt(KEYS_COUNT);
-
-                BinaryObject v = c2.get(k);
-
-                assertEquals(k, v.field("val"));
-            }
-        }
-        finally {
-            G.stopAll(true);
-        }
-    }
-
-    /**
-     * Check that keys correctly destributed by nodes after data streamer.
-     *
-     * @param g Grid to check.
-     */
-    private void checkDistribution(Ignite g) {
-        ClusterNode n = g.cluster().localNode();
-        IgniteCache c = g.cache(null);
-
-        // Check that data streamer correctly split data by nodes.
-        for (int i = 0; i < KEYS_COUNT; i ++) {
-            if (g.affinity(null).isPrimary(n, i))
-                assertNotNull(c.localPeek(i, CachePeekMode.ONHEAP));
-            else
-                assertNull(c.localPeek(i, CachePeekMode.ONHEAP));
-        }
-    }
-
-    /**
-     */
-    private static class TestObject implements Binarylizable, Serializable {
-        /** */
-        private int val;
-
-        /**
-         *
-         */
-        private TestObject() {
-            // No-op.
-        }
-
-        /**
-         * @param val Value.
-         */
-        private TestObject(int val) {
-            this.val = val;
-        }
-
-        public Integer val() {
-            return val;
-        }
-
-        /** {@inheritDoc} */
-        @Override public int hashCode() {
-            return val;
-        }
-
-        /** {@inheritDoc} */
-        @Override public boolean equals(Object obj) {
-            return obj instanceof TestObject && ((TestObject)obj).val == val;
-        }
-
-        /** {@inheritDoc} */
-        @Override public void writeBinary(BinaryWriter writer) throws BinaryObjectException {
-            writer.writeInt("val", val);
-        }
-
-        /** {@inheritDoc} */
-        @Override public void readBinary(BinaryReader reader) throws BinaryObjectException {
-            val = reader.readInt("val");
-        }
-    }
-
-    /**
-     */
-    private static class TestObject2 implements Binarylizable, Serializable {
-        /** */
-        private int val;
-
-        /**
-         */
-        private TestObject2() {
-            // No-op.
-        }
-
-        /**
-         * @param val Value.
-         */
-        private TestObject2(int val) {
-            this.val = val;
-        }
-
-        public Integer val() {
-            return val;
-        }
-
-        /** {@inheritDoc} */
-        @Override public int hashCode() {
-            return val;
-        }
-
-        /** {@inheritDoc} */
-        @Override public boolean equals(Object obj) {
-            return obj instanceof TestObject2 && ((TestObject2)obj).val == val;
-        }
-
-        /** {@inheritDoc} */
-        @Override public void writeBinary(BinaryWriter writer) throws BinaryObjectException {
-            writer.writeInt("val", val);
-        }
-
-        /** {@inheritDoc} */
-        @Override public void readBinary(BinaryReader reader) throws BinaryObjectException {
-            val = reader.readInt("val");
-        }
-    }
-}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ignite/blob/1dbf20e0/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/distributed/dht/GridCacheAffinityRoutingPortableSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/distributed/dht/GridCacheAffinityRoutingPortableSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/distributed/dht/GridCacheAffinityRoutingPortableSelfTest.java
deleted file mode 100644
index edd427f..0000000
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/distributed/dht/GridCacheAffinityRoutingPortableSelfTest.java
+++ /dev/null
@@ -1,54 +0,0 @@
-/*
- * 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.processors.cache.portable.distributed.dht;
-
-import java.util.Collections;
-import org.apache.ignite.cache.CacheKeyConfiguration;
-import org.apache.ignite.configuration.BinaryConfiguration;
-import org.apache.ignite.configuration.IgniteConfiguration;
-import org.apache.ignite.internal.processors.cache.GridCacheAffinityRoutingSelfTest;
-import org.apache.ignite.internal.portable.BinaryMarshaller;
-import org.apache.ignite.binary.BinaryTypeConfiguration;
-
-/**
- *
- */
-public class GridCacheAffinityRoutingPortableSelfTest extends GridCacheAffinityRoutingSelfTest {
-    /** {@inheritDoc} */
-    @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception {
-        IgniteConfiguration cfg = super.getConfiguration(gridName);
-
-        BinaryTypeConfiguration typeCfg = new BinaryTypeConfiguration();
-
-        typeCfg.setTypeName(AffinityTestKey.class.getName());
-
-        CacheKeyConfiguration keyCfg = new CacheKeyConfiguration(AffinityTestKey.class.getName(), "affKey");
-
-        cfg.setCacheKeyConfiguration(keyCfg);
-
-        BinaryConfiguration bCfg = new BinaryConfiguration();
-
-        bCfg.setTypeConfigurations(Collections.singleton(typeCfg));
-
-        cfg.setBinaryConfiguration(bCfg);
-
-        cfg.setMarshaller(new BinaryMarshaller());
-
-        return cfg;
-    }
-}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ignite/blob/1dbf20e0/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/distributed/dht/GridCacheAtomicPartitionedOnlyPortableDataStreamerMultiNodeSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/distributed/dht/GridCacheAtomicPartitionedOnlyPortableDataStreamerMultiNodeSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/distributed/dht/GridCacheAtomicPartitionedOnlyPortableDataStreamerMultiNodeSelfTest.java
deleted file mode 100644
index b3b988e..0000000
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/distributed/dht/GridCacheAtomicPartitionedOnlyPortableDataStreamerMultiNodeSelfTest.java
+++ /dev/null
@@ -1,29 +0,0 @@
-/*
- * 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.processors.cache.portable.distributed.dht;
-
-/**
- *
- */
-public class GridCacheAtomicPartitionedOnlyPortableDataStreamerMultiNodeSelfTest extends
-    GridCacheAtomicPartitionedOnlyPortableDataStreamerMultithreadedSelfTest {
-    /** {@inheritDoc} */
-    @Override protected int gridCount() {
-        return 4;
-    }
-}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ignite/blob/1dbf20e0/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/distributed/dht/GridCacheAtomicPartitionedOnlyPortableDataStreamerMultithreadedSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/distributed/dht/GridCacheAtomicPartitionedOnlyPortableDataStreamerMultithreadedSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/distributed/dht/GridCacheAtomicPartitionedOnlyPortableDataStreamerMultithreadedSelfTest.java
deleted file mode 100644
index ee95194..0000000
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/distributed/dht/GridCacheAtomicPartitionedOnlyPortableDataStreamerMultithreadedSelfTest.java
+++ /dev/null
@@ -1,47 +0,0 @@
-/*
- * 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.processors.cache.portable.distributed.dht;
-
-import org.apache.ignite.cache.CacheAtomicityMode;
-import org.apache.ignite.cache.CacheMode;
-import org.apache.ignite.configuration.NearCacheConfiguration;
-import org.apache.ignite.internal.processors.cache.portable.GridCacheBinaryObjectsAbstractDataStreamerSelfTest;
-
-import static org.apache.ignite.cache.CacheAtomicityMode.ATOMIC;
-import static org.apache.ignite.cache.CacheMode.PARTITIONED;
-
-/**
- *
- */
-public class GridCacheAtomicPartitionedOnlyPortableDataStreamerMultithreadedSelfTest extends
-    GridCacheBinaryObjectsAbstractDataStreamerSelfTest {
-    /** {@inheritDoc} */
-    @Override protected CacheMode cacheMode() {
-        return PARTITIONED;
-    }
-
-    /** {@inheritDoc} */
-    @Override protected CacheAtomicityMode atomicityMode() {
-        return ATOMIC;
-    }
-
-    /** {@inheritDoc} */
-    @Override protected NearCacheConfiguration nearConfiguration() {
-        return null;
-    }
-}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ignite/blob/1dbf20e0/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/distributed/dht/GridCacheAtomicPartitionedOnlyPortableMultiNodeSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/distributed/dht/GridCacheAtomicPartitionedOnlyPortableMultiNodeSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/distributed/dht/GridCacheAtomicPartitionedOnlyPortableMultiNodeSelfTest.java
deleted file mode 100644
index a53a5ea..0000000
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/distributed/dht/GridCacheAtomicPartitionedOnlyPortableMultiNodeSelfTest.java
+++ /dev/null
@@ -1,28 +0,0 @@
-/*
- * 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.processors.cache.portable.distributed.dht;
-
-/**
- *
- */
-public class GridCacheAtomicPartitionedOnlyPortableMultiNodeSelfTest extends
-    GridCacheAtomicPartitionedOnlyPortableMultithreadedSelfTest {
-    /** {@inheritDoc} */
-    @Override protected int gridCount() {
-        return 4;
-    }
-}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ignite/blob/1dbf20e0/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/distributed/dht/GridCacheAtomicPartitionedOnlyPortableMultithreadedSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/distributed/dht/GridCacheAtomicPartitionedOnlyPortableMultithreadedSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/distributed/dht/GridCacheAtomicPartitionedOnlyPortableMultithreadedSelfTest.java
deleted file mode 100644
index 7fb63db..0000000
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/distributed/dht/GridCacheAtomicPartitionedOnlyPortableMultithreadedSelfTest.java
+++ /dev/null
@@ -1,47 +0,0 @@
-/*
- * 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.processors.cache.portable.distributed.dht;
-
-import org.apache.ignite.cache.CacheAtomicityMode;
-import org.apache.ignite.cache.CacheMode;
-import org.apache.ignite.configuration.NearCacheConfiguration;
-import org.apache.ignite.internal.processors.cache.portable.GridCacheBinaryObjectsAbstractMultiThreadedSelfTest;
-
-import static org.apache.ignite.cache.CacheAtomicityMode.ATOMIC;
-import static org.apache.ignite.cache.CacheMode.PARTITIONED;
-
-/**
- *
- */
-public class GridCacheAtomicPartitionedOnlyPortableMultithreadedSelfTest extends
-    GridCacheBinaryObjectsAbstractMultiThreadedSelfTest {
-    /** {@inheritDoc} */
-    @Override protected CacheMode cacheMode() {
-        return PARTITIONED;
-    }
-
-    /** {@inheritDoc} */
-    @Override protected CacheAtomicityMode atomicityMode() {
-        return ATOMIC;
-    }
-
-    /** {@inheritDoc} */
-    @Override protected NearCacheConfiguration nearConfiguration() {
-        return null;
-    }
-}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ignite/blob/1dbf20e0/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/distributed/dht/GridCacheBinaryObjectsAtomicNearDisabledOffheapTieredSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/distributed/dht/GridCacheBinaryObjectsAtomicNearDisabledOffheapTieredSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/distributed/dht/GridCacheBinaryObjectsAtomicNearDisabledOffheapTieredSelfTest.java
deleted file mode 100644
index 79c69c4..0000000
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/distributed/dht/GridCacheBinaryObjectsAtomicNearDisabledOffheapTieredSelfTest.java
+++ /dev/null
@@ -1,29 +0,0 @@
-/*
- * 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.processors.cache.portable.distributed.dht;
-
-/**
- *
- */
-public class GridCacheBinaryObjectsAtomicNearDisabledOffheapTieredSelfTest
-    extends GridCacheBinaryObjectsAtomicNearDisabledSelfTest {
-    /** {@inheritDoc} */
-    @Override protected boolean offheapTiered() {
-        return true;
-    }
-}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ignite/blob/1dbf20e0/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/distributed/dht/GridCacheBinaryObjectsAtomicNearDisabledSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/distributed/dht/GridCacheBinaryObjectsAtomicNearDisabledSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/distributed/dht/GridCacheBinaryObjectsAtomicNearDisabledSelfTest.java
deleted file mode 100644
index fe46dea..0000000
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/distributed/dht/GridCacheBinaryObjectsAtomicNearDisabledSelfTest.java
+++ /dev/null
@@ -1,51 +0,0 @@
-/*
- * 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.processors.cache.portable.distributed.dht;
-
-import org.apache.ignite.cache.CacheAtomicityMode;
-import org.apache.ignite.cache.CacheMode;
-import org.apache.ignite.configuration.NearCacheConfiguration;
-import org.apache.ignite.internal.processors.cache.portable.GridCacheBinaryObjectsAbstractSelfTest;
-
-import static org.apache.ignite.cache.CacheAtomicityMode.ATOMIC;
-import static org.apache.ignite.cache.CacheMode.PARTITIONED;
-
-/**
- * Test for portable objects stored in cache.
- */
-public class GridCacheBinaryObjectsAtomicNearDisabledSelfTest extends GridCacheBinaryObjectsAbstractSelfTest {
-    /** {@inheritDoc} */
-    @Override protected CacheMode cacheMode() {
-        return PARTITIONED;
-    }
-
-    /** {@inheritDoc} */
-    @Override protected CacheAtomicityMode atomicityMode() {
-        return ATOMIC;
-    }
-
-    /** {@inheritDoc} */
-    @Override protected NearCacheConfiguration nearConfiguration() {
-        return null;
-    }
-
-    /** {@inheritDoc} */
-    @Override protected int gridCount() {
-        return 3;
-    }
-}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ignite/blob/1dbf20e0/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/distributed/dht/GridCacheBinaryObjectsAtomicOffheapTieredSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/distributed/dht/GridCacheBinaryObjectsAtomicOffheapTieredSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/distributed/dht/GridCacheBinaryObjectsAtomicOffheapTieredSelfTest.java
deleted file mode 100644
index d692624..0000000
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/distributed/dht/GridCacheBinaryObjectsAtomicOffheapTieredSelfTest.java
+++ /dev/null
@@ -1,29 +0,0 @@
-/*
- * 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.processors.cache.portable.distributed.dht;
-
-/**
- *
- */
-public class GridCacheBinaryObjectsAtomicOffheapTieredSelfTest extends GridCacheBinaryObjectsAtomicSelfTest {
-    /** {@inheritDoc} */
-    @Override protected boolean offheapTiered() {
-        return true;
-    }
-}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ignite/blob/1dbf20e0/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/distributed/dht/GridCacheBinaryObjectsAtomicSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/distributed/dht/GridCacheBinaryObjectsAtomicSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/distributed/dht/GridCacheBinaryObjectsAtomicSelfTest.java
deleted file mode 100644
index 097d51b..0000000
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/distributed/dht/GridCacheBinaryObjectsAtomicSelfTest.java
+++ /dev/null
@@ -1,51 +0,0 @@
-/*
- * 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.processors.cache.portable.distributed.dht;
-
-import org.apache.ignite.cache.CacheAtomicityMode;
-import org.apache.ignite.cache.CacheMode;
-import org.apache.ignite.configuration.NearCacheConfiguration;
-import org.apache.ignite.internal.processors.cache.portable.GridCacheBinaryObjectsAbstractSelfTest;
-
-import static org.apache.ignite.cache.CacheAtomicityMode.ATOMIC;
-import static org.apache.ignite.cache.CacheMode.PARTITIONED;
-
-/**
- * Test for portable objects stored in cache.
- */
-public class GridCacheBinaryObjectsAtomicSelfTest extends GridCacheBinaryObjectsAbstractSelfTest {
-    /** {@inheritDoc} */
-    @Override protected CacheMode cacheMode() {
-        return PARTITIONED;
-    }
-
-    /** {@inheritDoc} */
-    @Override protected CacheAtomicityMode atomicityMode() {
-        return ATOMIC;
-    }
-
-    /** {@inheritDoc} */
-    @Override protected NearCacheConfiguration nearConfiguration() {
-        return new NearCacheConfiguration();
-    }
-
-    /** {@inheritDoc} */
-    @Override protected int gridCount() {
-        return 3;
-    }
-}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ignite/blob/1dbf20e0/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/distributed/dht/GridCacheBinaryObjectsPartitionedNearDisabledOffheapTieredSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/distributed/dht/GridCacheBinaryObjectsPartitionedNearDisabledOffheapTieredSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/distributed/dht/GridCacheBinaryObjectsPartitionedNearDisabledOffheapTieredSelfTest.java
deleted file mode 100644
index fde8233..0000000
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/distributed/dht/GridCacheBinaryObjectsPartitionedNearDisabledOffheapTieredSelfTest.java
+++ /dev/null
@@ -1,30 +0,0 @@
-/*
- * 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.processors.cache.portable.distributed.dht;
-
-/**
- *
- */
-public class GridCacheBinaryObjectsPartitionedNearDisabledOffheapTieredSelfTest
-    extends GridCacheBinaryObjectsPartitionedNearDisabledSelfTest {
-    /** {@inheritDoc} */
-    @Override protected boolean offheapTiered() {
-        return true;
-    }
-}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ignite/blob/1dbf20e0/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/distributed/dht/GridCacheBinaryObjectsPartitionedNearDisabledSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/distributed/dht/GridCacheBinaryObjectsPartitionedNearDisabledSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/distributed/dht/GridCacheBinaryObjectsPartitionedNearDisabledSelfTest.java
deleted file mode 100644
index e916a55..0000000
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/distributed/dht/GridCacheBinaryObjectsPartitionedNearDisabledSelfTest.java
+++ /dev/null
@@ -1,51 +0,0 @@
-/*
- * 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.processors.cache.portable.distributed.dht;
-
-import org.apache.ignite.cache.CacheAtomicityMode;
-import org.apache.ignite.cache.CacheMode;
-import org.apache.ignite.configuration.NearCacheConfiguration;
-import org.apache.ignite.internal.processors.cache.portable.GridCacheBinaryObjectsAbstractSelfTest;
-
-import static org.apache.ignite.cache.CacheAtomicityMode.TRANSACTIONAL;
-import static org.apache.ignite.cache.CacheMode.PARTITIONED;
-
-/**
- * Test for portable objects stored in cache.
- */
-public class GridCacheBinaryObjectsPartitionedNearDisabledSelfTest extends GridCacheBinaryObjectsAbstractSelfTest {
-    /** {@inheritDoc} */
-    @Override protected CacheMode cacheMode() {
-        return PARTITIONED;
-    }
-
-    /** {@inheritDoc} */
-    @Override protected CacheAtomicityMode atomicityMode() {
-        return TRANSACTIONAL;
-    }
-
-    /** {@inheritDoc} */
-    @Override protected NearCacheConfiguration nearConfiguration() {
-        return null;
-    }
-
-    /** {@inheritDoc} */
-    @Override protected int gridCount() {
-        return 3;
-    }
-}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ignite/blob/1dbf20e0/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/distributed/dht/GridCacheBinaryObjectsPartitionedOffheapTieredSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/distributed/dht/GridCacheBinaryObjectsPartitionedOffheapTieredSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/distributed/dht/GridCacheBinaryObjectsPartitionedOffheapTieredSelfTest.java
deleted file mode 100644
index c6684d8..0000000
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/distributed/dht/GridCacheBinaryObjectsPartitionedOffheapTieredSelfTest.java
+++ /dev/null
@@ -1,30 +0,0 @@
-/*
- * 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.processors.cache.portable.distributed.dht;
-
-/**
- *
- */
-public class GridCacheBinaryObjectsPartitionedOffheapTieredSelfTest
-    extends GridCacheBinaryObjectsPartitionedSelfTest {
-    /** {@inheritDoc} */
-    @Override protected boolean offheapTiered() {
-        return true;
-    }
-}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ignite/blob/1dbf20e0/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/distributed/dht/GridCacheBinaryObjectsPartitionedSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/distributed/dht/GridCacheBinaryObjectsPartitionedSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/distributed/dht/GridCacheBinaryObjectsPartitionedSelfTest.java
deleted file mode 100644
index 80a13ec..0000000
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/distributed/dht/GridCacheBinaryObjectsPartitionedSelfTest.java
+++ /dev/null
@@ -1,51 +0,0 @@
-/*
- * 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.processors.cache.portable.distributed.dht;
-
-import org.apache.ignite.cache.CacheAtomicityMode;
-import org.apache.ignite.cache.CacheMode;
-import org.apache.ignite.configuration.NearCacheConfiguration;
-import org.apache.ignite.internal.processors.cache.portable.GridCacheBinaryObjectsAbstractSelfTest;
-
-import static org.apache.ignite.cache.CacheAtomicityMode.TRANSACTIONAL;
-import static org.apache.ignite.cache.CacheMode.PARTITIONED;
-
-/**
- * Test for portable objects stored in cache.
- */
-public class GridCacheBinaryObjectsPartitionedSelfTest extends GridCacheBinaryObjectsAbstractSelfTest {
-    /** {@inheritDoc} */
-    @Override protected CacheMode cacheMode() {
-        return PARTITIONED;
-    }
-
-    /** {@inheritDoc} */
-    @Override protected CacheAtomicityMode atomicityMode() {
-        return TRANSACTIONAL;
-    }
-
-    /** {@inheritDoc} */
-    @Override protected NearCacheConfiguration nearConfiguration() {
-        return new NearCacheConfiguration();
-    }
-
-    /** {@inheritDoc} */
-    @Override protected int gridCount() {
-        return 3;
-    }
-}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ignite/blob/1dbf20e0/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/distributed/dht/GridCacheMemoryModePortableSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/distributed/dht/GridCacheMemoryModePortableSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/distributed/dht/GridCacheMemoryModePortableSelfTest.java
deleted file mode 100644
index 71cf106..0000000
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/distributed/dht/GridCacheMemoryModePortableSelfTest.java
+++ /dev/null
@@ -1,36 +0,0 @@
-/*
- * 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.processors.cache.portable.distributed.dht;
-
-import org.apache.ignite.configuration.IgniteConfiguration;
-import org.apache.ignite.internal.processors.cache.GridCacheMemoryModeSelfTest;
-import org.apache.ignite.internal.portable.BinaryMarshaller;
-
-/**
- * Memory models test.
- */
-public class GridCacheMemoryModePortableSelfTest extends GridCacheMemoryModeSelfTest {
-    /** {@inheritDoc} */
-    @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception {
-        IgniteConfiguration cfg = super.getConfiguration(gridName);
-
-        cfg.setMarshaller(new BinaryMarshaller());
-
-        return cfg;
-    }
-}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ignite/blob/1dbf20e0/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/distributed/dht/GridCacheOffHeapTieredAtomicPortableSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/distributed/dht/GridCacheOffHeapTieredAtomicPortableSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/distributed/dht/GridCacheOffHeapTieredAtomicPortableSelfTest.java
deleted file mode 100644
index 80353c7..0000000
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/distributed/dht/GridCacheOffHeapTieredAtomicPortableSelfTest.java
+++ /dev/null
@@ -1,48 +0,0 @@
-/*
- * 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.processors.cache.portable.distributed.dht;
-
-import java.util.Arrays;
-import org.apache.ignite.configuration.BinaryConfiguration;
-import org.apache.ignite.configuration.IgniteConfiguration;
-import org.apache.ignite.internal.processors.cache.GridCacheOffHeapTieredAtomicSelfTest;
-import org.apache.ignite.internal.portable.BinaryMarshaller;
-
-/**
- *
- */
-public class GridCacheOffHeapTieredAtomicPortableSelfTest extends GridCacheOffHeapTieredAtomicSelfTest {
-    /** {@inheritDoc} */
-    @Override protected boolean portableEnabled() {
-        return true;
-    }
-
-    /** {@inheritDoc} */
-    @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception {
-        // Enable binary.
-        IgniteConfiguration cfg = super.getConfiguration(gridName);
-
-        BinaryConfiguration bCfg = new BinaryConfiguration();
-
-        bCfg.setClassNames(Arrays.asList(TestValue.class.getName()));
-
-        cfg.setMarshaller(new BinaryMarshaller());
-
-        return cfg;
-    }
-}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ignite/blob/1dbf20e0/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/distributed/dht/GridCacheOffHeapTieredEvictionAtomicPortableSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/distributed/dht/GridCacheOffHeapTieredEvictionAtomicPortableSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/distributed/dht/GridCacheOffHeapTieredEvictionAtomicPortableSelfTest.java
deleted file mode 100644
index a8c87ea..0000000
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/distributed/dht/GridCacheOffHeapTieredEvictionAtomicPortableSelfTest.java
+++ /dev/null
@@ -1,96 +0,0 @@
-/*
- * 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.processors.cache.portable.distributed.dht;
-
-import java.util.Arrays;
-import org.apache.ignite.configuration.BinaryConfiguration;
-import org.apache.ignite.configuration.IgniteConfiguration;
-import org.apache.ignite.internal.processors.cache.GridCacheOffHeapTieredEvictionAtomicSelfTest;
-import org.apache.ignite.internal.portable.BinaryMarshaller;
-import org.apache.ignite.binary.BinaryObject;
-
-/**
- *
- */
-public class GridCacheOffHeapTieredEvictionAtomicPortableSelfTest extends GridCacheOffHeapTieredEvictionAtomicSelfTest {
-    /** {@inheritDoc} */
-    @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception {
-        // Enable binary.
-        IgniteConfiguration cfg = super.getConfiguration(gridName);
-
-        BinaryConfiguration bCfg = new BinaryConfiguration();
-
-        bCfg.setClassNames(Arrays.asList(TestValue.class.getName()));
-
-        cfg.setMarshaller(new BinaryMarshaller());
-
-        return cfg;
-    }
-
-    /** {@inheritDoc} */
-    @Override protected TestPredicate testPredicate(String expVal, boolean acceptNull) {
-        return new PortableValuePredicate(expVal, acceptNull);
-    }
-
-    /** {@inheritDoc} */
-    @Override protected TestProcessor testClosure(String expVal, boolean acceptNull) {
-        return new PortableValueClosure(expVal, acceptNull);
-    }
-
-    /**
-     *
-     */
-    @SuppressWarnings("PackageVisibleInnerClass")
-    static class PortableValuePredicate extends TestPredicate {
-        /**
-         * @param expVal Expected value.
-         * @param acceptNull If {@code true} value can be null;
-         */
-        PortableValuePredicate(String expVal, boolean acceptNull) {
-            super(expVal, acceptNull);
-        }
-
-        /** {@inheritDoc} */
-        @Override public void checkValue(Object val) {
-            BinaryObject obj = (BinaryObject)val;
-
-            assertEquals(expVal, obj.field("val"));
-        }
-    }
-
-    /**
-     *
-     */
-    @SuppressWarnings("PackageVisibleInnerClass")
-    static class PortableValueClosure extends TestProcessor {
-        /**
-         * @param expVal Expected value.
-         * @param acceptNull If {@code true} value can be null;
-         */
-        PortableValueClosure(String expVal, boolean acceptNull) {
-            super(expVal, acceptNull);
-        }
-
-        /** {@inheritDoc} */
-        @Override public void checkValue(Object val) {
-            BinaryObject obj = (BinaryObject)val;
-
-            assertEquals(expVal, obj.field("val"));
-        }
-    }
-}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ignite/blob/1dbf20e0/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/distributed/dht/GridCacheOffHeapTieredEvictionPortableSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/distributed/dht/GridCacheOffHeapTieredEvictionPortableSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/distributed/dht/GridCacheOffHeapTieredEvictionPortableSelfTest.java
deleted file mode 100644
index 0665f20..0000000
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/distributed/dht/GridCacheOffHeapTieredEvictionPortableSelfTest.java
+++ /dev/null
@@ -1,96 +0,0 @@
-/*
- * 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.processors.cache.portable.distributed.dht;
-
-import java.util.Arrays;
-import org.apache.ignite.configuration.BinaryConfiguration;
-import org.apache.ignite.configuration.IgniteConfiguration;
-import org.apache.ignite.internal.processors.cache.GridCacheOffHeapTieredEvictionSelfTest;
-import org.apache.ignite.internal.portable.BinaryMarshaller;
-import org.apache.ignite.binary.BinaryObject;
-
-/**
- *
- */
-public class GridCacheOffHeapTieredEvictionPortableSelfTest extends GridCacheOffHeapTieredEvictionSelfTest {
-    /** {@inheritDoc} */
-    @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception {
-        // Enable binary.
-        IgniteConfiguration cfg = super.getConfiguration(gridName);
-
-        BinaryConfiguration bCfg = new BinaryConfiguration();
-
-        bCfg.setClassNames(Arrays.asList(TestValue.class.getName()));
-
-        cfg.setMarshaller(new BinaryMarshaller());
-
-        return cfg;
-    }
-
-    /** {@inheritDoc} */
-    @Override protected TestPredicate testPredicate(String expVal, boolean acceptNull) {
-        return new PortableValuePredicate(expVal, acceptNull);
-    }
-
-    /** {@inheritDoc} */
-    @Override protected TestProcessor testClosure(String expVal, boolean acceptNull) {
-        return new PortableValueClosure(expVal, acceptNull);
-    }
-
-    /**
-     *
-     */
-    @SuppressWarnings("PackageVisibleInnerClass")
-    static class PortableValuePredicate extends TestPredicate {
-        /**
-         * @param expVal Expected value.
-         * @param acceptNull If {@code true} value can be null;
-         */
-        PortableValuePredicate(String expVal, boolean acceptNull) {
-            super(expVal, acceptNull);
-        }
-
-        /** {@inheritDoc} */
-        @Override public void checkValue(Object val) {
-            BinaryObject obj = (BinaryObject)val;
-
-            assertEquals(expVal, obj.field("val"));
-        }
-    }
-
-    /**
-     *
-     */
-    @SuppressWarnings("PackageVisibleInnerClass")
-    static class PortableValueClosure extends TestProcessor {
-        /**
-         * @param expVal Expected value.
-         * @param acceptNull If {@code true} value can be null;
-         */
-        PortableValueClosure(String expVal, boolean acceptNull) {
-            super(expVal, acceptNull);
-        }
-
-        /** {@inheritDoc} */
-        @Override public void checkValue(Object val) {
-            BinaryObject obj = (BinaryObject)val;
-
-            assertEquals(expVal, obj.field("val"));
-        }
-    }
-}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ignite/blob/1dbf20e0/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/distributed/dht/GridCacheOffHeapTieredPortableSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/distributed/dht/GridCacheOffHeapTieredPortableSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/distributed/dht/GridCacheOffHeapTieredPortableSelfTest.java
deleted file mode 100644
index 8ab7f42..0000000
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/distributed/dht/GridCacheOffHeapTieredPortableSelfTest.java
+++ /dev/null
@@ -1,48 +0,0 @@
-/*
- * 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.processors.cache.portable.distributed.dht;
-
-import java.util.Arrays;
-import org.apache.ignite.configuration.BinaryConfiguration;
-import org.apache.ignite.configuration.IgniteConfiguration;
-import org.apache.ignite.internal.processors.cache.GridCacheOffHeapTieredSelfTest;
-import org.apache.ignite.internal.portable.BinaryMarshaller;
-
-/**
- *
- */
-public class GridCacheOffHeapTieredPortableSelfTest extends GridCacheOffHeapTieredSelfTest {
-    /** {@inheritDoc} */
-    @Override protected boolean portableEnabled() {
-        return true;
-    }
-
-    /** {@inheritDoc} */
-    @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception {
-        // Enable binary.
-        IgniteConfiguration cfg = super.getConfiguration(gridName);
-
-        BinaryConfiguration bCfg = new BinaryConfiguration();
-
-        bCfg.setClassNames(Arrays.asList(TestValue.class.getName()));
-
-        cfg.setMarshaller(new BinaryMarshaller());
-
-        return cfg;
-    }
-}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ignite/blob/1dbf20e0/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/distributed/dht/GridCachePortableDuplicateIndexObjectPartitionedAtomicSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/distributed/dht/GridCachePortableDuplicateIndexObjectPartitionedAtomicSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/distributed/dht/GridCachePortableDuplicateIndexObjectPartitionedAtomicSelfTest.java
deleted file mode 100644
index e6f7499..0000000
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/distributed/dht/GridCachePortableDuplicateIndexObjectPartitionedAtomicSelfTest.java
+++ /dev/null
@@ -1,38 +0,0 @@
-/*
- * 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.processors.cache.portable.distributed.dht;
-
-import org.apache.ignite.cache.CacheAtomicityMode;
-import org.apache.ignite.cache.CacheMode;
-import org.apache.ignite.internal.processors.cache.portable.GridPortableDuplicateIndexObjectsAbstractSelfTest;
-
-/**
- * Test PARTITIONED ATOMIC.
- */
-public class GridCachePortableDuplicateIndexObjectPartitionedAtomicSelfTest extends
-    GridPortableDuplicateIndexObjectsAbstractSelfTest {
-    /** {@inheritDoc} */
-    @Override public CacheAtomicityMode atomicityMode() {
-        return CacheAtomicityMode.ATOMIC;
-    }
-
-    /** {@inheritDoc} */
-    @Override public CacheMode cacheMode() {
-        return CacheMode.PARTITIONED;
-    }
-}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ignite/blob/1dbf20e0/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/distributed/dht/GridCachePortableDuplicateIndexObjectPartitionedTransactionalSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/distributed/dht/GridCachePortableDuplicateIndexObjectPartitionedTransactionalSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/distributed/dht/GridCachePortableDuplicateIndexObjectPartitionedTransactionalSelfTest.java
deleted file mode 100644
index b5dc4e9..0000000
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/distributed/dht/GridCachePortableDuplicateIndexObjectPartitionedTransactionalSelfTest.java
+++ /dev/null
@@ -1,41 +0,0 @@
-/*
- * 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.processors.cache.portable.distributed.dht;
-
-import org.apache.ignite.cache.CacheAtomicityMode;
-import org.apache.ignite.cache.CacheMode;
-import org.apache.ignite.internal.processors.cache.portable.GridPortableDuplicateIndexObjectsAbstractSelfTest;
-
-import static org.apache.ignite.cache.CacheAtomicityMode.TRANSACTIONAL;
-import static org.apache.ignite.cache.CacheMode.PARTITIONED;
-
-/**
- * Test PARTITIONED and TRANSACTIONAL.
- */
-public class GridCachePortableDuplicateIndexObjectPartitionedTransactionalSelfTest extends
-    GridPortableDuplicateIndexObjectsAbstractSelfTest {
-    /** {@inheritDoc} */
-    @Override public CacheAtomicityMode atomicityMode() {
-        return TRANSACTIONAL;
-    }
-
-    /** {@inheritDoc} */
-    @Override public CacheMode cacheMode() {
-        return PARTITIONED;
-    }
-}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ignite/blob/1dbf20e0/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/distributed/dht/GridCachePortablesNearPartitionedByteArrayValuesSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/distributed/dht/GridCachePortablesNearPartitionedByteArrayValuesSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/distributed/dht/GridCachePortablesNearPartitionedByteArrayValuesSelfTest.java
deleted file mode 100644
index ce3a9e1..0000000
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/distributed/dht/GridCachePortablesNearPartitionedByteArrayValuesSelfTest.java
+++ /dev/null
@@ -1,41 +0,0 @@
-/*
- * 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.processors.cache.portable.distributed.dht;
-
-import org.apache.ignite.configuration.IgniteConfiguration;
-import org.apache.ignite.internal.processors.cache.distributed.near.GridCacheAbstractNearPartitionedByteArrayValuesSelfTest;
-import org.apache.ignite.internal.portable.BinaryMarshaller;
-
-/**
- *
- */
-public class GridCachePortablesNearPartitionedByteArrayValuesSelfTest
-    extends GridCacheAbstractNearPartitionedByteArrayValuesSelfTest {
-    /** {@inheritDoc} */
-    @Override protected boolean peerClassLoading() {
-        return false;
-    }
-
-    /** {@inheritDoc} */
-    @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception {
-        IgniteConfiguration cfg = super.getConfiguration(gridName);
-
-        cfg.setMarshaller(new BinaryMarshaller());
-
-        return cfg;
-    }
-}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ignite/blob/1dbf20e0/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/distributed/dht/GridCachePortablesPartitionedOnlyByteArrayValuesSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/distributed/dht/GridCachePortablesPartitionedOnlyByteArrayValuesSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/distributed/dht/GridCachePortablesPartitionedOnlyByteArrayValuesSelfTest.java
deleted file mode 100644
index e20166e..0000000
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/distributed/dht/GridCachePortablesPartitionedOnlyByteArrayValuesSelfTest.java
+++ /dev/null
@@ -1,42 +0,0 @@
-/*
- * 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.processors.cache.portable.distributed.dht;
-
-import org.apache.ignite.configuration.IgniteConfiguration;
-import org.apache.ignite.internal.processors.cache.distributed.dht.GridCacheAbstractPartitionedOnlyByteArrayValuesSelfTest;
-import org.apache.ignite.internal.portable.BinaryMarshaller;
-
-/**
- *
- */
-public class GridCachePortablesPartitionedOnlyByteArrayValuesSelfTest
-    extends GridCacheAbstractPartitionedOnlyByteArrayValuesSelfTest {
-    /** {@inheritDoc} */
-    @Override protected boolean peerClassLoading() {
-        return false;
-    }
-
-    /** {@inheritDoc} */
-    @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception {
-        IgniteConfiguration cfg = super.getConfiguration(gridName);
-
-        cfg.setMarshaller(new BinaryMarshaller());
-
-        return cfg;
-    }
-}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ignite/blob/1dbf20e0/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/distributed/replicated/GridCacheBinaryObjectsReplicatedSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/distributed/replicated/GridCacheBinaryObjectsReplicatedSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/distributed/replicated/GridCacheBinaryObjectsReplicatedSelfTest.java
deleted file mode 100644
index 0c2734e..0000000
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/distributed/replicated/GridCacheBinaryObjectsReplicatedSelfTest.java
+++ /dev/null
@@ -1,51 +0,0 @@
-/*
- * 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.processors.cache.portable.distributed.replicated;
-
-import org.apache.ignite.cache.CacheAtomicityMode;
-import org.apache.ignite.cache.CacheMode;
-import org.apache.ignite.configuration.NearCacheConfiguration;
-import org.apache.ignite.internal.processors.cache.portable.GridCacheBinaryObjectsAbstractSelfTest;
-
-import static org.apache.ignite.cache.CacheAtomicityMode.TRANSACTIONAL;
-import static org.apache.ignite.cache.CacheMode.REPLICATED;
-
-/**
- * Test for portable objects stored in cache.
- */
-public class GridCacheBinaryObjectsReplicatedSelfTest extends GridCacheBinaryObjectsAbstractSelfTest {
-    /** {@inheritDoc} */
-    @Override protected CacheMode cacheMode() {
-        return REPLICATED;
-    }
-
-    /** {@inheritDoc} */
-    @Override protected CacheAtomicityMode atomicityMode() {
-        return TRANSACTIONAL;
-    }
-
-    /** {@inheritDoc} */
-    @Override protected NearCacheConfiguration nearConfiguration() {
-        return null;
-    }
-
-    /** {@inheritDoc} */
-    @Override protected int gridCount() {
-        return 3;
-    }
-}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ignite/blob/1dbf20e0/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/local/GridCacheBinaryObjectsAtomicLocalSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/local/GridCacheBinaryObjectsAtomicLocalSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/local/GridCacheBinaryObjectsAtomicLocalSelfTest.java
deleted file mode 100644
index 19321fb..0000000
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/local/GridCacheBinaryObjectsAtomicLocalSelfTest.java
+++ /dev/null
@@ -1,32 +0,0 @@
-/*
- * 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.processors.cache.portable.local;
-
-import org.apache.ignite.cache.CacheAtomicityMode;
-
-import static org.apache.ignite.cache.CacheAtomicityMode.ATOMIC;
-
-/**
- *
- */
-public class GridCacheBinaryObjectsAtomicLocalSelfTest extends GridCacheBinaryObjectsLocalSelfTest {
-    /** {@inheritDoc} */
-    @Override protected CacheAtomicityMode atomicityMode() {
-        return ATOMIC;
-    }
-}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ignite/blob/1dbf20e0/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/local/GridCacheBinaryObjectsLocalOffheapTieredSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/local/GridCacheBinaryObjectsLocalOffheapTieredSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/local/GridCacheBinaryObjectsLocalOffheapTieredSelfTest.java
deleted file mode 100644
index 4801fa5..0000000
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/local/GridCacheBinaryObjectsLocalOffheapTieredSelfTest.java
+++ /dev/null
@@ -1,29 +0,0 @@
-/*
- * 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.processors.cache.portable.local;
-
-/**
- *
- */
-public class GridCacheBinaryObjectsLocalOffheapTieredSelfTest extends GridCacheBinaryObjectsLocalSelfTest {
-    /** {@inheritDoc} */
-    @Override protected boolean offheapTiered() {
-        return true;
-    }
-}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ignite/blob/1dbf20e0/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/local/GridCacheBinaryObjectsLocalSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/local/GridCacheBinaryObjectsLocalSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/local/GridCacheBinaryObjectsLocalSelfTest.java
deleted file mode 100644
index 21053d7..0000000
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/local/GridCacheBinaryObjectsLocalSelfTest.java
+++ /dev/null
@@ -1,51 +0,0 @@
-/*
- * 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.processors.cache.portable.local;
-
-import org.apache.ignite.cache.CacheAtomicityMode;
-import org.apache.ignite.cache.CacheMode;
-import org.apache.ignite.configuration.NearCacheConfiguration;
-import org.apache.ignite.internal.processors.cache.portable.GridCacheBinaryObjectsAbstractSelfTest;
-
-import static org.apache.ignite.cache.CacheAtomicityMode.TRANSACTIONAL;
-import static org.apache.ignite.cache.CacheMode.LOCAL;
-
-/**
- * Test for portable objects stored in cache.
- */
-public class GridCacheBinaryObjectsLocalSelfTest extends GridCacheBinaryObjectsAbstractSelfTest {
-    /** {@inheritDoc} */
-    @Override protected CacheMode cacheMode() {
-        return LOCAL;
-    }
-
-    /** {@inheritDoc} */
-    @Override protected CacheAtomicityMode atomicityMode() {
-        return TRANSACTIONAL;
-    }
-
-    /** {@inheritDoc} */
-    @Override protected NearCacheConfiguration nearConfiguration() {
-        return null;
-    }
-
-    /** {@inheritDoc} */
-    @Override protected int gridCount() {
-        return 1;
-    }
-}
\ No newline at end of file


[07/59] [abbrv] ignite git commit: ignite-2065: rename "portable" packages to "binary"

Posted by ak...@apache.org.
http://git-wip-us.apache.org/repos/asf/ignite/blob/1dbf20e0/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
deleted file mode 100644
index 06535d2..0000000
--- a/modules/core/src/test/java/org/apache/ignite/internal/portable/BinaryObjectBuilderAdditionalSelfTest.java
+++ /dev/null
@@ -1,1272 +0,0 @@
-/*
- * 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.portable;
-
-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;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collections;
-import java.util.Date;
-import java.util.HashSet;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.Map;
-import java.util.Objects;
-import java.util.Set;
-import java.util.UUID;
-
-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.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;
-import static org.apache.ignite.internal.portable.mutabletest.GridPortableTestClasses.TestObjectContainer;
-import static org.apache.ignite.internal.portable.mutabletest.GridPortableTestClasses.TestObjectEnum;
-import static org.apache.ignite.internal.portable.mutabletest.GridPortableTestClasses.TestObjectInner;
-import static org.apache.ignite.internal.portable.mutabletest.GridPortableTestClasses.TestObjectOuter;
-
-/**
- *
- */
-public class BinaryObjectBuilderAdditionalSelfTest extends GridCommonAbstractTest {
-    /** {@inheritDoc} */
-    @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception {
-        IgniteConfiguration cfg = super.getConfiguration(gridName);
-
-        CacheConfiguration cacheCfg = new CacheConfiguration();
-
-        cacheCfg.setCacheMode(REPLICATED);
-
-        cfg.setCacheConfiguration(cacheCfg);
-
-        BinaryConfiguration bCfg = new BinaryConfiguration();
-
-        bCfg.setCompactFooter(compactFooter());
-        
-        bCfg.setClassNames(Arrays.asList("org.apache.ignite.internal.portable.mutabletest.*"));
-
-        cfg.setMarshaller(new BinaryMarshaller());
-
-        return cfg;
-    }
-
-    /** {@inheritDoc} */
-    @Override protected void beforeTestsStarted() throws Exception {
-        startGrids(1);
-    }
-
-    /** {@inheritDoc} */
-    @Override protected void afterTestsStopped() throws Exception {
-        stopAllGrids();
-    }
-
-    /** {@inheritDoc} */
-    @Override protected void afterTest() throws Exception {
-        jcache(0).clear();
-    }
-
-    /**
-     * @return Compact footer.
-     */
-    protected boolean compactFooter() {
-        return true;
-    }
-
-    /**
-     * @return Portables API.
-     */
-    protected IgniteBinary portables() {
-        return grid(0).binary();
-    }
-
-    /**
-     * @throws Exception If failed.
-     */
-    public void testSimpleTypeFieldRead() throws Exception {
-        TestObjectAllTypes exp = new TestObjectAllTypes();
-
-        exp.setDefaultData();
-
-        BinaryObjectBuilder mutPo = wrap(exp);
-
-        for (Field field : TestObjectAllTypes.class.getDeclaredFields()) {
-            Object expVal = field.get(exp);
-            Object actVal = mutPo.getField(field.getName());
-
-            switch (field.getName()) {
-                case "anEnum":
-                    assertEquals(((PortableBuilderEnum)actVal).getOrdinal(), ((Enum)expVal).ordinal());
-                    break;
-
-                case "enumArr": {
-                    PortableBuilderEnum[] actArr = (PortableBuilderEnum[])actVal;
-                    Enum[] expArr = (Enum[])expVal;
-
-                    assertEquals(expArr.length, actArr.length);
-
-                    for (int i = 0; i < actArr.length; i++)
-                        assertEquals(expArr[i].ordinal(), actArr[i].getOrdinal());
-
-                    break;
-                }
-            }
-        }
-    }
-
-    /**
-     *
-     */
-    public void testSimpleTypeFieldSerialize() {
-        TestObjectAllTypes exp = new TestObjectAllTypes();
-
-        exp.setDefaultData();
-
-        BinaryObjectBuilderImpl mutPo = wrap(exp);
-
-        TestObjectAllTypes res = mutPo.build().deserialize();
-
-        GridTestUtils.deepEquals(exp, res);
-    }
-
-    /**
-     * @throws Exception If any error occurs.
-     */
-    public void testSimpleTypeFieldOverride() throws Exception {
-        TestObjectAllTypes exp = new TestObjectAllTypes();
-
-        exp.setDefaultData();
-
-        BinaryObjectBuilderImpl mutPo = wrap(new TestObjectAllTypes());
-
-        for (Field field : TestObjectAllTypes.class.getDeclaredFields())
-            mutPo.setField(field.getName(), field.get(exp));
-
-        TestObjectAllTypes res = mutPo.build().deserialize();
-
-        GridTestUtils.deepEquals(exp, res);
-    }
-
-    /**
-     * @throws Exception If any error occurs.
-     */
-    public void testSimpleTypeFieldSetNull() throws Exception {
-        TestObjectAllTypes exp = new TestObjectAllTypes();
-
-        exp.setDefaultData();
-
-        BinaryObjectBuilderImpl mutPo = wrap(exp);
-
-        for (Field field : TestObjectAllTypes.class.getDeclaredFields()) {
-            if (!field.getType().isPrimitive())
-                mutPo.setField(field.getName(), null);
-        }
-
-        TestObjectAllTypes res = mutPo.build().deserialize();
-
-        for (Field field : TestObjectAllTypes.class.getDeclaredFields()) {
-            if (!field.getType().isPrimitive())
-                assertNull(field.getName(), field.get(res));
-        }
-    }
-
-    /**
-     * @throws IgniteCheckedException If any error occurs.
-     */
-    public void testMakeCyclicDependency() throws IgniteCheckedException {
-        TestObjectOuter outer = new TestObjectOuter();
-        outer.inner = new TestObjectInner();
-
-        BinaryObjectBuilderImpl mutOuter = wrap(outer);
-
-        BinaryObjectBuilderImpl mutInner = mutOuter.getField("inner");
-
-        mutInner.setField("outer", mutOuter);
-        mutInner.setField("foo", mutInner);
-
-        TestObjectOuter res = mutOuter.build().deserialize();
-
-        assertEquals(res, res.inner.outer);
-        assertEquals(res.inner, res.inner.foo);
-    }
-
-    /**
-     *
-     */
-    public void testDateArrayModification() {
-        TestObjectAllTypes obj = new TestObjectAllTypes();
-
-        obj.dateArr =  new Date[] {new Date(11111), new Date(11111), new Date(11111)};
-
-        BinaryObjectBuilderImpl mutObj = wrap(obj);
-
-        Date[] arr = mutObj.getField("dateArr");
-        arr[0] = new Date(22222);
-
-        TestObjectAllTypes res = mutObj.build().deserialize();
-
-        Assert.assertArrayEquals(new Date[] {new Date(22222), new Date(11111), new Date(11111)}, res.dateArr);
-    }
-
-    /**
-     *
-     */
-    public void testTimestampArrayModification() {
-        TestObjectAllTypes obj = new TestObjectAllTypes();
-
-        obj.tsArr = new Timestamp[] {new Timestamp(111222333), new Timestamp(222333444)};
-
-        BinaryObjectBuilderImpl mutObj = wrap(obj);
-
-        Timestamp[] arr = mutObj.getField("tsArr");
-        arr[0] = new Timestamp(333444555);
-
-        TestObjectAllTypes res = mutObj.build().deserialize();
-
-        Assert.assertArrayEquals(new Timestamp[] {new Timestamp(333444555), new Timestamp(222333444)}, res.tsArr);
-    }
-
-    /**
-     *
-     */
-    public void testUUIDArrayModification() {
-        TestObjectAllTypes obj = new TestObjectAllTypes();
-
-        obj.uuidArr = new UUID[] {new UUID(1, 1), new UUID(1, 1), new UUID(1, 1)};
-
-        BinaryObjectBuilderImpl mutObj = wrap(obj);
-
-        UUID[] arr = mutObj.getField("uuidArr");
-        arr[0] = new UUID(2, 2);
-
-        TestObjectAllTypes res = mutObj.build().deserialize();
-
-        Assert.assertArrayEquals(new UUID[] {new UUID(2, 2), new UUID(1, 1), new UUID(1, 1)}, res.uuidArr);
-    }
-
-    /**
-     *
-     */
-    public void testDecimalArrayModification() {
-        TestObjectAllTypes obj = new TestObjectAllTypes();
-
-        obj.bdArr = new BigDecimal[] {new BigDecimal(1000), new BigDecimal(1000), new BigDecimal(1000)};
-
-        BinaryObjectBuilderImpl mutObj = wrap(obj);
-
-        BigDecimal[] arr = mutObj.getField("bdArr");
-        arr[0] = new BigDecimal(2000);
-
-        TestObjectAllTypes res = mutObj.build().deserialize();
-
-        Assert.assertArrayEquals(new BigDecimal[] {new BigDecimal(1000), new BigDecimal(1000), new BigDecimal(1000)},
-            res.bdArr);
-    }
-
-    /**
-     *
-     */
-    public void testBooleanArrayModification() {
-        TestObjectAllTypes obj = new TestObjectAllTypes();
-
-        obj.zArr = new boolean[] {false, false, false};
-
-        BinaryObjectBuilderImpl mutObj = wrap(obj);
-
-        boolean[] arr = mutObj.getField("zArr");
-        arr[0] = true;
-
-        TestObjectAllTypes res = mutObj.build().deserialize();
-
-        boolean[] expected = new boolean[] {true, false, false};
-
-        assertEquals(expected.length, res.zArr.length);
-
-        for (int i = 0; i < expected.length; i++)
-            assertEquals(expected[i], res.zArr[i]);
-    }
-
-    /**
-     *
-     */
-    public void testCharArrayModification() {
-        TestObjectAllTypes obj = new TestObjectAllTypes();
-
-        obj.cArr = new char[] {'a', 'a', 'a'};
-
-        BinaryObjectBuilderImpl mutObj = wrap(obj);
-
-        char[] arr = mutObj.getField("cArr");
-        arr[0] = 'b';
-
-        TestObjectAllTypes res = mutObj.build().deserialize();
-
-        Assert.assertArrayEquals(new char[] {'b', 'a', 'a'}, res.cArr);
-    }
-
-    /**
-     *
-     */
-    public void testDoubleArrayModification() {
-        TestObjectAllTypes obj = new TestObjectAllTypes();
-
-        obj.dArr = new double[] {1.0, 1.0, 1.0};
-
-        BinaryObjectBuilderImpl mutObj = wrap(obj);
-
-        double[] arr = mutObj.getField("dArr");
-        arr[0] = 2.0;
-
-        TestObjectAllTypes res = mutObj.build().deserialize();
-
-        Assert.assertArrayEquals(new double[] {2.0, 1.0, 1.0}, res.dArr, 0);
-    }
-
-    /**
-     *
-     */
-    public void testFloatArrayModification() {
-        TestObjectAllTypes obj = new TestObjectAllTypes();
-
-        obj.fArr = new float[] {1.0f, 1.0f, 1.0f};
-
-        BinaryObjectBuilderImpl mutObj = wrap(obj);
-
-        float[] arr = mutObj.getField("fArr");
-        arr[0] = 2.0f;
-
-        BinaryObject resBinary = mutObj.build();
-
-        TestObjectAllTypes res = resBinary.deserialize();
-
-        Assert.assertArrayEquals(new float[] {2.0f, 1.0f, 1.0f}, res.fArr, 0);
-    }
-
-    /**
-     *
-     */
-    public void testLongArrayModification() {
-        TestObjectAllTypes obj = new TestObjectAllTypes();
-
-        obj.lArr = new long[] {1, 1, 1};
-
-        BinaryObjectBuilderImpl mutObj = wrap(obj);
-
-        long[] arr = mutObj.getField("lArr");
-        arr[0] = 2;
-
-        TestObjectAllTypes res = mutObj.build().deserialize();
-
-        Assert.assertArrayEquals(new long[] {2, 1, 1}, res.lArr);
-    }
-
-    /**
-     *
-     */
-    public void testIntArrayModification() {
-        TestObjectAllTypes obj = new TestObjectAllTypes();
-
-        obj.iArr = new int[] {1, 1, 1};
-
-        BinaryObjectBuilderImpl mutObj = wrap(obj);
-
-        int[] arr = mutObj.getField("iArr");
-        arr[0] = 2;
-
-        TestObjectAllTypes res = mutObj.build().deserialize();
-
-        Assert.assertArrayEquals(new int[] {2, 1, 1}, res.iArr);
-    }
-
-    /**
-     *
-     */
-    public void testShortArrayModification() {
-        TestObjectAllTypes obj = new TestObjectAllTypes();
-
-        obj.sArr = new short[] {1, 1, 1};
-
-        BinaryObjectBuilderImpl mutObj = wrap(obj);
-
-        short[] arr = mutObj.getField("sArr");
-        arr[0] = 2;
-
-        TestObjectAllTypes res = mutObj.build().deserialize();
-
-        Assert.assertArrayEquals(new short[] {2, 1, 1}, res.sArr);
-    }
-
-    /**
-     *
-     */
-    public void testByteArrayModification() {
-        TestObjectAllTypes obj = new TestObjectAllTypes();
-
-        obj.bArr = new byte[] {1, 1, 1};
-
-        BinaryObjectBuilderImpl mutObj = wrap(obj);
-
-        byte[] arr = mutObj.getField("bArr");
-        arr[0] = 2;
-
-        TestObjectAllTypes res = mutObj.build().deserialize();
-
-        Assert.assertArrayEquals(new byte[] {2, 1, 1}, res.bArr);
-    }
-
-    /**
-     *
-     */
-    public void testStringArrayModification() {
-        TestObjectAllTypes obj = new TestObjectAllTypes();
-
-        obj.strArr = new String[] {"a", "a", "a"};
-
-        BinaryObjectBuilderImpl mutObj = wrap(obj);
-
-        String[] arr = mutObj.getField("strArr");
-        arr[0] = "b";
-
-        TestObjectAllTypes res = mutObj.build().deserialize();
-
-        Assert.assertArrayEquals(new String[] {"b", "a", "a"}, res.strArr);
-    }
-
-    /**
-     *
-     */
-    public void testModifyObjectArray() {
-        TestObjectContainer obj = new TestObjectContainer();
-        obj.foo = new Object[] {"a"};
-
-        BinaryObjectBuilderImpl mutObj = wrap(obj);
-
-        Object[] arr = mutObj.getField("foo");
-
-        Assert.assertArrayEquals(new Object[] {"a"}, arr);
-
-        arr[0] = "b";
-
-        TestObjectContainer res = mutObj.build().deserialize();
-
-        Assert.assertArrayEquals(new Object[] {"b"}, (Object[])res.foo);
-    }
-
-    /**
-     *
-     */
-    public void testOverrideObjectArrayField() {
-        BinaryObjectBuilderImpl mutObj = wrap(new TestObjectContainer());
-
-        Object[] createdArr = {mutObj, "a", 1, new String[] {"s", "s"}, new byte[] {1, 2}, new UUID(3, 0)};
-
-        mutObj.setField("foo", createdArr.clone());
-
-        TestObjectContainer res = mutObj.build().deserialize();
-
-        createdArr[0] = res;
-
-        assertTrue(Objects.deepEquals(createdArr, res.foo));
-    }
-
-    /**
-     *
-     */
-    public void testDeepArray() {
-        TestObjectContainer obj = new TestObjectContainer();
-        obj.foo = new Object[] {new Object[] {"a", obj}};
-
-        BinaryObjectBuilderImpl mutObj = wrap(obj);
-
-        Object[] arr = (Object[])mutObj.<Object[]>getField("foo")[0];
-
-        assertEquals("a", arr[0]);
-        assertSame(mutObj, arr[1]);
-
-        arr[0] = mutObj;
-
-        TestObjectContainer res = mutObj.build().deserialize();
-
-        arr = (Object[])((Object[])res.foo)[0];
-
-        assertSame(arr[0], res);
-        assertSame(arr[0], arr[1]);
-    }
-
-    /**
-     *
-     */
-    public void testArrayListRead() {
-        TestObjectContainer obj = new TestObjectContainer();
-        obj.foo = Lists.newArrayList(obj, "a");
-
-        BinaryObjectBuilderImpl mutObj = wrap(obj);
-
-        List<Object> list = mutObj.getField("foo");
-
-        assert list.equals(Lists.newArrayList(mutObj, "a"));
-    }
-
-    /**
-     *
-     */
-    public void testArrayListOverride() {
-        TestObjectContainer obj = new TestObjectContainer();
-
-        BinaryObjectBuilderImpl mutObj = wrap(obj);
-
-        ArrayList<Object> list = Lists.newArrayList(mutObj, "a", Lists.newArrayList(1, 2));
-
-        mutObj.setField("foo", list);
-
-        TestObjectContainer res = mutObj.build().deserialize();
-
-        list.set(0, res);
-
-        assertNotSame(list, res.foo);
-        assertEquals(list, res.foo);
-    }
-
-    /**
-     *
-     */
-    public void testArrayListModification() {
-        TestObjectContainer obj = new TestObjectContainer();
-        obj.foo = Lists.newArrayList("a", "b", "c");
-
-        BinaryObjectBuilderImpl mutObj = wrap(obj);
-
-        List<String> list = mutObj.getField("foo");
-
-        list.add("!"); // "a", "b", "c", "!"
-        list.add(0, "_"); // "_", "a", "b", "c", "!"
-
-        String s = list.remove(1); // "_", "b", "c", "!"
-        assertEquals("a", s);
-
-        assertEquals(Arrays.asList("c", "!"), list.subList(2, 4));
-        assertEquals(1, list.indexOf("b"));
-        assertEquals(1, list.lastIndexOf("b"));
-
-        TestObjectContainer res = mutObj.build().deserialize();
-
-        assertTrue(res.foo instanceof ArrayList);
-        assertEquals(Arrays.asList("_", "b", "c", "!"), res.foo);
-    }
-
-    /**
-     *
-     */
-    public void testArrayListClear() {
-        TestObjectContainer obj = new TestObjectContainer();
-        obj.foo = Lists.newArrayList("a", "b", "c");
-
-        BinaryObjectBuilderImpl mutObj = wrap(obj);
-
-        List<String> list = mutObj.getField("foo");
-
-        list.clear();
-
-        assertEquals(Collections.emptyList(), mutObj.build().<TestObjectContainer>deserialize().foo);
-    }
-
-    /**
-     *
-     */
-    public void testArrayListWriteUnmodifiable() {
-        TestObjectContainer obj = new TestObjectContainer();
-
-        ArrayList<Object> src = Lists.newArrayList(obj, "a", "b", "c");
-
-        obj.foo = src;
-
-        BinaryObjectBuilderImpl mutObj = wrap(obj);
-
-        TestObjectContainer deserialized = mutObj.build().deserialize();
-
-        List<Object> res = (List<Object>)deserialized.foo;
-
-        src.set(0, deserialized);
-
-        assertEquals(src, res);
-    }
-
-    /**
-     *
-     */
-    public void testLinkedListRead() {
-        TestObjectContainer obj = new TestObjectContainer();
-        obj.foo = Lists.newLinkedList(Arrays.asList(obj, "a"));
-
-        BinaryObjectBuilderImpl mutObj = wrap(obj);
-
-        List<Object> list = mutObj.getField("foo");
-
-        assert list.equals(Lists.newLinkedList(Arrays.asList(mutObj, "a")));
-    }
-
-    /**
-     *
-     */
-    public void testLinkedListOverride() {
-        TestObjectContainer obj = new TestObjectContainer();
-
-        BinaryObjectBuilderImpl mutObj = wrap(obj);
-
-        List<Object> list = Lists.newLinkedList(Arrays.asList(mutObj, "a", Lists.newLinkedList(Arrays.asList(1, 2))));
-
-        mutObj.setField("foo", list);
-
-        TestObjectContainer res = mutObj.build().deserialize();
-
-        list.set(0, res);
-
-        assertNotSame(list, res.foo);
-        assertEquals(list, res.foo);
-    }
-
-    /**
-     *
-     */
-    public void testLinkedListModification() {
-        TestObjectContainer obj = new TestObjectContainer();
-
-        obj.foo = Lists.newLinkedList(Arrays.asList("a", "b", "c"));
-
-        BinaryObjectBuilderImpl mutObj = wrap(obj);
-
-        List<String> list = mutObj.getField("foo");
-
-        list.add("!"); // "a", "b", "c", "!"
-        list.add(0, "_"); // "_", "a", "b", "c", "!"
-
-        String s = list.remove(1); // "_", "b", "c", "!"
-        assertEquals("a", s);
-
-        assertEquals(Arrays.asList("c", "!"), list.subList(2, 4));
-        assertEquals(1, list.indexOf("b"));
-        assertEquals(1, list.lastIndexOf("b"));
-
-        TestObjectContainer res = mutObj.build().deserialize();
-
-        assertTrue(res.foo instanceof LinkedList);
-        assertEquals(Arrays.asList("_", "b", "c", "!"), res.foo);
-    }
-
-    /**
-     *
-     */
-    public void testLinkedListWriteUnmodifiable() {
-        TestObjectContainer obj = new TestObjectContainer();
-
-        LinkedList<Object> src = Lists.newLinkedList(Arrays.asList(obj, "a", "b", "c"));
-
-        obj.foo = src;
-
-        BinaryObjectBuilderImpl mutObj = wrap(obj);
-
-        TestObjectContainer deserialized = mutObj.build().deserialize();
-
-        List<Object> res = (List<Object>)deserialized.foo;
-
-        src.set(0, deserialized);
-
-        assertEquals(src, res);
-    }
-
-    /**
-     *
-     */
-    public void testHashSetRead() {
-        TestObjectContainer obj = new TestObjectContainer();
-        obj.foo = Sets.newHashSet(obj, "a");
-
-        BinaryObjectBuilderImpl mutObj = wrap(obj);
-
-        Set<Object> set = mutObj.getField("foo");
-
-        assert set.equals(Sets.newHashSet(mutObj, "a"));
-    }
-
-    /**
-     *
-     */
-    public void testHashSetOverride() {
-        TestObjectContainer obj = new TestObjectContainer();
-
-        BinaryObjectBuilderImpl mutObj = wrap(obj);
-
-        Set<Object> c = Sets.newHashSet(mutObj, "a", Sets.newHashSet(1, 2));
-
-        mutObj.setField("foo", c);
-
-        TestObjectContainer res = mutObj.build().deserialize();
-
-        c.remove(mutObj);
-        c.add(res);
-
-        assertNotSame(c, res.foo);
-        assertEquals(c, res.foo);
-    }
-
-    /**
-     *
-     */
-    public void testHashSetModification() {
-        TestObjectContainer obj = new TestObjectContainer();
-        obj.foo = Sets.newHashSet("a", "b", "c");
-
-        BinaryObjectBuilderImpl mutObj = wrap(obj);
-
-        Set<String> set = mutObj.getField("foo");
-
-        set.remove("b");
-        set.add("!");
-
-        assertEquals(Sets.newHashSet("a", "!", "c"), set);
-        assertTrue(set.contains("a"));
-        assertTrue(set.contains("!"));
-
-        TestObjectContainer res = mutObj.build().deserialize();
-
-        assertTrue(res.foo instanceof HashSet);
-        assertEquals(Sets.newHashSet("a", "!", "c"), res.foo);
-    }
-
-    /**
-     *
-     */
-    public void testHashSetWriteUnmodifiable() {
-        TestObjectContainer obj = new TestObjectContainer();
-
-        Set<Object> src = Sets.newHashSet(obj, "a", "b", "c");
-
-        obj.foo = src;
-
-        TestObjectContainer deserialized = wrap(obj).build().deserialize();
-
-        Set<Object> res = (Set<Object>)deserialized.foo;
-
-        src.remove(obj);
-        src.add(deserialized);
-
-        assertEquals(src, res);
-    }
-
-    /**
-     *
-     */
-    public void testMapRead() {
-        TestObjectContainer obj = new TestObjectContainer();
-        obj.foo = Maps.newHashMap(ImmutableMap.of(obj, "a", "b", obj));
-
-        BinaryObjectBuilderImpl mutObj = wrap(obj);
-
-        Map<Object, Object> map = mutObj.getField("foo");
-
-        assert map.equals(ImmutableMap.of(mutObj, "a", "b", mutObj));
-    }
-
-    /**
-     *
-     */
-    public void testMapOverride() {
-        TestObjectContainer obj = new TestObjectContainer();
-
-        BinaryObjectBuilderImpl mutObj = wrap(obj);
-
-        Map<Object, Object> map = Maps.newHashMap(ImmutableMap.of(mutObj, "a", "b", mutObj));
-
-        mutObj.setField("foo", map);
-
-        TestObjectContainer res = mutObj.build().deserialize();
-
-        assertEquals(ImmutableMap.of(res, "a", "b", res), res.foo);
-    }
-
-    /**
-     *
-     */
-    public void testMapModification() {
-        TestObjectContainer obj = new TestObjectContainer();
-        obj.foo = Maps.newHashMap(ImmutableMap.of(1, "a", 2, "b"));
-
-        BinaryObjectBuilderImpl mutObj = wrap(obj);
-
-        Map<Object, Object> map = mutObj.getField("foo");
-
-        map.put(3, mutObj);
-        Object rmv = map.remove(1);
-
-        assertEquals("a", rmv);
-
-        TestObjectContainer res = mutObj.build().deserialize();
-
-        assertEquals(ImmutableMap.of(2, "b", 3, res), res.foo);
-    }
-
-    /**
-     *
-     */
-    public void testEnumArrayModification() {
-        TestObjectAllTypes obj = new TestObjectAllTypes();
-
-        obj.enumArr = new TestObjectEnum[] {TestObjectEnum.A, TestObjectEnum.B};
-
-        BinaryObjectBuilderImpl mutObj = wrap(obj);
-
-        PortableBuilderEnum[] arr = mutObj.getField("enumArr");
-        arr[0] = new PortableBuilderEnum(mutObj.typeId(), TestObjectEnum.B);
-
-        TestObjectAllTypes res = mutObj.build().deserialize();
-
-        Assert.assertArrayEquals(new TestObjectEnum[] {TestObjectEnum.A, TestObjectEnum.B}, res.enumArr);
-    }
-
-    /**
-     *
-     */
-    public void testEditObjectWithRawData() {
-        GridBinaryMarshalerAwareTestClass obj = new GridBinaryMarshalerAwareTestClass();
-
-        obj.s = "a";
-        obj.sRaw = "aa";
-
-        BinaryObjectBuilderImpl mutableObj = wrap(obj);
-
-        mutableObj.setField("s", "z");
-
-        GridBinaryMarshalerAwareTestClass res = mutableObj.build().deserialize();
-        assertEquals("z", res.s);
-        assertEquals("aa", res.sRaw);
-    }
-
-    /**
-     *
-     */
-    public void testHashCode() {
-        TestObjectContainer obj = new TestObjectContainer();
-
-        BinaryObjectBuilderImpl mutableObj = wrap(obj);
-
-        assertEquals(obj.hashCode(), mutableObj.build().hashCode());
-
-        mutableObj.hashCode(25);
-
-        assertEquals(25, mutableObj.build().hashCode());
-    }
-
-    /**
-     *
-     */
-    public void testCollectionsInCollection() {
-        TestObjectContainer obj = new TestObjectContainer();
-        obj.foo = Lists.newArrayList(
-            Lists.newArrayList(1, 2),
-            Lists.newLinkedList(Arrays.asList(1, 2)),
-            Sets.newHashSet("a", "b"),
-            Sets.newLinkedHashSet(Arrays.asList("a", "b")),
-            Maps.newHashMap(ImmutableMap.of(1, "a", 2, "b")));
-
-        TestObjectContainer deserialized = wrap(obj).build().deserialize();
-
-        assertEquals(obj.foo, deserialized.foo);
-    }
-
-    /**
-     *
-     */
-    public void testMapEntryOverride() {
-        TestObjectContainer obj = new TestObjectContainer();
-
-        BinaryObjectBuilderImpl mutableObj = wrap(obj);
-
-        mutableObj.setField("foo", new GridMapEntry<>(1, "a"));
-
-        TestObjectContainer res = mutableObj.build().deserialize();
-
-        assertEquals(new GridMapEntry<>(1, "a"), res.foo);
-    }
-
-    /**
-     *
-     */
-    public void testMetadataChangingDoublePut() {
-        BinaryObjectBuilderImpl mutableObj = wrap(new TestObjectContainer());
-
-        mutableObj.setField("xx567", "a");
-        mutableObj.setField("xx567", "b");
-
-        mutableObj.build();
-
-        BinaryType metadata = portables().type(TestObjectContainer.class);
-
-        assertEquals("String", metadata.fieldTypeName("xx567"));
-    }
-
-    /**
-     *
-     */
-    public void testMetadataChangingDoublePut2() {
-        BinaryObjectBuilderImpl mutableObj = wrap(new TestObjectContainer());
-
-        mutableObj.setField("xx567", "a");
-        mutableObj.setField("xx567", "b");
-
-        mutableObj.build();
-
-        BinaryType metadata = portables().type(TestObjectContainer.class);
-
-        assertEquals("String", metadata.fieldTypeName("xx567"));
-    }
-
-    /**
-     *
-     */
-    public void testMetadataChanging() {
-        TestObjectContainer c = new TestObjectContainer();
-
-        BinaryObjectBuilderImpl mutableObj = wrap(c);
-
-        mutableObj.setField("intField", 1);
-        mutableObj.setField("intArrField", new int[] {1});
-        mutableObj.setField("arrField", new String[] {"1"});
-        mutableObj.setField("strField", "1");
-        mutableObj.setField("colField", Lists.newArrayList("1"));
-        mutableObj.setField("mapField", Maps.newHashMap(ImmutableMap.of(1, "1")));
-        mutableObj.setField("enumField", TestObjectEnum.A);
-        mutableObj.setField("enumArrField", new Enum[] {TestObjectEnum.A});
-
-        mutableObj.build();
-
-        BinaryType metadata = portables().type(c.getClass());
-
-        assertTrue(metadata.fieldNames().containsAll(Arrays.asList("intField", "intArrField", "arrField", "strField",
-            "colField", "mapField", "enumField", "enumArrField")));
-
-        assertEquals("int", metadata.fieldTypeName("intField"));
-        assertEquals("int[]", metadata.fieldTypeName("intArrField"));
-        assertEquals("String[]", metadata.fieldTypeName("arrField"));
-        assertEquals("String", metadata.fieldTypeName("strField"));
-        assertEquals("Collection", metadata.fieldTypeName("colField"));
-        assertEquals("Map", metadata.fieldTypeName("mapField"));
-        assertEquals("Enum", metadata.fieldTypeName("enumField"));
-        assertEquals("Enum[]", metadata.fieldTypeName("enumArrField"));
-    }
-
-    /**
-     *
-     */
-    public void testDateInObjectField() {
-        TestObjectContainer obj = new TestObjectContainer();
-
-        obj.foo = new Date();
-
-        BinaryObjectBuilderImpl mutableObj = wrap(obj);
-
-        assertEquals(Date.class, mutableObj.getField("foo").getClass());
-    }
-
-    /**
-     *
-     */
-    public void testTimestampInObjectField() {
-        TestObjectContainer obj = new TestObjectContainer();
-
-        obj.foo = new Timestamp(100020003);
-
-        BinaryObjectBuilderImpl mutableObj = wrap(obj);
-
-        assertEquals(Timestamp.class, mutableObj.getField("foo").getClass());
-    }
-
-    /**
-     *
-     */
-    public void testDateInCollection() {
-        TestObjectContainer obj = new TestObjectContainer();
-
-        obj.foo = Lists.newArrayList(new Date());
-
-        BinaryObjectBuilderImpl mutableObj = wrap(obj);
-
-        assertEquals(Date.class, ((List<?>)mutableObj.getField("foo")).get(0).getClass());
-    }
-
-    /**
-     *
-     */
-    public void testTimestampInCollection() {
-        TestObjectContainer obj = new TestObjectContainer();
-
-        obj.foo = Lists.newArrayList(new Timestamp(100020003));
-
-        BinaryObjectBuilderImpl mutableObj = wrap(obj);
-
-        assertEquals(Timestamp.class, ((List<?>)mutableObj.getField("foo")).get(0).getClass());
-    }
-
-    /**
-     *
-     */
-    @SuppressWarnings("AssertEqualsBetweenInconvertibleTypes")
-    public void testDateArrayOverride() {
-        TestObjectContainer obj = new TestObjectContainer();
-
-        BinaryObjectBuilderImpl mutableObj = wrap(obj);
-
-        Date[] arr = { new Date() };
-
-        mutableObj.setField("foo", arr);
-
-        TestObjectContainer res = mutableObj.build().deserialize();
-
-        assertEquals(Date[].class, res.foo.getClass());
-        assertTrue(Objects.deepEquals(arr, res.foo));
-    }
-
-    /**
-     *
-     */
-    @SuppressWarnings("AssertEqualsBetweenInconvertibleTypes")
-    public void testTimestampArrayOverride() {
-        TestObjectContainer obj = new TestObjectContainer();
-
-        BinaryObjectBuilderImpl mutableObj = wrap(obj);
-
-        Timestamp[] arr = { new Timestamp(100020003) };
-
-        mutableObj.setField("foo", arr);
-
-        TestObjectContainer res = mutableObj.build().deserialize();
-
-        assertEquals(Timestamp[].class, res.foo.getClass());
-        assertTrue(Objects.deepEquals(arr, res.foo));
-    }
-
-    /**
-     *
-     */
-    public void testChangeMap() {
-        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"));
-
-        BinaryObjectBuilderImpl binaryAddres = wrap(addrs);
-
-        Map<String, BinaryObjectBuilderImpl> map = binaryAddres.getField("companyByStreet");
-
-        BinaryObjectBuilderImpl binaryCompanies = map.get("Torzhkovskya");
-
-        List<BinaryObjectBuilderImpl> binaryCompaniesList = binaryCompanies.getField("companies");
-
-        BinaryObjectBuilderImpl company = binaryCompaniesList.get(0);
-
-        assert "Google inc".equals(company.<String>getField("name"));
-
-        binaryCompaniesList.remove(0);
-
-        Addresses res = binaryAddres.build().deserialize();
-
-        assertEquals(Arrays.asList("Nevskiy", "Torzhkovskya"), new ArrayList<>(res.getCompanyByStreet().keySet()));
-
-        Companies torzhkovskyaCompanies = res.getCompanyByStreet().get("Torzhkovskya");
-
-        assertEquals(2, torzhkovskyaCompanies.size());
-        assertEquals("Apple inc", torzhkovskyaCompanies.get(0).name);
-    }
-
-    /**
-     *
-     */
-    public void testSavingObjectWithNotZeroStart() {
-        TestObjectOuter out = new TestObjectOuter();
-        TestObjectInner inner = new TestObjectInner();
-
-        out.inner = inner;
-        inner.outer = out;
-
-        BinaryObjectBuilderImpl builder = wrap(out);
-
-        BinaryObjectBuilderImpl innerBuilder = builder.getField("inner");
-
-        TestObjectInner res = innerBuilder.build().deserialize();
-
-        assertSame(res, res.outer.inner);
-    }
-
-    /**
-     *
-     */
-    public void testPortableObjectField() {
-        TestObjectContainer container = new TestObjectContainer(toPortable(new TestObjectArrayList()));
-
-        BinaryObjectBuilderImpl wrapper = wrap(container);
-
-        assertTrue(wrapper.getField("foo") instanceof BinaryObject);
-
-        TestObjectContainer deserialized = wrapper.build().deserialize();
-        assertTrue(deserialized.foo instanceof BinaryObject);
-    }
-
-    /**
-     *
-     */
-    public void testAssignPortableObject() {
-        TestObjectContainer container = new TestObjectContainer();
-
-        BinaryObjectBuilderImpl wrapper = wrap(container);
-
-        wrapper.setField("foo", toPortable(new TestObjectArrayList()));
-
-        TestObjectContainer deserialized = wrapper.build().deserialize();
-        assertTrue(deserialized.foo instanceof TestObjectArrayList);
-    }
-
-    /**
-     *
-     */
-    public void testRemoveFromNewObject() {
-        BinaryObjectBuilderImpl wrapper = newWrapper(TestObjectAllTypes.class);
-
-        wrapper.setField("str", "a");
-
-        wrapper.removeField("str");
-
-        assertNull(wrapper.build().<TestObjectAllTypes>deserialize().str);
-    }
-
-    /**
-     *
-     */
-    public void testRemoveFromExistingObject() {
-        TestObjectAllTypes obj = new TestObjectAllTypes();
-        obj.setDefaultData();
-
-        BinaryObjectBuilderImpl wrapper = wrap(toPortable(obj));
-
-        wrapper.removeField("str");
-
-        assertNull(wrapper.build().<TestObjectAllTypes>deserialize().str);
-    }
-
-    /**
-     *
-     */
-    public void testCyclicArrays() {
-        TestObjectContainer obj = new TestObjectContainer();
-
-        Object[] arr1 = new Object[1];
-        Object[] arr2 = new Object[] {arr1};
-
-        arr1[0] = arr2;
-
-        obj.foo = arr1;
-
-        TestObjectContainer res = toPortable(obj).deserialize();
-
-        Object[] resArr = (Object[])res.foo;
-
-        assertSame(((Object[])resArr[0])[0], resArr);
-    }
-
-    /**
-     *
-     */
-    @SuppressWarnings("TypeMayBeWeakened")
-    public void testCyclicArrayList() {
-        TestObjectContainer obj = new TestObjectContainer();
-
-        List<Object> arr1 = new ArrayList<>();
-        List<Object> arr2 = new ArrayList<>();
-
-        arr1.add(arr2);
-        arr2.add(arr1);
-
-        obj.foo = arr1;
-
-        TestObjectContainer res = toPortable(obj).deserialize();
-
-        List<?> resArr = (List<?>)res.foo;
-
-        assertSame(((List<Object>)resArr.get(0)).get(0), resArr);
-    }
-
-    /**
-     * @param obj Object.
-     * @return Object in portable format.
-     */
-    private BinaryObject toPortable(Object obj) {
-        return portables().toBinary(obj);
-    }
-
-    /**
-     * @param obj Object.
-     * @return GridMutablePortableObject.
-     */
-    private BinaryObjectBuilderImpl wrap(Object obj) {
-        return BinaryObjectBuilderImpl.wrap(toPortable(obj));
-    }
-
-    /**
-     * @param aCls Class.
-     * @return Wrapper.
-     */
-    private BinaryObjectBuilderImpl newWrapper(Class<?> aCls) {
-        CacheObjectBinaryProcessorImpl processor = (CacheObjectBinaryProcessorImpl)(
-            (IgniteBinaryImpl)portables()).processor();
-
-        return new BinaryObjectBuilderImpl(processor.portableContext(), processor.typeId(aCls.getName()),
-            aCls.getSimpleName());
-    }
-}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ignite/blob/1dbf20e0/modules/core/src/test/java/org/apache/ignite/internal/portable/BinaryObjectBuilderSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/portable/BinaryObjectBuilderSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/portable/BinaryObjectBuilderSelfTest.java
deleted file mode 100644
index 66bd77e..0000000
--- a/modules/core/src/test/java/org/apache/ignite/internal/portable/BinaryObjectBuilderSelfTest.java
+++ /dev/null
@@ -1,1103 +0,0 @@
-/*
- * 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.portable;
-
-import java.math.BigDecimal;
-import java.sql.Timestamp;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.Date;
-import java.util.List;
-import java.util.Map;
-import java.util.UUID;
-import org.apache.ignite.IgniteBinary;
-import org.apache.ignite.IgniteCheckedException;
-import org.apache.ignite.binary.BinaryIdMapper;
-import org.apache.ignite.binary.BinaryObject;
-import org.apache.ignite.binary.BinaryObjectBuilder;
-import org.apache.ignite.binary.BinaryType;
-import org.apache.ignite.binary.BinaryTypeConfiguration;
-import org.apache.ignite.configuration.BinaryConfiguration;
-import org.apache.ignite.configuration.IgniteConfiguration;
-import org.apache.ignite.internal.portable.builder.BinaryObjectBuilderImpl;
-import org.apache.ignite.internal.portable.mutabletest.GridPortableTestClasses.TestObjectAllTypes;
-import org.apache.ignite.internal.portable.mutabletest.GridPortableTestClasses.TestObjectContainer;
-import org.apache.ignite.internal.portable.mutabletest.GridPortableTestClasses.TestObjectInner;
-import org.apache.ignite.internal.portable.mutabletest.GridPortableTestClasses.TestObjectOuter;
-import org.apache.ignite.internal.portable.mutabletest.GridPortableTestClasses.TestObjectPlainPortable;
-import org.apache.ignite.internal.processors.cache.portable.CacheObjectBinaryProcessorImpl;
-import org.apache.ignite.internal.util.GridUnsafe;
-import org.apache.ignite.internal.util.typedef.F;
-import org.apache.ignite.testframework.GridTestUtils;
-import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
-import sun.misc.Unsafe;
-
-/**
- * Portable builder test.
- */
-@SuppressWarnings("ResultOfMethodCallIgnored")
-public class BinaryObjectBuilderSelfTest extends GridCommonAbstractTest {
-    /** */
-    private static final Unsafe UNSAFE = GridUnsafe.unsafe();
-
-    /** */
-    protected static final long BYTE_ARR_OFF = UNSAFE.arrayBaseOffset(byte[].class);
-
-    /** {@inheritDoc} */
-    @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception {
-        IgniteConfiguration cfg = super.getConfiguration(gridName);
-
-        BinaryTypeConfiguration customTypeCfg = new BinaryTypeConfiguration();
-
-        customTypeCfg.setTypeName(CustomIdMapper.class.getName());
-        customTypeCfg.setIdMapper(new BinaryIdMapper() {
-            @Override public int typeId(String clsName) {
-                return ~BinaryInternalIdMapper.defaultInstance().typeId(clsName);
-            }
-
-            @Override public int fieldId(int typeId, String fieldName) {
-                return typeId + ~BinaryInternalIdMapper.defaultInstance().fieldId(typeId, fieldName);
-            }
-        });
-
-        BinaryConfiguration bCfg = new BinaryConfiguration();
-        
-        bCfg.setCompactFooter(compactFooter());
-
-        bCfg.setTypeConfigurations(Arrays.asList(
-            new BinaryTypeConfiguration(Key.class.getName()),
-            new BinaryTypeConfiguration(Value.class.getName()),
-            new BinaryTypeConfiguration("org.gridgain.grid.internal.util.portable.mutabletest.*"),
-            customTypeCfg));
-
-        cfg.setBinaryConfiguration(bCfg);
-
-        cfg.setMarshaller(new BinaryMarshaller());
-
-        return cfg;
-    }
-
-    /** {@inheritDoc} */
-    @Override protected void beforeTestsStarted() throws Exception {
-        startGrids(1);
-    }
-
-    /** {@inheritDoc} */
-    @Override protected void afterTestsStopped() throws Exception {
-        stopAllGrids();
-    }
-
-    /**
-     * @return Whether to use compact footer.
-     */
-    protected boolean compactFooter() {
-        return true;
-    }
-
-    /**
-     *
-     */
-    public void testAllFieldsSerialization() {
-        TestObjectAllTypes obj = new TestObjectAllTypes();
-        obj.setDefaultData();
-        obj.enumArr = null;
-
-        TestObjectAllTypes deserialized = builder(toPortable(obj)).build().deserialize();
-
-        GridTestUtils.deepEquals(obj, deserialized);
-    }
-
-    /**
-     * @throws Exception If failed.
-     */
-    public void testNullField() throws Exception {
-        BinaryObjectBuilder builder = builder("Class");
-
-        builder.hashCode(42);
-
-        builder.setField("objField", (Object)null);
-
-        builder.setField("otherField", "value");
-
-        BinaryObject obj = builder.build();
-
-        assertNull(obj.field("objField"));
-        assertEquals("value", obj.field("otherField"));
-        assertEquals(42, obj.hashCode());
-
-        builder = builder(obj);
-
-        builder.setField("objField", "value");
-        builder.setField("otherField", (Object)null);
-
-        obj = builder.build();
-
-        assertNull(obj.field("otherField"));
-        assertEquals("value", obj.field("objField"));
-        assertEquals(42, obj.hashCode());
-    }
-
-    /**
-     * @throws Exception If failed.
-     */
-    public void testByteField() throws Exception {
-        BinaryObjectBuilder builder = builder("Class");
-
-        builder.hashCode(100);
-
-        builder.setField("byteField", (byte)1);
-
-        BinaryObject po = builder.build();
-
-        assertEquals("class".hashCode(), po.type().typeId());
-        assertEquals(100, po.hashCode());
-
-        assertEquals((byte) 1, po.<Byte>field("byteField").byteValue());
-    }
-
-    /**
-     * @throws Exception If failed.
-     */
-    public void testShortField() throws Exception {
-        BinaryObjectBuilder builder = builder("Class");
-
-        builder.hashCode(100);
-
-        builder.setField("shortField", (short)1);
-
-        BinaryObject po = builder.build();
-
-        assertEquals("class".hashCode(), po.type().typeId());
-        assertEquals(100, po.hashCode());
-
-        assertEquals((short)1, po.<Short>field("shortField").shortValue());
-    }
-
-    /**
-     * @throws Exception If failed.
-     */
-    public void testIntField() throws Exception {
-        BinaryObjectBuilder builder = builder("Class");
-
-        builder.hashCode(100);
-
-        builder.setField("intField", 1);
-
-        BinaryObject po = builder.build();
-
-        assertEquals("class".hashCode(), po.type().typeId());
-        assertEquals(100, po.hashCode());
-
-        assertEquals(1, po.<Integer>field("intField").intValue());
-    }
-
-    /**
-     * @throws Exception If failed.
-     */
-    public void testLongField() throws Exception {
-        BinaryObjectBuilder builder = builder("Class");
-
-        builder.hashCode(100);
-
-        builder.setField("longField", 1L);
-
-        BinaryObject po = builder.build();
-
-        assertEquals("class".hashCode(), po.type().typeId());
-        assertEquals(100, po.hashCode());
-
-        assertEquals(1L, po.<Long>field("longField").longValue());
-    }
-
-    /**
-     * @throws Exception If failed.
-     */
-    public void testFloatField() throws Exception {
-        BinaryObjectBuilder builder = builder("Class");
-
-        builder.hashCode(100);
-
-        builder.setField("floatField", 1.0f);
-
-        BinaryObject po = builder.build();
-
-        assertEquals("class".hashCode(), po.type().typeId());
-        assertEquals(100, po.hashCode());
-
-        assertEquals(1.0f, po.<Float>field("floatField").floatValue(), 0);
-    }
-
-    /**
-     * @throws Exception If failed.
-     */
-    public void testDoubleField() throws Exception {
-        BinaryObjectBuilder builder = builder("Class");
-
-        builder.hashCode(100);
-
-        builder.setField("doubleField", 1.0d);
-
-        BinaryObject po = builder.build();
-
-        assertEquals("class".hashCode(), po.type().typeId());
-        assertEquals(100, po.hashCode());
-
-        assertEquals(1.0d, po.<Double>field("doubleField").doubleValue(), 0);
-    }
-
-    /**
-     * @throws Exception If failed.
-     */
-    public void testCharField() throws Exception {
-        BinaryObjectBuilder builder = builder("Class");
-
-        builder.hashCode(100);
-
-        builder.setField("charField", (char)1);
-
-        BinaryObject po = builder.build();
-
-        assertEquals("class".hashCode(), po.type().typeId());
-        assertEquals(100, po.hashCode());
-
-        assertEquals((char)1, po.<Character>field("charField").charValue());
-    }
-
-    /**
-     * @throws Exception If failed.
-     */
-    public void testBooleanField() throws Exception {
-        BinaryObjectBuilder builder = builder("Class");
-
-        builder.hashCode(100);
-
-        builder.setField("booleanField", true);
-
-        BinaryObject po = builder.build();
-
-        assertEquals("class".hashCode(), po.type().typeId());
-        assertEquals(100, po.hashCode());
-
-        assertTrue(po.<Boolean>field("booleanField"));
-    }
-
-    /**
-     * @throws Exception If failed.
-     */
-    public void testDecimalField() throws Exception {
-        BinaryObjectBuilder builder = builder("Class");
-
-        builder.hashCode(100);
-
-        builder.setField("decimalField", BigDecimal.TEN);
-
-        BinaryObject po = builder.build();
-
-        assertEquals("class".hashCode(), po.type().typeId());
-        assertEquals(100, po.hashCode());
-
-        assertEquals(BigDecimal.TEN, po.<BigDecimal>field("decimalField"));
-    }
-
-    /**
-     * @throws Exception If failed.
-     */
-    public void testStringField() throws Exception {
-        BinaryObjectBuilder builder = builder("Class");
-
-        builder.hashCode(100);
-
-        builder.setField("stringField", "str");
-
-        BinaryObject po = builder.build();
-
-        assertEquals("class".hashCode(), po.type().typeId());
-        assertEquals(100, po.hashCode());
-
-        assertEquals("str", po.<String>field("stringField"));
-    }
-
-    /**
-     * @throws Exception If failed.
-     */
-    public void testDateField() throws Exception {
-        Date date = new Date();
-
-        assertEquals(date, builder("C").setField("d", date).build().<Date>field("d"));
-    }
-
-    /**
-     * @throws Exception If failed.
-     */
-    public void testTimestampField() throws Exception {
-        Timestamp ts = new Timestamp(new Date().getTime());
-        ts.setNanos(1000);
-
-        assertEquals(ts, builder("C").setField("t", ts).build().<Timestamp>field("t"));
-    }
-
-    /**
-     * @throws Exception If failed.
-     */
-    public void testUuidField() throws Exception {
-        BinaryObjectBuilder builder = builder("Class");
-
-        builder.hashCode(100);
-
-        UUID uuid = UUID.randomUUID();
-
-        builder.setField("uuidField", uuid);
-
-        BinaryObject po = builder.build();
-
-        assertEquals("class".hashCode(), po.type().typeId());
-        assertEquals(100, po.hashCode());
-
-        assertEquals(uuid, po.<UUID>field("uuidField"));
-    }
-
-    /**
-     * @throws Exception If failed.
-     */
-    public void testByteArrayField() throws Exception {
-        BinaryObjectBuilder builder = builder("Class");
-
-        builder.hashCode(100);
-
-        builder.setField("byteArrayField", new byte[] {1, 2, 3});
-
-        BinaryObject po = builder.build();
-
-        assertEquals("class".hashCode(), po.type().typeId());
-        assertEquals(100, po.hashCode());
-
-        assertTrue(Arrays.equals(new byte[] {1, 2, 3}, po.<byte[]>field("byteArrayField")));
-    }
-
-    /**
-     * @throws Exception If failed.
-     */
-    public void testShortArrayField() throws Exception {
-        BinaryObjectBuilder builder = builder("Class");
-
-        builder.hashCode(100);
-
-        builder.setField("shortArrayField", new short[] {1, 2, 3});
-
-        BinaryObject po = builder.build();
-
-        assertEquals("class".hashCode(), po.type().typeId());
-        assertEquals(100, po.hashCode());
-
-        assertTrue(Arrays.equals(new short[] {1, 2, 3}, po.<short[]>field("shortArrayField")));
-    }
-
-    /**
-     * @throws Exception If failed.
-     */
-    public void testIntArrayField() throws Exception {
-        BinaryObjectBuilder builder = builder("Class");
-
-        builder.hashCode(100);
-
-        builder.setField("intArrayField", new int[] {1, 2, 3});
-
-        BinaryObject po = builder.build();
-
-        assertEquals("class".hashCode(), po.type().typeId());
-        assertEquals(100, po.hashCode());
-
-        assertTrue(Arrays.equals(new int[] {1, 2, 3}, po.<int[]>field("intArrayField")));
-    }
-
-    /**
-     * @throws Exception If failed.
-     */
-    public void testLongArrayField() throws Exception {
-        BinaryObjectBuilder builder = builder("Class");
-
-        builder.hashCode(100);
-
-        builder.setField("longArrayField", new long[] {1, 2, 3});
-
-        BinaryObject po = builder.build();
-
-        assertEquals("class".hashCode(), po.type().typeId());
-        assertEquals(100, po.hashCode());
-
-        assertTrue(Arrays.equals(new long[] {1, 2, 3}, po.<long[]>field("longArrayField")));
-    }
-
-    /**
-     * @throws Exception If failed.
-     */
-    public void testFloatArrayField() throws Exception {
-        BinaryObjectBuilder builder = builder("Class");
-
-        builder.hashCode(100);
-
-        builder.setField("floatArrayField", new float[] {1, 2, 3});
-
-        BinaryObject po = builder.build();
-
-        assertEquals("class".hashCode(), po.type().typeId());
-        assertEquals(100, po.hashCode());
-
-        assertTrue(Arrays.equals(new float[] {1, 2, 3}, po.<float[]>field("floatArrayField")));
-    }
-
-    /**
-     * @throws Exception If failed.
-     */
-    public void testDoubleArrayField() throws Exception {
-        BinaryObjectBuilder builder = builder("Class");
-
-        builder.hashCode(100);
-
-        builder.setField("doubleArrayField", new double[] {1, 2, 3});
-
-        BinaryObject po = builder.build();
-
-        assertEquals("class".hashCode(), po.type().typeId());
-        assertEquals(100, po.hashCode());
-
-        assertTrue(Arrays.equals(new double[] {1, 2, 3}, po.<double[]>field("doubleArrayField")));
-    }
-
-    /**
-     * @throws Exception If failed.
-     */
-    public void testCharArrayField() throws Exception {
-        BinaryObjectBuilder builder = builder("Class");
-
-        builder.hashCode(100);
-
-        builder.setField("charArrayField", new char[] {1, 2, 3});
-
-        BinaryObject po = builder.build();
-
-        assertEquals("class".hashCode(), po.type().typeId());
-        assertEquals(100, po.hashCode());
-
-        assertTrue(Arrays.equals(new char[] {1, 2, 3}, po.<char[]>field("charArrayField")));
-    }
-
-    /**
-     * @throws Exception If failed.
-     */
-    public void testBooleanArrayField() throws Exception {
-        BinaryObjectBuilder builder = builder("Class");
-
-        builder.hashCode(100);
-
-        builder.setField("booleanArrayField", new boolean[] {true, false});
-
-        BinaryObject po = builder.build();
-
-        assertEquals("class".hashCode(), po.type().typeId());
-        assertEquals(100, po.hashCode());
-
-        boolean[] arr = po.field("booleanArrayField");
-
-        assertEquals(2, arr.length);
-
-        assertTrue(arr[0]);
-        assertFalse(arr[1]);
-    }
-
-    /**
-     * @throws Exception If failed.
-     */
-    public void testDecimalArrayField() throws Exception {
-        BinaryObjectBuilder builder = builder("Class");
-
-        builder.hashCode(100);
-
-        builder.setField("decimalArrayField", new BigDecimal[] {BigDecimal.ONE, BigDecimal.TEN});
-
-        BinaryObject po = builder.build();
-
-        assertEquals("class".hashCode(), po.type().typeId());
-        assertEquals(100, po.hashCode());
-
-        assertTrue(Arrays.equals(new BigDecimal[] {BigDecimal.ONE, BigDecimal.TEN}, po.<String[]>field("decimalArrayField")));
-    }
-
-    /**
-     * @throws Exception If failed.
-     */
-    public void testStringArrayField() throws Exception {
-        BinaryObjectBuilder builder = builder("Class");
-
-        builder.hashCode(100);
-
-        builder.setField("stringArrayField", new String[] {"str1", "str2", "str3"});
-
-        BinaryObject po = builder.build();
-
-        assertEquals("class".hashCode(), po.type().typeId());
-        assertEquals(100, po.hashCode());
-
-        assertTrue(Arrays.equals(new String[] {"str1", "str2", "str3"}, po.<String[]>field("stringArrayField")));
-    }
-
-    /**
-     * @throws Exception If failed.
-     */
-    public void testDateArrayField() throws Exception {
-        Date date1 = new Date();
-        Date date2 = new Date(date1.getTime() + 1000);
-
-        Date[] dateArr = new Date[] { date1, date2 };
-
-        assertTrue(Arrays.equals(dateArr, builder("C").setField("da", dateArr).build().<Date[]>field("da")));
-    }
-
-    /**
-     * @throws Exception If failed.
-     */
-    public void testTimestampArrayField() throws Exception {
-        Timestamp ts1 = new Timestamp(new Date().getTime());
-        Timestamp ts2 = new Timestamp(new Date().getTime() + 1000);
-
-        ts1.setNanos(1000);
-        ts2.setNanos(2000);
-
-        Timestamp[] tsArr = new Timestamp[] { ts1, ts2 };
-
-        assertTrue(Arrays.equals(tsArr, builder("C").setField("ta", tsArr).build().<Timestamp[]>field("ta")));
-    }
-
-    /**
-     * @throws Exception If failed.
-     */
-    public void testUuidArrayField() throws Exception {
-        BinaryObjectBuilder builder = builder("Class");
-
-        builder.hashCode(100);
-
-        UUID[] arr = new UUID[] {UUID.randomUUID(), UUID.randomUUID()};
-
-        builder.setField("uuidArrayField", arr);
-
-        BinaryObject po = builder.build();
-
-        assertEquals("class".hashCode(), po.type().typeId());
-        assertEquals(100, po.hashCode());
-
-        assertTrue(Arrays.equals(arr, po.<UUID[]>field("uuidArrayField")));
-    }
-
-    /**
-     * @throws Exception If failed.
-     */
-    public void testObjectField() throws Exception {
-        BinaryObjectBuilder builder = builder("Class");
-
-        builder.hashCode(100);
-
-        builder.setField("objectField", new Value(1));
-
-        BinaryObject po = builder.build();
-
-        assertEquals("class".hashCode(), po.type().typeId());
-        assertEquals(100, po.hashCode());
-
-        assertEquals(1, po.<BinaryObject>field("objectField").<Value>deserialize().i);
-    }
-
-    /**
-     * @throws Exception If failed.
-     */
-    public void testObjectArrayField() throws Exception {
-        BinaryObjectBuilder builder = builder("Class");
-
-        builder.hashCode(100);
-
-        builder.setField("objectArrayField", new Value[] {new Value(1), new Value(2)});
-
-        BinaryObject po = builder.build();
-
-        assertEquals("class".hashCode(), po.type().typeId());
-        assertEquals(100, po.hashCode());
-
-        Object[] arr = po.field("objectArrayField");
-
-        assertEquals(2, arr.length);
-
-        assertEquals(1, ((BinaryObject)arr[0]).<Value>deserialize().i);
-        assertEquals(2, ((BinaryObject)arr[1]).<Value>deserialize().i);
-    }
-
-    /**
-     * @throws Exception If failed.
-     */
-    public void testCollectionField() throws Exception {
-        BinaryObjectBuilder builder = builder("Class");
-
-        builder.hashCode(100);
-
-        builder.setField("collectionField", Arrays.asList(new Value(1), new Value(2)));
-
-        BinaryObject po = builder.build();
-
-        assertEquals("class".hashCode(), po.type().typeId());
-        assertEquals(100, po.hashCode());
-
-        List<BinaryObject> list = po.field("collectionField");
-
-        assertEquals(2, list.size());
-
-        assertEquals(1, list.get(0).<Value>deserialize().i);
-        assertEquals(2, list.get(1).<Value>deserialize().i);
-    }
-
-    /**
-     * @throws Exception If failed.
-     */
-    public void testMapField() throws Exception {
-        BinaryObjectBuilder builder = builder("Class");
-
-        builder.hashCode(100);
-
-        builder.setField("mapField", F.asMap(new Key(1), new Value(1), new Key(2), new Value(2)));
-
-        BinaryObject po = builder.build();
-
-        assertEquals("class".hashCode(), po.type().typeId());
-        assertEquals(100, po.hashCode());
-
-        Map<BinaryObject, BinaryObject> map = po.field("mapField");
-
-        assertEquals(2, map.size());
-
-        for (Map.Entry<BinaryObject, BinaryObject> e : map.entrySet())
-            assertEquals(e.getKey().<Key>deserialize().i, e.getValue().<Value>deserialize().i);
-    }
-
-    /**
-     * @throws Exception If failed.
-     */
-    public void testSeveralFields() throws Exception {
-        BinaryObjectBuilder builder = builder("Class");
-
-        builder.hashCode(100);
-
-        builder.setField("i", 111);
-        builder.setField("f", 111.111f);
-        builder.setField("iArr", new int[] {1, 2, 3});
-        builder.setField("obj", new Key(1));
-        builder.setField("col", Arrays.asList(new Value(1), new Value(2)));
-
-        BinaryObject po = builder.build();
-
-        assertEquals("class".hashCode(), po.type().typeId());
-        assertEquals(100, po.hashCode());
-
-        assertEquals(111, po.<Integer>field("i").intValue());
-        assertEquals(111.111f, po.<Float>field("f").floatValue(), 0);
-        assertTrue(Arrays.equals(new int[] {1, 2, 3}, po.<int[]>field("iArr")));
-        assertEquals(1, po.<BinaryObject>field("obj").<Key>deserialize().i);
-
-        List<BinaryObject> list = po.field("col");
-
-        assertEquals(2, list.size());
-
-        assertEquals(1, list.get(0).<Value>deserialize().i);
-        assertEquals(2, list.get(1).<Value>deserialize().i);
-    }
-
-    /**
-     * @throws Exception If failed.
-     */
-    public void testOffheapPortable() throws Exception {
-        BinaryObjectBuilder builder = builder("Class");
-
-        builder.hashCode(100);
-
-        builder.setField("i", 111);
-        builder.setField("f", 111.111f);
-        builder.setField("iArr", new int[] {1, 2, 3});
-        builder.setField("obj", new Key(1));
-        builder.setField("col", Arrays.asList(new Value(1), new Value(2)));
-
-        BinaryObject po = builder.build();
-
-        byte[] arr = ((CacheObjectBinaryProcessorImpl)(grid(0)).context().cacheObjects()).marshal(po);
-
-        long ptr = UNSAFE.allocateMemory(arr.length + 5);
-
-        try {
-            long ptr0 = ptr;
-
-            UNSAFE.putBoolean(null, ptr0++, false);
-
-            UNSAFE.putInt(ptr0, arr.length);
-
-            UNSAFE.copyMemory(arr, BYTE_ARR_OFF, null, ptr0 + 4, arr.length);
-
-            BinaryObject offheapObj = (BinaryObject)
-                ((CacheObjectBinaryProcessorImpl)(grid(0)).context().cacheObjects()).unmarshal(ptr, false);
-
-            assertEquals(BinaryObjectOffheapImpl.class, offheapObj.getClass());
-
-            assertEquals("class".hashCode(), offheapObj.type().typeId());
-            assertEquals(100, offheapObj.hashCode());
-
-            assertEquals(111, offheapObj.<Integer>field("i").intValue());
-            assertEquals(111.111f, offheapObj.<Float>field("f").floatValue(), 0);
-            assertTrue(Arrays.equals(new int[] {1, 2, 3}, offheapObj.<int[]>field("iArr")));
-            assertEquals(1, offheapObj.<BinaryObject>field("obj").<Key>deserialize().i);
-
-            List<BinaryObject> list = offheapObj.field("col");
-
-            assertEquals(2, list.size());
-
-            assertEquals(1, list.get(0).<Value>deserialize().i);
-            assertEquals(2, list.get(1).<Value>deserialize().i);
-
-            assertEquals(po, offheapObj);
-            assertEquals(offheapObj, po);
-        }
-        finally {
-            UNSAFE.freeMemory(ptr);
-        }
-    }
-
-    /**
-     * @throws Exception If failed.
-     */
-    public void testBuildAndDeserialize() throws Exception {
-        BinaryObjectBuilder builder = builder(Value.class.getName());
-
-        builder.hashCode(100);
-
-        builder.setField("i", 1);
-
-        BinaryObject po = builder.build();
-
-        assertEquals("value".hashCode(), po.type().typeId());
-        assertEquals(100, po.hashCode());
-
-        assertEquals(1, po.<Value>deserialize().i);
-    }
-
-    /**
-     * @throws Exception If failed.
-     */
-    public void testMetaData2() throws Exception {
-        BinaryObjectBuilder builder = builder("org.test.MetaTest2");
-
-        builder.setField("objectField", "a", Object.class);
-
-        BinaryObject po = builder.build();
-
-        BinaryType meta = po.type();
-
-        assertEquals("MetaTest2", meta.typeName());
-        assertEquals("Object", meta.fieldTypeName("objectField"));
-    }
-
-    /**
-     * @throws Exception If failed.
-     */
-    public void testMetaData() throws Exception {
-        BinaryObjectBuilder builder = builder("org.test.MetaTest");
-
-        builder.hashCode(100);
-
-        builder.setField("intField", 1);
-        builder.setField("byteArrayField", new byte[] {1, 2, 3});
-
-        BinaryObject po = builder.build();
-
-        BinaryType meta = po.type();
-
-        assertEquals("MetaTest", meta.typeName());
-
-        Collection<String> fields = meta.fieldNames();
-
-        assertEquals(2, fields.size());
-
-        assertTrue(fields.contains("intField"));
-        assertTrue(fields.contains("byteArrayField"));
-
-        assertEquals("int", meta.fieldTypeName("intField"));
-        assertEquals("byte[]", meta.fieldTypeName("byteArrayField"));
-
-        builder = builder("org.test.MetaTest");
-
-        builder.hashCode(100);
-
-        builder.setField("intField", 2);
-        builder.setField("uuidField", UUID.randomUUID());
-
-        po = builder.build();
-
-        meta = po.type();
-
-        assertEquals("MetaTest", meta.typeName());
-
-        fields = meta.fieldNames();
-
-        assertEquals(3, fields.size());
-
-        assertTrue(fields.contains("intField"));
-        assertTrue(fields.contains("byteArrayField"));
-        assertTrue(fields.contains("uuidField"));
-
-        assertEquals("int", meta.fieldTypeName("intField"));
-        assertEquals("byte[]", meta.fieldTypeName("byteArrayField"));
-        assertEquals("UUID", meta.fieldTypeName("uuidField"));
-    }
-
-    /**
-     *
-     */
-    public void testGetFromCopiedObj() {
-        BinaryObject objStr = builder(TestObjectAllTypes.class.getName()).setField("str", "aaa").build();
-
-        BinaryObjectBuilderImpl builder = builder(objStr);
-        assertEquals("aaa", builder.getField("str"));
-
-        builder.setField("str", "bbb");
-        assertEquals("bbb", builder.getField("str"));
-
-        assertNull(builder.getField("i_"));
-        assertEquals("bbb", builder.build().<TestObjectAllTypes>deserialize().str);
-    }
-
-    /**
-     *
-     */
-    @SuppressWarnings("unchecked")
-    public void testCopyFromInnerObjects() {
-        ArrayList<Object> list = new ArrayList<>();
-        list.add(new TestObjectAllTypes());
-        list.add(list.get(0));
-
-        TestObjectContainer c = new TestObjectContainer(list);
-
-        BinaryObjectBuilderImpl builder = builder(toPortable(c));
-        builder.<List>getField("foo").add("!!!");
-
-        BinaryObject res = builder.build();
-
-        TestObjectContainer deserialized = res.deserialize();
-
-        List deserializedList = (List)deserialized.foo;
-
-        assertSame(deserializedList.get(0), deserializedList.get(1));
-        assertEquals("!!!", deserializedList.get(2));
-        assertTrue(deserializedList.get(0) instanceof TestObjectAllTypes);
-    }
-
-    /**
-     *
-     */
-    public void testSetPortableObject() {
-        BinaryObject portableObj = builder(TestObjectContainer.class.getName())
-            .setField("foo", toPortable(new TestObjectAllTypes()))
-            .build();
-
-        assertTrue(portableObj.<TestObjectContainer>deserialize().foo instanceof TestObjectAllTypes);
-    }
-
-    /**
-     *
-     */
-    public void testPlainPortableObjectCopyFrom() {
-        TestObjectPlainPortable obj = new TestObjectPlainPortable(toPortable(new TestObjectAllTypes()));
-
-        BinaryObjectBuilderImpl builder = builder(toPortable(obj));
-        assertTrue(builder.getField("plainPortable") instanceof BinaryObject);
-
-        TestObjectPlainPortable deserialized = builder.build().deserialize();
-        assertTrue(deserialized.plainPortable != null);
-    }
-
-    /**
-     *
-     */
-    public void testRemoveFromNewObject() {
-        BinaryObjectBuilder builder = builder(TestObjectAllTypes.class.getName());
-
-        builder.setField("str", "a");
-
-        builder.removeField("str");
-
-        assertNull(builder.build().<TestObjectAllTypes>deserialize().str);
-    }
-
-    /**
-     *
-     */
-    public void testRemoveFromExistingObject() {
-        TestObjectAllTypes obj = new TestObjectAllTypes();
-        obj.setDefaultData();
-        obj.enumArr = null;
-
-        BinaryObjectBuilder builder = builder(toPortable(obj));
-
-        builder.removeField("str");
-
-        BinaryObject binary = builder.build();
-
-        TestObjectAllTypes deserialzied = binary.deserialize();
-
-        assertNull(deserialzied.str);
-    }
-
-    /**
-     *
-     */
-    public void testRemoveFromExistingObjectAfterGet() {
-        TestObjectAllTypes obj = new TestObjectAllTypes();
-        obj.setDefaultData();
-        obj.enumArr = null;
-
-        BinaryObjectBuilderImpl builder = builder(toPortable(obj));
-
-        builder.getField("i_");
-
-        builder.removeField("str");
-
-        assertNull(builder.build().<TestObjectAllTypes>deserialize().str);
-    }
-
-    /**
-     * @throws IgniteCheckedException If any error occurs.
-     */
-    public void testDontBrokeCyclicDependency() throws IgniteCheckedException {
-        TestObjectOuter outer = new TestObjectOuter();
-        outer.inner = new TestObjectInner();
-        outer.inner.outer = outer;
-        outer.foo = "a";
-
-        BinaryObjectBuilder builder = builder(toPortable(outer));
-
-        builder.setField("foo", "b");
-
-        TestObjectOuter res = builder.build().deserialize();
-
-        assertEquals("b", res.foo);
-        assertSame(res, res.inner.outer);
-    }
-
-    /**
-     * @return Portables.
-     */
-    private IgniteBinary portables() {
-        return grid(0).binary();
-    }
-
-    /**
-     * @param obj Object.
-     * @return Portable object.
-     */
-    private BinaryObject toPortable(Object obj) {
-        return portables().toBinary(obj);
-    }
-
-    /**
-     * @return Builder.
-     */
-    private BinaryObjectBuilder builder(String clsName) {
-        return portables().builder(clsName);
-    }
-
-    /**
-     * @return Builder.
-     */
-    private BinaryObjectBuilderImpl builder(BinaryObject obj) {
-        return (BinaryObjectBuilderImpl)portables().builder(obj);
-    }
-
-    /**
-     *
-     */
-    @SuppressWarnings("UnusedDeclaration")
-    private static class CustomIdMapper {
-        /** */
-        private String str = "a";
-
-        /** */
-        private int i = 10;
-    }
-
-    /**
-     */
-    @SuppressWarnings("UnusedDeclaration")
-    private static class Key {
-        /** */
-        private int i;
-
-        /**
-         */
-        private Key() {
-            // No-op.
-        }
-
-        /**
-         * @param i Index.
-         */
-        private Key(int i) {
-            this.i = i;
-        }
-
-        /** {@inheritDoc} */
-        @Override public boolean equals(Object o) {
-            if (this == o)
-                return true;
-
-            if (o == null || getClass() != o.getClass())
-                return false;
-
-            Key key = (Key)o;
-
-            return i == key.i;
-        }
-
-        /** {@inheritDoc} */
-        @Override public int hashCode() {
-            return i;
-        }
-    }
-
-    /**
-     */
-    @SuppressWarnings("UnusedDeclaration")
-    private static class Value {
-        /** */
-        private int i;
-
-        /**
-         */
-        private Value() {
-            // No-op.
-        }
-
-        /**
-         * @param i Index.
-         */
-        private Value(int i) {
-            this.i = i;
-        }
-    }
-}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ignite/blob/1dbf20e0/modules/core/src/test/java/org/apache/ignite/internal/portable/GridPortableAffinityKeySelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/portable/GridPortableAffinityKeySelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/portable/GridPortableAffinityKeySelfTest.java
deleted file mode 100644
index c77bd3d..0000000
--- a/modules/core/src/test/java/org/apache/ignite/internal/portable/GridPortableAffinityKeySelfTest.java
+++ /dev/null
@@ -1,234 +0,0 @@
-/*
- * 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.portable;
-
-import java.util.Collections;
-import java.util.UUID;
-import java.util.concurrent.atomic.AtomicReference;
-import org.apache.ignite.Ignite;
-import org.apache.ignite.binary.BinaryObjectBuilder;
-import org.apache.ignite.cache.CacheKeyConfiguration;
-import org.apache.ignite.cache.affinity.Affinity;
-import org.apache.ignite.configuration.BinaryConfiguration;
-import org.apache.ignite.configuration.CacheConfiguration;
-import org.apache.ignite.configuration.IgniteConfiguration;
-import org.apache.ignite.internal.IgniteKernal;
-import org.apache.ignite.internal.processors.affinity.GridAffinityProcessor;
-import org.apache.ignite.internal.processors.cache.CacheObject;
-import org.apache.ignite.internal.processors.cache.CacheObjectContext;
-import org.apache.ignite.internal.processors.cacheobject.IgniteCacheObjectProcessor;
-import org.apache.ignite.lang.IgniteCallable;
-import org.apache.ignite.lang.IgniteRunnable;
-import org.apache.ignite.binary.BinaryTypeConfiguration;
-import org.apache.ignite.resources.IgniteInstanceResource;
-import org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi;
-import org.apache.ignite.spi.discovery.tcp.ipfinder.TcpDiscoveryIpFinder;
-import org.apache.ignite.spi.discovery.tcp.ipfinder.vm.TcpDiscoveryVmIpFinder;
-import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
-
-import static org.apache.ignite.cache.CacheMode.PARTITIONED;
-
-/**
- * Test for portable object affinity key.
- */
-public class GridPortableAffinityKeySelfTest extends GridCommonAbstractTest {
-    /** */
-    private static final AtomicReference<UUID> nodeId = new AtomicReference<>();
-
-    /** VM ip finder for TCP discovery. */
-    private static TcpDiscoveryIpFinder ipFinder = new TcpDiscoveryVmIpFinder(true);
-
-    /** */
-    private static int GRID_CNT = 5;
-
-    /** {@inheritDoc} */
-    @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception {
-        IgniteConfiguration cfg = super.getConfiguration(gridName);
-
-        BinaryTypeConfiguration typeCfg = new BinaryTypeConfiguration();
-
-        typeCfg.setTypeName(TestObject.class.getName());
-
-        BinaryConfiguration bCfg = new BinaryConfiguration();
-
-        bCfg.setTypeConfigurations(Collections.singleton(typeCfg));
-
-        cfg.setBinaryConfiguration(bCfg);
-
-        CacheKeyConfiguration keyCfg = new CacheKeyConfiguration(TestObject.class.getName(), "affKey");
-        CacheKeyConfiguration keyCfg2 = new CacheKeyConfiguration("TestObject2", "affKey");
-
-        cfg.setCacheKeyConfiguration(keyCfg, keyCfg2);
-
-        cfg.setMarshaller(new BinaryMarshaller());
-
-        if (!gridName.equals(getTestGridName(GRID_CNT))) {
-            CacheConfiguration cacheCfg = new CacheConfiguration();
-
-            cacheCfg.setCacheMode(PARTITIONED);
-
-            cfg.setCacheConfiguration(cacheCfg);
-        }
-
-        ((TcpDiscoverySpi)cfg.getDiscoverySpi()).setIpFinder(ipFinder);
-
-        return cfg;
-    }
-
-    /** {@inheritDoc} */
-    @Override protected void beforeTestsStarted() throws Exception {
-        startGridsMultiThreaded(GRID_CNT);
-    }
-
-    /** {@inheritDoc} */
-    @Override protected void afterTestsStopped() throws Exception {
-        stopAllGrids();
-    }
-
-    /**
-     * @throws Exception If failed.
-     */
-    public void testAffinity() throws Exception {
-        checkAffinity(grid(0));
-
-        try (Ignite igniteNoCache = startGrid(GRID_CNT)) {
-            try {
-                igniteNoCache.cache(null);
-            }
-            catch (IllegalArgumentException ignore) {
-                // Expected error.
-            }
-
-            checkAffinity(igniteNoCache);
-        }
-    }
-
-    /**
-     * @param ignite Ignite.
-     * @throws Exception If failed.
-     */
-    private void checkAffinity(Ignite ignite) throws Exception {
-        Affinity<Object> aff = ignite.affinity(null);
-
-        GridAffinityProcessor affProc = ((IgniteKernal)ignite).context().affinity();
-
-        IgniteCacheObjectProcessor cacheObjProc = ((IgniteKernal)ignite).context().cacheObjects();
-
-        CacheObjectContext cacheObjCtx = cacheObjProc.contextForCache(
-            ignite.cache(null).getConfiguration(CacheConfiguration.class));
-
-        for (int i = 0; i < 1000; i++) {
-            assertEquals(i, aff.affinityKey(i));
-
-            assertEquals(i, aff.affinityKey(new TestObject(i)));
-
-            assertEquals(i, aff.affinityKey(ignite.binary().toBinary(new TestObject(i))));
-
-            BinaryObjectBuilder bldr = ignite.binary().builder("TestObject2");
-
-            bldr.setField("affKey", i);
-
-            assertEquals(i, aff.affinityKey(bldr.build()));
-
-            CacheObject cacheObj = cacheObjProc.toCacheObject(cacheObjCtx, new TestObject(i), true);
-
-            assertEquals(i, aff.affinityKey(cacheObj));
-
-            assertEquals(aff.mapKeyToNode(i), aff.mapKeyToNode(new TestObject(i)));
-
-            assertEquals(aff.mapKeyToNode(i), aff.mapKeyToNode(cacheObj));
-
-            assertEquals(i, affProc.affinityKey(null, i));
-
-            assertEquals(i, affProc.affinityKey(null, new TestObject(i)));
-
-            assertEquals(i, affProc.affinityKey(null, cacheObj));
-
-            assertEquals(affProc.mapKeyToNode(null, i), affProc.mapKeyToNode(null, new TestObject(i)));
-
-            assertEquals(affProc.mapKeyToNode(null, i), affProc.mapKeyToNode(null, cacheObj));
-        }
-    }
-
-    /**
-     * @throws Exception If failed.
-     */
-    public void testAffinityRun() throws Exception {
-        Affinity<Object> aff = grid(0).affinity(null);
-
-        for (int i = 0; i < 1000; i++) {
-            nodeId.set(null);
-
-            grid(0).compute().affinityRun(null, new TestObject(i), new IgniteRunnable() {
-                @IgniteInstanceResource
-                private Ignite ignite;
-
-                @Override public void run() {
-                    nodeId.set(ignite.configuration().getNodeId());
-                }
-            });
-
-            assertEquals(aff.mapKeyToNode(i).id(), nodeId.get());
-        }
-    }
-
-    /**
-     * @throws Exception If failed.
-     */
-    public void testAffinityCall() throws Exception {
-        Affinity<Object> aff = grid(0).affinity(null);
-
-        for (int i = 0; i < 1000; i++) {
-            nodeId.set(null);
-
-            grid(0).compute().affinityCall(null, new TestObject(i), new IgniteCallable<Object>() {
-                @IgniteInstanceResource
-                private Ignite ignite;
-
-                @Override public Object call() {
-                    nodeId.set(ignite.configuration().getNodeId());
-
-                    return null;
-                }
-            });
-
-            assertEquals(aff.mapKeyToNode(i).id(), nodeId.get());
-        }
-    }
-
-    /**
-     */
-    private static class TestObject {
-        /** */
-        @SuppressWarnings("UnusedDeclaration")
-        private int affKey;
-
-        /**
-         */
-        private TestObject() {
-            // No-op.
-        }
-
-        /**
-         * @param affKey Affinity key.
-         */
-        private TestObject(int affKey) {
-            this.affKey = affKey;
-        }
-    }
-}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ignite/blob/1dbf20e0/modules/core/src/test/java/org/apache/ignite/internal/portable/GridPortableMarshallerCtxDisabledSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/portable/GridPortableMarshallerCtxDisabledSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/portable/GridPortableMarshallerCtxDisabledSelfTest.java
deleted file mode 100644
index 346cf80..0000000
--- a/modules/core/src/test/java/org/apache/ignite/internal/portable/GridPortableMarshallerCtxDisabledSelfTest.java
+++ /dev/null
@@ -1,247 +0,0 @@
-/*
- * 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.portable;
-
-import org.apache.ignite.IgniteCheckedException;
-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.configuration.IgniteConfiguration;
-import org.apache.ignite.internal.MarshallerContextAdapter;
-import org.apache.ignite.internal.util.IgniteUtils;
-import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
-
-import java.io.Externalizable;
-import java.io.IOException;
-import java.io.ObjectInput;
-import java.io.ObjectOutput;
-import java.util.Arrays;
-
-/**
- *
- */
-public class GridPortableMarshallerCtxDisabledSelfTest extends GridCommonAbstractTest {
-    /**
-     * @throws Exception If failed.
-     */
-    public void testObjectExchange() throws Exception {
-        BinaryMarshaller marsh = new BinaryMarshaller();
-        marsh.setContext(new MarshallerContextWithNoStorage());
-
-        IgniteConfiguration cfg = new IgniteConfiguration();
-
-        PortableContext context = new PortableContext(BinaryCachingMetadataHandler.create(), cfg);
-
-        IgniteUtils.invoke(BinaryMarshaller.class, marsh, "setPortableContext", context, cfg);
-
-        SimpleObject simpleObj = new SimpleObject();
-
-        simpleObj.b = 2;
-        simpleObj.bArr = new byte[] {2, 3, 4, 5, 5};
-        simpleObj.c = 'A';
-        simpleObj.enumVal = TestEnum.D;
-        simpleObj.objArr = new Object[] {"hello", "world", "from", "me"};
-        simpleObj.enumArr = new TestEnum[] {TestEnum.C, TestEnum.B};
-
-        SimpleObject otherObj = new SimpleObject();
-
-        otherObj.b = 3;
-        otherObj.bArr = new byte[] {5, 3, 4};
-
-        simpleObj.otherObj = otherObj;
-
-        assertEquals(simpleObj, marsh.unmarshal(marsh.marshal(simpleObj), null));
-
-        SimpleBinary simplePortable = new SimpleBinary();
-
-        simplePortable.str = "portable";
-        simplePortable.arr = new long[] {100, 200, 300};
-
-        assertEquals(simplePortable, marsh.unmarshal(marsh.marshal(simplePortable), null));
-
-        SimpleExternalizable simpleExtr = new SimpleExternalizable();
-
-        simpleExtr.str = "externalizable";
-        simpleExtr.arr = new long[] {20000, 300000, 400000};
-
-        assertEquals(simpleExtr, marsh.unmarshal(marsh.marshal(simpleExtr), null));
-    }
-
-    /**
-     * Marshaller context with no storage. Platform has to work in such environment as well by marshalling class name of
-     * a portable object.
-     */
-    private static class MarshallerContextWithNoStorage extends MarshallerContextAdapter {
-        /** */
-        public MarshallerContextWithNoStorage() {
-            super(null);
-        }
-
-        /** {@inheritDoc} */
-        @Override protected boolean registerClassName(int id, String clsName) throws IgniteCheckedException {
-            return false;
-        }
-
-        /** {@inheritDoc} */
-        @Override protected String className(int id) throws IgniteCheckedException {
-            return null;
-        }
-    }
-
-    /**
-     */
-    private enum TestEnum {
-        A, B, C, D, E
-    }
-
-    /**
-     */
-    private static class SimpleObject {
-        /** */
-        private byte b;
-
-        /** */
-        private char c;
-
-        /** */
-        private byte[] bArr;
-
-        /** */
-        private Object[] objArr;
-
-        /** */
-        private TestEnum enumVal;
-
-        /** */
-        private TestEnum[] enumArr;
-
-        private SimpleObject otherObj;
-
-        /** {@inheritDoc} */
-        @Override public boolean equals(Object o) {
-            if (this == o)
-                return true;
-
-            if (o == null || getClass() != o.getClass())
-                return false;
-
-            SimpleObject object = (SimpleObject)o;
-
-            if (b != object.b)
-                return false;
-
-            if (c != object.c)
-                return false;
-
-            if (!Arrays.equals(bArr, object.bArr))
-                return false;
-
-            // Probably incorrect - comparing Object[] arrays with Arrays.equals
-            if (!Arrays.equals(objArr, object.objArr))
-                return false;
-
-            if (enumVal != object.enumVal)
-                return false;
-
-            // Probably incorrect - comparing Object[] arrays with Arrays.equals
-            if (!Arrays.equals(enumArr, object.enumArr))
-                return false;
-
-            return !(otherObj != null ? !otherObj.equals(object.otherObj) : object.otherObj != null);
-        }
-    }
-
-    /**
-     *
-     */
-    private static class SimpleBinary implements Binarylizable {
-        /** */
-        private String str;
-
-        /** */
-        private long[] arr;
-
-        /** {@inheritDoc} */
-        @Override public void writeBinary(BinaryWriter writer) throws BinaryObjectException {
-            writer.writeString("str", str);
-            writer.writeLongArray("longArr", arr);
-        }
-
-        /** {@inheritDoc} */
-        @Override public void readBinary(BinaryReader reader) throws BinaryObjectException {
-            str = reader.readString("str");
-            arr = reader.readLongArray("longArr");
-        }
-
-        /** {@inheritDoc} */
-        @Override public boolean equals(Object o) {
-            if (this == o)
-                return true;
-
-            if (o == null || getClass() != o.getClass())
-                return false;
-
-            SimpleBinary that = (SimpleBinary)o;
-
-            if (str != null ? !str.equals(that.str) : that.str != null)
-                return false;
-
-            return Arrays.equals(arr, that.arr);
-        }
-    }
-
-    /**
-     *
-     */
-    private static class SimpleExternalizable implements Externalizable {
-        /** */
-        private String str;
-
-        /** */
-        private long[] arr;
-
-        /** {@inheritDoc} */
-        @Override public void writeExternal(ObjectOutput out) throws IOException {
-            out.writeUTF(str);
-            out.writeObject(arr);
-        }
-
-        /** {@inheritDoc} */
-        @Override public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
-            str = in.readUTF();
-            arr = (long[])in.readObject();
-        }
-
-        /** {@inheritDoc} */
-        @Override public boolean equals(Object o) {
-            if (this == o)
-                return true;
-
-            if (o == null || getClass() != o.getClass())
-                return false;
-
-            SimpleExternalizable that = (SimpleExternalizable)o;
-
-            if (str != null ? !str.equals(that.str) : that.str != null)
-                return false;
-
-            return Arrays.equals(arr, that.arr);
-        }
-    }
-}
\ No newline at end of file


[48/59] [abbrv] ignite git commit: ignite-2065: rename "portable" classes to "binary"

Posted by ak...@apache.org.
http://git-wip-us.apache.org/repos/asf/ignite/blob/71ad9cea/modules/core/src/main/java/org/apache/ignite/internal/binary/builder/BinaryPlainLazyValue.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/binary/builder/BinaryPlainLazyValue.java b/modules/core/src/main/java/org/apache/ignite/internal/binary/builder/BinaryPlainLazyValue.java
new file mode 100644
index 0000000..84e96d3
--- /dev/null
+++ b/modules/core/src/main/java/org/apache/ignite/internal/binary/builder/BinaryPlainLazyValue.java
@@ -0,0 +1,49 @@
+/*
+ * 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.binary.builder;
+
+import org.apache.ignite.internal.binary.BinaryWriterExImpl;
+
+/**
+ *
+ */
+class BinaryPlainLazyValue extends BinaryAbstractLazyValue {
+    /** */
+    protected final int len;
+
+    /**
+     * @param reader Reader
+     * @param valOff Offset
+     * @param len Length.
+     */
+    protected BinaryPlainLazyValue(BinaryBuilderReader reader, int valOff, int len) {
+        super(reader, valOff);
+
+        this.len = len;
+    }
+
+    /** {@inheritDoc} */
+    @Override protected Object init() {
+        return reader.reader().unmarshal(valOff);
+    }
+
+    /** {@inheritDoc} */
+    @Override public void writeTo(BinaryWriterExImpl writer, BinaryBuilderSerializer ctx) {
+        writer.write(reader.array(), valOff, len);
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/71ad9cea/modules/core/src/main/java/org/apache/ignite/internal/binary/builder/BinaryValueWithType.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/binary/builder/BinaryValueWithType.java b/modules/core/src/main/java/org/apache/ignite/internal/binary/builder/BinaryValueWithType.java
new file mode 100644
index 0000000..9f43bdb
--- /dev/null
+++ b/modules/core/src/main/java/org/apache/ignite/internal/binary/builder/BinaryValueWithType.java
@@ -0,0 +1,76 @@
+/*
+ * 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.binary.builder;
+
+import org.apache.ignite.internal.binary.BinaryWriterExImpl;
+import org.apache.ignite.internal.util.typedef.internal.S;
+
+/**
+ *
+ */
+class BinaryValueWithType implements BinaryLazyValue {
+    /** */
+    private byte type;
+
+    /** */
+    private Object val;
+
+    /**
+     * @param type Type
+     * @param val Value.
+     */
+    BinaryValueWithType(byte type, Object val) {
+        this.type = type;
+        this.val = val;
+    }
+
+    /** {@inheritDoc} */
+    @Override public void writeTo(BinaryWriterExImpl writer, BinaryBuilderSerializer ctx) {
+        if (val instanceof BinaryBuilderSerializationAware)
+            ((BinaryBuilderSerializationAware)val).writeTo(writer, ctx);
+        else
+            ctx.writeValue(writer, val);
+    }
+
+    /**
+     * @return Type ID.
+     */
+    public int typeId() {
+        return type;
+    }
+
+    /** {@inheritDoc} */
+    @Override public Object value() {
+        if (val instanceof BinaryLazyValue)
+            return ((BinaryLazyValue)val).value();
+
+        return val;
+    }
+
+    /**
+     * @param val New value.
+     */
+    public void value(Object val) {
+        this.val = val;
+    }
+
+    /** {@inheritDoc} */
+    @Override public String toString() {
+        return S.toString(BinaryValueWithType.class, this);
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/71ad9cea/modules/core/src/main/java/org/apache/ignite/internal/binary/builder/PortableAbstractLazyValue.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/binary/builder/PortableAbstractLazyValue.java b/modules/core/src/main/java/org/apache/ignite/internal/binary/builder/PortableAbstractLazyValue.java
deleted file mode 100644
index 0b6cc0a..0000000
--- a/modules/core/src/main/java/org/apache/ignite/internal/binary/builder/PortableAbstractLazyValue.java
+++ /dev/null
@@ -1,57 +0,0 @@
-/*
- * 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.binary.builder;
-
-/**
- *
- */
-abstract class PortableAbstractLazyValue implements PortableLazyValue {
-    /** */
-    protected Object val;
-
-    /** */
-    protected final PortableBuilderReader reader;
-
-    /** */
-    protected final int valOff;
-
-    /**
-     * @param reader Reader.
-     * @param valOff Value.
-     */
-    protected PortableAbstractLazyValue(PortableBuilderReader reader, int valOff) {
-        this.reader = reader;
-        this.valOff = valOff;
-    }
-
-    /**
-     * @return Value.
-     */
-    protected abstract Object init();
-
-    /** {@inheritDoc} */
-    @Override public Object value() {
-        if (val == null) {
-            val = init();
-
-            assert val != null;
-        }
-
-        return val;
-    }
-}

http://git-wip-us.apache.org/repos/asf/ignite/blob/71ad9cea/modules/core/src/main/java/org/apache/ignite/internal/binary/builder/PortableBuilderEnum.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/binary/builder/PortableBuilderEnum.java b/modules/core/src/main/java/org/apache/ignite/internal/binary/builder/PortableBuilderEnum.java
deleted file mode 100644
index 779c514..0000000
--- a/modules/core/src/main/java/org/apache/ignite/internal/binary/builder/PortableBuilderEnum.java
+++ /dev/null
@@ -1,115 +0,0 @@
-/*
- * 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.binary.builder;
-
-import org.apache.ignite.internal.binary.GridPortableMarshaller;
-import org.apache.ignite.internal.binary.BinaryWriterExImpl;
-import org.apache.ignite.internal.util.typedef.internal.U;
-import org.apache.ignite.binary.BinaryInvalidTypeException;
-
-/**
- *
- */
-public class PortableBuilderEnum implements PortableBuilderSerializationAware {
-    /** */
-    private final int ordinal;
-
-    /** */
-    private final int typeId;
-
-    /** */
-    private final String clsName;
-
-    /**
-     * @param typeId Type ID.
-     * @param anEnum Enum instance.
-     */
-    public PortableBuilderEnum(int typeId, Enum anEnum) {
-        ordinal = anEnum.ordinal();
-        this.typeId = typeId;
-        clsName = null;
-    }
-
-    /**
-     * @param reader PortableBuilderReader.
-     */
-    public PortableBuilderEnum(PortableBuilderReader reader) {
-        int typeId = reader.readInt();
-
-        if (typeId == GridPortableMarshaller.UNREGISTERED_TYPE_ID) {
-            clsName = reader.readString();
-
-            Class cls;
-
-            try {
-                cls = U.forName(reader.readString(), reader.portableContext().configuration().getClassLoader());
-            }
-            catch (ClassNotFoundException e) {
-                throw new BinaryInvalidTypeException("Failed to load the class: " + clsName, e);
-            }
-
-            this.typeId = reader.portableContext().descriptorForClass(cls, false).typeId();
-        }
-        else {
-            this.typeId = typeId;
-            this.clsName = null;
-        }
-
-        ordinal = reader.readInt();
-    }
-
-    /**
-     * @return Ordinal.
-     */
-    public int getOrdinal() {
-        return ordinal;
-    }
-
-    /** {@inheritDoc} */
-    @Override public void writeTo(BinaryWriterExImpl writer, PortableBuilderSerializer ctx) {
-        writer.writeByte(GridPortableMarshaller.ENUM);
-
-        if (typeId == GridPortableMarshaller.UNREGISTERED_TYPE_ID) {
-            writer.writeInt(GridPortableMarshaller.UNREGISTERED_TYPE_ID);
-            writer.writeString(clsName);
-        }
-        else
-            writer.writeInt(typeId);
-
-        writer.writeInt(ordinal);
-    }
-
-    /** {@inheritDoc} */
-    @Override public boolean equals(Object o) {
-        if (o == null || getClass() != o.getClass())
-            return false;
-
-        PortableBuilderEnum that = (PortableBuilderEnum)o;
-
-        return ordinal == that.ordinal && typeId == that.typeId;
-    }
-
-    /** {@inheritDoc} */
-    @Override public int hashCode() {
-        int result = ordinal;
-
-        result = 31 * result + typeId;
-
-        return result;
-    }
-}

http://git-wip-us.apache.org/repos/asf/ignite/blob/71ad9cea/modules/core/src/main/java/org/apache/ignite/internal/binary/builder/PortableBuilderReader.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/binary/builder/PortableBuilderReader.java b/modules/core/src/main/java/org/apache/ignite/internal/binary/builder/PortableBuilderReader.java
deleted file mode 100644
index c86fb95..0000000
--- a/modules/core/src/main/java/org/apache/ignite/internal/binary/builder/PortableBuilderReader.java
+++ /dev/null
@@ -1,857 +0,0 @@
-/*
- * 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.binary.builder;
-
-import org.apache.ignite.binary.BinaryObjectException;
-import org.apache.ignite.internal.binary.BinaryObjectImpl;
-import org.apache.ignite.internal.binary.BinaryReaderExImpl;
-import org.apache.ignite.internal.binary.BinaryWriterExImpl;
-import org.apache.ignite.internal.binary.GridPortableMarshaller;
-import org.apache.ignite.internal.binary.PortableContext;
-import org.apache.ignite.internal.binary.PortablePositionReadable;
-import org.apache.ignite.internal.binary.PortablePrimitives;
-import org.apache.ignite.internal.binary.PortableSchema;
-import org.apache.ignite.internal.binary.streams.PortableHeapInputStream;
-import org.apache.ignite.internal.binary.BinaryObjectImpl;
-import org.apache.ignite.internal.binary.BinaryReaderExImpl;
-import org.apache.ignite.internal.binary.BinaryWriterExImpl;
-import org.apache.ignite.internal.binary.GridPortableMarshaller;
-import org.apache.ignite.internal.binary.PortableContext;
-import org.apache.ignite.internal.binary.PortablePositionReadable;
-import org.apache.ignite.internal.binary.PortablePrimitives;
-import org.apache.ignite.internal.binary.PortableSchema;
-import org.apache.ignite.internal.binary.PortableUtils;
-import org.apache.ignite.internal.binary.streams.PortableHeapInputStream;
-
-import java.sql.Timestamp;
-import java.util.Date;
-import java.util.HashMap;
-import java.util.Map;
-
-import static java.nio.charset.StandardCharsets.UTF_8;
-import static org.apache.ignite.internal.binary.GridPortableMarshaller.NULL;
-import static org.apache.ignite.internal.binary.GridPortableMarshaller.STRING;
-
-/**
- *
- */
-public class PortableBuilderReader implements PortablePositionReadable {
-    /** */
-    private final PortableContext ctx;
-
-    /** */
-    private final byte[] arr;
-
-    /** */
-    private final BinaryReaderExImpl reader;
-
-    /** */
-    private final Map<Integer, BinaryObjectBuilderImpl> objMap;
-
-    /** */
-    private int pos;
-
-    /*
-     * Constructor.
-     *
-     * @param objImpl Portable object
-     */
-    PortableBuilderReader(BinaryObjectImpl objImpl) {
-        ctx = objImpl.context();
-        arr = objImpl.array();
-        pos = objImpl.start();
-
-        reader = new BinaryReaderExImpl(ctx,
-            PortableHeapInputStream.create(arr, pos),
-            ctx.configuration().getClassLoader());
-
-        objMap = new HashMap<>();
-    }
-
-    /**
-     * Copying constructor.
-     *
-     * @param other Other reader.
-     * @param start Start position.
-     */
-    PortableBuilderReader(PortableBuilderReader other, int start) {
-        this.ctx = other.ctx;
-        this.arr = other.arr;
-        this.pos = start;
-
-        reader = new BinaryReaderExImpl(ctx, PortableHeapInputStream.create(arr, start), null, other.reader.handles());
-
-        this.objMap = other.objMap;
-    }
-
-    /**
-     * @return Portable context.
-     */
-    public PortableContext portableContext() {
-        return ctx;
-    }
-
-    /**
-     * @param obj Mutable portable object.
-     */
-    public void registerObject(BinaryObjectBuilderImpl obj) {
-        objMap.put(obj.start(), obj);
-    }
-
-    /**
-     * Get schema of the object, starting at the given position.
-     *
-     * @return Object's schema.
-     */
-    public PortableSchema schema() {
-        return reader.getOrCreateSchema();
-    }
-
-    /**
-     * @return Read int value.
-     */
-    public int readInt() {
-        int res = readInt(0);
-
-        pos += 4;
-
-        return res;
-    }
-
-    /**
-     * @return Read int value.
-     */
-    public byte readByte() {
-        return arr[pos++];
-    }
-
-    /**
-     * @return Read boolean value.
-     */
-    public boolean readBoolean() {
-        return readByte() == 1;
-    }
-
-    /**
-     * @return Read int value.
-     */
-    public byte readByte(int off) {
-        return arr[pos + off];
-    }
-
-    /**
-     * @param off Offset related to {@link #pos}
-     * @return Read int value.
-     */
-    public int readInt(int off) {
-        return PortablePrimitives.readInt(arr, pos + off);
-    }
-
-    /**
-     * @param pos Position in the source array.
-     * @return Read byte value.
-     */
-    public byte readBytePositioned(int pos) {
-        return PortablePrimitives.readByte(arr, pos);
-    }
-
-    /** {@inheritDoc} */
-    @Override public short readShortPositioned(int pos) {
-        return PortablePrimitives.readShort(arr, pos);
-    }
-
-    /** {@inheritDoc} */
-    @Override public int readIntPositioned(int pos) {
-        return PortablePrimitives.readInt(arr, pos);
-    }
-
-    /**
-     * @return Read length of array.
-     */
-    public int readLength() {
-        return PortablePrimitives.readInt(arr, pos);
-    }
-
-    /**
-     * Read string length.
-     *
-     * @return String length.
-     */
-    public int readStringLength() {
-        return PortablePrimitives.readInt(arr, pos);
-    }
-
-    /**
-     * Reads string.
-     *
-     * @return String.
-     */
-    public String readString() {
-        byte flag = readByte();
-
-        if (flag == GridPortableMarshaller.NULL)
-            return null;
-
-        if (flag != GridPortableMarshaller.STRING)
-            throw new BinaryObjectException("Failed to deserialize String.");
-
-        int len = readInt();
-
-        String str = new String(arr, pos, len, UTF_8);
-
-        pos += len;
-
-        return str;
-    }
-
-    /**
-     *
-     */
-    public void skipValue() {
-        byte type = arr[pos++];
-
-        int len;
-
-        switch (type) {
-            case GridPortableMarshaller.NULL:
-                return;
-
-            case GridPortableMarshaller.OBJ:
-                pos += readInt(GridPortableMarshaller.TOTAL_LEN_POS - 1) - 1;
-
-                return;
-
-            case GridPortableMarshaller.BOOLEAN:
-            case GridPortableMarshaller.BYTE:
-                len = 1;
-                break;
-
-            case GridPortableMarshaller.CHAR:
-            case GridPortableMarshaller.SHORT:
-                len = 2;
-
-                break;
-
-            case GridPortableMarshaller.HANDLE:
-            case GridPortableMarshaller.FLOAT:
-            case GridPortableMarshaller.INT:
-                len = 4;
-
-                break;
-
-            case GridPortableMarshaller.ENUM:
-                //skipping type id and ordinal value
-                len = 8;
-
-                break;
-
-            case GridPortableMarshaller.LONG:
-            case GridPortableMarshaller.DOUBLE:
-                len = 8;
-
-                break;
-
-            case GridPortableMarshaller.BYTE_ARR:
-            case GridPortableMarshaller.BOOLEAN_ARR:
-                len = 4 + readLength();
-
-                break;
-
-            case GridPortableMarshaller.STRING:
-                len = 4 + readStringLength();
-
-                break;
-
-            case GridPortableMarshaller.DECIMAL:
-                len = /** scale */ 4  + /** mag len */ 4  + /** mag bytes count */ readInt(4);
-
-                break;
-
-            case GridPortableMarshaller.UUID:
-                len = 8 + 8;
-
-                break;
-
-            case GridPortableMarshaller.DATE:
-                len = 8;
-
-                break;
-
-            case GridPortableMarshaller.TIMESTAMP:
-                len = 8 + 4;
-
-                break;
-
-            case GridPortableMarshaller.CHAR_ARR:
-            case GridPortableMarshaller.SHORT_ARR:
-                len = 4 + readLength() * 2;
-
-                break;
-
-            case GridPortableMarshaller.INT_ARR:
-            case GridPortableMarshaller.FLOAT_ARR:
-                len = 4 + readLength() * 4;
-
-                break;
-
-            case GridPortableMarshaller.LONG_ARR:
-            case GridPortableMarshaller.DOUBLE_ARR:
-                len = 4 + readLength() * 8;
-
-                break;
-
-            case GridPortableMarshaller.DECIMAL_ARR:
-            case GridPortableMarshaller.DATE_ARR:
-            case GridPortableMarshaller.TIMESTAMP_ARR:
-            case GridPortableMarshaller.OBJ_ARR:
-            case GridPortableMarshaller.ENUM_ARR:
-            case GridPortableMarshaller.UUID_ARR:
-            case GridPortableMarshaller.STRING_ARR: {
-                int size = readInt();
-
-                for (int i = 0; i < size; i++)
-                    skipValue();
-
-                return;
-            }
-
-            case GridPortableMarshaller.COL: {
-                int size = readInt();
-
-                pos++; // skip collection type
-
-                for (int i = 0; i < size; i++)
-                    skipValue();
-
-                return;
-            }
-
-            case GridPortableMarshaller.MAP: {
-                int size = readInt();
-
-                pos++; // skip collection type
-
-                for (int i = 0; i < size; i++) {
-                    skipValue(); // skip key.
-                    skipValue(); // skip value.
-                }
-
-                return;
-            }
-
-            case GridPortableMarshaller.PORTABLE_OBJ:
-                len = readInt() + 4;
-
-                break;
-
-            default:
-                throw new BinaryObjectException("Invalid flag value: " + type);
-        }
-
-        pos += len;
-    }
-
-    /**
-     * @param pos Position.
-     * @param len Length.
-     * @return Object.
-     */
-    public Object getValueQuickly(int pos, int len) {
-        byte type = arr[pos];
-
-        switch (type) {
-            case GridPortableMarshaller.NULL:
-                return null;
-
-            case GridPortableMarshaller.HANDLE: {
-                int objStart = pos - readIntPositioned(pos + 1);
-
-                BinaryObjectBuilderImpl res = objMap.get(objStart);
-
-                if (res == null) {
-                    res = new BinaryObjectBuilderImpl(new PortableBuilderReader(this, objStart), objStart);
-
-                    objMap.put(objStart, res);
-                }
-
-                return res;
-            }
-
-            case GridPortableMarshaller.OBJ: {
-                BinaryObjectBuilderImpl res = objMap.get(pos);
-
-                if (res == null) {
-                    res = new BinaryObjectBuilderImpl(new PortableBuilderReader(this, pos), pos);
-
-                    objMap.put(pos, res);
-                }
-
-                return res;
-            }
-
-            case GridPortableMarshaller.BYTE:
-                return arr[pos + 1];
-
-            case GridPortableMarshaller.SHORT:
-                return PortablePrimitives.readShort(arr, pos + 1);
-
-            case GridPortableMarshaller.INT:
-                return PortablePrimitives.readInt(arr, pos + 1);
-
-            case GridPortableMarshaller.LONG:
-                return PortablePrimitives.readLong(arr, pos + 1);
-
-            case GridPortableMarshaller.FLOAT:
-                return PortablePrimitives.readFloat(arr, pos + 1);
-
-            case GridPortableMarshaller.DOUBLE:
-                return PortablePrimitives.readDouble(arr, pos + 1);
-
-            case GridPortableMarshaller.CHAR:
-                return PortablePrimitives.readChar(arr, pos + 1);
-
-            case GridPortableMarshaller.BOOLEAN:
-                return arr[pos + 1] != 0;
-
-            case GridPortableMarshaller.DECIMAL:
-            case GridPortableMarshaller.STRING:
-            case GridPortableMarshaller.UUID:
-            case GridPortableMarshaller.DATE:
-            case GridPortableMarshaller.TIMESTAMP:
-                return new PortablePlainLazyValue(this, pos, len);
-
-            case GridPortableMarshaller.BYTE_ARR:
-            case GridPortableMarshaller.SHORT_ARR:
-            case GridPortableMarshaller.INT_ARR:
-            case GridPortableMarshaller.LONG_ARR:
-            case GridPortableMarshaller.FLOAT_ARR:
-            case GridPortableMarshaller.DOUBLE_ARR:
-            case GridPortableMarshaller.CHAR_ARR:
-            case GridPortableMarshaller.BOOLEAN_ARR:
-            case GridPortableMarshaller.DECIMAL_ARR:
-            case GridPortableMarshaller.DATE_ARR:
-            case GridPortableMarshaller.TIMESTAMP_ARR:
-            case GridPortableMarshaller.UUID_ARR:
-            case GridPortableMarshaller.STRING_ARR:
-            case GridPortableMarshaller.ENUM_ARR:
-            case GridPortableMarshaller.OBJ_ARR:
-            case GridPortableMarshaller.COL:
-            case GridPortableMarshaller.MAP:
-                return new LazyCollection(pos);
-
-            case GridPortableMarshaller.ENUM: {
-                if (len == 1) {
-                    assert readByte(pos) == GridPortableMarshaller.NULL;
-
-                    return null;
-                }
-
-                int mark = position();
-                position(pos + 1);
-
-                PortableBuilderEnum builderEnum = new PortableBuilderEnum(this);
-
-                position(mark);
-
-                return builderEnum;
-            }
-
-            case GridPortableMarshaller.PORTABLE_OBJ: {
-                int size = readIntPositioned(pos + 1);
-
-                int start = readIntPositioned(pos + 4 + size);
-
-                BinaryObjectImpl portableObj = new BinaryObjectImpl(ctx, arr, pos + 4 + start);
-
-                return new PortablePlainPortableObject(portableObj);
-            }
-
-            default:
-                throw new BinaryObjectException("Invalid flag value: " + type);
-        }
-    }
-
-    /**
-     * @return Parsed value.
-     */
-    public Object parseValue() {
-        int valPos = pos;
-
-        byte type = arr[pos++];
-
-        int plainLazyValLen;
-
-        boolean modifiableLazyVal = false;
-
-        switch (type) {
-            case GridPortableMarshaller.NULL:
-                return null;
-
-            case GridPortableMarshaller.HANDLE: {
-                int objStart = pos - 1 - readInt();
-
-                BinaryObjectBuilderImpl res = objMap.get(objStart);
-
-                if (res == null) {
-                    res = new BinaryObjectBuilderImpl(new PortableBuilderReader(this, objStart), objStart);
-
-                    objMap.put(objStart, res);
-                }
-
-                return res;
-            }
-
-            case GridPortableMarshaller.OBJ: {
-                pos--;
-
-                BinaryObjectBuilderImpl res = objMap.get(pos);
-
-                if (res == null) {
-                    res = new BinaryObjectBuilderImpl(new PortableBuilderReader(this, pos), pos);
-
-                    objMap.put(pos, res);
-                }
-
-                pos += readInt(GridPortableMarshaller.TOTAL_LEN_POS);
-
-                return res;
-            }
-
-            case GridPortableMarshaller.BYTE:
-                return arr[pos++];
-
-            case GridPortableMarshaller.SHORT: {
-                Object res = PortablePrimitives.readShort(arr, pos);
-                pos += 2;
-                return res;
-            }
-
-            case GridPortableMarshaller.INT:
-                return readInt();
-
-            case GridPortableMarshaller.LONG:
-                plainLazyValLen = 8;
-
-                break;
-
-            case GridPortableMarshaller.FLOAT:
-                plainLazyValLen = 4;
-
-                break;
-
-            case GridPortableMarshaller.DOUBLE:
-                plainLazyValLen = 8;
-
-                break;
-
-            case GridPortableMarshaller.CHAR:
-                plainLazyValLen = 2;
-
-                break;
-
-            case GridPortableMarshaller.BOOLEAN:
-                return arr[pos++] != 0;
-
-            case GridPortableMarshaller.DECIMAL:
-                plainLazyValLen = /** scale */ 4  + /** mag len */ 4  + /** mag bytes count */ readInt(4);
-
-                break;
-
-            case GridPortableMarshaller.STRING:
-                plainLazyValLen = 4 + readStringLength();
-
-                break;
-
-            case GridPortableMarshaller.UUID:
-                plainLazyValLen = 8 + 8;
-
-                break;
-
-            case GridPortableMarshaller.DATE:
-                plainLazyValLen = 8;
-
-                break;
-
-            case GridPortableMarshaller.TIMESTAMP:
-                plainLazyValLen = 8 + 4;
-
-                break;
-
-            case GridPortableMarshaller.BYTE_ARR:
-                plainLazyValLen = 4 + readLength();
-                modifiableLazyVal = true;
-
-                break;
-
-            case GridPortableMarshaller.SHORT_ARR:
-                plainLazyValLen = 4 + readLength() * 2;
-                modifiableLazyVal = true;
-
-                break;
-
-            case GridPortableMarshaller.INT_ARR:
-                plainLazyValLen = 4 + readLength() * 4;
-                modifiableLazyVal = true;
-
-                break;
-
-            case GridPortableMarshaller.LONG_ARR:
-                plainLazyValLen = 4 + readLength() * 8;
-                modifiableLazyVal = true;
-
-                break;
-
-            case GridPortableMarshaller.FLOAT_ARR:
-                plainLazyValLen = 4 + readLength() * 4;
-                modifiableLazyVal = true;
-
-                break;
-
-            case GridPortableMarshaller.DOUBLE_ARR:
-                plainLazyValLen = 4 + readLength() * 8;
-                modifiableLazyVal = true;
-
-                break;
-
-            case GridPortableMarshaller.CHAR_ARR:
-                plainLazyValLen = 4 + readLength() * 2;
-                modifiableLazyVal = true;
-
-                break;
-
-            case GridPortableMarshaller.BOOLEAN_ARR:
-                plainLazyValLen = 4 + readLength();
-                modifiableLazyVal = true;
-
-                break;
-
-            case GridPortableMarshaller.OBJ_ARR:
-                return new PortableObjectArrayLazyValue(this);
-
-            case GridPortableMarshaller.DATE_ARR: {
-                int size = readInt();
-
-                Date[] res = new Date[size];
-
-                for (int i = 0; i < res.length; i++) {
-                    byte flag = arr[pos++];
-
-                    if (flag == GridPortableMarshaller.NULL) continue;
-
-                    if (flag != GridPortableMarshaller.DATE)
-                        throw new BinaryObjectException("Invalid flag value: " + flag);
-
-                    long time = PortablePrimitives.readLong(arr, pos);
-
-                    pos += 8;
-
-                    res[i] = new Date(time);
-                }
-
-                return res;
-            }
-
-            case GridPortableMarshaller.TIMESTAMP_ARR: {
-                int size = readInt();
-
-                Timestamp[] res = new Timestamp[size];
-
-                for (int i = 0; i < res.length; i++) {
-                    byte flag = arr[pos++];
-
-                    if (flag == GridPortableMarshaller.NULL)
-                        continue;
-
-                    if (flag != GridPortableMarshaller.TIMESTAMP)
-                        throw new BinaryObjectException("Invalid flag value: " + flag);
-
-                    long time = PortablePrimitives.readLong(arr, pos);
-
-                    pos += 8;
-
-                    int nano = PortablePrimitives.readInt(arr, pos);
-
-                    pos += 4;
-
-                    Timestamp ts = new Timestamp(time);
-
-                    ts.setNanos(ts.getNanos() + nano);
-
-                    res[i] = ts;
-                }
-
-                return res;
-            }
-
-            case GridPortableMarshaller.UUID_ARR:
-            case GridPortableMarshaller.STRING_ARR:
-            case GridPortableMarshaller.DECIMAL_ARR: {
-                int size = readInt();
-
-                for (int i = 0; i < size; i++) {
-                    byte flag = arr[pos++];
-
-                    if (flag == GridPortableMarshaller.UUID)
-                        pos += 8 + 8;
-                    else if (flag == GridPortableMarshaller.STRING)
-                        pos += 4 + readStringLength();
-                    else if (flag == GridPortableMarshaller.DECIMAL) {
-                        pos += 4; // scale value
-                        pos += 4 + readLength();
-                    }
-                    else
-                        assert flag == GridPortableMarshaller.NULL;
-                }
-
-                return new PortableModifiableLazyValue(this, valPos, pos - valPos);
-            }
-
-            case GridPortableMarshaller.COL: {
-                int size = readInt();
-                byte colType = arr[pos++];
-
-                switch (colType) {
-                    case GridPortableMarshaller.USER_COL:
-                    case GridPortableMarshaller.ARR_LIST:
-                        return new PortableLazyArrayList(this, size);
-
-                    case GridPortableMarshaller.LINKED_LIST:
-                        return new PortableLazyLinkedList(this, size);
-
-                    case GridPortableMarshaller.HASH_SET:
-                    case GridPortableMarshaller.LINKED_HASH_SET:
-                        return new PortableLazySet(this, size);
-                }
-
-                throw new BinaryObjectException("Unknown collection type: " + colType);
-            }
-
-            case GridPortableMarshaller.MAP:
-                return PortableLazyMap.parseMap(this);
-
-            case GridPortableMarshaller.ENUM:
-                return new PortableBuilderEnum(this);
-
-            case GridPortableMarshaller.ENUM_ARR:
-                return new PortableEnumArrayLazyValue(this);
-
-            case GridPortableMarshaller.PORTABLE_OBJ: {
-                int size = readInt();
-
-                pos += size;
-
-                int start = readInt();
-
-                BinaryObjectImpl portableObj = new BinaryObjectImpl(ctx, arr,
-                    pos - 4 - size + start);
-
-                return new PortablePlainPortableObject(portableObj);
-            }
-
-            default:
-                throw new BinaryObjectException("Invalid flag value: " + type);
-        }
-
-        PortableAbstractLazyValue res;
-
-        if (modifiableLazyVal)
-            res = new PortableModifiableLazyValue(this, valPos, 1 + plainLazyValLen);
-        else
-            res = new PortablePlainLazyValue(this, valPos, 1 + plainLazyValLen);
-
-        pos += plainLazyValLen;
-
-        return res;
-    }
-
-    /**
-     * @return Array.
-     */
-    public byte[] array() {
-        return arr;
-    }
-
-    /**
-     * @return Position of reader.
-     */
-    public int position() {
-        return pos;
-    }
-
-    /**
-     * @param pos New pos.
-     */
-    public void position(int pos) {
-        this.pos = pos;
-    }
-
-    /**
-     * @param n Number of bytes to skip.
-     */
-    public void skip(int n) {
-        pos += n;
-    }
-
-    /**
-     * @return Reader.
-     */
-    BinaryReaderExImpl reader() {
-        return reader;
-    }
-
-    /**
-     *
-     */
-    private class LazyCollection implements PortableLazyValue {
-        /** */
-        private final int valOff;
-
-        /** */
-        private Object col;
-
-        /**
-         * @param valOff Value.
-         */
-        protected LazyCollection(int valOff) {
-            this.valOff = valOff;
-        }
-
-        /**
-         * @return Object.
-         */
-        private Object wrappedCollection() {
-            if (col == null) {
-                position(valOff);
-
-                col = parseValue();
-            }
-
-            return col;
-        }
-
-        /** {@inheritDoc} */
-        @Override public void writeTo(BinaryWriterExImpl writer, PortableBuilderSerializer ctx) {
-            ctx.writeValue(writer, wrappedCollection());
-        }
-
-        /** {@inheritDoc} */
-        @Override public Object value() {
-            return PortableUtils.unwrapLazy(wrappedCollection());
-        }
-    }
-}

http://git-wip-us.apache.org/repos/asf/ignite/blob/71ad9cea/modules/core/src/main/java/org/apache/ignite/internal/binary/builder/PortableBuilderSerializationAware.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/binary/builder/PortableBuilderSerializationAware.java b/modules/core/src/main/java/org/apache/ignite/internal/binary/builder/PortableBuilderSerializationAware.java
deleted file mode 100644
index 03d5720..0000000
--- a/modules/core/src/main/java/org/apache/ignite/internal/binary/builder/PortableBuilderSerializationAware.java
+++ /dev/null
@@ -1,31 +0,0 @@
-/*
- * 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.binary.builder;
-
-import org.apache.ignite.internal.binary.BinaryWriterExImpl;
-
-/**
- *
- */
-interface PortableBuilderSerializationAware {
-    /**
-     * @param writer Writer.
-     * @param ctx Context.
-     */
-    public void writeTo(BinaryWriterExImpl writer, PortableBuilderSerializer ctx);
-}

http://git-wip-us.apache.org/repos/asf/ignite/blob/71ad9cea/modules/core/src/main/java/org/apache/ignite/internal/binary/builder/PortableBuilderSerializer.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/binary/builder/PortableBuilderSerializer.java b/modules/core/src/main/java/org/apache/ignite/internal/binary/builder/PortableBuilderSerializer.java
deleted file mode 100644
index 06c51fb..0000000
--- a/modules/core/src/main/java/org/apache/ignite/internal/binary/builder/PortableBuilderSerializer.java
+++ /dev/null
@@ -1,217 +0,0 @@
-/*
- * 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.binary.builder;
-
-import org.apache.ignite.binary.BinaryObject;
-import org.apache.ignite.internal.binary.BinaryMetadata;
-import org.apache.ignite.internal.binary.BinaryObjectExImpl;
-import org.apache.ignite.internal.binary.BinaryWriterExImpl;
-import org.apache.ignite.internal.binary.GridPortableMarshaller;
-import org.apache.ignite.internal.binary.PortableContext;
-import org.apache.ignite.internal.binary.PortableUtils;
-
-import java.util.Collection;
-import java.util.IdentityHashMap;
-import java.util.Map;
-
-/**
- *
- */
-class PortableBuilderSerializer {
-    /** */
-    private final Map<BinaryObjectBuilderImpl, Integer> objToPos = new IdentityHashMap<>();
-
-    /** */
-    private Map<BinaryObject, BinaryObjectBuilderImpl> portableObjToWrapper;
-
-    /**
-     * @param obj Mutable object.
-     * @param posInResArr Object position in the array.
-     */
-    public void registerObjectWriting(BinaryObjectBuilderImpl obj, int posInResArr) {
-        objToPos.put(obj, posInResArr);
-    }
-
-    /**
-     * @param writer Writer.
-     * @param val Value.
-     */
-    public void writeValue(BinaryWriterExImpl writer, Object val) {
-        if (val == null) {
-            writer.writeByte(GridPortableMarshaller.NULL);
-
-            return;
-        }
-
-        if (val instanceof PortableBuilderSerializationAware) {
-            ((PortableBuilderSerializationAware)val).writeTo(writer, this);
-
-            return;
-        }
-
-        if (val instanceof BinaryObjectExImpl) {
-            if (portableObjToWrapper == null)
-                portableObjToWrapper = new IdentityHashMap<>();
-
-            BinaryObjectBuilderImpl wrapper = portableObjToWrapper.get(val);
-
-            if (wrapper == null) {
-                wrapper = BinaryObjectBuilderImpl.wrap((BinaryObject)val);
-
-                portableObjToWrapper.put((BinaryObject)val, wrapper);
-            }
-
-            val = wrapper;
-        }
-
-        if (val instanceof BinaryObjectBuilderImpl) {
-            BinaryObjectBuilderImpl obj = (BinaryObjectBuilderImpl)val;
-
-            Integer posInResArr = objToPos.get(obj);
-
-            if (posInResArr == null) {
-                objToPos.put(obj, writer.out().position());
-
-                obj.serializeTo(writer.newWriter(obj.typeId()), this);
-            }
-            else {
-                int handle = writer.out().position() - posInResArr;
-
-                writer.writeByte(GridPortableMarshaller.HANDLE);
-                writer.writeInt(handle);
-            }
-
-            return;
-        }
-
-        if (val.getClass().isEnum()) {
-            String typeName = PortableContext.typeName(val.getClass().getName());
-            int typeId = writer.context().typeId(typeName);
-
-            BinaryMetadata meta = new BinaryMetadata(typeId, typeName, null, null, null, true);
-            writer.context().updateMetadata(typeId, meta);
-
-            writer.writeByte(GridPortableMarshaller.ENUM);
-            writer.writeInt(typeId);
-            writer.writeInt(((Enum)val).ordinal());
-
-            return;
-        }
-
-        if (val instanceof Collection) {
-            Collection<?> c = (Collection<?>)val;
-
-            writer.writeByte(GridPortableMarshaller.COL);
-            writer.writeInt(c.size());
-
-            byte colType = writer.context().collectionType(c.getClass());
-
-            writer.writeByte(colType);
-
-            for (Object obj : c)
-                writeValue(writer, obj);
-
-            return;
-        }
-
-        if (val instanceof Map) {
-            Map<?, ?> map = (Map<?, ?>)val;
-
-            writer.writeByte(GridPortableMarshaller.MAP);
-            writer.writeInt(map.size());
-
-            writer.writeByte(writer.context().mapType(map.getClass()));
-
-            for (Map.Entry<?, ?> entry : map.entrySet()) {
-                writeValue(writer, entry.getKey());
-                writeValue(writer, entry.getValue());
-            }
-
-            return;
-        }
-
-        Byte flag = PortableUtils.PLAIN_CLASS_TO_FLAG.get(val.getClass());
-
-        if (flag != null) {
-            PortableUtils.writePlainObject(writer, val);
-
-            return;
-        }
-
-        if (val instanceof Object[]) {
-            int compTypeId = writer.context().typeId(((Object[])val).getClass().getComponentType().getName());
-
-            if (val instanceof PortableBuilderEnum[]) {
-                writeArray(writer, GridPortableMarshaller.ENUM_ARR, (Object[])val, compTypeId);
-
-                return;
-            }
-
-            if (((Object[])val).getClass().getComponentType().isEnum()) {
-                Enum[] enumArr = (Enum[])val;
-
-                writer.writeByte(GridPortableMarshaller.ENUM_ARR);
-                writer.writeInt(compTypeId);
-                writer.writeInt(enumArr.length);
-
-                for (Enum anEnum : enumArr)
-                    writeValue(writer, anEnum);
-
-                return;
-            }
-
-            writeArray(writer, GridPortableMarshaller.OBJ_ARR, (Object[])val, compTypeId);
-
-            return;
-        }
-
-        writer.doWriteObject(val);
-    }
-
-    /**
-     * @param writer Writer.
-     * @param elementType Element type.
-     * @param arr The array.
-     * @param compTypeId Component type ID.
-     */
-    public void writeArray(BinaryWriterExImpl writer, byte elementType, Object[] arr, int compTypeId) {
-        writer.writeByte(elementType);
-        writer.writeInt(compTypeId);
-        writer.writeInt(arr.length);
-
-        for (Object obj : arr)
-            writeValue(writer, obj);
-    }
-
-    /**
-     * @param writer Writer.
-     * @param elementType Element type.
-     * @param arr The array.
-     * @param clsName Component class name.
-     */
-    public void writeArray(BinaryWriterExImpl writer, byte elementType, Object[] arr, String clsName) {
-        writer.writeByte(elementType);
-        writer.writeInt(GridPortableMarshaller.UNREGISTERED_TYPE_ID);
-        writer.writeString(clsName);
-        writer.writeInt(arr.length);
-
-        for (Object obj : arr)
-            writeValue(writer, obj);
-    }
-
-}

http://git-wip-us.apache.org/repos/asf/ignite/blob/71ad9cea/modules/core/src/main/java/org/apache/ignite/internal/binary/builder/PortableEnumArrayLazyValue.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/binary/builder/PortableEnumArrayLazyValue.java b/modules/core/src/main/java/org/apache/ignite/internal/binary/builder/PortableEnumArrayLazyValue.java
deleted file mode 100644
index fa83d7e..0000000
--- a/modules/core/src/main/java/org/apache/ignite/internal/binary/builder/PortableEnumArrayLazyValue.java
+++ /dev/null
@@ -1,115 +0,0 @@
-/*
- * 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.binary.builder;
-
-import org.apache.ignite.internal.binary.BinaryWriterExImpl;
-import org.apache.ignite.internal.binary.GridPortableMarshaller;
-import org.apache.ignite.internal.binary.GridPortableMarshaller;
-import org.apache.ignite.internal.binary.BinaryWriterExImpl;
-import org.apache.ignite.internal.util.typedef.internal.U;
-import org.apache.ignite.binary.BinaryObjectException;
-import org.apache.ignite.binary.BinaryInvalidTypeException;
-
-/**
- *
- */
-class PortableEnumArrayLazyValue extends PortableAbstractLazyValue {
-    /** */
-    private final int len;
-
-    /** */
-    private final int compTypeId;
-
-    /** */
-    private final String clsName;
-
-    /**
-     * @param reader Reader.
-     */
-    protected PortableEnumArrayLazyValue(PortableBuilderReader reader) {
-        super(reader, reader.position() - 1);
-
-        int typeId = reader.readInt();
-
-        if (typeId == GridPortableMarshaller.UNREGISTERED_TYPE_ID) {
-            clsName = reader.readString();
-
-            Class cls;
-
-            try {
-                cls = U.forName(reader.readString(), reader.portableContext().configuration().getClassLoader());
-            }
-            catch (ClassNotFoundException e) {
-                throw new BinaryInvalidTypeException("Failed to load the class: " + clsName, e);
-            }
-
-            compTypeId = reader.portableContext().descriptorForClass(cls, true).typeId();
-        }
-        else {
-            compTypeId = typeId;
-            clsName = null;
-        }
-
-        int size = reader.readInt();
-
-        for (int i = 0; i < size; i++)
-            reader.skipValue();
-
-        len = reader.position() - valOff;
-    }
-
-    /** {@inheritDoc} */
-    @Override protected Object init() {
-        reader.position(valOff + 1);
-
-        //skipping component type id
-        reader.readInt();
-
-        int size = reader.readInt();
-
-        PortableBuilderEnum[] res = new PortableBuilderEnum[size];
-
-        for (int i = 0; i < size; i++) {
-            byte flag = reader.readByte();
-
-            if (flag == GridPortableMarshaller.NULL)
-                continue;
-
-            if (flag != GridPortableMarshaller.ENUM)
-                throw new BinaryObjectException("Invalid flag value: " + flag);
-
-            res[i] = new PortableBuilderEnum(reader);
-        }
-
-        return res;
-    }
-
-    /** {@inheritDoc} */
-    @Override public void writeTo(BinaryWriterExImpl writer, PortableBuilderSerializer ctx) {
-        if (val != null) {
-            if (clsName != null)
-                ctx.writeArray(writer, GridPortableMarshaller.ENUM_ARR, (Object[])val, clsName);
-            else
-                ctx.writeArray(writer, GridPortableMarshaller.ENUM_ARR, (Object[])val, compTypeId);
-
-            return;
-        }
-
-        writer.write(reader.array(), valOff, len);
-    }
-}

http://git-wip-us.apache.org/repos/asf/ignite/blob/71ad9cea/modules/core/src/main/java/org/apache/ignite/internal/binary/builder/PortableLazyArrayList.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/binary/builder/PortableLazyArrayList.java b/modules/core/src/main/java/org/apache/ignite/internal/binary/builder/PortableLazyArrayList.java
deleted file mode 100644
index 846ac82..0000000
--- a/modules/core/src/main/java/org/apache/ignite/internal/binary/builder/PortableLazyArrayList.java
+++ /dev/null
@@ -1,167 +0,0 @@
-/*
- * 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.binary.builder;
-
-import java.util.AbstractList;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.List;
-import org.apache.ignite.internal.binary.BinaryWriterExImpl;
-import org.apache.ignite.internal.binary.GridPortableMarshaller;
-import org.apache.ignite.internal.binary.PortableUtils;
-
-/**
- *
- */
-class PortableLazyArrayList extends AbstractList<Object> implements PortableBuilderSerializationAware {
-    /** */
-    private final PortableBuilderReader reader;
-
-    /** */
-    private final int off;
-
-    /** */
-    private List<Object> delegate;
-
-    /**
-     * @param reader Reader.
-     * @param size Size,
-     */
-    PortableLazyArrayList(PortableBuilderReader reader, int size) {
-        this.reader = reader;
-        off = reader.position() - 1/* flag */ - 4/* size */ - 1/* col type */;
-
-        assert size >= 0;
-
-        for (int i = 0; i < size; i++)
-            reader.skipValue();
-    }
-
-    /**
-     *
-     */
-    private void ensureDelegateInit() {
-        if (delegate == null) {
-            int size = reader.readIntPositioned(off + 1);
-
-            reader.position(off + 1/* flag */ + 4/* size */ + 1/* col type */);
-
-            delegate = new ArrayList<>(size);
-
-            for (int i = 0; i < size; i++)
-                delegate.add(reader.parseValue());
-        }
-    }
-
-    /** {@inheritDoc} */
-    @Override public Object get(int idx) {
-        ensureDelegateInit();
-
-        return PortableUtils.unwrapLazy(delegate.get(idx));
-    }
-
-    /** {@inheritDoc} */
-    @Override public boolean add(Object o) {
-        ensureDelegateInit();
-
-        return delegate.add(o);
-    }
-
-    /** {@inheritDoc} */
-    @Override public void add(int idx, Object element) {
-        ensureDelegateInit();
-
-        delegate.add(idx, element);
-    }
-
-    /** {@inheritDoc} */
-    @Override public Object set(int idx, Object element) {
-        ensureDelegateInit();
-
-        return PortableUtils.unwrapLazy(delegate.set(idx, element));
-    }
-
-    /** {@inheritDoc} */
-    @Override public Object remove(int idx) {
-        ensureDelegateInit();
-
-        return PortableUtils.unwrapLazy(delegate.remove(idx));
-    }
-
-    /** {@inheritDoc} */
-    @Override public void clear() {
-        if (delegate == null)
-            delegate = new ArrayList<>();
-        else
-            delegate.clear();
-    }
-
-    /** {@inheritDoc} */
-    @Override public boolean addAll(int idx, Collection<?> c) {
-        return delegate.addAll(idx, c);
-    }
-
-    /** {@inheritDoc} */
-    @Override protected void removeRange(int fromIdx, int toIdx) {
-        ensureDelegateInit();
-
-        delegate.subList(fromIdx, toIdx).clear();
-    }
-
-    /** {@inheritDoc} */
-    @Override public int size() {
-        if (delegate == null)
-            return reader.readIntPositioned(off + 1);
-
-        return delegate.size();
-    }
-
-    /** {@inheritDoc} */
-    @Override public void writeTo(BinaryWriterExImpl writer, PortableBuilderSerializer ctx) {
-        if (delegate == null) {
-            int size = reader.readIntPositioned(off + 1);
-
-            int hdrSize = 1 /* flag */ + 4 /* size */ + 1 /* col type */;
-
-            writer.write(reader.array(), off, hdrSize);
-
-            reader.position(off + hdrSize);
-
-            for (int i = 0; i < size; i++) {
-                Object o = reader.parseValue();
-
-                ctx.writeValue(writer, o);
-            }
-        }
-        else {
-            writer.writeByte(GridPortableMarshaller.COL);
-            writer.writeInt(delegate.size());
-
-            byte colType = reader.array()[off + 1 /* flag */ + 4 /* size */];
-            writer.writeByte(colType);
-
-            int oldPos = reader.position();
-
-            for (Object o : delegate)
-                ctx.writeValue(writer, o);
-
-            // PortableBuilderImpl might have been written. It could override reader's position.
-            reader.position(oldPos);
-        }
-    }
-}

http://git-wip-us.apache.org/repos/asf/ignite/blob/71ad9cea/modules/core/src/main/java/org/apache/ignite/internal/binary/builder/PortableLazyLinkedList.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/binary/builder/PortableLazyLinkedList.java b/modules/core/src/main/java/org/apache/ignite/internal/binary/builder/PortableLazyLinkedList.java
deleted file mode 100644
index 11ed765..0000000
--- a/modules/core/src/main/java/org/apache/ignite/internal/binary/builder/PortableLazyLinkedList.java
+++ /dev/null
@@ -1,218 +0,0 @@
-/*
- * 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.binary.builder;
-
-import java.util.AbstractList;
-import java.util.Collection;
-import java.util.Iterator;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.ListIterator;
-import org.apache.ignite.internal.binary.BinaryWriterExImpl;
-import org.apache.ignite.internal.binary.GridPortableMarshaller;
-import org.apache.ignite.internal.binary.PortableUtils;
-
-/**
- *
- */
-class PortableLazyLinkedList extends AbstractList<Object> implements PortableBuilderSerializationAware {
-    /** */
-    private final PortableBuilderReader reader;
-
-    /** */
-    private final int off;
-
-    /** */
-    private List<Object> delegate;
-
-    /**
-     * @param reader Reader.
-     * @param size Size,
-     */
-    PortableLazyLinkedList(PortableBuilderReader reader, int size) {
-        this.reader = reader;
-        off = reader.position() - 1/* flag */ - 4/* size */ - 1/* col type */;
-
-        assert size >= 0;
-
-        for (int i = 0; i < size; i++)
-            reader.skipValue();
-    }
-
-    /**
-     *
-     */
-    private void ensureDelegateInit() {
-        if (delegate == null) {
-            int size = reader.readIntPositioned(off + 1);
-
-            reader.position(off + 1/* flag */ + 4/* size */ + 1/* col type */);
-
-            delegate = new LinkedList<>();
-
-            for (int i = 0; i < size; i++)
-                delegate.add(reader.parseValue());
-        }
-    }
-
-    /** {@inheritDoc} */
-    @Override public Object get(int idx) {
-        ensureDelegateInit();
-
-        return PortableUtils.unwrapLazy(delegate.get(idx));
-    }
-
-    /** {@inheritDoc} */
-    @Override public boolean add(Object o) {
-        ensureDelegateInit();
-
-        return delegate.add(o);
-    }
-
-    /** {@inheritDoc} */
-    @Override public void add(int idx, Object element) {
-        ensureDelegateInit();
-
-        delegate.add(idx, element);
-    }
-
-    /** {@inheritDoc} */
-    @Override public Object set(int idx, Object element) {
-        ensureDelegateInit();
-
-        return PortableUtils.unwrapLazy(delegate.set(idx, element));
-    }
-
-    /** {@inheritDoc} */
-    @Override public Object remove(int idx) {
-        ensureDelegateInit();
-
-        return PortableUtils.unwrapLazy(delegate.remove(idx));
-    }
-
-    /** {@inheritDoc} */
-    @Override public void clear() {
-        if (delegate == null)
-            delegate = new LinkedList<>();
-        else
-            delegate.clear();
-    }
-
-    /** {@inheritDoc} */
-    @Override public boolean addAll(int idx, Collection<?> c) {
-        ensureDelegateInit();
-
-        return delegate.addAll(idx, c);
-    }
-
-    /** {@inheritDoc} */
-    @Override protected void removeRange(int fromIdx, int toIdx) {
-        ensureDelegateInit();
-
-        delegate.subList(fromIdx, toIdx).clear();
-    }
-
-    /** {@inheritDoc} */
-    @Override public int size() {
-        if (delegate == null)
-            return reader.readIntPositioned(off + 1);
-
-        return delegate.size();
-    }
-
-    /** {@inheritDoc} */
-    @Override public ListIterator<Object> listIterator(final int idx) {
-        ensureDelegateInit();
-
-        return new ListIterator<Object>() {
-            /** */
-            private final ListIterator<Object> delegate = PortableLazyLinkedList.super.listIterator(idx);
-
-            @Override public boolean hasNext() {
-                return delegate.hasNext();
-            }
-
-            @Override public Object next() {
-                return PortableUtils.unwrapLazy(delegate.next());
-            }
-
-            @Override public boolean hasPrevious() {
-                return delegate.hasPrevious();
-            }
-
-            @Override public Object previous() {
-                return PortableUtils.unwrapLazy(delegate.previous());
-            }
-
-            @Override public int nextIndex() {
-                return delegate.nextIndex();
-            }
-
-            @Override public int previousIndex() {
-                return delegate.previousIndex();
-            }
-
-            @Override public void remove() {
-                delegate.remove();
-            }
-
-            @Override public void set(Object o) {
-                delegate.set(o);
-            }
-
-            @Override public void add(Object o) {
-                delegate.add(o);
-            }
-        };
-    }
-
-    /** {@inheritDoc} */
-    @Override public Iterator<Object> iterator() {
-        ensureDelegateInit();
-
-        return PortableUtils.unwrapLazyIterator(super.iterator());
-    }
-
-    /** {@inheritDoc} */
-    @Override public void writeTo(BinaryWriterExImpl writer, PortableBuilderSerializer ctx) {
-        if (delegate == null) {
-            int size = reader.readIntPositioned(off + 1);
-
-            int hdrSize = 1 /* flag */ + 4 /* size */ + 1 /* col type */;
-            writer.write(reader.array(), off, hdrSize);
-
-            reader.position(off + hdrSize);
-
-            for (int i = 0; i < size; i++) {
-                Object o = reader.parseValue();
-
-                ctx.writeValue(writer, o);
-            }
-        }
-        else {
-            writer.writeByte(GridPortableMarshaller.COL);
-            writer.writeInt(delegate.size());
-
-            byte colType = reader.array()[off + 1 /* flag */ + 4 /* size */];
-            writer.writeByte(colType);
-
-            for (Object o : delegate)
-                ctx.writeValue(writer, o);
-        }
-    }
-}

http://git-wip-us.apache.org/repos/asf/ignite/blob/71ad9cea/modules/core/src/main/java/org/apache/ignite/internal/binary/builder/PortableLazyMap.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/binary/builder/PortableLazyMap.java b/modules/core/src/main/java/org/apache/ignite/internal/binary/builder/PortableLazyMap.java
deleted file mode 100644
index 4bc7622..0000000
--- a/modules/core/src/main/java/org/apache/ignite/internal/binary/builder/PortableLazyMap.java
+++ /dev/null
@@ -1,221 +0,0 @@
-/*
- * 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.binary.builder;
-
-import java.util.AbstractMap;
-import java.util.AbstractSet;
-import java.util.Iterator;
-import java.util.LinkedHashMap;
-import java.util.Map;
-import java.util.Set;
-import org.apache.ignite.internal.binary.BinaryWriterExImpl;
-import org.apache.ignite.internal.binary.GridPortableMarshaller;
-import org.apache.ignite.internal.binary.PortableUtils;
-import org.jetbrains.annotations.Nullable;
-
-/**
- *
- */
-class PortableLazyMap extends AbstractMap<Object, Object> implements PortableBuilderSerializationAware {
-    /** */
-    private final PortableBuilderReader reader;
-
-    /** */
-    private final int off;
-
-    /** */
-    private Map<Object, Object> delegate;
-
-    /**
-     * @param reader Reader.
-     * @param off Offset.
-     */
-    private PortableLazyMap(PortableBuilderReader reader, int off) {
-        this.reader = reader;
-        this.off = off;
-    }
-
-    /**
-     * @param reader Reader.
-     * @return PortableLazyMap.
-     */
-    @Nullable public static PortableLazyMap parseMap(PortableBuilderReader reader) {
-        int off = reader.position() - 1;
-
-        int size = reader.readInt();
-
-        reader.skip(1); // map type.
-
-        for (int i = 0; i < size; i++) {
-            reader.skipValue(); // skip key
-            reader.skipValue(); // skip value
-        }
-
-        return new PortableLazyMap(reader, off);
-    }
-
-    /**
-     *
-     */
-    private void ensureDelegateInit() {
-        if (delegate == null) {
-            int size = reader.readIntPositioned(off + 1);
-
-            reader.position(off + 1/* flag */ + 4/* size */ + 1/* col type */);
-
-            delegate = new LinkedHashMap<>();
-
-            for (int i = 0; i < size; i++)
-                delegate.put(PortableUtils.unwrapLazy(reader.parseValue()), reader.parseValue());
-        }
-    }
-
-    /** {@inheritDoc} */
-    @Override public void writeTo(BinaryWriterExImpl writer, PortableBuilderSerializer ctx) {
-        if (delegate == null) {
-            int size = reader.readIntPositioned(off + 1);
-
-            int hdrSize = 1 /* flag */ + 4 /* size */ + 1 /* col type */;
-            writer.write(reader.array(), off, hdrSize);
-
-            reader.position(off + hdrSize);
-
-            for (int i = 0; i < size; i++) {
-                ctx.writeValue(writer, reader.parseValue()); // key
-                ctx.writeValue(writer, reader.parseValue()); // value
-            }
-        }
-        else {
-            writer.writeByte(GridPortableMarshaller.MAP);
-            writer.writeInt(delegate.size());
-
-            byte colType = reader.array()[off + 1 /* flag */ + 4 /* size */];
-
-            writer.writeByte(colType);
-
-            for (Entry<Object, Object> entry : delegate.entrySet()) {
-                ctx.writeValue(writer, entry.getKey());
-                ctx.writeValue(writer, entry.getValue());
-            }
-        }
-    }
-
-    /** {@inheritDoc} */
-    @Override public int size() {
-        if (delegate == null)
-            return reader.readIntPositioned(off + 1);
-
-        return delegate.size();
-    }
-
-    /** {@inheritDoc} */
-    @Override public boolean containsKey(Object key) {
-        ensureDelegateInit();
-
-        return delegate.containsKey(key);
-    }
-
-    /** {@inheritDoc} */
-    @Override public boolean containsValue(Object val) {
-        return values().contains(val);
-    }
-
-    /** {@inheritDoc} */
-    @Override public Set<Object> keySet() {
-        ensureDelegateInit();
-
-        return delegate.keySet();
-    }
-
-    /** {@inheritDoc} */
-    @Override public void clear() {
-        if (delegate == null)
-            delegate = new LinkedHashMap<>();
-        else
-            delegate.clear();
-    }
-
-    /** {@inheritDoc} */
-    @Override public Object get(Object key) {
-        ensureDelegateInit();
-
-        return PortableUtils.unwrapLazy(delegate.get(key));
-    }
-
-    /** {@inheritDoc} */
-    @Override public Object put(Object key, Object val) {
-        ensureDelegateInit();
-
-        return PortableUtils.unwrapLazy(delegate.put(key, val));
-    }
-
-    /** {@inheritDoc} */
-    @Override public Object remove(Object key) {
-        ensureDelegateInit();
-
-        return PortableUtils.unwrapLazy(delegate.remove(key));
-    }
-
-    /** {@inheritDoc} */
-    @Override public Set<Entry<Object, Object>> entrySet() {
-        ensureDelegateInit();
-
-        return new AbstractSet<Entry<Object, Object>>() {
-            @Override public boolean contains(Object o) {
-                throw new UnsupportedOperationException();
-            }
-
-            @Override public Iterator<Entry<Object, Object>> iterator() {
-                return new Iterator<Entry<Object, Object>>() {
-                    /** */
-                    private final Iterator<Entry<Object, Object>> itr = delegate.entrySet().iterator();
-
-                    @Override public boolean hasNext() {
-                        return itr.hasNext();
-                    }
-
-                    @Override public Entry<Object, Object> next() {
-                        Entry<Object, Object> res = itr.next();
-
-                        final Object val = res.getValue();
-
-                        if (val instanceof PortableLazyValue) {
-                            return new SimpleEntry<Object, Object>(res.getKey(), val) {
-                                private static final long serialVersionUID = 0L;
-
-                                @Override public Object getValue() {
-                                    return ((PortableLazyValue)val).value();
-                                }
-                            };
-                        }
-
-                        return res;
-                    }
-
-                    @Override public void remove() {
-                        itr.remove();
-                    }
-                };
-            }
-
-            @Override public int size() {
-                return delegate.size();
-            }
-        };
-    }
-}

http://git-wip-us.apache.org/repos/asf/ignite/blob/71ad9cea/modules/core/src/main/java/org/apache/ignite/internal/binary/builder/PortableLazySet.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/binary/builder/PortableLazySet.java b/modules/core/src/main/java/org/apache/ignite/internal/binary/builder/PortableLazySet.java
deleted file mode 100644
index 3548f1f..0000000
--- a/modules/core/src/main/java/org/apache/ignite/internal/binary/builder/PortableLazySet.java
+++ /dev/null
@@ -1,94 +0,0 @@
-/*
- * 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.binary.builder;
-
-import java.util.Collection;
-import java.util.Set;
-import org.apache.ignite.internal.binary.BinaryWriterExImpl;
-import org.apache.ignite.internal.binary.GridPortableMarshaller;
-import org.apache.ignite.internal.binary.GridPortableMarshaller;
-import org.apache.ignite.internal.binary.PortableUtils;
-import org.apache.ignite.internal.binary.BinaryWriterExImpl;
-import org.apache.ignite.internal.util.typedef.internal.U;
-
-/**
- *
- */
-class PortableLazySet extends PortableAbstractLazyValue {
-    /** */
-    private final int off;
-
-    /**
-     * @param reader Reader.
-     * @param size Size.
-     */
-    PortableLazySet(PortableBuilderReader reader, int size) {
-        super(reader, reader.position() - 1);
-
-        off = reader.position() - 1/* flag */ - 4/* size */ - 1/* col type */;
-
-        assert size >= 0;
-
-        for (int i = 0; i < size; i++)
-            reader.skipValue();
-    }
-
-    /** {@inheritDoc} */
-    @Override public void writeTo(BinaryWriterExImpl writer, PortableBuilderSerializer ctx) {
-        if (val == null) {
-            int size = reader.readIntPositioned(off + 1);
-
-            int hdrSize = 1 /* flag */ + 4 /* size */ + 1 /* col type */;
-            writer.write(reader.array(), off, hdrSize);
-
-            reader.position(off + hdrSize);
-
-            for (int i = 0; i < size; i++) {
-                Object o = reader.parseValue();
-
-                ctx.writeValue(writer, o);
-            }
-        }
-        else {
-            Collection<Object> c = (Collection<Object>)val;
-
-            writer.writeByte(GridPortableMarshaller.COL);
-            writer.writeInt(c.size());
-
-            byte colType = reader.array()[off + 1 /* flag */ + 4 /* size */];
-            writer.writeByte(colType);
-
-            for (Object o : c)
-                ctx.writeValue(writer, o);
-        }
-    }
-
-    /** {@inheritDoc} */
-    @Override protected Object init() {
-        int size = reader.readIntPositioned(off + 1);
-
-        reader.position(off + 1/* flag */ + 4/* size */ + 1/* col type */);
-
-        Set<Object> res = U.newLinkedHashSet(size);
-
-        for (int i = 0; i < size; i++)
-            res.add(PortableUtils.unwrapLazy(reader.parseValue()));
-
-        return res;
-    }
-}

http://git-wip-us.apache.org/repos/asf/ignite/blob/71ad9cea/modules/core/src/main/java/org/apache/ignite/internal/binary/builder/PortableLazyValue.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/binary/builder/PortableLazyValue.java b/modules/core/src/main/java/org/apache/ignite/internal/binary/builder/PortableLazyValue.java
deleted file mode 100644
index 51c6d7e..0000000
--- a/modules/core/src/main/java/org/apache/ignite/internal/binary/builder/PortableLazyValue.java
+++ /dev/null
@@ -1,28 +0,0 @@
-/*
- * 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.binary.builder;
-
-/**
- *
- */
-public interface PortableLazyValue extends PortableBuilderSerializationAware {
-    /**
-     * @return Value.
-     */
-    public Object value();
-}

http://git-wip-us.apache.org/repos/asf/ignite/blob/71ad9cea/modules/core/src/main/java/org/apache/ignite/internal/binary/builder/PortableModifiableLazyValue.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/binary/builder/PortableModifiableLazyValue.java b/modules/core/src/main/java/org/apache/ignite/internal/binary/builder/PortableModifiableLazyValue.java
deleted file mode 100644
index b00157e..0000000
--- a/modules/core/src/main/java/org/apache/ignite/internal/binary/builder/PortableModifiableLazyValue.java
+++ /dev/null
@@ -1,52 +0,0 @@
-/*
- * 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.binary.builder;
-
-import org.apache.ignite.internal.binary.BinaryWriterExImpl;
-
-/**
- *
- */
-public class PortableModifiableLazyValue extends PortableAbstractLazyValue {
-    /** */
-    protected final int len;
-
-    /**
-     * @param reader
-     * @param valOff
-     * @param len
-     */
-    public PortableModifiableLazyValue(PortableBuilderReader reader, int valOff, int len) {
-        super(reader, valOff);
-
-        this.len = len;
-    }
-
-    /** {@inheritDoc} */
-    @Override protected Object init() {
-        return reader.reader().unmarshal(valOff);
-    }
-
-    /** {@inheritDoc} */
-    @Override public void writeTo(BinaryWriterExImpl writer, PortableBuilderSerializer ctx) {
-        if (val == null)
-            writer.write(reader.array(), valOff, len);
-        else
-            writer.writeObject(val);
-    }
-}

http://git-wip-us.apache.org/repos/asf/ignite/blob/71ad9cea/modules/core/src/main/java/org/apache/ignite/internal/binary/builder/PortableObjectArrayLazyValue.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/binary/builder/PortableObjectArrayLazyValue.java b/modules/core/src/main/java/org/apache/ignite/internal/binary/builder/PortableObjectArrayLazyValue.java
deleted file mode 100644
index 7f77b0d..0000000
--- a/modules/core/src/main/java/org/apache/ignite/internal/binary/builder/PortableObjectArrayLazyValue.java
+++ /dev/null
@@ -1,90 +0,0 @@
-/*
- * 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.binary.builder;
-
-import org.apache.ignite.internal.binary.GridPortableMarshaller;
-import org.apache.ignite.internal.binary.BinaryWriterExImpl;
-import org.apache.ignite.internal.util.typedef.internal.U;
-import org.apache.ignite.binary.BinaryInvalidTypeException;
-
-/**
- *
- */
-class PortableObjectArrayLazyValue extends PortableAbstractLazyValue {
-    /** */
-    private Object[] lazyValsArr;
-
-    /** */
-    private int compTypeId;
-
-    /** */
-    private String clsName;
-
-    /**
-     * @param reader Reader.
-     */
-    protected PortableObjectArrayLazyValue(PortableBuilderReader reader) {
-        super(reader, reader.position() - 1);
-
-        int typeId = reader.readInt();
-
-        if (typeId == GridPortableMarshaller.UNREGISTERED_TYPE_ID) {
-            clsName = reader.readString();
-
-            Class cls;
-
-            try {
-                cls = U.forName(reader.readString(), reader.portableContext().configuration().getClassLoader());
-            }
-            catch (ClassNotFoundException e) {
-                throw new BinaryInvalidTypeException("Failed to load the class: " + clsName, e);
-            }
-
-            compTypeId = reader.portableContext().descriptorForClass(cls, true).typeId();
-        }
-        else {
-            compTypeId = typeId;
-            clsName = null;
-        }
-
-        int size = reader.readInt();
-
-        lazyValsArr = new Object[size];
-
-        for (int i = 0; i < size; i++)
-            lazyValsArr[i] = reader.parseValue();
-    }
-
-    /** {@inheritDoc} */
-    @Override protected Object init() {
-        for (int i = 0; i < lazyValsArr.length; i++) {
-            if (lazyValsArr[i] instanceof PortableLazyValue)
-                lazyValsArr[i] = ((PortableLazyValue)lazyValsArr[i]).value();
-        }
-
-        return lazyValsArr;
-    }
-
-    /** {@inheritDoc} */
-    @Override public void writeTo(BinaryWriterExImpl writer, PortableBuilderSerializer ctx) {
-        if (clsName == null)
-            ctx.writeArray(writer, GridPortableMarshaller.OBJ_ARR, lazyValsArr, compTypeId);
-        else
-            ctx.writeArray(writer, GridPortableMarshaller.OBJ_ARR, lazyValsArr, clsName);
-    }
-}

http://git-wip-us.apache.org/repos/asf/ignite/blob/71ad9cea/modules/core/src/main/java/org/apache/ignite/internal/binary/builder/PortablePlainLazyValue.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/binary/builder/PortablePlainLazyValue.java b/modules/core/src/main/java/org/apache/ignite/internal/binary/builder/PortablePlainLazyValue.java
deleted file mode 100644
index f572415..0000000
--- a/modules/core/src/main/java/org/apache/ignite/internal/binary/builder/PortablePlainLazyValue.java
+++ /dev/null
@@ -1,49 +0,0 @@
-/*
- * 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.binary.builder;
-
-import org.apache.ignite.internal.binary.BinaryWriterExImpl;
-
-/**
- *
- */
-class PortablePlainLazyValue extends PortableAbstractLazyValue {
-    /** */
-    protected final int len;
-
-    /**
-     * @param reader Reader
-     * @param valOff Offset
-     * @param len Length.
-     */
-    protected PortablePlainLazyValue(PortableBuilderReader reader, int valOff, int len) {
-        super(reader, valOff);
-
-        this.len = len;
-    }
-
-    /** {@inheritDoc} */
-    @Override protected Object init() {
-        return reader.reader().unmarshal(valOff);
-    }
-
-    /** {@inheritDoc} */
-    @Override public void writeTo(BinaryWriterExImpl writer, PortableBuilderSerializer ctx) {
-        writer.write(reader.array(), valOff, len);
-    }
-}

http://git-wip-us.apache.org/repos/asf/ignite/blob/71ad9cea/modules/core/src/main/java/org/apache/ignite/internal/binary/builder/PortablePlainPortableObject.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/binary/builder/PortablePlainPortableObject.java b/modules/core/src/main/java/org/apache/ignite/internal/binary/builder/PortablePlainPortableObject.java
deleted file mode 100644
index 3b77a52..0000000
--- a/modules/core/src/main/java/org/apache/ignite/internal/binary/builder/PortablePlainPortableObject.java
+++ /dev/null
@@ -1,56 +0,0 @@
-/*
- * 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.binary.builder;
-
-import org.apache.ignite.internal.binary.BinaryObjectImpl;
-import org.apache.ignite.internal.binary.BinaryObjectOffheapImpl;
-import org.apache.ignite.internal.binary.BinaryWriterExImpl;
-import org.apache.ignite.internal.binary.BinaryObjectImpl;
-import org.apache.ignite.internal.binary.BinaryObjectOffheapImpl;
-import org.apache.ignite.internal.binary.BinaryWriterExImpl;
-import org.apache.ignite.binary.BinaryObject;
-
-/**
- *
- */
-public class PortablePlainPortableObject implements PortableLazyValue {
-    /** */
-    private final BinaryObject portableObj;
-
-    /**
-     * @param portableObj Portable object.
-     */
-    public PortablePlainPortableObject(BinaryObject portableObj) {
-        this.portableObj = portableObj;
-    }
-
-    /** {@inheritDoc} */
-    @Override public Object value() {
-        return portableObj;
-    }
-
-    /** {@inheritDoc} */
-    @Override public void writeTo(BinaryWriterExImpl writer, PortableBuilderSerializer ctx) {
-        BinaryObject val = portableObj;
-
-        if (val instanceof BinaryObjectOffheapImpl)
-            val = ((BinaryObjectOffheapImpl)val).heapCopy();
-
-        writer.doWritePortableObject((BinaryObjectImpl)val);
-    }
-}


[55/59] [abbrv] ignite git commit: ignite-2065: rename "portable" classes to "binary"

Posted by ak...@apache.org.
ignite-2065: rename "portable" classes to "binary"


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

Branch: refs/heads/ignite-843-rc2
Commit: 71ad9ceadee77cf6729db6582980038564ef2dea
Parents: 2b3c93e
Author: ashutak <as...@gridgain.com>
Authored: Fri Dec 11 17:40:51 2015 +0300
Committer: ashutak <as...@gridgain.com>
Committed: Fri Dec 11 17:40:51 2015 +0300

----------------------------------------------------------------------
 .../examples/CacheClientBinaryExampleTest.java  |   46 +
 .../CacheClientPortableExampleTest.java         |   46 -
 .../ComputeClientBinaryExampleTest.java         |   37 +
 .../ComputeClientPortableExampleTest.java       |   37 -
 .../testsuites/IgniteExamplesSelfTestSuite.java |   13 +-
 .../binary/BinaryCachingMetadataHandler.java    |    2 +-
 .../internal/binary/BinaryClassDescriptor.java  |  813 ++++++++
 .../ignite/internal/binary/BinaryContext.java   | 1102 ++++++++++
 .../internal/binary/BinaryEnumObjectImpl.java   |   10 +-
 .../internal/binary/BinaryFieldAccessor.java    |    4 +-
 .../ignite/internal/binary/BinaryFieldImpl.java |   10 +-
 .../internal/binary/BinaryMarshaller.java       |    8 +-
 .../ignite/internal/binary/BinaryMetadata.java  |   12 +-
 .../binary/BinaryMetadataCollector.java         |    8 +-
 .../internal/binary/BinaryObjectExImpl.java     |    2 +-
 .../internal/binary/BinaryObjectImpl.java       |  110 +-
 .../binary/BinaryObjectOffheapImpl.java         |  121 +-
 .../internal/binary/BinaryPositionReadable.java |   47 +
 .../internal/binary/BinaryPrimitives.java       |  382 ++++
 .../internal/binary/BinaryRawWriterEx.java      |    4 +-
 .../internal/binary/BinaryReaderExImpl.java     |  284 +--
 .../ignite/internal/binary/BinarySchema.java    |  466 +++++
 .../internal/binary/BinarySchemaRegistry.java   |  172 ++
 .../binary/BinaryThreadLocalContext.java        |    9 +-
 .../ignite/internal/binary/BinaryTypeImpl.java  |    6 +-
 .../ignite/internal/binary/BinaryUtils.java     | 1859 +++++++++++++++++
 .../ignite/internal/binary/BinaryWriteMode.java |   92 +-
 .../internal/binary/BinaryWriterExImpl.java     |  260 +--
 .../binary/BinaryWriterSchemaHolder.java        |   19 +-
 .../internal/binary/GridBinaryMarshaller.java   |  286 +++
 .../internal/binary/GridPortableMarshaller.java |  289 ---
 .../binary/PortableClassDescriptor.java         |  813 --------
 .../ignite/internal/binary/PortableContext.java | 1102 ----------
 .../binary/PortablePositionReadable.java        |   47 -
 .../internal/binary/PortablePrimitives.java     |  382 ----
 .../ignite/internal/binary/PortableSchema.java  |  466 -----
 .../internal/binary/PortableSchemaRegistry.java |  172 --
 .../ignite/internal/binary/PortableUtils.java   | 1909 ------------------
 .../binary/builder/BinaryAbstractLazyValue.java |   57 +
 .../binary/builder/BinaryBuilderEnum.java       |  115 ++
 .../binary/builder/BinaryBuilderReader.java     |  846 ++++++++
 .../BinaryBuilderSerializationAware.java        |   31 +
 .../binary/builder/BinaryBuilderSerializer.java |  217 ++
 .../builder/BinaryEnumArrayLazyValue.java       |  113 ++
 .../binary/builder/BinaryLazyArrayList.java     |  167 ++
 .../binary/builder/BinaryLazyLinkedList.java    |  218 ++
 .../internal/binary/builder/BinaryLazyMap.java  |  221 ++
 .../internal/binary/builder/BinaryLazySet.java  |   92 +
 .../binary/builder/BinaryLazyValue.java         |   28 +
 .../builder/BinaryModifiableLazyValue.java      |   52 +
 .../builder/BinaryObjectArrayLazyValue.java     |   90 +
 .../binary/builder/BinaryObjectBuilderImpl.java |  120 +-
 .../binary/builder/BinaryPlainBinaryObject.java |   53 +
 .../binary/builder/BinaryPlainLazyValue.java    |   49 +
 .../binary/builder/BinaryValueWithType.java     |   76 +
 .../builder/PortableAbstractLazyValue.java      |   57 -
 .../binary/builder/PortableBuilderEnum.java     |  115 --
 .../binary/builder/PortableBuilderReader.java   |  857 --------
 .../PortableBuilderSerializationAware.java      |   31 -
 .../builder/PortableBuilderSerializer.java      |  217 --
 .../builder/PortableEnumArrayLazyValue.java     |  115 --
 .../binary/builder/PortableLazyArrayList.java   |  167 --
 .../binary/builder/PortableLazyLinkedList.java  |  218 --
 .../binary/builder/PortableLazyMap.java         |  221 --
 .../binary/builder/PortableLazySet.java         |   94 -
 .../binary/builder/PortableLazyValue.java       |   28 -
 .../builder/PortableModifiableLazyValue.java    |   52 -
 .../builder/PortableObjectArrayLazyValue.java   |   90 -
 .../binary/builder/PortablePlainLazyValue.java  |   49 -
 .../builder/PortablePlainPortableObject.java    |   56 -
 .../binary/builder/PortableValueWithType.java   |   77 -
 .../streams/BinaryAbstractInputStream.java      |  379 ++++
 .../streams/BinaryAbstractOutputStream.java     |  347 ++++
 .../binary/streams/BinaryAbstractStream.java    |   80 +
 .../binary/streams/BinaryHeapInputStream.java   |  166 ++
 .../binary/streams/BinaryHeapOutputStream.java  |  176 ++
 .../binary/streams/BinaryInputStream.java       |  162 ++
 .../binary/streams/BinaryMemoryAllocator.java   |   57 +
 .../streams/BinaryMemoryAllocatorChunk.java     |  117 ++
 .../streams/BinaryOffheapInputStream.java       |  144 ++
 .../streams/BinaryOffheapOutputStream.java      |  222 ++
 .../binary/streams/BinaryOutputStream.java      |  259 +++
 .../internal/binary/streams/BinaryStream.java   |   53 +
 .../streams/PortableAbstractInputStream.java    |  379 ----
 .../streams/PortableAbstractOutputStream.java   |  347 ----
 .../binary/streams/PortableAbstractStream.java  |   80 -
 .../binary/streams/PortableHeapInputStream.java |  166 --
 .../streams/PortableHeapOutputStream.java       |  176 --
 .../binary/streams/PortableInputStream.java     |  163 --
 .../binary/streams/PortableMemoryAllocator.java |   57 -
 .../streams/PortableMemoryAllocatorChunk.java   |  117 --
 .../streams/PortableOffheapInputStream.java     |  144 --
 .../streams/PortableOffheapOutputStream.java    |  222 --
 .../binary/streams/PortableOutputStream.java    |  259 ---
 .../internal/binary/streams/PortableStream.java |   53 -
 .../processors/cache/CacheObjectContext.java    |    6 +-
 .../cache/binary/BinaryMetadataKey.java         |   82 +
 .../CacheDefaultBinaryAffinityKeyMapper.java    |   51 +
 .../CacheDefaultPortableAffinityKeyMapper.java  |   51 -
 .../cache/binary/CacheObjectBinaryContext.java  |   56 +
 .../binary/CacheObjectBinaryProcessorImpl.java  |  104 +-
 .../binary/CacheObjectPortableContext.java      |   56 -
 .../cache/binary/PortableMetadataKey.java       |   82 -
 .../platform/PlatformContextImpl.java           |    4 +-
 .../PlatformDotNetConfigurationClosure.java     |   10 +-
 .../platform/memory/PlatformInputStream.java    |    4 +-
 .../platform/memory/PlatformOutputStream.java   |    4 +-
 .../message/GridClientBinaryMetaData.java       |   71 +
 .../message/GridClientPortableMetaData.java     |   71 -
 .../binary/BinaryFieldsAbstractSelfTest.java    |    6 +-
 .../BinaryFooterOffsetsAbstractSelfTest.java    |    4 +-
 .../binary/BinaryMarshallerSelfTest.java        |   24 +-
 .../BinaryObjectBuilderAdditionalSelfTest.java  |   10 +-
 .../binary/GridBinaryAffinityKeySelfTest.java   |  234 +++
 ...GridBinaryMarshallerCtxDisabledSelfTest.java |  247 +++
 .../binary/GridPortableAffinityKeySelfTest.java |  234 ---
 ...idPortableMarshallerCtxDisabledSelfTest.java |  247 ---
 .../binary/GridPortableWildcardsSelfTest.java   |   30 +-
 .../GridBinaryCacheEntryMemorySizeSelfTest.java |   48 +
 ...ryDuplicateIndexObjectsAbstractSelfTest.java |  161 ++
 .../GridCacheBinaryStoreAbstractSelfTest.java   |  300 +++
 .../GridCacheBinaryStoreObjectsSelfTest.java    |   55 +
 .../GridCacheBinaryStorePortablesSelfTest.java  |   66 +
 .../GridCachePortableStoreAbstractSelfTest.java |  300 ---
 .../GridCachePortableStoreObjectsSelfTest.java  |   55 -
 ...GridCachePortableStorePortablesSelfTest.java |   66 -
 ...ridPortableCacheEntryMemorySizeSelfTest.java |   48 -
 ...leDuplicateIndexObjectsAbstractSelfTest.java |  161 --
 .../DataStreamProcessorBinarySelfTest.java      |   71 +
 .../DataStreamProcessorPortableSelfTest.java    |   71 -
 .../GridCacheAffinityRoutingBinarySelfTest.java |   54 +
 ...ridCacheAffinityRoutingPortableSelfTest.java |   54 -
 ...OnlyBinaryDataStreamerMultiNodeSelfTest.java |   29 +
 ...BinaryDataStreamerMultithreadedSelfTest.java |   47 +
 ...cPartitionedOnlyBinaryMultiNodeSelfTest.java |   28 +
 ...titionedOnlyBinaryMultithreadedSelfTest.java |   47 +
 ...lyPortableDataStreamerMultiNodeSelfTest.java |   29 -
 ...rtableDataStreamerMultithreadedSelfTest.java |   47 -
 ...artitionedOnlyPortableMultiNodeSelfTest.java |   28 -
 ...tionedOnlyPortableMultithreadedSelfTest.java |   47 -
 ...sPartitionedOnlyByteArrayValuesSelfTest.java |   42 +
 ...ateIndexObjectPartitionedAtomicSelfTest.java |   38 +
 ...xObjectPartitionedTransactionalSelfTest.java |   41 +
 .../dht/GridCacheMemoryModeBinarySelfTest.java  |   36 +
 .../GridCacheMemoryModePortableSelfTest.java    |   36 -
 ...dCacheOffHeapTieredAtomicBinarySelfTest.java |   48 +
 ...acheOffHeapTieredAtomicPortableSelfTest.java |   48 -
 .../GridCacheOffHeapTieredBinarySelfTest.java   |   48 +
 ...fHeapTieredEvictionAtomicBinarySelfTest.java |   96 +
 ...eapTieredEvictionAtomicPortableSelfTest.java |   96 -
 ...acheOffHeapTieredEvictionBinarySelfTest.java |   96 +
 ...heOffHeapTieredEvictionPortableSelfTest.java |   96 -
 .../GridCacheOffHeapTieredPortableSelfTest.java |   48 -
 ...ateIndexObjectPartitionedAtomicSelfTest.java |   38 -
 ...xObjectPartitionedTransactionalSelfTest.java |   41 -
 ...sPartitionedOnlyByteArrayValuesSelfTest.java |   42 -
 .../session/GridSessionCheckpointSelfTest.java  |    4 +-
 .../ignite/testframework/junits/IgniteMock.java |    6 +-
 .../junits/IgniteTestResources.java             |    4 +-
 .../IgnitePortableCacheTestSuite.java           |   52 +-
 .../IgnitePortableObjectsTestSuite.java         |   16 +-
 .../CacheDeploymentBinaryEntryProcessor.java    |   35 +
 .../CacheDeploymentPortableEntryProcessor.java  |   35 -
 .../IgnitePortableCacheQueryTestSuite.java      |    8 +-
 164 files changed, 12582 insertions(+), 12729 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/71ad9cea/examples/src/test/java/org/apache/ignite/examples/CacheClientBinaryExampleTest.java
----------------------------------------------------------------------
diff --git a/examples/src/test/java/org/apache/ignite/examples/CacheClientBinaryExampleTest.java b/examples/src/test/java/org/apache/ignite/examples/CacheClientBinaryExampleTest.java
new file mode 100644
index 0000000..d5f8cc0
--- /dev/null
+++ b/examples/src/test/java/org/apache/ignite/examples/CacheClientBinaryExampleTest.java
@@ -0,0 +1,46 @@
+/*
+ * 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.examples;
+
+import org.apache.ignite.examples.binary.datagrid.CacheClientBinaryPutGetExample;
+import org.apache.ignite.examples.binary.datagrid.CacheClientBinaryQueryExample;
+import org.apache.ignite.testframework.junits.common.GridAbstractExamplesTest;
+
+/**
+ *
+ */
+public class CacheClientBinaryExampleTest extends GridAbstractExamplesTest {
+    /** {@inheritDoc} */
+    @Override protected String defaultConfig() {
+        return "examples/config/portable/example-ignite-portable.xml";
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testPortablePutGetExample() throws Exception {
+        CacheClientBinaryPutGetExample.main(new String[] {});
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testPortableQueryExample() throws Exception {
+        CacheClientBinaryQueryExample.main(new String[] {});
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/71ad9cea/examples/src/test/java/org/apache/ignite/examples/CacheClientPortableExampleTest.java
----------------------------------------------------------------------
diff --git a/examples/src/test/java/org/apache/ignite/examples/CacheClientPortableExampleTest.java b/examples/src/test/java/org/apache/ignite/examples/CacheClientPortableExampleTest.java
deleted file mode 100644
index 22261e2..0000000
--- a/examples/src/test/java/org/apache/ignite/examples/CacheClientPortableExampleTest.java
+++ /dev/null
@@ -1,46 +0,0 @@
-/*
- * 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.examples;
-
-import org.apache.ignite.examples.binary.datagrid.CacheClientBinaryPutGetExample;
-import org.apache.ignite.examples.binary.datagrid.CacheClientBinaryQueryExample;
-import org.apache.ignite.testframework.junits.common.GridAbstractExamplesTest;
-
-/**
- *
- */
-public class CacheClientPortableExampleTest extends GridAbstractExamplesTest {
-    /** {@inheritDoc} */
-    @Override protected String defaultConfig() {
-        return "examples/config/portable/example-ignite-portable.xml";
-    }
-
-    /**
-     * @throws Exception If failed.
-     */
-    public void testPortablePutGetExample() throws Exception {
-        CacheClientBinaryPutGetExample.main(new String[] {});
-    }
-
-    /**
-     * @throws Exception If failed.
-     */
-    public void testPortableQueryExample() throws Exception {
-        CacheClientBinaryQueryExample.main(new String[] {});
-    }
-}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ignite/blob/71ad9cea/examples/src/test/java/org/apache/ignite/examples/ComputeClientBinaryExampleTest.java
----------------------------------------------------------------------
diff --git a/examples/src/test/java/org/apache/ignite/examples/ComputeClientBinaryExampleTest.java b/examples/src/test/java/org/apache/ignite/examples/ComputeClientBinaryExampleTest.java
new file mode 100644
index 0000000..bdba7c3
--- /dev/null
+++ b/examples/src/test/java/org/apache/ignite/examples/ComputeClientBinaryExampleTest.java
@@ -0,0 +1,37 @@
+/*
+ * 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.examples;
+
+import org.apache.ignite.examples.binary.computegrid.ComputeClientBinaryTaskExecutionExample;
+import org.apache.ignite.testframework.junits.common.GridAbstractExamplesTest;
+
+/**
+ *
+ */
+public class ComputeClientBinaryExampleTest extends GridAbstractExamplesTest {
+    /** {@inheritDoc} */
+    @Override protected String defaultConfig() {
+        return "examples/config/portable/example-ignite-portable.xml";
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testPortableTaskExecutionExample() throws Exception {
+        ComputeClientBinaryTaskExecutionExample.main(new String[] {});
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/71ad9cea/examples/src/test/java/org/apache/ignite/examples/ComputeClientPortableExampleTest.java
----------------------------------------------------------------------
diff --git a/examples/src/test/java/org/apache/ignite/examples/ComputeClientPortableExampleTest.java b/examples/src/test/java/org/apache/ignite/examples/ComputeClientPortableExampleTest.java
deleted file mode 100644
index 44d8776..0000000
--- a/examples/src/test/java/org/apache/ignite/examples/ComputeClientPortableExampleTest.java
+++ /dev/null
@@ -1,37 +0,0 @@
-/*
- * 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.examples;
-
-import org.apache.ignite.examples.binary.computegrid.ComputeClientBinaryTaskExecutionExample;
-import org.apache.ignite.testframework.junits.common.GridAbstractExamplesTest;
-
-/**
- *
- */
-public class ComputeClientPortableExampleTest extends GridAbstractExamplesTest {
-    /** {@inheritDoc} */
-    @Override protected String defaultConfig() {
-        return "examples/config/portable/example-ignite-portable.xml";
-    }
-
-    /**
-     * @throws Exception If failed.
-     */
-    public void testPortableTaskExecutionExample() throws Exception {
-        ComputeClientBinaryTaskExecutionExample.main(new String[] {});
-    }
-}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ignite/blob/71ad9cea/examples/src/test/java/org/apache/ignite/testsuites/IgniteExamplesSelfTestSuite.java
----------------------------------------------------------------------
diff --git a/examples/src/test/java/org/apache/ignite/testsuites/IgniteExamplesSelfTestSuite.java b/examples/src/test/java/org/apache/ignite/testsuites/IgniteExamplesSelfTestSuite.java
index 4412af3..54fa8a3 100644
--- a/examples/src/test/java/org/apache/ignite/testsuites/IgniteExamplesSelfTestSuite.java
+++ b/examples/src/test/java/org/apache/ignite/testsuites/IgniteExamplesSelfTestSuite.java
@@ -20,12 +20,12 @@ package org.apache.ignite.testsuites;
 import junit.framework.TestSuite;
 import org.apache.ignite.examples.BasicExamplesMultiNodeSelfTest;
 import org.apache.ignite.examples.BasicExamplesSelfTest;
-import org.apache.ignite.examples.CacheClientPortableExampleTest;
+import org.apache.ignite.examples.CacheClientBinaryExampleTest;
 import org.apache.ignite.examples.CacheExamplesMultiNodeSelfTest;
 import org.apache.ignite.examples.CacheExamplesSelfTest;
 import org.apache.ignite.examples.CheckpointExamplesSelfTest;
 import org.apache.ignite.examples.ClusterGroupExampleSelfTest;
-import org.apache.ignite.examples.ComputeClientPortableExampleTest;
+import org.apache.ignite.examples.ComputeClientBinaryExampleTest;
 import org.apache.ignite.examples.ContinuationExamplesMultiNodeSelfTest;
 import org.apache.ignite.examples.ContinuationExamplesSelfTest;
 import org.apache.ignite.examples.ContinuousMapperExamplesMultiNodeSelfTest;
@@ -44,9 +44,6 @@ import org.apache.ignite.examples.MonteCarloExamplesSelfTest;
 import org.apache.ignite.examples.SpringBeanExamplesSelfTest;
 import org.apache.ignite.examples.TaskExamplesMultiNodeSelfTest;
 import org.apache.ignite.examples.TaskExamplesSelfTest;
-import org.apache.ignite.testframework.GridTestUtils;
-
-import static org.apache.ignite.IgniteSystemProperties.IGNITE_OVERRIDE_MCAST_GRP;
 
 /**
  * Examples test suite.
@@ -92,9 +89,9 @@ public class IgniteExamplesSelfTestSuite extends TestSuite {
         suite.addTest(new TestSuite(MonteCarloExamplesMultiNodeSelfTest.class));
 
         // Portable.
-        suite.addTest(new TestSuite(CacheClientPortableExampleTest.class));
-        suite.addTest(new TestSuite(ComputeClientPortableExampleTest.class));
+        suite.addTest(new TestSuite(CacheClientBinaryExampleTest.class));
+        suite.addTest(new TestSuite(ComputeClientBinaryExampleTest.class));
 
         return suite;
     }
-}
\ No newline at end of file
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/71ad9cea/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryCachingMetadataHandler.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryCachingMetadataHandler.java b/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryCachingMetadataHandler.java
index 584b683..39189f0 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryCachingMetadataHandler.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryCachingMetadataHandler.java
@@ -54,7 +54,7 @@ public class BinaryCachingMetadataHandler implements BinaryMetadataHandler {
                 BinaryMetadata oldMeta = ((BinaryTypeImpl)oldType).metadata();
                 BinaryMetadata newMeta = ((BinaryTypeImpl)type).metadata();
 
-                BinaryMetadata mergedMeta = PortableUtils.mergeMetadata(oldMeta, newMeta);
+                BinaryMetadata mergedMeta = BinaryUtils.mergeMetadata(oldMeta, newMeta);
 
                 BinaryType mergedType = mergedMeta.wrap(((BinaryTypeImpl)oldType).context());
 

http://git-wip-us.apache.org/repos/asf/ignite/blob/71ad9cea/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryClassDescriptor.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryClassDescriptor.java b/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryClassDescriptor.java
new file mode 100644
index 0000000..0c3275e
--- /dev/null
+++ b/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryClassDescriptor.java
@@ -0,0 +1,813 @@
+/*
+ * 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.binary;
+
+import java.io.Externalizable;
+import java.io.IOException;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+import java.lang.reflect.Constructor;
+import java.lang.reflect.Field;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.lang.reflect.Modifier;
+import java.math.BigDecimal;
+import java.sql.Timestamp;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.UUID;
+import org.apache.ignite.IgniteCheckedException;
+import org.apache.ignite.binary.BinaryIdMapper;
+import org.apache.ignite.binary.BinaryObjectException;
+import org.apache.ignite.binary.BinarySerializer;
+import org.apache.ignite.binary.Binarylizable;
+import org.apache.ignite.internal.processors.cache.CacheObjectImpl;
+import org.apache.ignite.internal.util.GridUnsafe;
+import org.apache.ignite.internal.util.typedef.internal.U;
+import org.apache.ignite.marshaller.MarshallerExclusions;
+import org.apache.ignite.marshaller.optimized.OptimizedMarshaller;
+import org.jetbrains.annotations.Nullable;
+import sun.misc.Unsafe;
+
+import static java.lang.reflect.Modifier.isStatic;
+import static java.lang.reflect.Modifier.isTransient;
+
+/**
+ * Portable class descriptor.
+ */
+public class BinaryClassDescriptor {
+    /** */
+    public static final Unsafe UNSAFE = GridUnsafe.unsafe();
+
+    /** */
+    private final BinaryContext ctx;
+
+    /** */
+    private final Class<?> cls;
+
+    /** */
+    private final BinarySerializer serializer;
+
+    /** ID mapper. */
+    private final BinaryIdMapper idMapper;
+
+    /** */
+    private final BinaryWriteMode mode;
+
+    /** */
+    private final boolean userType;
+
+    /** */
+    private final int typeId;
+
+    /** */
+    private final String typeName;
+
+    /** Affinity key field name. */
+    private final String affKeyFieldName;
+
+    /** */
+    private final Constructor<?> ctor;
+
+    /** */
+    private final BinaryFieldAccessor[] fields;
+
+    /** */
+    private final Method writeReplaceMtd;
+
+    /** */
+    private final Method readResolveMtd;
+
+    /** */
+    private final Map<String, Integer> stableFieldsMeta;
+
+    /** Object schemas. Initialized only for serializable classes and contains only 1 entry. */
+    private final BinarySchema stableSchema;
+
+    /** Schema registry. */
+    private final BinarySchemaRegistry schemaReg;
+
+    /** */
+    private final boolean registered;
+
+    /** */
+    private final boolean useOptMarshaller;
+
+    /** */
+    private final boolean excluded;
+
+    /**
+     * @param ctx Context.
+     * @param cls Class.
+     * @param userType User type flag.
+     * @param typeId Type ID.
+     * @param typeName Type name.
+     * @param affKeyFieldName Affinity key field name.
+     * @param idMapper ID mapper.
+     * @param serializer Serializer.
+     * @param metaDataEnabled Metadata enabled flag.
+     * @param registered Whether typeId has been successfully registered by MarshallerContext or not.
+     * @param predefined Whether the class is predefined or not.
+     * @throws BinaryObjectException In case of error.
+     */
+    BinaryClassDescriptor(
+        BinaryContext ctx,
+        Class<?> cls,
+        boolean userType,
+        int typeId,
+        String typeName,
+        @Nullable String affKeyFieldName,
+        @Nullable BinaryIdMapper idMapper,
+        @Nullable BinarySerializer serializer,
+        boolean metaDataEnabled,
+        boolean registered,
+        boolean predefined
+    ) throws BinaryObjectException {
+        assert ctx != null;
+        assert cls != null;
+        assert idMapper != null;
+
+        this.ctx = ctx;
+        this.cls = cls;
+        this.typeId = typeId;
+        this.userType = userType;
+        this.typeName = typeName;
+        this.affKeyFieldName = affKeyFieldName;
+        this.serializer = serializer;
+        this.idMapper = idMapper;
+        this.registered = registered;
+
+        schemaReg = ctx.schemaRegistry(typeId);
+
+        excluded = MarshallerExclusions.isExcluded(cls);
+
+        useOptMarshaller = !predefined && initUseOptimizedMarshallerFlag();
+
+        if (excluded)
+            mode = BinaryWriteMode.EXCLUSION;
+        else {
+            if (cls == BinaryEnumObjectImpl.class)
+                mode = BinaryWriteMode.PORTABLE_ENUM;
+            else
+                mode = serializer != null ? BinaryWriteMode.PORTABLE : BinaryUtils.mode(cls);
+        }
+
+        switch (mode) {
+            case P_BYTE:
+            case P_BOOLEAN:
+            case P_SHORT:
+            case P_CHAR:
+            case P_INT:
+            case P_LONG:
+            case P_FLOAT:
+            case P_DOUBLE:
+            case BYTE:
+            case SHORT:
+            case INT:
+            case LONG:
+            case FLOAT:
+            case DOUBLE:
+            case CHAR:
+            case BOOLEAN:
+            case DECIMAL:
+            case STRING:
+            case UUID:
+            case DATE:
+            case TIMESTAMP:
+            case BYTE_ARR:
+            case SHORT_ARR:
+            case INT_ARR:
+            case LONG_ARR:
+            case FLOAT_ARR:
+            case DOUBLE_ARR:
+            case CHAR_ARR:
+            case BOOLEAN_ARR:
+            case DECIMAL_ARR:
+            case STRING_ARR:
+            case UUID_ARR:
+            case DATE_ARR:
+            case TIMESTAMP_ARR:
+            case OBJECT_ARR:
+            case COL:
+            case MAP:
+            case PORTABLE_OBJ:
+            case ENUM:
+            case PORTABLE_ENUM:
+            case ENUM_ARR:
+            case CLASS:
+            case EXCLUSION:
+                ctor = null;
+                fields = null;
+                stableFieldsMeta = null;
+                stableSchema = null;
+
+                break;
+
+            case PORTABLE:
+            case EXTERNALIZABLE:
+                ctor = constructor(cls);
+                fields = null;
+                stableFieldsMeta = null;
+                stableSchema = null;
+
+                break;
+
+            case OBJECT:
+                // Must not use constructor to honor transient fields semantics.
+                ctor = null;
+                ArrayList<BinaryFieldAccessor> fields0 = new ArrayList<>();
+                stableFieldsMeta = metaDataEnabled ? new HashMap<String, Integer>() : null;
+
+                BinarySchema.Builder schemaBuilder = BinarySchema.Builder.newBuilder();
+
+                Collection<String> names = new HashSet<>();
+                Collection<Integer> ids = new HashSet<>();
+
+                for (Class<?> c = cls; c != null && !c.equals(Object.class); c = c.getSuperclass()) {
+                    for (Field f : c.getDeclaredFields()) {
+                        int mod = f.getModifiers();
+
+                        if (!isStatic(mod) && !isTransient(mod)) {
+                            f.setAccessible(true);
+
+                            String name = f.getName();
+
+                            if (!names.add(name))
+                                throw new BinaryObjectException("Duplicate field name [fieldName=" + name +
+                                    ", cls=" + cls.getName() + ']');
+
+                            int fieldId = idMapper.fieldId(typeId, name);
+
+                            if (!ids.add(fieldId))
+                                throw new BinaryObjectException("Duplicate field ID: " + name);
+
+                            BinaryFieldAccessor fieldInfo = BinaryFieldAccessor.create(f, fieldId);
+
+                            fields0.add(fieldInfo);
+
+                            schemaBuilder.addField(fieldId);
+
+                            if (metaDataEnabled)
+                                stableFieldsMeta.put(name, fieldInfo.mode().typeId());
+                        }
+                    }
+                }
+
+                fields = fields0.toArray(new BinaryFieldAccessor[fields0.size()]);
+
+                stableSchema = schemaBuilder.build();
+
+                break;
+
+            default:
+                // Should never happen.
+                throw new BinaryObjectException("Invalid mode: " + mode);
+        }
+
+        if (mode == BinaryWriteMode.PORTABLE || mode == BinaryWriteMode.EXTERNALIZABLE ||
+            mode == BinaryWriteMode.OBJECT) {
+            readResolveMtd = U.findNonPublicMethod(cls, "readResolve");
+            writeReplaceMtd = U.findNonPublicMethod(cls, "writeReplace");
+        }
+        else {
+            readResolveMtd = null;
+            writeReplaceMtd = null;
+        }
+    }
+
+    /**
+     * @return {@code True} if enum.
+     */
+    boolean isEnum() {
+        return mode == BinaryWriteMode.ENUM;
+    }
+
+    /**
+     * @return Described class.
+     */
+    Class<?> describedClass() {
+        return cls;
+    }
+
+    /**
+     * @return Type ID.
+     */
+    public int typeId() {
+        return typeId;
+    }
+
+    /**
+     * @return User type flag.
+     */
+    public boolean userType() {
+        return userType;
+    }
+
+    /**
+     * @return Fields meta data.
+     */
+    Map<String, Integer> fieldsMeta() {
+        return stableFieldsMeta;
+    }
+
+    /**
+     * @return Schema.
+     */
+    BinarySchema schema() {
+        return stableSchema;
+    }
+
+    /**
+     * @return Whether typeId has been successfully registered by MarshallerContext or not.
+     */
+    public boolean registered() {
+        return registered;
+    }
+
+    /**
+     * @return {@code true} if {@link OptimizedMarshaller} must be used instead of {@link BinaryMarshaller}
+     * for object serialization and deserialization.
+     */
+    public boolean useOptimizedMarshaller() {
+        return useOptMarshaller;
+    }
+
+    /**
+     * Checks whether the class values are explicitly excluded from marshalling.
+     *
+     * @return {@code true} if excluded, {@code false} otherwise.
+     */
+    public boolean excluded() {
+        return excluded;
+    }
+
+    /**
+     * @return portableWriteReplace() method
+     */
+    @Nullable Method getWriteReplaceMethod() {
+        return writeReplaceMtd;
+    }
+
+    /**
+     * @return portableReadResolve() method
+     */
+    @SuppressWarnings("UnusedDeclaration")
+    @Nullable Method getReadResolveMethod() {
+        return readResolveMtd;
+    }
+
+    /**
+     * @param obj Object.
+     * @param writer Writer.
+     * @throws BinaryObjectException In case of error.
+     */
+    void write(Object obj, BinaryWriterExImpl writer) throws BinaryObjectException {
+        assert obj != null;
+        assert writer != null;
+
+        writer.typeId(typeId);
+
+        switch (mode) {
+            case P_BYTE:
+            case BYTE:
+                writer.writeByteFieldPrimitive((byte) obj);
+
+                break;
+
+            case P_SHORT:
+            case SHORT:
+                writer.writeShortFieldPrimitive((short)obj);
+
+                break;
+
+            case P_INT:
+            case INT:
+                writer.writeIntFieldPrimitive((int) obj);
+
+                break;
+
+            case P_LONG:
+            case LONG:
+                writer.writeLongFieldPrimitive((long) obj);
+
+                break;
+
+            case P_FLOAT:
+            case FLOAT:
+                writer.writeFloatFieldPrimitive((float) obj);
+
+                break;
+
+            case P_DOUBLE:
+            case DOUBLE:
+                writer.writeDoubleFieldPrimitive((double) obj);
+
+                break;
+
+            case P_CHAR:
+            case CHAR:
+                writer.writeCharFieldPrimitive((char) obj);
+
+                break;
+
+            case P_BOOLEAN:
+            case BOOLEAN:
+                writer.writeBooleanFieldPrimitive((boolean) obj);
+
+                break;
+
+            case DECIMAL:
+                writer.doWriteDecimal((BigDecimal)obj);
+
+                break;
+
+            case STRING:
+                writer.doWriteString((String)obj);
+
+                break;
+
+            case UUID:
+                writer.doWriteUuid((UUID)obj);
+
+                break;
+
+            case DATE:
+                writer.doWriteDate((Date)obj);
+
+                break;
+
+            case TIMESTAMP:
+                writer.doWriteTimestamp((Timestamp)obj);
+
+                break;
+
+            case BYTE_ARR:
+                writer.doWriteByteArray((byte[])obj);
+
+                break;
+
+            case SHORT_ARR:
+                writer.doWriteShortArray((short[]) obj);
+
+                break;
+
+            case INT_ARR:
+                writer.doWriteIntArray((int[]) obj);
+
+                break;
+
+            case LONG_ARR:
+                writer.doWriteLongArray((long[]) obj);
+
+                break;
+
+            case FLOAT_ARR:
+                writer.doWriteFloatArray((float[]) obj);
+
+                break;
+
+            case DOUBLE_ARR:
+                writer.doWriteDoubleArray((double[]) obj);
+
+                break;
+
+            case CHAR_ARR:
+                writer.doWriteCharArray((char[]) obj);
+
+                break;
+
+            case BOOLEAN_ARR:
+                writer.doWriteBooleanArray((boolean[]) obj);
+
+                break;
+
+            case DECIMAL_ARR:
+                writer.doWriteDecimalArray((BigDecimal[]) obj);
+
+                break;
+
+            case STRING_ARR:
+                writer.doWriteStringArray((String[]) obj);
+
+                break;
+
+            case UUID_ARR:
+                writer.doWriteUuidArray((UUID[]) obj);
+
+                break;
+
+            case DATE_ARR:
+                writer.doWriteDateArray((Date[]) obj);
+
+                break;
+
+            case TIMESTAMP_ARR:
+                writer.doWriteTimestampArray((Timestamp[]) obj);
+
+                break;
+
+            case OBJECT_ARR:
+                writer.doWriteObjectArray((Object[])obj);
+
+                break;
+
+            case COL:
+                writer.doWriteCollection((Collection<?>)obj);
+
+                break;
+
+            case MAP:
+                writer.doWriteMap((Map<?, ?>)obj);
+
+                break;
+
+            case ENUM:
+                writer.doWriteEnum((Enum<?>)obj);
+
+                break;
+
+            case PORTABLE_ENUM:
+                writer.doWritePortableEnum((BinaryEnumObjectImpl)obj);
+
+                break;
+
+            case ENUM_ARR:
+                writer.doWriteEnumArray((Object[])obj);
+
+                break;
+
+            case CLASS:
+                writer.doWriteClass((Class)obj);
+
+                break;
+
+            case PORTABLE_OBJ:
+                writer.doWritePortableObject((BinaryObjectImpl)obj);
+
+                break;
+
+            case PORTABLE:
+                if (preWrite(writer, obj)) {
+                    try {
+                        if (serializer != null)
+                            serializer.writeBinary(obj, writer);
+                        else
+                            ((Binarylizable)obj).writeBinary(writer);
+
+                        postWrite(writer, obj);
+
+                        // Check whether we need to update metadata.
+                        if (obj.getClass() != BinaryMetadata.class) {
+                            int schemaId = writer.schemaId();
+
+                            if (schemaReg.schema(schemaId) == null) {
+                                // This is new schema, let's update metadata.
+                                BinaryMetadataCollector collector =
+                                    new BinaryMetadataCollector(typeId, typeName, idMapper);
+
+                                if (serializer != null)
+                                    serializer.writeBinary(obj, collector);
+                                else
+                                    ((Binarylizable)obj).writeBinary(collector);
+
+                                BinarySchema newSchema = collector.schema();
+
+                                BinaryMetadata meta = new BinaryMetadata(typeId, typeName, collector.meta(),
+                                    affKeyFieldName, Collections.singleton(newSchema), false);
+
+                                ctx.updateMetadata(typeId, meta);
+
+                                schemaReg.addSchema(newSchema.schemaId(), newSchema);
+                            }
+                        }
+                    }
+                    finally {
+                        writer.popSchema();
+                    }
+                }
+
+                break;
+
+            case EXTERNALIZABLE:
+                if (preWrite(writer, obj)) {
+                    writer.rawWriter();
+
+                    try {
+                        ((Externalizable)obj).writeExternal(writer);
+
+                        postWrite(writer, obj);
+                    }
+                    catch (IOException e) {
+                        throw new BinaryObjectException("Failed to write Externalizable object: " + obj, e);
+                    }
+                    finally {
+                        writer.popSchema();
+                    }
+                }
+
+                break;
+
+            case OBJECT:
+                if (preWrite(writer, obj)) {
+                    try {
+                        for (BinaryFieldAccessor info : fields)
+                            info.write(obj, writer);
+
+                        writer.schemaId(stableSchema.schemaId());
+
+                        postWrite(writer, obj);
+                    }
+                    finally {
+                        writer.popSchema();
+                    }
+                }
+
+                break;
+
+            default:
+                assert false : "Invalid mode: " + mode;
+        }
+    }
+
+    /**
+     * @param reader Reader.
+     * @return Object.
+     * @throws BinaryObjectException If failed.
+     */
+    Object read(BinaryReaderExImpl reader) throws BinaryObjectException {
+        assert reader != null;
+
+        Object res;
+
+        switch (mode) {
+            case PORTABLE:
+                res = newInstance();
+
+                reader.setHandle(res);
+
+                if (serializer != null)
+                    serializer.readBinary(res, reader);
+                else
+                    ((Binarylizable)res).readBinary(reader);
+
+                break;
+
+            case EXTERNALIZABLE:
+                res = newInstance();
+
+                reader.setHandle(res);
+
+                try {
+                    ((Externalizable)res).readExternal(reader);
+                }
+                catch (IOException | ClassNotFoundException e) {
+                    throw new BinaryObjectException("Failed to read Externalizable object: " +
+                        res.getClass().getName(), e);
+                }
+
+                break;
+
+            case OBJECT:
+                res = newInstance();
+
+                reader.setHandle(res);
+
+                for (BinaryFieldAccessor info : fields)
+                    info.read(res, reader);
+
+                break;
+
+            default:
+                assert false : "Invalid mode: " + mode;
+
+                return null;
+        }
+
+        if (readResolveMtd != null) {
+            try {
+                res = readResolveMtd.invoke(res);
+
+                reader.setHandle(res);
+            }
+            catch (IllegalAccessException e) {
+                throw new RuntimeException(e);
+            }
+            catch (InvocationTargetException e) {
+                if (e.getTargetException() instanceof BinaryObjectException)
+                    throw (BinaryObjectException)e.getTargetException();
+
+                throw new BinaryObjectException("Failed to execute readResolve() method on " + res, e);
+            }
+        }
+
+        return res;
+    }
+
+    /**
+     * Pre-write phase.
+     *
+     * @param writer Writer.
+     * @param obj Object.
+     * @return Whether further write is needed.
+     */
+    private boolean preWrite(BinaryWriterExImpl writer, Object obj) {
+        if (writer.tryWriteAsHandle(obj))
+            return false;
+
+        writer.preWrite(registered ? null : cls.getName());
+
+        return true;
+    }
+
+    /**
+     * Post-write phase.
+     *
+     * @param writer Writer.
+     * @param obj Object.
+     */
+    private void postWrite(BinaryWriterExImpl writer, Object obj) {
+        writer.postWrite(userType, registered, obj instanceof CacheObjectImpl ? 0 : obj.hashCode());
+    }
+
+    /**
+     * @return Instance.
+     * @throws BinaryObjectException In case of error.
+     */
+    private Object newInstance() throws BinaryObjectException {
+        try {
+            return ctor != null ? ctor.newInstance() : UNSAFE.allocateInstance(cls);
+        }
+        catch (InstantiationException | InvocationTargetException | IllegalAccessException e) {
+            throw new BinaryObjectException("Failed to instantiate instance: " + cls, e);
+        }
+    }
+
+    /**
+     * @param cls Class.
+     * @return Constructor.
+     * @throws BinaryObjectException If constructor doesn't exist.
+     */
+    @SuppressWarnings("ConstantConditions")
+    @Nullable private static Constructor<?> constructor(Class<?> cls) throws BinaryObjectException {
+        assert cls != null;
+
+        try {
+            Constructor<?> ctor = U.forceEmptyConstructor(cls);
+
+            if (ctor == null)
+                throw new BinaryObjectException("Failed to find empty constructor for class: " + cls.getName());
+
+            ctor.setAccessible(true);
+
+            return ctor;
+        }
+        catch (IgniteCheckedException e) {
+            throw new BinaryObjectException("Failed to get constructor for class: " + cls.getName(), e);
+        }
+    }
+
+    /**
+     * Determines whether to use {@link OptimizedMarshaller} for serialization or
+     * not.
+     *
+     * @return {@code true} if to use, {@code false} otherwise.
+     */
+    @SuppressWarnings("unchecked")
+    private boolean initUseOptimizedMarshallerFlag() {
+        for (Class c = cls; c != null && !c.equals(Object.class); c = c.getSuperclass()) {
+            try {
+                Method writeObj = c.getDeclaredMethod("writeObject", ObjectOutputStream.class);
+                Method readObj = c.getDeclaredMethod("readObject", ObjectInputStream.class);
+
+                if (!Modifier.isStatic(writeObj.getModifiers()) && !Modifier.isStatic(readObj.getModifiers()) &&
+                    writeObj.getReturnType() == void.class && readObj.getReturnType() == void.class)
+                    return true;
+            }
+            catch (NoSuchMethodException ignored) {
+                // No-op.
+            }
+        }
+
+        return false;
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/71ad9cea/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryContext.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryContext.java b/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryContext.java
new file mode 100644
index 0000000..6293cfe
--- /dev/null
+++ b/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryContext.java
@@ -0,0 +1,1102 @@
+/*
+ * 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.binary;
+
+import org.apache.ignite.IgniteCheckedException;
+import org.apache.ignite.binary.BinaryIdMapper;
+import org.apache.ignite.binary.BinaryInvalidTypeException;
+import org.apache.ignite.binary.BinaryObjectException;
+import org.apache.ignite.binary.BinarySerializer;
+import org.apache.ignite.binary.BinaryType;
+import org.apache.ignite.binary.BinaryTypeConfiguration;
+import org.apache.ignite.cache.CacheKeyConfiguration;
+import org.apache.ignite.cache.affinity.AffinityKeyMapped;
+import org.apache.ignite.configuration.BinaryConfiguration;
+import org.apache.ignite.configuration.IgniteConfiguration;
+import org.apache.ignite.internal.IgniteKernal;
+import org.apache.ignite.internal.IgnitionEx;
+import org.apache.ignite.internal.processors.cache.binary.CacheObjectBinaryProcessorImpl;
+import org.apache.ignite.internal.processors.datastructures.CollocatedQueueItemKey;
+import org.apache.ignite.internal.processors.datastructures.CollocatedSetItemKey;
+import org.apache.ignite.internal.util.IgniteUtils;
+import org.apache.ignite.internal.util.lang.GridMapEntry;
+import org.apache.ignite.internal.util.typedef.F;
+import org.apache.ignite.internal.util.typedef.T2;
+import org.apache.ignite.internal.util.typedef.internal.U;
+import org.apache.ignite.lang.IgniteBiTuple;
+import org.apache.ignite.marshaller.MarshallerContext;
+import org.apache.ignite.marshaller.optimized.OptimizedMarshaller;
+import org.jetbrains.annotations.Nullable;
+import org.jsr166.ConcurrentHashMap8;
+
+import java.io.Externalizable;
+import java.io.File;
+import java.io.IOException;
+import java.io.InvalidObjectException;
+import java.io.ObjectInput;
+import java.io.ObjectOutput;
+import java.io.ObjectStreamException;
+import java.lang.reflect.Field;
+import java.math.BigDecimal;
+import java.net.URISyntaxException;
+import java.net.URL;
+import java.net.URLClassLoader;
+import java.sql.Timestamp;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Date;
+import java.util.Enumeration;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.LinkedHashMap;
+import java.util.LinkedHashSet;
+import java.util.LinkedList;
+import java.util.Map;
+import java.util.Set;
+import java.util.UUID;
+import java.util.concurrent.ConcurrentMap;
+import java.util.jar.JarEntry;
+import java.util.jar.JarFile;
+
+/**
+ * Portable context.
+ */
+public class BinaryContext implements Externalizable {
+    /** */
+    private static final long serialVersionUID = 0L;
+
+    /** */
+    private static final ClassLoader dfltLdr = U.gridClassLoader();
+
+    /** */
+    private final ConcurrentMap<Class<?>, BinaryClassDescriptor> descByCls = new ConcurrentHashMap8<>();
+
+    /** Holds classes loaded by default class loader only. */
+    private final ConcurrentMap<Integer, BinaryClassDescriptor> userTypes = new ConcurrentHashMap8<>();
+
+    /** */
+    private final Map<Integer, BinaryClassDescriptor> predefinedTypes = new HashMap<>();
+
+    /** */
+    private final Map<String, Integer> predefinedTypeNames = new HashMap<>();
+
+    /** */
+    private final Map<Class<? extends Collection>, Byte> colTypes = new HashMap<>();
+
+    /** */
+    private final Map<Class<? extends Map>, Byte> mapTypes = new HashMap<>();
+
+    /** */
+    private final ConcurrentMap<Integer, BinaryIdMapper> mappers = new ConcurrentHashMap8<>(0);
+
+    /** Affinity key field names. */
+    private final ConcurrentMap<Integer, String> affKeyFieldNames = new ConcurrentHashMap8<>(0);
+
+    /** */
+    private final Map<String, BinaryIdMapper> typeMappers = new ConcurrentHashMap8<>(0);
+
+    /** */
+    private BinaryMetadataHandler metaHnd;
+
+    /** Actual marshaller. */
+    private BinaryMarshaller marsh;
+
+    /** */
+    private MarshallerContext marshCtx;
+
+    /** */
+    private String gridName;
+
+    /** */
+    private IgniteConfiguration igniteCfg;
+
+    /** */
+    private final OptimizedMarshaller optmMarsh = new OptimizedMarshaller();
+
+    /** Compact footer flag. */
+    private boolean compactFooter;
+
+    /** Object schemas. */
+    private volatile Map<Integer, BinarySchemaRegistry> schemas;
+
+    /**
+     * For {@link Externalizable}.
+     */
+    public BinaryContext() {
+        // No-op.
+    }
+
+    /**
+     * @param metaHnd Meta data handler.
+     * @param igniteCfg Ignite configuration.
+     */
+    public BinaryContext(BinaryMetadataHandler metaHnd, IgniteConfiguration igniteCfg) {
+        assert metaHnd != null;
+        assert igniteCfg != null;
+
+        this.metaHnd = metaHnd;
+        this.igniteCfg = igniteCfg;
+
+        gridName = igniteCfg.getGridName();
+
+        colTypes.put(ArrayList.class, GridBinaryMarshaller.ARR_LIST);
+        colTypes.put(LinkedList.class, GridBinaryMarshaller.LINKED_LIST);
+        colTypes.put(HashSet.class, GridBinaryMarshaller.HASH_SET);
+        colTypes.put(LinkedHashSet.class, GridBinaryMarshaller.LINKED_HASH_SET);
+
+        mapTypes.put(HashMap.class, GridBinaryMarshaller.HASH_MAP);
+        mapTypes.put(LinkedHashMap.class, GridBinaryMarshaller.LINKED_HASH_MAP);
+
+        // IDs range from [0..200] is used by Java SDK API and GridGain legacy API
+
+        registerPredefinedType(Byte.class, GridBinaryMarshaller.BYTE);
+        registerPredefinedType(Boolean.class, GridBinaryMarshaller.BOOLEAN);
+        registerPredefinedType(Short.class, GridBinaryMarshaller.SHORT);
+        registerPredefinedType(Character.class, GridBinaryMarshaller.CHAR);
+        registerPredefinedType(Integer.class, GridBinaryMarshaller.INT);
+        registerPredefinedType(Long.class, GridBinaryMarshaller.LONG);
+        registerPredefinedType(Float.class, GridBinaryMarshaller.FLOAT);
+        registerPredefinedType(Double.class, GridBinaryMarshaller.DOUBLE);
+        registerPredefinedType(String.class, GridBinaryMarshaller.STRING);
+        registerPredefinedType(BigDecimal.class, GridBinaryMarshaller.DECIMAL);
+        registerPredefinedType(Date.class, GridBinaryMarshaller.DATE);
+        registerPredefinedType(Timestamp.class, GridBinaryMarshaller.TIMESTAMP);
+        registerPredefinedType(UUID.class, GridBinaryMarshaller.UUID);
+
+        registerPredefinedType(byte[].class, GridBinaryMarshaller.BYTE_ARR);
+        registerPredefinedType(short[].class, GridBinaryMarshaller.SHORT_ARR);
+        registerPredefinedType(int[].class, GridBinaryMarshaller.INT_ARR);
+        registerPredefinedType(long[].class, GridBinaryMarshaller.LONG_ARR);
+        registerPredefinedType(float[].class, GridBinaryMarshaller.FLOAT_ARR);
+        registerPredefinedType(double[].class, GridBinaryMarshaller.DOUBLE_ARR);
+        registerPredefinedType(char[].class, GridBinaryMarshaller.CHAR_ARR);
+        registerPredefinedType(boolean[].class, GridBinaryMarshaller.BOOLEAN_ARR);
+        registerPredefinedType(BigDecimal[].class, GridBinaryMarshaller.DECIMAL_ARR);
+        registerPredefinedType(String[].class, GridBinaryMarshaller.STRING_ARR);
+        registerPredefinedType(UUID[].class, GridBinaryMarshaller.UUID_ARR);
+        registerPredefinedType(Date[].class, GridBinaryMarshaller.DATE_ARR);
+        registerPredefinedType(Timestamp[].class, GridBinaryMarshaller.TIMESTAMP_ARR);
+        registerPredefinedType(Object[].class, GridBinaryMarshaller.OBJ_ARR);
+
+        registerPredefinedType(ArrayList.class, 0);
+        registerPredefinedType(LinkedList.class, 0);
+        registerPredefinedType(HashSet.class, 0);
+        registerPredefinedType(LinkedHashSet.class, 0);
+
+        registerPredefinedType(HashMap.class, 0);
+        registerPredefinedType(LinkedHashMap.class, 0);
+
+        registerPredefinedType(GridMapEntry.class, 60);
+        registerPredefinedType(IgniteBiTuple.class, 61);
+        registerPredefinedType(T2.class, 62);
+
+        // IDs range [200..1000] is used by Ignite internal APIs.
+    }
+
+    /**
+     * @return Marshaller.
+     */
+    public BinaryMarshaller marshaller() {
+        return marsh;
+    }
+
+    /**
+     * @return Ignite configuration.
+     */
+    public IgniteConfiguration configuration(){
+        return igniteCfg;
+    }
+
+    /**
+     * @param marsh Portable marshaller.
+     * @param cfg Configuration.
+     * @throws BinaryObjectException In case of error.
+     */
+    public void configure(BinaryMarshaller marsh, IgniteConfiguration cfg) throws BinaryObjectException {
+        if (marsh == null)
+            return;
+
+        this.marsh = marsh;
+
+        marshCtx = marsh.getContext();
+
+        BinaryConfiguration binaryCfg = cfg.getBinaryConfiguration();
+
+        if (binaryCfg == null)
+            binaryCfg = new BinaryConfiguration();
+
+        assert marshCtx != null;
+
+        optmMarsh.setContext(marshCtx);
+
+        configure(
+            binaryCfg.getIdMapper(),
+            binaryCfg.getSerializer(),
+            binaryCfg.getTypeConfigurations()
+        );
+
+        compactFooter = binaryCfg.isCompactFooter();
+    }
+
+    /**
+     * @param globalIdMapper ID mapper.
+     * @param globalSerializer Serializer.
+     * @param typeCfgs Type configurations.
+     * @throws BinaryObjectException In case of error.
+     */
+    private void configure(
+        BinaryIdMapper globalIdMapper,
+        BinarySerializer globalSerializer,
+        Collection<BinaryTypeConfiguration> typeCfgs
+    ) throws BinaryObjectException {
+        TypeDescriptors descs = new TypeDescriptors();
+
+        Map<String, String> affFields = new HashMap<>();
+
+        if (!F.isEmpty(igniteCfg.getCacheKeyConfiguration())) {
+            for (CacheKeyConfiguration keyCfg : igniteCfg.getCacheKeyConfiguration())
+                affFields.put(keyCfg.getTypeName(), keyCfg.getAffinityKeyFieldName());
+        }
+
+        if (typeCfgs != null) {
+            for (BinaryTypeConfiguration typeCfg : typeCfgs) {
+                String clsName = typeCfg.getTypeName();
+
+                if (clsName == null)
+                    throw new BinaryObjectException("Class name is required for portable type configuration.");
+
+                BinaryIdMapper idMapper = globalIdMapper;
+
+                if (typeCfg.getIdMapper() != null)
+                    idMapper = typeCfg.getIdMapper();
+
+                idMapper = BinaryInternalIdMapper.create(idMapper);
+
+                BinarySerializer serializer = globalSerializer;
+
+                if (typeCfg.getSerializer() != null)
+                    serializer = typeCfg.getSerializer();
+
+                if (clsName.endsWith(".*")) {
+                    String pkgName = clsName.substring(0, clsName.length() - 2);
+
+                    for (String clsName0 : classesInPackage(pkgName))
+                        descs.add(clsName0, idMapper, serializer, affFields.get(clsName0),
+                            typeCfg.isEnum(), true);
+                }
+                else
+                    descs.add(clsName, idMapper, serializer, affFields.get(clsName),
+                        typeCfg.isEnum(), false);
+            }
+        }
+
+        for (TypeDescriptor desc : descs.descriptors())
+            registerUserType(desc.clsName, desc.idMapper, desc.serializer, desc.affKeyFieldName, desc.isEnum);
+
+        BinaryInternalIdMapper dfltMapper = BinaryInternalIdMapper.create(globalIdMapper);
+
+        // Put affinity field names for unconfigured types.
+        for (Map.Entry<String, String> entry : affFields.entrySet()) {
+            String typeName = entry.getKey();
+
+            int typeId = dfltMapper.typeId(typeName);
+
+            affKeyFieldNames.putIfAbsent(typeId, entry.getValue());
+        }
+
+        addSystemClassAffinityKey(CollocatedSetItemKey.class);
+        addSystemClassAffinityKey(CollocatedQueueItemKey.class);
+    }
+
+    /**
+     * @param cls Class.
+     */
+    private void addSystemClassAffinityKey(Class<?> cls) {
+        String fieldName = affinityFieldName(cls);
+
+        assert fieldName != null : cls;
+
+        affKeyFieldNames.putIfAbsent(cls.getName().hashCode(), affinityFieldName(cls));
+    }
+
+    /**
+     * @param pkgName Package name.
+     * @return Class names.
+     */
+    @SuppressWarnings("ConstantConditions")
+    private static Iterable<String> classesInPackage(String pkgName) {
+        assert pkgName != null;
+
+        Collection<String> clsNames = new ArrayList<>();
+
+        ClassLoader ldr = U.gridClassLoader();
+
+        if (ldr instanceof URLClassLoader) {
+            String pkgPath = pkgName.replaceAll("\\.", "/");
+
+            URL[] urls = ((URLClassLoader)ldr).getURLs();
+
+            for (URL url : urls) {
+                String proto = url.getProtocol().toLowerCase();
+
+                if ("file".equals(proto)) {
+                    try {
+                        File cpElement = new File(url.toURI());
+
+                        if (cpElement.isDirectory()) {
+                            File pkgDir = new File(cpElement, pkgPath);
+
+                            if (pkgDir.isDirectory()) {
+                                for (File file : pkgDir.listFiles()) {
+                                    String fileName = file.getName();
+
+                                    if (file.isFile() && fileName.toLowerCase().endsWith(".class"))
+                                        clsNames.add(pkgName + '.' + fileName.substring(0, fileName.length() - 6));
+                                }
+                            }
+                        }
+                        else if (cpElement.isFile()) {
+                            try {
+                                JarFile jar = new JarFile(cpElement);
+
+                                Enumeration<JarEntry> entries = jar.entries();
+
+                                while (entries.hasMoreElements()) {
+                                    String entry = entries.nextElement().getName();
+
+                                    if (entry.startsWith(pkgPath) && entry.endsWith(".class")) {
+                                        String clsName = entry.substring(pkgPath.length() + 1, entry.length() - 6);
+
+                                        if (!clsName.contains("/") && !clsName.contains("\\"))
+                                            clsNames.add(pkgName + '.' + clsName);
+                                    }
+                                }
+                            }
+                            catch (IOException ignored) {
+                                // No-op.
+                            }
+                        }
+                    }
+                    catch (URISyntaxException ignored) {
+                        // No-op.
+                    }
+                }
+            }
+        }
+
+        return clsNames;
+    }
+
+    /**
+     * @param cls Class.
+     * @return Class descriptor.
+     * @throws BinaryObjectException In case of error.
+     */
+    public BinaryClassDescriptor descriptorForClass(Class<?> cls, boolean deserialize)
+        throws BinaryObjectException {
+        assert cls != null;
+
+        BinaryClassDescriptor desc = descByCls.get(cls);
+
+        if (desc == null || !desc.registered())
+            desc = registerClassDescriptor(cls, deserialize);
+
+        return desc;
+    }
+
+    /**
+     * @param userType User type or not.
+     * @param typeId Type ID.
+     * @param ldr Class loader.
+     * @return Class descriptor.
+     */
+    public BinaryClassDescriptor descriptorForTypeId(
+        boolean userType,
+        int typeId,
+        ClassLoader ldr,
+        boolean deserialize
+    ) {
+        assert typeId != GridBinaryMarshaller.UNREGISTERED_TYPE_ID;
+
+        //TODO: As a workaround for IGNITE-1358 we always check the predefined map before without checking 'userType'
+        BinaryClassDescriptor desc = predefinedTypes.get(typeId);
+
+        if (desc != null)
+            return desc;
+
+        if (ldr == null)
+            ldr = dfltLdr;
+
+        // If the type hasn't been loaded by default class loader then we mustn't return the descriptor from here
+        // giving a chance to a custom class loader to reload type's class.
+        if (userType && ldr.equals(dfltLdr)) {
+            desc = userTypes.get(typeId);
+
+            if (desc != null)
+                return desc;
+        }
+
+        Class cls;
+
+        try {
+            cls = marshCtx.getClass(typeId, ldr);
+
+            desc = descByCls.get(cls);
+        }
+        catch (ClassNotFoundException e) {
+            // Class might have been loaded by default class loader.
+            if (userType && !ldr.equals(dfltLdr) && (desc = descriptorForTypeId(true, typeId, dfltLdr, deserialize)) != null)
+                return desc;
+
+            throw new BinaryInvalidTypeException(e);
+        }
+        catch (IgniteCheckedException e) {
+            // Class might have been loaded by default class loader.
+            if (userType && !ldr.equals(dfltLdr) && (desc = descriptorForTypeId(true, typeId, dfltLdr, deserialize)) != null)
+                return desc;
+
+            throw new BinaryObjectException("Failed resolve class for ID: " + typeId, e);
+        }
+
+        if (desc == null) {
+            desc = registerClassDescriptor(cls, deserialize);
+
+            assert desc.typeId() == typeId;
+        }
+
+        return desc;
+    }
+
+    /**
+     * Creates and registers {@link BinaryClassDescriptor} for the given {@code class}.
+     *
+     * @param cls Class.
+     * @return Class descriptor.
+     */
+    private BinaryClassDescriptor registerClassDescriptor(Class<?> cls, boolean deserialize) {
+        BinaryClassDescriptor desc;
+
+        String clsName = cls.getName();
+
+        if (marshCtx.isSystemType(clsName)) {
+            desc = new BinaryClassDescriptor(this,
+                cls,
+                false,
+                clsName.hashCode(),
+                clsName,
+                null,
+                BinaryInternalIdMapper.defaultInstance(),
+                null,
+                false,
+                true, /* registered */
+                false /* predefined */
+            );
+
+            BinaryClassDescriptor old = descByCls.putIfAbsent(cls, desc);
+
+            if (old != null)
+                desc = old;
+        }
+        else
+            desc = registerUserClassDescriptor(cls, deserialize);
+
+        return desc;
+    }
+
+    /**
+     * Creates and registers {@link BinaryClassDescriptor} for the given user {@code class}.
+     *
+     * @param cls Class.
+     * @return Class descriptor.
+     */
+    private BinaryClassDescriptor registerUserClassDescriptor(Class<?> cls, boolean deserialize) {
+        boolean registered;
+
+        String typeName = typeName(cls.getName());
+
+        BinaryIdMapper idMapper = userTypeIdMapper(typeName);
+
+        int typeId = idMapper.typeId(typeName);
+
+        try {
+            registered = marshCtx.registerClass(typeId, cls);
+        }
+        catch (IgniteCheckedException e) {
+            throw new BinaryObjectException("Failed to register class.", e);
+        }
+
+        String affFieldName = affinityFieldName(cls);
+
+        BinaryClassDescriptor desc = new BinaryClassDescriptor(this,
+            cls,
+            true,
+            typeId,
+            typeName,
+            affFieldName,
+            idMapper,
+            null,
+            true,
+            registered,
+            false /* predefined */
+        );
+
+        if (!deserialize) {
+            Collection<BinarySchema> schemas = desc.schema() != null ? Collections.singleton(desc.schema()) : null;
+
+            metaHnd.addMeta(typeId,
+                new BinaryMetadata(typeId, typeName, desc.fieldsMeta(), affFieldName, schemas, desc.isEnum()).wrap(this));
+        }
+
+        // perform put() instead of putIfAbsent() because "registered" flag might have been changed or class loader
+        // might have reloaded described class.
+        if (IgniteUtils.detectClassLoader(cls).equals(dfltLdr))
+            userTypes.put(typeId, desc);
+
+        descByCls.put(cls, desc);
+
+        mappers.putIfAbsent(typeId, idMapper);
+
+        return desc;
+    }
+
+    /**
+     * @param cls Collection class.
+     * @return Collection type ID.
+     */
+    public byte collectionType(Class<? extends Collection> cls) {
+        assert cls != null;
+
+        Byte type = colTypes.get(cls);
+
+        if (type != null)
+            return type;
+
+        return Set.class.isAssignableFrom(cls) ? GridBinaryMarshaller.USER_SET : GridBinaryMarshaller.USER_COL;
+    }
+
+    /**
+     * @param cls Map class.
+     * @return Map type ID.
+     */
+    public byte mapType(Class<? extends Map> cls) {
+        assert cls != null;
+
+        Byte type = mapTypes.get(cls);
+
+        return type != null ? type : GridBinaryMarshaller.USER_COL;
+    }
+
+    /**
+     * @param typeName Type name.
+     * @return Type ID.
+     */
+    public int typeId(String typeName) {
+        String typeName0 = typeName(typeName);
+
+        Integer id = predefinedTypeNames.get(typeName0);
+
+        if (id != null)
+            return id;
+
+        if (marshCtx.isSystemType(typeName))
+            return typeName.hashCode();
+
+        return userTypeIdMapper(typeName0).typeId(typeName0);
+    }
+
+    /**
+     * @param typeId Type ID.
+     * @param fieldName Field name.
+     * @return Field ID.
+     */
+    public int fieldId(int typeId, String fieldName) {
+        return userTypeIdMapper(typeId).fieldId(typeId, fieldName);
+    }
+
+    /**
+     * @param typeId Type ID.
+     * @return Instance of ID mapper.
+     */
+    public BinaryIdMapper userTypeIdMapper(int typeId) {
+        BinaryIdMapper idMapper = mappers.get(typeId);
+
+        return idMapper != null ? idMapper : BinaryInternalIdMapper.defaultInstance();
+    }
+
+    /**
+     * @param typeName Type name.
+     * @return Instance of ID mapper.
+     */
+    private BinaryIdMapper userTypeIdMapper(String typeName) {
+        BinaryIdMapper idMapper = typeMappers.get(typeName);
+
+        return idMapper != null ? idMapper : BinaryInternalIdMapper.defaultInstance();
+    }
+
+    /**
+     * @param cls Class to get affinity field for.
+     * @return Affinity field name or {@code null} if field name was not found.
+     */
+    private String affinityFieldName(Class cls) {
+        for (; cls != Object.class && cls != null; cls = cls.getSuperclass()) {
+            for (Field f : cls.getDeclaredFields()) {
+                if (f.getAnnotation(AffinityKeyMapped.class) != null)
+                    return f.getName();
+            }
+        }
+
+        return null;
+    }
+
+    /** {@inheritDoc} */
+    @Override public void writeExternal(ObjectOutput out) throws IOException {
+        U.writeString(out, igniteCfg.getGridName());
+    }
+
+    /** {@inheritDoc} */
+    @Override public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
+        gridName = U.readString(in);
+    }
+
+    /**
+     * @return Portable context.
+     * @throws ObjectStreamException In case of error.
+     */
+    protected Object readResolve() throws ObjectStreamException {
+        try {
+            IgniteKernal g = IgnitionEx.gridx(gridName);
+
+            if (g == null)
+                throw new IllegalStateException("Failed to find grid for name: " + gridName);
+
+            return ((CacheObjectBinaryProcessorImpl)g.context().cacheObjects()).portableContext();
+        }
+        catch (IllegalStateException e) {
+            throw U.withCause(new InvalidObjectException(e.getMessage()), e);
+        }
+    }
+
+    /**
+     * @param cls Class.
+     * @param id Type ID.
+     * @return GridPortableClassDescriptor.
+     */
+    public BinaryClassDescriptor registerPredefinedType(Class<?> cls, int id) {
+        String typeName = typeName(cls.getName());
+
+        BinaryClassDescriptor desc = new BinaryClassDescriptor(
+            this,
+            cls,
+            false,
+            id,
+            typeName,
+            null,
+            BinaryInternalIdMapper.defaultInstance(),
+            null,
+            false,
+            true, /* registered */
+            true /* predefined */
+        );
+
+        predefinedTypeNames.put(typeName, id);
+        predefinedTypes.put(id, desc);
+
+        descByCls.put(cls, desc);
+
+        return desc;
+    }
+
+    /**
+     * @param clsName Class name.
+     * @param idMapper ID mapper.
+     * @param serializer Serializer.
+     * @param affKeyFieldName Affinity key field name.
+     * @param isEnum If enum.
+     * @throws BinaryObjectException In case of error.
+     */
+    @SuppressWarnings("ErrorNotRethrown")
+    public void registerUserType(String clsName,
+        BinaryIdMapper idMapper,
+        @Nullable BinarySerializer serializer,
+        @Nullable String affKeyFieldName,
+        boolean isEnum)
+        throws BinaryObjectException {
+        assert idMapper != null;
+
+        Class<?> cls = null;
+
+        try {
+            cls = Class.forName(clsName);
+        }
+        catch (ClassNotFoundException | NoClassDefFoundError ignored) {
+            // No-op.
+        }
+
+        String typeName = typeName(clsName);
+
+        int id = idMapper.typeId(typeName);
+
+        //Workaround for IGNITE-1358
+        if (predefinedTypes.get(id) != null)
+            throw new BinaryObjectException("Duplicate type ID [clsName=" + clsName + ", id=" + id + ']');
+
+        if (mappers.put(id, idMapper) != null)
+            throw new BinaryObjectException("Duplicate type ID [clsName=" + clsName + ", id=" + id + ']');
+
+        if (affKeyFieldName != null) {
+            if (affKeyFieldNames.put(id, affKeyFieldName) != null)
+                throw new BinaryObjectException("Duplicate type ID [clsName=" + clsName + ", id=" + id + ']');
+        }
+
+        typeMappers.put(typeName, idMapper);
+
+        Map<String, Integer> fieldsMeta = null;
+        Collection<BinarySchema> schemas = null;
+
+        if (cls != null) {
+            BinaryClassDescriptor desc = new BinaryClassDescriptor(
+                this,
+                cls,
+                true,
+                id,
+                typeName,
+                affKeyFieldName,
+                idMapper,
+                serializer,
+                true,
+                true, /* registered */
+                false /* predefined */
+            );
+
+            fieldsMeta = desc.fieldsMeta();
+            schemas = desc.schema() != null ? Collections.singleton(desc.schema()) : null;
+
+            if (IgniteUtils.detectClassLoader(cls).equals(dfltLdr))
+                userTypes.put(id, desc);
+
+            descByCls.put(cls, desc);
+        }
+
+        metaHnd.addMeta(id, new BinaryMetadata(id, typeName, fieldsMeta, affKeyFieldName, schemas, isEnum).wrap(this));
+    }
+
+    /**
+     * Create binary field.
+     *
+     * @param typeId Type ID.
+     * @param fieldName Field name.
+     * @return Binary field.
+     */
+    public BinaryFieldImpl createField(int typeId, String fieldName) {
+        BinarySchemaRegistry schemaReg = schemaRegistry(typeId);
+
+        int fieldId = userTypeIdMapper(typeId).fieldId(typeId, fieldName);
+
+        return new BinaryFieldImpl(typeId, schemaReg, fieldName, fieldId);
+    }
+
+    /**
+     * @param typeId Type ID.
+     * @return Meta data.
+     * @throws BinaryObjectException In case of error.
+     */
+    @Nullable public BinaryType metadata(int typeId) throws BinaryObjectException {
+        return metaHnd != null ? metaHnd.metadata(typeId) : null;
+    }
+
+    /**
+     * @param typeId Type ID.
+     * @return Affinity key field name.
+     */
+    public String affinityKeyFieldName(int typeId) {
+        return affKeyFieldNames.get(typeId);
+    }
+
+    /**
+     * @param typeId Type ID.
+     * @param meta Meta data.
+     * @throws BinaryObjectException In case of error.
+     */
+    public void updateMetadata(int typeId, BinaryMetadata meta) throws BinaryObjectException {
+        metaHnd.addMeta(typeId, meta.wrap(this));
+    }
+
+    /**
+     * @return Whether field IDs should be skipped in footer or not.
+     */
+    public boolean isCompactFooter() {
+        return compactFooter;
+    }
+
+    /**
+     * Get schema registry for type ID.
+     *
+     * @param typeId Type ID.
+     * @return Schema registry for type ID.
+     */
+    public BinarySchemaRegistry schemaRegistry(int typeId) {
+        Map<Integer, BinarySchemaRegistry> schemas0 = schemas;
+
+        if (schemas0 == null) {
+            synchronized (this) {
+                schemas0 = schemas;
+
+                if (schemas0 == null) {
+                    schemas0 = new HashMap<>();
+
+                    BinarySchemaRegistry reg = new BinarySchemaRegistry();
+
+                    schemas0.put(typeId, reg);
+
+                    schemas = schemas0;
+
+                    return reg;
+                }
+            }
+        }
+
+        BinarySchemaRegistry reg = schemas0.get(typeId);
+
+        if (reg == null) {
+            synchronized (this) {
+                reg = schemas.get(typeId);
+
+                if (reg == null) {
+                    reg = new BinarySchemaRegistry();
+
+                    schemas0 = new HashMap<>(schemas);
+
+                    schemas0.put(typeId, reg);
+
+                    schemas = schemas0;
+                }
+            }
+        }
+
+        return reg;
+    }
+
+    /**
+     * Returns instance of {@link OptimizedMarshaller}.
+     *
+     * @return Optimized marshaller.
+     */
+    OptimizedMarshaller optimizedMarsh() {
+        return optmMarsh;
+    }
+
+    /**
+     * @param clsName Class name.
+     * @return Type name.
+     */
+    @SuppressWarnings("ResultOfMethodCallIgnored")
+    public static String typeName(String clsName) {
+        assert clsName != null;
+
+        int idx = clsName.lastIndexOf('$');
+
+        if (idx == clsName.length() - 1)
+            // This is a regular (not inner) class name that ends with '$'. Common use case for Scala classes.
+            idx = -1;
+        else if (idx >= 0) {
+            String typeName = clsName.substring(idx + 1);
+
+            try {
+                Integer.parseInt(typeName);
+
+                // This is an anonymous class. Don't cut off enclosing class name for it.
+                idx = -1;
+            }
+            catch (NumberFormatException ignore) {
+                // This is a lambda class.
+                if (clsName.indexOf("$$Lambda$") > 0)
+                    idx = -1;
+                else
+                    return typeName;
+            }
+        }
+
+        if (idx < 0)
+            idx = clsName.lastIndexOf('.');
+
+        return idx >= 0 ? clsName.substring(idx + 1) : clsName;
+    }
+
+    /**
+     * Undeployment callback invoked when class loader is being undeployed.
+     *
+     * Some marshallers may want to clean their internal state that uses the undeployed class loader somehow.
+     *
+     * @param ldr Class loader being undeployed.
+     */
+    public void onUndeploy(ClassLoader ldr) {
+        for (Class<?> cls : descByCls.keySet()) {
+            if (ldr.equals(cls.getClassLoader()))
+                descByCls.remove(cls);
+        }
+
+        U.clearClassCache(ldr);
+    }
+
+    /**
+     * Type descriptors.
+     */
+    private static class TypeDescriptors {
+        /** Descriptors map. */
+        private final Map<String, TypeDescriptor> descs = new LinkedHashMap<>();
+
+        /**
+         * Add type descriptor.
+         *
+         * @param clsName Class name.
+         * @param idMapper ID mapper.
+         * @param serializer Serializer.
+         * @param affKeyFieldName Affinity key field name.
+         * @param isEnum Enum flag.
+         * @param canOverride Whether this descriptor can be override.
+         * @throws BinaryObjectException If failed.
+         */
+        private void add(String clsName,
+            BinaryIdMapper idMapper,
+            BinarySerializer serializer,
+            String affKeyFieldName,
+            boolean isEnum,
+            boolean canOverride)
+            throws BinaryObjectException {
+            TypeDescriptor desc = new TypeDescriptor(clsName,
+                idMapper,
+                serializer,
+                affKeyFieldName,
+                isEnum,
+                canOverride);
+
+            TypeDescriptor oldDesc = descs.get(clsName);
+
+            if (oldDesc == null)
+                descs.put(clsName, desc);
+            else
+                oldDesc.override(desc);
+        }
+
+        /**
+         * Get all collected descriptors.
+         *
+         * @return Descriptors.
+         */
+        private Iterable<TypeDescriptor> descriptors() {
+            return descs.values();
+        }
+    }
+
+    /**
+     * Type descriptor.
+     */
+    private static class TypeDescriptor {
+        /** Class name. */
+        private final String clsName;
+
+        /** ID mapper. */
+        private BinaryIdMapper idMapper;
+
+        /** Serializer. */
+        private BinarySerializer serializer;
+
+        /** Affinity key field name. */
+        private String affKeyFieldName;
+
+        /** Enum flag. */
+        private boolean isEnum;
+
+        /** Whether this descriptor can be override. */
+        private boolean canOverride;
+
+        /**
+         * Constructor.
+         *
+         * @param clsName Class name.
+         * @param idMapper ID mapper.
+         * @param serializer Serializer.
+         * @param affKeyFieldName Affinity key field name.
+         * @param isEnum Enum type.
+         * @param canOverride Whether this descriptor can be override.
+         */
+        private TypeDescriptor(String clsName, BinaryIdMapper idMapper, BinarySerializer serializer,
+            String affKeyFieldName, boolean isEnum, boolean canOverride) {
+            this.clsName = clsName;
+            this.idMapper = idMapper;
+            this.serializer = serializer;
+            this.affKeyFieldName = affKeyFieldName;
+            this.isEnum = isEnum;
+            this.canOverride = canOverride;
+        }
+
+        /**
+         * Override portable class descriptor.
+         *
+         * @param other Other descriptor.
+         * @throws BinaryObjectException If failed.
+         */
+        private void override(TypeDescriptor other) throws BinaryObjectException {
+            assert clsName.equals(other.clsName);
+
+            if (canOverride) {
+                idMapper = other.idMapper;
+                serializer = other.serializer;
+                affKeyFieldName = other.affKeyFieldName;
+                canOverride = other.canOverride;
+            }
+            else if (!other.canOverride)
+                throw new BinaryObjectException("Duplicate explicit class definition in configuration: " + clsName);
+        }
+    }
+
+    /**
+     * Type id wrapper.
+     */
+    static class Type {
+        /** Type id */
+        private final int id;
+
+        /** Whether the following type is registered in a cache or not */
+        private final boolean registered;
+
+        /**
+         * @param id Id.
+         * @param registered Registered.
+         */
+        public Type(int id, boolean registered) {
+            this.id = id;
+            this.registered = registered;
+        }
+
+        /**
+         * @return Type ID.
+         */
+        public int id() {
+            return id;
+        }
+
+        /**
+         * @return Registered flag value.
+         */
+        public boolean registered() {
+            return registered;
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/71ad9cea/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryEnumObjectImpl.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryEnumObjectImpl.java b/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryEnumObjectImpl.java
index 15e42e3..3321170 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryEnumObjectImpl.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryEnumObjectImpl.java
@@ -45,7 +45,7 @@ public class BinaryEnumObjectImpl implements BinaryObjectEx, Externalizable, Cac
 
     /** Context. */
     @GridDirectTransient
-    private PortableContext ctx;
+    private BinaryContext ctx;
 
     /** Type ID. */
     private int typeId;
@@ -71,7 +71,7 @@ public class BinaryEnumObjectImpl implements BinaryObjectEx, Externalizable, Cac
      * @param clsName Class name.
      * @param ord Ordinal.
      */
-    public BinaryEnumObjectImpl(PortableContext ctx, int typeId, @Nullable String clsName, int ord) {
+    public BinaryEnumObjectImpl(BinaryContext ctx, int typeId, @Nullable String clsName, int ord) {
         assert ctx != null;
 
         this.ctx = ctx;
@@ -110,7 +110,7 @@ public class BinaryEnumObjectImpl implements BinaryObjectEx, Externalizable, Cac
     /** {@inheritDoc} */
     @SuppressWarnings("unchecked")
     @Override public <T> T deserialize() throws BinaryObjectException {
-        Class cls = PortableUtils.resolveClass(ctx, typeId, clsName, null, true);
+        Class cls = BinaryUtils.resolveClass(ctx, typeId, clsName, null, true);
 
         return BinaryEnumCache.get(cls, ord);
     }
@@ -167,7 +167,7 @@ public class BinaryEnumObjectImpl implements BinaryObjectEx, Externalizable, Cac
             return type.typeName() + "[ordinal=" + ord  + ']';
         }
         else {
-            if (typeId == GridPortableMarshaller.UNREGISTERED_TYPE_ID)
+            if (typeId == GridBinaryMarshaller.UNREGISTERED_TYPE_ID)
                 return "BinaryEnum[clsName=" + clsName + ", ordinal=" + ord + ']';
             else
                 return "BinaryEnum[typeId=" + typeId + ", ordinal=" + ord + ']';
@@ -185,7 +185,7 @@ public class BinaryEnumObjectImpl implements BinaryObjectEx, Externalizable, Cac
 
     /** {@inheritDoc} */
     @Override public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
-        ctx = (PortableContext)in.readObject();
+        ctx = (BinaryContext)in.readObject();
 
         typeId = in.readInt();
         clsName = (String)in.readObject();

http://git-wip-us.apache.org/repos/asf/ignite/blob/71ad9cea/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryFieldAccessor.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryFieldAccessor.java b/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryFieldAccessor.java
index 962805d..8cf1a11 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryFieldAccessor.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryFieldAccessor.java
@@ -48,7 +48,7 @@ public abstract class BinaryFieldAccessor {
      * @return Accessor.
      */
     public static BinaryFieldAccessor create(Field field, int id) {
-        BinaryWriteMode mode = PortableUtils.mode(field.getType());
+        BinaryWriteMode mode = BinaryUtils.mode(field.getType());
 
         switch (mode) {
             case P_BYTE:
@@ -849,7 +849,7 @@ public abstract class BinaryFieldAccessor {
          */
         protected BinaryWriteMode mode(Object val) {
             return dynamic ?
-                val == null ? BinaryWriteMode.OBJECT : PortableUtils.mode(val.getClass()) :
+                val == null ? BinaryWriteMode.OBJECT : BinaryUtils.mode(val.getClass()) :
                 mode;
         }
     }


[06/59] [abbrv] ignite git commit: ignite-2065: rename "portable" packages to "binary"

Posted by ak...@apache.org.
http://git-wip-us.apache.org/repos/asf/ignite/blob/1dbf20e0/modules/core/src/test/java/org/apache/ignite/internal/portable/GridPortableMetaDataSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/portable/GridPortableMetaDataSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/portable/GridPortableMetaDataSelfTest.java
deleted file mode 100644
index f2bca9a..0000000
--- a/modules/core/src/test/java/org/apache/ignite/internal/portable/GridPortableMetaDataSelfTest.java
+++ /dev/null
@@ -1,371 +0,0 @@
-/*
- * 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.portable;
-
-import java.math.BigDecimal;
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.Date;
-import java.util.HashMap;
-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.binary.BinaryObjectException;
-import org.apache.ignite.binary.Binarylizable;
-import org.apache.ignite.binary.BinaryType;
-import org.apache.ignite.binary.BinaryObject;
-import org.apache.ignite.binary.BinaryRawWriter;
-import org.apache.ignite.binary.BinaryReader;
-import org.apache.ignite.binary.BinaryWriter;
-import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
-
-/**
- * Portable meta data test.
- */
-public class GridPortableMetaDataSelfTest extends GridCommonAbstractTest {
-    /** */
-    private static int idx;
-
-    /** {@inheritDoc} */
-    @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception {
-        IgniteConfiguration cfg = super.getConfiguration(gridName);
-
-        BinaryConfiguration bCfg = new BinaryConfiguration();
-
-        bCfg.setClassNames(Arrays.asList(TestObject1.class.getName(), TestObject2.class.getName()));
-
-        cfg.setBinaryConfiguration(bCfg);
-
-        cfg.setMarshaller(new BinaryMarshaller());
-
-        CacheConfiguration ccfg = new CacheConfiguration();
-
-        cfg.setCacheConfiguration(ccfg);
-
-        return cfg;
-    }
-
-    /** {@inheritDoc} */
-    @Override protected void beforeTest() throws Exception {
-        idx = 0;
-
-        startGrid();
-    }
-
-    /** {@inheritDoc} */
-    @Override protected void afterTest() throws Exception {
-        stopGrid();
-    }
-
-    /**
-     * @return Portables API.
-     */
-    protected IgniteBinary portables() {
-        return grid().binary();
-    }
-
-    /**
-     * @throws Exception If failed.
-     */
-    public void testGetAll() throws Exception {
-        portables().toBinary(new TestObject2());
-
-        Collection<BinaryType> metas = portables().types();
-
-        assertEquals(2, metas.size());
-
-        for (BinaryType meta : metas) {
-            Collection<String> fields;
-
-            switch (meta.typeName()) {
-                case "TestObject1":
-                    fields = meta.fieldNames();
-
-                    assertEquals(7, fields.size());
-
-                    assertTrue(fields.contains("intVal"));
-                    assertTrue(fields.contains("strVal"));
-                    assertTrue(fields.contains("arrVal"));
-                    assertTrue(fields.contains("obj1Val"));
-                    assertTrue(fields.contains("obj2Val"));
-                    assertTrue(fields.contains("decVal"));
-                    assertTrue(fields.contains("decArrVal"));
-
-                    assertEquals("int", meta.fieldTypeName("intVal"));
-                    assertEquals("String", meta.fieldTypeName("strVal"));
-                    assertEquals("byte[]", meta.fieldTypeName("arrVal"));
-                    assertEquals("Object", meta.fieldTypeName("obj1Val"));
-                    assertEquals("Object", meta.fieldTypeName("obj2Val"));
-                    assertEquals("decimal", meta.fieldTypeName("decVal"));
-                    assertEquals("decimal[]", meta.fieldTypeName("decArrVal"));
-
-                    break;
-
-                case "TestObject2":
-                    fields = meta.fieldNames();
-
-                    assertEquals(7, fields.size());
-
-                    assertTrue(fields.contains("boolVal"));
-                    assertTrue(fields.contains("dateVal"));
-                    assertTrue(fields.contains("uuidArrVal"));
-                    assertTrue(fields.contains("objVal"));
-                    assertTrue(fields.contains("mapVal"));
-                    assertTrue(fields.contains("decVal"));
-                    assertTrue(fields.contains("decArrVal"));
-
-                    assertEquals("boolean", meta.fieldTypeName("boolVal"));
-                    assertEquals("Date", meta.fieldTypeName("dateVal"));
-                    assertEquals("UUID[]", meta.fieldTypeName("uuidArrVal"));
-                    assertEquals("Object", meta.fieldTypeName("objVal"));
-                    assertEquals("Map", meta.fieldTypeName("mapVal"));
-                    assertEquals("decimal", meta.fieldTypeName("decVal"));
-                    assertEquals("decimal[]", meta.fieldTypeName("decArrVal"));
-
-                    break;
-
-                default:
-                    assert false : meta.typeName();
-            }
-        }
-    }
-
-    /**
-     * @throws Exception If failed.
-     */
-    public void testNoConfiguration() throws Exception {
-        portables().toBinary(new TestObject3());
-
-        assertNotNull(portables().type(TestObject3.class));
-    }
-
-    /**
-     * @throws Exception If failed.
-     */
-    public void testReflection() throws Exception {
-        BinaryType meta = portables().type(TestObject1.class);
-
-        assertNotNull(meta);
-
-        assertEquals("TestObject1", meta.typeName());
-
-        Collection<String> fields = meta.fieldNames();
-
-        assertEquals(7, fields.size());
-
-        assertTrue(fields.contains("intVal"));
-        assertTrue(fields.contains("strVal"));
-        assertTrue(fields.contains("arrVal"));
-        assertTrue(fields.contains("obj1Val"));
-        assertTrue(fields.contains("obj2Val"));
-        assertTrue(fields.contains("decVal"));
-        assertTrue(fields.contains("decArrVal"));
-
-        assertEquals("int", meta.fieldTypeName("intVal"));
-        assertEquals("String", meta.fieldTypeName("strVal"));
-        assertEquals("byte[]", meta.fieldTypeName("arrVal"));
-        assertEquals("Object", meta.fieldTypeName("obj1Val"));
-        assertEquals("Object", meta.fieldTypeName("obj2Val"));
-        assertEquals("decimal", meta.fieldTypeName("decVal"));
-        assertEquals("decimal[]", meta.fieldTypeName("decArrVal"));
-    }
-
-    /**
-     * @throws Exception If failed.
-     */
-    public void testPortableMarshalAware() throws Exception {
-        portables().toBinary(new TestObject2());
-
-        BinaryType meta = portables().type(TestObject2.class);
-
-        assertNotNull(meta);
-
-        assertEquals("TestObject2", meta.typeName());
-
-        Collection<String> fields = meta.fieldNames();
-
-        assertEquals(7, fields.size());
-
-        assertTrue(fields.contains("boolVal"));
-        assertTrue(fields.contains("dateVal"));
-        assertTrue(fields.contains("uuidArrVal"));
-        assertTrue(fields.contains("objVal"));
-        assertTrue(fields.contains("mapVal"));
-        assertTrue(fields.contains("decVal"));
-        assertTrue(fields.contains("decArrVal"));
-
-        assertEquals("boolean", meta.fieldTypeName("boolVal"));
-        assertEquals("Date", meta.fieldTypeName("dateVal"));
-        assertEquals("UUID[]", meta.fieldTypeName("uuidArrVal"));
-        assertEquals("Object", meta.fieldTypeName("objVal"));
-        assertEquals("Map", meta.fieldTypeName("mapVal"));
-        assertEquals("decimal", meta.fieldTypeName("decVal"));
-        assertEquals("decimal[]", meta.fieldTypeName("decArrVal"));
-    }
-
-    /**
-     * @throws Exception If failed.
-     */
-    public void testMerge() throws Exception {
-        portables().toBinary(new TestObject2());
-
-        idx = 1;
-
-        portables().toBinary(new TestObject2());
-
-        BinaryType meta = portables().type(TestObject2.class);
-
-        assertNotNull(meta);
-
-        assertEquals("TestObject2", meta.typeName());
-
-        Collection<String> fields = meta.fieldNames();
-
-        assertEquals(9, fields.size());
-
-        assertTrue(fields.contains("boolVal"));
-        assertTrue(fields.contains("dateVal"));
-        assertTrue(fields.contains("uuidArrVal"));
-        assertTrue(fields.contains("objVal"));
-        assertTrue(fields.contains("mapVal"));
-        assertTrue(fields.contains("charVal"));
-        assertTrue(fields.contains("colVal"));
-        assertTrue(fields.contains("decVal"));
-        assertTrue(fields.contains("decArrVal"));
-
-        assertEquals("boolean", meta.fieldTypeName("boolVal"));
-        assertEquals("Date", meta.fieldTypeName("dateVal"));
-        assertEquals("UUID[]", meta.fieldTypeName("uuidArrVal"));
-        assertEquals("Object", meta.fieldTypeName("objVal"));
-        assertEquals("Map", meta.fieldTypeName("mapVal"));
-        assertEquals("char", meta.fieldTypeName("charVal"));
-        assertEquals("Collection", meta.fieldTypeName("colVal"));
-        assertEquals("decimal", meta.fieldTypeName("decVal"));
-        assertEquals("decimal[]", meta.fieldTypeName("decArrVal"));
-    }
-
-    /**
-     * @throws Exception If failed.
-     */
-    public void testSerializedObject() throws Exception {
-        TestObject1 obj = new TestObject1();
-
-        obj.intVal = 10;
-        obj.strVal = "str";
-        obj.arrVal = new byte[] {2, 4, 6};
-        obj.obj1Val = null;
-        obj.obj2Val = new TestObject2();
-        obj.decVal = BigDecimal.ZERO;
-        obj.decArrVal = new BigDecimal[] { BigDecimal.ONE };
-
-        BinaryObject po = portables().toBinary(obj);
-
-        info(po.toString());
-
-        BinaryType meta = po.type();
-
-        assertNotNull(meta);
-
-        assertEquals("TestObject1", meta.typeName());
-
-        Collection<String> fields = meta.fieldNames();
-
-        assertEquals(7, fields.size());
-
-        assertTrue(fields.contains("intVal"));
-        assertTrue(fields.contains("strVal"));
-        assertTrue(fields.contains("arrVal"));
-        assertTrue(fields.contains("obj1Val"));
-        assertTrue(fields.contains("obj2Val"));
-        assertTrue(fields.contains("decVal"));
-        assertTrue(fields.contains("decArrVal"));
-
-        assertEquals("int", meta.fieldTypeName("intVal"));
-        assertEquals("String", meta.fieldTypeName("strVal"));
-        assertEquals("byte[]", meta.fieldTypeName("arrVal"));
-        assertEquals("Object", meta.fieldTypeName("obj1Val"));
-        assertEquals("Object", meta.fieldTypeName("obj2Val"));
-        assertEquals("decimal", meta.fieldTypeName("decVal"));
-        assertEquals("decimal[]", meta.fieldTypeName("decArrVal"));
-    }
-
-    /**
-     */
-    @SuppressWarnings("UnusedDeclaration")
-    private static class TestObject1 {
-        /** */
-        private int intVal;
-
-        /** */
-        private String strVal;
-
-        /** */
-        private byte[] arrVal;
-
-        /** */
-        private TestObject1 obj1Val;
-
-        /** */
-        private TestObject2 obj2Val;
-
-        /** */
-        private BigDecimal decVal;
-
-        /** */
-        private BigDecimal[] decArrVal;
-    }
-
-    /**
-     */
-    private static class TestObject2 implements Binarylizable {
-        /** {@inheritDoc} */
-        @Override public void writeBinary(BinaryWriter writer) throws BinaryObjectException {
-            writer.writeBoolean("boolVal", false);
-            writer.writeDate("dateVal", new Date());
-            writer.writeUuidArray("uuidArrVal", null);
-            writer.writeObject("objVal", null);
-            writer.writeMap("mapVal", new HashMap<>());
-            writer.writeDecimal("decVal", BigDecimal.ZERO);
-            writer.writeDecimalArray("decArrVal", new BigDecimal[] { BigDecimal.ONE });
-
-            if (idx == 1) {
-                writer.writeChar("charVal", (char)0);
-                writer.writeCollection("colVal", null);
-            }
-
-            BinaryRawWriter raw = writer.rawWriter();
-
-            raw.writeChar((char)0);
-            raw.writeCollection(null);
-        }
-
-        /** {@inheritDoc} */
-        @Override public void readBinary(BinaryReader reader) throws BinaryObjectException {
-            // No-op.
-        }
-    }
-
-    /**
-     */
-    @SuppressWarnings("UnusedDeclaration")
-    private static class TestObject3 {
-        /** */
-        private int intVal;
-    }
-}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ignite/blob/1dbf20e0/modules/core/src/test/java/org/apache/ignite/internal/portable/GridPortableWildcardsSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/portable/GridPortableWildcardsSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/portable/GridPortableWildcardsSelfTest.java
deleted file mode 100644
index 0fb5381..0000000
--- a/modules/core/src/test/java/org/apache/ignite/internal/portable/GridPortableWildcardsSelfTest.java
+++ /dev/null
@@ -1,464 +0,0 @@
-/*
- * 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.portable;
-
-import java.util.Collection;
-import org.apache.ignite.IgniteCheckedException;
-import org.apache.ignite.binary.BinaryIdMapper;
-import org.apache.ignite.binary.BinarySerializer;
-import org.apache.ignite.binary.BinaryTypeConfiguration;
-import org.apache.ignite.configuration.BinaryConfiguration;
-import org.apache.ignite.configuration.IgniteConfiguration;
-import org.apache.ignite.internal.util.IgniteUtils;
-import org.apache.ignite.internal.util.typedef.internal.U;
-import org.apache.ignite.marshaller.MarshallerContextTestImpl;
-import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
-
-import java.util.Arrays;
-import java.util.Map;
-
-/**
- * Wildcards test.
- */
-public class GridPortableWildcardsSelfTest extends GridCommonAbstractTest {
-    /**
-     * @throws Exception If failed.
-     */
-    public void testClassNames() throws Exception {
-        BinaryMarshaller marsh = portableMarshaller(Arrays.asList(
-            new BinaryTypeConfiguration("org.apache.ignite.internal.portable.test.*"),
-            new BinaryTypeConfiguration("unknown.*")
-        ));
-
-        PortableContext ctx = portableContext(marsh);
-
-        Map<Integer, Class> typeIds = U.field(ctx, "userTypes");
-
-        assertEquals(3, typeIds.size());
-
-        assertTrue(typeIds.containsKey("gridportabletestclass1".hashCode()));
-        assertTrue(typeIds.containsKey("gridportabletestclass2".hashCode()));
-        assertTrue(typeIds.containsKey("innerclass".hashCode()));
-    }
-
-    /**
-     * @throws Exception If failed.
-     */
-    public void testClassNamesWithMapper() throws Exception {
-        BinaryMarshaller marsh = portableMarshaller(new BinaryIdMapper() {
-            @SuppressWarnings("IfMayBeConditional")
-            @Override public int typeId(String clsName) {
-                if (clsName.endsWith("1"))
-                    return 300;
-                else if (clsName.endsWith("2"))
-                    return 400;
-                else if (clsName.endsWith("InnerClass"))
-                    return 500;
-                else
-                    return -500;
-            }
-
-            @Override public int fieldId(int typeId, String fieldName) {
-                return 0;
-            }
-        }, Arrays.asList(
-            new BinaryTypeConfiguration("org.apache.ignite.internal.portable.test.*"),
-            new BinaryTypeConfiguration("unknown.*")
-        ));
-
-        PortableContext ctx = portableContext(marsh);
-
-        Map<String, BinaryIdMapper> typeMappers = U.field(ctx, "typeMappers");
-
-        assertEquals(3, typeMappers.size());
-
-        assertEquals(300, typeMappers.get("GridPortableTestClass1").typeId("GridPortableTestClass1"));
-        assertEquals(400, typeMappers.get("GridPortableTestClass2").typeId("GridPortableTestClass2"));
-        assertEquals(500, typeMappers.get("InnerClass").typeId("InnerClass"));
-    }
-
-    /**
-     * @throws Exception If failed.
-     */
-    public void testTypeConfigurations() throws Exception {
-        BinaryMarshaller marsh = portableMarshaller(Arrays.asList(
-            new BinaryTypeConfiguration("org.apache.ignite.internal.portable.test.*"),
-            new BinaryTypeConfiguration("unknown.*")
-        ));
-
-        PortableContext ctx = portableContext(marsh);
-
-        Map<Integer, Class> typeIds = U.field(ctx, "userTypes");
-
-        assertEquals(3, typeIds.size());
-
-        assertTrue(typeIds.containsKey("gridportabletestclass1".hashCode()));
-        assertTrue(typeIds.containsKey("gridportabletestclass2".hashCode()));
-        assertTrue(typeIds.containsKey("innerclass".hashCode()));
-    }
-
-    /**
-     * @throws Exception If failed.
-     */
-    public void testTypeConfigurationsWithGlobalMapper() throws Exception {
-        BinaryMarshaller marsh = portableMarshaller(new BinaryIdMapper() {
-            @SuppressWarnings("IfMayBeConditional")
-            @Override public int typeId(String clsName) {
-                if (clsName.endsWith("1"))
-                    return 300;
-                else if (clsName.endsWith("2"))
-                    return 400;
-                else if (clsName.endsWith("InnerClass"))
-                    return 500;
-                else
-                    return -500;
-            }
-
-            @Override public int fieldId(int typeId, String fieldName) {
-                return 0;
-            }
-        }, Arrays.asList(
-            new BinaryTypeConfiguration("org.apache.ignite.internal.portable.test.*"),
-            new BinaryTypeConfiguration("unknown.*")
-        ));
-
-        PortableContext ctx = portableContext(marsh);
-
-        Map<String, BinaryIdMapper> typeMappers = U.field(ctx, "typeMappers");
-
-        assertEquals(3, typeMappers.size());
-
-        assertEquals(300, typeMappers.get("GridPortableTestClass1").typeId("GridPortableTestClass1"));
-        assertEquals(400, typeMappers.get("GridPortableTestClass2").typeId("GridPortableTestClass2"));
-        assertEquals(500, typeMappers.get("InnerClass").typeId("InnerClass"));
-    }
-
-    /**
-     * @throws Exception If failed.
-     */
-    public void testTypeConfigurationsWithNonGlobalMapper() throws Exception {
-        BinaryMarshaller marsh = portableMarshaller(new BinaryIdMapper() {
-            @SuppressWarnings("IfMayBeConditional")
-            @Override public int typeId(String clsName) {
-                if (clsName.endsWith("1"))
-                    return 300;
-                else if (clsName.endsWith("2"))
-                    return 400;
-                else if (clsName.endsWith("InnerClass"))
-                    return 500;
-                else
-                    return -500;
-            }
-
-            @Override public int fieldId(int typeId, String fieldName) {
-                return 0;
-            }
-        }, Arrays.asList(
-            new BinaryTypeConfiguration("org.apache.ignite.internal.portable.test.*"),
-            new BinaryTypeConfiguration("unknown.*")
-        ));
-
-        PortableContext ctx = portableContext(marsh);
-
-        Map<String, BinaryIdMapper> typeMappers = U.field(ctx, "typeMappers");
-
-        assertEquals(3, typeMappers.size());
-
-        assertEquals(300, typeMappers.get("GridPortableTestClass1").typeId("GridPortableTestClass1"));
-        assertEquals(400, typeMappers.get("GridPortableTestClass2").typeId("GridPortableTestClass2"));
-        assertEquals(500, typeMappers.get("InnerClass").typeId("InnerClass"));
-    }
-
-    /**
-     * @throws Exception If failed.
-     */
-    public void testOverride() throws Exception {
-        BinaryTypeConfiguration typeCfg = new BinaryTypeConfiguration();
-
-        typeCfg.setTypeName("org.apache.ignite.internal.portable.test.GridPortableTestClass2");
-        typeCfg.setIdMapper(new BinaryIdMapper() {
-            @Override public int typeId(String clsName) {
-                return 100;
-            }
-
-            @Override public int fieldId(int typeId, String fieldName) {
-                return 0;
-            }
-        });
-
-        BinaryMarshaller marsh = portableMarshaller(Arrays.asList(
-            new BinaryTypeConfiguration("org.apache.ignite.internal.portable.test.*"),
-            typeCfg));
-
-        PortableContext ctx = portableContext(marsh);
-
-        Map<Integer, Class> typeIds = U.field(ctx, "userTypes");
-
-        assertEquals(3, typeIds.size());
-
-        assertTrue(typeIds.containsKey("gridportabletestclass1".hashCode()));
-        assertTrue(typeIds.containsKey("innerclass".hashCode()));
-        assertFalse(typeIds.containsKey("gridportabletestclass2".hashCode()));
-
-        Map<String, BinaryIdMapper> typeMappers = U.field(ctx, "typeMappers");
-
-        assertEquals(100, typeMappers.get("GridPortableTestClass2").typeId("GridPortableTestClass2"));
-    }
-
-    /**
-     * @throws Exception If failed.
-     */
-    public void testClassNamesJar() throws Exception {
-        BinaryMarshaller marsh = portableMarshaller(Arrays.asList(
-            new BinaryTypeConfiguration("org.apache.ignite.portable.testjar.*"),
-            new BinaryTypeConfiguration("unknown.*")
-        ));
-
-        PortableContext ctx = portableContext(marsh);
-
-        Map<Integer, Class> typeIds = U.field(ctx, "userTypes");
-
-        assertEquals(3, typeIds.size());
-
-        assertTrue(typeIds.containsKey("gridportabletestclass1".hashCode()));
-        assertTrue(typeIds.containsKey("gridportabletestclass2".hashCode()));
-    }
-
-    /**
-     * @throws Exception If failed.
-     */
-    public void testClassNamesWithMapperJar() throws Exception {
-        BinaryMarshaller marsh = portableMarshaller(new BinaryIdMapper() {
-            @SuppressWarnings("IfMayBeConditional")
-            @Override public int typeId(String clsName) {
-                if (clsName.endsWith("1"))
-                    return 300;
-                else if (clsName.endsWith("2"))
-                    return 400;
-                else
-                    return -500;
-            }
-
-            @Override public int fieldId(int typeId, String fieldName) {
-                return 0;
-            }
-        }, Arrays.asList(
-            new BinaryTypeConfiguration("org.apache.ignite.portable.testjar.*"),
-            new BinaryTypeConfiguration("unknown.*")
-        ));
-
-        PortableContext ctx = portableContext(marsh);
-
-        Map<String, BinaryIdMapper> typeMappers = U.field(ctx, "typeMappers");
-
-        assertEquals(3, typeMappers.size());
-
-        assertEquals(300, typeMappers.get("GridPortableTestClass1").typeId("GridPortableTestClass1"));
-        assertEquals(400, typeMappers.get("GridPortableTestClass2").typeId("GridPortableTestClass2"));
-    }
-
-    /**
-     * @throws Exception If failed.
-     */
-    public void testTypeConfigurationsJar() throws Exception {
-        BinaryMarshaller marsh = portableMarshaller(Arrays.asList(
-            new BinaryTypeConfiguration("org.apache.ignite.portable.testjar.*"),
-            new BinaryTypeConfiguration("unknown.*")
-        ));
-
-        PortableContext ctx = portableContext(marsh);
-
-        Map<Integer, Class> typeIds = U.field(ctx, "userTypes");
-
-        assertEquals(3, typeIds.size());
-
-        assertTrue(typeIds.containsKey("gridportabletestclass1".hashCode()));
-        assertTrue(typeIds.containsKey("gridportabletestclass2".hashCode()));
-    }
-
-    /**
-     * @throws Exception If failed.
-     */
-    public void testTypeConfigurationsWithGlobalMapperJar() throws Exception {
-        BinaryMarshaller marsh = portableMarshaller(new BinaryIdMapper() {
-            @SuppressWarnings("IfMayBeConditional")
-            @Override public int typeId(String clsName) {
-                if (clsName.endsWith("1"))
-                    return 300;
-                else if (clsName.endsWith("2"))
-                    return 400;
-                else
-                    return -500;
-            }
-
-            @Override public int fieldId(int typeId, String fieldName) {
-                return 0;
-            }
-        }, Arrays.asList(
-            new BinaryTypeConfiguration("org.apache.ignite.portable.testjar.*"),
-            new BinaryTypeConfiguration("unknown.*")
-        ));
-
-        PortableContext ctx = portableContext(marsh);
-
-        Map<String, BinaryIdMapper> typeMappers = U.field(ctx, "typeMappers");
-
-        assertEquals(3, typeMappers.size());
-
-        assertEquals(300, typeMappers.get("GridPortableTestClass1").typeId("GridPortableTestClass1"));
-        assertEquals(400, typeMappers.get("GridPortableTestClass2").typeId("GridPortableTestClass2"));
-    }
-
-    /**
-     * @throws Exception If failed.
-     */
-    public void testTypeConfigurationsWithNonGlobalMapperJar() throws Exception {
-        BinaryMarshaller marsh = portableMarshaller(new BinaryIdMapper() {
-            @SuppressWarnings("IfMayBeConditional")
-            @Override public int typeId(String clsName) {
-                if (clsName.endsWith("1"))
-                    return 300;
-                else if (clsName.endsWith("2"))
-                    return 400;
-                else
-                    return -500;
-            }
-
-            @Override public int fieldId(int typeId, String fieldName) {
-                return 0;
-            }
-        }, Arrays.asList(
-            new BinaryTypeConfiguration("org.apache.ignite.portable.testjar.*"),
-            new BinaryTypeConfiguration("unknown.*")
-        ));
-
-        PortableContext ctx = portableContext(marsh);
-
-        Map<String, BinaryIdMapper> typeMappers = U.field(ctx, "typeMappers");
-
-        assertEquals(3, typeMappers.size());
-
-        assertEquals(300, typeMappers.get("GridPortableTestClass1").typeId("GridPortableTestClass1"));
-        assertEquals(400, typeMappers.get("GridPortableTestClass2").typeId("GridPortableTestClass2"));
-    }
-
-    /**
-     * @throws Exception If failed.
-     */
-    public void testOverrideJar() throws Exception {
-        BinaryTypeConfiguration typeCfg = new BinaryTypeConfiguration(
-            "org.apache.ignite.portable.testjar.GridPortableTestClass2");
-
-        typeCfg.setIdMapper(new BinaryIdMapper() {
-            @Override public int typeId(String clsName) {
-                return 100;
-            }
-
-            @Override public int fieldId(int typeId, String fieldName) {
-                return 0;
-            }
-        });
-
-        BinaryMarshaller marsh = portableMarshaller(Arrays.asList(
-            new BinaryTypeConfiguration("org.apache.ignite.portable.testjar.*"),
-            typeCfg));
-
-        PortableContext ctx = portableContext(marsh);
-
-        Map<Integer, Class> typeIds = U.field(ctx, "userTypes");
-
-        assertEquals(3, typeIds.size());
-
-        assertTrue(typeIds.containsKey("gridportabletestclass1".hashCode()));
-
-        Map<String, BinaryIdMapper> typeMappers = U.field(ctx, "typeMappers");
-
-        assertEquals(3, typeMappers.size());
-
-        assertEquals(100, typeMappers.get("GridPortableTestClass2").typeId("GridPortableTestClass2"));
-    }
-
-    /**
-     * @param marsh Marshaller.
-     * @return Portable context.
-     */
-    protected PortableContext portableContext(BinaryMarshaller marsh) {
-        GridPortableMarshaller impl = U.field(marsh, "impl");
-
-        return impl.context();
-    }
-
-    /**
-     *
-     */
-    protected BinaryMarshaller portableMarshaller()
-        throws IgniteCheckedException {
-        return portableMarshaller(null, null, null);
-    }
-
-    /**
-     *
-     */
-    protected BinaryMarshaller portableMarshaller(Collection<BinaryTypeConfiguration> cfgs)
-        throws IgniteCheckedException {
-        return portableMarshaller(null, null, cfgs);
-    }
-
-    /**
-     *
-     */
-    protected BinaryMarshaller portableMarshaller(BinaryIdMapper mapper, Collection<BinaryTypeConfiguration> cfgs)
-        throws IgniteCheckedException {
-        return portableMarshaller(mapper, null, cfgs);
-    }
-
-    /**
-     *
-     */
-    protected BinaryMarshaller portableMarshaller(BinarySerializer serializer, Collection<BinaryTypeConfiguration> cfgs)
-        throws IgniteCheckedException {
-        return portableMarshaller(null, serializer, cfgs);
-    }
-
-    protected BinaryMarshaller portableMarshaller(
-        BinaryIdMapper mapper,
-        BinarySerializer serializer,
-        Collection<BinaryTypeConfiguration> cfgs
-    ) throws IgniteCheckedException {
-        IgniteConfiguration iCfg = new IgniteConfiguration();
-
-        BinaryConfiguration bCfg = new BinaryConfiguration();
-
-        bCfg.setIdMapper(mapper);
-        bCfg.setSerializer(serializer);
-
-        bCfg.setTypeConfigurations(cfgs);
-
-        iCfg.setBinaryConfiguration(bCfg);
-
-        PortableContext ctx = new PortableContext(BinaryNoopMetadataHandler.instance(), iCfg);
-
-        BinaryMarshaller marsh = new BinaryMarshaller();
-
-        marsh.setContext(new MarshallerContextTestImpl(null));
-
-        IgniteUtils.invoke(BinaryMarshaller.class, marsh, "setPortableContext", ctx, iCfg);
-
-        return marsh;
-    }
-}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ignite/blob/1dbf20e0/modules/core/src/test/java/org/apache/ignite/internal/portable/TestCachingMetadataHandler.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/portable/TestCachingMetadataHandler.java b/modules/core/src/test/java/org/apache/ignite/internal/portable/TestCachingMetadataHandler.java
deleted file mode 100644
index e49ebf3..0000000
--- a/modules/core/src/test/java/org/apache/ignite/internal/portable/TestCachingMetadataHandler.java
+++ /dev/null
@@ -1,45 +0,0 @@
-/*
- * 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.portable;
-
-import org.apache.ignite.binary.BinaryObjectException;
-import org.apache.ignite.binary.BinaryType;
-
-import java.util.concurrent.ConcurrentHashMap;
-
-/**
- * Test metadata handler.
- */
-public class TestCachingMetadataHandler implements BinaryMetadataHandler {
-    /** Cached metadatas. */
-    private final ConcurrentHashMap<Integer, BinaryType> metas = new ConcurrentHashMap<>();
-
-    /** {@inheritDoc} */
-    @Override public void addMeta(int typeId, BinaryType meta) throws BinaryObjectException {
-        BinaryType otherType = metas.put(typeId, meta);
-
-        if (otherType != null)
-            throw new IllegalStateException("Metadata replacement is not allowed in " +
-                TestCachingMetadataHandler.class.getSimpleName() + '.');
-    }
-
-    /** {@inheritDoc} */
-    @Override public BinaryType metadata(int typeId) throws BinaryObjectException {
-        return metas.get(typeId);
-    }
-}

http://git-wip-us.apache.org/repos/asf/ignite/blob/1dbf20e0/modules/core/src/test/java/org/apache/ignite/internal/portable/mutabletest/GridBinaryMarshalerAwareTestClass.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/portable/mutabletest/GridBinaryMarshalerAwareTestClass.java b/modules/core/src/test/java/org/apache/ignite/internal/portable/mutabletest/GridBinaryMarshalerAwareTestClass.java
deleted file mode 100644
index aad0e87..0000000
--- a/modules/core/src/test/java/org/apache/ignite/internal/portable/mutabletest/GridBinaryMarshalerAwareTestClass.java
+++ /dev/null
@@ -1,67 +0,0 @@
-/*
- * 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.portable.mutabletest;
-
-import org.apache.ignite.internal.util.typedef.internal.S;
-import org.apache.ignite.binary.BinaryObjectException;
-import org.apache.ignite.binary.Binarylizable;
-import org.apache.ignite.binary.BinaryRawReader;
-import org.apache.ignite.binary.BinaryRawWriter;
-import org.apache.ignite.binary.BinaryReader;
-import org.apache.ignite.binary.BinaryWriter;
-import org.apache.ignite.testframework.GridTestUtils;
-
-/**
- *
- */
-public class GridBinaryMarshalerAwareTestClass implements Binarylizable {
-    /** */
-    public String s;
-
-    /** */
-    public String sRaw;
-
-    /** {@inheritDoc} */
-    @Override public void writeBinary(BinaryWriter writer) throws BinaryObjectException {
-        writer.writeString("s", s);
-
-        BinaryRawWriter raw = writer.rawWriter();
-
-        raw.writeString(sRaw);
-    }
-
-    /** {@inheritDoc} */
-    @Override public void readBinary(BinaryReader reader) throws BinaryObjectException {
-        s = reader.readString("s");
-
-        BinaryRawReader raw = reader.rawReader();
-
-        sRaw = raw.readString();
-    }
-
-    /** {@inheritDoc} */
-    @SuppressWarnings("FloatingPointEquality")
-    @Override public boolean equals(Object other) {
-        return this == other || GridTestUtils.deepEquals(this, other);
-    }
-
-    /** {@inheritDoc} */
-    @Override public String toString() {
-        return S.toString(GridBinaryMarshalerAwareTestClass.class, this);
-    }
-}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ignite/blob/1dbf20e0/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
deleted file mode 100644
index b568cb5..0000000
--- a/modules/core/src/test/java/org/apache/ignite/internal/portable/mutabletest/GridPortableTestClasses.java
+++ /dev/null
@@ -1,484 +0,0 @@
-/*
- * 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.portable.mutabletest;
-
-import com.google.common.base.Throwables;
-import java.io.ByteArrayOutputStream;
-import java.io.IOException;
-import java.io.ObjectOutput;
-import java.io.ObjectOutputStream;
-import java.io.Serializable;
-import java.math.BigDecimal;
-import java.sql.Timestamp;
-import java.util.ArrayList;
-import java.util.Date;
-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;
-
-/**
- *
- */
-@SuppressWarnings({"PublicInnerClass", "PublicField"})
-public class GridPortableTestClasses {
-    /**
-     *
-     */
-    public static class TestObjectContainer {
-        /** */
-        public Object foo;
-
-        /**
-         *
-         */
-        public TestObjectContainer() {
-            // No-op.
-        }
-
-        /**
-         * @param foo Object.
-         */
-        public TestObjectContainer(Object foo) {
-            this.foo = foo;
-        }
-    }
-
-    /**
-     *
-     */
-    public static class TestObjectOuter {
-        /** */
-        public TestObjectInner inner;
-
-        /** */
-        public String foo;
-
-        /**
-         *
-         */
-        public TestObjectOuter() {
-
-        }
-
-        /**
-         * @param inner Inner object.
-         */
-        public TestObjectOuter(TestObjectInner inner) {
-            this.inner = inner;
-        }
-    }
-
-    /** */
-    public static class TestObjectInner {
-        /** */
-        public Object foo;
-
-        /** */
-        public TestObjectOuter outer;
-    }
-
-    /** */
-    public static class TestObjectArrayList {
-        /** */
-        public List<String> list = new ArrayList<>();
-    }
-
-    /**
-     *
-     */
-    public static class TestObjectPlainPortable {
-        /** */
-        public BinaryObject plainPortable;
-
-        /**
-         *
-         */
-        public TestObjectPlainPortable() {
-            // No-op.
-        }
-
-        /**
-         * @param plainPortable Object.
-         */
-        public TestObjectPlainPortable(BinaryObject plainPortable) {
-            this.plainPortable = plainPortable;
-        }
-    }
-
-    /**
-     *
-     */
-    public static class TestObjectAllTypes implements Serializable {
-        /** */
-        public Byte b_;
-
-        /** */
-        public Short s_;
-
-        /** */
-        public Integer i_;
-
-        /** */
-        public Long l_;
-
-        /** */
-        public Float f_;
-
-        /** */
-        public Double d_;
-
-        /** */
-        public Character c_;
-
-        /** */
-        public Boolean z_;
-
-        /** */
-        public byte b;
-
-        /** */
-        public short s;
-
-        /** */
-        public int i;
-
-        /** */
-        public long l;
-
-        /** */
-        public float f;
-
-        /** */
-        public double d;
-
-        /** */
-        public char c;
-
-        /** */
-        public boolean z;
-
-        /** */
-        public String str;
-
-        /** */
-        public UUID uuid;
-
-        /** */
-        public Date date;
-
-        /** */
-        public Timestamp ts;
-
-        /** */
-        public byte[] bArr;
-
-        /** */
-        public short[] sArr;
-
-        /** */
-        public int[] iArr;
-
-        /** */
-        public long[] lArr;
-
-        /** */
-        public float[] fArr;
-
-        /** */
-        public double[] dArr;
-
-        /** */
-        public char[] cArr;
-
-        /** */
-        public boolean[] zArr;
-
-        /** */
-        public BigDecimal[] bdArr;
-
-        /** */
-        public String[] strArr;
-
-        /** */
-        public UUID[] uuidArr;
-
-        /** */
-        public Date[] dateArr;
-
-        /** */
-        public Timestamp[] tsArr;
-
-        /** */
-        public TestObjectEnum anEnum;
-
-        /** */
-        public TestObjectEnum[] enumArr;
-
-        /** */
-        public Map.Entry entry;
-
-        /**
-         * @return Array.
-         */
-        private byte[] serialize() {
-            ByteArrayOutputStream byteOut = new ByteArrayOutputStream();
-
-            try {
-                ObjectOutput out = new ObjectOutputStream(byteOut);
-
-                out.writeObject(this);
-
-                out.close();
-            }
-            catch (IOException e) {
-                Throwables.propagate(e);
-            }
-
-            return byteOut.toByteArray();
-        }
-
-        /**
-         *
-         */
-        public void setDefaultData() {
-            b_ = 11;
-            s_ = 22;
-            i_ = 33;
-            l_ = 44L;
-            f_ = 55f;
-            d_ = 66d;
-            c_ = 'e';
-            z_ = true;
-
-            b = 1;
-            s = 2;
-            i = 3;
-            l = 4;
-            f = 5;
-            d = 6;
-            c = 7;
-            z = true;
-
-            str = "abc";
-            uuid = new UUID(1, 1);
-            date = new Date(1000000);
-            ts = new Timestamp(100020003);
-
-            bArr = new byte[] {1, 2, 3};
-            sArr = new short[] {1, 2, 3};
-            iArr = new int[] {1, 2, 3};
-            lArr = new long[] {1, 2, 3};
-            fArr = new float[] {1, 2, 3};
-            dArr = new double[] {1, 2, 3};
-            cArr = new char[] {1, 2, 3};
-            zArr = new boolean[] {true, false};
-
-            strArr = new String[] {"abc", "ab", "a"};
-            uuidArr = new UUID[] {new UUID(1, 1), new UUID(2, 2)};
-            bdArr = new BigDecimal[] {new BigDecimal(1000), BigDecimal.TEN};
-            dateArr = new Date[] {new Date(1000000), new Date(200000)};
-            tsArr = new Timestamp[] {new Timestamp(100020003), new Timestamp(200030004)};
-
-            anEnum = TestObjectEnum.A;
-
-            enumArr = new TestObjectEnum[] {TestObjectEnum.B};
-
-            entry = new GridMapEntry<>(1, "a");
-        }
-    }
-
-    /**
-     *
-     */
-    public enum TestObjectEnum {
-        A, B, C
-    }
-
-    /**
-     *
-     */
-    public static class Address implements Serializable {
-        /** SUID. */
-        private static final long serialVersionUID = 0L;
-
-        /** City. */
-        public String city;
-
-        /** Street. */
-        public String street;
-
-        /** Street number. */
-        public int streetNumber;
-
-        /** Flat number. */
-        public int flatNumber;
-
-        /**
-         * Default constructor.
-         */
-        public Address() {
-            // No-op.
-        }
-
-        /**
-         * Constructor.
-         *
-         * @param city City.
-         * @param street Street.
-         * @param streetNumber Street number.
-         * @param flatNumber Flat number.
-         */
-        public Address(String city, String street, int streetNumber, int flatNumber) {
-            this.city = city;
-            this.street = street;
-            this.streetNumber = streetNumber;
-            this.flatNumber = flatNumber;
-        }
-    }
-
-    /**
-     *
-     */
-    public static class Company implements Serializable {
-        /** SUID. */
-        private static final long serialVersionUID = 0L;
-
-        /** ID. */
-        public int id;
-
-        /** Name. */
-        public String name;
-
-        /** Size. */
-        public int size;
-
-        /** Address. */
-        public Address address;
-
-        /** Occupation. */
-        public String occupation;
-
-        /**
-         * Default constructor.
-         */
-        public Company() {
-            // No-op.
-        }
-
-        /**
-         * Constructor.
-         *
-         * @param id ID.
-         * @param name Name.
-         * @param size Size.
-         * @param address Address.
-         * @param occupation Occupation.
-         */
-        public Company(int id, String name, int size, Address address, String occupation) {
-            this.id = id;
-            this.name = name;
-            this.size = size;
-            this.address = address;
-            this.occupation = occupation;
-        }
-    }
-
-    /**
-     * Companies.
-     */
-    public static class Companies {
-        /** Companies. */
-        private List<Company> companies = new ArrayList<>();
-
-        /**
-         * @param idx Index.
-         * @return Company.
-         */
-        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) {
-            Companies list = companyByStreet.get(company.address.street);
-
-            if (list == null) {
-                list = new Companies();
-
-                companyByStreet.put(company.address.street, list);
-            }
-
-            list.add(company);
-        }
-
-        /**
-         * @return map
-         */
-        public Map<String, Companies> getCompanyByStreet() {
-            return 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

http://git-wip-us.apache.org/repos/asf/ignite/blob/1dbf20e0/modules/core/src/test/java/org/apache/ignite/internal/portable/mutabletest/package-info.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/portable/mutabletest/package-info.java b/modules/core/src/test/java/org/apache/ignite/internal/portable/mutabletest/package-info.java
deleted file mode 100644
index daa13d5..0000000
--- a/modules/core/src/test/java/org/apache/ignite/internal/portable/mutabletest/package-info.java
+++ /dev/null
@@ -1,22 +0,0 @@
-/*
- * 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 description. -->
- * Contains internal tests or test related classes and interfaces.
- */
-package org.apache.ignite.internal.portable.mutabletest;
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ignite/blob/1dbf20e0/modules/core/src/test/java/org/apache/ignite/internal/portable/noncompact/BinaryFieldsHeapNonCompactSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/portable/noncompact/BinaryFieldsHeapNonCompactSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/portable/noncompact/BinaryFieldsHeapNonCompactSelfTest.java
deleted file mode 100644
index 6c11938..0000000
--- a/modules/core/src/test/java/org/apache/ignite/internal/portable/noncompact/BinaryFieldsHeapNonCompactSelfTest.java
+++ /dev/null
@@ -1,30 +0,0 @@
-/*
- * 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.portable.noncompact;
-
-import org.apache.ignite.internal.portable.BinaryFieldsHeapSelfTest;
-
-/**
- * Field tests for heap-based portables with non-compact footer.
- */
-public class BinaryFieldsHeapNonCompactSelfTest extends BinaryFieldsHeapSelfTest {
-    /** {@inheritDoc} */
-    @Override protected boolean compactFooter() {
-        return false;
-    }
-}

http://git-wip-us.apache.org/repos/asf/ignite/blob/1dbf20e0/modules/core/src/test/java/org/apache/ignite/internal/portable/noncompact/BinaryFieldsOffheapNonCompactSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/portable/noncompact/BinaryFieldsOffheapNonCompactSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/portable/noncompact/BinaryFieldsOffheapNonCompactSelfTest.java
deleted file mode 100644
index 0bca601..0000000
--- a/modules/core/src/test/java/org/apache/ignite/internal/portable/noncompact/BinaryFieldsOffheapNonCompactSelfTest.java
+++ /dev/null
@@ -1,30 +0,0 @@
-/*
- * 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.portable.noncompact;
-
-import org.apache.ignite.internal.portable.BinaryFieldsOffheapSelfTest;
-
-/**
- * Field tests for offheap-based portables with non-compact footer.
- */
-public class BinaryFieldsOffheapNonCompactSelfTest extends BinaryFieldsOffheapSelfTest {
-    /** {@inheritDoc} */
-    @Override protected boolean compactFooter() {
-        return false;
-    }
-}

http://git-wip-us.apache.org/repos/asf/ignite/blob/1dbf20e0/modules/core/src/test/java/org/apache/ignite/internal/portable/noncompact/BinaryFooterOffsetsHeapNonCompactSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/portable/noncompact/BinaryFooterOffsetsHeapNonCompactSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/portable/noncompact/BinaryFooterOffsetsHeapNonCompactSelfTest.java
deleted file mode 100644
index 8fba738..0000000
--- a/modules/core/src/test/java/org/apache/ignite/internal/portable/noncompact/BinaryFooterOffsetsHeapNonCompactSelfTest.java
+++ /dev/null
@@ -1,30 +0,0 @@
-/*
- * 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.portable.noncompact;
-
-import org.apache.ignite.internal.portable.BinaryFooterOffsetsHeapSelfTest;
-
-/**
- * Compact offsets tests for heap portable objects with non-compact footer.
- */
-public class BinaryFooterOffsetsHeapNonCompactSelfTest extends BinaryFooterOffsetsHeapSelfTest {
-    /** {@inheritDoc} */
-    @Override protected boolean compactFooter() {
-        return false;
-    }
-}

http://git-wip-us.apache.org/repos/asf/ignite/blob/1dbf20e0/modules/core/src/test/java/org/apache/ignite/internal/portable/noncompact/BinaryFooterOffsetsOffheapNonCompactSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/portable/noncompact/BinaryFooterOffsetsOffheapNonCompactSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/portable/noncompact/BinaryFooterOffsetsOffheapNonCompactSelfTest.java
deleted file mode 100644
index b52bd83..0000000
--- a/modules/core/src/test/java/org/apache/ignite/internal/portable/noncompact/BinaryFooterOffsetsOffheapNonCompactSelfTest.java
+++ /dev/null
@@ -1,30 +0,0 @@
-/*
- * 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.portable.noncompact;
-
-import org.apache.ignite.internal.portable.BinaryFooterOffsetsOffheapSelfTest;
-
-/**
- * Compact offsets tests for offheap portable objects with non-compact footer.
- */
-public class BinaryFooterOffsetsOffheapNonCompactSelfTest extends BinaryFooterOffsetsOffheapSelfTest {
-    /** {@inheritDoc} */
-    @Override protected boolean compactFooter() {
-        return false;
-    }
-}

http://git-wip-us.apache.org/repos/asf/ignite/blob/1dbf20e0/modules/core/src/test/java/org/apache/ignite/internal/portable/noncompact/BinaryMarshallerNonCompactSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/portable/noncompact/BinaryMarshallerNonCompactSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/portable/noncompact/BinaryMarshallerNonCompactSelfTest.java
deleted file mode 100644
index 0484dea..0000000
--- a/modules/core/src/test/java/org/apache/ignite/internal/portable/noncompact/BinaryMarshallerNonCompactSelfTest.java
+++ /dev/null
@@ -1,30 +0,0 @@
-/*
- * 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.portable.noncompact;
-
-import org.apache.ignite.internal.portable.BinaryMarshallerSelfTest;
-
-/**
- * Basic marshaller test with non-compact footer.
- */
-public class BinaryMarshallerNonCompactSelfTest extends BinaryMarshallerSelfTest {
-    /** {@inheritDoc} */
-    @Override protected boolean compactFooter() {
-        return false;
-    }
-}

http://git-wip-us.apache.org/repos/asf/ignite/blob/1dbf20e0/modules/core/src/test/java/org/apache/ignite/internal/portable/noncompact/BinaryObjectBuilderAdditionalNonCompactSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/portable/noncompact/BinaryObjectBuilderAdditionalNonCompactSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/portable/noncompact/BinaryObjectBuilderAdditionalNonCompactSelfTest.java
deleted file mode 100644
index 8811029..0000000
--- a/modules/core/src/test/java/org/apache/ignite/internal/portable/noncompact/BinaryObjectBuilderAdditionalNonCompactSelfTest.java
+++ /dev/null
@@ -1,30 +0,0 @@
-/*
- * 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.portable.noncompact;
-
-import org.apache.ignite.internal.portable.BinaryObjectBuilderAdditionalSelfTest;
-
-/**
- *
- */
-public class BinaryObjectBuilderAdditionalNonCompactSelfTest extends BinaryObjectBuilderAdditionalSelfTest {
-    /** {@inheritDoc} */
-    @Override protected boolean compactFooter() {
-        return false;
-    }
-}

http://git-wip-us.apache.org/repos/asf/ignite/blob/1dbf20e0/modules/core/src/test/java/org/apache/ignite/internal/portable/noncompact/BinaryObjectBuilderNonCompactSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/portable/noncompact/BinaryObjectBuilderNonCompactSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/portable/noncompact/BinaryObjectBuilderNonCompactSelfTest.java
deleted file mode 100644
index 0b0916d..0000000
--- a/modules/core/src/test/java/org/apache/ignite/internal/portable/noncompact/BinaryObjectBuilderNonCompactSelfTest.java
+++ /dev/null
@@ -1,30 +0,0 @@
-/*
- * 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.portable.noncompact;
-
-import org.apache.ignite.internal.portable.BinaryObjectBuilderSelfTest;
-
-/**
- * Portable builder test for objects with non-compact footer.
- */
-public class BinaryObjectBuilderNonCompactSelfTest extends BinaryObjectBuilderSelfTest {
-    /** {@inheritDoc} */
-    @Override protected boolean compactFooter() {
-        return false;
-    }
-}

http://git-wip-us.apache.org/repos/asf/ignite/blob/1dbf20e0/modules/core/src/test/java/org/apache/ignite/internal/portable/package-info.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/portable/package-info.java b/modules/core/src/test/java/org/apache/ignite/internal/portable/package-info.java
deleted file mode 100644
index 26897e6..0000000
--- a/modules/core/src/test/java/org/apache/ignite/internal/portable/package-info.java
+++ /dev/null
@@ -1,22 +0,0 @@
-/*
- * 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 description. -->
- * Contains internal tests or test related classes and interfaces.
- */
-package org.apache.ignite.internal.portable;
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ignite/blob/1dbf20e0/modules/core/src/test/java/org/apache/ignite/internal/portable/test/GridPortableTestClass1.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/portable/test/GridPortableTestClass1.java b/modules/core/src/test/java/org/apache/ignite/internal/portable/test/GridPortableTestClass1.java
deleted file mode 100644
index 05a8c33..0000000
--- a/modules/core/src/test/java/org/apache/ignite/internal/portable/test/GridPortableTestClass1.java
+++ /dev/null
@@ -1,28 +0,0 @@
-/*
- * 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.portable.test;
-
-/**
- */
-public class GridPortableTestClass1 {
-    /**
-     */
-    private static class InnerClass {
-        // No-op.
-    }
-}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ignite/blob/1dbf20e0/modules/core/src/test/java/org/apache/ignite/internal/portable/test/GridPortableTestClass2.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/portable/test/GridPortableTestClass2.java b/modules/core/src/test/java/org/apache/ignite/internal/portable/test/GridPortableTestClass2.java
deleted file mode 100644
index ba69991..0000000
--- a/modules/core/src/test/java/org/apache/ignite/internal/portable/test/GridPortableTestClass2.java
+++ /dev/null
@@ -1,24 +0,0 @@
-/*
- * 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.portable.test;
-
-/**
- */
-public class GridPortableTestClass2 {
-    // No-op.
-}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ignite/blob/1dbf20e0/modules/core/src/test/java/org/apache/ignite/internal/portable/test/package-info.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/portable/test/package-info.java b/modules/core/src/test/java/org/apache/ignite/internal/portable/test/package-info.java
deleted file mode 100644
index e63b814..0000000
--- a/modules/core/src/test/java/org/apache/ignite/internal/portable/test/package-info.java
+++ /dev/null
@@ -1,22 +0,0 @@
-/*
- * 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 description. -->
- * Contains internal tests or test related classes and interfaces.
- */
-package org.apache.ignite.internal.portable.test;
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ignite/blob/1dbf20e0/modules/core/src/test/java/org/apache/ignite/internal/portable/test/subpackage/GridPortableTestClass3.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/portable/test/subpackage/GridPortableTestClass3.java b/modules/core/src/test/java/org/apache/ignite/internal/portable/test/subpackage/GridPortableTestClass3.java
deleted file mode 100644
index cf3aa2d..0000000
--- a/modules/core/src/test/java/org/apache/ignite/internal/portable/test/subpackage/GridPortableTestClass3.java
+++ /dev/null
@@ -1,24 +0,0 @@
-/*
- * 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.portable.test.subpackage;
-
-/**
- */
-public class GridPortableTestClass3 {
-    // No-op.
-}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ignite/blob/1dbf20e0/modules/core/src/test/java/org/apache/ignite/internal/portable/test/subpackage/package-info.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/portable/test/subpackage/package-info.java b/modules/core/src/test/java/org/apache/ignite/internal/portable/test/subpackage/package-info.java
deleted file mode 100644
index ae8ee73..0000000
--- a/modules/core/src/test/java/org/apache/ignite/internal/portable/test/subpackage/package-info.java
+++ /dev/null
@@ -1,22 +0,0 @@
-/*
- * 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 description. -->
- * Contains internal tests or test related classes and interfaces.
- */
-package org.apache.ignite.internal.portable.test.subpackage;
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ignite/blob/1dbf20e0/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheConditionalDeploymentSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheConditionalDeploymentSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheConditionalDeploymentSelfTest.java
index 4098225..ea16c1f 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheConditionalDeploymentSelfTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheConditionalDeploymentSelfTest.java
@@ -22,7 +22,7 @@ import org.apache.ignite.Ignition;
 import org.apache.ignite.configuration.CacheConfiguration;
 import org.apache.ignite.configuration.IgniteConfiguration;
 import org.apache.ignite.internal.managers.communication.GridIoMessageFactory;
-import org.apache.ignite.internal.portable.BinaryMarshaller;
+import org.apache.ignite.internal.binary.BinaryMarshaller;
 import org.apache.ignite.internal.util.IgniteUtils;
 import org.apache.ignite.internal.util.typedef.CO;
 import org.apache.ignite.plugin.extensions.communication.Message;

http://git-wip-us.apache.org/repos/asf/ignite/blob/1dbf20e0/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheDeploymentSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheDeploymentSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheDeploymentSelfTest.java
index bfa353b..22e8c36 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheDeploymentSelfTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheDeploymentSelfTest.java
@@ -26,7 +26,7 @@ import org.apache.ignite.configuration.CacheConfiguration;
 import org.apache.ignite.configuration.DeploymentMode;
 import org.apache.ignite.configuration.IgniteConfiguration;
 import org.apache.ignite.configuration.NearCacheConfiguration;
-import org.apache.ignite.internal.portable.BinaryMarshaller;
+import org.apache.ignite.internal.binary.BinaryMarshaller;
 import org.apache.ignite.internal.util.typedef.T2;
 import org.apache.ignite.internal.util.typedef.internal.U;
 import org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi;

http://git-wip-us.apache.org/repos/asf/ignite/blob/1dbf20e0/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheStoreValueAbstractTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheStoreValueAbstractTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheStoreValueAbstractTest.java
index 95527c3..70c5dc3 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheStoreValueAbstractTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/IgniteCacheStoreValueAbstractTest.java
@@ -39,8 +39,8 @@ import org.apache.ignite.cache.store.CacheStoreAdapter;
 import org.apache.ignite.configuration.CacheConfiguration;
 import org.apache.ignite.configuration.IgniteConfiguration;
 import org.apache.ignite.internal.IgniteEx;
-import org.apache.ignite.internal.portable.BinaryMarshaller;
-import org.apache.ignite.internal.portable.BinaryObjectImpl;
+import org.apache.ignite.internal.binary.BinaryMarshaller;
+import org.apache.ignite.internal.binary.BinaryObjectImpl;
 import org.apache.ignite.internal.processors.cache.distributed.near.GridNearCacheAdapter;
 import org.apache.ignite.internal.util.lang.GridAbsPredicate;
 import org.apache.ignite.lang.IgniteBiInClosure;
@@ -519,4 +519,4 @@ public abstract class IgniteCacheStoreValueAbstractTest extends IgniteCacheAbstr
     static class TestInterceptor extends CacheInterceptorAdapter {
         // No-op.
     }
-}
\ No newline at end of file
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/1dbf20e0/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/binary/GridCacheBinaryAtomicEntryProcessorDeploymentSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/binary/GridCacheBinaryAtomicEntryProcessorDeploymentSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/binary/GridCacheBinaryAtomicEntryProcessorDeploymentSelfTest.java
new file mode 100644
index 0000000..2c55381
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/binary/GridCacheBinaryAtomicEntryProcessorDeploymentSelfTest.java
@@ -0,0 +1,129 @@
+/*
+ *  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.processors.cache.binary;
+
+import org.apache.ignite.IgniteCache;
+import org.apache.ignite.binary.BinaryInvalidTypeException;
+import org.apache.ignite.binary.BinaryObject;
+import org.apache.ignite.configuration.DeploymentMode;
+import org.apache.ignite.internal.processors.cache.GridCacheAtomicEntryProcessorDeploymentSelfTest;
+
+/**
+ * Cache EntryProcessor + Deployment.
+ */
+public class GridCacheBinaryAtomicEntryProcessorDeploymentSelfTest
+    extends GridCacheAtomicEntryProcessorDeploymentSelfTest {
+    /** {@inheritDoc} */
+    protected IgniteCache getCache() {
+        return grid(1).cache(null).withKeepBinary();
+    }
+
+    /** {@inheritDoc} */
+    @Override protected String getEntryProcessor() {
+        return "org.apache.ignite.tests.p2p.CacheDeploymentBinaryObjectEntryProcessor";
+    }
+
+    /**
+     * @throws Exception In case of error.
+     */
+    public void testGetDeployment() throws Exception {
+        depMode = DeploymentMode.CONTINUOUS;
+
+        doTestGet(false);
+    }
+
+    /**
+     * @throws Exception In case of error.
+     */
+    public void testGetDeployment2() throws Exception {
+        depMode = DeploymentMode.SHARED;
+
+        doTestGet(false);
+    }
+
+    /**
+     * @throws Exception In case of error.
+     */
+    public void testGetDeploymentWithKeepBinary() throws Exception {
+        depMode = DeploymentMode.CONTINUOUS;
+
+        doTestGet(true);
+    }
+
+    /**
+     * @throws Exception In case of error.
+     */
+    public void testGetDeployment2WithKeepBinary() throws Exception {
+        depMode = DeploymentMode.SHARED;
+
+        doTestGet(true);
+    }
+
+    /**
+     * @throws Exception Exception.
+     */
+    private void doTestGet(boolean withKeepBinary) throws Exception {
+        try {
+            clientMode = false;
+            startGrid(0);
+
+            clientMode = true;
+            startGrid(1);
+
+            Class valCls = grid(1).configuration().getClassLoader().loadClass(TEST_VALUE);
+
+            assertTrue(grid(1).configuration().isClientMode());
+            assertFalse(grid(0).configuration().isClientMode());
+
+            IgniteCache cache1 = grid(1).cache(null);
+            IgniteCache cache0 = grid(0).cache(null);
+
+            if (withKeepBinary) {
+                cache1 = cache1.withKeepBinary();
+                cache0 = cache0.withKeepBinary();
+            }
+
+            cache1.put("key", valCls.newInstance());
+
+            if (withKeepBinary) {
+                BinaryObject obj = (BinaryObject)(cache0.get("key"));
+
+                try {
+                    obj.deserialize();
+
+                    fail("Exception did not happened.");
+                }
+                catch (BinaryInvalidTypeException e) {
+                    // No-op.
+                }
+            }
+            else
+                try {
+                    cache0.get("key");
+
+                    fail("Exception did not happened.");
+                }
+                catch (BinaryInvalidTypeException e) {
+                    // No-op.
+                }
+        }
+        finally {
+            stopAllGrids();
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/1dbf20e0/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/binary/GridCacheBinaryObjectsAbstractDataStreamerSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/binary/GridCacheBinaryObjectsAbstractDataStreamerSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/binary/GridCacheBinaryObjectsAbstractDataStreamerSelfTest.java
new file mode 100644
index 0000000..5840149
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/binary/GridCacheBinaryObjectsAbstractDataStreamerSelfTest.java
@@ -0,0 +1,192 @@
+/*
+ * 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.processors.cache.binary;
+
+import java.io.Serializable;
+import java.util.Arrays;
+import java.util.concurrent.Callable;
+import java.util.concurrent.ThreadLocalRandom;
+import java.util.concurrent.atomic.AtomicBoolean;
+import org.apache.ignite.IgniteDataStreamer;
+import org.apache.ignite.cache.CacheAtomicityMode;
+import org.apache.ignite.cache.CacheMode;
+import org.apache.ignite.cache.CacheWriteSynchronizationMode;
+import org.apache.ignite.configuration.BinaryConfiguration;
+import org.apache.ignite.configuration.CacheConfiguration;
+import org.apache.ignite.configuration.IgniteConfiguration;
+import org.apache.ignite.configuration.NearCacheConfiguration;
+import org.apache.ignite.internal.IgniteInternalFuture;
+import org.apache.ignite.internal.binary.BinaryMarshaller;
+import org.apache.ignite.binary.BinaryObjectException;
+import org.apache.ignite.binary.Binarylizable;
+import org.apache.ignite.binary.BinaryReader;
+import org.apache.ignite.binary.BinaryTypeConfiguration;
+import org.apache.ignite.binary.BinaryWriter;
+import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
+import org.jsr166.LongAdder8;
+
+import static org.apache.ignite.cache.CacheWriteSynchronizationMode.PRIMARY_SYNC;
+
+/**
+ * Test for portable objects stored in cache.
+ */
+public abstract class GridCacheBinaryObjectsAbstractDataStreamerSelfTest extends GridCommonAbstractTest {
+    /** */
+    private static final int THREAD_CNT = 64;
+
+    /** {@inheritDoc} */
+    @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception {
+        IgniteConfiguration cfg = super.getConfiguration(gridName);
+
+        CacheConfiguration cacheCfg = new CacheConfiguration();
+
+        cacheCfg.setCacheMode(cacheMode());
+        cacheCfg.setAtomicityMode(atomicityMode());
+        cacheCfg.setNearConfiguration(nearConfiguration());
+        cacheCfg.setWriteSynchronizationMode(writeSynchronizationMode());
+
+        cfg.setCacheConfiguration(cacheCfg);
+
+        BinaryConfiguration bCfg = new BinaryConfiguration();
+
+        bCfg.setTypeConfigurations(Arrays.asList(
+            new BinaryTypeConfiguration(TestObject.class.getName())));
+
+        cfg.setBinaryConfiguration(bCfg);
+        cfg.setMarshaller(new BinaryMarshaller());
+
+        return cfg;
+    }
+
+    /**
+     * @return Sync mode.
+     */
+    protected CacheWriteSynchronizationMode writeSynchronizationMode() {
+        return PRIMARY_SYNC;
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void beforeTestsStarted() throws Exception {
+        startGridsMultiThreaded(gridCount());
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void afterTestsStopped() throws Exception {
+        stopAllGrids();
+    }
+
+    /**
+     * @return Cache mode.
+     */
+    protected abstract CacheMode cacheMode();
+
+    /**
+     * @return Atomicity mode.
+     */
+    protected abstract CacheAtomicityMode atomicityMode();
+
+    /**
+     * @return Near configuration.
+     */
+    protected abstract NearCacheConfiguration nearConfiguration();
+
+    /**
+     * @return Grid count.
+     */
+    protected int gridCount() {
+        return 1;
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    @SuppressWarnings("BusyWait")
+    public void testGetPut() throws Exception {
+        final AtomicBoolean flag = new AtomicBoolean();
+
+        final LongAdder8 cnt = new LongAdder8();
+
+        try (IgniteDataStreamer<Object, Object> ldr = grid(0).dataStreamer(null)) {
+            IgniteInternalFuture<?> f = multithreadedAsync(
+                new Callable<Object>() {
+                    @Override public Object call() throws Exception {
+                        ThreadLocalRandom rnd = ThreadLocalRandom.current();
+
+                        while (!flag.get()) {
+                            ldr.addData(rnd.nextInt(10000), new TestObject(rnd.nextInt(10000)));
+
+                            cnt.add(1);
+                        }
+
+                        return null;
+                    }
+                },
+                THREAD_CNT
+            );
+
+            for (int i = 0; i < 30 && !f.isDone(); i++)
+                Thread.sleep(1000);
+
+            flag.set(true);
+
+            f.get();
+        }
+
+        info("Operations in 30 sec: " + cnt.sum());
+    }
+
+    /**
+     */
+    private static class TestObject implements Binarylizable, Serializable {
+        /** */
+        private int val;
+
+        /**
+         */
+        private TestObject() {
+            // No-op.
+        }
+
+        /**
+         * @param val Value.
+         */
+        private TestObject(int val) {
+            this.val = val;
+        }
+
+        /** {@inheritDoc} */
+        @Override public int hashCode() {
+            return val;
+        }
+
+        /** {@inheritDoc} */
+        @Override public boolean equals(Object obj) {
+            return obj instanceof TestObject && ((TestObject)obj).val == val;
+        }
+
+        /** {@inheritDoc} */
+        @Override public void writeBinary(BinaryWriter writer) throws BinaryObjectException {
+            writer.writeInt("val", val);
+        }
+
+        /** {@inheritDoc} */
+        @Override public void readBinary(BinaryReader reader) throws BinaryObjectException {
+            val = reader.readInt("val");
+        }
+    }
+}


[53/59] [abbrv] ignite git commit: ignite-2065: rename "portable" classes to "binary"

Posted by ak...@apache.org.
http://git-wip-us.apache.org/repos/asf/ignite/blob/71ad9cea/modules/core/src/main/java/org/apache/ignite/internal/binary/BinarySchema.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/binary/BinarySchema.java b/modules/core/src/main/java/org/apache/ignite/internal/binary/BinarySchema.java
new file mode 100644
index 0000000..99e642c
--- /dev/null
+++ b/modules/core/src/main/java/org/apache/ignite/internal/binary/BinarySchema.java
@@ -0,0 +1,466 @@
+/*
+ * 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.binary;
+
+import java.io.Externalizable;
+import java.io.IOException;
+import java.io.ObjectInput;
+import java.io.ObjectOutput;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+/**
+ * Schema describing portable object content. We rely on the following assumptions:
+ * - When amount of fields in the object is low, it is better to inline these values into int fields thus allowing
+ * for quick comparisons performed within already fetched L1 cache line.
+ * - When there are more fields, we store them inside a hash map.
+ */
+public class BinarySchema implements Externalizable {
+    /** */
+    private static final long serialVersionUID = 0L;
+
+    /** Order returned if field is not found. */
+    public static final int ORDER_NOT_FOUND = -1;
+
+    /** Minimum sensible size. */
+    private static final int MAP_MIN_SIZE = 32;
+
+    /** Empty cell. */
+    private static final int MAP_EMPTY = 0;
+
+    /** Schema ID. */
+    private int schemaId;
+
+    /** IDs depending on order. */
+    private int[] ids;
+
+    /** Interned names of associated fields. */
+    private String[] names;
+
+    /** ID-to-order data. */
+    private int[] idToOrderData;
+
+    /** ID-to-order mask. */
+    private int idToOrderMask;
+
+    /** ID 1. */
+    private int id0;
+
+    /** ID 2. */
+    private int id1;
+
+    /** ID 3. */
+    private int id2;
+
+    /** ID 4. */
+    private int id3;
+
+    /**
+     * {@link Externalizable} support.
+     */
+    public BinarySchema() {
+        // No-op.
+    }
+
+    /**
+     * Constructor.
+     *
+     * @param schemaId Schema ID.
+     * @param fieldIds Field IDs.
+     */
+    private BinarySchema(int schemaId, List<Integer> fieldIds) {
+        assert fieldIds != null;
+
+        this.schemaId = schemaId;
+
+        initialize(fieldIds);
+    }
+
+    /**
+     * @return Schema ID.
+     */
+    public int schemaId() {
+        return schemaId;
+    }
+
+    /**
+     * Try speculatively confirming order for the given field name.
+     *
+     * @param expOrder Expected order.
+     * @param expName Expected name.
+     * @return Field ID.
+     */
+    @SuppressWarnings("StringEquality")
+    public Confirmation confirmOrder(int expOrder, String expName) {
+        assert expName != null;
+
+        if (expOrder < names.length) {
+            String name = names[expOrder];
+
+            // Note that we use only reference equality assuming that field names are interned literals.
+            if (name == expName)
+                return Confirmation.CONFIRMED;
+
+            if (name == null)
+                return Confirmation.CLARIFY;
+        }
+
+        return Confirmation.REJECTED;
+    }
+
+    /**
+     * Add field name.
+     *
+     * @param order Order.
+     * @param name Name.
+     */
+    public void clarifyFieldName(int order, String name) {
+        assert name != null;
+        assert order < names.length;
+
+        names[order] = name.intern();
+    }
+
+    /**
+     * Get field ID by order in footer.
+     *
+     * @param order Order.
+     * @return Field ID.
+     */
+    public int fieldId(int order) {
+        return order < ids.length ? ids[order] : 0;
+    }
+
+    /**
+     * Get field order in footer by field ID.
+     *
+     * @param id Field ID.
+     * @return Offset or {@code 0} if there is no such field.
+     */
+    public int order(int id) {
+        if (idToOrderData == null) {
+            if (id == id0)
+                return 0;
+
+            if (id == id1)
+                return 1;
+
+            if (id == id2)
+                return 2;
+
+            if (id == id3)
+                return 3;
+
+            return ORDER_NOT_FOUND;
+        }
+        else {
+            int idx = (id & idToOrderMask) << 1;
+
+            int curId = idToOrderData[idx];
+
+            if (id == curId) // Hit!
+                return idToOrderData[idx + 1];
+            else if (curId == MAP_EMPTY) // No such ID!
+                return ORDER_NOT_FOUND;
+            else {
+                // Unlikely collision scenario.
+                for (int i = 2; i < idToOrderData.length; i += 2) {
+                    int newIdx = (idx + i) % idToOrderData.length;
+
+                    assert newIdx < idToOrderData.length - 1;
+
+                    curId = idToOrderData[newIdx];
+
+                    if (id == curId)
+                        return idToOrderData[newIdx + 1];
+                    else if (curId == MAP_EMPTY)
+                        return ORDER_NOT_FOUND;
+                }
+
+                return ORDER_NOT_FOUND;
+            }
+        }
+    }
+
+    /** {@inheritDoc} */
+    @Override public int hashCode() {
+        return schemaId;
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean equals(Object o) {
+        return o != null && o instanceof BinarySchema && schemaId == ((BinarySchema)o).schemaId;
+    }
+
+    /** {@inheritDoc} */
+    @Override public void writeExternal(ObjectOutput out) throws IOException {
+        out.writeInt(schemaId);
+
+        out.writeInt(ids.length);
+
+        for (Integer id : ids)
+            out.writeInt(id);
+    }
+
+    /** {@inheritDoc} */
+    @Override public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
+        schemaId = in.readInt();
+
+        int idsCnt = in.readInt();
+
+        List<Integer> fieldIds = new ArrayList<>(idsCnt);
+
+        for (int i = 0; i < idsCnt; i++)
+            fieldIds.add(in.readInt());
+
+        initialize(fieldIds);
+    }
+
+    /**
+     * Parse values.
+     *
+     * @param vals Values.
+     * @param size Proposed result size.
+     * @return Parse result.
+     */
+    private static ParseResult parse(int[] vals, int size) {
+        int mask = maskForPowerOfTwo(size);
+
+        int totalSize = size * 2;
+
+        int[] data = new int[totalSize];
+        int collisions = 0;
+
+        for (int order = 0; order < vals.length; order++) {
+            int id = vals[order];
+
+            assert id != 0;
+
+            int idIdx = (id & mask) << 1;
+
+            if (data[idIdx] == 0) {
+                // Found empty slot.
+                data[idIdx] = id;
+                data[idIdx + 1] = order;
+            }
+            else {
+                // Collision!
+                collisions++;
+
+                boolean placeFound = false;
+
+                for (int i = 2; i < totalSize; i += 2) {
+                    int newIdIdx = (idIdx + i) % totalSize;
+
+                    if (data[newIdIdx] == 0) {
+                        data[newIdIdx] = id;
+                        data[newIdIdx + 1] = order;
+
+                        placeFound = true;
+
+                        break;
+                    }
+                }
+
+                assert placeFound : "Should always have a place for entry!";
+            }
+        }
+
+        return new ParseResult(data, collisions);
+    }
+
+    /**
+     * Get next power of two which greater or equal to the given number.
+     * This implementation is not meant to be very efficient, so it is expected to be used relatively rare.
+     *
+     * @param val Number
+     * @return Nearest pow2.
+     */
+    private static int nextPowerOfTwo(int val) {
+        int res = 1;
+
+        while (res < val)
+            res = res << 1;
+
+        if (res < 0)
+            throw new IllegalArgumentException("Value is too big to find positive pow2: " + val);
+
+        return res;
+    }
+
+    /**
+     * Calculate mask for the given value which is a power of two.
+     *
+     * @param val Value.
+     * @return Mask.
+     */
+    private static int maskForPowerOfTwo(int val) {
+        int mask = 0;
+        int comparand = 1;
+
+        while (comparand < val) {
+            mask |= comparand;
+
+            comparand <<= 1;
+        }
+
+        return mask;
+    }
+
+    /**
+     * Initialization routine.
+     *
+     * @param fieldIds Field IDs.
+     */
+    private void initialize(List<Integer> fieldIds) {
+        ids = new int[fieldIds.size()];
+
+        for (int i = 0; i < fieldIds.size(); i++)
+            ids[i] = fieldIds.get(i);
+
+        names = new String[fieldIds.size()];
+
+        if (fieldIds.size() <= 4) {
+            Iterator<Integer> iter = fieldIds.iterator();
+
+            id0 = iter.hasNext() ? iter.next() : 0;
+            id1 = iter.hasNext() ? iter.next() : 0;
+            id2 = iter.hasNext() ? iter.next() : 0;
+            id3 = iter.hasNext() ? iter.next() : 0;
+        }
+        else {
+            id0 = id1 = id2 = id3 = 0;
+
+            initializeMap(ids);
+        }
+    }
+
+    /**
+     * Initialize the map.
+     *
+     * @param vals Values.
+     */
+    private void initializeMap(int[] vals) {
+        int size = Math.max(nextPowerOfTwo(vals.length) << 2, MAP_MIN_SIZE);
+
+        assert size > 0;
+
+        ParseResult finalRes;
+
+        ParseResult res1 = parse(vals, size);
+
+        if (res1.collisions == 0)
+            finalRes = res1;
+        else {
+            ParseResult res2 = parse(vals, size * 2);
+
+            // Failed to decrease aom
+            if (res2.collisions == 0)
+                finalRes = res2;
+            else
+                finalRes = parse(vals, size * 4);
+        }
+
+        idToOrderData = finalRes.data;
+        idToOrderMask = maskForPowerOfTwo(idToOrderData.length / 2);
+    }
+
+    /**
+     * Schema builder.
+     */
+    public static class Builder {
+        /** Schema ID. */
+        private int schemaId = BinaryUtils.schemaInitialId();
+
+        /** Fields. */
+        private final ArrayList<Integer> fields = new ArrayList<>();
+
+        /**
+         * Create new schema builder.
+         *
+         * @return Schema builder.
+         */
+        public static Builder newBuilder() {
+            return new Builder();
+        }
+
+        /**
+         * Private constructor.
+         */
+        private Builder() {
+            // No-op.
+        }
+
+        /**
+         * Add field.
+         *
+         * @param fieldId Field ID.
+         */
+        public void addField(int fieldId) {
+            fields.add(fieldId);
+
+            schemaId = BinaryUtils.updateSchemaId(schemaId, fieldId);
+        }
+
+        /**
+         * Build schema.
+         *
+         * @return Schema.
+         */
+        public BinarySchema build() {
+            return new BinarySchema(schemaId, fields);
+        }
+    }
+
+    /**
+     * Order confirmation result.
+     */
+    public enum Confirmation {
+        /** Confirmed. */
+        CONFIRMED,
+
+        /** Denied. */
+        REJECTED,
+
+        /** Field name clarification is needed. */
+        CLARIFY
+    }
+
+    /**
+     * Result of map parsing.
+     */
+    private static class ParseResult {
+        /** Data. */
+        private int[] data;
+
+        /** Collisions. */
+        private int collisions;
+
+        /**
+         * Constructor.
+         *
+         * @param data Data.
+         * @param collisions Collisions.
+         */
+        private ParseResult(int[] data, int collisions) {
+            this.data = data;
+            this.collisions = collisions;
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/71ad9cea/modules/core/src/main/java/org/apache/ignite/internal/binary/BinarySchemaRegistry.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/binary/BinarySchemaRegistry.java b/modules/core/src/main/java/org/apache/ignite/internal/binary/BinarySchemaRegistry.java
new file mode 100644
index 0000000..6920a34
--- /dev/null
+++ b/modules/core/src/main/java/org/apache/ignite/internal/binary/BinarySchemaRegistry.java
@@ -0,0 +1,172 @@
+/*
+ * 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.binary;
+
+import org.jetbrains.annotations.Nullable;
+
+import java.util.HashMap;
+
+/**
+ * Portable schema registry. Contains all well-known object schemas.
+ * <p>
+ * We rely on the fact that usually object has only few different schemas. For this reason we inline several
+ * of them with optional fallback to normal hash map lookup.
+ *
+ */
+public class BinarySchemaRegistry {
+    /** Empty schema ID. */
+    private static final int EMPTY = 0;
+
+    /** Whether registry still works in inline mode. */
+    private volatile boolean inline = true;
+
+    /** First schema ID. */
+    private int schemaId1;
+
+    /** Second schema ID. */
+    private int schemaId2;
+
+    /** Third schema ID. */
+    private int schemaId3;
+
+    /** Fourth schema ID. */
+    private int schemaId4;
+
+    /** First schema. */
+    private BinarySchema schema1;
+
+    /** Second schema. */
+    private BinarySchema schema2;
+
+    /** Third schema. */
+    private BinarySchema schema3;
+
+    /** Fourth schema. */
+    private BinarySchema schema4;
+
+    /** Schemas with COW semantics. */
+    private volatile HashMap<Integer, BinarySchema> schemas;
+
+    /**
+     * Get schema for the given ID. We rely on very relaxed memory semantics here assuming that it is not critical
+     * to return false-positive {@code null} values.
+     *
+     * @param schemaId Schema ID.
+     * @return Schema or {@code null}.
+     */
+    @Nullable public BinarySchema schema(int schemaId) {
+        if (inline) {
+            if (schemaId == schemaId1)
+                return schema1;
+            else if (schemaId == schemaId2)
+                return schema2;
+            else if (schemaId == schemaId3)
+                return schema3;
+            else if (schemaId == schemaId4)
+                return schema4;
+        }
+        else {
+            HashMap<Integer, BinarySchema> schemas0 = schemas;
+
+            // Null can be observed here due to either data race or race condition when switching to non-inlined mode.
+            // Both of them are benign for us because they lead only to unnecessary schema re-calc.
+            if (schemas0 != null)
+                return schemas0.get(schemaId);
+        }
+
+        return null;
+    }
+
+    /**
+     * Add schema.
+     *
+     * @param schemaId Schema ID.
+     * @param schema Schema.
+     */
+    public void addSchema(int schemaId, BinarySchema schema) {
+        synchronized (this) {
+            if (inline) {
+                // Check if this is already known schema.
+                if (schemaId == schemaId1 || schemaId == schemaId2 || schemaId == schemaId3 || schemaId == schemaId4)
+                    return;
+
+                // Try positioning new schema in inline mode.
+                if (schemaId1 == EMPTY) {
+                    schemaId1 = schemaId;
+
+                    schema1 = schema;
+
+                    inline = true; // Forcing HB edge just in case.
+
+                    return;
+                }
+
+                if (schemaId2 == EMPTY) {
+                    schemaId2 = schemaId;
+
+                    schema2 = schema;
+
+                    inline = true; // Forcing HB edge just in case.
+
+                    return;
+                }
+
+                if (schemaId3 == EMPTY) {
+                    schemaId3 = schemaId;
+
+                    schema3 = schema;
+
+                    inline = true; // Forcing HB edge just in case.
+
+                    return;
+                }
+
+                if (schemaId4 == EMPTY) {
+                    schemaId4 = schemaId;
+
+                    schema4 = schema;
+
+                    inline = true; // Forcing HB edge just in case.
+
+                    return;
+                }
+
+                // No luck, switching to hash map mode.
+                HashMap<Integer, BinarySchema> newSchemas = new HashMap<>();
+
+                newSchemas.put(schemaId1, schema1);
+                newSchemas.put(schemaId2, schema2);
+                newSchemas.put(schemaId3, schema3);
+                newSchemas.put(schemaId4, schema4);
+
+                newSchemas.put(schemaId, schema);
+
+                schemas = newSchemas;
+
+                inline = false;
+            }
+            else {
+                HashMap<Integer, BinarySchema> newSchemas = new HashMap<>(schemas);
+
+                newSchemas.put(schemaId, schema);
+
+                schemas = newSchemas;
+            }
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/71ad9cea/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryThreadLocalContext.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryThreadLocalContext.java b/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryThreadLocalContext.java
index 8fff80b..0ddd581 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryThreadLocalContext.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryThreadLocalContext.java
@@ -17,9 +17,8 @@
 
 package org.apache.ignite.internal.binary;
 
-import org.apache.ignite.internal.binary.streams.PortableMemoryAllocatorChunk;
-import org.apache.ignite.internal.binary.streams.PortableMemoryAllocator;
-import org.apache.ignite.internal.binary.streams.PortableMemoryAllocatorChunk;
+import org.apache.ignite.internal.binary.streams.BinaryMemoryAllocatorChunk;
+import org.apache.ignite.internal.binary.streams.BinaryMemoryAllocator;
 
 /**
  * Contains thread-local data for binary marshalling.
@@ -33,7 +32,7 @@ public class BinaryThreadLocalContext {
     };
 
     /** Memory chunk. */
-    private final PortableMemoryAllocatorChunk chunk = PortableMemoryAllocator.INSTANCE.chunk();
+    private final BinaryMemoryAllocatorChunk chunk = BinaryMemoryAllocator.INSTANCE.chunk();
 
     /** Schema holder. */
     private final BinaryWriterSchemaHolder schema = new BinaryWriterSchemaHolder();
@@ -57,7 +56,7 @@ public class BinaryThreadLocalContext {
     /**
      * @return Memory chunk.
      */
-    public PortableMemoryAllocatorChunk chunk() {
+    public BinaryMemoryAllocatorChunk chunk() {
         return chunk;
     }
 

http://git-wip-us.apache.org/repos/asf/ignite/blob/71ad9cea/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryTypeImpl.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryTypeImpl.java b/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryTypeImpl.java
index d19076b..23aacb2 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryTypeImpl.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryTypeImpl.java
@@ -26,7 +26,7 @@ import java.util.Collection;
  */
 public class BinaryTypeImpl implements BinaryType {
     /** Portable context. */
-    private final PortableContext ctx;
+    private final BinaryContext ctx;
 
     /** Type metadata. */
     private final BinaryMetadata meta;
@@ -37,7 +37,7 @@ public class BinaryTypeImpl implements BinaryType {
      * @param ctx Portable context.
      * @param meta Type  metadata.
      */
-    public BinaryTypeImpl(PortableContext ctx, BinaryMetadata meta) {
+    public BinaryTypeImpl(BinaryContext ctx, BinaryMetadata meta) {
         this.ctx = ctx;
         this.meta = meta;
     }
@@ -80,7 +80,7 @@ public class BinaryTypeImpl implements BinaryType {
     /**
      * @return Context.
      */
-    public PortableContext context() {
+    public BinaryContext context() {
         return ctx;
     }
 

http://git-wip-us.apache.org/repos/asf/ignite/blob/71ad9cea/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryUtils.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryUtils.java b/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryUtils.java
new file mode 100644
index 0000000..d285df5
--- /dev/null
+++ b/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryUtils.java
@@ -0,0 +1,1859 @@
+/*
+ * 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.binary;
+
+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;
+import org.apache.ignite.internal.binary.builder.BinaryLazyValue;
+import org.apache.ignite.internal.binary.streams.BinaryInputStream;
+import org.apache.ignite.internal.util.typedef.F;
+import org.apache.ignite.internal.util.typedef.internal.U;
+import org.apache.ignite.lang.IgniteBiTuple;
+import org.jetbrains.annotations.Nullable;
+import org.jsr166.ConcurrentHashMap8;
+
+import java.io.ByteArrayInputStream;
+import java.io.Externalizable;
+import java.lang.reflect.Array;
+import java.math.BigDecimal;
+import java.math.BigInteger;
+import java.sql.Timestamp;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.LinkedHashMap;
+import java.util.LinkedHashSet;
+import java.util.LinkedList;
+import java.util.Map;
+import java.util.Set;
+import java.util.TreeMap;
+import java.util.TreeSet;
+import java.util.UUID;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ConcurrentSkipListSet;
+
+import static java.nio.charset.StandardCharsets.UTF_8;
+
+/**
+ * Portable utils.
+ */
+public class BinaryUtils {
+    /** */
+    public static final Map<Class<?>, Byte> PLAIN_CLASS_TO_FLAG = new HashMap<>();
+
+    /** */
+    public static final Map<Byte, Class<?>> FLAG_TO_CLASS = new HashMap<>();
+
+    /** {@code true} if serialized value of this type cannot contain references to objects. */
+    private static final boolean[] PLAIN_TYPE_FLAG = new boolean[102];
+
+    /** Portable classes. */
+    private static final Collection<Class<?>> PORTABLE_CLS = new HashSet<>();
+
+    /** Flag: user type. */
+    public static final short FLAG_USR_TYP = 0x0001;
+
+    /** Flag: only raw data exists. */
+    public static final short FLAG_HAS_SCHEMA = 0x0002;
+
+    /** Flag indicating that object has raw data. */
+    public static final short FLAG_HAS_RAW = 0x0004;
+
+    /** Flag: offsets take 1 byte. */
+    public static final short FLAG_OFFSET_ONE_BYTE = 0x0008;
+
+    /** Flag: offsets take 2 bytes. */
+    public static final short FLAG_OFFSET_TWO_BYTES = 0x0010;
+
+    /** Flag: compact footer, no field IDs. */
+    public static final short FLAG_COMPACT_FOOTER = 0x0020;
+
+    /** Offset which fits into 1 byte. */
+    public static final int OFFSET_1 = 1;
+
+    /** Offset which fits into 2 bytes. */
+    public static final int OFFSET_2 = 2;
+
+    /** Offset which fits into 4 bytes. */
+    public static final int OFFSET_4 = 4;
+
+    /** Field ID length. */
+    public static final int FIELD_ID_LEN = 4;
+
+    /** Field type names. */
+    private static final String[] FIELD_TYPE_NAMES;
+
+    /** FNV1 hash offset basis. */
+    private static final int FNV1_OFFSET_BASIS = 0x811C9DC5;
+
+    /** FNV1 hash prime. */
+    private static final int FNV1_PRIME = 0x01000193;
+
+    /**
+     * Static class initializer.
+     */
+    static {
+        PLAIN_CLASS_TO_FLAG.put(Byte.class, GridBinaryMarshaller.BYTE);
+        PLAIN_CLASS_TO_FLAG.put(Short.class, GridBinaryMarshaller.SHORT);
+        PLAIN_CLASS_TO_FLAG.put(Integer.class, GridBinaryMarshaller.INT);
+        PLAIN_CLASS_TO_FLAG.put(Long.class, GridBinaryMarshaller.LONG);
+        PLAIN_CLASS_TO_FLAG.put(Float.class, GridBinaryMarshaller.FLOAT);
+        PLAIN_CLASS_TO_FLAG.put(Double.class, GridBinaryMarshaller.DOUBLE);
+        PLAIN_CLASS_TO_FLAG.put(Character.class, GridBinaryMarshaller.CHAR);
+        PLAIN_CLASS_TO_FLAG.put(Boolean.class, GridBinaryMarshaller.BOOLEAN);
+        PLAIN_CLASS_TO_FLAG.put(BigDecimal.class, GridBinaryMarshaller.DECIMAL);
+        PLAIN_CLASS_TO_FLAG.put(String.class, GridBinaryMarshaller.STRING);
+        PLAIN_CLASS_TO_FLAG.put(UUID.class, GridBinaryMarshaller.UUID);
+        PLAIN_CLASS_TO_FLAG.put(Date.class, GridBinaryMarshaller.DATE);
+        PLAIN_CLASS_TO_FLAG.put(Timestamp.class, GridBinaryMarshaller.TIMESTAMP);
+
+        PLAIN_CLASS_TO_FLAG.put(byte[].class, GridBinaryMarshaller.BYTE_ARR);
+        PLAIN_CLASS_TO_FLAG.put(short[].class, GridBinaryMarshaller.SHORT_ARR);
+        PLAIN_CLASS_TO_FLAG.put(int[].class, GridBinaryMarshaller.INT_ARR);
+        PLAIN_CLASS_TO_FLAG.put(long[].class, GridBinaryMarshaller.LONG_ARR);
+        PLAIN_CLASS_TO_FLAG.put(float[].class, GridBinaryMarshaller.FLOAT_ARR);
+        PLAIN_CLASS_TO_FLAG.put(double[].class, GridBinaryMarshaller.DOUBLE_ARR);
+        PLAIN_CLASS_TO_FLAG.put(char[].class, GridBinaryMarshaller.CHAR_ARR);
+        PLAIN_CLASS_TO_FLAG.put(boolean[].class, GridBinaryMarshaller.BOOLEAN_ARR);
+        PLAIN_CLASS_TO_FLAG.put(BigDecimal[].class, GridBinaryMarshaller.DECIMAL_ARR);
+        PLAIN_CLASS_TO_FLAG.put(String[].class, GridBinaryMarshaller.STRING_ARR);
+        PLAIN_CLASS_TO_FLAG.put(UUID[].class, GridBinaryMarshaller.UUID_ARR);
+        PLAIN_CLASS_TO_FLAG.put(Date[].class, GridBinaryMarshaller.DATE_ARR);
+        PLAIN_CLASS_TO_FLAG.put(Timestamp[].class, GridBinaryMarshaller.TIMESTAMP_ARR);
+
+        for (Map.Entry<Class<?>, Byte> entry : PLAIN_CLASS_TO_FLAG.entrySet())
+            FLAG_TO_CLASS.put(entry.getValue(), entry.getKey());
+
+        PLAIN_CLASS_TO_FLAG.put(byte.class, GridBinaryMarshaller.BYTE);
+        PLAIN_CLASS_TO_FLAG.put(short.class, GridBinaryMarshaller.SHORT);
+        PLAIN_CLASS_TO_FLAG.put(int.class, GridBinaryMarshaller.INT);
+        PLAIN_CLASS_TO_FLAG.put(long.class, GridBinaryMarshaller.LONG);
+        PLAIN_CLASS_TO_FLAG.put(float.class, GridBinaryMarshaller.FLOAT);
+        PLAIN_CLASS_TO_FLAG.put(double.class, GridBinaryMarshaller.DOUBLE);
+        PLAIN_CLASS_TO_FLAG.put(char.class, GridBinaryMarshaller.CHAR);
+        PLAIN_CLASS_TO_FLAG.put(boolean.class, GridBinaryMarshaller.BOOLEAN);
+
+        for (byte b : new byte[] {
+            GridBinaryMarshaller.BYTE, GridBinaryMarshaller.SHORT, GridBinaryMarshaller.INT, GridBinaryMarshaller.LONG, GridBinaryMarshaller.FLOAT, GridBinaryMarshaller.DOUBLE,
+            GridBinaryMarshaller.CHAR, GridBinaryMarshaller.BOOLEAN, GridBinaryMarshaller.DECIMAL, GridBinaryMarshaller.STRING, GridBinaryMarshaller.UUID, GridBinaryMarshaller.DATE, GridBinaryMarshaller.TIMESTAMP,
+            GridBinaryMarshaller.BYTE_ARR, GridBinaryMarshaller.SHORT_ARR, GridBinaryMarshaller.INT_ARR, GridBinaryMarshaller.LONG_ARR, GridBinaryMarshaller.FLOAT_ARR, GridBinaryMarshaller.DOUBLE_ARR,
+            GridBinaryMarshaller.CHAR_ARR, GridBinaryMarshaller.BOOLEAN_ARR, GridBinaryMarshaller.DECIMAL_ARR, GridBinaryMarshaller.STRING_ARR, GridBinaryMarshaller.UUID_ARR, GridBinaryMarshaller.DATE_ARR, GridBinaryMarshaller.TIMESTAMP_ARR,
+            GridBinaryMarshaller.ENUM, GridBinaryMarshaller.ENUM_ARR, GridBinaryMarshaller.NULL}) {
+
+            PLAIN_TYPE_FLAG[b] = true;
+        }
+
+        PORTABLE_CLS.add(Byte.class);
+        PORTABLE_CLS.add(Short.class);
+        PORTABLE_CLS.add(Integer.class);
+        PORTABLE_CLS.add(Long.class);
+        PORTABLE_CLS.add(Float.class);
+        PORTABLE_CLS.add(Double.class);
+        PORTABLE_CLS.add(Character.class);
+        PORTABLE_CLS.add(Boolean.class);
+        PORTABLE_CLS.add(String.class);
+        PORTABLE_CLS.add(UUID.class);
+        PORTABLE_CLS.add(Date.class);
+        PORTABLE_CLS.add(Timestamp.class);
+        PORTABLE_CLS.add(BigDecimal.class);
+        PORTABLE_CLS.add(byte[].class);
+        PORTABLE_CLS.add(short[].class);
+        PORTABLE_CLS.add(int[].class);
+        PORTABLE_CLS.add(long[].class);
+        PORTABLE_CLS.add(float[].class);
+        PORTABLE_CLS.add(double[].class);
+        PORTABLE_CLS.add(char[].class);
+        PORTABLE_CLS.add(boolean[].class);
+        PORTABLE_CLS.add(String[].class);
+        PORTABLE_CLS.add(UUID[].class);
+        PORTABLE_CLS.add(Date[].class);
+        PORTABLE_CLS.add(Timestamp[].class);
+        PORTABLE_CLS.add(BigDecimal[].class);
+
+        FIELD_TYPE_NAMES = new String[104];
+
+        FIELD_TYPE_NAMES[GridBinaryMarshaller.BYTE] = "byte";
+        FIELD_TYPE_NAMES[GridBinaryMarshaller.SHORT] = "short";
+        FIELD_TYPE_NAMES[GridBinaryMarshaller.INT] = "int";
+        FIELD_TYPE_NAMES[GridBinaryMarshaller.LONG] = "long";
+        FIELD_TYPE_NAMES[GridBinaryMarshaller.BOOLEAN] = "boolean";
+        FIELD_TYPE_NAMES[GridBinaryMarshaller.FLOAT] = "float";
+        FIELD_TYPE_NAMES[GridBinaryMarshaller.DOUBLE] = "double";
+        FIELD_TYPE_NAMES[GridBinaryMarshaller.CHAR] = "char";
+        FIELD_TYPE_NAMES[GridBinaryMarshaller.UUID] = "UUID";
+        FIELD_TYPE_NAMES[GridBinaryMarshaller.DECIMAL] = "decimal";
+        FIELD_TYPE_NAMES[GridBinaryMarshaller.STRING] = "String";
+        FIELD_TYPE_NAMES[GridBinaryMarshaller.DATE] = "Date";
+        FIELD_TYPE_NAMES[GridBinaryMarshaller.TIMESTAMP] = "Timestamp";
+        FIELD_TYPE_NAMES[GridBinaryMarshaller.ENUM] = "Enum";
+        FIELD_TYPE_NAMES[GridBinaryMarshaller.OBJ] = "Object";
+        FIELD_TYPE_NAMES[GridBinaryMarshaller.PORTABLE_OBJ] = "Object";
+        FIELD_TYPE_NAMES[GridBinaryMarshaller.COL] = "Collection";
+        FIELD_TYPE_NAMES[GridBinaryMarshaller.MAP] = "Map";
+        FIELD_TYPE_NAMES[GridBinaryMarshaller.CLASS] = "Class";
+        FIELD_TYPE_NAMES[GridBinaryMarshaller.BYTE_ARR] = "byte[]";
+        FIELD_TYPE_NAMES[GridBinaryMarshaller.SHORT_ARR] = "short[]";
+        FIELD_TYPE_NAMES[GridBinaryMarshaller.INT_ARR] = "int[]";
+        FIELD_TYPE_NAMES[GridBinaryMarshaller.LONG_ARR] = "long[]";
+        FIELD_TYPE_NAMES[GridBinaryMarshaller.BOOLEAN_ARR] = "boolean[]";
+        FIELD_TYPE_NAMES[GridBinaryMarshaller.FLOAT_ARR] = "float[]";
+        FIELD_TYPE_NAMES[GridBinaryMarshaller.DOUBLE_ARR] = "double[]";
+        FIELD_TYPE_NAMES[GridBinaryMarshaller.CHAR_ARR] = "char[]";
+        FIELD_TYPE_NAMES[GridBinaryMarshaller.UUID_ARR] = "UUID[]";
+        FIELD_TYPE_NAMES[GridBinaryMarshaller.DECIMAL_ARR] = "decimal[]";
+        FIELD_TYPE_NAMES[GridBinaryMarshaller.STRING_ARR] = "String[]";
+        FIELD_TYPE_NAMES[GridBinaryMarshaller.DATE_ARR] = "Date[]";
+        FIELD_TYPE_NAMES[GridBinaryMarshaller.TIMESTAMP_ARR] = "Timestamp[]";
+        FIELD_TYPE_NAMES[GridBinaryMarshaller.OBJ_ARR] = "Object[]";
+        FIELD_TYPE_NAMES[GridBinaryMarshaller.ENUM_ARR] = "Enum[]";
+    }
+
+    /**
+     * Check if user type flag is set.
+     *
+     * @param flags Flags.
+     * @return {@code True} if set.
+     */
+    public static boolean isUserType(short flags) {
+        return isFlagSet(flags, FLAG_USR_TYP);
+    }
+
+    /**
+     * Check if raw-only flag is set.
+     *
+     * @param flags Flags.
+     * @return {@code True} if set.
+     */
+    public static boolean hasSchema(short flags) {
+        return isFlagSet(flags, FLAG_HAS_SCHEMA);
+    }
+
+    /**
+     * Check if raw-only flag is set.
+     *
+     * @param flags Flags.
+     * @return {@code True} if set.
+     */
+    public static boolean hasRaw(short flags) {
+        return isFlagSet(flags, FLAG_HAS_RAW);
+    }
+
+    /**
+     * Check if "no-field-ids" flag is set.
+     *
+     * @param flags Flags.
+     * @return {@code True} if set.
+     */
+    public static boolean isCompactFooter(short flags) {
+        return isFlagSet(flags, FLAG_COMPACT_FOOTER);
+    }
+
+    /**
+     * Check whether particular flag is set.
+     *
+     * @param flags Flags.
+     * @param flag Flag.
+     * @return {@code True} if flag is set in flags.
+     */
+    private static boolean isFlagSet(short flags, short flag) {
+        return (flags & flag) == flag;
+    }
+
+    /**
+     * Schema initial ID.
+     *
+     * @return ID.
+     */
+    public static int schemaInitialId() {
+        return FNV1_OFFSET_BASIS;
+    }
+
+    /**
+     * Update schema ID when new field is added.
+     *
+     * @param schemaId Current schema ID.
+     * @param fieldId Field ID.
+     * @return New schema ID.
+     */
+    public static int updateSchemaId(int schemaId, int fieldId) {
+        schemaId = schemaId ^ (fieldId & 0xFF);
+        schemaId = schemaId * FNV1_PRIME;
+        schemaId = schemaId ^ ((fieldId >> 8) & 0xFF);
+        schemaId = schemaId * FNV1_PRIME;
+        schemaId = schemaId ^ ((fieldId >> 16) & 0xFF);
+        schemaId = schemaId * FNV1_PRIME;
+        schemaId = schemaId ^ ((fieldId >> 24) & 0xFF);
+        schemaId = schemaId * FNV1_PRIME;
+
+        return schemaId;
+    }
+
+    /**
+     * @param typeName Field type name.
+     * @return Field type ID;
+     */
+    @SuppressWarnings("StringEquality")
+    public static int fieldTypeId(String typeName) {
+        for (int i = 0; i < FIELD_TYPE_NAMES.length; i++) {
+            String typeName0 = FIELD_TYPE_NAMES[i];
+
+            if (typeName.equals(typeName0))
+                return i;
+        }
+
+        throw new IllegalArgumentException("Invalid metadata type name: " + typeName);
+    }
+
+    /**
+     * @param typeId Field type ID.
+     * @return Field type name.
+     */
+    public static String fieldTypeName(int typeId) {
+        assert typeId >= 0 && typeId < FIELD_TYPE_NAMES.length : typeId;
+
+        String typeName = FIELD_TYPE_NAMES[typeId];
+
+        assert typeName != null : typeId;
+
+        return typeName;
+    }
+
+    /**
+     * Write value with flag. e.g. writePlainObject(writer, (byte)77) will write two byte: {BYTE, 77}.
+     *
+     * @param writer W
+     * @param val Value.
+     */
+    public static void writePlainObject(BinaryWriterExImpl writer, Object val) {
+        Byte flag = PLAIN_CLASS_TO_FLAG.get(val.getClass());
+
+        if (flag == null)
+            throw new IllegalArgumentException("Can't write object with type: " + val.getClass());
+
+        switch (flag) {
+            case GridBinaryMarshaller.BYTE:
+                writer.writeByte(flag);
+                writer.writeByte((Byte)val);
+
+                break;
+
+            case GridBinaryMarshaller.SHORT:
+                writer.writeByte(flag);
+                writer.writeShort((Short)val);
+
+                break;
+
+            case GridBinaryMarshaller.INT:
+                writer.writeByte(flag);
+                writer.writeInt((Integer)val);
+
+                break;
+
+            case GridBinaryMarshaller.LONG:
+                writer.writeByte(flag);
+                writer.writeLong((Long)val);
+
+                break;
+
+            case GridBinaryMarshaller.FLOAT:
+                writer.writeByte(flag);
+                writer.writeFloat((Float)val);
+
+                break;
+
+            case GridBinaryMarshaller.DOUBLE:
+                writer.writeByte(flag);
+                writer.writeDouble((Double)val);
+
+                break;
+
+            case GridBinaryMarshaller.CHAR:
+                writer.writeByte(flag);
+                writer.writeChar((Character)val);
+
+                break;
+
+            case GridBinaryMarshaller.BOOLEAN:
+                writer.writeByte(flag);
+                writer.writeBoolean((Boolean)val);
+
+                break;
+
+            case GridBinaryMarshaller.DECIMAL:
+                writer.doWriteDecimal((BigDecimal)val);
+
+                break;
+
+            case GridBinaryMarshaller.STRING:
+                writer.doWriteString((String)val);
+
+                break;
+
+            case GridBinaryMarshaller.UUID:
+                writer.doWriteUuid((UUID)val);
+
+                break;
+
+            case GridBinaryMarshaller.DATE:
+                writer.doWriteDate((Date)val);
+
+                break;
+
+            case GridBinaryMarshaller.TIMESTAMP:
+                writer.doWriteTimestamp((Timestamp) val);
+
+                break;
+
+            case GridBinaryMarshaller.BYTE_ARR:
+                writer.doWriteByteArray((byte[])val);
+
+                break;
+
+            case GridBinaryMarshaller.SHORT_ARR:
+                writer.doWriteShortArray((short[])val);
+
+                break;
+
+            case GridBinaryMarshaller.INT_ARR:
+                writer.doWriteIntArray((int[])val);
+
+                break;
+
+            case GridBinaryMarshaller.LONG_ARR:
+                writer.doWriteLongArray((long[])val);
+
+                break;
+
+            case GridBinaryMarshaller.FLOAT_ARR:
+                writer.doWriteFloatArray((float[])val);
+
+                break;
+
+            case GridBinaryMarshaller.DOUBLE_ARR:
+                writer.doWriteDoubleArray((double[])val);
+
+                break;
+
+            case GridBinaryMarshaller.CHAR_ARR:
+                writer.doWriteCharArray((char[])val);
+
+                break;
+
+            case GridBinaryMarshaller.BOOLEAN_ARR:
+                writer.doWriteBooleanArray((boolean[])val);
+
+                break;
+
+            case GridBinaryMarshaller.DECIMAL_ARR:
+                writer.doWriteDecimalArray((BigDecimal[])val);
+
+                break;
+
+            case GridBinaryMarshaller.STRING_ARR:
+                writer.doWriteStringArray((String[])val);
+
+                break;
+
+            case GridBinaryMarshaller.UUID_ARR:
+                writer.doWriteUuidArray((UUID[])val);
+
+                break;
+
+            case GridBinaryMarshaller.DATE_ARR:
+                writer.doWriteDateArray((Date[])val);
+
+                break;
+
+            case GridBinaryMarshaller.TIMESTAMP_ARR:
+                writer.doWriteTimestampArray((Timestamp[])val);
+
+                break;
+
+            default:
+                throw new IllegalArgumentException("Can't write object with type: " + val.getClass());
+        }
+    }
+
+    /**
+     * @param obj Value to unwrap.
+     * @return Unwrapped value.
+     */
+    public static Object unwrapLazy(@Nullable Object obj) {
+        if (obj instanceof BinaryLazyValue)
+            return ((BinaryLazyValue)obj).value();
+
+        return obj;
+    }
+
+    /**
+     * @param delegate Iterator to delegate.
+     * @return New iterator.
+     */
+    public static Iterator<Object> unwrapLazyIterator(final Iterator<Object> delegate) {
+        return new Iterator<Object>() {
+            @Override public boolean hasNext() {
+                return delegate.hasNext();
+            }
+
+            @Override public Object next() {
+                return unwrapLazy(delegate.next());
+            }
+
+            @Override public void remove() {
+                delegate.remove();
+            }
+        };
+    }
+
+    /**
+     * @return {@code true} if content of serialized value cannot contain references to other object.
+     */
+    public static boolean isPlainType(int type) {
+        return type > 0 && type < PLAIN_TYPE_FLAG.length && PLAIN_TYPE_FLAG[type];
+    }
+
+    /**
+     * Checks whether an array type values can or can not contain references to other object.
+     *
+     * @param type Array type.
+     * @return {@code true} if content of serialized array value cannot contain references to other object.
+     */
+    public static boolean isPlainArrayType(int type) {
+        return (type >= GridBinaryMarshaller.BYTE_ARR && type <= GridBinaryMarshaller.DATE_ARR) || type == GridBinaryMarshaller.TIMESTAMP_ARR;
+    }
+
+    /**
+     * @param cls Class.
+     * @return Portable field type.
+     */
+    public static byte typeByClass(Class<?> cls) {
+        Byte type = PLAIN_CLASS_TO_FLAG.get(cls);
+
+        if (type != null)
+            return type;
+
+        if (cls.isEnum())
+            return GridBinaryMarshaller.ENUM;
+
+        if (cls.isArray())
+            return cls.getComponentType().isEnum() || cls.getComponentType() == Enum.class ? GridBinaryMarshaller.ENUM_ARR : GridBinaryMarshaller.OBJ_ARR;
+
+        if (isSpecialCollection(cls))
+            return GridBinaryMarshaller.COL;
+
+        if (isSpecialMap(cls))
+            return GridBinaryMarshaller.MAP;
+
+        return GridBinaryMarshaller.OBJ;
+    }
+
+    /**
+     * Tells whether provided type is portable.
+     *
+     * @param cls Class to check.
+     * @return Whether type is portable.
+     */
+    public static boolean isPortableType(Class<?> cls) {
+        assert cls != null;
+
+        return BinaryObject.class.isAssignableFrom(cls) ||
+            PORTABLE_CLS.contains(cls) ||
+            cls.isEnum() ||
+            (cls.isArray() && cls.getComponentType().isEnum());
+    }
+
+    /**
+     * Attempts to create a new map of the same type as {@code map} has. Otherwise returns new {@code HashMap} instance.
+     *
+     * @param map Original map.
+     * @return New map.
+     */
+    public static <K, V> Map<K, V> newMap(Map<K, V> map) {
+        if (map instanceof LinkedHashMap)
+            return U.newLinkedHashMap(map.size());
+        else if (map instanceof TreeMap)
+            return new TreeMap<>(((TreeMap<Object, Object>)map).comparator());
+        else if (map instanceof ConcurrentHashMap8)
+            return new ConcurrentHashMap8<>(U.capacity(map.size()));
+        else if (map instanceof ConcurrentHashMap)
+            return new ConcurrentHashMap<>(U.capacity(map.size()));
+
+        return U.newHashMap(map.size());
+    }
+
+    /**
+     * Attempts to create a new set of the same type as {@code set} has. Otherwise returns new {@code HashSet} instance.
+     *
+     * @param set Original set.
+     * @return New set.
+     */
+    public static <V> Set<V> newSet(Set<V> set) {
+        if (set instanceof LinkedHashSet)
+            return U.newLinkedHashSet(set.size());
+        else if (set instanceof TreeSet)
+            return new TreeSet<>(((TreeSet<Object>)set).comparator());
+        else if (set instanceof ConcurrentSkipListSet)
+            return new ConcurrentSkipListSet<>(((ConcurrentSkipListSet<Object>)set).comparator());
+
+        return U.newHashSet(set.size());
+    }
+
+    /**
+     * Check protocol version.
+     *
+     * @param protoVer Protocol version.
+     */
+    public static void checkProtocolVersion(byte protoVer) {
+        if (GridBinaryMarshaller.PROTO_VER != protoVer)
+            throw new BinaryObjectException("Unsupported protocol version: " + protoVer);
+    }
+
+    /**
+     * Get portable object length.
+     *
+     * @param in Input stream.
+     * @param start Start position.
+     * @return Length.
+     */
+    public static int length(BinaryPositionReadable in, int start) {
+        return in.readIntPositioned(start + GridBinaryMarshaller.TOTAL_LEN_POS);
+    }
+
+    /**
+     * Get footer start of the object.
+     *
+     * @param in Input stream.
+     * @param start Object start position inside the stream.
+     * @return Footer start.
+     */
+    public static int footerStartRelative(BinaryPositionReadable in, int start) {
+        short flags = in.readShortPositioned(start + GridBinaryMarshaller.FLAGS_POS);
+
+        if (hasSchema(flags))
+            // Schema exists, use offset.
+            return in.readIntPositioned(start + GridBinaryMarshaller.SCHEMA_OR_RAW_OFF_POS);
+        else
+            // No schema, footer start equals to object end.
+            return length(in, start);
+    }
+
+    /**
+     * Get object's footer.
+     *
+     * @param in Input stream.
+     * @param start Start position.
+     * @return Footer start.
+     */
+    public static int footerStartAbsolute(BinaryPositionReadable in, int start) {
+        return footerStartRelative(in, start) + start;
+    }
+
+    /**
+     * Get object's footer.
+     *
+     * @param in Input stream.
+     * @param start Start position.
+     * @return Footer.
+     */
+    public static IgniteBiTuple<Integer, Integer> footerAbsolute(BinaryPositionReadable in, int start) {
+        short flags = in.readShortPositioned(start + GridBinaryMarshaller.FLAGS_POS);
+
+        int footerEnd = length(in, start);
+
+        if (hasSchema(flags)) {
+            // Schema exists.
+            int footerStart = in.readIntPositioned(start + GridBinaryMarshaller.SCHEMA_OR_RAW_OFF_POS);
+
+            if (hasRaw(flags))
+                footerEnd -= 4;
+
+            assert footerStart <= footerEnd;
+
+            return F.t(start + footerStart, start + footerEnd);
+        }
+        else
+            // No schema.
+            return F.t(start + footerEnd, start + footerEnd);
+    }
+
+    /**
+     * Get relative raw offset of the object.
+     *
+     * @param in Input stream.
+     * @param start Object start position inside the stream.
+     * @return Raw offset.
+     */
+    public static int rawOffsetRelative(BinaryPositionReadable in, int start) {
+        short flags = in.readShortPositioned(start + GridBinaryMarshaller.FLAGS_POS);
+
+        int len = length(in, start);
+
+        if (hasSchema(flags)){
+            // Schema exists.
+            if (hasRaw(flags))
+                // Raw offset is set, it is at the very end of the object.
+                return in.readIntPositioned(start + len - 4);
+            else
+                // Raw offset is not set, so just return schema offset.
+                return in.readIntPositioned(start + GridBinaryMarshaller.SCHEMA_OR_RAW_OFF_POS);
+        }
+        else
+            // No schema, raw offset is located on schema offset position.
+            return in.readIntPositioned(start + GridBinaryMarshaller.SCHEMA_OR_RAW_OFF_POS);
+    }
+
+    /**
+     * Get absolute raw offset of the object.
+     *
+     * @param in Input stream.
+     * @param start Object start position inside the stream.
+     * @return Raw offset.
+     */
+    public static int rawOffsetAbsolute(BinaryPositionReadable in, int start) {
+        return start + rawOffsetRelative(in, start);
+    }
+
+    /**
+     * Get offset length for the given flags.
+     *
+     * @param flags Flags.
+     * @return Offset size.
+     */
+    public static int fieldOffsetLength(short flags) {
+        if ((flags & FLAG_OFFSET_ONE_BYTE) == FLAG_OFFSET_ONE_BYTE)
+            return OFFSET_1;
+        else if ((flags & FLAG_OFFSET_TWO_BYTES) == FLAG_OFFSET_TWO_BYTES)
+            return OFFSET_2;
+        else
+            return OFFSET_4;
+    }
+
+    /**
+     * Get field ID length.
+     *
+     * @param flags Flags.
+     * @return Field ID length.
+     */
+    public static int fieldIdLength(short flags) {
+        return isCompactFooter(flags) ? 0 : FIELD_ID_LEN;
+    }
+
+    /**
+     * Get relative field offset.
+     *
+     * @param stream Stream.
+     * @param pos Position.
+     * @param fieldOffsetSize Field offset size.
+     * @return Relative field offset.
+     */
+    public static int fieldOffsetRelative(BinaryPositionReadable stream, int pos, int fieldOffsetSize) {
+        int res;
+
+        if (fieldOffsetSize == OFFSET_1)
+            res = (int)stream.readBytePositioned(pos) & 0xFF;
+        else if (fieldOffsetSize == OFFSET_2)
+            res = (int)stream.readShortPositioned(pos) & 0xFFFF;
+        else
+            res = stream.readIntPositioned(pos);
+
+        return res;
+    }
+
+    /**
+     * Merge old and new metas.
+     *
+     * @param oldMeta Old meta.
+     * @param newMeta New meta.
+     * @return New meta if old meta was null, old meta if no changes detected, merged meta otherwise.
+     * @throws BinaryObjectException If merge failed due to metadata conflict.
+     */
+    public static BinaryMetadata mergeMetadata(@Nullable BinaryMetadata oldMeta, BinaryMetadata newMeta) {
+        assert newMeta != null;
+
+        if (oldMeta == null)
+            return newMeta;
+        else {
+            assert oldMeta.typeId() == newMeta.typeId();
+
+            // Check type name.
+            if (!F.eq(oldMeta.typeName(), newMeta.typeName())) {
+                throw new BinaryObjectException(
+                    "Two portable types have duplicate type ID [" + "typeId=" + oldMeta.typeId() +
+                        ", typeName1=" + oldMeta.typeName() + ", typeName2=" + newMeta.typeName() + ']'
+                );
+            }
+
+            // Check affinity field names.
+            if (!F.eq(oldMeta.affinityKeyFieldName(), newMeta.affinityKeyFieldName())) {
+                throw new BinaryObjectException(
+                    "Binary type has different affinity key fields [" + "typeName=" + newMeta.typeName() +
+                        ", affKeyFieldName1=" + oldMeta.affinityKeyFieldName() +
+                        ", affKeyFieldName2=" + newMeta.affinityKeyFieldName() + ']'
+                );
+            }
+
+            // Check enum flag.
+            if (oldMeta.isEnum() != newMeta.isEnum()) {
+                if (oldMeta.isEnum())
+                    throw new BinaryObjectException("Binary type already registered as enum: " +
+                        newMeta.typeName());
+                else
+                    throw new BinaryObjectException("Binary type already registered as non-enum: " +
+                        newMeta.typeName());
+            }
+
+            // Check and merge fields.
+            boolean changed = false;
+
+            Map<String, Integer> mergedFields = new HashMap<>(oldMeta.fieldsMap());
+            Map<String, Integer> newFields = newMeta.fieldsMap();
+
+            for (Map.Entry<String, Integer> newField : newFields.entrySet()) {
+                Integer oldFieldType = mergedFields.put(newField.getKey(), newField.getValue());
+
+                if (oldFieldType == null)
+                    changed = true;
+                else if (!F.eq(oldFieldType, newField.getValue())) {
+                    throw new BinaryObjectException(
+                        "Binary type has different field types [" + "typeName=" + oldMeta.typeName() +
+                            ", fieldName=" + newField.getKey() +
+                            ", fieldTypeName1=" + fieldTypeName(oldFieldType) +
+                            ", fieldTypeName2=" + fieldTypeName(newField.getValue()) + ']'
+                    );
+                }
+            }
+
+            // Check and merge schemas.
+            Collection<BinarySchema> mergedSchemas = new HashSet<>(oldMeta.schemas());
+
+            for (BinarySchema newSchema : newMeta.schemas()) {
+                if (mergedSchemas.add(newSchema))
+                    changed = true;
+            }
+
+            // Return either old meta if no changes detected, or new merged meta.
+            return changed ? new BinaryMetadata(oldMeta.typeId(), oldMeta.typeName(), mergedFields,
+                oldMeta.affinityKeyFieldName(), mergedSchemas, oldMeta.isEnum()) : oldMeta;
+        }
+    }
+
+    /**
+     * @param cls Class.
+     * @return Mode.
+     */
+    @SuppressWarnings("IfMayBeConditional")
+    public static BinaryWriteMode mode(Class<?> cls) {
+        assert cls != null;
+
+        /** Primitives. */
+        if (cls == byte.class)
+            return BinaryWriteMode.P_BYTE;
+        else if (cls == boolean.class)
+            return BinaryWriteMode.P_BOOLEAN;
+        else if (cls == short.class)
+            return BinaryWriteMode.P_SHORT;
+        else if (cls == char.class)
+            return BinaryWriteMode.P_CHAR;
+        else if (cls == int.class)
+            return BinaryWriteMode.P_INT;
+        else if (cls == long.class)
+            return BinaryWriteMode.P_LONG;
+        else if (cls == float.class)
+            return BinaryWriteMode.P_FLOAT;
+        else if (cls == double.class)
+            return BinaryWriteMode.P_DOUBLE;
+
+        /** Boxed primitives. */
+        else if (cls == Byte.class)
+            return BinaryWriteMode.BYTE;
+        else if (cls == Boolean.class)
+            return BinaryWriteMode.BOOLEAN;
+        else if (cls == Short.class)
+            return BinaryWriteMode.SHORT;
+        else if (cls == Character.class)
+            return BinaryWriteMode.CHAR;
+        else if (cls == Integer.class)
+            return BinaryWriteMode.INT;
+        else if (cls == Long.class)
+            return BinaryWriteMode.LONG;
+        else if (cls == Float.class)
+            return BinaryWriteMode.FLOAT;
+        else if (cls == Double.class)
+            return BinaryWriteMode.DOUBLE;
+
+        /** The rest types. */
+        else if (cls == BigDecimal.class)
+            return BinaryWriteMode.DECIMAL;
+        else if (cls == String.class)
+            return BinaryWriteMode.STRING;
+        else if (cls == UUID.class)
+            return BinaryWriteMode.UUID;
+        else if (cls == Date.class)
+            return BinaryWriteMode.DATE;
+        else if (cls == Timestamp.class)
+            return BinaryWriteMode.TIMESTAMP;
+        else if (cls == byte[].class)
+            return BinaryWriteMode.BYTE_ARR;
+        else if (cls == short[].class)
+            return BinaryWriteMode.SHORT_ARR;
+        else if (cls == int[].class)
+            return BinaryWriteMode.INT_ARR;
+        else if (cls == long[].class)
+            return BinaryWriteMode.LONG_ARR;
+        else if (cls == float[].class)
+            return BinaryWriteMode.FLOAT_ARR;
+        else if (cls == double[].class)
+            return BinaryWriteMode.DOUBLE_ARR;
+        else if (cls == char[].class)
+            return BinaryWriteMode.CHAR_ARR;
+        else if (cls == boolean[].class)
+            return BinaryWriteMode.BOOLEAN_ARR;
+        else if (cls == BigDecimal[].class)
+            return BinaryWriteMode.DECIMAL_ARR;
+        else if (cls == String[].class)
+            return BinaryWriteMode.STRING_ARR;
+        else if (cls == UUID[].class)
+            return BinaryWriteMode.UUID_ARR;
+        else if (cls == Date[].class)
+            return BinaryWriteMode.DATE_ARR;
+        else if (cls == Timestamp[].class)
+            return BinaryWriteMode.TIMESTAMP_ARR;
+        else if (cls.isArray())
+            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))
+            return BinaryWriteMode.PORTABLE;
+        else if (Externalizable.class.isAssignableFrom(cls))
+            return BinaryWriteMode.EXTERNALIZABLE;
+        else if (isSpecialCollection(cls))
+            return BinaryWriteMode.COL;
+        else if (isSpecialMap(cls))
+            return BinaryWriteMode.MAP;
+        else if (cls.isEnum())
+            return BinaryWriteMode.ENUM;
+        else if (cls == Class.class)
+            return BinaryWriteMode.CLASS;
+        else
+            return BinaryWriteMode.OBJECT;
+    }
+
+    /**
+     * 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(BinaryInputStream in) {
+        int len = in.readInt();
+
+        return in.readByteArray(len);
+    }
+
+    /**
+     * @return Value.
+     */
+    public static boolean[] doReadBooleanArray(BinaryInputStream in) {
+        int len = in.readInt();
+
+        return in.readBooleanArray(len);
+    }
+
+    /**
+     * @return Value.
+     */
+    public static short[] doReadShortArray(BinaryInputStream in) {
+        int len = in.readInt();
+
+        return in.readShortArray(len);
+    }
+
+    /**
+     * @return Value.
+     */
+    public static char[] doReadCharArray(BinaryInputStream in) {
+        int len = in.readInt();
+
+        return in.readCharArray(len);
+    }
+
+    /**
+     * @return Value.
+     */
+    public static int[] doReadIntArray(BinaryInputStream in) {
+        int len = in.readInt();
+
+        return in.readIntArray(len);
+    }
+
+    /**
+     * @return Value.
+     */
+    public static long[] doReadLongArray(BinaryInputStream in) {
+        int len = in.readInt();
+
+        return in.readLongArray(len);
+    }
+
+    /**
+     * @return Value.
+     */
+    public static float[] doReadFloatArray(BinaryInputStream in) {
+        int len = in.readInt();
+
+        return in.readFloatArray(len);
+    }
+
+    /**
+     * @return Value.
+     */
+    public static double[] doReadDoubleArray(BinaryInputStream in) {
+        int len = in.readInt();
+
+        return in.readDoubleArray(len);
+    }
+
+    /**
+     * @return Value.
+     */
+    public static BigDecimal doReadDecimal(BinaryInputStream in) {
+        int scale = in.readInt();
+        byte[] mag = doReadByteArray(in);
+
+        BigInteger intVal = new BigInteger(mag);
+
+        if (scale < 0) {
+            scale &= 0x7FFFFFFF;
+
+            intVal = intVal.negate();
+        }
+
+        return new BigDecimal(intVal, scale);
+    }
+
+    /**
+     * @return Value.
+     */
+    public static String doReadString(BinaryInputStream in) {
+        if (!in.hasArray())
+            return new String(doReadByteArray(in), UTF_8);
+
+        int strLen = in.readInt();
+
+        int pos = in.position();
+
+        // String will copy necessary array part for us.
+        String res = new String(in.array(), pos, strLen, UTF_8);
+
+        in.position(pos + strLen);
+
+        return res;
+    }
+
+    /**
+     * @return Value.
+     */
+    public static UUID doReadUuid(BinaryInputStream in) {
+        return new UUID(in.readLong(), in.readLong());
+    }
+
+    /**
+     * @return Value.
+     */
+    public static Date doReadDate(BinaryInputStream in) {
+        long time = in.readLong();
+
+        return new Date(time);
+    }
+
+    /**
+     * @return Value.
+     */
+    public static Timestamp doReadTimestamp(BinaryInputStream in) {
+        long time = in.readLong();
+        int nanos = in.readInt();
+
+        Timestamp ts = new Timestamp(time);
+
+        ts.setNanos(ts.getNanos() + nanos);
+
+        return ts;
+    }
+
+    /**
+     * @return Value.
+     * @throws BinaryObjectException In case of error.
+     */
+    public static BigDecimal[] doReadDecimalArray(BinaryInputStream in) throws BinaryObjectException {
+        int len = in.readInt();
+
+        BigDecimal[] arr = new BigDecimal[len];
+
+        for (int i = 0; i < len; i++) {
+            byte flag = in.readByte();
+
+            if (flag == GridBinaryMarshaller.NULL)
+                arr[i] = null;
+            else {
+                if (flag != GridBinaryMarshaller.DECIMAL)
+                    throw new BinaryObjectException("Invalid flag value: " + flag);
+
+                arr[i] = doReadDecimal(in);
+            }
+        }
+
+        return arr;
+    }
+
+    /**
+     * @return Value.
+     * @throws BinaryObjectException In case of error.
+     */
+    public static String[] doReadStringArray(BinaryInputStream in) throws BinaryObjectException {
+        int len = in.readInt();
+
+        String[] arr = new String[len];
+
+        for (int i = 0; i < len; i++) {
+            byte flag = in.readByte();
+
+            if (flag == GridBinaryMarshaller.NULL)
+                arr[i] = null;
+            else {
+                if (flag != GridBinaryMarshaller.STRING)
+                    throw new BinaryObjectException("Invalid flag value: " + flag);
+
+                arr[i] = doReadString(in);
+            }
+        }
+
+        return arr;
+    }
+
+    /**
+     * @return Value.
+     * @throws BinaryObjectException In case of error.
+     */
+    public static UUID[] doReadUuidArray(BinaryInputStream in) throws BinaryObjectException {
+        int len = in.readInt();
+
+        UUID[] arr = new UUID[len];
+
+        for (int i = 0; i < len; i++) {
+            byte flag = in.readByte();
+
+            if (flag == GridBinaryMarshaller.NULL)
+                arr[i] = null;
+            else {
+                if (flag != GridBinaryMarshaller.UUID)
+                    throw new BinaryObjectException("Invalid flag value: " + flag);
+
+                arr[i] = doReadUuid(in);
+            }
+        }
+
+        return arr;
+    }
+
+    /**
+     * @return Value.
+     * @throws BinaryObjectException In case of error.
+     */
+    public static Date[] doReadDateArray(BinaryInputStream in) throws BinaryObjectException {
+        int len = in.readInt();
+
+        Date[] arr = new Date[len];
+
+        for (int i = 0; i < len; i++) {
+            byte flag = in.readByte();
+
+            if (flag == GridBinaryMarshaller.NULL)
+                arr[i] = null;
+            else {
+                if (flag != GridBinaryMarshaller.DATE)
+                    throw new BinaryObjectException("Invalid flag value: " + flag);
+
+                arr[i] = doReadDate(in);
+            }
+        }
+
+        return arr;
+    }
+
+    /**
+     * @return Value.
+     * @throws BinaryObjectException In case of error.
+     */
+    public static Timestamp[] doReadTimestampArray(BinaryInputStream in) throws BinaryObjectException {
+        int len = in.readInt();
+
+        Timestamp[] arr = new Timestamp[len];
+
+        for (int i = 0; i < len; i++) {
+            byte flag = in.readByte();
+
+            if (flag == GridBinaryMarshaller.NULL)
+                arr[i] = null;
+            else {
+                if (flag != GridBinaryMarshaller.TIMESTAMP)
+                    throw new BinaryObjectException("Invalid flag value: " + flag);
+
+                arr[i] = doReadTimestamp(in);
+            }
+        }
+
+        return arr;
+    }
+
+    /**
+     * @return Value.
+     */
+    public static BinaryObject doReadPortableObject(BinaryInputStream in, BinaryContext ctx) {
+        if (in.offheapPointer() > 0) {
+            int len = in.readInt();
+
+            int pos = in.position();
+
+            in.position(in.position() + len);
+
+            int start = in.readInt();
+
+            return new BinaryObjectOffheapImpl(ctx, in.offheapPointer() + pos, start, len);
+        }
+        else {
+            byte[] arr = doReadByteArray(in);
+            int start = in.readInt();
+
+            return new BinaryObjectImpl(ctx, arr, start);
+        }
+    }
+
+    /**
+     * @return Value.
+     */
+    public static Class doReadClass(BinaryInputStream in, BinaryContext ctx, ClassLoader ldr)
+        throws BinaryObjectException {
+        int typeId = in.readInt();
+
+        return doReadClass(in, ctx, ldr, typeId);
+    }
+
+    /**
+     * Read plain type.
+     *
+     * @param in Input stream.
+     * @return Plain type.
+     */
+    private static EnumType doReadEnumType(BinaryInputStream in) {
+        int typeId = in.readInt();
+
+        if (typeId != GridBinaryMarshaller.UNREGISTERED_TYPE_ID)
+            return new EnumType(typeId, null);
+        else {
+            String clsName = doReadClassName(in);
+
+            return new EnumType(GridBinaryMarshaller.UNREGISTERED_TYPE_ID, clsName);
+        }
+    }
+
+    /**
+     * @param in Input stream.
+     * @return Class name.
+     */
+    private static String doReadClassName(BinaryInputStream in) {
+        byte flag = in.readByte();
+
+        if (flag != GridBinaryMarshaller.STRING)
+            throw new BinaryObjectException("Failed to read class name [position=" + (in.position() - 1) + ']');
+
+        return doReadString(in);
+    }
+
+    /**
+     * @param typeId Type id.
+     * @return Value.
+     */
+    public static Class doReadClass(BinaryInputStream in, BinaryContext ctx, ClassLoader ldr, int typeId)
+        throws BinaryObjectException {
+        Class cls;
+
+        if (typeId == GridBinaryMarshaller.OBJECT_TYPE_ID)
+            return Object.class;
+
+        if (typeId != GridBinaryMarshaller.UNREGISTERED_TYPE_ID)
+            cls = ctx.descriptorForTypeId(true, typeId, ldr, false).describedClass();
+        else {
+            String clsName = doReadClassName(in);
+
+            try {
+                cls = U.forName(clsName, ldr);
+            }
+            catch (ClassNotFoundException e) {
+                throw new BinaryInvalidTypeException("Failed to load the class: " + clsName, e);
+            }
+
+            // forces registering of class by type id, at least locally
+            ctx.descriptorForClass(cls, true);
+        }
+
+        return cls;
+    }
+
+    /**
+     * Resolve the class.
+     *
+     * @param ctx Portable context.
+     * @param typeId Type ID.
+     * @param clsName Class name.
+     * @param ldr Class loaded.
+     * @return Resovled class.
+     */
+    public static Class resolveClass(BinaryContext ctx, int typeId, @Nullable String clsName,
+        @Nullable ClassLoader ldr, boolean deserialize) {
+        Class cls;
+
+        if (typeId == GridBinaryMarshaller.OBJECT_TYPE_ID)
+            return Object.class;
+
+        if (typeId != GridBinaryMarshaller.UNREGISTERED_TYPE_ID)
+            cls = ctx.descriptorForTypeId(true, typeId, ldr, deserialize).describedClass();
+        else {
+            try {
+                cls = U.forName(clsName, ldr);
+            }
+            catch (ClassNotFoundException e) {
+                throw new BinaryInvalidTypeException("Failed to load the class: " + clsName, e);
+            }
+
+            // forces registering of class by type id, at least locally
+            ctx.descriptorForClass(cls, true);
+        }
+
+        return cls;
+    }
+
+    /**
+     * Read portable enum.
+     *
+     * @param in Input stream.
+     * @param ctx Portable context.
+     * @param type Plain type.
+     * @return Enum.
+     */
+    private static BinaryEnumObjectImpl doReadPortableEnum(BinaryInputStream in, BinaryContext ctx,
+        EnumType type) {
+        return new BinaryEnumObjectImpl(ctx, type.typeId, type.clsName, in.readInt());
+    }
+
+    /**
+     * Read portable enum array.
+     *
+     * @param in Input stream.
+     * @param ctx Portable context.
+     * @return Enum array.
+     */
+    private static Object[] doReadPortableEnumArray(BinaryInputStream in, BinaryContext ctx) {
+        int len = in.readInt();
+
+        Object[] arr = (Object[]) Array.newInstance(BinaryObject.class, len);
+
+        for (int i = 0; i < len; i++) {
+            byte flag = in.readByte();
+
+            if (flag == GridBinaryMarshaller.NULL)
+                arr[i] = null;
+            else
+                arr[i] = doReadPortableEnum(in, ctx, doReadEnumType(in));
+        }
+
+        return arr;
+    }
+
+    /**
+     * Having target class in place we simply read ordinal and create final representation.
+     *
+     * @param cls Enum class.
+     * @return Value.
+     */
+    public static Enum<?> doReadEnum(BinaryInputStream in, Class<?> cls) throws BinaryObjectException {
+        assert cls != null;
+
+        if (!cls.isEnum())
+            throw new BinaryObjectException("Class does not represent enum type: " + cls.getName());
+
+        int ord = in.readInt();
+
+        return BinaryEnumCache.get(cls, ord);
+    }
+
+    /**
+     * @param cls Enum class.
+     * @return Value.
+     */
+    public static Object[] doReadEnumArray(BinaryInputStream in, BinaryContext ctx, ClassLoader ldr, Class<?> cls)
+        throws BinaryObjectException {
+        int len = in.readInt();
+
+        Object[] arr = (Object[]) Array.newInstance(cls, len);
+
+        for (int i = 0; i < len; i++) {
+            byte flag = in.readByte();
+
+            if (flag == GridBinaryMarshaller.NULL)
+                arr[i] = null;
+            else
+                arr[i] = doReadEnum(in, doReadClass(in, ctx, ldr));
+        }
+
+        return arr;
+    }
+
+    /**
+     * Read object serialized using optimized marshaller.
+     *
+     * @return Result.
+     */
+    public static Object doReadOptimized(BinaryInputStream in, BinaryContext ctx, @Nullable ClassLoader clsLdr) {
+        int len = in.readInt();
+
+        ByteArrayInputStream input = new ByteArrayInputStream(in.array(), in.position(), len);
+
+        try {
+            return ctx.optimizedMarsh().unmarshal(input, clsLdr);
+        }
+        catch (IgniteCheckedException e) {
+            throw new BinaryObjectException("Failed to unmarshal object with optimized marshaller", e);
+        }
+        finally {
+            in.position(in.position() + len);
+        }
+    }
+
+    /**
+     * @return Object.
+     * @throws BinaryObjectException In case of error.
+     */
+    @Nullable public static Object doReadObject(BinaryInputStream in, BinaryContext ctx, ClassLoader ldr,
+        BinaryReaderHandlesHolder handles) throws BinaryObjectException {
+        return new BinaryReaderExImpl(ctx, in, ldr, handles.handles()).deserialize();
+    }
+
+    /**
+     * @return Unmarshalled value.
+     * @throws BinaryObjectException In case of error.
+     */
+    @Nullable public static Object unmarshal(BinaryInputStream in, BinaryContext ctx, ClassLoader ldr)
+        throws BinaryObjectException {
+        return unmarshal(in, ctx, ldr, new BinaryReaderHandlesHolderImpl());
+    }
+
+    /**
+     * @return Unmarshalled value.
+     * @throws BinaryObjectException In case of error.
+     */
+    @Nullable public static Object unmarshal(BinaryInputStream in, BinaryContext ctx, ClassLoader ldr,
+        BinaryReaderHandlesHolder handles) throws BinaryObjectException {
+        return unmarshal(in, ctx, ldr, handles, false);
+    }
+
+    /**
+     * @return Unmarshalled value.
+     * @throws BinaryObjectException In case of error.
+     */
+    @Nullable public static Object unmarshal(BinaryInputStream in, BinaryContext ctx, ClassLoader ldr,
+        BinaryReaderHandlesHolder handles, boolean detach) throws BinaryObjectException {
+        int start = in.position();
+
+        byte flag = in.readByte();
+
+        switch (flag) {
+            case GridBinaryMarshaller.NULL:
+                return null;
+
+            case GridBinaryMarshaller.HANDLE: {
+                int handlePos = start - in.readInt();
+
+                Object obj = handles.getHandle(handlePos);
+
+                if (obj == null) {
+                    int retPos = in.position();
+
+                    in.position(handlePos);
+
+                    obj = unmarshal(in, ctx, ldr, handles);
+
+                    in.position(retPos);
+                }
+
+                return obj;
+            }
+
+            case GridBinaryMarshaller.OBJ: {
+                checkProtocolVersion(in.readByte());
+
+                int len = length(in, start);
+
+                BinaryObjectExImpl po;
+
+                if (detach) {
+                    // In detach mode we simply copy object's content.
+                    in.position(start);
+
+                    po = new BinaryObjectImpl(ctx, in.readByteArray(len), 0);
+                }
+                else {
+                    if (in.offheapPointer() == 0)
+                        po = new BinaryObjectImpl(ctx, in.array(), start);
+                    else
+                        po = new BinaryObjectOffheapImpl(ctx, in.offheapPointer(), start,
+                            in.remaining() + in.position());
+
+                    in.position(start + po.length());
+                }
+
+                handles.setHandle(po, start);
+
+                return po;
+            }
+
+            case GridBinaryMarshaller.BYTE:
+                return in.readByte();
+
+            case GridBinaryMarshaller.SHORT:
+                return in.readShort();
+
+            case GridBinaryMarshaller.INT:
+                return in.readInt();
+
+            case GridBinaryMarshaller.LONG:
+                return in.readLong();
+
+            case GridBinaryMarshaller.FLOAT:
+                return in.readFloat();
+
+            case GridBinaryMarshaller.DOUBLE:
+                return in.readDouble();
+
+            case GridBinaryMarshaller.CHAR:
+                return in.readChar();
+
+            case GridBinaryMarshaller.BOOLEAN:
+                return in.readBoolean();
+
+            case GridBinaryMarshaller.DECIMAL:
+                return doReadDecimal(in);
+
+            case GridBinaryMarshaller.STRING:
+                return doReadString(in);
+
+            case GridBinaryMarshaller.UUID:
+                return doReadUuid(in);
+
+            case GridBinaryMarshaller.DATE:
+                return doReadDate(in);
+
+            case GridBinaryMarshaller.TIMESTAMP:
+                return doReadTimestamp(in);
+
+            case GridBinaryMarshaller.BYTE_ARR:
+                return doReadByteArray(in);
+
+            case GridBinaryMarshaller.SHORT_ARR:
+                return doReadShortArray(in);
+
+            case GridBinaryMarshaller.INT_ARR:
+                return doReadIntArray(in);
+
+            case GridBinaryMarshaller.LONG_ARR:
+                return doReadLongArray(in);
+
+            case GridBinaryMarshaller.FLOAT_ARR:
+                return doReadFloatArray(in);
+
+            case GridBinaryMarshaller.DOUBLE_ARR:
+                return doReadDoubleArray(in);
+
+            case GridBinaryMarshaller.CHAR_ARR:
+                return doReadCharArray(in);
+
+            case GridBinaryMarshaller.BOOLEAN_ARR:
+                return doReadBooleanArray(in);
+
+            case GridBinaryMarshaller.DECIMAL_ARR:
+                return doReadDecimalArray(in);
+
+            case GridBinaryMarshaller.STRING_ARR:
+                return doReadStringArray(in);
+
+            case GridBinaryMarshaller.UUID_ARR:
+                return doReadUuidArray(in);
+
+            case GridBinaryMarshaller.DATE_ARR:
+                return doReadDateArray(in);
+
+            case GridBinaryMarshaller.TIMESTAMP_ARR:
+                return doReadTimestampArray(in);
+
+            case GridBinaryMarshaller.OBJ_ARR:
+                return doReadObjectArray(in, ctx, ldr, handles, false);
+
+            case GridBinaryMarshaller.COL:
+                return doReadCollection(in, ctx, ldr, handles, false, null);
+
+            case GridBinaryMarshaller.MAP:
+                return doReadMap(in, ctx, ldr, handles, false, null);
+
+            case GridBinaryMarshaller.PORTABLE_OBJ:
+                return doReadPortableObject(in, ctx);
+
+            case GridBinaryMarshaller.ENUM:
+                return doReadPortableEnum(in, ctx, doReadEnumType(in));
+
+            case GridBinaryMarshaller.ENUM_ARR:
+                doReadEnumType(in); // Simply skip this part as we do not need it.
+
+                return doReadPortableEnumArray(in, ctx);
+
+            case GridBinaryMarshaller.CLASS:
+                return doReadClass(in, ctx, ldr);
+
+            case GridBinaryMarshaller.OPTM_MARSH:
+                return doReadOptimized(in, ctx, ldr);
+
+            default:
+                throw new BinaryObjectException("Invalid flag value: " + flag);
+        }
+    }
+
+    /**
+     * @param deserialize Deep flag.
+     * @return Value.
+     * @throws BinaryObjectException In case of error.
+     */
+    public static Object[] doReadObjectArray(BinaryInputStream in, BinaryContext ctx, ClassLoader ldr,
+        BinaryReaderHandlesHolder handles, boolean deserialize) throws BinaryObjectException {
+        int hPos = positionForHandle(in);
+
+        Class compType = doReadClass(in, ctx, ldr);
+
+        int len = in.readInt();
+
+        Object[] arr = deserialize ? (Object[])Array.newInstance(compType, len) : new Object[len];
+
+        handles.setHandle(arr, hPos);
+
+        for (int i = 0; i < len; i++)
+            arr[i] = deserializeOrUnmarshal(in, ctx, ldr, handles, deserialize);
+
+        return arr;
+    }
+
+    /**
+     * @param deserialize Deep flag.
+     * @param factory Collection factory.
+     * @return Value.
+     * @throws BinaryObjectException In case of error.
+     */
+    @SuppressWarnings("unchecked")
+    public static Collection<?> doReadCollection(BinaryInputStream in, BinaryContext ctx, ClassLoader ldr,
+        BinaryReaderHandlesHolder handles, boolean deserialize, BinaryCollectionFactory factory)
+        throws BinaryObjectException {
+        int hPos = positionForHandle(in);
+
+        int size = in.readInt();
+
+        assert size >= 0;
+
+        byte colType = in.readByte();
+
+        Collection<Object> col;
+
+        if (factory != null)
+            col = factory.create(size);
+        else {
+            switch (colType) {
+                case GridBinaryMarshaller.ARR_LIST:
+                    col = new ArrayList<>(size);
+
+                    break;
+
+                case GridBinaryMarshaller.LINKED_LIST:
+                    col = new LinkedList<>();
+
+                    break;
+
+                case GridBinaryMarshaller.HASH_SET:
+                    col = U.newHashSet(size);
+
+                    break;
+
+                case GridBinaryMarshaller.LINKED_HASH_SET:
+                    col = U.newLinkedHashSet(size);
+
+                    break;
+
+                case GridBinaryMarshaller.USER_SET:
+                    col = U.newHashSet(size);
+
+                    break;
+
+                case GridBinaryMarshaller.USER_COL:
+                    col = new ArrayList<>(size);
+
+                    break;
+
+                default:
+                    throw new BinaryObjectException("Invalid collection type: " + colType);
+            }
+        }
+
+        handles.setHandle(col, hPos);
+
+        for (int i = 0; i < size; i++)
+            col.add(deserializeOrUnmarshal(in, ctx, ldr, handles, deserialize));
+
+        return col;
+    }
+
+    /**
+     * @param deserialize Deep flag.
+     * @param factory Map factory.
+     * @return Value.
+     * @throws BinaryObjectException In case of error.
+     */
+    @SuppressWarnings("unchecked")
+    public static Map<?, ?> doReadMap(BinaryInputStream in, BinaryContext ctx, ClassLoader ldr,
+        BinaryReaderHandlesHolder handles, boolean deserialize, BinaryMapFactory factory)
+        throws BinaryObjectException {
+        int hPos = positionForHandle(in);
+
+        int size = in.readInt();
+
+        assert size >= 0;
+
+        byte mapType = in.readByte();
+
+        Map<Object, Object> map;
+
+        if (factory != null)
+            map = factory.create(size);
+        else {
+            switch (mapType) {
+                case GridBinaryMarshaller.HASH_MAP:
+                    map = U.newHashMap(size);
+
+                    break;
+
+                case GridBinaryMarshaller.LINKED_HASH_MAP:
+                    map = U.newLinkedHashMap(size);
+
+                    break;
+
+                case GridBinaryMarshaller.USER_COL:
+                    map = U.newHashMap(size);
+
+                    break;
+
+                default:
+                    throw new BinaryObjectException("Invalid map type: " + mapType);
+            }
+        }
+
+        handles.setHandle(map, hPos);
+
+        for (int i = 0; i < size; i++) {
+            Object key = deserializeOrUnmarshal(in, ctx, ldr, handles, deserialize);
+            Object val = deserializeOrUnmarshal(in, ctx, ldr, handles, deserialize);
+
+            map.put(key, val);
+        }
+
+        return map;
+    }
+
+    /**
+     * Deserialize or unmarshal the object.
+     *
+     * @param deserialize Deserialize.
+     * @return Result.
+     */
+    private static Object deserializeOrUnmarshal(BinaryInputStream in, BinaryContext ctx, ClassLoader ldr,
+        BinaryReaderHandlesHolder handles, boolean deserialize) {
+        return deserialize ? doReadObject(in, ctx, ldr, handles) : unmarshal(in, ctx, ldr, handles);
+    }
+
+    /**
+     * Get position to be used for handle. We assume here that the hdr byte was read, hence subtract -1.
+     *
+     * @return Position for handle.
+     */
+    public static int positionForHandle(BinaryInputStream in) {
+        return in.position() - 1;
+    }
+
+    /**
+     * Enum type.
+     */
+    private static class EnumType {
+        /** Type ID. */
+        private final int typeId;
+
+        /** Class name. */
+        private final String clsName;
+
+        /**
+         * Constructor.
+         *
+         * @param typeId Type ID.
+         * @param clsName Class name.
+         */
+        public EnumType(int typeId, @Nullable String clsName) {
+            assert typeId != GridBinaryMarshaller.UNREGISTERED_TYPE_ID && clsName == null ||
+                typeId == GridBinaryMarshaller.UNREGISTERED_TYPE_ID && clsName != null;
+
+            this.typeId = typeId;
+            this.clsName = clsName;
+        }
+    }
+}


[25/59] [abbrv] ignite git commit: ignite-2065: rename "portable" packages to "binary"

Posted by ak...@apache.org.
http://git-wip-us.apache.org/repos/asf/ignite/blob/1dbf20e0/modules/core/src/main/java/org/apache/ignite/internal/binary/builder/BinaryObjectBuilderImpl.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/binary/builder/BinaryObjectBuilderImpl.java b/modules/core/src/main/java/org/apache/ignite/internal/binary/builder/BinaryObjectBuilderImpl.java
new file mode 100644
index 0000000..f5e4e06
--- /dev/null
+++ b/modules/core/src/main/java/org/apache/ignite/internal/binary/builder/BinaryObjectBuilderImpl.java
@@ -0,0 +1,587 @@
+/*
+ * 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.binary.builder;
+
+import org.apache.ignite.binary.BinaryInvalidTypeException;
+import org.apache.ignite.binary.BinaryObject;
+import org.apache.ignite.binary.BinaryObjectBuilder;
+import org.apache.ignite.binary.BinaryObjectException;
+import org.apache.ignite.binary.BinaryType;
+import org.apache.ignite.internal.binary.BinaryMetadata;
+import org.apache.ignite.internal.binary.BinaryObjectImpl;
+import org.apache.ignite.internal.binary.BinaryWriterExImpl;
+import org.apache.ignite.internal.binary.GridPortableMarshaller;
+import org.apache.ignite.internal.binary.PortableContext;
+import org.apache.ignite.internal.binary.PortableSchema;
+import org.apache.ignite.internal.binary.PortableSchemaRegistry;
+import org.apache.ignite.internal.binary.BinaryMetadata;
+import org.apache.ignite.internal.binary.BinaryObjectImpl;
+import org.apache.ignite.internal.binary.BinaryObjectOffheapImpl;
+import org.apache.ignite.internal.binary.BinaryWriterExImpl;
+import org.apache.ignite.internal.binary.GridPortableMarshaller;
+import org.apache.ignite.internal.binary.PortableContext;
+import org.apache.ignite.internal.binary.PortableSchema;
+import org.apache.ignite.internal.binary.PortableSchemaRegistry;
+import org.apache.ignite.internal.binary.PortableUtils;
+import org.apache.ignite.internal.util.typedef.F;
+import org.apache.ignite.internal.util.typedef.internal.U;
+import org.apache.ignite.lang.IgniteBiTuple;
+import org.jetbrains.annotations.Nullable;
+
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.LinkedHashMap;
+import java.util.Map;
+import java.util.Set;
+
+import static org.apache.ignite.internal.binary.GridPortableMarshaller.DFLT_HDR_LEN;
+import static org.apache.ignite.internal.binary.GridPortableMarshaller.FLAGS_POS;
+import static org.apache.ignite.internal.binary.GridPortableMarshaller.HASH_CODE_POS;
+import static org.apache.ignite.internal.binary.GridPortableMarshaller.PROTO_VER_POS;
+import static org.apache.ignite.internal.binary.GridPortableMarshaller.TYPE_ID_POS;
+import static org.apache.ignite.internal.binary.GridPortableMarshaller.UNREGISTERED_TYPE_ID;
+
+/**
+ *
+ */
+public class BinaryObjectBuilderImpl implements BinaryObjectBuilder {
+    /** */
+    private static final Object REMOVED_FIELD_MARKER = new Object();
+
+    /** */
+    private final PortableContext ctx;
+
+    /** */
+    private final int typeId;
+
+    /** May be null. */
+    private String typeName;
+
+    /** May be null. */
+    private String clsNameToWrite;
+
+    /** */
+    private boolean registeredType = true;
+
+    /** */
+    private Map<String, Object> assignedVals;
+
+    /** */
+    private Map<Integer, Object> readCache;
+
+    /** Position of object in source array, or -1 if object is not created from PortableObject. */
+    private final int start;
+
+    /** Flags. */
+    private final short flags;
+
+    /** Total header length */
+    private final int hdrLen;
+
+    /** Context of PortableObject reading process. Or {@code null} if object is not created from PortableObject. */
+    private final PortableBuilderReader reader;
+
+    /** */
+    private int hashCode;
+
+    /**
+     * @param clsName Class name.
+     * @param ctx Portable context.
+     */
+    public BinaryObjectBuilderImpl(PortableContext ctx, String clsName) {
+        this(ctx, ctx.typeId(clsName), PortableContext.typeName(clsName));
+    }
+
+    /**
+     * @param typeName Type name.
+     * @param ctx Context.
+     * @param typeId Type id.
+     */
+    public BinaryObjectBuilderImpl(PortableContext ctx, int typeId, String typeName) {
+        this.typeId = typeId;
+        this.typeName = typeName;
+        this.ctx = ctx;
+
+        start = -1;
+        flags = -1;
+        reader = null;
+        hdrLen = GridPortableMarshaller.DFLT_HDR_LEN;
+
+        readCache = Collections.emptyMap();
+    }
+
+    /**
+     * @param obj Object to wrap.
+     */
+    public BinaryObjectBuilderImpl(BinaryObjectImpl obj) {
+        this(new PortableBuilderReader(obj), obj.start());
+
+        reader.registerObject(this);
+    }
+
+    /**
+     * @param reader ctx
+     * @param start Start.
+     */
+    BinaryObjectBuilderImpl(PortableBuilderReader reader, int start) {
+        this.reader = reader;
+        this.start = start;
+        this.flags = reader.readShortPositioned(start + GridPortableMarshaller.FLAGS_POS);
+
+        byte ver = reader.readBytePositioned(start + GridPortableMarshaller.PROTO_VER_POS);
+
+        PortableUtils.checkProtocolVersion(ver);
+
+        int typeId = reader.readIntPositioned(start + GridPortableMarshaller.TYPE_ID_POS);
+        ctx = reader.portableContext();
+        hashCode = reader.readIntPositioned(start + GridPortableMarshaller.HASH_CODE_POS);
+
+        if (typeId == GridPortableMarshaller.UNREGISTERED_TYPE_ID) {
+            int mark = reader.position();
+
+            reader.position(start + GridPortableMarshaller.DFLT_HDR_LEN);
+
+            clsNameToWrite = reader.readString();
+
+            Class cls;
+
+            try {
+                // TODO: IGNITE-1272 - Is class loader needed here?
+                cls = U.forName(clsNameToWrite, null);
+            }
+            catch (ClassNotFoundException e) {
+                throw new BinaryInvalidTypeException("Failed to load the class: " + clsNameToWrite, e);
+            }
+
+            this.typeId = ctx.descriptorForClass(cls, false).typeId();
+
+            registeredType = false;
+
+            hdrLen = reader.position() - mark;
+
+            reader.position(mark);
+        }
+        else {
+            this.typeId = typeId;
+            hdrLen = GridPortableMarshaller.DFLT_HDR_LEN;
+        }
+    }
+
+    /** {@inheritDoc} */
+    @Override public BinaryObject build() {
+        try (BinaryWriterExImpl writer = new BinaryWriterExImpl(ctx)) {
+            writer.typeId(typeId);
+
+            PortableBuilderSerializer serializationCtx = new PortableBuilderSerializer();
+
+            serializationCtx.registerObjectWriting(this, 0);
+
+            serializeTo(writer, serializationCtx);
+
+            byte[] arr = writer.array();
+
+            return new BinaryObjectImpl(ctx, arr, 0);
+        }
+    }
+
+    /**
+     * @param writer Writer.
+     * @param serializer Serializer.
+     */
+    void serializeTo(BinaryWriterExImpl writer, PortableBuilderSerializer serializer) {
+        try {
+            writer.preWrite(registeredType ? null : clsNameToWrite);
+
+            Set<Integer> remainsFlds = null;
+
+            if (reader != null) {
+                PortableSchema schema = reader.schema();
+
+                Map<Integer, Object> assignedFldsById;
+
+                if (assignedVals != null) {
+                    assignedFldsById = U.newHashMap(assignedVals.size());
+
+                    for (Map.Entry<String, Object> entry : assignedVals.entrySet()) {
+                        int fieldId = ctx.fieldId(typeId, entry.getKey());
+
+                        assignedFldsById.put(fieldId, entry.getValue());
+                    }
+
+                    remainsFlds = assignedFldsById.keySet();
+                }
+                else
+                    assignedFldsById = Collections.emptyMap();
+
+                // Get footer details.
+                int fieldIdLen = PortableUtils.fieldIdLength(flags);
+                int fieldOffsetLen = PortableUtils.fieldOffsetLength(flags);
+
+                IgniteBiTuple<Integer, Integer> footer = PortableUtils.footerAbsolute(reader, start);
+
+                int footerPos = footer.get1();
+                int footerEnd = footer.get2();
+
+                // Get raw position.
+                int rawPos = PortableUtils.rawOffsetAbsolute(reader, start);
+
+                // Position reader on data.
+                reader.position(start + hdrLen);
+
+                int idx = 0;
+
+                while (reader.position() < rawPos) {
+                    int fieldId = schema.fieldId(idx++);
+                    int fieldLen =
+                        fieldPositionAndLength(footerPos, footerEnd, rawPos, fieldIdLen, fieldOffsetLen).get2();
+
+                    int postPos = reader.position() + fieldLen; // Position where reader will be placed afterwards.
+
+                    footerPos += fieldIdLen + fieldOffsetLen;
+
+                    if (assignedFldsById.containsKey(fieldId)) {
+                        Object assignedVal = assignedFldsById.remove(fieldId);
+
+                        if (assignedVal != REMOVED_FIELD_MARKER) {
+                            writer.writeFieldId(fieldId);
+
+                            serializer.writeValue(writer, assignedVal);
+                        }
+                    }
+                    else {
+                        int type = fieldLen != 0 ? reader.readByte(0) : 0;
+
+                        if (fieldLen != 0 && !PortableUtils.isPlainArrayType(type) && PortableUtils.isPlainType(type)) {
+                            writer.writeFieldId(fieldId);
+
+                            writer.write(reader.array(), reader.position(), fieldLen);
+                        }
+                        else {
+                            writer.writeFieldId(fieldId);
+
+                            Object val;
+
+                            if (fieldLen == 0)
+                                val = null;
+                            else if (readCache == null) {
+                                val = reader.parseValue();
+
+                                assert reader.position() == postPos;
+                            }
+                            else
+                                val = readCache.get(fieldId);
+
+                            serializer.writeValue(writer, val);
+                        }
+                    }
+
+                    reader.position(postPos);
+                }
+            }
+
+            BinaryType meta = ctx.metadata(typeId);
+
+            Map<String, Integer> fieldsMeta = null;
+
+            if (assignedVals != null && (remainsFlds == null || !remainsFlds.isEmpty())) {
+                for (Map.Entry<String, Object> entry : assignedVals.entrySet()) {
+                    Object val = entry.getValue();
+
+                    if (val == REMOVED_FIELD_MARKER)
+                        continue;
+
+                    String name = entry.getKey();
+
+                    int fieldId = ctx.fieldId(typeId, name);
+
+                    if (remainsFlds != null && !remainsFlds.contains(fieldId))
+                        continue;
+
+                    writer.writeFieldId(fieldId);
+
+                    serializer.writeValue(writer, val);
+
+                    String oldFldTypeName = meta == null ? null : meta.fieldTypeName(name);
+
+                    boolean nullObjField = false;
+
+                    int newFldTypeId;
+
+                    if (val instanceof PortableValueWithType) {
+                        newFldTypeId = ((PortableValueWithType)val).typeId();
+
+                        if (newFldTypeId == GridPortableMarshaller.OBJ && ((PortableValueWithType)val).value() == null)
+                            nullObjField = true;
+                    }
+                    else
+                        newFldTypeId = PortableUtils.typeByClass(val.getClass());
+
+                    String newFldTypeName = PortableUtils.fieldTypeName(newFldTypeId);
+
+                    if (oldFldTypeName == null) {
+                        // It's a new field, we have to add it to metadata.
+                        if (fieldsMeta == null)
+                            fieldsMeta = new HashMap<>();
+
+                        fieldsMeta.put(name, PortableUtils.fieldTypeId(newFldTypeName));
+                    }
+                    else if (!nullObjField) {
+                        String objTypeName = PortableUtils.fieldTypeName(GridPortableMarshaller.OBJ);
+
+                        if (!objTypeName.equals(oldFldTypeName) && !oldFldTypeName.equals(newFldTypeName)) {
+                            throw new BinaryObjectException(
+                                "Wrong value has been set [" +
+                                    "typeName=" + (typeName == null ? meta.typeName() : typeName) +
+                                    ", fieldName=" + name +
+                                    ", fieldType=" + oldFldTypeName +
+                                    ", assignedValueType=" + newFldTypeName + ']'
+                            );
+                        }
+                    }
+                }
+            }
+
+            if (reader != null) {
+                // Write raw data if any.
+                int rawOff = PortableUtils.rawOffsetAbsolute(reader, start);
+                int footerStart = PortableUtils.footerStartAbsolute(reader, start);
+
+                if (rawOff < footerStart) {
+                    writer.rawWriter();
+
+                    writer.write(reader.array(), rawOff, footerStart - rawOff);
+                }
+
+                // Shift reader to the end of the object.
+                reader.position(start + PortableUtils.length(reader, start));
+            }
+
+            writer.postWrite(true, registeredType, hashCode);
+
+            // Update metadata if needed.
+            int schemaId = writer.schemaId();
+
+            PortableSchemaRegistry schemaReg = ctx.schemaRegistry(typeId);
+
+            if (schemaReg.schema(schemaId) == null) {
+                String typeName = this.typeName;
+
+                if (typeName == null) {
+                    assert meta != null;
+
+                    typeName = meta.typeName();
+                }
+
+                PortableSchema curSchema = writer.currentSchema();
+
+                ctx.updateMetadata(typeId, new BinaryMetadata(typeId, typeName, fieldsMeta,
+                    ctx.affinityKeyFieldName(typeId), Collections.singleton(curSchema), false));
+
+                schemaReg.addSchema(curSchema.schemaId(), curSchema);
+            }
+        }
+        finally {
+            writer.popSchema();
+        }
+    }
+
+    /** {@inheritDoc} */
+    @Override public BinaryObjectBuilderImpl hashCode(int hashCode) {
+        this.hashCode = hashCode;
+
+        return this;
+    }
+
+    /**
+     * Get field position and length.
+     *
+     * @param footerPos Field position inside the footer (absolute).
+     * @param footerEnd Footer end (absolute).
+     * @param rawPos Raw data position (absolute).
+     * @param fieldIdLen Field ID length.
+     * @param fieldOffsetLen Field offset length.
+     * @return Tuple with field position and length.
+     */
+    private IgniteBiTuple<Integer, Integer> fieldPositionAndLength(int footerPos, int footerEnd, int rawPos,
+        int fieldIdLen, int fieldOffsetLen) {
+        // Get field offset first.
+        int fieldOffset = PortableUtils.fieldOffsetRelative(reader, footerPos + fieldIdLen, fieldOffsetLen);
+        int fieldPos = start + fieldOffset;
+
+        // Get field length.
+        int fieldLen;
+
+        if (footerPos + fieldIdLen + fieldOffsetLen == footerEnd)
+            // This is the last field, compare to raw offset.
+            fieldLen = rawPos - fieldPos;
+        else {
+            // Field is somewhere in the middle, get difference with the next offset.
+            int nextFieldOffset = PortableUtils.fieldOffsetRelative(reader,
+                footerPos + fieldIdLen + fieldOffsetLen + fieldIdLen, fieldOffsetLen);
+
+            fieldLen = nextFieldOffset - fieldOffset;
+        }
+
+        return F.t(fieldPos, fieldLen);
+    }
+
+    /**
+     * Initialize read cache if needed.
+     */
+    private void ensureReadCacheInit() {
+        assert reader != null;
+
+        if (readCache == null) {
+            int fieldIdLen = PortableUtils.fieldIdLength(flags);
+            int fieldOffsetLen = PortableUtils.fieldOffsetLength(flags);
+
+            PortableSchema schema = reader.schema();
+
+            Map<Integer, Object> readCache = new HashMap<>();
+
+            IgniteBiTuple<Integer, Integer> footer = PortableUtils.footerAbsolute(reader, start);
+
+            int footerPos = footer.get1();
+            int footerEnd = footer.get2();
+
+            int rawPos = PortableUtils.rawOffsetAbsolute(reader, start);
+
+            int idx = 0;
+
+            while (footerPos + fieldIdLen < footerEnd) {
+                int fieldId = schema.fieldId(idx++);
+
+                IgniteBiTuple<Integer, Integer> posAndLen =
+                    fieldPositionAndLength(footerPos, footerEnd, rawPos, fieldIdLen, fieldOffsetLen);
+
+                Object val = reader.getValueQuickly(posAndLen.get1(), posAndLen.get2());
+
+                readCache.put(fieldId, val);
+
+                // Shift current footer position.
+                footerPos += fieldIdLen + fieldOffsetLen;
+            }
+
+            this.readCache = readCache;
+        }
+    }
+
+    /** {@inheritDoc} */
+    @SuppressWarnings("unchecked")
+    @Override public <T> T getField(String name) {
+        Object val;
+
+        if (assignedVals != null && assignedVals.containsKey(name)) {
+            val = assignedVals.get(name);
+
+            if (val == REMOVED_FIELD_MARKER)
+                return null;
+        }
+        else {
+            ensureReadCacheInit();
+
+            int fldId = ctx.fieldId(typeId, name);
+
+            val = readCache.get(fldId);
+        }
+
+        return (T)PortableUtils.unwrapLazy(val);
+    }
+
+    /** {@inheritDoc} */
+    @Override public BinaryObjectBuilder setField(String name, Object val0) {
+        Object val = val0 == null ? new PortableValueWithType(PortableUtils.typeByClass(Object.class), null) : val0;
+
+        if (assignedVals == null)
+            assignedVals = new LinkedHashMap<>();
+
+        Object oldVal = assignedVals.put(name, val);
+
+        if (oldVal instanceof PortableValueWithType && val0 != null) {
+            ((PortableValueWithType)oldVal).value(val);
+
+            assignedVals.put(name, oldVal);
+        }
+
+        return this;
+    }
+
+    /** {@inheritDoc} */
+    @Override public <T> BinaryObjectBuilder setField(String name, @Nullable T val, Class<? super T> type) {
+        if (assignedVals == null)
+            assignedVals = new LinkedHashMap<>();
+
+        assignedVals.put(name, new PortableValueWithType(PortableUtils.typeByClass(type), val));
+
+        return this;
+    }
+
+    /** {@inheritDoc} */
+    @Override public BinaryObjectBuilder setField(String name, @Nullable BinaryObjectBuilder builder) {
+        if (builder == null)
+            return setField(name, null, Object.class);
+        else
+            return setField(name, (Object)builder);
+    }
+
+    /**
+     * Removes field from portable object.
+     *
+     * @param name Field name.
+     * @return {@code this} instance for chaining.
+     */
+    @Override public BinaryObjectBuilderImpl removeField(String name) {
+        if (assignedVals == null)
+            assignedVals = new LinkedHashMap<>();
+
+        assignedVals.put(name, REMOVED_FIELD_MARKER);
+
+        return this;
+    }
+
+    /**
+     * Creates builder initialized by specified portable object.
+     *
+     * @param obj Portable object to initialize builder.
+     * @return New builder.
+     */
+    public static BinaryObjectBuilderImpl wrap(BinaryObject obj) {
+        BinaryObjectImpl heapObj;
+
+        if (obj instanceof BinaryObjectOffheapImpl)
+            heapObj = (BinaryObjectImpl)((BinaryObjectOffheapImpl)obj).heapCopy();
+        else
+            heapObj = (BinaryObjectImpl)obj;
+
+        return new BinaryObjectBuilderImpl(heapObj);
+    }
+
+    /**
+     * @return Object start position in source array.
+     */
+    int start() {
+        return start;
+    }
+
+    /**
+     * @return Object type id.
+     */
+    public int typeId() {
+        return typeId;
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/1dbf20e0/modules/core/src/main/java/org/apache/ignite/internal/binary/builder/PortableAbstractLazyValue.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/binary/builder/PortableAbstractLazyValue.java b/modules/core/src/main/java/org/apache/ignite/internal/binary/builder/PortableAbstractLazyValue.java
new file mode 100644
index 0000000..0b6cc0a
--- /dev/null
+++ b/modules/core/src/main/java/org/apache/ignite/internal/binary/builder/PortableAbstractLazyValue.java
@@ -0,0 +1,57 @@
+/*
+ * 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.binary.builder;
+
+/**
+ *
+ */
+abstract class PortableAbstractLazyValue implements PortableLazyValue {
+    /** */
+    protected Object val;
+
+    /** */
+    protected final PortableBuilderReader reader;
+
+    /** */
+    protected final int valOff;
+
+    /**
+     * @param reader Reader.
+     * @param valOff Value.
+     */
+    protected PortableAbstractLazyValue(PortableBuilderReader reader, int valOff) {
+        this.reader = reader;
+        this.valOff = valOff;
+    }
+
+    /**
+     * @return Value.
+     */
+    protected abstract Object init();
+
+    /** {@inheritDoc} */
+    @Override public Object value() {
+        if (val == null) {
+            val = init();
+
+            assert val != null;
+        }
+
+        return val;
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/1dbf20e0/modules/core/src/main/java/org/apache/ignite/internal/binary/builder/PortableBuilderEnum.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/binary/builder/PortableBuilderEnum.java b/modules/core/src/main/java/org/apache/ignite/internal/binary/builder/PortableBuilderEnum.java
new file mode 100644
index 0000000..3bb8194
--- /dev/null
+++ b/modules/core/src/main/java/org/apache/ignite/internal/binary/builder/PortableBuilderEnum.java
@@ -0,0 +1,116 @@
+/*
+ * 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.binary.builder;
+
+import org.apache.ignite.internal.binary.GridPortableMarshaller;
+import org.apache.ignite.internal.binary.BinaryWriterExImpl;
+import org.apache.ignite.internal.util.typedef.internal.U;
+import org.apache.ignite.binary.BinaryInvalidTypeException;
+
+/**
+ *
+ */
+public class PortableBuilderEnum implements PortableBuilderSerializationAware {
+    /** */
+    private final int ordinal;
+
+    /** */
+    private final int typeId;
+
+    /** */
+    private final String clsName;
+
+    /**
+     * @param typeId Type ID.
+     * @param anEnum Enum instance.
+     */
+    public PortableBuilderEnum(int typeId, Enum anEnum) {
+        ordinal = anEnum.ordinal();
+        this.typeId = typeId;
+        clsName = null;
+    }
+
+    /**
+     * @param reader PortableBuilderReader.
+     */
+    public PortableBuilderEnum(PortableBuilderReader reader) {
+        int typeId = reader.readInt();
+
+        if (typeId == GridPortableMarshaller.UNREGISTERED_TYPE_ID) {
+            clsName = reader.readString();
+
+            Class cls;
+
+            try {
+                // TODO: IGNITE-1272 - Is class loader needed here?
+                cls = U.forName(reader.readString(), null);
+            }
+            catch (ClassNotFoundException e) {
+                throw new BinaryInvalidTypeException("Failed to load the class: " + clsName, e);
+            }
+
+            this.typeId = reader.portableContext().descriptorForClass(cls, false).typeId();
+        }
+        else {
+            this.typeId = typeId;
+            this.clsName = null;
+        }
+
+        ordinal = reader.readInt();
+    }
+
+    /**
+     * @return Ordinal.
+     */
+    public int getOrdinal() {
+        return ordinal;
+    }
+
+    /** {@inheritDoc} */
+    @Override public void writeTo(BinaryWriterExImpl writer, PortableBuilderSerializer ctx) {
+        writer.writeByte(GridPortableMarshaller.ENUM);
+
+        if (typeId == GridPortableMarshaller.UNREGISTERED_TYPE_ID) {
+            writer.writeInt(GridPortableMarshaller.UNREGISTERED_TYPE_ID);
+            writer.writeString(clsName);
+        }
+        else
+            writer.writeInt(typeId);
+
+        writer.writeInt(ordinal);
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean equals(Object o) {
+        if (o == null || getClass() != o.getClass())
+            return false;
+
+        PortableBuilderEnum that = (PortableBuilderEnum)o;
+
+        return ordinal == that.ordinal && typeId == that.typeId;
+    }
+
+    /** {@inheritDoc} */
+    @Override public int hashCode() {
+        int result = ordinal;
+
+        result = 31 * result + typeId;
+
+        return result;
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/1dbf20e0/modules/core/src/main/java/org/apache/ignite/internal/binary/builder/PortableBuilderReader.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/binary/builder/PortableBuilderReader.java b/modules/core/src/main/java/org/apache/ignite/internal/binary/builder/PortableBuilderReader.java
new file mode 100644
index 0000000..2b28e3d
--- /dev/null
+++ b/modules/core/src/main/java/org/apache/ignite/internal/binary/builder/PortableBuilderReader.java
@@ -0,0 +1,856 @@
+/*
+ * 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.binary.builder;
+
+import org.apache.ignite.binary.BinaryObjectException;
+import org.apache.ignite.internal.binary.BinaryObjectImpl;
+import org.apache.ignite.internal.binary.BinaryReaderExImpl;
+import org.apache.ignite.internal.binary.BinaryWriterExImpl;
+import org.apache.ignite.internal.binary.GridPortableMarshaller;
+import org.apache.ignite.internal.binary.PortableContext;
+import org.apache.ignite.internal.binary.PortablePositionReadable;
+import org.apache.ignite.internal.binary.PortablePrimitives;
+import org.apache.ignite.internal.binary.PortableSchema;
+import org.apache.ignite.internal.binary.streams.PortableHeapInputStream;
+import org.apache.ignite.internal.binary.BinaryObjectImpl;
+import org.apache.ignite.internal.binary.BinaryReaderExImpl;
+import org.apache.ignite.internal.binary.BinaryWriterExImpl;
+import org.apache.ignite.internal.binary.GridPortableMarshaller;
+import org.apache.ignite.internal.binary.PortableContext;
+import org.apache.ignite.internal.binary.PortablePositionReadable;
+import org.apache.ignite.internal.binary.PortablePrimitives;
+import org.apache.ignite.internal.binary.PortableSchema;
+import org.apache.ignite.internal.binary.PortableUtils;
+import org.apache.ignite.internal.binary.streams.PortableHeapInputStream;
+
+import java.sql.Timestamp;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.Map;
+
+import static java.nio.charset.StandardCharsets.UTF_8;
+import static org.apache.ignite.internal.binary.GridPortableMarshaller.NULL;
+import static org.apache.ignite.internal.binary.GridPortableMarshaller.STRING;
+
+/**
+ *
+ */
+public class PortableBuilderReader implements PortablePositionReadable {
+    /** */
+    private final PortableContext ctx;
+
+    /** */
+    private final byte[] arr;
+
+    /** */
+    private final BinaryReaderExImpl reader;
+
+    /** */
+    private final Map<Integer, BinaryObjectBuilderImpl> objMap;
+
+    /** */
+    private int pos;
+
+    /*
+     * Constructor.
+     *
+     * @param objImpl Portable object
+     */
+    PortableBuilderReader(BinaryObjectImpl objImpl) {
+        ctx = objImpl.context();
+        arr = objImpl.array();
+        pos = objImpl.start();
+
+        // TODO: IGNITE-1272 - Is class loader needed here?
+        reader = new BinaryReaderExImpl(ctx, PortableHeapInputStream.create(arr, pos), null);
+
+        objMap = new HashMap<>();
+    }
+
+    /**
+     * Copying constructor.
+     *
+     * @param other Other reader.
+     * @param start Start position.
+     */
+    PortableBuilderReader(PortableBuilderReader other, int start) {
+        this.ctx = other.ctx;
+        this.arr = other.arr;
+        this.pos = start;
+
+        reader = new BinaryReaderExImpl(ctx, PortableHeapInputStream.create(arr, start), null, other.reader.handles());
+
+        this.objMap = other.objMap;
+    }
+
+    /**
+     * @return Portable context.
+     */
+    public PortableContext portableContext() {
+        return ctx;
+    }
+
+    /**
+     * @param obj Mutable portable object.
+     */
+    public void registerObject(BinaryObjectBuilderImpl obj) {
+        objMap.put(obj.start(), obj);
+    }
+
+    /**
+     * Get schema of the object, starting at the given position.
+     *
+     * @return Object's schema.
+     */
+    public PortableSchema schema() {
+        return reader.getOrCreateSchema();
+    }
+
+    /**
+     * @return Read int value.
+     */
+    public int readInt() {
+        int res = readInt(0);
+
+        pos += 4;
+
+        return res;
+    }
+
+    /**
+     * @return Read int value.
+     */
+    public byte readByte() {
+        return arr[pos++];
+    }
+
+    /**
+     * @return Read boolean value.
+     */
+    public boolean readBoolean() {
+        return readByte() == 1;
+    }
+
+    /**
+     * @return Read int value.
+     */
+    public byte readByte(int off) {
+        return arr[pos + off];
+    }
+
+    /**
+     * @param off Offset related to {@link #pos}
+     * @return Read int value.
+     */
+    public int readInt(int off) {
+        return PortablePrimitives.readInt(arr, pos + off);
+    }
+
+    /**
+     * @param pos Position in the source array.
+     * @return Read byte value.
+     */
+    public byte readBytePositioned(int pos) {
+        return PortablePrimitives.readByte(arr, pos);
+    }
+
+    /** {@inheritDoc} */
+    @Override public short readShortPositioned(int pos) {
+        return PortablePrimitives.readShort(arr, pos);
+    }
+
+    /** {@inheritDoc} */
+    @Override public int readIntPositioned(int pos) {
+        return PortablePrimitives.readInt(arr, pos);
+    }
+
+    /**
+     * @return Read length of array.
+     */
+    public int readLength() {
+        return PortablePrimitives.readInt(arr, pos);
+    }
+
+    /**
+     * Read string length.
+     *
+     * @return String length.
+     */
+    public int readStringLength() {
+        return PortablePrimitives.readInt(arr, pos);
+    }
+
+    /**
+     * Reads string.
+     *
+     * @return String.
+     */
+    public String readString() {
+        byte flag = readByte();
+
+        if (flag == GridPortableMarshaller.NULL)
+            return null;
+
+        if (flag != GridPortableMarshaller.STRING)
+            throw new BinaryObjectException("Failed to deserialize String.");
+
+        int len = readInt();
+
+        String str = new String(arr, pos, len, UTF_8);
+
+        pos += len;
+
+        return str;
+    }
+
+    /**
+     *
+     */
+    public void skipValue() {
+        byte type = arr[pos++];
+
+        int len;
+
+        switch (type) {
+            case GridPortableMarshaller.NULL:
+                return;
+
+            case GridPortableMarshaller.OBJ:
+                pos += readInt(GridPortableMarshaller.TOTAL_LEN_POS - 1) - 1;
+
+                return;
+
+            case GridPortableMarshaller.BOOLEAN:
+            case GridPortableMarshaller.BYTE:
+                len = 1;
+                break;
+
+            case GridPortableMarshaller.CHAR:
+            case GridPortableMarshaller.SHORT:
+                len = 2;
+
+                break;
+
+            case GridPortableMarshaller.HANDLE:
+            case GridPortableMarshaller.FLOAT:
+            case GridPortableMarshaller.INT:
+                len = 4;
+
+                break;
+
+            case GridPortableMarshaller.ENUM:
+                //skipping type id and ordinal value
+                len = 8;
+
+                break;
+
+            case GridPortableMarshaller.LONG:
+            case GridPortableMarshaller.DOUBLE:
+                len = 8;
+
+                break;
+
+            case GridPortableMarshaller.BYTE_ARR:
+            case GridPortableMarshaller.BOOLEAN_ARR:
+                len = 4 + readLength();
+
+                break;
+
+            case GridPortableMarshaller.STRING:
+                len = 4 + readStringLength();
+
+                break;
+
+            case GridPortableMarshaller.DECIMAL:
+                len = /** scale */ 4  + /** mag len */ 4  + /** mag bytes count */ readInt(4);
+
+                break;
+
+            case GridPortableMarshaller.UUID:
+                len = 8 + 8;
+
+                break;
+
+            case GridPortableMarshaller.DATE:
+                len = 8;
+
+                break;
+
+            case GridPortableMarshaller.TIMESTAMP:
+                len = 8 + 4;
+
+                break;
+
+            case GridPortableMarshaller.CHAR_ARR:
+            case GridPortableMarshaller.SHORT_ARR:
+                len = 4 + readLength() * 2;
+
+                break;
+
+            case GridPortableMarshaller.INT_ARR:
+            case GridPortableMarshaller.FLOAT_ARR:
+                len = 4 + readLength() * 4;
+
+                break;
+
+            case GridPortableMarshaller.LONG_ARR:
+            case GridPortableMarshaller.DOUBLE_ARR:
+                len = 4 + readLength() * 8;
+
+                break;
+
+            case GridPortableMarshaller.DECIMAL_ARR:
+            case GridPortableMarshaller.DATE_ARR:
+            case GridPortableMarshaller.TIMESTAMP_ARR:
+            case GridPortableMarshaller.OBJ_ARR:
+            case GridPortableMarshaller.ENUM_ARR:
+            case GridPortableMarshaller.UUID_ARR:
+            case GridPortableMarshaller.STRING_ARR: {
+                int size = readInt();
+
+                for (int i = 0; i < size; i++)
+                    skipValue();
+
+                return;
+            }
+
+            case GridPortableMarshaller.COL: {
+                int size = readInt();
+
+                pos++; // skip collection type
+
+                for (int i = 0; i < size; i++)
+                    skipValue();
+
+                return;
+            }
+
+            case GridPortableMarshaller.MAP: {
+                int size = readInt();
+
+                pos++; // skip collection type
+
+                for (int i = 0; i < size; i++) {
+                    skipValue(); // skip key.
+                    skipValue(); // skip value.
+                }
+
+                return;
+            }
+
+            case GridPortableMarshaller.PORTABLE_OBJ:
+                len = readInt() + 4;
+
+                break;
+
+            default:
+                throw new BinaryObjectException("Invalid flag value: " + type);
+        }
+
+        pos += len;
+    }
+
+    /**
+     * @param pos Position.
+     * @param len Length.
+     * @return Object.
+     */
+    public Object getValueQuickly(int pos, int len) {
+        byte type = arr[pos];
+
+        switch (type) {
+            case GridPortableMarshaller.NULL:
+                return null;
+
+            case GridPortableMarshaller.HANDLE: {
+                int objStart = pos - readIntPositioned(pos + 1);
+
+                BinaryObjectBuilderImpl res = objMap.get(objStart);
+
+                if (res == null) {
+                    res = new BinaryObjectBuilderImpl(new PortableBuilderReader(this, objStart), objStart);
+
+                    objMap.put(objStart, res);
+                }
+
+                return res;
+            }
+
+            case GridPortableMarshaller.OBJ: {
+                BinaryObjectBuilderImpl res = objMap.get(pos);
+
+                if (res == null) {
+                    res = new BinaryObjectBuilderImpl(new PortableBuilderReader(this, pos), pos);
+
+                    objMap.put(pos, res);
+                }
+
+                return res;
+            }
+
+            case GridPortableMarshaller.BYTE:
+                return arr[pos + 1];
+
+            case GridPortableMarshaller.SHORT:
+                return PortablePrimitives.readShort(arr, pos + 1);
+
+            case GridPortableMarshaller.INT:
+                return PortablePrimitives.readInt(arr, pos + 1);
+
+            case GridPortableMarshaller.LONG:
+                return PortablePrimitives.readLong(arr, pos + 1);
+
+            case GridPortableMarshaller.FLOAT:
+                return PortablePrimitives.readFloat(arr, pos + 1);
+
+            case GridPortableMarshaller.DOUBLE:
+                return PortablePrimitives.readDouble(arr, pos + 1);
+
+            case GridPortableMarshaller.CHAR:
+                return PortablePrimitives.readChar(arr, pos + 1);
+
+            case GridPortableMarshaller.BOOLEAN:
+                return arr[pos + 1] != 0;
+
+            case GridPortableMarshaller.DECIMAL:
+            case GridPortableMarshaller.STRING:
+            case GridPortableMarshaller.UUID:
+            case GridPortableMarshaller.DATE:
+            case GridPortableMarshaller.TIMESTAMP:
+                return new PortablePlainLazyValue(this, pos, len);
+
+            case GridPortableMarshaller.BYTE_ARR:
+            case GridPortableMarshaller.SHORT_ARR:
+            case GridPortableMarshaller.INT_ARR:
+            case GridPortableMarshaller.LONG_ARR:
+            case GridPortableMarshaller.FLOAT_ARR:
+            case GridPortableMarshaller.DOUBLE_ARR:
+            case GridPortableMarshaller.CHAR_ARR:
+            case GridPortableMarshaller.BOOLEAN_ARR:
+            case GridPortableMarshaller.DECIMAL_ARR:
+            case GridPortableMarshaller.DATE_ARR:
+            case GridPortableMarshaller.TIMESTAMP_ARR:
+            case GridPortableMarshaller.UUID_ARR:
+            case GridPortableMarshaller.STRING_ARR:
+            case GridPortableMarshaller.ENUM_ARR:
+            case GridPortableMarshaller.OBJ_ARR:
+            case GridPortableMarshaller.COL:
+            case GridPortableMarshaller.MAP:
+                return new LazyCollection(pos);
+
+            case GridPortableMarshaller.ENUM: {
+                if (len == 1) {
+                    assert readByte(pos) == GridPortableMarshaller.NULL;
+
+                    return null;
+                }
+
+                int mark = position();
+                position(pos + 1);
+
+                PortableBuilderEnum builderEnum = new PortableBuilderEnum(this);
+
+                position(mark);
+
+                return builderEnum;
+            }
+
+            case GridPortableMarshaller.PORTABLE_OBJ: {
+                int size = readIntPositioned(pos + 1);
+
+                int start = readIntPositioned(pos + 4 + size);
+
+                BinaryObjectImpl portableObj = new BinaryObjectImpl(ctx, arr, pos + 4 + start);
+
+                return new PortablePlainPortableObject(portableObj);
+            }
+
+            default:
+                throw new BinaryObjectException("Invalid flag value: " + type);
+        }
+    }
+
+    /**
+     * @return Parsed value.
+     */
+    public Object parseValue() {
+        int valPos = pos;
+
+        byte type = arr[pos++];
+
+        int plainLazyValLen;
+
+        boolean modifiableLazyVal = false;
+
+        switch (type) {
+            case GridPortableMarshaller.NULL:
+                return null;
+
+            case GridPortableMarshaller.HANDLE: {
+                int objStart = pos - 1 - readInt();
+
+                BinaryObjectBuilderImpl res = objMap.get(objStart);
+
+                if (res == null) {
+                    res = new BinaryObjectBuilderImpl(new PortableBuilderReader(this, objStart), objStart);
+
+                    objMap.put(objStart, res);
+                }
+
+                return res;
+            }
+
+            case GridPortableMarshaller.OBJ: {
+                pos--;
+
+                BinaryObjectBuilderImpl res = objMap.get(pos);
+
+                if (res == null) {
+                    res = new BinaryObjectBuilderImpl(new PortableBuilderReader(this, pos), pos);
+
+                    objMap.put(pos, res);
+                }
+
+                pos += readInt(GridPortableMarshaller.TOTAL_LEN_POS);
+
+                return res;
+            }
+
+            case GridPortableMarshaller.BYTE:
+                return arr[pos++];
+
+            case GridPortableMarshaller.SHORT: {
+                Object res = PortablePrimitives.readShort(arr, pos);
+                pos += 2;
+                return res;
+            }
+
+            case GridPortableMarshaller.INT:
+                return readInt();
+
+            case GridPortableMarshaller.LONG:
+                plainLazyValLen = 8;
+
+                break;
+
+            case GridPortableMarshaller.FLOAT:
+                plainLazyValLen = 4;
+
+                break;
+
+            case GridPortableMarshaller.DOUBLE:
+                plainLazyValLen = 8;
+
+                break;
+
+            case GridPortableMarshaller.CHAR:
+                plainLazyValLen = 2;
+
+                break;
+
+            case GridPortableMarshaller.BOOLEAN:
+                return arr[pos++] != 0;
+
+            case GridPortableMarshaller.DECIMAL:
+                plainLazyValLen = /** scale */ 4  + /** mag len */ 4  + /** mag bytes count */ readInt(4);
+
+                break;
+
+            case GridPortableMarshaller.STRING:
+                plainLazyValLen = 4 + readStringLength();
+
+                break;
+
+            case GridPortableMarshaller.UUID:
+                plainLazyValLen = 8 + 8;
+
+                break;
+
+            case GridPortableMarshaller.DATE:
+                plainLazyValLen = 8;
+
+                break;
+
+            case GridPortableMarshaller.TIMESTAMP:
+                plainLazyValLen = 8 + 4;
+
+                break;
+
+            case GridPortableMarshaller.BYTE_ARR:
+                plainLazyValLen = 4 + readLength();
+                modifiableLazyVal = true;
+
+                break;
+
+            case GridPortableMarshaller.SHORT_ARR:
+                plainLazyValLen = 4 + readLength() * 2;
+                modifiableLazyVal = true;
+
+                break;
+
+            case GridPortableMarshaller.INT_ARR:
+                plainLazyValLen = 4 + readLength() * 4;
+                modifiableLazyVal = true;
+
+                break;
+
+            case GridPortableMarshaller.LONG_ARR:
+                plainLazyValLen = 4 + readLength() * 8;
+                modifiableLazyVal = true;
+
+                break;
+
+            case GridPortableMarshaller.FLOAT_ARR:
+                plainLazyValLen = 4 + readLength() * 4;
+                modifiableLazyVal = true;
+
+                break;
+
+            case GridPortableMarshaller.DOUBLE_ARR:
+                plainLazyValLen = 4 + readLength() * 8;
+                modifiableLazyVal = true;
+
+                break;
+
+            case GridPortableMarshaller.CHAR_ARR:
+                plainLazyValLen = 4 + readLength() * 2;
+                modifiableLazyVal = true;
+
+                break;
+
+            case GridPortableMarshaller.BOOLEAN_ARR:
+                plainLazyValLen = 4 + readLength();
+                modifiableLazyVal = true;
+
+                break;
+
+            case GridPortableMarshaller.OBJ_ARR:
+                return new PortableObjectArrayLazyValue(this);
+
+            case GridPortableMarshaller.DATE_ARR: {
+                int size = readInt();
+
+                Date[] res = new Date[size];
+
+                for (int i = 0; i < res.length; i++) {
+                    byte flag = arr[pos++];
+
+                    if (flag == GridPortableMarshaller.NULL) continue;
+
+                    if (flag != GridPortableMarshaller.DATE)
+                        throw new BinaryObjectException("Invalid flag value: " + flag);
+
+                    long time = PortablePrimitives.readLong(arr, pos);
+
+                    pos += 8;
+
+                    res[i] = new Date(time);
+                }
+
+                return res;
+            }
+
+            case GridPortableMarshaller.TIMESTAMP_ARR: {
+                int size = readInt();
+
+                Timestamp[] res = new Timestamp[size];
+
+                for (int i = 0; i < res.length; i++) {
+                    byte flag = arr[pos++];
+
+                    if (flag == GridPortableMarshaller.NULL)
+                        continue;
+
+                    if (flag != GridPortableMarshaller.TIMESTAMP)
+                        throw new BinaryObjectException("Invalid flag value: " + flag);
+
+                    long time = PortablePrimitives.readLong(arr, pos);
+
+                    pos += 8;
+
+                    int nano = PortablePrimitives.readInt(arr, pos);
+
+                    pos += 4;
+
+                    Timestamp ts = new Timestamp(time);
+
+                    ts.setNanos(ts.getNanos() + nano);
+
+                    res[i] = ts;
+                }
+
+                return res;
+            }
+
+            case GridPortableMarshaller.UUID_ARR:
+            case GridPortableMarshaller.STRING_ARR:
+            case GridPortableMarshaller.DECIMAL_ARR: {
+                int size = readInt();
+
+                for (int i = 0; i < size; i++) {
+                    byte flag = arr[pos++];
+
+                    if (flag == GridPortableMarshaller.UUID)
+                        pos += 8 + 8;
+                    else if (flag == GridPortableMarshaller.STRING)
+                        pos += 4 + readStringLength();
+                    else if (flag == GridPortableMarshaller.DECIMAL) {
+                        pos += 4; // scale value
+                        pos += 4 + readLength();
+                    }
+                    else
+                        assert flag == GridPortableMarshaller.NULL;
+                }
+
+                return new PortableModifiableLazyValue(this, valPos, pos - valPos);
+            }
+
+            case GridPortableMarshaller.COL: {
+                int size = readInt();
+                byte colType = arr[pos++];
+
+                switch (colType) {
+                    case GridPortableMarshaller.USER_COL:
+                    case GridPortableMarshaller.ARR_LIST:
+                        return new PortableLazyArrayList(this, size);
+
+                    case GridPortableMarshaller.LINKED_LIST:
+                        return new PortableLazyLinkedList(this, size);
+
+                    case GridPortableMarshaller.HASH_SET:
+                    case GridPortableMarshaller.LINKED_HASH_SET:
+                        return new PortableLazySet(this, size);
+                }
+
+                throw new BinaryObjectException("Unknown collection type: " + colType);
+            }
+
+            case GridPortableMarshaller.MAP:
+                return PortableLazyMap.parseMap(this);
+
+            case GridPortableMarshaller.ENUM:
+                return new PortableBuilderEnum(this);
+
+            case GridPortableMarshaller.ENUM_ARR:
+                return new PortableEnumArrayLazyValue(this);
+
+            case GridPortableMarshaller.PORTABLE_OBJ: {
+                int size = readInt();
+
+                pos += size;
+
+                int start = readInt();
+
+                BinaryObjectImpl portableObj = new BinaryObjectImpl(ctx, arr,
+                    pos - 4 - size + start);
+
+                return new PortablePlainPortableObject(portableObj);
+            }
+
+            default:
+                throw new BinaryObjectException("Invalid flag value: " + type);
+        }
+
+        PortableAbstractLazyValue res;
+
+        if (modifiableLazyVal)
+            res = new PortableModifiableLazyValue(this, valPos, 1 + plainLazyValLen);
+        else
+            res = new PortablePlainLazyValue(this, valPos, 1 + plainLazyValLen);
+
+        pos += plainLazyValLen;
+
+        return res;
+    }
+
+    /**
+     * @return Array.
+     */
+    public byte[] array() {
+        return arr;
+    }
+
+    /**
+     * @return Position of reader.
+     */
+    public int position() {
+        return pos;
+    }
+
+    /**
+     * @param pos New pos.
+     */
+    public void position(int pos) {
+        this.pos = pos;
+    }
+
+    /**
+     * @param n Number of bytes to skip.
+     */
+    public void skip(int n) {
+        pos += n;
+    }
+
+    /**
+     * @return Reader.
+     */
+    BinaryReaderExImpl reader() {
+        return reader;
+    }
+
+    /**
+     *
+     */
+    private class LazyCollection implements PortableLazyValue {
+        /** */
+        private final int valOff;
+
+        /** */
+        private Object col;
+
+        /**
+         * @param valOff Value.
+         */
+        protected LazyCollection(int valOff) {
+            this.valOff = valOff;
+        }
+
+        /**
+         * @return Object.
+         */
+        private Object wrappedCollection() {
+            if (col == null) {
+                position(valOff);
+
+                col = parseValue();
+            }
+
+            return col;
+        }
+
+        /** {@inheritDoc} */
+        @Override public void writeTo(BinaryWriterExImpl writer, PortableBuilderSerializer ctx) {
+            ctx.writeValue(writer, wrappedCollection());
+        }
+
+        /** {@inheritDoc} */
+        @Override public Object value() {
+            return PortableUtils.unwrapLazy(wrappedCollection());
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/1dbf20e0/modules/core/src/main/java/org/apache/ignite/internal/binary/builder/PortableBuilderSerializationAware.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/binary/builder/PortableBuilderSerializationAware.java b/modules/core/src/main/java/org/apache/ignite/internal/binary/builder/PortableBuilderSerializationAware.java
new file mode 100644
index 0000000..03d5720
--- /dev/null
+++ b/modules/core/src/main/java/org/apache/ignite/internal/binary/builder/PortableBuilderSerializationAware.java
@@ -0,0 +1,31 @@
+/*
+ * 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.binary.builder;
+
+import org.apache.ignite.internal.binary.BinaryWriterExImpl;
+
+/**
+ *
+ */
+interface PortableBuilderSerializationAware {
+    /**
+     * @param writer Writer.
+     * @param ctx Context.
+     */
+    public void writeTo(BinaryWriterExImpl writer, PortableBuilderSerializer ctx);
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/1dbf20e0/modules/core/src/main/java/org/apache/ignite/internal/binary/builder/PortableBuilderSerializer.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/binary/builder/PortableBuilderSerializer.java b/modules/core/src/main/java/org/apache/ignite/internal/binary/builder/PortableBuilderSerializer.java
new file mode 100644
index 0000000..06c51fb
--- /dev/null
+++ b/modules/core/src/main/java/org/apache/ignite/internal/binary/builder/PortableBuilderSerializer.java
@@ -0,0 +1,217 @@
+/*
+ * 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.binary.builder;
+
+import org.apache.ignite.binary.BinaryObject;
+import org.apache.ignite.internal.binary.BinaryMetadata;
+import org.apache.ignite.internal.binary.BinaryObjectExImpl;
+import org.apache.ignite.internal.binary.BinaryWriterExImpl;
+import org.apache.ignite.internal.binary.GridPortableMarshaller;
+import org.apache.ignite.internal.binary.PortableContext;
+import org.apache.ignite.internal.binary.PortableUtils;
+
+import java.util.Collection;
+import java.util.IdentityHashMap;
+import java.util.Map;
+
+/**
+ *
+ */
+class PortableBuilderSerializer {
+    /** */
+    private final Map<BinaryObjectBuilderImpl, Integer> objToPos = new IdentityHashMap<>();
+
+    /** */
+    private Map<BinaryObject, BinaryObjectBuilderImpl> portableObjToWrapper;
+
+    /**
+     * @param obj Mutable object.
+     * @param posInResArr Object position in the array.
+     */
+    public void registerObjectWriting(BinaryObjectBuilderImpl obj, int posInResArr) {
+        objToPos.put(obj, posInResArr);
+    }
+
+    /**
+     * @param writer Writer.
+     * @param val Value.
+     */
+    public void writeValue(BinaryWriterExImpl writer, Object val) {
+        if (val == null) {
+            writer.writeByte(GridPortableMarshaller.NULL);
+
+            return;
+        }
+
+        if (val instanceof PortableBuilderSerializationAware) {
+            ((PortableBuilderSerializationAware)val).writeTo(writer, this);
+
+            return;
+        }
+
+        if (val instanceof BinaryObjectExImpl) {
+            if (portableObjToWrapper == null)
+                portableObjToWrapper = new IdentityHashMap<>();
+
+            BinaryObjectBuilderImpl wrapper = portableObjToWrapper.get(val);
+
+            if (wrapper == null) {
+                wrapper = BinaryObjectBuilderImpl.wrap((BinaryObject)val);
+
+                portableObjToWrapper.put((BinaryObject)val, wrapper);
+            }
+
+            val = wrapper;
+        }
+
+        if (val instanceof BinaryObjectBuilderImpl) {
+            BinaryObjectBuilderImpl obj = (BinaryObjectBuilderImpl)val;
+
+            Integer posInResArr = objToPos.get(obj);
+
+            if (posInResArr == null) {
+                objToPos.put(obj, writer.out().position());
+
+                obj.serializeTo(writer.newWriter(obj.typeId()), this);
+            }
+            else {
+                int handle = writer.out().position() - posInResArr;
+
+                writer.writeByte(GridPortableMarshaller.HANDLE);
+                writer.writeInt(handle);
+            }
+
+            return;
+        }
+
+        if (val.getClass().isEnum()) {
+            String typeName = PortableContext.typeName(val.getClass().getName());
+            int typeId = writer.context().typeId(typeName);
+
+            BinaryMetadata meta = new BinaryMetadata(typeId, typeName, null, null, null, true);
+            writer.context().updateMetadata(typeId, meta);
+
+            writer.writeByte(GridPortableMarshaller.ENUM);
+            writer.writeInt(typeId);
+            writer.writeInt(((Enum)val).ordinal());
+
+            return;
+        }
+
+        if (val instanceof Collection) {
+            Collection<?> c = (Collection<?>)val;
+
+            writer.writeByte(GridPortableMarshaller.COL);
+            writer.writeInt(c.size());
+
+            byte colType = writer.context().collectionType(c.getClass());
+
+            writer.writeByte(colType);
+
+            for (Object obj : c)
+                writeValue(writer, obj);
+
+            return;
+        }
+
+        if (val instanceof Map) {
+            Map<?, ?> map = (Map<?, ?>)val;
+
+            writer.writeByte(GridPortableMarshaller.MAP);
+            writer.writeInt(map.size());
+
+            writer.writeByte(writer.context().mapType(map.getClass()));
+
+            for (Map.Entry<?, ?> entry : map.entrySet()) {
+                writeValue(writer, entry.getKey());
+                writeValue(writer, entry.getValue());
+            }
+
+            return;
+        }
+
+        Byte flag = PortableUtils.PLAIN_CLASS_TO_FLAG.get(val.getClass());
+
+        if (flag != null) {
+            PortableUtils.writePlainObject(writer, val);
+
+            return;
+        }
+
+        if (val instanceof Object[]) {
+            int compTypeId = writer.context().typeId(((Object[])val).getClass().getComponentType().getName());
+
+            if (val instanceof PortableBuilderEnum[]) {
+                writeArray(writer, GridPortableMarshaller.ENUM_ARR, (Object[])val, compTypeId);
+
+                return;
+            }
+
+            if (((Object[])val).getClass().getComponentType().isEnum()) {
+                Enum[] enumArr = (Enum[])val;
+
+                writer.writeByte(GridPortableMarshaller.ENUM_ARR);
+                writer.writeInt(compTypeId);
+                writer.writeInt(enumArr.length);
+
+                for (Enum anEnum : enumArr)
+                    writeValue(writer, anEnum);
+
+                return;
+            }
+
+            writeArray(writer, GridPortableMarshaller.OBJ_ARR, (Object[])val, compTypeId);
+
+            return;
+        }
+
+        writer.doWriteObject(val);
+    }
+
+    /**
+     * @param writer Writer.
+     * @param elementType Element type.
+     * @param arr The array.
+     * @param compTypeId Component type ID.
+     */
+    public void writeArray(BinaryWriterExImpl writer, byte elementType, Object[] arr, int compTypeId) {
+        writer.writeByte(elementType);
+        writer.writeInt(compTypeId);
+        writer.writeInt(arr.length);
+
+        for (Object obj : arr)
+            writeValue(writer, obj);
+    }
+
+    /**
+     * @param writer Writer.
+     * @param elementType Element type.
+     * @param arr The array.
+     * @param clsName Component class name.
+     */
+    public void writeArray(BinaryWriterExImpl writer, byte elementType, Object[] arr, String clsName) {
+        writer.writeByte(elementType);
+        writer.writeInt(GridPortableMarshaller.UNREGISTERED_TYPE_ID);
+        writer.writeString(clsName);
+        writer.writeInt(arr.length);
+
+        for (Object obj : arr)
+            writeValue(writer, obj);
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/1dbf20e0/modules/core/src/main/java/org/apache/ignite/internal/binary/builder/PortableEnumArrayLazyValue.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/binary/builder/PortableEnumArrayLazyValue.java b/modules/core/src/main/java/org/apache/ignite/internal/binary/builder/PortableEnumArrayLazyValue.java
new file mode 100644
index 0000000..d6848e9
--- /dev/null
+++ b/modules/core/src/main/java/org/apache/ignite/internal/binary/builder/PortableEnumArrayLazyValue.java
@@ -0,0 +1,116 @@
+/*
+ * 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.binary.builder;
+
+import org.apache.ignite.internal.binary.BinaryWriterExImpl;
+import org.apache.ignite.internal.binary.GridPortableMarshaller;
+import org.apache.ignite.internal.binary.GridPortableMarshaller;
+import org.apache.ignite.internal.binary.BinaryWriterExImpl;
+import org.apache.ignite.internal.util.typedef.internal.U;
+import org.apache.ignite.binary.BinaryObjectException;
+import org.apache.ignite.binary.BinaryInvalidTypeException;
+
+/**
+ *
+ */
+class PortableEnumArrayLazyValue extends PortableAbstractLazyValue {
+    /** */
+    private final int len;
+
+    /** */
+    private final int compTypeId;
+
+    /** */
+    private final String clsName;
+
+    /**
+     * @param reader Reader.
+     */
+    protected PortableEnumArrayLazyValue(PortableBuilderReader reader) {
+        super(reader, reader.position() - 1);
+
+        int typeId = reader.readInt();
+
+        if (typeId == GridPortableMarshaller.UNREGISTERED_TYPE_ID) {
+            clsName = reader.readString();
+
+            Class cls;
+
+            try {
+                // TODO: IGNITE-1272 - Is class loader needed here?
+                cls = U.forName(reader.readString(), null);
+            }
+            catch (ClassNotFoundException e) {
+                throw new BinaryInvalidTypeException("Failed to load the class: " + clsName, e);
+            }
+
+            compTypeId = reader.portableContext().descriptorForClass(cls, true).typeId();
+        }
+        else {
+            compTypeId = typeId;
+            clsName = null;
+        }
+
+        int size = reader.readInt();
+
+        for (int i = 0; i < size; i++)
+            reader.skipValue();
+
+        len = reader.position() - valOff;
+    }
+
+    /** {@inheritDoc} */
+    @Override protected Object init() {
+        reader.position(valOff + 1);
+
+        //skipping component type id
+        reader.readInt();
+
+        int size = reader.readInt();
+
+        PortableBuilderEnum[] res = new PortableBuilderEnum[size];
+
+        for (int i = 0; i < size; i++) {
+            byte flag = reader.readByte();
+
+            if (flag == GridPortableMarshaller.NULL)
+                continue;
+
+            if (flag != GridPortableMarshaller.ENUM)
+                throw new BinaryObjectException("Invalid flag value: " + flag);
+
+            res[i] = new PortableBuilderEnum(reader);
+        }
+
+        return res;
+    }
+
+    /** {@inheritDoc} */
+    @Override public void writeTo(BinaryWriterExImpl writer, PortableBuilderSerializer ctx) {
+        if (val != null) {
+            if (clsName != null)
+                ctx.writeArray(writer, GridPortableMarshaller.ENUM_ARR, (Object[])val, clsName);
+            else
+                ctx.writeArray(writer, GridPortableMarshaller.ENUM_ARR, (Object[])val, compTypeId);
+
+            return;
+        }
+
+        writer.write(reader.array(), valOff, len);
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/1dbf20e0/modules/core/src/main/java/org/apache/ignite/internal/binary/builder/PortableLazyArrayList.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/binary/builder/PortableLazyArrayList.java b/modules/core/src/main/java/org/apache/ignite/internal/binary/builder/PortableLazyArrayList.java
new file mode 100644
index 0000000..846ac82
--- /dev/null
+++ b/modules/core/src/main/java/org/apache/ignite/internal/binary/builder/PortableLazyArrayList.java
@@ -0,0 +1,167 @@
+/*
+ * 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.binary.builder;
+
+import java.util.AbstractList;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+import org.apache.ignite.internal.binary.BinaryWriterExImpl;
+import org.apache.ignite.internal.binary.GridPortableMarshaller;
+import org.apache.ignite.internal.binary.PortableUtils;
+
+/**
+ *
+ */
+class PortableLazyArrayList extends AbstractList<Object> implements PortableBuilderSerializationAware {
+    /** */
+    private final PortableBuilderReader reader;
+
+    /** */
+    private final int off;
+
+    /** */
+    private List<Object> delegate;
+
+    /**
+     * @param reader Reader.
+     * @param size Size,
+     */
+    PortableLazyArrayList(PortableBuilderReader reader, int size) {
+        this.reader = reader;
+        off = reader.position() - 1/* flag */ - 4/* size */ - 1/* col type */;
+
+        assert size >= 0;
+
+        for (int i = 0; i < size; i++)
+            reader.skipValue();
+    }
+
+    /**
+     *
+     */
+    private void ensureDelegateInit() {
+        if (delegate == null) {
+            int size = reader.readIntPositioned(off + 1);
+
+            reader.position(off + 1/* flag */ + 4/* size */ + 1/* col type */);
+
+            delegate = new ArrayList<>(size);
+
+            for (int i = 0; i < size; i++)
+                delegate.add(reader.parseValue());
+        }
+    }
+
+    /** {@inheritDoc} */
+    @Override public Object get(int idx) {
+        ensureDelegateInit();
+
+        return PortableUtils.unwrapLazy(delegate.get(idx));
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean add(Object o) {
+        ensureDelegateInit();
+
+        return delegate.add(o);
+    }
+
+    /** {@inheritDoc} */
+    @Override public void add(int idx, Object element) {
+        ensureDelegateInit();
+
+        delegate.add(idx, element);
+    }
+
+    /** {@inheritDoc} */
+    @Override public Object set(int idx, Object element) {
+        ensureDelegateInit();
+
+        return PortableUtils.unwrapLazy(delegate.set(idx, element));
+    }
+
+    /** {@inheritDoc} */
+    @Override public Object remove(int idx) {
+        ensureDelegateInit();
+
+        return PortableUtils.unwrapLazy(delegate.remove(idx));
+    }
+
+    /** {@inheritDoc} */
+    @Override public void clear() {
+        if (delegate == null)
+            delegate = new ArrayList<>();
+        else
+            delegate.clear();
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean addAll(int idx, Collection<?> c) {
+        return delegate.addAll(idx, c);
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void removeRange(int fromIdx, int toIdx) {
+        ensureDelegateInit();
+
+        delegate.subList(fromIdx, toIdx).clear();
+    }
+
+    /** {@inheritDoc} */
+    @Override public int size() {
+        if (delegate == null)
+            return reader.readIntPositioned(off + 1);
+
+        return delegate.size();
+    }
+
+    /** {@inheritDoc} */
+    @Override public void writeTo(BinaryWriterExImpl writer, PortableBuilderSerializer ctx) {
+        if (delegate == null) {
+            int size = reader.readIntPositioned(off + 1);
+
+            int hdrSize = 1 /* flag */ + 4 /* size */ + 1 /* col type */;
+
+            writer.write(reader.array(), off, hdrSize);
+
+            reader.position(off + hdrSize);
+
+            for (int i = 0; i < size; i++) {
+                Object o = reader.parseValue();
+
+                ctx.writeValue(writer, o);
+            }
+        }
+        else {
+            writer.writeByte(GridPortableMarshaller.COL);
+            writer.writeInt(delegate.size());
+
+            byte colType = reader.array()[off + 1 /* flag */ + 4 /* size */];
+            writer.writeByte(colType);
+
+            int oldPos = reader.position();
+
+            for (Object o : delegate)
+                ctx.writeValue(writer, o);
+
+            // PortableBuilderImpl might have been written. It could override reader's position.
+            reader.position(oldPos);
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/1dbf20e0/modules/core/src/main/java/org/apache/ignite/internal/binary/builder/PortableLazyLinkedList.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/binary/builder/PortableLazyLinkedList.java b/modules/core/src/main/java/org/apache/ignite/internal/binary/builder/PortableLazyLinkedList.java
new file mode 100644
index 0000000..11ed765
--- /dev/null
+++ b/modules/core/src/main/java/org/apache/ignite/internal/binary/builder/PortableLazyLinkedList.java
@@ -0,0 +1,218 @@
+/*
+ * 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.binary.builder;
+
+import java.util.AbstractList;
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.ListIterator;
+import org.apache.ignite.internal.binary.BinaryWriterExImpl;
+import org.apache.ignite.internal.binary.GridPortableMarshaller;
+import org.apache.ignite.internal.binary.PortableUtils;
+
+/**
+ *
+ */
+class PortableLazyLinkedList extends AbstractList<Object> implements PortableBuilderSerializationAware {
+    /** */
+    private final PortableBuilderReader reader;
+
+    /** */
+    private final int off;
+
+    /** */
+    private List<Object> delegate;
+
+    /**
+     * @param reader Reader.
+     * @param size Size,
+     */
+    PortableLazyLinkedList(PortableBuilderReader reader, int size) {
+        this.reader = reader;
+        off = reader.position() - 1/* flag */ - 4/* size */ - 1/* col type */;
+
+        assert size >= 0;
+
+        for (int i = 0; i < size; i++)
+            reader.skipValue();
+    }
+
+    /**
+     *
+     */
+    private void ensureDelegateInit() {
+        if (delegate == null) {
+            int size = reader.readIntPositioned(off + 1);
+
+            reader.position(off + 1/* flag */ + 4/* size */ + 1/* col type */);
+
+            delegate = new LinkedList<>();
+
+            for (int i = 0; i < size; i++)
+                delegate.add(reader.parseValue());
+        }
+    }
+
+    /** {@inheritDoc} */
+    @Override public Object get(int idx) {
+        ensureDelegateInit();
+
+        return PortableUtils.unwrapLazy(delegate.get(idx));
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean add(Object o) {
+        ensureDelegateInit();
+
+        return delegate.add(o);
+    }
+
+    /** {@inheritDoc} */
+    @Override public void add(int idx, Object element) {
+        ensureDelegateInit();
+
+        delegate.add(idx, element);
+    }
+
+    /** {@inheritDoc} */
+    @Override public Object set(int idx, Object element) {
+        ensureDelegateInit();
+
+        return PortableUtils.unwrapLazy(delegate.set(idx, element));
+    }
+
+    /** {@inheritDoc} */
+    @Override public Object remove(int idx) {
+        ensureDelegateInit();
+
+        return PortableUtils.unwrapLazy(delegate.remove(idx));
+    }
+
+    /** {@inheritDoc} */
+    @Override public void clear() {
+        if (delegate == null)
+            delegate = new LinkedList<>();
+        else
+            delegate.clear();
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean addAll(int idx, Collection<?> c) {
+        ensureDelegateInit();
+
+        return delegate.addAll(idx, c);
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void removeRange(int fromIdx, int toIdx) {
+        ensureDelegateInit();
+
+        delegate.subList(fromIdx, toIdx).clear();
+    }
+
+    /** {@inheritDoc} */
+    @Override public int size() {
+        if (delegate == null)
+            return reader.readIntPositioned(off + 1);
+
+        return delegate.size();
+    }
+
+    /** {@inheritDoc} */
+    @Override public ListIterator<Object> listIterator(final int idx) {
+        ensureDelegateInit();
+
+        return new ListIterator<Object>() {
+            /** */
+            private final ListIterator<Object> delegate = PortableLazyLinkedList.super.listIterator(idx);
+
+            @Override public boolean hasNext() {
+                return delegate.hasNext();
+            }
+
+            @Override public Object next() {
+                return PortableUtils.unwrapLazy(delegate.next());
+            }
+
+            @Override public boolean hasPrevious() {
+                return delegate.hasPrevious();
+            }
+
+            @Override public Object previous() {
+                return PortableUtils.unwrapLazy(delegate.previous());
+            }
+
+            @Override public int nextIndex() {
+                return delegate.nextIndex();
+            }
+
+            @Override public int previousIndex() {
+                return delegate.previousIndex();
+            }
+
+            @Override public void remove() {
+                delegate.remove();
+            }
+
+            @Override public void set(Object o) {
+                delegate.set(o);
+            }
+
+            @Override public void add(Object o) {
+                delegate.add(o);
+            }
+        };
+    }
+
+    /** {@inheritDoc} */
+    @Override public Iterator<Object> iterator() {
+        ensureDelegateInit();
+
+        return PortableUtils.unwrapLazyIterator(super.iterator());
+    }
+
+    /** {@inheritDoc} */
+    @Override public void writeTo(BinaryWriterExImpl writer, PortableBuilderSerializer ctx) {
+        if (delegate == null) {
+            int size = reader.readIntPositioned(off + 1);
+
+            int hdrSize = 1 /* flag */ + 4 /* size */ + 1 /* col type */;
+            writer.write(reader.array(), off, hdrSize);
+
+            reader.position(off + hdrSize);
+
+            for (int i = 0; i < size; i++) {
+                Object o = reader.parseValue();
+
+                ctx.writeValue(writer, o);
+            }
+        }
+        else {
+            writer.writeByte(GridPortableMarshaller.COL);
+            writer.writeInt(delegate.size());
+
+            byte colType = reader.array()[off + 1 /* flag */ + 4 /* size */];
+            writer.writeByte(colType);
+
+            for (Object o : delegate)
+                ctx.writeValue(writer, o);
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/1dbf20e0/modules/core/src/main/java/org/apache/ignite/internal/binary/builder/PortableLazyMap.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/binary/builder/PortableLazyMap.java b/modules/core/src/main/java/org/apache/ignite/internal/binary/builder/PortableLazyMap.java
new file mode 100644
index 0000000..4bc7622
--- /dev/null
+++ b/modules/core/src/main/java/org/apache/ignite/internal/binary/builder/PortableLazyMap.java
@@ -0,0 +1,221 @@
+/*
+ * 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.binary.builder;
+
+import java.util.AbstractMap;
+import java.util.AbstractSet;
+import java.util.Iterator;
+import java.util.LinkedHashMap;
+import java.util.Map;
+import java.util.Set;
+import org.apache.ignite.internal.binary.BinaryWriterExImpl;
+import org.apache.ignite.internal.binary.GridPortableMarshaller;
+import org.apache.ignite.internal.binary.PortableUtils;
+import org.jetbrains.annotations.Nullable;
+
+/**
+ *
+ */
+class PortableLazyMap extends AbstractMap<Object, Object> implements PortableBuilderSerializationAware {
+    /** */
+    private final PortableBuilderReader reader;
+
+    /** */
+    private final int off;
+
+    /** */
+    private Map<Object, Object> delegate;
+
+    /**
+     * @param reader Reader.
+     * @param off Offset.
+     */
+    private PortableLazyMap(PortableBuilderReader reader, int off) {
+        this.reader = reader;
+        this.off = off;
+    }
+
+    /**
+     * @param reader Reader.
+     * @return PortableLazyMap.
+     */
+    @Nullable public static PortableLazyMap parseMap(PortableBuilderReader reader) {
+        int off = reader.position() - 1;
+
+        int size = reader.readInt();
+
+        reader.skip(1); // map type.
+
+        for (int i = 0; i < size; i++) {
+            reader.skipValue(); // skip key
+            reader.skipValue(); // skip value
+        }
+
+        return new PortableLazyMap(reader, off);
+    }
+
+    /**
+     *
+     */
+    private void ensureDelegateInit() {
+        if (delegate == null) {
+            int size = reader.readIntPositioned(off + 1);
+
+            reader.position(off + 1/* flag */ + 4/* size */ + 1/* col type */);
+
+            delegate = new LinkedHashMap<>();
+
+            for (int i = 0; i < size; i++)
+                delegate.put(PortableUtils.unwrapLazy(reader.parseValue()), reader.parseValue());
+        }
+    }
+
+    /** {@inheritDoc} */
+    @Override public void writeTo(BinaryWriterExImpl writer, PortableBuilderSerializer ctx) {
+        if (delegate == null) {
+            int size = reader.readIntPositioned(off + 1);
+
+            int hdrSize = 1 /* flag */ + 4 /* size */ + 1 /* col type */;
+            writer.write(reader.array(), off, hdrSize);
+
+            reader.position(off + hdrSize);
+
+            for (int i = 0; i < size; i++) {
+                ctx.writeValue(writer, reader.parseValue()); // key
+                ctx.writeValue(writer, reader.parseValue()); // value
+            }
+        }
+        else {
+            writer.writeByte(GridPortableMarshaller.MAP);
+            writer.writeInt(delegate.size());
+
+            byte colType = reader.array()[off + 1 /* flag */ + 4 /* size */];
+
+            writer.writeByte(colType);
+
+            for (Entry<Object, Object> entry : delegate.entrySet()) {
+                ctx.writeValue(writer, entry.getKey());
+                ctx.writeValue(writer, entry.getValue());
+            }
+        }
+    }
+
+    /** {@inheritDoc} */
+    @Override public int size() {
+        if (delegate == null)
+            return reader.readIntPositioned(off + 1);
+
+        return delegate.size();
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean containsKey(Object key) {
+        ensureDelegateInit();
+
+        return delegate.containsKey(key);
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean containsValue(Object val) {
+        return values().contains(val);
+    }
+
+    /** {@inheritDoc} */
+    @Override public Set<Object> keySet() {
+        ensureDelegateInit();
+
+        return delegate.keySet();
+    }
+
+    /** {@inheritDoc} */
+    @Override public void clear() {
+        if (delegate == null)
+            delegate = new LinkedHashMap<>();
+        else
+            delegate.clear();
+    }
+
+    /** {@inheritDoc} */
+    @Override public Object get(Object key) {
+        ensureDelegateInit();
+
+        return PortableUtils.unwrapLazy(delegate.get(key));
+    }
+
+    /** {@inheritDoc} */
+    @Override public Object put(Object key, Object val) {
+        ensureDelegateInit();
+
+        return PortableUtils.unwrapLazy(delegate.put(key, val));
+    }
+
+    /** {@inheritDoc} */
+    @Override public Object remove(Object key) {
+        ensureDelegateInit();
+
+        return PortableUtils.unwrapLazy(delegate.remove(key));
+    }
+
+    /** {@inheritDoc} */
+    @Override public Set<Entry<Object, Object>> entrySet() {
+        ensureDelegateInit();
+
+        return new AbstractSet<Entry<Object, Object>>() {
+            @Override public boolean contains(Object o) {
+                throw new UnsupportedOperationException();
+            }
+
+            @Override public Iterator<Entry<Object, Object>> iterator() {
+                return new Iterator<Entry<Object, Object>>() {
+                    /** */
+                    private final Iterator<Entry<Object, Object>> itr = delegate.entrySet().iterator();
+
+                    @Override public boolean hasNext() {
+                        return itr.hasNext();
+                    }
+
+                    @Override public Entry<Object, Object> next() {
+                        Entry<Object, Object> res = itr.next();
+
+                        final Object val = res.getValue();
+
+                        if (val instanceof PortableLazyValue) {
+                            return new SimpleEntry<Object, Object>(res.getKey(), val) {
+                                private static final long serialVersionUID = 0L;
+
+                                @Override public Object getValue() {
+                                    return ((PortableLazyValue)val).value();
+                                }
+                            };
+                        }
+
+                        return res;
+                    }
+
+                    @Override public void remove() {
+                        itr.remove();
+                    }
+                };
+            }
+
+            @Override public int size() {
+                return delegate.size();
+            }
+        };
+    }
+}


[19/59] [abbrv] ignite git commit: ignite-2065: rename "portable" packages to "binary"

Posted by ak...@apache.org.
http://git-wip-us.apache.org/repos/asf/ignite/blob/1dbf20e0/modules/core/src/main/java/org/apache/ignite/internal/portable/PortableClassDescriptor.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/portable/PortableClassDescriptor.java b/modules/core/src/main/java/org/apache/ignite/internal/portable/PortableClassDescriptor.java
deleted file mode 100644
index 9a65da1..0000000
--- a/modules/core/src/main/java/org/apache/ignite/internal/portable/PortableClassDescriptor.java
+++ /dev/null
@@ -1,813 +0,0 @@
-/*
- * 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.portable;
-
-import java.io.Externalizable;
-import java.io.IOException;
-import java.io.ObjectInputStream;
-import java.io.ObjectOutputStream;
-import java.lang.reflect.Constructor;
-import java.lang.reflect.Field;
-import java.lang.reflect.InvocationTargetException;
-import java.lang.reflect.Method;
-import java.lang.reflect.Modifier;
-import java.math.BigDecimal;
-import java.sql.Timestamp;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.Date;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Map;
-import java.util.UUID;
-import org.apache.ignite.IgniteCheckedException;
-import org.apache.ignite.binary.BinaryIdMapper;
-import org.apache.ignite.binary.BinaryObjectException;
-import org.apache.ignite.binary.BinarySerializer;
-import org.apache.ignite.binary.Binarylizable;
-import org.apache.ignite.internal.processors.cache.CacheObjectImpl;
-import org.apache.ignite.internal.util.GridUnsafe;
-import org.apache.ignite.internal.util.typedef.internal.U;
-import org.apache.ignite.marshaller.MarshallerExclusions;
-import org.apache.ignite.marshaller.optimized.OptimizedMarshaller;
-import org.jetbrains.annotations.Nullable;
-import sun.misc.Unsafe;
-
-import static java.lang.reflect.Modifier.isStatic;
-import static java.lang.reflect.Modifier.isTransient;
-
-/**
- * Portable class descriptor.
- */
-public class PortableClassDescriptor {
-    /** */
-    public static final Unsafe UNSAFE = GridUnsafe.unsafe();
-
-    /** */
-    private final PortableContext ctx;
-
-    /** */
-    private final Class<?> cls;
-
-    /** */
-    private final BinarySerializer serializer;
-
-    /** ID mapper. */
-    private final BinaryIdMapper idMapper;
-
-    /** */
-    private final BinaryWriteMode mode;
-
-    /** */
-    private final boolean userType;
-
-    /** */
-    private final int typeId;
-
-    /** */
-    private final String typeName;
-
-    /** Affinity key field name. */
-    private final String affKeyFieldName;
-
-    /** */
-    private final Constructor<?> ctor;
-
-    /** */
-    private final BinaryFieldAccessor[] fields;
-
-    /** */
-    private final Method writeReplaceMtd;
-
-    /** */
-    private final Method readResolveMtd;
-
-    /** */
-    private final Map<String, Integer> stableFieldsMeta;
-
-    /** Object schemas. Initialized only for serializable classes and contains only 1 entry. */
-    private final PortableSchema stableSchema;
-
-    /** Schema registry. */
-    private final PortableSchemaRegistry schemaReg;
-
-    /** */
-    private final boolean registered;
-
-    /** */
-    private final boolean useOptMarshaller;
-
-    /** */
-    private final boolean excluded;
-
-    /**
-     * @param ctx Context.
-     * @param cls Class.
-     * @param userType User type flag.
-     * @param typeId Type ID.
-     * @param typeName Type name.
-     * @param affKeyFieldName Affinity key field name.
-     * @param idMapper ID mapper.
-     * @param serializer Serializer.
-     * @param metaDataEnabled Metadata enabled flag.
-     * @param registered Whether typeId has been successfully registered by MarshallerContext or not.
-     * @param predefined Whether the class is predefined or not.
-     * @throws BinaryObjectException In case of error.
-     */
-    PortableClassDescriptor(
-        PortableContext ctx,
-        Class<?> cls,
-        boolean userType,
-        int typeId,
-        String typeName,
-        @Nullable String affKeyFieldName,
-        @Nullable BinaryIdMapper idMapper,
-        @Nullable BinarySerializer serializer,
-        boolean metaDataEnabled,
-        boolean registered,
-        boolean predefined
-    ) throws BinaryObjectException {
-        assert ctx != null;
-        assert cls != null;
-        assert idMapper != null;
-
-        this.ctx = ctx;
-        this.cls = cls;
-        this.typeId = typeId;
-        this.userType = userType;
-        this.typeName = typeName;
-        this.affKeyFieldName = affKeyFieldName;
-        this.serializer = serializer;
-        this.idMapper = idMapper;
-        this.registered = registered;
-
-        schemaReg = ctx.schemaRegistry(typeId);
-
-        excluded = MarshallerExclusions.isExcluded(cls);
-
-        useOptMarshaller = !predefined && initUseOptimizedMarshallerFlag();
-
-        if (excluded)
-            mode = BinaryWriteMode.EXCLUSION;
-        else {
-            if (cls == BinaryEnumObjectImpl.class)
-                mode = BinaryWriteMode.PORTABLE_ENUM;
-            else
-                mode = serializer != null ? BinaryWriteMode.PORTABLE : PortableUtils.mode(cls);
-        }
-
-        switch (mode) {
-            case P_BYTE:
-            case P_BOOLEAN:
-            case P_SHORT:
-            case P_CHAR:
-            case P_INT:
-            case P_LONG:
-            case P_FLOAT:
-            case P_DOUBLE:
-            case BYTE:
-            case SHORT:
-            case INT:
-            case LONG:
-            case FLOAT:
-            case DOUBLE:
-            case CHAR:
-            case BOOLEAN:
-            case DECIMAL:
-            case STRING:
-            case UUID:
-            case DATE:
-            case TIMESTAMP:
-            case BYTE_ARR:
-            case SHORT_ARR:
-            case INT_ARR:
-            case LONG_ARR:
-            case FLOAT_ARR:
-            case DOUBLE_ARR:
-            case CHAR_ARR:
-            case BOOLEAN_ARR:
-            case DECIMAL_ARR:
-            case STRING_ARR:
-            case UUID_ARR:
-            case DATE_ARR:
-            case TIMESTAMP_ARR:
-            case OBJECT_ARR:
-            case COL:
-            case MAP:
-            case PORTABLE_OBJ:
-            case ENUM:
-            case PORTABLE_ENUM:
-            case ENUM_ARR:
-            case CLASS:
-            case EXCLUSION:
-                ctor = null;
-                fields = null;
-                stableFieldsMeta = null;
-                stableSchema = null;
-
-                break;
-
-            case PORTABLE:
-            case EXTERNALIZABLE:
-                ctor = constructor(cls);
-                fields = null;
-                stableFieldsMeta = null;
-                stableSchema = null;
-
-                break;
-
-            case OBJECT:
-                // Must not use constructor to honor transient fields semantics.
-                ctor = null;
-                ArrayList<BinaryFieldAccessor> fields0 = new ArrayList<>();
-                stableFieldsMeta = metaDataEnabled ? new HashMap<String, Integer>() : null;
-
-                PortableSchema.Builder schemaBuilder = PortableSchema.Builder.newBuilder();
-
-                Collection<String> names = new HashSet<>();
-                Collection<Integer> ids = new HashSet<>();
-
-                for (Class<?> c = cls; c != null && !c.equals(Object.class); c = c.getSuperclass()) {
-                    for (Field f : c.getDeclaredFields()) {
-                        int mod = f.getModifiers();
-
-                        if (!isStatic(mod) && !isTransient(mod)) {
-                            f.setAccessible(true);
-
-                            String name = f.getName();
-
-                            if (!names.add(name))
-                                throw new BinaryObjectException("Duplicate field name [fieldName=" + name +
-                                    ", cls=" + cls.getName() + ']');
-
-                            int fieldId = idMapper.fieldId(typeId, name);
-
-                            if (!ids.add(fieldId))
-                                throw new BinaryObjectException("Duplicate field ID: " + name);
-
-                            BinaryFieldAccessor fieldInfo = BinaryFieldAccessor.create(f, fieldId);
-
-                            fields0.add(fieldInfo);
-
-                            schemaBuilder.addField(fieldId);
-
-                            if (metaDataEnabled)
-                                stableFieldsMeta.put(name, fieldInfo.mode().typeId());
-                        }
-                    }
-                }
-
-                fields = fields0.toArray(new BinaryFieldAccessor[fields0.size()]);
-
-                stableSchema = schemaBuilder.build();
-
-                break;
-
-            default:
-                // Should never happen.
-                throw new BinaryObjectException("Invalid mode: " + mode);
-        }
-
-        if (mode == BinaryWriteMode.PORTABLE || mode == BinaryWriteMode.EXTERNALIZABLE ||
-            mode == BinaryWriteMode.OBJECT) {
-            readResolveMtd = U.findNonPublicMethod(cls, "readResolve");
-            writeReplaceMtd = U.findNonPublicMethod(cls, "writeReplace");
-        }
-        else {
-            readResolveMtd = null;
-            writeReplaceMtd = null;
-        }
-    }
-
-    /**
-     * @return {@code True} if enum.
-     */
-    boolean isEnum() {
-        return mode == BinaryWriteMode.ENUM;
-    }
-
-    /**
-     * @return Described class.
-     */
-    Class<?> describedClass() {
-        return cls;
-    }
-
-    /**
-     * @return Type ID.
-     */
-    public int typeId() {
-        return typeId;
-    }
-
-    /**
-     * @return User type flag.
-     */
-    public boolean userType() {
-        return userType;
-    }
-
-    /**
-     * @return Fields meta data.
-     */
-    Map<String, Integer> fieldsMeta() {
-        return stableFieldsMeta;
-    }
-
-    /**
-     * @return Schema.
-     */
-    PortableSchema schema() {
-        return stableSchema;
-    }
-
-    /**
-     * @return Whether typeId has been successfully registered by MarshallerContext or not.
-     */
-    public boolean registered() {
-        return registered;
-    }
-
-    /**
-     * @return {@code true} if {@link OptimizedMarshaller} must be used instead of {@link BinaryMarshaller}
-     * for object serialization and deserialization.
-     */
-    public boolean useOptimizedMarshaller() {
-        return useOptMarshaller;
-    }
-
-    /**
-     * Checks whether the class values are explicitly excluded from marshalling.
-     *
-     * @return {@code true} if excluded, {@code false} otherwise.
-     */
-    public boolean excluded() {
-        return excluded;
-    }
-
-    /**
-     * @return portableWriteReplace() method
-     */
-    @Nullable Method getWriteReplaceMethod() {
-        return writeReplaceMtd;
-    }
-
-    /**
-     * @return portableReadResolve() method
-     */
-    @SuppressWarnings("UnusedDeclaration")
-    @Nullable Method getReadResolveMethod() {
-        return readResolveMtd;
-    }
-
-    /**
-     * @param obj Object.
-     * @param writer Writer.
-     * @throws BinaryObjectException In case of error.
-     */
-    void write(Object obj, BinaryWriterExImpl writer) throws BinaryObjectException {
-        assert obj != null;
-        assert writer != null;
-
-        writer.typeId(typeId);
-
-        switch (mode) {
-            case P_BYTE:
-            case BYTE:
-                writer.writeByteFieldPrimitive((byte) obj);
-
-                break;
-
-            case P_SHORT:
-            case SHORT:
-                writer.writeShortFieldPrimitive((short)obj);
-
-                break;
-
-            case P_INT:
-            case INT:
-                writer.writeIntFieldPrimitive((int) obj);
-
-                break;
-
-            case P_LONG:
-            case LONG:
-                writer.writeLongFieldPrimitive((long) obj);
-
-                break;
-
-            case P_FLOAT:
-            case FLOAT:
-                writer.writeFloatFieldPrimitive((float) obj);
-
-                break;
-
-            case P_DOUBLE:
-            case DOUBLE:
-                writer.writeDoubleFieldPrimitive((double) obj);
-
-                break;
-
-            case P_CHAR:
-            case CHAR:
-                writer.writeCharFieldPrimitive((char) obj);
-
-                break;
-
-            case P_BOOLEAN:
-            case BOOLEAN:
-                writer.writeBooleanFieldPrimitive((boolean) obj);
-
-                break;
-
-            case DECIMAL:
-                writer.doWriteDecimal((BigDecimal)obj);
-
-                break;
-
-            case STRING:
-                writer.doWriteString((String)obj);
-
-                break;
-
-            case UUID:
-                writer.doWriteUuid((UUID)obj);
-
-                break;
-
-            case DATE:
-                writer.doWriteDate((Date)obj);
-
-                break;
-
-            case TIMESTAMP:
-                writer.doWriteTimestamp((Timestamp)obj);
-
-                break;
-
-            case BYTE_ARR:
-                writer.doWriteByteArray((byte[])obj);
-
-                break;
-
-            case SHORT_ARR:
-                writer.doWriteShortArray((short[]) obj);
-
-                break;
-
-            case INT_ARR:
-                writer.doWriteIntArray((int[]) obj);
-
-                break;
-
-            case LONG_ARR:
-                writer.doWriteLongArray((long[]) obj);
-
-                break;
-
-            case FLOAT_ARR:
-                writer.doWriteFloatArray((float[]) obj);
-
-                break;
-
-            case DOUBLE_ARR:
-                writer.doWriteDoubleArray((double[]) obj);
-
-                break;
-
-            case CHAR_ARR:
-                writer.doWriteCharArray((char[]) obj);
-
-                break;
-
-            case BOOLEAN_ARR:
-                writer.doWriteBooleanArray((boolean[]) obj);
-
-                break;
-
-            case DECIMAL_ARR:
-                writer.doWriteDecimalArray((BigDecimal[]) obj);
-
-                break;
-
-            case STRING_ARR:
-                writer.doWriteStringArray((String[]) obj);
-
-                break;
-
-            case UUID_ARR:
-                writer.doWriteUuidArray((UUID[]) obj);
-
-                break;
-
-            case DATE_ARR:
-                writer.doWriteDateArray((Date[]) obj);
-
-                break;
-
-            case TIMESTAMP_ARR:
-                writer.doWriteTimestampArray((Timestamp[]) obj);
-
-                break;
-
-            case OBJECT_ARR:
-                writer.doWriteObjectArray((Object[])obj);
-
-                break;
-
-            case COL:
-                writer.doWriteCollection((Collection<?>)obj);
-
-                break;
-
-            case MAP:
-                writer.doWriteMap((Map<?, ?>)obj);
-
-                break;
-
-            case ENUM:
-                writer.doWriteEnum((Enum<?>)obj);
-
-                break;
-
-            case PORTABLE_ENUM:
-                writer.doWritePortableEnum((BinaryEnumObjectImpl)obj);
-
-                break;
-
-            case ENUM_ARR:
-                writer.doWriteEnumArray((Object[])obj);
-
-                break;
-
-            case CLASS:
-                writer.doWriteClass((Class)obj);
-
-                break;
-
-            case PORTABLE_OBJ:
-                writer.doWritePortableObject((BinaryObjectImpl)obj);
-
-                break;
-
-            case PORTABLE:
-                if (preWrite(writer, obj)) {
-                    try {
-                        if (serializer != null)
-                            serializer.writeBinary(obj, writer);
-                        else
-                            ((Binarylizable)obj).writeBinary(writer);
-
-                        postWrite(writer, obj);
-
-                        // Check whether we need to update metadata.
-                        if (obj.getClass() != BinaryMetadata.class) {
-                            int schemaId = writer.schemaId();
-
-                            if (schemaReg.schema(schemaId) == null) {
-                                // This is new schema, let's update metadata.
-                                BinaryMetadataCollector collector =
-                                    new BinaryMetadataCollector(typeId, typeName, idMapper);
-
-                                if (serializer != null)
-                                    serializer.writeBinary(obj, collector);
-                                else
-                                    ((Binarylizable)obj).writeBinary(collector);
-
-                                PortableSchema newSchema = collector.schema();
-
-                                BinaryMetadata meta = new BinaryMetadata(typeId, typeName, collector.meta(),
-                                    affKeyFieldName, Collections.singleton(newSchema), false);
-
-                                ctx.updateMetadata(typeId, meta);
-
-                                schemaReg.addSchema(newSchema.schemaId(), newSchema);
-                            }
-                        }
-                    }
-                    finally {
-                        writer.popSchema();
-                    }
-                }
-
-                break;
-
-            case EXTERNALIZABLE:
-                if (preWrite(writer, obj)) {
-                    writer.rawWriter();
-
-                    try {
-                        ((Externalizable)obj).writeExternal(writer);
-
-                        postWrite(writer, obj);
-                    }
-                    catch (IOException e) {
-                        throw new BinaryObjectException("Failed to write Externalizable object: " + obj, e);
-                    }
-                    finally {
-                        writer.popSchema();
-                    }
-                }
-
-                break;
-
-            case OBJECT:
-                if (preWrite(writer, obj)) {
-                    try {
-                        for (BinaryFieldAccessor info : fields)
-                            info.write(obj, writer);
-
-                        writer.schemaId(stableSchema.schemaId());
-
-                        postWrite(writer, obj);
-                    }
-                    finally {
-                        writer.popSchema();
-                    }
-                }
-
-                break;
-
-            default:
-                assert false : "Invalid mode: " + mode;
-        }
-    }
-
-    /**
-     * @param reader Reader.
-     * @return Object.
-     * @throws BinaryObjectException If failed.
-     */
-    Object read(BinaryReaderExImpl reader) throws BinaryObjectException {
-        assert reader != null;
-
-        Object res;
-
-        switch (mode) {
-            case PORTABLE:
-                res = newInstance();
-
-                reader.setHandle(res);
-
-                if (serializer != null)
-                    serializer.readBinary(res, reader);
-                else
-                    ((Binarylizable)res).readBinary(reader);
-
-                break;
-
-            case EXTERNALIZABLE:
-                res = newInstance();
-
-                reader.setHandle(res);
-
-                try {
-                    ((Externalizable)res).readExternal(reader);
-                }
-                catch (IOException | ClassNotFoundException e) {
-                    throw new BinaryObjectException("Failed to read Externalizable object: " +
-                        res.getClass().getName(), e);
-                }
-
-                break;
-
-            case OBJECT:
-                res = newInstance();
-
-                reader.setHandle(res);
-
-                for (BinaryFieldAccessor info : fields)
-                    info.read(res, reader);
-
-                break;
-
-            default:
-                assert false : "Invalid mode: " + mode;
-
-                return null;
-        }
-
-        if (readResolveMtd != null) {
-            try {
-                res = readResolveMtd.invoke(res);
-
-                reader.setHandle(res);
-            }
-            catch (IllegalAccessException e) {
-                throw new RuntimeException(e);
-            }
-            catch (InvocationTargetException e) {
-                if (e.getTargetException() instanceof BinaryObjectException)
-                    throw (BinaryObjectException)e.getTargetException();
-
-                throw new BinaryObjectException("Failed to execute readResolve() method on " + res, e);
-            }
-        }
-
-        return res;
-    }
-
-    /**
-     * Pre-write phase.
-     *
-     * @param writer Writer.
-     * @param obj Object.
-     * @return Whether further write is needed.
-     */
-    private boolean preWrite(BinaryWriterExImpl writer, Object obj) {
-        if (writer.tryWriteAsHandle(obj))
-            return false;
-
-        writer.preWrite(registered ? null : cls.getName());
-
-        return true;
-    }
-
-    /**
-     * Post-write phase.
-     *
-     * @param writer Writer.
-     * @param obj Object.
-     */
-    private void postWrite(BinaryWriterExImpl writer, Object obj) {
-        writer.postWrite(userType, registered, obj instanceof CacheObjectImpl ? 0 : obj.hashCode());
-    }
-
-    /**
-     * @return Instance.
-     * @throws BinaryObjectException In case of error.
-     */
-    private Object newInstance() throws BinaryObjectException {
-        try {
-            return ctor != null ? ctor.newInstance() : UNSAFE.allocateInstance(cls);
-        }
-        catch (InstantiationException | InvocationTargetException | IllegalAccessException e) {
-            throw new BinaryObjectException("Failed to instantiate instance: " + cls, e);
-        }
-    }
-
-    /**
-     * @param cls Class.
-     * @return Constructor.
-     * @throws BinaryObjectException If constructor doesn't exist.
-     */
-    @SuppressWarnings("ConstantConditions")
-    @Nullable private static Constructor<?> constructor(Class<?> cls) throws BinaryObjectException {
-        assert cls != null;
-
-        try {
-            Constructor<?> ctor = U.forceEmptyConstructor(cls);
-
-            if (ctor == null)
-                throw new BinaryObjectException("Failed to find empty constructor for class: " + cls.getName());
-
-            ctor.setAccessible(true);
-
-            return ctor;
-        }
-        catch (IgniteCheckedException e) {
-            throw new BinaryObjectException("Failed to get constructor for class: " + cls.getName(), e);
-        }
-    }
-
-    /**
-     * Determines whether to use {@link OptimizedMarshaller} for serialization or
-     * not.
-     *
-     * @return {@code true} if to use, {@code false} otherwise.
-     */
-    @SuppressWarnings("unchecked")
-    private boolean initUseOptimizedMarshallerFlag() {
-        for (Class c = cls; c != null && !c.equals(Object.class); c = c.getSuperclass()) {
-            try {
-                Method writeObj = c.getDeclaredMethod("writeObject", ObjectOutputStream.class);
-                Method readObj = c.getDeclaredMethod("readObject", ObjectInputStream.class);
-
-                if (!Modifier.isStatic(writeObj.getModifiers()) && !Modifier.isStatic(readObj.getModifiers()) &&
-                    writeObj.getReturnType() == void.class && readObj.getReturnType() == void.class)
-                    return true;
-            }
-            catch (NoSuchMethodException ignored) {
-                // No-op.
-            }
-        }
-
-        return false;
-    }
-}

http://git-wip-us.apache.org/repos/asf/ignite/blob/1dbf20e0/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
deleted file mode 100644
index f02867b..0000000
--- a/modules/core/src/main/java/org/apache/ignite/internal/portable/PortableContext.java
+++ /dev/null
@@ -1,1102 +0,0 @@
-/*
- * 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.portable;
-
-import org.apache.ignite.IgniteCheckedException;
-import org.apache.ignite.binary.BinaryIdMapper;
-import org.apache.ignite.binary.BinaryInvalidTypeException;
-import org.apache.ignite.binary.BinaryObjectException;
-import org.apache.ignite.binary.BinarySerializer;
-import org.apache.ignite.binary.BinaryType;
-import org.apache.ignite.binary.BinaryTypeConfiguration;
-import org.apache.ignite.cache.CacheKeyConfiguration;
-import org.apache.ignite.cache.affinity.AffinityKeyMapped;
-import org.apache.ignite.configuration.BinaryConfiguration;
-import org.apache.ignite.configuration.IgniteConfiguration;
-import org.apache.ignite.internal.IgniteKernal;
-import org.apache.ignite.internal.IgnitionEx;
-import org.apache.ignite.internal.processors.cache.portable.CacheObjectBinaryProcessorImpl;
-import org.apache.ignite.internal.processors.datastructures.CollocatedQueueItemKey;
-import org.apache.ignite.internal.processors.datastructures.CollocatedSetItemKey;
-import org.apache.ignite.internal.util.IgniteUtils;
-import org.apache.ignite.internal.util.lang.GridMapEntry;
-import org.apache.ignite.internal.util.typedef.F;
-import org.apache.ignite.internal.util.typedef.T2;
-import org.apache.ignite.internal.util.typedef.internal.U;
-import org.apache.ignite.lang.IgniteBiTuple;
-import org.apache.ignite.marshaller.MarshallerContext;
-import org.apache.ignite.marshaller.optimized.OptimizedMarshaller;
-import org.jetbrains.annotations.Nullable;
-import org.jsr166.ConcurrentHashMap8;
-
-import java.io.Externalizable;
-import java.io.File;
-import java.io.IOException;
-import java.io.InvalidObjectException;
-import java.io.ObjectInput;
-import java.io.ObjectOutput;
-import java.io.ObjectStreamException;
-import java.lang.reflect.Field;
-import java.math.BigDecimal;
-import java.net.URISyntaxException;
-import java.net.URL;
-import java.net.URLClassLoader;
-import java.sql.Timestamp;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.Date;
-import java.util.Enumeration;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.LinkedHashMap;
-import java.util.LinkedHashSet;
-import java.util.LinkedList;
-import java.util.Map;
-import java.util.Set;
-import java.util.UUID;
-import java.util.concurrent.ConcurrentMap;
-import java.util.jar.JarEntry;
-import java.util.jar.JarFile;
-
-/**
- * Portable context.
- */
-public class PortableContext implements Externalizable {
-    /** */
-    private static final long serialVersionUID = 0L;
-
-    /** */
-    private static final ClassLoader dfltLdr = U.gridClassLoader();
-
-    /** */
-    private final ConcurrentMap<Class<?>, PortableClassDescriptor> descByCls = new ConcurrentHashMap8<>();
-
-    /** Holds classes loaded by default class loader only. */
-    private final ConcurrentMap<Integer, PortableClassDescriptor> userTypes = new ConcurrentHashMap8<>();
-
-    /** */
-    private final Map<Integer, PortableClassDescriptor> predefinedTypes = new HashMap<>();
-
-    /** */
-    private final Map<String, Integer> predefinedTypeNames = new HashMap<>();
-
-    /** */
-    private final Map<Class<? extends Collection>, Byte> colTypes = new HashMap<>();
-
-    /** */
-    private final Map<Class<? extends Map>, Byte> mapTypes = new HashMap<>();
-
-    /** */
-    private final ConcurrentMap<Integer, BinaryIdMapper> mappers = new ConcurrentHashMap8<>(0);
-
-    /** Affinity key field names. */
-    private final ConcurrentMap<Integer, String> affKeyFieldNames = new ConcurrentHashMap8<>(0);
-
-    /** */
-    private final Map<String, BinaryIdMapper> typeMappers = new ConcurrentHashMap8<>(0);
-
-    /** */
-    private BinaryMetadataHandler metaHnd;
-
-    /** Actual marshaller. */
-    private BinaryMarshaller marsh;
-
-    /** */
-    private MarshallerContext marshCtx;
-
-    /** */
-    private String gridName;
-
-    /** */
-    private IgniteConfiguration igniteCfg;
-
-    /** */
-    private final OptimizedMarshaller optmMarsh = new OptimizedMarshaller();
-
-    /** Compact footer flag. */
-    private boolean compactFooter;
-
-    /** Object schemas. */
-    private volatile Map<Integer, PortableSchemaRegistry> schemas;
-
-    /**
-     * For {@link Externalizable}.
-     */
-    public PortableContext() {
-        // No-op.
-    }
-
-    /**
-     * @param metaHnd Meta data handler.
-     * @param igniteCfg Ignite configuration.
-     */
-    public PortableContext(BinaryMetadataHandler metaHnd, IgniteConfiguration igniteCfg) {
-        assert metaHnd != null;
-        assert igniteCfg != null;
-
-        this.metaHnd = metaHnd;
-        this.igniteCfg = igniteCfg;
-
-        gridName = igniteCfg.getGridName();
-
-        colTypes.put(ArrayList.class, GridPortableMarshaller.ARR_LIST);
-        colTypes.put(LinkedList.class, GridPortableMarshaller.LINKED_LIST);
-        colTypes.put(HashSet.class, GridPortableMarshaller.HASH_SET);
-        colTypes.put(LinkedHashSet.class, GridPortableMarshaller.LINKED_HASH_SET);
-
-        mapTypes.put(HashMap.class, GridPortableMarshaller.HASH_MAP);
-        mapTypes.put(LinkedHashMap.class, GridPortableMarshaller.LINKED_HASH_MAP);
-
-        // IDs range from [0..200] is used by Java SDK API and GridGain legacy API
-
-        registerPredefinedType(Byte.class, GridPortableMarshaller.BYTE);
-        registerPredefinedType(Boolean.class, GridPortableMarshaller.BOOLEAN);
-        registerPredefinedType(Short.class, GridPortableMarshaller.SHORT);
-        registerPredefinedType(Character.class, GridPortableMarshaller.CHAR);
-        registerPredefinedType(Integer.class, GridPortableMarshaller.INT);
-        registerPredefinedType(Long.class, GridPortableMarshaller.LONG);
-        registerPredefinedType(Float.class, GridPortableMarshaller.FLOAT);
-        registerPredefinedType(Double.class, GridPortableMarshaller.DOUBLE);
-        registerPredefinedType(String.class, GridPortableMarshaller.STRING);
-        registerPredefinedType(BigDecimal.class, GridPortableMarshaller.DECIMAL);
-        registerPredefinedType(Date.class, GridPortableMarshaller.DATE);
-        registerPredefinedType(Timestamp.class, GridPortableMarshaller.TIMESTAMP);
-        registerPredefinedType(UUID.class, GridPortableMarshaller.UUID);
-
-        registerPredefinedType(byte[].class, GridPortableMarshaller.BYTE_ARR);
-        registerPredefinedType(short[].class, GridPortableMarshaller.SHORT_ARR);
-        registerPredefinedType(int[].class, GridPortableMarshaller.INT_ARR);
-        registerPredefinedType(long[].class, GridPortableMarshaller.LONG_ARR);
-        registerPredefinedType(float[].class, GridPortableMarshaller.FLOAT_ARR);
-        registerPredefinedType(double[].class, GridPortableMarshaller.DOUBLE_ARR);
-        registerPredefinedType(char[].class, GridPortableMarshaller.CHAR_ARR);
-        registerPredefinedType(boolean[].class, GridPortableMarshaller.BOOLEAN_ARR);
-        registerPredefinedType(BigDecimal[].class, GridPortableMarshaller.DECIMAL_ARR);
-        registerPredefinedType(String[].class, GridPortableMarshaller.STRING_ARR);
-        registerPredefinedType(UUID[].class, GridPortableMarshaller.UUID_ARR);
-        registerPredefinedType(Date[].class, GridPortableMarshaller.DATE_ARR);
-        registerPredefinedType(Timestamp[].class, GridPortableMarshaller.TIMESTAMP_ARR);
-        registerPredefinedType(Object[].class, GridPortableMarshaller.OBJ_ARR);
-
-        registerPredefinedType(ArrayList.class, 0);
-        registerPredefinedType(LinkedList.class, 0);
-        registerPredefinedType(HashSet.class, 0);
-        registerPredefinedType(LinkedHashSet.class, 0);
-
-        registerPredefinedType(HashMap.class, 0);
-        registerPredefinedType(LinkedHashMap.class, 0);
-
-        registerPredefinedType(GridMapEntry.class, 60);
-        registerPredefinedType(IgniteBiTuple.class, 61);
-        registerPredefinedType(T2.class, 62);
-
-        // IDs range [200..1000] is used by Ignite internal APIs.
-    }
-
-    /**
-     * @return Marshaller.
-     */
-    public BinaryMarshaller marshaller() {
-        return marsh;
-    }
-
-    /**
-     * @return Ignite configuration.
-     */
-    public IgniteConfiguration configuration(){
-        return igniteCfg;
-    }
-
-    /**
-     * @param marsh Portable marshaller.
-     * @param cfg Configuration.
-     * @throws BinaryObjectException In case of error.
-     */
-    public void configure(BinaryMarshaller marsh, IgniteConfiguration cfg) throws BinaryObjectException {
-        if (marsh == null)
-            return;
-
-        this.marsh = marsh;
-
-        marshCtx = marsh.getContext();
-
-        BinaryConfiguration binaryCfg = cfg.getBinaryConfiguration();
-
-        if (binaryCfg == null)
-            binaryCfg = new BinaryConfiguration();
-
-        assert marshCtx != null;
-
-        optmMarsh.setContext(marshCtx);
-
-        configure(
-            binaryCfg.getIdMapper(),
-            binaryCfg.getSerializer(),
-            binaryCfg.getTypeConfigurations()
-        );
-
-        compactFooter = binaryCfg.isCompactFooter();
-    }
-
-    /**
-     * @param globalIdMapper ID mapper.
-     * @param globalSerializer Serializer.
-     * @param typeCfgs Type configurations.
-     * @throws BinaryObjectException In case of error.
-     */
-    private void configure(
-        BinaryIdMapper globalIdMapper,
-        BinarySerializer globalSerializer,
-        Collection<BinaryTypeConfiguration> typeCfgs
-    ) throws BinaryObjectException {
-        TypeDescriptors descs = new TypeDescriptors();
-
-        Map<String, String> affFields = new HashMap<>();
-
-        if (!F.isEmpty(igniteCfg.getCacheKeyConfiguration())) {
-            for (CacheKeyConfiguration keyCfg : igniteCfg.getCacheKeyConfiguration())
-                affFields.put(keyCfg.getTypeName(), keyCfg.getAffinityKeyFieldName());
-        }
-
-        if (typeCfgs != null) {
-            for (BinaryTypeConfiguration typeCfg : typeCfgs) {
-                String clsName = typeCfg.getTypeName();
-
-                if (clsName == null)
-                    throw new BinaryObjectException("Class name is required for portable type configuration.");
-
-                BinaryIdMapper idMapper = globalIdMapper;
-
-                if (typeCfg.getIdMapper() != null)
-                    idMapper = typeCfg.getIdMapper();
-
-                idMapper = BinaryInternalIdMapper.create(idMapper);
-
-                BinarySerializer serializer = globalSerializer;
-
-                if (typeCfg.getSerializer() != null)
-                    serializer = typeCfg.getSerializer();
-
-                if (clsName.endsWith(".*")) {
-                    String pkgName = clsName.substring(0, clsName.length() - 2);
-
-                    for (String clsName0 : classesInPackage(pkgName))
-                        descs.add(clsName0, idMapper, serializer, affFields.get(clsName0),
-                            typeCfg.isEnum(), true);
-                }
-                else
-                    descs.add(clsName, idMapper, serializer, affFields.get(clsName),
-                        typeCfg.isEnum(), false);
-            }
-        }
-
-        for (TypeDescriptor desc : descs.descriptors())
-            registerUserType(desc.clsName, desc.idMapper, desc.serializer, desc.affKeyFieldName, desc.isEnum);
-
-        BinaryInternalIdMapper dfltMapper = BinaryInternalIdMapper.create(globalIdMapper);
-
-        // Put affinity field names for unconfigured types.
-        for (Map.Entry<String, String> entry : affFields.entrySet()) {
-            String typeName = entry.getKey();
-
-            int typeId = dfltMapper.typeId(typeName);
-
-            affKeyFieldNames.putIfAbsent(typeId, entry.getValue());
-        }
-
-        addSystemClassAffinityKey(CollocatedSetItemKey.class);
-        addSystemClassAffinityKey(CollocatedQueueItemKey.class);
-    }
-
-    /**
-     * @param cls Class.
-     */
-    private void addSystemClassAffinityKey(Class<?> cls) {
-        String fieldName = affinityFieldName(cls);
-
-        assert fieldName != null : cls;
-
-        affKeyFieldNames.putIfAbsent(cls.getName().hashCode(), affinityFieldName(cls));
-    }
-
-    /**
-     * @param pkgName Package name.
-     * @return Class names.
-     */
-    @SuppressWarnings("ConstantConditions")
-    private static Iterable<String> classesInPackage(String pkgName) {
-        assert pkgName != null;
-
-        Collection<String> clsNames = new ArrayList<>();
-
-        ClassLoader ldr = U.gridClassLoader();
-
-        if (ldr instanceof URLClassLoader) {
-            String pkgPath = pkgName.replaceAll("\\.", "/");
-
-            URL[] urls = ((URLClassLoader)ldr).getURLs();
-
-            for (URL url : urls) {
-                String proto = url.getProtocol().toLowerCase();
-
-                if ("file".equals(proto)) {
-                    try {
-                        File cpElement = new File(url.toURI());
-
-                        if (cpElement.isDirectory()) {
-                            File pkgDir = new File(cpElement, pkgPath);
-
-                            if (pkgDir.isDirectory()) {
-                                for (File file : pkgDir.listFiles()) {
-                                    String fileName = file.getName();
-
-                                    if (file.isFile() && fileName.toLowerCase().endsWith(".class"))
-                                        clsNames.add(pkgName + '.' + fileName.substring(0, fileName.length() - 6));
-                                }
-                            }
-                        }
-                        else if (cpElement.isFile()) {
-                            try {
-                                JarFile jar = new JarFile(cpElement);
-
-                                Enumeration<JarEntry> entries = jar.entries();
-
-                                while (entries.hasMoreElements()) {
-                                    String entry = entries.nextElement().getName();
-
-                                    if (entry.startsWith(pkgPath) && entry.endsWith(".class")) {
-                                        String clsName = entry.substring(pkgPath.length() + 1, entry.length() - 6);
-
-                                        if (!clsName.contains("/") && !clsName.contains("\\"))
-                                            clsNames.add(pkgName + '.' + clsName);
-                                    }
-                                }
-                            }
-                            catch (IOException ignored) {
-                                // No-op.
-                            }
-                        }
-                    }
-                    catch (URISyntaxException ignored) {
-                        // No-op.
-                    }
-                }
-            }
-        }
-
-        return clsNames;
-    }
-
-    /**
-     * @param cls Class.
-     * @return Class descriptor.
-     * @throws BinaryObjectException In case of error.
-     */
-    public PortableClassDescriptor descriptorForClass(Class<?> cls, boolean deserialize)
-        throws BinaryObjectException {
-        assert cls != null;
-
-        PortableClassDescriptor desc = descByCls.get(cls);
-
-        if (desc == null || !desc.registered())
-            desc = registerClassDescriptor(cls, deserialize);
-
-        return desc;
-    }
-
-    /**
-     * @param userType User type or not.
-     * @param typeId Type ID.
-     * @param ldr Class loader.
-     * @return Class descriptor.
-     */
-    public PortableClassDescriptor descriptorForTypeId(
-        boolean userType,
-        int typeId,
-        ClassLoader ldr,
-        boolean deserialize
-    ) {
-        assert typeId != GridPortableMarshaller.UNREGISTERED_TYPE_ID;
-
-        //TODO: As a workaround for IGNITE-1358 we always check the predefined map before without checking 'userType'
-        PortableClassDescriptor desc = predefinedTypes.get(typeId);
-
-        if (desc != null)
-            return desc;
-
-        if (ldr == null)
-            ldr = dfltLdr;
-
-        // If the type hasn't been loaded by default class loader then we mustn't return the descriptor from here
-        // giving a chance to a custom class loader to reload type's class.
-        if (userType && ldr.equals(dfltLdr)) {
-            desc = userTypes.get(typeId);
-
-            if (desc != null)
-                return desc;
-        }
-
-        Class cls;
-
-        try {
-            cls = marshCtx.getClass(typeId, ldr);
-
-            desc = descByCls.get(cls);
-        }
-        catch (ClassNotFoundException e) {
-            // Class might have been loaded by default class loader.
-            if (userType && !ldr.equals(dfltLdr) && (desc = descriptorForTypeId(true, typeId, dfltLdr, deserialize)) != null)
-                return desc;
-
-            throw new BinaryInvalidTypeException(e);
-        }
-        catch (IgniteCheckedException e) {
-            // Class might have been loaded by default class loader.
-            if (userType && !ldr.equals(dfltLdr) && (desc = descriptorForTypeId(true, typeId, dfltLdr, deserialize)) != null)
-                return desc;
-
-            throw new BinaryObjectException("Failed resolve class for ID: " + typeId, e);
-        }
-
-        if (desc == null) {
-            desc = registerClassDescriptor(cls, deserialize);
-
-            assert desc.typeId() == typeId;
-        }
-
-        return desc;
-    }
-
-    /**
-     * Creates and registers {@link PortableClassDescriptor} for the given {@code class}.
-     *
-     * @param cls Class.
-     * @return Class descriptor.
-     */
-    private PortableClassDescriptor registerClassDescriptor(Class<?> cls, boolean deserialize) {
-        PortableClassDescriptor desc;
-
-        String clsName = cls.getName();
-
-        if (marshCtx.isSystemType(clsName)) {
-            desc = new PortableClassDescriptor(this,
-                cls,
-                false,
-                clsName.hashCode(),
-                clsName,
-                null,
-                BinaryInternalIdMapper.defaultInstance(),
-                null,
-                false,
-                true, /* registered */
-                false /* predefined */
-            );
-
-            PortableClassDescriptor old = descByCls.putIfAbsent(cls, desc);
-
-            if (old != null)
-                desc = old;
-        }
-        else
-            desc = registerUserClassDescriptor(cls, deserialize);
-
-        return desc;
-    }
-
-    /**
-     * Creates and registers {@link PortableClassDescriptor} for the given user {@code class}.
-     *
-     * @param cls Class.
-     * @return Class descriptor.
-     */
-    private PortableClassDescriptor registerUserClassDescriptor(Class<?> cls, boolean deserialize) {
-        boolean registered;
-
-        String typeName = typeName(cls.getName());
-
-        BinaryIdMapper idMapper = userTypeIdMapper(typeName);
-
-        int typeId = idMapper.typeId(typeName);
-
-        try {
-            registered = marshCtx.registerClass(typeId, cls);
-        }
-        catch (IgniteCheckedException e) {
-            throw new BinaryObjectException("Failed to register class.", e);
-        }
-
-        String affFieldName = affinityFieldName(cls);
-
-        PortableClassDescriptor desc = new PortableClassDescriptor(this,
-            cls,
-            true,
-            typeId,
-            typeName,
-            affFieldName,
-            idMapper,
-            null,
-            true,
-            registered,
-            false /* predefined */
-        );
-
-        if (!deserialize) {
-            Collection<PortableSchema> schemas = desc.schema() != null ? Collections.singleton(desc.schema()) : null;
-
-            metaHnd.addMeta(typeId,
-                new BinaryMetadata(typeId, typeName, desc.fieldsMeta(), affFieldName, schemas, desc.isEnum()).wrap(this));
-        }
-
-        // perform put() instead of putIfAbsent() because "registered" flag might have been changed or class loader
-        // might have reloaded described class.
-        if (IgniteUtils.detectClassLoader(cls).equals(dfltLdr))
-            userTypes.put(typeId, desc);
-
-        descByCls.put(cls, desc);
-
-        mappers.putIfAbsent(typeId, idMapper);
-
-        return desc;
-    }
-
-    /**
-     * @param cls Collection class.
-     * @return Collection type ID.
-     */
-    public byte collectionType(Class<? extends Collection> cls) {
-        assert cls != null;
-
-        Byte type = colTypes.get(cls);
-
-        if (type != null)
-            return type;
-
-        return Set.class.isAssignableFrom(cls) ? GridPortableMarshaller.USER_SET : GridPortableMarshaller.USER_COL;
-    }
-
-    /**
-     * @param cls Map class.
-     * @return Map type ID.
-     */
-    public byte mapType(Class<? extends Map> cls) {
-        assert cls != null;
-
-        Byte type = mapTypes.get(cls);
-
-        return type != null ? type : GridPortableMarshaller.USER_COL;
-    }
-
-    /**
-     * @param typeName Type name.
-     * @return Type ID.
-     */
-    public int typeId(String typeName) {
-        String typeName0 = typeName(typeName);
-
-        Integer id = predefinedTypeNames.get(typeName0);
-
-        if (id != null)
-            return id;
-
-        if (marshCtx.isSystemType(typeName))
-            return typeName.hashCode();
-
-        return userTypeIdMapper(typeName0).typeId(typeName0);
-    }
-
-    /**
-     * @param typeId Type ID.
-     * @param fieldName Field name.
-     * @return Field ID.
-     */
-    public int fieldId(int typeId, String fieldName) {
-        return userTypeIdMapper(typeId).fieldId(typeId, fieldName);
-    }
-
-    /**
-     * @param typeId Type ID.
-     * @return Instance of ID mapper.
-     */
-    public BinaryIdMapper userTypeIdMapper(int typeId) {
-        BinaryIdMapper idMapper = mappers.get(typeId);
-
-        return idMapper != null ? idMapper : BinaryInternalIdMapper.defaultInstance();
-    }
-
-    /**
-     * @param typeName Type name.
-     * @return Instance of ID mapper.
-     */
-    private BinaryIdMapper userTypeIdMapper(String typeName) {
-        BinaryIdMapper idMapper = typeMappers.get(typeName);
-
-        return idMapper != null ? idMapper : BinaryInternalIdMapper.defaultInstance();
-    }
-
-    /**
-     * @param cls Class to get affinity field for.
-     * @return Affinity field name or {@code null} if field name was not found.
-     */
-    private String affinityFieldName(Class cls) {
-        for (; cls != Object.class && cls != null; cls = cls.getSuperclass()) {
-            for (Field f : cls.getDeclaredFields()) {
-                if (f.getAnnotation(AffinityKeyMapped.class) != null)
-                    return f.getName();
-            }
-        }
-
-        return null;
-    }
-
-    /** {@inheritDoc} */
-    @Override public void writeExternal(ObjectOutput out) throws IOException {
-        U.writeString(out, igniteCfg.getGridName());
-    }
-
-    /** {@inheritDoc} */
-    @Override public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
-        gridName = U.readString(in);
-    }
-
-    /**
-     * @return Portable context.
-     * @throws ObjectStreamException In case of error.
-     */
-    protected Object readResolve() throws ObjectStreamException {
-        try {
-            IgniteKernal g = IgnitionEx.gridx(gridName);
-
-            if (g == null)
-                throw new IllegalStateException("Failed to find grid for name: " + gridName);
-
-            return ((CacheObjectBinaryProcessorImpl)g.context().cacheObjects()).portableContext();
-        }
-        catch (IllegalStateException e) {
-            throw U.withCause(new InvalidObjectException(e.getMessage()), e);
-        }
-    }
-
-    /**
-     * @param cls Class.
-     * @param id Type ID.
-     * @return GridPortableClassDescriptor.
-     */
-    public PortableClassDescriptor registerPredefinedType(Class<?> cls, int id) {
-        String typeName = typeName(cls.getName());
-
-        PortableClassDescriptor desc = new PortableClassDescriptor(
-            this,
-            cls,
-            false,
-            id,
-            typeName,
-            null,
-            BinaryInternalIdMapper.defaultInstance(),
-            null,
-            false,
-            true, /* registered */
-            true /* predefined */
-        );
-
-        predefinedTypeNames.put(typeName, id);
-        predefinedTypes.put(id, desc);
-
-        descByCls.put(cls, desc);
-
-        return desc;
-    }
-
-    /**
-     * @param clsName Class name.
-     * @param idMapper ID mapper.
-     * @param serializer Serializer.
-     * @param affKeyFieldName Affinity key field name.
-     * @param isEnum If enum.
-     * @throws BinaryObjectException In case of error.
-     */
-    @SuppressWarnings("ErrorNotRethrown")
-    public void registerUserType(String clsName,
-        BinaryIdMapper idMapper,
-        @Nullable BinarySerializer serializer,
-        @Nullable String affKeyFieldName,
-        boolean isEnum)
-        throws BinaryObjectException {
-        assert idMapper != null;
-
-        Class<?> cls = null;
-
-        try {
-            cls = Class.forName(clsName);
-        }
-        catch (ClassNotFoundException | NoClassDefFoundError ignored) {
-            // No-op.
-        }
-
-        String typeName = typeName(clsName);
-
-        int id = idMapper.typeId(typeName);
-
-        //Workaround for IGNITE-1358
-        if (predefinedTypes.get(id) != null)
-            throw new BinaryObjectException("Duplicate type ID [clsName=" + clsName + ", id=" + id + ']');
-
-        if (mappers.put(id, idMapper) != null)
-            throw new BinaryObjectException("Duplicate type ID [clsName=" + clsName + ", id=" + id + ']');
-
-        if (affKeyFieldName != null) {
-            if (affKeyFieldNames.put(id, affKeyFieldName) != null)
-                throw new BinaryObjectException("Duplicate type ID [clsName=" + clsName + ", id=" + id + ']');
-        }
-
-        typeMappers.put(typeName, idMapper);
-
-        Map<String, Integer> fieldsMeta = null;
-        Collection<PortableSchema> schemas = null;
-
-        if (cls != null) {
-            PortableClassDescriptor desc = new PortableClassDescriptor(
-                this,
-                cls,
-                true,
-                id,
-                typeName,
-                affKeyFieldName,
-                idMapper,
-                serializer,
-                true,
-                true, /* registered */
-                false /* predefined */
-            );
-
-            fieldsMeta = desc.fieldsMeta();
-            schemas = desc.schema() != null ? Collections.singleton(desc.schema()) : null;
-
-            if (IgniteUtils.detectClassLoader(cls).equals(dfltLdr))
-                userTypes.put(id, desc);
-
-            descByCls.put(cls, desc);
-        }
-
-        metaHnd.addMeta(id, new BinaryMetadata(id, typeName, fieldsMeta, affKeyFieldName, schemas, isEnum).wrap(this));
-    }
-
-    /**
-     * Create binary field.
-     *
-     * @param typeId Type ID.
-     * @param fieldName Field name.
-     * @return Binary field.
-     */
-    public BinaryFieldImpl createField(int typeId, String fieldName) {
-        PortableSchemaRegistry schemaReg = schemaRegistry(typeId);
-
-        int fieldId = userTypeIdMapper(typeId).fieldId(typeId, fieldName);
-
-        return new BinaryFieldImpl(typeId, schemaReg, fieldName, fieldId);
-    }
-
-    /**
-     * @param typeId Type ID.
-     * @return Meta data.
-     * @throws BinaryObjectException In case of error.
-     */
-    @Nullable public BinaryType metadata(int typeId) throws BinaryObjectException {
-        return metaHnd != null ? metaHnd.metadata(typeId) : null;
-    }
-
-    /**
-     * @param typeId Type ID.
-     * @return Affinity key field name.
-     */
-    public String affinityKeyFieldName(int typeId) {
-        return affKeyFieldNames.get(typeId);
-    }
-
-    /**
-     * @param typeId Type ID.
-     * @param meta Meta data.
-     * @throws BinaryObjectException In case of error.
-     */
-    public void updateMetadata(int typeId, BinaryMetadata meta) throws BinaryObjectException {
-        metaHnd.addMeta(typeId, meta.wrap(this));
-    }
-
-    /**
-     * @return Whether field IDs should be skipped in footer or not.
-     */
-    public boolean isCompactFooter() {
-        return compactFooter;
-    }
-
-    /**
-     * Get schema registry for type ID.
-     *
-     * @param typeId Type ID.
-     * @return Schema registry for type ID.
-     */
-    public PortableSchemaRegistry schemaRegistry(int typeId) {
-        Map<Integer, PortableSchemaRegistry> schemas0 = schemas;
-
-        if (schemas0 == null) {
-            synchronized (this) {
-                schemas0 = schemas;
-
-                if (schemas0 == null) {
-                    schemas0 = new HashMap<>();
-
-                    PortableSchemaRegistry reg = new PortableSchemaRegistry();
-
-                    schemas0.put(typeId, reg);
-
-                    schemas = schemas0;
-
-                    return reg;
-                }
-            }
-        }
-
-        PortableSchemaRegistry reg = schemas0.get(typeId);
-
-        if (reg == null) {
-            synchronized (this) {
-                reg = schemas.get(typeId);
-
-                if (reg == null) {
-                    reg = new PortableSchemaRegistry();
-
-                    schemas0 = new HashMap<>(schemas);
-
-                    schemas0.put(typeId, reg);
-
-                    schemas = schemas0;
-                }
-            }
-        }
-
-        return reg;
-    }
-
-    /**
-     * Returns instance of {@link OptimizedMarshaller}.
-     *
-     * @return Optimized marshaller.
-     */
-    OptimizedMarshaller optimizedMarsh() {
-        return optmMarsh;
-    }
-
-    /**
-     * @param clsName Class name.
-     * @return Type name.
-     */
-    @SuppressWarnings("ResultOfMethodCallIgnored")
-    public static String typeName(String clsName) {
-        assert clsName != null;
-
-        int idx = clsName.lastIndexOf('$');
-
-        if (idx == clsName.length() - 1)
-            // This is a regular (not inner) class name that ends with '$'. Common use case for Scala classes.
-            idx = -1;
-        else if (idx >= 0) {
-            String typeName = clsName.substring(idx + 1);
-
-            try {
-                Integer.parseInt(typeName);
-
-                // This is an anonymous class. Don't cut off enclosing class name for it.
-                idx = -1;
-            }
-            catch (NumberFormatException ignore) {
-                // This is a lambda class.
-                if (clsName.indexOf("$$Lambda$") > 0)
-                    idx = -1;
-                else
-                    return typeName;
-            }
-        }
-
-        if (idx < 0)
-            idx = clsName.lastIndexOf('.');
-
-        return idx >= 0 ? clsName.substring(idx + 1) : clsName;
-    }
-
-    /**
-     * Undeployment callback invoked when class loader is being undeployed.
-     *
-     * Some marshallers may want to clean their internal state that uses the undeployed class loader somehow.
-     *
-     * @param ldr Class loader being undeployed.
-     */
-    public void onUndeploy(ClassLoader ldr) {
-        for (Class<?> cls : descByCls.keySet()) {
-            if (ldr.equals(cls.getClassLoader()))
-                descByCls.remove(cls);
-        }
-
-        U.clearClassCache(ldr);
-    }
-
-    /**
-     * Type descriptors.
-     */
-    private static class TypeDescriptors {
-        /** Descriptors map. */
-        private final Map<String, TypeDescriptor> descs = new LinkedHashMap<>();
-
-        /**
-         * Add type descriptor.
-         *
-         * @param clsName Class name.
-         * @param idMapper ID mapper.
-         * @param serializer Serializer.
-         * @param affKeyFieldName Affinity key field name.
-         * @param isEnum Enum flag.
-         * @param canOverride Whether this descriptor can be override.
-         * @throws BinaryObjectException If failed.
-         */
-        private void add(String clsName,
-            BinaryIdMapper idMapper,
-            BinarySerializer serializer,
-            String affKeyFieldName,
-            boolean isEnum,
-            boolean canOverride)
-            throws BinaryObjectException {
-            TypeDescriptor desc = new TypeDescriptor(clsName,
-                idMapper,
-                serializer,
-                affKeyFieldName,
-                isEnum,
-                canOverride);
-
-            TypeDescriptor oldDesc = descs.get(clsName);
-
-            if (oldDesc == null)
-                descs.put(clsName, desc);
-            else
-                oldDesc.override(desc);
-        }
-
-        /**
-         * Get all collected descriptors.
-         *
-         * @return Descriptors.
-         */
-        private Iterable<TypeDescriptor> descriptors() {
-            return descs.values();
-        }
-    }
-
-    /**
-     * Type descriptor.
-     */
-    private static class TypeDescriptor {
-        /** Class name. */
-        private final String clsName;
-
-        /** ID mapper. */
-        private BinaryIdMapper idMapper;
-
-        /** Serializer. */
-        private BinarySerializer serializer;
-
-        /** Affinity key field name. */
-        private String affKeyFieldName;
-
-        /** Enum flag. */
-        private boolean isEnum;
-
-        /** Whether this descriptor can be override. */
-        private boolean canOverride;
-
-        /**
-         * Constructor.
-         *
-         * @param clsName Class name.
-         * @param idMapper ID mapper.
-         * @param serializer Serializer.
-         * @param affKeyFieldName Affinity key field name.
-         * @param isEnum Enum type.
-         * @param canOverride Whether this descriptor can be override.
-         */
-        private TypeDescriptor(String clsName, BinaryIdMapper idMapper, BinarySerializer serializer,
-            String affKeyFieldName, boolean isEnum, boolean canOverride) {
-            this.clsName = clsName;
-            this.idMapper = idMapper;
-            this.serializer = serializer;
-            this.affKeyFieldName = affKeyFieldName;
-            this.isEnum = isEnum;
-            this.canOverride = canOverride;
-        }
-
-        /**
-         * Override portable class descriptor.
-         *
-         * @param other Other descriptor.
-         * @throws BinaryObjectException If failed.
-         */
-        private void override(TypeDescriptor other) throws BinaryObjectException {
-            assert clsName.equals(other.clsName);
-
-            if (canOverride) {
-                idMapper = other.idMapper;
-                serializer = other.serializer;
-                affKeyFieldName = other.affKeyFieldName;
-                canOverride = other.canOverride;
-            }
-            else if (!other.canOverride)
-                throw new BinaryObjectException("Duplicate explicit class definition in configuration: " + clsName);
-        }
-    }
-
-    /**
-     * Type id wrapper.
-     */
-    static class Type {
-        /** Type id */
-        private final int id;
-
-        /** Whether the following type is registered in a cache or not */
-        private final boolean registered;
-
-        /**
-         * @param id Id.
-         * @param registered Registered.
-         */
-        public Type(int id, boolean registered) {
-            this.id = id;
-            this.registered = registered;
-        }
-
-        /**
-         * @return Type ID.
-         */
-        public int id() {
-            return id;
-        }
-
-        /**
-         * @return Registered flag value.
-         */
-        public boolean registered() {
-            return registered;
-        }
-    }
-}

http://git-wip-us.apache.org/repos/asf/ignite/blob/1dbf20e0/modules/core/src/main/java/org/apache/ignite/internal/portable/PortablePositionReadable.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/portable/PortablePositionReadable.java b/modules/core/src/main/java/org/apache/ignite/internal/portable/PortablePositionReadable.java
deleted file mode 100644
index c49c898..0000000
--- a/modules/core/src/main/java/org/apache/ignite/internal/portable/PortablePositionReadable.java
+++ /dev/null
@@ -1,47 +0,0 @@
-/*
- * 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.portable;
-
-/**
- * Interface allowing for positioned read.
- */
-public interface PortablePositionReadable {
-    /**
-     * Read byte at the given position.
-     *
-     * @param pos Position.
-     * @return Value.
-     */
-    public byte readBytePositioned(int pos);
-
-    /**
-     * Read short at the given position.
-     *
-     * @param pos Position.
-     * @return Value.
-     */
-    public short readShortPositioned(int pos);
-
-    /**
-     * Read integer at the given position.
-     *
-     * @param pos Position.
-     * @return Value.
-     */
-    public int readIntPositioned(int pos);
-}

http://git-wip-us.apache.org/repos/asf/ignite/blob/1dbf20e0/modules/core/src/main/java/org/apache/ignite/internal/portable/PortablePrimitives.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/portable/PortablePrimitives.java b/modules/core/src/main/java/org/apache/ignite/internal/portable/PortablePrimitives.java
deleted file mode 100644
index 02f552a..0000000
--- a/modules/core/src/main/java/org/apache/ignite/internal/portable/PortablePrimitives.java
+++ /dev/null
@@ -1,382 +0,0 @@
-/*
- * 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.portable;
-
-import org.apache.ignite.internal.util.GridUnsafe;
-import sun.misc.Unsafe;
-
-import java.nio.ByteOrder;
-
-/**
- * Primitives writer.
- */
-public abstract class PortablePrimitives {
-    /** */
-    private static final Unsafe UNSAFE = GridUnsafe.unsafe();
-
-    /** */
-    private static final long BYTE_ARR_OFF = UNSAFE.arrayBaseOffset(byte[].class);
-
-    /** */
-    private static final long CHAR_ARR_OFF = UNSAFE.arrayBaseOffset(char[].class);
-
-    /** Whether little endian is set. */
-    private static final boolean BIG_ENDIAN = ByteOrder.nativeOrder() == ByteOrder.BIG_ENDIAN;
-
-    /**
-     * @param arr Array.
-     * @param off Offset.
-     * @param val Value.
-     */
-    public static void writeByte(byte[] arr, int off, byte val) {
-        UNSAFE.putByte(arr, BYTE_ARR_OFF + off, val);
-    }
-
-    /**
-     * @param arr Array.
-     * @param off Offset.
-     * @return Value.
-     */
-    public static byte readByte(byte[] arr, int off) {
-        return UNSAFE.getByte(arr, BYTE_ARR_OFF + off);
-    }
-
-    /**
-     * @param ptr Pointer.
-     * @param off Offset.
-     * @return Value.
-     */
-    public static byte readByte(long ptr, int off) {
-        return UNSAFE.getByte(ptr + off);
-    }
-
-    /**
-     * @param arr Array.
-     * @param off Offset.
-     * @return Value.
-     */
-    public static byte[] readByteArray(byte[] arr, int off, int len) {
-        byte[] arr0 = new byte[len];
-
-        UNSAFE.copyMemory(arr, BYTE_ARR_OFF + off, arr0, BYTE_ARR_OFF, len);
-
-        return arr0;
-    }
-
-    /**
-     * @param ptr Pointer.
-     * @param off Offset.
-     * @return Value.
-     */
-    public static byte[] readByteArray(long ptr, int off, int len) {
-        byte[] arr0 = new byte[len];
-
-        UNSAFE.copyMemory(null, ptr + off, arr0, BYTE_ARR_OFF, len);
-
-        return arr0;
-    }
-
-    /**
-     * @param arr Array.
-     * @param off Offset.
-     * @param val Value.
-     */
-    public static void writeBoolean(byte[] arr, int off, boolean val) {
-        writeByte(arr, off, val ? (byte)1 : (byte)0);
-    }
-
-    /**
-     * @param arr Array.
-     * @param off Offset.
-     * @return Value.
-     */
-    public static boolean readBoolean(byte[] arr, int off) {
-        return readByte(arr, off) == 1;
-    }
-
-    /**
-     * @param ptr Pointer.
-     * @param off Offset.
-     * @return Value.
-     */
-    public static boolean readBoolean(long ptr, int off) {
-        return readByte(ptr, off) == 1;
-    }
-
-    /**
-     * @param arr Array.
-     * @param off Offset.
-     * @param val Value.
-     */
-    public static void writeShort(byte[] arr, int off, short val) {
-        if (BIG_ENDIAN)
-            val = Short.reverseBytes(val);
-
-        UNSAFE.putShort(arr, BYTE_ARR_OFF + off, val);
-    }
-
-    /**
-     * @param arr Array.
-     * @param off Offset.
-     * @return Value.
-     */
-    public static short readShort(byte[] arr, int off) {
-        short val = UNSAFE.getShort(arr, BYTE_ARR_OFF + off);
-
-        if (BIG_ENDIAN)
-            val = Short.reverseBytes(val);
-
-        return val;
-    }
-
-    /**
-     * @param ptr Pointer.
-     * @param off Offset.
-     * @return Value.
-     */
-    public static short readShort(long ptr, int off) {
-        short val = UNSAFE.getShort(ptr + off);
-
-        if (BIG_ENDIAN)
-            val = Short.reverseBytes(val);
-
-        return val;
-    }
-
-    /**
-     * @param arr Array.
-     * @param off Offset.
-     * @param val Value.
-     */
-    public static void writeChar(byte[] arr, int off, char val) {
-        if (BIG_ENDIAN)
-            val = Character.reverseBytes(val);
-
-        UNSAFE.putChar(arr, BYTE_ARR_OFF + off, val);
-    }
-
-    /**
-     * @param arr Array.
-     * @param off Offset.
-     * @return Value.
-     */
-    public static char readChar(byte[] arr, int off) {
-        char val = UNSAFE.getChar(arr, BYTE_ARR_OFF + off);
-
-        if (BIG_ENDIAN)
-            val = Character.reverseBytes(val);
-
-        return val;
-    }
-
-    /**
-     * @param ptr Pointer.
-     * @param off Offset.
-     * @return Value.
-     */
-    public static char readChar(long ptr, int off) {
-        char val = UNSAFE.getChar(ptr + off);
-
-        if (BIG_ENDIAN)
-            val = Character.reverseBytes(val);
-
-        return val;
-    }
-
-    /**
-     * @param arr Array.
-     * @param off Offset.
-     * @return Value.
-     */
-    public static char[] readCharArray(byte[] arr, int off, int len) {
-        char[] arr0 = new char[len];
-
-        UNSAFE.copyMemory(arr, BYTE_ARR_OFF + off, arr0, CHAR_ARR_OFF, len << 1);
-
-        if (BIG_ENDIAN) {
-            for (int i = 0; i < len; i++)
-                arr0[i] = Character.reverseBytes(arr0[i]);
-        }
-
-        return arr0;
-    }
-
-    /**
-     * @param ptr Pointer.
-     * @param off Offset.
-     * @return Value.
-     */
-    public static char[] readCharArray(long ptr, int off, int len) {
-        char[] arr0 = new char[len];
-
-        UNSAFE.copyMemory(null, ptr + off, arr0, CHAR_ARR_OFF, len << 1);
-
-        if (BIG_ENDIAN) {
-            for (int i = 0; i < len; i++)
-                arr0[i] = Character.reverseBytes(arr0[i]);
-        }
-
-        return arr0;
-    }
-
-    /**
-     * @param arr Array.
-     * @param off Offset.
-     * @param val Value.
-     */
-    public static void writeInt(byte[] arr, int off, int val) {
-        if (BIG_ENDIAN)
-            val = Integer.reverseBytes(val);
-
-        UNSAFE.putInt(arr, BYTE_ARR_OFF + off, val);
-    }
-
-    /**
-     * @param arr Array.
-     * @param off Offset.
-     * @return Value.
-     */
-    public static int readInt(byte[] arr, int off) {
-        int val = UNSAFE.getInt(arr, BYTE_ARR_OFF + off);
-
-        if (BIG_ENDIAN)
-            val = Integer.reverseBytes(val);
-
-        return val;
-    }
-
-    /**
-     * @param ptr Pointer.
-     * @param off Offset.
-     * @return Value.
-     */
-    public static int readInt(long ptr, int off) {
-        int val = UNSAFE.getInt(ptr + off);
-
-        if (BIG_ENDIAN)
-            val = Integer.reverseBytes(val);
-
-        return val;
-    }
-
-    /**
-     * @param arr Array.
-     * @param off Offset.
-     * @param val Value.
-     */
-    public static void writeLong(byte[] arr, int off, long val) {
-        if (BIG_ENDIAN)
-            val = Long.reverseBytes(val);
-
-        UNSAFE.putLong(arr, BYTE_ARR_OFF + off, val);
-    }
-
-    /**
-     * @param arr Array.
-     * @param off Offset.
-     * @return Value.
-     */
-    public static long readLong(byte[] arr, int off) {
-        long val = UNSAFE.getLong(arr, BYTE_ARR_OFF + off);
-
-        if (BIG_ENDIAN)
-            val = Long.reverseBytes(val);
-
-        return val;
-    }
-
-    /**
-     * @param ptr Pointer.
-     * @param off Offset.
-     * @return Value.
-     */
-    public static long readLong(long ptr, int off) {
-        long val = UNSAFE.getLong(ptr + off);
-
-        if (BIG_ENDIAN)
-            val = Long.reverseBytes(val);
-
-        return val;
-    }
-
-    /**
-     * @param arr Array.
-     * @param off Offset.
-     * @param val Value.
-     */
-    public static void writeFloat(byte[] arr, int off, float val) {
-        int val0 = Float.floatToIntBits(val);
-
-        writeInt(arr, off, val0);
-    }
-
-    /**
-     * @param arr Array.
-     * @param off Offset.
-     * @return Value.
-     */
-    public static float readFloat(byte[] arr, int off) {
-        int val = readInt(arr, off);
-
-        return Float.intBitsToFloat(val);
-    }
-
-    /**
-     * @param ptr Pointer.
-     * @param off Offset.
-     * @return Value.
-     */
-    public static float readFloat(long ptr, int off) {
-        int val = readInt(ptr, off);
-
-        return Float.intBitsToFloat(val);
-    }
-
-    /**
-     * @param arr Array.
-     * @param off Offset.
-     * @param val Value.
-     */
-    public static void writeDouble(byte[] arr, int off, double val) {
-        long val0 = Double.doubleToLongBits(val);
-
-        writeLong(arr, off, val0);
-    }
-
-    /**
-     * @param arr Array.
-     * @param off Offset.
-     * @return Value.
-     */
-    public static double readDouble(byte[] arr, int off) {
-        long val = readLong(arr, off);
-
-        return Double.longBitsToDouble(val);
-    }
-
-    /**
-     * @param ptr Pointer.
-     * @param off Offset.
-     * @return Value.
-     */
-    public static double readDouble(long ptr, int off) {
-        long val = readLong(ptr, off);
-
-        return Double.longBitsToDouble(val);
-    }
-}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ignite/blob/1dbf20e0/modules/core/src/main/java/org/apache/ignite/internal/portable/PortableSchema.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/portable/PortableSchema.java b/modules/core/src/main/java/org/apache/ignite/internal/portable/PortableSchema.java
deleted file mode 100644
index 72a96b9..0000000
--- a/modules/core/src/main/java/org/apache/ignite/internal/portable/PortableSchema.java
+++ /dev/null
@@ -1,466 +0,0 @@
-/*
- * 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.portable;
-
-import java.io.Externalizable;
-import java.io.IOException;
-import java.io.ObjectInput;
-import java.io.ObjectOutput;
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.List;
-
-/**
- * Schema describing portable object content. We rely on the following assumptions:
- * - When amount of fields in the object is low, it is better to inline these values into int fields thus allowing
- * for quick comparisons performed within already fetched L1 cache line.
- * - When there are more fields, we store them inside a hash map.
- */
-public class PortableSchema implements Externalizable {
-    /** */
-    private static final long serialVersionUID = 0L;
-
-    /** Order returned if field is not found. */
-    public static final int ORDER_NOT_FOUND = -1;
-
-    /** Minimum sensible size. */
-    private static final int MAP_MIN_SIZE = 32;
-
-    /** Empty cell. */
-    private static final int MAP_EMPTY = 0;
-
-    /** Schema ID. */
-    private int schemaId;
-
-    /** IDs depending on order. */
-    private int[] ids;
-
-    /** Interned names of associated fields. */
-    private String[] names;
-
-    /** ID-to-order data. */
-    private int[] idToOrderData;
-
-    /** ID-to-order mask. */
-    private int idToOrderMask;
-
-    /** ID 1. */
-    private int id0;
-
-    /** ID 2. */
-    private int id1;
-
-    /** ID 3. */
-    private int id2;
-
-    /** ID 4. */
-    private int id3;
-
-    /**
-     * {@link Externalizable} support.
-     */
-    public PortableSchema() {
-        // No-op.
-    }
-
-    /**
-     * Constructor.
-     *
-     * @param schemaId Schema ID.
-     * @param fieldIds Field IDs.
-     */
-    private PortableSchema(int schemaId, List<Integer> fieldIds) {
-        assert fieldIds != null;
-
-        this.schemaId = schemaId;
-
-        initialize(fieldIds);
-    }
-
-    /**
-     * @return Schema ID.
-     */
-    public int schemaId() {
-        return schemaId;
-    }
-
-    /**
-     * Try speculatively confirming order for the given field name.
-     *
-     * @param expOrder Expected order.
-     * @param expName Expected name.
-     * @return Field ID.
-     */
-    @SuppressWarnings("StringEquality")
-    public Confirmation confirmOrder(int expOrder, String expName) {
-        assert expName != null;
-
-        if (expOrder < names.length) {
-            String name = names[expOrder];
-
-            // Note that we use only reference equality assuming that field names are interned literals.
-            if (name == expName)
-                return Confirmation.CONFIRMED;
-
-            if (name == null)
-                return Confirmation.CLARIFY;
-        }
-
-        return Confirmation.REJECTED;
-    }
-
-    /**
-     * Add field name.
-     *
-     * @param order Order.
-     * @param name Name.
-     */
-    public void clarifyFieldName(int order, String name) {
-        assert name != null;
-        assert order < names.length;
-
-        names[order] = name.intern();
-    }
-
-    /**
-     * Get field ID by order in footer.
-     *
-     * @param order Order.
-     * @return Field ID.
-     */
-    public int fieldId(int order) {
-        return order < ids.length ? ids[order] : 0;
-    }
-
-    /**
-     * Get field order in footer by field ID.
-     *
-     * @param id Field ID.
-     * @return Offset or {@code 0} if there is no such field.
-     */
-    public int order(int id) {
-        if (idToOrderData == null) {
-            if (id == id0)
-                return 0;
-
-            if (id == id1)
-                return 1;
-
-            if (id == id2)
-                return 2;
-
-            if (id == id3)
-                return 3;
-
-            return ORDER_NOT_FOUND;
-        }
-        else {
-            int idx = (id & idToOrderMask) << 1;
-
-            int curId = idToOrderData[idx];
-
-            if (id == curId) // Hit!
-                return idToOrderData[idx + 1];
-            else if (curId == MAP_EMPTY) // No such ID!
-                return ORDER_NOT_FOUND;
-            else {
-                // Unlikely collision scenario.
-                for (int i = 2; i < idToOrderData.length; i += 2) {
-                    int newIdx = (idx + i) % idToOrderData.length;
-
-                    assert newIdx < idToOrderData.length - 1;
-
-                    curId = idToOrderData[newIdx];
-
-                    if (id == curId)
-                        return idToOrderData[newIdx + 1];
-                    else if (curId == MAP_EMPTY)
-                        return ORDER_NOT_FOUND;
-                }
-
-                return ORDER_NOT_FOUND;
-            }
-        }
-    }
-
-    /** {@inheritDoc} */
-    @Override public int hashCode() {
-        return schemaId;
-    }
-
-    /** {@inheritDoc} */
-    @Override public boolean equals(Object o) {
-        return o != null && o instanceof PortableSchema && schemaId == ((PortableSchema)o).schemaId;
-    }
-
-    /** {@inheritDoc} */
-    @Override public void writeExternal(ObjectOutput out) throws IOException {
-        out.writeInt(schemaId);
-
-        out.writeInt(ids.length);
-
-        for (Integer id : ids)
-            out.writeInt(id);
-    }
-
-    /** {@inheritDoc} */
-    @Override public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
-        schemaId = in.readInt();
-
-        int idsCnt = in.readInt();
-
-        List<Integer> fieldIds = new ArrayList<>(idsCnt);
-
-        for (int i = 0; i < idsCnt; i++)
-            fieldIds.add(in.readInt());
-
-        initialize(fieldIds);
-    }
-
-    /**
-     * Parse values.
-     *
-     * @param vals Values.
-     * @param size Proposed result size.
-     * @return Parse result.
-     */
-    private static ParseResult parse(int[] vals, int size) {
-        int mask = maskForPowerOfTwo(size);
-
-        int totalSize = size * 2;
-
-        int[] data = new int[totalSize];
-        int collisions = 0;
-
-        for (int order = 0; order < vals.length; order++) {
-            int id = vals[order];
-
-            assert id != 0;
-
-            int idIdx = (id & mask) << 1;
-
-            if (data[idIdx] == 0) {
-                // Found empty slot.
-                data[idIdx] = id;
-                data[idIdx + 1] = order;
-            }
-            else {
-                // Collision!
-                collisions++;
-
-                boolean placeFound = false;
-
-                for (int i = 2; i < totalSize; i += 2) {
-                    int newIdIdx = (idIdx + i) % totalSize;
-
-                    if (data[newIdIdx] == 0) {
-                        data[newIdIdx] = id;
-                        data[newIdIdx + 1] = order;
-
-                        placeFound = true;
-
-                        break;
-                    }
-                }
-
-                assert placeFound : "Should always have a place for entry!";
-            }
-        }
-
-        return new ParseResult(data, collisions);
-    }
-
-    /**
-     * Get next power of two which greater or equal to the given number.
-     * This implementation is not meant to be very efficient, so it is expected to be used relatively rare.
-     *
-     * @param val Number
-     * @return Nearest pow2.
-     */
-    private static int nextPowerOfTwo(int val) {
-        int res = 1;
-
-        while (res < val)
-            res = res << 1;
-
-        if (res < 0)
-            throw new IllegalArgumentException("Value is too big to find positive pow2: " + val);
-
-        return res;
-    }
-
-    /**
-     * Calculate mask for the given value which is a power of two.
-     *
-     * @param val Value.
-     * @return Mask.
-     */
-    private static int maskForPowerOfTwo(int val) {
-        int mask = 0;
-        int comparand = 1;
-
-        while (comparand < val) {
-            mask |= comparand;
-
-            comparand <<= 1;
-        }
-
-        return mask;
-    }
-
-    /**
-     * Initialization routine.
-     *
-     * @param fieldIds Field IDs.
-     */
-    private void initialize(List<Integer> fieldIds) {
-        ids = new int[fieldIds.size()];
-
-        for (int i = 0; i < fieldIds.size(); i++)
-            ids[i] = fieldIds.get(i);
-
-        names = new String[fieldIds.size()];
-
-        if (fieldIds.size() <= 4) {
-            Iterator<Integer> iter = fieldIds.iterator();
-
-            id0 = iter.hasNext() ? iter.next() : 0;
-            id1 = iter.hasNext() ? iter.next() : 0;
-            id2 = iter.hasNext() ? iter.next() : 0;
-            id3 = iter.hasNext() ? iter.next() : 0;
-        }
-        else {
-            id0 = id1 = id2 = id3 = 0;
-
-            initializeMap(ids);
-        }
-    }
-
-    /**
-     * Initialize the map.
-     *
-     * @param vals Values.
-     */
-    private void initializeMap(int[] vals) {
-        int size = Math.max(nextPowerOfTwo(vals.length) << 2, MAP_MIN_SIZE);
-
-        assert size > 0;
-
-        ParseResult finalRes;
-
-        ParseResult res1 = parse(vals, size);
-
-        if (res1.collisions == 0)
-            finalRes = res1;
-        else {
-            ParseResult res2 = parse(vals, size * 2);
-
-            // Failed to decrease aom
-            if (res2.collisions == 0)
-                finalRes = res2;
-            else
-                finalRes = parse(vals, size * 4);
-        }
-
-        idToOrderData = finalRes.data;
-        idToOrderMask = maskForPowerOfTwo(idToOrderData.length / 2);
-    }
-
-    /**
-     * Schema builder.
-     */
-    public static class Builder {
-        /** Schema ID. */
-        private int schemaId = PortableUtils.schemaInitialId();
-
-        /** Fields. */
-        private final ArrayList<Integer> fields = new ArrayList<>();
-
-        /**
-         * Create new schema builder.
-         *
-         * @return Schema builder.
-         */
-        public static Builder newBuilder() {
-            return new Builder();
-        }
-
-        /**
-         * Private constructor.
-         */
-        private Builder() {
-            // No-op.
-        }
-
-        /**
-         * Add field.
-         *
-         * @param fieldId Field ID.
-         */
-        public void addField(int fieldId) {
-            fields.add(fieldId);
-
-            schemaId = PortableUtils.updateSchemaId(schemaId, fieldId);
-        }
-
-        /**
-         * Build schema.
-         *
-         * @return Schema.
-         */
-        public PortableSchema build() {
-            return new PortableSchema(schemaId, fields);
-        }
-    }
-
-    /**
-     * Order confirmation result.
-     */
-    public enum Confirmation {
-        /** Confirmed. */
-        CONFIRMED,
-
-        /** Denied. */
-        REJECTED,
-
-        /** Field name clarification is needed. */
-        CLARIFY
-    }
-
-    /**
-     * Result of map parsing.
-     */
-    private static class ParseResult {
-        /** Data. */
-        private int[] data;
-
-        /** Collisions. */
-        private int collisions;
-
-        /**
-         * Constructor.
-         *
-         * @param data Data.
-         * @param collisions Collisions.
-         */
-        private ParseResult(int[] data, int collisions) {
-            this.data = data;
-            this.collisions = collisions;
-        }
-    }
-}


[14/59] [abbrv] ignite git commit: ignite-2065: rename "portable" packages to "binary"

Posted by ak...@apache.org.
http://git-wip-us.apache.org/repos/asf/ignite/blob/1dbf20e0/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/portable/CacheObjectBinaryProcessorImpl.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/portable/CacheObjectBinaryProcessorImpl.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/portable/CacheObjectBinaryProcessorImpl.java
deleted file mode 100644
index cd65681..0000000
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/portable/CacheObjectBinaryProcessorImpl.java
+++ /dev/null
@@ -1,895 +0,0 @@
-/*
- * 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.processors.cache.portable;
-
-import java.io.Externalizable;
-import java.io.IOException;
-import java.io.ObjectInput;
-import java.io.ObjectOutput;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Map;
-import java.util.Set;
-import java.util.UUID;
-import java.util.concurrent.ConcurrentHashMap;
-import java.util.concurrent.CountDownLatch;
-import javax.cache.Cache;
-import javax.cache.CacheException;
-import javax.cache.event.CacheEntryEvent;
-import javax.cache.event.CacheEntryListenerException;
-import javax.cache.event.CacheEntryUpdatedListener;
-import javax.cache.event.EventType;
-import javax.cache.processor.EntryProcessor;
-import javax.cache.processor.MutableEntry;
-import org.apache.ignite.IgniteBinary;
-import org.apache.ignite.IgniteCheckedException;
-import org.apache.ignite.IgniteException;
-import org.apache.ignite.binary.BinaryObject;
-import org.apache.ignite.binary.BinaryObjectBuilder;
-import org.apache.ignite.binary.BinaryObjectException;
-import org.apache.ignite.binary.BinaryType;
-import org.apache.ignite.cache.CacheEntryEventSerializableFilter;
-import org.apache.ignite.cluster.ClusterNode;
-import org.apache.ignite.cluster.ClusterTopologyException;
-import org.apache.ignite.configuration.CacheConfiguration;
-import org.apache.ignite.internal.GridKernalContext;
-import org.apache.ignite.internal.cluster.ClusterTopologyCheckedException;
-import org.apache.ignite.internal.portable.BinaryEnumObjectImpl;
-import org.apache.ignite.internal.portable.BinaryMarshaller;
-import org.apache.ignite.internal.portable.BinaryMetadata;
-import org.apache.ignite.internal.portable.BinaryMetadataHandler;
-import org.apache.ignite.internal.portable.BinaryObjectEx;
-import org.apache.ignite.internal.portable.BinaryObjectImpl;
-import org.apache.ignite.internal.portable.BinaryObjectOffheapImpl;
-import org.apache.ignite.internal.portable.BinaryTypeImpl;
-import org.apache.ignite.internal.portable.GridPortableMarshaller;
-import org.apache.ignite.internal.portable.PortableContext;
-import org.apache.ignite.internal.portable.PortableUtils;
-import org.apache.ignite.internal.portable.builder.BinaryObjectBuilderImpl;
-import org.apache.ignite.internal.portable.streams.PortableInputStream;
-import org.apache.ignite.internal.portable.streams.PortableOffheapInputStream;
-import org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion;
-import org.apache.ignite.internal.processors.cache.CacheEntryPredicate;
-import org.apache.ignite.internal.processors.cache.CacheEntryPredicateAdapter;
-import org.apache.ignite.internal.processors.cache.CacheObject;
-import org.apache.ignite.internal.processors.cache.CacheObjectContext;
-import org.apache.ignite.internal.processors.cache.CacheObjectImpl;
-import org.apache.ignite.internal.processors.cache.GridCacheContext;
-import org.apache.ignite.internal.processors.cache.GridCacheEntryEx;
-import org.apache.ignite.internal.processors.cache.GridCacheUtils;
-import org.apache.ignite.internal.processors.cache.IgniteCacheProxy;
-import org.apache.ignite.internal.processors.cache.KeyCacheObject;
-import org.apache.ignite.internal.processors.cache.query.CacheQuery;
-import org.apache.ignite.internal.processors.cache.query.CacheQueryFuture;
-import org.apache.ignite.internal.processors.cache.query.GridCacheQueryManager;
-import org.apache.ignite.internal.processors.cacheobject.IgniteCacheObjectProcessorImpl;
-import org.apache.ignite.internal.util.GridUnsafe;
-import org.apache.ignite.internal.util.IgniteUtils;
-import org.apache.ignite.internal.util.lang.GridMapEntry;
-import org.apache.ignite.internal.util.tostring.GridToStringExclude;
-import org.apache.ignite.internal.util.typedef.C1;
-import org.apache.ignite.internal.util.typedef.F;
-import org.apache.ignite.internal.util.typedef.T2;
-import org.apache.ignite.internal.util.typedef.X;
-import org.apache.ignite.internal.util.typedef.internal.CU;
-import org.apache.ignite.internal.util.typedef.internal.S;
-import org.apache.ignite.internal.util.typedef.internal.U;
-import org.apache.ignite.lang.IgniteBiPredicate;
-import org.apache.ignite.lang.IgniteBiTuple;
-import org.apache.ignite.lang.IgniteClosure;
-import org.apache.ignite.marshaller.Marshaller;
-import org.jetbrains.annotations.Nullable;
-import org.jsr166.ConcurrentHashMap8;
-import sun.misc.Unsafe;
-
-/**
- * Portable processor implementation.
- */
-public class CacheObjectBinaryProcessorImpl extends IgniteCacheObjectProcessorImpl implements
-    CacheObjectBinaryProcessor {
-    /** */
-    private static final Unsafe UNSAFE = GridUnsafe.unsafe();
-
-    /** */
-    private final CountDownLatch startLatch = new CountDownLatch(1);
-
-    /** */
-    private final boolean clientNode;
-
-    /** */
-    private volatile IgniteCacheProxy<PortableMetadataKey, BinaryMetadata> metaDataCache;
-
-    /** */
-    private final ConcurrentHashMap8<Integer, BinaryTypeImpl> clientMetaDataCache;
-
-    /** Predicate to filter portable meta data in utility cache. */
-    private final CacheEntryPredicate metaPred = new CacheEntryPredicateAdapter() {
-        private static final long serialVersionUID = 0L;
-
-        @Override public boolean apply(GridCacheEntryEx e) {
-            return e.key().value(e.context().cacheObjectContext(), false) instanceof PortableMetadataKey;
-        }
-    };
-
-    /** */
-    private PortableContext portableCtx;
-
-    /** */
-    private Marshaller marsh;
-
-    /** */
-    private GridPortableMarshaller portableMarsh;
-
-    /** */
-    @GridToStringExclude
-    private IgniteBinary portables;
-
-    /** Metadata updates collected before metadata cache is initialized. */
-    private final Map<Integer, BinaryMetadata> metaBuf = new ConcurrentHashMap<>();
-
-    /** */
-    private UUID metaCacheQryId;
-
-    /**
-     * @param ctx Kernal context.
-     */
-    public CacheObjectBinaryProcessorImpl(GridKernalContext ctx) {
-        super(ctx);
-
-        marsh = ctx.grid().configuration().getMarshaller();
-
-        clientNode = this.ctx.clientNode();
-
-        clientMetaDataCache = clientNode ? new ConcurrentHashMap8<Integer, BinaryTypeImpl>() : null;
-    }
-
-    /** {@inheritDoc} */
-    @Override public void start() throws IgniteCheckedException {
-        if (marsh instanceof BinaryMarshaller) {
-            BinaryMetadataHandler metaHnd = new BinaryMetadataHandler() {
-                @Override public void addMeta(int typeId, BinaryType newMeta) throws BinaryObjectException {
-                    assert newMeta != null;
-                    assert newMeta instanceof BinaryTypeImpl;
-
-                    BinaryMetadata newMeta0 = ((BinaryTypeImpl)newMeta).metadata();
-
-                    if (metaDataCache == null) {
-                        BinaryMetadata oldMeta = metaBuf.get(typeId);
-                        BinaryMetadata mergedMeta = PortableUtils.mergeMetadata(oldMeta, newMeta0);
-
-                        if (oldMeta != mergedMeta) {
-                            synchronized (this) {
-                                mergedMeta = PortableUtils.mergeMetadata(oldMeta, newMeta0);
-
-                                if (oldMeta != mergedMeta)
-                                    metaBuf.put(typeId, mergedMeta);
-                                else
-                                    return;
-                            }
-
-                            if (metaDataCache == null)
-                                return;
-                            else
-                                metaBuf.remove(typeId);
-                        }
-                        else
-                            return;
-                    }
-
-                    assert metaDataCache != null;
-
-                    CacheObjectBinaryProcessorImpl.this.addMeta(typeId, newMeta0.wrap(portableCtx));
-                }
-
-                @Override public BinaryType metadata(int typeId) throws BinaryObjectException {
-                    if (metaDataCache == null)
-                        U.awaitQuiet(startLatch);
-
-                    return CacheObjectBinaryProcessorImpl.this.metadata(typeId);
-                }
-            };
-
-            BinaryMarshaller pMarh0 = (BinaryMarshaller)marsh;
-
-            portableCtx = new PortableContext(metaHnd, ctx.config());
-
-            IgniteUtils.invoke(BinaryMarshaller.class, pMarh0, "setPortableContext", portableCtx,
-                ctx.config());
-
-            portableMarsh = new GridPortableMarshaller(portableCtx);
-
-            portables = new IgniteBinaryImpl(ctx, this);
-        }
-    }
-
-    /** {@inheritDoc} */
-    @SuppressWarnings("unchecked")
-    @Override public void onUtilityCacheStarted() throws IgniteCheckedException {
-        IgniteCacheProxy<Object, Object> proxy = ctx.cache().jcache(CU.UTILITY_CACHE_NAME);
-
-        boolean old = proxy.context().deploy().ignoreOwnership(true);
-
-        try {
-            metaDataCache = (IgniteCacheProxy)proxy.withNoRetries();
-        }
-        finally {
-            proxy.context().deploy().ignoreOwnership(old);
-        }
-
-        if (clientNode) {
-            assert !metaDataCache.context().affinityNode();
-
-            metaCacheQryId = metaDataCache.context().continuousQueries().executeInternalQuery(
-                new MetaDataEntryListener(),
-                new MetaDataEntryFilter(),
-                false,
-                true);
-
-            while (true) {
-                ClusterNode oldestSrvNode =
-                    CU.oldestAliveCacheServerNode(ctx.cache().context(), AffinityTopologyVersion.NONE);
-
-                if (oldestSrvNode == null)
-                    break;
-
-                GridCacheQueryManager qryMgr = metaDataCache.context().queries();
-
-                CacheQuery<Map.Entry<PortableMetadataKey, BinaryMetadata>> qry =
-                    qryMgr.createScanQuery(new MetaDataPredicate(), null, false);
-
-                qry.keepAll(false);
-
-                qry.projection(ctx.cluster().get().forNode(oldestSrvNode));
-
-                try {
-                    CacheQueryFuture<Map.Entry<PortableMetadataKey, BinaryMetadata>> fut = qry.execute();
-
-                    Map.Entry<PortableMetadataKey, BinaryMetadata> next;
-
-                    while ((next = fut.next()) != null) {
-                        assert next.getKey() != null : next;
-                        assert next.getValue() != null : next;
-
-                        addClientCacheMetaData(next.getKey(), next.getValue());
-                    }
-                }
-                catch (IgniteCheckedException e) {
-                    if (!ctx.discovery().alive(oldestSrvNode) || !ctx.discovery().pingNode(oldestSrvNode.id()))
-                        continue;
-                    else
-                        throw e;
-                }
-                catch (CacheException e) {
-                    if (X.hasCause(e, ClusterTopologyCheckedException.class, ClusterTopologyException.class))
-                        continue;
-                    else
-                        throw e;
-                }
-
-                break;
-            }
-        }
-
-        for (Map.Entry<Integer, BinaryMetadata> e : metaBuf.entrySet())
-            addMeta(e.getKey(), e.getValue().wrap(portableCtx));
-
-        metaBuf.clear();
-
-        startLatch.countDown();
-    }
-
-    /** {@inheritDoc} */
-    @Override public void onKernalStop(boolean cancel) {
-        super.onKernalStop(cancel);
-
-        if (metaCacheQryId != null)
-            metaDataCache.context().continuousQueries().cancelInternalQuery(metaCacheQryId);
-    }
-
-    /**
-     * @param key Metadata key.
-     * @param newMeta Metadata.
-     */
-    private void addClientCacheMetaData(PortableMetadataKey key, final BinaryMetadata newMeta) {
-        int key0 = key.typeId();
-
-        clientMetaDataCache.compute(key0, new ConcurrentHashMap8.BiFun<Integer, BinaryTypeImpl, BinaryTypeImpl>() {
-            @Override public BinaryTypeImpl apply(Integer key, BinaryTypeImpl oldMeta) {
-                BinaryMetadata res;
-
-                BinaryMetadata oldMeta0 = oldMeta != null ? oldMeta.metadata() : null;
-
-                try {
-                    res = PortableUtils.mergeMetadata(oldMeta0, newMeta);
-                }
-                catch (BinaryObjectException e) {
-                    res = oldMeta0;
-                }
-
-                return res != null ? res.wrap(portableCtx) : null;
-            }
-        });
-    }
-
-    /** {@inheritDoc} */
-    @Override public int typeId(String typeName) {
-        if (portableCtx == null)
-            return super.typeId(typeName);
-
-        return portableCtx.typeId(typeName);
-    }
-
-    /**
-     * @param obj Object.
-     * @return Bytes.
-     * @throws org.apache.ignite.binary.BinaryObjectException If failed.
-     */
-    public byte[] marshal(@Nullable Object obj) throws BinaryObjectException {
-        byte[] arr = portableMarsh.marshal(obj);
-
-        assert arr.length > 0;
-
-        return arr;
-    }
-
-    /**
-     * @param ptr Off-heap pointer.
-     * @param forceHeap If {@code true} creates heap-based object.
-     * @return Object.
-     * @throws org.apache.ignite.binary.BinaryObjectException If failed.
-     */
-    public Object unmarshal(long ptr, boolean forceHeap) throws BinaryObjectException {
-        assert ptr > 0 : ptr;
-
-        int size = UNSAFE.getInt(ptr);
-
-        ptr += 4;
-
-        byte type = UNSAFE.getByte(ptr++);
-
-        if (type != CacheObject.TYPE_BYTE_ARR) {
-            assert size > 0 : size;
-
-            PortableInputStream in = new PortableOffheapInputStream(ptr, size, forceHeap);
-
-            return portableMarsh.unmarshal(in);
-        }
-        else
-            return U.copyMemory(ptr, size);
-    }
-
-    /** {@inheritDoc} */
-    @SuppressWarnings("unchecked")
-    @Override public Object marshalToPortable(@Nullable Object obj) throws BinaryObjectException {
-        if (obj == null)
-            return null;
-
-        if (PortableUtils.isPortableType(obj.getClass()))
-            return obj;
-
-        if (obj instanceof Object[]) {
-            Object[] arr = (Object[])obj;
-
-            Object[] pArr = new Object[arr.length];
-
-            for (int i = 0; i < arr.length; i++)
-                pArr[i] = marshalToPortable(arr[i]);
-
-            return pArr;
-        }
-
-        if (obj instanceof IgniteBiTuple) {
-            IgniteBiTuple tup = (IgniteBiTuple)obj;
-
-            if (obj instanceof T2)
-                return new T2<>(marshalToPortable(tup.get1()), marshalToPortable(tup.get2()));
-
-            return new IgniteBiTuple<>(marshalToPortable(tup.get1()), marshalToPortable(tup.get2()));
-        }
-
-        if (obj instanceof Collection) {
-            Collection<Object> col = (Collection<Object>)obj;
-
-            Collection<Object> pCol;
-
-            if (col instanceof Set)
-                pCol = (Collection<Object>)PortableUtils.newSet((Set<?>)col);
-            else
-                pCol = new ArrayList<>(col.size());
-
-            for (Object item : col)
-                pCol.add(marshalToPortable(item));
-
-            return pCol;
-        }
-
-        if (obj instanceof Map) {
-            Map<?, ?> map = (Map<?, ?>)obj;
-
-            Map<Object, Object> pMap = PortableUtils.newMap((Map<Object, Object>)obj);
-
-            for (Map.Entry<?, ?> e : map.entrySet())
-                pMap.put(marshalToPortable(e.getKey()), marshalToPortable(e.getValue()));
-
-            return pMap;
-        }
-
-        if (obj instanceof Map.Entry) {
-            Map.Entry<?, ?> e = (Map.Entry<?, ?>)obj;
-
-            return new GridMapEntry<>(marshalToPortable(e.getKey()), marshalToPortable(e.getValue()));
-        }
-
-        byte[] arr = portableMarsh.marshal(obj);
-
-        assert arr.length > 0;
-
-        Object obj0 = portableMarsh.unmarshal(arr, null);
-
-        // Possible if a class has writeObject method.
-        if (obj0 instanceof BinaryObject)
-            ((BinaryObjectImpl)obj0).detachAllowed(true);
-
-        return obj0;
-    }
-
-    /**
-     * @return Marshaller.
-     */
-    public GridPortableMarshaller marshaller() {
-        return portableMarsh;
-    }
-
-    /** {@inheritDoc} */
-    @Override public BinaryObjectBuilder builder(String clsName) {
-        return new BinaryObjectBuilderImpl(portableCtx, clsName);
-    }
-
-    /** {@inheritDoc} */
-    @Override public BinaryObjectBuilder builder(BinaryObject portableObj) {
-        return BinaryObjectBuilderImpl.wrap(portableObj);
-    }
-
-    /** {@inheritDoc} */
-    @Override public void updateMetadata(int typeId, String typeName, @Nullable String affKeyFieldName,
-        Map<String, Integer> fieldTypeIds, boolean isEnum) throws BinaryObjectException {
-        BinaryMetadata meta = new BinaryMetadata(typeId, typeName, fieldTypeIds, affKeyFieldName, null, isEnum);
-
-        portableCtx.updateMetadata(typeId, meta);
-    }
-
-    /** {@inheritDoc} */
-    @Override public void addMeta(final int typeId, final BinaryType newMeta) throws BinaryObjectException {
-        assert newMeta != null;
-        assert newMeta instanceof BinaryTypeImpl;
-
-        BinaryMetadata newMeta0 = ((BinaryTypeImpl)newMeta).metadata();
-
-        final PortableMetadataKey key = new PortableMetadataKey(typeId);
-
-        try {
-            BinaryMetadata oldMeta = metaDataCache.localPeek(key);
-            BinaryMetadata mergedMeta = PortableUtils.mergeMetadata(oldMeta, newMeta0);
-
-            BinaryObjectException err = metaDataCache.invoke(key, new MetadataProcessor(mergedMeta));
-
-            if (err != null)
-                throw err;
-        }
-        catch (CacheException e) {
-            throw new BinaryObjectException("Failed to update meta data for type: " + newMeta.typeName(), e);
-        }
-    }
-
-    /** {@inheritDoc} */
-    @Nullable @Override public BinaryType metadata(final int typeId) throws BinaryObjectException {
-        try {
-            if (clientNode)
-                return clientMetaDataCache.get(typeId);
-            else {
-                PortableMetadataKey key = new PortableMetadataKey(typeId);
-
-                BinaryMetadata meta = metaDataCache.localPeek(key);
-
-                if (meta == null && !metaDataCache.context().preloader().syncFuture().isDone())
-                    meta = metaDataCache.getTopologySafe(key);
-
-                return meta != null ? meta.wrap(portableCtx) : null;
-            }
-        }
-        catch (CacheException e) {
-            throw new BinaryObjectException(e);
-        }
-    }
-
-    /** {@inheritDoc} */
-    @Override public Map<Integer, BinaryType> metadata(Collection<Integer> typeIds)
-        throws BinaryObjectException {
-        try {
-            Collection<PortableMetadataKey> keys = new ArrayList<>(typeIds.size());
-
-            for (Integer typeId : typeIds)
-                keys.add(new PortableMetadataKey(typeId));
-
-            Map<PortableMetadataKey, BinaryMetadata> meta = metaDataCache.getAll(keys);
-
-            Map<Integer, BinaryType> res = U.newHashMap(meta.size());
-
-            for (Map.Entry<PortableMetadataKey, BinaryMetadata> e : meta.entrySet())
-                res.put(e.getKey().typeId(), e.getValue().wrap(portableCtx));
-
-            return res;
-        }
-        catch (CacheException e) {
-            throw new BinaryObjectException(e);
-        }
-    }
-
-    /** {@inheritDoc} */
-    @SuppressWarnings("unchecked")
-    @Override public Collection<BinaryType> metadata() throws BinaryObjectException {
-        if (clientNode)
-            return F.viewReadOnly(clientMetaDataCache.values(), new IgniteClosure<BinaryTypeImpl, BinaryType>() {
-                @Override public BinaryType apply(BinaryTypeImpl meta) {
-                    return meta;
-                }
-            });
-        else {
-            return F.viewReadOnly(metaDataCache.entrySetx(metaPred),
-                new C1<Cache.Entry<PortableMetadataKey, BinaryMetadata>, BinaryType>() {
-                    private static final long serialVersionUID = 0L;
-
-                    @Override public BinaryType apply(Cache.Entry<PortableMetadataKey, BinaryMetadata> e) {
-                        return e.getValue().wrap(portableCtx);
-                    }
-                });
-        }
-    }
-
-    /** {@inheritDoc} */
-    @Override public BinaryObject buildEnum(String typeName, int ord) throws IgniteException {
-        typeName = PortableContext.typeName(typeName);
-
-        int typeId = portableCtx.typeId(typeName);
-
-        updateMetadata(typeId, typeName, null, null, true);
-
-        return new BinaryEnumObjectImpl(portableCtx, typeId, null, ord);
-    }
-
-    /** {@inheritDoc} */
-    @Override public IgniteBinary binary() throws IgniteException {
-        return portables;
-    }
-
-    /** {@inheritDoc} */
-    @Override public boolean isPortableObject(Object obj) {
-        return obj instanceof BinaryObject;
-    }
-
-    /** {@inheritDoc} */
-    @Override public boolean isPortableEnabled(CacheConfiguration<?, ?> ccfg) {
-        return marsh instanceof BinaryMarshaller;
-    }
-
-    /**
-     * @param po Portable object.
-     * @return Affinity key.
-     */
-    public Object affinityKey(BinaryObject po) {
-        try {
-            BinaryType meta = po.type();
-
-            if (meta != null) {
-                String affKeyFieldName = meta.affinityKeyFieldName();
-
-                if (affKeyFieldName != null)
-                    return po.field(affKeyFieldName);
-            }
-            else if (po instanceof BinaryObjectEx) {
-                int id = ((BinaryObjectEx)po).typeId();
-
-                String affKeyFieldName = portableCtx.affinityKeyFieldName(id);
-
-                if (affKeyFieldName != null)
-                    return po.field(affKeyFieldName);
-            }
-        }
-        catch (BinaryObjectException e) {
-            U.error(log, "Failed to get affinity field from portable object: " + po, e);
-        }
-
-        return po;
-    }
-
-    /** {@inheritDoc} */
-    @Override public int typeId(Object obj) {
-        if (obj == null)
-            return 0;
-
-        return isPortableObject(obj) ? ((BinaryObjectEx)obj).typeId() : typeId(obj.getClass().getSimpleName());
-    }
-
-    /** {@inheritDoc} */
-    @Override public Object field(Object obj, String fieldName) {
-        if (obj == null)
-            return null;
-
-        return isPortableObject(obj) ? ((BinaryObject)obj).field(fieldName) : super.field(obj, fieldName);
-    }
-
-    /** {@inheritDoc} */
-    @Override public boolean hasField(Object obj, String fieldName) {
-        return obj != null && ((BinaryObject)obj).hasField(fieldName);
-    }
-
-    /**
-     * @return Portable context.
-     */
-    public PortableContext portableContext() {
-        return portableCtx;
-    }
-
-    /** {@inheritDoc} */
-    @Override public CacheObjectContext contextForCache(CacheConfiguration cfg) throws IgniteCheckedException {
-        assert cfg != null;
-
-        boolean portableEnabled = marsh instanceof BinaryMarshaller && !GridCacheUtils.isSystemCache(cfg.getName()) &&
-            !GridCacheUtils.isIgfsCache(ctx.config(), cfg.getName());
-
-        CacheObjectContext ctx0 = super.contextForCache(cfg);
-
-        CacheObjectContext res = new CacheObjectPortableContext(ctx,
-            ctx0.copyOnGet(),
-            ctx0.storeValue(),
-            portableEnabled,
-            ctx0.addDeploymentInfo());
-
-        ctx.resource().injectGeneric(res.defaultAffMapper());
-
-        return res;
-    }
-
-    /** {@inheritDoc} */
-    @Override public byte[] marshal(CacheObjectContext ctx, Object val) throws IgniteCheckedException {
-        if (!((CacheObjectPortableContext)ctx).portableEnabled() || portableMarsh == null)
-            return super.marshal(ctx, val);
-
-        byte[] arr = portableMarsh.marshal(val);
-
-        assert arr.length > 0;
-
-        return arr;
-    }
-
-    /** {@inheritDoc} */
-    @Override public Object unmarshal(CacheObjectContext ctx, byte[] bytes, ClassLoader clsLdr)
-        throws IgniteCheckedException {
-        if (!((CacheObjectPortableContext)ctx).portableEnabled() || portableMarsh == null)
-            return super.unmarshal(ctx, bytes, clsLdr);
-
-        return portableMarsh.unmarshal(bytes, clsLdr);
-    }
-
-    /** {@inheritDoc} */
-    @Override public KeyCacheObject toCacheKeyObject(CacheObjectContext ctx, Object obj, boolean userObj) {
-        if (!((CacheObjectPortableContext)ctx).portableEnabled())
-            return super.toCacheKeyObject(ctx, obj, userObj);
-
-        if (obj instanceof KeyCacheObject)
-            return (KeyCacheObject)obj;
-
-        if (((CacheObjectPortableContext)ctx).portableEnabled()) {
-            obj = toPortable(obj);
-
-            if (obj instanceof BinaryObject)
-                return (BinaryObjectImpl)obj;
-        }
-
-        return toCacheKeyObject0(obj, userObj);
-    }
-
-    /** {@inheritDoc} */
-    @Nullable @Override public CacheObject toCacheObject(CacheObjectContext ctx, @Nullable Object obj,
-        boolean userObj) {
-        if (!((CacheObjectPortableContext)ctx).portableEnabled())
-            return super.toCacheObject(ctx, obj, userObj);
-
-        if (obj == null || obj instanceof CacheObject)
-            return (CacheObject)obj;
-
-        obj = toPortable(obj);
-
-        if (obj instanceof BinaryObject)
-            return (BinaryObjectImpl)obj;
-
-        return toCacheObject0(obj, userObj);
-    }
-
-    /** {@inheritDoc} */
-    @Override public CacheObject toCacheObject(CacheObjectContext ctx, byte type, byte[] bytes) {
-        if (type == BinaryObjectImpl.TYPE_BINARY)
-            return new BinaryObjectImpl(portableContext(), bytes, 0);
-
-        return super.toCacheObject(ctx, type, bytes);
-    }
-
-    /** {@inheritDoc} */
-    @Override public CacheObject toCacheObject(GridCacheContext ctx, long valPtr, boolean tmp)
-        throws IgniteCheckedException {
-        if (!((CacheObjectPortableContext)ctx.cacheObjectContext()).portableEnabled())
-            return super.toCacheObject(ctx, valPtr, tmp);
-
-        Object val = unmarshal(valPtr, !tmp);
-
-        if (val instanceof BinaryObjectOffheapImpl)
-            return (BinaryObjectOffheapImpl)val;
-
-        return new CacheObjectImpl(val, null);
-    }
-
-    /** {@inheritDoc} */
-    @Override public Object unwrapTemporary(GridCacheContext ctx, Object obj) throws BinaryObjectException {
-        if (!((CacheObjectPortableContext)ctx.cacheObjectContext()).portableEnabled())
-            return obj;
-
-        if (obj instanceof BinaryObjectOffheapImpl)
-            return ((BinaryObjectOffheapImpl)obj).heapCopy();
-
-        return obj;
-    }
-
-    /**
-     * @param obj Object.
-     * @return Portable object.
-     * @throws IgniteException In case of error.
-     */
-    @Nullable public Object toPortable(@Nullable Object obj) throws IgniteException {
-        if (obj == null)
-            return null;
-
-        if (isPortableObject(obj))
-            return obj;
-
-        return marshalToPortable(obj);
-    }
-
-    /**
-     * Processor responsible for metadata update.
-     */
-    private static class MetadataProcessor
-        implements EntryProcessor<PortableMetadataKey, BinaryMetadata, BinaryObjectException>, Externalizable {
-        /** */
-        private static final long serialVersionUID = 0L;
-
-        /** */
-        private BinaryMetadata newMeta;
-
-        /**
-         * For {@link Externalizable}.
-         */
-        public MetadataProcessor() {
-            // No-op.
-        }
-
-        /**
-         * @param newMeta New metadata.
-         */
-        private MetadataProcessor(BinaryMetadata newMeta) {
-            assert newMeta != null;
-
-            this.newMeta = newMeta;
-        }
-
-        /** {@inheritDoc} */
-        @Override public BinaryObjectException process(MutableEntry<PortableMetadataKey, BinaryMetadata> entry,
-            Object... args) {
-            try {
-                BinaryMetadata oldMeta = entry.getValue();
-
-                BinaryMetadata mergedMeta = PortableUtils.mergeMetadata(oldMeta, newMeta);
-
-                if (mergedMeta != oldMeta)
-                    entry.setValue(mergedMeta);
-
-                return null;
-            }
-            catch (BinaryObjectException e) {
-                return e;
-            }
-        }
-
-        /** {@inheritDoc} */
-        @Override public void writeExternal(ObjectOutput out) throws IOException {
-            out.writeObject(newMeta);
-        }
-
-        /** {@inheritDoc} */
-        @Override public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
-            newMeta = (BinaryMetadata)in.readObject();
-        }
-
-        /** {@inheritDoc} */
-        @Override public String toString() {
-            return S.toString(MetadataProcessor.class, this);
-        }
-    }
-
-    /**
-     *
-     */
-    class MetaDataEntryListener implements CacheEntryUpdatedListener<PortableMetadataKey, BinaryMetadata> {
-        /** {@inheritDoc} */
-        @Override public void onUpdated(
-            Iterable<CacheEntryEvent<? extends PortableMetadataKey, ? extends BinaryMetadata>> evts)
-            throws CacheEntryListenerException {
-            for (CacheEntryEvent<? extends PortableMetadataKey, ? extends BinaryMetadata> evt : evts) {
-                assert evt.getEventType() == EventType.CREATED || evt.getEventType() == EventType.UPDATED : evt;
-
-                PortableMetadataKey key = evt.getKey();
-
-                final BinaryMetadata newMeta = evt.getValue();
-
-                assert newMeta != null : evt;
-
-                addClientCacheMetaData(key, newMeta);
-            }
-        }
-
-        /** {@inheritDoc} */
-        @Override public String toString() {
-            return S.toString(MetaDataEntryListener.class, this);
-        }
-    }
-
-    /**
-     *
-     */
-    static class MetaDataEntryFilter implements CacheEntryEventSerializableFilter<Object, Object> {
-        /** */
-        private static final long serialVersionUID = 0L;
-
-        /** {@inheritDoc} */
-        @Override public boolean evaluate(CacheEntryEvent<?, ?> evt) throws CacheEntryListenerException {
-            return evt.getKey() instanceof PortableMetadataKey;
-        }
-
-        /** {@inheritDoc} */
-        @Override public String toString() {
-            return S.toString(MetaDataEntryFilter.class, this);
-        }
-    }
-
-    /**
-     *
-     */
-    static class MetaDataPredicate implements IgniteBiPredicate<Object, Object> {
-        /** */
-        private static final long serialVersionUID = 0L;
-
-        /** {@inheritDoc} */
-        @Override public boolean apply(Object key, Object val) {
-            return key instanceof PortableMetadataKey;
-        }
-
-        /** {@inheritDoc} */
-        @Override public String toString() {
-            return S.toString(MetaDataPredicate.class, this);
-        }
-    }
-}

http://git-wip-us.apache.org/repos/asf/ignite/blob/1dbf20e0/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/portable/CacheObjectPortableContext.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/portable/CacheObjectPortableContext.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/portable/CacheObjectPortableContext.java
deleted file mode 100644
index 719d0a9..0000000
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/portable/CacheObjectPortableContext.java
+++ /dev/null
@@ -1,56 +0,0 @@
-/*
- * 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.processors.cache.portable;
-
-import org.apache.ignite.internal.GridKernalContext;
-import org.apache.ignite.internal.processors.cache.CacheDefaultBinaryAffinityKeyMapper;
-import org.apache.ignite.internal.processors.cache.CacheObjectContext;
-import org.apache.ignite.internal.processors.cache.GridCacheDefaultAffinityKeyMapper;
-
-/**
- *
- */
-public class CacheObjectPortableContext extends CacheObjectContext {
-    /** */
-    private boolean portableEnabled;
-
-    /**
-     * @param kernalCtx Kernal context.
-     * @param portableEnabled Portable enabled flag.
-     * @param cpyOnGet Copy on get flag.
-     * @param storeVal {@code True} if should store unmarshalled value in cache.
-     * @param depEnabled {@code true} if deployment is enabled for the given cache.
-     */
-    public CacheObjectPortableContext(GridKernalContext kernalCtx,
-        boolean cpyOnGet,
-        boolean storeVal,
-        boolean portableEnabled,
-        boolean depEnabled) {
-        super(kernalCtx, portableEnabled ? new CacheDefaultBinaryAffinityKeyMapper() :
-            new GridCacheDefaultAffinityKeyMapper(), cpyOnGet, storeVal, depEnabled);
-
-        this.portableEnabled = portableEnabled;
-    }
-
-    /**
-     * @return Portable enabled flag.
-     */
-    public boolean portableEnabled() {
-        return portableEnabled;
-    }
-}

http://git-wip-us.apache.org/repos/asf/ignite/blob/1dbf20e0/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/portable/IgniteBinaryImpl.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/portable/IgniteBinaryImpl.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/portable/IgniteBinaryImpl.java
deleted file mode 100644
index 7008502..0000000
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/portable/IgniteBinaryImpl.java
+++ /dev/null
@@ -1,178 +0,0 @@
-/*
- * 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.processors.cache.portable;
-
-import java.util.Collection;
-import org.apache.ignite.IgniteBinary;
-import org.apache.ignite.internal.GridKernalContext;
-import org.apache.ignite.internal.processors.cacheobject.IgniteCacheObjectProcessor;
-import org.apache.ignite.binary.BinaryObjectBuilder;
-import org.apache.ignite.binary.BinaryObjectException;
-import org.apache.ignite.binary.BinaryType;
-import org.apache.ignite.binary.BinaryObject;
-import org.jetbrains.annotations.Nullable;
-
-/**
- * {@link org.apache.ignite.IgniteBinary} implementation.
- */
-public class IgniteBinaryImpl implements IgniteBinary {
-    /** */
-    private GridKernalContext ctx;
-
-    /** */
-    private CacheObjectBinaryProcessor proc;
-
-    /**
-     * @param ctx Context.
-     */
-    public IgniteBinaryImpl(GridKernalContext ctx, CacheObjectBinaryProcessor proc) {
-        this.ctx = ctx;
-
-        this.proc = proc;
-    }
-
-    /** {@inheritDoc} */
-    @Override public int typeId(String typeName) {
-        guard();
-
-        try {
-            return proc.typeId(typeName);
-        }
-        finally {
-            unguard();
-        }
-    }
-
-    /** {@inheritDoc} */
-    @SuppressWarnings("unchecked")
-    @Override public <T> T toBinary(@Nullable Object obj) throws BinaryObjectException {
-        guard();
-
-        try {
-            return (T)proc.marshalToPortable(obj);
-        }
-        finally {
-            unguard();
-        }
-    }
-
-    /** {@inheritDoc} */
-    @Override public BinaryObjectBuilder builder(String typeName) {
-        guard();
-
-        try {
-            return proc.builder(typeName);
-        }
-        finally {
-            unguard();
-        }
-    }
-
-    /** {@inheritDoc} */
-    @Override public BinaryObjectBuilder builder(BinaryObject portableObj) {
-        guard();
-
-        try {
-            return proc.builder(portableObj);
-        }
-        finally {
-            unguard();
-        }
-    }
-
-    /** {@inheritDoc} */
-    @Nullable @Override public BinaryType type(Class<?> cls) throws BinaryObjectException {
-        guard();
-
-        try {
-            return proc.metadata(proc.typeId(cls.getName()));
-        }
-        finally {
-            unguard();
-        }
-    }
-
-    /** {@inheritDoc} */
-    @Nullable @Override public BinaryType type(String typeName) throws BinaryObjectException {
-        guard();
-
-        try {
-            return proc.metadata(proc.typeId(typeName));
-        }
-        finally {
-            unguard();
-        }
-    }
-
-    /** {@inheritDoc} */
-    @Nullable @Override public BinaryType type(int typeId) throws BinaryObjectException {
-        guard();
-
-        try {
-            return proc.metadata(typeId);
-        }
-        finally {
-            unguard();
-        }
-    }
-
-    /** {@inheritDoc} */
-    @Override public Collection<BinaryType> types() throws BinaryObjectException {
-        guard();
-
-        try {
-            return proc.metadata();
-        }
-        finally {
-            unguard();
-        }
-    }
-
-    /** {@inheritDoc} */
-    @Override public BinaryObject buildEnum(String typeName, int ord) {
-        guard();
-
-        try {
-            return proc.buildEnum(typeName, ord);
-        }
-        finally {
-            unguard();
-        }
-    }
-
-    /**
-     * @return Portable processor.
-     */
-    public IgniteCacheObjectProcessor processor() {
-        return proc;
-    }
-
-    /**
-     * <tt>ctx.gateway().readLock()</tt>
-     */
-    private void guard() {
-        ctx.gateway().readLock();
-    }
-
-    /**
-     * <tt>ctx.gateway().readUnlock()</tt>
-     */
-    private void unguard() {
-        ctx.gateway().readUnlock();
-    }
-}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ignite/blob/1dbf20e0/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/portable/PortableMetadataKey.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/portable/PortableMetadataKey.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/portable/PortableMetadataKey.java
deleted file mode 100644
index f838c82..0000000
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/portable/PortableMetadataKey.java
+++ /dev/null
@@ -1,82 +0,0 @@
-/*
- * 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.processors.cache.portable;
-
-import java.io.Externalizable;
-import java.io.IOException;
-import java.io.ObjectInput;
-import java.io.ObjectOutput;
-import org.apache.ignite.internal.processors.cache.GridCacheUtilityKey;
-import org.apache.ignite.internal.util.typedef.internal.S;
-
-/**
- * Key for portable meta data.
- */
-class PortableMetadataKey extends GridCacheUtilityKey<PortableMetadataKey> implements Externalizable {
-    /** */
-    private static final long serialVersionUID = 0L;
-
-    /** */
-    private int typeId;
-
-    /**
-     * For {@link Externalizable}.
-     */
-    public PortableMetadataKey() {
-        // No-op.
-    }
-
-    /**
-     * @param typeId Type ID.
-     */
-    PortableMetadataKey(int typeId) {
-        this.typeId = typeId;
-    }
-
-    /**
-     * @return Type id.
-     */
-    public int typeId() {
-        return typeId;
-    }
-
-    /** {@inheritDoc} */
-    @Override public void writeExternal(ObjectOutput out) throws IOException {
-        out.writeInt(typeId);
-    }
-
-    /** {@inheritDoc} */
-    @Override public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
-        typeId = in.readInt();
-    }
-
-    /** {@inheritDoc} */
-    @Override protected boolean equalsx(PortableMetadataKey key) {
-        return typeId == key.typeId;
-    }
-
-    /** {@inheritDoc} */
-    @Override public int hashCode() {
-        return typeId;
-    }
-
-    /** {@inheritDoc} */
-    @Override public String toString() {
-        return S.toString(PortableMetadataKey.class, this);
-    }
-}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ignite/blob/1dbf20e0/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/portable/package-info.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/portable/package-info.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/portable/package-info.java
deleted file mode 100644
index 6c30811..0000000
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/portable/package-info.java
+++ /dev/null
@@ -1,22 +0,0 @@
-/*
- * 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 description. -->
- * Implementation of portable processor.
- */
-package org.apache.ignite.internal.processors.cache.portable;
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ignite/blob/1dbf20e0/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/store/CacheOsStoreManager.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/store/CacheOsStoreManager.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/store/CacheOsStoreManager.java
index 385b4b1..d001c76 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/store/CacheOsStoreManager.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/store/CacheOsStoreManager.java
@@ -23,7 +23,7 @@ import org.apache.ignite.configuration.CacheConfiguration;
 import org.apache.ignite.internal.GridKernalContext;
 import org.apache.ignite.internal.processors.platform.PlatformProcessor;
 import org.apache.ignite.internal.processors.platform.cache.store.PlatformCacheStore;
-import org.apache.ignite.internal.portable.BinaryMarshaller;
+import org.apache.ignite.internal.binary.BinaryMarshaller;
 
 /**
  * Default store manager implementation.
@@ -84,4 +84,4 @@ public class CacheOsStoreManager extends GridCacheStoreManagerAdapter {
     @Override public boolean configuredConvertPortable() {
         return !(ctx.config().getMarshaller() instanceof BinaryMarshaller && cfg.isKeepBinaryInStore());
     }
-}
\ No newline at end of file
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/1dbf20e0/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/PlatformAbstractTarget.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/PlatformAbstractTarget.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/PlatformAbstractTarget.java
index 09cb29d..9c783aa 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/PlatformAbstractTarget.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/PlatformAbstractTarget.java
@@ -20,8 +20,8 @@ package org.apache.ignite.internal.processors.platform;
 import org.apache.ignite.IgniteCheckedException;
 import org.apache.ignite.IgniteLogger;
 import org.apache.ignite.internal.IgniteInternalFuture;
-import org.apache.ignite.internal.portable.BinaryRawReaderEx;
-import org.apache.ignite.internal.portable.BinaryRawWriterEx;
+import org.apache.ignite.internal.binary.BinaryRawReaderEx;
+import org.apache.ignite.internal.binary.BinaryRawWriterEx;
 import org.apache.ignite.internal.processors.platform.memory.PlatformMemory;
 import org.apache.ignite.internal.processors.platform.memory.PlatformOutputStream;
 import org.apache.ignite.internal.processors.platform.utils.PlatformFutureUtils;
@@ -317,4 +317,4 @@ public abstract class PlatformAbstractTarget implements PlatformTarget {
     protected <T> T throwUnsupported(int type) throws IgniteCheckedException {
         throw new IgniteCheckedException("Unsupported operation type: " + type);
     }
-}
\ No newline at end of file
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/1dbf20e0/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/PlatformContext.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/PlatformContext.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/PlatformContext.java
index 12eb36e..b8f5912 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/PlatformContext.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/PlatformContext.java
@@ -21,8 +21,8 @@ import org.apache.ignite.cluster.ClusterMetrics;
 import org.apache.ignite.cluster.ClusterNode;
 import org.apache.ignite.events.Event;
 import org.apache.ignite.internal.GridKernalContext;
-import org.apache.ignite.internal.portable.BinaryRawReaderEx;
-import org.apache.ignite.internal.portable.BinaryRawWriterEx;
+import org.apache.ignite.internal.binary.BinaryRawReaderEx;
+import org.apache.ignite.internal.binary.BinaryRawWriterEx;
 import org.apache.ignite.internal.processors.platform.cache.PlatformCacheEntryFilter;
 import org.apache.ignite.internal.processors.platform.cache.PlatformCacheEntryProcessor;
 import org.apache.ignite.internal.processors.platform.cache.query.PlatformContinuousQuery;
@@ -272,4 +272,4 @@ public interface PlatformContext {
      * @return Cluster node filter.
      */
     public PlatformClusterNodeFilter createClusterNodeFilter(Object filter);
-}
\ No newline at end of file
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/1dbf20e0/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/PlatformContextImpl.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/PlatformContextImpl.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/PlatformContextImpl.java
index 71f42e2..631f78c 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/PlatformContextImpl.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/PlatformContextImpl.java
@@ -34,12 +34,12 @@ import org.apache.ignite.events.JobEvent;
 import org.apache.ignite.events.SwapSpaceEvent;
 import org.apache.ignite.events.TaskEvent;
 import org.apache.ignite.internal.GridKernalContext;
-import org.apache.ignite.internal.portable.BinaryRawReaderEx;
-import org.apache.ignite.internal.portable.BinaryRawWriterEx;
-import org.apache.ignite.internal.portable.BinaryReaderExImpl;
-import org.apache.ignite.internal.portable.BinaryTypeImpl;
-import org.apache.ignite.internal.portable.GridPortableMarshaller;
-import org.apache.ignite.internal.processors.cache.portable.CacheObjectBinaryProcessorImpl;
+import org.apache.ignite.internal.binary.BinaryRawReaderEx;
+import org.apache.ignite.internal.binary.BinaryRawWriterEx;
+import org.apache.ignite.internal.binary.BinaryReaderExImpl;
+import org.apache.ignite.internal.binary.BinaryTypeImpl;
+import org.apache.ignite.internal.binary.GridPortableMarshaller;
+import org.apache.ignite.internal.processors.cache.binary.CacheObjectBinaryProcessorImpl;
 import org.apache.ignite.internal.processors.platform.cache.PlatformCacheEntryFilter;
 import org.apache.ignite.internal.processors.platform.cache.PlatformCacheEntryFilterImpl;
 import org.apache.ignite.internal.processors.platform.cache.PlatformCacheEntryProcessor;

http://git-wip-us.apache.org/repos/asf/ignite/blob/1dbf20e0/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/PlatformExtendedException.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/PlatformExtendedException.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/PlatformExtendedException.java
index e8e7b9b..f537d5e 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/PlatformExtendedException.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/PlatformExtendedException.java
@@ -17,7 +17,7 @@
 
 package org.apache.ignite.internal.processors.platform;
 
-import org.apache.ignite.internal.portable.BinaryRawWriterEx;
+import org.apache.ignite.internal.binary.BinaryRawWriterEx;
 
 /**
  * Denotes an exception which has some data to be written in a special manner.
@@ -54,4 +54,4 @@ public abstract class PlatformExtendedException extends PlatformException {
      * @param writer Writer.
      */
     public abstract void writeData(BinaryRawWriterEx writer);
-}
\ No newline at end of file
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/1dbf20e0/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/PlatformProcessorImpl.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/PlatformProcessorImpl.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/PlatformProcessorImpl.java
index 27d7da3..a788775 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/PlatformProcessorImpl.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/PlatformProcessorImpl.java
@@ -26,7 +26,7 @@ import org.apache.ignite.configuration.PlatformConfiguration;
 import org.apache.ignite.internal.GridKernalContext;
 import org.apache.ignite.internal.IgniteComputeImpl;
 import org.apache.ignite.internal.cluster.ClusterGroupAdapter;
-import org.apache.ignite.internal.portable.BinaryRawWriterEx;
+import org.apache.ignite.internal.binary.BinaryRawWriterEx;
 import org.apache.ignite.internal.processors.GridProcessorAdapter;
 import org.apache.ignite.internal.processors.cache.IgniteCacheProxy;
 import org.apache.ignite.internal.processors.datastreamer.DataStreamerImpl;
@@ -371,4 +371,4 @@ public class PlatformProcessorImpl extends GridProcessorAdapter implements Platf
             this.convertPortable = convertPortable;
         }
     }
-}
\ No newline at end of file
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/1dbf20e0/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/cache/PlatformCache.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/cache/PlatformCache.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/cache/PlatformCache.java
index 5943440..da7a15d 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/cache/PlatformCache.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/cache/PlatformCache.java
@@ -28,8 +28,8 @@ import org.apache.ignite.cache.query.ScanQuery;
 import org.apache.ignite.cache.query.SqlFieldsQuery;
 import org.apache.ignite.cache.query.SqlQuery;
 import org.apache.ignite.cache.query.TextQuery;
-import org.apache.ignite.internal.portable.BinaryRawReaderEx;
-import org.apache.ignite.internal.portable.BinaryRawWriterEx;
+import org.apache.ignite.internal.binary.BinaryRawReaderEx;
+import org.apache.ignite.internal.binary.BinaryRawWriterEx;
 import org.apache.ignite.internal.processors.cache.CacheOperationContext;
 import org.apache.ignite.internal.processors.cache.CachePartialUpdateCheckedException;
 import org.apache.ignite.internal.processors.cache.IgniteCacheProxy;
@@ -1087,4 +1087,4 @@ public class PlatformCache extends PlatformAbstractTarget {
             }
         }
     }
-}
\ No newline at end of file
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/1dbf20e0/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/cache/PlatformCacheEntryFilterImpl.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/cache/PlatformCacheEntryFilterImpl.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/cache/PlatformCacheEntryFilterImpl.java
index 6998451..d027a9a 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/cache/PlatformCacheEntryFilterImpl.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/cache/PlatformCacheEntryFilterImpl.java
@@ -18,7 +18,7 @@
 package org.apache.ignite.internal.processors.platform.cache;
 
 import org.apache.ignite.Ignite;
-import org.apache.ignite.internal.portable.BinaryRawWriterEx;
+import org.apache.ignite.internal.binary.BinaryRawWriterEx;
 import org.apache.ignite.internal.processors.platform.PlatformAbstractPredicate;
 import org.apache.ignite.internal.processors.platform.PlatformContext;
 import org.apache.ignite.internal.processors.platform.memory.PlatformMemory;
@@ -103,4 +103,4 @@ public class PlatformCacheEntryFilterImpl extends PlatformAbstractPredicate impl
             ptr = ctx.gateway().cacheEntryFilterCreate(mem.pointer());
         }
     }
-}
\ No newline at end of file
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/1dbf20e0/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/cache/PlatformCacheEntryProcessorImpl.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/cache/PlatformCacheEntryProcessorImpl.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/cache/PlatformCacheEntryProcessorImpl.java
index ce06ec1..3986a13 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/cache/PlatformCacheEntryProcessorImpl.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/cache/PlatformCacheEntryProcessorImpl.java
@@ -26,8 +26,8 @@ import javax.cache.processor.MutableEntry;
 import org.apache.ignite.Ignite;
 import org.apache.ignite.IgniteCheckedException;
 import org.apache.ignite.internal.IgniteKernal;
-import org.apache.ignite.internal.portable.BinaryRawReaderEx;
-import org.apache.ignite.internal.portable.BinaryRawWriterEx;
+import org.apache.ignite.internal.binary.BinaryRawReaderEx;
+import org.apache.ignite.internal.binary.BinaryRawWriterEx;
 import org.apache.ignite.internal.processors.platform.PlatformContext;
 import org.apache.ignite.internal.processors.platform.PlatformProcessor;
 import org.apache.ignite.internal.processors.platform.memory.PlatformInputStream;
@@ -217,4 +217,4 @@ public class PlatformCacheEntryProcessorImpl implements PlatformCacheEntryProces
     @Override public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
         proc = in.readObject();
     }
-}
\ No newline at end of file
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/1dbf20e0/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/cache/PlatformCacheIterator.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/cache/PlatformCacheIterator.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/cache/PlatformCacheIterator.java
index a5659af..292caea 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/cache/PlatformCacheIterator.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/cache/PlatformCacheIterator.java
@@ -20,7 +20,7 @@ package org.apache.ignite.internal.processors.platform.cache;
 import java.util.Iterator;
 import javax.cache.Cache;
 import org.apache.ignite.IgniteCheckedException;
-import org.apache.ignite.internal.portable.BinaryRawWriterEx;
+import org.apache.ignite.internal.binary.BinaryRawWriterEx;
 import org.apache.ignite.internal.processors.platform.PlatformAbstractTarget;
 import org.apache.ignite.internal.processors.platform.PlatformContext;
 
@@ -69,4 +69,4 @@ public class PlatformCacheIterator extends PlatformAbstractTarget {
                 super.processOutStream(type, writer);
         }
     }
-}
\ No newline at end of file
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/1dbf20e0/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/cache/PlatformCachePartialUpdateException.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/cache/PlatformCachePartialUpdateException.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/cache/PlatformCachePartialUpdateException.java
index 8314e3a..8cb1490 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/cache/PlatformCachePartialUpdateException.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/cache/PlatformCachePartialUpdateException.java
@@ -17,7 +17,7 @@
 
 package org.apache.ignite.internal.processors.platform.cache;
 
-import org.apache.ignite.internal.portable.BinaryRawWriterEx;
+import org.apache.ignite.internal.binary.BinaryRawWriterEx;
 import org.apache.ignite.internal.processors.cache.CachePartialUpdateCheckedException;
 import org.apache.ignite.internal.processors.platform.PlatformContext;
 import org.apache.ignite.internal.processors.platform.PlatformExtendedException;
@@ -56,4 +56,4 @@ public class PlatformCachePartialUpdateException extends PlatformExtendedExcepti
 
         PlatformUtils.writeNullableCollection(writer, keys);
     }
-}
\ No newline at end of file
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/1dbf20e0/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/cache/affinity/PlatformAffinity.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/cache/affinity/PlatformAffinity.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/cache/affinity/PlatformAffinity.java
index c4e0350..acd2707 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/cache/affinity/PlatformAffinity.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/cache/affinity/PlatformAffinity.java
@@ -25,8 +25,8 @@ import org.apache.ignite.cache.affinity.Affinity;
 import org.apache.ignite.cluster.ClusterNode;
 import org.apache.ignite.internal.GridKernalContext;
 import org.apache.ignite.internal.managers.discovery.GridDiscoveryManager;
-import org.apache.ignite.internal.portable.BinaryRawReaderEx;
-import org.apache.ignite.internal.portable.BinaryRawWriterEx;
+import org.apache.ignite.internal.binary.BinaryRawReaderEx;
+import org.apache.ignite.internal.binary.BinaryRawWriterEx;
 import org.apache.ignite.internal.processors.platform.PlatformAbstractTarget;
 import org.apache.ignite.internal.processors.platform.PlatformContext;
 import org.apache.ignite.internal.processors.platform.utils.PlatformUtils;
@@ -294,4 +294,4 @@ public class PlatformAffinity extends PlatformAbstractTarget {
     public int partitions() {
         return aff.partitions();
     }
-}
\ No newline at end of file
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/1dbf20e0/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/cache/query/PlatformAbstractQueryCursor.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/cache/query/PlatformAbstractQueryCursor.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/cache/query/PlatformAbstractQueryCursor.java
index 8c24d23..7422757 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/cache/query/PlatformAbstractQueryCursor.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/cache/query/PlatformAbstractQueryCursor.java
@@ -19,7 +19,7 @@ package org.apache.ignite.internal.processors.platform.cache.query;
 
 import java.util.Iterator;
 import org.apache.ignite.IgniteCheckedException;
-import org.apache.ignite.internal.portable.BinaryRawWriterEx;
+import org.apache.ignite.internal.binary.BinaryRawWriterEx;
 import org.apache.ignite.internal.processors.cache.query.QueryCursorEx;
 import org.apache.ignite.internal.processors.platform.PlatformAbstractTarget;
 import org.apache.ignite.internal.processors.platform.PlatformContext;
@@ -189,4 +189,4 @@ public abstract class PlatformAbstractQueryCursor<T> extends PlatformAbstractTar
             cnt++;
         }
     }
-}
\ No newline at end of file
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/1dbf20e0/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/cache/query/PlatformContinuousQueryRemoteFilter.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/cache/query/PlatformContinuousQueryRemoteFilter.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/cache/query/PlatformContinuousQueryRemoteFilter.java
index 9f67118..759797c 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/cache/query/PlatformContinuousQueryRemoteFilter.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/cache/query/PlatformContinuousQueryRemoteFilter.java
@@ -18,7 +18,7 @@
 package org.apache.ignite.internal.processors.platform.cache.query;
 
 import org.apache.ignite.Ignite;
-import org.apache.ignite.internal.portable.BinaryRawWriterEx;
+import org.apache.ignite.internal.binary.BinaryRawWriterEx;
 import org.apache.ignite.internal.processors.platform.PlatformContext;
 import org.apache.ignite.internal.processors.platform.memory.PlatformMemory;
 import org.apache.ignite.internal.processors.platform.memory.PlatformOutputStream;
@@ -185,4 +185,4 @@ public class PlatformContinuousQueryRemoteFilter implements PlatformContinuousQu
     @Override public String toString() {
         return S.toString(PlatformContinuousQueryRemoteFilter.class, this);
     }
-}
\ No newline at end of file
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/1dbf20e0/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/cache/query/PlatformFieldsQueryCursor.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/cache/query/PlatformFieldsQueryCursor.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/cache/query/PlatformFieldsQueryCursor.java
index 035e927..a4cdae6 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/cache/query/PlatformFieldsQueryCursor.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/cache/query/PlatformFieldsQueryCursor.java
@@ -18,7 +18,7 @@
 package org.apache.ignite.internal.processors.platform.cache.query;
 
 import java.util.List;
-import org.apache.ignite.internal.portable.BinaryRawWriterEx;
+import org.apache.ignite.internal.binary.BinaryRawWriterEx;
 import org.apache.ignite.internal.processors.cache.query.QueryCursorEx;
 import org.apache.ignite.internal.processors.platform.PlatformContext;
 
@@ -46,4 +46,4 @@ public class PlatformFieldsQueryCursor extends PlatformAbstractQueryCursor<List<
         for (Object val : vals)
             writer.writeObjectDetached(val);
     }
-}
\ No newline at end of file
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/1dbf20e0/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/cache/query/PlatformQueryCursor.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/cache/query/PlatformQueryCursor.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/cache/query/PlatformQueryCursor.java
index fe94e65..39e0184 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/cache/query/PlatformQueryCursor.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/cache/query/PlatformQueryCursor.java
@@ -18,7 +18,7 @@
 package org.apache.ignite.internal.processors.platform.cache.query;
 
 import javax.cache.Cache;
-import org.apache.ignite.internal.portable.BinaryRawWriterEx;
+import org.apache.ignite.internal.binary.BinaryRawWriterEx;
 import org.apache.ignite.internal.processors.cache.query.QueryCursorEx;
 import org.apache.ignite.internal.processors.platform.PlatformContext;
 
@@ -42,4 +42,4 @@ public class PlatformQueryCursor extends PlatformAbstractQueryCursor<Cache.Entry
         writer.writeObjectDetached(val.getKey());
         writer.writeObjectDetached(val.getValue());
     }
-}
\ No newline at end of file
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/1dbf20e0/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/cache/store/PlatformCacheStoreCallback.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/cache/store/PlatformCacheStoreCallback.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/cache/store/PlatformCacheStoreCallback.java
index 45110ce..ad0d081 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/cache/store/PlatformCacheStoreCallback.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/cache/store/PlatformCacheStoreCallback.java
@@ -17,7 +17,7 @@
 
 package org.apache.ignite.internal.processors.platform.cache.store;
 
-import org.apache.ignite.internal.portable.BinaryRawReaderEx;
+import org.apache.ignite.internal.binary.BinaryRawReaderEx;
 import org.apache.ignite.internal.processors.platform.PlatformContext;
 import org.apache.ignite.internal.processors.platform.memory.PlatformMemory;
 
@@ -58,4 +58,4 @@ public abstract class PlatformCacheStoreCallback {
      * @param reader Reader.
      */
     protected abstract void invoke0(BinaryRawReaderEx reader);
-}
\ No newline at end of file
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/1dbf20e0/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/cluster/PlatformClusterGroup.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/cluster/PlatformClusterGroup.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/cluster/PlatformClusterGroup.java
index fc47a4b..f60766b 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/cluster/PlatformClusterGroup.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/cluster/PlatformClusterGroup.java
@@ -24,8 +24,8 @@ import org.apache.ignite.IgniteCluster;
 import org.apache.ignite.cluster.ClusterMetrics;
 import org.apache.ignite.cluster.ClusterNode;
 import org.apache.ignite.internal.cluster.ClusterGroupEx;
-import org.apache.ignite.internal.portable.BinaryRawReaderEx;
-import org.apache.ignite.internal.portable.BinaryRawWriterEx;
+import org.apache.ignite.internal.binary.BinaryRawReaderEx;
+import org.apache.ignite.internal.binary.BinaryRawWriterEx;
 import org.apache.ignite.internal.processors.platform.PlatformAbstractTarget;
 import org.apache.ignite.internal.processors.platform.PlatformContext;
 import org.apache.ignite.internal.processors.platform.utils.PlatformUtils;
@@ -332,4 +332,4 @@ public class PlatformClusterGroup extends PlatformAbstractTarget {
 
         return ((IgniteCluster)prj).topology(topVer);
     }
-}
\ No newline at end of file
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/1dbf20e0/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/cluster/PlatformClusterNodeFilterImpl.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/cluster/PlatformClusterNodeFilterImpl.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/cluster/PlatformClusterNodeFilterImpl.java
index 92aabd8..72e4a71 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/cluster/PlatformClusterNodeFilterImpl.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/cluster/PlatformClusterNodeFilterImpl.java
@@ -19,7 +19,7 @@ package org.apache.ignite.internal.processors.platform.cluster;
 
 import org.apache.ignite.Ignite;
 import org.apache.ignite.cluster.ClusterNode;
-import org.apache.ignite.internal.portable.BinaryRawWriterEx;
+import org.apache.ignite.internal.binary.BinaryRawWriterEx;
 import org.apache.ignite.internal.processors.platform.PlatformAbstractPredicate;
 import org.apache.ignite.internal.processors.platform.PlatformContext;
 import org.apache.ignite.internal.processors.platform.memory.PlatformMemory;
@@ -75,4 +75,4 @@ public class PlatformClusterNodeFilterImpl extends PlatformAbstractPredicate imp
     public void setIgniteInstance(Ignite ignite) {
         ctx = PlatformUtils.platformContext(ignite);
     }
-}
\ No newline at end of file
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/1dbf20e0/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/compute/PlatformAbstractJob.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/compute/PlatformAbstractJob.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/compute/PlatformAbstractJob.java
index 462f2c4..32aed39 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/compute/PlatformAbstractJob.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/compute/PlatformAbstractJob.java
@@ -20,7 +20,7 @@ package org.apache.ignite.internal.processors.platform.compute;
 import java.io.Externalizable;
 import org.apache.ignite.Ignite;
 import org.apache.ignite.IgniteCheckedException;
-import org.apache.ignite.internal.portable.BinaryRawWriterEx;
+import org.apache.ignite.internal.binary.BinaryRawWriterEx;
 import org.apache.ignite.internal.processors.platform.PlatformContext;
 import org.apache.ignite.internal.processors.platform.PlatformProcessor;
 import org.apache.ignite.internal.processors.platform.memory.PlatformMemory;
@@ -153,4 +153,4 @@ public abstract class PlatformAbstractJob implements PlatformJob, Externalizable
     @Override public Object job() {
         return job;
     }
-}
\ No newline at end of file
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/1dbf20e0/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/compute/PlatformAbstractTask.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/compute/PlatformAbstractTask.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/compute/PlatformAbstractTask.java
index c293c51..a8a51d4 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/compute/PlatformAbstractTask.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/compute/PlatformAbstractTask.java
@@ -24,7 +24,7 @@ import org.apache.ignite.IgniteException;
 import org.apache.ignite.compute.ComputeJobResult;
 import org.apache.ignite.compute.ComputeJobResultPolicy;
 import org.apache.ignite.compute.ComputeTask;
-import org.apache.ignite.internal.portable.BinaryRawWriterEx;
+import org.apache.ignite.internal.binary.BinaryRawWriterEx;
 import org.apache.ignite.internal.processors.platform.PlatformContext;
 import org.apache.ignite.internal.processors.platform.PlatformNativeException;
 import org.apache.ignite.internal.processors.platform.memory.PlatformMemory;
@@ -203,4 +203,4 @@ public abstract class PlatformAbstractTask implements ComputeTask<Object, Void>
 
         lock.readLock().unlock();
     }
-}
\ No newline at end of file
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/1dbf20e0/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/compute/PlatformClosureJob.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/compute/PlatformClosureJob.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/compute/PlatformClosureJob.java
index b35f31c..f8567ce 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/compute/PlatformClosureJob.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/compute/PlatformClosureJob.java
@@ -21,7 +21,7 @@ import java.io.IOException;
 import java.io.ObjectInput;
 import java.io.ObjectOutput;
 import org.apache.ignite.IgniteCheckedException;
-import org.apache.ignite.internal.portable.BinaryRawReaderEx;
+import org.apache.ignite.internal.binary.BinaryRawReaderEx;
 import org.apache.ignite.internal.processors.platform.PlatformContext;
 import org.apache.ignite.internal.processors.platform.memory.PlatformInputStream;
 import org.apache.ignite.internal.processors.platform.memory.PlatformMemory;
@@ -101,4 +101,4 @@ public class PlatformClosureJob extends PlatformAbstractJob {
     @Override public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
         job = in.readObject();
     }
-}
\ No newline at end of file
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/1dbf20e0/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/compute/PlatformCompute.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/compute/PlatformCompute.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/compute/PlatformCompute.java
index 05db49d..3cb65b9 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/compute/PlatformCompute.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/compute/PlatformCompute.java
@@ -25,9 +25,9 @@ import org.apache.ignite.IgniteCheckedException;
 import org.apache.ignite.IgniteCompute;
 import org.apache.ignite.internal.IgniteComputeImpl;
 import org.apache.ignite.internal.IgniteInternalFuture;
-import org.apache.ignite.internal.portable.BinaryObjectImpl;
-import org.apache.ignite.internal.portable.BinaryRawReaderEx;
-import org.apache.ignite.internal.portable.BinaryRawWriterEx;
+import org.apache.ignite.internal.binary.BinaryObjectImpl;
+import org.apache.ignite.internal.binary.BinaryRawReaderEx;
+import org.apache.ignite.internal.binary.BinaryRawWriterEx;
 import org.apache.ignite.internal.processors.platform.PlatformAbstractTarget;
 import org.apache.ignite.internal.processors.platform.PlatformContext;
 import org.apache.ignite.internal.util.typedef.C1;
@@ -329,4 +329,4 @@ public class PlatformCompute extends PlatformAbstractTarget {
         return nodeIds == null ? compute :
             platformCtx.kernalContext().grid().compute(compute.clusterGroup().forNodeIds(nodeIds));
     }
-}
\ No newline at end of file
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/1dbf20e0/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/compute/PlatformFullJob.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/compute/PlatformFullJob.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/compute/PlatformFullJob.java
index 9302c03..51c9cdb 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/compute/PlatformFullJob.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/compute/PlatformFullJob.java
@@ -21,7 +21,7 @@ import java.io.IOException;
 import java.io.ObjectInput;
 import java.io.ObjectOutput;
 import org.apache.ignite.IgniteCheckedException;
-import org.apache.ignite.internal.portable.BinaryRawReaderEx;
+import org.apache.ignite.internal.binary.BinaryRawReaderEx;
 import org.apache.ignite.internal.processors.platform.PlatformContext;
 import org.apache.ignite.internal.processors.platform.PlatformProcessor;
 import org.apache.ignite.internal.processors.platform.memory.PlatformInputStream;
@@ -217,4 +217,4 @@ public class PlatformFullJob extends PlatformAbstractJob {
                 throw new IgniteCheckedException(reader.readString());
         }
     }
-}
\ No newline at end of file
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/1dbf20e0/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/compute/PlatformFullTask.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/compute/PlatformFullTask.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/compute/PlatformFullTask.java
index d789003..e2f6720 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/compute/PlatformFullTask.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/compute/PlatformFullTask.java
@@ -27,8 +27,8 @@ import org.apache.ignite.compute.ComputeJob;
 import org.apache.ignite.compute.ComputeTaskNoResultCache;
 import org.apache.ignite.internal.IgniteComputeImpl;
 import org.apache.ignite.internal.managers.discovery.GridDiscoveryManager;
-import org.apache.ignite.internal.portable.BinaryRawReaderEx;
-import org.apache.ignite.internal.portable.BinaryRawWriterEx;
+import org.apache.ignite.internal.binary.BinaryRawReaderEx;
+import org.apache.ignite.internal.binary.BinaryRawWriterEx;
 import org.apache.ignite.internal.processors.platform.PlatformContext;
 import org.apache.ignite.internal.processors.platform.memory.PlatformInputStream;
 import org.apache.ignite.internal.processors.platform.memory.PlatformMemory;
@@ -189,4 +189,4 @@ public final class PlatformFullTask extends PlatformAbstractTask {
         else
             throw new IgniteException(reader.readString());
     }
-}
\ No newline at end of file
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/1dbf20e0/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/cpp/PlatformCppConfigurationClosure.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/cpp/PlatformCppConfigurationClosure.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/cpp/PlatformCppConfigurationClosure.java
index 4bd311b..3cfbcaa 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/cpp/PlatformCppConfigurationClosure.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/cpp/PlatformCppConfigurationClosure.java
@@ -26,7 +26,7 @@ import org.apache.ignite.internal.processors.platform.PlatformAbstractConfigurat
 import org.apache.ignite.internal.processors.platform.memory.PlatformMemoryManagerImpl;
 import org.apache.ignite.internal.util.typedef.internal.U;
 import org.apache.ignite.marshaller.Marshaller;
-import org.apache.ignite.internal.portable.BinaryMarshaller;
+import org.apache.ignite.internal.binary.BinaryMarshaller;
 import org.apache.ignite.platform.cpp.PlatformCppConfiguration;
 
 import java.util.Collections;
@@ -111,4 +111,4 @@ public class PlatformCppConfigurationClosure extends PlatformAbstractConfigurati
             throw U.convertException(e);
         }
     }
-}
\ No newline at end of file
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/1dbf20e0/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/datastreamer/PlatformDataStreamer.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/datastreamer/PlatformDataStreamer.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/datastreamer/PlatformDataStreamer.java
index 794ab0b..82c3e59 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/datastreamer/PlatformDataStreamer.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/datastreamer/PlatformDataStreamer.java
@@ -24,14 +24,13 @@ import org.apache.ignite.events.DiscoveryEvent;
 import org.apache.ignite.events.Event;
 import org.apache.ignite.internal.managers.discovery.GridDiscoveryManager;
 import org.apache.ignite.internal.managers.eventstorage.GridLocalEventListener;
-import org.apache.ignite.internal.portable.BinaryRawReaderEx;
+import org.apache.ignite.internal.binary.BinaryRawReaderEx;
 import org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion;
 import org.apache.ignite.internal.processors.datastreamer.DataStreamerImpl;
 import org.apache.ignite.internal.processors.platform.PlatformAbstractTarget;
 import org.apache.ignite.internal.processors.platform.PlatformContext;
 import org.apache.ignite.internal.processors.platform.utils.PlatformFutureUtils;
 import org.apache.ignite.internal.util.lang.GridMapEntry;
-import org.apache.ignite.internal.util.typedef.internal.U;
 
 import static org.apache.ignite.events.EventType.EVT_NODE_FAILED;
 import static org.apache.ignite.events.EventType.EVT_NODE_JOINED;
@@ -224,4 +223,4 @@ public class PlatformDataStreamer extends PlatformAbstractTarget {
     public void perNodeParallelOperations(int val) {
         ldr.perNodeParallelOperations(val);
     }
-}
\ No newline at end of file
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/1dbf20e0/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/datastreamer/PlatformStreamReceiverImpl.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/datastreamer/PlatformStreamReceiverImpl.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/datastreamer/PlatformStreamReceiverImpl.java
index 5915496..2a3848a 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/datastreamer/PlatformStreamReceiverImpl.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/datastreamer/PlatformStreamReceiverImpl.java
@@ -20,7 +20,7 @@ package org.apache.ignite.internal.processors.platform.datastreamer;
 import org.apache.ignite.Ignite;
 import org.apache.ignite.IgniteCache;
 import org.apache.ignite.IgniteException;
-import org.apache.ignite.internal.portable.BinaryRawWriterEx;
+import org.apache.ignite.internal.binary.BinaryRawWriterEx;
 import org.apache.ignite.internal.processors.platform.PlatformAbstractPredicate;
 import org.apache.ignite.internal.processors.platform.PlatformContext;
 import org.apache.ignite.internal.processors.platform.cache.PlatformCache;
@@ -116,4 +116,4 @@ public class PlatformStreamReceiverImpl extends PlatformAbstractPredicate implem
 
         keepPortable = in.readBoolean();
     }
-}
\ No newline at end of file
+}


[27/59] [abbrv] ignite git commit: ignite-2065: rename "portable" packages to "binary"

Posted by ak...@apache.org.
http://git-wip-us.apache.org/repos/asf/ignite/blob/1dbf20e0/modules/core/src/main/java/org/apache/ignite/internal/binary/PortableClassDescriptor.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/binary/PortableClassDescriptor.java b/modules/core/src/main/java/org/apache/ignite/internal/binary/PortableClassDescriptor.java
new file mode 100644
index 0000000..9b4d444
--- /dev/null
+++ b/modules/core/src/main/java/org/apache/ignite/internal/binary/PortableClassDescriptor.java
@@ -0,0 +1,813 @@
+/*
+ * 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.binary;
+
+import java.io.Externalizable;
+import java.io.IOException;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+import java.lang.reflect.Constructor;
+import java.lang.reflect.Field;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.lang.reflect.Modifier;
+import java.math.BigDecimal;
+import java.sql.Timestamp;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.UUID;
+import org.apache.ignite.IgniteCheckedException;
+import org.apache.ignite.binary.BinaryIdMapper;
+import org.apache.ignite.binary.BinaryObjectException;
+import org.apache.ignite.binary.BinarySerializer;
+import org.apache.ignite.binary.Binarylizable;
+import org.apache.ignite.internal.processors.cache.CacheObjectImpl;
+import org.apache.ignite.internal.util.GridUnsafe;
+import org.apache.ignite.internal.util.typedef.internal.U;
+import org.apache.ignite.marshaller.MarshallerExclusions;
+import org.apache.ignite.marshaller.optimized.OptimizedMarshaller;
+import org.jetbrains.annotations.Nullable;
+import sun.misc.Unsafe;
+
+import static java.lang.reflect.Modifier.isStatic;
+import static java.lang.reflect.Modifier.isTransient;
+
+/**
+ * Portable class descriptor.
+ */
+public class PortableClassDescriptor {
+    /** */
+    public static final Unsafe UNSAFE = GridUnsafe.unsafe();
+
+    /** */
+    private final PortableContext ctx;
+
+    /** */
+    private final Class<?> cls;
+
+    /** */
+    private final BinarySerializer serializer;
+
+    /** ID mapper. */
+    private final BinaryIdMapper idMapper;
+
+    /** */
+    private final BinaryWriteMode mode;
+
+    /** */
+    private final boolean userType;
+
+    /** */
+    private final int typeId;
+
+    /** */
+    private final String typeName;
+
+    /** Affinity key field name. */
+    private final String affKeyFieldName;
+
+    /** */
+    private final Constructor<?> ctor;
+
+    /** */
+    private final BinaryFieldAccessor[] fields;
+
+    /** */
+    private final Method writeReplaceMtd;
+
+    /** */
+    private final Method readResolveMtd;
+
+    /** */
+    private final Map<String, Integer> stableFieldsMeta;
+
+    /** Object schemas. Initialized only for serializable classes and contains only 1 entry. */
+    private final PortableSchema stableSchema;
+
+    /** Schema registry. */
+    private final PortableSchemaRegistry schemaReg;
+
+    /** */
+    private final boolean registered;
+
+    /** */
+    private final boolean useOptMarshaller;
+
+    /** */
+    private final boolean excluded;
+
+    /**
+     * @param ctx Context.
+     * @param cls Class.
+     * @param userType User type flag.
+     * @param typeId Type ID.
+     * @param typeName Type name.
+     * @param affKeyFieldName Affinity key field name.
+     * @param idMapper ID mapper.
+     * @param serializer Serializer.
+     * @param metaDataEnabled Metadata enabled flag.
+     * @param registered Whether typeId has been successfully registered by MarshallerContext or not.
+     * @param predefined Whether the class is predefined or not.
+     * @throws BinaryObjectException In case of error.
+     */
+    PortableClassDescriptor(
+        PortableContext ctx,
+        Class<?> cls,
+        boolean userType,
+        int typeId,
+        String typeName,
+        @Nullable String affKeyFieldName,
+        @Nullable BinaryIdMapper idMapper,
+        @Nullable BinarySerializer serializer,
+        boolean metaDataEnabled,
+        boolean registered,
+        boolean predefined
+    ) throws BinaryObjectException {
+        assert ctx != null;
+        assert cls != null;
+        assert idMapper != null;
+
+        this.ctx = ctx;
+        this.cls = cls;
+        this.typeId = typeId;
+        this.userType = userType;
+        this.typeName = typeName;
+        this.affKeyFieldName = affKeyFieldName;
+        this.serializer = serializer;
+        this.idMapper = idMapper;
+        this.registered = registered;
+
+        schemaReg = ctx.schemaRegistry(typeId);
+
+        excluded = MarshallerExclusions.isExcluded(cls);
+
+        useOptMarshaller = !predefined && initUseOptimizedMarshallerFlag();
+
+        if (excluded)
+            mode = BinaryWriteMode.EXCLUSION;
+        else {
+            if (cls == BinaryEnumObjectImpl.class)
+                mode = BinaryWriteMode.PORTABLE_ENUM;
+            else
+                mode = serializer != null ? BinaryWriteMode.PORTABLE : PortableUtils.mode(cls);
+        }
+
+        switch (mode) {
+            case P_BYTE:
+            case P_BOOLEAN:
+            case P_SHORT:
+            case P_CHAR:
+            case P_INT:
+            case P_LONG:
+            case P_FLOAT:
+            case P_DOUBLE:
+            case BYTE:
+            case SHORT:
+            case INT:
+            case LONG:
+            case FLOAT:
+            case DOUBLE:
+            case CHAR:
+            case BOOLEAN:
+            case DECIMAL:
+            case STRING:
+            case UUID:
+            case DATE:
+            case TIMESTAMP:
+            case BYTE_ARR:
+            case SHORT_ARR:
+            case INT_ARR:
+            case LONG_ARR:
+            case FLOAT_ARR:
+            case DOUBLE_ARR:
+            case CHAR_ARR:
+            case BOOLEAN_ARR:
+            case DECIMAL_ARR:
+            case STRING_ARR:
+            case UUID_ARR:
+            case DATE_ARR:
+            case TIMESTAMP_ARR:
+            case OBJECT_ARR:
+            case COL:
+            case MAP:
+            case PORTABLE_OBJ:
+            case ENUM:
+            case PORTABLE_ENUM:
+            case ENUM_ARR:
+            case CLASS:
+            case EXCLUSION:
+                ctor = null;
+                fields = null;
+                stableFieldsMeta = null;
+                stableSchema = null;
+
+                break;
+
+            case PORTABLE:
+            case EXTERNALIZABLE:
+                ctor = constructor(cls);
+                fields = null;
+                stableFieldsMeta = null;
+                stableSchema = null;
+
+                break;
+
+            case OBJECT:
+                // Must not use constructor to honor transient fields semantics.
+                ctor = null;
+                ArrayList<BinaryFieldAccessor> fields0 = new ArrayList<>();
+                stableFieldsMeta = metaDataEnabled ? new HashMap<String, Integer>() : null;
+
+                PortableSchema.Builder schemaBuilder = PortableSchema.Builder.newBuilder();
+
+                Collection<String> names = new HashSet<>();
+                Collection<Integer> ids = new HashSet<>();
+
+                for (Class<?> c = cls; c != null && !c.equals(Object.class); c = c.getSuperclass()) {
+                    for (Field f : c.getDeclaredFields()) {
+                        int mod = f.getModifiers();
+
+                        if (!isStatic(mod) && !isTransient(mod)) {
+                            f.setAccessible(true);
+
+                            String name = f.getName();
+
+                            if (!names.add(name))
+                                throw new BinaryObjectException("Duplicate field name [fieldName=" + name +
+                                    ", cls=" + cls.getName() + ']');
+
+                            int fieldId = idMapper.fieldId(typeId, name);
+
+                            if (!ids.add(fieldId))
+                                throw new BinaryObjectException("Duplicate field ID: " + name);
+
+                            BinaryFieldAccessor fieldInfo = BinaryFieldAccessor.create(f, fieldId);
+
+                            fields0.add(fieldInfo);
+
+                            schemaBuilder.addField(fieldId);
+
+                            if (metaDataEnabled)
+                                stableFieldsMeta.put(name, fieldInfo.mode().typeId());
+                        }
+                    }
+                }
+
+                fields = fields0.toArray(new BinaryFieldAccessor[fields0.size()]);
+
+                stableSchema = schemaBuilder.build();
+
+                break;
+
+            default:
+                // Should never happen.
+                throw new BinaryObjectException("Invalid mode: " + mode);
+        }
+
+        if (mode == BinaryWriteMode.PORTABLE || mode == BinaryWriteMode.EXTERNALIZABLE ||
+            mode == BinaryWriteMode.OBJECT) {
+            readResolveMtd = U.findNonPublicMethod(cls, "readResolve");
+            writeReplaceMtd = U.findNonPublicMethod(cls, "writeReplace");
+        }
+        else {
+            readResolveMtd = null;
+            writeReplaceMtd = null;
+        }
+    }
+
+    /**
+     * @return {@code True} if enum.
+     */
+    boolean isEnum() {
+        return mode == BinaryWriteMode.ENUM;
+    }
+
+    /**
+     * @return Described class.
+     */
+    Class<?> describedClass() {
+        return cls;
+    }
+
+    /**
+     * @return Type ID.
+     */
+    public int typeId() {
+        return typeId;
+    }
+
+    /**
+     * @return User type flag.
+     */
+    public boolean userType() {
+        return userType;
+    }
+
+    /**
+     * @return Fields meta data.
+     */
+    Map<String, Integer> fieldsMeta() {
+        return stableFieldsMeta;
+    }
+
+    /**
+     * @return Schema.
+     */
+    PortableSchema schema() {
+        return stableSchema;
+    }
+
+    /**
+     * @return Whether typeId has been successfully registered by MarshallerContext or not.
+     */
+    public boolean registered() {
+        return registered;
+    }
+
+    /**
+     * @return {@code true} if {@link OptimizedMarshaller} must be used instead of {@link BinaryMarshaller}
+     * for object serialization and deserialization.
+     */
+    public boolean useOptimizedMarshaller() {
+        return useOptMarshaller;
+    }
+
+    /**
+     * Checks whether the class values are explicitly excluded from marshalling.
+     *
+     * @return {@code true} if excluded, {@code false} otherwise.
+     */
+    public boolean excluded() {
+        return excluded;
+    }
+
+    /**
+     * @return portableWriteReplace() method
+     */
+    @Nullable Method getWriteReplaceMethod() {
+        return writeReplaceMtd;
+    }
+
+    /**
+     * @return portableReadResolve() method
+     */
+    @SuppressWarnings("UnusedDeclaration")
+    @Nullable Method getReadResolveMethod() {
+        return readResolveMtd;
+    }
+
+    /**
+     * @param obj Object.
+     * @param writer Writer.
+     * @throws BinaryObjectException In case of error.
+     */
+    void write(Object obj, BinaryWriterExImpl writer) throws BinaryObjectException {
+        assert obj != null;
+        assert writer != null;
+
+        writer.typeId(typeId);
+
+        switch (mode) {
+            case P_BYTE:
+            case BYTE:
+                writer.writeByteFieldPrimitive((byte) obj);
+
+                break;
+
+            case P_SHORT:
+            case SHORT:
+                writer.writeShortFieldPrimitive((short)obj);
+
+                break;
+
+            case P_INT:
+            case INT:
+                writer.writeIntFieldPrimitive((int) obj);
+
+                break;
+
+            case P_LONG:
+            case LONG:
+                writer.writeLongFieldPrimitive((long) obj);
+
+                break;
+
+            case P_FLOAT:
+            case FLOAT:
+                writer.writeFloatFieldPrimitive((float) obj);
+
+                break;
+
+            case P_DOUBLE:
+            case DOUBLE:
+                writer.writeDoubleFieldPrimitive((double) obj);
+
+                break;
+
+            case P_CHAR:
+            case CHAR:
+                writer.writeCharFieldPrimitive((char) obj);
+
+                break;
+
+            case P_BOOLEAN:
+            case BOOLEAN:
+                writer.writeBooleanFieldPrimitive((boolean) obj);
+
+                break;
+
+            case DECIMAL:
+                writer.doWriteDecimal((BigDecimal)obj);
+
+                break;
+
+            case STRING:
+                writer.doWriteString((String)obj);
+
+                break;
+
+            case UUID:
+                writer.doWriteUuid((UUID)obj);
+
+                break;
+
+            case DATE:
+                writer.doWriteDate((Date)obj);
+
+                break;
+
+            case TIMESTAMP:
+                writer.doWriteTimestamp((Timestamp)obj);
+
+                break;
+
+            case BYTE_ARR:
+                writer.doWriteByteArray((byte[])obj);
+
+                break;
+
+            case SHORT_ARR:
+                writer.doWriteShortArray((short[]) obj);
+
+                break;
+
+            case INT_ARR:
+                writer.doWriteIntArray((int[]) obj);
+
+                break;
+
+            case LONG_ARR:
+                writer.doWriteLongArray((long[]) obj);
+
+                break;
+
+            case FLOAT_ARR:
+                writer.doWriteFloatArray((float[]) obj);
+
+                break;
+
+            case DOUBLE_ARR:
+                writer.doWriteDoubleArray((double[]) obj);
+
+                break;
+
+            case CHAR_ARR:
+                writer.doWriteCharArray((char[]) obj);
+
+                break;
+
+            case BOOLEAN_ARR:
+                writer.doWriteBooleanArray((boolean[]) obj);
+
+                break;
+
+            case DECIMAL_ARR:
+                writer.doWriteDecimalArray((BigDecimal[]) obj);
+
+                break;
+
+            case STRING_ARR:
+                writer.doWriteStringArray((String[]) obj);
+
+                break;
+
+            case UUID_ARR:
+                writer.doWriteUuidArray((UUID[]) obj);
+
+                break;
+
+            case DATE_ARR:
+                writer.doWriteDateArray((Date[]) obj);
+
+                break;
+
+            case TIMESTAMP_ARR:
+                writer.doWriteTimestampArray((Timestamp[]) obj);
+
+                break;
+
+            case OBJECT_ARR:
+                writer.doWriteObjectArray((Object[])obj);
+
+                break;
+
+            case COL:
+                writer.doWriteCollection((Collection<?>)obj);
+
+                break;
+
+            case MAP:
+                writer.doWriteMap((Map<?, ?>)obj);
+
+                break;
+
+            case ENUM:
+                writer.doWriteEnum((Enum<?>)obj);
+
+                break;
+
+            case PORTABLE_ENUM:
+                writer.doWritePortableEnum((BinaryEnumObjectImpl)obj);
+
+                break;
+
+            case ENUM_ARR:
+                writer.doWriteEnumArray((Object[])obj);
+
+                break;
+
+            case CLASS:
+                writer.doWriteClass((Class)obj);
+
+                break;
+
+            case PORTABLE_OBJ:
+                writer.doWritePortableObject((BinaryObjectImpl)obj);
+
+                break;
+
+            case PORTABLE:
+                if (preWrite(writer, obj)) {
+                    try {
+                        if (serializer != null)
+                            serializer.writeBinary(obj, writer);
+                        else
+                            ((Binarylizable)obj).writeBinary(writer);
+
+                        postWrite(writer, obj);
+
+                        // Check whether we need to update metadata.
+                        if (obj.getClass() != BinaryMetadata.class) {
+                            int schemaId = writer.schemaId();
+
+                            if (schemaReg.schema(schemaId) == null) {
+                                // This is new schema, let's update metadata.
+                                BinaryMetadataCollector collector =
+                                    new BinaryMetadataCollector(typeId, typeName, idMapper);
+
+                                if (serializer != null)
+                                    serializer.writeBinary(obj, collector);
+                                else
+                                    ((Binarylizable)obj).writeBinary(collector);
+
+                                PortableSchema newSchema = collector.schema();
+
+                                BinaryMetadata meta = new BinaryMetadata(typeId, typeName, collector.meta(),
+                                    affKeyFieldName, Collections.singleton(newSchema), false);
+
+                                ctx.updateMetadata(typeId, meta);
+
+                                schemaReg.addSchema(newSchema.schemaId(), newSchema);
+                            }
+                        }
+                    }
+                    finally {
+                        writer.popSchema();
+                    }
+                }
+
+                break;
+
+            case EXTERNALIZABLE:
+                if (preWrite(writer, obj)) {
+                    writer.rawWriter();
+
+                    try {
+                        ((Externalizable)obj).writeExternal(writer);
+
+                        postWrite(writer, obj);
+                    }
+                    catch (IOException e) {
+                        throw new BinaryObjectException("Failed to write Externalizable object: " + obj, e);
+                    }
+                    finally {
+                        writer.popSchema();
+                    }
+                }
+
+                break;
+
+            case OBJECT:
+                if (preWrite(writer, obj)) {
+                    try {
+                        for (BinaryFieldAccessor info : fields)
+                            info.write(obj, writer);
+
+                        writer.schemaId(stableSchema.schemaId());
+
+                        postWrite(writer, obj);
+                    }
+                    finally {
+                        writer.popSchema();
+                    }
+                }
+
+                break;
+
+            default:
+                assert false : "Invalid mode: " + mode;
+        }
+    }
+
+    /**
+     * @param reader Reader.
+     * @return Object.
+     * @throws BinaryObjectException If failed.
+     */
+    Object read(BinaryReaderExImpl reader) throws BinaryObjectException {
+        assert reader != null;
+
+        Object res;
+
+        switch (mode) {
+            case PORTABLE:
+                res = newInstance();
+
+                reader.setHandle(res);
+
+                if (serializer != null)
+                    serializer.readBinary(res, reader);
+                else
+                    ((Binarylizable)res).readBinary(reader);
+
+                break;
+
+            case EXTERNALIZABLE:
+                res = newInstance();
+
+                reader.setHandle(res);
+
+                try {
+                    ((Externalizable)res).readExternal(reader);
+                }
+                catch (IOException | ClassNotFoundException e) {
+                    throw new BinaryObjectException("Failed to read Externalizable object: " +
+                        res.getClass().getName(), e);
+                }
+
+                break;
+
+            case OBJECT:
+                res = newInstance();
+
+                reader.setHandle(res);
+
+                for (BinaryFieldAccessor info : fields)
+                    info.read(res, reader);
+
+                break;
+
+            default:
+                assert false : "Invalid mode: " + mode;
+
+                return null;
+        }
+
+        if (readResolveMtd != null) {
+            try {
+                res = readResolveMtd.invoke(res);
+
+                reader.setHandle(res);
+            }
+            catch (IllegalAccessException e) {
+                throw new RuntimeException(e);
+            }
+            catch (InvocationTargetException e) {
+                if (e.getTargetException() instanceof BinaryObjectException)
+                    throw (BinaryObjectException)e.getTargetException();
+
+                throw new BinaryObjectException("Failed to execute readResolve() method on " + res, e);
+            }
+        }
+
+        return res;
+    }
+
+    /**
+     * Pre-write phase.
+     *
+     * @param writer Writer.
+     * @param obj Object.
+     * @return Whether further write is needed.
+     */
+    private boolean preWrite(BinaryWriterExImpl writer, Object obj) {
+        if (writer.tryWriteAsHandle(obj))
+            return false;
+
+        writer.preWrite(registered ? null : cls.getName());
+
+        return true;
+    }
+
+    /**
+     * Post-write phase.
+     *
+     * @param writer Writer.
+     * @param obj Object.
+     */
+    private void postWrite(BinaryWriterExImpl writer, Object obj) {
+        writer.postWrite(userType, registered, obj instanceof CacheObjectImpl ? 0 : obj.hashCode());
+    }
+
+    /**
+     * @return Instance.
+     * @throws BinaryObjectException In case of error.
+     */
+    private Object newInstance() throws BinaryObjectException {
+        try {
+            return ctor != null ? ctor.newInstance() : UNSAFE.allocateInstance(cls);
+        }
+        catch (InstantiationException | InvocationTargetException | IllegalAccessException e) {
+            throw new BinaryObjectException("Failed to instantiate instance: " + cls, e);
+        }
+    }
+
+    /**
+     * @param cls Class.
+     * @return Constructor.
+     * @throws BinaryObjectException If constructor doesn't exist.
+     */
+    @SuppressWarnings("ConstantConditions")
+    @Nullable private static Constructor<?> constructor(Class<?> cls) throws BinaryObjectException {
+        assert cls != null;
+
+        try {
+            Constructor<?> ctor = U.forceEmptyConstructor(cls);
+
+            if (ctor == null)
+                throw new BinaryObjectException("Failed to find empty constructor for class: " + cls.getName());
+
+            ctor.setAccessible(true);
+
+            return ctor;
+        }
+        catch (IgniteCheckedException e) {
+            throw new BinaryObjectException("Failed to get constructor for class: " + cls.getName(), e);
+        }
+    }
+
+    /**
+     * Determines whether to use {@link OptimizedMarshaller} for serialization or
+     * not.
+     *
+     * @return {@code true} if to use, {@code false} otherwise.
+     */
+    @SuppressWarnings("unchecked")
+    private boolean initUseOptimizedMarshallerFlag() {
+        for (Class c = cls; c != null && !c.equals(Object.class); c = c.getSuperclass()) {
+            try {
+                Method writeObj = c.getDeclaredMethod("writeObject", ObjectOutputStream.class);
+                Method readObj = c.getDeclaredMethod("readObject", ObjectInputStream.class);
+
+                if (!Modifier.isStatic(writeObj.getModifiers()) && !Modifier.isStatic(readObj.getModifiers()) &&
+                    writeObj.getReturnType() == void.class && readObj.getReturnType() == void.class)
+                    return true;
+            }
+            catch (NoSuchMethodException ignored) {
+                // No-op.
+            }
+        }
+
+        return false;
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/1dbf20e0/modules/core/src/main/java/org/apache/ignite/internal/binary/PortableContext.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/binary/PortableContext.java b/modules/core/src/main/java/org/apache/ignite/internal/binary/PortableContext.java
new file mode 100644
index 0000000..f7375a4
--- /dev/null
+++ b/modules/core/src/main/java/org/apache/ignite/internal/binary/PortableContext.java
@@ -0,0 +1,1102 @@
+/*
+ * 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.binary;
+
+import org.apache.ignite.IgniteCheckedException;
+import org.apache.ignite.binary.BinaryIdMapper;
+import org.apache.ignite.binary.BinaryInvalidTypeException;
+import org.apache.ignite.binary.BinaryObjectException;
+import org.apache.ignite.binary.BinarySerializer;
+import org.apache.ignite.binary.BinaryType;
+import org.apache.ignite.binary.BinaryTypeConfiguration;
+import org.apache.ignite.cache.CacheKeyConfiguration;
+import org.apache.ignite.cache.affinity.AffinityKeyMapped;
+import org.apache.ignite.configuration.BinaryConfiguration;
+import org.apache.ignite.configuration.IgniteConfiguration;
+import org.apache.ignite.internal.IgniteKernal;
+import org.apache.ignite.internal.IgnitionEx;
+import org.apache.ignite.internal.processors.cache.binary.CacheObjectBinaryProcessorImpl;
+import org.apache.ignite.internal.processors.datastructures.CollocatedQueueItemKey;
+import org.apache.ignite.internal.processors.datastructures.CollocatedSetItemKey;
+import org.apache.ignite.internal.util.IgniteUtils;
+import org.apache.ignite.internal.util.lang.GridMapEntry;
+import org.apache.ignite.internal.util.typedef.F;
+import org.apache.ignite.internal.util.typedef.T2;
+import org.apache.ignite.internal.util.typedef.internal.U;
+import org.apache.ignite.lang.IgniteBiTuple;
+import org.apache.ignite.marshaller.MarshallerContext;
+import org.apache.ignite.marshaller.optimized.OptimizedMarshaller;
+import org.jetbrains.annotations.Nullable;
+import org.jsr166.ConcurrentHashMap8;
+
+import java.io.Externalizable;
+import java.io.File;
+import java.io.IOException;
+import java.io.InvalidObjectException;
+import java.io.ObjectInput;
+import java.io.ObjectOutput;
+import java.io.ObjectStreamException;
+import java.lang.reflect.Field;
+import java.math.BigDecimal;
+import java.net.URISyntaxException;
+import java.net.URL;
+import java.net.URLClassLoader;
+import java.sql.Timestamp;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Date;
+import java.util.Enumeration;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.LinkedHashMap;
+import java.util.LinkedHashSet;
+import java.util.LinkedList;
+import java.util.Map;
+import java.util.Set;
+import java.util.UUID;
+import java.util.concurrent.ConcurrentMap;
+import java.util.jar.JarEntry;
+import java.util.jar.JarFile;
+
+/**
+ * Portable context.
+ */
+public class PortableContext implements Externalizable {
+    /** */
+    private static final long serialVersionUID = 0L;
+
+    /** */
+    private static final ClassLoader dfltLdr = U.gridClassLoader();
+
+    /** */
+    private final ConcurrentMap<Class<?>, PortableClassDescriptor> descByCls = new ConcurrentHashMap8<>();
+
+    /** Holds classes loaded by default class loader only. */
+    private final ConcurrentMap<Integer, PortableClassDescriptor> userTypes = new ConcurrentHashMap8<>();
+
+    /** */
+    private final Map<Integer, PortableClassDescriptor> predefinedTypes = new HashMap<>();
+
+    /** */
+    private final Map<String, Integer> predefinedTypeNames = new HashMap<>();
+
+    /** */
+    private final Map<Class<? extends Collection>, Byte> colTypes = new HashMap<>();
+
+    /** */
+    private final Map<Class<? extends Map>, Byte> mapTypes = new HashMap<>();
+
+    /** */
+    private final ConcurrentMap<Integer, BinaryIdMapper> mappers = new ConcurrentHashMap8<>(0);
+
+    /** Affinity key field names. */
+    private final ConcurrentMap<Integer, String> affKeyFieldNames = new ConcurrentHashMap8<>(0);
+
+    /** */
+    private final Map<String, BinaryIdMapper> typeMappers = new ConcurrentHashMap8<>(0);
+
+    /** */
+    private BinaryMetadataHandler metaHnd;
+
+    /** Actual marshaller. */
+    private BinaryMarshaller marsh;
+
+    /** */
+    private MarshallerContext marshCtx;
+
+    /** */
+    private String gridName;
+
+    /** */
+    private IgniteConfiguration igniteCfg;
+
+    /** */
+    private final OptimizedMarshaller optmMarsh = new OptimizedMarshaller();
+
+    /** Compact footer flag. */
+    private boolean compactFooter;
+
+    /** Object schemas. */
+    private volatile Map<Integer, PortableSchemaRegistry> schemas;
+
+    /**
+     * For {@link Externalizable}.
+     */
+    public PortableContext() {
+        // No-op.
+    }
+
+    /**
+     * @param metaHnd Meta data handler.
+     * @param igniteCfg Ignite configuration.
+     */
+    public PortableContext(BinaryMetadataHandler metaHnd, IgniteConfiguration igniteCfg) {
+        assert metaHnd != null;
+        assert igniteCfg != null;
+
+        this.metaHnd = metaHnd;
+        this.igniteCfg = igniteCfg;
+
+        gridName = igniteCfg.getGridName();
+
+        colTypes.put(ArrayList.class, GridPortableMarshaller.ARR_LIST);
+        colTypes.put(LinkedList.class, GridPortableMarshaller.LINKED_LIST);
+        colTypes.put(HashSet.class, GridPortableMarshaller.HASH_SET);
+        colTypes.put(LinkedHashSet.class, GridPortableMarshaller.LINKED_HASH_SET);
+
+        mapTypes.put(HashMap.class, GridPortableMarshaller.HASH_MAP);
+        mapTypes.put(LinkedHashMap.class, GridPortableMarshaller.LINKED_HASH_MAP);
+
+        // IDs range from [0..200] is used by Java SDK API and GridGain legacy API
+
+        registerPredefinedType(Byte.class, GridPortableMarshaller.BYTE);
+        registerPredefinedType(Boolean.class, GridPortableMarshaller.BOOLEAN);
+        registerPredefinedType(Short.class, GridPortableMarshaller.SHORT);
+        registerPredefinedType(Character.class, GridPortableMarshaller.CHAR);
+        registerPredefinedType(Integer.class, GridPortableMarshaller.INT);
+        registerPredefinedType(Long.class, GridPortableMarshaller.LONG);
+        registerPredefinedType(Float.class, GridPortableMarshaller.FLOAT);
+        registerPredefinedType(Double.class, GridPortableMarshaller.DOUBLE);
+        registerPredefinedType(String.class, GridPortableMarshaller.STRING);
+        registerPredefinedType(BigDecimal.class, GridPortableMarshaller.DECIMAL);
+        registerPredefinedType(Date.class, GridPortableMarshaller.DATE);
+        registerPredefinedType(Timestamp.class, GridPortableMarshaller.TIMESTAMP);
+        registerPredefinedType(UUID.class, GridPortableMarshaller.UUID);
+
+        registerPredefinedType(byte[].class, GridPortableMarshaller.BYTE_ARR);
+        registerPredefinedType(short[].class, GridPortableMarshaller.SHORT_ARR);
+        registerPredefinedType(int[].class, GridPortableMarshaller.INT_ARR);
+        registerPredefinedType(long[].class, GridPortableMarshaller.LONG_ARR);
+        registerPredefinedType(float[].class, GridPortableMarshaller.FLOAT_ARR);
+        registerPredefinedType(double[].class, GridPortableMarshaller.DOUBLE_ARR);
+        registerPredefinedType(char[].class, GridPortableMarshaller.CHAR_ARR);
+        registerPredefinedType(boolean[].class, GridPortableMarshaller.BOOLEAN_ARR);
+        registerPredefinedType(BigDecimal[].class, GridPortableMarshaller.DECIMAL_ARR);
+        registerPredefinedType(String[].class, GridPortableMarshaller.STRING_ARR);
+        registerPredefinedType(UUID[].class, GridPortableMarshaller.UUID_ARR);
+        registerPredefinedType(Date[].class, GridPortableMarshaller.DATE_ARR);
+        registerPredefinedType(Timestamp[].class, GridPortableMarshaller.TIMESTAMP_ARR);
+        registerPredefinedType(Object[].class, GridPortableMarshaller.OBJ_ARR);
+
+        registerPredefinedType(ArrayList.class, 0);
+        registerPredefinedType(LinkedList.class, 0);
+        registerPredefinedType(HashSet.class, 0);
+        registerPredefinedType(LinkedHashSet.class, 0);
+
+        registerPredefinedType(HashMap.class, 0);
+        registerPredefinedType(LinkedHashMap.class, 0);
+
+        registerPredefinedType(GridMapEntry.class, 60);
+        registerPredefinedType(IgniteBiTuple.class, 61);
+        registerPredefinedType(T2.class, 62);
+
+        // IDs range [200..1000] is used by Ignite internal APIs.
+    }
+
+    /**
+     * @return Marshaller.
+     */
+    public BinaryMarshaller marshaller() {
+        return marsh;
+    }
+
+    /**
+     * @return Ignite configuration.
+     */
+    public IgniteConfiguration configuration(){
+        return igniteCfg;
+    }
+
+    /**
+     * @param marsh Portable marshaller.
+     * @param cfg Configuration.
+     * @throws BinaryObjectException In case of error.
+     */
+    public void configure(BinaryMarshaller marsh, IgniteConfiguration cfg) throws BinaryObjectException {
+        if (marsh == null)
+            return;
+
+        this.marsh = marsh;
+
+        marshCtx = marsh.getContext();
+
+        BinaryConfiguration binaryCfg = cfg.getBinaryConfiguration();
+
+        if (binaryCfg == null)
+            binaryCfg = new BinaryConfiguration();
+
+        assert marshCtx != null;
+
+        optmMarsh.setContext(marshCtx);
+
+        configure(
+            binaryCfg.getIdMapper(),
+            binaryCfg.getSerializer(),
+            binaryCfg.getTypeConfigurations()
+        );
+
+        compactFooter = binaryCfg.isCompactFooter();
+    }
+
+    /**
+     * @param globalIdMapper ID mapper.
+     * @param globalSerializer Serializer.
+     * @param typeCfgs Type configurations.
+     * @throws BinaryObjectException In case of error.
+     */
+    private void configure(
+        BinaryIdMapper globalIdMapper,
+        BinarySerializer globalSerializer,
+        Collection<BinaryTypeConfiguration> typeCfgs
+    ) throws BinaryObjectException {
+        TypeDescriptors descs = new TypeDescriptors();
+
+        Map<String, String> affFields = new HashMap<>();
+
+        if (!F.isEmpty(igniteCfg.getCacheKeyConfiguration())) {
+            for (CacheKeyConfiguration keyCfg : igniteCfg.getCacheKeyConfiguration())
+                affFields.put(keyCfg.getTypeName(), keyCfg.getAffinityKeyFieldName());
+        }
+
+        if (typeCfgs != null) {
+            for (BinaryTypeConfiguration typeCfg : typeCfgs) {
+                String clsName = typeCfg.getTypeName();
+
+                if (clsName == null)
+                    throw new BinaryObjectException("Class name is required for portable type configuration.");
+
+                BinaryIdMapper idMapper = globalIdMapper;
+
+                if (typeCfg.getIdMapper() != null)
+                    idMapper = typeCfg.getIdMapper();
+
+                idMapper = BinaryInternalIdMapper.create(idMapper);
+
+                BinarySerializer serializer = globalSerializer;
+
+                if (typeCfg.getSerializer() != null)
+                    serializer = typeCfg.getSerializer();
+
+                if (clsName.endsWith(".*")) {
+                    String pkgName = clsName.substring(0, clsName.length() - 2);
+
+                    for (String clsName0 : classesInPackage(pkgName))
+                        descs.add(clsName0, idMapper, serializer, affFields.get(clsName0),
+                            typeCfg.isEnum(), true);
+                }
+                else
+                    descs.add(clsName, idMapper, serializer, affFields.get(clsName),
+                        typeCfg.isEnum(), false);
+            }
+        }
+
+        for (TypeDescriptor desc : descs.descriptors())
+            registerUserType(desc.clsName, desc.idMapper, desc.serializer, desc.affKeyFieldName, desc.isEnum);
+
+        BinaryInternalIdMapper dfltMapper = BinaryInternalIdMapper.create(globalIdMapper);
+
+        // Put affinity field names for unconfigured types.
+        for (Map.Entry<String, String> entry : affFields.entrySet()) {
+            String typeName = entry.getKey();
+
+            int typeId = dfltMapper.typeId(typeName);
+
+            affKeyFieldNames.putIfAbsent(typeId, entry.getValue());
+        }
+
+        addSystemClassAffinityKey(CollocatedSetItemKey.class);
+        addSystemClassAffinityKey(CollocatedQueueItemKey.class);
+    }
+
+    /**
+     * @param cls Class.
+     */
+    private void addSystemClassAffinityKey(Class<?> cls) {
+        String fieldName = affinityFieldName(cls);
+
+        assert fieldName != null : cls;
+
+        affKeyFieldNames.putIfAbsent(cls.getName().hashCode(), affinityFieldName(cls));
+    }
+
+    /**
+     * @param pkgName Package name.
+     * @return Class names.
+     */
+    @SuppressWarnings("ConstantConditions")
+    private static Iterable<String> classesInPackage(String pkgName) {
+        assert pkgName != null;
+
+        Collection<String> clsNames = new ArrayList<>();
+
+        ClassLoader ldr = U.gridClassLoader();
+
+        if (ldr instanceof URLClassLoader) {
+            String pkgPath = pkgName.replaceAll("\\.", "/");
+
+            URL[] urls = ((URLClassLoader)ldr).getURLs();
+
+            for (URL url : urls) {
+                String proto = url.getProtocol().toLowerCase();
+
+                if ("file".equals(proto)) {
+                    try {
+                        File cpElement = new File(url.toURI());
+
+                        if (cpElement.isDirectory()) {
+                            File pkgDir = new File(cpElement, pkgPath);
+
+                            if (pkgDir.isDirectory()) {
+                                for (File file : pkgDir.listFiles()) {
+                                    String fileName = file.getName();
+
+                                    if (file.isFile() && fileName.toLowerCase().endsWith(".class"))
+                                        clsNames.add(pkgName + '.' + fileName.substring(0, fileName.length() - 6));
+                                }
+                            }
+                        }
+                        else if (cpElement.isFile()) {
+                            try {
+                                JarFile jar = new JarFile(cpElement);
+
+                                Enumeration<JarEntry> entries = jar.entries();
+
+                                while (entries.hasMoreElements()) {
+                                    String entry = entries.nextElement().getName();
+
+                                    if (entry.startsWith(pkgPath) && entry.endsWith(".class")) {
+                                        String clsName = entry.substring(pkgPath.length() + 1, entry.length() - 6);
+
+                                        if (!clsName.contains("/") && !clsName.contains("\\"))
+                                            clsNames.add(pkgName + '.' + clsName);
+                                    }
+                                }
+                            }
+                            catch (IOException ignored) {
+                                // No-op.
+                            }
+                        }
+                    }
+                    catch (URISyntaxException ignored) {
+                        // No-op.
+                    }
+                }
+            }
+        }
+
+        return clsNames;
+    }
+
+    /**
+     * @param cls Class.
+     * @return Class descriptor.
+     * @throws BinaryObjectException In case of error.
+     */
+    public PortableClassDescriptor descriptorForClass(Class<?> cls, boolean deserialize)
+        throws BinaryObjectException {
+        assert cls != null;
+
+        PortableClassDescriptor desc = descByCls.get(cls);
+
+        if (desc == null || !desc.registered())
+            desc = registerClassDescriptor(cls, deserialize);
+
+        return desc;
+    }
+
+    /**
+     * @param userType User type or not.
+     * @param typeId Type ID.
+     * @param ldr Class loader.
+     * @return Class descriptor.
+     */
+    public PortableClassDescriptor descriptorForTypeId(
+        boolean userType,
+        int typeId,
+        ClassLoader ldr,
+        boolean deserialize
+    ) {
+        assert typeId != GridPortableMarshaller.UNREGISTERED_TYPE_ID;
+
+        //TODO: As a workaround for IGNITE-1358 we always check the predefined map before without checking 'userType'
+        PortableClassDescriptor desc = predefinedTypes.get(typeId);
+
+        if (desc != null)
+            return desc;
+
+        if (ldr == null)
+            ldr = dfltLdr;
+
+        // If the type hasn't been loaded by default class loader then we mustn't return the descriptor from here
+        // giving a chance to a custom class loader to reload type's class.
+        if (userType && ldr.equals(dfltLdr)) {
+            desc = userTypes.get(typeId);
+
+            if (desc != null)
+                return desc;
+        }
+
+        Class cls;
+
+        try {
+            cls = marshCtx.getClass(typeId, ldr);
+
+            desc = descByCls.get(cls);
+        }
+        catch (ClassNotFoundException e) {
+            // Class might have been loaded by default class loader.
+            if (userType && !ldr.equals(dfltLdr) && (desc = descriptorForTypeId(true, typeId, dfltLdr, deserialize)) != null)
+                return desc;
+
+            throw new BinaryInvalidTypeException(e);
+        }
+        catch (IgniteCheckedException e) {
+            // Class might have been loaded by default class loader.
+            if (userType && !ldr.equals(dfltLdr) && (desc = descriptorForTypeId(true, typeId, dfltLdr, deserialize)) != null)
+                return desc;
+
+            throw new BinaryObjectException("Failed resolve class for ID: " + typeId, e);
+        }
+
+        if (desc == null) {
+            desc = registerClassDescriptor(cls, deserialize);
+
+            assert desc.typeId() == typeId;
+        }
+
+        return desc;
+    }
+
+    /**
+     * Creates and registers {@link PortableClassDescriptor} for the given {@code class}.
+     *
+     * @param cls Class.
+     * @return Class descriptor.
+     */
+    private PortableClassDescriptor registerClassDescriptor(Class<?> cls, boolean deserialize) {
+        PortableClassDescriptor desc;
+
+        String clsName = cls.getName();
+
+        if (marshCtx.isSystemType(clsName)) {
+            desc = new PortableClassDescriptor(this,
+                cls,
+                false,
+                clsName.hashCode(),
+                clsName,
+                null,
+                BinaryInternalIdMapper.defaultInstance(),
+                null,
+                false,
+                true, /* registered */
+                false /* predefined */
+            );
+
+            PortableClassDescriptor old = descByCls.putIfAbsent(cls, desc);
+
+            if (old != null)
+                desc = old;
+        }
+        else
+            desc = registerUserClassDescriptor(cls, deserialize);
+
+        return desc;
+    }
+
+    /**
+     * Creates and registers {@link PortableClassDescriptor} for the given user {@code class}.
+     *
+     * @param cls Class.
+     * @return Class descriptor.
+     */
+    private PortableClassDescriptor registerUserClassDescriptor(Class<?> cls, boolean deserialize) {
+        boolean registered;
+
+        String typeName = typeName(cls.getName());
+
+        BinaryIdMapper idMapper = userTypeIdMapper(typeName);
+
+        int typeId = idMapper.typeId(typeName);
+
+        try {
+            registered = marshCtx.registerClass(typeId, cls);
+        }
+        catch (IgniteCheckedException e) {
+            throw new BinaryObjectException("Failed to register class.", e);
+        }
+
+        String affFieldName = affinityFieldName(cls);
+
+        PortableClassDescriptor desc = new PortableClassDescriptor(this,
+            cls,
+            true,
+            typeId,
+            typeName,
+            affFieldName,
+            idMapper,
+            null,
+            true,
+            registered,
+            false /* predefined */
+        );
+
+        if (!deserialize) {
+            Collection<PortableSchema> schemas = desc.schema() != null ? Collections.singleton(desc.schema()) : null;
+
+            metaHnd.addMeta(typeId,
+                new BinaryMetadata(typeId, typeName, desc.fieldsMeta(), affFieldName, schemas, desc.isEnum()).wrap(this));
+        }
+
+        // perform put() instead of putIfAbsent() because "registered" flag might have been changed or class loader
+        // might have reloaded described class.
+        if (IgniteUtils.detectClassLoader(cls).equals(dfltLdr))
+            userTypes.put(typeId, desc);
+
+        descByCls.put(cls, desc);
+
+        mappers.putIfAbsent(typeId, idMapper);
+
+        return desc;
+    }
+
+    /**
+     * @param cls Collection class.
+     * @return Collection type ID.
+     */
+    public byte collectionType(Class<? extends Collection> cls) {
+        assert cls != null;
+
+        Byte type = colTypes.get(cls);
+
+        if (type != null)
+            return type;
+
+        return Set.class.isAssignableFrom(cls) ? GridPortableMarshaller.USER_SET : GridPortableMarshaller.USER_COL;
+    }
+
+    /**
+     * @param cls Map class.
+     * @return Map type ID.
+     */
+    public byte mapType(Class<? extends Map> cls) {
+        assert cls != null;
+
+        Byte type = mapTypes.get(cls);
+
+        return type != null ? type : GridPortableMarshaller.USER_COL;
+    }
+
+    /**
+     * @param typeName Type name.
+     * @return Type ID.
+     */
+    public int typeId(String typeName) {
+        String typeName0 = typeName(typeName);
+
+        Integer id = predefinedTypeNames.get(typeName0);
+
+        if (id != null)
+            return id;
+
+        if (marshCtx.isSystemType(typeName))
+            return typeName.hashCode();
+
+        return userTypeIdMapper(typeName0).typeId(typeName0);
+    }
+
+    /**
+     * @param typeId Type ID.
+     * @param fieldName Field name.
+     * @return Field ID.
+     */
+    public int fieldId(int typeId, String fieldName) {
+        return userTypeIdMapper(typeId).fieldId(typeId, fieldName);
+    }
+
+    /**
+     * @param typeId Type ID.
+     * @return Instance of ID mapper.
+     */
+    public BinaryIdMapper userTypeIdMapper(int typeId) {
+        BinaryIdMapper idMapper = mappers.get(typeId);
+
+        return idMapper != null ? idMapper : BinaryInternalIdMapper.defaultInstance();
+    }
+
+    /**
+     * @param typeName Type name.
+     * @return Instance of ID mapper.
+     */
+    private BinaryIdMapper userTypeIdMapper(String typeName) {
+        BinaryIdMapper idMapper = typeMappers.get(typeName);
+
+        return idMapper != null ? idMapper : BinaryInternalIdMapper.defaultInstance();
+    }
+
+    /**
+     * @param cls Class to get affinity field for.
+     * @return Affinity field name or {@code null} if field name was not found.
+     */
+    private String affinityFieldName(Class cls) {
+        for (; cls != Object.class && cls != null; cls = cls.getSuperclass()) {
+            for (Field f : cls.getDeclaredFields()) {
+                if (f.getAnnotation(AffinityKeyMapped.class) != null)
+                    return f.getName();
+            }
+        }
+
+        return null;
+    }
+
+    /** {@inheritDoc} */
+    @Override public void writeExternal(ObjectOutput out) throws IOException {
+        U.writeString(out, igniteCfg.getGridName());
+    }
+
+    /** {@inheritDoc} */
+    @Override public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
+        gridName = U.readString(in);
+    }
+
+    /**
+     * @return Portable context.
+     * @throws ObjectStreamException In case of error.
+     */
+    protected Object readResolve() throws ObjectStreamException {
+        try {
+            IgniteKernal g = IgnitionEx.gridx(gridName);
+
+            if (g == null)
+                throw new IllegalStateException("Failed to find grid for name: " + gridName);
+
+            return ((CacheObjectBinaryProcessorImpl)g.context().cacheObjects()).portableContext();
+        }
+        catch (IllegalStateException e) {
+            throw U.withCause(new InvalidObjectException(e.getMessage()), e);
+        }
+    }
+
+    /**
+     * @param cls Class.
+     * @param id Type ID.
+     * @return GridPortableClassDescriptor.
+     */
+    public PortableClassDescriptor registerPredefinedType(Class<?> cls, int id) {
+        String typeName = typeName(cls.getName());
+
+        PortableClassDescriptor desc = new PortableClassDescriptor(
+            this,
+            cls,
+            false,
+            id,
+            typeName,
+            null,
+            BinaryInternalIdMapper.defaultInstance(),
+            null,
+            false,
+            true, /* registered */
+            true /* predefined */
+        );
+
+        predefinedTypeNames.put(typeName, id);
+        predefinedTypes.put(id, desc);
+
+        descByCls.put(cls, desc);
+
+        return desc;
+    }
+
+    /**
+     * @param clsName Class name.
+     * @param idMapper ID mapper.
+     * @param serializer Serializer.
+     * @param affKeyFieldName Affinity key field name.
+     * @param isEnum If enum.
+     * @throws BinaryObjectException In case of error.
+     */
+    @SuppressWarnings("ErrorNotRethrown")
+    public void registerUserType(String clsName,
+        BinaryIdMapper idMapper,
+        @Nullable BinarySerializer serializer,
+        @Nullable String affKeyFieldName,
+        boolean isEnum)
+        throws BinaryObjectException {
+        assert idMapper != null;
+
+        Class<?> cls = null;
+
+        try {
+            cls = Class.forName(clsName);
+        }
+        catch (ClassNotFoundException | NoClassDefFoundError ignored) {
+            // No-op.
+        }
+
+        String typeName = typeName(clsName);
+
+        int id = idMapper.typeId(typeName);
+
+        //Workaround for IGNITE-1358
+        if (predefinedTypes.get(id) != null)
+            throw new BinaryObjectException("Duplicate type ID [clsName=" + clsName + ", id=" + id + ']');
+
+        if (mappers.put(id, idMapper) != null)
+            throw new BinaryObjectException("Duplicate type ID [clsName=" + clsName + ", id=" + id + ']');
+
+        if (affKeyFieldName != null) {
+            if (affKeyFieldNames.put(id, affKeyFieldName) != null)
+                throw new BinaryObjectException("Duplicate type ID [clsName=" + clsName + ", id=" + id + ']');
+        }
+
+        typeMappers.put(typeName, idMapper);
+
+        Map<String, Integer> fieldsMeta = null;
+        Collection<PortableSchema> schemas = null;
+
+        if (cls != null) {
+            PortableClassDescriptor desc = new PortableClassDescriptor(
+                this,
+                cls,
+                true,
+                id,
+                typeName,
+                affKeyFieldName,
+                idMapper,
+                serializer,
+                true,
+                true, /* registered */
+                false /* predefined */
+            );
+
+            fieldsMeta = desc.fieldsMeta();
+            schemas = desc.schema() != null ? Collections.singleton(desc.schema()) : null;
+
+            if (IgniteUtils.detectClassLoader(cls).equals(dfltLdr))
+                userTypes.put(id, desc);
+
+            descByCls.put(cls, desc);
+        }
+
+        metaHnd.addMeta(id, new BinaryMetadata(id, typeName, fieldsMeta, affKeyFieldName, schemas, isEnum).wrap(this));
+    }
+
+    /**
+     * Create binary field.
+     *
+     * @param typeId Type ID.
+     * @param fieldName Field name.
+     * @return Binary field.
+     */
+    public BinaryFieldImpl createField(int typeId, String fieldName) {
+        PortableSchemaRegistry schemaReg = schemaRegistry(typeId);
+
+        int fieldId = userTypeIdMapper(typeId).fieldId(typeId, fieldName);
+
+        return new BinaryFieldImpl(typeId, schemaReg, fieldName, fieldId);
+    }
+
+    /**
+     * @param typeId Type ID.
+     * @return Meta data.
+     * @throws BinaryObjectException In case of error.
+     */
+    @Nullable public BinaryType metadata(int typeId) throws BinaryObjectException {
+        return metaHnd != null ? metaHnd.metadata(typeId) : null;
+    }
+
+    /**
+     * @param typeId Type ID.
+     * @return Affinity key field name.
+     */
+    public String affinityKeyFieldName(int typeId) {
+        return affKeyFieldNames.get(typeId);
+    }
+
+    /**
+     * @param typeId Type ID.
+     * @param meta Meta data.
+     * @throws BinaryObjectException In case of error.
+     */
+    public void updateMetadata(int typeId, BinaryMetadata meta) throws BinaryObjectException {
+        metaHnd.addMeta(typeId, meta.wrap(this));
+    }
+
+    /**
+     * @return Whether field IDs should be skipped in footer or not.
+     */
+    public boolean isCompactFooter() {
+        return compactFooter;
+    }
+
+    /**
+     * Get schema registry for type ID.
+     *
+     * @param typeId Type ID.
+     * @return Schema registry for type ID.
+     */
+    public PortableSchemaRegistry schemaRegistry(int typeId) {
+        Map<Integer, PortableSchemaRegistry> schemas0 = schemas;
+
+        if (schemas0 == null) {
+            synchronized (this) {
+                schemas0 = schemas;
+
+                if (schemas0 == null) {
+                    schemas0 = new HashMap<>();
+
+                    PortableSchemaRegistry reg = new PortableSchemaRegistry();
+
+                    schemas0.put(typeId, reg);
+
+                    schemas = schemas0;
+
+                    return reg;
+                }
+            }
+        }
+
+        PortableSchemaRegistry reg = schemas0.get(typeId);
+
+        if (reg == null) {
+            synchronized (this) {
+                reg = schemas.get(typeId);
+
+                if (reg == null) {
+                    reg = new PortableSchemaRegistry();
+
+                    schemas0 = new HashMap<>(schemas);
+
+                    schemas0.put(typeId, reg);
+
+                    schemas = schemas0;
+                }
+            }
+        }
+
+        return reg;
+    }
+
+    /**
+     * Returns instance of {@link OptimizedMarshaller}.
+     *
+     * @return Optimized marshaller.
+     */
+    OptimizedMarshaller optimizedMarsh() {
+        return optmMarsh;
+    }
+
+    /**
+     * @param clsName Class name.
+     * @return Type name.
+     */
+    @SuppressWarnings("ResultOfMethodCallIgnored")
+    public static String typeName(String clsName) {
+        assert clsName != null;
+
+        int idx = clsName.lastIndexOf('$');
+
+        if (idx == clsName.length() - 1)
+            // This is a regular (not inner) class name that ends with '$'. Common use case for Scala classes.
+            idx = -1;
+        else if (idx >= 0) {
+            String typeName = clsName.substring(idx + 1);
+
+            try {
+                Integer.parseInt(typeName);
+
+                // This is an anonymous class. Don't cut off enclosing class name for it.
+                idx = -1;
+            }
+            catch (NumberFormatException ignore) {
+                // This is a lambda class.
+                if (clsName.indexOf("$$Lambda$") > 0)
+                    idx = -1;
+                else
+                    return typeName;
+            }
+        }
+
+        if (idx < 0)
+            idx = clsName.lastIndexOf('.');
+
+        return idx >= 0 ? clsName.substring(idx + 1) : clsName;
+    }
+
+    /**
+     * Undeployment callback invoked when class loader is being undeployed.
+     *
+     * Some marshallers may want to clean their internal state that uses the undeployed class loader somehow.
+     *
+     * @param ldr Class loader being undeployed.
+     */
+    public void onUndeploy(ClassLoader ldr) {
+        for (Class<?> cls : descByCls.keySet()) {
+            if (ldr.equals(cls.getClassLoader()))
+                descByCls.remove(cls);
+        }
+
+        U.clearClassCache(ldr);
+    }
+
+    /**
+     * Type descriptors.
+     */
+    private static class TypeDescriptors {
+        /** Descriptors map. */
+        private final Map<String, TypeDescriptor> descs = new LinkedHashMap<>();
+
+        /**
+         * Add type descriptor.
+         *
+         * @param clsName Class name.
+         * @param idMapper ID mapper.
+         * @param serializer Serializer.
+         * @param affKeyFieldName Affinity key field name.
+         * @param isEnum Enum flag.
+         * @param canOverride Whether this descriptor can be override.
+         * @throws BinaryObjectException If failed.
+         */
+        private void add(String clsName,
+            BinaryIdMapper idMapper,
+            BinarySerializer serializer,
+            String affKeyFieldName,
+            boolean isEnum,
+            boolean canOverride)
+            throws BinaryObjectException {
+            TypeDescriptor desc = new TypeDescriptor(clsName,
+                idMapper,
+                serializer,
+                affKeyFieldName,
+                isEnum,
+                canOverride);
+
+            TypeDescriptor oldDesc = descs.get(clsName);
+
+            if (oldDesc == null)
+                descs.put(clsName, desc);
+            else
+                oldDesc.override(desc);
+        }
+
+        /**
+         * Get all collected descriptors.
+         *
+         * @return Descriptors.
+         */
+        private Iterable<TypeDescriptor> descriptors() {
+            return descs.values();
+        }
+    }
+
+    /**
+     * Type descriptor.
+     */
+    private static class TypeDescriptor {
+        /** Class name. */
+        private final String clsName;
+
+        /** ID mapper. */
+        private BinaryIdMapper idMapper;
+
+        /** Serializer. */
+        private BinarySerializer serializer;
+
+        /** Affinity key field name. */
+        private String affKeyFieldName;
+
+        /** Enum flag. */
+        private boolean isEnum;
+
+        /** Whether this descriptor can be override. */
+        private boolean canOverride;
+
+        /**
+         * Constructor.
+         *
+         * @param clsName Class name.
+         * @param idMapper ID mapper.
+         * @param serializer Serializer.
+         * @param affKeyFieldName Affinity key field name.
+         * @param isEnum Enum type.
+         * @param canOverride Whether this descriptor can be override.
+         */
+        private TypeDescriptor(String clsName, BinaryIdMapper idMapper, BinarySerializer serializer,
+            String affKeyFieldName, boolean isEnum, boolean canOverride) {
+            this.clsName = clsName;
+            this.idMapper = idMapper;
+            this.serializer = serializer;
+            this.affKeyFieldName = affKeyFieldName;
+            this.isEnum = isEnum;
+            this.canOverride = canOverride;
+        }
+
+        /**
+         * Override portable class descriptor.
+         *
+         * @param other Other descriptor.
+         * @throws BinaryObjectException If failed.
+         */
+        private void override(TypeDescriptor other) throws BinaryObjectException {
+            assert clsName.equals(other.clsName);
+
+            if (canOverride) {
+                idMapper = other.idMapper;
+                serializer = other.serializer;
+                affKeyFieldName = other.affKeyFieldName;
+                canOverride = other.canOverride;
+            }
+            else if (!other.canOverride)
+                throw new BinaryObjectException("Duplicate explicit class definition in configuration: " + clsName);
+        }
+    }
+
+    /**
+     * Type id wrapper.
+     */
+    static class Type {
+        /** Type id */
+        private final int id;
+
+        /** Whether the following type is registered in a cache or not */
+        private final boolean registered;
+
+        /**
+         * @param id Id.
+         * @param registered Registered.
+         */
+        public Type(int id, boolean registered) {
+            this.id = id;
+            this.registered = registered;
+        }
+
+        /**
+         * @return Type ID.
+         */
+        public int id() {
+            return id;
+        }
+
+        /**
+         * @return Registered flag value.
+         */
+        public boolean registered() {
+            return registered;
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/1dbf20e0/modules/core/src/main/java/org/apache/ignite/internal/binary/PortablePositionReadable.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/binary/PortablePositionReadable.java b/modules/core/src/main/java/org/apache/ignite/internal/binary/PortablePositionReadable.java
new file mode 100644
index 0000000..8db6384
--- /dev/null
+++ b/modules/core/src/main/java/org/apache/ignite/internal/binary/PortablePositionReadable.java
@@ -0,0 +1,47 @@
+/*
+ * 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.binary;
+
+/**
+ * Interface allowing for positioned read.
+ */
+public interface PortablePositionReadable {
+    /**
+     * Read byte at the given position.
+     *
+     * @param pos Position.
+     * @return Value.
+     */
+    public byte readBytePositioned(int pos);
+
+    /**
+     * Read short at the given position.
+     *
+     * @param pos Position.
+     * @return Value.
+     */
+    public short readShortPositioned(int pos);
+
+    /**
+     * Read integer at the given position.
+     *
+     * @param pos Position.
+     * @return Value.
+     */
+    public int readIntPositioned(int pos);
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/1dbf20e0/modules/core/src/main/java/org/apache/ignite/internal/binary/PortablePrimitives.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/binary/PortablePrimitives.java b/modules/core/src/main/java/org/apache/ignite/internal/binary/PortablePrimitives.java
new file mode 100644
index 0000000..e5ff494
--- /dev/null
+++ b/modules/core/src/main/java/org/apache/ignite/internal/binary/PortablePrimitives.java
@@ -0,0 +1,382 @@
+/*
+ * 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.binary;
+
+import org.apache.ignite.internal.util.GridUnsafe;
+import sun.misc.Unsafe;
+
+import java.nio.ByteOrder;
+
+/**
+ * Primitives writer.
+ */
+public abstract class PortablePrimitives {
+    /** */
+    private static final Unsafe UNSAFE = GridUnsafe.unsafe();
+
+    /** */
+    private static final long BYTE_ARR_OFF = UNSAFE.arrayBaseOffset(byte[].class);
+
+    /** */
+    private static final long CHAR_ARR_OFF = UNSAFE.arrayBaseOffset(char[].class);
+
+    /** Whether little endian is set. */
+    private static final boolean BIG_ENDIAN = ByteOrder.nativeOrder() == ByteOrder.BIG_ENDIAN;
+
+    /**
+     * @param arr Array.
+     * @param off Offset.
+     * @param val Value.
+     */
+    public static void writeByte(byte[] arr, int off, byte val) {
+        UNSAFE.putByte(arr, BYTE_ARR_OFF + off, val);
+    }
+
+    /**
+     * @param arr Array.
+     * @param off Offset.
+     * @return Value.
+     */
+    public static byte readByte(byte[] arr, int off) {
+        return UNSAFE.getByte(arr, BYTE_ARR_OFF + off);
+    }
+
+    /**
+     * @param ptr Pointer.
+     * @param off Offset.
+     * @return Value.
+     */
+    public static byte readByte(long ptr, int off) {
+        return UNSAFE.getByte(ptr + off);
+    }
+
+    /**
+     * @param arr Array.
+     * @param off Offset.
+     * @return Value.
+     */
+    public static byte[] readByteArray(byte[] arr, int off, int len) {
+        byte[] arr0 = new byte[len];
+
+        UNSAFE.copyMemory(arr, BYTE_ARR_OFF + off, arr0, BYTE_ARR_OFF, len);
+
+        return arr0;
+    }
+
+    /**
+     * @param ptr Pointer.
+     * @param off Offset.
+     * @return Value.
+     */
+    public static byte[] readByteArray(long ptr, int off, int len) {
+        byte[] arr0 = new byte[len];
+
+        UNSAFE.copyMemory(null, ptr + off, arr0, BYTE_ARR_OFF, len);
+
+        return arr0;
+    }
+
+    /**
+     * @param arr Array.
+     * @param off Offset.
+     * @param val Value.
+     */
+    public static void writeBoolean(byte[] arr, int off, boolean val) {
+        writeByte(arr, off, val ? (byte)1 : (byte)0);
+    }
+
+    /**
+     * @param arr Array.
+     * @param off Offset.
+     * @return Value.
+     */
+    public static boolean readBoolean(byte[] arr, int off) {
+        return readByte(arr, off) == 1;
+    }
+
+    /**
+     * @param ptr Pointer.
+     * @param off Offset.
+     * @return Value.
+     */
+    public static boolean readBoolean(long ptr, int off) {
+        return readByte(ptr, off) == 1;
+    }
+
+    /**
+     * @param arr Array.
+     * @param off Offset.
+     * @param val Value.
+     */
+    public static void writeShort(byte[] arr, int off, short val) {
+        if (BIG_ENDIAN)
+            val = Short.reverseBytes(val);
+
+        UNSAFE.putShort(arr, BYTE_ARR_OFF + off, val);
+    }
+
+    /**
+     * @param arr Array.
+     * @param off Offset.
+     * @return Value.
+     */
+    public static short readShort(byte[] arr, int off) {
+        short val = UNSAFE.getShort(arr, BYTE_ARR_OFF + off);
+
+        if (BIG_ENDIAN)
+            val = Short.reverseBytes(val);
+
+        return val;
+    }
+
+    /**
+     * @param ptr Pointer.
+     * @param off Offset.
+     * @return Value.
+     */
+    public static short readShort(long ptr, int off) {
+        short val = UNSAFE.getShort(ptr + off);
+
+        if (BIG_ENDIAN)
+            val = Short.reverseBytes(val);
+
+        return val;
+    }
+
+    /**
+     * @param arr Array.
+     * @param off Offset.
+     * @param val Value.
+     */
+    public static void writeChar(byte[] arr, int off, char val) {
+        if (BIG_ENDIAN)
+            val = Character.reverseBytes(val);
+
+        UNSAFE.putChar(arr, BYTE_ARR_OFF + off, val);
+    }
+
+    /**
+     * @param arr Array.
+     * @param off Offset.
+     * @return Value.
+     */
+    public static char readChar(byte[] arr, int off) {
+        char val = UNSAFE.getChar(arr, BYTE_ARR_OFF + off);
+
+        if (BIG_ENDIAN)
+            val = Character.reverseBytes(val);
+
+        return val;
+    }
+
+    /**
+     * @param ptr Pointer.
+     * @param off Offset.
+     * @return Value.
+     */
+    public static char readChar(long ptr, int off) {
+        char val = UNSAFE.getChar(ptr + off);
+
+        if (BIG_ENDIAN)
+            val = Character.reverseBytes(val);
+
+        return val;
+    }
+
+    /**
+     * @param arr Array.
+     * @param off Offset.
+     * @return Value.
+     */
+    public static char[] readCharArray(byte[] arr, int off, int len) {
+        char[] arr0 = new char[len];
+
+        UNSAFE.copyMemory(arr, BYTE_ARR_OFF + off, arr0, CHAR_ARR_OFF, len << 1);
+
+        if (BIG_ENDIAN) {
+            for (int i = 0; i < len; i++)
+                arr0[i] = Character.reverseBytes(arr0[i]);
+        }
+
+        return arr0;
+    }
+
+    /**
+     * @param ptr Pointer.
+     * @param off Offset.
+     * @return Value.
+     */
+    public static char[] readCharArray(long ptr, int off, int len) {
+        char[] arr0 = new char[len];
+
+        UNSAFE.copyMemory(null, ptr + off, arr0, CHAR_ARR_OFF, len << 1);
+
+        if (BIG_ENDIAN) {
+            for (int i = 0; i < len; i++)
+                arr0[i] = Character.reverseBytes(arr0[i]);
+        }
+
+        return arr0;
+    }
+
+    /**
+     * @param arr Array.
+     * @param off Offset.
+     * @param val Value.
+     */
+    public static void writeInt(byte[] arr, int off, int val) {
+        if (BIG_ENDIAN)
+            val = Integer.reverseBytes(val);
+
+        UNSAFE.putInt(arr, BYTE_ARR_OFF + off, val);
+    }
+
+    /**
+     * @param arr Array.
+     * @param off Offset.
+     * @return Value.
+     */
+    public static int readInt(byte[] arr, int off) {
+        int val = UNSAFE.getInt(arr, BYTE_ARR_OFF + off);
+
+        if (BIG_ENDIAN)
+            val = Integer.reverseBytes(val);
+
+        return val;
+    }
+
+    /**
+     * @param ptr Pointer.
+     * @param off Offset.
+     * @return Value.
+     */
+    public static int readInt(long ptr, int off) {
+        int val = UNSAFE.getInt(ptr + off);
+
+        if (BIG_ENDIAN)
+            val = Integer.reverseBytes(val);
+
+        return val;
+    }
+
+    /**
+     * @param arr Array.
+     * @param off Offset.
+     * @param val Value.
+     */
+    public static void writeLong(byte[] arr, int off, long val) {
+        if (BIG_ENDIAN)
+            val = Long.reverseBytes(val);
+
+        UNSAFE.putLong(arr, BYTE_ARR_OFF + off, val);
+    }
+
+    /**
+     * @param arr Array.
+     * @param off Offset.
+     * @return Value.
+     */
+    public static long readLong(byte[] arr, int off) {
+        long val = UNSAFE.getLong(arr, BYTE_ARR_OFF + off);
+
+        if (BIG_ENDIAN)
+            val = Long.reverseBytes(val);
+
+        return val;
+    }
+
+    /**
+     * @param ptr Pointer.
+     * @param off Offset.
+     * @return Value.
+     */
+    public static long readLong(long ptr, int off) {
+        long val = UNSAFE.getLong(ptr + off);
+
+        if (BIG_ENDIAN)
+            val = Long.reverseBytes(val);
+
+        return val;
+    }
+
+    /**
+     * @param arr Array.
+     * @param off Offset.
+     * @param val Value.
+     */
+    public static void writeFloat(byte[] arr, int off, float val) {
+        int val0 = Float.floatToIntBits(val);
+
+        writeInt(arr, off, val0);
+    }
+
+    /**
+     * @param arr Array.
+     * @param off Offset.
+     * @return Value.
+     */
+    public static float readFloat(byte[] arr, int off) {
+        int val = readInt(arr, off);
+
+        return Float.intBitsToFloat(val);
+    }
+
+    /**
+     * @param ptr Pointer.
+     * @param off Offset.
+     * @return Value.
+     */
+    public static float readFloat(long ptr, int off) {
+        int val = readInt(ptr, off);
+
+        return Float.intBitsToFloat(val);
+    }
+
+    /**
+     * @param arr Array.
+     * @param off Offset.
+     * @param val Value.
+     */
+    public static void writeDouble(byte[] arr, int off, double val) {
+        long val0 = Double.doubleToLongBits(val);
+
+        writeLong(arr, off, val0);
+    }
+
+    /**
+     * @param arr Array.
+     * @param off Offset.
+     * @return Value.
+     */
+    public static double readDouble(byte[] arr, int off) {
+        long val = readLong(arr, off);
+
+        return Double.longBitsToDouble(val);
+    }
+
+    /**
+     * @param ptr Pointer.
+     * @param off Offset.
+     * @return Value.
+     */
+    public static double readDouble(long ptr, int off) {
+        long val = readLong(ptr, off);
+
+        return Double.longBitsToDouble(val);
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/1dbf20e0/modules/core/src/main/java/org/apache/ignite/internal/binary/PortableSchema.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/binary/PortableSchema.java b/modules/core/src/main/java/org/apache/ignite/internal/binary/PortableSchema.java
new file mode 100644
index 0000000..61b5d45
--- /dev/null
+++ b/modules/core/src/main/java/org/apache/ignite/internal/binary/PortableSchema.java
@@ -0,0 +1,466 @@
+/*
+ * 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.binary;
+
+import java.io.Externalizable;
+import java.io.IOException;
+import java.io.ObjectInput;
+import java.io.ObjectOutput;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+/**
+ * Schema describing portable object content. We rely on the following assumptions:
+ * - When amount of fields in the object is low, it is better to inline these values into int fields thus allowing
+ * for quick comparisons performed within already fetched L1 cache line.
+ * - When there are more fields, we store them inside a hash map.
+ */
+public class PortableSchema implements Externalizable {
+    /** */
+    private static final long serialVersionUID = 0L;
+
+    /** Order returned if field is not found. */
+    public static final int ORDER_NOT_FOUND = -1;
+
+    /** Minimum sensible size. */
+    private static final int MAP_MIN_SIZE = 32;
+
+    /** Empty cell. */
+    private static final int MAP_EMPTY = 0;
+
+    /** Schema ID. */
+    private int schemaId;
+
+    /** IDs depending on order. */
+    private int[] ids;
+
+    /** Interned names of associated fields. */
+    private String[] names;
+
+    /** ID-to-order data. */
+    private int[] idToOrderData;
+
+    /** ID-to-order mask. */
+    private int idToOrderMask;
+
+    /** ID 1. */
+    private int id0;
+
+    /** ID 2. */
+    private int id1;
+
+    /** ID 3. */
+    private int id2;
+
+    /** ID 4. */
+    private int id3;
+
+    /**
+     * {@link Externalizable} support.
+     */
+    public PortableSchema() {
+        // No-op.
+    }
+
+    /**
+     * Constructor.
+     *
+     * @param schemaId Schema ID.
+     * @param fieldIds Field IDs.
+     */
+    private PortableSchema(int schemaId, List<Integer> fieldIds) {
+        assert fieldIds != null;
+
+        this.schemaId = schemaId;
+
+        initialize(fieldIds);
+    }
+
+    /**
+     * @return Schema ID.
+     */
+    public int schemaId() {
+        return schemaId;
+    }
+
+    /**
+     * Try speculatively confirming order for the given field name.
+     *
+     * @param expOrder Expected order.
+     * @param expName Expected name.
+     * @return Field ID.
+     */
+    @SuppressWarnings("StringEquality")
+    public Confirmation confirmOrder(int expOrder, String expName) {
+        assert expName != null;
+
+        if (expOrder < names.length) {
+            String name = names[expOrder];
+
+            // Note that we use only reference equality assuming that field names are interned literals.
+            if (name == expName)
+                return Confirmation.CONFIRMED;
+
+            if (name == null)
+                return Confirmation.CLARIFY;
+        }
+
+        return Confirmation.REJECTED;
+    }
+
+    /**
+     * Add field name.
+     *
+     * @param order Order.
+     * @param name Name.
+     */
+    public void clarifyFieldName(int order, String name) {
+        assert name != null;
+        assert order < names.length;
+
+        names[order] = name.intern();
+    }
+
+    /**
+     * Get field ID by order in footer.
+     *
+     * @param order Order.
+     * @return Field ID.
+     */
+    public int fieldId(int order) {
+        return order < ids.length ? ids[order] : 0;
+    }
+
+    /**
+     * Get field order in footer by field ID.
+     *
+     * @param id Field ID.
+     * @return Offset or {@code 0} if there is no such field.
+     */
+    public int order(int id) {
+        if (idToOrderData == null) {
+            if (id == id0)
+                return 0;
+
+            if (id == id1)
+                return 1;
+
+            if (id == id2)
+                return 2;
+
+            if (id == id3)
+                return 3;
+
+            return ORDER_NOT_FOUND;
+        }
+        else {
+            int idx = (id & idToOrderMask) << 1;
+
+            int curId = idToOrderData[idx];
+
+            if (id == curId) // Hit!
+                return idToOrderData[idx + 1];
+            else if (curId == MAP_EMPTY) // No such ID!
+                return ORDER_NOT_FOUND;
+            else {
+                // Unlikely collision scenario.
+                for (int i = 2; i < idToOrderData.length; i += 2) {
+                    int newIdx = (idx + i) % idToOrderData.length;
+
+                    assert newIdx < idToOrderData.length - 1;
+
+                    curId = idToOrderData[newIdx];
+
+                    if (id == curId)
+                        return idToOrderData[newIdx + 1];
+                    else if (curId == MAP_EMPTY)
+                        return ORDER_NOT_FOUND;
+                }
+
+                return ORDER_NOT_FOUND;
+            }
+        }
+    }
+
+    /** {@inheritDoc} */
+    @Override public int hashCode() {
+        return schemaId;
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean equals(Object o) {
+        return o != null && o instanceof PortableSchema && schemaId == ((PortableSchema)o).schemaId;
+    }
+
+    /** {@inheritDoc} */
+    @Override public void writeExternal(ObjectOutput out) throws IOException {
+        out.writeInt(schemaId);
+
+        out.writeInt(ids.length);
+
+        for (Integer id : ids)
+            out.writeInt(id);
+    }
+
+    /** {@inheritDoc} */
+    @Override public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
+        schemaId = in.readInt();
+
+        int idsCnt = in.readInt();
+
+        List<Integer> fieldIds = new ArrayList<>(idsCnt);
+
+        for (int i = 0; i < idsCnt; i++)
+            fieldIds.add(in.readInt());
+
+        initialize(fieldIds);
+    }
+
+    /**
+     * Parse values.
+     *
+     * @param vals Values.
+     * @param size Proposed result size.
+     * @return Parse result.
+     */
+    private static ParseResult parse(int[] vals, int size) {
+        int mask = maskForPowerOfTwo(size);
+
+        int totalSize = size * 2;
+
+        int[] data = new int[totalSize];
+        int collisions = 0;
+
+        for (int order = 0; order < vals.length; order++) {
+            int id = vals[order];
+
+            assert id != 0;
+
+            int idIdx = (id & mask) << 1;
+
+            if (data[idIdx] == 0) {
+                // Found empty slot.
+                data[idIdx] = id;
+                data[idIdx + 1] = order;
+            }
+            else {
+                // Collision!
+                collisions++;
+
+                boolean placeFound = false;
+
+                for (int i = 2; i < totalSize; i += 2) {
+                    int newIdIdx = (idIdx + i) % totalSize;
+
+                    if (data[newIdIdx] == 0) {
+                        data[newIdIdx] = id;
+                        data[newIdIdx + 1] = order;
+
+                        placeFound = true;
+
+                        break;
+                    }
+                }
+
+                assert placeFound : "Should always have a place for entry!";
+            }
+        }
+
+        return new ParseResult(data, collisions);
+    }
+
+    /**
+     * Get next power of two which greater or equal to the given number.
+     * This implementation is not meant to be very efficient, so it is expected to be used relatively rare.
+     *
+     * @param val Number
+     * @return Nearest pow2.
+     */
+    private static int nextPowerOfTwo(int val) {
+        int res = 1;
+
+        while (res < val)
+            res = res << 1;
+
+        if (res < 0)
+            throw new IllegalArgumentException("Value is too big to find positive pow2: " + val);
+
+        return res;
+    }
+
+    /**
+     * Calculate mask for the given value which is a power of two.
+     *
+     * @param val Value.
+     * @return Mask.
+     */
+    private static int maskForPowerOfTwo(int val) {
+        int mask = 0;
+        int comparand = 1;
+
+        while (comparand < val) {
+            mask |= comparand;
+
+            comparand <<= 1;
+        }
+
+        return mask;
+    }
+
+    /**
+     * Initialization routine.
+     *
+     * @param fieldIds Field IDs.
+     */
+    private void initialize(List<Integer> fieldIds) {
+        ids = new int[fieldIds.size()];
+
+        for (int i = 0; i < fieldIds.size(); i++)
+            ids[i] = fieldIds.get(i);
+
+        names = new String[fieldIds.size()];
+
+        if (fieldIds.size() <= 4) {
+            Iterator<Integer> iter = fieldIds.iterator();
+
+            id0 = iter.hasNext() ? iter.next() : 0;
+            id1 = iter.hasNext() ? iter.next() : 0;
+            id2 = iter.hasNext() ? iter.next() : 0;
+            id3 = iter.hasNext() ? iter.next() : 0;
+        }
+        else {
+            id0 = id1 = id2 = id3 = 0;
+
+            initializeMap(ids);
+        }
+    }
+
+    /**
+     * Initialize the map.
+     *
+     * @param vals Values.
+     */
+    private void initializeMap(int[] vals) {
+        int size = Math.max(nextPowerOfTwo(vals.length) << 2, MAP_MIN_SIZE);
+
+        assert size > 0;
+
+        ParseResult finalRes;
+
+        ParseResult res1 = parse(vals, size);
+
+        if (res1.collisions == 0)
+            finalRes = res1;
+        else {
+            ParseResult res2 = parse(vals, size * 2);
+
+            // Failed to decrease aom
+            if (res2.collisions == 0)
+                finalRes = res2;
+            else
+                finalRes = parse(vals, size * 4);
+        }
+
+        idToOrderData = finalRes.data;
+        idToOrderMask = maskForPowerOfTwo(idToOrderData.length / 2);
+    }
+
+    /**
+     * Schema builder.
+     */
+    public static class Builder {
+        /** Schema ID. */
+        private int schemaId = PortableUtils.schemaInitialId();
+
+        /** Fields. */
+        private final ArrayList<Integer> fields = new ArrayList<>();
+
+        /**
+         * Create new schema builder.
+         *
+         * @return Schema builder.
+         */
+        public static Builder newBuilder() {
+            return new Builder();
+        }
+
+        /**
+         * Private constructor.
+         */
+        private Builder() {
+            // No-op.
+        }
+
+        /**
+         * Add field.
+         *
+         * @param fieldId Field ID.
+         */
+        public void addField(int fieldId) {
+            fields.add(fieldId);
+
+            schemaId = PortableUtils.updateSchemaId(schemaId, fieldId);
+        }
+
+        /**
+         * Build schema.
+         *
+         * @return Schema.
+         */
+        public PortableSchema build() {
+            return new PortableSchema(schemaId, fields);
+        }
+    }
+
+    /**
+     * Order confirmation result.
+     */
+    public enum Confirmation {
+        /** Confirmed. */
+        CONFIRMED,
+
+        /** Denied. */
+        REJECTED,
+
+        /** Field name clarification is needed. */
+        CLARIFY
+    }
+
+    /**
+     * Result of map parsing.
+     */
+    private static class ParseResult {
+        /** Data. */
+        private int[] data;
+
+        /** Collisions. */
+        private int collisions;
+
+        /**
+         * Constructor.
+         *
+         * @param data Data.
+         * @param collisions Collisions.
+         */
+        private ParseResult(int[] data, int collisions) {
+            this.data = data;
+            this.collisions = collisions;
+        }
+    }
+}


[37/59] [abbrv] ignite git commit: ignite-1.5 Fix for transaction retry logic in DataStructuresProcessor. Fixed CacheObjectBinaryProcessorImpl.meta for client nodes to try get meta from cache if local value not found.

Posted by ak...@apache.org.
ignite-1.5 Fix for transaction retry logic in DataStructuresProcessor.  Fixed CacheObjectBinaryProcessorImpl.meta for client nodes to try get meta from cache if local value not found.


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

Branch: refs/heads/ignite-843-rc2
Commit: 6e0ef3480ed7d2df33aea6c23dff69c0cd957306
Parents: f6555da
Author: sboikov <sb...@gridgain.com>
Authored: Fri Dec 11 14:55:27 2015 +0300
Committer: sboikov <sb...@gridgain.com>
Committed: Fri Dec 11 14:55:27 2015 +0300

----------------------------------------------------------------------
 .../binary/CacheObjectBinaryProcessorImpl.java  |  12 +-
 .../datastructures/DataStructuresProcessor.java | 161 +++++++++----------
 2 files changed, 89 insertions(+), 84 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/6e0ef348/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/binary/CacheObjectBinaryProcessorImpl.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/binary/CacheObjectBinaryProcessorImpl.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/binary/CacheObjectBinaryProcessorImpl.java
index 9ae8a62..12e7078 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/binary/CacheObjectBinaryProcessorImpl.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/binary/CacheObjectBinaryProcessorImpl.java
@@ -499,8 +499,16 @@ public class CacheObjectBinaryProcessorImpl extends IgniteCacheObjectProcessorIm
     /** {@inheritDoc} */
     @Nullable @Override public BinaryType metadata(final int typeId) throws BinaryObjectException {
         try {
-            if (clientNode)
-                return clientMetaDataCache.get(typeId);
+            if (clientNode) {
+                BinaryType typeMeta = clientMetaDataCache.get(typeId);
+
+                if (typeMeta != null)
+                    return typeMeta;
+
+                BinaryMetadata meta = metaDataCache.getTopologySafe(new PortableMetadataKey(typeId));
+
+                return meta != null ? meta.wrap(portableCtx) : null;
+            }
             else {
                 PortableMetadataKey key = new PortableMetadataKey(typeId);
 

http://git-wip-us.apache.org/repos/asf/ignite/blob/6e0ef348/modules/core/src/main/java/org/apache/ignite/internal/processors/datastructures/DataStructuresProcessor.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/datastructures/DataStructuresProcessor.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/datastructures/DataStructuresProcessor.java
index 51c4067..cd783e4 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/datastructures/DataStructuresProcessor.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/datastructures/DataStructuresProcessor.java
@@ -57,15 +57,16 @@ import org.apache.ignite.internal.GridKernalContext;
 import org.apache.ignite.internal.IgniteInternalFuture;
 import org.apache.ignite.internal.IgniteInterruptedCheckedException;
 import org.apache.ignite.internal.cluster.ClusterTopologyCheckedException;
+import org.apache.ignite.internal.cluster.ClusterTopologyServerNotFoundException;
 import org.apache.ignite.internal.managers.eventstorage.GridLocalEventListener;
 import org.apache.ignite.internal.processors.GridProcessorAdapter;
 import org.apache.ignite.internal.processors.cache.CacheType;
+import org.apache.ignite.internal.processors.cache.GridCacheAdapter;
 import org.apache.ignite.internal.processors.cache.GridCacheContext;
 import org.apache.ignite.internal.processors.cache.GridCacheInternal;
 import org.apache.ignite.internal.processors.cache.GridCacheUtils;
 import org.apache.ignite.internal.processors.cache.IgniteInternalCache;
 import org.apache.ignite.internal.processors.cache.transactions.IgniteInternalTx;
-import org.apache.ignite.internal.transactions.IgniteTxRollbackCheckedException;
 import org.apache.ignite.internal.util.lang.IgniteClosureX;
 import org.apache.ignite.internal.util.lang.IgniteInClosureX;
 import org.apache.ignite.internal.util.lang.IgniteOutClosureX;
@@ -504,8 +505,8 @@ public final class DataStructuresProcessor extends GridProcessorAdapter {
      * @throws IgniteCheckedException If failed.
      */
     @Nullable private <T> T getAtomic(final IgniteOutClosureX<T> c,
-        DataStructureInfo dsInfo,
-        boolean create,
+        final DataStructureInfo dsInfo,
+        final boolean create,
         Class<? extends T> cls)
         throws IgniteCheckedException
     {
@@ -527,39 +528,26 @@ public final class DataStructuresProcessor extends GridProcessorAdapter {
         if (dataStructure != null)
             return dataStructure;
 
-        while (true) {
-            try {
+        return retryTopologySafe(new IgniteOutClosureX<T>() {
+            @Override public T applyx() throws IgniteCheckedException {
                 if (!create)
                     return c.applyx();
 
                 try (IgniteInternalTx tx = utilityCache.txStartEx(PESSIMISTIC, REPEATABLE_READ)) {
-                    err = utilityCache.invoke(DATA_STRUCTURES_KEY, new AddAtomicProcessor(dsInfo)).get();
+                    IgniteCheckedException err =
+                        utilityCache.invoke(DATA_STRUCTURES_KEY, new AddAtomicProcessor(dsInfo)).get();
 
                     if (err != null)
                         throw err;
 
-                    dataStructure = c.applyx();
+                    T dataStructure = c.applyx();
 
                     tx.commit();
 
                     return dataStructure;
                 }
             }
-            catch (IgniteTxRollbackCheckedException ignore) {
-                // Safe to retry right away.
-            }
-            catch (IgniteCheckedException e) {
-                ClusterTopologyCheckedException topErr = e.getCause(ClusterTopologyCheckedException.class);
-
-                if (topErr == null)
-                    throw e;
-
-                IgniteInternalFuture<?> fut = topErr.retryReadyFuture();
-
-                if (fut != null)
-                    fut.get();
-            }
-        }
+        });
     }
 
     /**
@@ -597,10 +585,10 @@ public final class DataStructuresProcessor extends GridProcessorAdapter {
      * @param afterRmv Optional closure to run after data structure removed.
      * @throws IgniteCheckedException If failed.
      */
-    private <T> void removeDataStructure(IgniteOutClosureX<T> c,
+    private <T> void removeDataStructure(final IgniteOutClosureX<T> c,
         String name,
         DataStructureType type,
-        @Nullable IgniteInClosureX<T> afterRmv)
+        @Nullable final IgniteInClosureX<T> afterRmv)
         throws IgniteCheckedException
     {
         Map<String, DataStructureInfo> dsMap = utilityCache.get(DATA_STRUCTURES_KEY);
@@ -608,52 +596,42 @@ public final class DataStructuresProcessor extends GridProcessorAdapter {
         if (dsMap == null || !dsMap.containsKey(name))
             return;
 
-        DataStructureInfo dsInfo = new DataStructureInfo(name, type, null);
+        final DataStructureInfo dsInfo = new DataStructureInfo(name, type, null);
 
         IgniteCheckedException err = validateDataStructure(dsMap, dsInfo, false);
 
         if (err != null)
             throw err;
 
-        while (true) {
-            try (IgniteInternalTx tx = utilityCache.txStartEx(PESSIMISTIC, REPEATABLE_READ)) {
-                T2<Boolean, IgniteCheckedException> res =
-                    utilityCache.invoke(DATA_STRUCTURES_KEY, new RemoveDataStructureProcessor(dsInfo)).get();
-
-                err = res.get2();
+        retryTopologySafe(new IgniteOutClosureX<Void>() {
+            @Override public Void applyx() throws IgniteCheckedException {
+                try (IgniteInternalTx tx = utilityCache.txStartEx(PESSIMISTIC, REPEATABLE_READ)) {
+                    T2<Boolean, IgniteCheckedException> res =
+                        utilityCache.invoke(DATA_STRUCTURES_KEY, new RemoveDataStructureProcessor(dsInfo)).get();
 
-                if (err != null)
-                    throw err;
+                    IgniteCheckedException err = res.get2();
 
-                assert res.get1() != null;
+                    if (err != null)
+                        throw err;
 
-                boolean exists = res.get1();
+                    assert res.get1() != null;
 
-                if (!exists)
-                    return;
+                    boolean exists = res.get1();
 
-                T rmvInfo = c.applyx();
+                    if (!exists)
+                        return null;
 
-                tx.commit();
+                    T rmvInfo = c.applyx();
 
-                if (afterRmv != null && rmvInfo != null)
-                    afterRmv.applyx(rmvInfo);
-            }
-            catch (IgniteTxRollbackCheckedException ignore) {
-                // Safe to retry right away.
-            }
-            catch (IgniteCheckedException e) {
-                ClusterTopologyCheckedException topErr = e.getCause(ClusterTopologyCheckedException.class);
-
-                if (topErr == null)
-                    throw e;
+                    tx.commit();
 
-                IgniteInternalFuture<?> fut = topErr.retryReadyFuture();
+                    if (afterRmv != null && rmvInfo != null)
+                        afterRmv.applyx(rmvInfo);
 
-                if (fut != null)
-                    fut.get();
+                    return null;
+                }
             }
-        }
+        });
     }
 
     /**
@@ -1000,7 +978,7 @@ public final class DataStructuresProcessor extends GridProcessorAdapter {
      * @throws IgniteCheckedException If failed.
      */
     @Nullable private <T> T getCollection(final IgniteClosureX<GridCacheContext, T> c,
-        DataStructureInfo dsInfo,
+        final DataStructureInfo dsInfo,
         boolean create)
         throws IgniteCheckedException
     {
@@ -1028,41 +1006,29 @@ public final class DataStructuresProcessor extends GridProcessorAdapter {
             return c.applyx(cacheCtx);
         }
 
-        while (true) {
-            try (IgniteInternalTx tx = utilityCache.txStartEx(PESSIMISTIC, REPEATABLE_READ)) {
-                T2<String, IgniteCheckedException> res =
-                    utilityCache.invoke(DATA_STRUCTURES_KEY, new AddCollectionProcessor(dsInfo)).get();
-
-                err = res.get2();
-
-                if (err != null)
-                    throw err;
-
-                String cacheName = res.get1();
+        return retryTopologySafe(new IgniteOutClosureX<T>() {
+            @Override public T applyx() throws IgniteCheckedException {
+                try (IgniteInternalTx tx = utilityCache.txStartEx(PESSIMISTIC, REPEATABLE_READ)) {
+                    T2<String, IgniteCheckedException> res =
+                        utilityCache.invoke(DATA_STRUCTURES_KEY, new AddCollectionProcessor(dsInfo)).get();
 
-                final GridCacheContext cacheCtx = ctx.cache().internalCache(cacheName).context();
+                    IgniteCheckedException err = res.get2();
 
-                T col = c.applyx(cacheCtx);
+                    if (err != null)
+                        throw err;
 
-                tx.commit();
+                    String cacheName = res.get1();
 
-                return col;
-            }
-            catch (IgniteTxRollbackCheckedException ignore) {
-                // Safe to retry right away.
-            }
-            catch (IgniteCheckedException e) {
-                ClusterTopologyCheckedException topErr = e.getCause(ClusterTopologyCheckedException.class);
+                    final GridCacheContext cacheCtx = ctx.cache().internalCache(cacheName).context();
 
-                if (topErr == null)
-                    throw e;
+                    T col = c.applyx(cacheCtx);
 
-                IgniteInternalFuture<?> fut = topErr.retryReadyFuture();
+                    tx.commit();
 
-                if (fut != null)
-                    fut.get();
+                    return col;
+                }
             }
-        }
+        });
     }
 
     /**
@@ -1659,6 +1625,37 @@ public final class DataStructuresProcessor extends GridProcessorAdapter {
     }
 
     /**
+     * @param c Closure to run.
+     * @throws IgniteCheckedException If failed.
+     * @return Closure return value.
+     */
+    private static <T> T retryTopologySafe(IgniteOutClosureX<T> c) throws IgniteCheckedException {
+        for (int i = 0; i < GridCacheAdapter.MAX_RETRIES; i++) {
+            try {
+                return c.applyx();
+            }
+            catch (IgniteCheckedException e) {
+                if (i == GridCacheAdapter.MAX_RETRIES - 1)
+                    throw e;
+
+                ClusterTopologyCheckedException topErr = e.getCause(ClusterTopologyCheckedException.class);
+
+                if (topErr == null || (topErr instanceof ClusterTopologyServerNotFoundException))
+                    throw e;
+
+                IgniteInternalFuture<?> fut = topErr.retryReadyFuture();
+
+                if (fut != null)
+                    fut.get();
+            }
+        }
+
+        assert false;
+
+        return null;
+    }
+
+    /**
      *
      */
     enum DataStructureType {


[09/59] [abbrv] ignite git commit: ignite-2065: rename "portable" packages to "binary"

Posted by ak...@apache.org.
http://git-wip-us.apache.org/repos/asf/ignite/blob/1dbf20e0/modules/core/src/test/java/org/apache/ignite/internal/portable/BinaryEnumsSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/portable/BinaryEnumsSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/portable/BinaryEnumsSelfTest.java
deleted file mode 100644
index 3bc3922..0000000
--- a/modules/core/src/test/java/org/apache/ignite/internal/portable/BinaryEnumsSelfTest.java
+++ /dev/null
@@ -1,446 +0,0 @@
-/*
- * 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.portable;
-
-import org.apache.ignite.Ignite;
-import org.apache.ignite.IgniteCache;
-import org.apache.ignite.binary.BinaryObject;
-import org.apache.ignite.binary.BinaryTypeConfiguration;
-import org.apache.ignite.cache.CacheMode;
-import org.apache.ignite.configuration.BinaryConfiguration;
-import org.apache.ignite.configuration.CacheConfiguration;
-import org.apache.ignite.configuration.IgniteConfiguration;
-import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
-
-import java.io.Serializable;
-import java.util.Arrays;
-
-/**
- * Contains tests for binary enums.
- */
-@SuppressWarnings("unchecked")
-public class BinaryEnumsSelfTest extends GridCommonAbstractTest {
-    /** Cache name. */
-    private static String CACHE_NAME = "cache";
-
-    /** Whether to register types or not. */
-    private boolean register;
-
-    /** Node 1. */
-    private Ignite node1;
-
-    /** Node 2. */
-    private Ignite node2;
-
-    /** Cache 1. */
-    private IgniteCache cache1;
-
-    /** Cache 2. */
-    private IgniteCache cache2;
-
-    /** Binary cache 1. */
-    private IgniteCache cacheBinary1;
-
-    /** Binary cache 2. */
-    private IgniteCache cacheBinary2;
-
-    /** {@inheritDoc} */
-    @Override protected void beforeTest() throws Exception {
-        register = false;
-    }
-
-    /** {@inheritDoc} */
-    @Override protected void afterTest() throws Exception {
-        stopAllGrids();
-    }
-
-    /** {@inheritDoc} */
-    @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception {
-        IgniteConfiguration cfg = super.getConfiguration(gridName);
-
-        if (register) {
-            BinaryConfiguration bCfg = new BinaryConfiguration();
-
-            BinaryTypeConfiguration enumCfg = new BinaryTypeConfiguration(EnumType.class.getName());
-            enumCfg.setEnum(true);
-
-            bCfg.setTypeConfigurations(Arrays.asList(enumCfg, new BinaryTypeConfiguration(EnumHolder.class.getName())));
-
-            cfg.setBinaryConfiguration(bCfg);
-        }
-
-        cfg.setMarshaller(new BinaryMarshaller());
-
-        CacheConfiguration ccfg = new CacheConfiguration();
-        ccfg.setName(CACHE_NAME);
-        ccfg.setCacheMode(CacheMode.PARTITIONED);
-
-        cfg.setCacheConfiguration(ccfg);
-
-        return cfg;
-    }
-
-    /**
-     * Start up routine.
-     *
-     * @throws Exception If failed.
-     */
-    private void startUp(boolean register) throws Exception {
-        this.register = register;
-
-        node1 = startGrid(0);
-        cache1 = node1.cache(CACHE_NAME);
-        cacheBinary1 = cache1.withKeepBinary();
-
-        node2 = startGrid(1);
-        cache2 = node2.cache(CACHE_NAME);
-        cacheBinary2 = cache2.withKeepBinary();
-    }
-
-    /**
-     * Test operations on simple type which is registered in advance.
-     *
-     * @throws Exception If failed.
-     */
-    public void testSimpleRegistered() throws Exception {
-        checkSimple(true);
-    }
-
-    /**
-     * Test operations on simple type which is not registered in advance.
-     *
-     * @throws Exception If failed.
-     */
-    public void testSimpleNotRegistered() throws Exception {
-        checkSimple(false);
-    }
-
-    /**
-     * Test operations when enum is nested into an object (registered).
-     *
-     * @throws Exception If failed.
-     */
-    public void testNestedRegistered() throws Exception {
-        checkNested(true);
-    }
-
-    /**
-     * Test operations when enum is nested into an object (not registered).
-     *
-     * @throws Exception If failed.
-     */
-    public void testNestedNotRegistered() throws Exception {
-        checkNested(false);
-    }
-
-    /**
-     * Test builder operations on simple type which is registered in advance.
-     *
-     * @throws Exception If failed.
-     */
-    public void testSimpleBuilderRegistered() throws Exception {
-        checkSimpleBuilder(true);
-    }
-
-    /**
-     * Test builder operations on simple type which is not registered in advance.
-     *
-     * @throws Exception If failed.
-     */
-    public void testSimpleBuilderNotRegistered() throws Exception {
-        checkSimpleBuilder(false);
-    }
-
-    /**
-     * Test builder operations when enum is nested into an object (registered).
-     *
-     * @throws Exception If failed.
-     */
-    public void testNestedBuilderRegistered() throws Exception {
-        checkNestedBuilder(true);
-    }
-
-    /**
-     * Test builder operations when enum is nested into an object (not registered).
-     *
-     * @throws Exception If failed.
-     */
-    public void testNestedBuilderNotRegistered() throws Exception {
-        checkNestedBuilder(false);
-    }
-
-    /**
-     * Check simple serialization - deserialization.
-     *
-     * @param registered If type should be registered in advance.
-     * @throws Exception If failed.
-     */
-    public void checkSimple(boolean registered) throws Exception {
-        startUp(registered);
-
-        cache1.put(1, EnumType.ONE);
-
-        validateSimple(1, EnumType.ONE, registered);
-    }
-
-    /**
-     * Check nested serialization - deserialization.
-     *
-     * @param registered If type should be registered in advance.
-     * @throws Exception If failed.
-     */
-    private void checkNested(boolean registered) throws Exception {
-        startUp(registered);
-
-        cache1.put(1, new EnumHolder(EnumType.ONE));
-
-        validateNested(1, EnumType.ONE, registered);
-    }
-
-    /**
-     * Check nested builder serialization - deserialization.
-     *
-     * @param registered If type should be registered in advance.
-     * @throws Exception If failed.
-     */
-    private void checkNestedBuilder(boolean registered) throws Exception {
-        startUp(registered);
-
-        BinaryObject obj = node1.binary().builder("EnumHolder").setField("val", EnumType.ONE).build();
-
-        assert node1.binary().type("EnumHolder") != null;
-        assert node1.binary().type("EnumType") != null;
-
-        cacheBinary1.put(1, obj);
-
-        validateNested(1, EnumType.ONE, registered);
-
-        obj = (BinaryObject)cacheBinary1.get(1);
-        obj = node1.binary().builder(obj).setField("val", EnumType.TWO).build();
-
-        cacheBinary1.put(1, obj);
-
-        validateNested(1, EnumType.TWO, registered);
-    }
-
-    /**
-     * Validate nested object.
-     *
-     * @param key Key.
-     * @param val Value.
-     * @param registered Registered flag.
-     * @throws Exception If failed.
-     */
-    private void validateNested(int key, EnumType val, boolean registered) throws Exception {
-        if (registered) {
-            EnumHolder res1 = (EnumHolder) cache1.get(key);
-            EnumHolder res2 = (EnumHolder) cache2.get(key);
-
-            assertEquals(val, res1.val);
-            assertEquals(val, res2.val);
-        }
-
-        BinaryObject resBinary1 = (BinaryObject)cacheBinary1.get(key);
-        BinaryObject resBinary2 = (BinaryObject)cacheBinary2.get(key);
-
-        validate((BinaryObject)resBinary1.field("val"), val);
-        validate((BinaryObject)resBinary2.field("val"), val);
-    }
-
-    /**
-     * Check simple serialization - deserialization using builder.
-     *
-     * @param registered If type should be registered in advance.
-     * @throws Exception If failed.
-     */
-    public void checkSimpleBuilder(boolean registered) throws Exception {
-        startUp(registered);
-
-        BinaryObject binary = node1.binary().buildEnum(EnumType.class.getSimpleName(), EnumType.ONE.ordinal());
-
-        cacheBinary1.put(1, binary);
-
-        validateSimple(1, EnumType.ONE, registered);
-    }
-
-    /**
-     * Test enum array (registered).
-     *
-     * @throws Exception If failed.
-     */
-    public void testSimpleArrayRegistered() throws Exception {
-        checkSimpleArray(true);
-    }
-
-    /**
-     * Test enum array (not registered).
-     *
-     * @throws Exception If failed.
-     */
-    public void testSimpleArrayNotRegistered() throws Exception {
-        checkSimpleArray(false);
-    }
-
-    /**
-     * Test enum array created using builder (registered).
-     *
-     * @throws Exception If failed.
-     */
-    public void testSimpleBuilderArrayRegistered() throws Exception {
-        checkSimpleBuilderArray(true);
-    }
-
-    /**
-     * Test enum array created using builder (not registered).
-     *
-     * @throws Exception If failed.
-     */
-    public void testSimpleBuilderArrayNotRegistered() throws Exception {
-        checkSimpleBuilderArray(false);
-    }
-
-    /**
-     * Check arrays with builder.
-     *
-     * @param registered Registered flag.
-     * @throws Exception If failed.
-     */
-    public void checkSimpleArray(boolean registered) throws Exception {
-        startUp(registered);
-
-        cache1.put(1, new EnumType[] { EnumType.ONE, EnumType.TWO });
-
-        validateSimpleArray(registered);
-    }
-
-    /**
-     * Check arrays with builder.
-     *
-     * @param registered Registered flag.
-     * @throws Exception If failed.
-     */
-    public void checkSimpleBuilderArray(boolean registered) throws Exception {
-        startUp(registered);
-
-        BinaryObject binaryOne = node1.binary().buildEnum(EnumType.class.getSimpleName(), EnumType.ONE.ordinal());
-        BinaryObject binaryTwo = node1.binary().buildEnum(EnumType.class.getSimpleName(), EnumType.TWO.ordinal());
-
-        cacheBinary1.put(1, new BinaryObject[] { binaryOne, binaryTwo });
-
-        validateSimpleArray(registered);
-    }
-
-    /**
-     * Validate simple array.
-     *
-     * @param registered Registered flag.
-     */
-    private void validateSimpleArray(boolean registered) {
-        if (registered) {
-            Object[] arr1 = (Object[])cache1.get(1);
-            Object[] arr2 = (Object[])cache2.get(1);
-
-            assertEquals(2, arr1.length);
-            assertEquals(2, arr2.length);
-
-            assertEquals(EnumType.ONE, arr1[0]);
-            assertEquals(EnumType.TWO, arr1[1]);
-
-            assertEquals(EnumType.ONE, arr2[0]);
-            assertEquals(EnumType.TWO, arr2[1]);
-        }
-
-        Object[] arrBinary1 = (Object[])cacheBinary1.get(1);
-        Object[] arrBinary2 = (Object[])cacheBinary2.get(1);
-
-        assertEquals(2, arrBinary1.length);
-        assertEquals(2, arrBinary2.length);
-
-        validate((BinaryObject) arrBinary1[0], EnumType.ONE);
-        validate((BinaryObject) arrBinary1[1], EnumType.TWO);
-
-        validate((BinaryObject) arrBinary2[0], EnumType.ONE);
-        validate((BinaryObject) arrBinary2[1], EnumType.TWO);
-    }
-
-    /**
-     * Internal check routine for simple scenario.
-     *
-     * @param key Key.
-     * @param val Value.
-     * @param registered Registered flag.
-     * @throws Exception If failed.
-     */
-    private void validateSimple(int key, EnumType val, boolean registered) throws Exception {
-        if (registered) {
-            assertEquals(val, cache1.get(key));
-            assertEquals(val, cache2.get(key));
-        }
-
-        validate((BinaryObject) cacheBinary1.get(key), val);
-        validate((BinaryObject) cacheBinary2.get(key), val);
-    }
-
-    /**
-     * Validate single value.
-     *
-     * @param obj Binary value.
-     * @param val Expected value.
-     */
-    private void validate(BinaryObject obj, EnumType val) {
-        assertTrue(obj.type().isEnum());
-
-        assertEquals(node1.binary().typeId(EnumType.class.getName()), obj.type().typeId());
-        assertEquals(node2.binary().typeId(EnumType.class.getName()), obj.type().typeId());
-
-        assertEquals(val.ordinal(), obj.enumOrdinal());
-    }
-
-    /**
-     * Enumeration holder.
-     */
-    public static class EnumHolder implements Serializable {
-        /** Value. */
-        public EnumType val;
-
-        /**
-         * Default constructor.
-         */
-        @SuppressWarnings("UnusedDeclaration")
-        public EnumHolder() {
-            // No-op.
-        }
-
-        /**
-         * Constructor.
-         *
-         * @param val Value.
-         */
-        public EnumHolder(EnumType val) {
-            this.val = val;
-        }
-    }
-
-    /**
-     * Enumeration for tests.
-     */
-    public static enum EnumType {
-        ONE,
-        TWO
-    }
-}

http://git-wip-us.apache.org/repos/asf/ignite/blob/1dbf20e0/modules/core/src/test/java/org/apache/ignite/internal/portable/BinaryFieldsAbstractSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/portable/BinaryFieldsAbstractSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/portable/BinaryFieldsAbstractSelfTest.java
deleted file mode 100644
index 47f3886..0000000
--- a/modules/core/src/test/java/org/apache/ignite/internal/portable/BinaryFieldsAbstractSelfTest.java
+++ /dev/null
@@ -1,718 +0,0 @@
-/*
- * 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.portable;
-
-import org.apache.ignite.binary.BinaryField;
-import org.apache.ignite.binary.BinaryObject;
-import org.apache.ignite.binary.BinaryTypeConfiguration;
-import org.apache.ignite.configuration.BinaryConfiguration;
-import org.apache.ignite.configuration.IgniteConfiguration;
-import org.apache.ignite.internal.util.IgniteUtils;
-import org.apache.ignite.internal.util.typedef.internal.U;
-import org.apache.ignite.marshaller.MarshallerContextTestImpl;
-import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
-
-import java.math.BigDecimal;
-import java.sql.Timestamp;
-import java.util.Arrays;
-import java.util.Date;
-import java.util.UUID;
-
-/**
- * Contains tests for portable object fields.
- */
-public abstract class BinaryFieldsAbstractSelfTest extends GridCommonAbstractTest {
-    /** Marshaller. */
-    protected BinaryMarshaller dfltMarsh;
-
-    /**
-     * Create marshaller.
-     *
-     * @return Portable marshaller.
-     * @throws Exception If failed.
-     */
-    protected BinaryMarshaller createMarshaller() throws Exception {
-        PortableContext ctx = new PortableContext(BinaryCachingMetadataHandler.create(), new IgniteConfiguration());
-
-        BinaryMarshaller marsh = new BinaryMarshaller();
-
-        BinaryConfiguration bCfg = new BinaryConfiguration();
-        
-        bCfg.setCompactFooter(compactFooter());
-
-        bCfg.setTypeConfigurations(Arrays.asList(
-            new BinaryTypeConfiguration(TestObject.class.getName()),
-            new BinaryTypeConfiguration(TestOuterObject.class.getName()),
-            new BinaryTypeConfiguration(TestInnerObject.class.getName())
-        ));
-
-        IgniteConfiguration iCfg = new IgniteConfiguration();
-
-        iCfg.setBinaryConfiguration(bCfg);
-
-        marsh.setContext(new MarshallerContextTestImpl(null));
-
-        IgniteUtils.invoke(BinaryMarshaller.class, marsh, "setPortableContext", ctx, iCfg);
-
-        return marsh;
-    }
-
-    /**
-     * @return Whether to use compact footer.
-     */
-    protected boolean compactFooter() {
-        return true;
-    }
-
-    /**
-     * Get portable context for the current marshaller.
-     *
-     * @param marsh Marshaller.
-     * @return Portable context.
-     */
-    protected static PortableContext portableContext(BinaryMarshaller marsh) {
-        GridPortableMarshaller impl = U.field(marsh, "impl");
-
-        return impl.context();
-    }
-
-    /** {@inheritDoc} */
-    @Override protected void beforeTest() throws Exception {
-        super.beforeTest();
-
-        dfltMarsh = createMarshaller();
-    }
-
-    /**
-     * Test byte field.
-     *
-     * @throws Exception If failed.
-     */
-    public void testByte() throws Exception {
-        check("fByte");
-    }
-
-    /**
-     * Test byte array field.
-     *
-     * @throws Exception If failed.
-     */
-    public void testByteArray() throws Exception {
-        check("fByteArr");
-    }
-
-    /**
-     * Test boolean field.
-     *
-     * @throws Exception If failed.
-     */
-    public void testBoolean() throws Exception {
-        check("fBool");
-    }
-
-    /**
-     * Test boolean array field.
-     *
-     * @throws Exception If failed.
-     */
-    public void testBooleanArray() throws Exception {
-        check("fBoolArr");
-    }
-
-    /**
-     * Test short field.
-     *
-     * @throws Exception If failed.
-     */
-    public void testShort() throws Exception {
-        check("fShort");
-    }
-
-    /**
-     * Test short array field.
-     *
-     * @throws Exception If failed.
-     */
-    public void testShortArray() throws Exception {
-        check("fShortArr");
-    }
-
-    /**
-     * Test char field.
-     *
-     * @throws Exception If failed.
-     */
-    public void testChar() throws Exception {
-        check("fChar");
-    }
-
-    /**
-     * Test char array field.
-     *
-     * @throws Exception If failed.
-     */
-    public void testCharArray() throws Exception {
-        check("fCharArr");
-    }
-
-    /**
-     * Test int field.
-     *
-     * @throws Exception If failed.
-     */
-    public void testInt() throws Exception {
-        check("fInt");
-    }
-
-    /**
-     * Test int array field.
-     *
-     * @throws Exception If failed.
-     */
-    public void testIntArray() throws Exception {
-        check("fIntArr");
-    }
-
-    /**
-     * Test long field.
-     *
-     * @throws Exception If failed.
-     */
-    public void testLong() throws Exception {
-        check("fLong");
-    }
-
-    /**
-     * Test long array field.
-     *
-     * @throws Exception If failed.
-     */
-    public void testLongArray() throws Exception {
-        check("fLongArr");
-    }
-
-    /**
-     * Test float field.
-     *
-     * @throws Exception If failed.
-     */
-    public void testFloat() throws Exception {
-        check("fFloat");
-    }
-
-    /**
-     * Test float array field.
-     *
-     * @throws Exception If failed.
-     */
-    public void testFloatArray() throws Exception {
-        check("fFloatArr");
-    }
-
-    /**
-     * Test double field.
-     *
-     * @throws Exception If failed.
-     */
-    public void testDouble() throws Exception {
-        check("fDouble");
-    }
-
-    /**
-     * Test double array field.
-     *
-     * @throws Exception If failed.
-     */
-    public void testDoubleArray() throws Exception {
-        check("fDoubleArr");
-    }
-
-    /**
-     * Test string field.
-     *
-     * @throws Exception If failed.
-     */
-    public void testString() throws Exception {
-        check("fString");
-    }
-
-    /**
-     * Test string array field.
-     *
-     * @throws Exception If failed.
-     */
-    public void testStringArray() throws Exception {
-        check("fStringArr");
-    }
-
-    /**
-     * Test date field.
-     *
-     * @throws Exception If failed.
-     */
-    public void testDate() throws Exception {
-        check("fDate");
-    }
-
-    /**
-     * Test date array field.
-     *
-     * @throws Exception If failed.
-     */
-    public void testDateArray() throws Exception {
-        check("fDateArr");
-    }
-
-    /**
-     * Test timestamp field.
-     *
-     * @throws Exception If failed.
-     */
-    public void testTimestamp() throws Exception {
-        check("fTimestamp");
-    }
-
-    /**
-     * Test timestamp array field.
-     *
-     * @throws Exception If failed.
-     */
-    public void testTimestampArray() throws Exception {
-        check("fTimestampArr");
-    }
-
-    /**
-     * Test UUID field.
-     *
-     * @throws Exception If failed.
-     */
-    public void testUuid() throws Exception {
-        check("fUuid");
-    }
-
-    /**
-     * Test UUID array field.
-     *
-     * @throws Exception If failed.
-     */
-    public void testUuidArray() throws Exception {
-        check("fUuidArr");
-    }
-
-    /**
-     * Test decimal field.
-     *
-     * @throws Exception If failed.
-     */
-    public void testDecimal() throws Exception {
-        check("fDecimal");
-    }
-
-    /**
-     * Test decimal array field.
-     *
-     * @throws Exception If failed.
-     */
-    public void testDecimalArray() throws Exception {
-        check("fDecimalArr");
-    }
-
-    /**
-     * Test object field.
-     *
-     * @throws Exception If failed.
-     */
-    public void testObject() throws Exception {
-        check("fObj");
-    }
-
-    /**
-     * Test object array field.
-     *
-     * @throws Exception If failed.
-     */
-    public void testObjectArray() throws Exception {
-        check("fObjArr");
-    }
-
-    /**
-     * Test null field.
-     *
-     * @throws Exception If failed.
-     */
-    public void testNull() throws Exception {
-        check("fNull");
-    }
-
-    /**
-     * Test missing field.
-     *
-     * @throws Exception If failed.
-     */
-    public void testMissing() throws Exception {
-        String fieldName = "fMissing";
-
-        checkNormal(dfltMarsh, fieldName, false);
-        checkNested(dfltMarsh, fieldName, false);
-    }
-
-    /**
-     * Check field resolution in both normal and nested modes.
-     *
-     * @param fieldName Field name.
-     * @throws Exception If failed.
-     */
-    public void check(String fieldName) throws Exception {
-        checkNormal(dfltMarsh, fieldName, true);
-        checkNested(dfltMarsh, fieldName, true);
-    }
-
-    /**
-     * Check field.
-     *
-     * @param marsh Marshaller.
-     * @param fieldName Field name.
-     * @param exists Whether field should exist.
-     * @throws Exception If failed.
-     */
-    private void checkNormal(BinaryMarshaller marsh, String fieldName, boolean exists) throws Exception {
-        TestContext testCtx = context(marsh, fieldName);
-
-        check0(fieldName, testCtx, exists);
-    }
-
-    /**
-     * Check nested field.
-     *
-     * @param marsh Marshaller.
-     * @param fieldName Field name.
-     * @param exists Whether field should exist.
-     * @throws Exception If failed.
-     */
-    private void checkNested(BinaryMarshaller marsh, String fieldName, boolean exists) throws Exception {
-        TestContext testCtx = nestedContext(marsh, fieldName);
-
-        check0(fieldName, testCtx, exists);
-    }
-
-    /**
-     * Internal check routine.
-     *
-     * @param fieldName Field name.
-     * @param ctx Context.
-     * @param exists Whether field should exist.
-     * @throws Exception If failed.
-     */
-    private void check0(String fieldName, TestContext ctx, boolean exists) throws Exception {
-        Object val = ctx.field.value(ctx.portObj);
-
-        if (exists) {
-            assertTrue(ctx.field.exists(ctx.portObj));
-
-            Object expVal = U.field(ctx.obj, fieldName);
-
-            if (val instanceof BinaryObject)
-                val = ((BinaryObject) val).deserialize();
-
-            if (val != null && val.getClass().isArray()) {
-                assertNotNull(expVal);
-
-                if (val instanceof byte[])
-                    assertTrue(Arrays.equals((byte[]) expVal, (byte[]) val));
-                else if (val instanceof boolean[])
-                    assertTrue(Arrays.equals((boolean[]) expVal, (boolean[]) val));
-                else if (val instanceof short[])
-                    assertTrue(Arrays.equals((short[]) expVal, (short[]) val));
-                else if (val instanceof char[])
-                    assertTrue(Arrays.equals((char[]) expVal, (char[]) val));
-                else if (val instanceof int[])
-                    assertTrue(Arrays.equals((int[]) expVal, (int[]) val));
-                else if (val instanceof long[])
-                    assertTrue(Arrays.equals((long[]) expVal, (long[]) val));
-                else if (val instanceof float[])
-                    assertTrue(Arrays.equals((float[]) expVal, (float[]) val));
-                else if (val instanceof double[])
-                    assertTrue(Arrays.equals((double[]) expVal, (double[]) val));
-                else {
-                    Object[] expVal0 = (Object[])expVal;
-                    Object[] val0 = (Object[])val;
-
-                    assertEquals(expVal0.length, val0.length);
-
-                    for (int i = 0; i < expVal0.length; i++) {
-                        Object expItem = expVal0[i];
-                        Object item = val0[i];
-
-                        if (item instanceof BinaryObject)
-                            item = ((BinaryObject)item).deserialize();
-
-                        assertEquals(expItem, item);
-                    }
-                }
-            }
-            else
-                assertEquals(expVal, val);
-        }
-        else {
-            assertFalse(ctx.field.exists(ctx.portObj));
-
-            assert val == null;
-        }
-    }
-
-    /**
-     * Get test context.
-     *
-     * @param marsh Portable marshaller.
-     * @param fieldName Field name.
-     * @return Test context.
-     * @throws Exception If failed.
-     */
-    private TestContext context(BinaryMarshaller marsh, String fieldName) throws Exception {
-        TestObject obj = createObject();
-
-        BinaryObjectExImpl portObj = toPortable(marsh, obj);
-
-        BinaryField field = portObj.type().field(fieldName);
-
-        return new TestContext(obj, portObj, field);
-    }
-
-    /**
-     * Get test context with nested test object.
-     *
-     * @param marsh Portable marshaller.
-     * @param fieldName Field name.
-     * @return Test context.
-     * @throws Exception If failed.
-     */
-    private TestContext nestedContext(BinaryMarshaller marsh, String fieldName)
-        throws Exception {
-        TestObject obj = createObject();
-        TestOuterObject outObj = new TestOuterObject(obj);
-
-        BinaryObjectExImpl portOutObj = toPortable(marsh, outObj);
-        BinaryObjectExImpl portObj = portOutObj.field("fInner");
-
-        assert portObj != null;
-
-        BinaryField field = portObj.type().field(fieldName);
-
-        return new TestContext(obj, portObj, field);
-    }
-
-    /**
-     * Create test object.
-     *
-     * @return Test object.
-     */
-    private TestObject createObject() {
-        return new TestObject(0);
-    }
-
-    /**
-     * Convert object to portable object.
-     *
-     * @param marsh Marshaller.
-     * @param obj Object.
-     * @return Portable object.
-     * @throws Exception If failed.
-     */
-    protected abstract BinaryObjectExImpl toPortable(BinaryMarshaller marsh, Object obj) throws Exception;
-
-    /**
-     * Outer test object.
-     */
-    @SuppressWarnings("UnusedDeclaration")
-    public static class TestOuterObject {
-        /** Inner object. */
-        public TestObject fInner;
-
-        /**
-         * Default constructor.
-         */
-        public TestOuterObject() {
-            // No-op.
-        }
-
-        /**
-         * Constructor.
-         *
-         * @param fInner Inner object.
-         */
-        public TestOuterObject(TestObject fInner) {
-            this.fInner = fInner;
-        }
-    }
-
-    /**
-     * Test object class, c
-     */
-    @SuppressWarnings("UnusedDeclaration")
-    public static class TestObject {
-        /** Primitive fields. */
-        public byte fByte;
-        public boolean fBool;
-        public short fShort;
-        public char fChar;
-        public int fInt;
-        public long fLong;
-        public float fFloat;
-        public double fDouble;
-
-        public byte[] fByteArr;
-        public boolean[] fBoolArr;
-        public short[] fShortArr;
-        public char[] fCharArr;
-        public int[] fIntArr;
-        public long[] fLongArr;
-        public float[] fFloatArr;
-        public double[] fDoubleArr;
-
-        /** Special fields. */
-        public String fString;
-        public Date fDate;
-        public Timestamp fTimestamp;
-        public UUID fUuid;
-        public BigDecimal fDecimal;
-
-        public String[] fStringArr;
-        public Date[] fDateArr;
-        public Timestamp[] fTimestampArr;
-        public UUID[] fUuidArr;
-        public BigDecimal[] fDecimalArr;
-
-        /** Nested object. */
-        public TestInnerObject fObj;
-
-        public TestInnerObject[] fObjArr;
-
-        /** Field which is always set to null. */
-        public Object fNull;
-
-        /**
-         * Default constructor.
-         */
-        public TestObject() {
-            // No-op.
-        }
-
-        /**
-         * Non-default constructor.
-         *
-         * @param ignore Ignored.
-         */
-        public TestObject(int ignore) {
-            fByte = 1;
-            fBool = true;
-            fShort = 2;
-            fChar = 3;
-            fInt = 4;
-            fLong = 5;
-            fFloat = 6.6f;
-            fDouble = 7.7;
-
-            fByteArr = new byte[] { 1, 2 };
-            fBoolArr = new boolean[] { true, false };
-            fShortArr = new short[] { 2, 3 };
-            fCharArr = new char[] { 3, 4 };
-            fIntArr = new int[] { 4, 5 };
-            fLongArr = new long[] { 5, 6 };
-            fFloatArr = new float[] { 6.6f, 7.7f };
-            fDoubleArr = new double[] { 7.7, 8.8 };
-
-            fString = "8";
-            fDate = new Date();
-            fTimestamp = new Timestamp(new Date().getTime() + 1);
-            fUuid = UUID.randomUUID();
-            fDecimal = new BigDecimal(9);
-
-            fStringArr = new String[] { "8", "9" };
-            fDateArr = new Date[] { new Date(), new Date(new Date().getTime() + 1) };
-            fTimestampArr =
-                new Timestamp[] { new Timestamp(new Date().getTime() + 1), new Timestamp(new Date().getTime() + 2) };
-            fUuidArr = new UUID[] { UUID.randomUUID(), UUID.randomUUID() };
-            fDecimalArr = new BigDecimal[] { new BigDecimal(9), new BigDecimal(10) };
-
-            fObj = new TestInnerObject(10);
-            fObjArr = new TestInnerObject[] { new TestInnerObject(10), new TestInnerObject(11) };
-        }
-    }
-
-    /**
-     * Inner test object.
-     */
-    @SuppressWarnings("UnusedDeclaration")
-    public static class TestInnerObject {
-        /** Value. */
-        private int val;
-
-        /**
-         * Default constructor.
-         */
-        public TestInnerObject() {
-            // No-op.
-        }
-
-        /**
-         * Constructor.
-         *
-         * @param val Value.
-         */
-        public TestInnerObject(int val) {
-            this.val = val;
-        }
-
-        /** {@inheritDoc} */
-        @Override public int hashCode() {
-            return val;
-        }
-
-        /** {@inheritDoc} */
-        @Override public boolean equals(Object other) {
-            return other != null && other instanceof TestInnerObject && val == ((TestInnerObject)(other)).val;
-        }
-    }
-
-    /**
-     * Test context.
-     */
-    public static class TestContext {
-        /** Object. */
-        public final TestObject obj;
-
-        /** Portable object. */
-        public final BinaryObjectExImpl portObj;
-
-        /** Field. */
-        public final BinaryField field;
-
-        /**
-         * Constructor.
-         *
-         * @param obj Object.
-         * @param portObj Portable object.
-         * @param field Field.
-         */
-        public TestContext(TestObject obj, BinaryObjectExImpl portObj, BinaryField field) {
-            this.obj = obj;
-            this.portObj = portObj;
-            this.field = field;
-        }
-    }
-}

http://git-wip-us.apache.org/repos/asf/ignite/blob/1dbf20e0/modules/core/src/test/java/org/apache/ignite/internal/portable/BinaryFieldsHeapSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/portable/BinaryFieldsHeapSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/portable/BinaryFieldsHeapSelfTest.java
deleted file mode 100644
index a45809f..0000000
--- a/modules/core/src/test/java/org/apache/ignite/internal/portable/BinaryFieldsHeapSelfTest.java
+++ /dev/null
@@ -1,30 +0,0 @@
-/*
- * 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.portable;
-
-/**
- * Field tests for heap-based portables.
- */
-public class BinaryFieldsHeapSelfTest extends BinaryFieldsAbstractSelfTest {
-    /** {@inheritDoc} */
-    @Override protected BinaryObjectExImpl toPortable(BinaryMarshaller marsh, Object obj) throws Exception {
-        byte[] bytes = marsh.marshal(obj);
-
-        return new BinaryObjectImpl(portableContext(marsh), bytes, 0);
-    }
-}

http://git-wip-us.apache.org/repos/asf/ignite/blob/1dbf20e0/modules/core/src/test/java/org/apache/ignite/internal/portable/BinaryFieldsOffheapSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/portable/BinaryFieldsOffheapSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/portable/BinaryFieldsOffheapSelfTest.java
deleted file mode 100644
index 2f579e1..0000000
--- a/modules/core/src/test/java/org/apache/ignite/internal/portable/BinaryFieldsOffheapSelfTest.java
+++ /dev/null
@@ -1,60 +0,0 @@
-/*
- * 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.portable;
-
-import org.apache.ignite.internal.util.GridUnsafe;
-import org.eclipse.jetty.util.ConcurrentHashSet;
-import sun.misc.Unsafe;
-
-/**
- * Field tests for heap-based portables.
- */
-public class BinaryFieldsOffheapSelfTest extends BinaryFieldsAbstractSelfTest {
-    /** Unsafe instance. */
-    private static final Unsafe UNSAFE = GridUnsafe.unsafe();
-
-    /** Byte array offset for unsafe mechanics. */
-    protected static final long BYTE_ARR_OFF = UNSAFE.arrayBaseOffset(byte[].class);
-
-    /** Allocated unsafe pointer. */
-    private final ConcurrentHashSet<Long> ptrs = new ConcurrentHashSet<>();
-
-    /** {@inheritDoc} */
-    @Override protected void afterTest() throws Exception {
-        super.afterTest();
-
-        // Cleanup allocated objects.
-        for (Long ptr : ptrs)
-            UNSAFE.freeMemory(ptr);
-
-        ptrs.clear();
-    }
-
-    /** {@inheritDoc} */
-    @Override protected BinaryObjectExImpl toPortable(BinaryMarshaller marsh, Object obj) throws Exception {
-        byte[] arr = marsh.marshal(obj);
-
-        long ptr = UNSAFE.allocateMemory(arr.length);
-
-        ptrs.add(ptr);
-
-        UNSAFE.copyMemory(arr, BYTE_ARR_OFF, null, ptr, arr.length);
-
-        return new BinaryObjectOffheapImpl(portableContext(marsh), ptr, 0, arr.length);
-    }
-}

http://git-wip-us.apache.org/repos/asf/ignite/blob/1dbf20e0/modules/core/src/test/java/org/apache/ignite/internal/portable/BinaryFooterOffsetsAbstractSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/portable/BinaryFooterOffsetsAbstractSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/portable/BinaryFooterOffsetsAbstractSelfTest.java
deleted file mode 100644
index 38c0137..0000000
--- a/modules/core/src/test/java/org/apache/ignite/internal/portable/BinaryFooterOffsetsAbstractSelfTest.java
+++ /dev/null
@@ -1,205 +0,0 @@
-/*
- * 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.portable;
-
-import java.util.Arrays;
-import org.apache.ignite.binary.BinaryField;
-import org.apache.ignite.binary.BinaryTypeConfiguration;
-import org.apache.ignite.configuration.BinaryConfiguration;
-import org.apache.ignite.configuration.IgniteConfiguration;
-import org.apache.ignite.internal.util.IgniteUtils;
-import org.apache.ignite.marshaller.MarshallerContextTestImpl;
-import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
-
-/**
- * Contains tests for compact offsets.
- */
-public abstract class BinaryFooterOffsetsAbstractSelfTest extends GridCommonAbstractTest {
-    /** 2 pow 8. */
-    private static int POW_8 = 1 << 8;
-
-    /** 2 pow 16. */
-    private static int POW_16 = 1 << 16;
-
-    /** Marshaller. */
-    protected BinaryMarshaller marsh;
-
-    /** Portable context. */
-    protected PortableContext ctx;
-
-    /** {@inheritDoc} */
-    @Override protected void beforeTest() throws Exception {
-        super.beforeTest();
-
-        ctx = new PortableContext(BinaryCachingMetadataHandler.create(), new IgniteConfiguration());
-
-        marsh = new BinaryMarshaller();
-
-        IgniteConfiguration iCfg = new IgniteConfiguration();
-
-        BinaryConfiguration bCfg = new BinaryConfiguration();
-
-        bCfg.setTypeConfigurations(Arrays.asList(new BinaryTypeConfiguration(TestObject.class.getName())));
-        
-        bCfg.setCompactFooter(compactFooter());
-
-        iCfg.setBinaryConfiguration(bCfg);
-
-        marsh.setContext(new MarshallerContextTestImpl(null));
-
-        IgniteUtils.invoke(BinaryMarshaller.class, marsh, "setPortableContext", ctx, iCfg);
-    }
-
-    /**
-     * @return Whether to use compact footers.
-     */
-    protected boolean compactFooter() {
-        return true;
-    }
-    
-    /**
-     * Test 1 byte.
-     *
-     * @throws Exception If failed.
-     */
-    public void test1Byte() throws Exception {
-        check(POW_8 >> 2);
-    }
-
-    /**
-     * Test 1 byte with sign altering.
-     *
-     * @throws Exception If failed.
-     */
-    public void test1ByteSign() throws Exception {
-        check(POW_8 >> 1);
-    }
-
-    /**
-     * Test 2 bytes.
-     *
-     * @throws Exception If failed.
-     */
-    public void test2Bytes() throws Exception {
-        check(POW_16 >> 2);
-    }
-
-    /**
-     * Test 2 bytes with sign altering.
-     *
-     * @throws Exception If failed.
-     */
-    public void test2BytesSign() throws Exception {
-        check(POW_16 >> 1);
-    }
-
-    /**
-     * Test 4 bytes.
-     *
-     * @throws Exception If failed.
-     */
-    public void test4Bytes() throws Exception {
-        check(POW_16 << 2);
-    }
-
-    /**
-     * Main check routine.
-     *
-     * @param len Length of the first field.
-     *
-     * @throws Exception If failed.
-     */
-    private void check(int len) throws Exception {
-        TestObject obj = new TestObject(len);
-
-        BinaryObjectExImpl portObj = toPortable(marsh, obj);
-
-        // 1. Test portable object content.
-        assert portObj.hasField("field1");
-        assert portObj.hasField("field2");
-
-        byte[] field1 = portObj.field("field1");
-        Integer field2 = portObj.field("field2");
-
-        assert field1 != null;
-        assert field2 != null;
-
-        assert Arrays.equals(obj.field1, field1);
-        assert obj.field2 == field2;
-
-        // 2. Test fields API.
-        BinaryField field1Desc = portObj.type().field("field1");
-        BinaryField field2Desc = portObj.type().field("field2");
-
-        assert field1Desc.exists(portObj);
-        assert field2Desc.exists(portObj);
-
-        assert Arrays.equals(obj.field1, (byte[])field1Desc.value(portObj));
-        assert obj.field2 == (Integer)field2Desc.value(portObj);
-
-        // 3. Test deserialize.
-        TestObject objRestored = portObj.deserialize();
-
-        assert objRestored != null;
-
-        assert Arrays.equals(obj.field1, objRestored.field1);
-        assert obj.field2 == objRestored.field2;
-    }
-
-    /**
-     * Convert object to portable object.
-     *
-     * @param marsh Marshaller.
-     * @param obj Object.
-     * @return Portable object.
-     * @throws Exception If failed.
-     */
-    protected abstract BinaryObjectExImpl toPortable(BinaryMarshaller marsh, Object obj) throws Exception;
-
-    /**
-     * Test object.
-     */
-    public static class TestObject {
-        /** First field with variable length. */
-        public byte[] field1;
-
-        /** Second field. */
-        public int field2;
-
-        /**
-         * Default constructor.
-         */
-        public TestObject() {
-            // No-op.
-        }
-
-        /**
-         * Constructor.
-         *
-         * @param len Array length.
-         */
-        public TestObject(int len) {
-            field1 = new byte[len];
-
-            field1[0] = 1;
-            field1[len - 1] = 2;
-
-            field2 = len;
-        }
-    }
-}

http://git-wip-us.apache.org/repos/asf/ignite/blob/1dbf20e0/modules/core/src/test/java/org/apache/ignite/internal/portable/BinaryFooterOffsetsHeapSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/portable/BinaryFooterOffsetsHeapSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/portable/BinaryFooterOffsetsHeapSelfTest.java
deleted file mode 100644
index bc48bef..0000000
--- a/modules/core/src/test/java/org/apache/ignite/internal/portable/BinaryFooterOffsetsHeapSelfTest.java
+++ /dev/null
@@ -1,30 +0,0 @@
-/*
- * 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.portable;
-
-/**
- * Compact offsets tests for heap portable objects.
- */
-public class BinaryFooterOffsetsHeapSelfTest extends BinaryFooterOffsetsAbstractSelfTest {
-    /** {@inheritDoc} */
-    @Override protected BinaryObjectExImpl toPortable(BinaryMarshaller marsh, Object obj) throws Exception {
-        byte[] bytes = marsh.marshal(obj);
-
-        return new BinaryObjectImpl(ctx, bytes, 0);
-    }
-}

http://git-wip-us.apache.org/repos/asf/ignite/blob/1dbf20e0/modules/core/src/test/java/org/apache/ignite/internal/portable/BinaryFooterOffsetsOffheapSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/portable/BinaryFooterOffsetsOffheapSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/portable/BinaryFooterOffsetsOffheapSelfTest.java
deleted file mode 100644
index a2c0a05..0000000
--- a/modules/core/src/test/java/org/apache/ignite/internal/portable/BinaryFooterOffsetsOffheapSelfTest.java
+++ /dev/null
@@ -1,60 +0,0 @@
-/*
- * 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.portable;
-
-import org.apache.ignite.internal.util.GridUnsafe;
-import org.eclipse.jetty.util.ConcurrentHashSet;
-import sun.misc.Unsafe;
-
-/**
- * Compact offsets tests for offheap portable objects.
- */
-public class BinaryFooterOffsetsOffheapSelfTest extends BinaryFooterOffsetsAbstractSelfTest {
-    /** Unsafe instance. */
-    private static final Unsafe UNSAFE = GridUnsafe.unsafe();
-
-    /** Byte array offset for unsafe mechanics. */
-    protected static final long BYTE_ARR_OFF = UNSAFE.arrayBaseOffset(byte[].class);
-
-    /** Allocated unsafe pointer. */
-    private final ConcurrentHashSet<Long> ptrs = new ConcurrentHashSet<>();
-
-    /** {@inheritDoc} */
-    @Override protected void afterTest() throws Exception {
-        super.afterTest();
-
-        // Cleanup allocated objects.
-        for (Long ptr : ptrs)
-            UNSAFE.freeMemory(ptr);
-
-        ptrs.clear();
-    }
-
-    /** {@inheritDoc} */
-    @Override protected BinaryObjectExImpl toPortable(BinaryMarshaller marsh, Object obj) throws Exception {
-        byte[] arr = marsh.marshal(obj);
-
-        long ptr = UNSAFE.allocateMemory(arr.length);
-
-        ptrs.add(ptr);
-
-        UNSAFE.copyMemory(arr, BYTE_ARR_OFF, null, ptr, arr.length);
-
-        return new BinaryObjectOffheapImpl(ctx, ptr, 0, arr.length);
-    }
-}


[51/59] [abbrv] ignite git commit: ignite-2065: rename "portable" classes to "binary"

Posted by ak...@apache.org.
http://git-wip-us.apache.org/repos/asf/ignite/blob/71ad9cea/modules/core/src/main/java/org/apache/ignite/internal/binary/PortableContext.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/binary/PortableContext.java b/modules/core/src/main/java/org/apache/ignite/internal/binary/PortableContext.java
deleted file mode 100644
index f7375a4..0000000
--- a/modules/core/src/main/java/org/apache/ignite/internal/binary/PortableContext.java
+++ /dev/null
@@ -1,1102 +0,0 @@
-/*
- * 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.binary;
-
-import org.apache.ignite.IgniteCheckedException;
-import org.apache.ignite.binary.BinaryIdMapper;
-import org.apache.ignite.binary.BinaryInvalidTypeException;
-import org.apache.ignite.binary.BinaryObjectException;
-import org.apache.ignite.binary.BinarySerializer;
-import org.apache.ignite.binary.BinaryType;
-import org.apache.ignite.binary.BinaryTypeConfiguration;
-import org.apache.ignite.cache.CacheKeyConfiguration;
-import org.apache.ignite.cache.affinity.AffinityKeyMapped;
-import org.apache.ignite.configuration.BinaryConfiguration;
-import org.apache.ignite.configuration.IgniteConfiguration;
-import org.apache.ignite.internal.IgniteKernal;
-import org.apache.ignite.internal.IgnitionEx;
-import org.apache.ignite.internal.processors.cache.binary.CacheObjectBinaryProcessorImpl;
-import org.apache.ignite.internal.processors.datastructures.CollocatedQueueItemKey;
-import org.apache.ignite.internal.processors.datastructures.CollocatedSetItemKey;
-import org.apache.ignite.internal.util.IgniteUtils;
-import org.apache.ignite.internal.util.lang.GridMapEntry;
-import org.apache.ignite.internal.util.typedef.F;
-import org.apache.ignite.internal.util.typedef.T2;
-import org.apache.ignite.internal.util.typedef.internal.U;
-import org.apache.ignite.lang.IgniteBiTuple;
-import org.apache.ignite.marshaller.MarshallerContext;
-import org.apache.ignite.marshaller.optimized.OptimizedMarshaller;
-import org.jetbrains.annotations.Nullable;
-import org.jsr166.ConcurrentHashMap8;
-
-import java.io.Externalizable;
-import java.io.File;
-import java.io.IOException;
-import java.io.InvalidObjectException;
-import java.io.ObjectInput;
-import java.io.ObjectOutput;
-import java.io.ObjectStreamException;
-import java.lang.reflect.Field;
-import java.math.BigDecimal;
-import java.net.URISyntaxException;
-import java.net.URL;
-import java.net.URLClassLoader;
-import java.sql.Timestamp;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.Date;
-import java.util.Enumeration;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.LinkedHashMap;
-import java.util.LinkedHashSet;
-import java.util.LinkedList;
-import java.util.Map;
-import java.util.Set;
-import java.util.UUID;
-import java.util.concurrent.ConcurrentMap;
-import java.util.jar.JarEntry;
-import java.util.jar.JarFile;
-
-/**
- * Portable context.
- */
-public class PortableContext implements Externalizable {
-    /** */
-    private static final long serialVersionUID = 0L;
-
-    /** */
-    private static final ClassLoader dfltLdr = U.gridClassLoader();
-
-    /** */
-    private final ConcurrentMap<Class<?>, PortableClassDescriptor> descByCls = new ConcurrentHashMap8<>();
-
-    /** Holds classes loaded by default class loader only. */
-    private final ConcurrentMap<Integer, PortableClassDescriptor> userTypes = new ConcurrentHashMap8<>();
-
-    /** */
-    private final Map<Integer, PortableClassDescriptor> predefinedTypes = new HashMap<>();
-
-    /** */
-    private final Map<String, Integer> predefinedTypeNames = new HashMap<>();
-
-    /** */
-    private final Map<Class<? extends Collection>, Byte> colTypes = new HashMap<>();
-
-    /** */
-    private final Map<Class<? extends Map>, Byte> mapTypes = new HashMap<>();
-
-    /** */
-    private final ConcurrentMap<Integer, BinaryIdMapper> mappers = new ConcurrentHashMap8<>(0);
-
-    /** Affinity key field names. */
-    private final ConcurrentMap<Integer, String> affKeyFieldNames = new ConcurrentHashMap8<>(0);
-
-    /** */
-    private final Map<String, BinaryIdMapper> typeMappers = new ConcurrentHashMap8<>(0);
-
-    /** */
-    private BinaryMetadataHandler metaHnd;
-
-    /** Actual marshaller. */
-    private BinaryMarshaller marsh;
-
-    /** */
-    private MarshallerContext marshCtx;
-
-    /** */
-    private String gridName;
-
-    /** */
-    private IgniteConfiguration igniteCfg;
-
-    /** */
-    private final OptimizedMarshaller optmMarsh = new OptimizedMarshaller();
-
-    /** Compact footer flag. */
-    private boolean compactFooter;
-
-    /** Object schemas. */
-    private volatile Map<Integer, PortableSchemaRegistry> schemas;
-
-    /**
-     * For {@link Externalizable}.
-     */
-    public PortableContext() {
-        // No-op.
-    }
-
-    /**
-     * @param metaHnd Meta data handler.
-     * @param igniteCfg Ignite configuration.
-     */
-    public PortableContext(BinaryMetadataHandler metaHnd, IgniteConfiguration igniteCfg) {
-        assert metaHnd != null;
-        assert igniteCfg != null;
-
-        this.metaHnd = metaHnd;
-        this.igniteCfg = igniteCfg;
-
-        gridName = igniteCfg.getGridName();
-
-        colTypes.put(ArrayList.class, GridPortableMarshaller.ARR_LIST);
-        colTypes.put(LinkedList.class, GridPortableMarshaller.LINKED_LIST);
-        colTypes.put(HashSet.class, GridPortableMarshaller.HASH_SET);
-        colTypes.put(LinkedHashSet.class, GridPortableMarshaller.LINKED_HASH_SET);
-
-        mapTypes.put(HashMap.class, GridPortableMarshaller.HASH_MAP);
-        mapTypes.put(LinkedHashMap.class, GridPortableMarshaller.LINKED_HASH_MAP);
-
-        // IDs range from [0..200] is used by Java SDK API and GridGain legacy API
-
-        registerPredefinedType(Byte.class, GridPortableMarshaller.BYTE);
-        registerPredefinedType(Boolean.class, GridPortableMarshaller.BOOLEAN);
-        registerPredefinedType(Short.class, GridPortableMarshaller.SHORT);
-        registerPredefinedType(Character.class, GridPortableMarshaller.CHAR);
-        registerPredefinedType(Integer.class, GridPortableMarshaller.INT);
-        registerPredefinedType(Long.class, GridPortableMarshaller.LONG);
-        registerPredefinedType(Float.class, GridPortableMarshaller.FLOAT);
-        registerPredefinedType(Double.class, GridPortableMarshaller.DOUBLE);
-        registerPredefinedType(String.class, GridPortableMarshaller.STRING);
-        registerPredefinedType(BigDecimal.class, GridPortableMarshaller.DECIMAL);
-        registerPredefinedType(Date.class, GridPortableMarshaller.DATE);
-        registerPredefinedType(Timestamp.class, GridPortableMarshaller.TIMESTAMP);
-        registerPredefinedType(UUID.class, GridPortableMarshaller.UUID);
-
-        registerPredefinedType(byte[].class, GridPortableMarshaller.BYTE_ARR);
-        registerPredefinedType(short[].class, GridPortableMarshaller.SHORT_ARR);
-        registerPredefinedType(int[].class, GridPortableMarshaller.INT_ARR);
-        registerPredefinedType(long[].class, GridPortableMarshaller.LONG_ARR);
-        registerPredefinedType(float[].class, GridPortableMarshaller.FLOAT_ARR);
-        registerPredefinedType(double[].class, GridPortableMarshaller.DOUBLE_ARR);
-        registerPredefinedType(char[].class, GridPortableMarshaller.CHAR_ARR);
-        registerPredefinedType(boolean[].class, GridPortableMarshaller.BOOLEAN_ARR);
-        registerPredefinedType(BigDecimal[].class, GridPortableMarshaller.DECIMAL_ARR);
-        registerPredefinedType(String[].class, GridPortableMarshaller.STRING_ARR);
-        registerPredefinedType(UUID[].class, GridPortableMarshaller.UUID_ARR);
-        registerPredefinedType(Date[].class, GridPortableMarshaller.DATE_ARR);
-        registerPredefinedType(Timestamp[].class, GridPortableMarshaller.TIMESTAMP_ARR);
-        registerPredefinedType(Object[].class, GridPortableMarshaller.OBJ_ARR);
-
-        registerPredefinedType(ArrayList.class, 0);
-        registerPredefinedType(LinkedList.class, 0);
-        registerPredefinedType(HashSet.class, 0);
-        registerPredefinedType(LinkedHashSet.class, 0);
-
-        registerPredefinedType(HashMap.class, 0);
-        registerPredefinedType(LinkedHashMap.class, 0);
-
-        registerPredefinedType(GridMapEntry.class, 60);
-        registerPredefinedType(IgniteBiTuple.class, 61);
-        registerPredefinedType(T2.class, 62);
-
-        // IDs range [200..1000] is used by Ignite internal APIs.
-    }
-
-    /**
-     * @return Marshaller.
-     */
-    public BinaryMarshaller marshaller() {
-        return marsh;
-    }
-
-    /**
-     * @return Ignite configuration.
-     */
-    public IgniteConfiguration configuration(){
-        return igniteCfg;
-    }
-
-    /**
-     * @param marsh Portable marshaller.
-     * @param cfg Configuration.
-     * @throws BinaryObjectException In case of error.
-     */
-    public void configure(BinaryMarshaller marsh, IgniteConfiguration cfg) throws BinaryObjectException {
-        if (marsh == null)
-            return;
-
-        this.marsh = marsh;
-
-        marshCtx = marsh.getContext();
-
-        BinaryConfiguration binaryCfg = cfg.getBinaryConfiguration();
-
-        if (binaryCfg == null)
-            binaryCfg = new BinaryConfiguration();
-
-        assert marshCtx != null;
-
-        optmMarsh.setContext(marshCtx);
-
-        configure(
-            binaryCfg.getIdMapper(),
-            binaryCfg.getSerializer(),
-            binaryCfg.getTypeConfigurations()
-        );
-
-        compactFooter = binaryCfg.isCompactFooter();
-    }
-
-    /**
-     * @param globalIdMapper ID mapper.
-     * @param globalSerializer Serializer.
-     * @param typeCfgs Type configurations.
-     * @throws BinaryObjectException In case of error.
-     */
-    private void configure(
-        BinaryIdMapper globalIdMapper,
-        BinarySerializer globalSerializer,
-        Collection<BinaryTypeConfiguration> typeCfgs
-    ) throws BinaryObjectException {
-        TypeDescriptors descs = new TypeDescriptors();
-
-        Map<String, String> affFields = new HashMap<>();
-
-        if (!F.isEmpty(igniteCfg.getCacheKeyConfiguration())) {
-            for (CacheKeyConfiguration keyCfg : igniteCfg.getCacheKeyConfiguration())
-                affFields.put(keyCfg.getTypeName(), keyCfg.getAffinityKeyFieldName());
-        }
-
-        if (typeCfgs != null) {
-            for (BinaryTypeConfiguration typeCfg : typeCfgs) {
-                String clsName = typeCfg.getTypeName();
-
-                if (clsName == null)
-                    throw new BinaryObjectException("Class name is required for portable type configuration.");
-
-                BinaryIdMapper idMapper = globalIdMapper;
-
-                if (typeCfg.getIdMapper() != null)
-                    idMapper = typeCfg.getIdMapper();
-
-                idMapper = BinaryInternalIdMapper.create(idMapper);
-
-                BinarySerializer serializer = globalSerializer;
-
-                if (typeCfg.getSerializer() != null)
-                    serializer = typeCfg.getSerializer();
-
-                if (clsName.endsWith(".*")) {
-                    String pkgName = clsName.substring(0, clsName.length() - 2);
-
-                    for (String clsName0 : classesInPackage(pkgName))
-                        descs.add(clsName0, idMapper, serializer, affFields.get(clsName0),
-                            typeCfg.isEnum(), true);
-                }
-                else
-                    descs.add(clsName, idMapper, serializer, affFields.get(clsName),
-                        typeCfg.isEnum(), false);
-            }
-        }
-
-        for (TypeDescriptor desc : descs.descriptors())
-            registerUserType(desc.clsName, desc.idMapper, desc.serializer, desc.affKeyFieldName, desc.isEnum);
-
-        BinaryInternalIdMapper dfltMapper = BinaryInternalIdMapper.create(globalIdMapper);
-
-        // Put affinity field names for unconfigured types.
-        for (Map.Entry<String, String> entry : affFields.entrySet()) {
-            String typeName = entry.getKey();
-
-            int typeId = dfltMapper.typeId(typeName);
-
-            affKeyFieldNames.putIfAbsent(typeId, entry.getValue());
-        }
-
-        addSystemClassAffinityKey(CollocatedSetItemKey.class);
-        addSystemClassAffinityKey(CollocatedQueueItemKey.class);
-    }
-
-    /**
-     * @param cls Class.
-     */
-    private void addSystemClassAffinityKey(Class<?> cls) {
-        String fieldName = affinityFieldName(cls);
-
-        assert fieldName != null : cls;
-
-        affKeyFieldNames.putIfAbsent(cls.getName().hashCode(), affinityFieldName(cls));
-    }
-
-    /**
-     * @param pkgName Package name.
-     * @return Class names.
-     */
-    @SuppressWarnings("ConstantConditions")
-    private static Iterable<String> classesInPackage(String pkgName) {
-        assert pkgName != null;
-
-        Collection<String> clsNames = new ArrayList<>();
-
-        ClassLoader ldr = U.gridClassLoader();
-
-        if (ldr instanceof URLClassLoader) {
-            String pkgPath = pkgName.replaceAll("\\.", "/");
-
-            URL[] urls = ((URLClassLoader)ldr).getURLs();
-
-            for (URL url : urls) {
-                String proto = url.getProtocol().toLowerCase();
-
-                if ("file".equals(proto)) {
-                    try {
-                        File cpElement = new File(url.toURI());
-
-                        if (cpElement.isDirectory()) {
-                            File pkgDir = new File(cpElement, pkgPath);
-
-                            if (pkgDir.isDirectory()) {
-                                for (File file : pkgDir.listFiles()) {
-                                    String fileName = file.getName();
-
-                                    if (file.isFile() && fileName.toLowerCase().endsWith(".class"))
-                                        clsNames.add(pkgName + '.' + fileName.substring(0, fileName.length() - 6));
-                                }
-                            }
-                        }
-                        else if (cpElement.isFile()) {
-                            try {
-                                JarFile jar = new JarFile(cpElement);
-
-                                Enumeration<JarEntry> entries = jar.entries();
-
-                                while (entries.hasMoreElements()) {
-                                    String entry = entries.nextElement().getName();
-
-                                    if (entry.startsWith(pkgPath) && entry.endsWith(".class")) {
-                                        String clsName = entry.substring(pkgPath.length() + 1, entry.length() - 6);
-
-                                        if (!clsName.contains("/") && !clsName.contains("\\"))
-                                            clsNames.add(pkgName + '.' + clsName);
-                                    }
-                                }
-                            }
-                            catch (IOException ignored) {
-                                // No-op.
-                            }
-                        }
-                    }
-                    catch (URISyntaxException ignored) {
-                        // No-op.
-                    }
-                }
-            }
-        }
-
-        return clsNames;
-    }
-
-    /**
-     * @param cls Class.
-     * @return Class descriptor.
-     * @throws BinaryObjectException In case of error.
-     */
-    public PortableClassDescriptor descriptorForClass(Class<?> cls, boolean deserialize)
-        throws BinaryObjectException {
-        assert cls != null;
-
-        PortableClassDescriptor desc = descByCls.get(cls);
-
-        if (desc == null || !desc.registered())
-            desc = registerClassDescriptor(cls, deserialize);
-
-        return desc;
-    }
-
-    /**
-     * @param userType User type or not.
-     * @param typeId Type ID.
-     * @param ldr Class loader.
-     * @return Class descriptor.
-     */
-    public PortableClassDescriptor descriptorForTypeId(
-        boolean userType,
-        int typeId,
-        ClassLoader ldr,
-        boolean deserialize
-    ) {
-        assert typeId != GridPortableMarshaller.UNREGISTERED_TYPE_ID;
-
-        //TODO: As a workaround for IGNITE-1358 we always check the predefined map before without checking 'userType'
-        PortableClassDescriptor desc = predefinedTypes.get(typeId);
-
-        if (desc != null)
-            return desc;
-
-        if (ldr == null)
-            ldr = dfltLdr;
-
-        // If the type hasn't been loaded by default class loader then we mustn't return the descriptor from here
-        // giving a chance to a custom class loader to reload type's class.
-        if (userType && ldr.equals(dfltLdr)) {
-            desc = userTypes.get(typeId);
-
-            if (desc != null)
-                return desc;
-        }
-
-        Class cls;
-
-        try {
-            cls = marshCtx.getClass(typeId, ldr);
-
-            desc = descByCls.get(cls);
-        }
-        catch (ClassNotFoundException e) {
-            // Class might have been loaded by default class loader.
-            if (userType && !ldr.equals(dfltLdr) && (desc = descriptorForTypeId(true, typeId, dfltLdr, deserialize)) != null)
-                return desc;
-
-            throw new BinaryInvalidTypeException(e);
-        }
-        catch (IgniteCheckedException e) {
-            // Class might have been loaded by default class loader.
-            if (userType && !ldr.equals(dfltLdr) && (desc = descriptorForTypeId(true, typeId, dfltLdr, deserialize)) != null)
-                return desc;
-
-            throw new BinaryObjectException("Failed resolve class for ID: " + typeId, e);
-        }
-
-        if (desc == null) {
-            desc = registerClassDescriptor(cls, deserialize);
-
-            assert desc.typeId() == typeId;
-        }
-
-        return desc;
-    }
-
-    /**
-     * Creates and registers {@link PortableClassDescriptor} for the given {@code class}.
-     *
-     * @param cls Class.
-     * @return Class descriptor.
-     */
-    private PortableClassDescriptor registerClassDescriptor(Class<?> cls, boolean deserialize) {
-        PortableClassDescriptor desc;
-
-        String clsName = cls.getName();
-
-        if (marshCtx.isSystemType(clsName)) {
-            desc = new PortableClassDescriptor(this,
-                cls,
-                false,
-                clsName.hashCode(),
-                clsName,
-                null,
-                BinaryInternalIdMapper.defaultInstance(),
-                null,
-                false,
-                true, /* registered */
-                false /* predefined */
-            );
-
-            PortableClassDescriptor old = descByCls.putIfAbsent(cls, desc);
-
-            if (old != null)
-                desc = old;
-        }
-        else
-            desc = registerUserClassDescriptor(cls, deserialize);
-
-        return desc;
-    }
-
-    /**
-     * Creates and registers {@link PortableClassDescriptor} for the given user {@code class}.
-     *
-     * @param cls Class.
-     * @return Class descriptor.
-     */
-    private PortableClassDescriptor registerUserClassDescriptor(Class<?> cls, boolean deserialize) {
-        boolean registered;
-
-        String typeName = typeName(cls.getName());
-
-        BinaryIdMapper idMapper = userTypeIdMapper(typeName);
-
-        int typeId = idMapper.typeId(typeName);
-
-        try {
-            registered = marshCtx.registerClass(typeId, cls);
-        }
-        catch (IgniteCheckedException e) {
-            throw new BinaryObjectException("Failed to register class.", e);
-        }
-
-        String affFieldName = affinityFieldName(cls);
-
-        PortableClassDescriptor desc = new PortableClassDescriptor(this,
-            cls,
-            true,
-            typeId,
-            typeName,
-            affFieldName,
-            idMapper,
-            null,
-            true,
-            registered,
-            false /* predefined */
-        );
-
-        if (!deserialize) {
-            Collection<PortableSchema> schemas = desc.schema() != null ? Collections.singleton(desc.schema()) : null;
-
-            metaHnd.addMeta(typeId,
-                new BinaryMetadata(typeId, typeName, desc.fieldsMeta(), affFieldName, schemas, desc.isEnum()).wrap(this));
-        }
-
-        // perform put() instead of putIfAbsent() because "registered" flag might have been changed or class loader
-        // might have reloaded described class.
-        if (IgniteUtils.detectClassLoader(cls).equals(dfltLdr))
-            userTypes.put(typeId, desc);
-
-        descByCls.put(cls, desc);
-
-        mappers.putIfAbsent(typeId, idMapper);
-
-        return desc;
-    }
-
-    /**
-     * @param cls Collection class.
-     * @return Collection type ID.
-     */
-    public byte collectionType(Class<? extends Collection> cls) {
-        assert cls != null;
-
-        Byte type = colTypes.get(cls);
-
-        if (type != null)
-            return type;
-
-        return Set.class.isAssignableFrom(cls) ? GridPortableMarshaller.USER_SET : GridPortableMarshaller.USER_COL;
-    }
-
-    /**
-     * @param cls Map class.
-     * @return Map type ID.
-     */
-    public byte mapType(Class<? extends Map> cls) {
-        assert cls != null;
-
-        Byte type = mapTypes.get(cls);
-
-        return type != null ? type : GridPortableMarshaller.USER_COL;
-    }
-
-    /**
-     * @param typeName Type name.
-     * @return Type ID.
-     */
-    public int typeId(String typeName) {
-        String typeName0 = typeName(typeName);
-
-        Integer id = predefinedTypeNames.get(typeName0);
-
-        if (id != null)
-            return id;
-
-        if (marshCtx.isSystemType(typeName))
-            return typeName.hashCode();
-
-        return userTypeIdMapper(typeName0).typeId(typeName0);
-    }
-
-    /**
-     * @param typeId Type ID.
-     * @param fieldName Field name.
-     * @return Field ID.
-     */
-    public int fieldId(int typeId, String fieldName) {
-        return userTypeIdMapper(typeId).fieldId(typeId, fieldName);
-    }
-
-    /**
-     * @param typeId Type ID.
-     * @return Instance of ID mapper.
-     */
-    public BinaryIdMapper userTypeIdMapper(int typeId) {
-        BinaryIdMapper idMapper = mappers.get(typeId);
-
-        return idMapper != null ? idMapper : BinaryInternalIdMapper.defaultInstance();
-    }
-
-    /**
-     * @param typeName Type name.
-     * @return Instance of ID mapper.
-     */
-    private BinaryIdMapper userTypeIdMapper(String typeName) {
-        BinaryIdMapper idMapper = typeMappers.get(typeName);
-
-        return idMapper != null ? idMapper : BinaryInternalIdMapper.defaultInstance();
-    }
-
-    /**
-     * @param cls Class to get affinity field for.
-     * @return Affinity field name or {@code null} if field name was not found.
-     */
-    private String affinityFieldName(Class cls) {
-        for (; cls != Object.class && cls != null; cls = cls.getSuperclass()) {
-            for (Field f : cls.getDeclaredFields()) {
-                if (f.getAnnotation(AffinityKeyMapped.class) != null)
-                    return f.getName();
-            }
-        }
-
-        return null;
-    }
-
-    /** {@inheritDoc} */
-    @Override public void writeExternal(ObjectOutput out) throws IOException {
-        U.writeString(out, igniteCfg.getGridName());
-    }
-
-    /** {@inheritDoc} */
-    @Override public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
-        gridName = U.readString(in);
-    }
-
-    /**
-     * @return Portable context.
-     * @throws ObjectStreamException In case of error.
-     */
-    protected Object readResolve() throws ObjectStreamException {
-        try {
-            IgniteKernal g = IgnitionEx.gridx(gridName);
-
-            if (g == null)
-                throw new IllegalStateException("Failed to find grid for name: " + gridName);
-
-            return ((CacheObjectBinaryProcessorImpl)g.context().cacheObjects()).portableContext();
-        }
-        catch (IllegalStateException e) {
-            throw U.withCause(new InvalidObjectException(e.getMessage()), e);
-        }
-    }
-
-    /**
-     * @param cls Class.
-     * @param id Type ID.
-     * @return GridPortableClassDescriptor.
-     */
-    public PortableClassDescriptor registerPredefinedType(Class<?> cls, int id) {
-        String typeName = typeName(cls.getName());
-
-        PortableClassDescriptor desc = new PortableClassDescriptor(
-            this,
-            cls,
-            false,
-            id,
-            typeName,
-            null,
-            BinaryInternalIdMapper.defaultInstance(),
-            null,
-            false,
-            true, /* registered */
-            true /* predefined */
-        );
-
-        predefinedTypeNames.put(typeName, id);
-        predefinedTypes.put(id, desc);
-
-        descByCls.put(cls, desc);
-
-        return desc;
-    }
-
-    /**
-     * @param clsName Class name.
-     * @param idMapper ID mapper.
-     * @param serializer Serializer.
-     * @param affKeyFieldName Affinity key field name.
-     * @param isEnum If enum.
-     * @throws BinaryObjectException In case of error.
-     */
-    @SuppressWarnings("ErrorNotRethrown")
-    public void registerUserType(String clsName,
-        BinaryIdMapper idMapper,
-        @Nullable BinarySerializer serializer,
-        @Nullable String affKeyFieldName,
-        boolean isEnum)
-        throws BinaryObjectException {
-        assert idMapper != null;
-
-        Class<?> cls = null;
-
-        try {
-            cls = Class.forName(clsName);
-        }
-        catch (ClassNotFoundException | NoClassDefFoundError ignored) {
-            // No-op.
-        }
-
-        String typeName = typeName(clsName);
-
-        int id = idMapper.typeId(typeName);
-
-        //Workaround for IGNITE-1358
-        if (predefinedTypes.get(id) != null)
-            throw new BinaryObjectException("Duplicate type ID [clsName=" + clsName + ", id=" + id + ']');
-
-        if (mappers.put(id, idMapper) != null)
-            throw new BinaryObjectException("Duplicate type ID [clsName=" + clsName + ", id=" + id + ']');
-
-        if (affKeyFieldName != null) {
-            if (affKeyFieldNames.put(id, affKeyFieldName) != null)
-                throw new BinaryObjectException("Duplicate type ID [clsName=" + clsName + ", id=" + id + ']');
-        }
-
-        typeMappers.put(typeName, idMapper);
-
-        Map<String, Integer> fieldsMeta = null;
-        Collection<PortableSchema> schemas = null;
-
-        if (cls != null) {
-            PortableClassDescriptor desc = new PortableClassDescriptor(
-                this,
-                cls,
-                true,
-                id,
-                typeName,
-                affKeyFieldName,
-                idMapper,
-                serializer,
-                true,
-                true, /* registered */
-                false /* predefined */
-            );
-
-            fieldsMeta = desc.fieldsMeta();
-            schemas = desc.schema() != null ? Collections.singleton(desc.schema()) : null;
-
-            if (IgniteUtils.detectClassLoader(cls).equals(dfltLdr))
-                userTypes.put(id, desc);
-
-            descByCls.put(cls, desc);
-        }
-
-        metaHnd.addMeta(id, new BinaryMetadata(id, typeName, fieldsMeta, affKeyFieldName, schemas, isEnum).wrap(this));
-    }
-
-    /**
-     * Create binary field.
-     *
-     * @param typeId Type ID.
-     * @param fieldName Field name.
-     * @return Binary field.
-     */
-    public BinaryFieldImpl createField(int typeId, String fieldName) {
-        PortableSchemaRegistry schemaReg = schemaRegistry(typeId);
-
-        int fieldId = userTypeIdMapper(typeId).fieldId(typeId, fieldName);
-
-        return new BinaryFieldImpl(typeId, schemaReg, fieldName, fieldId);
-    }
-
-    /**
-     * @param typeId Type ID.
-     * @return Meta data.
-     * @throws BinaryObjectException In case of error.
-     */
-    @Nullable public BinaryType metadata(int typeId) throws BinaryObjectException {
-        return metaHnd != null ? metaHnd.metadata(typeId) : null;
-    }
-
-    /**
-     * @param typeId Type ID.
-     * @return Affinity key field name.
-     */
-    public String affinityKeyFieldName(int typeId) {
-        return affKeyFieldNames.get(typeId);
-    }
-
-    /**
-     * @param typeId Type ID.
-     * @param meta Meta data.
-     * @throws BinaryObjectException In case of error.
-     */
-    public void updateMetadata(int typeId, BinaryMetadata meta) throws BinaryObjectException {
-        metaHnd.addMeta(typeId, meta.wrap(this));
-    }
-
-    /**
-     * @return Whether field IDs should be skipped in footer or not.
-     */
-    public boolean isCompactFooter() {
-        return compactFooter;
-    }
-
-    /**
-     * Get schema registry for type ID.
-     *
-     * @param typeId Type ID.
-     * @return Schema registry for type ID.
-     */
-    public PortableSchemaRegistry schemaRegistry(int typeId) {
-        Map<Integer, PortableSchemaRegistry> schemas0 = schemas;
-
-        if (schemas0 == null) {
-            synchronized (this) {
-                schemas0 = schemas;
-
-                if (schemas0 == null) {
-                    schemas0 = new HashMap<>();
-
-                    PortableSchemaRegistry reg = new PortableSchemaRegistry();
-
-                    schemas0.put(typeId, reg);
-
-                    schemas = schemas0;
-
-                    return reg;
-                }
-            }
-        }
-
-        PortableSchemaRegistry reg = schemas0.get(typeId);
-
-        if (reg == null) {
-            synchronized (this) {
-                reg = schemas.get(typeId);
-
-                if (reg == null) {
-                    reg = new PortableSchemaRegistry();
-
-                    schemas0 = new HashMap<>(schemas);
-
-                    schemas0.put(typeId, reg);
-
-                    schemas = schemas0;
-                }
-            }
-        }
-
-        return reg;
-    }
-
-    /**
-     * Returns instance of {@link OptimizedMarshaller}.
-     *
-     * @return Optimized marshaller.
-     */
-    OptimizedMarshaller optimizedMarsh() {
-        return optmMarsh;
-    }
-
-    /**
-     * @param clsName Class name.
-     * @return Type name.
-     */
-    @SuppressWarnings("ResultOfMethodCallIgnored")
-    public static String typeName(String clsName) {
-        assert clsName != null;
-
-        int idx = clsName.lastIndexOf('$');
-
-        if (idx == clsName.length() - 1)
-            // This is a regular (not inner) class name that ends with '$'. Common use case for Scala classes.
-            idx = -1;
-        else if (idx >= 0) {
-            String typeName = clsName.substring(idx + 1);
-
-            try {
-                Integer.parseInt(typeName);
-
-                // This is an anonymous class. Don't cut off enclosing class name for it.
-                idx = -1;
-            }
-            catch (NumberFormatException ignore) {
-                // This is a lambda class.
-                if (clsName.indexOf("$$Lambda$") > 0)
-                    idx = -1;
-                else
-                    return typeName;
-            }
-        }
-
-        if (idx < 0)
-            idx = clsName.lastIndexOf('.');
-
-        return idx >= 0 ? clsName.substring(idx + 1) : clsName;
-    }
-
-    /**
-     * Undeployment callback invoked when class loader is being undeployed.
-     *
-     * Some marshallers may want to clean their internal state that uses the undeployed class loader somehow.
-     *
-     * @param ldr Class loader being undeployed.
-     */
-    public void onUndeploy(ClassLoader ldr) {
-        for (Class<?> cls : descByCls.keySet()) {
-            if (ldr.equals(cls.getClassLoader()))
-                descByCls.remove(cls);
-        }
-
-        U.clearClassCache(ldr);
-    }
-
-    /**
-     * Type descriptors.
-     */
-    private static class TypeDescriptors {
-        /** Descriptors map. */
-        private final Map<String, TypeDescriptor> descs = new LinkedHashMap<>();
-
-        /**
-         * Add type descriptor.
-         *
-         * @param clsName Class name.
-         * @param idMapper ID mapper.
-         * @param serializer Serializer.
-         * @param affKeyFieldName Affinity key field name.
-         * @param isEnum Enum flag.
-         * @param canOverride Whether this descriptor can be override.
-         * @throws BinaryObjectException If failed.
-         */
-        private void add(String clsName,
-            BinaryIdMapper idMapper,
-            BinarySerializer serializer,
-            String affKeyFieldName,
-            boolean isEnum,
-            boolean canOverride)
-            throws BinaryObjectException {
-            TypeDescriptor desc = new TypeDescriptor(clsName,
-                idMapper,
-                serializer,
-                affKeyFieldName,
-                isEnum,
-                canOverride);
-
-            TypeDescriptor oldDesc = descs.get(clsName);
-
-            if (oldDesc == null)
-                descs.put(clsName, desc);
-            else
-                oldDesc.override(desc);
-        }
-
-        /**
-         * Get all collected descriptors.
-         *
-         * @return Descriptors.
-         */
-        private Iterable<TypeDescriptor> descriptors() {
-            return descs.values();
-        }
-    }
-
-    /**
-     * Type descriptor.
-     */
-    private static class TypeDescriptor {
-        /** Class name. */
-        private final String clsName;
-
-        /** ID mapper. */
-        private BinaryIdMapper idMapper;
-
-        /** Serializer. */
-        private BinarySerializer serializer;
-
-        /** Affinity key field name. */
-        private String affKeyFieldName;
-
-        /** Enum flag. */
-        private boolean isEnum;
-
-        /** Whether this descriptor can be override. */
-        private boolean canOverride;
-
-        /**
-         * Constructor.
-         *
-         * @param clsName Class name.
-         * @param idMapper ID mapper.
-         * @param serializer Serializer.
-         * @param affKeyFieldName Affinity key field name.
-         * @param isEnum Enum type.
-         * @param canOverride Whether this descriptor can be override.
-         */
-        private TypeDescriptor(String clsName, BinaryIdMapper idMapper, BinarySerializer serializer,
-            String affKeyFieldName, boolean isEnum, boolean canOverride) {
-            this.clsName = clsName;
-            this.idMapper = idMapper;
-            this.serializer = serializer;
-            this.affKeyFieldName = affKeyFieldName;
-            this.isEnum = isEnum;
-            this.canOverride = canOverride;
-        }
-
-        /**
-         * Override portable class descriptor.
-         *
-         * @param other Other descriptor.
-         * @throws BinaryObjectException If failed.
-         */
-        private void override(TypeDescriptor other) throws BinaryObjectException {
-            assert clsName.equals(other.clsName);
-
-            if (canOverride) {
-                idMapper = other.idMapper;
-                serializer = other.serializer;
-                affKeyFieldName = other.affKeyFieldName;
-                canOverride = other.canOverride;
-            }
-            else if (!other.canOverride)
-                throw new BinaryObjectException("Duplicate explicit class definition in configuration: " + clsName);
-        }
-    }
-
-    /**
-     * Type id wrapper.
-     */
-    static class Type {
-        /** Type id */
-        private final int id;
-
-        /** Whether the following type is registered in a cache or not */
-        private final boolean registered;
-
-        /**
-         * @param id Id.
-         * @param registered Registered.
-         */
-        public Type(int id, boolean registered) {
-            this.id = id;
-            this.registered = registered;
-        }
-
-        /**
-         * @return Type ID.
-         */
-        public int id() {
-            return id;
-        }
-
-        /**
-         * @return Registered flag value.
-         */
-        public boolean registered() {
-            return registered;
-        }
-    }
-}

http://git-wip-us.apache.org/repos/asf/ignite/blob/71ad9cea/modules/core/src/main/java/org/apache/ignite/internal/binary/PortablePositionReadable.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/binary/PortablePositionReadable.java b/modules/core/src/main/java/org/apache/ignite/internal/binary/PortablePositionReadable.java
deleted file mode 100644
index 8db6384..0000000
--- a/modules/core/src/main/java/org/apache/ignite/internal/binary/PortablePositionReadable.java
+++ /dev/null
@@ -1,47 +0,0 @@
-/*
- * 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.binary;
-
-/**
- * Interface allowing for positioned read.
- */
-public interface PortablePositionReadable {
-    /**
-     * Read byte at the given position.
-     *
-     * @param pos Position.
-     * @return Value.
-     */
-    public byte readBytePositioned(int pos);
-
-    /**
-     * Read short at the given position.
-     *
-     * @param pos Position.
-     * @return Value.
-     */
-    public short readShortPositioned(int pos);
-
-    /**
-     * Read integer at the given position.
-     *
-     * @param pos Position.
-     * @return Value.
-     */
-    public int readIntPositioned(int pos);
-}

http://git-wip-us.apache.org/repos/asf/ignite/blob/71ad9cea/modules/core/src/main/java/org/apache/ignite/internal/binary/PortablePrimitives.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/binary/PortablePrimitives.java b/modules/core/src/main/java/org/apache/ignite/internal/binary/PortablePrimitives.java
deleted file mode 100644
index e5ff494..0000000
--- a/modules/core/src/main/java/org/apache/ignite/internal/binary/PortablePrimitives.java
+++ /dev/null
@@ -1,382 +0,0 @@
-/*
- * 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.binary;
-
-import org.apache.ignite.internal.util.GridUnsafe;
-import sun.misc.Unsafe;
-
-import java.nio.ByteOrder;
-
-/**
- * Primitives writer.
- */
-public abstract class PortablePrimitives {
-    /** */
-    private static final Unsafe UNSAFE = GridUnsafe.unsafe();
-
-    /** */
-    private static final long BYTE_ARR_OFF = UNSAFE.arrayBaseOffset(byte[].class);
-
-    /** */
-    private static final long CHAR_ARR_OFF = UNSAFE.arrayBaseOffset(char[].class);
-
-    /** Whether little endian is set. */
-    private static final boolean BIG_ENDIAN = ByteOrder.nativeOrder() == ByteOrder.BIG_ENDIAN;
-
-    /**
-     * @param arr Array.
-     * @param off Offset.
-     * @param val Value.
-     */
-    public static void writeByte(byte[] arr, int off, byte val) {
-        UNSAFE.putByte(arr, BYTE_ARR_OFF + off, val);
-    }
-
-    /**
-     * @param arr Array.
-     * @param off Offset.
-     * @return Value.
-     */
-    public static byte readByte(byte[] arr, int off) {
-        return UNSAFE.getByte(arr, BYTE_ARR_OFF + off);
-    }
-
-    /**
-     * @param ptr Pointer.
-     * @param off Offset.
-     * @return Value.
-     */
-    public static byte readByte(long ptr, int off) {
-        return UNSAFE.getByte(ptr + off);
-    }
-
-    /**
-     * @param arr Array.
-     * @param off Offset.
-     * @return Value.
-     */
-    public static byte[] readByteArray(byte[] arr, int off, int len) {
-        byte[] arr0 = new byte[len];
-
-        UNSAFE.copyMemory(arr, BYTE_ARR_OFF + off, arr0, BYTE_ARR_OFF, len);
-
-        return arr0;
-    }
-
-    /**
-     * @param ptr Pointer.
-     * @param off Offset.
-     * @return Value.
-     */
-    public static byte[] readByteArray(long ptr, int off, int len) {
-        byte[] arr0 = new byte[len];
-
-        UNSAFE.copyMemory(null, ptr + off, arr0, BYTE_ARR_OFF, len);
-
-        return arr0;
-    }
-
-    /**
-     * @param arr Array.
-     * @param off Offset.
-     * @param val Value.
-     */
-    public static void writeBoolean(byte[] arr, int off, boolean val) {
-        writeByte(arr, off, val ? (byte)1 : (byte)0);
-    }
-
-    /**
-     * @param arr Array.
-     * @param off Offset.
-     * @return Value.
-     */
-    public static boolean readBoolean(byte[] arr, int off) {
-        return readByte(arr, off) == 1;
-    }
-
-    /**
-     * @param ptr Pointer.
-     * @param off Offset.
-     * @return Value.
-     */
-    public static boolean readBoolean(long ptr, int off) {
-        return readByte(ptr, off) == 1;
-    }
-
-    /**
-     * @param arr Array.
-     * @param off Offset.
-     * @param val Value.
-     */
-    public static void writeShort(byte[] arr, int off, short val) {
-        if (BIG_ENDIAN)
-            val = Short.reverseBytes(val);
-
-        UNSAFE.putShort(arr, BYTE_ARR_OFF + off, val);
-    }
-
-    /**
-     * @param arr Array.
-     * @param off Offset.
-     * @return Value.
-     */
-    public static short readShort(byte[] arr, int off) {
-        short val = UNSAFE.getShort(arr, BYTE_ARR_OFF + off);
-
-        if (BIG_ENDIAN)
-            val = Short.reverseBytes(val);
-
-        return val;
-    }
-
-    /**
-     * @param ptr Pointer.
-     * @param off Offset.
-     * @return Value.
-     */
-    public static short readShort(long ptr, int off) {
-        short val = UNSAFE.getShort(ptr + off);
-
-        if (BIG_ENDIAN)
-            val = Short.reverseBytes(val);
-
-        return val;
-    }
-
-    /**
-     * @param arr Array.
-     * @param off Offset.
-     * @param val Value.
-     */
-    public static void writeChar(byte[] arr, int off, char val) {
-        if (BIG_ENDIAN)
-            val = Character.reverseBytes(val);
-
-        UNSAFE.putChar(arr, BYTE_ARR_OFF + off, val);
-    }
-
-    /**
-     * @param arr Array.
-     * @param off Offset.
-     * @return Value.
-     */
-    public static char readChar(byte[] arr, int off) {
-        char val = UNSAFE.getChar(arr, BYTE_ARR_OFF + off);
-
-        if (BIG_ENDIAN)
-            val = Character.reverseBytes(val);
-
-        return val;
-    }
-
-    /**
-     * @param ptr Pointer.
-     * @param off Offset.
-     * @return Value.
-     */
-    public static char readChar(long ptr, int off) {
-        char val = UNSAFE.getChar(ptr + off);
-
-        if (BIG_ENDIAN)
-            val = Character.reverseBytes(val);
-
-        return val;
-    }
-
-    /**
-     * @param arr Array.
-     * @param off Offset.
-     * @return Value.
-     */
-    public static char[] readCharArray(byte[] arr, int off, int len) {
-        char[] arr0 = new char[len];
-
-        UNSAFE.copyMemory(arr, BYTE_ARR_OFF + off, arr0, CHAR_ARR_OFF, len << 1);
-
-        if (BIG_ENDIAN) {
-            for (int i = 0; i < len; i++)
-                arr0[i] = Character.reverseBytes(arr0[i]);
-        }
-
-        return arr0;
-    }
-
-    /**
-     * @param ptr Pointer.
-     * @param off Offset.
-     * @return Value.
-     */
-    public static char[] readCharArray(long ptr, int off, int len) {
-        char[] arr0 = new char[len];
-
-        UNSAFE.copyMemory(null, ptr + off, arr0, CHAR_ARR_OFF, len << 1);
-
-        if (BIG_ENDIAN) {
-            for (int i = 0; i < len; i++)
-                arr0[i] = Character.reverseBytes(arr0[i]);
-        }
-
-        return arr0;
-    }
-
-    /**
-     * @param arr Array.
-     * @param off Offset.
-     * @param val Value.
-     */
-    public static void writeInt(byte[] arr, int off, int val) {
-        if (BIG_ENDIAN)
-            val = Integer.reverseBytes(val);
-
-        UNSAFE.putInt(arr, BYTE_ARR_OFF + off, val);
-    }
-
-    /**
-     * @param arr Array.
-     * @param off Offset.
-     * @return Value.
-     */
-    public static int readInt(byte[] arr, int off) {
-        int val = UNSAFE.getInt(arr, BYTE_ARR_OFF + off);
-
-        if (BIG_ENDIAN)
-            val = Integer.reverseBytes(val);
-
-        return val;
-    }
-
-    /**
-     * @param ptr Pointer.
-     * @param off Offset.
-     * @return Value.
-     */
-    public static int readInt(long ptr, int off) {
-        int val = UNSAFE.getInt(ptr + off);
-
-        if (BIG_ENDIAN)
-            val = Integer.reverseBytes(val);
-
-        return val;
-    }
-
-    /**
-     * @param arr Array.
-     * @param off Offset.
-     * @param val Value.
-     */
-    public static void writeLong(byte[] arr, int off, long val) {
-        if (BIG_ENDIAN)
-            val = Long.reverseBytes(val);
-
-        UNSAFE.putLong(arr, BYTE_ARR_OFF + off, val);
-    }
-
-    /**
-     * @param arr Array.
-     * @param off Offset.
-     * @return Value.
-     */
-    public static long readLong(byte[] arr, int off) {
-        long val = UNSAFE.getLong(arr, BYTE_ARR_OFF + off);
-
-        if (BIG_ENDIAN)
-            val = Long.reverseBytes(val);
-
-        return val;
-    }
-
-    /**
-     * @param ptr Pointer.
-     * @param off Offset.
-     * @return Value.
-     */
-    public static long readLong(long ptr, int off) {
-        long val = UNSAFE.getLong(ptr + off);
-
-        if (BIG_ENDIAN)
-            val = Long.reverseBytes(val);
-
-        return val;
-    }
-
-    /**
-     * @param arr Array.
-     * @param off Offset.
-     * @param val Value.
-     */
-    public static void writeFloat(byte[] arr, int off, float val) {
-        int val0 = Float.floatToIntBits(val);
-
-        writeInt(arr, off, val0);
-    }
-
-    /**
-     * @param arr Array.
-     * @param off Offset.
-     * @return Value.
-     */
-    public static float readFloat(byte[] arr, int off) {
-        int val = readInt(arr, off);
-
-        return Float.intBitsToFloat(val);
-    }
-
-    /**
-     * @param ptr Pointer.
-     * @param off Offset.
-     * @return Value.
-     */
-    public static float readFloat(long ptr, int off) {
-        int val = readInt(ptr, off);
-
-        return Float.intBitsToFloat(val);
-    }
-
-    /**
-     * @param arr Array.
-     * @param off Offset.
-     * @param val Value.
-     */
-    public static void writeDouble(byte[] arr, int off, double val) {
-        long val0 = Double.doubleToLongBits(val);
-
-        writeLong(arr, off, val0);
-    }
-
-    /**
-     * @param arr Array.
-     * @param off Offset.
-     * @return Value.
-     */
-    public static double readDouble(byte[] arr, int off) {
-        long val = readLong(arr, off);
-
-        return Double.longBitsToDouble(val);
-    }
-
-    /**
-     * @param ptr Pointer.
-     * @param off Offset.
-     * @return Value.
-     */
-    public static double readDouble(long ptr, int off) {
-        long val = readLong(ptr, off);
-
-        return Double.longBitsToDouble(val);
-    }
-}

http://git-wip-us.apache.org/repos/asf/ignite/blob/71ad9cea/modules/core/src/main/java/org/apache/ignite/internal/binary/PortableSchema.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/binary/PortableSchema.java b/modules/core/src/main/java/org/apache/ignite/internal/binary/PortableSchema.java
deleted file mode 100644
index 61b5d45..0000000
--- a/modules/core/src/main/java/org/apache/ignite/internal/binary/PortableSchema.java
+++ /dev/null
@@ -1,466 +0,0 @@
-/*
- * 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.binary;
-
-import java.io.Externalizable;
-import java.io.IOException;
-import java.io.ObjectInput;
-import java.io.ObjectOutput;
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.List;
-
-/**
- * Schema describing portable object content. We rely on the following assumptions:
- * - When amount of fields in the object is low, it is better to inline these values into int fields thus allowing
- * for quick comparisons performed within already fetched L1 cache line.
- * - When there are more fields, we store them inside a hash map.
- */
-public class PortableSchema implements Externalizable {
-    /** */
-    private static final long serialVersionUID = 0L;
-
-    /** Order returned if field is not found. */
-    public static final int ORDER_NOT_FOUND = -1;
-
-    /** Minimum sensible size. */
-    private static final int MAP_MIN_SIZE = 32;
-
-    /** Empty cell. */
-    private static final int MAP_EMPTY = 0;
-
-    /** Schema ID. */
-    private int schemaId;
-
-    /** IDs depending on order. */
-    private int[] ids;
-
-    /** Interned names of associated fields. */
-    private String[] names;
-
-    /** ID-to-order data. */
-    private int[] idToOrderData;
-
-    /** ID-to-order mask. */
-    private int idToOrderMask;
-
-    /** ID 1. */
-    private int id0;
-
-    /** ID 2. */
-    private int id1;
-
-    /** ID 3. */
-    private int id2;
-
-    /** ID 4. */
-    private int id3;
-
-    /**
-     * {@link Externalizable} support.
-     */
-    public PortableSchema() {
-        // No-op.
-    }
-
-    /**
-     * Constructor.
-     *
-     * @param schemaId Schema ID.
-     * @param fieldIds Field IDs.
-     */
-    private PortableSchema(int schemaId, List<Integer> fieldIds) {
-        assert fieldIds != null;
-
-        this.schemaId = schemaId;
-
-        initialize(fieldIds);
-    }
-
-    /**
-     * @return Schema ID.
-     */
-    public int schemaId() {
-        return schemaId;
-    }
-
-    /**
-     * Try speculatively confirming order for the given field name.
-     *
-     * @param expOrder Expected order.
-     * @param expName Expected name.
-     * @return Field ID.
-     */
-    @SuppressWarnings("StringEquality")
-    public Confirmation confirmOrder(int expOrder, String expName) {
-        assert expName != null;
-
-        if (expOrder < names.length) {
-            String name = names[expOrder];
-
-            // Note that we use only reference equality assuming that field names are interned literals.
-            if (name == expName)
-                return Confirmation.CONFIRMED;
-
-            if (name == null)
-                return Confirmation.CLARIFY;
-        }
-
-        return Confirmation.REJECTED;
-    }
-
-    /**
-     * Add field name.
-     *
-     * @param order Order.
-     * @param name Name.
-     */
-    public void clarifyFieldName(int order, String name) {
-        assert name != null;
-        assert order < names.length;
-
-        names[order] = name.intern();
-    }
-
-    /**
-     * Get field ID by order in footer.
-     *
-     * @param order Order.
-     * @return Field ID.
-     */
-    public int fieldId(int order) {
-        return order < ids.length ? ids[order] : 0;
-    }
-
-    /**
-     * Get field order in footer by field ID.
-     *
-     * @param id Field ID.
-     * @return Offset or {@code 0} if there is no such field.
-     */
-    public int order(int id) {
-        if (idToOrderData == null) {
-            if (id == id0)
-                return 0;
-
-            if (id == id1)
-                return 1;
-
-            if (id == id2)
-                return 2;
-
-            if (id == id3)
-                return 3;
-
-            return ORDER_NOT_FOUND;
-        }
-        else {
-            int idx = (id & idToOrderMask) << 1;
-
-            int curId = idToOrderData[idx];
-
-            if (id == curId) // Hit!
-                return idToOrderData[idx + 1];
-            else if (curId == MAP_EMPTY) // No such ID!
-                return ORDER_NOT_FOUND;
-            else {
-                // Unlikely collision scenario.
-                for (int i = 2; i < idToOrderData.length; i += 2) {
-                    int newIdx = (idx + i) % idToOrderData.length;
-
-                    assert newIdx < idToOrderData.length - 1;
-
-                    curId = idToOrderData[newIdx];
-
-                    if (id == curId)
-                        return idToOrderData[newIdx + 1];
-                    else if (curId == MAP_EMPTY)
-                        return ORDER_NOT_FOUND;
-                }
-
-                return ORDER_NOT_FOUND;
-            }
-        }
-    }
-
-    /** {@inheritDoc} */
-    @Override public int hashCode() {
-        return schemaId;
-    }
-
-    /** {@inheritDoc} */
-    @Override public boolean equals(Object o) {
-        return o != null && o instanceof PortableSchema && schemaId == ((PortableSchema)o).schemaId;
-    }
-
-    /** {@inheritDoc} */
-    @Override public void writeExternal(ObjectOutput out) throws IOException {
-        out.writeInt(schemaId);
-
-        out.writeInt(ids.length);
-
-        for (Integer id : ids)
-            out.writeInt(id);
-    }
-
-    /** {@inheritDoc} */
-    @Override public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
-        schemaId = in.readInt();
-
-        int idsCnt = in.readInt();
-
-        List<Integer> fieldIds = new ArrayList<>(idsCnt);
-
-        for (int i = 0; i < idsCnt; i++)
-            fieldIds.add(in.readInt());
-
-        initialize(fieldIds);
-    }
-
-    /**
-     * Parse values.
-     *
-     * @param vals Values.
-     * @param size Proposed result size.
-     * @return Parse result.
-     */
-    private static ParseResult parse(int[] vals, int size) {
-        int mask = maskForPowerOfTwo(size);
-
-        int totalSize = size * 2;
-
-        int[] data = new int[totalSize];
-        int collisions = 0;
-
-        for (int order = 0; order < vals.length; order++) {
-            int id = vals[order];
-
-            assert id != 0;
-
-            int idIdx = (id & mask) << 1;
-
-            if (data[idIdx] == 0) {
-                // Found empty slot.
-                data[idIdx] = id;
-                data[idIdx + 1] = order;
-            }
-            else {
-                // Collision!
-                collisions++;
-
-                boolean placeFound = false;
-
-                for (int i = 2; i < totalSize; i += 2) {
-                    int newIdIdx = (idIdx + i) % totalSize;
-
-                    if (data[newIdIdx] == 0) {
-                        data[newIdIdx] = id;
-                        data[newIdIdx + 1] = order;
-
-                        placeFound = true;
-
-                        break;
-                    }
-                }
-
-                assert placeFound : "Should always have a place for entry!";
-            }
-        }
-
-        return new ParseResult(data, collisions);
-    }
-
-    /**
-     * Get next power of two which greater or equal to the given number.
-     * This implementation is not meant to be very efficient, so it is expected to be used relatively rare.
-     *
-     * @param val Number
-     * @return Nearest pow2.
-     */
-    private static int nextPowerOfTwo(int val) {
-        int res = 1;
-
-        while (res < val)
-            res = res << 1;
-
-        if (res < 0)
-            throw new IllegalArgumentException("Value is too big to find positive pow2: " + val);
-
-        return res;
-    }
-
-    /**
-     * Calculate mask for the given value which is a power of two.
-     *
-     * @param val Value.
-     * @return Mask.
-     */
-    private static int maskForPowerOfTwo(int val) {
-        int mask = 0;
-        int comparand = 1;
-
-        while (comparand < val) {
-            mask |= comparand;
-
-            comparand <<= 1;
-        }
-
-        return mask;
-    }
-
-    /**
-     * Initialization routine.
-     *
-     * @param fieldIds Field IDs.
-     */
-    private void initialize(List<Integer> fieldIds) {
-        ids = new int[fieldIds.size()];
-
-        for (int i = 0; i < fieldIds.size(); i++)
-            ids[i] = fieldIds.get(i);
-
-        names = new String[fieldIds.size()];
-
-        if (fieldIds.size() <= 4) {
-            Iterator<Integer> iter = fieldIds.iterator();
-
-            id0 = iter.hasNext() ? iter.next() : 0;
-            id1 = iter.hasNext() ? iter.next() : 0;
-            id2 = iter.hasNext() ? iter.next() : 0;
-            id3 = iter.hasNext() ? iter.next() : 0;
-        }
-        else {
-            id0 = id1 = id2 = id3 = 0;
-
-            initializeMap(ids);
-        }
-    }
-
-    /**
-     * Initialize the map.
-     *
-     * @param vals Values.
-     */
-    private void initializeMap(int[] vals) {
-        int size = Math.max(nextPowerOfTwo(vals.length) << 2, MAP_MIN_SIZE);
-
-        assert size > 0;
-
-        ParseResult finalRes;
-
-        ParseResult res1 = parse(vals, size);
-
-        if (res1.collisions == 0)
-            finalRes = res1;
-        else {
-            ParseResult res2 = parse(vals, size * 2);
-
-            // Failed to decrease aom
-            if (res2.collisions == 0)
-                finalRes = res2;
-            else
-                finalRes = parse(vals, size * 4);
-        }
-
-        idToOrderData = finalRes.data;
-        idToOrderMask = maskForPowerOfTwo(idToOrderData.length / 2);
-    }
-
-    /**
-     * Schema builder.
-     */
-    public static class Builder {
-        /** Schema ID. */
-        private int schemaId = PortableUtils.schemaInitialId();
-
-        /** Fields. */
-        private final ArrayList<Integer> fields = new ArrayList<>();
-
-        /**
-         * Create new schema builder.
-         *
-         * @return Schema builder.
-         */
-        public static Builder newBuilder() {
-            return new Builder();
-        }
-
-        /**
-         * Private constructor.
-         */
-        private Builder() {
-            // No-op.
-        }
-
-        /**
-         * Add field.
-         *
-         * @param fieldId Field ID.
-         */
-        public void addField(int fieldId) {
-            fields.add(fieldId);
-
-            schemaId = PortableUtils.updateSchemaId(schemaId, fieldId);
-        }
-
-        /**
-         * Build schema.
-         *
-         * @return Schema.
-         */
-        public PortableSchema build() {
-            return new PortableSchema(schemaId, fields);
-        }
-    }
-
-    /**
-     * Order confirmation result.
-     */
-    public enum Confirmation {
-        /** Confirmed. */
-        CONFIRMED,
-
-        /** Denied. */
-        REJECTED,
-
-        /** Field name clarification is needed. */
-        CLARIFY
-    }
-
-    /**
-     * Result of map parsing.
-     */
-    private static class ParseResult {
-        /** Data. */
-        private int[] data;
-
-        /** Collisions. */
-        private int collisions;
-
-        /**
-         * Constructor.
-         *
-         * @param data Data.
-         * @param collisions Collisions.
-         */
-        private ParseResult(int[] data, int collisions) {
-            this.data = data;
-            this.collisions = collisions;
-        }
-    }
-}

http://git-wip-us.apache.org/repos/asf/ignite/blob/71ad9cea/modules/core/src/main/java/org/apache/ignite/internal/binary/PortableSchemaRegistry.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/binary/PortableSchemaRegistry.java b/modules/core/src/main/java/org/apache/ignite/internal/binary/PortableSchemaRegistry.java
deleted file mode 100644
index f3f92ee..0000000
--- a/modules/core/src/main/java/org/apache/ignite/internal/binary/PortableSchemaRegistry.java
+++ /dev/null
@@ -1,172 +0,0 @@
-/*
- * 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.binary;
-
-import org.jetbrains.annotations.Nullable;
-
-import java.util.HashMap;
-
-/**
- * Portable schema registry. Contains all well-known object schemas.
- * <p>
- * We rely on the fact that usually object has only few different schemas. For this reason we inline several
- * of them with optional fallback to normal hash map lookup.
- *
- */
-public class PortableSchemaRegistry {
-    /** Empty schema ID. */
-    private static final int EMPTY = 0;
-
-    /** Whether registry still works in inline mode. */
-    private volatile boolean inline = true;
-
-    /** First schema ID. */
-    private int schemaId1;
-
-    /** Second schema ID. */
-    private int schemaId2;
-
-    /** Third schema ID. */
-    private int schemaId3;
-
-    /** Fourth schema ID. */
-    private int schemaId4;
-
-    /** First schema. */
-    private PortableSchema schema1;
-
-    /** Second schema. */
-    private PortableSchema schema2;
-
-    /** Third schema. */
-    private PortableSchema schema3;
-
-    /** Fourth schema. */
-    private PortableSchema schema4;
-
-    /** Schemas with COW semantics. */
-    private volatile HashMap<Integer, PortableSchema> schemas;
-
-    /**
-     * Get schema for the given ID. We rely on very relaxed memory semantics here assuming that it is not critical
-     * to return false-positive {@code null} values.
-     *
-     * @param schemaId Schema ID.
-     * @return Schema or {@code null}.
-     */
-    @Nullable public PortableSchema schema(int schemaId) {
-        if (inline) {
-            if (schemaId == schemaId1)
-                return schema1;
-            else if (schemaId == schemaId2)
-                return schema2;
-            else if (schemaId == schemaId3)
-                return schema3;
-            else if (schemaId == schemaId4)
-                return schema4;
-        }
-        else {
-            HashMap<Integer, PortableSchema> schemas0 = schemas;
-
-            // Null can be observed here due to either data race or race condition when switching to non-inlined mode.
-            // Both of them are benign for us because they lead only to unnecessary schema re-calc.
-            if (schemas0 != null)
-                return schemas0.get(schemaId);
-        }
-
-        return null;
-    }
-
-    /**
-     * Add schema.
-     *
-     * @param schemaId Schema ID.
-     * @param schema Schema.
-     */
-    public void addSchema(int schemaId, PortableSchema schema) {
-        synchronized (this) {
-            if (inline) {
-                // Check if this is already known schema.
-                if (schemaId == schemaId1 || schemaId == schemaId2 || schemaId == schemaId3 || schemaId == schemaId4)
-                    return;
-
-                // Try positioning new schema in inline mode.
-                if (schemaId1 == EMPTY) {
-                    schemaId1 = schemaId;
-
-                    schema1 = schema;
-
-                    inline = true; // Forcing HB edge just in case.
-
-                    return;
-                }
-
-                if (schemaId2 == EMPTY) {
-                    schemaId2 = schemaId;
-
-                    schema2 = schema;
-
-                    inline = true; // Forcing HB edge just in case.
-
-                    return;
-                }
-
-                if (schemaId3 == EMPTY) {
-                    schemaId3 = schemaId;
-
-                    schema3 = schema;
-
-                    inline = true; // Forcing HB edge just in case.
-
-                    return;
-                }
-
-                if (schemaId4 == EMPTY) {
-                    schemaId4 = schemaId;
-
-                    schema4 = schema;
-
-                    inline = true; // Forcing HB edge just in case.
-
-                    return;
-                }
-
-                // No luck, switching to hash map mode.
-                HashMap<Integer, PortableSchema> newSchemas = new HashMap<>();
-
-                newSchemas.put(schemaId1, schema1);
-                newSchemas.put(schemaId2, schema2);
-                newSchemas.put(schemaId3, schema3);
-                newSchemas.put(schemaId4, schema4);
-
-                newSchemas.put(schemaId, schema);
-
-                schemas = newSchemas;
-
-                inline = false;
-            }
-            else {
-                HashMap<Integer, PortableSchema> newSchemas = new HashMap<>(schemas);
-
-                newSchemas.put(schemaId, schema);
-
-                schemas = newSchemas;
-            }
-        }
-    }
-}


[31/59] [abbrv] ignite git commit: ignite-2065: rename "portable" packages to "binary"

Posted by ak...@apache.org.
ignite-2065: rename "portable" packages to "binary"


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

Branch: refs/heads/ignite-843-rc2
Commit: 1dbf20e0e13f8af83e6ff0a4299f0e1ac335c8de
Parents: 9d478ae
Author: ashutak <as...@gridgain.com>
Authored: Fri Dec 11 12:35:04 2015 +0300
Committer: ashutak <as...@gridgain.com>
Committed: Fri Dec 11 12:35:05 2015 +0300

----------------------------------------------------------------------
 modules/core/pom.xml                            |    4 +-
 .../java/org/apache/ignite/IgniteBinary.java    |    2 +-
 .../java/org/apache/ignite/IgniteCache.java     |    2 +-
 .../store/jdbc/CacheAbstractJdbcStore.java      |    2 +-
 .../cache/store/jdbc/CacheJdbcPojoStore.java    |    2 +-
 .../ignite/internal/GridKernalContextImpl.java  |    2 +-
 .../apache/ignite/internal/IgniteKernal.java    |    6 +-
 .../org/apache/ignite/internal/IgnitionEx.java  |    2 +-
 .../binary/BinaryCachingMetadataHandler.java    |   70 +
 .../ignite/internal/binary/BinaryEnumCache.java |   69 +
 .../internal/binary/BinaryEnumObjectImpl.java   |  311 ++
 .../internal/binary/BinaryFieldAccessor.java    |  856 ++++
 .../ignite/internal/binary/BinaryFieldImpl.java |  116 +
 .../internal/binary/BinaryInternalIdMapper.java |  161 +
 .../internal/binary/BinaryMarshaller.java       |  142 +
 .../ignite/internal/binary/BinaryMetadata.java  |  180 +
 .../binary/BinaryMetadataCollector.java         |  277 ++
 .../internal/binary/BinaryMetadataHandler.java  |   44 +
 .../binary/BinaryNoopMetadataHandler.java       |   53 +
 .../ignite/internal/binary/BinaryObjectEx.java  |   30 +
 .../internal/binary/BinaryObjectExImpl.java     |  251 ++
 .../internal/binary/BinaryObjectImpl.java       |  570 +++
 .../binary/BinaryObjectOffheapImpl.java         |  430 ++
 .../internal/binary/BinaryRawReaderEx.java      |   33 +
 .../internal/binary/BinaryRawWriterEx.java      |   60 +
 .../internal/binary/BinaryReaderExImpl.java     | 2028 +++++++++
 .../internal/binary/BinaryReaderHandles.java    |  108 +
 .../binary/BinaryReaderHandlesHolder.java       |   46 +
 .../binary/BinaryReaderHandlesHolderImpl.java   |   44 +
 .../binary/BinaryThreadLocalContext.java        |   70 +
 .../ignite/internal/binary/BinaryTypeImpl.java  |   93 +
 .../ignite/internal/binary/BinaryWriteMode.java |  178 +
 .../internal/binary/BinaryWriterExImpl.java     | 1808 ++++++++
 .../internal/binary/BinaryWriterHandles.java    |  101 +
 .../binary/BinaryWriterSchemaHolder.java        |  149 +
 .../internal/binary/GridPortableMarshaller.java |  289 ++
 .../binary/PortableClassDescriptor.java         |  813 ++++
 .../ignite/internal/binary/PortableContext.java | 1102 +++++
 .../binary/PortablePositionReadable.java        |   47 +
 .../internal/binary/PortablePrimitives.java     |  382 ++
 .../ignite/internal/binary/PortableSchema.java  |  466 ++
 .../internal/binary/PortableSchemaRegistry.java |  172 +
 .../ignite/internal/binary/PortableUtils.java   | 1909 ++++++++
 .../binary/builder/BinaryObjectBuilderImpl.java |  587 +++
 .../builder/PortableAbstractLazyValue.java      |   57 +
 .../binary/builder/PortableBuilderEnum.java     |  116 +
 .../binary/builder/PortableBuilderReader.java   |  856 ++++
 .../PortableBuilderSerializationAware.java      |   31 +
 .../builder/PortableBuilderSerializer.java      |  217 +
 .../builder/PortableEnumArrayLazyValue.java     |  116 +
 .../binary/builder/PortableLazyArrayList.java   |  167 +
 .../binary/builder/PortableLazyLinkedList.java  |  218 +
 .../binary/builder/PortableLazyMap.java         |  221 +
 .../binary/builder/PortableLazySet.java         |   94 +
 .../binary/builder/PortableLazyValue.java       |   28 +
 .../builder/PortableModifiableLazyValue.java    |   52 +
 .../builder/PortableObjectArrayLazyValue.java   |   91 +
 .../binary/builder/PortablePlainLazyValue.java  |   49 +
 .../builder/PortablePlainPortableObject.java    |   56 +
 .../binary/builder/PortableValueWithType.java   |   77 +
 .../internal/binary/builder/package-info.java   |   22 +
 .../ignite/internal/binary/package-info.java    |   22 +
 .../streams/PortableAbstractInputStream.java    |  379 ++
 .../streams/PortableAbstractOutputStream.java   |  347 ++
 .../binary/streams/PortableAbstractStream.java  |   80 +
 .../binary/streams/PortableHeapInputStream.java |  166 +
 .../streams/PortableHeapOutputStream.java       |  176 +
 .../binary/streams/PortableInputStream.java     |  163 +
 .../binary/streams/PortableMemoryAllocator.java |   57 +
 .../streams/PortableMemoryAllocatorChunk.java   |  117 +
 .../streams/PortableOffheapInputStream.java     |  144 +
 .../streams/PortableOffheapOutputStream.java    |  222 +
 .../binary/streams/PortableOutputStream.java    |  259 ++
 .../internal/binary/streams/PortableStream.java |   53 +
 .../internal/binary/streams/package-info.java   |   22 +
 .../communication/GridIoMessageFactory.java     |    4 +-
 .../portable/BinaryCachingMetadataHandler.java  |   70 -
 .../internal/portable/BinaryEnumCache.java      |   69 -
 .../internal/portable/BinaryEnumObjectImpl.java |  311 --
 .../internal/portable/BinaryFieldAccessor.java  |  856 ----
 .../internal/portable/BinaryFieldImpl.java      |  116 -
 .../portable/BinaryInternalIdMapper.java        |  161 -
 .../internal/portable/BinaryMarshaller.java     |  142 -
 .../internal/portable/BinaryMetadata.java       |  180 -
 .../portable/BinaryMetadataCollector.java       |  277 --
 .../portable/BinaryMetadataHandler.java         |   44 -
 .../portable/BinaryNoopMetadataHandler.java     |   53 -
 .../internal/portable/BinaryObjectEx.java       |   30 -
 .../internal/portable/BinaryObjectExImpl.java   |  251 --
 .../internal/portable/BinaryObjectImpl.java     |  584 ---
 .../portable/BinaryObjectOffheapImpl.java       |  429 --
 .../internal/portable/BinaryRawReaderEx.java    |   33 -
 .../internal/portable/BinaryRawWriterEx.java    |   60 -
 .../internal/portable/BinaryReaderExImpl.java   | 2028 ---------
 .../internal/portable/BinaryReaderHandles.java  |  108 -
 .../portable/BinaryReaderHandlesHolder.java     |   46 -
 .../portable/BinaryReaderHandlesHolderImpl.java |   44 -
 .../portable/BinaryThreadLocalContext.java      |   69 -
 .../internal/portable/BinaryTypeImpl.java       |   93 -
 .../internal/portable/BinaryWriteMode.java      |  178 -
 .../internal/portable/BinaryWriterExImpl.java   | 1807 --------
 .../internal/portable/BinaryWriterHandles.java  |  101 -
 .../portable/BinaryWriterSchemaHolder.java      |  148 -
 .../portable/GridPortableMarshaller.java        |  286 --
 .../portable/PortableClassDescriptor.java       |  813 ----
 .../internal/portable/PortableContext.java      | 1102 -----
 .../portable/PortablePositionReadable.java      |   47 -
 .../internal/portable/PortablePrimitives.java   |  382 --
 .../internal/portable/PortableSchema.java       |  466 --
 .../portable/PortableSchemaRegistry.java        |  172 -
 .../ignite/internal/portable/PortableUtils.java | 1907 --------
 .../builder/BinaryObjectBuilderImpl.java        |  580 ---
 .../builder/PortableAbstractLazyValue.java      |   57 -
 .../portable/builder/PortableBuilderEnum.java   |  116 -
 .../portable/builder/PortableBuilderReader.java |  847 ----
 .../PortableBuilderSerializationAware.java      |   31 -
 .../builder/PortableBuilderSerializer.java      |  217 -
 .../builder/PortableEnumArrayLazyValue.java     |  114 -
 .../portable/builder/PortableLazyArrayList.java |  166 -
 .../builder/PortableLazyLinkedList.java         |  217 -
 .../portable/builder/PortableLazyMap.java       |  220 -
 .../portable/builder/PortableLazySet.java       |   92 -
 .../portable/builder/PortableLazyValue.java     |   28 -
 .../builder/PortableModifiableLazyValue.java    |   52 -
 .../builder/PortableObjectArrayLazyValue.java   |   91 -
 .../builder/PortablePlainLazyValue.java         |   49 -
 .../builder/PortablePlainPortableObject.java    |   53 -
 .../portable/builder/PortableValueWithType.java |   76 -
 .../internal/portable/builder/package-info.java |   22 -
 .../ignite/internal/portable/package-info.java  |   22 -
 .../streams/PortableAbstractInputStream.java    |  379 --
 .../streams/PortableAbstractOutputStream.java   |  347 --
 .../streams/PortableAbstractStream.java         |   80 -
 .../streams/PortableHeapInputStream.java        |  166 -
 .../streams/PortableHeapOutputStream.java       |  176 -
 .../portable/streams/PortableInputStream.java   |  162 -
 .../streams/PortableMemoryAllocator.java        |   57 -
 .../streams/PortableMemoryAllocatorChunk.java   |  117 -
 .../streams/PortableOffheapInputStream.java     |  144 -
 .../streams/PortableOffheapOutputStream.java    |  222 -
 .../portable/streams/PortableOutputStream.java  |  259 --
 .../portable/streams/PortableStream.java        |   53 -
 .../internal/portable/streams/package-info.java |   22 -
 .../CacheDefaultBinaryAffinityKeyMapper.java    |    4 +-
 .../processors/cache/CacheObjectContext.java    |    2 +-
 .../processors/cache/GridCacheContext.java      |    2 +-
 .../processors/cache/GridCacheProcessor.java    |    2 +-
 .../CacheDefaultPortableAffinityKeyMapper.java  |   51 +
 .../binary/CacheObjectBinaryProcessor.java      |  106 +
 .../binary/CacheObjectBinaryProcessorImpl.java  |  895 ++++
 .../binary/CacheObjectPortableContext.java      |   56 +
 .../cache/binary/IgniteBinaryImpl.java          |  178 +
 .../cache/binary/PortableMetadataKey.java       |   82 +
 .../processors/cache/binary/package-info.java   |   22 +
 .../CacheDefaultPortableAffinityKeyMapper.java  |   51 -
 .../portable/CacheObjectBinaryProcessor.java    |  106 -
 .../CacheObjectBinaryProcessorImpl.java         |  895 ----
 .../portable/CacheObjectPortableContext.java    |   56 -
 .../cache/portable/IgniteBinaryImpl.java        |  178 -
 .../cache/portable/PortableMetadataKey.java     |   82 -
 .../processors/cache/portable/package-info.java |   22 -
 .../cache/store/CacheOsStoreManager.java        |    4 +-
 .../platform/PlatformAbstractTarget.java        |    6 +-
 .../processors/platform/PlatformContext.java    |    6 +-
 .../platform/PlatformContextImpl.java           |   12 +-
 .../platform/PlatformExtendedException.java     |    4 +-
 .../platform/PlatformProcessorImpl.java         |    4 +-
 .../platform/cache/PlatformCache.java           |    6 +-
 .../cache/PlatformCacheEntryFilterImpl.java     |    4 +-
 .../cache/PlatformCacheEntryProcessorImpl.java  |    6 +-
 .../platform/cache/PlatformCacheIterator.java   |    4 +-
 .../PlatformCachePartialUpdateException.java    |    4 +-
 .../cache/affinity/PlatformAffinity.java        |    6 +-
 .../query/PlatformAbstractQueryCursor.java      |    4 +-
 .../PlatformContinuousQueryRemoteFilter.java    |    4 +-
 .../cache/query/PlatformFieldsQueryCursor.java  |    4 +-
 .../cache/query/PlatformQueryCursor.java        |    4 +-
 .../cache/store/PlatformCacheStoreCallback.java |    4 +-
 .../platform/cluster/PlatformClusterGroup.java  |    6 +-
 .../cluster/PlatformClusterNodeFilterImpl.java  |    4 +-
 .../platform/compute/PlatformAbstractJob.java   |    4 +-
 .../platform/compute/PlatformAbstractTask.java  |    4 +-
 .../platform/compute/PlatformClosureJob.java    |    4 +-
 .../platform/compute/PlatformCompute.java       |    8 +-
 .../platform/compute/PlatformFullJob.java       |    4 +-
 .../platform/compute/PlatformFullTask.java      |    6 +-
 .../cpp/PlatformCppConfigurationClosure.java    |    4 +-
 .../datastreamer/PlatformDataStreamer.java      |    5 +-
 .../PlatformStreamReceiverImpl.java             |    4 +-
 .../dotnet/PlatformDotNetCacheStore.java        |    6 +-
 .../PlatformDotNetConfigurationClosure.java     |   12 +-
 .../events/PlatformEventFilterListenerImpl.java |    4 +-
 .../platform/events/PlatformEvents.java         |    4 +-
 .../platform/memory/PlatformInputStream.java    |    4 +-
 .../platform/memory/PlatformOutputStream.java   |    4 +-
 .../messaging/PlatformMessageFilterImpl.java    |    4 +-
 .../messaging/PlatformMessageLocalFilter.java   |    2 +-
 .../platform/messaging/PlatformMessaging.java   |    6 +-
 .../services/PlatformAbstractService.java       |    6 +-
 .../platform/services/PlatformServices.java     |    6 +-
 .../transactions/PlatformTransactions.java      |    4 +-
 .../platform/utils/PlatformFutureUtils.java     |    4 +-
 .../platform/utils/PlatformReaderBiClosure.java |    4 +-
 .../platform/utils/PlatformReaderClosure.java   |    4 +-
 .../platform/utils/PlatformUtils.java           |    6 +-
 .../platform/utils/PlatformWriterBiClosure.java |    4 +-
 .../platform/utils/PlatformWriterClosure.java   |    4 +-
 .../sharedfs/SharedFsCheckpointSpi.java         |    4 +-
 .../resources/META-INF/classnames.properties    |   36 +-
 ...heJdbcPojoStoreBinaryMarshallerSelfTest.java |    2 +-
 .../internal/binary/BinaryEnumsSelfTest.java    |  446 ++
 .../binary/BinaryFieldsAbstractSelfTest.java    |  718 +++
 .../binary/BinaryFieldsHeapSelfTest.java        |   30 +
 .../binary/BinaryFieldsOffheapSelfTest.java     |   60 +
 .../BinaryFooterOffsetsAbstractSelfTest.java    |  205 +
 .../binary/BinaryFooterOffsetsHeapSelfTest.java |   30 +
 .../BinaryFooterOffsetsOffheapSelfTest.java     |   60 +
 .../binary/BinaryMarshallerSelfTest.java        | 4209 +++++++++++++++++
 .../BinaryObjectBuilderAdditionalSelfTest.java  | 1264 ++++++
 .../binary/BinaryObjectBuilderSelfTest.java     | 1100 +++++
 .../binary/GridPortableAffinityKeySelfTest.java |  234 +
 ...idPortableMarshallerCtxDisabledSelfTest.java |  247 +
 .../binary/GridPortableMetaDataSelfTest.java    |  371 ++
 .../binary/GridPortableWildcardsSelfTest.java   |  464 ++
 .../binary/TestCachingMetadataHandler.java      |   45 +
 .../GridBinaryMarshalerAwareTestClass.java      |   67 +
 .../mutabletest/GridPortableTestClasses.java    |  484 ++
 .../binary/mutabletest/package-info.java        |   22 +
 .../BinaryFieldsHeapNonCompactSelfTest.java     |   30 +
 .../BinaryFieldsOffheapNonCompactSelfTest.java  |   30 +
 ...naryFooterOffsetsHeapNonCompactSelfTest.java |   30 +
 ...yFooterOffsetsOffheapNonCompactSelfTest.java |   30 +
 .../BinaryMarshallerNonCompactSelfTest.java     |   30 +
 ...jectBuilderAdditionalNonCompactSelfTest.java |   30 +
 .../BinaryObjectBuilderNonCompactSelfTest.java  |   30 +
 .../ignite/internal/binary/package-info.java    |   22 +
 .../binary/test/GridPortableTestClass1.java     |   28 +
 .../binary/test/GridPortableTestClass2.java     |   24 +
 .../internal/binary/test/package-info.java      |   22 +
 .../test/subpackage/GridPortableTestClass3.java |   24 +
 .../binary/test/subpackage/package-info.java    |   22 +
 .../internal/portable/BinaryEnumsSelfTest.java  |  446 --
 .../portable/BinaryFieldsAbstractSelfTest.java  |  718 ---
 .../portable/BinaryFieldsHeapSelfTest.java      |   30 -
 .../portable/BinaryFieldsOffheapSelfTest.java   |   60 -
 .../BinaryFooterOffsetsAbstractSelfTest.java    |  205 -
 .../BinaryFooterOffsetsHeapSelfTest.java        |   30 -
 .../BinaryFooterOffsetsOffheapSelfTest.java     |   60 -
 .../portable/BinaryMarshallerSelfTest.java      | 4210 ------------------
 .../BinaryObjectBuilderAdditionalSelfTest.java  | 1272 ------
 .../portable/BinaryObjectBuilderSelfTest.java   | 1103 -----
 .../GridPortableAffinityKeySelfTest.java        |  234 -
 ...idPortableMarshallerCtxDisabledSelfTest.java |  247 -
 .../portable/GridPortableMetaDataSelfTest.java  |  371 --
 .../portable/GridPortableWildcardsSelfTest.java |  464 --
 .../portable/TestCachingMetadataHandler.java    |   45 -
 .../GridBinaryMarshalerAwareTestClass.java      |   67 -
 .../mutabletest/GridPortableTestClasses.java    |  484 --
 .../portable/mutabletest/package-info.java      |   22 -
 .../BinaryFieldsHeapNonCompactSelfTest.java     |   30 -
 .../BinaryFieldsOffheapNonCompactSelfTest.java  |   30 -
 ...naryFooterOffsetsHeapNonCompactSelfTest.java |   30 -
 ...yFooterOffsetsOffheapNonCompactSelfTest.java |   30 -
 .../BinaryMarshallerNonCompactSelfTest.java     |   30 -
 ...jectBuilderAdditionalNonCompactSelfTest.java |   30 -
 .../BinaryObjectBuilderNonCompactSelfTest.java  |   30 -
 .../ignite/internal/portable/package-info.java  |   22 -
 .../portable/test/GridPortableTestClass1.java   |   28 -
 .../portable/test/GridPortableTestClass2.java   |   24 -
 .../internal/portable/test/package-info.java    |   22 -
 .../test/subpackage/GridPortableTestClass3.java |   24 -
 .../portable/test/subpackage/package-info.java  |   22 -
 .../GridCacheConditionalDeploymentSelfTest.java |    2 +-
 .../cache/GridCacheDeploymentSelfTest.java      |    2 +-
 .../IgniteCacheStoreValueAbstractTest.java      |    6 +-
 ...yAtomicEntryProcessorDeploymentSelfTest.java |  129 +
 ...naryObjectsAbstractDataStreamerSelfTest.java |  192 +
 ...aryObjectsAbstractMultiThreadedSelfTest.java |  241 +
 .../GridCacheBinaryObjectsAbstractSelfTest.java |  981 ++++
 ...ctionalEntryProcessorDeploymentSelfTest.java |   31 +
 ...ntNodeBinaryObjectMetadataMultinodeTest.java |  295 ++
 ...CacheClientNodeBinaryObjectMetadataTest.java |  221 +
 .../GridCachePortableStoreAbstractSelfTest.java |  300 ++
 .../GridCachePortableStoreObjectsSelfTest.java  |   55 +
 ...GridCachePortableStorePortablesSelfTest.java |   66 +
 ...ridPortableCacheEntryMemorySizeSelfTest.java |   48 +
 ...leDuplicateIndexObjectsAbstractSelfTest.java |  161 +
 .../DataStreamProcessorPortableSelfTest.java    |   71 +
 .../GridDataStreamerImplSelfTest.java           |  345 ++
 ...ridCacheAffinityRoutingPortableSelfTest.java |   54 +
 ...lyPortableDataStreamerMultiNodeSelfTest.java |   29 +
 ...rtableDataStreamerMultithreadedSelfTest.java |   47 +
 ...artitionedOnlyPortableMultiNodeSelfTest.java |   28 +
 ...tionedOnlyPortableMultithreadedSelfTest.java |   47 +
 ...AtomicNearDisabledOffheapTieredSelfTest.java |   29 +
 ...BinaryObjectsAtomicNearDisabledSelfTest.java |   51 +
 ...inaryObjectsAtomicOffheapTieredSelfTest.java |   29 +
 .../GridCacheBinaryObjectsAtomicSelfTest.java   |   51 +
 ...tionedNearDisabledOffheapTieredSelfTest.java |   30 +
 ...yObjectsPartitionedNearDisabledSelfTest.java |   51 +
 ...ObjectsPartitionedOffheapTieredSelfTest.java |   30 +
 ...idCacheBinaryObjectsPartitionedSelfTest.java |   51 +
 .../GridCacheMemoryModePortableSelfTest.java    |   36 +
 ...acheOffHeapTieredAtomicPortableSelfTest.java |   48 +
 ...eapTieredEvictionAtomicPortableSelfTest.java |   96 +
 ...heOffHeapTieredEvictionPortableSelfTest.java |   96 +
 .../GridCacheOffHeapTieredPortableSelfTest.java |   48 +
 ...ateIndexObjectPartitionedAtomicSelfTest.java |   38 +
 ...xObjectPartitionedTransactionalSelfTest.java |   41 +
 ...sNearPartitionedByteArrayValuesSelfTest.java |   41 +
 ...sPartitionedOnlyByteArrayValuesSelfTest.java |   42 +
 ...ridCacheBinaryObjectsReplicatedSelfTest.java |   51 +
 ...idCacheBinaryObjectsAtomicLocalSelfTest.java |   32 +
 ...BinaryObjectsLocalOffheapTieredSelfTest.java |   29 +
 .../GridCacheBinaryObjectsLocalSelfTest.java    |   51 +
 ...IgniteCacheAbstractExecutionContextTest.java |    4 +-
 ...eRebalancingUnmarshallingFailedSelfTest.java |    2 +-
 ...idCacheReplicatedUnswapAdvancedSelfTest.java |    4 +-
 .../GridCacheReplicatedPreloadSelfTest.java     |    2 +-
 ...yAtomicEntryProcessorDeploymentSelfTest.java |  129 -
 ...naryObjectsAbstractDataStreamerSelfTest.java |  192 -
 ...aryObjectsAbstractMultiThreadedSelfTest.java |  241 -
 .../GridCacheBinaryObjectsAbstractSelfTest.java |  981 ----
 ...ctionalEntryProcessorDeploymentSelfTest.java |   31 -
 ...ntNodeBinaryObjectMetadataMultinodeTest.java |  295 --
 ...CacheClientNodeBinaryObjectMetadataTest.java |  221 -
 .../GridCachePortableStoreAbstractSelfTest.java |  300 --
 .../GridCachePortableStoreObjectsSelfTest.java  |   55 -
 ...GridCachePortableStorePortablesSelfTest.java |   66 -
 ...ridPortableCacheEntryMemorySizeSelfTest.java |   48 -
 ...leDuplicateIndexObjectsAbstractSelfTest.java |  161 -
 .../DataStreamProcessorPortableSelfTest.java    |   71 -
 .../GridDataStreamerImplSelfTest.java           |  345 --
 ...ridCacheAffinityRoutingPortableSelfTest.java |   54 -
 ...lyPortableDataStreamerMultiNodeSelfTest.java |   29 -
 ...rtableDataStreamerMultithreadedSelfTest.java |   47 -
 ...artitionedOnlyPortableMultiNodeSelfTest.java |   28 -
 ...tionedOnlyPortableMultithreadedSelfTest.java |   47 -
 ...AtomicNearDisabledOffheapTieredSelfTest.java |   29 -
 ...BinaryObjectsAtomicNearDisabledSelfTest.java |   51 -
 ...inaryObjectsAtomicOffheapTieredSelfTest.java |   29 -
 .../GridCacheBinaryObjectsAtomicSelfTest.java   |   51 -
 ...tionedNearDisabledOffheapTieredSelfTest.java |   30 -
 ...yObjectsPartitionedNearDisabledSelfTest.java |   51 -
 ...ObjectsPartitionedOffheapTieredSelfTest.java |   30 -
 ...idCacheBinaryObjectsPartitionedSelfTest.java |   51 -
 .../GridCacheMemoryModePortableSelfTest.java    |   36 -
 ...acheOffHeapTieredAtomicPortableSelfTest.java |   48 -
 ...eapTieredEvictionAtomicPortableSelfTest.java |   96 -
 ...heOffHeapTieredEvictionPortableSelfTest.java |   96 -
 .../GridCacheOffHeapTieredPortableSelfTest.java |   48 -
 ...ateIndexObjectPartitionedAtomicSelfTest.java |   38 -
 ...xObjectPartitionedTransactionalSelfTest.java |   41 -
 ...sNearPartitionedByteArrayValuesSelfTest.java |   41 -
 ...sPartitionedOnlyByteArrayValuesSelfTest.java |   42 -
 ...ridCacheBinaryObjectsReplicatedSelfTest.java |   51 -
 ...idCacheBinaryObjectsAtomicLocalSelfTest.java |   32 -
 ...BinaryObjectsLocalOffheapTieredSelfTest.java |   29 -
 .../GridCacheBinaryObjectsLocalSelfTest.java    |   51 -
 .../PlatformComputeBinarizableArgTask.java      |    4 +-
 .../platform/PlatformEventsWriteEventTask.java  |    4 +-
 .../session/GridSessionCheckpointSelfTest.java  |    8 +-
 .../testframework/junits/GridAbstractTest.java  |    4 +-
 .../ignite/testframework/junits/IgniteMock.java |    6 +-
 .../junits/IgniteTestResources.java             |    8 +-
 ...ObjectsCacheDataStructuresSelfTestSuite.java |    2 +-
 ...BinaryObjectsCacheExpiryPolicyTestSuite.java |    2 +-
 ...gniteBinaryObjectsCacheRestartTestSuite.java |    2 +-
 .../IgniteBinaryObjectsCacheTestSuite2.java     |    2 +-
 .../IgniteBinaryObjectsCacheTestSuite3.java     |    6 +-
 .../IgniteBinaryObjectsCacheTestSuite4.java     |    2 +-
 ...IgniteBinaryObjectsComputeGridTestSuite.java |    2 +-
 .../IgnitePortableCacheFullApiTestSuite.java    |    4 +-
 .../IgnitePortableCacheTestSuite.java           |   34 +-
 .../IgnitePortableObjectsTestSuite.java         |   70 +-
 .../ignite/portable/test1/1.1/test1-1.1.pom     |    2 +-
 .../portable/test1/maven-metadata-local.xml     |    2 +-
 .../ignite/portable/test2/1.1/test2-1.1.pom     |    2 +-
 .../portable/test2/maven-metadata-local.xml     |    2 +-
 .../IgnitePortableCacheQueryTestSuite.java      |    8 +-
 .../Config/marshaller-explicit.xml              |    2 +-
 .../ignite-int-max-values-offheap-config.xml    |    2 +-
 .../ignite-int-max-values-onheap-config.xml     |    2 +-
 .../ignite-int-max-values-swap-config.xml       |    2 +-
 384 files changed, 35085 insertions(+), 35075 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/1dbf20e0/modules/core/pom.xml
----------------------------------------------------------------------
diff --git a/modules/core/pom.xml b/modules/core/pom.xml
index c3d34ef..e4e975e 100644
--- a/modules/core/pom.xml
+++ b/modules/core/pom.xml
@@ -194,14 +194,14 @@
         </dependency>
 
         <dependency>
-            <groupId>org.apache.ignite.portable</groupId>
+            <groupId>org.apache.ignite.binary</groupId>
             <artifactId>test1</artifactId>
             <version>1.1</version>
             <scope>test</scope>
         </dependency>
 
         <dependency>
-            <groupId>org.apache.ignite.portable</groupId>
+            <groupId>org.apache.ignite.binary</groupId>
             <artifactId>test2</artifactId>
             <version>1.1</version>
             <scope>test</scope>

http://git-wip-us.apache.org/repos/asf/ignite/blob/1dbf20e0/modules/core/src/main/java/org/apache/ignite/IgniteBinary.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/IgniteBinary.java b/modules/core/src/main/java/org/apache/ignite/IgniteBinary.java
index a1c656b..2f68e7a 100644
--- a/modules/core/src/main/java/org/apache/ignite/IgniteBinary.java
+++ b/modules/core/src/main/java/org/apache/ignite/IgniteBinary.java
@@ -198,7 +198,7 @@ import org.jetbrains.annotations.Nullable;
  *         ...
  *         &lt;property name="typeConfigurations"&gt;
  *             &lt;list&gt;
- *                 &lt;bean class="org.apache.ignite.portable.PortableTypeConfiguration"&gt;
+ *                 &lt;bean class="org.apache.ignite.binary.PortableTypeConfiguration"&gt;
  *                     &lt;property name="className" value="org.apache.ignite.examples.client.portable.EmployeeKey"/&gt;
  *                     &lt;property name="affinityKeyFieldName" value="organizationId"/&gt;
  *                 &lt;/bean&gt;

http://git-wip-us.apache.org/repos/asf/ignite/blob/1dbf20e0/modules/core/src/main/java/org/apache/ignite/IgniteCache.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/IgniteCache.java b/modules/core/src/main/java/org/apache/ignite/IgniteCache.java
index 3903d02..3376abc 100644
--- a/modules/core/src/main/java/org/apache/ignite/IgniteCache.java
+++ b/modules/core/src/main/java/org/apache/ignite/IgniteCache.java
@@ -138,7 +138,7 @@ public interface IgniteCache<K, V> extends javax.cache.Cache<K, V>, IgniteAsyncS
      * so keys and values will be returned from cache API methods without changes. Therefore,
      * signature of the cache can contain only following types:
      * <ul>
-     *     <li><code>org.apache.ignite.portable.PortableObject</code> for portable classes</li>
+     *     <li><code>org.apache.ignite.binary.PortableObject</code> for portable classes</li>
      *     <li>All primitives (byte, int, ...) and there boxed versions (Byte, Integer, ...)</li>
      *     <li>Arrays of primitives (byte[], int[], ...)</li>
      *     <li>{@link String} and array of {@link String}s</li>

http://git-wip-us.apache.org/repos/asf/ignite/blob/1dbf20e0/modules/core/src/main/java/org/apache/ignite/cache/store/jdbc/CacheAbstractJdbcStore.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/cache/store/jdbc/CacheAbstractJdbcStore.java b/modules/core/src/main/java/org/apache/ignite/cache/store/jdbc/CacheAbstractJdbcStore.java
index 060ab89..07e9c9b 100644
--- a/modules/core/src/main/java/org/apache/ignite/cache/store/jdbc/CacheAbstractJdbcStore.java
+++ b/modules/core/src/main/java/org/apache/ignite/cache/store/jdbc/CacheAbstractJdbcStore.java
@@ -62,7 +62,7 @@ import org.apache.ignite.cache.store.jdbc.dialect.MySQLDialect;
 import org.apache.ignite.cache.store.jdbc.dialect.OracleDialect;
 import org.apache.ignite.cache.store.jdbc.dialect.SQLServerDialect;
 import org.apache.ignite.configuration.CacheConfiguration;
-import org.apache.ignite.internal.portable.BinaryMarshaller;
+import org.apache.ignite.internal.binary.BinaryMarshaller;
 import org.apache.ignite.internal.util.tostring.GridToStringExclude;
 import org.apache.ignite.internal.util.typedef.C1;
 import org.apache.ignite.internal.util.typedef.F;

http://git-wip-us.apache.org/repos/asf/ignite/blob/1dbf20e0/modules/core/src/main/java/org/apache/ignite/cache/store/jdbc/CacheJdbcPojoStore.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/cache/store/jdbc/CacheJdbcPojoStore.java b/modules/core/src/main/java/org/apache/ignite/cache/store/jdbc/CacheJdbcPojoStore.java
index a25df04..200aa0f 100644
--- a/modules/core/src/main/java/org/apache/ignite/cache/store/jdbc/CacheJdbcPojoStore.java
+++ b/modules/core/src/main/java/org/apache/ignite/cache/store/jdbc/CacheJdbcPojoStore.java
@@ -34,7 +34,7 @@ import org.apache.ignite.binary.BinaryObject;
 import org.apache.ignite.binary.BinaryObjectBuilder;
 import org.apache.ignite.cache.store.CacheStore;
 import org.apache.ignite.configuration.CacheConfiguration;
-import org.apache.ignite.internal.portable.BinaryObjectEx;
+import org.apache.ignite.internal.binary.BinaryObjectEx;
 import org.apache.ignite.internal.util.typedef.internal.U;
 import org.jetbrains.annotations.Nullable;
 

http://git-wip-us.apache.org/repos/asf/ignite/blob/1dbf20e0/modules/core/src/main/java/org/apache/ignite/internal/GridKernalContextImpl.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/GridKernalContextImpl.java b/modules/core/src/main/java/org/apache/ignite/internal/GridKernalContextImpl.java
index 4990dc7..22fd96c 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/GridKernalContextImpl.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/GridKernalContextImpl.java
@@ -49,7 +49,7 @@ import org.apache.ignite.internal.managers.swapspace.GridSwapSpaceManager;
 import org.apache.ignite.internal.processors.affinity.GridAffinityProcessor;
 import org.apache.ignite.internal.processors.cache.CacheConflictResolutionManager;
 import org.apache.ignite.internal.processors.cache.GridCacheProcessor;
-import org.apache.ignite.internal.processors.cache.portable.CacheObjectBinaryProcessorImpl;
+import org.apache.ignite.internal.processors.cache.binary.CacheObjectBinaryProcessorImpl;
 import org.apache.ignite.internal.processors.cacheobject.IgniteCacheObjectProcessor;
 import org.apache.ignite.internal.processors.clock.GridClockSource;
 import org.apache.ignite.internal.processors.clock.GridClockSyncProcessor;

http://git-wip-us.apache.org/repos/asf/ignite/blob/1dbf20e0/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 d231ad3..4fb5d4a 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
@@ -96,8 +96,8 @@ import org.apache.ignite.internal.managers.failover.GridFailoverManager;
 import org.apache.ignite.internal.managers.indexing.GridIndexingManager;
 import org.apache.ignite.internal.managers.loadbalancer.GridLoadBalancerManager;
 import org.apache.ignite.internal.managers.swapspace.GridSwapSpaceManager;
-import org.apache.ignite.internal.portable.BinaryEnumCache;
-import org.apache.ignite.internal.portable.BinaryMarshaller;
+import org.apache.ignite.internal.binary.BinaryEnumCache;
+import org.apache.ignite.internal.binary.BinaryMarshaller;
 import org.apache.ignite.internal.processors.GridProcessor;
 import org.apache.ignite.internal.processors.affinity.GridAffinityProcessor;
 import org.apache.ignite.internal.processors.cache.GridCacheAdapter;
@@ -106,7 +106,7 @@ import org.apache.ignite.internal.processors.cache.GridCacheProcessor;
 import org.apache.ignite.internal.processors.cache.GridCacheUtilityKey;
 import org.apache.ignite.internal.processors.cache.IgniteCacheProxy;
 import org.apache.ignite.internal.processors.cache.IgniteInternalCache;
-import org.apache.ignite.internal.processors.cache.portable.CacheObjectBinaryProcessorImpl;
+import org.apache.ignite.internal.processors.cache.binary.CacheObjectBinaryProcessorImpl;
 import org.apache.ignite.internal.processors.cacheobject.IgniteCacheObjectProcessor;
 import org.apache.ignite.internal.processors.clock.GridClockSyncProcessor;
 import org.apache.ignite.internal.processors.closure.GridClosureProcessor;

http://git-wip-us.apache.org/repos/asf/ignite/blob/1dbf20e0/modules/core/src/main/java/org/apache/ignite/internal/IgnitionEx.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/IgnitionEx.java b/modules/core/src/main/java/org/apache/ignite/internal/IgnitionEx.java
index 9b886e8..4f6c6d9 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/IgnitionEx.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/IgnitionEx.java
@@ -61,7 +61,7 @@ import org.apache.ignite.configuration.DeploymentMode;
 import org.apache.ignite.configuration.FileSystemConfiguration;
 import org.apache.ignite.configuration.IgniteConfiguration;
 import org.apache.ignite.configuration.TransactionConfiguration;
-import org.apache.ignite.internal.portable.BinaryMarshaller;
+import org.apache.ignite.internal.binary.BinaryMarshaller;
 import org.apache.ignite.internal.processors.resource.GridSpringResourceContext;
 import org.apache.ignite.internal.util.GridConcurrentHashSet;
 import org.apache.ignite.internal.util.IgniteUtils;

http://git-wip-us.apache.org/repos/asf/ignite/blob/1dbf20e0/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryCachingMetadataHandler.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryCachingMetadataHandler.java b/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryCachingMetadataHandler.java
new file mode 100644
index 0000000..584b683
--- /dev/null
+++ b/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryCachingMetadataHandler.java
@@ -0,0 +1,70 @@
+/*
+ * 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.binary;
+
+import org.apache.ignite.binary.BinaryObjectException;
+import org.apache.ignite.binary.BinaryType;
+
+import java.util.HashMap;
+
+/**
+ * Simple caching metadata handler. Used mainly in tests.
+ */
+public class BinaryCachingMetadataHandler implements BinaryMetadataHandler {
+    /** Cached metadatas. */
+    private final HashMap<Integer, BinaryType> metas = new HashMap<>();
+
+    /**
+     * Create new handler instance.
+     *
+     * @return New handler.
+     */
+    public static BinaryCachingMetadataHandler create() {
+        return new BinaryCachingMetadataHandler();
+    }
+
+    /**
+     * Private constructor.
+     */
+    private BinaryCachingMetadataHandler() {
+        // No-op.
+    }
+
+    /** {@inheritDoc} */
+    @Override public synchronized void addMeta(int typeId, BinaryType type) throws BinaryObjectException {
+        synchronized (this) {
+            BinaryType oldType = metas.put(typeId, type);
+
+            if (oldType != null) {
+                BinaryMetadata oldMeta = ((BinaryTypeImpl)oldType).metadata();
+                BinaryMetadata newMeta = ((BinaryTypeImpl)type).metadata();
+
+                BinaryMetadata mergedMeta = PortableUtils.mergeMetadata(oldMeta, newMeta);
+
+                BinaryType mergedType = mergedMeta.wrap(((BinaryTypeImpl)oldType).context());
+
+                metas.put(typeId, mergedType);
+            }
+        }
+    }
+
+    /** {@inheritDoc} */
+    @Override public synchronized BinaryType metadata(int typeId) throws BinaryObjectException {
+        return metas.get(typeId);
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/1dbf20e0/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryEnumCache.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryEnumCache.java b/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryEnumCache.java
new file mode 100644
index 0000000..6089cfd
--- /dev/null
+++ b/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryEnumCache.java
@@ -0,0 +1,69 @@
+/*
+ * 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.binary;
+
+import org.apache.ignite.binary.BinaryObjectException;
+import org.jsr166.ConcurrentHashMap8;
+
+import java.util.concurrent.ConcurrentMap;
+
+/**
+ * Cache for enum constants.
+ */
+public class BinaryEnumCache {
+    /** Cache for enum constants. */
+    private static final ConcurrentMap<Class<?>, Object[]> ENUM_CACHE = new ConcurrentHashMap8<>();
+
+    /**
+     * Get value for the given class and ordinal.
+     *
+     * @param cls Class.
+     * @param ord Ordinal.
+     * @return Value.
+     * @throws BinaryObjectException In case of invalid ordinal.
+     */
+    @SuppressWarnings("unchecked")
+    public static <T> T get(Class<?> cls, int ord) throws BinaryObjectException {
+        assert cls != null;
+
+        if (ord >= 0) {
+            Object[] vals = ENUM_CACHE.get(cls);
+
+            if (vals == null) {
+                vals = cls.getEnumConstants();
+
+                ENUM_CACHE.putIfAbsent(cls, vals);
+            }
+
+            if (ord < vals.length)
+                return (T) vals[ord];
+            else
+                throw new BinaryObjectException("Failed to get enum value for ordinal (do you have correct class " +
+                    "version?) [cls=" + cls.getName() + ", ordinal=" + ord + ", totalValues=" + vals.length + ']');
+        }
+        else
+            return null;
+    }
+
+    /**
+     * Clears cache.
+     */
+    public static void clear() {
+        ENUM_CACHE.clear();
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/1dbf20e0/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryEnumObjectImpl.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryEnumObjectImpl.java b/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryEnumObjectImpl.java
new file mode 100644
index 0000000..15e42e3
--- /dev/null
+++ b/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryEnumObjectImpl.java
@@ -0,0 +1,311 @@
+/*
+ * 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.binary;
+
+import org.apache.ignite.IgniteCheckedException;
+import org.apache.ignite.binary.BinaryObject;
+import org.apache.ignite.binary.BinaryObjectException;
+import org.apache.ignite.binary.BinaryType;
+import org.apache.ignite.internal.GridDirectTransient;
+import org.apache.ignite.internal.processors.cache.CacheObject;
+import org.apache.ignite.internal.processors.cache.CacheObjectContext;
+import org.apache.ignite.internal.processors.cache.binary.CacheObjectBinaryProcessorImpl;
+import org.apache.ignite.internal.util.typedef.internal.SB;
+import org.apache.ignite.plugin.extensions.communication.MessageReader;
+import org.apache.ignite.plugin.extensions.communication.MessageWriter;
+import org.jetbrains.annotations.Nullable;
+
+import java.io.Externalizable;
+import java.io.IOException;
+import java.io.ObjectInput;
+import java.io.ObjectOutput;
+import java.nio.ByteBuffer;
+
+/**
+ * Binary enum object.
+ */
+public class BinaryEnumObjectImpl implements BinaryObjectEx, Externalizable, CacheObject {
+    /** */
+    private static final long serialVersionUID = 0L;
+
+    /** Context. */
+    @GridDirectTransient
+    private PortableContext ctx;
+
+    /** Type ID. */
+    private int typeId;
+
+    /** Raw data. */
+    private String clsName;
+
+    /** Ordinal. */
+    private int ord;
+
+    /**
+     * {@link Externalizable} support.
+     */
+    public BinaryEnumObjectImpl() {
+        // No-op.
+    }
+
+    /**
+     * Constructor.
+     *
+     * @param ctx Context.
+     * @param typeId Type ID.
+     * @param clsName Class name.
+     * @param ord Ordinal.
+     */
+    public BinaryEnumObjectImpl(PortableContext ctx, int typeId, @Nullable String clsName, int ord) {
+        assert ctx != null;
+
+        this.ctx = ctx;
+        this.typeId = typeId;
+        this.clsName = clsName;
+        this.ord = ord;
+    }
+
+    /**
+     * @return Class name.
+     */
+    @Nullable public String className() {
+        return clsName;
+    }
+
+    /** {@inheritDoc} */
+    @Override public int typeId() {
+        return typeId;
+    }
+
+    /** {@inheritDoc} */
+    @Override public BinaryType type() throws BinaryObjectException {
+        return ctx.metadata(typeId());
+    }
+
+    /** {@inheritDoc} */
+    @Override public <F> F field(String fieldName) throws BinaryObjectException {
+        return null;
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean hasField(String fieldName) {
+        return false;
+    }
+
+    /** {@inheritDoc} */
+    @SuppressWarnings("unchecked")
+    @Override public <T> T deserialize() throws BinaryObjectException {
+        Class cls = PortableUtils.resolveClass(ctx, typeId, clsName, null, true);
+
+        return BinaryEnumCache.get(cls, ord);
+    }
+
+    /** {@inheritDoc} */
+    @Override public BinaryObject clone() throws CloneNotSupportedException {
+        return (BinaryObject)super.clone();
+    }
+
+    /** {@inheritDoc} */
+    @Override public int enumOrdinal() throws BinaryObjectException {
+        return ord;
+    }
+
+    /** {@inheritDoc} */
+    @Override public int hashCode() {
+        return 31 * typeId + ord;
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean equals(Object obj) {
+        if (obj != null && (obj instanceof BinaryEnumObjectImpl)) {
+            BinaryEnumObjectImpl other = (BinaryEnumObjectImpl)obj;
+
+            return typeId == other.typeId && ord == other.ord;
+        }
+
+        return false;
+    }
+
+    /** {@inheritDoc} */
+    @Override public String toString() {
+        // 1. Try deserializing the object.
+        try {
+            Object val = deserialize();
+
+            return new SB().a(val).toString();
+        }
+        catch (Exception e) {
+            // No-op.
+        }
+
+        // 2. Try getting meta.
+        BinaryType type;
+
+        try {
+            type = type();
+        }
+        catch (Exception e) {
+            type = null;
+        }
+
+        if (type != null) {
+            return type.typeName() + "[ordinal=" + ord  + ']';
+        }
+        else {
+            if (typeId == GridPortableMarshaller.UNREGISTERED_TYPE_ID)
+                return "BinaryEnum[clsName=" + clsName + ", ordinal=" + ord + ']';
+            else
+                return "BinaryEnum[typeId=" + typeId + ", ordinal=" + ord + ']';
+        }
+    }
+
+    /** {@inheritDoc} */
+    @Override public void writeExternal(ObjectOutput out) throws IOException {
+        out.writeObject(ctx);
+
+        out.writeInt(typeId);
+        out.writeObject(clsName);
+        out.writeInt(ord);
+    }
+
+    /** {@inheritDoc} */
+    @Override public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
+        ctx = (PortableContext)in.readObject();
+
+        typeId = in.readInt();
+        clsName = (String)in.readObject();
+        ord = in.readInt();
+    }
+
+    /** {@inheritDoc} */
+    @Nullable @Override public <T> T value(CacheObjectContext ctx, boolean cpy) {
+        return deserialize();
+    }
+
+    /** {@inheritDoc} */
+    @Override public byte[] valueBytes(CacheObjectContext cacheCtx) throws IgniteCheckedException {
+        return ctx.marshaller().marshal(this);
+    }
+
+    /** {@inheritDoc} */
+    @Override public byte cacheObjectType() {
+        return TYPE_BINARY;
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean isPlatformType() {
+        return false;
+    }
+
+    /** {@inheritDoc} */
+    @Override public CacheObject prepareForCache(CacheObjectContext ctx) {
+        return this;
+    }
+
+    /** {@inheritDoc} */
+    @Override public void finishUnmarshal(CacheObjectContext ctx, ClassLoader ldr) throws IgniteCheckedException {
+        this.ctx = ((CacheObjectBinaryProcessorImpl)ctx.processor()).portableContext();
+    }
+
+    /** {@inheritDoc} */
+    @Override public void prepareMarshal(CacheObjectContext ctx) throws IgniteCheckedException {
+        // No-op.
+    }
+
+    /** {@inheritDoc} */
+    @Override public byte directType() {
+        return 119;
+    }
+
+    /** {@inheritDoc} */
+    @Override public byte fieldsCount() {
+        return 3;
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean writeTo(ByteBuffer buf, MessageWriter writer) {
+        writer.setBuffer(buf);
+
+        if (!writer.isHeaderWritten()) {
+            if (!writer.writeHeader(directType(), fieldsCount()))
+                return false;
+
+            writer.onHeaderWritten();
+        }
+
+        switch (writer.state()) {
+            case 0:
+                if (!writer.writeString("clsName", clsName))
+                    return false;
+
+                writer.incrementState();
+
+            case 1:
+                if (!writer.writeInt("ord", ord))
+                    return false;
+
+                writer.incrementState();
+
+            case 2:
+                if (!writer.writeInt("typeId", typeId))
+                    return false;
+
+                writer.incrementState();
+
+        }
+
+        return true;
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean readFrom(ByteBuffer buf, MessageReader reader) {
+        reader.setBuffer(buf);
+
+        if (!reader.beforeMessageRead())
+            return false;
+
+        switch (reader.state()) {
+            case 0:
+                clsName = reader.readString("clsName");
+
+                if (!reader.isLastRead())
+                    return false;
+
+                reader.incrementState();
+
+            case 1:
+                ord = reader.readInt("ord");
+
+                if (!reader.isLastRead())
+                    return false;
+
+                reader.incrementState();
+
+            case 2:
+                typeId = reader.readInt("typeId");
+
+                if (!reader.isLastRead())
+                    return false;
+
+                reader.incrementState();
+
+        }
+
+        return reader.afterMessageRead(BinaryEnumObjectImpl.class);
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/1dbf20e0/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryFieldAccessor.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryFieldAccessor.java b/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryFieldAccessor.java
new file mode 100644
index 0000000..962805d
--- /dev/null
+++ b/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryFieldAccessor.java
@@ -0,0 +1,856 @@
+/*
+ * 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.binary;
+
+import org.apache.ignite.binary.BinaryObjectException;
+import org.apache.ignite.internal.util.GridUnsafe;
+import org.apache.ignite.internal.util.typedef.internal.U;
+import sun.misc.Unsafe;
+
+import java.lang.reflect.Field;
+import java.math.BigDecimal;
+import java.sql.Timestamp;
+import java.util.Collection;
+import java.util.Date;
+import java.util.Map;
+import java.util.UUID;
+
+/**
+ * Field accessor to speedup access.
+ */
+public abstract class BinaryFieldAccessor {
+    /** Field ID. */
+    protected final int id;
+
+    /** Mode. */
+    protected final BinaryWriteMode mode;
+
+    /**
+     * Create accessor for the field.
+     *
+     * @param field Field.
+     * @param id FIeld ID.
+     * @return Accessor.
+     */
+    public static BinaryFieldAccessor create(Field field, int id) {
+        BinaryWriteMode mode = PortableUtils.mode(field.getType());
+
+        switch (mode) {
+            case P_BYTE:
+                return new BytePrimitiveAccessor(field, id);
+
+            case P_BOOLEAN:
+                return new BooleanPrimitiveAccessor(field, id);
+
+            case P_SHORT:
+                return new ShortPrimitiveAccessor(field, id);
+
+            case P_CHAR:
+                return new CharPrimitiveAccessor(field, id);
+
+            case P_INT:
+                return new IntPrimitiveAccessor(field, id);
+
+            case P_LONG:
+                return new LongPrimitiveAccessor(field, id);
+
+            case P_FLOAT:
+                return new FloatPrimitiveAccessor(field, id);
+
+            case P_DOUBLE:
+                return new DoublePrimitiveAccessor(field, id);
+
+            case BYTE:
+            case BOOLEAN:
+            case SHORT:
+            case CHAR:
+            case INT:
+            case LONG:
+            case FLOAT:
+            case DOUBLE:
+            case DECIMAL:
+            case STRING:
+            case UUID:
+            case DATE:
+            case TIMESTAMP:
+            case BYTE_ARR:
+            case SHORT_ARR:
+            case INT_ARR:
+            case LONG_ARR:
+            case FLOAT_ARR:
+            case DOUBLE_ARR:
+            case CHAR_ARR:
+            case BOOLEAN_ARR:
+            case DECIMAL_ARR:
+            case STRING_ARR:
+            case UUID_ARR:
+            case DATE_ARR:
+            case TIMESTAMP_ARR:
+            case ENUM_ARR:
+            case OBJECT_ARR:
+            case PORTABLE_OBJ:
+            case PORTABLE:
+            case EXTERNALIZABLE:
+                return new DefaultFinalClassAccessor(field, id, mode, false);
+
+            default:
+                return new DefaultFinalClassAccessor(field, id, mode, !U.isFinal(field.getType()));
+        }
+    }
+
+    /**
+     * Protected constructor.
+     *
+     * @param id Field ID.
+     * @param mode Mode;
+     */
+    protected BinaryFieldAccessor(int id, BinaryWriteMode mode) {
+        assert id != 0;
+        assert mode != null;
+
+        this.id = id;
+        this.mode = mode;
+    }
+
+    /**
+     * Get mode.
+     *
+     * @return Mode.
+     */
+    public BinaryWriteMode mode() {
+        return mode;
+    }
+
+    /**
+     * Write field.
+     *
+     * @param obj Object.
+     * @param writer Writer.
+     * @throws BinaryObjectException If failed.
+     */
+    public abstract void write(Object obj, BinaryWriterExImpl writer) throws BinaryObjectException;
+
+    /**
+     * Read field.
+     *
+     * @param obj Object.
+     * @param reader Reader.
+     * @throws BinaryObjectException If failed.
+     */
+    public abstract void read(Object obj, BinaryReaderExImpl reader) throws BinaryObjectException;
+
+    /**
+     * Base primitive field accessor.
+     */
+    private static abstract class AbstractPrimitiveAccessor extends BinaryFieldAccessor {
+        /** Unsafe instance. */
+        protected static final Unsafe UNSAFE = GridUnsafe.unsafe();
+
+        /** Offset. */
+        protected final long offset;
+
+        /**
+         * Constructor.
+         *
+         * @param field Field.
+         * @param id Field ID.
+         * @param mode Mode.
+         */
+        protected AbstractPrimitiveAccessor(Field field, int id, BinaryWriteMode mode) {
+            super(id, mode);
+
+            assert field != null;
+
+            offset = UNSAFE.objectFieldOffset(field);
+        }
+    }
+
+    /**
+     * Byte field accessor.
+     */
+    private static class BytePrimitiveAccessor extends AbstractPrimitiveAccessor {
+        /**
+         * Constructor.
+         *
+         * @param field Field.
+         */
+        public BytePrimitiveAccessor(Field field, int id) {
+            super(field, id, BinaryWriteMode.P_BYTE);
+        }
+
+        /** {@inheritDoc} */
+        @Override public void write(Object obj, BinaryWriterExImpl writer) throws BinaryObjectException {
+            writer.writeFieldIdNoSchemaUpdate(id);
+
+            byte val = UNSAFE.getByte(obj, offset);
+
+            writer.writeByteFieldPrimitive(val);
+        }
+
+        /** {@inheritDoc} */
+        @Override public void read(Object obj, BinaryReaderExImpl reader) throws BinaryObjectException {
+            byte val = reader.readByte(id);
+
+            UNSAFE.putByte(obj, offset, val);
+        }
+    }
+
+    /**
+     * Boolean field accessor.
+     */
+    private static class BooleanPrimitiveAccessor extends AbstractPrimitiveAccessor {
+        /**
+         * Constructor.
+         *
+         * @param field Field.
+         */
+        public BooleanPrimitiveAccessor(Field field, int id) {
+            super(field, id, BinaryWriteMode.P_BOOLEAN);
+        }
+
+        /** {@inheritDoc} */
+        @Override public void write(Object obj, BinaryWriterExImpl writer) throws BinaryObjectException {
+            writer.writeFieldIdNoSchemaUpdate(id);
+
+            boolean val = UNSAFE.getBoolean(obj, offset);
+
+            writer.writeBooleanFieldPrimitive(val);
+        }
+
+        /** {@inheritDoc} */
+        @Override public void read(Object obj, BinaryReaderExImpl reader) throws BinaryObjectException {
+            boolean val = reader.readBoolean(id);
+
+            UNSAFE.putBoolean(obj, offset, val);
+        }
+    }
+
+    /**
+     * Short field accessor.
+     */
+    private static class ShortPrimitiveAccessor extends AbstractPrimitiveAccessor {
+        /**
+         * Constructor.
+         *
+         * @param field Field.
+         */
+        public ShortPrimitiveAccessor(Field field, int id) {
+            super(field, id, BinaryWriteMode.P_SHORT);
+        }
+
+        /** {@inheritDoc} */
+        @Override public void write(Object obj, BinaryWriterExImpl writer) throws BinaryObjectException {
+            writer.writeFieldIdNoSchemaUpdate(id);
+
+            short val = UNSAFE.getShort(obj, offset);
+
+            writer.writeShortFieldPrimitive(val);
+        }
+
+        /** {@inheritDoc} */
+        @Override public void read(Object obj, BinaryReaderExImpl reader) throws BinaryObjectException {
+            short val = reader.readShort(id);
+
+            UNSAFE.putShort(obj, offset, val);
+        }
+    }
+
+    /**
+     * Char field accessor.
+     */
+    private static class CharPrimitiveAccessor extends AbstractPrimitiveAccessor {
+        /**
+         * Constructor.
+         *
+         * @param field Field.
+         */
+        public CharPrimitiveAccessor(Field field, int id) {
+            super(field, id, BinaryWriteMode.P_CHAR);
+        }
+
+        /** {@inheritDoc} */
+        @Override public void write(Object obj, BinaryWriterExImpl writer) throws BinaryObjectException {
+            writer.writeFieldIdNoSchemaUpdate(id);
+
+            char val = UNSAFE.getChar(obj, offset);
+
+            writer.writeCharFieldPrimitive(val);
+        }
+
+        /** {@inheritDoc} */
+        @Override public void read(Object obj, BinaryReaderExImpl reader) throws BinaryObjectException {
+            char val = reader.readChar(id);
+
+            UNSAFE.putChar(obj, offset, val);
+        }
+    }
+
+    /**
+     * Int field accessor.
+     */
+    private static class IntPrimitiveAccessor extends AbstractPrimitiveAccessor {
+        /**
+         * Constructor.
+         *
+         * @param field Field.
+         */
+        public IntPrimitiveAccessor(Field field, int id) {
+            super(field, id, BinaryWriteMode.P_INT);
+        }
+
+        /** {@inheritDoc} */
+        @Override public void write(Object obj, BinaryWriterExImpl writer) throws BinaryObjectException {
+            writer.writeFieldIdNoSchemaUpdate(id);
+
+            int val = UNSAFE.getInt(obj, offset);
+
+            writer.writeIntFieldPrimitive(val);
+        }
+
+        /** {@inheritDoc} */
+        @Override public void read(Object obj, BinaryReaderExImpl reader) throws BinaryObjectException {
+            int val = reader.readInt(id);
+
+            UNSAFE.putInt(obj, offset, val);
+        }
+    }
+
+    /**
+     * Long field accessor.
+     */
+    private static class LongPrimitiveAccessor extends AbstractPrimitiveAccessor {
+        /**
+         * Constructor.
+         *
+         * @param field Field.
+         */
+        public LongPrimitiveAccessor(Field field, int id) {
+            super(field, id, BinaryWriteMode.P_LONG);
+        }
+
+        /** {@inheritDoc} */
+        @Override public void write(Object obj, BinaryWriterExImpl writer) throws BinaryObjectException {
+            writer.writeFieldIdNoSchemaUpdate(id);
+
+            long val = UNSAFE.getLong(obj, offset);
+
+            writer.writeLongFieldPrimitive(val);
+        }
+
+        /** {@inheritDoc} */
+        @Override public void read(Object obj, BinaryReaderExImpl reader) throws BinaryObjectException {
+            long val = reader.readLong(id);
+
+            UNSAFE.putLong(obj, offset, val);
+        }
+    }
+
+    /**
+     * Float field accessor.
+     */
+    private static class FloatPrimitiveAccessor extends AbstractPrimitiveAccessor {
+        /**
+         * Constructor.
+         *
+         * @param field Field.
+         */
+        public FloatPrimitiveAccessor(Field field, int id) {
+            super(field, id, BinaryWriteMode.P_FLOAT);
+        }
+
+        /** {@inheritDoc} */
+        @Override public void write(Object obj, BinaryWriterExImpl writer) throws BinaryObjectException {
+            writer.writeFieldIdNoSchemaUpdate(id);
+
+            float val = UNSAFE.getFloat(obj, offset);
+
+            writer.writeFloatFieldPrimitive(val);
+        }
+
+        /** {@inheritDoc} */
+        @Override public void read(Object obj, BinaryReaderExImpl reader) throws BinaryObjectException {
+            float val = reader.readFloat(id);
+
+            UNSAFE.putFloat(obj, offset, val);
+        }
+    }
+
+    /**
+     * Double field accessor.
+     */
+    private static class DoublePrimitiveAccessor extends AbstractPrimitiveAccessor {
+        /**
+         * Constructor.
+         *
+         * @param field Field.
+         */
+        public DoublePrimitiveAccessor(Field field, int id) {
+            super(field, id, BinaryWriteMode.P_DOUBLE);
+        }
+
+        /** {@inheritDoc} */
+        @Override public void write(Object obj, BinaryWriterExImpl writer) throws BinaryObjectException {
+            writer.writeFieldIdNoSchemaUpdate(id);
+
+            double val = UNSAFE.getDouble(obj, offset);
+
+            writer.writeDoubleFieldPrimitive(val);
+        }
+
+        /** {@inheritDoc} */
+        @Override public void read(Object obj, BinaryReaderExImpl reader) throws BinaryObjectException {
+            double val = reader.readDouble(id);
+
+            UNSAFE.putDouble(obj, offset, val);
+        }
+    }
+
+    /**
+     * Default accessor.
+     */
+    private static class DefaultFinalClassAccessor extends BinaryFieldAccessor {
+        /** Target field. */
+        private final Field field;
+
+        /** Dynamic accessor flag. */
+        private final boolean dynamic;
+
+        /**
+         * Constructor.
+         *
+         * @param field Field.
+         * @param id Field ID.
+         * @param mode Mode.
+         */
+        DefaultFinalClassAccessor(Field field, int id, BinaryWriteMode mode, boolean dynamic) {
+            super(id, mode);
+
+            assert field != null;
+
+            this.field = field;
+            this.dynamic = dynamic;
+        }
+
+        /** {@inheritDoc} */
+        @Override public void write(Object obj, BinaryWriterExImpl writer) throws BinaryObjectException {
+            assert obj != null;
+            assert writer != null;
+
+            writer.writeFieldIdNoSchemaUpdate(id);
+
+            Object val;
+
+            try {
+                val = field.get(obj);
+            }
+            catch (IllegalAccessException e) {
+                throw new BinaryObjectException("Failed to get value for field: " + field, e);
+            }
+
+            switch (mode(val)) {
+                case BYTE:
+                    writer.writeByteField((Byte) val);
+
+                    break;
+
+                case SHORT:
+                    writer.writeShortField((Short) val);
+
+                    break;
+
+                case INT:
+                    writer.writeIntField((Integer) val);
+
+                    break;
+
+                case LONG:
+                    writer.writeLongField((Long)val);
+
+                    break;
+
+                case FLOAT:
+                    writer.writeFloatField((Float)val);
+
+                    break;
+
+                case DOUBLE:
+                    writer.writeDoubleField((Double)val);
+
+                    break;
+
+                case CHAR:
+                    writer.writeCharField((Character)val);
+
+                    break;
+
+                case BOOLEAN:
+                    writer.writeBooleanField((Boolean)val);
+
+                    break;
+
+                case DECIMAL:
+                    writer.writeDecimalField((BigDecimal)val);
+
+                    break;
+
+                case STRING:
+                    writer.writeStringField((String)val);
+
+                    break;
+
+                case UUID:
+                    writer.writeUuidField((UUID)val);
+
+                    break;
+
+                case DATE:
+                    writer.writeDateField((Date)val);
+
+                    break;
+
+                case TIMESTAMP:
+                    writer.writeTimestampField((Timestamp)val);
+
+                    break;
+
+                case BYTE_ARR:
+                    writer.writeByteArrayField((byte[])val);
+
+                    break;
+
+                case SHORT_ARR:
+                    writer.writeShortArrayField((short[])val);
+
+                    break;
+
+                case INT_ARR:
+                    writer.writeIntArrayField((int[])val);
+
+                    break;
+
+                case LONG_ARR:
+                    writer.writeLongArrayField((long[])val);
+
+                    break;
+
+                case FLOAT_ARR:
+                    writer.writeFloatArrayField((float[])val);
+
+                    break;
+
+                case DOUBLE_ARR:
+                    writer.writeDoubleArrayField((double[])val);
+
+                    break;
+
+                case CHAR_ARR:
+                    writer.writeCharArrayField((char[])val);
+
+                    break;
+
+                case BOOLEAN_ARR:
+                    writer.writeBooleanArrayField((boolean[])val);
+
+                    break;
+
+                case DECIMAL_ARR:
+                    writer.writeDecimalArrayField((BigDecimal[])val);
+
+                    break;
+
+                case STRING_ARR:
+                    writer.writeStringArrayField((String[])val);
+
+                    break;
+
+                case UUID_ARR:
+                    writer.writeUuidArrayField((UUID[])val);
+
+                    break;
+
+                case DATE_ARR:
+                    writer.writeDateArrayField((Date[])val);
+
+                    break;
+
+                case TIMESTAMP_ARR:
+                    writer.writeTimestampArrayField((Timestamp[])val);
+
+                    break;
+
+                case OBJECT_ARR:
+                    writer.writeObjectArrayField((Object[])val);
+
+                    break;
+
+                case COL:
+                    writer.writeCollectionField((Collection<?>)val);
+
+                    break;
+
+                case MAP:
+                    writer.writeMapField((Map<?, ?>)val);
+
+                    break;
+
+                case PORTABLE_OBJ:
+                    writer.writePortableObjectField((BinaryObjectImpl)val);
+
+                    break;
+
+                case ENUM:
+                    writer.writeEnumField((Enum<?>)val);
+
+                    break;
+
+                case ENUM_ARR:
+                    writer.writeEnumArrayField((Object[])val);
+
+                    break;
+
+                case PORTABLE:
+                case EXTERNALIZABLE:
+                case OBJECT:
+                    writer.writeObjectField(val);
+
+                    break;
+
+                case CLASS:
+                    writer.writeClassField((Class)val);
+
+                    break;
+
+                default:
+                    assert false : "Invalid mode: " + mode;
+            }
+        }
+
+        /** {@inheritDoc} */
+        @Override public void read(Object obj, BinaryReaderExImpl reader) throws BinaryObjectException {
+            Object val = dynamic ? reader.readField(id) : readFixedType(reader);
+
+            try {
+                if (val != null || !field.getType().isPrimitive())
+                    field.set(obj, val);
+            }
+            catch (IllegalAccessException e) {
+                throw new BinaryObjectException("Failed to set value for field: " + field, e);
+            }
+        }
+
+        /**
+         * Reads fixed type from the given reader with flags validation.
+         *
+         * @param reader Reader to read from.
+         * @return Read value.
+         * @throws BinaryObjectException If failed to read value from the stream.
+         */
+        protected Object readFixedType(BinaryReaderExImpl reader) throws BinaryObjectException {
+            Object val = null;
+
+            switch (mode) {
+                case BYTE:
+                    val = reader.readByteNullable(id);
+
+                    break;
+
+                case SHORT:
+                    val = reader.readShortNullable(id);
+
+                    break;
+
+                case INT:
+                    val = reader.readIntNullable(id);
+
+                    break;
+
+                case LONG:
+                    val = reader.readLongNullable(id);
+
+                    break;
+
+                case FLOAT:
+                    val = reader.readFloatNullable(id);
+
+                    break;
+
+                case DOUBLE:
+                    val = reader.readDoubleNullable(id);
+
+                    break;
+
+                case CHAR:
+                    val = reader.readCharNullable(id);
+
+                    break;
+
+                case BOOLEAN:
+                    val = reader.readBooleanNullable(id);
+
+                    break;
+
+                case DECIMAL:
+                    val = reader.readDecimal(id);
+
+                    break;
+
+                case STRING:
+                    val = reader.readString(id);
+
+                    break;
+
+                case UUID:
+                    val = reader.readUuid(id);
+
+                    break;
+
+                case DATE:
+                    val = reader.readDate(id);
+
+                    break;
+
+                case TIMESTAMP:
+                    val = reader.readTimestamp(id);
+
+                    break;
+
+                case BYTE_ARR:
+                    val = reader.readByteArray(id);
+
+                    break;
+
+                case SHORT_ARR:
+                    val = reader.readShortArray(id);
+
+                    break;
+
+                case INT_ARR:
+                    val = reader.readIntArray(id);
+
+                    break;
+
+                case LONG_ARR:
+                    val = reader.readLongArray(id);
+
+                    break;
+
+                case FLOAT_ARR:
+                    val = reader.readFloatArray(id);
+
+                    break;
+
+                case DOUBLE_ARR:
+                    val = reader.readDoubleArray(id);
+
+                    break;
+
+                case CHAR_ARR:
+                    val = reader.readCharArray(id);
+
+                    break;
+
+                case BOOLEAN_ARR:
+                    val = reader.readBooleanArray(id);
+
+                    break;
+
+                case DECIMAL_ARR:
+                    val = reader.readDecimalArray(id);
+
+                    break;
+
+                case STRING_ARR:
+                    val = reader.readStringArray(id);
+
+                    break;
+
+                case UUID_ARR:
+                    val = reader.readUuidArray(id);
+
+                    break;
+
+                case DATE_ARR:
+                    val = reader.readDateArray(id);
+
+                    break;
+
+                case TIMESTAMP_ARR:
+                    val = reader.readTimestampArray(id);
+
+                    break;
+
+                case OBJECT_ARR:
+                    val = reader.readObjectArray(id);
+
+                    break;
+
+                case COL:
+                    val = reader.readCollection(id, null);
+
+                    break;
+
+                case MAP:
+                    val = reader.readMap(id, null);
+
+                    break;
+
+                case PORTABLE_OBJ:
+                    val = reader.readPortableObject(id);
+
+                    break;
+
+                case ENUM:
+                    val = reader.readEnum(id, field.getType());
+
+                    break;
+
+                case ENUM_ARR:
+                    val = reader.readEnumArray(id, field.getType().getComponentType());
+
+                    break;
+
+                case PORTABLE:
+                case EXTERNALIZABLE:
+                case OBJECT:
+                    val = reader.readObject(id);
+
+                    break;
+
+                case CLASS:
+                    val = reader.readClass(id);
+
+                    break;
+
+                default:
+                    assert false : "Invalid mode: " + mode;
+            }
+
+            return val;
+        }
+
+        /**
+         * @param val Val to get write mode for.
+         * @return Write mode.
+         */
+        protected BinaryWriteMode mode(Object val) {
+            return dynamic ?
+                val == null ? BinaryWriteMode.OBJECT : PortableUtils.mode(val.getClass()) :
+                mode;
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/1dbf20e0/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryFieldImpl.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryFieldImpl.java b/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryFieldImpl.java
new file mode 100644
index 0000000..36fde02
--- /dev/null
+++ b/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryFieldImpl.java
@@ -0,0 +1,116 @@
+/*
+ * 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.binary;
+
+import org.apache.ignite.binary.BinaryObjectException;
+import org.apache.ignite.internal.util.tostring.GridToStringExclude;
+import org.apache.ignite.internal.util.typedef.internal.S;
+import org.apache.ignite.binary.BinaryObject;
+import org.apache.ignite.binary.BinaryField;
+
+/**
+ * Implementation of portable field descriptor.
+ */
+public class BinaryFieldImpl implements BinaryField {
+    /** Type ID. */
+    private final int typeId;
+
+    /** Well-known object schemas. */
+    @GridToStringExclude
+    private final PortableSchemaRegistry schemas;
+
+    /** Field name. */
+    private final String fieldName;
+
+    /** Pre-calculated field ID. */
+    private final int fieldId;
+
+    /**
+     * Constructor.
+     *
+     * @param schemas Schemas.
+     * @param fieldName Field name.
+     * @param fieldId Field ID.
+     */
+    public BinaryFieldImpl(int typeId, PortableSchemaRegistry schemas, String fieldName, int fieldId) {
+        assert typeId != 0;
+        assert schemas != null;
+        assert fieldName != null;
+        assert fieldId != 0;
+
+        this.typeId = typeId;
+        this.schemas = schemas;
+        this.fieldName = fieldName;
+        this.fieldId = fieldId;
+    }
+
+    /** {@inheritDoc} */
+    @Override public String name() {
+        return fieldName;
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean exists(BinaryObject obj) {
+        BinaryObjectExImpl obj0 = (BinaryObjectExImpl)obj;
+
+        return fieldOrder(obj0) != PortableSchema.ORDER_NOT_FOUND;
+    }
+
+    /** {@inheritDoc} */
+    @SuppressWarnings("unchecked")
+    @Override public <T> T value(BinaryObject obj) {
+        BinaryObjectExImpl obj0 = (BinaryObjectExImpl)obj;
+
+        int order = fieldOrder(obj0);
+
+        return order != PortableSchema.ORDER_NOT_FOUND ? (T)obj0.fieldByOrder(order) : null;
+    }
+
+    /**
+     * Get relative field offset.
+     *
+     * @param obj Object.
+     * @return Field offset.
+     */
+    private int fieldOrder(BinaryObjectExImpl obj) {
+        if (typeId != obj.typeId()) {
+            throw new BinaryObjectException("Failed to get field because type ID of passed object differs" +
+                " from type ID this " + BinaryField.class.getSimpleName() + " belongs to [expected=" + typeId +
+                ", actual=" + obj.typeId() + ']');
+        }
+
+        int schemaId = obj.schemaId();
+
+        PortableSchema schema = schemas.schema(schemaId);
+
+        if (schema == null) {
+            schema = obj.createSchema();
+
+            schemas.addSchema(schemaId, schema);
+        }
+
+        assert schema != null;
+
+        return schema.order(fieldId);
+    }
+
+    /** {@inheritDoc} */
+    @Override public String toString() {
+        return S.toString(BinaryFieldImpl.class, this);
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/1dbf20e0/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryInternalIdMapper.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryInternalIdMapper.java b/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryInternalIdMapper.java
new file mode 100644
index 0000000..14d7d6f
--- /dev/null
+++ b/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryInternalIdMapper.java
@@ -0,0 +1,161 @@
+/*
+ * 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.binary;
+
+import org.apache.ignite.binary.BinaryIdMapper;
+import org.apache.ignite.binary.BinaryObjectException;
+import org.jetbrains.annotations.Nullable;
+
+/**
+ * Internal ID mapper. Mimics ID mapper interface, but provides default implementation and offers slightly better
+ * performance on micro-level in default case because it doesn't need virtual calls.
+ */
+public class BinaryInternalIdMapper implements BinaryIdMapper {
+    /** Maximum lower-case character. */
+    private static final char MAX_LOWER_CASE_CHAR = 0x7e;
+
+    /** Cached lower-case characters. */
+    private static final char[] LOWER_CASE_CHARS;
+
+    /** Default implementation. */
+    private static final BinaryInternalIdMapper DFLT = new BinaryInternalIdMapper();
+
+    /**
+     * Static initializer.
+     */
+    static {
+        LOWER_CASE_CHARS = new char[MAX_LOWER_CASE_CHAR + 1];
+
+        for (char c = 0; c <= MAX_LOWER_CASE_CHAR; c++)
+            LOWER_CASE_CHARS[c] = Character.toLowerCase(c);
+    }
+
+    /**
+     * Get default instance.
+     *
+     * @return Default instance.
+     */
+    public static BinaryInternalIdMapper defaultInstance() {
+        return DFLT;
+    }
+
+    /**
+     * Create internal mapper.
+     *
+     * @param mapper Public mapper.
+     * @return Internal mapper.
+     */
+    public static BinaryInternalIdMapper create(@Nullable BinaryIdMapper mapper) {
+        return mapper == null ? DFLT : new Wrapper(mapper);
+    }
+
+    /**
+     * Private constructor.
+     */
+    protected BinaryInternalIdMapper() {
+        // No-op.
+    }
+
+    /**
+     * Get type ID.
+     *
+     * @param typeName Type name.
+     * @return Type ID.
+     */
+    public int typeId(String typeName) {
+        assert typeName != null;
+
+        return lowerCaseHashCode(typeName, true);
+    }
+
+    /**
+     * Get field ID.
+     *
+     * @param typeId Type ID.
+     * @param fieldName Field name.
+     * @return Field ID.
+     */
+    public int fieldId(int typeId, String fieldName) {
+        assert fieldName != null;
+
+        return lowerCaseHashCode(fieldName, false);
+    }
+
+    /**
+     * Routine to calculate string hash code an
+     *
+     * @param str String.
+     * @param type {@code True} if this is type name, false otherwise.
+     * @return Hash code for given string converted to lower case.
+     */
+    private static int lowerCaseHashCode(String str, boolean type) {
+        int len = str.length();
+
+        int h = 0;
+
+        for (int i = 0; i < len; i++) {
+            int c = str.charAt(i);
+
+            c = c <= MAX_LOWER_CASE_CHAR ? LOWER_CASE_CHARS[c] : Character.toLowerCase(c);
+
+            h = 31 * h + c;
+        }
+
+        if (h != 0)
+            return h;
+        else {
+            String what = type ? "type" : "field";
+
+            throw new BinaryObjectException("Default binary ID mapper resolved " + what + " ID to zero " +
+                "(either change " + what + "'s name or use custom ID mapper) [name=" + str + ']');
+        }
+    }
+
+    /**
+     * Wrapping ID mapper.
+     */
+    private static class Wrapper extends BinaryInternalIdMapper {
+        /** Delegate. */
+        private final BinaryIdMapper mapper;
+
+        /**
+         * Constructor.
+         *
+         * @param mapper Delegate.
+         */
+        private Wrapper(BinaryIdMapper mapper) {
+            assert mapper != null;
+
+            this.mapper = mapper;
+        }
+
+        /** {@inheritDoc} */
+        @Override public int typeId(String typeName) {
+            int id = mapper.typeId(typeName);
+
+            return id != 0 ? id : super.typeId(typeName);
+        }
+
+        /** {@inheritDoc} */
+        @Override public int fieldId(int typeId, String fieldName) {
+            int id = mapper.fieldId(typeId, fieldName);
+
+            return id != 0 ? id : super.fieldId(typeId, fieldName);
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/1dbf20e0/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryMarshaller.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryMarshaller.java b/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryMarshaller.java
new file mode 100644
index 0000000..13435e6
--- /dev/null
+++ b/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryMarshaller.java
@@ -0,0 +1,142 @@
+/*
+ * 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.binary;
+
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import org.apache.ignite.IgniteCheckedException;
+import org.apache.ignite.binary.BinaryObjectException;
+import org.apache.ignite.configuration.IgniteConfiguration;
+import org.apache.ignite.internal.util.GridUnsafe;
+import org.apache.ignite.marshaller.AbstractMarshaller;
+import org.apache.ignite.marshaller.MarshallerContext;
+import org.jetbrains.annotations.Nullable;
+import sun.misc.Unsafe;
+
+/**
+ * Implementation of {@link org.apache.ignite.marshaller.Marshaller} that lets to serialize and deserialize all objects
+ * in the binary format.
+ */
+public class BinaryMarshaller extends AbstractMarshaller {
+    /** */
+    private GridPortableMarshaller impl;
+
+    /**
+     * Checks whether {@code BinaryMarshaller} is able to work on the current JVM.
+     * <p>
+     * As long as {@code BinaryMarshaller} uses JVM-private API, which is not guaranteed
+     * to be available on all JVM, this method should be called to ensure marshaller could work properly.
+     * <p>
+     * Result of this method is automatically checked in constructor.
+     *
+     * @return {@code true} if {@code BinaryMarshaller} can work on the current JVM or
+     *      {@code false} if it can't.
+     */
+    @SuppressWarnings({"TypeParameterExtendsFinalClass", "ErrorNotRethrown"})
+    public static boolean available() {
+        try {
+            Unsafe unsafe = GridUnsafe.unsafe();
+
+            Class<? extends Unsafe> unsafeCls = unsafe.getClass();
+
+            unsafeCls.getMethod("allocateInstance", Class.class);
+            unsafeCls.getMethod("copyMemory", Object.class, long.class, Object.class, long.class, long.class);
+
+            return true;
+        }
+        catch (Exception ignored) {
+            return false;
+        }
+        catch (NoClassDefFoundError ignored) {
+            return false;
+        }
+    }
+
+    /**
+     * Returns currently set {@link MarshallerContext}.
+     *
+     * @return Marshaller context.
+     */
+    public MarshallerContext getContext() {
+        return ctx;
+    }
+
+    /**
+     * Sets {@link PortableContext}.
+     * <p/>
+     * @param ctx Portable context.
+     */
+    @SuppressWarnings("UnusedDeclaration")
+    private void setPortableContext(PortableContext ctx, IgniteConfiguration cfg) {
+        ctx.configure(this, cfg);
+
+        impl = new GridPortableMarshaller(ctx);
+    }
+
+    /** {@inheritDoc} */
+    @Override public byte[] marshal(@Nullable Object obj) throws IgniteCheckedException {
+        return impl.marshal(obj);
+    }
+
+    /** {@inheritDoc} */
+    @Override public void marshal(@Nullable Object obj, OutputStream out) throws IgniteCheckedException {
+        byte[] arr = marshal(obj);
+
+        try {
+            out.write(arr);
+        }
+        catch (IOException e) {
+            throw new BinaryObjectException("Failed to marshal the object: " + obj, e);
+        }
+    }
+
+    /** {@inheritDoc} */
+    @Override public <T> T unmarshal(byte[] bytes, @Nullable ClassLoader clsLdr) throws IgniteCheckedException {
+        return impl.deserialize(bytes, clsLdr);
+    }
+
+    /** {@inheritDoc} */
+    @Override public <T> T unmarshal(InputStream in, @Nullable ClassLoader clsLdr) throws IgniteCheckedException {
+        ByteArrayOutputStream buf = new ByteArrayOutputStream();
+
+        // we have to fully read the InputStream because GridPortableMarshaller requires support of a method that
+        // returns number of bytes remaining.
+        try {
+            byte[] arr = new byte[4096];
+
+            int cnt;
+
+            while ((cnt = in.read(arr)) != -1)
+                buf.write(arr, 0, cnt);
+
+            buf.flush();
+
+            return impl.deserialize(buf.toByteArray(), clsLdr);
+        }
+        catch (IOException e) {
+            throw new BinaryObjectException("Failed to unmarshal the object from InputStream", e);
+        }
+    }
+
+    /** {@inheritDoc} */
+    @Override public void onUndeploy(ClassLoader ldr) {
+        impl.context().onUndeploy(ldr);
+    }
+}


[11/59] [abbrv] ignite git commit: ignite-2065: rename "portable" packages to "binary"

Posted by ak...@apache.org.
http://git-wip-us.apache.org/repos/asf/ignite/blob/1dbf20e0/modules/core/src/test/java/org/apache/ignite/internal/binary/BinaryObjectBuilderAdditionalSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/binary/BinaryObjectBuilderAdditionalSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/binary/BinaryObjectBuilderAdditionalSelfTest.java
new file mode 100644
index 0000000..50f74eb
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/binary/BinaryObjectBuilderAdditionalSelfTest.java
@@ -0,0 +1,1264 @@
+/*
+ * 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.binary;
+
+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 junit.framework.TestCase;
+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.binary.mutabletest.GridPortableTestClasses;
+import org.apache.ignite.internal.binary.builder.BinaryObjectBuilderImpl;
+import org.apache.ignite.internal.binary.builder.PortableBuilderEnum;
+import org.apache.ignite.internal.binary.mutabletest.GridBinaryMarshalerAwareTestClass;
+import org.apache.ignite.internal.processors.cache.binary.CacheObjectBinaryProcessorImpl;
+import org.apache.ignite.internal.processors.cache.binary.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;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.Date;
+import java.util.HashSet;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+import java.util.Objects;
+import java.util.Set;
+import java.util.UUID;
+
+import static org.apache.ignite.cache.CacheMode.REPLICATED;
+
+/**
+ *
+ */
+public class BinaryObjectBuilderAdditionalSelfTest extends GridCommonAbstractTest {
+    /** {@inheritDoc} */
+    @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception {
+        IgniteConfiguration cfg = super.getConfiguration(gridName);
+
+        CacheConfiguration cacheCfg = new CacheConfiguration();
+
+        cacheCfg.setCacheMode(REPLICATED);
+
+        cfg.setCacheConfiguration(cacheCfg);
+
+        BinaryConfiguration bCfg = new BinaryConfiguration();
+
+        bCfg.setCompactFooter(compactFooter());
+
+        bCfg.setClassNames(Arrays.asList("org.apache.ignite.internal.binary.mutabletest.*"));
+
+        cfg.setMarshaller(new BinaryMarshaller());
+
+        return cfg;
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void beforeTestsStarted() throws Exception {
+        startGrids(1);
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void afterTestsStopped() throws Exception {
+        stopAllGrids();
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void afterTest() throws Exception {
+        jcache(0).clear();
+    }
+
+    /**
+     * @return Compact footer.
+     */
+    protected boolean compactFooter() {
+        return true;
+    }
+
+    /**
+     * @return Portables API.
+     */
+    protected IgniteBinary portables() {
+        return grid(0).binary();
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testSimpleTypeFieldRead() throws Exception {
+        GridPortableTestClasses.TestObjectAllTypes exp = new GridPortableTestClasses.TestObjectAllTypes();
+
+        exp.setDefaultData();
+
+        BinaryObjectBuilder mutPo = wrap(exp);
+
+        for (Field field : GridPortableTestClasses.TestObjectAllTypes.class.getDeclaredFields()) {
+            Object expVal = field.get(exp);
+            Object actVal = mutPo.getField(field.getName());
+
+            switch (field.getName()) {
+                case "anEnum":
+                    assertEquals(((PortableBuilderEnum)actVal).getOrdinal(), ((Enum)expVal).ordinal());
+                    break;
+
+                case "enumArr": {
+                    PortableBuilderEnum[] actArr = (PortableBuilderEnum[])actVal;
+                    Enum[] expArr = (Enum[])expVal;
+
+                    assertEquals(expArr.length, actArr.length);
+
+                    for (int i = 0; i < actArr.length; i++)
+                        assertEquals(expArr[i].ordinal(), actArr[i].getOrdinal());
+
+                    break;
+                }
+            }
+        }
+    }
+
+    /**
+     *
+     */
+    public void testSimpleTypeFieldSerialize() {
+        GridPortableTestClasses.TestObjectAllTypes exp = new GridPortableTestClasses.TestObjectAllTypes();
+
+        exp.setDefaultData();
+
+        BinaryObjectBuilderImpl mutPo = wrap(exp);
+
+        GridPortableTestClasses.TestObjectAllTypes res = mutPo.build().deserialize();
+
+        GridTestUtils.deepEquals(exp, res);
+    }
+
+    /**
+     * @throws Exception If any error occurs.
+     */
+    public void testSimpleTypeFieldOverride() throws Exception {
+        GridPortableTestClasses.TestObjectAllTypes exp = new GridPortableTestClasses.TestObjectAllTypes();
+
+        exp.setDefaultData();
+
+        BinaryObjectBuilderImpl mutPo = wrap(new GridPortableTestClasses.TestObjectAllTypes());
+
+        for (Field field : GridPortableTestClasses.TestObjectAllTypes.class.getDeclaredFields())
+            mutPo.setField(field.getName(), field.get(exp));
+
+        GridPortableTestClasses.TestObjectAllTypes res = mutPo.build().deserialize();
+
+        GridTestUtils.deepEquals(exp, res);
+    }
+
+    /**
+     * @throws Exception If any error occurs.
+     */
+    public void testSimpleTypeFieldSetNull() throws Exception {
+        GridPortableTestClasses.TestObjectAllTypes exp = new GridPortableTestClasses.TestObjectAllTypes();
+
+        exp.setDefaultData();
+
+        BinaryObjectBuilderImpl mutPo = wrap(exp);
+
+        for (Field field : GridPortableTestClasses.TestObjectAllTypes.class.getDeclaredFields()) {
+            if (!field.getType().isPrimitive())
+                mutPo.setField(field.getName(), null);
+        }
+
+        GridPortableTestClasses.TestObjectAllTypes res = mutPo.build().deserialize();
+
+        for (Field field : GridPortableTestClasses.TestObjectAllTypes.class.getDeclaredFields()) {
+            if (!field.getType().isPrimitive())
+                assertNull(field.getName(), field.get(res));
+        }
+    }
+
+    /**
+     * @throws IgniteCheckedException If any error occurs.
+     */
+    public void testMakeCyclicDependency() throws IgniteCheckedException {
+        GridPortableTestClasses.TestObjectOuter outer = new GridPortableTestClasses.TestObjectOuter();
+        outer.inner = new GridPortableTestClasses.TestObjectInner();
+
+        BinaryObjectBuilderImpl mutOuter = wrap(outer);
+
+        BinaryObjectBuilderImpl mutInner = mutOuter.getField("inner");
+
+        mutInner.setField("outer", mutOuter);
+        mutInner.setField("foo", mutInner);
+
+        GridPortableTestClasses.TestObjectOuter res = mutOuter.build().deserialize();
+
+        assertEquals(res, res.inner.outer);
+        assertEquals(res.inner, res.inner.foo);
+    }
+
+    /**
+     *
+     */
+    public void testDateArrayModification() {
+        GridPortableTestClasses.TestObjectAllTypes obj = new GridPortableTestClasses.TestObjectAllTypes();
+
+        obj.dateArr =  new Date[] {new Date(11111), new Date(11111), new Date(11111)};
+
+        BinaryObjectBuilderImpl mutObj = wrap(obj);
+
+        Date[] arr = mutObj.getField("dateArr");
+        arr[0] = new Date(22222);
+
+        GridPortableTestClasses.TestObjectAllTypes res = mutObj.build().deserialize();
+
+        Assert.assertArrayEquals(new Date[] {new Date(22222), new Date(11111), new Date(11111)}, res.dateArr);
+    }
+
+    /**
+     *
+     */
+    public void testTimestampArrayModification() {
+        GridPortableTestClasses.TestObjectAllTypes obj = new GridPortableTestClasses.TestObjectAllTypes();
+
+        obj.tsArr = new Timestamp[] {new Timestamp(111222333), new Timestamp(222333444)};
+
+        BinaryObjectBuilderImpl mutObj = wrap(obj);
+
+        Timestamp[] arr = mutObj.getField("tsArr");
+        arr[0] = new Timestamp(333444555);
+
+        GridPortableTestClasses.TestObjectAllTypes res = mutObj.build().deserialize();
+
+        Assert.assertArrayEquals(new Timestamp[] {new Timestamp(333444555), new Timestamp(222333444)}, res.tsArr);
+    }
+
+    /**
+     *
+     */
+    public void testUUIDArrayModification() {
+        GridPortableTestClasses.TestObjectAllTypes obj = new GridPortableTestClasses.TestObjectAllTypes();
+
+        obj.uuidArr = new UUID[] {new UUID(1, 1), new UUID(1, 1), new UUID(1, 1)};
+
+        BinaryObjectBuilderImpl mutObj = wrap(obj);
+
+        UUID[] arr = mutObj.getField("uuidArr");
+        arr[0] = new UUID(2, 2);
+
+        GridPortableTestClasses.TestObjectAllTypes res = mutObj.build().deserialize();
+
+        Assert.assertArrayEquals(new UUID[] {new UUID(2, 2), new UUID(1, 1), new UUID(1, 1)}, res.uuidArr);
+    }
+
+    /**
+     *
+     */
+    public void testDecimalArrayModification() {
+        GridPortableTestClasses.TestObjectAllTypes obj = new GridPortableTestClasses.TestObjectAllTypes();
+
+        obj.bdArr = new BigDecimal[] {new BigDecimal(1000), new BigDecimal(1000), new BigDecimal(1000)};
+
+        BinaryObjectBuilderImpl mutObj = wrap(obj);
+
+        BigDecimal[] arr = mutObj.getField("bdArr");
+        arr[0] = new BigDecimal(2000);
+
+        GridPortableTestClasses.TestObjectAllTypes res = mutObj.build().deserialize();
+
+        Assert.assertArrayEquals(new BigDecimal[] {new BigDecimal(1000), new BigDecimal(1000), new BigDecimal(1000)},
+            res.bdArr);
+    }
+
+    /**
+     *
+     */
+    public void testBooleanArrayModification() {
+        GridPortableTestClasses.TestObjectAllTypes obj = new GridPortableTestClasses.TestObjectAllTypes();
+
+        obj.zArr = new boolean[] {false, false, false};
+
+        BinaryObjectBuilderImpl mutObj = wrap(obj);
+
+        boolean[] arr = mutObj.getField("zArr");
+        arr[0] = true;
+
+        GridPortableTestClasses.TestObjectAllTypes res = mutObj.build().deserialize();
+
+        boolean[] expected = new boolean[] {true, false, false};
+
+        assertEquals(expected.length, res.zArr.length);
+
+        for (int i = 0; i < expected.length; i++)
+            assertEquals(expected[i], res.zArr[i]);
+    }
+
+    /**
+     *
+     */
+    public void testCharArrayModification() {
+        GridPortableTestClasses.TestObjectAllTypes obj = new GridPortableTestClasses.TestObjectAllTypes();
+
+        obj.cArr = new char[] {'a', 'a', 'a'};
+
+        BinaryObjectBuilderImpl mutObj = wrap(obj);
+
+        char[] arr = mutObj.getField("cArr");
+        arr[0] = 'b';
+
+        GridPortableTestClasses.TestObjectAllTypes res = mutObj.build().deserialize();
+
+        Assert.assertArrayEquals(new char[] {'b', 'a', 'a'}, res.cArr);
+    }
+
+    /**
+     *
+     */
+    public void testDoubleArrayModification() {
+        GridPortableTestClasses.TestObjectAllTypes obj = new GridPortableTestClasses.TestObjectAllTypes();
+
+        obj.dArr = new double[] {1.0, 1.0, 1.0};
+
+        BinaryObjectBuilderImpl mutObj = wrap(obj);
+
+        double[] arr = mutObj.getField("dArr");
+        arr[0] = 2.0;
+
+        GridPortableTestClasses.TestObjectAllTypes res = mutObj.build().deserialize();
+
+        Assert.assertArrayEquals(new double[] {2.0, 1.0, 1.0}, res.dArr, 0);
+    }
+
+    /**
+     *
+     */
+    public void testFloatArrayModification() {
+        GridPortableTestClasses.TestObjectAllTypes obj = new GridPortableTestClasses.TestObjectAllTypes();
+
+        obj.fArr = new float[] {1.0f, 1.0f, 1.0f};
+
+        BinaryObjectBuilderImpl mutObj = wrap(obj);
+
+        float[] arr = mutObj.getField("fArr");
+        arr[0] = 2.0f;
+
+        BinaryObject resBinary = mutObj.build();
+
+        GridPortableTestClasses.TestObjectAllTypes res = resBinary.deserialize();
+
+        Assert.assertArrayEquals(new float[] {2.0f, 1.0f, 1.0f}, res.fArr, 0);
+    }
+
+    /**
+     *
+     */
+    public void testLongArrayModification() {
+        GridPortableTestClasses.TestObjectAllTypes obj = new GridPortableTestClasses.TestObjectAllTypes();
+
+        obj.lArr = new long[] {1, 1, 1};
+
+        BinaryObjectBuilderImpl mutObj = wrap(obj);
+
+        long[] arr = mutObj.getField("lArr");
+        arr[0] = 2;
+
+        GridPortableTestClasses.TestObjectAllTypes res = mutObj.build().deserialize();
+
+        Assert.assertArrayEquals(new long[] {2, 1, 1}, res.lArr);
+    }
+
+    /**
+     *
+     */
+    public void testIntArrayModification() {
+        GridPortableTestClasses.TestObjectAllTypes obj = new GridPortableTestClasses.TestObjectAllTypes();
+
+        obj.iArr = new int[] {1, 1, 1};
+
+        BinaryObjectBuilderImpl mutObj = wrap(obj);
+
+        int[] arr = mutObj.getField("iArr");
+        arr[0] = 2;
+
+        GridPortableTestClasses.TestObjectAllTypes res = mutObj.build().deserialize();
+
+        Assert.assertArrayEquals(new int[] {2, 1, 1}, res.iArr);
+    }
+
+    /**
+     *
+     */
+    public void testShortArrayModification() {
+        GridPortableTestClasses.TestObjectAllTypes obj = new GridPortableTestClasses.TestObjectAllTypes();
+
+        obj.sArr = new short[] {1, 1, 1};
+
+        BinaryObjectBuilderImpl mutObj = wrap(obj);
+
+        short[] arr = mutObj.getField("sArr");
+        arr[0] = 2;
+
+        GridPortableTestClasses.TestObjectAllTypes res = mutObj.build().deserialize();
+
+        Assert.assertArrayEquals(new short[] {2, 1, 1}, res.sArr);
+    }
+
+    /**
+     *
+     */
+    public void testByteArrayModification() {
+        GridPortableTestClasses.TestObjectAllTypes obj = new GridPortableTestClasses.TestObjectAllTypes();
+
+        obj.bArr = new byte[] {1, 1, 1};
+
+        BinaryObjectBuilderImpl mutObj = wrap(obj);
+
+        byte[] arr = mutObj.getField("bArr");
+        arr[0] = 2;
+
+        GridPortableTestClasses.TestObjectAllTypes res = mutObj.build().deserialize();
+
+        Assert.assertArrayEquals(new byte[] {2, 1, 1}, res.bArr);
+    }
+
+    /**
+     *
+     */
+    public void testStringArrayModification() {
+        GridPortableTestClasses.TestObjectAllTypes obj = new GridPortableTestClasses.TestObjectAllTypes();
+
+        obj.strArr = new String[] {"a", "a", "a"};
+
+        BinaryObjectBuilderImpl mutObj = wrap(obj);
+
+        String[] arr = mutObj.getField("strArr");
+        arr[0] = "b";
+
+        GridPortableTestClasses.TestObjectAllTypes res = mutObj.build().deserialize();
+
+        Assert.assertArrayEquals(new String[] {"b", "a", "a"}, res.strArr);
+    }
+
+    /**
+     *
+     */
+    public void testModifyObjectArray() {
+        GridPortableTestClasses.TestObjectContainer obj = new GridPortableTestClasses.TestObjectContainer();
+        obj.foo = new Object[] {"a"};
+
+        BinaryObjectBuilderImpl mutObj = wrap(obj);
+
+        Object[] arr = mutObj.getField("foo");
+
+        Assert.assertArrayEquals(new Object[] {"a"}, arr);
+
+        arr[0] = "b";
+
+        GridPortableTestClasses.TestObjectContainer res = mutObj.build().deserialize();
+
+        Assert.assertArrayEquals(new Object[] {"b"}, (Object[])res.foo);
+    }
+
+    /**
+     *
+     */
+    public void testOverrideObjectArrayField() {
+        BinaryObjectBuilderImpl mutObj = wrap(new GridPortableTestClasses.TestObjectContainer());
+
+        Object[] createdArr = {mutObj, "a", 1, new String[] {"s", "s"}, new byte[] {1, 2}, new UUID(3, 0)};
+
+        mutObj.setField("foo", createdArr.clone());
+
+        GridPortableTestClasses.TestObjectContainer res = mutObj.build().deserialize();
+
+        createdArr[0] = res;
+
+        assertTrue(Objects.deepEquals(createdArr, res.foo));
+    }
+
+    /**
+     *
+     */
+    public void testDeepArray() {
+        GridPortableTestClasses.TestObjectContainer obj = new GridPortableTestClasses.TestObjectContainer();
+        obj.foo = new Object[] {new Object[] {"a", obj}};
+
+        BinaryObjectBuilderImpl mutObj = wrap(obj);
+
+        Object[] arr = (Object[])mutObj.<Object[]>getField("foo")[0];
+
+        assertEquals("a", arr[0]);
+        assertSame(mutObj, arr[1]);
+
+        arr[0] = mutObj;
+
+        GridPortableTestClasses.TestObjectContainer res = mutObj.build().deserialize();
+
+        arr = (Object[])((Object[])res.foo)[0];
+
+        assertSame(arr[0], res);
+        assertSame(arr[0], arr[1]);
+    }
+
+    /**
+     *
+     */
+    public void testArrayListRead() {
+        GridPortableTestClasses.TestObjectContainer obj = new GridPortableTestClasses.TestObjectContainer();
+        obj.foo = Lists.newArrayList(obj, "a");
+
+        BinaryObjectBuilderImpl mutObj = wrap(obj);
+
+        List<Object> list = mutObj.getField("foo");
+
+        assert list.equals(Lists.newArrayList(mutObj, "a"));
+    }
+
+    /**
+     *
+     */
+    public void testArrayListOverride() {
+        GridPortableTestClasses.TestObjectContainer obj = new GridPortableTestClasses.TestObjectContainer();
+
+        BinaryObjectBuilderImpl mutObj = wrap(obj);
+
+        ArrayList<Object> list = Lists.newArrayList(mutObj, "a", Lists.newArrayList(1, 2));
+
+        mutObj.setField("foo", list);
+
+        GridPortableTestClasses.TestObjectContainer res = mutObj.build().deserialize();
+
+        list.set(0, res);
+
+        assertNotSame(list, res.foo);
+        assertEquals(list, res.foo);
+    }
+
+    /**
+     *
+     */
+    public void testArrayListModification() {
+        GridPortableTestClasses.TestObjectContainer obj = new GridPortableTestClasses.TestObjectContainer();
+        obj.foo = Lists.newArrayList("a", "b", "c");
+
+        BinaryObjectBuilderImpl mutObj = wrap(obj);
+
+        List<String> list = mutObj.getField("foo");
+
+        list.add("!"); // "a", "b", "c", "!"
+        list.add(0, "_"); // "_", "a", "b", "c", "!"
+
+        String s = list.remove(1); // "_", "b", "c", "!"
+        assertEquals("a", s);
+
+        assertEquals(Arrays.asList("c", "!"), list.subList(2, 4));
+        assertEquals(1, list.indexOf("b"));
+        assertEquals(1, list.lastIndexOf("b"));
+
+        GridPortableTestClasses.TestObjectContainer res = mutObj.build().deserialize();
+
+        assertTrue(res.foo instanceof ArrayList);
+        assertEquals(Arrays.asList("_", "b", "c", "!"), res.foo);
+    }
+
+    /**
+     *
+     */
+    public void testArrayListClear() {
+        GridPortableTestClasses.TestObjectContainer obj = new GridPortableTestClasses.TestObjectContainer();
+        obj.foo = Lists.newArrayList("a", "b", "c");
+
+        BinaryObjectBuilderImpl mutObj = wrap(obj);
+
+        List<String> list = mutObj.getField("foo");
+
+        list.clear();
+
+        TestCase.assertEquals(Collections.emptyList(), mutObj.build().<GridPortableTestClasses.TestObjectContainer>deserialize().foo);
+    }
+
+    /**
+     *
+     */
+    public void testArrayListWriteUnmodifiable() {
+        GridPortableTestClasses.TestObjectContainer obj = new GridPortableTestClasses.TestObjectContainer();
+
+        ArrayList<Object> src = Lists.newArrayList(obj, "a", "b", "c");
+
+        obj.foo = src;
+
+        BinaryObjectBuilderImpl mutObj = wrap(obj);
+
+        GridPortableTestClasses.TestObjectContainer deserialized = mutObj.build().deserialize();
+
+        List<Object> res = (List<Object>)deserialized.foo;
+
+        src.set(0, deserialized);
+
+        assertEquals(src, res);
+    }
+
+    /**
+     *
+     */
+    public void testLinkedListRead() {
+        GridPortableTestClasses.TestObjectContainer obj = new GridPortableTestClasses.TestObjectContainer();
+        obj.foo = Lists.newLinkedList(Arrays.asList(obj, "a"));
+
+        BinaryObjectBuilderImpl mutObj = wrap(obj);
+
+        List<Object> list = mutObj.getField("foo");
+
+        assert list.equals(Lists.newLinkedList(Arrays.asList(mutObj, "a")));
+    }
+
+    /**
+     *
+     */
+    public void testLinkedListOverride() {
+        GridPortableTestClasses.TestObjectContainer obj = new GridPortableTestClasses.TestObjectContainer();
+
+        BinaryObjectBuilderImpl mutObj = wrap(obj);
+
+        List<Object> list = Lists.newLinkedList(Arrays.asList(mutObj, "a", Lists.newLinkedList(Arrays.asList(1, 2))));
+
+        mutObj.setField("foo", list);
+
+        GridPortableTestClasses.TestObjectContainer res = mutObj.build().deserialize();
+
+        list.set(0, res);
+
+        assertNotSame(list, res.foo);
+        assertEquals(list, res.foo);
+    }
+
+    /**
+     *
+     */
+    public void testLinkedListModification() {
+        GridPortableTestClasses.TestObjectContainer obj = new GridPortableTestClasses.TestObjectContainer();
+
+        obj.foo = Lists.newLinkedList(Arrays.asList("a", "b", "c"));
+
+        BinaryObjectBuilderImpl mutObj = wrap(obj);
+
+        List<String> list = mutObj.getField("foo");
+
+        list.add("!"); // "a", "b", "c", "!"
+        list.add(0, "_"); // "_", "a", "b", "c", "!"
+
+        String s = list.remove(1); // "_", "b", "c", "!"
+        assertEquals("a", s);
+
+        assertEquals(Arrays.asList("c", "!"), list.subList(2, 4));
+        assertEquals(1, list.indexOf("b"));
+        assertEquals(1, list.lastIndexOf("b"));
+
+        GridPortableTestClasses.TestObjectContainer res = mutObj.build().deserialize();
+
+        assertTrue(res.foo instanceof LinkedList);
+        assertEquals(Arrays.asList("_", "b", "c", "!"), res.foo);
+    }
+
+    /**
+     *
+     */
+    public void testLinkedListWriteUnmodifiable() {
+        GridPortableTestClasses.TestObjectContainer obj = new GridPortableTestClasses.TestObjectContainer();
+
+        LinkedList<Object> src = Lists.newLinkedList(Arrays.asList(obj, "a", "b", "c"));
+
+        obj.foo = src;
+
+        BinaryObjectBuilderImpl mutObj = wrap(obj);
+
+        GridPortableTestClasses.TestObjectContainer deserialized = mutObj.build().deserialize();
+
+        List<Object> res = (List<Object>)deserialized.foo;
+
+        src.set(0, deserialized);
+
+        assertEquals(src, res);
+    }
+
+    /**
+     *
+     */
+    public void testHashSetRead() {
+        GridPortableTestClasses.TestObjectContainer obj = new GridPortableTestClasses.TestObjectContainer();
+        obj.foo = Sets.newHashSet(obj, "a");
+
+        BinaryObjectBuilderImpl mutObj = wrap(obj);
+
+        Set<Object> set = mutObj.getField("foo");
+
+        assert set.equals(Sets.newHashSet(mutObj, "a"));
+    }
+
+    /**
+     *
+     */
+    public void testHashSetOverride() {
+        GridPortableTestClasses.TestObjectContainer obj = new GridPortableTestClasses.TestObjectContainer();
+
+        BinaryObjectBuilderImpl mutObj = wrap(obj);
+
+        Set<Object> c = Sets.newHashSet(mutObj, "a", Sets.newHashSet(1, 2));
+
+        mutObj.setField("foo", c);
+
+        GridPortableTestClasses.TestObjectContainer res = mutObj.build().deserialize();
+
+        c.remove(mutObj);
+        c.add(res);
+
+        assertNotSame(c, res.foo);
+        assertEquals(c, res.foo);
+    }
+
+    /**
+     *
+     */
+    public void testHashSetModification() {
+        GridPortableTestClasses.TestObjectContainer obj = new GridPortableTestClasses.TestObjectContainer();
+        obj.foo = Sets.newHashSet("a", "b", "c");
+
+        BinaryObjectBuilderImpl mutObj = wrap(obj);
+
+        Set<String> set = mutObj.getField("foo");
+
+        set.remove("b");
+        set.add("!");
+
+        assertEquals(Sets.newHashSet("a", "!", "c"), set);
+        assertTrue(set.contains("a"));
+        assertTrue(set.contains("!"));
+
+        GridPortableTestClasses.TestObjectContainer res = mutObj.build().deserialize();
+
+        assertTrue(res.foo instanceof HashSet);
+        assertEquals(Sets.newHashSet("a", "!", "c"), res.foo);
+    }
+
+    /**
+     *
+     */
+    public void testHashSetWriteUnmodifiable() {
+        GridPortableTestClasses.TestObjectContainer obj = new GridPortableTestClasses.TestObjectContainer();
+
+        Set<Object> src = Sets.newHashSet(obj, "a", "b", "c");
+
+        obj.foo = src;
+
+        GridPortableTestClasses.TestObjectContainer deserialized = wrap(obj).build().deserialize();
+
+        Set<Object> res = (Set<Object>)deserialized.foo;
+
+        src.remove(obj);
+        src.add(deserialized);
+
+        assertEquals(src, res);
+    }
+
+    /**
+     *
+     */
+    public void testMapRead() {
+        GridPortableTestClasses.TestObjectContainer obj = new GridPortableTestClasses.TestObjectContainer();
+        obj.foo = Maps.newHashMap(ImmutableMap.of(obj, "a", "b", obj));
+
+        BinaryObjectBuilderImpl mutObj = wrap(obj);
+
+        Map<Object, Object> map = mutObj.getField("foo");
+
+        assert map.equals(ImmutableMap.of(mutObj, "a", "b", mutObj));
+    }
+
+    /**
+     *
+     */
+    public void testMapOverride() {
+        GridPortableTestClasses.TestObjectContainer obj = new GridPortableTestClasses.TestObjectContainer();
+
+        BinaryObjectBuilderImpl mutObj = wrap(obj);
+
+        Map<Object, Object> map = Maps.newHashMap(ImmutableMap.of(mutObj, "a", "b", mutObj));
+
+        mutObj.setField("foo", map);
+
+        GridPortableTestClasses.TestObjectContainer res = mutObj.build().deserialize();
+
+        assertEquals(ImmutableMap.of(res, "a", "b", res), res.foo);
+    }
+
+    /**
+     *
+     */
+    public void testMapModification() {
+        GridPortableTestClasses.TestObjectContainer obj = new GridPortableTestClasses.TestObjectContainer();
+        obj.foo = Maps.newHashMap(ImmutableMap.of(1, "a", 2, "b"));
+
+        BinaryObjectBuilderImpl mutObj = wrap(obj);
+
+        Map<Object, Object> map = mutObj.getField("foo");
+
+        map.put(3, mutObj);
+        Object rmv = map.remove(1);
+
+        assertEquals("a", rmv);
+
+        GridPortableTestClasses.TestObjectContainer res = mutObj.build().deserialize();
+
+        assertEquals(ImmutableMap.of(2, "b", 3, res), res.foo);
+    }
+
+    /**
+     *
+     */
+    public void testEnumArrayModification() {
+        GridPortableTestClasses.TestObjectAllTypes obj = new GridPortableTestClasses.TestObjectAllTypes();
+
+        obj.enumArr = new GridPortableTestClasses.TestObjectEnum[] {GridPortableTestClasses.TestObjectEnum.A, GridPortableTestClasses.TestObjectEnum.B};
+
+        BinaryObjectBuilderImpl mutObj = wrap(obj);
+
+        PortableBuilderEnum[] arr = mutObj.getField("enumArr");
+        arr[0] = new PortableBuilderEnum(mutObj.typeId(), GridPortableTestClasses.TestObjectEnum.B);
+
+        GridPortableTestClasses.TestObjectAllTypes res = mutObj.build().deserialize();
+
+        Assert.assertArrayEquals(new GridPortableTestClasses.TestObjectEnum[] {GridPortableTestClasses.TestObjectEnum.A, GridPortableTestClasses.TestObjectEnum.B}, res.enumArr);
+    }
+
+    /**
+     *
+     */
+    public void testEditObjectWithRawData() {
+        GridBinaryMarshalerAwareTestClass obj = new GridBinaryMarshalerAwareTestClass();
+
+        obj.s = "a";
+        obj.sRaw = "aa";
+
+        BinaryObjectBuilderImpl mutableObj = wrap(obj);
+
+        mutableObj.setField("s", "z");
+
+        GridBinaryMarshalerAwareTestClass res = mutableObj.build().deserialize();
+        assertEquals("z", res.s);
+        assertEquals("aa", res.sRaw);
+    }
+
+    /**
+     *
+     */
+    public void testHashCode() {
+        GridPortableTestClasses.TestObjectContainer obj = new GridPortableTestClasses.TestObjectContainer();
+
+        BinaryObjectBuilderImpl mutableObj = wrap(obj);
+
+        assertEquals(obj.hashCode(), mutableObj.build().hashCode());
+
+        mutableObj.hashCode(25);
+
+        assertEquals(25, mutableObj.build().hashCode());
+    }
+
+    /**
+     *
+     */
+    public void testCollectionsInCollection() {
+        GridPortableTestClasses.TestObjectContainer obj = new GridPortableTestClasses.TestObjectContainer();
+        obj.foo = Lists.newArrayList(
+            Lists.newArrayList(1, 2),
+            Lists.newLinkedList(Arrays.asList(1, 2)),
+            Sets.newHashSet("a", "b"),
+            Sets.newLinkedHashSet(Arrays.asList("a", "b")),
+            Maps.newHashMap(ImmutableMap.of(1, "a", 2, "b")));
+
+        GridPortableTestClasses.TestObjectContainer deserialized = wrap(obj).build().deserialize();
+
+        assertEquals(obj.foo, deserialized.foo);
+    }
+
+    /**
+     *
+     */
+    public void testMapEntryOverride() {
+        GridPortableTestClasses.TestObjectContainer obj = new GridPortableTestClasses.TestObjectContainer();
+
+        BinaryObjectBuilderImpl mutableObj = wrap(obj);
+
+        mutableObj.setField("foo", new GridMapEntry<>(1, "a"));
+
+        GridPortableTestClasses.TestObjectContainer res = mutableObj.build().deserialize();
+
+        assertEquals(new GridMapEntry<>(1, "a"), res.foo);
+    }
+
+    /**
+     *
+     */
+    public void testMetadataChangingDoublePut() {
+        BinaryObjectBuilderImpl mutableObj = wrap(new GridPortableTestClasses.TestObjectContainer());
+
+        mutableObj.setField("xx567", "a");
+        mutableObj.setField("xx567", "b");
+
+        mutableObj.build();
+
+        BinaryType metadata = portables().type(GridPortableTestClasses.TestObjectContainer.class);
+
+        assertEquals("String", metadata.fieldTypeName("xx567"));
+    }
+
+    /**
+     *
+     */
+    public void testMetadataChangingDoublePut2() {
+        BinaryObjectBuilderImpl mutableObj = wrap(new GridPortableTestClasses.TestObjectContainer());
+
+        mutableObj.setField("xx567", "a");
+        mutableObj.setField("xx567", "b");
+
+        mutableObj.build();
+
+        BinaryType metadata = portables().type(GridPortableTestClasses.TestObjectContainer.class);
+
+        assertEquals("String", metadata.fieldTypeName("xx567"));
+    }
+
+    /**
+     *
+     */
+    public void testMetadataChanging() {
+        GridPortableTestClasses.TestObjectContainer c = new GridPortableTestClasses.TestObjectContainer();
+
+        BinaryObjectBuilderImpl mutableObj = wrap(c);
+
+        mutableObj.setField("intField", 1);
+        mutableObj.setField("intArrField", new int[] {1});
+        mutableObj.setField("arrField", new String[] {"1"});
+        mutableObj.setField("strField", "1");
+        mutableObj.setField("colField", Lists.newArrayList("1"));
+        mutableObj.setField("mapField", Maps.newHashMap(ImmutableMap.of(1, "1")));
+        mutableObj.setField("enumField", GridPortableTestClasses.TestObjectEnum.A);
+        mutableObj.setField("enumArrField", new Enum[] {GridPortableTestClasses.TestObjectEnum.A});
+
+        mutableObj.build();
+
+        BinaryType metadata = portables().type(c.getClass());
+
+        assertTrue(metadata.fieldNames().containsAll(Arrays.asList("intField", "intArrField", "arrField", "strField",
+            "colField", "mapField", "enumField", "enumArrField")));
+
+        assertEquals("int", metadata.fieldTypeName("intField"));
+        assertEquals("int[]", metadata.fieldTypeName("intArrField"));
+        assertEquals("String[]", metadata.fieldTypeName("arrField"));
+        assertEquals("String", metadata.fieldTypeName("strField"));
+        assertEquals("Collection", metadata.fieldTypeName("colField"));
+        assertEquals("Map", metadata.fieldTypeName("mapField"));
+        assertEquals("Enum", metadata.fieldTypeName("enumField"));
+        assertEquals("Enum[]", metadata.fieldTypeName("enumArrField"));
+    }
+
+    /**
+     *
+     */
+    public void testDateInObjectField() {
+        GridPortableTestClasses.TestObjectContainer obj = new GridPortableTestClasses.TestObjectContainer();
+
+        obj.foo = new Date();
+
+        BinaryObjectBuilderImpl mutableObj = wrap(obj);
+
+        assertEquals(Date.class, mutableObj.getField("foo").getClass());
+    }
+
+    /**
+     *
+     */
+    public void testTimestampInObjectField() {
+        GridPortableTestClasses.TestObjectContainer obj = new GridPortableTestClasses.TestObjectContainer();
+
+        obj.foo = new Timestamp(100020003);
+
+        BinaryObjectBuilderImpl mutableObj = wrap(obj);
+
+        assertEquals(Timestamp.class, mutableObj.getField("foo").getClass());
+    }
+
+    /**
+     *
+     */
+    public void testDateInCollection() {
+        GridPortableTestClasses.TestObjectContainer obj = new GridPortableTestClasses.TestObjectContainer();
+
+        obj.foo = Lists.newArrayList(new Date());
+
+        BinaryObjectBuilderImpl mutableObj = wrap(obj);
+
+        assertEquals(Date.class, ((List<?>)mutableObj.getField("foo")).get(0).getClass());
+    }
+
+    /**
+     *
+     */
+    public void testTimestampInCollection() {
+        GridPortableTestClasses.TestObjectContainer obj = new GridPortableTestClasses.TestObjectContainer();
+
+        obj.foo = Lists.newArrayList(new Timestamp(100020003));
+
+        BinaryObjectBuilderImpl mutableObj = wrap(obj);
+
+        assertEquals(Timestamp.class, ((List<?>)mutableObj.getField("foo")).get(0).getClass());
+    }
+
+    /**
+     *
+     */
+    @SuppressWarnings("AssertEqualsBetweenInconvertibleTypes")
+    public void testDateArrayOverride() {
+        GridPortableTestClasses.TestObjectContainer obj = new GridPortableTestClasses.TestObjectContainer();
+
+        BinaryObjectBuilderImpl mutableObj = wrap(obj);
+
+        Date[] arr = { new Date() };
+
+        mutableObj.setField("foo", arr);
+
+        GridPortableTestClasses.TestObjectContainer res = mutableObj.build().deserialize();
+
+        assertEquals(Date[].class, res.foo.getClass());
+        assertTrue(Objects.deepEquals(arr, res.foo));
+    }
+
+    /**
+     *
+     */
+    @SuppressWarnings("AssertEqualsBetweenInconvertibleTypes")
+    public void testTimestampArrayOverride() {
+        GridPortableTestClasses.TestObjectContainer obj = new GridPortableTestClasses.TestObjectContainer();
+
+        BinaryObjectBuilderImpl mutableObj = wrap(obj);
+
+        Timestamp[] arr = { new Timestamp(100020003) };
+
+        mutableObj.setField("foo", arr);
+
+        GridPortableTestClasses.TestObjectContainer res = mutableObj.build().deserialize();
+
+        assertEquals(Timestamp[].class, res.foo.getClass());
+        assertTrue(Objects.deepEquals(arr, res.foo));
+    }
+
+    /**
+     *
+     */
+    public void testChangeMap() {
+        GridPortableTestClasses.Addresses addrs = new GridPortableTestClasses.Addresses();
+
+        addrs.addCompany(new GridPortableTestClasses.Company(1, "Google inc", 100,
+            new GridPortableTestClasses.Address("Saint-Petersburg", "Torzhkovskya", 1, 53), "occupation"));
+
+        addrs.addCompany(new GridPortableTestClasses.Company(2, "Apple inc", 100,
+            new GridPortableTestClasses.Address("Saint-Petersburg", "Torzhkovskya", 1, 54), "occupation"));
+
+        addrs.addCompany(new GridPortableTestClasses.Company(3, "Microsoft", 100,
+            new GridPortableTestClasses.Address("Saint-Petersburg", "Torzhkovskya", 1, 55), "occupation"));
+
+        addrs.addCompany(new GridPortableTestClasses.Company(4, "Oracle", 100,
+            new GridPortableTestClasses.Address("Saint-Petersburg", "Nevskiy", 1, 1), "occupation"));
+
+        BinaryObjectBuilderImpl binaryAddres = wrap(addrs);
+
+        Map<String, BinaryObjectBuilderImpl> map = binaryAddres.getField("companyByStreet");
+
+        BinaryObjectBuilderImpl binaryCompanies = map.get("Torzhkovskya");
+
+        List<BinaryObjectBuilderImpl> binaryCompaniesList = binaryCompanies.getField("companies");
+
+        BinaryObjectBuilderImpl company = binaryCompaniesList.get(0);
+
+        assert "Google inc".equals(company.<String>getField("name"));
+
+        binaryCompaniesList.remove(0);
+
+        GridPortableTestClasses.Addresses res = binaryAddres.build().deserialize();
+
+        assertEquals(Arrays.asList("Nevskiy", "Torzhkovskya"), new ArrayList<>(res.getCompanyByStreet().keySet()));
+
+        GridPortableTestClasses.Companies torzhkovskyaCompanies = res.getCompanyByStreet().get("Torzhkovskya");
+
+        assertEquals(2, torzhkovskyaCompanies.size());
+        assertEquals("Apple inc", torzhkovskyaCompanies.get(0).name);
+    }
+
+    /**
+     *
+     */
+    public void testSavingObjectWithNotZeroStart() {
+        GridPortableTestClasses.TestObjectOuter out = new GridPortableTestClasses.TestObjectOuter();
+        GridPortableTestClasses.TestObjectInner inner = new GridPortableTestClasses.TestObjectInner();
+
+        out.inner = inner;
+        inner.outer = out;
+
+        BinaryObjectBuilderImpl builder = wrap(out);
+
+        BinaryObjectBuilderImpl innerBuilder = builder.getField("inner");
+
+        GridPortableTestClasses.TestObjectInner res = innerBuilder.build().deserialize();
+
+        assertSame(res, res.outer.inner);
+    }
+
+    /**
+     *
+     */
+    public void testPortableObjectField() {
+        GridPortableTestClasses.TestObjectContainer container = new GridPortableTestClasses.TestObjectContainer(toPortable(new GridPortableTestClasses.TestObjectArrayList()));
+
+        BinaryObjectBuilderImpl wrapper = wrap(container);
+
+        assertTrue(wrapper.getField("foo") instanceof BinaryObject);
+
+        GridPortableTestClasses.TestObjectContainer deserialized = wrapper.build().deserialize();
+        assertTrue(deserialized.foo instanceof BinaryObject);
+    }
+
+    /**
+     *
+     */
+    public void testAssignPortableObject() {
+        GridPortableTestClasses.TestObjectContainer container = new GridPortableTestClasses.TestObjectContainer();
+
+        BinaryObjectBuilderImpl wrapper = wrap(container);
+
+        wrapper.setField("foo", toPortable(new GridPortableTestClasses.TestObjectArrayList()));
+
+        GridPortableTestClasses.TestObjectContainer deserialized = wrapper.build().deserialize();
+        assertTrue(deserialized.foo instanceof GridPortableTestClasses.TestObjectArrayList);
+    }
+
+    /**
+     *
+     */
+    public void testRemoveFromNewObject() {
+        BinaryObjectBuilderImpl wrapper = newWrapper(GridPortableTestClasses.TestObjectAllTypes.class);
+
+        wrapper.setField("str", "a");
+
+        wrapper.removeField("str");
+
+        TestCase.assertNull(wrapper.build().<GridPortableTestClasses.TestObjectAllTypes>deserialize().str);
+    }
+
+    /**
+     *
+     */
+    public void testRemoveFromExistingObject() {
+        GridPortableTestClasses.TestObjectAllTypes obj = new GridPortableTestClasses.TestObjectAllTypes();
+        obj.setDefaultData();
+
+        BinaryObjectBuilderImpl wrapper = wrap(toPortable(obj));
+
+        wrapper.removeField("str");
+
+        TestCase.assertNull(wrapper.build().<GridPortableTestClasses.TestObjectAllTypes>deserialize().str);
+    }
+
+    /**
+     *
+     */
+    public void testCyclicArrays() {
+        GridPortableTestClasses.TestObjectContainer obj = new GridPortableTestClasses.TestObjectContainer();
+
+        Object[] arr1 = new Object[1];
+        Object[] arr2 = new Object[] {arr1};
+
+        arr1[0] = arr2;
+
+        obj.foo = arr1;
+
+        GridPortableTestClasses.TestObjectContainer res = toPortable(obj).deserialize();
+
+        Object[] resArr = (Object[])res.foo;
+
+        assertSame(((Object[])resArr[0])[0], resArr);
+    }
+
+    /**
+     *
+     */
+    @SuppressWarnings("TypeMayBeWeakened")
+    public void testCyclicArrayList() {
+        GridPortableTestClasses.TestObjectContainer obj = new GridPortableTestClasses.TestObjectContainer();
+
+        List<Object> arr1 = new ArrayList<>();
+        List<Object> arr2 = new ArrayList<>();
+
+        arr1.add(arr2);
+        arr2.add(arr1);
+
+        obj.foo = arr1;
+
+        GridPortableTestClasses.TestObjectContainer res = toPortable(obj).deserialize();
+
+        List<?> resArr = (List<?>)res.foo;
+
+        assertSame(((List<Object>)resArr.get(0)).get(0), resArr);
+    }
+
+    /**
+     * @param obj Object.
+     * @return Object in portable format.
+     */
+    private BinaryObject toPortable(Object obj) {
+        return portables().toBinary(obj);
+    }
+
+    /**
+     * @param obj Object.
+     * @return GridMutablePortableObject.
+     */
+    private BinaryObjectBuilderImpl wrap(Object obj) {
+        return BinaryObjectBuilderImpl.wrap(toPortable(obj));
+    }
+
+    /**
+     * @param aCls Class.
+     * @return Wrapper.
+     */
+    private BinaryObjectBuilderImpl newWrapper(Class<?> aCls) {
+        CacheObjectBinaryProcessorImpl processor = (CacheObjectBinaryProcessorImpl)(
+            (IgniteBinaryImpl)portables()).processor();
+
+        return new BinaryObjectBuilderImpl(processor.portableContext(), processor.typeId(aCls.getName()),
+            aCls.getSimpleName());
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/1dbf20e0/modules/core/src/test/java/org/apache/ignite/internal/binary/BinaryObjectBuilderSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/binary/BinaryObjectBuilderSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/binary/BinaryObjectBuilderSelfTest.java
new file mode 100644
index 0000000..d02347c
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/binary/BinaryObjectBuilderSelfTest.java
@@ -0,0 +1,1100 @@
+/*
+ * 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.binary;
+
+import java.math.BigDecimal;
+import java.sql.Timestamp;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Date;
+import java.util.List;
+import java.util.Map;
+import java.util.UUID;
+import junit.framework.TestCase;
+import org.apache.ignite.IgniteBinary;
+import org.apache.ignite.IgniteCheckedException;
+import org.apache.ignite.binary.BinaryIdMapper;
+import org.apache.ignite.binary.BinaryObject;
+import org.apache.ignite.binary.BinaryObjectBuilder;
+import org.apache.ignite.binary.BinaryType;
+import org.apache.ignite.binary.BinaryTypeConfiguration;
+import org.apache.ignite.configuration.BinaryConfiguration;
+import org.apache.ignite.configuration.IgniteConfiguration;
+import org.apache.ignite.internal.binary.mutabletest.GridPortableTestClasses;
+import org.apache.ignite.internal.binary.builder.BinaryObjectBuilderImpl;
+import org.apache.ignite.internal.processors.cache.binary.CacheObjectBinaryProcessorImpl;
+import org.apache.ignite.internal.util.GridUnsafe;
+import org.apache.ignite.internal.util.typedef.F;
+import org.apache.ignite.testframework.GridTestUtils;
+import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
+import sun.misc.Unsafe;
+
+/**
+ * Portable builder test.
+ */
+@SuppressWarnings("ResultOfMethodCallIgnored")
+public class BinaryObjectBuilderSelfTest extends GridCommonAbstractTest {
+    /** */
+    private static final Unsafe UNSAFE = GridUnsafe.unsafe();
+
+    /** */
+    protected static final long BYTE_ARR_OFF = UNSAFE.arrayBaseOffset(byte[].class);
+
+    /** {@inheritDoc} */
+    @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception {
+        IgniteConfiguration cfg = super.getConfiguration(gridName);
+
+        BinaryTypeConfiguration customTypeCfg = new BinaryTypeConfiguration();
+
+        customTypeCfg.setTypeName(CustomIdMapper.class.getName());
+        customTypeCfg.setIdMapper(new BinaryIdMapper() {
+            @Override public int typeId(String clsName) {
+                return ~BinaryInternalIdMapper.defaultInstance().typeId(clsName);
+            }
+
+            @Override public int fieldId(int typeId, String fieldName) {
+                return typeId + ~BinaryInternalIdMapper.defaultInstance().fieldId(typeId, fieldName);
+            }
+        });
+
+        BinaryConfiguration bCfg = new BinaryConfiguration();
+
+        bCfg.setCompactFooter(compactFooter());
+
+        bCfg.setTypeConfigurations(Arrays.asList(
+            new BinaryTypeConfiguration(Key.class.getName()),
+            new BinaryTypeConfiguration(Value.class.getName()),
+            new BinaryTypeConfiguration("org.gridgain.grid.internal.util.portable.mutabletest.*"),
+            customTypeCfg));
+
+        cfg.setBinaryConfiguration(bCfg);
+
+        cfg.setMarshaller(new BinaryMarshaller());
+
+        return cfg;
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void beforeTestsStarted() throws Exception {
+        startGrids(1);
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void afterTestsStopped() throws Exception {
+        stopAllGrids();
+    }
+
+    /**
+     * @return Whether to use compact footer.
+     */
+    protected boolean compactFooter() {
+        return true;
+    }
+
+    /**
+     *
+     */
+    public void testAllFieldsSerialization() {
+        GridPortableTestClasses.TestObjectAllTypes obj = new GridPortableTestClasses.TestObjectAllTypes();
+        obj.setDefaultData();
+        obj.enumArr = null;
+
+        GridPortableTestClasses.TestObjectAllTypes deserialized = builder(toPortable(obj)).build().deserialize();
+
+        GridTestUtils.deepEquals(obj, deserialized);
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testNullField() throws Exception {
+        BinaryObjectBuilder builder = builder("Class");
+
+        builder.hashCode(42);
+
+        builder.setField("objField", (Object)null);
+
+        builder.setField("otherField", "value");
+
+        BinaryObject obj = builder.build();
+
+        assertNull(obj.field("objField"));
+        assertEquals("value", obj.field("otherField"));
+        assertEquals(42, obj.hashCode());
+
+        builder = builder(obj);
+
+        builder.setField("objField", "value");
+        builder.setField("otherField", (Object)null);
+
+        obj = builder.build();
+
+        assertNull(obj.field("otherField"));
+        assertEquals("value", obj.field("objField"));
+        assertEquals(42, obj.hashCode());
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testByteField() throws Exception {
+        BinaryObjectBuilder builder = builder("Class");
+
+        builder.hashCode(100);
+
+        builder.setField("byteField", (byte)1);
+
+        BinaryObject po = builder.build();
+
+        assertEquals("class".hashCode(), po.type().typeId());
+        assertEquals(100, po.hashCode());
+
+        assertEquals((byte) 1, po.<Byte>field("byteField").byteValue());
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testShortField() throws Exception {
+        BinaryObjectBuilder builder = builder("Class");
+
+        builder.hashCode(100);
+
+        builder.setField("shortField", (short)1);
+
+        BinaryObject po = builder.build();
+
+        assertEquals("class".hashCode(), po.type().typeId());
+        assertEquals(100, po.hashCode());
+
+        assertEquals((short)1, po.<Short>field("shortField").shortValue());
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testIntField() throws Exception {
+        BinaryObjectBuilder builder = builder("Class");
+
+        builder.hashCode(100);
+
+        builder.setField("intField", 1);
+
+        BinaryObject po = builder.build();
+
+        assertEquals("class".hashCode(), po.type().typeId());
+        assertEquals(100, po.hashCode());
+
+        assertEquals(1, po.<Integer>field("intField").intValue());
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testLongField() throws Exception {
+        BinaryObjectBuilder builder = builder("Class");
+
+        builder.hashCode(100);
+
+        builder.setField("longField", 1L);
+
+        BinaryObject po = builder.build();
+
+        assertEquals("class".hashCode(), po.type().typeId());
+        assertEquals(100, po.hashCode());
+
+        assertEquals(1L, po.<Long>field("longField").longValue());
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testFloatField() throws Exception {
+        BinaryObjectBuilder builder = builder("Class");
+
+        builder.hashCode(100);
+
+        builder.setField("floatField", 1.0f);
+
+        BinaryObject po = builder.build();
+
+        assertEquals("class".hashCode(), po.type().typeId());
+        assertEquals(100, po.hashCode());
+
+        assertEquals(1.0f, po.<Float>field("floatField").floatValue(), 0);
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testDoubleField() throws Exception {
+        BinaryObjectBuilder builder = builder("Class");
+
+        builder.hashCode(100);
+
+        builder.setField("doubleField", 1.0d);
+
+        BinaryObject po = builder.build();
+
+        assertEquals("class".hashCode(), po.type().typeId());
+        assertEquals(100, po.hashCode());
+
+        assertEquals(1.0d, po.<Double>field("doubleField").doubleValue(), 0);
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testCharField() throws Exception {
+        BinaryObjectBuilder builder = builder("Class");
+
+        builder.hashCode(100);
+
+        builder.setField("charField", (char)1);
+
+        BinaryObject po = builder.build();
+
+        assertEquals("class".hashCode(), po.type().typeId());
+        assertEquals(100, po.hashCode());
+
+        assertEquals((char)1, po.<Character>field("charField").charValue());
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testBooleanField() throws Exception {
+        BinaryObjectBuilder builder = builder("Class");
+
+        builder.hashCode(100);
+
+        builder.setField("booleanField", true);
+
+        BinaryObject po = builder.build();
+
+        assertEquals("class".hashCode(), po.type().typeId());
+        assertEquals(100, po.hashCode());
+
+        assertTrue(po.<Boolean>field("booleanField"));
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testDecimalField() throws Exception {
+        BinaryObjectBuilder builder = builder("Class");
+
+        builder.hashCode(100);
+
+        builder.setField("decimalField", BigDecimal.TEN);
+
+        BinaryObject po = builder.build();
+
+        assertEquals("class".hashCode(), po.type().typeId());
+        assertEquals(100, po.hashCode());
+
+        assertEquals(BigDecimal.TEN, po.<BigDecimal>field("decimalField"));
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testStringField() throws Exception {
+        BinaryObjectBuilder builder = builder("Class");
+
+        builder.hashCode(100);
+
+        builder.setField("stringField", "str");
+
+        BinaryObject po = builder.build();
+
+        assertEquals("class".hashCode(), po.type().typeId());
+        assertEquals(100, po.hashCode());
+
+        assertEquals("str", po.<String>field("stringField"));
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testDateField() throws Exception {
+        Date date = new Date();
+
+        assertEquals(date, builder("C").setField("d", date).build().<Date>field("d"));
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testTimestampField() throws Exception {
+        Timestamp ts = new Timestamp(new Date().getTime());
+        ts.setNanos(1000);
+
+        assertEquals(ts, builder("C").setField("t", ts).build().<Timestamp>field("t"));
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testUuidField() throws Exception {
+        BinaryObjectBuilder builder = builder("Class");
+
+        builder.hashCode(100);
+
+        UUID uuid = UUID.randomUUID();
+
+        builder.setField("uuidField", uuid);
+
+        BinaryObject po = builder.build();
+
+        assertEquals("class".hashCode(), po.type().typeId());
+        assertEquals(100, po.hashCode());
+
+        assertEquals(uuid, po.<UUID>field("uuidField"));
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testByteArrayField() throws Exception {
+        BinaryObjectBuilder builder = builder("Class");
+
+        builder.hashCode(100);
+
+        builder.setField("byteArrayField", new byte[] {1, 2, 3});
+
+        BinaryObject po = builder.build();
+
+        assertEquals("class".hashCode(), po.type().typeId());
+        assertEquals(100, po.hashCode());
+
+        assertTrue(Arrays.equals(new byte[] {1, 2, 3}, po.<byte[]>field("byteArrayField")));
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testShortArrayField() throws Exception {
+        BinaryObjectBuilder builder = builder("Class");
+
+        builder.hashCode(100);
+
+        builder.setField("shortArrayField", new short[] {1, 2, 3});
+
+        BinaryObject po = builder.build();
+
+        assertEquals("class".hashCode(), po.type().typeId());
+        assertEquals(100, po.hashCode());
+
+        assertTrue(Arrays.equals(new short[] {1, 2, 3}, po.<short[]>field("shortArrayField")));
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testIntArrayField() throws Exception {
+        BinaryObjectBuilder builder = builder("Class");
+
+        builder.hashCode(100);
+
+        builder.setField("intArrayField", new int[] {1, 2, 3});
+
+        BinaryObject po = builder.build();
+
+        assertEquals("class".hashCode(), po.type().typeId());
+        assertEquals(100, po.hashCode());
+
+        assertTrue(Arrays.equals(new int[] {1, 2, 3}, po.<int[]>field("intArrayField")));
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testLongArrayField() throws Exception {
+        BinaryObjectBuilder builder = builder("Class");
+
+        builder.hashCode(100);
+
+        builder.setField("longArrayField", new long[] {1, 2, 3});
+
+        BinaryObject po = builder.build();
+
+        assertEquals("class".hashCode(), po.type().typeId());
+        assertEquals(100, po.hashCode());
+
+        assertTrue(Arrays.equals(new long[] {1, 2, 3}, po.<long[]>field("longArrayField")));
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testFloatArrayField() throws Exception {
+        BinaryObjectBuilder builder = builder("Class");
+
+        builder.hashCode(100);
+
+        builder.setField("floatArrayField", new float[] {1, 2, 3});
+
+        BinaryObject po = builder.build();
+
+        assertEquals("class".hashCode(), po.type().typeId());
+        assertEquals(100, po.hashCode());
+
+        assertTrue(Arrays.equals(new float[] {1, 2, 3}, po.<float[]>field("floatArrayField")));
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testDoubleArrayField() throws Exception {
+        BinaryObjectBuilder builder = builder("Class");
+
+        builder.hashCode(100);
+
+        builder.setField("doubleArrayField", new double[] {1, 2, 3});
+
+        BinaryObject po = builder.build();
+
+        assertEquals("class".hashCode(), po.type().typeId());
+        assertEquals(100, po.hashCode());
+
+        assertTrue(Arrays.equals(new double[] {1, 2, 3}, po.<double[]>field("doubleArrayField")));
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testCharArrayField() throws Exception {
+        BinaryObjectBuilder builder = builder("Class");
+
+        builder.hashCode(100);
+
+        builder.setField("charArrayField", new char[] {1, 2, 3});
+
+        BinaryObject po = builder.build();
+
+        assertEquals("class".hashCode(), po.type().typeId());
+        assertEquals(100, po.hashCode());
+
+        assertTrue(Arrays.equals(new char[] {1, 2, 3}, po.<char[]>field("charArrayField")));
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testBooleanArrayField() throws Exception {
+        BinaryObjectBuilder builder = builder("Class");
+
+        builder.hashCode(100);
+
+        builder.setField("booleanArrayField", new boolean[] {true, false});
+
+        BinaryObject po = builder.build();
+
+        assertEquals("class".hashCode(), po.type().typeId());
+        assertEquals(100, po.hashCode());
+
+        boolean[] arr = po.field("booleanArrayField");
+
+        assertEquals(2, arr.length);
+
+        assertTrue(arr[0]);
+        assertFalse(arr[1]);
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testDecimalArrayField() throws Exception {
+        BinaryObjectBuilder builder = builder("Class");
+
+        builder.hashCode(100);
+
+        builder.setField("decimalArrayField", new BigDecimal[] {BigDecimal.ONE, BigDecimal.TEN});
+
+        BinaryObject po = builder.build();
+
+        assertEquals("class".hashCode(), po.type().typeId());
+        assertEquals(100, po.hashCode());
+
+        assertTrue(Arrays.equals(new BigDecimal[] {BigDecimal.ONE, BigDecimal.TEN}, po.<String[]>field("decimalArrayField")));
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testStringArrayField() throws Exception {
+        BinaryObjectBuilder builder = builder("Class");
+
+        builder.hashCode(100);
+
+        builder.setField("stringArrayField", new String[] {"str1", "str2", "str3"});
+
+        BinaryObject po = builder.build();
+
+        assertEquals("class".hashCode(), po.type().typeId());
+        assertEquals(100, po.hashCode());
+
+        assertTrue(Arrays.equals(new String[] {"str1", "str2", "str3"}, po.<String[]>field("stringArrayField")));
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testDateArrayField() throws Exception {
+        Date date1 = new Date();
+        Date date2 = new Date(date1.getTime() + 1000);
+
+        Date[] dateArr = new Date[] { date1, date2 };
+
+        assertTrue(Arrays.equals(dateArr, builder("C").setField("da", dateArr).build().<Date[]>field("da")));
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testTimestampArrayField() throws Exception {
+        Timestamp ts1 = new Timestamp(new Date().getTime());
+        Timestamp ts2 = new Timestamp(new Date().getTime() + 1000);
+
+        ts1.setNanos(1000);
+        ts2.setNanos(2000);
+
+        Timestamp[] tsArr = new Timestamp[] { ts1, ts2 };
+
+        assertTrue(Arrays.equals(tsArr, builder("C").setField("ta", tsArr).build().<Timestamp[]>field("ta")));
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testUuidArrayField() throws Exception {
+        BinaryObjectBuilder builder = builder("Class");
+
+        builder.hashCode(100);
+
+        UUID[] arr = new UUID[] {UUID.randomUUID(), UUID.randomUUID()};
+
+        builder.setField("uuidArrayField", arr);
+
+        BinaryObject po = builder.build();
+
+        assertEquals("class".hashCode(), po.type().typeId());
+        assertEquals(100, po.hashCode());
+
+        assertTrue(Arrays.equals(arr, po.<UUID[]>field("uuidArrayField")));
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testObjectField() throws Exception {
+        BinaryObjectBuilder builder = builder("Class");
+
+        builder.hashCode(100);
+
+        builder.setField("objectField", new Value(1));
+
+        BinaryObject po = builder.build();
+
+        assertEquals("class".hashCode(), po.type().typeId());
+        assertEquals(100, po.hashCode());
+
+        assertEquals(1, po.<BinaryObject>field("objectField").<Value>deserialize().i);
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testObjectArrayField() throws Exception {
+        BinaryObjectBuilder builder = builder("Class");
+
+        builder.hashCode(100);
+
+        builder.setField("objectArrayField", new Value[] {new Value(1), new Value(2)});
+
+        BinaryObject po = builder.build();
+
+        assertEquals("class".hashCode(), po.type().typeId());
+        assertEquals(100, po.hashCode());
+
+        Object[] arr = po.field("objectArrayField");
+
+        assertEquals(2, arr.length);
+
+        assertEquals(1, ((BinaryObject)arr[0]).<Value>deserialize().i);
+        assertEquals(2, ((BinaryObject)arr[1]).<Value>deserialize().i);
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testCollectionField() throws Exception {
+        BinaryObjectBuilder builder = builder("Class");
+
+        builder.hashCode(100);
+
+        builder.setField("collectionField", Arrays.asList(new Value(1), new Value(2)));
+
+        BinaryObject po = builder.build();
+
+        assertEquals("class".hashCode(), po.type().typeId());
+        assertEquals(100, po.hashCode());
+
+        List<BinaryObject> list = po.field("collectionField");
+
+        assertEquals(2, list.size());
+
+        assertEquals(1, list.get(0).<Value>deserialize().i);
+        assertEquals(2, list.get(1).<Value>deserialize().i);
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testMapField() throws Exception {
+        BinaryObjectBuilder builder = builder("Class");
+
+        builder.hashCode(100);
+
+        builder.setField("mapField", F.asMap(new Key(1), new Value(1), new Key(2), new Value(2)));
+
+        BinaryObject po = builder.build();
+
+        assertEquals("class".hashCode(), po.type().typeId());
+        assertEquals(100, po.hashCode());
+
+        Map<BinaryObject, BinaryObject> map = po.field("mapField");
+
+        assertEquals(2, map.size());
+
+        for (Map.Entry<BinaryObject, BinaryObject> e : map.entrySet())
+            assertEquals(e.getKey().<Key>deserialize().i, e.getValue().<Value>deserialize().i);
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testSeveralFields() throws Exception {
+        BinaryObjectBuilder builder = builder("Class");
+
+        builder.hashCode(100);
+
+        builder.setField("i", 111);
+        builder.setField("f", 111.111f);
+        builder.setField("iArr", new int[] {1, 2, 3});
+        builder.setField("obj", new Key(1));
+        builder.setField("col", Arrays.asList(new Value(1), new Value(2)));
+
+        BinaryObject po = builder.build();
+
+        assertEquals("class".hashCode(), po.type().typeId());
+        assertEquals(100, po.hashCode());
+
+        assertEquals(111, po.<Integer>field("i").intValue());
+        assertEquals(111.111f, po.<Float>field("f").floatValue(), 0);
+        assertTrue(Arrays.equals(new int[] {1, 2, 3}, po.<int[]>field("iArr")));
+        assertEquals(1, po.<BinaryObject>field("obj").<Key>deserialize().i);
+
+        List<BinaryObject> list = po.field("col");
+
+        assertEquals(2, list.size());
+
+        assertEquals(1, list.get(0).<Value>deserialize().i);
+        assertEquals(2, list.get(1).<Value>deserialize().i);
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testOffheapPortable() throws Exception {
+        BinaryObjectBuilder builder = builder("Class");
+
+        builder.hashCode(100);
+
+        builder.setField("i", 111);
+        builder.setField("f", 111.111f);
+        builder.setField("iArr", new int[] {1, 2, 3});
+        builder.setField("obj", new Key(1));
+        builder.setField("col", Arrays.asList(new Value(1), new Value(2)));
+
+        BinaryObject po = builder.build();
+
+        byte[] arr = ((CacheObjectBinaryProcessorImpl)(grid(0)).context().cacheObjects()).marshal(po);
+
+        long ptr = UNSAFE.allocateMemory(arr.length + 5);
+
+        try {
+            long ptr0 = ptr;
+
+            UNSAFE.putBoolean(null, ptr0++, false);
+
+            UNSAFE.putInt(ptr0, arr.length);
+
+            UNSAFE.copyMemory(arr, BYTE_ARR_OFF, null, ptr0 + 4, arr.length);
+
+            BinaryObject offheapObj = (BinaryObject)
+                ((CacheObjectBinaryProcessorImpl)(grid(0)).context().cacheObjects()).unmarshal(ptr, false);
+
+            assertEquals(BinaryObjectOffheapImpl.class, offheapObj.getClass());
+
+            assertEquals("class".hashCode(), offheapObj.type().typeId());
+            assertEquals(100, offheapObj.hashCode());
+
+            assertEquals(111, offheapObj.<Integer>field("i").intValue());
+            assertEquals(111.111f, offheapObj.<Float>field("f").floatValue(), 0);
+            assertTrue(Arrays.equals(new int[] {1, 2, 3}, offheapObj.<int[]>field("iArr")));
+            assertEquals(1, offheapObj.<BinaryObject>field("obj").<Key>deserialize().i);
+
+            List<BinaryObject> list = offheapObj.field("col");
+
+            assertEquals(2, list.size());
+
+            assertEquals(1, list.get(0).<Value>deserialize().i);
+            assertEquals(2, list.get(1).<Value>deserialize().i);
+
+            assertEquals(po, offheapObj);
+            assertEquals(offheapObj, po);
+        }
+        finally {
+            UNSAFE.freeMemory(ptr);
+        }
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testBuildAndDeserialize() throws Exception {
+        BinaryObjectBuilder builder = builder(Value.class.getName());
+
+        builder.hashCode(100);
+
+        builder.setField("i", 1);
+
+        BinaryObject po = builder.build();
+
+        assertEquals("value".hashCode(), po.type().typeId());
+        assertEquals(100, po.hashCode());
+
+        assertEquals(1, po.<Value>deserialize().i);
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testMetaData2() throws Exception {
+        BinaryObjectBuilder builder = builder("org.test.MetaTest2");
+
+        builder.setField("objectField", "a", Object.class);
+
+        BinaryObject po = builder.build();
+
+        BinaryType meta = po.type();
+
+        assertEquals("MetaTest2", meta.typeName());
+        assertEquals("Object", meta.fieldTypeName("objectField"));
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testMetaData() throws Exception {
+        BinaryObjectBuilder builder = builder("org.test.MetaTest");
+
+        builder.hashCode(100);
+
+        builder.setField("intField", 1);
+        builder.setField("byteArrayField", new byte[] {1, 2, 3});
+
+        BinaryObject po = builder.build();
+
+        BinaryType meta = po.type();
+
+        assertEquals("MetaTest", meta.typeName());
+
+        Collection<String> fields = meta.fieldNames();
+
+        assertEquals(2, fields.size());
+
+        assertTrue(fields.contains("intField"));
+        assertTrue(fields.contains("byteArrayField"));
+
+        assertEquals("int", meta.fieldTypeName("intField"));
+        assertEquals("byte[]", meta.fieldTypeName("byteArrayField"));
+
+        builder = builder("org.test.MetaTest");
+
+        builder.hashCode(100);
+
+        builder.setField("intField", 2);
+        builder.setField("uuidField", UUID.randomUUID());
+
+        po = builder.build();
+
+        meta = po.type();
+
+        assertEquals("MetaTest", meta.typeName());
+
+        fields = meta.fieldNames();
+
+        assertEquals(3, fields.size());
+
+        assertTrue(fields.contains("intField"));
+        assertTrue(fields.contains("byteArrayField"));
+        assertTrue(fields.contains("uuidField"));
+
+        assertEquals("int", meta.fieldTypeName("intField"));
+        assertEquals("byte[]", meta.fieldTypeName("byteArrayField"));
+        assertEquals("UUID", meta.fieldTypeName("uuidField"));
+    }
+
+    /**
+     *
+     */
+    public void testGetFromCopiedObj() {
+        BinaryObject objStr = builder(GridPortableTestClasses.TestObjectAllTypes.class.getName()).setField("str", "aaa").build();
+
+        BinaryObjectBuilderImpl builder = builder(objStr);
+        assertEquals("aaa", builder.getField("str"));
+
+        builder.setField("str", "bbb");
+        assertEquals("bbb", builder.getField("str"));
+
+        assertNull(builder.getField("i_"));
+        TestCase.assertEquals("bbb", builder.build().<GridPortableTestClasses.TestObjectAllTypes>deserialize().str);
+    }
+
+    /**
+     *
+     */
+    @SuppressWarnings("unchecked")
+    public void testCopyFromInnerObjects() {
+        ArrayList<Object> list = new ArrayList<>();
+        list.add(new GridPortableTestClasses.TestObjectAllTypes());
+        list.add(list.get(0));
+
+        GridPortableTestClasses.TestObjectContainer c = new GridPortableTestClasses.TestObjectContainer(list);
+
+        BinaryObjectBuilderImpl builder = builder(toPortable(c));
+        builder.<List>getField("foo").add("!!!");
+
+        BinaryObject res = builder.build();
+
+        GridPortableTestClasses.TestObjectContainer deserialized = res.deserialize();
+
+        List deserializedList = (List)deserialized.foo;
+
+        assertSame(deserializedList.get(0), deserializedList.get(1));
+        assertEquals("!!!", deserializedList.get(2));
+        assertTrue(deserializedList.get(0) instanceof GridPortableTestClasses.TestObjectAllTypes);
+    }
+
+    /**
+     *
+     */
+    public void testSetPortableObject() {
+        BinaryObject portableObj = builder(GridPortableTestClasses.TestObjectContainer.class.getName())
+            .setField("foo", toPortable(new GridPortableTestClasses.TestObjectAllTypes()))
+            .build();
+
+        assertTrue(portableObj.<GridPortableTestClasses.TestObjectContainer>deserialize().foo instanceof GridPortableTestClasses.TestObjectAllTypes);
+    }
+
+    /**
+     *
+     */
+    public void testPlainPortableObjectCopyFrom() {
+        GridPortableTestClasses.TestObjectPlainPortable obj = new GridPortableTestClasses.TestObjectPlainPortable(toPortable(new GridPortableTestClasses.TestObjectAllTypes()));
+
+        BinaryObjectBuilderImpl builder = builder(toPortable(obj));
+        assertTrue(builder.getField("plainPortable") instanceof BinaryObject);
+
+        GridPortableTestClasses.TestObjectPlainPortable deserialized = builder.build().deserialize();
+        assertTrue(deserialized.plainPortable != null);
+    }
+
+    /**
+     *
+     */
+    public void testRemoveFromNewObject() {
+        BinaryObjectBuilder builder = builder(GridPortableTestClasses.TestObjectAllTypes.class.getName());
+
+        builder.setField("str", "a");
+
+        builder.removeField("str");
+
+        TestCase.assertNull(builder.build().<GridPortableTestClasses.TestObjectAllTypes>deserialize().str);
+    }
+
+    /**
+     *
+     */
+    public void testRemoveFromExistingObject() {
+        GridPortableTestClasses.TestObjectAllTypes obj = new GridPortableTestClasses.TestObjectAllTypes();
+        obj.setDefaultData();
+        obj.enumArr = null;
+
+        BinaryObjectBuilder builder = builder(toPortable(obj));
+
+        builder.removeField("str");
+
+        BinaryObject binary = builder.build();
+
+        GridPortableTestClasses.TestObjectAllTypes deserialzied = binary.deserialize();
+
+        assertNull(deserialzied.str);
+    }
+
+    /**
+     *
+     */
+    public void testRemoveFromExistingObjectAfterGet() {
+        GridPortableTestClasses.TestObjectAllTypes obj = new GridPortableTestClasses.TestObjectAllTypes();
+        obj.setDefaultData();
+        obj.enumArr = null;
+
+        BinaryObjectBuilderImpl builder = builder(toPortable(obj));
+
+        builder.getField("i_");
+
+        builder.removeField("str");
+
+        TestCase.assertNull(builder.build().<GridPortableTestClasses.TestObjectAllTypes>deserialize().str);
+    }
+
+    /**
+     * @throws IgniteCheckedException If any error occurs.
+     */
+    public void testDontBrokeCyclicDependency() throws IgniteCheckedException {
+        GridPortableTestClasses.TestObjectOuter outer = new GridPortableTestClasses.TestObjectOuter();
+        outer.inner = new GridPortableTestClasses.TestObjectInner();
+        outer.inner.outer = outer;
+        outer.foo = "a";
+
+        BinaryObjectBuilder builder = builder(toPortable(outer));
+
+        builder.setField("foo", "b");
+
+        GridPortableTestClasses.TestObjectOuter res = builder.build().deserialize();
+
+        assertEquals("b", res.foo);
+        assertSame(res, res.inner.outer);
+    }
+
+    /**
+     * @return Portables.
+     */
+    private IgniteBinary portables() {
+        return grid(0).binary();
+    }
+
+    /**
+     * @param obj Object.
+     * @return Portable object.
+     */
+    private BinaryObject toPortable(Object obj) {
+        return portables().toBinary(obj);
+    }
+
+    /**
+     * @return Builder.
+     */
+    private BinaryObjectBuilder builder(String clsName) {
+        return portables().builder(clsName);
+    }
+
+    /**
+     * @return Builder.
+     */
+    private BinaryObjectBuilderImpl builder(BinaryObject obj) {
+        return (BinaryObjectBuilderImpl)portables().builder(obj);
+    }
+
+    /**
+     *
+     */
+    @SuppressWarnings("UnusedDeclaration")
+    private static class CustomIdMapper {
+        /** */
+        private String str = "a";
+
+        /** */
+        private int i = 10;
+    }
+
+    /**
+     */
+    @SuppressWarnings("UnusedDeclaration")
+    private static class Key {
+        /** */
+        private int i;
+
+        /**
+         */
+        private Key() {
+            // No-op.
+        }
+
+        /**
+         * @param i Index.
+         */
+        private Key(int i) {
+            this.i = i;
+        }
+
+        /** {@inheritDoc} */
+        @Override public boolean equals(Object o) {
+            if (this == o)
+                return true;
+
+            if (o == null || getClass() != o.getClass())
+                return false;
+
+            Key key = (Key)o;
+
+            return i == key.i;
+        }
+
+        /** {@inheritDoc} */
+        @Override public int hashCode() {
+            return i;
+        }
+    }
+
+    /**
+     */
+    @SuppressWarnings("UnusedDeclaration")
+    private static class Value {
+        /** */
+        private int i;
+
+        /**
+         */
+        private Value() {
+            // No-op.
+        }
+
+        /**
+         * @param i Index.
+         */
+        private Value(int i) {
+            this.i = i;
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/1dbf20e0/modules/core/src/test/java/org/apache/ignite/internal/binary/GridPortableAffinityKeySelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/binary/GridPortableAffinityKeySelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/binary/GridPortableAffinityKeySelfTest.java
new file mode 100644
index 0000000..74941d0
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/binary/GridPortableAffinityKeySelfTest.java
@@ -0,0 +1,234 @@
+/*
+ * 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.binary;
+
+import java.util.Collections;
+import java.util.UUID;
+import java.util.concurrent.atomic.AtomicReference;
+import org.apache.ignite.Ignite;
+import org.apache.ignite.binary.BinaryObjectBuilder;
+import org.apache.ignite.cache.CacheKeyConfiguration;
+import org.apache.ignite.cache.affinity.Affinity;
+import org.apache.ignite.configuration.BinaryConfiguration;
+import org.apache.ignite.configuration.CacheConfiguration;
+import org.apache.ignite.configuration.IgniteConfiguration;
+import org.apache.ignite.internal.IgniteKernal;
+import org.apache.ignite.internal.processors.affinity.GridAffinityProcessor;
+import org.apache.ignite.internal.processors.cache.CacheObject;
+import org.apache.ignite.internal.processors.cache.CacheObjectContext;
+import org.apache.ignite.internal.processors.cacheobject.IgniteCacheObjectProcessor;
+import org.apache.ignite.lang.IgniteCallable;
+import org.apache.ignite.lang.IgniteRunnable;
+import org.apache.ignite.binary.BinaryTypeConfiguration;
+import org.apache.ignite.resources.IgniteInstanceResource;
+import org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi;
+import org.apache.ignite.spi.discovery.tcp.ipfinder.TcpDiscoveryIpFinder;
+import org.apache.ignite.spi.discovery.tcp.ipfinder.vm.TcpDiscoveryVmIpFinder;
+import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
+
+import static org.apache.ignite.cache.CacheMode.PARTITIONED;
+
+/**
+ * Test for portable object affinity key.
+ */
+public class GridPortableAffinityKeySelfTest extends GridCommonAbstractTest {
+    /** */
+    private static final AtomicReference<UUID> nodeId = new AtomicReference<>();
+
+    /** VM ip finder for TCP discovery. */
+    private static TcpDiscoveryIpFinder ipFinder = new TcpDiscoveryVmIpFinder(true);
+
+    /** */
+    private static int GRID_CNT = 5;
+
+    /** {@inheritDoc} */
+    @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception {
+        IgniteConfiguration cfg = super.getConfiguration(gridName);
+
+        BinaryTypeConfiguration typeCfg = new BinaryTypeConfiguration();
+
+        typeCfg.setTypeName(TestObject.class.getName());
+
+        BinaryConfiguration bCfg = new BinaryConfiguration();
+
+        bCfg.setTypeConfigurations(Collections.singleton(typeCfg));
+
+        cfg.setBinaryConfiguration(bCfg);
+
+        CacheKeyConfiguration keyCfg = new CacheKeyConfiguration(TestObject.class.getName(), "affKey");
+        CacheKeyConfiguration keyCfg2 = new CacheKeyConfiguration("TestObject2", "affKey");
+
+        cfg.setCacheKeyConfiguration(keyCfg, keyCfg2);
+
+        cfg.setMarshaller(new BinaryMarshaller());
+
+        if (!gridName.equals(getTestGridName(GRID_CNT))) {
+            CacheConfiguration cacheCfg = new CacheConfiguration();
+
+            cacheCfg.setCacheMode(PARTITIONED);
+
+            cfg.setCacheConfiguration(cacheCfg);
+        }
+
+        ((TcpDiscoverySpi)cfg.getDiscoverySpi()).setIpFinder(ipFinder);
+
+        return cfg;
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void beforeTestsStarted() throws Exception {
+        startGridsMultiThreaded(GRID_CNT);
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void afterTestsStopped() throws Exception {
+        stopAllGrids();
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testAffinity() throws Exception {
+        checkAffinity(grid(0));
+
+        try (Ignite igniteNoCache = startGrid(GRID_CNT)) {
+            try {
+                igniteNoCache.cache(null);
+            }
+            catch (IllegalArgumentException ignore) {
+                // Expected error.
+            }
+
+            checkAffinity(igniteNoCache);
+        }
+    }
+
+    /**
+     * @param ignite Ignite.
+     * @throws Exception If failed.
+     */
+    private void checkAffinity(Ignite ignite) throws Exception {
+        Affinity<Object> aff = ignite.affinity(null);
+
+        GridAffinityProcessor affProc = ((IgniteKernal)ignite).context().affinity();
+
+        IgniteCacheObjectProcessor cacheObjProc = ((IgniteKernal)ignite).context().cacheObjects();
+
+        CacheObjectContext cacheObjCtx = cacheObjProc.contextForCache(
+            ignite.cache(null).getConfiguration(CacheConfiguration.class));
+
+        for (int i = 0; i < 1000; i++) {
+            assertEquals(i, aff.affinityKey(i));
+
+            assertEquals(i, aff.affinityKey(new TestObject(i)));
+
+            assertEquals(i, aff.affinityKey(ignite.binary().toBinary(new TestObject(i))));
+
+            BinaryObjectBuilder bldr = ignite.binary().builder("TestObject2");
+
+            bldr.setField("affKey", i);
+
+            assertEquals(i, aff.affinityKey(bldr.build()));
+
+            CacheObject cacheObj = cacheObjProc.toCacheObject(cacheObjCtx, new TestObject(i), true);
+
+            assertEquals(i, aff.affinityKey(cacheObj));
+
+            assertEquals(aff.mapKeyToNode(i), aff.mapKeyToNode(new TestObject(i)));
+
+            assertEquals(aff.mapKeyToNode(i), aff.mapKeyToNode(cacheObj));
+
+            assertEquals(i, affProc.affinityKey(null, i));
+
+            assertEquals(i, affProc.affinityKey(null, new TestObject(i)));
+
+            assertEquals(i, affProc.affinityKey(null, cacheObj));
+
+            assertEquals(affProc.mapKeyToNode(null, i), affProc.mapKeyToNode(null, new TestObject(i)));
+
+            assertEquals(affProc.mapKeyToNode(null, i), affProc.mapKeyToNode(null, cacheObj));
+        }
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testAffinityRun() throws Exception {
+        Affinity<Object> aff = grid(0).affinity(null);
+
+        for (int i = 0; i < 1000; i++) {
+            nodeId.set(null);
+
+            grid(0).compute().affinityRun(null, new TestObject(i), new IgniteRunnable() {
+                @IgniteInstanceResource
+                private Ignite ignite;
+
+                @Override public void run() {
+                    nodeId.set(ignite.configuration().getNodeId());
+                }
+            });
+
+            assertEquals(aff.mapKeyToNode(i).id(), nodeId.get());
+        }
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testAffinityCall() throws Exception {
+        Affinity<Object> aff = grid(0).affinity(null);
+
+        for (int i = 0; i < 1000; i++) {
+            nodeId.set(null);
+
+            grid(0).compute().affinityCall(null, new TestObject(i), new IgniteCallable<Object>() {
+                @IgniteInstanceResource
+                private Ignite ignite;
+
+                @Override public Object call() {
+                    nodeId.set(ignite.configuration().getNodeId());
+
+                    return null;
+                }
+            });
+
+            assertEquals(aff.mapKeyToNode(i).id(), nodeId.get());
+        }
+    }
+
+    /**
+     */
+    private static class TestObject {
+        /** */
+        @SuppressWarnings("UnusedDeclaration")
+        private int affKey;
+
+        /**
+         */
+        private TestObject() {
+            // No-op.
+        }
+
+        /**
+         * @param affKey Affinity key.
+         */
+        private TestObject(int affKey) {
+            this.affKey = affKey;
+        }
+    }
+}


[54/59] [abbrv] ignite git commit: ignite-2065: rename "portable" classes to "binary"

Posted by ak...@apache.org.
http://git-wip-us.apache.org/repos/asf/ignite/blob/71ad9cea/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryFieldImpl.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryFieldImpl.java b/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryFieldImpl.java
index 36fde02..7f51631 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryFieldImpl.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryFieldImpl.java
@@ -32,7 +32,7 @@ public class BinaryFieldImpl implements BinaryField {
 
     /** Well-known object schemas. */
     @GridToStringExclude
-    private final PortableSchemaRegistry schemas;
+    private final BinarySchemaRegistry schemas;
 
     /** Field name. */
     private final String fieldName;
@@ -47,7 +47,7 @@ public class BinaryFieldImpl implements BinaryField {
      * @param fieldName Field name.
      * @param fieldId Field ID.
      */
-    public BinaryFieldImpl(int typeId, PortableSchemaRegistry schemas, String fieldName, int fieldId) {
+    public BinaryFieldImpl(int typeId, BinarySchemaRegistry schemas, String fieldName, int fieldId) {
         assert typeId != 0;
         assert schemas != null;
         assert fieldName != null;
@@ -68,7 +68,7 @@ public class BinaryFieldImpl implements BinaryField {
     @Override public boolean exists(BinaryObject obj) {
         BinaryObjectExImpl obj0 = (BinaryObjectExImpl)obj;
 
-        return fieldOrder(obj0) != PortableSchema.ORDER_NOT_FOUND;
+        return fieldOrder(obj0) != BinarySchema.ORDER_NOT_FOUND;
     }
 
     /** {@inheritDoc} */
@@ -78,7 +78,7 @@ public class BinaryFieldImpl implements BinaryField {
 
         int order = fieldOrder(obj0);
 
-        return order != PortableSchema.ORDER_NOT_FOUND ? (T)obj0.fieldByOrder(order) : null;
+        return order != BinarySchema.ORDER_NOT_FOUND ? (T)obj0.fieldByOrder(order) : null;
     }
 
     /**
@@ -96,7 +96,7 @@ public class BinaryFieldImpl implements BinaryField {
 
         int schemaId = obj.schemaId();
 
-        PortableSchema schema = schemas.schema(schemaId);
+        BinarySchema schema = schemas.schema(schemaId);
 
         if (schema == null) {
             schema = obj.createSchema();

http://git-wip-us.apache.org/repos/asf/ignite/blob/71ad9cea/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryMarshaller.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryMarshaller.java b/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryMarshaller.java
index 13435e6..03bf9f9 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryMarshaller.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryMarshaller.java
@@ -36,7 +36,7 @@ import sun.misc.Unsafe;
  */
 public class BinaryMarshaller extends AbstractMarshaller {
     /** */
-    private GridPortableMarshaller impl;
+    private GridBinaryMarshaller impl;
 
     /**
      * Checks whether {@code BinaryMarshaller} is able to work on the current JVM.
@@ -79,15 +79,15 @@ public class BinaryMarshaller extends AbstractMarshaller {
     }
 
     /**
-     * Sets {@link PortableContext}.
+     * Sets {@link BinaryContext}.
      * <p/>
      * @param ctx Portable context.
      */
     @SuppressWarnings("UnusedDeclaration")
-    private void setPortableContext(PortableContext ctx, IgniteConfiguration cfg) {
+    private void setPortableContext(BinaryContext ctx, IgniteConfiguration cfg) {
         ctx.configure(this, cfg);
 
-        impl = new GridPortableMarshaller(ctx);
+        impl = new GridBinaryMarshaller(ctx);
     }
 
     /** {@inheritDoc} */

http://git-wip-us.apache.org/repos/asf/ignite/blob/71ad9cea/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryMetadata.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryMetadata.java b/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryMetadata.java
index cefad9e..a8ff140 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryMetadata.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryMetadata.java
@@ -50,7 +50,7 @@ public class BinaryMetadata implements Externalizable {
     private String affKeyFieldName;
 
     /** Schemas associated with type. */
-    private Collection<PortableSchema> schemas;
+    private Collection<BinarySchema> schemas;
 
     /** Whether this is enum type. */
     private boolean isEnum;
@@ -73,7 +73,7 @@ public class BinaryMetadata implements Externalizable {
      * @param isEnum Enum flag.
      */
     public BinaryMetadata(int typeId, String typeName, @Nullable Map<String, Integer> fields,
-        @Nullable String affKeyFieldName, @Nullable Collection<PortableSchema> schemas, boolean isEnum) {
+        @Nullable String affKeyFieldName, @Nullable Collection<BinarySchema> schemas, boolean isEnum) {
         assert typeName != null;
 
         this.typeId = typeId;
@@ -119,7 +119,7 @@ public class BinaryMetadata implements Externalizable {
     @Nullable public String fieldTypeName(String fieldName) {
         Integer typeId = fields != null ? fields.get(fieldName) : null;
 
-        return typeId != null ? PortableUtils.fieldTypeName(typeId) : null;
+        return typeId != null ? BinaryUtils.fieldTypeName(typeId) : null;
     }
 
     /**
@@ -132,8 +132,8 @@ public class BinaryMetadata implements Externalizable {
     /**
      * @return Schemas.
      */
-    public Collection<PortableSchema> schemas() {
-        return schemas != null ? schemas : Collections.<PortableSchema>emptyList();
+    public Collection<BinarySchema> schemas() {
+        return schemas != null ? schemas : Collections.<BinarySchema>emptyList();
     }
 
     /**
@@ -149,7 +149,7 @@ public class BinaryMetadata implements Externalizable {
      * @param ctx Portable context.
      * @return Binary type.
      */
-    public BinaryTypeImpl wrap(PortableContext ctx) {
+    public BinaryTypeImpl wrap(BinaryContext ctx) {
         return new BinaryTypeImpl(ctx, this);
     }
 

http://git-wip-us.apache.org/repos/asf/ignite/blob/71ad9cea/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryMetadataCollector.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryMetadataCollector.java b/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryMetadataCollector.java
index af99cce..54f2b13 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryMetadataCollector.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryMetadataCollector.java
@@ -51,7 +51,7 @@ class BinaryMetadataCollector implements BinaryWriter {
     private final Map<String, Integer> meta = new HashMap<>();
 
     /** Schema builder. */
-    private PortableSchema.Builder schemaBuilder = PortableSchema.Builder.newBuilder();
+    private BinarySchema.Builder schemaBuilder = BinarySchema.Builder.newBuilder();
 
     /**
      * Constructor.
@@ -76,7 +76,7 @@ class BinaryMetadataCollector implements BinaryWriter {
     /**
      * @return Schemas.
      */
-    PortableSchema schema() {
+    BinarySchema schema() {
         return schemaBuilder.build();
     }
 
@@ -267,8 +267,8 @@ class BinaryMetadataCollector implements BinaryWriter {
         if (oldFieldTypeId != null && !oldFieldTypeId.equals(fieldTypeId)) {
             throw new BinaryObjectException(
                 "Field is written twice with different types [" + "typeName=" + typeName + ", fieldName=" + name +
-                ", fieldTypeName1=" + PortableUtils.fieldTypeName(oldFieldTypeId) +
-                ", fieldTypeName2=" + PortableUtils.fieldTypeName(fieldTypeId) + ']'
+                ", fieldTypeName1=" + BinaryUtils.fieldTypeName(oldFieldTypeId) +
+                ", fieldTypeName2=" + BinaryUtils.fieldTypeName(fieldTypeId) + ']'
             );
         }
 

http://git-wip-us.apache.org/repos/asf/ignite/blob/71ad9cea/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryObjectExImpl.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryObjectExImpl.java b/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryObjectExImpl.java
index d09bc28..252c495 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryObjectExImpl.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryObjectExImpl.java
@@ -98,7 +98,7 @@ public abstract class BinaryObjectExImpl implements BinaryObjectEx {
      *
      * @return Schema.
      */
-    protected abstract PortableSchema createSchema();
+    protected abstract BinarySchema createSchema();
 
     /** {@inheritDoc} */
     @Override public BinaryObject clone() throws CloneNotSupportedException {

http://git-wip-us.apache.org/repos/asf/ignite/blob/71ad9cea/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryObjectImpl.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryObjectImpl.java b/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryObjectImpl.java
index 18adbc1..9fd5901 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryObjectImpl.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryObjectImpl.java
@@ -33,7 +33,7 @@ import org.apache.ignite.binary.BinaryObjectException;
 import org.apache.ignite.binary.BinaryType;
 import org.apache.ignite.internal.GridDirectTransient;
 import org.apache.ignite.internal.IgniteCodeGeneratingFail;
-import org.apache.ignite.internal.binary.streams.PortableHeapInputStream;
+import org.apache.ignite.internal.binary.streams.BinaryHeapInputStream;
 import org.apache.ignite.internal.processors.cache.CacheObject;
 import org.apache.ignite.internal.processors.cache.CacheObjectContext;
 import org.apache.ignite.internal.processors.cache.KeyCacheObject;
@@ -55,7 +55,7 @@ public final class BinaryObjectImpl extends BinaryObjectExImpl implements Extern
 
     /** */
     @GridDirectTransient
-    private PortableContext ctx;
+    private BinaryContext ctx;
 
     /** */
     private byte[] arr;
@@ -83,7 +83,7 @@ public final class BinaryObjectImpl extends BinaryObjectExImpl implements Extern
      * @param arr Array.
      * @param start Start.
      */
-    public BinaryObjectImpl(PortableContext ctx, byte[] arr, int start) {
+    public BinaryObjectImpl(BinaryContext ctx, byte[] arr, int start) {
         assert ctx != null;
         assert arr != null;
 
@@ -152,7 +152,7 @@ public final class BinaryObjectImpl extends BinaryObjectExImpl implements Extern
 
     /** {@inheritDoc} */
     @Override public int length() {
-        return PortablePrimitives.readInt(arr, start + GridPortableMarshaller.TOTAL_LEN_POS);
+        return BinaryPrimitives.readInt(arr, start + GridBinaryMarshaller.TOTAL_LEN_POS);
     }
 
     /**
@@ -188,14 +188,14 @@ public final class BinaryObjectImpl extends BinaryObjectExImpl implements Extern
     /**
      * @return Context.
      */
-    public PortableContext context() {
+    public BinaryContext context() {
         return ctx;
     }
 
     /**
      * @param ctx Context.
      */
-    public void context(PortableContext ctx) {
+    public void context(BinaryContext ctx) {
         this.ctx = ctx;
     }
 
@@ -221,7 +221,7 @@ public final class BinaryObjectImpl extends BinaryObjectExImpl implements Extern
 
     /** {@inheritDoc} */
     @Override public int typeId() {
-        return PortablePrimitives.readInt(arr, start + GridPortableMarshaller.TYPE_ID_POS);
+        return BinaryPrimitives.readInt(arr, start + GridBinaryMarshaller.TYPE_ID_POS);
     }
 
     /** {@inheritDoc} */
@@ -250,87 +250,87 @@ public final class BinaryObjectImpl extends BinaryObjectExImpl implements Extern
         Object val;
 
         // Calculate field position.
-        int schemaOffset = PortablePrimitives.readInt(arr, start + GridPortableMarshaller.SCHEMA_OR_RAW_OFF_POS);
+        int schemaOffset = BinaryPrimitives.readInt(arr, start + GridBinaryMarshaller.SCHEMA_OR_RAW_OFF_POS);
 
-        short flags = PortablePrimitives.readShort(arr, start + GridPortableMarshaller.FLAGS_POS);
+        short flags = BinaryPrimitives.readShort(arr, start + GridBinaryMarshaller.FLAGS_POS);
 
-        int fieldIdLen = PortableUtils.isCompactFooter(flags) ? 0 : PortableUtils.FIELD_ID_LEN;
-        int fieldOffsetLen = PortableUtils.fieldOffsetLength(flags);
+        int fieldIdLen = BinaryUtils.isCompactFooter(flags) ? 0 : BinaryUtils.FIELD_ID_LEN;
+        int fieldOffsetLen = BinaryUtils.fieldOffsetLength(flags);
 
         int fieldOffsetPos = start + schemaOffset + order * (fieldIdLen + fieldOffsetLen) + fieldIdLen;
 
         int fieldPos;
 
-        if (fieldOffsetLen == PortableUtils.OFFSET_1)
-            fieldPos = start + ((int)PortablePrimitives.readByte(arr, fieldOffsetPos) & 0xFF);
-        else if (fieldOffsetLen == PortableUtils.OFFSET_2)
-            fieldPos = start + ((int)PortablePrimitives.readShort(arr, fieldOffsetPos) & 0xFFFF);
+        if (fieldOffsetLen == BinaryUtils.OFFSET_1)
+            fieldPos = start + ((int)BinaryPrimitives.readByte(arr, fieldOffsetPos) & 0xFF);
+        else if (fieldOffsetLen == BinaryUtils.OFFSET_2)
+            fieldPos = start + ((int)BinaryPrimitives.readShort(arr, fieldOffsetPos) & 0xFFFF);
         else
-            fieldPos = start + PortablePrimitives.readInt(arr, fieldOffsetPos);
+            fieldPos = start + BinaryPrimitives.readInt(arr, fieldOffsetPos);
 
         // Read header and try performing fast lookup for well-known types (the most common types go first).
-        byte hdr = PortablePrimitives.readByte(arr, fieldPos);
+        byte hdr = BinaryPrimitives.readByte(arr, fieldPos);
 
         switch (hdr) {
-            case GridPortableMarshaller.INT:
-                val = PortablePrimitives.readInt(arr, fieldPos + 1);
+            case GridBinaryMarshaller.INT:
+                val = BinaryPrimitives.readInt(arr, fieldPos + 1);
 
                 break;
 
-            case GridPortableMarshaller.LONG:
-                val = PortablePrimitives.readLong(arr, fieldPos + 1);
+            case GridBinaryMarshaller.LONG:
+                val = BinaryPrimitives.readLong(arr, fieldPos + 1);
 
                 break;
 
-            case GridPortableMarshaller.BOOLEAN:
-                val = PortablePrimitives.readBoolean(arr, fieldPos + 1);
+            case GridBinaryMarshaller.BOOLEAN:
+                val = BinaryPrimitives.readBoolean(arr, fieldPos + 1);
 
                 break;
 
-            case GridPortableMarshaller.SHORT:
-                val = PortablePrimitives.readShort(arr, fieldPos + 1);
+            case GridBinaryMarshaller.SHORT:
+                val = BinaryPrimitives.readShort(arr, fieldPos + 1);
 
                 break;
 
-            case GridPortableMarshaller.BYTE:
-                val = PortablePrimitives.readByte(arr, fieldPos + 1);
+            case GridBinaryMarshaller.BYTE:
+                val = BinaryPrimitives.readByte(arr, fieldPos + 1);
 
                 break;
 
-            case GridPortableMarshaller.CHAR:
-                val = PortablePrimitives.readChar(arr, fieldPos + 1);
+            case GridBinaryMarshaller.CHAR:
+                val = BinaryPrimitives.readChar(arr, fieldPos + 1);
 
                 break;
 
-            case GridPortableMarshaller.FLOAT:
-                val = PortablePrimitives.readFloat(arr, fieldPos + 1);
+            case GridBinaryMarshaller.FLOAT:
+                val = BinaryPrimitives.readFloat(arr, fieldPos + 1);
 
                 break;
 
-            case GridPortableMarshaller.DOUBLE:
-                val = PortablePrimitives.readDouble(arr, fieldPos + 1);
+            case GridBinaryMarshaller.DOUBLE:
+                val = BinaryPrimitives.readDouble(arr, fieldPos + 1);
 
                 break;
 
-            case GridPortableMarshaller.STRING: {
-                int dataLen = PortablePrimitives.readInt(arr, fieldPos + 1);
+            case GridBinaryMarshaller.STRING: {
+                int dataLen = BinaryPrimitives.readInt(arr, fieldPos + 1);
 
                 val = new String(arr, fieldPos + 5, dataLen, UTF_8);
 
                 break;
             }
 
-            case GridPortableMarshaller.DATE: {
-                long time = PortablePrimitives.readLong(arr, fieldPos + 1);
+            case GridBinaryMarshaller.DATE: {
+                long time = BinaryPrimitives.readLong(arr, fieldPos + 1);
 
                 val = new Date(time);
 
                 break;
             }
 
-            case GridPortableMarshaller.TIMESTAMP: {
-                long time = PortablePrimitives.readLong(arr, fieldPos + 1);
-                int nanos = PortablePrimitives.readInt(arr, fieldPos + 1 + 8);
+            case GridBinaryMarshaller.TIMESTAMP: {
+                long time = BinaryPrimitives.readLong(arr, fieldPos + 1);
+                int nanos = BinaryPrimitives.readInt(arr, fieldPos + 1 + 8);
 
                 Timestamp ts = new Timestamp(time);
 
@@ -341,20 +341,20 @@ public final class BinaryObjectImpl extends BinaryObjectExImpl implements Extern
                 break;
             }
 
-            case GridPortableMarshaller.UUID: {
-                long most = PortablePrimitives.readLong(arr, fieldPos + 1);
-                long least = PortablePrimitives.readLong(arr, fieldPos + 1 + 8);
+            case GridBinaryMarshaller.UUID: {
+                long most = BinaryPrimitives.readLong(arr, fieldPos + 1);
+                long least = BinaryPrimitives.readLong(arr, fieldPos + 1 + 8);
 
                 val = new UUID(most, least);
 
                 break;
             }
 
-            case GridPortableMarshaller.DECIMAL: {
-                int scale = PortablePrimitives.readInt(arr, fieldPos + 1);
+            case GridBinaryMarshaller.DECIMAL: {
+                int scale = BinaryPrimitives.readInt(arr, fieldPos + 1);
 
-                int dataLen = PortablePrimitives.readInt(arr, fieldPos + 5);
-                byte[] data = PortablePrimitives.readByteArray(arr, fieldPos + 9, dataLen);
+                int dataLen = BinaryPrimitives.readInt(arr, fieldPos + 5);
+                byte[] data = BinaryPrimitives.readByteArray(arr, fieldPos + 9, dataLen);
 
                 BigInteger intVal = new BigInteger(data);
 
@@ -369,13 +369,13 @@ public final class BinaryObjectImpl extends BinaryObjectExImpl implements Extern
                 break;
             }
 
-            case GridPortableMarshaller.NULL:
+            case GridBinaryMarshaller.NULL:
                 val = null;
 
                 break;
 
             default:
-                val = PortableUtils.unmarshal(PortableHeapInputStream.create(arr, fieldPos), ctx, null);
+                val = BinaryUtils.unmarshal(BinaryHeapInputStream.create(arr, fieldPos), ctx, null);
 
                 break;
         }
@@ -412,16 +412,16 @@ public final class BinaryObjectImpl extends BinaryObjectExImpl implements Extern
 
     /** {@inheritDoc} */
     @Override public int hashCode() {
-        return PortablePrimitives.readInt(arr, start + GridPortableMarshaller.HASH_CODE_POS);
+        return BinaryPrimitives.readInt(arr, start + GridBinaryMarshaller.HASH_CODE_POS);
     }
 
     /** {@inheritDoc} */
     @Override protected int schemaId() {
-        return PortablePrimitives.readInt(arr, start + GridPortableMarshaller.SCHEMA_ID_POS);
+        return BinaryPrimitives.readInt(arr, start + GridBinaryMarshaller.SCHEMA_ID_POS);
     }
 
     /** {@inheritDoc} */
-    @Override protected PortableSchema createSchema() {
+    @Override protected BinarySchema createSchema() {
         return reader(null).getOrCreateSchema();
     }
 
@@ -445,7 +445,7 @@ public final class BinaryObjectImpl extends BinaryObjectExImpl implements Extern
 
     /** {@inheritDoc} */
     @Override public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
-        ctx = (PortableContext)in.readObject();
+        ctx = (BinaryContext)in.readObject();
 
         arr = new byte[in.readInt()];
 
@@ -536,7 +536,7 @@ public final class BinaryObjectImpl extends BinaryObjectExImpl implements Extern
 
         Object obj0 = reader.deserialize();
 
-        PortableClassDescriptor desc = reader.descriptor();
+        BinaryClassDescriptor desc = reader.descriptor();
 
         assert desc != null;
 
@@ -562,7 +562,7 @@ public final class BinaryObjectImpl extends BinaryObjectExImpl implements Extern
      */
     private BinaryReaderExImpl reader(@Nullable BinaryReaderHandles rCtx) {
         return new BinaryReaderExImpl(ctx,
-            PortableHeapInputStream.create(arr, start),
+            BinaryHeapInputStream.create(arr, start),
             ctx.configuration().getClassLoader(),
             rCtx);
     }

http://git-wip-us.apache.org/repos/asf/ignite/blob/71ad9cea/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryObjectOffheapImpl.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryObjectOffheapImpl.java b/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryObjectOffheapImpl.java
index 2944099..1206db7 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryObjectOffheapImpl.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryObjectOffheapImpl.java
@@ -21,8 +21,7 @@ import org.apache.ignite.IgniteCheckedException;
 import org.apache.ignite.binary.BinaryObject;
 import org.apache.ignite.binary.BinaryObjectException;
 import org.apache.ignite.binary.BinaryType;
-import org.apache.ignite.internal.binary.streams.PortableOffheapInputStream;
-import org.apache.ignite.internal.binary.streams.PortableOffheapInputStream;
+import org.apache.ignite.internal.binary.streams.BinaryOffheapInputStream;
 import org.apache.ignite.internal.processors.cache.CacheObject;
 import org.apache.ignite.internal.processors.cache.CacheObjectContext;
 import org.apache.ignite.internal.util.GridUnsafe;
@@ -44,20 +43,6 @@ import java.util.Date;
 import java.util.UUID;
 
 import static java.nio.charset.StandardCharsets.UTF_8;
-import static org.apache.ignite.internal.binary.GridPortableMarshaller.BOOLEAN;
-import static org.apache.ignite.internal.binary.GridPortableMarshaller.BYTE;
-import static org.apache.ignite.internal.binary.GridPortableMarshaller.CHAR;
-import static org.apache.ignite.internal.binary.GridPortableMarshaller.DATE;
-import static org.apache.ignite.internal.binary.GridPortableMarshaller.DECIMAL;
-import static org.apache.ignite.internal.binary.GridPortableMarshaller.DOUBLE;
-import static org.apache.ignite.internal.binary.GridPortableMarshaller.FLOAT;
-import static org.apache.ignite.internal.binary.GridPortableMarshaller.INT;
-import static org.apache.ignite.internal.binary.GridPortableMarshaller.LONG;
-import static org.apache.ignite.internal.binary.GridPortableMarshaller.NULL;
-import static org.apache.ignite.internal.binary.GridPortableMarshaller.SHORT;
-import static org.apache.ignite.internal.binary.GridPortableMarshaller.STRING;
-import static org.apache.ignite.internal.binary.GridPortableMarshaller.TIMESTAMP;
-import static org.apache.ignite.internal.binary.GridPortableMarshaller.UUID;
 
 /**
  *  Portable object implementation over offheap memory
@@ -70,7 +55,7 @@ public class BinaryObjectOffheapImpl extends BinaryObjectExImpl implements Exter
     private static final Unsafe UNSAFE = GridUnsafe.unsafe();
 
     /** */
-    private final PortableContext ctx;
+    private final BinaryContext ctx;
 
     /** */
     private final long ptr;
@@ -94,7 +79,7 @@ public class BinaryObjectOffheapImpl extends BinaryObjectExImpl implements Exter
      * @param start Object start.
      * @param size Memory size.
      */
-    public BinaryObjectOffheapImpl(PortableContext ctx, long ptr, int start, int size) {
+    public BinaryObjectOffheapImpl(BinaryContext ctx, long ptr, int start, int size) {
         this.ctx = ctx;
         this.ptr = ptr;
         this.start = start;
@@ -110,26 +95,26 @@ public class BinaryObjectOffheapImpl extends BinaryObjectExImpl implements Exter
 
     /** {@inheritDoc} */
     @Override public int typeId() {
-        return UNSAFE.getInt(ptr + start + GridPortableMarshaller.TYPE_ID_POS);
+        return UNSAFE.getInt(ptr + start + GridBinaryMarshaller.TYPE_ID_POS);
     }
 
     /** {@inheritDoc} */
     @Override public int length() {
-        return UNSAFE.getInt(ptr + start + GridPortableMarshaller.TOTAL_LEN_POS);
+        return UNSAFE.getInt(ptr + start + GridBinaryMarshaller.TOTAL_LEN_POS);
     }
 
     /** {@inheritDoc} */
     @Override public int hashCode() {
-        return UNSAFE.getInt(ptr + start + GridPortableMarshaller.HASH_CODE_POS);
+        return UNSAFE.getInt(ptr + start + GridBinaryMarshaller.HASH_CODE_POS);
     }
 
     /** {@inheritDoc} */
     @Override protected int schemaId() {
-        return UNSAFE.getInt(ptr + start + GridPortableMarshaller.SCHEMA_ID_POS);
+        return UNSAFE.getInt(ptr + start + GridBinaryMarshaller.SCHEMA_ID_POS);
     }
 
     /** {@inheritDoc} */
-    @Override protected PortableSchema createSchema() {
+    @Override protected BinarySchema createSchema() {
         return reader(null).getOrCreateSchema();
     }
 
@@ -179,88 +164,88 @@ public class BinaryObjectOffheapImpl extends BinaryObjectExImpl implements Exter
         Object val;
 
         // Calculate field position.
-        int schemaOffset = PortablePrimitives.readInt(ptr, start + GridPortableMarshaller.SCHEMA_OR_RAW_OFF_POS);
+        int schemaOffset = BinaryPrimitives.readInt(ptr, start + GridBinaryMarshaller.SCHEMA_OR_RAW_OFF_POS);
 
-        short flags = PortablePrimitives.readShort(ptr, start + GridPortableMarshaller.FLAGS_POS);
+        short flags = BinaryPrimitives.readShort(ptr, start + GridBinaryMarshaller.FLAGS_POS);
 
-        int fieldIdLen = PortableUtils.isCompactFooter(flags) ? 0 : PortableUtils.FIELD_ID_LEN;
-        int fieldOffsetLen = PortableUtils.fieldOffsetLength(flags);
+        int fieldIdLen = BinaryUtils.isCompactFooter(flags) ? 0 : BinaryUtils.FIELD_ID_LEN;
+        int fieldOffsetLen = BinaryUtils.fieldOffsetLength(flags);
 
         int fieldOffsetPos = start + schemaOffset + order * (fieldIdLen + fieldOffsetLen) + fieldIdLen;
 
         int fieldPos;
 
-        if (fieldOffsetLen == PortableUtils.OFFSET_1)
-            fieldPos = start + ((int)PortablePrimitives.readByte(ptr, fieldOffsetPos) & 0xFF);
-        else if (fieldOffsetLen == PortableUtils.OFFSET_2)
-            fieldPos = start + ((int)PortablePrimitives.readShort(ptr, fieldOffsetPos) & 0xFFFF);
+        if (fieldOffsetLen == BinaryUtils.OFFSET_1)
+            fieldPos = start + ((int)BinaryPrimitives.readByte(ptr, fieldOffsetPos) & 0xFF);
+        else if (fieldOffsetLen == BinaryUtils.OFFSET_2)
+            fieldPos = start + ((int)BinaryPrimitives.readShort(ptr, fieldOffsetPos) & 0xFFFF);
         else
-            fieldPos = start + PortablePrimitives.readInt(ptr, fieldOffsetPos);
+            fieldPos = start + BinaryPrimitives.readInt(ptr, fieldOffsetPos);
 
         // Read header and try performing fast lookup for well-known types (the most common types go first).
-        byte hdr = PortablePrimitives.readByte(ptr, fieldPos);
+        byte hdr = BinaryPrimitives.readByte(ptr, fieldPos);
 
         switch (hdr) {
-            case GridPortableMarshaller.INT:
-                val = PortablePrimitives.readInt(ptr, fieldPos + 1);
+            case GridBinaryMarshaller.INT:
+                val = BinaryPrimitives.readInt(ptr, fieldPos + 1);
 
                 break;
 
-            case GridPortableMarshaller.LONG:
-                val = PortablePrimitives.readLong(ptr, fieldPos + 1);
+            case GridBinaryMarshaller.LONG:
+                val = BinaryPrimitives.readLong(ptr, fieldPos + 1);
 
                 break;
 
-            case GridPortableMarshaller.BOOLEAN:
-                val = PortablePrimitives.readBoolean(ptr, fieldPos + 1);
+            case GridBinaryMarshaller.BOOLEAN:
+                val = BinaryPrimitives.readBoolean(ptr, fieldPos + 1);
 
                 break;
 
-            case GridPortableMarshaller.SHORT:
-                val = PortablePrimitives.readShort(ptr, fieldPos + 1);
+            case GridBinaryMarshaller.SHORT:
+                val = BinaryPrimitives.readShort(ptr, fieldPos + 1);
 
                 break;
 
-            case GridPortableMarshaller.BYTE:
-                val = PortablePrimitives.readByte(ptr, fieldPos + 1);
+            case GridBinaryMarshaller.BYTE:
+                val = BinaryPrimitives.readByte(ptr, fieldPos + 1);
 
                 break;
 
-            case GridPortableMarshaller.CHAR:
-                val = PortablePrimitives.readChar(ptr, fieldPos + 1);
+            case GridBinaryMarshaller.CHAR:
+                val = BinaryPrimitives.readChar(ptr, fieldPos + 1);
 
                 break;
 
-            case GridPortableMarshaller.FLOAT:
-                val = PortablePrimitives.readFloat(ptr, fieldPos + 1);
+            case GridBinaryMarshaller.FLOAT:
+                val = BinaryPrimitives.readFloat(ptr, fieldPos + 1);
 
                 break;
 
-            case GridPortableMarshaller.DOUBLE:
-                val = PortablePrimitives.readDouble(ptr, fieldPos + 1);
+            case GridBinaryMarshaller.DOUBLE:
+                val = BinaryPrimitives.readDouble(ptr, fieldPos + 1);
 
                 break;
 
-            case GridPortableMarshaller.STRING: {
-                int dataLen = PortablePrimitives.readInt(ptr, fieldPos + 1);
-                byte[] data = PortablePrimitives.readByteArray(ptr, fieldPos + 5, dataLen);
+            case GridBinaryMarshaller.STRING: {
+                int dataLen = BinaryPrimitives.readInt(ptr, fieldPos + 1);
+                byte[] data = BinaryPrimitives.readByteArray(ptr, fieldPos + 5, dataLen);
 
                 val = new String(data, UTF_8);
 
                 break;
             }
 
-            case GridPortableMarshaller.DATE: {
-                long time = PortablePrimitives.readLong(ptr, fieldPos + 1);
+            case GridBinaryMarshaller.DATE: {
+                long time = BinaryPrimitives.readLong(ptr, fieldPos + 1);
 
                 val = new Date(time);
 
                 break;
             }
 
-            case GridPortableMarshaller.TIMESTAMP: {
-                long time = PortablePrimitives.readLong(ptr, fieldPos + 1);
-                int nanos = PortablePrimitives.readInt(ptr, fieldPos + 1 + 8);
+            case GridBinaryMarshaller.TIMESTAMP: {
+                long time = BinaryPrimitives.readLong(ptr, fieldPos + 1);
+                int nanos = BinaryPrimitives.readInt(ptr, fieldPos + 1 + 8);
 
                 Timestamp ts = new Timestamp(time);
 
@@ -271,20 +256,20 @@ public class BinaryObjectOffheapImpl extends BinaryObjectExImpl implements Exter
                 break;
             }
 
-            case GridPortableMarshaller.UUID: {
-                long most = PortablePrimitives.readLong(ptr, fieldPos + 1);
-                long least = PortablePrimitives.readLong(ptr, fieldPos + 1 + 8);
+            case GridBinaryMarshaller.UUID: {
+                long most = BinaryPrimitives.readLong(ptr, fieldPos + 1);
+                long least = BinaryPrimitives.readLong(ptr, fieldPos + 1 + 8);
 
                 val = new UUID(most, least);
 
                 break;
             }
 
-            case GridPortableMarshaller.DECIMAL: {
-                int scale = PortablePrimitives.readInt(ptr, fieldPos + 1);
+            case GridBinaryMarshaller.DECIMAL: {
+                int scale = BinaryPrimitives.readInt(ptr, fieldPos + 1);
 
-                int dataLen = PortablePrimitives.readInt(ptr, fieldPos + 5);
-                byte[] data = PortablePrimitives.readByteArray(ptr, fieldPos + 9, dataLen);
+                int dataLen = BinaryPrimitives.readInt(ptr, fieldPos + 5);
+                byte[] data = BinaryPrimitives.readByteArray(ptr, fieldPos + 9, dataLen);
 
                 BigInteger intVal = new BigInteger(data);
 
@@ -299,17 +284,17 @@ public class BinaryObjectOffheapImpl extends BinaryObjectExImpl implements Exter
                 break;
             }
 
-            case GridPortableMarshaller.NULL:
+            case GridBinaryMarshaller.NULL:
                 val = null;
 
                 break;
 
             default:
-                PortableOffheapInputStream stream = new PortableOffheapInputStream(ptr, size, false);
+                BinaryOffheapInputStream stream = new BinaryOffheapInputStream(ptr, size, false);
 
                 stream.position(fieldPos);
 
-                val = PortableUtils.unmarshal(stream, ctx, null);
+                val = BinaryUtils.unmarshal(stream, ctx, null);
 
                 break;
         }
@@ -420,7 +405,7 @@ public class BinaryObjectOffheapImpl extends BinaryObjectExImpl implements Exter
      * @return Reader.
      */
     private BinaryReaderExImpl reader(@Nullable BinaryReaderHandles rCtx) {
-        PortableOffheapInputStream stream = new PortableOffheapInputStream(ptr, size, false);
+        BinaryOffheapInputStream stream = new BinaryOffheapInputStream(ptr, size, false);
 
         stream.position(start);
 

http://git-wip-us.apache.org/repos/asf/ignite/blob/71ad9cea/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryPositionReadable.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryPositionReadable.java b/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryPositionReadable.java
new file mode 100644
index 0000000..c85bb19
--- /dev/null
+++ b/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryPositionReadable.java
@@ -0,0 +1,47 @@
+/*
+ * 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.binary;
+
+/**
+ * Interface allowing for positioned read.
+ */
+public interface BinaryPositionReadable {
+    /**
+     * Read byte at the given position.
+     *
+     * @param pos Position.
+     * @return Value.
+     */
+    public byte readBytePositioned(int pos);
+
+    /**
+     * Read short at the given position.
+     *
+     * @param pos Position.
+     * @return Value.
+     */
+    public short readShortPositioned(int pos);
+
+    /**
+     * Read integer at the given position.
+     *
+     * @param pos Position.
+     * @return Value.
+     */
+    public int readIntPositioned(int pos);
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/71ad9cea/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryPrimitives.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryPrimitives.java b/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryPrimitives.java
new file mode 100644
index 0000000..a6a867c
--- /dev/null
+++ b/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryPrimitives.java
@@ -0,0 +1,382 @@
+/*
+ * 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.binary;
+
+import org.apache.ignite.internal.util.GridUnsafe;
+import sun.misc.Unsafe;
+
+import java.nio.ByteOrder;
+
+/**
+ * Primitives writer.
+ */
+public abstract class BinaryPrimitives {
+    /** */
+    private static final Unsafe UNSAFE = GridUnsafe.unsafe();
+
+    /** */
+    private static final long BYTE_ARR_OFF = UNSAFE.arrayBaseOffset(byte[].class);
+
+    /** */
+    private static final long CHAR_ARR_OFF = UNSAFE.arrayBaseOffset(char[].class);
+
+    /** Whether little endian is set. */
+    private static final boolean BIG_ENDIAN = ByteOrder.nativeOrder() == ByteOrder.BIG_ENDIAN;
+
+    /**
+     * @param arr Array.
+     * @param off Offset.
+     * @param val Value.
+     */
+    public static void writeByte(byte[] arr, int off, byte val) {
+        UNSAFE.putByte(arr, BYTE_ARR_OFF + off, val);
+    }
+
+    /**
+     * @param arr Array.
+     * @param off Offset.
+     * @return Value.
+     */
+    public static byte readByte(byte[] arr, int off) {
+        return UNSAFE.getByte(arr, BYTE_ARR_OFF + off);
+    }
+
+    /**
+     * @param ptr Pointer.
+     * @param off Offset.
+     * @return Value.
+     */
+    public static byte readByte(long ptr, int off) {
+        return UNSAFE.getByte(ptr + off);
+    }
+
+    /**
+     * @param arr Array.
+     * @param off Offset.
+     * @return Value.
+     */
+    public static byte[] readByteArray(byte[] arr, int off, int len) {
+        byte[] arr0 = new byte[len];
+
+        UNSAFE.copyMemory(arr, BYTE_ARR_OFF + off, arr0, BYTE_ARR_OFF, len);
+
+        return arr0;
+    }
+
+    /**
+     * @param ptr Pointer.
+     * @param off Offset.
+     * @return Value.
+     */
+    public static byte[] readByteArray(long ptr, int off, int len) {
+        byte[] arr0 = new byte[len];
+
+        UNSAFE.copyMemory(null, ptr + off, arr0, BYTE_ARR_OFF, len);
+
+        return arr0;
+    }
+
+    /**
+     * @param arr Array.
+     * @param off Offset.
+     * @param val Value.
+     */
+    public static void writeBoolean(byte[] arr, int off, boolean val) {
+        writeByte(arr, off, val ? (byte)1 : (byte)0);
+    }
+
+    /**
+     * @param arr Array.
+     * @param off Offset.
+     * @return Value.
+     */
+    public static boolean readBoolean(byte[] arr, int off) {
+        return readByte(arr, off) == 1;
+    }
+
+    /**
+     * @param ptr Pointer.
+     * @param off Offset.
+     * @return Value.
+     */
+    public static boolean readBoolean(long ptr, int off) {
+        return readByte(ptr, off) == 1;
+    }
+
+    /**
+     * @param arr Array.
+     * @param off Offset.
+     * @param val Value.
+     */
+    public static void writeShort(byte[] arr, int off, short val) {
+        if (BIG_ENDIAN)
+            val = Short.reverseBytes(val);
+
+        UNSAFE.putShort(arr, BYTE_ARR_OFF + off, val);
+    }
+
+    /**
+     * @param arr Array.
+     * @param off Offset.
+     * @return Value.
+     */
+    public static short readShort(byte[] arr, int off) {
+        short val = UNSAFE.getShort(arr, BYTE_ARR_OFF + off);
+
+        if (BIG_ENDIAN)
+            val = Short.reverseBytes(val);
+
+        return val;
+    }
+
+    /**
+     * @param ptr Pointer.
+     * @param off Offset.
+     * @return Value.
+     */
+    public static short readShort(long ptr, int off) {
+        short val = UNSAFE.getShort(ptr + off);
+
+        if (BIG_ENDIAN)
+            val = Short.reverseBytes(val);
+
+        return val;
+    }
+
+    /**
+     * @param arr Array.
+     * @param off Offset.
+     * @param val Value.
+     */
+    public static void writeChar(byte[] arr, int off, char val) {
+        if (BIG_ENDIAN)
+            val = Character.reverseBytes(val);
+
+        UNSAFE.putChar(arr, BYTE_ARR_OFF + off, val);
+    }
+
+    /**
+     * @param arr Array.
+     * @param off Offset.
+     * @return Value.
+     */
+    public static char readChar(byte[] arr, int off) {
+        char val = UNSAFE.getChar(arr, BYTE_ARR_OFF + off);
+
+        if (BIG_ENDIAN)
+            val = Character.reverseBytes(val);
+
+        return val;
+    }
+
+    /**
+     * @param ptr Pointer.
+     * @param off Offset.
+     * @return Value.
+     */
+    public static char readChar(long ptr, int off) {
+        char val = UNSAFE.getChar(ptr + off);
+
+        if (BIG_ENDIAN)
+            val = Character.reverseBytes(val);
+
+        return val;
+    }
+
+    /**
+     * @param arr Array.
+     * @param off Offset.
+     * @return Value.
+     */
+    public static char[] readCharArray(byte[] arr, int off, int len) {
+        char[] arr0 = new char[len];
+
+        UNSAFE.copyMemory(arr, BYTE_ARR_OFF + off, arr0, CHAR_ARR_OFF, len << 1);
+
+        if (BIG_ENDIAN) {
+            for (int i = 0; i < len; i++)
+                arr0[i] = Character.reverseBytes(arr0[i]);
+        }
+
+        return arr0;
+    }
+
+    /**
+     * @param ptr Pointer.
+     * @param off Offset.
+     * @return Value.
+     */
+    public static char[] readCharArray(long ptr, int off, int len) {
+        char[] arr0 = new char[len];
+
+        UNSAFE.copyMemory(null, ptr + off, arr0, CHAR_ARR_OFF, len << 1);
+
+        if (BIG_ENDIAN) {
+            for (int i = 0; i < len; i++)
+                arr0[i] = Character.reverseBytes(arr0[i]);
+        }
+
+        return arr0;
+    }
+
+    /**
+     * @param arr Array.
+     * @param off Offset.
+     * @param val Value.
+     */
+    public static void writeInt(byte[] arr, int off, int val) {
+        if (BIG_ENDIAN)
+            val = Integer.reverseBytes(val);
+
+        UNSAFE.putInt(arr, BYTE_ARR_OFF + off, val);
+    }
+
+    /**
+     * @param arr Array.
+     * @param off Offset.
+     * @return Value.
+     */
+    public static int readInt(byte[] arr, int off) {
+        int val = UNSAFE.getInt(arr, BYTE_ARR_OFF + off);
+
+        if (BIG_ENDIAN)
+            val = Integer.reverseBytes(val);
+
+        return val;
+    }
+
+    /**
+     * @param ptr Pointer.
+     * @param off Offset.
+     * @return Value.
+     */
+    public static int readInt(long ptr, int off) {
+        int val = UNSAFE.getInt(ptr + off);
+
+        if (BIG_ENDIAN)
+            val = Integer.reverseBytes(val);
+
+        return val;
+    }
+
+    /**
+     * @param arr Array.
+     * @param off Offset.
+     * @param val Value.
+     */
+    public static void writeLong(byte[] arr, int off, long val) {
+        if (BIG_ENDIAN)
+            val = Long.reverseBytes(val);
+
+        UNSAFE.putLong(arr, BYTE_ARR_OFF + off, val);
+    }
+
+    /**
+     * @param arr Array.
+     * @param off Offset.
+     * @return Value.
+     */
+    public static long readLong(byte[] arr, int off) {
+        long val = UNSAFE.getLong(arr, BYTE_ARR_OFF + off);
+
+        if (BIG_ENDIAN)
+            val = Long.reverseBytes(val);
+
+        return val;
+    }
+
+    /**
+     * @param ptr Pointer.
+     * @param off Offset.
+     * @return Value.
+     */
+    public static long readLong(long ptr, int off) {
+        long val = UNSAFE.getLong(ptr + off);
+
+        if (BIG_ENDIAN)
+            val = Long.reverseBytes(val);
+
+        return val;
+    }
+
+    /**
+     * @param arr Array.
+     * @param off Offset.
+     * @param val Value.
+     */
+    public static void writeFloat(byte[] arr, int off, float val) {
+        int val0 = Float.floatToIntBits(val);
+
+        writeInt(arr, off, val0);
+    }
+
+    /**
+     * @param arr Array.
+     * @param off Offset.
+     * @return Value.
+     */
+    public static float readFloat(byte[] arr, int off) {
+        int val = readInt(arr, off);
+
+        return Float.intBitsToFloat(val);
+    }
+
+    /**
+     * @param ptr Pointer.
+     * @param off Offset.
+     * @return Value.
+     */
+    public static float readFloat(long ptr, int off) {
+        int val = readInt(ptr, off);
+
+        return Float.intBitsToFloat(val);
+    }
+
+    /**
+     * @param arr Array.
+     * @param off Offset.
+     * @param val Value.
+     */
+    public static void writeDouble(byte[] arr, int off, double val) {
+        long val0 = Double.doubleToLongBits(val);
+
+        writeLong(arr, off, val0);
+    }
+
+    /**
+     * @param arr Array.
+     * @param off Offset.
+     * @return Value.
+     */
+    public static double readDouble(byte[] arr, int off) {
+        long val = readLong(arr, off);
+
+        return Double.longBitsToDouble(val);
+    }
+
+    /**
+     * @param ptr Pointer.
+     * @param off Offset.
+     * @return Value.
+     */
+    public static double readDouble(long ptr, int off) {
+        long val = readLong(ptr, off);
+
+        return Double.longBitsToDouble(val);
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/71ad9cea/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryRawWriterEx.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryRawWriterEx.java b/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryRawWriterEx.java
index 6e7e0cb..0ba0d90 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryRawWriterEx.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryRawWriterEx.java
@@ -17,7 +17,7 @@
 
 package org.apache.ignite.internal.binary;
 
-import org.apache.ignite.internal.binary.streams.PortableOutputStream;
+import org.apache.ignite.internal.binary.streams.BinaryOutputStream;
 import org.apache.ignite.binary.BinaryObjectException;
 import org.apache.ignite.binary.BinaryRawWriter;
 import org.jetbrains.annotations.Nullable;
@@ -35,7 +35,7 @@ public interface BinaryRawWriterEx extends BinaryRawWriter, AutoCloseable {
     /**
      * @return Output stream.
      */
-    public PortableOutputStream out();
+    public BinaryOutputStream out();
 
     /**
      * Cleans resources.

http://git-wip-us.apache.org/repos/asf/ignite/blob/71ad9cea/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryReaderExImpl.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryReaderExImpl.java b/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryReaderExImpl.java
index bf47d53..b673e27 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryReaderExImpl.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryReaderExImpl.java
@@ -35,50 +35,50 @@ import org.apache.ignite.binary.BinaryObject;
 import org.apache.ignite.binary.BinaryObjectException;
 import org.apache.ignite.binary.BinaryRawReader;
 import org.apache.ignite.binary.BinaryReader;
-import org.apache.ignite.internal.binary.streams.PortableInputStream;
+import org.apache.ignite.internal.binary.streams.BinaryInputStream;
 import org.apache.ignite.internal.util.typedef.internal.SB;
 import org.jetbrains.annotations.NotNull;
 import org.jetbrains.annotations.Nullable;
 
-import static org.apache.ignite.internal.binary.GridPortableMarshaller.BOOLEAN;
-import static org.apache.ignite.internal.binary.GridPortableMarshaller.BOOLEAN_ARR;
-import static org.apache.ignite.internal.binary.GridPortableMarshaller.BYTE;
-import static org.apache.ignite.internal.binary.GridPortableMarshaller.BYTE_ARR;
-import static org.apache.ignite.internal.binary.GridPortableMarshaller.CHAR;
-import static org.apache.ignite.internal.binary.GridPortableMarshaller.CHAR_ARR;
-import static org.apache.ignite.internal.binary.GridPortableMarshaller.CLASS;
-import static org.apache.ignite.internal.binary.GridPortableMarshaller.COL;
-import static org.apache.ignite.internal.binary.GridPortableMarshaller.DATE;
-import static org.apache.ignite.internal.binary.GridPortableMarshaller.DATE_ARR;
-import static org.apache.ignite.internal.binary.GridPortableMarshaller.DECIMAL;
-import static org.apache.ignite.internal.binary.GridPortableMarshaller.DECIMAL_ARR;
-import static org.apache.ignite.internal.binary.GridPortableMarshaller.DFLT_HDR_LEN;
-import static org.apache.ignite.internal.binary.GridPortableMarshaller.DOUBLE;
-import static org.apache.ignite.internal.binary.GridPortableMarshaller.DOUBLE_ARR;
-import static org.apache.ignite.internal.binary.GridPortableMarshaller.ENUM;
-import static org.apache.ignite.internal.binary.GridPortableMarshaller.ENUM_ARR;
-import static org.apache.ignite.internal.binary.GridPortableMarshaller.FLOAT;
-import static org.apache.ignite.internal.binary.GridPortableMarshaller.FLOAT_ARR;
-import static org.apache.ignite.internal.binary.GridPortableMarshaller.HANDLE;
-import static org.apache.ignite.internal.binary.GridPortableMarshaller.INT;
-import static org.apache.ignite.internal.binary.GridPortableMarshaller.INT_ARR;
-import static org.apache.ignite.internal.binary.GridPortableMarshaller.LONG;
-import static org.apache.ignite.internal.binary.GridPortableMarshaller.LONG_ARR;
-import static org.apache.ignite.internal.binary.GridPortableMarshaller.MAP;
-import static org.apache.ignite.internal.binary.GridPortableMarshaller.NULL;
-import static org.apache.ignite.internal.binary.GridPortableMarshaller.OBJ;
-import static org.apache.ignite.internal.binary.GridPortableMarshaller.OBJ_ARR;
-import static org.apache.ignite.internal.binary.GridPortableMarshaller.OPTM_MARSH;
-import static org.apache.ignite.internal.binary.GridPortableMarshaller.PORTABLE_OBJ;
-import static org.apache.ignite.internal.binary.GridPortableMarshaller.SHORT;
-import static org.apache.ignite.internal.binary.GridPortableMarshaller.SHORT_ARR;
-import static org.apache.ignite.internal.binary.GridPortableMarshaller.STRING;
-import static org.apache.ignite.internal.binary.GridPortableMarshaller.STRING_ARR;
-import static org.apache.ignite.internal.binary.GridPortableMarshaller.TIMESTAMP;
-import static org.apache.ignite.internal.binary.GridPortableMarshaller.TIMESTAMP_ARR;
-import static org.apache.ignite.internal.binary.GridPortableMarshaller.UNREGISTERED_TYPE_ID;
-import static org.apache.ignite.internal.binary.GridPortableMarshaller.UUID;
-import static org.apache.ignite.internal.binary.GridPortableMarshaller.UUID_ARR;
+import static org.apache.ignite.internal.binary.GridBinaryMarshaller.BOOLEAN;
+import static org.apache.ignite.internal.binary.GridBinaryMarshaller.BOOLEAN_ARR;
+import static org.apache.ignite.internal.binary.GridBinaryMarshaller.BYTE;
+import static org.apache.ignite.internal.binary.GridBinaryMarshaller.BYTE_ARR;
+import static org.apache.ignite.internal.binary.GridBinaryMarshaller.CHAR;
+import static org.apache.ignite.internal.binary.GridBinaryMarshaller.CHAR_ARR;
+import static org.apache.ignite.internal.binary.GridBinaryMarshaller.CLASS;
+import static org.apache.ignite.internal.binary.GridBinaryMarshaller.COL;
+import static org.apache.ignite.internal.binary.GridBinaryMarshaller.DATE;
+import static org.apache.ignite.internal.binary.GridBinaryMarshaller.DATE_ARR;
+import static org.apache.ignite.internal.binary.GridBinaryMarshaller.DECIMAL;
+import static org.apache.ignite.internal.binary.GridBinaryMarshaller.DECIMAL_ARR;
+import static org.apache.ignite.internal.binary.GridBinaryMarshaller.DFLT_HDR_LEN;
+import static org.apache.ignite.internal.binary.GridBinaryMarshaller.DOUBLE;
+import static org.apache.ignite.internal.binary.GridBinaryMarshaller.DOUBLE_ARR;
+import static org.apache.ignite.internal.binary.GridBinaryMarshaller.ENUM;
+import static org.apache.ignite.internal.binary.GridBinaryMarshaller.ENUM_ARR;
+import static org.apache.ignite.internal.binary.GridBinaryMarshaller.FLOAT;
+import static org.apache.ignite.internal.binary.GridBinaryMarshaller.FLOAT_ARR;
+import static org.apache.ignite.internal.binary.GridBinaryMarshaller.HANDLE;
+import static org.apache.ignite.internal.binary.GridBinaryMarshaller.INT;
+import static org.apache.ignite.internal.binary.GridBinaryMarshaller.INT_ARR;
+import static org.apache.ignite.internal.binary.GridBinaryMarshaller.LONG;
+import static org.apache.ignite.internal.binary.GridBinaryMarshaller.LONG_ARR;
+import static org.apache.ignite.internal.binary.GridBinaryMarshaller.MAP;
+import static org.apache.ignite.internal.binary.GridBinaryMarshaller.NULL;
+import static org.apache.ignite.internal.binary.GridBinaryMarshaller.OBJ;
+import static org.apache.ignite.internal.binary.GridBinaryMarshaller.OBJ_ARR;
+import static org.apache.ignite.internal.binary.GridBinaryMarshaller.OPTM_MARSH;
+import static org.apache.ignite.internal.binary.GridBinaryMarshaller.PORTABLE_OBJ;
+import static org.apache.ignite.internal.binary.GridBinaryMarshaller.SHORT;
+import static org.apache.ignite.internal.binary.GridBinaryMarshaller.SHORT_ARR;
+import static org.apache.ignite.internal.binary.GridBinaryMarshaller.STRING;
+import static org.apache.ignite.internal.binary.GridBinaryMarshaller.STRING_ARR;
+import static org.apache.ignite.internal.binary.GridBinaryMarshaller.TIMESTAMP;
+import static org.apache.ignite.internal.binary.GridBinaryMarshaller.TIMESTAMP_ARR;
+import static org.apache.ignite.internal.binary.GridBinaryMarshaller.UNREGISTERED_TYPE_ID;
+import static org.apache.ignite.internal.binary.GridBinaryMarshaller.UUID;
+import static org.apache.ignite.internal.binary.GridBinaryMarshaller.UUID_ARR;
 
 /**
  * Portable reader implementation.
@@ -86,10 +86,10 @@ import static org.apache.ignite.internal.binary.GridPortableMarshaller.UUID_ARR;
 @SuppressWarnings("unchecked")
 public class BinaryReaderExImpl implements BinaryReader, BinaryRawReaderEx, BinaryReaderHandlesHolder, ObjectInput {
     /** Portable context. */
-    private final PortableContext ctx;
+    private final BinaryContext ctx;
 
     /** Input stream. */
-    private final PortableInputStream in;
+    private final BinaryInputStream in;
 
     /** Class loaded. */
     private final ClassLoader ldr;
@@ -131,7 +131,7 @@ public class BinaryReaderExImpl implements BinaryReader, BinaryRawReaderEx, Bina
     private final int fieldOffsetLen;
 
     /** Object schema. */
-    private final PortableSchema schema;
+    private final BinarySchema schema;
 
     /** Whether passed IDs matches schema order. Reset to false as soon as a single mismatch detected. */
     private boolean matching = true;
@@ -149,7 +149,7 @@ public class BinaryReaderExImpl implements BinaryReader, BinaryRawReaderEx, Bina
      * @param in Input stream.
      * @param ldr Class loader.
      */
-    public BinaryReaderExImpl(PortableContext ctx, PortableInputStream in, ClassLoader ldr) {
+    public BinaryReaderExImpl(BinaryContext ctx, BinaryInputStream in, ClassLoader ldr) {
         this(ctx, in, ldr, null);
     }
 
@@ -161,7 +161,7 @@ public class BinaryReaderExImpl implements BinaryReader, BinaryRawReaderEx, Bina
      * @param ldr Class loader.
      * @param hnds Context.
      */
-    public BinaryReaderExImpl(PortableContext ctx, PortableInputStream in, ClassLoader ldr,
+    public BinaryReaderExImpl(BinaryContext ctx, BinaryInputStream in, ClassLoader ldr,
         @Nullable BinaryReaderHandles hnds) {
         this(ctx, in, ldr, hnds, false);
     }
@@ -175,7 +175,7 @@ public class BinaryReaderExImpl implements BinaryReader, BinaryRawReaderEx, Bina
      * @param hnds Context.
      * @param skipHdrCheck Whether to skip header check.
      */
-    public BinaryReaderExImpl(PortableContext ctx, PortableInputStream in, ClassLoader ldr,
+    public BinaryReaderExImpl(BinaryContext ctx, BinaryInputStream in, ClassLoader ldr,
         @Nullable BinaryReaderHandles hnds, boolean skipHdrCheck) {
         // Initialize base members.
         this.ctx = ctx;
@@ -186,9 +186,9 @@ public class BinaryReaderExImpl implements BinaryReader, BinaryRawReaderEx, Bina
         start = in.position();
 
         // Perform full header parsing in case of portable object.
-        if (!skipHdrCheck && (in.readByte() == GridPortableMarshaller.OBJ)) {
+        if (!skipHdrCheck && (in.readByte() == GridBinaryMarshaller.OBJ)) {
             // Ensure protocol is fine.
-            PortableUtils.checkProtocolVersion(in.readByte());
+            BinaryUtils.checkProtocolVersion(in.readByte());
 
             // Read header content.
             short flags = in.readShort();
@@ -201,16 +201,16 @@ public class BinaryReaderExImpl implements BinaryReader, BinaryRawReaderEx, Bina
             int offset = in.readInt();
 
             // Get trivial flag values.
-            userType = PortableUtils.isUserType(flags);
-            fieldIdLen = PortableUtils.fieldIdLength(flags);
-            fieldOffsetLen = PortableUtils.fieldOffsetLength(flags);
+            userType = BinaryUtils.isUserType(flags);
+            fieldIdLen = BinaryUtils.fieldIdLength(flags);
+            fieldOffsetLen = BinaryUtils.fieldOffsetLength(flags);
 
             // Calculate footer borders and raw offset.
-            if (PortableUtils.hasSchema(flags)) {
+            if (BinaryUtils.hasSchema(flags)) {
                 // Schema exists.
                 footerStart = start + offset;
 
-                if (PortableUtils.hasRaw(flags)) {
+                if (BinaryUtils.hasRaw(flags)) {
                     footerLen = len - offset - 4;
                     rawOff = start + in.readIntPositioned(start + len - 4);
                 }
@@ -224,7 +224,7 @@ public class BinaryReaderExImpl implements BinaryReader, BinaryRawReaderEx, Bina
                 footerStart = start + len;
                 footerLen = 0;
 
-                if (PortableUtils.hasRaw(flags))
+                if (BinaryUtils.hasRaw(flags))
                     rawOff = start + offset;
                 else
                     rawOff = start + len;
@@ -235,7 +235,7 @@ public class BinaryReaderExImpl implements BinaryReader, BinaryRawReaderEx, Bina
                 int off = in.position();
 
                 // Registers class by type ID, at least locally if the cache is not ready yet.
-                typeId = ctx.descriptorForClass(PortableUtils.doReadClass(in, ctx, ldr, typeId0), false).typeId();
+                typeId = ctx.descriptorForClass(BinaryUtils.doReadClass(in, ctx, ldr, typeId0), false).typeId();
 
                 int clsNameLen = in.position() - off;
 
@@ -248,7 +248,7 @@ public class BinaryReaderExImpl implements BinaryReader, BinaryRawReaderEx, Bina
             }
 
             idMapper = userType ? ctx.userTypeIdMapper(typeId) : BinaryInternalIdMapper.defaultInstance();
-            schema = PortableUtils.hasSchema(flags) ? getOrCreateSchema() : null;
+            schema = BinaryUtils.hasSchema(flags) ? getOrCreateSchema() : null;
         }
         else {
             dataStart = 0;
@@ -270,14 +270,14 @@ public class BinaryReaderExImpl implements BinaryReader, BinaryRawReaderEx, Bina
     /**
      * @return Input stream.
      */
-    public PortableInputStream in() {
+    public BinaryInputStream in() {
         return in;
     }
 
     /**
      * @return Descriptor.
      */
-    PortableClassDescriptor descriptor() {
+    BinaryClassDescriptor descriptor() {
         return ctx.descriptorForTypeId(userType, typeId, ldr, true);
     }
 
@@ -289,7 +289,7 @@ public class BinaryReaderExImpl implements BinaryReader, BinaryRawReaderEx, Bina
     public Object unmarshal(int offset) throws BinaryObjectException {
         streamPosition(offset);
 
-        return in.position() >= 0 ? PortableUtils.unmarshal(in, ctx, ldr, this) : null;
+        return in.position() >= 0 ? BinaryUtils.unmarshal(in, ctx, ldr, this) : null;
     }
 
     /**
@@ -298,7 +298,7 @@ public class BinaryReaderExImpl implements BinaryReader, BinaryRawReaderEx, Bina
      * @throws BinaryObjectException In case of error.
      */
     @Nullable Object unmarshalField(String fieldName) throws BinaryObjectException {
-        return findFieldByName(fieldName) ? PortableUtils.unmarshal(in, ctx, ldr, this) : null;
+        return findFieldByName(fieldName) ? BinaryUtils.unmarshal(in, ctx, ldr, this) : null;
     }
 
     /**
@@ -307,7 +307,7 @@ public class BinaryReaderExImpl implements BinaryReader, BinaryRawReaderEx, Bina
      * @throws BinaryObjectException In case of error.
      */
     @Nullable Object unmarshalField(int fieldId) throws BinaryObjectException {
-        return findFieldById(fieldId) ? PortableUtils.unmarshal(in, ctx, ldr, this) : null;
+        return findFieldById(fieldId) ? BinaryUtils.unmarshal(in, ctx, ldr, this) : null;
     }
 
     /**
@@ -320,7 +320,7 @@ public class BinaryReaderExImpl implements BinaryReader, BinaryRawReaderEx, Bina
             if (checkFlag(PORTABLE_OBJ) == Flag.NULL)
                 return null;
 
-            return new BinaryObjectImpl(ctx, PortableUtils.doReadByteArray(in), in.readInt());
+            return new BinaryObjectImpl(ctx, BinaryUtils.doReadByteArray(in), in.readInt());
         }
         else
             return null;
@@ -336,7 +336,7 @@ public class BinaryReaderExImpl implements BinaryReader, BinaryRawReaderEx, Bina
             if (checkFlag(CLASS) == Flag.NULL)
                 return null;
 
-            return PortableUtils.doReadClass(in, ctx, ldr);
+            return BinaryUtils.doReadClass(in, ctx, ldr);
         }
 
         return null;
@@ -374,7 +374,7 @@ public class BinaryReaderExImpl implements BinaryReader, BinaryRawReaderEx, Bina
      * @return Field.
      */
     private <T> T readHandleField() {
-        int handlePos = PortableUtils.positionForHandle(in) - in.readInt();
+        int handlePos = BinaryUtils.positionForHandle(in) - in.readInt();
 
         Object obj = getHandle(handlePos);
 
@@ -383,7 +383,7 @@ public class BinaryReaderExImpl implements BinaryReader, BinaryRawReaderEx, Bina
 
             streamPosition(handlePos);
 
-            obj = PortableUtils.doReadObject(in, ctx, ldr, this);
+            obj = BinaryUtils.doReadObject(in, ctx, ldr, this);
 
             streamPosition(retPos);
         }
@@ -436,7 +436,7 @@ public class BinaryReaderExImpl implements BinaryReader, BinaryRawReaderEx, Bina
     @Nullable @Override public byte[] readByteArray() throws BinaryObjectException {
         switch (checkFlag(BYTE_ARR)) {
             case NORMAL:
-                return PortableUtils.doReadByteArray(in);
+                return BinaryUtils.doReadByteArray(in);
 
             case HANDLE:
                 return readHandleField();
@@ -492,7 +492,7 @@ public class BinaryReaderExImpl implements BinaryReader, BinaryRawReaderEx, Bina
     @Nullable @Override public boolean[] readBooleanArray() throws BinaryObjectException {
         switch (checkFlag(BOOLEAN_ARR)) {
             case NORMAL:
-                return PortableUtils.doReadBooleanArray(in);
+                return BinaryUtils.doReadBooleanArray(in);
 
             case HANDLE:
                 return readHandleField();
@@ -548,7 +548,7 @@ public class BinaryReaderExImpl implements BinaryReader, BinaryRawReaderEx, Bina
     @Nullable @Override public short[] readShortArray() throws BinaryObjectException {
         switch (checkFlag(SHORT_ARR)) {
             case NORMAL:
-                return PortableUtils.doReadShortArray(in);
+                return BinaryUtils.doReadShortArray(in);
 
             case HANDLE:
                 return readHandleField();
@@ -604,7 +604,7 @@ public class BinaryReaderExImpl implements BinaryReader, BinaryRawReaderEx, Bina
     @Nullable @Override public char[] readCharArray() throws BinaryObjectException {
         switch (checkFlag(CHAR_ARR)) {
             case NORMAL:
-                return PortableUtils.doReadCharArray(in);
+                return BinaryUtils.doReadCharArray(in);
 
             case HANDLE:
                 return readHandleField();
@@ -660,7 +660,7 @@ public class BinaryReaderExImpl implements BinaryReader, BinaryRawReaderEx, Bina
     @Nullable @Override public int[] readIntArray() throws BinaryObjectException {
         switch (checkFlag(INT_ARR)) {
             case NORMAL:
-                return PortableUtils.doReadIntArray(in);
+                return BinaryUtils.doReadIntArray(in);
 
             case HANDLE:
                 return readHandleField();
@@ -716,7 +716,7 @@ public class BinaryReaderExImpl implements BinaryReader, BinaryRawReaderEx, Bina
     @Nullable @Override public long[] readLongArray() throws BinaryObjectException {
         switch (checkFlag(LONG_ARR)) {
             case NORMAL:
-                return PortableUtils.doReadLongArray(in);
+                return BinaryUtils.doReadLongArray(in);
 
             case HANDLE:
                 return readHandleField();
@@ -772,7 +772,7 @@ public class BinaryReaderExImpl implements BinaryReader, BinaryRawReaderEx, Bina
     @Nullable @Override public float[] readFloatArray() throws BinaryObjectException {
         switch (checkFlag(FLOAT_ARR)) {
             case NORMAL:
-                return PortableUtils.doReadFloatArray(in);
+                return BinaryUtils.doReadFloatArray(in);
 
             case HANDLE:
                 return readHandleField();
@@ -828,7 +828,7 @@ public class BinaryReaderExImpl implements BinaryReader, BinaryRawReaderEx, Bina
     @Nullable @Override public double[] readDoubleArray() throws BinaryObjectException {
         switch (checkFlag(DOUBLE_ARR)) {
             case NORMAL:
-                return PortableUtils.doReadDoubleArray(in);
+                return BinaryUtils.doReadDoubleArray(in);
 
             case HANDLE:
                 return readHandleField();
@@ -854,7 +854,7 @@ public class BinaryReaderExImpl implements BinaryReader, BinaryRawReaderEx, Bina
 
     /** {@inheritDoc} */
     @Override @Nullable public BigDecimal readDecimal() throws BinaryObjectException {
-        return checkFlagNoHandles(DECIMAL) == Flag.NORMAL ? PortableUtils.doReadDecimal(in) : null;
+        return checkFlagNoHandles(DECIMAL) == Flag.NORMAL ? BinaryUtils.doReadDecimal(in) : null;
     }
 
     /** {@inheritDoc} */
@@ -875,7 +875,7 @@ public class BinaryReaderExImpl implements BinaryReader, BinaryRawReaderEx, Bina
     @Override @Nullable public BigDecimal[] readDecimalArray() throws BinaryObjectException {
         switch (checkFlag(DECIMAL_ARR)) {
             case NORMAL:
-                return PortableUtils.doReadDecimalArray(in);
+                return BinaryUtils.doReadDecimalArray(in);
 
             case HANDLE:
                 return readHandleField();
@@ -901,7 +901,7 @@ public class BinaryReaderExImpl implements BinaryReader, BinaryRawReaderEx, Bina
 
     /** {@inheritDoc} */
     @Override @Nullable public String readString() throws BinaryObjectException {
-        return checkFlagNoHandles(STRING) == Flag.NORMAL ? PortableUtils.doReadString(in) : null;
+        return checkFlagNoHandles(STRING) == Flag.NORMAL ? BinaryUtils.doReadString(in) : null;
     }
 
     /** {@inheritDoc} */
@@ -922,7 +922,7 @@ public class BinaryReaderExImpl implements BinaryReader, BinaryRawReaderEx, Bina
     @Override @Nullable public String[] readStringArray() throws BinaryObjectException {
         switch (checkFlag(STRING_ARR)) {
             case NORMAL:
-                return PortableUtils.doReadStringArray(in);
+                return BinaryUtils.doReadStringArray(in);
 
             case HANDLE:
                 return readHandleField();
@@ -948,7 +948,7 @@ public class BinaryReaderExImpl implements BinaryReader, BinaryRawReaderEx, Bina
 
     /** {@inheritDoc} */
     @Override @Nullable public UUID readUuid() throws BinaryObjectException {
-        return checkFlagNoHandles(UUID) == Flag.NORMAL ? PortableUtils.doReadUuid(in) : null;
+        return checkFlagNoHandles(UUID) == Flag.NORMAL ? BinaryUtils.doReadUuid(in) : null;
     }
 
     /** {@inheritDoc} */
@@ -969,7 +969,7 @@ public class BinaryReaderExImpl implements BinaryReader, BinaryRawReaderEx, Bina
     @Override @Nullable public UUID[] readUuidArray() throws BinaryObjectException {
         switch (checkFlag(UUID_ARR)) {
             case NORMAL:
-                return PortableUtils.doReadUuidArray(in);
+                return BinaryUtils.doReadUuidArray(in);
 
             case HANDLE:
                 return readHandleField();
@@ -995,7 +995,7 @@ public class BinaryReaderExImpl implements BinaryReader, BinaryRawReaderEx, Bina
 
     /** {@inheritDoc} */
     @Override @Nullable public Date readDate() throws BinaryObjectException {
-        return checkFlagNoHandles(DATE) == Flag.NORMAL ? PortableUtils.doReadDate(in) : null;
+        return checkFlagNoHandles(DATE) == Flag.NORMAL ? BinaryUtils.doReadDate(in) : null;
     }
 
     /** {@inheritDoc} */
@@ -1016,7 +1016,7 @@ public class BinaryReaderExImpl implements BinaryReader, BinaryRawReaderEx, Bina
     @Override @Nullable public Date[] readDateArray() throws BinaryObjectException {
         switch (checkFlag(DATE_ARR)) {
             case NORMAL:
-                return PortableUtils.doReadDateArray(in);
+                return BinaryUtils.doReadDateArray(in);
 
             case HANDLE:
                 return readHandleField();
@@ -1042,7 +1042,7 @@ public class BinaryReaderExImpl implements BinaryReader, BinaryRawReaderEx, Bina
 
     /** {@inheritDoc} */
     @Override @Nullable public Timestamp readTimestamp() throws BinaryObjectException {
-        return checkFlagNoHandles(TIMESTAMP) == Flag.NORMAL ? PortableUtils.doReadTimestamp(in) : null;
+        return checkFlagNoHandles(TIMESTAMP) == Flag.NORMAL ? BinaryUtils.doReadTimestamp(in) : null;
     }
 
     /** {@inheritDoc} */
@@ -1063,7 +1063,7 @@ public class BinaryReaderExImpl implements BinaryReader, BinaryRawReaderEx, Bina
     @Override @Nullable public Timestamp[] readTimestampArray() throws BinaryObjectException {
         switch (checkFlag(TIMESTAMP_ARR)) {
             case NORMAL:
-                return PortableUtils.doReadTimestampArray(in);
+                return BinaryUtils.doReadTimestampArray(in);
 
             case HANDLE:
                 return readHandleField();
@@ -1076,7 +1076,7 @@ public class BinaryReaderExImpl implements BinaryReader, BinaryRawReaderEx, Bina
     /** {@inheritDoc} */
     @SuppressWarnings("unchecked")
     @Nullable @Override public <T> T readObject(String fieldName) throws BinaryObjectException {
-        return findFieldByName(fieldName) ? (T)PortableUtils.doReadObject(in, ctx, ldr, this) : null;
+        return findFieldByName(fieldName) ? (T)BinaryUtils.doReadObject(in, ctx, ldr, this) : null;
     }
 
     /**
@@ -1085,17 +1085,17 @@ public class BinaryReaderExImpl implements BinaryReader, BinaryRawReaderEx, Bina
      * @throws BinaryObjectException In case of error.
      */
     @Nullable Object readObject(int fieldId) throws BinaryObjectException {
-        return findFieldById(fieldId) ? PortableUtils.doReadObject(in, ctx, ldr, this) : null;
+        return findFieldById(fieldId) ? BinaryUtils.doReadObject(in, ctx, ldr, this) : null;
     }
 
     /** {@inheritDoc} */
     @Override public Object readObject() throws BinaryObjectException {
-        return PortableUtils.doReadObject(in, ctx, ldr, this);
+        return BinaryUtils.doReadObject(in, ctx, ldr, this);
     }
 
     /** {@inheritDoc} */
     @Nullable @Override public Object readObjectDetached() throws BinaryObjectException {
-        return PortableUtils.unmarshal(in, ctx, ldr, this, true);
+        return BinaryUtils.unmarshal(in, ctx, ldr, this, true);
     }
 
     /** {@inheritDoc} */
@@ -1116,7 +1116,7 @@ public class BinaryReaderExImpl implements BinaryReader, BinaryRawReaderEx, Bina
     @Nullable @Override public Object[] readObjectArray() throws BinaryObjectException {
         switch (checkFlag(OBJ_ARR)) {
             case NORMAL:
-                return PortableUtils.doReadObjectArray(in, ctx, ldr, this, true);
+                return BinaryUtils.doReadObjectArray(in, ctx, ldr, this, true);
 
             case HANDLE:
                 return readHandleField();
@@ -1156,12 +1156,12 @@ public class BinaryReaderExImpl implements BinaryReader, BinaryRawReaderEx, Bina
     private Enum<?> readEnum0(@Nullable Class<?> cls) throws BinaryObjectException {
         if (checkFlagNoHandles(ENUM) == Flag.NORMAL) {
             // Read class even if we know it in advance to set correct stream position.
-            Class<?> cls0 = PortableUtils.doReadClass(in, ctx, ldr);
+            Class<?> cls0 = BinaryUtils.doReadClass(in, ctx, ldr);
 
             if (cls == null)
                 cls = cls0;
 
-            return PortableUtils.doReadEnum(in, cls);
+            return BinaryUtils.doReadEnum(in, cls);
         }
         else
             return null;
@@ -1199,12 +1199,12 @@ public class BinaryReaderExImpl implements BinaryReader, BinaryRawReaderEx, Bina
         switch (checkFlag(ENUM_ARR)) {
             case NORMAL:
                 // Read class even if we know it in advance to set correct stream position.
-                Class<?> cls0 = PortableUtils.doReadClass(in, ctx, ldr);
+                Class<?> cls0 = BinaryUtils.doReadClass(in, ctx, ldr);
 
                 if (cls == null)
                     cls = cls0;
 
-                return PortableUtils.doReadEnumArray(in, ctx, ldr, cls);
+                return BinaryUtils.doReadEnumArray(in, ctx, ldr, cls);
 
             case HANDLE:
                 return readHandleField();
@@ -1258,10 +1258,10 @@ public class BinaryReaderExImpl implements BinaryReader, BinaryRawReaderEx, Bina
         throws BinaryObjectException {
         switch (checkFlag(COL)) {
             case NORMAL:
-                return (Collection)PortableUtils.doReadCollection(in, ctx, ldr, this, true, factory);
+                return (Collection)BinaryUtils.doReadCollection(in, ctx, ldr, this, true, factory);
 
             case HANDLE: {
-                int handlePos = PortableUtils.positionForHandle(in) - in.readInt();
+                int handlePos = BinaryUtils.positionForHandle(in) - in.readInt();
 
                 Object obj = getHandle(handlePos);
 
@@ -1325,10 +1325,10 @@ public class BinaryReaderExImpl implements BinaryReader, BinaryRawReaderEx, Bina
     private Map readMap0(@Nullable BinaryMapFactory factory) throws BinaryObjectException {
         switch (checkFlag(MAP)) {
             case NORMAL:
-                return (Map)PortableUtils.doReadMap(in, ctx, ldr, this, true, factory);
+                return (Map)BinaryUtils.doReadMap(in, ctx, ldr, this, true, factory);
 
             case HANDLE: {
-                int handlePos = PortableUtils.positionForHandle(in) - in.readInt();
+                int handlePos = BinaryUtils.positionForHandle(in) - in.readInt();
 
                 Object obj = getHandle(handlePos);
 
@@ -1367,7 +1367,7 @@ public class BinaryReaderExImpl implements BinaryReader, BinaryRawReaderEx, Bina
         else if (flag == HANDLE)
             return Flag.HANDLE;
 
-        int pos = PortableUtils.positionForHandle(in);
+        int pos = BinaryUtils.positionForHandle(in);
 
         throw new BinaryObjectException("Unexpected flag value [pos=" + pos + ", expected=" + expFlag +
             ", actual=" + flag + ']');
@@ -1388,7 +1388,7 @@ public class BinaryReaderExImpl implements BinaryReader, BinaryRawReaderEx, Bina
         else if (flag == NULL)
             return Flag.NULL;
 
-        int pos = PortableUtils.positionForHandle(in);
+        int pos = BinaryUtils.positionForHandle(in);
 
         throw new BinaryObjectException("Unexpected flag value [pos=" + pos + ", expected=" + expFlag +
             ", actual=" + flag + ']');
@@ -1432,7 +1432,7 @@ public class BinaryReaderExImpl implements BinaryReader, BinaryRawReaderEx, Bina
 
                     streamPosition(handlePos);
 
-                    obj = PortableUtils.doReadObject(in, ctx, ldr, this);
+                    obj = BinaryUtils.doReadObject(in, ctx, ldr, this);
 
                     streamPosition(retPos);
                 }
@@ -1440,7 +1440,7 @@ public class BinaryReaderExImpl implements BinaryReader, BinaryRawReaderEx, Bina
                 break;
 
             case OBJ:
-                PortableClassDescriptor desc = ctx.descriptorForTypeId(userType, typeId, ldr, true);
+                BinaryClassDescriptor desc = ctx.descriptorForTypeId(userType, typeId, ldr, true);
 
                 streamPosition(dataStart);
 
@@ -1494,137 +1494,137 @@ public class BinaryReaderExImpl implements BinaryReader, BinaryRawReaderEx, Bina
                 break;
 
             case DECIMAL:
-                obj = PortableUtils.doReadDecimal(in);
+                obj = BinaryUtils.doReadDecimal(in);
 
                 break;
 
             case STRING:
-                obj = PortableUtils.doReadString(in);
+                obj = BinaryUtils.doReadString(in);
 
                 break;
 
             case UUID:
-                obj = PortableUtils.doReadUuid(in);
+                obj = BinaryUtils.doReadUuid(in);
 
                 break;
 
             case DATE:
-                obj = PortableUtils.doReadDate(in);
+                obj = BinaryUtils.doReadDate(in);
 
                 break;
 
             case TIMESTAMP:
-                obj = PortableUtils.doReadTimestamp(in);
+                obj = BinaryUtils.doReadTimestamp(in);
 
                 break;
 
             case BYTE_ARR:
-                obj = PortableUtils.doReadByteArray(in);
+                obj = BinaryUtils.doReadByteArray(in);
 
                 break;
 
             case SHORT_ARR:
-                obj = PortableUtils.doReadShortArray(in);
+                obj = BinaryUtils.doReadShortArray(in);
 
                 break;
 
             case INT_ARR:
-                obj = PortableUtils.doReadIntArray(in);
+                obj = BinaryUtils.doReadIntArray(in);
 
                 break;
 
             case LONG_ARR:
-                obj = PortableUtils.doReadLongArray(in);
+                obj = BinaryUtils.doReadLongArray(in);
 
                 break;
 
             case FLOAT_ARR:
-                obj = PortableUtils.doReadFloatArray(in);
+                obj = BinaryUtils.doReadFloatArray(in);
 
                 break;
 
             case DOUBLE_ARR:
-                obj = PortableUtils.doReadDoubleArray(in);
+                obj = BinaryUtils.doReadDoubleArray(in);
 
                 break;
 
             case CHAR_ARR:
-                obj = PortableUtils.doReadCharArray(in);
+                obj = BinaryUtils.doReadCharArray(in);
 
                 break;
 
             case BOOLEAN_ARR:
-                obj = PortableUtils.doReadBooleanArray(in);
+                obj = BinaryUtils.doReadBooleanArray(in);
 
                 break;
 
             case DECIMAL_ARR:
-                obj = PortableUtils.doReadDecimalArray(in);
+                obj = BinaryUtils.doReadDecimalArray(in);
 
                 break;
 
             case STRING_ARR:
-                obj = PortableUtils.doReadStringArray(in);
+                obj = BinaryUtils.doReadStringArray(in);
 
                 break;
 
             case UUID_ARR:
-                obj = PortableUtils.doReadUuidArray(in);
+                obj = BinaryUtils.doReadUuidArray(in);
 
                 break;
 
             case DATE_ARR:
-                obj = PortableUtils.doReadDateArray(in);
+                obj = BinaryUtils.doReadDateArray(in);
 
                 break;
 
             case TIMESTAMP_ARR:
-                obj = PortableUtils.doReadTimestampArray(in);
+                obj = BinaryUtils.doReadTimestampArray(in);
 
                 break;
 
             case OBJ_ARR:
-                obj = PortableUtils.doReadObjectArray(in, ctx, ldr, this, true);
+                obj = BinaryUtils.doReadObjectArray(in, ctx, ldr, this, true);
 
                 break;
 
             case COL:
-                obj = PortableUtils.doReadCollection(in, ctx, ldr, this, true, null);
+                obj = BinaryUtils.doReadCollection(in, ctx, ldr, this, true, null);
 
                 break;
 
             case MAP:
-                obj = PortableUtils.doReadMap(in, ctx, ldr, this, true, null);
+                obj = BinaryUtils.doReadMap(in, ctx, ldr, this, true, null);
 
                 break;
 
             case PORTABLE_OBJ:
-                obj = PortableUtils.doReadPortableObject(in, ctx);
+                obj = BinaryUtils.doReadPortableObject(in, ctx);
 
                 ((BinaryObjectImpl)obj).context(ctx);
 
-                if (!GridPortableMarshaller.KEEP_PORTABLES.get())
+                if (!GridBinaryMarshaller.KEEP_PORTABLES.get())
                     obj = ((BinaryObject)obj).deserialize();
 
                 break;
 
             case ENUM:
-                obj = PortableUtils.doReadEnum(in, PortableUtils.doReadClass(in, ctx, ldr));
+                obj = BinaryUtils.doReadEnum(in, BinaryUtils.doReadClass(in, ctx, ldr));
 
                 break;
 
             case ENUM_ARR:
-                obj = PortableUtils.doReadEnumArray(in, ctx, ldr, PortableUtils.doReadClass(in, ctx, ldr));
+                obj = BinaryUtils.doReadEnumArray(in, ctx, ldr, BinaryUtils.doReadClass(in, ctx, ldr));
 
                 break;
 
             case CLASS:
-                obj = PortableUtils.doReadClass(in, ctx, ldr);
+                obj = BinaryUtils.doReadClass(in, ctx, ldr);
 
                 break;
 
             case OPTM_MARSH:
-                obj = PortableUtils.doReadOptimized(in, ctx, ldr);
+                obj = BinaryUtils.doReadOptimized(in, ctx, ldr);
 
                 break;
 
@@ -1661,18 +1661,18 @@ public class BinaryReaderExImpl implements BinaryReader, BinaryRawReaderEx, Bina
      *
      * @return Schema.
      */
-    public PortableSchema getOrCreateSchema() {
-        PortableSchema schema = ctx.schemaRegistry(typeId).schema(schemaId);
+    public BinarySchema getOrCreateSchema() {
+        BinarySchema schema = ctx.schemaRegistry(typeId).schema(schemaId);
 
         if (schema == null) {
-            if (fieldIdLen != PortableUtils.FIELD_ID_LEN) {
+            if (fieldIdLen != BinaryUtils.FIELD_ID_LEN) {
                 BinaryTypeImpl type = (BinaryTypeImpl)ctx.metadata(typeId);
 
                 if (type == null || type.metadata() == null)
                     throw new BinaryObjectException("Cannot find metadata for object with compact footer: " +
                         typeId);
 
-                for (PortableSchema typeSchema : type.metadata().schemas()) {
+                for (BinarySchema typeSchema : type.metadata().schemas()) {
                     if (schemaId == typeSchema.schemaId()) {
                         schema = typeSchema;
 
@@ -1700,10 +1700,10 @@ public class BinaryReaderExImpl implements BinaryReader, BinaryRawReaderEx, Bina
      *
      * @return Schema.
      */
-    private PortableSchema createSchema() {
-        assert fieldIdLen == PortableUtils.FIELD_ID_LEN;
+    private BinarySchema createSchema() {
+        assert fieldIdLen == BinaryUtils.FIELD_ID_LEN;
 
-        PortableSchema.Builder builder = PortableSchema.Builder.newBuilder();
+        BinarySchema.Builder builder = BinarySchema.Builder.newBuilder();
 
         int searchPos = footerStart;
         int searchEnd = searchPos + footerLen;
@@ -1713,7 +1713,7 @@ public class BinaryReaderExImpl implements BinaryReader, BinaryRawReaderEx, Bina
 
             builder.addField(fieldId);
 
-            searchPos += PortableUtils.FIELD_ID_LEN + fieldOffsetLen;
+            searchPos += BinaryUtils.FIELD_ID_LEN + fieldOffsetLen;
         }
 
         return builder.build();
@@ -1740,7 +1740,7 @@ public class BinaryReaderExImpl implements BinaryReader, BinaryRawReaderEx, Bina
             if (matching) {
                 int expOrder = matchingOrder++;
 
-                PortableSchema.Confirmation confirm = schema.confirmOrder(expOrder, name);
+                BinarySchema.Confirmation confirm = schema.confirmOrder(expOrder, name);
 
                 switch (confirm) {
                     case CONFIRMED:
@@ -1761,7 +1761,7 @@ public class BinaryReaderExImpl implements BinaryReader, BinaryRawReaderEx, Bina
 
                     default:
                         // Field name is not know for this order. Need to calculate ID and repeat speculation.
-                        assert confirm == PortableSchema.Confirmation.CLARIFY;
+                        assert confirm == BinarySchema.Confirmation.CLARIFY;
 
                         int id = fieldId(name);
                         int realId = schema.fieldId(expOrder);
@@ -1846,10 +1846,10 @@ public class BinaryReaderExImpl implements BinaryReader, BinaryRawReaderEx, Bina
      * @return {@code True} if field was found and stream was positioned accordingly.
      */
     private boolean trySetUserFieldPosition(int order) {
-        if (order != PortableSchema.ORDER_NOT_FOUND) {
+        if (order != BinarySchema.ORDER_NOT_FOUND) {
             int offsetPos = footerStart + order * (fieldIdLen + fieldOffsetLen) + fieldIdLen;
 
-            int pos = start + PortableUtils.fieldOffsetRelative(in, offsetPos, fieldOffsetLen);
+            int pos = start + BinaryUtils.fieldOffsetRelative(in, offsetPos, fieldOffsetLen);
 
             streamPosition(pos);
 
@@ -1867,7 +1867,7 @@ public class BinaryReaderExImpl implements BinaryReader, BinaryRawReaderEx, Bina
      */
     private boolean trySetSystemFieldPosition(int id) {
         // System types are never written with compact footers because they do not have metadata.
-        assert fieldIdLen == PortableUtils.FIELD_ID_LEN;
+        assert fieldIdLen == BinaryUtils.FIELD_ID_LEN;
 
         int searchPos = footerStart;
         int searchTail = searchPos + footerLen;
@@ -1879,7 +1879,7 @@ public class BinaryReaderExImpl implements BinaryReader, BinaryRawReaderEx, Bina
             int id0 = in.readIntPositioned(searchPos);
 
             if (id0 == id) {
-                int pos = start + PortableUtils.fieldOffsetRelative(in, searchPos + PortableUtils.FIELD_ID_LEN,
+                int pos = start + BinaryUtils.fieldOffsetRelative(in, searchPos + BinaryUtils.FIELD_ID_LEN,
                     fieldOffsetLen);
 
                 streamPosition(pos);
@@ -1887,7 +1887,7 @@ public class BinaryReaderExImpl implements BinaryReader, BinaryRawReaderEx, Bina
                 return true;
             }
 
-            searchPos += PortableUtils.FIELD_ID_LEN + fieldOffsetLen;
+            searchPos += BinaryUtils.FIELD_ID_LEN + fieldOffsetLen;
         }
     }
 


[04/59] [abbrv] ignite git commit: ignite-2065: rename "portable" packages to "binary"

Posted by ak...@apache.org.
http://git-wip-us.apache.org/repos/asf/ignite/blob/1dbf20e0/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/binary/datastreaming/GridDataStreamerImplSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/binary/datastreaming/GridDataStreamerImplSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/binary/datastreaming/GridDataStreamerImplSelfTest.java
new file mode 100644
index 0000000..125a055
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/binary/datastreaming/GridDataStreamerImplSelfTest.java
@@ -0,0 +1,345 @@
+/*
+ * 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.processors.cache.binary.datastreaming;
+
+import java.io.Serializable;
+import java.util.Map;
+import java.util.Random;
+import org.apache.ignite.Ignite;
+import org.apache.ignite.IgniteCache;
+import org.apache.ignite.IgniteDataStreamer;
+import org.apache.ignite.cache.CachePeekMode;
+import org.apache.ignite.cluster.ClusterNode;
+import org.apache.ignite.configuration.CacheConfiguration;
+import org.apache.ignite.configuration.IgniteConfiguration;
+import org.apache.ignite.internal.processors.cache.IgniteCacheProxy;
+import org.apache.ignite.internal.util.typedef.G;
+import org.apache.ignite.internal.util.typedef.internal.U;
+import org.apache.ignite.internal.binary.BinaryMarshaller;
+import org.apache.ignite.binary.BinaryObjectException;
+import org.apache.ignite.binary.Binarylizable;
+import org.apache.ignite.binary.BinaryObject;
+import org.apache.ignite.binary.BinaryReader;
+import org.apache.ignite.binary.BinaryWriter;
+import org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi;
+import org.apache.ignite.spi.discovery.tcp.ipfinder.TcpDiscoveryIpFinder;
+import org.apache.ignite.spi.discovery.tcp.ipfinder.vm.TcpDiscoveryVmIpFinder;
+import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
+
+import static org.apache.ignite.cache.CacheMode.PARTITIONED;
+import static org.apache.ignite.cache.CacheWriteSynchronizationMode.FULL_SYNC;
+
+/**
+ * Tests for {@code IgniteDataStreamerImpl}.
+ */
+public class GridDataStreamerImplSelfTest extends GridCommonAbstractTest {
+    /** IP finder. */
+    private static final TcpDiscoveryIpFinder IP_FINDER = new TcpDiscoveryVmIpFinder(true);
+
+    /** Number of keys to load via data streamer. */
+    private static final int KEYS_COUNT = 1000;
+
+    /** Flag indicating should be cache configured with binary or not.  */
+    private static boolean portables;
+
+    /** {@inheritDoc} */
+    @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception {
+        IgniteConfiguration cfg = super.getConfiguration(gridName);
+
+        TcpDiscoverySpi discoSpi = new TcpDiscoverySpi();
+        discoSpi.setIpFinder(IP_FINDER);
+
+        cfg.setDiscoverySpi(discoSpi);
+
+        if (portables) {
+            BinaryMarshaller marsh = new BinaryMarshaller();
+
+            cfg.setMarshaller(marsh);
+        }
+
+        cfg.setCacheConfiguration(cacheConfiguration());
+
+        return cfg;
+    }
+
+    /**
+     * Gets cache configuration.
+     *
+     * @return Cache configuration.
+     */
+    private CacheConfiguration cacheConfiguration() {
+        CacheConfiguration cacheCfg = defaultCacheConfiguration();
+
+        cacheCfg.setCacheMode(PARTITIONED);
+        cacheCfg.setNearConfiguration(null);
+        cacheCfg.setBackups(0);
+        cacheCfg.setWriteSynchronizationMode(FULL_SYNC);
+
+        return cacheCfg;
+    }
+
+    /**
+     * Data streamer should correctly load entries from HashMap in case of grids with more than one node
+     *  and with GridOptimizedMarshaller that requires serializable.
+     *
+     * @throws Exception If failed.
+     */
+    public void testAddDataFromMap() throws Exception {
+        try {
+            portables = false;
+
+            startGrids(2);
+
+            awaitPartitionMapExchange();
+
+            Ignite g0 = grid(0);
+
+            IgniteDataStreamer<Integer, String> dataLdr = g0.dataStreamer(null);
+
+            Map<Integer, String> map = U.newHashMap(KEYS_COUNT);
+
+            for (int i = 0; i < KEYS_COUNT; i ++)
+                map.put(i, String.valueOf(i));
+
+            dataLdr.addData(map);
+
+            dataLdr.close();
+
+            checkDistribution(grid(0));
+
+            checkDistribution(grid(1));
+
+            // Check several random keys in cache.
+            Random rnd = new Random();
+
+            IgniteCache<Integer, String> c0 = g0.cache(null);
+
+            for (int i = 0; i < 100; i ++) {
+                Integer k = rnd.nextInt(KEYS_COUNT);
+
+                String v = c0.get(k);
+
+                assertEquals(k.toString(), v);
+            }
+        }
+        finally {
+            G.stopAll(true);
+        }
+    }
+
+    /**
+     * Data streamer should add portable object that weren't registered explicitly.
+     *
+     * @throws Exception If failed.
+     */
+    public void testAddMissingPortable() throws Exception {
+        try {
+            portables = true;
+
+            startGrids(2);
+
+            awaitPartitionMapExchange();
+
+            Ignite g0 = grid(0);
+
+            IgniteDataStreamer<Integer, TestObject2> dataLdr = g0.dataStreamer(null);
+
+            dataLdr.perNodeBufferSize(1);
+            dataLdr.autoFlushFrequency(1L);
+
+            Map<Integer, TestObject2> map = U.newHashMap(KEYS_COUNT);
+
+            for (int i = 0; i < KEYS_COUNT; i ++)
+                map.put(i, new TestObject2(i));
+
+            dataLdr.addData(map).get();
+
+            dataLdr.close();
+        }
+        finally {
+            G.stopAll(true);
+        }
+    }
+
+    /**
+     * Data streamer should correctly load portable entries from HashMap in case of grids with more than one node
+     *  and with GridOptimizedMarshaller that requires serializable.
+     *
+     * @throws Exception If failed.
+     */
+    public void testAddPortableDataFromMap() throws Exception {
+        try {
+            portables = true;
+
+            startGrids(2);
+
+            awaitPartitionMapExchange();
+
+            Ignite g0 = grid(0);
+
+            IgniteDataStreamer<Integer, TestObject> dataLdr = g0.dataStreamer(null);
+
+            Map<Integer, TestObject> map = U.newHashMap(KEYS_COUNT);
+
+            for (int i = 0; i < KEYS_COUNT; i ++)
+                map.put(i, new TestObject(i));
+
+            dataLdr.addData(map);
+
+            dataLdr.close(false);
+
+            checkDistribution(grid(0));
+
+            checkDistribution(grid(1));
+
+            // Read random keys. Take values as TestObject.
+            Random rnd = new Random();
+
+            IgniteCache<Integer, TestObject> c = g0.cache(null);
+
+            for (int i = 0; i < 100; i ++) {
+                Integer k = rnd.nextInt(KEYS_COUNT);
+
+                TestObject v = c.get(k);
+
+                assertEquals(k, v.val());
+            }
+
+            // Read random keys. Take values as PortableObject.
+            IgniteCache<Integer, BinaryObject> c2 = ((IgniteCacheProxy)c).keepPortable();
+
+            for (int i = 0; i < 100; i ++) {
+                Integer k = rnd.nextInt(KEYS_COUNT);
+
+                BinaryObject v = c2.get(k);
+
+                assertEquals(k, v.field("val"));
+            }
+        }
+        finally {
+            G.stopAll(true);
+        }
+    }
+
+    /**
+     * Check that keys correctly destributed by nodes after data streamer.
+     *
+     * @param g Grid to check.
+     */
+    private void checkDistribution(Ignite g) {
+        ClusterNode n = g.cluster().localNode();
+        IgniteCache c = g.cache(null);
+
+        // Check that data streamer correctly split data by nodes.
+        for (int i = 0; i < KEYS_COUNT; i ++) {
+            if (g.affinity(null).isPrimary(n, i))
+                assertNotNull(c.localPeek(i, CachePeekMode.ONHEAP));
+            else
+                assertNull(c.localPeek(i, CachePeekMode.ONHEAP));
+        }
+    }
+
+    /**
+     */
+    private static class TestObject implements Binarylizable, Serializable {
+        /** */
+        private int val;
+
+        /**
+         *
+         */
+        private TestObject() {
+            // No-op.
+        }
+
+        /**
+         * @param val Value.
+         */
+        private TestObject(int val) {
+            this.val = val;
+        }
+
+        public Integer val() {
+            return val;
+        }
+
+        /** {@inheritDoc} */
+        @Override public int hashCode() {
+            return val;
+        }
+
+        /** {@inheritDoc} */
+        @Override public boolean equals(Object obj) {
+            return obj instanceof TestObject && ((TestObject)obj).val == val;
+        }
+
+        /** {@inheritDoc} */
+        @Override public void writeBinary(BinaryWriter writer) throws BinaryObjectException {
+            writer.writeInt("val", val);
+        }
+
+        /** {@inheritDoc} */
+        @Override public void readBinary(BinaryReader reader) throws BinaryObjectException {
+            val = reader.readInt("val");
+        }
+    }
+
+    /**
+     */
+    private static class TestObject2 implements Binarylizable, Serializable {
+        /** */
+        private int val;
+
+        /**
+         */
+        private TestObject2() {
+            // No-op.
+        }
+
+        /**
+         * @param val Value.
+         */
+        private TestObject2(int val) {
+            this.val = val;
+        }
+
+        public Integer val() {
+            return val;
+        }
+
+        /** {@inheritDoc} */
+        @Override public int hashCode() {
+            return val;
+        }
+
+        /** {@inheritDoc} */
+        @Override public boolean equals(Object obj) {
+            return obj instanceof TestObject2 && ((TestObject2)obj).val == val;
+        }
+
+        /** {@inheritDoc} */
+        @Override public void writeBinary(BinaryWriter writer) throws BinaryObjectException {
+            writer.writeInt("val", val);
+        }
+
+        /** {@inheritDoc} */
+        @Override public void readBinary(BinaryReader reader) throws BinaryObjectException {
+            val = reader.readInt("val");
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/1dbf20e0/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/binary/distributed/dht/GridCacheAffinityRoutingPortableSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/binary/distributed/dht/GridCacheAffinityRoutingPortableSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/binary/distributed/dht/GridCacheAffinityRoutingPortableSelfTest.java
new file mode 100644
index 0000000..9f564dd
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/binary/distributed/dht/GridCacheAffinityRoutingPortableSelfTest.java
@@ -0,0 +1,54 @@
+/*
+ * 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.processors.cache.binary.distributed.dht;
+
+import java.util.Collections;
+import org.apache.ignite.cache.CacheKeyConfiguration;
+import org.apache.ignite.configuration.BinaryConfiguration;
+import org.apache.ignite.configuration.IgniteConfiguration;
+import org.apache.ignite.internal.processors.cache.GridCacheAffinityRoutingSelfTest;
+import org.apache.ignite.internal.binary.BinaryMarshaller;
+import org.apache.ignite.binary.BinaryTypeConfiguration;
+
+/**
+ *
+ */
+public class GridCacheAffinityRoutingPortableSelfTest extends GridCacheAffinityRoutingSelfTest {
+    /** {@inheritDoc} */
+    @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception {
+        IgniteConfiguration cfg = super.getConfiguration(gridName);
+
+        BinaryTypeConfiguration typeCfg = new BinaryTypeConfiguration();
+
+        typeCfg.setTypeName(AffinityTestKey.class.getName());
+
+        CacheKeyConfiguration keyCfg = new CacheKeyConfiguration(AffinityTestKey.class.getName(), "affKey");
+
+        cfg.setCacheKeyConfiguration(keyCfg);
+
+        BinaryConfiguration bCfg = new BinaryConfiguration();
+
+        bCfg.setTypeConfigurations(Collections.singleton(typeCfg));
+
+        cfg.setBinaryConfiguration(bCfg);
+
+        cfg.setMarshaller(new BinaryMarshaller());
+
+        return cfg;
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/1dbf20e0/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/binary/distributed/dht/GridCacheAtomicPartitionedOnlyPortableDataStreamerMultiNodeSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/binary/distributed/dht/GridCacheAtomicPartitionedOnlyPortableDataStreamerMultiNodeSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/binary/distributed/dht/GridCacheAtomicPartitionedOnlyPortableDataStreamerMultiNodeSelfTest.java
new file mode 100644
index 0000000..82ad26f
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/binary/distributed/dht/GridCacheAtomicPartitionedOnlyPortableDataStreamerMultiNodeSelfTest.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.processors.cache.binary.distributed.dht;
+
+/**
+ *
+ */
+public class GridCacheAtomicPartitionedOnlyPortableDataStreamerMultiNodeSelfTest extends
+    GridCacheAtomicPartitionedOnlyPortableDataStreamerMultithreadedSelfTest {
+    /** {@inheritDoc} */
+    @Override protected int gridCount() {
+        return 4;
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/1dbf20e0/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/binary/distributed/dht/GridCacheAtomicPartitionedOnlyPortableDataStreamerMultithreadedSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/binary/distributed/dht/GridCacheAtomicPartitionedOnlyPortableDataStreamerMultithreadedSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/binary/distributed/dht/GridCacheAtomicPartitionedOnlyPortableDataStreamerMultithreadedSelfTest.java
new file mode 100644
index 0000000..3e37a18
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/binary/distributed/dht/GridCacheAtomicPartitionedOnlyPortableDataStreamerMultithreadedSelfTest.java
@@ -0,0 +1,47 @@
+/*
+ * 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.processors.cache.binary.distributed.dht;
+
+import org.apache.ignite.cache.CacheAtomicityMode;
+import org.apache.ignite.cache.CacheMode;
+import org.apache.ignite.configuration.NearCacheConfiguration;
+import org.apache.ignite.internal.processors.cache.binary.GridCacheBinaryObjectsAbstractDataStreamerSelfTest;
+
+import static org.apache.ignite.cache.CacheAtomicityMode.ATOMIC;
+import static org.apache.ignite.cache.CacheMode.PARTITIONED;
+
+/**
+ *
+ */
+public class GridCacheAtomicPartitionedOnlyPortableDataStreamerMultithreadedSelfTest extends
+    GridCacheBinaryObjectsAbstractDataStreamerSelfTest {
+    /** {@inheritDoc} */
+    @Override protected CacheMode cacheMode() {
+        return PARTITIONED;
+    }
+
+    /** {@inheritDoc} */
+    @Override protected CacheAtomicityMode atomicityMode() {
+        return ATOMIC;
+    }
+
+    /** {@inheritDoc} */
+    @Override protected NearCacheConfiguration nearConfiguration() {
+        return null;
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/1dbf20e0/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/binary/distributed/dht/GridCacheAtomicPartitionedOnlyPortableMultiNodeSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/binary/distributed/dht/GridCacheAtomicPartitionedOnlyPortableMultiNodeSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/binary/distributed/dht/GridCacheAtomicPartitionedOnlyPortableMultiNodeSelfTest.java
new file mode 100644
index 0000000..d704dcf
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/binary/distributed/dht/GridCacheAtomicPartitionedOnlyPortableMultiNodeSelfTest.java
@@ -0,0 +1,28 @@
+/*
+ * 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.processors.cache.binary.distributed.dht;
+
+/**
+ *
+ */
+public class GridCacheAtomicPartitionedOnlyPortableMultiNodeSelfTest extends
+    GridCacheAtomicPartitionedOnlyPortableMultithreadedSelfTest {
+    /** {@inheritDoc} */
+    @Override protected int gridCount() {
+        return 4;
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/1dbf20e0/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/binary/distributed/dht/GridCacheAtomicPartitionedOnlyPortableMultithreadedSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/binary/distributed/dht/GridCacheAtomicPartitionedOnlyPortableMultithreadedSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/binary/distributed/dht/GridCacheAtomicPartitionedOnlyPortableMultithreadedSelfTest.java
new file mode 100644
index 0000000..4391b2b
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/binary/distributed/dht/GridCacheAtomicPartitionedOnlyPortableMultithreadedSelfTest.java
@@ -0,0 +1,47 @@
+/*
+ * 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.processors.cache.binary.distributed.dht;
+
+import org.apache.ignite.cache.CacheAtomicityMode;
+import org.apache.ignite.cache.CacheMode;
+import org.apache.ignite.configuration.NearCacheConfiguration;
+import org.apache.ignite.internal.processors.cache.binary.GridCacheBinaryObjectsAbstractMultiThreadedSelfTest;
+
+import static org.apache.ignite.cache.CacheAtomicityMode.ATOMIC;
+import static org.apache.ignite.cache.CacheMode.PARTITIONED;
+
+/**
+ *
+ */
+public class GridCacheAtomicPartitionedOnlyPortableMultithreadedSelfTest extends
+    GridCacheBinaryObjectsAbstractMultiThreadedSelfTest {
+    /** {@inheritDoc} */
+    @Override protected CacheMode cacheMode() {
+        return PARTITIONED;
+    }
+
+    /** {@inheritDoc} */
+    @Override protected CacheAtomicityMode atomicityMode() {
+        return ATOMIC;
+    }
+
+    /** {@inheritDoc} */
+    @Override protected NearCacheConfiguration nearConfiguration() {
+        return null;
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/1dbf20e0/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/binary/distributed/dht/GridCacheBinaryObjectsAtomicNearDisabledOffheapTieredSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/binary/distributed/dht/GridCacheBinaryObjectsAtomicNearDisabledOffheapTieredSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/binary/distributed/dht/GridCacheBinaryObjectsAtomicNearDisabledOffheapTieredSelfTest.java
new file mode 100644
index 0000000..39c35a2
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/binary/distributed/dht/GridCacheBinaryObjectsAtomicNearDisabledOffheapTieredSelfTest.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.processors.cache.binary.distributed.dht;
+
+/**
+ *
+ */
+public class GridCacheBinaryObjectsAtomicNearDisabledOffheapTieredSelfTest
+    extends GridCacheBinaryObjectsAtomicNearDisabledSelfTest {
+    /** {@inheritDoc} */
+    @Override protected boolean offheapTiered() {
+        return true;
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/1dbf20e0/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/binary/distributed/dht/GridCacheBinaryObjectsAtomicNearDisabledSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/binary/distributed/dht/GridCacheBinaryObjectsAtomicNearDisabledSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/binary/distributed/dht/GridCacheBinaryObjectsAtomicNearDisabledSelfTest.java
new file mode 100644
index 0000000..0199217
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/binary/distributed/dht/GridCacheBinaryObjectsAtomicNearDisabledSelfTest.java
@@ -0,0 +1,51 @@
+/*
+ * 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.processors.cache.binary.distributed.dht;
+
+import org.apache.ignite.cache.CacheAtomicityMode;
+import org.apache.ignite.cache.CacheMode;
+import org.apache.ignite.configuration.NearCacheConfiguration;
+import org.apache.ignite.internal.processors.cache.binary.GridCacheBinaryObjectsAbstractSelfTest;
+
+import static org.apache.ignite.cache.CacheAtomicityMode.ATOMIC;
+import static org.apache.ignite.cache.CacheMode.PARTITIONED;
+
+/**
+ * Test for portable objects stored in cache.
+ */
+public class GridCacheBinaryObjectsAtomicNearDisabledSelfTest extends GridCacheBinaryObjectsAbstractSelfTest {
+    /** {@inheritDoc} */
+    @Override protected CacheMode cacheMode() {
+        return PARTITIONED;
+    }
+
+    /** {@inheritDoc} */
+    @Override protected CacheAtomicityMode atomicityMode() {
+        return ATOMIC;
+    }
+
+    /** {@inheritDoc} */
+    @Override protected NearCacheConfiguration nearConfiguration() {
+        return null;
+    }
+
+    /** {@inheritDoc} */
+    @Override protected int gridCount() {
+        return 3;
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/1dbf20e0/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/binary/distributed/dht/GridCacheBinaryObjectsAtomicOffheapTieredSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/binary/distributed/dht/GridCacheBinaryObjectsAtomicOffheapTieredSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/binary/distributed/dht/GridCacheBinaryObjectsAtomicOffheapTieredSelfTest.java
new file mode 100644
index 0000000..e6ae410
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/binary/distributed/dht/GridCacheBinaryObjectsAtomicOffheapTieredSelfTest.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.processors.cache.binary.distributed.dht;
+
+/**
+ *
+ */
+public class GridCacheBinaryObjectsAtomicOffheapTieredSelfTest extends GridCacheBinaryObjectsAtomicSelfTest {
+    /** {@inheritDoc} */
+    @Override protected boolean offheapTiered() {
+        return true;
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/1dbf20e0/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/binary/distributed/dht/GridCacheBinaryObjectsAtomicSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/binary/distributed/dht/GridCacheBinaryObjectsAtomicSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/binary/distributed/dht/GridCacheBinaryObjectsAtomicSelfTest.java
new file mode 100644
index 0000000..fcdd184
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/binary/distributed/dht/GridCacheBinaryObjectsAtomicSelfTest.java
@@ -0,0 +1,51 @@
+/*
+ * 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.processors.cache.binary.distributed.dht;
+
+import org.apache.ignite.cache.CacheAtomicityMode;
+import org.apache.ignite.cache.CacheMode;
+import org.apache.ignite.configuration.NearCacheConfiguration;
+import org.apache.ignite.internal.processors.cache.binary.GridCacheBinaryObjectsAbstractSelfTest;
+
+import static org.apache.ignite.cache.CacheAtomicityMode.ATOMIC;
+import static org.apache.ignite.cache.CacheMode.PARTITIONED;
+
+/**
+ * Test for portable objects stored in cache.
+ */
+public class GridCacheBinaryObjectsAtomicSelfTest extends GridCacheBinaryObjectsAbstractSelfTest {
+    /** {@inheritDoc} */
+    @Override protected CacheMode cacheMode() {
+        return PARTITIONED;
+    }
+
+    /** {@inheritDoc} */
+    @Override protected CacheAtomicityMode atomicityMode() {
+        return ATOMIC;
+    }
+
+    /** {@inheritDoc} */
+    @Override protected NearCacheConfiguration nearConfiguration() {
+        return new NearCacheConfiguration();
+    }
+
+    /** {@inheritDoc} */
+    @Override protected int gridCount() {
+        return 3;
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/1dbf20e0/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/binary/distributed/dht/GridCacheBinaryObjectsPartitionedNearDisabledOffheapTieredSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/binary/distributed/dht/GridCacheBinaryObjectsPartitionedNearDisabledOffheapTieredSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/binary/distributed/dht/GridCacheBinaryObjectsPartitionedNearDisabledOffheapTieredSelfTest.java
new file mode 100644
index 0000000..8aa082e
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/binary/distributed/dht/GridCacheBinaryObjectsPartitionedNearDisabledOffheapTieredSelfTest.java
@@ -0,0 +1,30 @@
+/*
+ * 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.processors.cache.binary.distributed.dht;
+
+/**
+ *
+ */
+public class GridCacheBinaryObjectsPartitionedNearDisabledOffheapTieredSelfTest
+    extends GridCacheBinaryObjectsPartitionedNearDisabledSelfTest {
+    /** {@inheritDoc} */
+    @Override protected boolean offheapTiered() {
+        return true;
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/1dbf20e0/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/binary/distributed/dht/GridCacheBinaryObjectsPartitionedNearDisabledSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/binary/distributed/dht/GridCacheBinaryObjectsPartitionedNearDisabledSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/binary/distributed/dht/GridCacheBinaryObjectsPartitionedNearDisabledSelfTest.java
new file mode 100644
index 0000000..dc439d7
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/binary/distributed/dht/GridCacheBinaryObjectsPartitionedNearDisabledSelfTest.java
@@ -0,0 +1,51 @@
+/*
+ * 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.processors.cache.binary.distributed.dht;
+
+import org.apache.ignite.cache.CacheAtomicityMode;
+import org.apache.ignite.cache.CacheMode;
+import org.apache.ignite.configuration.NearCacheConfiguration;
+import org.apache.ignite.internal.processors.cache.binary.GridCacheBinaryObjectsAbstractSelfTest;
+
+import static org.apache.ignite.cache.CacheAtomicityMode.TRANSACTIONAL;
+import static org.apache.ignite.cache.CacheMode.PARTITIONED;
+
+/**
+ * Test for portable objects stored in cache.
+ */
+public class GridCacheBinaryObjectsPartitionedNearDisabledSelfTest extends GridCacheBinaryObjectsAbstractSelfTest {
+    /** {@inheritDoc} */
+    @Override protected CacheMode cacheMode() {
+        return PARTITIONED;
+    }
+
+    /** {@inheritDoc} */
+    @Override protected CacheAtomicityMode atomicityMode() {
+        return TRANSACTIONAL;
+    }
+
+    /** {@inheritDoc} */
+    @Override protected NearCacheConfiguration nearConfiguration() {
+        return null;
+    }
+
+    /** {@inheritDoc} */
+    @Override protected int gridCount() {
+        return 3;
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/1dbf20e0/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/binary/distributed/dht/GridCacheBinaryObjectsPartitionedOffheapTieredSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/binary/distributed/dht/GridCacheBinaryObjectsPartitionedOffheapTieredSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/binary/distributed/dht/GridCacheBinaryObjectsPartitionedOffheapTieredSelfTest.java
new file mode 100644
index 0000000..7db608d
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/binary/distributed/dht/GridCacheBinaryObjectsPartitionedOffheapTieredSelfTest.java
@@ -0,0 +1,30 @@
+/*
+ * 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.processors.cache.binary.distributed.dht;
+
+/**
+ *
+ */
+public class GridCacheBinaryObjectsPartitionedOffheapTieredSelfTest
+    extends GridCacheBinaryObjectsPartitionedSelfTest {
+    /** {@inheritDoc} */
+    @Override protected boolean offheapTiered() {
+        return true;
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/1dbf20e0/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/binary/distributed/dht/GridCacheBinaryObjectsPartitionedSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/binary/distributed/dht/GridCacheBinaryObjectsPartitionedSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/binary/distributed/dht/GridCacheBinaryObjectsPartitionedSelfTest.java
new file mode 100644
index 0000000..550ae3f
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/binary/distributed/dht/GridCacheBinaryObjectsPartitionedSelfTest.java
@@ -0,0 +1,51 @@
+/*
+ * 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.processors.cache.binary.distributed.dht;
+
+import org.apache.ignite.cache.CacheAtomicityMode;
+import org.apache.ignite.cache.CacheMode;
+import org.apache.ignite.configuration.NearCacheConfiguration;
+import org.apache.ignite.internal.processors.cache.binary.GridCacheBinaryObjectsAbstractSelfTest;
+
+import static org.apache.ignite.cache.CacheAtomicityMode.TRANSACTIONAL;
+import static org.apache.ignite.cache.CacheMode.PARTITIONED;
+
+/**
+ * Test for portable objects stored in cache.
+ */
+public class GridCacheBinaryObjectsPartitionedSelfTest extends GridCacheBinaryObjectsAbstractSelfTest {
+    /** {@inheritDoc} */
+    @Override protected CacheMode cacheMode() {
+        return PARTITIONED;
+    }
+
+    /** {@inheritDoc} */
+    @Override protected CacheAtomicityMode atomicityMode() {
+        return TRANSACTIONAL;
+    }
+
+    /** {@inheritDoc} */
+    @Override protected NearCacheConfiguration nearConfiguration() {
+        return new NearCacheConfiguration();
+    }
+
+    /** {@inheritDoc} */
+    @Override protected int gridCount() {
+        return 3;
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/1dbf20e0/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/binary/distributed/dht/GridCacheMemoryModePortableSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/binary/distributed/dht/GridCacheMemoryModePortableSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/binary/distributed/dht/GridCacheMemoryModePortableSelfTest.java
new file mode 100644
index 0000000..7836c17
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/binary/distributed/dht/GridCacheMemoryModePortableSelfTest.java
@@ -0,0 +1,36 @@
+/*
+ * 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.processors.cache.binary.distributed.dht;
+
+import org.apache.ignite.configuration.IgniteConfiguration;
+import org.apache.ignite.internal.processors.cache.GridCacheMemoryModeSelfTest;
+import org.apache.ignite.internal.binary.BinaryMarshaller;
+
+/**
+ * Memory models test.
+ */
+public class GridCacheMemoryModePortableSelfTest extends GridCacheMemoryModeSelfTest {
+    /** {@inheritDoc} */
+    @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception {
+        IgniteConfiguration cfg = super.getConfiguration(gridName);
+
+        cfg.setMarshaller(new BinaryMarshaller());
+
+        return cfg;
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/1dbf20e0/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/binary/distributed/dht/GridCacheOffHeapTieredAtomicPortableSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/binary/distributed/dht/GridCacheOffHeapTieredAtomicPortableSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/binary/distributed/dht/GridCacheOffHeapTieredAtomicPortableSelfTest.java
new file mode 100644
index 0000000..0d9b1ec
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/binary/distributed/dht/GridCacheOffHeapTieredAtomicPortableSelfTest.java
@@ -0,0 +1,48 @@
+/*
+ * 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.processors.cache.binary.distributed.dht;
+
+import java.util.Arrays;
+import org.apache.ignite.configuration.BinaryConfiguration;
+import org.apache.ignite.configuration.IgniteConfiguration;
+import org.apache.ignite.internal.processors.cache.GridCacheOffHeapTieredAtomicSelfTest;
+import org.apache.ignite.internal.binary.BinaryMarshaller;
+
+/**
+ *
+ */
+public class GridCacheOffHeapTieredAtomicPortableSelfTest extends GridCacheOffHeapTieredAtomicSelfTest {
+    /** {@inheritDoc} */
+    @Override protected boolean portableEnabled() {
+        return true;
+    }
+
+    /** {@inheritDoc} */
+    @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception {
+        // Enable binary.
+        IgniteConfiguration cfg = super.getConfiguration(gridName);
+
+        BinaryConfiguration bCfg = new BinaryConfiguration();
+
+        bCfg.setClassNames(Arrays.asList(TestValue.class.getName()));
+
+        cfg.setMarshaller(new BinaryMarshaller());
+
+        return cfg;
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/1dbf20e0/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/binary/distributed/dht/GridCacheOffHeapTieredEvictionAtomicPortableSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/binary/distributed/dht/GridCacheOffHeapTieredEvictionAtomicPortableSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/binary/distributed/dht/GridCacheOffHeapTieredEvictionAtomicPortableSelfTest.java
new file mode 100644
index 0000000..addee05
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/binary/distributed/dht/GridCacheOffHeapTieredEvictionAtomicPortableSelfTest.java
@@ -0,0 +1,96 @@
+/*
+ * 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.processors.cache.binary.distributed.dht;
+
+import java.util.Arrays;
+import org.apache.ignite.configuration.BinaryConfiguration;
+import org.apache.ignite.configuration.IgniteConfiguration;
+import org.apache.ignite.internal.processors.cache.GridCacheOffHeapTieredEvictionAtomicSelfTest;
+import org.apache.ignite.internal.binary.BinaryMarshaller;
+import org.apache.ignite.binary.BinaryObject;
+
+/**
+ *
+ */
+public class GridCacheOffHeapTieredEvictionAtomicPortableSelfTest extends GridCacheOffHeapTieredEvictionAtomicSelfTest {
+    /** {@inheritDoc} */
+    @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception {
+        // Enable binary.
+        IgniteConfiguration cfg = super.getConfiguration(gridName);
+
+        BinaryConfiguration bCfg = new BinaryConfiguration();
+
+        bCfg.setClassNames(Arrays.asList(TestValue.class.getName()));
+
+        cfg.setMarshaller(new BinaryMarshaller());
+
+        return cfg;
+    }
+
+    /** {@inheritDoc} */
+    @Override protected TestPredicate testPredicate(String expVal, boolean acceptNull) {
+        return new PortableValuePredicate(expVal, acceptNull);
+    }
+
+    /** {@inheritDoc} */
+    @Override protected TestProcessor testClosure(String expVal, boolean acceptNull) {
+        return new PortableValueClosure(expVal, acceptNull);
+    }
+
+    /**
+     *
+     */
+    @SuppressWarnings("PackageVisibleInnerClass")
+    static class PortableValuePredicate extends TestPredicate {
+        /**
+         * @param expVal Expected value.
+         * @param acceptNull If {@code true} value can be null;
+         */
+        PortableValuePredicate(String expVal, boolean acceptNull) {
+            super(expVal, acceptNull);
+        }
+
+        /** {@inheritDoc} */
+        @Override public void checkValue(Object val) {
+            BinaryObject obj = (BinaryObject)val;
+
+            assertEquals(expVal, obj.field("val"));
+        }
+    }
+
+    /**
+     *
+     */
+    @SuppressWarnings("PackageVisibleInnerClass")
+    static class PortableValueClosure extends TestProcessor {
+        /**
+         * @param expVal Expected value.
+         * @param acceptNull If {@code true} value can be null;
+         */
+        PortableValueClosure(String expVal, boolean acceptNull) {
+            super(expVal, acceptNull);
+        }
+
+        /** {@inheritDoc} */
+        @Override public void checkValue(Object val) {
+            BinaryObject obj = (BinaryObject)val;
+
+            assertEquals(expVal, obj.field("val"));
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/1dbf20e0/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/binary/distributed/dht/GridCacheOffHeapTieredEvictionPortableSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/binary/distributed/dht/GridCacheOffHeapTieredEvictionPortableSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/binary/distributed/dht/GridCacheOffHeapTieredEvictionPortableSelfTest.java
new file mode 100644
index 0000000..3e5d7e0
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/binary/distributed/dht/GridCacheOffHeapTieredEvictionPortableSelfTest.java
@@ -0,0 +1,96 @@
+/*
+ * 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.processors.cache.binary.distributed.dht;
+
+import java.util.Arrays;
+import org.apache.ignite.configuration.BinaryConfiguration;
+import org.apache.ignite.configuration.IgniteConfiguration;
+import org.apache.ignite.internal.processors.cache.GridCacheOffHeapTieredEvictionSelfTest;
+import org.apache.ignite.internal.binary.BinaryMarshaller;
+import org.apache.ignite.binary.BinaryObject;
+
+/**
+ *
+ */
+public class GridCacheOffHeapTieredEvictionPortableSelfTest extends GridCacheOffHeapTieredEvictionSelfTest {
+    /** {@inheritDoc} */
+    @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception {
+        // Enable binary.
+        IgniteConfiguration cfg = super.getConfiguration(gridName);
+
+        BinaryConfiguration bCfg = new BinaryConfiguration();
+
+        bCfg.setClassNames(Arrays.asList(TestValue.class.getName()));
+
+        cfg.setMarshaller(new BinaryMarshaller());
+
+        return cfg;
+    }
+
+    /** {@inheritDoc} */
+    @Override protected TestPredicate testPredicate(String expVal, boolean acceptNull) {
+        return new PortableValuePredicate(expVal, acceptNull);
+    }
+
+    /** {@inheritDoc} */
+    @Override protected TestProcessor testClosure(String expVal, boolean acceptNull) {
+        return new PortableValueClosure(expVal, acceptNull);
+    }
+
+    /**
+     *
+     */
+    @SuppressWarnings("PackageVisibleInnerClass")
+    static class PortableValuePredicate extends TestPredicate {
+        /**
+         * @param expVal Expected value.
+         * @param acceptNull If {@code true} value can be null;
+         */
+        PortableValuePredicate(String expVal, boolean acceptNull) {
+            super(expVal, acceptNull);
+        }
+
+        /** {@inheritDoc} */
+        @Override public void checkValue(Object val) {
+            BinaryObject obj = (BinaryObject)val;
+
+            assertEquals(expVal, obj.field("val"));
+        }
+    }
+
+    /**
+     *
+     */
+    @SuppressWarnings("PackageVisibleInnerClass")
+    static class PortableValueClosure extends TestProcessor {
+        /**
+         * @param expVal Expected value.
+         * @param acceptNull If {@code true} value can be null;
+         */
+        PortableValueClosure(String expVal, boolean acceptNull) {
+            super(expVal, acceptNull);
+        }
+
+        /** {@inheritDoc} */
+        @Override public void checkValue(Object val) {
+            BinaryObject obj = (BinaryObject)val;
+
+            assertEquals(expVal, obj.field("val"));
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/1dbf20e0/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/binary/distributed/dht/GridCacheOffHeapTieredPortableSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/binary/distributed/dht/GridCacheOffHeapTieredPortableSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/binary/distributed/dht/GridCacheOffHeapTieredPortableSelfTest.java
new file mode 100644
index 0000000..12298c6
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/binary/distributed/dht/GridCacheOffHeapTieredPortableSelfTest.java
@@ -0,0 +1,48 @@
+/*
+ * 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.processors.cache.binary.distributed.dht;
+
+import java.util.Arrays;
+import org.apache.ignite.configuration.BinaryConfiguration;
+import org.apache.ignite.configuration.IgniteConfiguration;
+import org.apache.ignite.internal.processors.cache.GridCacheOffHeapTieredSelfTest;
+import org.apache.ignite.internal.binary.BinaryMarshaller;
+
+/**
+ *
+ */
+public class GridCacheOffHeapTieredPortableSelfTest extends GridCacheOffHeapTieredSelfTest {
+    /** {@inheritDoc} */
+    @Override protected boolean portableEnabled() {
+        return true;
+    }
+
+    /** {@inheritDoc} */
+    @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception {
+        // Enable binary.
+        IgniteConfiguration cfg = super.getConfiguration(gridName);
+
+        BinaryConfiguration bCfg = new BinaryConfiguration();
+
+        bCfg.setClassNames(Arrays.asList(TestValue.class.getName()));
+
+        cfg.setMarshaller(new BinaryMarshaller());
+
+        return cfg;
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/1dbf20e0/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/binary/distributed/dht/GridCachePortableDuplicateIndexObjectPartitionedAtomicSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/binary/distributed/dht/GridCachePortableDuplicateIndexObjectPartitionedAtomicSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/binary/distributed/dht/GridCachePortableDuplicateIndexObjectPartitionedAtomicSelfTest.java
new file mode 100644
index 0000000..f01914c
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/binary/distributed/dht/GridCachePortableDuplicateIndexObjectPartitionedAtomicSelfTest.java
@@ -0,0 +1,38 @@
+/*
+ * 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.processors.cache.binary.distributed.dht;
+
+import org.apache.ignite.cache.CacheAtomicityMode;
+import org.apache.ignite.cache.CacheMode;
+import org.apache.ignite.internal.processors.cache.binary.GridPortableDuplicateIndexObjectsAbstractSelfTest;
+
+/**
+ * Test PARTITIONED ATOMIC.
+ */
+public class GridCachePortableDuplicateIndexObjectPartitionedAtomicSelfTest extends
+    GridPortableDuplicateIndexObjectsAbstractSelfTest {
+    /** {@inheritDoc} */
+    @Override public CacheAtomicityMode atomicityMode() {
+        return CacheAtomicityMode.ATOMIC;
+    }
+
+    /** {@inheritDoc} */
+    @Override public CacheMode cacheMode() {
+        return CacheMode.PARTITIONED;
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/1dbf20e0/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/binary/distributed/dht/GridCachePortableDuplicateIndexObjectPartitionedTransactionalSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/binary/distributed/dht/GridCachePortableDuplicateIndexObjectPartitionedTransactionalSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/binary/distributed/dht/GridCachePortableDuplicateIndexObjectPartitionedTransactionalSelfTest.java
new file mode 100644
index 0000000..68305f3
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/binary/distributed/dht/GridCachePortableDuplicateIndexObjectPartitionedTransactionalSelfTest.java
@@ -0,0 +1,41 @@
+/*
+ * 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.processors.cache.binary.distributed.dht;
+
+import org.apache.ignite.cache.CacheAtomicityMode;
+import org.apache.ignite.cache.CacheMode;
+import org.apache.ignite.internal.processors.cache.binary.GridPortableDuplicateIndexObjectsAbstractSelfTest;
+
+import static org.apache.ignite.cache.CacheAtomicityMode.TRANSACTIONAL;
+import static org.apache.ignite.cache.CacheMode.PARTITIONED;
+
+/**
+ * Test PARTITIONED and TRANSACTIONAL.
+ */
+public class GridCachePortableDuplicateIndexObjectPartitionedTransactionalSelfTest extends
+    GridPortableDuplicateIndexObjectsAbstractSelfTest {
+    /** {@inheritDoc} */
+    @Override public CacheAtomicityMode atomicityMode() {
+        return TRANSACTIONAL;
+    }
+
+    /** {@inheritDoc} */
+    @Override public CacheMode cacheMode() {
+        return PARTITIONED;
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/1dbf20e0/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/binary/distributed/dht/GridCachePortablesNearPartitionedByteArrayValuesSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/binary/distributed/dht/GridCachePortablesNearPartitionedByteArrayValuesSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/binary/distributed/dht/GridCachePortablesNearPartitionedByteArrayValuesSelfTest.java
new file mode 100644
index 0000000..9c1572e
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/binary/distributed/dht/GridCachePortablesNearPartitionedByteArrayValuesSelfTest.java
@@ -0,0 +1,41 @@
+/*
+ * 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.processors.cache.binary.distributed.dht;
+
+import org.apache.ignite.configuration.IgniteConfiguration;
+import org.apache.ignite.internal.processors.cache.distributed.near.GridCacheAbstractNearPartitionedByteArrayValuesSelfTest;
+import org.apache.ignite.internal.binary.BinaryMarshaller;
+
+/**
+ *
+ */
+public class GridCachePortablesNearPartitionedByteArrayValuesSelfTest
+    extends GridCacheAbstractNearPartitionedByteArrayValuesSelfTest {
+    /** {@inheritDoc} */
+    @Override protected boolean peerClassLoading() {
+        return false;
+    }
+
+    /** {@inheritDoc} */
+    @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception {
+        IgniteConfiguration cfg = super.getConfiguration(gridName);
+
+        cfg.setMarshaller(new BinaryMarshaller());
+
+        return cfg;
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/1dbf20e0/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/binary/distributed/dht/GridCachePortablesPartitionedOnlyByteArrayValuesSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/binary/distributed/dht/GridCachePortablesPartitionedOnlyByteArrayValuesSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/binary/distributed/dht/GridCachePortablesPartitionedOnlyByteArrayValuesSelfTest.java
new file mode 100644
index 0000000..95630f6
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/binary/distributed/dht/GridCachePortablesPartitionedOnlyByteArrayValuesSelfTest.java
@@ -0,0 +1,42 @@
+/*
+ * 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.processors.cache.binary.distributed.dht;
+
+import org.apache.ignite.configuration.IgniteConfiguration;
+import org.apache.ignite.internal.processors.cache.distributed.dht.GridCacheAbstractPartitionedOnlyByteArrayValuesSelfTest;
+import org.apache.ignite.internal.binary.BinaryMarshaller;
+
+/**
+ *
+ */
+public class GridCachePortablesPartitionedOnlyByteArrayValuesSelfTest
+    extends GridCacheAbstractPartitionedOnlyByteArrayValuesSelfTest {
+    /** {@inheritDoc} */
+    @Override protected boolean peerClassLoading() {
+        return false;
+    }
+
+    /** {@inheritDoc} */
+    @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception {
+        IgniteConfiguration cfg = super.getConfiguration(gridName);
+
+        cfg.setMarshaller(new BinaryMarshaller());
+
+        return cfg;
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/1dbf20e0/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/binary/distributed/replicated/GridCacheBinaryObjectsReplicatedSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/binary/distributed/replicated/GridCacheBinaryObjectsReplicatedSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/binary/distributed/replicated/GridCacheBinaryObjectsReplicatedSelfTest.java
new file mode 100644
index 0000000..90f060f
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/binary/distributed/replicated/GridCacheBinaryObjectsReplicatedSelfTest.java
@@ -0,0 +1,51 @@
+/*
+ * 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.processors.cache.binary.distributed.replicated;
+
+import org.apache.ignite.cache.CacheAtomicityMode;
+import org.apache.ignite.cache.CacheMode;
+import org.apache.ignite.configuration.NearCacheConfiguration;
+import org.apache.ignite.internal.processors.cache.binary.GridCacheBinaryObjectsAbstractSelfTest;
+
+import static org.apache.ignite.cache.CacheAtomicityMode.TRANSACTIONAL;
+import static org.apache.ignite.cache.CacheMode.REPLICATED;
+
+/**
+ * Test for portable objects stored in cache.
+ */
+public class GridCacheBinaryObjectsReplicatedSelfTest extends GridCacheBinaryObjectsAbstractSelfTest {
+    /** {@inheritDoc} */
+    @Override protected CacheMode cacheMode() {
+        return REPLICATED;
+    }
+
+    /** {@inheritDoc} */
+    @Override protected CacheAtomicityMode atomicityMode() {
+        return TRANSACTIONAL;
+    }
+
+    /** {@inheritDoc} */
+    @Override protected NearCacheConfiguration nearConfiguration() {
+        return null;
+    }
+
+    /** {@inheritDoc} */
+    @Override protected int gridCount() {
+        return 3;
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/1dbf20e0/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/binary/local/GridCacheBinaryObjectsAtomicLocalSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/binary/local/GridCacheBinaryObjectsAtomicLocalSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/binary/local/GridCacheBinaryObjectsAtomicLocalSelfTest.java
new file mode 100644
index 0000000..4e4ae75
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/binary/local/GridCacheBinaryObjectsAtomicLocalSelfTest.java
@@ -0,0 +1,32 @@
+/*
+ * 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.processors.cache.binary.local;
+
+import org.apache.ignite.cache.CacheAtomicityMode;
+
+import static org.apache.ignite.cache.CacheAtomicityMode.ATOMIC;
+
+/**
+ *
+ */
+public class GridCacheBinaryObjectsAtomicLocalSelfTest extends GridCacheBinaryObjectsLocalSelfTest {
+    /** {@inheritDoc} */
+    @Override protected CacheAtomicityMode atomicityMode() {
+        return ATOMIC;
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/1dbf20e0/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/binary/local/GridCacheBinaryObjectsLocalOffheapTieredSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/binary/local/GridCacheBinaryObjectsLocalOffheapTieredSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/binary/local/GridCacheBinaryObjectsLocalOffheapTieredSelfTest.java
new file mode 100644
index 0000000..d53da63
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/binary/local/GridCacheBinaryObjectsLocalOffheapTieredSelfTest.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.processors.cache.binary.local;
+
+/**
+ *
+ */
+public class GridCacheBinaryObjectsLocalOffheapTieredSelfTest extends GridCacheBinaryObjectsLocalSelfTest {
+    /** {@inheritDoc} */
+    @Override protected boolean offheapTiered() {
+        return true;
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/1dbf20e0/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/binary/local/GridCacheBinaryObjectsLocalSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/binary/local/GridCacheBinaryObjectsLocalSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/binary/local/GridCacheBinaryObjectsLocalSelfTest.java
new file mode 100644
index 0000000..fc38561
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/binary/local/GridCacheBinaryObjectsLocalSelfTest.java
@@ -0,0 +1,51 @@
+/*
+ * 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.processors.cache.binary.local;
+
+import org.apache.ignite.cache.CacheAtomicityMode;
+import org.apache.ignite.cache.CacheMode;
+import org.apache.ignite.configuration.NearCacheConfiguration;
+import org.apache.ignite.internal.processors.cache.binary.GridCacheBinaryObjectsAbstractSelfTest;
+
+import static org.apache.ignite.cache.CacheAtomicityMode.TRANSACTIONAL;
+import static org.apache.ignite.cache.CacheMode.LOCAL;
+
+/**
+ * Test for portable objects stored in cache.
+ */
+public class GridCacheBinaryObjectsLocalSelfTest extends GridCacheBinaryObjectsAbstractSelfTest {
+    /** {@inheritDoc} */
+    @Override protected CacheMode cacheMode() {
+        return LOCAL;
+    }
+
+    /** {@inheritDoc} */
+    @Override protected CacheAtomicityMode atomicityMode() {
+        return TRANSACTIONAL;
+    }
+
+    /** {@inheritDoc} */
+    @Override protected NearCacheConfiguration nearConfiguration() {
+        return null;
+    }
+
+    /** {@inheritDoc} */
+    @Override protected int gridCount() {
+        return 1;
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/1dbf20e0/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/context/IgniteCacheAbstractExecutionContextTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/context/IgniteCacheAbstractExecutionContextTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/context/IgniteCacheAbstractExecutionContextTest.java
index cc4d228..eeefbb0 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/context/IgniteCacheAbstractExecutionContextTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/context/IgniteCacheAbstractExecutionContextTest.java
@@ -24,7 +24,7 @@ import org.apache.ignite.configuration.CacheConfiguration;
 import org.apache.ignite.configuration.IgniteConfiguration;
 import org.apache.ignite.internal.processors.cache.IgniteCacheAbstractTest;
 import org.apache.ignite.internal.util.typedef.F;
-import org.apache.ignite.internal.portable.BinaryMarshaller;
+import org.apache.ignite.internal.binary.BinaryMarshaller;
 import org.apache.ignite.testframework.GridTestExternalClassLoader;
 import org.apache.ignite.testframework.config.GridTestProperties;
 
@@ -100,4 +100,4 @@ public abstract class IgniteCacheAbstractExecutionContextTest extends IgniteCach
             super(new URL[] {new URL(GridTestProperties.getProperty("p2p.uri.cls"))});
         }
     }
-}
\ No newline at end of file
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/1dbf20e0/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/rebalancing/GridCacheRebalancingUnmarshallingFailedSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/rebalancing/GridCacheRebalancingUnmarshallingFailedSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/rebalancing/GridCacheRebalancingUnmarshallingFailedSelfTest.java
index 7e35906..bff604c 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/rebalancing/GridCacheRebalancingUnmarshallingFailedSelfTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/rebalancing/GridCacheRebalancingUnmarshallingFailedSelfTest.java
@@ -27,7 +27,7 @@ import org.apache.ignite.cache.CacheRebalanceMode;
 import org.apache.ignite.cache.query.annotations.QuerySqlField;
 import org.apache.ignite.configuration.CacheConfiguration;
 import org.apache.ignite.configuration.IgniteConfiguration;
-import org.apache.ignite.internal.portable.BinaryMarshaller;
+import org.apache.ignite.internal.binary.BinaryMarshaller;
 import org.apache.ignite.spi.discovery.tcp.ipfinder.TcpDiscoveryIpFinder;
 import org.apache.ignite.spi.discovery.tcp.ipfinder.vm.TcpDiscoveryVmIpFinder;
 import org.apache.ignite.testframework.config.GridTestProperties;

http://git-wip-us.apache.org/repos/asf/ignite/blob/1dbf20e0/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/replicated/GridCacheReplicatedUnswapAdvancedSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/replicated/GridCacheReplicatedUnswapAdvancedSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/replicated/GridCacheReplicatedUnswapAdvancedSelfTest.java
index 8f3f3f8..88932d9 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/replicated/GridCacheReplicatedUnswapAdvancedSelfTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/replicated/GridCacheReplicatedUnswapAdvancedSelfTest.java
@@ -25,7 +25,7 @@ import org.apache.ignite.cache.CachePeekMode;
 import org.apache.ignite.configuration.CacheConfiguration;
 import org.apache.ignite.configuration.IgniteConfiguration;
 import org.apache.ignite.events.Event;
-import org.apache.ignite.internal.portable.BinaryMarshaller;
+import org.apache.ignite.internal.binary.BinaryMarshaller;
 import org.apache.ignite.lang.IgnitePredicate;
 import org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi;
 import org.apache.ignite.spi.discovery.tcp.ipfinder.TcpDiscoveryIpFinder;
@@ -150,4 +150,4 @@ public class GridCacheReplicatedUnswapAdvancedSelfTest extends GridCommonAbstrac
             stopGrid(2);
         }
     }
-}
\ No newline at end of file
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/1dbf20e0/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/replicated/preloader/GridCacheReplicatedPreloadSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/replicated/preloader/GridCacheReplicatedPreloadSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/replicated/preloader/GridCacheReplicatedPreloadSelfTest.java
index 5ee27c8..5649b34 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/replicated/preloader/GridCacheReplicatedPreloadSelfTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/replicated/preloader/GridCacheReplicatedPreloadSelfTest.java
@@ -37,7 +37,7 @@ import org.apache.ignite.configuration.CacheConfiguration;
 import org.apache.ignite.configuration.IgniteConfiguration;
 import org.apache.ignite.events.Event;
 import org.apache.ignite.internal.IgniteKernal;
-import org.apache.ignite.internal.portable.BinaryMarshaller;
+import org.apache.ignite.internal.binary.BinaryMarshaller;
 import org.apache.ignite.internal.processors.cache.GridCacheAdapter;
 import org.apache.ignite.internal.processors.cache.GridCacheEntryEx;
 import org.apache.ignite.internal.util.typedef.F;

http://git-wip-us.apache.org/repos/asf/ignite/blob/1dbf20e0/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/GridCacheBinaryAtomicEntryProcessorDeploymentSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/GridCacheBinaryAtomicEntryProcessorDeploymentSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/GridCacheBinaryAtomicEntryProcessorDeploymentSelfTest.java
deleted file mode 100644
index 1004e7a..0000000
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/portable/GridCacheBinaryAtomicEntryProcessorDeploymentSelfTest.java
+++ /dev/null
@@ -1,129 +0,0 @@
-/*
- *  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.processors.cache.portable;
-
-import org.apache.ignite.IgniteCache;
-import org.apache.ignite.binary.BinaryInvalidTypeException;
-import org.apache.ignite.binary.BinaryObject;
-import org.apache.ignite.configuration.DeploymentMode;
-import org.apache.ignite.internal.processors.cache.GridCacheAtomicEntryProcessorDeploymentSelfTest;
-
-/**
- * Cache EntryProcessor + Deployment.
- */
-public class GridCacheBinaryAtomicEntryProcessorDeploymentSelfTest
-    extends GridCacheAtomicEntryProcessorDeploymentSelfTest {
-    /** {@inheritDoc} */
-    protected IgniteCache getCache() {
-        return grid(1).cache(null).withKeepBinary();
-    }
-
-    /** {@inheritDoc} */
-    @Override protected String getEntryProcessor() {
-        return "org.apache.ignite.tests.p2p.CacheDeploymentBinaryObjectEntryProcessor";
-    }
-
-    /**
-     * @throws Exception In case of error.
-     */
-    public void testGetDeployment() throws Exception {
-        depMode = DeploymentMode.CONTINUOUS;
-
-        doTestGet(false);
-    }
-
-    /**
-     * @throws Exception In case of error.
-     */
-    public void testGetDeployment2() throws Exception {
-        depMode = DeploymentMode.SHARED;
-
-        doTestGet(false);
-    }
-
-    /**
-     * @throws Exception In case of error.
-     */
-    public void testGetDeploymentWithKeepBinary() throws Exception {
-        depMode = DeploymentMode.CONTINUOUS;
-
-        doTestGet(true);
-    }
-
-    /**
-     * @throws Exception In case of error.
-     */
-    public void testGetDeployment2WithKeepBinary() throws Exception {
-        depMode = DeploymentMode.SHARED;
-
-        doTestGet(true);
-    }
-
-    /**
-     * @throws Exception Exception.
-     */
-    private void doTestGet(boolean withKeepBinary) throws Exception {
-        try {
-            clientMode = false;
-            startGrid(0);
-
-            clientMode = true;
-            startGrid(1);
-
-            Class valCls = grid(1).configuration().getClassLoader().loadClass(TEST_VALUE);
-
-            assertTrue(grid(1).configuration().isClientMode());
-            assertFalse(grid(0).configuration().isClientMode());
-
-            IgniteCache cache1 = grid(1).cache(null);
-            IgniteCache cache0 = grid(0).cache(null);
-
-            if (withKeepBinary) {
-                cache1 = cache1.withKeepBinary();
-                cache0 = cache0.withKeepBinary();
-            }
-
-            cache1.put("key", valCls.newInstance());
-
-            if (withKeepBinary) {
-                BinaryObject obj = (BinaryObject)(cache0.get("key"));
-
-                try {
-                    obj.deserialize();
-
-                    fail("Exception did not happened.");
-                }
-                catch (BinaryInvalidTypeException e) {
-                    // No-op.
-                }
-            }
-            else
-                try {
-                    cache0.get("key");
-
-                    fail("Exception did not happened.");
-                }
-                catch (BinaryInvalidTypeException e) {
-                    // No-op.
-                }
-        }
-        finally {
-            stopAllGrids();
-        }
-    }
-}


[36/59] [abbrv] ignite git commit: Ignite-2065 Compilation fixed

Posted by ak...@apache.org.
Ignite-2065 Compilation fixed


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

Branch: refs/heads/ignite-843-rc2
Commit: f6555da03d3fbd7f88beffeaf5bf513ff158a062
Parents: c291644
Author: Anton Vinogradov <av...@apache.org>
Authored: Fri Dec 11 13:53:08 2015 +0300
Committer: Anton Vinogradov <av...@apache.org>
Committed: Fri Dec 11 13:53:08 2015 +0300

----------------------------------------------------------------------
 .../apache/ignite/binary/test1/1.1/test1-1.1.jar    | Bin 0 -> 2548 bytes
 .../apache/ignite/binary/test1/1.1/test1-1.1.pom    |   9 +++++++++
 .../ignite/binary/test1/maven-metadata-local.xml    |  12 ++++++++++++
 .../apache/ignite/binary/test2/1.1/test2-1.1.jar    | Bin 0 -> 1361 bytes
 .../apache/ignite/binary/test2/1.1/test2-1.1.pom    |   9 +++++++++
 .../ignite/binary/test2/maven-metadata-local.xml    |  12 ++++++++++++
 .../apache/ignite/portable/test1/1.1/test1-1.1.jar  | Bin 2548 -> 0 bytes
 .../apache/ignite/portable/test1/1.1/test1-1.1.pom  |   9 ---------
 .../ignite/portable/test1/maven-metadata-local.xml  |  12 ------------
 .../apache/ignite/portable/test2/1.1/test2-1.1.jar  | Bin 1361 -> 0 bytes
 .../apache/ignite/portable/test2/1.1/test2-1.1.pom  |   9 ---------
 .../ignite/portable/test2/maven-metadata-local.xml  |  12 ------------
 12 files changed, 42 insertions(+), 42 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ignite/blob/f6555da0/modules/core/src/test/portables/repo/org/apache/ignite/binary/test1/1.1/test1-1.1.jar
----------------------------------------------------------------------
diff --git a/modules/core/src/test/portables/repo/org/apache/ignite/binary/test1/1.1/test1-1.1.jar b/modules/core/src/test/portables/repo/org/apache/ignite/binary/test1/1.1/test1-1.1.jar
new file mode 100644
index 0000000..863350d
Binary files /dev/null and b/modules/core/src/test/portables/repo/org/apache/ignite/binary/test1/1.1/test1-1.1.jar differ

http://git-wip-us.apache.org/repos/asf/ignite/blob/f6555da0/modules/core/src/test/portables/repo/org/apache/ignite/binary/test1/1.1/test1-1.1.pom
----------------------------------------------------------------------
diff --git a/modules/core/src/test/portables/repo/org/apache/ignite/binary/test1/1.1/test1-1.1.pom b/modules/core/src/test/portables/repo/org/apache/ignite/binary/test1/1.1/test1-1.1.pom
new file mode 100644
index 0000000..533a3c9
--- /dev/null
+++ b/modules/core/src/test/portables/repo/org/apache/ignite/binary/test1/1.1/test1-1.1.pom
@@ -0,0 +1,9 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
+    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
+  <modelVersion>4.0.0</modelVersion>
+  <groupId>org.apache.ignite.binary</groupId>
+  <artifactId>test1</artifactId>
+  <version>1.1</version>
+  <description>POM was created from install:install-file</description>
+</project>

http://git-wip-us.apache.org/repos/asf/ignite/blob/f6555da0/modules/core/src/test/portables/repo/org/apache/ignite/binary/test1/maven-metadata-local.xml
----------------------------------------------------------------------
diff --git a/modules/core/src/test/portables/repo/org/apache/ignite/binary/test1/maven-metadata-local.xml b/modules/core/src/test/portables/repo/org/apache/ignite/binary/test1/maven-metadata-local.xml
new file mode 100644
index 0000000..4ca5d44
--- /dev/null
+++ b/modules/core/src/test/portables/repo/org/apache/ignite/binary/test1/maven-metadata-local.xml
@@ -0,0 +1,12 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<metadata>
+  <groupId>org.apache.ignite.binary</groupId>
+  <artifactId>test1</artifactId>
+  <versioning>
+    <release>1.1</release>
+    <versions>
+      <version>1.1</version>
+    </versions>
+    <lastUpdated>20140806090184</lastUpdated>
+  </versioning>
+</metadata>

http://git-wip-us.apache.org/repos/asf/ignite/blob/f6555da0/modules/core/src/test/portables/repo/org/apache/ignite/binary/test2/1.1/test2-1.1.jar
----------------------------------------------------------------------
diff --git a/modules/core/src/test/portables/repo/org/apache/ignite/binary/test2/1.1/test2-1.1.jar b/modules/core/src/test/portables/repo/org/apache/ignite/binary/test2/1.1/test2-1.1.jar
new file mode 100644
index 0000000..ccf4ea2
Binary files /dev/null and b/modules/core/src/test/portables/repo/org/apache/ignite/binary/test2/1.1/test2-1.1.jar differ

http://git-wip-us.apache.org/repos/asf/ignite/blob/f6555da0/modules/core/src/test/portables/repo/org/apache/ignite/binary/test2/1.1/test2-1.1.pom
----------------------------------------------------------------------
diff --git a/modules/core/src/test/portables/repo/org/apache/ignite/binary/test2/1.1/test2-1.1.pom b/modules/core/src/test/portables/repo/org/apache/ignite/binary/test2/1.1/test2-1.1.pom
new file mode 100644
index 0000000..2eaaeff
--- /dev/null
+++ b/modules/core/src/test/portables/repo/org/apache/ignite/binary/test2/1.1/test2-1.1.pom
@@ -0,0 +1,9 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
+    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
+  <modelVersion>4.0.0</modelVersion>
+  <groupId>org.apache.ignite.binary</groupId>
+  <artifactId>test2</artifactId>
+  <version>1.1</version>
+  <description>POM was created from install:install-file</description>
+</project>

http://git-wip-us.apache.org/repos/asf/ignite/blob/f6555da0/modules/core/src/test/portables/repo/org/apache/ignite/binary/test2/maven-metadata-local.xml
----------------------------------------------------------------------
diff --git a/modules/core/src/test/portables/repo/org/apache/ignite/binary/test2/maven-metadata-local.xml b/modules/core/src/test/portables/repo/org/apache/ignite/binary/test2/maven-metadata-local.xml
new file mode 100644
index 0000000..c45c88f
--- /dev/null
+++ b/modules/core/src/test/portables/repo/org/apache/ignite/binary/test2/maven-metadata-local.xml
@@ -0,0 +1,12 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<metadata>
+  <groupId>org.apache.ignite.binary</groupId>
+  <artifactId>test2</artifactId>
+  <versioning>
+    <release>1.1</release>
+    <versions>
+      <version>1.1</version>
+    </versions>
+    <lastUpdated>20140806090410</lastUpdated>
+  </versioning>
+</metadata>

http://git-wip-us.apache.org/repos/asf/ignite/blob/f6555da0/modules/core/src/test/portables/repo/org/apache/ignite/portable/test1/1.1/test1-1.1.jar
----------------------------------------------------------------------
diff --git a/modules/core/src/test/portables/repo/org/apache/ignite/portable/test1/1.1/test1-1.1.jar b/modules/core/src/test/portables/repo/org/apache/ignite/portable/test1/1.1/test1-1.1.jar
deleted file mode 100644
index 863350d..0000000
Binary files a/modules/core/src/test/portables/repo/org/apache/ignite/portable/test1/1.1/test1-1.1.jar and /dev/null differ

http://git-wip-us.apache.org/repos/asf/ignite/blob/f6555da0/modules/core/src/test/portables/repo/org/apache/ignite/portable/test1/1.1/test1-1.1.pom
----------------------------------------------------------------------
diff --git a/modules/core/src/test/portables/repo/org/apache/ignite/portable/test1/1.1/test1-1.1.pom b/modules/core/src/test/portables/repo/org/apache/ignite/portable/test1/1.1/test1-1.1.pom
deleted file mode 100644
index 533a3c9..0000000
--- a/modules/core/src/test/portables/repo/org/apache/ignite/portable/test1/1.1/test1-1.1.pom
+++ /dev/null
@@ -1,9 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
-    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
-  <modelVersion>4.0.0</modelVersion>
-  <groupId>org.apache.ignite.binary</groupId>
-  <artifactId>test1</artifactId>
-  <version>1.1</version>
-  <description>POM was created from install:install-file</description>
-</project>

http://git-wip-us.apache.org/repos/asf/ignite/blob/f6555da0/modules/core/src/test/portables/repo/org/apache/ignite/portable/test1/maven-metadata-local.xml
----------------------------------------------------------------------
diff --git a/modules/core/src/test/portables/repo/org/apache/ignite/portable/test1/maven-metadata-local.xml b/modules/core/src/test/portables/repo/org/apache/ignite/portable/test1/maven-metadata-local.xml
deleted file mode 100644
index 4ca5d44..0000000
--- a/modules/core/src/test/portables/repo/org/apache/ignite/portable/test1/maven-metadata-local.xml
+++ /dev/null
@@ -1,12 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<metadata>
-  <groupId>org.apache.ignite.binary</groupId>
-  <artifactId>test1</artifactId>
-  <versioning>
-    <release>1.1</release>
-    <versions>
-      <version>1.1</version>
-    </versions>
-    <lastUpdated>20140806090184</lastUpdated>
-  </versioning>
-</metadata>

http://git-wip-us.apache.org/repos/asf/ignite/blob/f6555da0/modules/core/src/test/portables/repo/org/apache/ignite/portable/test2/1.1/test2-1.1.jar
----------------------------------------------------------------------
diff --git a/modules/core/src/test/portables/repo/org/apache/ignite/portable/test2/1.1/test2-1.1.jar b/modules/core/src/test/portables/repo/org/apache/ignite/portable/test2/1.1/test2-1.1.jar
deleted file mode 100644
index ccf4ea2..0000000
Binary files a/modules/core/src/test/portables/repo/org/apache/ignite/portable/test2/1.1/test2-1.1.jar and /dev/null differ

http://git-wip-us.apache.org/repos/asf/ignite/blob/f6555da0/modules/core/src/test/portables/repo/org/apache/ignite/portable/test2/1.1/test2-1.1.pom
----------------------------------------------------------------------
diff --git a/modules/core/src/test/portables/repo/org/apache/ignite/portable/test2/1.1/test2-1.1.pom b/modules/core/src/test/portables/repo/org/apache/ignite/portable/test2/1.1/test2-1.1.pom
deleted file mode 100644
index 2eaaeff..0000000
--- a/modules/core/src/test/portables/repo/org/apache/ignite/portable/test2/1.1/test2-1.1.pom
+++ /dev/null
@@ -1,9 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
-    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
-  <modelVersion>4.0.0</modelVersion>
-  <groupId>org.apache.ignite.binary</groupId>
-  <artifactId>test2</artifactId>
-  <version>1.1</version>
-  <description>POM was created from install:install-file</description>
-</project>

http://git-wip-us.apache.org/repos/asf/ignite/blob/f6555da0/modules/core/src/test/portables/repo/org/apache/ignite/portable/test2/maven-metadata-local.xml
----------------------------------------------------------------------
diff --git a/modules/core/src/test/portables/repo/org/apache/ignite/portable/test2/maven-metadata-local.xml b/modules/core/src/test/portables/repo/org/apache/ignite/portable/test2/maven-metadata-local.xml
deleted file mode 100644
index c45c88f..0000000
--- a/modules/core/src/test/portables/repo/org/apache/ignite/portable/test2/maven-metadata-local.xml
+++ /dev/null
@@ -1,12 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<metadata>
-  <groupId>org.apache.ignite.binary</groupId>
-  <artifactId>test2</artifactId>
-  <versioning>
-    <release>1.1</release>
-    <versions>
-      <version>1.1</version>
-    </versions>
-    <lastUpdated>20140806090410</lastUpdated>
-  </versioning>
-</metadata>


[32/59] [abbrv] ignite git commit: Merge branch 'ignite-2064-4' into ignite-1.5

Posted by ak...@apache.org.
http://git-wip-us.apache.org/repos/asf/ignite/blob/0ac39c97/modules/core/src/main/java/org/apache/ignite/internal/binary/builder/PortableEnumArrayLazyValue.java
----------------------------------------------------------------------
diff --cc modules/core/src/main/java/org/apache/ignite/internal/binary/builder/PortableEnumArrayLazyValue.java
index d6848e9,0000000..fa83d7e
mode 100644,000000..100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/binary/builder/PortableEnumArrayLazyValue.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/binary/builder/PortableEnumArrayLazyValue.java
@@@ -1,116 -1,0 +1,115 @@@
 +/*
 + * 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.binary.builder;
 +
 +import org.apache.ignite.internal.binary.BinaryWriterExImpl;
 +import org.apache.ignite.internal.binary.GridPortableMarshaller;
 +import org.apache.ignite.internal.binary.GridPortableMarshaller;
 +import org.apache.ignite.internal.binary.BinaryWriterExImpl;
 +import org.apache.ignite.internal.util.typedef.internal.U;
 +import org.apache.ignite.binary.BinaryObjectException;
 +import org.apache.ignite.binary.BinaryInvalidTypeException;
 +
 +/**
 + *
 + */
 +class PortableEnumArrayLazyValue extends PortableAbstractLazyValue {
 +    /** */
 +    private final int len;
 +
 +    /** */
 +    private final int compTypeId;
 +
 +    /** */
 +    private final String clsName;
 +
 +    /**
 +     * @param reader Reader.
 +     */
 +    protected PortableEnumArrayLazyValue(PortableBuilderReader reader) {
 +        super(reader, reader.position() - 1);
 +
 +        int typeId = reader.readInt();
 +
 +        if (typeId == GridPortableMarshaller.UNREGISTERED_TYPE_ID) {
 +            clsName = reader.readString();
 +
 +            Class cls;
 +
 +            try {
-                 // TODO: IGNITE-1272 - Is class loader needed here?
-                 cls = U.forName(reader.readString(), null);
++                cls = U.forName(reader.readString(), reader.portableContext().configuration().getClassLoader());
 +            }
 +            catch (ClassNotFoundException e) {
 +                throw new BinaryInvalidTypeException("Failed to load the class: " + clsName, e);
 +            }
 +
 +            compTypeId = reader.portableContext().descriptorForClass(cls, true).typeId();
 +        }
 +        else {
 +            compTypeId = typeId;
 +            clsName = null;
 +        }
 +
 +        int size = reader.readInt();
 +
 +        for (int i = 0; i < size; i++)
 +            reader.skipValue();
 +
 +        len = reader.position() - valOff;
 +    }
 +
 +    /** {@inheritDoc} */
 +    @Override protected Object init() {
 +        reader.position(valOff + 1);
 +
 +        //skipping component type id
 +        reader.readInt();
 +
 +        int size = reader.readInt();
 +
 +        PortableBuilderEnum[] res = new PortableBuilderEnum[size];
 +
 +        for (int i = 0; i < size; i++) {
 +            byte flag = reader.readByte();
 +
 +            if (flag == GridPortableMarshaller.NULL)
 +                continue;
 +
 +            if (flag != GridPortableMarshaller.ENUM)
 +                throw new BinaryObjectException("Invalid flag value: " + flag);
 +
 +            res[i] = new PortableBuilderEnum(reader);
 +        }
 +
 +        return res;
 +    }
 +
 +    /** {@inheritDoc} */
 +    @Override public void writeTo(BinaryWriterExImpl writer, PortableBuilderSerializer ctx) {
 +        if (val != null) {
 +            if (clsName != null)
 +                ctx.writeArray(writer, GridPortableMarshaller.ENUM_ARR, (Object[])val, clsName);
 +            else
 +                ctx.writeArray(writer, GridPortableMarshaller.ENUM_ARR, (Object[])val, compTypeId);
 +
 +            return;
 +        }
 +
 +        writer.write(reader.array(), valOff, len);
 +    }
 +}

http://git-wip-us.apache.org/repos/asf/ignite/blob/0ac39c97/modules/core/src/main/java/org/apache/ignite/internal/binary/builder/PortableObjectArrayLazyValue.java
----------------------------------------------------------------------
diff --cc modules/core/src/main/java/org/apache/ignite/internal/binary/builder/PortableObjectArrayLazyValue.java
index 537a25f,0000000..7f77b0d
mode 100644,000000..100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/binary/builder/PortableObjectArrayLazyValue.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/binary/builder/PortableObjectArrayLazyValue.java
@@@ -1,91 -1,0 +1,90 @@@
 +/*
 + * 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.binary.builder;
 +
 +import org.apache.ignite.internal.binary.GridPortableMarshaller;
 +import org.apache.ignite.internal.binary.BinaryWriterExImpl;
 +import org.apache.ignite.internal.util.typedef.internal.U;
 +import org.apache.ignite.binary.BinaryInvalidTypeException;
 +
 +/**
 + *
 + */
 +class PortableObjectArrayLazyValue extends PortableAbstractLazyValue {
 +    /** */
 +    private Object[] lazyValsArr;
 +
 +    /** */
 +    private int compTypeId;
 +
 +    /** */
 +    private String clsName;
 +
 +    /**
 +     * @param reader Reader.
 +     */
 +    protected PortableObjectArrayLazyValue(PortableBuilderReader reader) {
 +        super(reader, reader.position() - 1);
 +
 +        int typeId = reader.readInt();
 +
 +        if (typeId == GridPortableMarshaller.UNREGISTERED_TYPE_ID) {
 +            clsName = reader.readString();
 +
 +            Class cls;
 +
 +            try {
-                 // TODO: IGNITE-1272 - Is class loader needed here?
-                 cls = U.forName(reader.readString(), null);
++                cls = U.forName(reader.readString(), reader.portableContext().configuration().getClassLoader());
 +            }
 +            catch (ClassNotFoundException e) {
 +                throw new BinaryInvalidTypeException("Failed to load the class: " + clsName, e);
 +            }
 +
 +            compTypeId = reader.portableContext().descriptorForClass(cls, true).typeId();
 +        }
 +        else {
 +            compTypeId = typeId;
 +            clsName = null;
 +        }
 +
 +        int size = reader.readInt();
 +
 +        lazyValsArr = new Object[size];
 +
 +        for (int i = 0; i < size; i++)
 +            lazyValsArr[i] = reader.parseValue();
 +    }
 +
 +    /** {@inheritDoc} */
 +    @Override protected Object init() {
 +        for (int i = 0; i < lazyValsArr.length; i++) {
 +            if (lazyValsArr[i] instanceof PortableLazyValue)
 +                lazyValsArr[i] = ((PortableLazyValue)lazyValsArr[i]).value();
 +        }
 +
 +        return lazyValsArr;
 +    }
 +
 +    /** {@inheritDoc} */
 +    @Override public void writeTo(BinaryWriterExImpl writer, PortableBuilderSerializer ctx) {
 +        if (clsName == null)
 +            ctx.writeArray(writer, GridPortableMarshaller.OBJ_ARR, lazyValsArr, compTypeId);
 +        else
 +            ctx.writeArray(writer, GridPortableMarshaller.OBJ_ARR, lazyValsArr, clsName);
 +    }
 +}

http://git-wip-us.apache.org/repos/asf/ignite/blob/0ac39c97/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/PlatformContextImpl.java
----------------------------------------------------------------------

http://git-wip-us.apache.org/repos/asf/ignite/blob/0ac39c97/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/context/IgniteCacheAbstractExecutionContextTest.java
----------------------------------------------------------------------


[45/59] [abbrv] ignite git commit: ignite-2065: rename "portable" classes to "binary"

Posted by ak...@apache.org.
http://git-wip-us.apache.org/repos/asf/ignite/blob/71ad9cea/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/client/message/GridClientPortableMetaData.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/client/message/GridClientPortableMetaData.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/client/message/GridClientPortableMetaData.java
deleted file mode 100644
index 5522095..0000000
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/client/message/GridClientPortableMetaData.java
+++ /dev/null
@@ -1,71 +0,0 @@
-/*
- * 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.processors.rest.client.message;
-
-import java.util.Map;
-import org.apache.ignite.internal.util.typedef.internal.S;
-
-/**
- * Portable meta data sent from client.
- */
-public class GridClientPortableMetaData {
-    /** */
-    private int typeId;
-
-    /** */
-    private String typeName;
-
-    /** */
-    private Map<String, Integer> fields;
-
-    /** */
-    private String affKeyFieldName;
-
-    /**
-     * @return Type ID.
-     */
-    public int typeId() {
-        return typeId;
-    }
-
-    /**
-     * @return Type name.
-     */
-    public String typeName() {
-        return typeName;
-    }
-
-    /**
-     * @return Fields.
-     */
-    public Map<String, Integer> fields() {
-        return fields;
-    }
-
-    /**
-     * @return Affinity key field name.
-     */
-    public String affinityKeyFieldName() {
-        return affKeyFieldName;
-    }
-
-    /** {@inheritDoc} */
-    @Override public String toString() {
-        return S.toString(GridClientPortableMetaData.class, this);
-    }
-}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ignite/blob/71ad9cea/modules/core/src/test/java/org/apache/ignite/internal/binary/BinaryFieldsAbstractSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/binary/BinaryFieldsAbstractSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/binary/BinaryFieldsAbstractSelfTest.java
index f12bb92..7d53705 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/binary/BinaryFieldsAbstractSelfTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/binary/BinaryFieldsAbstractSelfTest.java
@@ -47,7 +47,7 @@ public abstract class BinaryFieldsAbstractSelfTest extends GridCommonAbstractTes
      * @throws Exception If failed.
      */
     protected BinaryMarshaller createMarshaller() throws Exception {
-        PortableContext ctx = new PortableContext(BinaryCachingMetadataHandler.create(), new IgniteConfiguration());
+        BinaryContext ctx = new BinaryContext(BinaryCachingMetadataHandler.create(), new IgniteConfiguration());
 
         BinaryMarshaller marsh = new BinaryMarshaller();
 
@@ -85,8 +85,8 @@ public abstract class BinaryFieldsAbstractSelfTest extends GridCommonAbstractTes
      * @param marsh Marshaller.
      * @return Portable context.
      */
-    protected static PortableContext portableContext(BinaryMarshaller marsh) {
-        GridPortableMarshaller impl = U.field(marsh, "impl");
+    protected static BinaryContext portableContext(BinaryMarshaller marsh) {
+        GridBinaryMarshaller impl = U.field(marsh, "impl");
 
         return impl.context();
     }

http://git-wip-us.apache.org/repos/asf/ignite/blob/71ad9cea/modules/core/src/test/java/org/apache/ignite/internal/binary/BinaryFooterOffsetsAbstractSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/binary/BinaryFooterOffsetsAbstractSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/binary/BinaryFooterOffsetsAbstractSelfTest.java
index 1e0f375..43609b8 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/binary/BinaryFooterOffsetsAbstractSelfTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/binary/BinaryFooterOffsetsAbstractSelfTest.java
@@ -40,13 +40,13 @@ public abstract class BinaryFooterOffsetsAbstractSelfTest extends GridCommonAbst
     protected BinaryMarshaller marsh;
 
     /** Portable context. */
-    protected PortableContext ctx;
+    protected BinaryContext ctx;
 
     /** {@inheritDoc} */
     @Override protected void beforeTest() throws Exception {
         super.beforeTest();
 
-        ctx = new PortableContext(BinaryCachingMetadataHandler.create(), new IgniteConfiguration());
+        ctx = new BinaryContext(BinaryCachingMetadataHandler.create(), new IgniteConfiguration());
 
         marsh = new BinaryMarshaller();
 

http://git-wip-us.apache.org/repos/asf/ignite/blob/71ad9cea/modules/core/src/test/java/org/apache/ignite/internal/binary/BinaryMarshallerSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/binary/BinaryMarshallerSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/binary/BinaryMarshallerSelfTest.java
index d4f3acf..52fecbf 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/binary/BinaryMarshallerSelfTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/binary/BinaryMarshallerSelfTest.java
@@ -84,7 +84,7 @@ import org.jetbrains.annotations.Nullable;
 import org.jsr166.ConcurrentHashMap8;
 import sun.misc.Unsafe;
 
-import static org.apache.ignite.internal.binary.streams.PortableMemoryAllocator.INSTANCE;
+import static org.apache.ignite.internal.binary.streams.BinaryMemoryAllocator.INSTANCE;
 import static org.junit.Assert.assertArrayEquals;
 import static org.junit.Assert.assertNotEquals;
 
@@ -1244,7 +1244,7 @@ public class BinaryMarshallerSelfTest extends GridCommonAbstractTest {
                 String typeName;
 
                 try {
-                    Method mtd = PortableContext.class.getDeclaredMethod("typeName", String.class);
+                    Method mtd = BinaryContext.class.getDeclaredMethod("typeName", String.class);
 
                     mtd.setAccessible(true);
 
@@ -1343,7 +1343,7 @@ public class BinaryMarshallerSelfTest extends GridCommonAbstractTest {
             customType4
         ));
 
-        PortableContext ctx = portableContext(marsh);
+        BinaryContext ctx = portableContext(marsh);
 
         assertEquals("notconfiguredclass".hashCode(), ctx.typeId("NotConfiguredClass"));
         assertEquals("key".hashCode(), ctx.typeId("Key"));
@@ -1406,7 +1406,7 @@ public class BinaryMarshallerSelfTest extends GridCommonAbstractTest {
             customType1,
             customType2));
 
-        PortableContext ctx = portableContext(marsh);
+        BinaryContext ctx = portableContext(marsh);
 
         assertEquals("val".hashCode(), ctx.fieldId("key".hashCode(), "val"));
         assertEquals("val".hashCode(), ctx.fieldId("nonexistentclass2".hashCode(), "val"));
@@ -1942,7 +1942,7 @@ public class BinaryMarshallerSelfTest extends GridCommonAbstractTest {
     public void testOffheapPortable() throws Exception {
         BinaryMarshaller marsh = binaryMarshaller(Arrays.asList(new BinaryTypeConfiguration(SimpleObject.class.getName())));
 
-        PortableContext ctx = portableContext(marsh);
+        BinaryContext ctx = portableContext(marsh);
 
         SimpleObject simpleObj = simpleObject();
 
@@ -2273,7 +2273,7 @@ public class BinaryMarshallerSelfTest extends GridCommonAbstractTest {
     public void testPredefinedTypeIds() throws Exception {
         BinaryMarshaller marsh = binaryMarshaller();
 
-        PortableContext pCtx = portableContext(marsh);
+        BinaryContext pCtx = portableContext(marsh);
 
         Field field = pCtx.getClass().getDeclaredField("predefinedTypeNames");
 
@@ -2286,10 +2286,10 @@ public class BinaryMarshallerSelfTest extends GridCommonAbstractTest {
         for (Map.Entry<String, Integer> entry : map.entrySet()) {
             int id = entry.getValue();
 
-            if (id == GridPortableMarshaller.UNREGISTERED_TYPE_ID)
+            if (id == GridBinaryMarshaller.UNREGISTERED_TYPE_ID)
                 continue;
 
-            PortableClassDescriptor desc = pCtx.descriptorForTypeId(false, entry.getValue(), null, false);
+            BinaryClassDescriptor desc = pCtx.descriptorForTypeId(false, entry.getValue(), null, false);
 
             assertEquals(desc.typeId(), pCtx.typeId(desc.describedClass().getName()));
             assertEquals(desc.typeId(), pCtx.typeId(pCtx.typeName(desc.describedClass().getName())));
@@ -2652,7 +2652,7 @@ public class BinaryMarshallerSelfTest extends GridCommonAbstractTest {
     private <T> BinaryObjectImpl marshal(T obj, BinaryMarshaller marsh) throws IgniteCheckedException {
         byte[] bytes = marsh.marshal(obj);
 
-        return new BinaryObjectImpl(U.<GridPortableMarshaller>field(marsh, "impl").context(),
+        return new BinaryObjectImpl(U.<GridBinaryMarshaller>field(marsh, "impl").context(),
             bytes, 0);
     }
 
@@ -2667,8 +2667,8 @@ public class BinaryMarshallerSelfTest extends GridCommonAbstractTest {
      * @param marsh Marshaller.
      * @return Portable context.
      */
-    protected PortableContext portableContext(BinaryMarshaller marsh) {
-        GridPortableMarshaller impl = U.field(marsh, "impl");
+    protected BinaryContext portableContext(BinaryMarshaller marsh) {
+        GridBinaryMarshaller impl = U.field(marsh, "impl");
 
         return impl.context();
     }
@@ -2725,7 +2725,7 @@ public class BinaryMarshallerSelfTest extends GridCommonAbstractTest {
 
         iCfg.setBinaryConfiguration(bCfg);
 
-        PortableContext ctx = new PortableContext(BinaryCachingMetadataHandler.create(), iCfg);
+        BinaryContext ctx = new BinaryContext(BinaryCachingMetadataHandler.create(), iCfg);
 
         BinaryMarshaller marsh = new BinaryMarshaller();
 

http://git-wip-us.apache.org/repos/asf/ignite/blob/71ad9cea/modules/core/src/test/java/org/apache/ignite/internal/binary/BinaryObjectBuilderAdditionalSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/binary/BinaryObjectBuilderAdditionalSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/binary/BinaryObjectBuilderAdditionalSelfTest.java
index 50f74eb..bf329a5 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/binary/BinaryObjectBuilderAdditionalSelfTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/binary/BinaryObjectBuilderAdditionalSelfTest.java
@@ -32,7 +32,7 @@ import org.apache.ignite.configuration.CacheConfiguration;
 import org.apache.ignite.configuration.IgniteConfiguration;
 import org.apache.ignite.internal.binary.mutabletest.GridPortableTestClasses;
 import org.apache.ignite.internal.binary.builder.BinaryObjectBuilderImpl;
-import org.apache.ignite.internal.binary.builder.PortableBuilderEnum;
+import org.apache.ignite.internal.binary.builder.BinaryBuilderEnum;
 import org.apache.ignite.internal.binary.mutabletest.GridBinaryMarshalerAwareTestClass;
 import org.apache.ignite.internal.processors.cache.binary.CacheObjectBinaryProcessorImpl;
 import org.apache.ignite.internal.processors.cache.binary.IgniteBinaryImpl;
@@ -128,11 +128,11 @@ public class BinaryObjectBuilderAdditionalSelfTest extends GridCommonAbstractTes
 
             switch (field.getName()) {
                 case "anEnum":
-                    assertEquals(((PortableBuilderEnum)actVal).getOrdinal(), ((Enum)expVal).ordinal());
+                    assertEquals(((BinaryBuilderEnum)actVal).getOrdinal(), ((Enum)expVal).ordinal());
                     break;
 
                 case "enumArr": {
-                    PortableBuilderEnum[] actArr = (PortableBuilderEnum[])actVal;
+                    BinaryBuilderEnum[] actArr = (BinaryBuilderEnum[])actVal;
                     Enum[] expArr = (Enum[])expVal;
 
                     assertEquals(expArr.length, actArr.length);
@@ -847,8 +847,8 @@ public class BinaryObjectBuilderAdditionalSelfTest extends GridCommonAbstractTes
 
         BinaryObjectBuilderImpl mutObj = wrap(obj);
 
-        PortableBuilderEnum[] arr = mutObj.getField("enumArr");
-        arr[0] = new PortableBuilderEnum(mutObj.typeId(), GridPortableTestClasses.TestObjectEnum.B);
+        BinaryBuilderEnum[] arr = mutObj.getField("enumArr");
+        arr[0] = new BinaryBuilderEnum(mutObj.typeId(), GridPortableTestClasses.TestObjectEnum.B);
 
         GridPortableTestClasses.TestObjectAllTypes res = mutObj.build().deserialize();
 

http://git-wip-us.apache.org/repos/asf/ignite/blob/71ad9cea/modules/core/src/test/java/org/apache/ignite/internal/binary/GridBinaryAffinityKeySelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/binary/GridBinaryAffinityKeySelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/binary/GridBinaryAffinityKeySelfTest.java
new file mode 100644
index 0000000..2528f17
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/binary/GridBinaryAffinityKeySelfTest.java
@@ -0,0 +1,234 @@
+/*
+ * 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.binary;
+
+import java.util.Collections;
+import java.util.UUID;
+import java.util.concurrent.atomic.AtomicReference;
+import org.apache.ignite.Ignite;
+import org.apache.ignite.binary.BinaryObjectBuilder;
+import org.apache.ignite.cache.CacheKeyConfiguration;
+import org.apache.ignite.cache.affinity.Affinity;
+import org.apache.ignite.configuration.BinaryConfiguration;
+import org.apache.ignite.configuration.CacheConfiguration;
+import org.apache.ignite.configuration.IgniteConfiguration;
+import org.apache.ignite.internal.IgniteKernal;
+import org.apache.ignite.internal.processors.affinity.GridAffinityProcessor;
+import org.apache.ignite.internal.processors.cache.CacheObject;
+import org.apache.ignite.internal.processors.cache.CacheObjectContext;
+import org.apache.ignite.internal.processors.cacheobject.IgniteCacheObjectProcessor;
+import org.apache.ignite.lang.IgniteCallable;
+import org.apache.ignite.lang.IgniteRunnable;
+import org.apache.ignite.binary.BinaryTypeConfiguration;
+import org.apache.ignite.resources.IgniteInstanceResource;
+import org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi;
+import org.apache.ignite.spi.discovery.tcp.ipfinder.TcpDiscoveryIpFinder;
+import org.apache.ignite.spi.discovery.tcp.ipfinder.vm.TcpDiscoveryVmIpFinder;
+import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
+
+import static org.apache.ignite.cache.CacheMode.PARTITIONED;
+
+/**
+ * Test for portable object affinity key.
+ */
+public class GridBinaryAffinityKeySelfTest extends GridCommonAbstractTest {
+    /** */
+    private static final AtomicReference<UUID> nodeId = new AtomicReference<>();
+
+    /** VM ip finder for TCP discovery. */
+    private static TcpDiscoveryIpFinder ipFinder = new TcpDiscoveryVmIpFinder(true);
+
+    /** */
+    private static int GRID_CNT = 5;
+
+    /** {@inheritDoc} */
+    @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception {
+        IgniteConfiguration cfg = super.getConfiguration(gridName);
+
+        BinaryTypeConfiguration typeCfg = new BinaryTypeConfiguration();
+
+        typeCfg.setTypeName(TestObject.class.getName());
+
+        BinaryConfiguration bCfg = new BinaryConfiguration();
+
+        bCfg.setTypeConfigurations(Collections.singleton(typeCfg));
+
+        cfg.setBinaryConfiguration(bCfg);
+
+        CacheKeyConfiguration keyCfg = new CacheKeyConfiguration(TestObject.class.getName(), "affKey");
+        CacheKeyConfiguration keyCfg2 = new CacheKeyConfiguration("TestObject2", "affKey");
+
+        cfg.setCacheKeyConfiguration(keyCfg, keyCfg2);
+
+        cfg.setMarshaller(new BinaryMarshaller());
+
+        if (!gridName.equals(getTestGridName(GRID_CNT))) {
+            CacheConfiguration cacheCfg = new CacheConfiguration();
+
+            cacheCfg.setCacheMode(PARTITIONED);
+
+            cfg.setCacheConfiguration(cacheCfg);
+        }
+
+        ((TcpDiscoverySpi)cfg.getDiscoverySpi()).setIpFinder(ipFinder);
+
+        return cfg;
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void beforeTestsStarted() throws Exception {
+        startGridsMultiThreaded(GRID_CNT);
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void afterTestsStopped() throws Exception {
+        stopAllGrids();
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testAffinity() throws Exception {
+        checkAffinity(grid(0));
+
+        try (Ignite igniteNoCache = startGrid(GRID_CNT)) {
+            try {
+                igniteNoCache.cache(null);
+            }
+            catch (IllegalArgumentException ignore) {
+                // Expected error.
+            }
+
+            checkAffinity(igniteNoCache);
+        }
+    }
+
+    /**
+     * @param ignite Ignite.
+     * @throws Exception If failed.
+     */
+    private void checkAffinity(Ignite ignite) throws Exception {
+        Affinity<Object> aff = ignite.affinity(null);
+
+        GridAffinityProcessor affProc = ((IgniteKernal)ignite).context().affinity();
+
+        IgniteCacheObjectProcessor cacheObjProc = ((IgniteKernal)ignite).context().cacheObjects();
+
+        CacheObjectContext cacheObjCtx = cacheObjProc.contextForCache(
+            ignite.cache(null).getConfiguration(CacheConfiguration.class));
+
+        for (int i = 0; i < 1000; i++) {
+            assertEquals(i, aff.affinityKey(i));
+
+            assertEquals(i, aff.affinityKey(new TestObject(i)));
+
+            assertEquals(i, aff.affinityKey(ignite.binary().toBinary(new TestObject(i))));
+
+            BinaryObjectBuilder bldr = ignite.binary().builder("TestObject2");
+
+            bldr.setField("affKey", i);
+
+            assertEquals(i, aff.affinityKey(bldr.build()));
+
+            CacheObject cacheObj = cacheObjProc.toCacheObject(cacheObjCtx, new TestObject(i), true);
+
+            assertEquals(i, aff.affinityKey(cacheObj));
+
+            assertEquals(aff.mapKeyToNode(i), aff.mapKeyToNode(new TestObject(i)));
+
+            assertEquals(aff.mapKeyToNode(i), aff.mapKeyToNode(cacheObj));
+
+            assertEquals(i, affProc.affinityKey(null, i));
+
+            assertEquals(i, affProc.affinityKey(null, new TestObject(i)));
+
+            assertEquals(i, affProc.affinityKey(null, cacheObj));
+
+            assertEquals(affProc.mapKeyToNode(null, i), affProc.mapKeyToNode(null, new TestObject(i)));
+
+            assertEquals(affProc.mapKeyToNode(null, i), affProc.mapKeyToNode(null, cacheObj));
+        }
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testAffinityRun() throws Exception {
+        Affinity<Object> aff = grid(0).affinity(null);
+
+        for (int i = 0; i < 1000; i++) {
+            nodeId.set(null);
+
+            grid(0).compute().affinityRun(null, new TestObject(i), new IgniteRunnable() {
+                @IgniteInstanceResource
+                private Ignite ignite;
+
+                @Override public void run() {
+                    nodeId.set(ignite.configuration().getNodeId());
+                }
+            });
+
+            assertEquals(aff.mapKeyToNode(i).id(), nodeId.get());
+        }
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testAffinityCall() throws Exception {
+        Affinity<Object> aff = grid(0).affinity(null);
+
+        for (int i = 0; i < 1000; i++) {
+            nodeId.set(null);
+
+            grid(0).compute().affinityCall(null, new TestObject(i), new IgniteCallable<Object>() {
+                @IgniteInstanceResource
+                private Ignite ignite;
+
+                @Override public Object call() {
+                    nodeId.set(ignite.configuration().getNodeId());
+
+                    return null;
+                }
+            });
+
+            assertEquals(aff.mapKeyToNode(i).id(), nodeId.get());
+        }
+    }
+
+    /**
+     */
+    private static class TestObject {
+        /** */
+        @SuppressWarnings("UnusedDeclaration")
+        private int affKey;
+
+        /**
+         */
+        private TestObject() {
+            // No-op.
+        }
+
+        /**
+         * @param affKey Affinity key.
+         */
+        private TestObject(int affKey) {
+            this.affKey = affKey;
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/71ad9cea/modules/core/src/test/java/org/apache/ignite/internal/binary/GridBinaryMarshallerCtxDisabledSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/binary/GridBinaryMarshallerCtxDisabledSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/binary/GridBinaryMarshallerCtxDisabledSelfTest.java
new file mode 100644
index 0000000..c48b056
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/binary/GridBinaryMarshallerCtxDisabledSelfTest.java
@@ -0,0 +1,247 @@
+/*
+ * 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.binary;
+
+import org.apache.ignite.IgniteCheckedException;
+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.configuration.IgniteConfiguration;
+import org.apache.ignite.internal.MarshallerContextAdapter;
+import org.apache.ignite.internal.util.IgniteUtils;
+import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
+
+import java.io.Externalizable;
+import java.io.IOException;
+import java.io.ObjectInput;
+import java.io.ObjectOutput;
+import java.util.Arrays;
+
+/**
+ *
+ */
+public class GridBinaryMarshallerCtxDisabledSelfTest extends GridCommonAbstractTest {
+    /**
+     * @throws Exception If failed.
+     */
+    public void testObjectExchange() throws Exception {
+        BinaryMarshaller marsh = new BinaryMarshaller();
+        marsh.setContext(new MarshallerContextWithNoStorage());
+
+        IgniteConfiguration cfg = new IgniteConfiguration();
+
+        BinaryContext context = new BinaryContext(BinaryCachingMetadataHandler.create(), cfg);
+
+        IgniteUtils.invoke(BinaryMarshaller.class, marsh, "setPortableContext", context, cfg);
+
+        SimpleObject simpleObj = new SimpleObject();
+
+        simpleObj.b = 2;
+        simpleObj.bArr = new byte[] {2, 3, 4, 5, 5};
+        simpleObj.c = 'A';
+        simpleObj.enumVal = TestEnum.D;
+        simpleObj.objArr = new Object[] {"hello", "world", "from", "me"};
+        simpleObj.enumArr = new TestEnum[] {TestEnum.C, TestEnum.B};
+
+        SimpleObject otherObj = new SimpleObject();
+
+        otherObj.b = 3;
+        otherObj.bArr = new byte[] {5, 3, 4};
+
+        simpleObj.otherObj = otherObj;
+
+        assertEquals(simpleObj, marsh.unmarshal(marsh.marshal(simpleObj), null));
+
+        SimpleBinary simplePortable = new SimpleBinary();
+
+        simplePortable.str = "portable";
+        simplePortable.arr = new long[] {100, 200, 300};
+
+        assertEquals(simplePortable, marsh.unmarshal(marsh.marshal(simplePortable), null));
+
+        SimpleExternalizable simpleExtr = new SimpleExternalizable();
+
+        simpleExtr.str = "externalizable";
+        simpleExtr.arr = new long[] {20000, 300000, 400000};
+
+        assertEquals(simpleExtr, marsh.unmarshal(marsh.marshal(simpleExtr), null));
+    }
+
+    /**
+     * Marshaller context with no storage. Platform has to work in such environment as well by marshalling class name of
+     * a portable object.
+     */
+    private static class MarshallerContextWithNoStorage extends MarshallerContextAdapter {
+        /** */
+        public MarshallerContextWithNoStorage() {
+            super(null);
+        }
+
+        /** {@inheritDoc} */
+        @Override protected boolean registerClassName(int id, String clsName) throws IgniteCheckedException {
+            return false;
+        }
+
+        /** {@inheritDoc} */
+        @Override protected String className(int id) throws IgniteCheckedException {
+            return null;
+        }
+    }
+
+    /**
+     */
+    private enum TestEnum {
+        A, B, C, D, E
+    }
+
+    /**
+     */
+    private static class SimpleObject {
+        /** */
+        private byte b;
+
+        /** */
+        private char c;
+
+        /** */
+        private byte[] bArr;
+
+        /** */
+        private Object[] objArr;
+
+        /** */
+        private TestEnum enumVal;
+
+        /** */
+        private TestEnum[] enumArr;
+
+        private SimpleObject otherObj;
+
+        /** {@inheritDoc} */
+        @Override public boolean equals(Object o) {
+            if (this == o)
+                return true;
+
+            if (o == null || getClass() != o.getClass())
+                return false;
+
+            SimpleObject object = (SimpleObject)o;
+
+            if (b != object.b)
+                return false;
+
+            if (c != object.c)
+                return false;
+
+            if (!Arrays.equals(bArr, object.bArr))
+                return false;
+
+            // Probably incorrect - comparing Object[] arrays with Arrays.equals
+            if (!Arrays.equals(objArr, object.objArr))
+                return false;
+
+            if (enumVal != object.enumVal)
+                return false;
+
+            // Probably incorrect - comparing Object[] arrays with Arrays.equals
+            if (!Arrays.equals(enumArr, object.enumArr))
+                return false;
+
+            return !(otherObj != null ? !otherObj.equals(object.otherObj) : object.otherObj != null);
+        }
+    }
+
+    /**
+     *
+     */
+    private static class SimpleBinary implements Binarylizable {
+        /** */
+        private String str;
+
+        /** */
+        private long[] arr;
+
+        /** {@inheritDoc} */
+        @Override public void writeBinary(BinaryWriter writer) throws BinaryObjectException {
+            writer.writeString("str", str);
+            writer.writeLongArray("longArr", arr);
+        }
+
+        /** {@inheritDoc} */
+        @Override public void readBinary(BinaryReader reader) throws BinaryObjectException {
+            str = reader.readString("str");
+            arr = reader.readLongArray("longArr");
+        }
+
+        /** {@inheritDoc} */
+        @Override public boolean equals(Object o) {
+            if (this == o)
+                return true;
+
+            if (o == null || getClass() != o.getClass())
+                return false;
+
+            SimpleBinary that = (SimpleBinary)o;
+
+            if (str != null ? !str.equals(that.str) : that.str != null)
+                return false;
+
+            return Arrays.equals(arr, that.arr);
+        }
+    }
+
+    /**
+     *
+     */
+    private static class SimpleExternalizable implements Externalizable {
+        /** */
+        private String str;
+
+        /** */
+        private long[] arr;
+
+        /** {@inheritDoc} */
+        @Override public void writeExternal(ObjectOutput out) throws IOException {
+            out.writeUTF(str);
+            out.writeObject(arr);
+        }
+
+        /** {@inheritDoc} */
+        @Override public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
+            str = in.readUTF();
+            arr = (long[])in.readObject();
+        }
+
+        /** {@inheritDoc} */
+        @Override public boolean equals(Object o) {
+            if (this == o)
+                return true;
+
+            if (o == null || getClass() != o.getClass())
+                return false;
+
+            SimpleExternalizable that = (SimpleExternalizable)o;
+
+            if (str != null ? !str.equals(that.str) : that.str != null)
+                return false;
+
+            return Arrays.equals(arr, that.arr);
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/71ad9cea/modules/core/src/test/java/org/apache/ignite/internal/binary/GridPortableAffinityKeySelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/binary/GridPortableAffinityKeySelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/binary/GridPortableAffinityKeySelfTest.java
deleted file mode 100644
index 74941d0..0000000
--- a/modules/core/src/test/java/org/apache/ignite/internal/binary/GridPortableAffinityKeySelfTest.java
+++ /dev/null
@@ -1,234 +0,0 @@
-/*
- * 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.binary;
-
-import java.util.Collections;
-import java.util.UUID;
-import java.util.concurrent.atomic.AtomicReference;
-import org.apache.ignite.Ignite;
-import org.apache.ignite.binary.BinaryObjectBuilder;
-import org.apache.ignite.cache.CacheKeyConfiguration;
-import org.apache.ignite.cache.affinity.Affinity;
-import org.apache.ignite.configuration.BinaryConfiguration;
-import org.apache.ignite.configuration.CacheConfiguration;
-import org.apache.ignite.configuration.IgniteConfiguration;
-import org.apache.ignite.internal.IgniteKernal;
-import org.apache.ignite.internal.processors.affinity.GridAffinityProcessor;
-import org.apache.ignite.internal.processors.cache.CacheObject;
-import org.apache.ignite.internal.processors.cache.CacheObjectContext;
-import org.apache.ignite.internal.processors.cacheobject.IgniteCacheObjectProcessor;
-import org.apache.ignite.lang.IgniteCallable;
-import org.apache.ignite.lang.IgniteRunnable;
-import org.apache.ignite.binary.BinaryTypeConfiguration;
-import org.apache.ignite.resources.IgniteInstanceResource;
-import org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi;
-import org.apache.ignite.spi.discovery.tcp.ipfinder.TcpDiscoveryIpFinder;
-import org.apache.ignite.spi.discovery.tcp.ipfinder.vm.TcpDiscoveryVmIpFinder;
-import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
-
-import static org.apache.ignite.cache.CacheMode.PARTITIONED;
-
-/**
- * Test for portable object affinity key.
- */
-public class GridPortableAffinityKeySelfTest extends GridCommonAbstractTest {
-    /** */
-    private static final AtomicReference<UUID> nodeId = new AtomicReference<>();
-
-    /** VM ip finder for TCP discovery. */
-    private static TcpDiscoveryIpFinder ipFinder = new TcpDiscoveryVmIpFinder(true);
-
-    /** */
-    private static int GRID_CNT = 5;
-
-    /** {@inheritDoc} */
-    @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception {
-        IgniteConfiguration cfg = super.getConfiguration(gridName);
-
-        BinaryTypeConfiguration typeCfg = new BinaryTypeConfiguration();
-
-        typeCfg.setTypeName(TestObject.class.getName());
-
-        BinaryConfiguration bCfg = new BinaryConfiguration();
-
-        bCfg.setTypeConfigurations(Collections.singleton(typeCfg));
-
-        cfg.setBinaryConfiguration(bCfg);
-
-        CacheKeyConfiguration keyCfg = new CacheKeyConfiguration(TestObject.class.getName(), "affKey");
-        CacheKeyConfiguration keyCfg2 = new CacheKeyConfiguration("TestObject2", "affKey");
-
-        cfg.setCacheKeyConfiguration(keyCfg, keyCfg2);
-
-        cfg.setMarshaller(new BinaryMarshaller());
-
-        if (!gridName.equals(getTestGridName(GRID_CNT))) {
-            CacheConfiguration cacheCfg = new CacheConfiguration();
-
-            cacheCfg.setCacheMode(PARTITIONED);
-
-            cfg.setCacheConfiguration(cacheCfg);
-        }
-
-        ((TcpDiscoverySpi)cfg.getDiscoverySpi()).setIpFinder(ipFinder);
-
-        return cfg;
-    }
-
-    /** {@inheritDoc} */
-    @Override protected void beforeTestsStarted() throws Exception {
-        startGridsMultiThreaded(GRID_CNT);
-    }
-
-    /** {@inheritDoc} */
-    @Override protected void afterTestsStopped() throws Exception {
-        stopAllGrids();
-    }
-
-    /**
-     * @throws Exception If failed.
-     */
-    public void testAffinity() throws Exception {
-        checkAffinity(grid(0));
-
-        try (Ignite igniteNoCache = startGrid(GRID_CNT)) {
-            try {
-                igniteNoCache.cache(null);
-            }
-            catch (IllegalArgumentException ignore) {
-                // Expected error.
-            }
-
-            checkAffinity(igniteNoCache);
-        }
-    }
-
-    /**
-     * @param ignite Ignite.
-     * @throws Exception If failed.
-     */
-    private void checkAffinity(Ignite ignite) throws Exception {
-        Affinity<Object> aff = ignite.affinity(null);
-
-        GridAffinityProcessor affProc = ((IgniteKernal)ignite).context().affinity();
-
-        IgniteCacheObjectProcessor cacheObjProc = ((IgniteKernal)ignite).context().cacheObjects();
-
-        CacheObjectContext cacheObjCtx = cacheObjProc.contextForCache(
-            ignite.cache(null).getConfiguration(CacheConfiguration.class));
-
-        for (int i = 0; i < 1000; i++) {
-            assertEquals(i, aff.affinityKey(i));
-
-            assertEquals(i, aff.affinityKey(new TestObject(i)));
-
-            assertEquals(i, aff.affinityKey(ignite.binary().toBinary(new TestObject(i))));
-
-            BinaryObjectBuilder bldr = ignite.binary().builder("TestObject2");
-
-            bldr.setField("affKey", i);
-
-            assertEquals(i, aff.affinityKey(bldr.build()));
-
-            CacheObject cacheObj = cacheObjProc.toCacheObject(cacheObjCtx, new TestObject(i), true);
-
-            assertEquals(i, aff.affinityKey(cacheObj));
-
-            assertEquals(aff.mapKeyToNode(i), aff.mapKeyToNode(new TestObject(i)));
-
-            assertEquals(aff.mapKeyToNode(i), aff.mapKeyToNode(cacheObj));
-
-            assertEquals(i, affProc.affinityKey(null, i));
-
-            assertEquals(i, affProc.affinityKey(null, new TestObject(i)));
-
-            assertEquals(i, affProc.affinityKey(null, cacheObj));
-
-            assertEquals(affProc.mapKeyToNode(null, i), affProc.mapKeyToNode(null, new TestObject(i)));
-
-            assertEquals(affProc.mapKeyToNode(null, i), affProc.mapKeyToNode(null, cacheObj));
-        }
-    }
-
-    /**
-     * @throws Exception If failed.
-     */
-    public void testAffinityRun() throws Exception {
-        Affinity<Object> aff = grid(0).affinity(null);
-
-        for (int i = 0; i < 1000; i++) {
-            nodeId.set(null);
-
-            grid(0).compute().affinityRun(null, new TestObject(i), new IgniteRunnable() {
-                @IgniteInstanceResource
-                private Ignite ignite;
-
-                @Override public void run() {
-                    nodeId.set(ignite.configuration().getNodeId());
-                }
-            });
-
-            assertEquals(aff.mapKeyToNode(i).id(), nodeId.get());
-        }
-    }
-
-    /**
-     * @throws Exception If failed.
-     */
-    public void testAffinityCall() throws Exception {
-        Affinity<Object> aff = grid(0).affinity(null);
-
-        for (int i = 0; i < 1000; i++) {
-            nodeId.set(null);
-
-            grid(0).compute().affinityCall(null, new TestObject(i), new IgniteCallable<Object>() {
-                @IgniteInstanceResource
-                private Ignite ignite;
-
-                @Override public Object call() {
-                    nodeId.set(ignite.configuration().getNodeId());
-
-                    return null;
-                }
-            });
-
-            assertEquals(aff.mapKeyToNode(i).id(), nodeId.get());
-        }
-    }
-
-    /**
-     */
-    private static class TestObject {
-        /** */
-        @SuppressWarnings("UnusedDeclaration")
-        private int affKey;
-
-        /**
-         */
-        private TestObject() {
-            // No-op.
-        }
-
-        /**
-         * @param affKey Affinity key.
-         */
-        private TestObject(int affKey) {
-            this.affKey = affKey;
-        }
-    }
-}

http://git-wip-us.apache.org/repos/asf/ignite/blob/71ad9cea/modules/core/src/test/java/org/apache/ignite/internal/binary/GridPortableMarshallerCtxDisabledSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/binary/GridPortableMarshallerCtxDisabledSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/binary/GridPortableMarshallerCtxDisabledSelfTest.java
deleted file mode 100644
index a30d09f..0000000
--- a/modules/core/src/test/java/org/apache/ignite/internal/binary/GridPortableMarshallerCtxDisabledSelfTest.java
+++ /dev/null
@@ -1,247 +0,0 @@
-/*
- * 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.binary;
-
-import org.apache.ignite.IgniteCheckedException;
-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.configuration.IgniteConfiguration;
-import org.apache.ignite.internal.MarshallerContextAdapter;
-import org.apache.ignite.internal.util.IgniteUtils;
-import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
-
-import java.io.Externalizable;
-import java.io.IOException;
-import java.io.ObjectInput;
-import java.io.ObjectOutput;
-import java.util.Arrays;
-
-/**
- *
- */
-public class GridPortableMarshallerCtxDisabledSelfTest extends GridCommonAbstractTest {
-    /**
-     * @throws Exception If failed.
-     */
-    public void testObjectExchange() throws Exception {
-        BinaryMarshaller marsh = new BinaryMarshaller();
-        marsh.setContext(new MarshallerContextWithNoStorage());
-
-        IgniteConfiguration cfg = new IgniteConfiguration();
-
-        PortableContext context = new PortableContext(BinaryCachingMetadataHandler.create(), cfg);
-
-        IgniteUtils.invoke(BinaryMarshaller.class, marsh, "setPortableContext", context, cfg);
-
-        SimpleObject simpleObj = new SimpleObject();
-
-        simpleObj.b = 2;
-        simpleObj.bArr = new byte[] {2, 3, 4, 5, 5};
-        simpleObj.c = 'A';
-        simpleObj.enumVal = TestEnum.D;
-        simpleObj.objArr = new Object[] {"hello", "world", "from", "me"};
-        simpleObj.enumArr = new TestEnum[] {TestEnum.C, TestEnum.B};
-
-        SimpleObject otherObj = new SimpleObject();
-
-        otherObj.b = 3;
-        otherObj.bArr = new byte[] {5, 3, 4};
-
-        simpleObj.otherObj = otherObj;
-
-        assertEquals(simpleObj, marsh.unmarshal(marsh.marshal(simpleObj), null));
-
-        SimpleBinary simplePortable = new SimpleBinary();
-
-        simplePortable.str = "portable";
-        simplePortable.arr = new long[] {100, 200, 300};
-
-        assertEquals(simplePortable, marsh.unmarshal(marsh.marshal(simplePortable), null));
-
-        SimpleExternalizable simpleExtr = new SimpleExternalizable();
-
-        simpleExtr.str = "externalizable";
-        simpleExtr.arr = new long[] {20000, 300000, 400000};
-
-        assertEquals(simpleExtr, marsh.unmarshal(marsh.marshal(simpleExtr), null));
-    }
-
-    /**
-     * Marshaller context with no storage. Platform has to work in such environment as well by marshalling class name of
-     * a portable object.
-     */
-    private static class MarshallerContextWithNoStorage extends MarshallerContextAdapter {
-        /** */
-        public MarshallerContextWithNoStorage() {
-            super(null);
-        }
-
-        /** {@inheritDoc} */
-        @Override protected boolean registerClassName(int id, String clsName) throws IgniteCheckedException {
-            return false;
-        }
-
-        /** {@inheritDoc} */
-        @Override protected String className(int id) throws IgniteCheckedException {
-            return null;
-        }
-    }
-
-    /**
-     */
-    private enum TestEnum {
-        A, B, C, D, E
-    }
-
-    /**
-     */
-    private static class SimpleObject {
-        /** */
-        private byte b;
-
-        /** */
-        private char c;
-
-        /** */
-        private byte[] bArr;
-
-        /** */
-        private Object[] objArr;
-
-        /** */
-        private TestEnum enumVal;
-
-        /** */
-        private TestEnum[] enumArr;
-
-        private SimpleObject otherObj;
-
-        /** {@inheritDoc} */
-        @Override public boolean equals(Object o) {
-            if (this == o)
-                return true;
-
-            if (o == null || getClass() != o.getClass())
-                return false;
-
-            SimpleObject object = (SimpleObject)o;
-
-            if (b != object.b)
-                return false;
-
-            if (c != object.c)
-                return false;
-
-            if (!Arrays.equals(bArr, object.bArr))
-                return false;
-
-            // Probably incorrect - comparing Object[] arrays with Arrays.equals
-            if (!Arrays.equals(objArr, object.objArr))
-                return false;
-
-            if (enumVal != object.enumVal)
-                return false;
-
-            // Probably incorrect - comparing Object[] arrays with Arrays.equals
-            if (!Arrays.equals(enumArr, object.enumArr))
-                return false;
-
-            return !(otherObj != null ? !otherObj.equals(object.otherObj) : object.otherObj != null);
-        }
-    }
-
-    /**
-     *
-     */
-    private static class SimpleBinary implements Binarylizable {
-        /** */
-        private String str;
-
-        /** */
-        private long[] arr;
-
-        /** {@inheritDoc} */
-        @Override public void writeBinary(BinaryWriter writer) throws BinaryObjectException {
-            writer.writeString("str", str);
-            writer.writeLongArray("longArr", arr);
-        }
-
-        /** {@inheritDoc} */
-        @Override public void readBinary(BinaryReader reader) throws BinaryObjectException {
-            str = reader.readString("str");
-            arr = reader.readLongArray("longArr");
-        }
-
-        /** {@inheritDoc} */
-        @Override public boolean equals(Object o) {
-            if (this == o)
-                return true;
-
-            if (o == null || getClass() != o.getClass())
-                return false;
-
-            SimpleBinary that = (SimpleBinary)o;
-
-            if (str != null ? !str.equals(that.str) : that.str != null)
-                return false;
-
-            return Arrays.equals(arr, that.arr);
-        }
-    }
-
-    /**
-     *
-     */
-    private static class SimpleExternalizable implements Externalizable {
-        /** */
-        private String str;
-
-        /** */
-        private long[] arr;
-
-        /** {@inheritDoc} */
-        @Override public void writeExternal(ObjectOutput out) throws IOException {
-            out.writeUTF(str);
-            out.writeObject(arr);
-        }
-
-        /** {@inheritDoc} */
-        @Override public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
-            str = in.readUTF();
-            arr = (long[])in.readObject();
-        }
-
-        /** {@inheritDoc} */
-        @Override public boolean equals(Object o) {
-            if (this == o)
-                return true;
-
-            if (o == null || getClass() != o.getClass())
-                return false;
-
-            SimpleExternalizable that = (SimpleExternalizable)o;
-
-            if (str != null ? !str.equals(that.str) : that.str != null)
-                return false;
-
-            return Arrays.equals(arr, that.arr);
-        }
-    }
-}

http://git-wip-us.apache.org/repos/asf/ignite/blob/71ad9cea/modules/core/src/test/java/org/apache/ignite/internal/binary/GridPortableWildcardsSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/binary/GridPortableWildcardsSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/binary/GridPortableWildcardsSelfTest.java
index a91e350..9226272 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/binary/GridPortableWildcardsSelfTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/binary/GridPortableWildcardsSelfTest.java
@@ -45,7 +45,7 @@ public class GridPortableWildcardsSelfTest extends GridCommonAbstractTest {
             new BinaryTypeConfiguration("unknown.*")
         ));
 
-        PortableContext ctx = portableContext(marsh);
+        BinaryContext ctx = portableContext(marsh);
 
         Map<Integer, Class> typeIds = U.field(ctx, "userTypes");
 
@@ -81,7 +81,7 @@ public class GridPortableWildcardsSelfTest extends GridCommonAbstractTest {
             new BinaryTypeConfiguration("unknown.*")
         ));
 
-        PortableContext ctx = portableContext(marsh);
+        BinaryContext ctx = portableContext(marsh);
 
         Map<String, BinaryIdMapper> typeMappers = U.field(ctx, "typeMappers");
 
@@ -101,7 +101,7 @@ public class GridPortableWildcardsSelfTest extends GridCommonAbstractTest {
             new BinaryTypeConfiguration("unknown.*")
         ));
 
-        PortableContext ctx = portableContext(marsh);
+        BinaryContext ctx = portableContext(marsh);
 
         Map<Integer, Class> typeIds = U.field(ctx, "userTypes");
 
@@ -137,7 +137,7 @@ public class GridPortableWildcardsSelfTest extends GridCommonAbstractTest {
             new BinaryTypeConfiguration("unknown.*")
         ));
 
-        PortableContext ctx = portableContext(marsh);
+        BinaryContext ctx = portableContext(marsh);
 
         Map<String, BinaryIdMapper> typeMappers = U.field(ctx, "typeMappers");
 
@@ -173,7 +173,7 @@ public class GridPortableWildcardsSelfTest extends GridCommonAbstractTest {
             new BinaryTypeConfiguration("unknown.*")
         ));
 
-        PortableContext ctx = portableContext(marsh);
+        BinaryContext ctx = portableContext(marsh);
 
         Map<String, BinaryIdMapper> typeMappers = U.field(ctx, "typeMappers");
 
@@ -205,7 +205,7 @@ public class GridPortableWildcardsSelfTest extends GridCommonAbstractTest {
             new BinaryTypeConfiguration("org.apache.ignite.internal.binary.test.*"),
             typeCfg));
 
-        PortableContext ctx = portableContext(marsh);
+        BinaryContext ctx = portableContext(marsh);
 
         Map<Integer, Class> typeIds = U.field(ctx, "userTypes");
 
@@ -229,7 +229,7 @@ public class GridPortableWildcardsSelfTest extends GridCommonAbstractTest {
             new BinaryTypeConfiguration("unknown.*")
         ));
 
-        PortableContext ctx = portableContext(marsh);
+        BinaryContext ctx = portableContext(marsh);
 
         Map<Integer, Class> typeIds = U.field(ctx, "userTypes");
 
@@ -262,7 +262,7 @@ public class GridPortableWildcardsSelfTest extends GridCommonAbstractTest {
             new BinaryTypeConfiguration("unknown.*")
         ));
 
-        PortableContext ctx = portableContext(marsh);
+        BinaryContext ctx = portableContext(marsh);
 
         Map<String, BinaryIdMapper> typeMappers = U.field(ctx, "typeMappers");
 
@@ -281,7 +281,7 @@ public class GridPortableWildcardsSelfTest extends GridCommonAbstractTest {
             new BinaryTypeConfiguration("unknown.*")
         ));
 
-        PortableContext ctx = portableContext(marsh);
+        BinaryContext ctx = portableContext(marsh);
 
         Map<Integer, Class> typeIds = U.field(ctx, "userTypes");
 
@@ -314,7 +314,7 @@ public class GridPortableWildcardsSelfTest extends GridCommonAbstractTest {
             new BinaryTypeConfiguration("unknown.*")
         ));
 
-        PortableContext ctx = portableContext(marsh);
+        BinaryContext ctx = portableContext(marsh);
 
         Map<String, BinaryIdMapper> typeMappers = U.field(ctx, "typeMappers");
 
@@ -347,7 +347,7 @@ public class GridPortableWildcardsSelfTest extends GridCommonAbstractTest {
             new BinaryTypeConfiguration("unknown.*")
         ));
 
-        PortableContext ctx = portableContext(marsh);
+        BinaryContext ctx = portableContext(marsh);
 
         Map<String, BinaryIdMapper> typeMappers = U.field(ctx, "typeMappers");
 
@@ -378,7 +378,7 @@ public class GridPortableWildcardsSelfTest extends GridCommonAbstractTest {
             new BinaryTypeConfiguration("org.apache.ignite.binary.testjar.*"),
             typeCfg));
 
-        PortableContext ctx = portableContext(marsh);
+        BinaryContext ctx = portableContext(marsh);
 
         Map<Integer, Class> typeIds = U.field(ctx, "userTypes");
 
@@ -397,8 +397,8 @@ public class GridPortableWildcardsSelfTest extends GridCommonAbstractTest {
      * @param marsh Marshaller.
      * @return Portable context.
      */
-    protected PortableContext portableContext(BinaryMarshaller marsh) {
-        GridPortableMarshaller impl = U.field(marsh, "impl");
+    protected BinaryContext portableContext(BinaryMarshaller marsh) {
+        GridBinaryMarshaller impl = U.field(marsh, "impl");
 
         return impl.context();
     }
@@ -451,7 +451,7 @@ public class GridPortableWildcardsSelfTest extends GridCommonAbstractTest {
 
         iCfg.setBinaryConfiguration(bCfg);
 
-        PortableContext ctx = new PortableContext(BinaryNoopMetadataHandler.instance(), iCfg);
+        BinaryContext ctx = new BinaryContext(BinaryNoopMetadataHandler.instance(), iCfg);
 
         BinaryMarshaller marsh = new BinaryMarshaller();
 

http://git-wip-us.apache.org/repos/asf/ignite/blob/71ad9cea/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/binary/GridBinaryCacheEntryMemorySizeSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/binary/GridBinaryCacheEntryMemorySizeSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/binary/GridBinaryCacheEntryMemorySizeSelfTest.java
new file mode 100644
index 0000000..128e316
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/binary/GridBinaryCacheEntryMemorySizeSelfTest.java
@@ -0,0 +1,48 @@
+/*
+ * 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.processors.cache.binary;
+
+import org.apache.ignite.IgniteCheckedException;
+import org.apache.ignite.configuration.IgniteConfiguration;
+import org.apache.ignite.internal.binary.BinaryNoopMetadataHandler;
+import org.apache.ignite.internal.binary.BinaryContext;
+import org.apache.ignite.internal.processors.cache.GridCacheEntryMemorySizeSelfTest;
+import org.apache.ignite.internal.util.IgniteUtils;
+import org.apache.ignite.marshaller.Marshaller;
+import org.apache.ignite.marshaller.MarshallerContextTestImpl;
+import org.apache.ignite.internal.binary.BinaryMarshaller;
+
+/**
+ *
+ */
+public class GridBinaryCacheEntryMemorySizeSelfTest extends GridCacheEntryMemorySizeSelfTest {
+    /** {@inheritDoc} */
+    @Override protected Marshaller createMarshaller() throws IgniteCheckedException {
+        BinaryMarshaller marsh = new BinaryMarshaller();
+
+        marsh.setContext(new MarshallerContextTestImpl(null));
+
+        IgniteConfiguration iCfg = new IgniteConfiguration();
+
+        BinaryContext pCtx = new BinaryContext(BinaryNoopMetadataHandler.instance(), iCfg);
+
+        IgniteUtils.invoke(BinaryMarshaller.class, marsh, "setPortableContext", pCtx, iCfg);
+
+        return marsh;
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/71ad9cea/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/binary/GridBinaryDuplicateIndexObjectsAbstractSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/binary/GridBinaryDuplicateIndexObjectsAbstractSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/binary/GridBinaryDuplicateIndexObjectsAbstractSelfTest.java
new file mode 100644
index 0000000..9306958
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/binary/GridBinaryDuplicateIndexObjectsAbstractSelfTest.java
@@ -0,0 +1,161 @@
+/*
+ * 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.processors.cache.binary;
+
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import org.apache.ignite.IgniteCache;
+import org.apache.ignite.cache.CacheAtomicityMode;
+import org.apache.ignite.cache.CacheMode;
+import org.apache.ignite.cache.CacheTypeMetadata;
+import org.apache.ignite.cache.query.SqlFieldsQuery;
+import org.apache.ignite.configuration.BinaryConfiguration;
+import org.apache.ignite.configuration.CacheConfiguration;
+import org.apache.ignite.configuration.IgniteConfiguration;
+import org.apache.ignite.internal.processors.cache.GridCacheAbstractSelfTest;
+import org.apache.ignite.internal.util.typedef.F;
+import org.apache.ignite.internal.binary.BinaryMarshaller;
+import org.apache.ignite.binary.BinaryObject;
+
+/**
+ * Tests that portable object is the same in cache entry and in index.
+ */
+public abstract class GridBinaryDuplicateIndexObjectsAbstractSelfTest extends GridCacheAbstractSelfTest {
+    /** {@inheritDoc} */
+    @Override protected int gridCount() {
+        return 1;
+    }
+
+    /** {@inheritDoc} */
+    @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception {
+        IgniteConfiguration cfg = super.getConfiguration(gridName);
+
+        BinaryConfiguration bCfg = new BinaryConfiguration();
+
+        bCfg.setClassNames(Collections.singletonList(TestPortable.class.getName()));
+
+        cfg.setBinaryConfiguration(bCfg);
+
+        cfg.setMarshaller(new BinaryMarshaller());
+
+        return cfg;
+    }
+
+    /** {@inheritDoc} */
+    @Override protected CacheConfiguration cacheConfiguration(String gridName) throws Exception {
+        CacheConfiguration ccfg = super.cacheConfiguration(gridName);
+
+        ccfg.setCopyOnRead(false);
+
+        CacheTypeMetadata meta = new CacheTypeMetadata();
+
+        meta.setKeyType(Integer.class);
+        meta.setValueType(TestPortable.class.getName());
+
+        Map<String, Class<?>> idx = new HashMap<>();
+
+        idx.put("fieldOne", String.class);
+        idx.put("fieldTwo", Integer.class);
+
+        meta.setAscendingFields(idx);
+
+        ccfg.setTypeMetadata(Collections.singletonList(meta));
+
+        return ccfg;
+    }
+
+    /** {@inheritDoc} */
+    @Override public abstract CacheAtomicityMode atomicityMode();
+
+    /** {@inheritDoc} */
+    @Override public abstract CacheMode cacheMode();
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testIndexReferences() throws Exception {
+        IgniteCache<Integer, TestPortable> cache = grid(0).cache(null);
+
+        String fieldOneVal = "123";
+        int fieldTwoVal = 123;
+        int key = 0;
+
+        cache.put(key, new TestPortable(fieldOneVal, fieldTwoVal));
+
+        IgniteCache<Integer, BinaryObject> prj = grid(0).cache(null).withKeepBinary();
+
+        BinaryObject cacheVal = prj.get(key);
+
+        assertEquals(fieldOneVal, cacheVal.field("fieldOne"));
+        assertEquals(new Integer(fieldTwoVal), cacheVal.field("fieldTwo"));
+
+        List<?> row = F.first(prj.query(new SqlFieldsQuery("select _val from " +
+            "TestPortable where _key = ?").setArgs(key)).getAll());
+
+        assertEquals(1, row.size());
+
+        BinaryObject qryVal = (BinaryObject)row.get(0);
+
+        assertEquals(fieldOneVal, qryVal.field("fieldOne"));
+        assertEquals(new Integer(fieldTwoVal), qryVal.field("fieldTwo"));
+        assertSame(cacheVal, qryVal);
+    }
+
+    /**
+     * Test portable object.
+     */
+    private static class TestPortable {
+        /** */
+        private String fieldOne;
+
+        /** */
+        private int fieldTwo;
+
+        /**
+         *
+         */
+        private TestPortable() {
+            // No-op.
+        }
+
+        /**
+         * @param fieldOne Field one.
+         * @param fieldTwo Field two.
+         */
+        private TestPortable(String fieldOne, int fieldTwo) {
+            this.fieldOne = fieldOne;
+            this.fieldTwo = fieldTwo;
+        }
+
+        /**
+         * @return Field one.
+         */
+        public String fieldOne() {
+            return fieldOne;
+        }
+
+        /**
+         * @return Field two.
+         */
+        public int fieldTwo() {
+            return fieldTwo;
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/71ad9cea/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/binary/GridCacheBinaryStoreAbstractSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/binary/GridCacheBinaryStoreAbstractSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/binary/GridCacheBinaryStoreAbstractSelfTest.java
new file mode 100644
index 0000000..058dc0b
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/binary/GridCacheBinaryStoreAbstractSelfTest.java
@@ -0,0 +1,300 @@
+/*
+ * 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.processors.cache.binary;
+
+import com.google.common.collect.ImmutableSet;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+import javax.cache.Cache;
+import org.apache.ignite.cache.store.CacheStoreAdapter;
+import org.apache.ignite.configuration.BinaryConfiguration;
+import org.apache.ignite.configuration.CacheConfiguration;
+import org.apache.ignite.configuration.IgniteConfiguration;
+import org.apache.ignite.internal.binary.BinaryMarshaller;
+import org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi;
+import org.apache.ignite.spi.discovery.tcp.ipfinder.TcpDiscoveryIpFinder;
+import org.apache.ignite.spi.discovery.tcp.ipfinder.vm.TcpDiscoveryVmIpFinder;
+import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
+import org.jetbrains.annotations.Nullable;
+import org.jsr166.ConcurrentHashMap8;
+
+/**
+ * Tests for cache store with binary.
+ */
+public abstract class GridCacheBinaryStoreAbstractSelfTest extends GridCommonAbstractTest {
+    /** */
+    private static final TcpDiscoveryIpFinder IP_FINDER = new TcpDiscoveryVmIpFinder(true);
+
+    /** */
+    private static final TestStore STORE = new TestStore();
+
+    /** {@inheritDoc} */
+    @SuppressWarnings("unchecked")
+    @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception {
+        IgniteConfiguration cfg = super.getConfiguration(gridName);
+
+        BinaryConfiguration bCfg = new BinaryConfiguration();
+
+        bCfg.setClassNames(Arrays.asList(Key.class.getName(), Value.class.getName()));
+
+        cfg.setBinaryConfiguration(bCfg);
+
+        cfg.setMarshaller(new BinaryMarshaller());
+
+        CacheConfiguration cacheCfg = new CacheConfiguration();
+
+        cacheCfg.setCacheStoreFactory(singletonFactory(STORE));
+        cacheCfg.setKeepBinaryInStore(keepPortableInStore());
+        cacheCfg.setReadThrough(true);
+        cacheCfg.setWriteThrough(true);
+        cacheCfg.setLoadPreviousValue(true);
+
+        cfg.setCacheConfiguration(cacheCfg);
+
+        TcpDiscoverySpi disco = new TcpDiscoverySpi();
+
+        disco.setIpFinder(IP_FINDER);
+
+        cfg.setDiscoverySpi(disco);
+
+        return cfg;
+    }
+
+    /**
+     * @return Keep binary in store flag.
+     */
+    protected abstract boolean keepPortableInStore();
+
+    /** {@inheritDoc} */
+    @Override protected void beforeTestsStarted() throws Exception {
+        startGrid();
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void afterTestsStopped() throws Exception {
+        stopGrid();
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void beforeTest() throws Exception {
+        STORE.map().clear();
+
+        jcache().clear();
+
+        assert jcache().size() == 0;
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testPut() throws Exception {
+        jcache().put(new Key(1), new Value(1));
+
+        checkMap(STORE.map(), 1);
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testPutAll() throws Exception {
+        Map<Object, Object> map = new HashMap<>();
+
+        for (int i = 1; i <= 3; i++)
+            map.put(new Key(i), new Value(i));
+
+        jcache().putAll(map);
+
+        checkMap(STORE.map(), 1, 2, 3);
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testLoad() throws Exception {
+        populateMap(STORE.map(), 1);
+
+        Object val = jcache().get(new Key(1));
+
+        assertTrue(String.valueOf(val), val instanceof Value);
+
+        assertEquals(1, ((Value)val).index());
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testLoadAll() throws Exception {
+        populateMap(STORE.map(), 1, 2, 3);
+
+        Set<Object> keys = new HashSet<>();
+
+        for (int i = 1; i <= 3; i++)
+            keys.add(new Key(i));
+
+        Map<Object, Object> res = jcache().getAll(keys);
+
+        assertEquals(3, res.size());
+
+        for (int i = 1; i <= 3; i++) {
+            Object val = res.get(new Key(i));
+
+            assertTrue(String.valueOf(val), val instanceof Value);
+
+            assertEquals(i, ((Value)val).index());
+        }
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testRemove() throws Exception {
+        for (int i = 1; i <= 3; i++)
+            jcache().put(new Key(i), new Value(i));
+
+        jcache().remove(new Key(1));
+
+        checkMap(STORE.map(), 2, 3);
+    }
+
+    /**
+     * @throws Exception If failed.
+     */
+    public void testRemoveAll() throws Exception {
+        for (int i = 1; i <= 3; i++)
+            jcache().put(new Key(i), new Value(i));
+
+        jcache().removeAll(ImmutableSet.of(new Key(1), new Key(2)));
+
+        checkMap(STORE.map(), 3);
+    }
+
+    /**
+     * @param map Map.
+     * @param idxs Indexes.
+     */
+    protected abstract void populateMap(Map<Object, Object> map, int... idxs);
+
+    /**
+     * @param map Map.
+     * @param idxs Indexes.
+     */
+    protected abstract void checkMap(Map<Object, Object> map, int... idxs);
+
+    /**
+     */
+    protected static class Key {
+        /** */
+        private int idx;
+
+        /**
+         * @param idx Index.
+         */
+        public Key(int idx) {
+            this.idx = idx;
+        }
+
+        /**
+         * @return Index.
+         */
+        int index() {
+            return idx;
+        }
+
+        /** {@inheritDoc} */
+        @Override public boolean equals(Object o) {
+            if (this == o)
+                return true;
+
+            if (o == null || getClass() != o.getClass())
+                return false;
+
+            Key key = (Key)o;
+
+            return idx == key.idx;
+        }
+
+        /** {@inheritDoc} */
+        @Override public int hashCode() {
+            return idx;
+        }
+
+        /** {@inheritDoc} */
+        @Override public String toString() {
+            return "Key [idx=" + idx + ']';
+        }
+    }
+
+    /**
+     */
+    protected static class Value {
+        /** */
+        private int idx;
+
+        /**
+         * @param idx Index.
+         */
+        public Value(int idx) {
+            this.idx = idx;
+        }
+
+        /**
+         * @return Index.
+         */
+        int index() {
+            return idx;
+        }
+
+        /** {@inheritDoc} */
+        @Override public String toString() {
+            return "Value [idx=" + idx + ']';
+        }
+    }
+
+    /**
+     *
+     */
+    private static class TestStore extends CacheStoreAdapter<Object, Object> {
+        /** */
+        private final Map<Object, Object> map = new ConcurrentHashMap8<>();
+
+        /** {@inheritDoc} */
+        @Nullable @Override public Object load(Object key) {
+            return map.get(key);
+        }
+
+        /** {@inheritDoc} */
+        @Override public void write(Cache.Entry<?, ?> e) {
+            map.put(e.getKey(), e.getValue());
+        }
+
+        /** {@inheritDoc} */
+        @Override public void delete(Object key) {
+            map.remove(key);
+        }
+
+        /**
+         * @return Map.
+         */
+        Map<Object, Object> map() {
+            return map;
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/71ad9cea/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/binary/GridCacheBinaryStoreObjectsSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/binary/GridCacheBinaryStoreObjectsSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/binary/GridCacheBinaryStoreObjectsSelfTest.java
new file mode 100644
index 0000000..a4d08ec
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/binary/GridCacheBinaryStoreObjectsSelfTest.java
@@ -0,0 +1,55 @@
+/*
+ * 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.processors.cache.binary;
+
+import java.util.Map;
+
+/**
+ * Tests for cache store with binary.
+ */
+public class GridCacheBinaryStoreObjectsSelfTest extends GridCacheBinaryStoreAbstractSelfTest {
+    /** {@inheritDoc} */
+    @Override protected boolean keepPortableInStore() {
+        return false;
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void populateMap(Map<Object, Object> map, int... idxs) {
+        assert map != null;
+        assert idxs != null;
+
+        for (int idx : idxs)
+            map.put(new Key(idx), new Value(idx));
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void checkMap(Map<Object, Object> map, int... idxs) {
+        assert map != null;
+        assert idxs != null;
+
+        assertEquals(idxs.length, map.size());
+
+        for (int idx : idxs) {
+            Object val = map.get(new Key(idx));
+
+            assertTrue(String.valueOf(val), val instanceof Value);
+
+            assertEquals(idx, ((Value)val).index());
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/71ad9cea/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/binary/GridCacheBinaryStorePortablesSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/binary/GridCacheBinaryStorePortablesSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/binary/GridCacheBinaryStorePortablesSelfTest.java
new file mode 100644
index 0000000..db15f08
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/binary/GridCacheBinaryStorePortablesSelfTest.java
@@ -0,0 +1,66 @@
+/*
+ * 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.processors.cache.binary;
+
+import java.util.Map;
+import org.apache.ignite.binary.BinaryObject;
+
+/**
+ * Tests for cache store with binary.
+ */
+public class GridCacheBinaryStorePortablesSelfTest extends GridCacheBinaryStoreAbstractSelfTest {
+    /** {@inheritDoc} */
+    @Override protected boolean keepPortableInStore() {
+        return true;
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void populateMap(Map<Object, Object> map, int... idxs) {
+        assert map != null;
+        assert idxs != null;
+
+        for (int idx : idxs)
+            map.put(portable(new Key(idx)), portable(new Value(idx)));
+    }
+
+    /** {@inheritDoc} */
+    @Override protected void checkMap(Map<Object, Object> map, int... idxs) {
+        assert map != null;
+        assert idxs != null;
+
+        assertEquals(idxs.length, map.size());
+
+        for (int idx : idxs) {
+            Object val = map.get(portable(new Key(idx)));
+
+            assertTrue(String.valueOf(val), val instanceof BinaryObject);
+
+            BinaryObject po = (BinaryObject)val;
+
+            assertEquals("Value", po.type().typeName());
+            assertEquals(new Integer(idx), po.field("idx"));
+        }
+    }
+
+    /**
+     * @param obj Object.
+     * @return Portable object.
+     */
+    private Object portable(Object obj) {
+        return grid().binary().toBinary(obj);
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/71ad9cea/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/binary/GridCachePortableStoreAbstractSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/binary/GridCachePortableStoreAbstractSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/binary/GridCachePortableStoreAbstractSelfTest.java
deleted file mode 100644
index b9d7b5d..0000000
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/binary/GridCachePortableStoreAbstractSelfTest.java
+++ /dev/null
@@ -1,300 +0,0 @@
-/*
- * 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.processors.cache.binary;
-
-import com.google.common.collect.ImmutableSet;
-import java.util.Arrays;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Map;
-import java.util.Set;
-import javax.cache.Cache;
-import org.apache.ignite.cache.store.CacheStoreAdapter;
-import org.apache.ignite.configuration.BinaryConfiguration;
-import org.apache.ignite.configuration.CacheConfiguration;
-import org.apache.ignite.configuration.IgniteConfiguration;
-import org.apache.ignite.internal.binary.BinaryMarshaller;
-import org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi;
-import org.apache.ignite.spi.discovery.tcp.ipfinder.TcpDiscoveryIpFinder;
-import org.apache.ignite.spi.discovery.tcp.ipfinder.vm.TcpDiscoveryVmIpFinder;
-import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
-import org.jetbrains.annotations.Nullable;
-import org.jsr166.ConcurrentHashMap8;
-
-/**
- * Tests for cache store with binary.
- */
-public abstract class GridCachePortableStoreAbstractSelfTest extends GridCommonAbstractTest {
-    /** */
-    private static final TcpDiscoveryIpFinder IP_FINDER = new TcpDiscoveryVmIpFinder(true);
-
-    /** */
-    private static final TestStore STORE = new TestStore();
-
-    /** {@inheritDoc} */
-    @SuppressWarnings("unchecked")
-    @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception {
-        IgniteConfiguration cfg = super.getConfiguration(gridName);
-
-        BinaryConfiguration bCfg = new BinaryConfiguration();
-
-        bCfg.setClassNames(Arrays.asList(Key.class.getName(), Value.class.getName()));
-
-        cfg.setBinaryConfiguration(bCfg);
-
-        cfg.setMarshaller(new BinaryMarshaller());
-
-        CacheConfiguration cacheCfg = new CacheConfiguration();
-
-        cacheCfg.setCacheStoreFactory(singletonFactory(STORE));
-        cacheCfg.setKeepBinaryInStore(keepPortableInStore());
-        cacheCfg.setReadThrough(true);
-        cacheCfg.setWriteThrough(true);
-        cacheCfg.setLoadPreviousValue(true);
-
-        cfg.setCacheConfiguration(cacheCfg);
-
-        TcpDiscoverySpi disco = new TcpDiscoverySpi();
-
-        disco.setIpFinder(IP_FINDER);
-
-        cfg.setDiscoverySpi(disco);
-
-        return cfg;
-    }
-
-    /**
-     * @return Keep binary in store flag.
-     */
-    protected abstract boolean keepPortableInStore();
-
-    /** {@inheritDoc} */
-    @Override protected void beforeTestsStarted() throws Exception {
-        startGrid();
-    }
-
-    /** {@inheritDoc} */
-    @Override protected void afterTestsStopped() throws Exception {
-        stopGrid();
-    }
-
-    /** {@inheritDoc} */
-    @Override protected void beforeTest() throws Exception {
-        STORE.map().clear();
-
-        jcache().clear();
-
-        assert jcache().size() == 0;
-    }
-
-    /**
-     * @throws Exception If failed.
-     */
-    public void testPut() throws Exception {
-        jcache().put(new Key(1), new Value(1));
-
-        checkMap(STORE.map(), 1);
-    }
-
-    /**
-     * @throws Exception If failed.
-     */
-    public void testPutAll() throws Exception {
-        Map<Object, Object> map = new HashMap<>();
-
-        for (int i = 1; i <= 3; i++)
-            map.put(new Key(i), new Value(i));
-
-        jcache().putAll(map);
-
-        checkMap(STORE.map(), 1, 2, 3);
-    }
-
-    /**
-     * @throws Exception If failed.
-     */
-    public void testLoad() throws Exception {
-        populateMap(STORE.map(), 1);
-
-        Object val = jcache().get(new Key(1));
-
-        assertTrue(String.valueOf(val), val instanceof Value);
-
-        assertEquals(1, ((Value)val).index());
-    }
-
-    /**
-     * @throws Exception If failed.
-     */
-    public void testLoadAll() throws Exception {
-        populateMap(STORE.map(), 1, 2, 3);
-
-        Set<Object> keys = new HashSet<>();
-
-        for (int i = 1; i <= 3; i++)
-            keys.add(new Key(i));
-
-        Map<Object, Object> res = jcache().getAll(keys);
-
-        assertEquals(3, res.size());
-
-        for (int i = 1; i <= 3; i++) {
-            Object val = res.get(new Key(i));
-
-            assertTrue(String.valueOf(val), val instanceof Value);
-
-            assertEquals(i, ((Value)val).index());
-        }
-    }
-
-    /**
-     * @throws Exception If failed.
-     */
-    public void testRemove() throws Exception {
-        for (int i = 1; i <= 3; i++)
-            jcache().put(new Key(i), new Value(i));
-
-        jcache().remove(new Key(1));
-
-        checkMap(STORE.map(), 2, 3);
-    }
-
-    /**
-     * @throws Exception If failed.
-     */
-    public void testRemoveAll() throws Exception {
-        for (int i = 1; i <= 3; i++)
-            jcache().put(new Key(i), new Value(i));
-
-        jcache().removeAll(ImmutableSet.of(new Key(1), new Key(2)));
-
-        checkMap(STORE.map(), 3);
-    }
-
-    /**
-     * @param map Map.
-     * @param idxs Indexes.
-     */
-    protected abstract void populateMap(Map<Object, Object> map, int... idxs);
-
-    /**
-     * @param map Map.
-     * @param idxs Indexes.
-     */
-    protected abstract void checkMap(Map<Object, Object> map, int... idxs);
-
-    /**
-     */
-    protected static class Key {
-        /** */
-        private int idx;
-
-        /**
-         * @param idx Index.
-         */
-        public Key(int idx) {
-            this.idx = idx;
-        }
-
-        /**
-         * @return Index.
-         */
-        int index() {
-            return idx;
-        }
-
-        /** {@inheritDoc} */
-        @Override public boolean equals(Object o) {
-            if (this == o)
-                return true;
-
-            if (o == null || getClass() != o.getClass())
-                return false;
-
-            Key key = (Key)o;
-
-            return idx == key.idx;
-        }
-
-        /** {@inheritDoc} */
-        @Override public int hashCode() {
-            return idx;
-        }
-
-        /** {@inheritDoc} */
-        @Override public String toString() {
-            return "Key [idx=" + idx + ']';
-        }
-    }
-
-    /**
-     */
-    protected static class Value {
-        /** */
-        private int idx;
-
-        /**
-         * @param idx Index.
-         */
-        public Value(int idx) {
-            this.idx = idx;
-        }
-
-        /**
-         * @return Index.
-         */
-        int index() {
-            return idx;
-        }
-
-        /** {@inheritDoc} */
-        @Override public String toString() {
-            return "Value [idx=" + idx + ']';
-        }
-    }
-
-    /**
-     *
-     */
-    private static class TestStore extends CacheStoreAdapter<Object, Object> {
-        /** */
-        private final Map<Object, Object> map = new ConcurrentHashMap8<>();
-
-        /** {@inheritDoc} */
-        @Nullable @Override public Object load(Object key) {
-            return map.get(key);
-        }
-
-        /** {@inheritDoc} */
-        @Override public void write(Cache.Entry<?, ?> e) {
-            map.put(e.getKey(), e.getValue());
-        }
-
-        /** {@inheritDoc} */
-        @Override public void delete(Object key) {
-            map.remove(key);
-        }
-
-        /**
-         * @return Map.
-         */
-        Map<Object, Object> map() {
-            return map;
-        }
-    }
-}

http://git-wip-us.apache.org/repos/asf/ignite/blob/71ad9cea/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/binary/GridCachePortableStoreObjectsSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/binary/GridCachePortableStoreObjectsSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/binary/GridCachePortableStoreObjectsSelfTest.java
deleted file mode 100644
index 00d1ae4..0000000
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/binary/GridCachePortableStoreObjectsSelfTest.java
+++ /dev/null
@@ -1,55 +0,0 @@
-/*
- * 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.processors.cache.binary;
-
-import java.util.Map;
-
-/**
- * Tests for cache store with binary.
- */
-public class GridCachePortableStoreObjectsSelfTest extends GridCachePortableStoreAbstractSelfTest {
-    /** {@inheritDoc} */
-    @Override protected boolean keepPortableInStore() {
-        return false;
-    }
-
-    /** {@inheritDoc} */
-    @Override protected void populateMap(Map<Object, Object> map, int... idxs) {
-        assert map != null;
-        assert idxs != null;
-
-        for (int idx : idxs)
-            map.put(new Key(idx), new Value(idx));
-    }
-
-    /** {@inheritDoc} */
-    @Override protected void checkMap(Map<Object, Object> map, int... idxs) {
-        assert map != null;
-        assert idxs != null;
-
-        assertEquals(idxs.length, map.size());
-
-        for (int idx : idxs) {
-            Object val = map.get(new Key(idx));
-
-            assertTrue(String.valueOf(val), val instanceof Value);
-
-            assertEquals(idx, ((Value)val).index());
-        }
-    }
-}


[29/59] [abbrv] ignite git commit: ignite-2065: rename "portable" packages to "binary"

Posted by ak...@apache.org.
http://git-wip-us.apache.org/repos/asf/ignite/blob/1dbf20e0/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryReaderExImpl.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryReaderExImpl.java b/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryReaderExImpl.java
new file mode 100644
index 0000000..bf47d53
--- /dev/null
+++ b/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryReaderExImpl.java
@@ -0,0 +1,2028 @@
+/*
+ * 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.binary;
+
+import java.io.EOFException;
+import java.io.IOException;
+import java.io.ObjectInput;
+import java.math.BigDecimal;
+import java.sql.Timestamp;
+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;
+import org.apache.ignite.binary.BinaryReader;
+import org.apache.ignite.internal.binary.streams.PortableInputStream;
+import org.apache.ignite.internal.util.typedef.internal.SB;
+import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.Nullable;
+
+import static org.apache.ignite.internal.binary.GridPortableMarshaller.BOOLEAN;
+import static org.apache.ignite.internal.binary.GridPortableMarshaller.BOOLEAN_ARR;
+import static org.apache.ignite.internal.binary.GridPortableMarshaller.BYTE;
+import static org.apache.ignite.internal.binary.GridPortableMarshaller.BYTE_ARR;
+import static org.apache.ignite.internal.binary.GridPortableMarshaller.CHAR;
+import static org.apache.ignite.internal.binary.GridPortableMarshaller.CHAR_ARR;
+import static org.apache.ignite.internal.binary.GridPortableMarshaller.CLASS;
+import static org.apache.ignite.internal.binary.GridPortableMarshaller.COL;
+import static org.apache.ignite.internal.binary.GridPortableMarshaller.DATE;
+import static org.apache.ignite.internal.binary.GridPortableMarshaller.DATE_ARR;
+import static org.apache.ignite.internal.binary.GridPortableMarshaller.DECIMAL;
+import static org.apache.ignite.internal.binary.GridPortableMarshaller.DECIMAL_ARR;
+import static org.apache.ignite.internal.binary.GridPortableMarshaller.DFLT_HDR_LEN;
+import static org.apache.ignite.internal.binary.GridPortableMarshaller.DOUBLE;
+import static org.apache.ignite.internal.binary.GridPortableMarshaller.DOUBLE_ARR;
+import static org.apache.ignite.internal.binary.GridPortableMarshaller.ENUM;
+import static org.apache.ignite.internal.binary.GridPortableMarshaller.ENUM_ARR;
+import static org.apache.ignite.internal.binary.GridPortableMarshaller.FLOAT;
+import static org.apache.ignite.internal.binary.GridPortableMarshaller.FLOAT_ARR;
+import static org.apache.ignite.internal.binary.GridPortableMarshaller.HANDLE;
+import static org.apache.ignite.internal.binary.GridPortableMarshaller.INT;
+import static org.apache.ignite.internal.binary.GridPortableMarshaller.INT_ARR;
+import static org.apache.ignite.internal.binary.GridPortableMarshaller.LONG;
+import static org.apache.ignite.internal.binary.GridPortableMarshaller.LONG_ARR;
+import static org.apache.ignite.internal.binary.GridPortableMarshaller.MAP;
+import static org.apache.ignite.internal.binary.GridPortableMarshaller.NULL;
+import static org.apache.ignite.internal.binary.GridPortableMarshaller.OBJ;
+import static org.apache.ignite.internal.binary.GridPortableMarshaller.OBJ_ARR;
+import static org.apache.ignite.internal.binary.GridPortableMarshaller.OPTM_MARSH;
+import static org.apache.ignite.internal.binary.GridPortableMarshaller.PORTABLE_OBJ;
+import static org.apache.ignite.internal.binary.GridPortableMarshaller.SHORT;
+import static org.apache.ignite.internal.binary.GridPortableMarshaller.SHORT_ARR;
+import static org.apache.ignite.internal.binary.GridPortableMarshaller.STRING;
+import static org.apache.ignite.internal.binary.GridPortableMarshaller.STRING_ARR;
+import static org.apache.ignite.internal.binary.GridPortableMarshaller.TIMESTAMP;
+import static org.apache.ignite.internal.binary.GridPortableMarshaller.TIMESTAMP_ARR;
+import static org.apache.ignite.internal.binary.GridPortableMarshaller.UNREGISTERED_TYPE_ID;
+import static org.apache.ignite.internal.binary.GridPortableMarshaller.UUID;
+import static org.apache.ignite.internal.binary.GridPortableMarshaller.UUID_ARR;
+
+/**
+ * Portable reader implementation.
+ */
+@SuppressWarnings("unchecked")
+public class BinaryReaderExImpl implements BinaryReader, BinaryRawReaderEx, BinaryReaderHandlesHolder, ObjectInput {
+    /** Portable context. */
+    private final PortableContext ctx;
+
+    /** Input stream. */
+    private final PortableInputStream in;
+
+    /** Class loaded. */
+    private final ClassLoader ldr;
+
+    /** Reader context which is constantly passed between objects. */
+    private BinaryReaderHandles hnds;
+
+    /** */
+    private final int start;
+
+    /** Start of actual data. Positioned right after the header. */
+    private final int dataStart;
+
+    /** Type ID. */
+    private final int typeId;
+
+    /** Raw offset. */
+    private final int rawOff;
+
+    /** Footer start. */
+    private final int footerStart;
+
+    /** Footer end. */
+    private final int footerLen;
+
+    /** ID mapper. */
+    private final BinaryIdMapper idMapper;
+
+    /** Schema Id. */
+    private final int schemaId;
+
+    /** Whether this is user type or not. */
+    private final boolean userType;
+
+    /** Whether field IDs exist. */
+    private final int fieldIdLen;
+
+    /** Offset size in bytes. */
+    private final int fieldOffsetLen;
+
+    /** Object schema. */
+    private final PortableSchema schema;
+
+    /** Whether passed IDs matches schema order. Reset to false as soon as a single mismatch detected. */
+    private boolean matching = true;
+
+    /** Order of a field whose match is expected. */
+    private int matchingOrder;
+
+    /** Whether stream is in raw mode. */
+    private boolean raw;
+
+    /**
+     * Constructor.
+     *
+     * @param ctx Context.
+     * @param in Input stream.
+     * @param ldr Class loader.
+     */
+    public BinaryReaderExImpl(PortableContext ctx, PortableInputStream in, ClassLoader ldr) {
+        this(ctx, in, ldr, null);
+    }
+
+    /**
+     * Constructor.
+     *
+     * @param ctx Context.
+     * @param in Input stream.
+     * @param ldr Class loader.
+     * @param hnds Context.
+     */
+    public BinaryReaderExImpl(PortableContext ctx, PortableInputStream in, ClassLoader ldr,
+        @Nullable BinaryReaderHandles hnds) {
+        this(ctx, in, ldr, hnds, false);
+    }
+
+    /**
+     * Constructor.
+     *
+     * @param ctx Context.
+     * @param in Input stream.
+     * @param ldr Class loader.
+     * @param hnds Context.
+     * @param skipHdrCheck Whether to skip header check.
+     */
+    public BinaryReaderExImpl(PortableContext ctx, PortableInputStream in, ClassLoader ldr,
+        @Nullable BinaryReaderHandles hnds, boolean skipHdrCheck) {
+        // Initialize base members.
+        this.ctx = ctx;
+        this.in = in;
+        this.ldr = ldr;
+        this.hnds = hnds;
+
+        start = in.position();
+
+        // Perform full header parsing in case of portable object.
+        if (!skipHdrCheck && (in.readByte() == GridPortableMarshaller.OBJ)) {
+            // Ensure protocol is fine.
+            PortableUtils.checkProtocolVersion(in.readByte());
+
+            // Read header content.
+            short flags = in.readShort();
+            int typeId0 = in.readInt();
+
+            in.readInt(); // Skip hash code.
+
+            int len = in.readInt();
+            schemaId = in.readInt();
+            int offset = in.readInt();
+
+            // Get trivial flag values.
+            userType = PortableUtils.isUserType(flags);
+            fieldIdLen = PortableUtils.fieldIdLength(flags);
+            fieldOffsetLen = PortableUtils.fieldOffsetLength(flags);
+
+            // Calculate footer borders and raw offset.
+            if (PortableUtils.hasSchema(flags)) {
+                // Schema exists.
+                footerStart = start + offset;
+
+                if (PortableUtils.hasRaw(flags)) {
+                    footerLen = len - offset - 4;
+                    rawOff = start + in.readIntPositioned(start + len - 4);
+                }
+                else {
+                    footerLen = len - offset;
+                    rawOff = start + len;
+                }
+            }
+            else {
+                // No schema.
+                footerStart = start + len;
+                footerLen = 0;
+
+                if (PortableUtils.hasRaw(flags))
+                    rawOff = start + offset;
+                else
+                    rawOff = start + len;
+            }
+
+            // Finally, we have to resolve real type ID.
+            if (typeId0 == UNREGISTERED_TYPE_ID) {
+                int off = in.position();
+
+                // Registers class by type ID, at least locally if the cache is not ready yet.
+                typeId = ctx.descriptorForClass(PortableUtils.doReadClass(in, ctx, ldr, typeId0), false).typeId();
+
+                int clsNameLen = in.position() - off;
+
+                dataStart = start + DFLT_HDR_LEN + clsNameLen;
+            }
+            else {
+                typeId = typeId0;
+
+                dataStart = start + DFLT_HDR_LEN;
+            }
+
+            idMapper = userType ? ctx.userTypeIdMapper(typeId) : BinaryInternalIdMapper.defaultInstance();
+            schema = PortableUtils.hasSchema(flags) ? getOrCreateSchema() : null;
+        }
+        else {
+            dataStart = 0;
+            typeId = 0;
+            rawOff = 0;
+            footerStart = 0;
+            footerLen = 0;
+            idMapper = null;
+            schemaId = 0;
+            userType = false;
+            fieldIdLen = 0;
+            fieldOffsetLen = 0;
+            schema = null;
+        }
+
+        streamPosition(start);
+    }
+
+    /**
+     * @return Input stream.
+     */
+    public PortableInputStream in() {
+        return in;
+    }
+
+    /**
+     * @return Descriptor.
+     */
+    PortableClassDescriptor descriptor() {
+        return ctx.descriptorForTypeId(userType, typeId, ldr, true);
+    }
+
+    /**
+     * @param offset Offset in the array.
+     * @return Unmarshalled value.
+     * @throws BinaryObjectException In case of error.
+     */
+    public Object unmarshal(int offset) throws BinaryObjectException {
+        streamPosition(offset);
+
+        return in.position() >= 0 ? PortableUtils.unmarshal(in, ctx, ldr, this) : null;
+    }
+
+    /**
+     * @param fieldName Field name.
+     * @return Unmarshalled value.
+     * @throws BinaryObjectException In case of error.
+     */
+    @Nullable Object unmarshalField(String fieldName) throws BinaryObjectException {
+        return findFieldByName(fieldName) ? PortableUtils.unmarshal(in, ctx, ldr, this) : null;
+    }
+
+    /**
+     * @param fieldId Field ID.
+     * @return Unmarshalled value.
+     * @throws BinaryObjectException In case of error.
+     */
+    @Nullable Object unmarshalField(int fieldId) throws BinaryObjectException {
+        return findFieldById(fieldId) ? PortableUtils.unmarshal(in, ctx, ldr, this) : null;
+    }
+
+    /**
+     * @param fieldId Field ID.
+     * @return Portable object.
+     * @throws BinaryObjectException In case of error.
+     */
+    @Nullable BinaryObject readPortableObject(int fieldId) throws BinaryObjectException {
+        if (findFieldById(fieldId)) {
+            if (checkFlag(PORTABLE_OBJ) == Flag.NULL)
+                return null;
+
+            return new BinaryObjectImpl(ctx, PortableUtils.doReadByteArray(in), in.readInt());
+        }
+        else
+            return null;
+    }
+
+    /**
+     * @param fieldId Field ID.
+     * @return Field class.
+     * @throws BinaryObjectException In case of error.
+     */
+    @Nullable Class<?> readClass(int fieldId) throws BinaryObjectException {
+        if (findFieldById(fieldId)) {
+            if (checkFlag(CLASS) == Flag.NULL)
+                return null;
+
+            return PortableUtils.doReadClass(in, ctx, ldr);
+        }
+
+        return null;
+    }
+
+    /**
+     * @param obj Object.
+     */
+    void setHandle(Object obj) {
+        setHandle(obj, start);
+    }
+
+    /** {@inheritDoc} */
+    @Override public void setHandle(Object obj, int pos) {
+        handles().put(pos, obj);
+    }
+
+    /** {@inheritDoc} */
+    @Override public Object getHandle(int pos) {
+        return hnds != null ? hnds.get(pos) : null;
+    }
+
+    /** {@inheritDoc} */
+    @Override public BinaryReaderHandles handles() {
+        if (hnds == null)
+            hnds = new BinaryReaderHandles();
+
+        return hnds;
+    }
+
+    /**
+     * Recreating field value from a handle.
+     *
+     * @param <T> Field type.
+     * @return Field.
+     */
+    private <T> T readHandleField() {
+        int handlePos = PortableUtils.positionForHandle(in) - in.readInt();
+
+        Object obj = getHandle(handlePos);
+
+        if (obj == null) {
+            int retPos = in.position();
+
+            streamPosition(handlePos);
+
+            obj = PortableUtils.doReadObject(in, ctx, ldr, this);
+
+            streamPosition(retPos);
+        }
+
+        return (T)obj;
+    }
+    /** {@inheritDoc} */
+    @Override public byte readByte(String fieldName) throws BinaryObjectException {
+        return findFieldByName(fieldName) && checkFlagNoHandles(BYTE) == Flag.NORMAL ? in.readByte() : 0;
+    }
+
+    /**
+     * @param fieldId Field ID.
+     * @return Value.
+     * @throws BinaryObjectException If failed.
+     */
+    byte readByte(int fieldId) throws BinaryObjectException {
+        return findFieldById(fieldId) && checkFlagNoHandles(BYTE) == Flag.NORMAL ? in.readByte() : 0;
+    }
+
+    /**
+     * @param fieldId Field ID.
+     * @return Value.
+     * @throws BinaryObjectException In case of error.
+     */
+    @Nullable Byte readByteNullable(int fieldId) throws BinaryObjectException {
+        return findFieldById(fieldId) && checkFlagNoHandles(BYTE) == Flag.NORMAL ? in.readByte() : null;
+    }
+
+    /** {@inheritDoc} */
+    @Override public byte readByte() throws BinaryObjectException {
+        return in.readByte();
+    }
+
+    /** {@inheritDoc} */
+    @Nullable @Override public byte[] readByteArray(String fieldName) throws BinaryObjectException {
+        return findFieldByName(fieldName) ? this.readByteArray() : null;
+    }
+
+    /**
+     * @param fieldId Field ID.
+     * @return Value.
+     * @throws BinaryObjectException In case of error.
+     */
+    @Nullable byte[] readByteArray(int fieldId) throws BinaryObjectException {
+        return findFieldById(fieldId) ? this.readByteArray() : null;
+    }
+
+    /** {@inheritDoc} */
+    @Nullable @Override public byte[] readByteArray() throws BinaryObjectException {
+        switch (checkFlag(BYTE_ARR)) {
+            case NORMAL:
+                return PortableUtils.doReadByteArray(in);
+
+            case HANDLE:
+                return readHandleField();
+
+            default:
+                return null;
+        }
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean readBoolean(String fieldName) throws BinaryObjectException {
+        return findFieldByName(fieldName) && checkFlagNoHandles(BOOLEAN) == Flag.NORMAL && in.readBoolean();
+    }
+
+    /**
+     * @param fieldId Field ID.
+     * @return Value.
+     * @throws BinaryObjectException If failed.
+     */
+    boolean readBoolean(int fieldId) throws BinaryObjectException {
+        return findFieldById(fieldId) && checkFlagNoHandles(BOOLEAN) == Flag.NORMAL && in.readBoolean();
+    }
+
+    /**
+     * @param fieldId Field ID.
+     * @return Value.
+     * @throws BinaryObjectException In case of error.
+     */
+    @Nullable Boolean readBooleanNullable(int fieldId) throws BinaryObjectException {
+        return findFieldById(fieldId) && checkFlagNoHandles(BOOLEAN) == Flag.NORMAL ? in.readBoolean() : null;
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean readBoolean() throws BinaryObjectException {
+        return in.readBoolean();
+    }
+
+    /** {@inheritDoc} */
+    @Nullable @Override public boolean[] readBooleanArray(String fieldName) throws BinaryObjectException {
+        return findFieldByName(fieldName) ? this.readBooleanArray() : null;
+    }
+
+    /**
+     * @param fieldId Field ID.
+     * @return Value.
+     * @throws BinaryObjectException In case of error.
+     */
+    @Nullable boolean[] readBooleanArray(int fieldId) throws BinaryObjectException {
+        return findFieldById(fieldId) ? this.readBooleanArray() : null;
+    }
+
+    /** {@inheritDoc} */
+    @Nullable @Override public boolean[] readBooleanArray() throws BinaryObjectException {
+        switch (checkFlag(BOOLEAN_ARR)) {
+            case NORMAL:
+                return PortableUtils.doReadBooleanArray(in);
+
+            case HANDLE:
+                return readHandleField();
+
+            default:
+                return null;
+        }
+    }
+
+    /** {@inheritDoc} */
+    @Override public short readShort(String fieldName) throws BinaryObjectException {
+        return findFieldByName(fieldName) && checkFlagNoHandles(SHORT) == Flag.NORMAL ? in.readShort() : 0;
+    }
+
+    /**
+     * @param fieldId Field ID.
+     * @return Value.
+     * @throws BinaryObjectException If failed.
+     */
+    short readShort(int fieldId) throws BinaryObjectException {
+        return findFieldById(fieldId) && checkFlagNoHandles(SHORT) == Flag.NORMAL ? in.readShort() : 0;
+    }
+
+    /**
+     * @param fieldId Field ID.
+     * @return Value.
+     * @throws BinaryObjectException In case of error.
+     */
+    @Nullable Short readShortNullable(int fieldId) throws BinaryObjectException {
+        return findFieldById(fieldId) && checkFlagNoHandles(SHORT) == Flag.NORMAL ? in.readShort() : null;
+    }
+
+    /** {@inheritDoc} */
+    @Override public short readShort() throws BinaryObjectException {
+        return in.readShort();
+    }
+
+    /** {@inheritDoc} */
+    @Nullable @Override public short[] readShortArray(String fieldName) throws BinaryObjectException {
+        return findFieldByName(fieldName) ? this.readShortArray() : null;
+    }
+
+    /**
+     * @param fieldId Field ID.
+     * @return Value.
+     * @throws BinaryObjectException In case of error.
+     */
+    @Nullable short[] readShortArray(int fieldId) throws BinaryObjectException {
+        return findFieldById(fieldId) ? this.readShortArray() : null;
+    }
+
+    /** {@inheritDoc} */
+    @Nullable @Override public short[] readShortArray() throws BinaryObjectException {
+        switch (checkFlag(SHORT_ARR)) {
+            case NORMAL:
+                return PortableUtils.doReadShortArray(in);
+
+            case HANDLE:
+                return readHandleField();
+
+            default:
+                return null;
+        }
+    }
+
+    /** {@inheritDoc} */
+    @Override public char readChar(String fieldName) throws BinaryObjectException {
+        return findFieldByName(fieldName) && checkFlagNoHandles(CHAR) == Flag.NORMAL ? in.readChar() : 0;
+    }
+
+    /**
+     * @param fieldId Field ID.
+     * @return Value.
+     * @throws BinaryObjectException If failed.
+     */
+    char readChar(int fieldId) throws BinaryObjectException {
+        return findFieldById(fieldId) && checkFlagNoHandles(CHAR) == Flag.NORMAL ? in.readChar() : 0;
+    }
+
+    /**
+     * @param fieldId Field ID.
+     * @return Value.
+     * @throws BinaryObjectException In case of error.
+     */
+    @Nullable Character readCharNullable(int fieldId) throws BinaryObjectException {
+        return findFieldById(fieldId) && checkFlagNoHandles(CHAR) == Flag.NORMAL ? in.readChar() : null;
+    }
+
+    /** {@inheritDoc} */
+    @Override public char readChar() throws BinaryObjectException {
+        return in.readChar();
+    }
+
+    /** {@inheritDoc} */
+    @Nullable @Override public char[] readCharArray(String fieldName) throws BinaryObjectException {
+        return findFieldByName(fieldName) ? this.readCharArray() : null;
+    }
+
+    /**
+     * @param fieldId Field ID.
+     * @return Value.
+     * @throws BinaryObjectException In case of error.
+     */
+    @Nullable char[] readCharArray(int fieldId) throws BinaryObjectException {
+        return findFieldById(fieldId) ? this.readCharArray() : null;
+    }
+
+    /** {@inheritDoc} */
+    @Nullable @Override public char[] readCharArray() throws BinaryObjectException {
+        switch (checkFlag(CHAR_ARR)) {
+            case NORMAL:
+                return PortableUtils.doReadCharArray(in);
+
+            case HANDLE:
+                return readHandleField();
+
+            default:
+                return null;
+        }
+    }
+
+    /** {@inheritDoc} */
+    @Override public int readInt(String fieldName) throws BinaryObjectException {
+        return findFieldByName(fieldName) && checkFlagNoHandles(INT) == Flag.NORMAL ? in.readInt() : 0;
+    }
+
+    /**
+     * @param fieldId Field ID.
+     * @return Value.
+     * @throws BinaryObjectException If failed.
+     */
+    int readInt(int fieldId) throws BinaryObjectException {
+        return findFieldById(fieldId) && checkFlagNoHandles(INT) == Flag.NORMAL ? in.readInt() : 0;
+    }
+
+    /**
+     * @param fieldId Field ID.
+     * @return Value.
+     * @throws BinaryObjectException In case of error.
+     */
+    @Nullable Integer readIntNullable(int fieldId) throws BinaryObjectException {
+        return findFieldById(fieldId) && checkFlagNoHandles(INT) == Flag.NORMAL ? in.readInt() : null;
+    }
+
+    /** {@inheritDoc} */
+    @Override public int readInt() throws BinaryObjectException {
+        return in.readInt();
+    }
+
+    /** {@inheritDoc} */
+    @Nullable @Override public int[] readIntArray(String fieldName) throws BinaryObjectException {
+        return findFieldByName(fieldName) ? this.readIntArray() : null;
+    }
+
+    /**
+     * @param fieldId Field ID.
+     * @return Value.
+     * @throws BinaryObjectException In case of error.
+     */
+    @Nullable int[] readIntArray(int fieldId) throws BinaryObjectException {
+        return findFieldById(fieldId) ? this.readIntArray() : null;
+    }
+
+    /** {@inheritDoc} */
+    @Nullable @Override public int[] readIntArray() throws BinaryObjectException {
+        switch (checkFlag(INT_ARR)) {
+            case NORMAL:
+                return PortableUtils.doReadIntArray(in);
+
+            case HANDLE:
+                return readHandleField();
+
+            default:
+                return null;
+        }
+    }
+
+    /** {@inheritDoc} */
+    @Override public long readLong(String fieldName) throws BinaryObjectException {
+        return findFieldByName(fieldName) && checkFlagNoHandles(LONG) == Flag.NORMAL ? in.readLong() : 0;
+    }
+
+    /**
+     * @param fieldId Field ID.
+     * @return Value.
+     * @throws BinaryObjectException If failed.
+     */
+    long readLong(int fieldId) throws BinaryObjectException {
+        return findFieldById(fieldId) && checkFlagNoHandles(LONG) == Flag.NORMAL ? in.readLong() : 0;
+    }
+
+    /**
+     * @param fieldId Field ID.
+     * @return Value.
+     * @throws BinaryObjectException In case of error.
+     */
+    @Nullable Long readLongNullable(int fieldId) throws BinaryObjectException {
+        return findFieldById(fieldId) && checkFlagNoHandles(LONG) == Flag.NORMAL ? in.readLong() : null;
+    }
+
+    /** {@inheritDoc} */
+    @Override public long readLong() throws BinaryObjectException {
+        return in.readLong();
+    }
+
+    /** {@inheritDoc} */
+    @Nullable @Override public long[] readLongArray(String fieldName) throws BinaryObjectException {
+        return findFieldByName(fieldName) ? this.readLongArray() : null;
+    }
+
+    /**
+     * @param fieldId Field ID.
+     * @return Value.
+     * @throws BinaryObjectException In case of error.
+     */
+    @Nullable long[] readLongArray(int fieldId) throws BinaryObjectException {
+        return findFieldById(fieldId) ? this.readLongArray() : null;
+    }
+
+    /** {@inheritDoc} */
+    @Nullable @Override public long[] readLongArray() throws BinaryObjectException {
+        switch (checkFlag(LONG_ARR)) {
+            case NORMAL:
+                return PortableUtils.doReadLongArray(in);
+
+            case HANDLE:
+                return readHandleField();
+
+            default:
+                return null;
+        }
+    }
+
+    /** {@inheritDoc} */
+    @Override public float readFloat(String fieldName) throws BinaryObjectException {
+        return findFieldByName(fieldName) && checkFlagNoHandles(FLOAT) == Flag.NORMAL ? in.readFloat() : 0;
+    }
+
+    /**
+     * @param fieldId Field ID.
+     * @return Value.
+     * @throws BinaryObjectException If failed.
+     */
+    float readFloat(int fieldId) throws BinaryObjectException {
+        return findFieldById(fieldId) && checkFlagNoHandles(FLOAT) == Flag.NORMAL ? in.readFloat() : 0;
+    }
+
+    /**
+     * @param fieldId Field ID.
+     * @return Value.
+     * @throws BinaryObjectException In case of error.
+     */
+    @Nullable Float readFloatNullable(int fieldId) throws BinaryObjectException {
+        return findFieldById(fieldId) && checkFlagNoHandles(FLOAT) == Flag.NORMAL ? in.readFloat() : null;
+    }
+
+    /** {@inheritDoc} */
+    @Override public float readFloat() throws BinaryObjectException {
+        return in.readFloat();
+    }
+
+    /** {@inheritDoc} */
+    @Nullable @Override public float[] readFloatArray(String fieldName) throws BinaryObjectException {
+        return findFieldByName(fieldName) ? this.readFloatArray() : null;
+    }
+
+    /**
+     * @param fieldId Field ID.
+     * @return Value.
+     * @throws BinaryObjectException In case of error.
+     */
+    @Nullable float[] readFloatArray(int fieldId) throws BinaryObjectException {
+        return findFieldById(fieldId) ? this.readFloatArray() : null;
+    }
+
+    /** {@inheritDoc} */
+    @Nullable @Override public float[] readFloatArray() throws BinaryObjectException {
+        switch (checkFlag(FLOAT_ARR)) {
+            case NORMAL:
+                return PortableUtils.doReadFloatArray(in);
+
+            case HANDLE:
+                return readHandleField();
+
+            default:
+                return null;
+        }
+    }
+
+    /** {@inheritDoc} */
+    @Override public double readDouble(String fieldName) throws BinaryObjectException {
+        return findFieldByName(fieldName) && checkFlagNoHandles(DOUBLE) == Flag.NORMAL ? in.readDouble() : 0;
+    }
+
+    /**
+     * @param fieldId Field ID.
+     * @return Value.
+     * @throws BinaryObjectException If failed.
+     */
+    double readDouble(int fieldId) throws BinaryObjectException {
+        return findFieldById(fieldId) && checkFlagNoHandles(DOUBLE) == Flag.NORMAL ? in.readDouble() : 0;
+    }
+
+    /**
+     * @param fieldId Field ID.
+     * @return Value.
+     * @throws BinaryObjectException In case of error.
+     */
+    @Nullable Double readDoubleNullable(int fieldId) throws BinaryObjectException {
+        return findFieldById(fieldId) && checkFlagNoHandles(DOUBLE) == Flag.NORMAL ? in.readDouble() : null;
+    }
+
+    /** {@inheritDoc} */
+    @Override public double readDouble() throws BinaryObjectException {
+        return in.readDouble();
+    }
+
+    /** {@inheritDoc} */
+    @Nullable @Override public double[] readDoubleArray(String fieldName) throws BinaryObjectException {
+        return findFieldByName(fieldName) ? this.readDoubleArray() : null;
+    }
+
+    /**
+     * @param fieldId Field ID.
+     * @return Value.
+     * @throws BinaryObjectException In case of error.
+     */
+    @Nullable double[] readDoubleArray(int fieldId) throws BinaryObjectException {
+        return findFieldById(fieldId) ? this.readDoubleArray() : null;
+    }
+
+    /** {@inheritDoc} */
+    @Nullable @Override public double[] readDoubleArray() throws BinaryObjectException {
+        switch (checkFlag(DOUBLE_ARR)) {
+            case NORMAL:
+                return PortableUtils.doReadDoubleArray(in);
+
+            case HANDLE:
+                return readHandleField();
+
+            default:
+                return null;
+        }
+    }
+
+    /** {@inheritDoc} */
+    @Override @Nullable public BigDecimal readDecimal(String fieldName) throws BinaryObjectException {
+        return findFieldByName(fieldName) ? this.readDecimal() : null;
+    }
+
+    /**
+     * @param fieldId Field ID.
+     * @return Value.
+     * @throws BinaryObjectException In case of error.
+     */
+    @Nullable BigDecimal readDecimal(int fieldId) throws BinaryObjectException {
+        return findFieldById(fieldId) ? this.readDecimal() : null;
+    }
+
+    /** {@inheritDoc} */
+    @Override @Nullable public BigDecimal readDecimal() throws BinaryObjectException {
+        return checkFlagNoHandles(DECIMAL) == Flag.NORMAL ? PortableUtils.doReadDecimal(in) : null;
+    }
+
+    /** {@inheritDoc} */
+    @Override @Nullable public BigDecimal[] readDecimalArray(String fieldName) throws BinaryObjectException {
+        return findFieldByName(fieldName) ? this.readDecimalArray() : null;
+    }
+
+    /**
+     * @param fieldId Field ID.
+     * @return Value.
+     * @throws BinaryObjectException In case of error.
+     */
+    @Nullable BigDecimal[] readDecimalArray(int fieldId) throws BinaryObjectException {
+        return findFieldById(fieldId) ? this.readDecimalArray() : null;
+    }
+
+    /** {@inheritDoc} */
+    @Override @Nullable public BigDecimal[] readDecimalArray() throws BinaryObjectException {
+        switch (checkFlag(DECIMAL_ARR)) {
+            case NORMAL:
+                return PortableUtils.doReadDecimalArray(in);
+
+            case HANDLE:
+                return readHandleField();
+
+            default:
+                return null;
+        }
+    }
+
+    /** {@inheritDoc} */
+    @Override @Nullable public String readString(String fieldName) throws BinaryObjectException {
+        return findFieldByName(fieldName) ? this.readString() : null;
+    }
+
+    /**
+     * @param fieldId Field ID.
+     * @return Value.
+     * @throws BinaryObjectException In case of error.
+     */
+    @Nullable String readString(int fieldId) throws BinaryObjectException {
+        return findFieldById(fieldId) ? this.readString() : null;
+    }
+
+    /** {@inheritDoc} */
+    @Override @Nullable public String readString() throws BinaryObjectException {
+        return checkFlagNoHandles(STRING) == Flag.NORMAL ? PortableUtils.doReadString(in) : null;
+    }
+
+    /** {@inheritDoc} */
+    @Override @Nullable public String[] readStringArray(String fieldName) throws BinaryObjectException {
+        return findFieldByName(fieldName) ? this.readStringArray() : null;
+    }
+
+    /**
+     * @param fieldId Field ID.
+     * @return Value.
+     * @throws BinaryObjectException In case of error.
+     */
+    @Nullable String[] readStringArray(int fieldId) throws BinaryObjectException {
+        return findFieldById(fieldId) ? this.readStringArray() : null;
+    }
+
+    /** {@inheritDoc} */
+    @Override @Nullable public String[] readStringArray() throws BinaryObjectException {
+        switch (checkFlag(STRING_ARR)) {
+            case NORMAL:
+                return PortableUtils.doReadStringArray(in);
+
+            case HANDLE:
+                return readHandleField();
+
+            default:
+                return null;
+        }
+    }
+
+    /** {@inheritDoc} */
+    @Override @Nullable public UUID readUuid(String fieldName) throws BinaryObjectException {
+        return findFieldByName(fieldName) ? this.readUuid() : null;
+    }
+
+    /**
+     * @param fieldId Field ID.
+     * @return Value.
+     * @throws BinaryObjectException In case of error.
+     */
+    @Nullable UUID readUuid(int fieldId) throws BinaryObjectException {
+        return findFieldById(fieldId) ? this.readUuid() : null;
+    }
+
+    /** {@inheritDoc} */
+    @Override @Nullable public UUID readUuid() throws BinaryObjectException {
+        return checkFlagNoHandles(UUID) == Flag.NORMAL ? PortableUtils.doReadUuid(in) : null;
+    }
+
+    /** {@inheritDoc} */
+    @Override @Nullable public UUID[] readUuidArray(String fieldName) throws BinaryObjectException {
+        return findFieldByName(fieldName) ? this.readUuidArray() : null;
+    }
+
+    /**
+     * @param fieldId Field ID.
+     * @return Value.
+     * @throws BinaryObjectException In case of error.
+     */
+    @Nullable UUID[] readUuidArray(int fieldId) throws BinaryObjectException {
+        return findFieldById(fieldId) ? this.readUuidArray() : null;
+    }
+
+    /** {@inheritDoc} */
+    @Override @Nullable public UUID[] readUuidArray() throws BinaryObjectException {
+        switch (checkFlag(UUID_ARR)) {
+            case NORMAL:
+                return PortableUtils.doReadUuidArray(in);
+
+            case HANDLE:
+                return readHandleField();
+
+            default:
+                return null;
+        }
+    }
+
+    /** {@inheritDoc} */
+    @Override @Nullable public Date readDate(String fieldName) throws BinaryObjectException {
+        return findFieldByName(fieldName) ? this.readDate() : null;
+    }
+
+    /**
+     * @param fieldId Field ID.
+     * @return Value.
+     * @throws BinaryObjectException In case of error.
+     */
+    @Nullable Date readDate(int fieldId) throws BinaryObjectException {
+        return findFieldById(fieldId) ? this.readDate() : null;
+    }
+
+    /** {@inheritDoc} */
+    @Override @Nullable public Date readDate() throws BinaryObjectException {
+        return checkFlagNoHandles(DATE) == Flag.NORMAL ? PortableUtils.doReadDate(in) : null;
+    }
+
+    /** {@inheritDoc} */
+    @Override @Nullable public Date[] readDateArray(String fieldName) throws BinaryObjectException {
+        return findFieldByName(fieldName) ? this.readDateArray() : null;
+    }
+
+    /**
+     * @param fieldId Field ID.
+     * @return Value.
+     * @throws BinaryObjectException In case of error.
+     */
+    @Nullable Date[] readDateArray(int fieldId) throws BinaryObjectException {
+        return findFieldById(fieldId) ? this.readDateArray() : null;
+    }
+
+    /** {@inheritDoc} */
+    @Override @Nullable public Date[] readDateArray() throws BinaryObjectException {
+        switch (checkFlag(DATE_ARR)) {
+            case NORMAL:
+                return PortableUtils.doReadDateArray(in);
+
+            case HANDLE:
+                return readHandleField();
+
+            default:
+                return null;
+        }
+    }
+
+    /** {@inheritDoc} */
+    @Override @Nullable public Timestamp readTimestamp(String fieldName) throws BinaryObjectException {
+        return findFieldByName(fieldName) ? this.readTimestamp() : null;
+    }
+
+    /**
+     * @param fieldId Field ID.
+     * @return Value.
+     * @throws BinaryObjectException In case of error.
+     */
+    @Nullable Timestamp readTimestamp(int fieldId) throws BinaryObjectException {
+        return findFieldById(fieldId) ? this.readTimestamp() : null;
+    }
+
+    /** {@inheritDoc} */
+    @Override @Nullable public Timestamp readTimestamp() throws BinaryObjectException {
+        return checkFlagNoHandles(TIMESTAMP) == Flag.NORMAL ? PortableUtils.doReadTimestamp(in) : null;
+    }
+
+    /** {@inheritDoc} */
+    @Override @Nullable public Timestamp[] readTimestampArray(String fieldName) throws BinaryObjectException {
+        return findFieldByName(fieldName) ? this.readTimestampArray() : null;
+    }
+
+    /**
+     * @param fieldId Field ID.
+     * @return Value.
+     * @throws BinaryObjectException In case of error.
+     */
+    @Nullable Timestamp[] readTimestampArray(int fieldId) throws BinaryObjectException {
+        return findFieldById(fieldId) ? this.readTimestampArray() : null;
+    }
+
+    /** {@inheritDoc} */
+    @Override @Nullable public Timestamp[] readTimestampArray() throws BinaryObjectException {
+        switch (checkFlag(TIMESTAMP_ARR)) {
+            case NORMAL:
+                return PortableUtils.doReadTimestampArray(in);
+
+            case HANDLE:
+                return readHandleField();
+
+            default:
+                return null;
+        }
+    }
+
+    /** {@inheritDoc} */
+    @SuppressWarnings("unchecked")
+    @Nullable @Override public <T> T readObject(String fieldName) throws BinaryObjectException {
+        return findFieldByName(fieldName) ? (T)PortableUtils.doReadObject(in, ctx, ldr, this) : null;
+    }
+
+    /**
+     * @param fieldId Field ID.
+     * @return Value.
+     * @throws BinaryObjectException In case of error.
+     */
+    @Nullable Object readObject(int fieldId) throws BinaryObjectException {
+        return findFieldById(fieldId) ? PortableUtils.doReadObject(in, ctx, ldr, this) : null;
+    }
+
+    /** {@inheritDoc} */
+    @Override public Object readObject() throws BinaryObjectException {
+        return PortableUtils.doReadObject(in, ctx, ldr, this);
+    }
+
+    /** {@inheritDoc} */
+    @Nullable @Override public Object readObjectDetached() throws BinaryObjectException {
+        return PortableUtils.unmarshal(in, ctx, ldr, this, true);
+    }
+
+    /** {@inheritDoc} */
+    @Nullable @Override public Object[] readObjectArray(String fieldName) throws BinaryObjectException {
+        return findFieldByName(fieldName) ? this.readObjectArray() : null;
+    }
+
+    /**
+     * @param fieldId Field ID.
+     * @return Value.
+     * @throws BinaryObjectException In case of error.
+     */
+    @Nullable Object[] readObjectArray(int fieldId) throws BinaryObjectException {
+        return findFieldById(fieldId) ? this.readObjectArray() : null;
+    }
+
+    /** {@inheritDoc} */
+    @Nullable @Override public Object[] readObjectArray() throws BinaryObjectException {
+        switch (checkFlag(OBJ_ARR)) {
+            case NORMAL:
+                return PortableUtils.doReadObjectArray(in, ctx, ldr, this, true);
+
+            case HANDLE:
+                return readHandleField();
+
+            default:
+                return null;
+        }
+    }
+
+    /** {@inheritDoc} */
+    @Nullable @Override public <T extends Enum<?>> T readEnum(String fieldName) throws BinaryObjectException {
+        return findFieldByName(fieldName) ? (T)readEnum0(null) : null;
+    }
+
+    /**
+     * @param fieldId Field ID.
+     * @param cls Class.
+     * @return Value.
+     * @throws BinaryObjectException In case of error.
+     */
+    @Nullable Enum<?> readEnum(int fieldId, @Nullable Class<?> cls) throws BinaryObjectException {
+        return findFieldById(fieldId) ? readEnum0(cls) : null;
+    }
+
+    /** {@inheritDoc} */
+    @Nullable @Override public <T extends Enum<?>> T readEnum() throws BinaryObjectException {
+        return (T)readEnum0(null);
+    }
+
+    /**
+     * Internal routine to read enum for named field.
+     *
+     * @param cls Class.
+     * @return Value.
+     * @throws BinaryObjectException In case of error.
+     */
+    private Enum<?> readEnum0(@Nullable Class<?> cls) throws BinaryObjectException {
+        if (checkFlagNoHandles(ENUM) == Flag.NORMAL) {
+            // Read class even if we know it in advance to set correct stream position.
+            Class<?> cls0 = PortableUtils.doReadClass(in, ctx, ldr);
+
+            if (cls == null)
+                cls = cls0;
+
+            return PortableUtils.doReadEnum(in, cls);
+        }
+        else
+            return null;
+    }
+
+    /** {@inheritDoc} */
+    @Nullable @Override public <T extends Enum<?>> T[] readEnumArray(String fieldName)
+        throws BinaryObjectException {
+        return findFieldByName(fieldName) ? (T[])readEnumArray0(null) : null;
+    }
+
+    /**
+     * @param fieldId Field ID.
+     * @param cls Class.
+     * @return Value.
+     * @throws BinaryObjectException In case of error.
+     */
+    @Nullable Object[] readEnumArray(int fieldId, @Nullable Class<?> cls) throws BinaryObjectException {
+        return findFieldById(fieldId) ? readEnumArray0(cls) : null;
+    }
+
+    /** {@inheritDoc} */
+    @Nullable @Override public <T extends Enum<?>> T[] readEnumArray() throws BinaryObjectException {
+        return (T[])readEnumArray0(null);
+    }
+
+    /**
+     * Internal routine to read enum for named field.
+     *
+     * @param cls Class.
+     * @return Value.
+     * @throws BinaryObjectException In case of error.
+     */
+    private Object[] readEnumArray0(@Nullable Class<?> cls) throws BinaryObjectException {
+        switch (checkFlag(ENUM_ARR)) {
+            case NORMAL:
+                // Read class even if we know it in advance to set correct stream position.
+                Class<?> cls0 = PortableUtils.doReadClass(in, ctx, ldr);
+
+                if (cls == null)
+                    cls = cls0;
+
+                return PortableUtils.doReadEnumArray(in, ctx, ldr, cls);
+
+            case HANDLE:
+                return readHandleField();
+
+            default:
+                return null;
+        }
+    }
+
+    /** {@inheritDoc} */
+    @Nullable @Override public <T> Collection<T> readCollection(String fieldName) throws BinaryObjectException {
+        return findFieldByName(fieldName) ? (Collection<T>)readCollection0(null) : null;
+    }
+
+    /** {@inheritDoc} */
+    @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 factory Collection factory.
+     * @return Value.
+     * @throws BinaryObjectException In case of error.
+     */
+    @Nullable <T> Collection<T> readCollection(int fieldId, @Nullable BinaryCollectionFactory<T> factory)
+        throws BinaryObjectException {
+        return findFieldById(fieldId) ? (Collection<T>)readCollection0(factory) : null;
+    }
+
+    /** {@inheritDoc} */
+    @Nullable @Override public <T> Collection<T> readCollection() throws BinaryObjectException {
+        return readCollection0(null);
+    }
+
+    /** {@inheritDoc} */
+    @Nullable @Override public <T> Collection<T> readCollection(BinaryCollectionFactory<T> factory)
+        throws BinaryObjectException {
+        return readCollection0(factory);
+    }
+
+    /**
+     * Internal read collection routine.
+     *
+     * @param factory Collection factory.
+     * @return Value.
+     * @throws BinaryObjectException If failed.
+     */
+    private Collection readCollection0(@Nullable BinaryCollectionFactory factory)
+        throws BinaryObjectException {
+        switch (checkFlag(COL)) {
+            case NORMAL:
+                return (Collection)PortableUtils.doReadCollection(in, ctx, ldr, this, true, factory);
+
+            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;
+        }
+    }
+
+    /** {@inheritDoc} */
+    @Nullable @Override public <K, V> Map<K, V> readMap(String fieldName) throws BinaryObjectException {
+        return findFieldByName(fieldName) ? (Map<K, V>)readMap0(null) : null;
+    }
+
+    /** {@inheritDoc} */
+    @Nullable @Override public <K, V> Map<K, V> readMap(String fieldName, BinaryMapFactory<K, V> factory)
+        throws BinaryObjectException {
+        return findFieldByName(fieldName) ? readMap0(factory) : null;
+    }
+
+    /**
+     * @param fieldId Field ID.
+     * @param factory Factory.
+     * @return Value.
+     * @throws BinaryObjectException In case of error.
+     */
+    @Nullable Map<?, ?> readMap(int fieldId, @Nullable BinaryMapFactory factory) throws BinaryObjectException {
+        return findFieldById(fieldId) ? readMap0(factory) : null;
+    }
+
+    /** {@inheritDoc} */
+    @Nullable @Override public <K, V> Map<K, V> readMap() throws BinaryObjectException {
+        return readMap0(null);
+    }
+
+    /** {@inheritDoc} */
+    @Nullable @Override public <K, V> Map<K, V> readMap(BinaryMapFactory<K, V> factory)
+        throws BinaryObjectException {
+        return readMap0(factory);
+    }
+
+    /**
+     * Internal read map routine.
+     *
+     * @param factory Factory.
+     * @return Value.
+     * @throws BinaryObjectException If failed.
+     */
+    private Map readMap0(@Nullable BinaryMapFactory factory) throws BinaryObjectException {
+        switch (checkFlag(MAP)) {
+            case NORMAL:
+                return (Map)PortableUtils.doReadMap(in, ctx, ldr, this, true, factory);
+
+            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;
+        }
+    }
+
+    /**
+     * Ensure that type flag is either null, handle or contains expected value.
+     *
+     * @param expFlag Expected value.
+     * @return Flag mode.
+     * @throws BinaryObjectException If flag is neither null, nor handle or expected.
+     */
+    private Flag checkFlag(byte expFlag) {
+        byte flag = in.readByte();
+
+        if (flag == expFlag)
+            return Flag.NORMAL;
+        else if (flag == NULL)
+            return Flag.NULL;
+        else if (flag == HANDLE)
+            return Flag.HANDLE;
+
+        int pos = PortableUtils.positionForHandle(in);
+
+        throw new BinaryObjectException("Unexpected flag value [pos=" + pos + ", expected=" + expFlag +
+            ", actual=" + flag + ']');
+    }
+
+    /**
+     * Ensure that type flag is either null or contains expected value.
+     *
+     * @param expFlag Expected value.
+     * @return Flag mode.
+     * @throws BinaryObjectException If flag is neither null, nor expected.
+     */
+    private Flag checkFlagNoHandles(byte expFlag) {
+        byte flag = in.readByte();
+
+        if (flag == expFlag)
+            return Flag.NORMAL;
+        else if (flag == NULL)
+            return Flag.NULL;
+
+        int pos = PortableUtils.positionForHandle(in);
+
+        throw new BinaryObjectException("Unexpected flag value [pos=" + pos + ", expected=" + expFlag +
+            ", actual=" + flag + ']');
+    }
+
+    /** {@inheritDoc} */
+    @Override public BinaryRawReader rawReader() {
+        if (!raw) {
+            streamPositionRandom(rawOff);
+
+            raw = true;
+
+            return this;
+        }
+        else
+            throw new BinaryObjectException("Method \"rawReader\" can be called only once.");
+    }
+
+    /**
+     * @return Deserialized object.
+     * @throws BinaryObjectException If failed.
+     */
+    @Nullable Object deserialize() throws BinaryObjectException {
+        Object obj;
+
+        byte flag = in.readByte();
+
+        switch (flag) {
+            case NULL:
+                obj = null;
+
+                break;
+
+            case HANDLE:
+                int handlePos = start - in.readInt();
+
+                obj = getHandle(handlePos);
+
+                if (obj == null) {
+                    int retPos = in.position();
+
+                    streamPosition(handlePos);
+
+                    obj = PortableUtils.doReadObject(in, ctx, ldr, this);
+
+                    streamPosition(retPos);
+                }
+
+                break;
+
+            case OBJ:
+                PortableClassDescriptor desc = ctx.descriptorForTypeId(userType, typeId, ldr, true);
+
+                streamPosition(dataStart);
+
+                if (desc == null)
+                    throw new BinaryInvalidTypeException("Unknown type ID: " + typeId);
+
+                obj = desc.read(this);
+
+                streamPosition(footerStart + footerLen);
+
+                break;
+
+            case BYTE:
+                obj = in.readByte();
+
+                break;
+
+            case SHORT:
+                obj = in.readShort();
+
+                break;
+
+            case INT:
+                obj = in.readInt();
+
+                break;
+
+            case LONG:
+                obj = in.readLong();
+
+                break;
+
+            case FLOAT:
+                obj = in.readFloat();
+
+                break;
+
+            case DOUBLE:
+                obj = in.readDouble();
+
+                break;
+
+            case CHAR:
+                obj = in.readChar();
+
+                break;
+
+            case BOOLEAN:
+                obj = in.readBoolean();
+
+                break;
+
+            case DECIMAL:
+                obj = PortableUtils.doReadDecimal(in);
+
+                break;
+
+            case STRING:
+                obj = PortableUtils.doReadString(in);
+
+                break;
+
+            case UUID:
+                obj = PortableUtils.doReadUuid(in);
+
+                break;
+
+            case DATE:
+                obj = PortableUtils.doReadDate(in);
+
+                break;
+
+            case TIMESTAMP:
+                obj = PortableUtils.doReadTimestamp(in);
+
+                break;
+
+            case BYTE_ARR:
+                obj = PortableUtils.doReadByteArray(in);
+
+                break;
+
+            case SHORT_ARR:
+                obj = PortableUtils.doReadShortArray(in);
+
+                break;
+
+            case INT_ARR:
+                obj = PortableUtils.doReadIntArray(in);
+
+                break;
+
+            case LONG_ARR:
+                obj = PortableUtils.doReadLongArray(in);
+
+                break;
+
+            case FLOAT_ARR:
+                obj = PortableUtils.doReadFloatArray(in);
+
+                break;
+
+            case DOUBLE_ARR:
+                obj = PortableUtils.doReadDoubleArray(in);
+
+                break;
+
+            case CHAR_ARR:
+                obj = PortableUtils.doReadCharArray(in);
+
+                break;
+
+            case BOOLEAN_ARR:
+                obj = PortableUtils.doReadBooleanArray(in);
+
+                break;
+
+            case DECIMAL_ARR:
+                obj = PortableUtils.doReadDecimalArray(in);
+
+                break;
+
+            case STRING_ARR:
+                obj = PortableUtils.doReadStringArray(in);
+
+                break;
+
+            case UUID_ARR:
+                obj = PortableUtils.doReadUuidArray(in);
+
+                break;
+
+            case DATE_ARR:
+                obj = PortableUtils.doReadDateArray(in);
+
+                break;
+
+            case TIMESTAMP_ARR:
+                obj = PortableUtils.doReadTimestampArray(in);
+
+                break;
+
+            case OBJ_ARR:
+                obj = PortableUtils.doReadObjectArray(in, ctx, ldr, this, true);
+
+                break;
+
+            case COL:
+                obj = PortableUtils.doReadCollection(in, ctx, ldr, this, true, null);
+
+                break;
+
+            case MAP:
+                obj = PortableUtils.doReadMap(in, ctx, ldr, this, true, null);
+
+                break;
+
+            case PORTABLE_OBJ:
+                obj = PortableUtils.doReadPortableObject(in, ctx);
+
+                ((BinaryObjectImpl)obj).context(ctx);
+
+                if (!GridPortableMarshaller.KEEP_PORTABLES.get())
+                    obj = ((BinaryObject)obj).deserialize();
+
+                break;
+
+            case ENUM:
+                obj = PortableUtils.doReadEnum(in, PortableUtils.doReadClass(in, ctx, ldr));
+
+                break;
+
+            case ENUM_ARR:
+                obj = PortableUtils.doReadEnumArray(in, ctx, ldr, PortableUtils.doReadClass(in, ctx, ldr));
+
+                break;
+
+            case CLASS:
+                obj = PortableUtils.doReadClass(in, ctx, ldr);
+
+                break;
+
+            case OPTM_MARSH:
+                obj = PortableUtils.doReadOptimized(in, ctx, ldr);
+
+                break;
+
+            default:
+                throw new BinaryObjectException("Invalid flag value: " + flag);
+        }
+
+        return obj;
+    }
+
+    /**
+     * @return Deserialized object.
+     * @throws BinaryObjectException If failed.
+     */
+    @Nullable Object readField(int fieldId) throws BinaryObjectException {
+        if (!findFieldById(fieldId))
+            return null;
+
+        return new BinaryReaderExImpl(ctx, in, ldr, hnds).deserialize();
+    }
+
+    /**
+     * @param name Field name.
+     * @return Field offset.
+     */
+    private int fieldId(String name) {
+        assert name != null;
+
+        return idMapper.fieldId(typeId, name);
+    }
+
+    /**
+     * Get or create object schema.
+     *
+     * @return Schema.
+     */
+    public PortableSchema getOrCreateSchema() {
+        PortableSchema schema = ctx.schemaRegistry(typeId).schema(schemaId);
+
+        if (schema == null) {
+            if (fieldIdLen != PortableUtils.FIELD_ID_LEN) {
+                BinaryTypeImpl type = (BinaryTypeImpl)ctx.metadata(typeId);
+
+                if (type == null || type.metadata() == null)
+                    throw new BinaryObjectException("Cannot find metadata for object with compact footer: " +
+                        typeId);
+
+                for (PortableSchema typeSchema : type.metadata().schemas()) {
+                    if (schemaId == typeSchema.schemaId()) {
+                        schema = typeSchema;
+
+                        break;
+                    }
+                }
+
+                if (schema == null)
+                    throw new BinaryObjectException("Cannot find schema for object with compact footer [" +
+                        "typeId=" + typeId + ", schemaId=" + schemaId + ']');
+            }
+            else
+                schema = createSchema();
+
+            assert schema != null;
+
+            ctx.schemaRegistry(typeId).addSchema(schemaId, schema);
+        }
+
+        return schema;
+    }
+
+    /**
+     * Create schema.
+     *
+     * @return Schema.
+     */
+    private PortableSchema createSchema() {
+        assert fieldIdLen == PortableUtils.FIELD_ID_LEN;
+
+        PortableSchema.Builder builder = PortableSchema.Builder.newBuilder();
+
+        int searchPos = footerStart;
+        int searchEnd = searchPos + footerLen;
+
+        while (searchPos < searchEnd) {
+            int fieldId = in.readIntPositioned(searchPos);
+
+            builder.addField(fieldId);
+
+            searchPos += PortableUtils.FIELD_ID_LEN + fieldOffsetLen;
+        }
+
+        return builder.build();
+    }
+
+    /**
+     * Try finding the field by name.
+     *
+     * @param name Field name.
+     * @return Offset.
+     */
+    public boolean findFieldByName(String name) {
+        if (raw)
+            throw new BinaryObjectException("Failed to read named field because reader is in raw mode.");
+
+        assert dataStart != start;
+
+        if (footerLen == 0)
+            return false;
+
+        if (userType) {
+            int order;
+
+            if (matching) {
+                int expOrder = matchingOrder++;
+
+                PortableSchema.Confirmation confirm = schema.confirmOrder(expOrder, name);
+
+                switch (confirm) {
+                    case CONFIRMED:
+                        // The best case: got order without ID calculation and (ID -> order) lookup.
+                        if (expOrder == 0)
+                            // When we read the very first field, position is set to start, hence this re-positioning.
+                            streamPosition(dataStart);
+
+                        return true;
+
+                    case REJECTED:
+                        // Rejected, no more speculations are possible. Fallback to the slowest scenario.
+                        matching = false;
+
+                        order = schema.order(fieldId(name));
+
+                        break;
+
+                    default:
+                        // Field name is not know for this order. Need to calculate ID and repeat speculation.
+                        assert confirm == PortableSchema.Confirmation.CLARIFY;
+
+                        int id = fieldId(name);
+                        int realId = schema.fieldId(expOrder);
+
+                        if (id == realId) {
+                            // IDs matched, cache field name inside schema.
+                            schema.clarifyFieldName(expOrder, name);
+
+                            if (expOrder == 0)
+                                streamPosition(dataStart);
+
+                            return true;
+                        }
+                        else {
+                            // No match, stop further speculations.
+                            matching = false;
+
+                            order = schema.order(id);
+                        }
+
+                        break;
+                }
+            }
+            else
+                order = schema.order(fieldId(name));
+
+            return trySetUserFieldPosition(order);
+        }
+        else
+            return trySetSystemFieldPosition(fieldId(name));
+    }
+
+    /**
+     * Try finding the field by ID. Used for types with stable schema (Serializable) to avoid
+     * (string -> ID) calculations.
+     *
+     * @param id Field ID.
+     * @return {@code True} if field was found and stream was positioned accordingly.
+     */
+    private boolean findFieldById(int id) {
+        assert !raw; // Assert, not exception, because this is called only from internals for Serializable types.
+        assert dataStart != start;
+
+        if (footerLen == 0)
+            return false;
+
+        if (userType) {
+            int order;
+
+            if (matching) {
+                // Trying to get field order speculatively.
+                int expOrder = matchingOrder++;
+
+                int realId = schema.fieldId(expOrder);
+
+                if (realId == id) {
+                    if (expOrder == 0)
+                        streamPosition(dataStart);
+
+                    return true;
+                }
+                else {
+                    // Mismatch detected, no need for further speculations.
+                    matching = false;
+
+                    order = schema.order(id);
+                }
+            }
+            else
+                order = schema.order(id);
+
+            return trySetUserFieldPosition(order);
+        }
+        else
+            return trySetSystemFieldPosition(id);
+    }
+
+    /**
+     * Set position for the given user field order.
+     *
+     * @param order Order.
+     * @return {@code True} if field was found and stream was positioned accordingly.
+     */
+    private boolean trySetUserFieldPosition(int order) {
+        if (order != PortableSchema.ORDER_NOT_FOUND) {
+            int offsetPos = footerStart + order * (fieldIdLen + fieldOffsetLen) + fieldIdLen;
+
+            int pos = start + PortableUtils.fieldOffsetRelative(in, offsetPos, fieldOffsetLen);
+
+            streamPosition(pos);
+
+            return true;
+        }
+        else
+            return false;
+    }
+
+    /**
+     * Set position for the given system field ID.
+     *
+     * @param id Field ID.
+     * @return {@code True} if field was found and stream was positioned accordingly.
+     */
+    private boolean trySetSystemFieldPosition(int id) {
+        // System types are never written with compact footers because they do not have metadata.
+        assert fieldIdLen == PortableUtils.FIELD_ID_LEN;
+
+        int searchPos = footerStart;
+        int searchTail = searchPos + footerLen;
+
+        while (true) {
+            if (searchPos >= searchTail)
+                return false;
+
+            int id0 = in.readIntPositioned(searchPos);
+
+            if (id0 == id) {
+                int pos = start + PortableUtils.fieldOffsetRelative(in, searchPos + PortableUtils.FIELD_ID_LEN,
+                    fieldOffsetLen);
+
+                streamPosition(pos);
+
+                return true;
+            }
+
+            searchPos += PortableUtils.FIELD_ID_LEN + fieldOffsetLen;
+        }
+    }
+
+    /**
+     * Set stream position.
+     *
+     * @param pos Position.
+     */
+    private void streamPosition(int pos) {
+        in.position(pos);
+    }
+
+    /**
+     * Set stream position as a part of some random read. Further speculations will be disabled after this call.
+     *
+     * @param pos Position.
+     */
+    private void streamPositionRandom(int pos) {
+        streamPosition(pos);
+
+        matching = false;
+    }
+
+    /** {@inheritDoc} */
+    @Override public int readUnsignedByte() throws IOException {
+        return readByte() & 0xff;
+    }
+
+    /** {@inheritDoc} */
+    @Override public int readUnsignedShort() throws IOException {
+        return readShort() & 0xffff;
+    }
+
+    /** {@inheritDoc} */
+    @Override public String readLine() throws IOException {
+        SB sb = new SB();
+
+        int b;
+
+        while ((b = read()) >= 0) {
+            char c = (char)b;
+
+            switch (c) {
+                case '\n':
+                    return sb.toString();
+
+                case '\r':
+                    b = read();
+
+                    if (b < 0 || b == '\n')
+                        return sb.toString();
+                    else
+                        sb.a((char)b);
+
+                    break;
+
+                default:
+                    sb.a(c);
+            }
+        }
+
+        return sb.toString();
+    }
+
+    /** {@inheritDoc} */
+    @SuppressWarnings("ConstantConditions")
+    @NotNull @Override public String readUTF() throws IOException {
+        return readString();
+    }
+
+    /** {@inheritDoc} */
+    @SuppressWarnings("NullableProblems")
+    @Override public void readFully(byte[] b) throws IOException {
+        readFully(b, 0, b.length);
+    }
+
+    /** {@inheritDoc} */
+    @SuppressWarnings("NullableProblems")
+    @Override public void readFully(byte[] b, int off, int len) throws IOException {
+        int cnt = in.read(b, off, len);
+
+        if (cnt < len)
+            throw new EOFException();
+    }
+
+    /** {@inheritDoc} */
+    @Override public int skipBytes(int n) throws IOException {
+        int toSkip = Math.min(in.remaining(), n);
+
+        streamPositionRandom(in.position() + toSkip);
+
+        return toSkip;
+    }
+
+    /** {@inheritDoc} */
+    @Override public int read() throws IOException {
+        return readByte();
+    }
+
+    /** {@inheritDoc} */
+    @Override public int read(byte[] b) throws IOException {
+        return read(b, 0, b.length);
+    }
+
+    /** {@inheritDoc} */
+    @Override public int read(byte[] b, int off, int len) throws IOException {
+        return in.read(b, off, len);
+    }
+
+    /** {@inheritDoc} */
+    @Override public long skip(long n) throws IOException {
+        return skipBytes((int) n);
+    }
+
+    /** {@inheritDoc} */
+    @Override public int available() throws IOException {
+        return in.remaining();
+    }
+
+    /** {@inheritDoc} */
+    @Override public void close() throws IOException {
+        // No-op.
+    }
+
+    /**
+     * Flag.
+     */
+    private static enum Flag {
+        /** Regular. */
+        NORMAL,
+
+        /** Handle. */
+        HANDLE,
+
+        /** Null. */
+        NULL
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/1dbf20e0/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryReaderHandles.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryReaderHandles.java b/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryReaderHandles.java
new file mode 100644
index 0000000..fddb8aa
--- /dev/null
+++ b/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryReaderHandles.java
@@ -0,0 +1,108 @@
+/*
+ * 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.binary;
+
+import org.jetbrains.annotations.Nullable;
+
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * Reader handles.
+ */
+public class BinaryReaderHandles {
+    /** Mode: empty. */
+    private static final int MODE_EMPTY = 0;
+
+    /** Mode: single object. */
+    private static final int MODE_SINGLE = 1;
+
+    /** Mode: multiple objects. */
+    private static final int MODE_MULTIPLE = 2;
+
+    /** Position.  */
+    private int singlePos;
+
+    /** Data. This is either an object or a map. */
+    private Object data;
+
+    /** Mode. */
+    private int mode = MODE_EMPTY;
+
+    /**
+     * Get object by position.
+     *
+     * @param pos Position.
+     * @return Object.
+     */
+    @SuppressWarnings("unchecked")
+    public @Nullable <T> T get(int pos) {
+        switch (mode) {
+            case MODE_EMPTY:
+                return null;
+
+            case MODE_SINGLE:
+                return (T)data;
+
+            default:
+                assert mode == MODE_MULTIPLE;
+
+                return (T)((Map<Integer, Object>)data).get(pos);
+        }
+    }
+
+    /**
+     * Put object to registry and return previous position (if any).
+     *
+     * @param pos Position.
+     * @param obj Object.
+     */
+    @SuppressWarnings("unchecked")
+    public void put(int pos, Object obj) {
+        assert pos >= 0;
+        assert obj != null;
+
+        switch (mode) {
+            case MODE_EMPTY:
+                this.singlePos = pos;
+                this.data = obj;
+                this.mode = MODE_SINGLE;
+
+                break;
+
+            case MODE_SINGLE:
+                Map<Integer, Object> newData = new HashMap(3, 1.0f);
+
+                newData.put(singlePos, data);
+                newData.put(pos, obj);
+
+                this.singlePos = -1;
+                this.data = newData;
+                this.mode = MODE_MULTIPLE;
+
+                break;
+
+            default:
+                assert mode == MODE_MULTIPLE;
+
+                Map<Integer, Object> data0 = (Map<Integer, Object>)data;
+
+                data0.put(pos, obj);
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/1dbf20e0/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryReaderHandlesHolder.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryReaderHandlesHolder.java b/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryReaderHandlesHolder.java
new file mode 100644
index 0000000..48c9e8e
--- /dev/null
+++ b/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryReaderHandlesHolder.java
@@ -0,0 +1,46 @@
+/*
+ * 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.binary;
+
+/**
+ * Holder for handles.
+ */
+public interface BinaryReaderHandlesHolder {
+    /**
+     * Set handle.
+     *
+     * @param obj Object.
+     * @param pos Position.
+     */
+    public void setHandle(Object obj, int pos);
+
+    /**
+     * Get handle.
+     *
+     * @param pos Position.
+     * @return Handle.
+     */
+    public Object getHandle(int pos);
+
+    /**
+     * Get all handles.
+     *
+     * @return Handles.
+     */
+    public BinaryReaderHandles handles();
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/1dbf20e0/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryReaderHandlesHolderImpl.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryReaderHandlesHolderImpl.java b/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryReaderHandlesHolderImpl.java
new file mode 100644
index 0000000..83b34a9
--- /dev/null
+++ b/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryReaderHandlesHolderImpl.java
@@ -0,0 +1,44 @@
+/*
+ * 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.binary;
+
+/**
+ * Simple holder for handles.
+ */
+public class BinaryReaderHandlesHolderImpl implements BinaryReaderHandlesHolder  {
+    /** Handles. */
+    private BinaryReaderHandles hnds;
+
+    /** {@inheritDoc} */
+    @Override public void setHandle(Object obj, int pos) {
+        handles().put(pos, obj);
+    }
+
+    /** {@inheritDoc} */
+    @Override public Object getHandle(int pos) {
+        return hnds != null ? hnds.get(pos) : null;
+    }
+
+    /** {@inheritDoc} */
+    @Override public BinaryReaderHandles handles() {
+        if (hnds == null)
+            hnds = new BinaryReaderHandles();
+
+        return hnds;
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/1dbf20e0/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryThreadLocalContext.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryThreadLocalContext.java b/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryThreadLocalContext.java
new file mode 100644
index 0000000..8fff80b
--- /dev/null
+++ b/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryThreadLocalContext.java
@@ -0,0 +1,70 @@
+/*
+ * 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.binary;
+
+import org.apache.ignite.internal.binary.streams.PortableMemoryAllocatorChunk;
+import org.apache.ignite.internal.binary.streams.PortableMemoryAllocator;
+import org.apache.ignite.internal.binary.streams.PortableMemoryAllocatorChunk;
+
+/**
+ * Contains thread-local data for binary marshalling.
+ */
+public class BinaryThreadLocalContext {
+    /** Thread-local instance. */
+    private static final ThreadLocal<BinaryThreadLocalContext> CTX = new ThreadLocal<BinaryThreadLocalContext>() {
+        @Override protected BinaryThreadLocalContext initialValue() {
+            return new BinaryThreadLocalContext();
+        }
+    };
+
+    /** Memory chunk. */
+    private final PortableMemoryAllocatorChunk chunk = PortableMemoryAllocator.INSTANCE.chunk();
+
+    /** Schema holder. */
+    private final BinaryWriterSchemaHolder schema = new BinaryWriterSchemaHolder();
+
+    /**
+     * Get current context.
+     *
+     * @return Context.
+     */
+    public static BinaryThreadLocalContext get() {
+        return CTX.get();
+    }
+
+    /**
+     * Private constructor.
+     */
+    private BinaryThreadLocalContext() {
+        // No-op.
+    }
+
+    /**
+     * @return Memory chunk.
+     */
+    public PortableMemoryAllocatorChunk chunk() {
+        return chunk;
+    }
+
+    /**
+     * @return Schema holder.
+     */
+    public BinaryWriterSchemaHolder schemaHolder() {
+        return schema;
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/1dbf20e0/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryTypeImpl.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryTypeImpl.java b/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryTypeImpl.java
new file mode 100644
index 0000000..d19076b
--- /dev/null
+++ b/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryTypeImpl.java
@@ -0,0 +1,93 @@
+/*
+ * 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.binary;
+
+import org.apache.ignite.binary.BinaryType;
+
+import java.util.Collection;
+
+/**
+ * Binary type implementation.
+ */
+public class BinaryTypeImpl implements BinaryType {
+    /** Portable context. */
+    private final PortableContext ctx;
+
+    /** Type metadata. */
+    private final BinaryMetadata meta;
+
+    /**
+     * Constructor.
+     *
+     * @param ctx Portable context.
+     * @param meta Type  metadata.
+     */
+    public BinaryTypeImpl(PortableContext ctx, BinaryMetadata meta) {
+        this.ctx = ctx;
+        this.meta = meta;
+    }
+
+    /** {@inheritDoc} */
+    @Override public String typeName() {
+        return meta.typeName();
+    }
+
+    /** {@inheritDoc} */
+    @Override public int typeId() {
+        return meta.typeId();
+    }
+
+    /** {@inheritDoc} */
+    @Override public Collection<String> fieldNames() {
+        return meta.fields();
+    }
+
+    /** {@inheritDoc} */
+    @Override public String fieldTypeName(String fieldName) {
+        return meta.fieldTypeName(fieldName);
+    }
+
+    /** {@inheritDoc} */
+    @Override public BinaryFieldImpl field(String fieldName) {
+        return ctx.createField(meta.typeId(), fieldName);
+    }
+
+    /** {@inheritDoc} */
+    @Override public String affinityKeyFieldName() {
+        return meta.affinityKeyFieldName();
+    }
+
+    /** {@inheritDoc} */
+    @Override public boolean isEnum() {
+        return meta.isEnum();
+    }
+
+    /**
+     * @return Context.
+     */
+    public PortableContext context() {
+        return ctx;
+    }
+
+    /**
+     * @return Metadata.
+     */
+    public BinaryMetadata metadata() {
+        return meta;
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/1dbf20e0/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryWriteMode.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryWriteMode.java b/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryWriteMode.java
new file mode 100644
index 0000000..a20b5ed
--- /dev/null
+++ b/modules/core/src/main/java/org/apache/ignite/internal/binary/BinaryWriteMode.java
@@ -0,0 +1,178 @@
+/*
+ * 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.binary;
+
+/**
+ * Various write modes for binary objects.
+ */
+public enum BinaryWriteMode {
+    /** Primitive byte. */
+    P_BYTE(GridPortableMarshaller.BYTE),
+
+    /** Primitive boolean. */
+    P_BOOLEAN(GridPortableMarshaller.BOOLEAN),
+
+    /** Primitive short. */
+    P_SHORT(GridPortableMarshaller.SHORT),
+
+    /** Primitive char. */
+    P_CHAR(GridPortableMarshaller.CHAR),
+
+    /** Primitive int. */
+    P_INT(GridPortableMarshaller.INT),
+
+    /** Primitive long. */
+    P_LONG(GridPortableMarshaller.LONG),
+
+    /** Primitive float. */
+    P_FLOAT(GridPortableMarshaller.FLOAT),
+
+    /** Primitive int. */
+    P_DOUBLE(GridPortableMarshaller.DOUBLE),
+
+    /** */
+    BYTE(GridPortableMarshaller.BYTE),
+
+    /** */
+    SHORT(GridPortableMarshaller.SHORT),
+
+    /** */
+    INT(GridPortableMarshaller.INT),
+
+    /** */
+    LONG(GridPortableMarshaller.LONG),
+
+    /** */
+    FLOAT(GridPortableMarshaller.FLOAT),
+
+    /** */
+    DOUBLE(GridPortableMarshaller.DOUBLE),
+
+    /** */
+    CHAR(GridPortableMarshaller.CHAR),
+
+    /** */
+    BOOLEAN(GridPortableMarshaller.BOOLEAN),
+
+    /** */
+    DECIMAL(GridPortableMarshaller.DECIMAL),
+
+    /** */
+    STRING(GridPortableMarshaller.STRING),
+
+    /** */
+    UUID(GridPortableMarshaller.UUID),
+
+    /** */
+    DATE(GridPortableMarshaller.DATE),
+
+    /** */
+    TIMESTAMP(GridPortableMarshaller.TIMESTAMP),
+
+    /** */
+    BYTE_ARR(GridPortableMarshaller.BYTE_ARR),
+
+    /** */
+    SHORT_ARR(GridPortableMarshaller.SHORT_ARR),
+
+    /** */
+    INT_ARR(GridPortableMarshaller.INT_ARR),
+
+    /** */
+    LONG_ARR(GridPortableMarshaller.LONG_ARR),
+
+    /** */
+    FLOAT_ARR(GridPortableMarshaller.FLOAT_ARR),
+
+    /** */
+    DOUBLE_ARR(GridPortableMarshaller.DOUBLE_ARR),
+
+    /** */
+    CHAR_ARR(GridPortableMarshaller.CHAR_ARR),
+
+    /** */
+    BOOLEAN_ARR(GridPortableMarshaller.BOOLEAN_ARR),
+
+    /** */
+    DECIMAL_ARR(GridPortableMarshaller.DECIMAL_ARR),
+
+    /** */
+    STRING_ARR(GridPortableMarshaller.STRING_ARR),
+
+    /** */
+    UUID_ARR(GridPortableMarshaller.UUID_ARR),
+
+    /** */
+    DATE_ARR(GridPortableMarshaller.DATE_ARR),
+
+    /** */
+    TIMESTAMP_ARR(GridPortableMarshaller.TIMESTAMP_ARR),
+
+    /** */
+    OBJECT_ARR(GridPortableMarshaller.OBJ_ARR),
+
+    /** */
+    COL(GridPortableMarshaller.COL),
+
+    /** */
+    MAP(GridPortableMarshaller.MAP),
+
+    /** */
+    PORTABLE_OBJ(GridPortableMarshaller.OBJ),
+
+    /** */
+    ENUM(GridPortableMarshaller.ENUM),
+
+    /** Portable enum. */
+    PORTABLE_ENUM(GridPortableMarshaller.ENUM),
+
+    /** */
+    ENUM_ARR(GridPortableMarshaller.ENUM_ARR),
+
+    /** */
+    CLASS(GridPortableMarshaller.CLASS),
+
+    /** */
+    PORTABLE(GridPortableMarshaller.PORTABLE_OBJ),
+
+    /** */
+    EXTERNALIZABLE(GridPortableMarshaller.OBJ),
+
+    /** */
+    OBJECT(GridPortableMarshaller.OBJ),
+
+    /** */
+    EXCLUSION(GridPortableMarshaller.OBJ);
+
+    /** Type ID. */
+    private final int typeId;
+
+    /**
+     * @param typeId Type ID.
+     */
+    private BinaryWriteMode(int typeId) {
+        this.typeId = typeId;
+    }
+
+    /**
+     * @return Type ID.
+     */
+    public int typeId() {
+        return typeId;
+    }
+}


[43/59] [abbrv] ignite git commit: ignite-2065: rename "portable" classes to "binary"

Posted by ak...@apache.org.
http://git-wip-us.apache.org/repos/asf/ignite/blob/71ad9cea/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/binary/distributed/dht/GridCachePortablesPartitionedOnlyByteArrayValuesSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/binary/distributed/dht/GridCachePortablesPartitionedOnlyByteArrayValuesSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/binary/distributed/dht/GridCachePortablesPartitionedOnlyByteArrayValuesSelfTest.java
deleted file mode 100644
index 95630f6..0000000
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/binary/distributed/dht/GridCachePortablesPartitionedOnlyByteArrayValuesSelfTest.java
+++ /dev/null
@@ -1,42 +0,0 @@
-/*
- * 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.processors.cache.binary.distributed.dht;
-
-import org.apache.ignite.configuration.IgniteConfiguration;
-import org.apache.ignite.internal.processors.cache.distributed.dht.GridCacheAbstractPartitionedOnlyByteArrayValuesSelfTest;
-import org.apache.ignite.internal.binary.BinaryMarshaller;
-
-/**
- *
- */
-public class GridCachePortablesPartitionedOnlyByteArrayValuesSelfTest
-    extends GridCacheAbstractPartitionedOnlyByteArrayValuesSelfTest {
-    /** {@inheritDoc} */
-    @Override protected boolean peerClassLoading() {
-        return false;
-    }
-
-    /** {@inheritDoc} */
-    @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception {
-        IgniteConfiguration cfg = super.getConfiguration(gridName);
-
-        cfg.setMarshaller(new BinaryMarshaller());
-
-        return cfg;
-    }
-}

http://git-wip-us.apache.org/repos/asf/ignite/blob/71ad9cea/modules/core/src/test/java/org/apache/ignite/session/GridSessionCheckpointSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/session/GridSessionCheckpointSelfTest.java b/modules/core/src/test/java/org/apache/ignite/session/GridSessionCheckpointSelfTest.java
index ded30cb..f3374c4 100644
--- a/modules/core/src/test/java/org/apache/ignite/session/GridSessionCheckpointSelfTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/session/GridSessionCheckpointSelfTest.java
@@ -21,7 +21,7 @@ import org.apache.ignite.configuration.CacheConfiguration;
 import org.apache.ignite.configuration.IgniteConfiguration;
 import org.apache.ignite.internal.binary.BinaryCachingMetadataHandler;
 import org.apache.ignite.internal.binary.BinaryMarshaller;
-import org.apache.ignite.internal.binary.PortableContext;
+import org.apache.ignite.internal.binary.BinaryContext;
 import org.apache.ignite.internal.util.IgniteUtils;
 import org.apache.ignite.marshaller.Marshaller;
 import org.apache.ignite.marshaller.MarshallerContextTestImpl;
@@ -96,7 +96,7 @@ public class GridSessionCheckpointSelfTest extends GridSessionCheckpointAbstract
         cfg.setCheckpointSpi(spi);
 
         if (cfg.getMarshaller() instanceof BinaryMarshaller) {
-            PortableContext ctx = new PortableContext(BinaryCachingMetadataHandler.create(), cfg);
+            BinaryContext ctx = new BinaryContext(BinaryCachingMetadataHandler.create(), cfg);
 
             Marshaller marsh = cfg.getMarshaller();
 

http://git-wip-us.apache.org/repos/asf/ignite/blob/71ad9cea/modules/core/src/test/java/org/apache/ignite/testframework/junits/IgniteMock.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/testframework/junits/IgniteMock.java b/modules/core/src/test/java/org/apache/ignite/testframework/junits/IgniteMock.java
index 8c8b831..2367688 100644
--- a/modules/core/src/test/java/org/apache/ignite/testframework/junits/IgniteMock.java
+++ b/modules/core/src/test/java/org/apache/ignite/testframework/junits/IgniteMock.java
@@ -51,7 +51,7 @@ import org.apache.ignite.configuration.CollectionConfiguration;
 import org.apache.ignite.configuration.IgniteConfiguration;
 import org.apache.ignite.configuration.NearCacheConfiguration;
 import org.apache.ignite.internal.binary.BinaryCachingMetadataHandler;
-import org.apache.ignite.internal.binary.PortableContext;
+import org.apache.ignite.internal.binary.BinaryContext;
 import org.apache.ignite.internal.binary.builder.BinaryObjectBuilderImpl;
 import org.apache.ignite.internal.processors.cacheobject.NoOpBinary;
 import org.apache.ignite.lang.IgniteProductVersion;
@@ -89,7 +89,7 @@ public class IgniteMock implements Ignite {
     private IgniteBinary binaryMock;
 
     /** */
-    private PortableContext ctx;
+    private BinaryContext ctx;
 
     /**
      * Mock values
@@ -295,7 +295,7 @@ public class IgniteMock implements Ignite {
 
         if (ctx == null) {
             /** {@inheritDoc} */
-            ctx = new PortableContext(BinaryCachingMetadataHandler.create(), configuration()) {
+            ctx = new BinaryContext(BinaryCachingMetadataHandler.create(), configuration()) {
                 @Override public int typeId(String typeName) {
                     return typeName.hashCode();
                 }

http://git-wip-us.apache.org/repos/asf/ignite/blob/71ad9cea/modules/core/src/test/java/org/apache/ignite/testframework/junits/IgniteTestResources.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/testframework/junits/IgniteTestResources.java b/modules/core/src/test/java/org/apache/ignite/testframework/junits/IgniteTestResources.java
index 69ecb4f..67a4f20 100644
--- a/modules/core/src/test/java/org/apache/ignite/testframework/junits/IgniteTestResources.java
+++ b/modules/core/src/test/java/org/apache/ignite/testframework/junits/IgniteTestResources.java
@@ -29,7 +29,7 @@ import org.apache.ignite.IgniteLogger;
 import org.apache.ignite.configuration.IgniteConfiguration;
 import org.apache.ignite.internal.binary.BinaryCachingMetadataHandler;
 import org.apache.ignite.internal.binary.BinaryMarshaller;
-import org.apache.ignite.internal.binary.PortableContext;
+import org.apache.ignite.internal.binary.BinaryContext;
 import org.apache.ignite.internal.processors.resource.GridResourceProcessor;
 import org.apache.ignite.internal.util.IgniteUtils;
 import org.apache.ignite.internal.util.typedef.internal.U;
@@ -264,7 +264,7 @@ public class IgniteTestResources {
         marsh.setContext(new MarshallerContextTestImpl());
 
         if (marsh instanceof BinaryMarshaller) {
-            PortableContext ctx = new PortableContext(BinaryCachingMetadataHandler.create(), new IgniteConfiguration());
+            BinaryContext ctx = new BinaryContext(BinaryCachingMetadataHandler.create(), new IgniteConfiguration());
 
             IgniteUtils.invoke(BinaryMarshaller.class, marsh, "setPortableContext", ctx, new IgniteConfiguration());
         }

http://git-wip-us.apache.org/repos/asf/ignite/blob/71ad9cea/modules/core/src/test/java/org/apache/ignite/testsuites/IgnitePortableCacheTestSuite.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/testsuites/IgnitePortableCacheTestSuite.java b/modules/core/src/test/java/org/apache/ignite/testsuites/IgnitePortableCacheTestSuite.java
index f569718..f5745d8 100644
--- a/modules/core/src/test/java/org/apache/ignite/testsuites/IgnitePortableCacheTestSuite.java
+++ b/modules/core/src/test/java/org/apache/ignite/testsuites/IgnitePortableCacheTestSuite.java
@@ -28,21 +28,21 @@ import org.apache.ignite.internal.processors.cache.GridCacheOffHeapTieredEvictio
 import org.apache.ignite.internal.processors.cache.GridCacheOffHeapTieredEvictionSelfTest;
 import org.apache.ignite.internal.processors.cache.GridCacheOffHeapTieredSelfTest;
 import org.apache.ignite.internal.processors.cache.expiry.IgniteCacheAtomicLocalExpiryPolicyTest;
-import org.apache.ignite.internal.processors.cache.binary.GridPortableCacheEntryMemorySizeSelfTest;
-import org.apache.ignite.internal.processors.cache.binary.datastreaming.DataStreamProcessorPortableSelfTest;
+import org.apache.ignite.internal.processors.cache.binary.GridBinaryCacheEntryMemorySizeSelfTest;
+import org.apache.ignite.internal.processors.cache.binary.datastreaming.DataStreamProcessorBinarySelfTest;
 import org.apache.ignite.internal.processors.cache.binary.datastreaming.GridDataStreamerImplSelfTest;
-import org.apache.ignite.internal.processors.cache.binary.distributed.dht.GridCacheAffinityRoutingPortableSelfTest;
-import org.apache.ignite.internal.processors.cache.binary.distributed.dht.GridCacheAtomicPartitionedOnlyPortableDataStreamerMultiNodeSelfTest;
-import org.apache.ignite.internal.processors.cache.binary.distributed.dht.GridCacheAtomicPartitionedOnlyPortableDataStreamerMultithreadedSelfTest;
-import org.apache.ignite.internal.processors.cache.binary.distributed.dht.GridCacheAtomicPartitionedOnlyPortableMultiNodeSelfTest;
-import org.apache.ignite.internal.processors.cache.binary.distributed.dht.GridCacheAtomicPartitionedOnlyPortableMultithreadedSelfTest;
-import org.apache.ignite.internal.processors.cache.binary.distributed.dht.GridCacheMemoryModePortableSelfTest;
-import org.apache.ignite.internal.processors.cache.binary.distributed.dht.GridCacheOffHeapTieredAtomicPortableSelfTest;
-import org.apache.ignite.internal.processors.cache.binary.distributed.dht.GridCacheOffHeapTieredEvictionAtomicPortableSelfTest;
-import org.apache.ignite.internal.processors.cache.binary.distributed.dht.GridCacheOffHeapTieredEvictionPortableSelfTest;
-import org.apache.ignite.internal.processors.cache.binary.distributed.dht.GridCacheOffHeapTieredPortableSelfTest;
+import org.apache.ignite.internal.processors.cache.binary.distributed.dht.GridCacheAffinityRoutingBinarySelfTest;
+import org.apache.ignite.internal.processors.cache.binary.distributed.dht.GridCacheAtomicPartitionedOnlyBinaryDataStreamerMultiNodeSelfTest;
+import org.apache.ignite.internal.processors.cache.binary.distributed.dht.GridCacheAtomicPartitionedOnlyBinaryDataStreamerMultithreadedSelfTest;
+import org.apache.ignite.internal.processors.cache.binary.distributed.dht.GridCacheAtomicPartitionedOnlyBinaryMultiNodeSelfTest;
+import org.apache.ignite.internal.processors.cache.binary.distributed.dht.GridCacheAtomicPartitionedOnlyBinaryMultithreadedSelfTest;
+import org.apache.ignite.internal.processors.cache.binary.distributed.dht.GridCacheMemoryModeBinarySelfTest;
+import org.apache.ignite.internal.processors.cache.binary.distributed.dht.GridCacheOffHeapTieredAtomicBinarySelfTest;
+import org.apache.ignite.internal.processors.cache.binary.distributed.dht.GridCacheOffHeapTieredEvictionAtomicBinarySelfTest;
+import org.apache.ignite.internal.processors.cache.binary.distributed.dht.GridCacheOffHeapTieredEvictionBinarySelfTest;
+import org.apache.ignite.internal.processors.cache.binary.distributed.dht.GridCacheOffHeapTieredBinarySelfTest;
 import org.apache.ignite.internal.processors.cache.binary.distributed.dht.GridCachePortablesNearPartitionedByteArrayValuesSelfTest;
-import org.apache.ignite.internal.processors.cache.binary.distributed.dht.GridCachePortablesPartitionedOnlyByteArrayValuesSelfTest;
+import org.apache.ignite.internal.processors.cache.binary.distributed.dht.GridCacheBinariesPartitionedOnlyByteArrayValuesSelfTest;
 import org.apache.ignite.internal.processors.datastreamer.DataStreamProcessorSelfTest;
 import org.apache.ignite.testframework.config.GridTestProperties;
 
@@ -76,25 +76,25 @@ public class IgnitePortableCacheTestSuite extends TestSuite {
 
         suite.addTest(IgniteCacheTestSuite.suite(ignoredTests));
 
-        suite.addTestSuite(GridCacheMemoryModePortableSelfTest.class);
-        suite.addTestSuite(GridCacheOffHeapTieredEvictionAtomicPortableSelfTest.class);
-        suite.addTestSuite(GridCacheOffHeapTieredEvictionPortableSelfTest.class);
+        suite.addTestSuite(GridCacheMemoryModeBinarySelfTest.class);
+        suite.addTestSuite(GridCacheOffHeapTieredEvictionAtomicBinarySelfTest.class);
+        suite.addTestSuite(GridCacheOffHeapTieredEvictionBinarySelfTest.class);
 
-        suite.addTestSuite(GridCachePortablesPartitionedOnlyByteArrayValuesSelfTest.class);
+        suite.addTestSuite(GridCacheBinariesPartitionedOnlyByteArrayValuesSelfTest.class);
         suite.addTestSuite(GridCachePortablesNearPartitionedByteArrayValuesSelfTest.class);
-        suite.addTestSuite(GridCacheOffHeapTieredPortableSelfTest.class);
-        suite.addTestSuite(GridCacheOffHeapTieredAtomicPortableSelfTest.class);
+        suite.addTestSuite(GridCacheOffHeapTieredBinarySelfTest.class);
+        suite.addTestSuite(GridCacheOffHeapTieredAtomicBinarySelfTest.class);
 
         suite.addTestSuite(GridDataStreamerImplSelfTest.class);
-        suite.addTestSuite(DataStreamProcessorPortableSelfTest.class);
-        suite.addTestSuite(GridCacheAtomicPartitionedOnlyPortableDataStreamerMultiNodeSelfTest.class);
-        suite.addTestSuite(GridCacheAtomicPartitionedOnlyPortableDataStreamerMultithreadedSelfTest.class);
+        suite.addTestSuite(DataStreamProcessorBinarySelfTest.class);
+        suite.addTestSuite(GridCacheAtomicPartitionedOnlyBinaryDataStreamerMultiNodeSelfTest.class);
+        suite.addTestSuite(GridCacheAtomicPartitionedOnlyBinaryDataStreamerMultithreadedSelfTest.class);
 
-        suite.addTestSuite(GridCacheAtomicPartitionedOnlyPortableMultiNodeSelfTest.class);
-        suite.addTestSuite(GridCacheAtomicPartitionedOnlyPortableMultithreadedSelfTest.class);
+        suite.addTestSuite(GridCacheAtomicPartitionedOnlyBinaryMultiNodeSelfTest.class);
+        suite.addTestSuite(GridCacheAtomicPartitionedOnlyBinaryMultithreadedSelfTest.class);
 
-        suite.addTestSuite(GridCacheAffinityRoutingPortableSelfTest.class);
-        suite.addTestSuite(GridPortableCacheEntryMemorySizeSelfTest.class);
+        suite.addTestSuite(GridCacheAffinityRoutingBinarySelfTest.class);
+        suite.addTestSuite(GridBinaryCacheEntryMemorySizeSelfTest.class);
 
         return suite;
     }

http://git-wip-us.apache.org/repos/asf/ignite/blob/71ad9cea/modules/core/src/test/java/org/apache/ignite/testsuites/IgnitePortableObjectsTestSuite.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/testsuites/IgnitePortableObjectsTestSuite.java b/modules/core/src/test/java/org/apache/ignite/testsuites/IgnitePortableObjectsTestSuite.java
index 4329225..942a5fa 100644
--- a/modules/core/src/test/java/org/apache/ignite/testsuites/IgnitePortableObjectsTestSuite.java
+++ b/modules/core/src/test/java/org/apache/ignite/testsuites/IgnitePortableObjectsTestSuite.java
@@ -19,10 +19,10 @@ package org.apache.ignite.testsuites;
 
 import junit.framework.TestSuite;
 import org.apache.ignite.internal.binary.BinaryEnumsSelfTest;
-import org.apache.ignite.internal.binary.GridPortableAffinityKeySelfTest;
+import org.apache.ignite.internal.binary.GridBinaryAffinityKeySelfTest;
 import org.apache.ignite.internal.binary.BinaryObjectBuilderAdditionalSelfTest;
 import org.apache.ignite.internal.binary.BinaryObjectBuilderSelfTest;
-import org.apache.ignite.internal.binary.GridPortableMarshallerCtxDisabledSelfTest;
+import org.apache.ignite.internal.binary.GridBinaryMarshallerCtxDisabledSelfTest;
 import org.apache.ignite.internal.binary.BinaryMarshallerSelfTest;
 import org.apache.ignite.internal.binary.GridPortableMetaDataSelfTest;
 import org.apache.ignite.internal.binary.GridPortableWildcardsSelfTest;
@@ -40,8 +40,8 @@ import org.apache.ignite.internal.binary.noncompact.BinaryObjectBuilderNonCompac
 import org.apache.ignite.internal.processors.cache.distributed.IgniteBinaryMetadataUpdateChangingTopologySelfTest;
 import org.apache.ignite.internal.processors.cache.binary.GridCacheClientNodeBinaryObjectMetadataMultinodeTest;
 import org.apache.ignite.internal.processors.cache.binary.GridCacheClientNodeBinaryObjectMetadataTest;
-import org.apache.ignite.internal.processors.cache.binary.GridCachePortableStoreObjectsSelfTest;
-import org.apache.ignite.internal.processors.cache.binary.GridCachePortableStorePortablesSelfTest;
+import org.apache.ignite.internal.processors.cache.binary.GridCacheBinaryStoreObjectsSelfTest;
+import org.apache.ignite.internal.processors.cache.binary.GridCacheBinaryStorePortablesSelfTest;
 import org.apache.ignite.internal.processors.cache.binary.distributed.dht.GridCacheBinaryObjectsAtomicNearDisabledOffheapTieredSelfTest;
 import org.apache.ignite.internal.processors.cache.binary.distributed.dht.GridCacheBinaryObjectsAtomicNearDisabledSelfTest;
 import org.apache.ignite.internal.processors.cache.binary.distributed.dht.GridCacheBinaryObjectsAtomicOffheapTieredSelfTest;
@@ -67,7 +67,7 @@ public class IgnitePortableObjectsTestSuite extends TestSuite {
         TestSuite suite = new TestSuite("Ignite Binary Objects Test Suite");
 
         suite.addTestSuite(BinaryMarshallerSelfTest.class);
-        suite.addTestSuite(GridPortableMarshallerCtxDisabledSelfTest.class);
+        suite.addTestSuite(GridBinaryMarshallerCtxDisabledSelfTest.class);
         suite.addTestSuite(BinaryObjectBuilderSelfTest.class);
         suite.addTestSuite(BinaryObjectBuilderAdditionalSelfTest.class);
         suite.addTestSuite(BinaryFieldsHeapSelfTest.class);
@@ -76,7 +76,7 @@ public class IgnitePortableObjectsTestSuite extends TestSuite {
         suite.addTestSuite(BinaryFooterOffsetsOffheapSelfTest.class);
         suite.addTestSuite(BinaryEnumsSelfTest.class);
         suite.addTestSuite(GridPortableMetaDataSelfTest.class);
-        suite.addTestSuite(GridPortableAffinityKeySelfTest.class);
+        suite.addTestSuite(GridBinaryAffinityKeySelfTest.class);
         suite.addTestSuite(GridPortableWildcardsSelfTest.class);
 
         // Tests for objects with non-compact footers.
@@ -102,8 +102,8 @@ public class IgnitePortableObjectsTestSuite extends TestSuite {
         suite.addTestSuite(GridCacheBinaryObjectsPartitionedOffheapTieredSelfTest.class);
         suite.addTestSuite(GridCacheBinaryObjectsPartitionedNearDisabledOffheapTieredSelfTest.class);
 
-        suite.addTestSuite(GridCachePortableStoreObjectsSelfTest.class);
-        suite.addTestSuite(GridCachePortableStorePortablesSelfTest.class);
+        suite.addTestSuite(GridCacheBinaryStoreObjectsSelfTest.class);
+        suite.addTestSuite(GridCacheBinaryStorePortablesSelfTest.class);
 
         suite.addTestSuite(GridCacheClientNodeBinaryObjectMetadataTest.class);
         suite.addTestSuite(GridCacheClientNodeBinaryObjectMetadataMultinodeTest.class);

http://git-wip-us.apache.org/repos/asf/ignite/blob/71ad9cea/modules/extdata/p2p/src/main/java/org/apache/ignite/tests/p2p/CacheDeploymentBinaryEntryProcessor.java
----------------------------------------------------------------------
diff --git a/modules/extdata/p2p/src/main/java/org/apache/ignite/tests/p2p/CacheDeploymentBinaryEntryProcessor.java b/modules/extdata/p2p/src/main/java/org/apache/ignite/tests/p2p/CacheDeploymentBinaryEntryProcessor.java
new file mode 100644
index 0000000..7b94613
--- /dev/null
+++ b/modules/extdata/p2p/src/main/java/org/apache/ignite/tests/p2p/CacheDeploymentBinaryEntryProcessor.java
@@ -0,0 +1,35 @@
+/*
+ * 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.tests.p2p;
+
+import javax.cache.processor.EntryProcessorException;
+import javax.cache.processor.MutableEntry;
+import org.apache.ignite.cache.CacheEntryProcessor;
+
+/**
+ * Entry processor used by {@code GridCacheEntryProcessorDeploymentSelfTest}.
+ */
+public class CacheDeploymentBinaryEntryProcessor implements CacheEntryProcessor<String, String, Boolean> {
+    /** {@inheritDoc} */
+    @Override public Boolean process(MutableEntry<String, String> entry, Object... arguments)
+        throws EntryProcessorException {
+        String val = entry.getKey();
+
+        return true;
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/71ad9cea/modules/extdata/p2p/src/main/java/org/apache/ignite/tests/p2p/CacheDeploymentPortableEntryProcessor.java
----------------------------------------------------------------------
diff --git a/modules/extdata/p2p/src/main/java/org/apache/ignite/tests/p2p/CacheDeploymentPortableEntryProcessor.java b/modules/extdata/p2p/src/main/java/org/apache/ignite/tests/p2p/CacheDeploymentPortableEntryProcessor.java
deleted file mode 100644
index 03d3efc..0000000
--- a/modules/extdata/p2p/src/main/java/org/apache/ignite/tests/p2p/CacheDeploymentPortableEntryProcessor.java
+++ /dev/null
@@ -1,35 +0,0 @@
-/*
- * 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.tests.p2p;
-
-import javax.cache.processor.EntryProcessorException;
-import javax.cache.processor.MutableEntry;
-import org.apache.ignite.cache.CacheEntryProcessor;
-
-/**
- * Entry processor used by {@code GridCacheEntryProcessorDeploymentSelfTest}.
- */
-public class CacheDeploymentPortableEntryProcessor implements CacheEntryProcessor<String, String, Boolean> {
-    /** {@inheritDoc} */
-    @Override public Boolean process(MutableEntry<String, String> entry, Object... arguments)
-        throws EntryProcessorException {
-        String val = entry.getKey();
-
-        return true;
-    }
-}

http://git-wip-us.apache.org/repos/asf/ignite/blob/71ad9cea/modules/indexing/src/test/java/org/apache/ignite/testsuites/IgnitePortableCacheQueryTestSuite.java
----------------------------------------------------------------------
diff --git a/modules/indexing/src/test/java/org/apache/ignite/testsuites/IgnitePortableCacheQueryTestSuite.java b/modules/indexing/src/test/java/org/apache/ignite/testsuites/IgnitePortableCacheQueryTestSuite.java
index 3773f8c..2df9026 100644
--- a/modules/indexing/src/test/java/org/apache/ignite/testsuites/IgnitePortableCacheQueryTestSuite.java
+++ b/modules/indexing/src/test/java/org/apache/ignite/testsuites/IgnitePortableCacheQueryTestSuite.java
@@ -35,8 +35,8 @@ import org.apache.ignite.internal.processors.cache.IgniteCachePartitionedQueryMu
 import org.apache.ignite.internal.processors.cache.IgniteCacheQueryEvictsMultiThreadedSelfTest;
 import org.apache.ignite.internal.processors.cache.IgniteCacheQueryMultiThreadedSelfTest;
 import org.apache.ignite.internal.processors.cache.IgniteCacheQueryOffheapMultiThreadedSelfTest;
-import org.apache.ignite.internal.processors.cache.binary.distributed.dht.GridCachePortableDuplicateIndexObjectPartitionedAtomicSelfTest;
-import org.apache.ignite.internal.processors.cache.binary.distributed.dht.GridCachePortableDuplicateIndexObjectPartitionedTransactionalSelfTest;
+import org.apache.ignite.internal.processors.cache.binary.distributed.dht.GridCacheBinaryDuplicateIndexObjectPartitionedAtomicSelfTest;
+import org.apache.ignite.internal.processors.cache.binary.distributed.dht.GridCacheBinaryDuplicateIndexObjectPartitionedTransactionalSelfTest;
 import org.apache.ignite.internal.processors.cache.query.continuous.GridCacheContinuousQueryAtomicNearEnabledSelfTest;
 import org.apache.ignite.internal.processors.cache.query.continuous.GridCacheContinuousQueryAtomicP2PDisabledSelfTest;
 import org.apache.ignite.internal.processors.cache.query.continuous.GridCacheContinuousQueryAtomicSelfTest;
@@ -111,8 +111,8 @@ public class IgnitePortableCacheQueryTestSuite extends TestSuite {
         //Unmarshallig query test.
         suite.addTestSuite(IgniteCacheP2pUnmarshallingQueryErrorTest.class);
 
-        suite.addTestSuite(GridCachePortableDuplicateIndexObjectPartitionedAtomicSelfTest.class);
-        suite.addTestSuite(GridCachePortableDuplicateIndexObjectPartitionedTransactionalSelfTest.class);
+        suite.addTestSuite(GridCacheBinaryDuplicateIndexObjectPartitionedAtomicSelfTest.class);
+        suite.addTestSuite(GridCacheBinaryDuplicateIndexObjectPartitionedTransactionalSelfTest.class);
 
         return suite;
     }


[17/59] [abbrv] ignite git commit: ignite-2065: rename "portable" packages to "binary"

Posted by ak...@apache.org.
http://git-wip-us.apache.org/repos/asf/ignite/blob/1dbf20e0/modules/core/src/main/java/org/apache/ignite/internal/portable/builder/BinaryObjectBuilderImpl.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/portable/builder/BinaryObjectBuilderImpl.java b/modules/core/src/main/java/org/apache/ignite/internal/portable/builder/BinaryObjectBuilderImpl.java
deleted file mode 100644
index c4ce9e6..0000000
--- a/modules/core/src/main/java/org/apache/ignite/internal/portable/builder/BinaryObjectBuilderImpl.java
+++ /dev/null
@@ -1,580 +0,0 @@
-/*
- * 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.portable.builder;
-
-import org.apache.ignite.binary.BinaryInvalidTypeException;
-import org.apache.ignite.binary.BinaryObject;
-import org.apache.ignite.binary.BinaryObjectBuilder;
-import org.apache.ignite.binary.BinaryObjectException;
-import org.apache.ignite.binary.BinaryType;
-import org.apache.ignite.internal.portable.BinaryMetadata;
-import org.apache.ignite.internal.portable.BinaryObjectImpl;
-import org.apache.ignite.internal.portable.BinaryObjectOffheapImpl;
-import org.apache.ignite.internal.portable.BinaryWriterExImpl;
-import org.apache.ignite.internal.portable.GridPortableMarshaller;
-import org.apache.ignite.internal.portable.PortableContext;
-import org.apache.ignite.internal.portable.PortableSchema;
-import org.apache.ignite.internal.portable.PortableSchemaRegistry;
-import org.apache.ignite.internal.portable.PortableUtils;
-import org.apache.ignite.internal.util.typedef.F;
-import org.apache.ignite.internal.util.typedef.internal.U;
-import org.apache.ignite.lang.IgniteBiTuple;
-import org.jetbrains.annotations.Nullable;
-
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.LinkedHashMap;
-import java.util.Map;
-import java.util.Set;
-
-import static org.apache.ignite.internal.portable.GridPortableMarshaller.DFLT_HDR_LEN;
-import static org.apache.ignite.internal.portable.GridPortableMarshaller.FLAGS_POS;
-import static org.apache.ignite.internal.portable.GridPortableMarshaller.HASH_CODE_POS;
-import static org.apache.ignite.internal.portable.GridPortableMarshaller.PROTO_VER_POS;
-import static org.apache.ignite.internal.portable.GridPortableMarshaller.TYPE_ID_POS;
-import static org.apache.ignite.internal.portable.GridPortableMarshaller.UNREGISTERED_TYPE_ID;
-
-/**
- *
- */
-public class BinaryObjectBuilderImpl implements BinaryObjectBuilder {
-    /** */
-    private static final Object REMOVED_FIELD_MARKER = new Object();
-
-    /** */
-    private final PortableContext ctx;
-
-    /** */
-    private final int typeId;
-
-    /** May be null. */
-    private String typeName;
-
-    /** May be null. */
-    private String clsNameToWrite;
-
-    /** */
-    private boolean registeredType = true;
-
-    /** */
-    private Map<String, Object> assignedVals;
-
-    /** */
-    private Map<Integer, Object> readCache;
-
-    /** Position of object in source array, or -1 if object is not created from PortableObject. */
-    private final int start;
-
-    /** Flags. */
-    private final short flags;
-
-    /** Total header length */
-    private final int hdrLen;
-
-    /** Context of PortableObject reading process. Or {@code null} if object is not created from PortableObject. */
-    private final PortableBuilderReader reader;
-
-    /** */
-    private int hashCode;
-
-    /**
-     * @param clsName Class name.
-     * @param ctx Portable context.
-     */
-    public BinaryObjectBuilderImpl(PortableContext ctx, String clsName) {
-        this(ctx, ctx.typeId(clsName), PortableContext.typeName(clsName));
-    }
-
-    /**
-     * @param typeName Type name.
-     * @param ctx Context.
-     * @param typeId Type id.
-     */
-    public BinaryObjectBuilderImpl(PortableContext ctx, int typeId, String typeName) {
-        this.typeId = typeId;
-        this.typeName = typeName;
-        this.ctx = ctx;
-
-        start = -1;
-        flags = -1;
-        reader = null;
-        hdrLen = DFLT_HDR_LEN;
-
-        readCache = Collections.emptyMap();
-    }
-
-    /**
-     * @param obj Object to wrap.
-     */
-    public BinaryObjectBuilderImpl(BinaryObjectImpl obj) {
-        this(new PortableBuilderReader(obj), obj.start());
-
-        reader.registerObject(this);
-    }
-
-    /**
-     * @param reader ctx
-     * @param start Start.
-     */
-    BinaryObjectBuilderImpl(PortableBuilderReader reader, int start) {
-        this.reader = reader;
-        this.start = start;
-        this.flags = reader.readShortPositioned(start + FLAGS_POS);
-
-        byte ver = reader.readBytePositioned(start + PROTO_VER_POS);
-
-        PortableUtils.checkProtocolVersion(ver);
-
-        int typeId = reader.readIntPositioned(start + TYPE_ID_POS);
-        ctx = reader.portableContext();
-        hashCode = reader.readIntPositioned(start + HASH_CODE_POS);
-
-        if (typeId == UNREGISTERED_TYPE_ID) {
-            int mark = reader.position();
-
-            reader.position(start + DFLT_HDR_LEN);
-
-            clsNameToWrite = reader.readString();
-
-            Class cls;
-
-            try {
-                // TODO: IGNITE-1272 - Is class loader needed here?
-                cls = U.forName(clsNameToWrite, null);
-            }
-            catch (ClassNotFoundException e) {
-                throw new BinaryInvalidTypeException("Failed to load the class: " + clsNameToWrite, e);
-            }
-
-            this.typeId = ctx.descriptorForClass(cls, false).typeId();
-
-            registeredType = false;
-
-            hdrLen = reader.position() - mark;
-
-            reader.position(mark);
-        }
-        else {
-            this.typeId = typeId;
-            hdrLen = DFLT_HDR_LEN;
-        }
-    }
-
-    /** {@inheritDoc} */
-    @Override public BinaryObject build() {
-        try (BinaryWriterExImpl writer = new BinaryWriterExImpl(ctx)) {
-            writer.typeId(typeId);
-
-            PortableBuilderSerializer serializationCtx = new PortableBuilderSerializer();
-
-            serializationCtx.registerObjectWriting(this, 0);
-
-            serializeTo(writer, serializationCtx);
-
-            byte[] arr = writer.array();
-
-            return new BinaryObjectImpl(ctx, arr, 0);
-        }
-    }
-
-    /**
-     * @param writer Writer.
-     * @param serializer Serializer.
-     */
-    void serializeTo(BinaryWriterExImpl writer, PortableBuilderSerializer serializer) {
-        try {
-            writer.preWrite(registeredType ? null : clsNameToWrite);
-
-            Set<Integer> remainsFlds = null;
-
-            if (reader != null) {
-                PortableSchema schema = reader.schema();
-
-                Map<Integer, Object> assignedFldsById;
-
-                if (assignedVals != null) {
-                    assignedFldsById = U.newHashMap(assignedVals.size());
-
-                    for (Map.Entry<String, Object> entry : assignedVals.entrySet()) {
-                        int fieldId = ctx.fieldId(typeId, entry.getKey());
-
-                        assignedFldsById.put(fieldId, entry.getValue());
-                    }
-
-                    remainsFlds = assignedFldsById.keySet();
-                }
-                else
-                    assignedFldsById = Collections.emptyMap();
-
-                // Get footer details.
-                int fieldIdLen = PortableUtils.fieldIdLength(flags);
-                int fieldOffsetLen = PortableUtils.fieldOffsetLength(flags);
-
-                IgniteBiTuple<Integer, Integer> footer = PortableUtils.footerAbsolute(reader, start);
-
-                int footerPos = footer.get1();
-                int footerEnd = footer.get2();
-
-                // Get raw position.
-                int rawPos = PortableUtils.rawOffsetAbsolute(reader, start);
-
-                // Position reader on data.
-                reader.position(start + hdrLen);
-
-                int idx = 0;
-
-                while (reader.position() < rawPos) {
-                    int fieldId = schema.fieldId(idx++);
-                    int fieldLen =
-                        fieldPositionAndLength(footerPos, footerEnd, rawPos, fieldIdLen, fieldOffsetLen).get2();
-
-                    int postPos = reader.position() + fieldLen; // Position where reader will be placed afterwards.
-
-                    footerPos += fieldIdLen + fieldOffsetLen;
-
-                    if (assignedFldsById.containsKey(fieldId)) {
-                        Object assignedVal = assignedFldsById.remove(fieldId);
-
-                        if (assignedVal != REMOVED_FIELD_MARKER) {
-                            writer.writeFieldId(fieldId);
-
-                            serializer.writeValue(writer, assignedVal);
-                        }
-                    }
-                    else {
-                        int type = fieldLen != 0 ? reader.readByte(0) : 0;
-
-                        if (fieldLen != 0 && !PortableUtils.isPlainArrayType(type) && PortableUtils.isPlainType(type)) {
-                            writer.writeFieldId(fieldId);
-
-                            writer.write(reader.array(), reader.position(), fieldLen);
-                        }
-                        else {
-                            writer.writeFieldId(fieldId);
-
-                            Object val;
-
-                            if (fieldLen == 0)
-                                val = null;
-                            else if (readCache == null) {
-                                val = reader.parseValue();
-
-                                assert reader.position() == postPos;
-                            }
-                            else
-                                val = readCache.get(fieldId);
-
-                            serializer.writeValue(writer, val);
-                        }
-                    }
-
-                    reader.position(postPos);
-                }
-            }
-
-            BinaryType meta = ctx.metadata(typeId);
-
-            Map<String, Integer> fieldsMeta = null;
-
-            if (assignedVals != null && (remainsFlds == null || !remainsFlds.isEmpty())) {
-                for (Map.Entry<String, Object> entry : assignedVals.entrySet()) {
-                    Object val = entry.getValue();
-
-                    if (val == REMOVED_FIELD_MARKER)
-                        continue;
-
-                    String name = entry.getKey();
-
-                    int fieldId = ctx.fieldId(typeId, name);
-
-                    if (remainsFlds != null && !remainsFlds.contains(fieldId))
-                        continue;
-
-                    writer.writeFieldId(fieldId);
-
-                    serializer.writeValue(writer, val);
-
-                    String oldFldTypeName = meta == null ? null : meta.fieldTypeName(name);
-
-                    boolean nullObjField = false;
-
-                    int newFldTypeId;
-
-                    if (val instanceof PortableValueWithType) {
-                        newFldTypeId = ((PortableValueWithType)val).typeId();
-
-                        if (newFldTypeId == GridPortableMarshaller.OBJ && ((PortableValueWithType)val).value() == null)
-                            nullObjField = true;
-                    }
-                    else
-                        newFldTypeId = PortableUtils.typeByClass(val.getClass());
-
-                    String newFldTypeName = PortableUtils.fieldTypeName(newFldTypeId);
-
-                    if (oldFldTypeName == null) {
-                        // It's a new field, we have to add it to metadata.
-                        if (fieldsMeta == null)
-                            fieldsMeta = new HashMap<>();
-
-                        fieldsMeta.put(name, PortableUtils.fieldTypeId(newFldTypeName));
-                    }
-                    else if (!nullObjField) {
-                        String objTypeName = PortableUtils.fieldTypeName(GridPortableMarshaller.OBJ);
-
-                        if (!objTypeName.equals(oldFldTypeName) && !oldFldTypeName.equals(newFldTypeName)) {
-                            throw new BinaryObjectException(
-                                "Wrong value has been set [" +
-                                    "typeName=" + (typeName == null ? meta.typeName() : typeName) +
-                                    ", fieldName=" + name +
-                                    ", fieldType=" + oldFldTypeName +
-                                    ", assignedValueType=" + newFldTypeName + ']'
-                            );
-                        }
-                    }
-                }
-            }
-
-            if (reader != null) {
-                // Write raw data if any.
-                int rawOff = PortableUtils.rawOffsetAbsolute(reader, start);
-                int footerStart = PortableUtils.footerStartAbsolute(reader, start);
-
-                if (rawOff < footerStart) {
-                    writer.rawWriter();
-
-                    writer.write(reader.array(), rawOff, footerStart - rawOff);
-                }
-
-                // Shift reader to the end of the object.
-                reader.position(start + PortableUtils.length(reader, start));
-            }
-
-            writer.postWrite(true, registeredType, hashCode);
-
-            // Update metadata if needed.
-            int schemaId = writer.schemaId();
-
-            PortableSchemaRegistry schemaReg = ctx.schemaRegistry(typeId);
-
-            if (schemaReg.schema(schemaId) == null) {
-                String typeName = this.typeName;
-
-                if (typeName == null) {
-                    assert meta != null;
-
-                    typeName = meta.typeName();
-                }
-
-                PortableSchema curSchema = writer.currentSchema();
-
-                ctx.updateMetadata(typeId, new BinaryMetadata(typeId, typeName, fieldsMeta,
-                    ctx.affinityKeyFieldName(typeId), Collections.singleton(curSchema), false));
-
-                schemaReg.addSchema(curSchema.schemaId(), curSchema);
-            }
-        }
-        finally {
-            writer.popSchema();
-        }
-    }
-
-    /** {@inheritDoc} */
-    @Override public BinaryObjectBuilderImpl hashCode(int hashCode) {
-        this.hashCode = hashCode;
-
-        return this;
-    }
-
-    /**
-     * Get field position and length.
-     *
-     * @param footerPos Field position inside the footer (absolute).
-     * @param footerEnd Footer end (absolute).
-     * @param rawPos Raw data position (absolute).
-     * @param fieldIdLen Field ID length.
-     * @param fieldOffsetLen Field offset length.
-     * @return Tuple with field position and length.
-     */
-    private IgniteBiTuple<Integer, Integer> fieldPositionAndLength(int footerPos, int footerEnd, int rawPos,
-        int fieldIdLen, int fieldOffsetLen) {
-        // Get field offset first.
-        int fieldOffset = PortableUtils.fieldOffsetRelative(reader, footerPos + fieldIdLen, fieldOffsetLen);
-        int fieldPos = start + fieldOffset;
-
-        // Get field length.
-        int fieldLen;
-
-        if (footerPos + fieldIdLen + fieldOffsetLen == footerEnd)
-            // This is the last field, compare to raw offset.
-            fieldLen = rawPos - fieldPos;
-        else {
-            // Field is somewhere in the middle, get difference with the next offset.
-            int nextFieldOffset = PortableUtils.fieldOffsetRelative(reader,
-                footerPos + fieldIdLen + fieldOffsetLen + fieldIdLen, fieldOffsetLen);
-
-            fieldLen = nextFieldOffset - fieldOffset;
-        }
-
-        return F.t(fieldPos, fieldLen);
-    }
-
-    /**
-     * Initialize read cache if needed.
-     */
-    private void ensureReadCacheInit() {
-        assert reader != null;
-
-        if (readCache == null) {
-            int fieldIdLen = PortableUtils.fieldIdLength(flags);
-            int fieldOffsetLen = PortableUtils.fieldOffsetLength(flags);
-
-            PortableSchema schema = reader.schema();
-
-            Map<Integer, Object> readCache = new HashMap<>();
-
-            IgniteBiTuple<Integer, Integer> footer = PortableUtils.footerAbsolute(reader, start);
-
-            int footerPos = footer.get1();
-            int footerEnd = footer.get2();
-
-            int rawPos = PortableUtils.rawOffsetAbsolute(reader, start);
-
-            int idx = 0;
-
-            while (footerPos + fieldIdLen < footerEnd) {
-                int fieldId = schema.fieldId(idx++);
-
-                IgniteBiTuple<Integer, Integer> posAndLen =
-                    fieldPositionAndLength(footerPos, footerEnd, rawPos, fieldIdLen, fieldOffsetLen);
-
-                Object val = reader.getValueQuickly(posAndLen.get1(), posAndLen.get2());
-
-                readCache.put(fieldId, val);
-
-                // Shift current footer position.
-                footerPos += fieldIdLen + fieldOffsetLen;
-            }
-
-            this.readCache = readCache;
-        }
-    }
-
-    /** {@inheritDoc} */
-    @SuppressWarnings("unchecked")
-    @Override public <T> T getField(String name) {
-        Object val;
-
-        if (assignedVals != null && assignedVals.containsKey(name)) {
-            val = assignedVals.get(name);
-
-            if (val == REMOVED_FIELD_MARKER)
-                return null;
-        }
-        else {
-            ensureReadCacheInit();
-
-            int fldId = ctx.fieldId(typeId, name);
-
-            val = readCache.get(fldId);
-        }
-
-        return (T)PortableUtils.unwrapLazy(val);
-    }
-
-    /** {@inheritDoc} */
-    @Override public BinaryObjectBuilder setField(String name, Object val0) {
-        Object val = val0 == null ? new PortableValueWithType(PortableUtils.typeByClass(Object.class), null) : val0;
-
-        if (assignedVals == null)
-            assignedVals = new LinkedHashMap<>();
-
-        Object oldVal = assignedVals.put(name, val);
-
-        if (oldVal instanceof PortableValueWithType && val0 != null) {
-            ((PortableValueWithType)oldVal).value(val);
-
-            assignedVals.put(name, oldVal);
-        }
-
-        return this;
-    }
-
-    /** {@inheritDoc} */
-    @Override public <T> BinaryObjectBuilder setField(String name, @Nullable T val, Class<? super T> type) {
-        if (assignedVals == null)
-            assignedVals = new LinkedHashMap<>();
-
-        assignedVals.put(name, new PortableValueWithType(PortableUtils.typeByClass(type), val));
-
-        return this;
-    }
-
-    /** {@inheritDoc} */
-    @Override public BinaryObjectBuilder setField(String name, @Nullable BinaryObjectBuilder builder) {
-        if (builder == null)
-            return setField(name, null, Object.class);
-        else
-            return setField(name, (Object)builder);
-    }
-
-    /**
-     * Removes field from portable object.
-     *
-     * @param name Field name.
-     * @return {@code this} instance for chaining.
-     */
-    @Override public BinaryObjectBuilderImpl removeField(String name) {
-        if (assignedVals == null)
-            assignedVals = new LinkedHashMap<>();
-
-        assignedVals.put(name, REMOVED_FIELD_MARKER);
-
-        return this;
-    }
-
-    /**
-     * Creates builder initialized by specified portable object.
-     *
-     * @param obj Portable object to initialize builder.
-     * @return New builder.
-     */
-    public static BinaryObjectBuilderImpl wrap(BinaryObject obj) {
-        BinaryObjectImpl heapObj;
-
-        if (obj instanceof BinaryObjectOffheapImpl)
-            heapObj = (BinaryObjectImpl)((BinaryObjectOffheapImpl)obj).heapCopy();
-        else
-            heapObj = (BinaryObjectImpl)obj;
-
-        return new BinaryObjectBuilderImpl(heapObj);
-    }
-
-    /**
-     * @return Object start position in source array.
-     */
-    int start() {
-        return start;
-    }
-
-    /**
-     * @return Object type id.
-     */
-    public int typeId() {
-        return typeId;
-    }
-}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ignite/blob/1dbf20e0/modules/core/src/main/java/org/apache/ignite/internal/portable/builder/PortableAbstractLazyValue.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/portable/builder/PortableAbstractLazyValue.java b/modules/core/src/main/java/org/apache/ignite/internal/portable/builder/PortableAbstractLazyValue.java
deleted file mode 100644
index 1f521ac..0000000
--- a/modules/core/src/main/java/org/apache/ignite/internal/portable/builder/PortableAbstractLazyValue.java
+++ /dev/null
@@ -1,57 +0,0 @@
-/*
- * 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.portable.builder;
-
-/**
- *
- */
-abstract class PortableAbstractLazyValue implements PortableLazyValue {
-    /** */
-    protected Object val;
-
-    /** */
-    protected final PortableBuilderReader reader;
-
-    /** */
-    protected final int valOff;
-
-    /**
-     * @param reader Reader.
-     * @param valOff Value.
-     */
-    protected PortableAbstractLazyValue(PortableBuilderReader reader, int valOff) {
-        this.reader = reader;
-        this.valOff = valOff;
-    }
-
-    /**
-     * @return Value.
-     */
-    protected abstract Object init();
-
-    /** {@inheritDoc} */
-    @Override public Object value() {
-        if (val == null) {
-            val = init();
-
-            assert val != null;
-        }
-
-        return val;
-    }
-}

http://git-wip-us.apache.org/repos/asf/ignite/blob/1dbf20e0/modules/core/src/main/java/org/apache/ignite/internal/portable/builder/PortableBuilderEnum.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/portable/builder/PortableBuilderEnum.java b/modules/core/src/main/java/org/apache/ignite/internal/portable/builder/PortableBuilderEnum.java
deleted file mode 100644
index 6f79e73..0000000
--- a/modules/core/src/main/java/org/apache/ignite/internal/portable/builder/PortableBuilderEnum.java
+++ /dev/null
@@ -1,116 +0,0 @@
-/*
- * 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.portable.builder;
-
-import org.apache.ignite.internal.portable.GridPortableMarshaller;
-import org.apache.ignite.internal.portable.BinaryWriterExImpl;
-import org.apache.ignite.internal.util.typedef.internal.U;
-import org.apache.ignite.binary.BinaryInvalidTypeException;
-
-/**
- *
- */
-public class PortableBuilderEnum implements PortableBuilderSerializationAware {
-    /** */
-    private final int ordinal;
-
-    /** */
-    private final int typeId;
-
-    /** */
-    private final String clsName;
-
-    /**
-     * @param typeId Type ID.
-     * @param anEnum Enum instance.
-     */
-    public PortableBuilderEnum(int typeId, Enum anEnum) {
-        ordinal = anEnum.ordinal();
-        this.typeId = typeId;
-        clsName = null;
-    }
-
-    /**
-     * @param reader PortableBuilderReader.
-     */
-    public PortableBuilderEnum(PortableBuilderReader reader) {
-        int typeId = reader.readInt();
-
-        if (typeId == GridPortableMarshaller.UNREGISTERED_TYPE_ID) {
-            clsName = reader.readString();
-
-            Class cls;
-
-            try {
-                // TODO: IGNITE-1272 - Is class loader needed here?
-                cls = U.forName(reader.readString(), null);
-            }
-            catch (ClassNotFoundException e) {
-                throw new BinaryInvalidTypeException("Failed to load the class: " + clsName, e);
-            }
-
-            this.typeId = reader.portableContext().descriptorForClass(cls, false).typeId();
-        }
-        else {
-            this.typeId = typeId;
-            this.clsName = null;
-        }
-
-        ordinal = reader.readInt();
-    }
-
-    /**
-     * @return Ordinal.
-     */
-    public int getOrdinal() {
-        return ordinal;
-    }
-
-    /** {@inheritDoc} */
-    @Override public void writeTo(BinaryWriterExImpl writer, PortableBuilderSerializer ctx) {
-        writer.writeByte(GridPortableMarshaller.ENUM);
-
-        if (typeId == GridPortableMarshaller.UNREGISTERED_TYPE_ID) {
-            writer.writeInt(GridPortableMarshaller.UNREGISTERED_TYPE_ID);
-            writer.writeString(clsName);
-        }
-        else
-            writer.writeInt(typeId);
-
-        writer.writeInt(ordinal);
-    }
-
-    /** {@inheritDoc} */
-    @Override public boolean equals(Object o) {
-        if (o == null || getClass() != o.getClass())
-            return false;
-
-        PortableBuilderEnum that = (PortableBuilderEnum)o;
-
-        return ordinal == that.ordinal && typeId == that.typeId;
-    }
-
-    /** {@inheritDoc} */
-    @Override public int hashCode() {
-        int result = ordinal;
-
-        result = 31 * result + typeId;
-
-        return result;
-    }
-}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ignite/blob/1dbf20e0/modules/core/src/main/java/org/apache/ignite/internal/portable/builder/PortableBuilderReader.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/portable/builder/PortableBuilderReader.java b/modules/core/src/main/java/org/apache/ignite/internal/portable/builder/PortableBuilderReader.java
deleted file mode 100644
index 0b7e0b5..0000000
--- a/modules/core/src/main/java/org/apache/ignite/internal/portable/builder/PortableBuilderReader.java
+++ /dev/null
@@ -1,847 +0,0 @@
-/*
- * 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.portable.builder;
-
-import org.apache.ignite.binary.BinaryObjectException;
-import org.apache.ignite.internal.portable.BinaryObjectImpl;
-import org.apache.ignite.internal.portable.BinaryReaderExImpl;
-import org.apache.ignite.internal.portable.BinaryWriterExImpl;
-import org.apache.ignite.internal.portable.GridPortableMarshaller;
-import org.apache.ignite.internal.portable.PortableContext;
-import org.apache.ignite.internal.portable.PortablePositionReadable;
-import org.apache.ignite.internal.portable.PortablePrimitives;
-import org.apache.ignite.internal.portable.PortableSchema;
-import org.apache.ignite.internal.portable.PortableUtils;
-import org.apache.ignite.internal.portable.streams.PortableHeapInputStream;
-
-import java.sql.Timestamp;
-import java.util.Date;
-import java.util.HashMap;
-import java.util.Map;
-
-import static java.nio.charset.StandardCharsets.UTF_8;
-import static org.apache.ignite.internal.portable.GridPortableMarshaller.NULL;
-import static org.apache.ignite.internal.portable.GridPortableMarshaller.STRING;
-
-/**
- *
- */
-public class PortableBuilderReader implements PortablePositionReadable {
-    /** */
-    private final PortableContext ctx;
-
-    /** */
-    private final byte[] arr;
-
-    /** */
-    private final BinaryReaderExImpl reader;
-
-    /** */
-    private final Map<Integer, BinaryObjectBuilderImpl> objMap;
-
-    /** */
-    private int pos;
-
-    /*
-     * Constructor.
-     *
-     * @param objImpl Portable object
-     */
-    PortableBuilderReader(BinaryObjectImpl objImpl) {
-        ctx = objImpl.context();
-        arr = objImpl.array();
-        pos = objImpl.start();
-
-        // TODO: IGNITE-1272 - Is class loader needed here?
-        reader = new BinaryReaderExImpl(ctx, PortableHeapInputStream.create(arr, pos), null);
-
-        objMap = new HashMap<>();
-    }
-
-    /**
-     * Copying constructor.
-     *
-     * @param other Other reader.
-     * @param start Start position.
-     */
-    PortableBuilderReader(PortableBuilderReader other, int start) {
-        this.ctx = other.ctx;
-        this.arr = other.arr;
-        this.pos = start;
-
-        reader = new BinaryReaderExImpl(ctx, PortableHeapInputStream.create(arr, start), null, other.reader.handles());
-
-        this.objMap = other.objMap;
-    }
-
-    /**
-     * @return Portable context.
-     */
-    public PortableContext portableContext() {
-        return ctx;
-    }
-
-    /**
-     * @param obj Mutable portable object.
-     */
-    public void registerObject(BinaryObjectBuilderImpl obj) {
-        objMap.put(obj.start(), obj);
-    }
-
-    /**
-     * Get schema of the object, starting at the given position.
-     *
-     * @return Object's schema.
-     */
-    public PortableSchema schema() {
-        return reader.getOrCreateSchema();
-    }
-
-    /**
-     * @return Read int value.
-     */
-    public int readInt() {
-        int res = readInt(0);
-
-        pos += 4;
-
-        return res;
-    }
-
-    /**
-     * @return Read int value.
-     */
-    public byte readByte() {
-        return arr[pos++];
-    }
-
-    /**
-     * @return Read boolean value.
-     */
-    public boolean readBoolean() {
-        return readByte() == 1;
-    }
-
-    /**
-     * @return Read int value.
-     */
-    public byte readByte(int off) {
-        return arr[pos + off];
-    }
-
-    /**
-     * @param off Offset related to {@link #pos}
-     * @return Read int value.
-     */
-    public int readInt(int off) {
-        return PortablePrimitives.readInt(arr, pos + off);
-    }
-
-    /**
-     * @param pos Position in the source array.
-     * @return Read byte value.
-     */
-    public byte readBytePositioned(int pos) {
-        return PortablePrimitives.readByte(arr, pos);
-    }
-
-    /** {@inheritDoc} */
-    @Override public short readShortPositioned(int pos) {
-        return PortablePrimitives.readShort(arr, pos);
-    }
-
-    /** {@inheritDoc} */
-    @Override public int readIntPositioned(int pos) {
-        return PortablePrimitives.readInt(arr, pos);
-    }
-
-    /**
-     * @return Read length of array.
-     */
-    public int readLength() {
-        return PortablePrimitives.readInt(arr, pos);
-    }
-
-    /**
-     * Read string length.
-     *
-     * @return String length.
-     */
-    public int readStringLength() {
-        return PortablePrimitives.readInt(arr, pos);
-    }
-
-    /**
-     * Reads string.
-     *
-     * @return String.
-     */
-    public String readString() {
-        byte flag = readByte();
-
-        if (flag == NULL)
-            return null;
-
-        if (flag != STRING)
-            throw new BinaryObjectException("Failed to deserialize String.");
-
-        int len = readInt();
-
-        String str = new String(arr, pos, len, UTF_8);
-
-        pos += len;
-
-        return str;
-    }
-
-    /**
-     *
-     */
-    public void skipValue() {
-        byte type = arr[pos++];
-
-        int len;
-
-        switch (type) {
-            case GridPortableMarshaller.NULL:
-                return;
-
-            case GridPortableMarshaller.OBJ:
-                pos += readInt(GridPortableMarshaller.TOTAL_LEN_POS - 1) - 1;
-
-                return;
-
-            case GridPortableMarshaller.BOOLEAN:
-            case GridPortableMarshaller.BYTE:
-                len = 1;
-                break;
-
-            case GridPortableMarshaller.CHAR:
-            case GridPortableMarshaller.SHORT:
-                len = 2;
-
-                break;
-
-            case GridPortableMarshaller.HANDLE:
-            case GridPortableMarshaller.FLOAT:
-            case GridPortableMarshaller.INT:
-                len = 4;
-
-                break;
-
-            case GridPortableMarshaller.ENUM:
-                //skipping type id and ordinal value
-                len = 8;
-
-                break;
-
-            case GridPortableMarshaller.LONG:
-            case GridPortableMarshaller.DOUBLE:
-                len = 8;
-
-                break;
-
-            case GridPortableMarshaller.BYTE_ARR:
-            case GridPortableMarshaller.BOOLEAN_ARR:
-                len = 4 + readLength();
-
-                break;
-
-            case GridPortableMarshaller.STRING:
-                len = 4 + readStringLength();
-
-                break;
-
-            case GridPortableMarshaller.DECIMAL:
-                len = /** scale */ 4  + /** mag len */ 4  + /** mag bytes count */ readInt(4);
-
-                break;
-
-            case GridPortableMarshaller.UUID:
-                len = 8 + 8;
-
-                break;
-
-            case GridPortableMarshaller.DATE:
-                len = 8;
-
-                break;
-
-            case GridPortableMarshaller.TIMESTAMP:
-                len = 8 + 4;
-
-                break;
-
-            case GridPortableMarshaller.CHAR_ARR:
-            case GridPortableMarshaller.SHORT_ARR:
-                len = 4 + readLength() * 2;
-
-                break;
-
-            case GridPortableMarshaller.INT_ARR:
-            case GridPortableMarshaller.FLOAT_ARR:
-                len = 4 + readLength() * 4;
-
-                break;
-
-            case GridPortableMarshaller.LONG_ARR:
-            case GridPortableMarshaller.DOUBLE_ARR:
-                len = 4 + readLength() * 8;
-
-                break;
-
-            case GridPortableMarshaller.DECIMAL_ARR:
-            case GridPortableMarshaller.DATE_ARR:
-            case GridPortableMarshaller.TIMESTAMP_ARR:
-            case GridPortableMarshaller.OBJ_ARR:
-            case GridPortableMarshaller.ENUM_ARR:
-            case GridPortableMarshaller.UUID_ARR:
-            case GridPortableMarshaller.STRING_ARR: {
-                int size = readInt();
-
-                for (int i = 0; i < size; i++)
-                    skipValue();
-
-                return;
-            }
-
-            case GridPortableMarshaller.COL: {
-                int size = readInt();
-
-                pos++; // skip collection type
-
-                for (int i = 0; i < size; i++)
-                    skipValue();
-
-                return;
-            }
-
-            case GridPortableMarshaller.MAP: {
-                int size = readInt();
-
-                pos++; // skip collection type
-
-                for (int i = 0; i < size; i++) {
-                    skipValue(); // skip key.
-                    skipValue(); // skip value.
-                }
-
-                return;
-            }
-
-            case GridPortableMarshaller.PORTABLE_OBJ:
-                len = readInt() + 4;
-
-                break;
-
-            default:
-                throw new BinaryObjectException("Invalid flag value: " + type);
-        }
-
-        pos += len;
-    }
-
-    /**
-     * @param pos Position.
-     * @param len Length.
-     * @return Object.
-     */
-    public Object getValueQuickly(int pos, int len) {
-        byte type = arr[pos];
-
-        switch (type) {
-            case GridPortableMarshaller.NULL:
-                return null;
-
-            case GridPortableMarshaller.HANDLE: {
-                int objStart = pos - readIntPositioned(pos + 1);
-
-                BinaryObjectBuilderImpl res = objMap.get(objStart);
-
-                if (res == null) {
-                    res = new BinaryObjectBuilderImpl(new PortableBuilderReader(this, objStart), objStart);
-
-                    objMap.put(objStart, res);
-                }
-
-                return res;
-            }
-
-            case GridPortableMarshaller.OBJ: {
-                BinaryObjectBuilderImpl res = objMap.get(pos);
-
-                if (res == null) {
-                    res = new BinaryObjectBuilderImpl(new PortableBuilderReader(this, pos), pos);
-
-                    objMap.put(pos, res);
-                }
-
-                return res;
-            }
-
-            case GridPortableMarshaller.BYTE:
-                return arr[pos + 1];
-
-            case GridPortableMarshaller.SHORT:
-                return PortablePrimitives.readShort(arr, pos + 1);
-
-            case GridPortableMarshaller.INT:
-                return PortablePrimitives.readInt(arr, pos + 1);
-
-            case GridPortableMarshaller.LONG:
-                return PortablePrimitives.readLong(arr, pos + 1);
-
-            case GridPortableMarshaller.FLOAT:
-                return PortablePrimitives.readFloat(arr, pos + 1);
-
-            case GridPortableMarshaller.DOUBLE:
-                return PortablePrimitives.readDouble(arr, pos + 1);
-
-            case GridPortableMarshaller.CHAR:
-                return PortablePrimitives.readChar(arr, pos + 1);
-
-            case GridPortableMarshaller.BOOLEAN:
-                return arr[pos + 1] != 0;
-
-            case GridPortableMarshaller.DECIMAL:
-            case GridPortableMarshaller.STRING:
-            case GridPortableMarshaller.UUID:
-            case GridPortableMarshaller.DATE:
-            case GridPortableMarshaller.TIMESTAMP:
-                return new PortablePlainLazyValue(this, pos, len);
-
-            case GridPortableMarshaller.BYTE_ARR:
-            case GridPortableMarshaller.SHORT_ARR:
-            case GridPortableMarshaller.INT_ARR:
-            case GridPortableMarshaller.LONG_ARR:
-            case GridPortableMarshaller.FLOAT_ARR:
-            case GridPortableMarshaller.DOUBLE_ARR:
-            case GridPortableMarshaller.CHAR_ARR:
-            case GridPortableMarshaller.BOOLEAN_ARR:
-            case GridPortableMarshaller.DECIMAL_ARR:
-            case GridPortableMarshaller.DATE_ARR:
-            case GridPortableMarshaller.TIMESTAMP_ARR:
-            case GridPortableMarshaller.UUID_ARR:
-            case GridPortableMarshaller.STRING_ARR:
-            case GridPortableMarshaller.ENUM_ARR:
-            case GridPortableMarshaller.OBJ_ARR:
-            case GridPortableMarshaller.COL:
-            case GridPortableMarshaller.MAP:
-                return new LazyCollection(pos);
-
-            case GridPortableMarshaller.ENUM: {
-                if (len == 1) {
-                    assert readByte(pos) == GridPortableMarshaller.NULL;
-
-                    return null;
-                }
-
-                int mark = position();
-                position(pos + 1);
-
-                PortableBuilderEnum builderEnum = new PortableBuilderEnum(this);
-
-                position(mark);
-
-                return builderEnum;
-            }
-
-            case GridPortableMarshaller.PORTABLE_OBJ: {
-                int size = readIntPositioned(pos + 1);
-
-                int start = readIntPositioned(pos + 4 + size);
-
-                BinaryObjectImpl portableObj = new BinaryObjectImpl(ctx, arr, pos + 4 + start);
-
-                return new PortablePlainPortableObject(portableObj);
-            }
-
-            default:
-                throw new BinaryObjectException("Invalid flag value: " + type);
-        }
-    }
-
-    /**
-     * @return Parsed value.
-     */
-    public Object parseValue() {
-        int valPos = pos;
-
-        byte type = arr[pos++];
-
-        int plainLazyValLen;
-
-        boolean modifiableLazyVal = false;
-
-        switch (type) {
-            case GridPortableMarshaller.NULL:
-                return null;
-
-            case GridPortableMarshaller.HANDLE: {
-                int objStart = pos - 1 - readInt();
-
-                BinaryObjectBuilderImpl res = objMap.get(objStart);
-
-                if (res == null) {
-                    res = new BinaryObjectBuilderImpl(new PortableBuilderReader(this, objStart), objStart);
-
-                    objMap.put(objStart, res);
-                }
-
-                return res;
-            }
-
-            case GridPortableMarshaller.OBJ: {
-                pos--;
-
-                BinaryObjectBuilderImpl res = objMap.get(pos);
-
-                if (res == null) {
-                    res = new BinaryObjectBuilderImpl(new PortableBuilderReader(this, pos), pos);
-
-                    objMap.put(pos, res);
-                }
-
-                pos += readInt(GridPortableMarshaller.TOTAL_LEN_POS);
-
-                return res;
-            }
-
-            case GridPortableMarshaller.BYTE:
-                return arr[pos++];
-
-            case GridPortableMarshaller.SHORT: {
-                Object res = PortablePrimitives.readShort(arr, pos);
-                pos += 2;
-                return res;
-            }
-
-            case GridPortableMarshaller.INT:
-                return readInt();
-
-            case GridPortableMarshaller.LONG:
-                plainLazyValLen = 8;
-
-                break;
-
-            case GridPortableMarshaller.FLOAT:
-                plainLazyValLen = 4;
-
-                break;
-
-            case GridPortableMarshaller.DOUBLE:
-                plainLazyValLen = 8;
-
-                break;
-
-            case GridPortableMarshaller.CHAR:
-                plainLazyValLen = 2;
-
-                break;
-
-            case GridPortableMarshaller.BOOLEAN:
-                return arr[pos++] != 0;
-
-            case GridPortableMarshaller.DECIMAL:
-                plainLazyValLen = /** scale */ 4  + /** mag len */ 4  + /** mag bytes count */ readInt(4);
-
-                break;
-
-            case GridPortableMarshaller.STRING:
-                plainLazyValLen = 4 + readStringLength();
-
-                break;
-
-            case GridPortableMarshaller.UUID:
-                plainLazyValLen = 8 + 8;
-
-                break;
-
-            case GridPortableMarshaller.DATE:
-                plainLazyValLen = 8;
-
-                break;
-
-            case GridPortableMarshaller.TIMESTAMP:
-                plainLazyValLen = 8 + 4;
-
-                break;
-
-            case GridPortableMarshaller.BYTE_ARR:
-                plainLazyValLen = 4 + readLength();
-                modifiableLazyVal = true;
-
-                break;
-
-            case GridPortableMarshaller.SHORT_ARR:
-                plainLazyValLen = 4 + readLength() * 2;
-                modifiableLazyVal = true;
-
-                break;
-
-            case GridPortableMarshaller.INT_ARR:
-                plainLazyValLen = 4 + readLength() * 4;
-                modifiableLazyVal = true;
-
-                break;
-
-            case GridPortableMarshaller.LONG_ARR:
-                plainLazyValLen = 4 + readLength() * 8;
-                modifiableLazyVal = true;
-
-                break;
-
-            case GridPortableMarshaller.FLOAT_ARR:
-                plainLazyValLen = 4 + readLength() * 4;
-                modifiableLazyVal = true;
-
-                break;
-
-            case GridPortableMarshaller.DOUBLE_ARR:
-                plainLazyValLen = 4 + readLength() * 8;
-                modifiableLazyVal = true;
-
-                break;
-
-            case GridPortableMarshaller.CHAR_ARR:
-                plainLazyValLen = 4 + readLength() * 2;
-                modifiableLazyVal = true;
-
-                break;
-
-            case GridPortableMarshaller.BOOLEAN_ARR:
-                plainLazyValLen = 4 + readLength();
-                modifiableLazyVal = true;
-
-                break;
-
-            case GridPortableMarshaller.OBJ_ARR:
-                return new PortableObjectArrayLazyValue(this);
-
-            case GridPortableMarshaller.DATE_ARR: {
-                int size = readInt();
-
-                Date[] res = new Date[size];
-
-                for (int i = 0; i < res.length; i++) {
-                    byte flag = arr[pos++];
-
-                    if (flag == GridPortableMarshaller.NULL) continue;
-
-                    if (flag != GridPortableMarshaller.DATE)
-                        throw new BinaryObjectException("Invalid flag value: " + flag);
-
-                    long time = PortablePrimitives.readLong(arr, pos);
-
-                    pos += 8;
-
-                    res[i] = new Date(time);
-                }
-
-                return res;
-            }
-
-            case GridPortableMarshaller.TIMESTAMP_ARR: {
-                int size = readInt();
-
-                Timestamp[] res = new Timestamp[size];
-
-                for (int i = 0; i < res.length; i++) {
-                    byte flag = arr[pos++];
-
-                    if (flag == GridPortableMarshaller.NULL)
-                        continue;
-
-                    if (flag != GridPortableMarshaller.TIMESTAMP)
-                        throw new BinaryObjectException("Invalid flag value: " + flag);
-
-                    long time = PortablePrimitives.readLong(arr, pos);
-
-                    pos += 8;
-
-                    int nano = PortablePrimitives.readInt(arr, pos);
-
-                    pos += 4;
-
-                    Timestamp ts = new Timestamp(time);
-
-                    ts.setNanos(ts.getNanos() + nano);
-
-                    res[i] = ts;
-                }
-
-                return res;
-            }
-
-            case GridPortableMarshaller.UUID_ARR:
-            case GridPortableMarshaller.STRING_ARR:
-            case GridPortableMarshaller.DECIMAL_ARR: {
-                int size = readInt();
-
-                for (int i = 0; i < size; i++) {
-                    byte flag = arr[pos++];
-
-                    if (flag == GridPortableMarshaller.UUID)
-                        pos += 8 + 8;
-                    else if (flag == GridPortableMarshaller.STRING)
-                        pos += 4 + readStringLength();
-                    else if (flag == GridPortableMarshaller.DECIMAL) {
-                        pos += 4; // scale value
-                        pos += 4 + readLength();
-                    }
-                    else
-                        assert flag == GridPortableMarshaller.NULL;
-                }
-
-                return new PortableModifiableLazyValue(this, valPos, pos - valPos);
-            }
-
-            case GridPortableMarshaller.COL: {
-                int size = readInt();
-                byte colType = arr[pos++];
-
-                switch (colType) {
-                    case GridPortableMarshaller.USER_COL:
-                    case GridPortableMarshaller.ARR_LIST:
-                        return new PortableLazyArrayList(this, size);
-
-                    case GridPortableMarshaller.LINKED_LIST:
-                        return new PortableLazyLinkedList(this, size);
-
-                    case GridPortableMarshaller.HASH_SET:
-                    case GridPortableMarshaller.LINKED_HASH_SET:
-                        return new PortableLazySet(this, size);
-                }
-
-                throw new BinaryObjectException("Unknown collection type: " + colType);
-            }
-
-            case GridPortableMarshaller.MAP:
-                return PortableLazyMap.parseMap(this);
-
-            case GridPortableMarshaller.ENUM:
-                return new PortableBuilderEnum(this);
-
-            case GridPortableMarshaller.ENUM_ARR:
-                return new PortableEnumArrayLazyValue(this);
-
-            case GridPortableMarshaller.PORTABLE_OBJ: {
-                int size = readInt();
-
-                pos += size;
-
-                int start = readInt();
-
-                BinaryObjectImpl portableObj = new BinaryObjectImpl(ctx, arr,
-                    pos - 4 - size + start);
-
-                return new PortablePlainPortableObject(portableObj);
-            }
-
-            default:
-                throw new BinaryObjectException("Invalid flag value: " + type);
-        }
-
-        PortableAbstractLazyValue res;
-
-        if (modifiableLazyVal)
-            res = new PortableModifiableLazyValue(this, valPos, 1 + plainLazyValLen);
-        else
-            res = new PortablePlainLazyValue(this, valPos, 1 + plainLazyValLen);
-
-        pos += plainLazyValLen;
-
-        return res;
-    }
-
-    /**
-     * @return Array.
-     */
-    public byte[] array() {
-        return arr;
-    }
-
-    /**
-     * @return Position of reader.
-     */
-    public int position() {
-        return pos;
-    }
-
-    /**
-     * @param pos New pos.
-     */
-    public void position(int pos) {
-        this.pos = pos;
-    }
-
-    /**
-     * @param n Number of bytes to skip.
-     */
-    public void skip(int n) {
-        pos += n;
-    }
-
-    /**
-     * @return Reader.
-     */
-    BinaryReaderExImpl reader() {
-        return reader;
-    }
-
-    /**
-     *
-     */
-    private class LazyCollection implements PortableLazyValue {
-        /** */
-        private final int valOff;
-
-        /** */
-        private Object col;
-
-        /**
-         * @param valOff Value.
-         */
-        protected LazyCollection(int valOff) {
-            this.valOff = valOff;
-        }
-
-        /**
-         * @return Object.
-         */
-        private Object wrappedCollection() {
-            if (col == null) {
-                position(valOff);
-
-                col = parseValue();
-            }
-
-            return col;
-        }
-
-        /** {@inheritDoc} */
-        @Override public void writeTo(BinaryWriterExImpl writer, PortableBuilderSerializer ctx) {
-            ctx.writeValue(writer, wrappedCollection());
-        }
-
-        /** {@inheritDoc} */
-        @Override public Object value() {
-            return PortableUtils.unwrapLazy(wrappedCollection());
-        }
-    }
-}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ignite/blob/1dbf20e0/modules/core/src/main/java/org/apache/ignite/internal/portable/builder/PortableBuilderSerializationAware.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/portable/builder/PortableBuilderSerializationAware.java b/modules/core/src/main/java/org/apache/ignite/internal/portable/builder/PortableBuilderSerializationAware.java
deleted file mode 100644
index a750f6c..0000000
--- a/modules/core/src/main/java/org/apache/ignite/internal/portable/builder/PortableBuilderSerializationAware.java
+++ /dev/null
@@ -1,31 +0,0 @@
-/*
- * 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.portable.builder;
-
-import org.apache.ignite.internal.portable.*;
-
-/**
- *
- */
-interface PortableBuilderSerializationAware {
-    /**
-     * @param writer Writer.
-     * @param ctx Context.
-     */
-    public void writeTo(BinaryWriterExImpl writer, PortableBuilderSerializer ctx);
-}

http://git-wip-us.apache.org/repos/asf/ignite/blob/1dbf20e0/modules/core/src/main/java/org/apache/ignite/internal/portable/builder/PortableBuilderSerializer.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/portable/builder/PortableBuilderSerializer.java b/modules/core/src/main/java/org/apache/ignite/internal/portable/builder/PortableBuilderSerializer.java
deleted file mode 100644
index d5923ee..0000000
--- a/modules/core/src/main/java/org/apache/ignite/internal/portable/builder/PortableBuilderSerializer.java
+++ /dev/null
@@ -1,217 +0,0 @@
-/*
- * 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.portable.builder;
-
-import org.apache.ignite.binary.BinaryObject;
-import org.apache.ignite.internal.portable.BinaryMetadata;
-import org.apache.ignite.internal.portable.BinaryObjectExImpl;
-import org.apache.ignite.internal.portable.BinaryWriterExImpl;
-import org.apache.ignite.internal.portable.GridPortableMarshaller;
-import org.apache.ignite.internal.portable.PortableContext;
-import org.apache.ignite.internal.portable.PortableUtils;
-
-import java.util.Collection;
-import java.util.IdentityHashMap;
-import java.util.Map;
-
-/**
- *
- */
-class PortableBuilderSerializer {
-    /** */
-    private final Map<BinaryObjectBuilderImpl, Integer> objToPos = new IdentityHashMap<>();
-
-    /** */
-    private Map<BinaryObject, BinaryObjectBuilderImpl> portableObjToWrapper;
-
-    /**
-     * @param obj Mutable object.
-     * @param posInResArr Object position in the array.
-     */
-    public void registerObjectWriting(BinaryObjectBuilderImpl obj, int posInResArr) {
-        objToPos.put(obj, posInResArr);
-    }
-
-    /**
-     * @param writer Writer.
-     * @param val Value.
-     */
-    public void writeValue(BinaryWriterExImpl writer, Object val) {
-        if (val == null) {
-            writer.writeByte(GridPortableMarshaller.NULL);
-
-            return;
-        }
-
-        if (val instanceof PortableBuilderSerializationAware) {
-            ((PortableBuilderSerializationAware)val).writeTo(writer, this);
-
-            return;
-        }
-
-        if (val instanceof BinaryObjectExImpl) {
-            if (portableObjToWrapper == null)
-                portableObjToWrapper = new IdentityHashMap<>();
-
-            BinaryObjectBuilderImpl wrapper = portableObjToWrapper.get(val);
-
-            if (wrapper == null) {
-                wrapper = BinaryObjectBuilderImpl.wrap((BinaryObject)val);
-
-                portableObjToWrapper.put((BinaryObject)val, wrapper);
-            }
-
-            val = wrapper;
-        }
-
-        if (val instanceof BinaryObjectBuilderImpl) {
-            BinaryObjectBuilderImpl obj = (BinaryObjectBuilderImpl)val;
-
-            Integer posInResArr = objToPos.get(obj);
-
-            if (posInResArr == null) {
-                objToPos.put(obj, writer.out().position());
-
-                obj.serializeTo(writer.newWriter(obj.typeId()), this);
-            }
-            else {
-                int handle = writer.out().position() - posInResArr;
-
-                writer.writeByte(GridPortableMarshaller.HANDLE);
-                writer.writeInt(handle);
-            }
-
-            return;
-        }
-
-        if (val.getClass().isEnum()) {
-            String typeName = PortableContext.typeName(val.getClass().getName());
-            int typeId = writer.context().typeId(typeName);
-
-            BinaryMetadata meta = new BinaryMetadata(typeId, typeName, null, null, null, true);
-            writer.context().updateMetadata(typeId, meta);
-
-            writer.writeByte(GridPortableMarshaller.ENUM);
-            writer.writeInt(typeId);
-            writer.writeInt(((Enum)val).ordinal());
-
-            return;
-        }
-
-        if (val instanceof Collection) {
-            Collection<?> c = (Collection<?>)val;
-
-            writer.writeByte(GridPortableMarshaller.COL);
-            writer.writeInt(c.size());
-
-            byte colType = writer.context().collectionType(c.getClass());
-
-            writer.writeByte(colType);
-
-            for (Object obj : c)
-                writeValue(writer, obj);
-
-            return;
-        }
-
-        if (val instanceof Map) {
-            Map<?, ?> map = (Map<?, ?>)val;
-
-            writer.writeByte(GridPortableMarshaller.MAP);
-            writer.writeInt(map.size());
-
-            writer.writeByte(writer.context().mapType(map.getClass()));
-
-            for (Map.Entry<?, ?> entry : map.entrySet()) {
-                writeValue(writer, entry.getKey());
-                writeValue(writer, entry.getValue());
-            }
-
-            return;
-        }
-
-        Byte flag = PortableUtils.PLAIN_CLASS_TO_FLAG.get(val.getClass());
-
-        if (flag != null) {
-            PortableUtils.writePlainObject(writer, val);
-
-            return;
-        }
-
-        if (val instanceof Object[]) {
-            int compTypeId = writer.context().typeId(((Object[])val).getClass().getComponentType().getName());
-
-            if (val instanceof PortableBuilderEnum[]) {
-                writeArray(writer, GridPortableMarshaller.ENUM_ARR, (Object[])val, compTypeId);
-
-                return;
-            }
-
-            if (((Object[])val).getClass().getComponentType().isEnum()) {
-                Enum[] enumArr = (Enum[])val;
-
-                writer.writeByte(GridPortableMarshaller.ENUM_ARR);
-                writer.writeInt(compTypeId);
-                writer.writeInt(enumArr.length);
-
-                for (Enum anEnum : enumArr)
-                    writeValue(writer, anEnum);
-
-                return;
-            }
-
-            writeArray(writer, GridPortableMarshaller.OBJ_ARR, (Object[])val, compTypeId);
-
-            return;
-        }
-
-        writer.doWriteObject(val);
-    }
-
-    /**
-     * @param writer Writer.
-     * @param elementType Element type.
-     * @param arr The array.
-     * @param compTypeId Component type ID.
-     */
-    public void writeArray(BinaryWriterExImpl writer, byte elementType, Object[] arr, int compTypeId) {
-        writer.writeByte(elementType);
-        writer.writeInt(compTypeId);
-        writer.writeInt(arr.length);
-
-        for (Object obj : arr)
-            writeValue(writer, obj);
-    }
-
-    /**
-     * @param writer Writer.
-     * @param elementType Element type.
-     * @param arr The array.
-     * @param clsName Component class name.
-     */
-    public void writeArray(BinaryWriterExImpl writer, byte elementType, Object[] arr, String clsName) {
-        writer.writeByte(elementType);
-        writer.writeInt(GridPortableMarshaller.UNREGISTERED_TYPE_ID);
-        writer.writeString(clsName);
-        writer.writeInt(arr.length);
-
-        for (Object obj : arr)
-            writeValue(writer, obj);
-    }
-
-}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ignite/blob/1dbf20e0/modules/core/src/main/java/org/apache/ignite/internal/portable/builder/PortableEnumArrayLazyValue.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/portable/builder/PortableEnumArrayLazyValue.java b/modules/core/src/main/java/org/apache/ignite/internal/portable/builder/PortableEnumArrayLazyValue.java
deleted file mode 100644
index 91c1c87..0000000
--- a/modules/core/src/main/java/org/apache/ignite/internal/portable/builder/PortableEnumArrayLazyValue.java
+++ /dev/null
@@ -1,114 +0,0 @@
-/*
- * 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.portable.builder;
-
-import org.apache.ignite.internal.portable.GridPortableMarshaller;
-import org.apache.ignite.internal.portable.BinaryWriterExImpl;
-import org.apache.ignite.internal.util.typedef.internal.U;
-import org.apache.ignite.binary.BinaryObjectException;
-import org.apache.ignite.binary.BinaryInvalidTypeException;
-
-/**
- *
- */
-class PortableEnumArrayLazyValue extends PortableAbstractLazyValue {
-    /** */
-    private final int len;
-
-    /** */
-    private final int compTypeId;
-
-    /** */
-    private final String clsName;
-
-    /**
-     * @param reader Reader.
-     */
-    protected PortableEnumArrayLazyValue(PortableBuilderReader reader) {
-        super(reader, reader.position() - 1);
-
-        int typeId = reader.readInt();
-
-        if (typeId == GridPortableMarshaller.UNREGISTERED_TYPE_ID) {
-            clsName = reader.readString();
-
-            Class cls;
-
-            try {
-                // TODO: IGNITE-1272 - Is class loader needed here?
-                cls = U.forName(reader.readString(), null);
-            }
-            catch (ClassNotFoundException e) {
-                throw new BinaryInvalidTypeException("Failed to load the class: " + clsName, e);
-            }
-
-            compTypeId = reader.portableContext().descriptorForClass(cls, true).typeId();
-        }
-        else {
-            compTypeId = typeId;
-            clsName = null;
-        }
-
-        int size = reader.readInt();
-
-        for (int i = 0; i < size; i++)
-            reader.skipValue();
-
-        len = reader.position() - valOff;
-    }
-
-    /** {@inheritDoc} */
-    @Override protected Object init() {
-        reader.position(valOff + 1);
-
-        //skipping component type id
-        reader.readInt();
-
-        int size = reader.readInt();
-
-        PortableBuilderEnum[] res = new PortableBuilderEnum[size];
-
-        for (int i = 0; i < size; i++) {
-            byte flag = reader.readByte();
-
-            if (flag == GridPortableMarshaller.NULL)
-                continue;
-
-            if (flag != GridPortableMarshaller.ENUM)
-                throw new BinaryObjectException("Invalid flag value: " + flag);
-
-            res[i] = new PortableBuilderEnum(reader);
-        }
-
-        return res;
-    }
-
-    /** {@inheritDoc} */
-    @Override public void writeTo(BinaryWriterExImpl writer, PortableBuilderSerializer ctx) {
-        if (val != null) {
-            if (clsName != null)
-                ctx.writeArray(writer, GridPortableMarshaller.ENUM_ARR, (Object[])val, clsName);
-            else
-                ctx.writeArray(writer, GridPortableMarshaller.ENUM_ARR, (Object[])val, compTypeId);
-
-            return;
-        }
-
-        writer.write(reader.array(), valOff, len);
-    }
-}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ignite/blob/1dbf20e0/modules/core/src/main/java/org/apache/ignite/internal/portable/builder/PortableLazyArrayList.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/portable/builder/PortableLazyArrayList.java b/modules/core/src/main/java/org/apache/ignite/internal/portable/builder/PortableLazyArrayList.java
deleted file mode 100644
index 29bbe85..0000000
--- a/modules/core/src/main/java/org/apache/ignite/internal/portable/builder/PortableLazyArrayList.java
+++ /dev/null
@@ -1,166 +0,0 @@
-/*
- * 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.portable.builder;
-
-import org.apache.ignite.internal.portable.*;
-
-import java.util.AbstractList;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.List;
-
-/**
- *
- */
-class PortableLazyArrayList extends AbstractList<Object> implements PortableBuilderSerializationAware {
-    /** */
-    private final PortableBuilderReader reader;
-
-    /** */
-    private final int off;
-
-    /** */
-    private List<Object> delegate;
-
-    /**
-     * @param reader Reader.
-     * @param size Size,
-     */
-    PortableLazyArrayList(PortableBuilderReader reader, int size) {
-        this.reader = reader;
-        off = reader.position() - 1/* flag */ - 4/* size */ - 1/* col type */;
-
-        assert size >= 0;
-
-        for (int i = 0; i < size; i++)
-            reader.skipValue();
-    }
-
-    /**
-     *
-     */
-    private void ensureDelegateInit() {
-        if (delegate == null) {
-            int size = reader.readIntPositioned(off + 1);
-
-            reader.position(off + 1/* flag */ + 4/* size */ + 1/* col type */);
-
-            delegate = new ArrayList<>(size);
-
-            for (int i = 0; i < size; i++)
-                delegate.add(reader.parseValue());
-        }
-    }
-
-    /** {@inheritDoc} */
-    @Override public Object get(int idx) {
-        ensureDelegateInit();
-
-        return PortableUtils.unwrapLazy(delegate.get(idx));
-    }
-
-    /** {@inheritDoc} */
-    @Override public boolean add(Object o) {
-        ensureDelegateInit();
-
-        return delegate.add(o);
-    }
-
-    /** {@inheritDoc} */
-    @Override public void add(int idx, Object element) {
-        ensureDelegateInit();
-
-        delegate.add(idx, element);
-    }
-
-    /** {@inheritDoc} */
-    @Override public Object set(int idx, Object element) {
-        ensureDelegateInit();
-
-        return PortableUtils.unwrapLazy(delegate.set(idx, element));
-    }
-
-    /** {@inheritDoc} */
-    @Override public Object remove(int idx) {
-        ensureDelegateInit();
-
-        return PortableUtils.unwrapLazy(delegate.remove(idx));
-    }
-
-    /** {@inheritDoc} */
-    @Override public void clear() {
-        if (delegate == null)
-            delegate = new ArrayList<>();
-        else
-            delegate.clear();
-    }
-
-    /** {@inheritDoc} */
-    @Override public boolean addAll(int idx, Collection<?> c) {
-        return delegate.addAll(idx, c);
-    }
-
-    /** {@inheritDoc} */
-    @Override protected void removeRange(int fromIdx, int toIdx) {
-        ensureDelegateInit();
-
-        delegate.subList(fromIdx, toIdx).clear();
-    }
-
-    /** {@inheritDoc} */
-    @Override public int size() {
-        if (delegate == null)
-            return reader.readIntPositioned(off + 1);
-
-        return delegate.size();
-    }
-
-    /** {@inheritDoc} */
-    @Override public void writeTo(BinaryWriterExImpl writer, PortableBuilderSerializer ctx) {
-        if (delegate == null) {
-            int size = reader.readIntPositioned(off + 1);
-
-            int hdrSize = 1 /* flag */ + 4 /* size */ + 1 /* col type */;
-
-            writer.write(reader.array(), off, hdrSize);
-
-            reader.position(off + hdrSize);
-
-            for (int i = 0; i < size; i++) {
-                Object o = reader.parseValue();
-
-                ctx.writeValue(writer, o);
-            }
-        }
-        else {
-            writer.writeByte(GridPortableMarshaller.COL);
-            writer.writeInt(delegate.size());
-
-            byte colType = reader.array()[off + 1 /* flag */ + 4 /* size */];
-            writer.writeByte(colType);
-
-            int oldPos = reader.position();
-
-            for (Object o : delegate)
-                ctx.writeValue(writer, o);
-
-            // PortableBuilderImpl might have been written. It could override reader's position.
-            reader.position(oldPos);
-        }
-    }
-}

http://git-wip-us.apache.org/repos/asf/ignite/blob/1dbf20e0/modules/core/src/main/java/org/apache/ignite/internal/portable/builder/PortableLazyLinkedList.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/portable/builder/PortableLazyLinkedList.java b/modules/core/src/main/java/org/apache/ignite/internal/portable/builder/PortableLazyLinkedList.java
deleted file mode 100644
index 3271aaa..0000000
--- a/modules/core/src/main/java/org/apache/ignite/internal/portable/builder/PortableLazyLinkedList.java
+++ /dev/null
@@ -1,217 +0,0 @@
-/*
- * 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.portable.builder;
-
-import org.apache.ignite.internal.portable.*;
-
-import java.util.AbstractList;
-import java.util.Collection;
-import java.util.Iterator;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.ListIterator;
-
-/**
- *
- */
-class PortableLazyLinkedList extends AbstractList<Object> implements PortableBuilderSerializationAware {
-    /** */
-    private final PortableBuilderReader reader;
-
-    /** */
-    private final int off;
-
-    /** */
-    private List<Object> delegate;
-
-    /**
-     * @param reader Reader.
-     * @param size Size,
-     */
-    PortableLazyLinkedList(PortableBuilderReader reader, int size) {
-        this.reader = reader;
-        off = reader.position() - 1/* flag */ - 4/* size */ - 1/* col type */;
-
-        assert size >= 0;
-
-        for (int i = 0; i < size; i++)
-            reader.skipValue();
-    }
-
-    /**
-     *
-     */
-    private void ensureDelegateInit() {
-        if (delegate == null) {
-            int size = reader.readIntPositioned(off + 1);
-
-            reader.position(off + 1/* flag */ + 4/* size */ + 1/* col type */);
-
-            delegate = new LinkedList<>();
-
-            for (int i = 0; i < size; i++)
-                delegate.add(reader.parseValue());
-        }
-    }
-
-    /** {@inheritDoc} */
-    @Override public Object get(int idx) {
-        ensureDelegateInit();
-
-        return PortableUtils.unwrapLazy(delegate.get(idx));
-    }
-
-    /** {@inheritDoc} */
-    @Override public boolean add(Object o) {
-        ensureDelegateInit();
-
-        return delegate.add(o);
-    }
-
-    /** {@inheritDoc} */
-    @Override public void add(int idx, Object element) {
-        ensureDelegateInit();
-
-        delegate.add(idx, element);
-    }
-
-    /** {@inheritDoc} */
-    @Override public Object set(int idx, Object element) {
-        ensureDelegateInit();
-
-        return PortableUtils.unwrapLazy(delegate.set(idx, element));
-    }
-
-    /** {@inheritDoc} */
-    @Override public Object remove(int idx) {
-        ensureDelegateInit();
-
-        return PortableUtils.unwrapLazy(delegate.remove(idx));
-    }
-
-    /** {@inheritDoc} */
-    @Override public void clear() {
-        if (delegate == null)
-            delegate = new LinkedList<>();
-        else
-            delegate.clear();
-    }
-
-    /** {@inheritDoc} */
-    @Override public boolean addAll(int idx, Collection<?> c) {
-        ensureDelegateInit();
-
-        return delegate.addAll(idx, c);
-    }
-
-    /** {@inheritDoc} */
-    @Override protected void removeRange(int fromIdx, int toIdx) {
-        ensureDelegateInit();
-
-        delegate.subList(fromIdx, toIdx).clear();
-    }
-
-    /** {@inheritDoc} */
-    @Override public int size() {
-        if (delegate == null)
-            return reader.readIntPositioned(off + 1);
-
-        return delegate.size();
-    }
-
-    /** {@inheritDoc} */
-    @Override public ListIterator<Object> listIterator(final int idx) {
-        ensureDelegateInit();
-
-        return new ListIterator<Object>() {
-            /** */
-            private final ListIterator<Object> delegate = PortableLazyLinkedList.super.listIterator(idx);
-
-            @Override public boolean hasNext() {
-                return delegate.hasNext();
-            }
-
-            @Override public Object next() {
-                return PortableUtils.unwrapLazy(delegate.next());
-            }
-
-            @Override public boolean hasPrevious() {
-                return delegate.hasPrevious();
-            }
-
-            @Override public Object previous() {
-                return PortableUtils.unwrapLazy(delegate.previous());
-            }
-
-            @Override public int nextIndex() {
-                return delegate.nextIndex();
-            }
-
-            @Override public int previousIndex() {
-                return delegate.previousIndex();
-            }
-
-            @Override public void remove() {
-                delegate.remove();
-            }
-
-            @Override public void set(Object o) {
-                delegate.set(o);
-            }
-
-            @Override public void add(Object o) {
-                delegate.add(o);
-            }
-        };
-    }
-
-    /** {@inheritDoc} */
-    @Override public Iterator<Object> iterator() {
-        ensureDelegateInit();
-
-        return PortableUtils.unwrapLazyIterator(super.iterator());
-    }
-
-    /** {@inheritDoc} */
-    @Override public void writeTo(BinaryWriterExImpl writer, PortableBuilderSerializer ctx) {
-        if (delegate == null) {
-            int size = reader.readIntPositioned(off + 1);
-
-            int hdrSize = 1 /* flag */ + 4 /* size */ + 1 /* col type */;
-            writer.write(reader.array(), off, hdrSize);
-
-            reader.position(off + hdrSize);
-
-            for (int i = 0; i < size; i++) {
-                Object o = reader.parseValue();
-
-                ctx.writeValue(writer, o);
-            }
-        }
-        else {
-            writer.writeByte(GridPortableMarshaller.COL);
-            writer.writeInt(delegate.size());
-
-            byte colType = reader.array()[off + 1 /* flag */ + 4 /* size */];
-            writer.writeByte(colType);
-
-            for (Object o : delegate)
-                ctx.writeValue(writer, o);
-        }
-    }
-}

http://git-wip-us.apache.org/repos/asf/ignite/blob/1dbf20e0/modules/core/src/main/java/org/apache/ignite/internal/portable/builder/PortableLazyMap.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/portable/builder/PortableLazyMap.java b/modules/core/src/main/java/org/apache/ignite/internal/portable/builder/PortableLazyMap.java
deleted file mode 100644
index 32d4f44..0000000
--- a/modules/core/src/main/java/org/apache/ignite/internal/portable/builder/PortableLazyMap.java
+++ /dev/null
@@ -1,220 +0,0 @@
-/*
- * 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.portable.builder;
-
-import org.apache.ignite.internal.portable.*;
-
-import java.util.AbstractMap;
-import java.util.AbstractSet;
-import java.util.Iterator;
-import java.util.LinkedHashMap;
-import java.util.Map;
-import java.util.Set;
-import org.jetbrains.annotations.Nullable;
-
-/**
- *
- */
-class PortableLazyMap extends AbstractMap<Object, Object> implements PortableBuilderSerializationAware {
-    /** */
-    private final PortableBuilderReader reader;
-
-    /** */
-    private final int off;
-
-    /** */
-    private Map<Object, Object> delegate;
-
-    /**
-     * @param reader Reader.
-     * @param off Offset.
-     */
-    private PortableLazyMap(PortableBuilderReader reader, int off) {
-        this.reader = reader;
-        this.off = off;
-    }
-
-    /**
-     * @param reader Reader.
-     * @return PortableLazyMap.
-     */
-    @Nullable public static PortableLazyMap parseMap(PortableBuilderReader reader) {
-        int off = reader.position() - 1;
-
-        int size = reader.readInt();
-
-        reader.skip(1); // map type.
-
-        for (int i = 0; i < size; i++) {
-            reader.skipValue(); // skip key
-            reader.skipValue(); // skip value
-        }
-
-        return new PortableLazyMap(reader, off);
-    }
-
-    /**
-     *
-     */
-    private void ensureDelegateInit() {
-        if (delegate == null) {
-            int size = reader.readIntPositioned(off + 1);
-
-            reader.position(off + 1/* flag */ + 4/* size */ + 1/* col type */);
-
-            delegate = new LinkedHashMap<>();
-
-            for (int i = 0; i < size; i++)
-                delegate.put(PortableUtils.unwrapLazy(reader.parseValue()), reader.parseValue());
-        }
-    }
-
-    /** {@inheritDoc} */
-    @Override public void writeTo(BinaryWriterExImpl writer, PortableBuilderSerializer ctx) {
-        if (delegate == null) {
-            int size = reader.readIntPositioned(off + 1);
-
-            int hdrSize = 1 /* flag */ + 4 /* size */ + 1 /* col type */;
-            writer.write(reader.array(), off, hdrSize);
-
-            reader.position(off + hdrSize);
-
-            for (int i = 0; i < size; i++) {
-                ctx.writeValue(writer, reader.parseValue()); // key
-                ctx.writeValue(writer, reader.parseValue()); // value
-            }
-        }
-        else {
-            writer.writeByte(GridPortableMarshaller.MAP);
-            writer.writeInt(delegate.size());
-
-            byte colType = reader.array()[off + 1 /* flag */ + 4 /* size */];
-
-            writer.writeByte(colType);
-
-            for (Entry<Object, Object> entry : delegate.entrySet()) {
-                ctx.writeValue(writer, entry.getKey());
-                ctx.writeValue(writer, entry.getValue());
-            }
-        }
-    }
-
-    /** {@inheritDoc} */
-    @Override public int size() {
-        if (delegate == null)
-            return reader.readIntPositioned(off + 1);
-
-        return delegate.size();
-    }
-
-    /** {@inheritDoc} */
-    @Override public boolean containsKey(Object key) {
-        ensureDelegateInit();
-
-        return delegate.containsKey(key);
-    }
-
-    /** {@inheritDoc} */
-    @Override public boolean containsValue(Object val) {
-        return values().contains(val);
-    }
-
-    /** {@inheritDoc} */
-    @Override public Set<Object> keySet() {
-        ensureDelegateInit();
-
-        return delegate.keySet();
-    }
-
-    /** {@inheritDoc} */
-    @Override public void clear() {
-        if (delegate == null)
-            delegate = new LinkedHashMap<>();
-        else
-            delegate.clear();
-    }
-
-    /** {@inheritDoc} */
-    @Override public Object get(Object key) {
-        ensureDelegateInit();
-
-        return PortableUtils.unwrapLazy(delegate.get(key));
-    }
-
-    /** {@inheritDoc} */
-    @Override public Object put(Object key, Object val) {
-        ensureDelegateInit();
-
-        return PortableUtils.unwrapLazy(delegate.put(key, val));
-    }
-
-    /** {@inheritDoc} */
-    @Override public Object remove(Object key) {
-        ensureDelegateInit();
-
-        return PortableUtils.unwrapLazy(delegate.remove(key));
-    }
-
-    /** {@inheritDoc} */
-    @Override public Set<Entry<Object, Object>> entrySet() {
-        ensureDelegateInit();
-
-        return new AbstractSet<Entry<Object, Object>>() {
-            @Override public boolean contains(Object o) {
-                throw new UnsupportedOperationException();
-            }
-
-            @Override public Iterator<Entry<Object, Object>> iterator() {
-                return new Iterator<Entry<Object, Object>>() {
-                    /** */
-                    private final Iterator<Entry<Object, Object>> itr = delegate.entrySet().iterator();
-
-                    @Override public boolean hasNext() {
-                        return itr.hasNext();
-                    }
-
-                    @Override public Entry<Object, Object> next() {
-                        Entry<Object, Object> res = itr.next();
-
-                        final Object val = res.getValue();
-
-                        if (val instanceof PortableLazyValue) {
-                            return new SimpleEntry<Object, Object>(res.getKey(), val) {
-                                private static final long serialVersionUID = 0L;
-
-                                @Override public Object getValue() {
-                                    return ((PortableLazyValue)val).value();
-                                }
-                            };
-                        }
-
-                        return res;
-                    }
-
-                    @Override public void remove() {
-                        itr.remove();
-                    }
-                };
-            }
-
-            @Override public int size() {
-                return delegate.size();
-            }
-        };
-    }
-}

http://git-wip-us.apache.org/repos/asf/ignite/blob/1dbf20e0/modules/core/src/main/java/org/apache/ignite/internal/portable/builder/PortableLazySet.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/portable/builder/PortableLazySet.java b/modules/core/src/main/java/org/apache/ignite/internal/portable/builder/PortableLazySet.java
deleted file mode 100644
index 7e62aa4..0000000
--- a/modules/core/src/main/java/org/apache/ignite/internal/portable/builder/PortableLazySet.java
+++ /dev/null
@@ -1,92 +0,0 @@
-/*
- * 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.portable.builder;
-
-import java.util.Collection;
-import java.util.Set;
-import org.apache.ignite.internal.portable.GridPortableMarshaller;
-import org.apache.ignite.internal.portable.PortableUtils;
-import org.apache.ignite.internal.portable.BinaryWriterExImpl;
-import org.apache.ignite.internal.util.typedef.internal.U;
-
-/**
- *
- */
-class PortableLazySet extends PortableAbstractLazyValue {
-    /** */
-    private final int off;
-
-    /**
-     * @param reader Reader.
-     * @param size Size.
-     */
-    PortableLazySet(PortableBuilderReader reader, int size) {
-        super(reader, reader.position() - 1);
-
-        off = reader.position() - 1/* flag */ - 4/* size */ - 1/* col type */;
-
-        assert size >= 0;
-
-        for (int i = 0; i < size; i++)
-            reader.skipValue();
-    }
-
-    /** {@inheritDoc} */
-    @Override public void writeTo(BinaryWriterExImpl writer, PortableBuilderSerializer ctx) {
-        if (val == null) {
-            int size = reader.readIntPositioned(off + 1);
-
-            int hdrSize = 1 /* flag */ + 4 /* size */ + 1 /* col type */;
-            writer.write(reader.array(), off, hdrSize);
-
-            reader.position(off + hdrSize);
-
-            for (int i = 0; i < size; i++) {
-                Object o = reader.parseValue();
-
-                ctx.writeValue(writer, o);
-            }
-        }
-        else {
-            Collection<Object> c = (Collection<Object>)val;
-
-            writer.writeByte(GridPortableMarshaller.COL);
-            writer.writeInt(c.size());
-
-            byte colType = reader.array()[off + 1 /* flag */ + 4 /* size */];
-            writer.writeByte(colType);
-
-            for (Object o : c)
-                ctx.writeValue(writer, o);
-        }
-    }
-
-    /** {@inheritDoc} */
-    @Override protected Object init() {
-        int size = reader.readIntPositioned(off + 1);
-
-        reader.position(off + 1/* flag */ + 4/* size */ + 1/* col type */);
-
-        Set<Object> res = U.newLinkedHashSet(size);
-
-        for (int i = 0; i < size; i++)
-            res.add(PortableUtils.unwrapLazy(reader.parseValue()));
-
-        return res;
-    }
-}
\ No newline at end of file


[44/59] [abbrv] ignite git commit: ignite-2065: rename "portable" classes to "binary"

Posted by ak...@apache.org.
http://git-wip-us.apache.org/repos/asf/ignite/blob/71ad9cea/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/binary/GridCachePortableStorePortablesSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/binary/GridCachePortableStorePortablesSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/binary/GridCachePortableStorePortablesSelfTest.java
deleted file mode 100644
index 40fc9c6..0000000
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/binary/GridCachePortableStorePortablesSelfTest.java
+++ /dev/null
@@ -1,66 +0,0 @@
-/*
- * 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.processors.cache.binary;
-
-import java.util.Map;
-import org.apache.ignite.binary.BinaryObject;
-
-/**
- * Tests for cache store with binary.
- */
-public class GridCachePortableStorePortablesSelfTest extends GridCachePortableStoreAbstractSelfTest {
-    /** {@inheritDoc} */
-    @Override protected boolean keepPortableInStore() {
-        return true;
-    }
-
-    /** {@inheritDoc} */
-    @Override protected void populateMap(Map<Object, Object> map, int... idxs) {
-        assert map != null;
-        assert idxs != null;
-
-        for (int idx : idxs)
-            map.put(portable(new Key(idx)), portable(new Value(idx)));
-    }
-
-    /** {@inheritDoc} */
-    @Override protected void checkMap(Map<Object, Object> map, int... idxs) {
-        assert map != null;
-        assert idxs != null;
-
-        assertEquals(idxs.length, map.size());
-
-        for (int idx : idxs) {
-            Object val = map.get(portable(new Key(idx)));
-
-            assertTrue(String.valueOf(val), val instanceof BinaryObject);
-
-            BinaryObject po = (BinaryObject)val;
-
-            assertEquals("Value", po.type().typeName());
-            assertEquals(new Integer(idx), po.field("idx"));
-        }
-    }
-
-    /**
-     * @param obj Object.
-     * @return Portable object.
-     */
-    private Object portable(Object obj) {
-        return grid().binary().toBinary(obj);
-    }
-}

http://git-wip-us.apache.org/repos/asf/ignite/blob/71ad9cea/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/binary/GridPortableCacheEntryMemorySizeSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/binary/GridPortableCacheEntryMemorySizeSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/binary/GridPortableCacheEntryMemorySizeSelfTest.java
deleted file mode 100644
index f2c75c9..0000000
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/binary/GridPortableCacheEntryMemorySizeSelfTest.java
+++ /dev/null
@@ -1,48 +0,0 @@
-/*
- * 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.processors.cache.binary;
-
-import org.apache.ignite.IgniteCheckedException;
-import org.apache.ignite.configuration.IgniteConfiguration;
-import org.apache.ignite.internal.binary.BinaryNoopMetadataHandler;
-import org.apache.ignite.internal.binary.PortableContext;
-import org.apache.ignite.internal.processors.cache.GridCacheEntryMemorySizeSelfTest;
-import org.apache.ignite.internal.util.IgniteUtils;
-import org.apache.ignite.marshaller.Marshaller;
-import org.apache.ignite.marshaller.MarshallerContextTestImpl;
-import org.apache.ignite.internal.binary.BinaryMarshaller;
-
-/**
- *
- */
-public class GridPortableCacheEntryMemorySizeSelfTest extends GridCacheEntryMemorySizeSelfTest {
-    /** {@inheritDoc} */
-    @Override protected Marshaller createMarshaller() throws IgniteCheckedException {
-        BinaryMarshaller marsh = new BinaryMarshaller();
-
-        marsh.setContext(new MarshallerContextTestImpl(null));
-
-        IgniteConfiguration iCfg = new IgniteConfiguration();
-
-        PortableContext pCtx = new PortableContext(BinaryNoopMetadataHandler.instance(), iCfg);
-
-        IgniteUtils.invoke(BinaryMarshaller.class, marsh, "setPortableContext", pCtx, iCfg);
-
-        return marsh;
-    }
-}

http://git-wip-us.apache.org/repos/asf/ignite/blob/71ad9cea/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/binary/GridPortableDuplicateIndexObjectsAbstractSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/binary/GridPortableDuplicateIndexObjectsAbstractSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/binary/GridPortableDuplicateIndexObjectsAbstractSelfTest.java
deleted file mode 100644
index 6ef8749..0000000
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/binary/GridPortableDuplicateIndexObjectsAbstractSelfTest.java
+++ /dev/null
@@ -1,161 +0,0 @@
-/*
- * 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.processors.cache.binary;
-
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import org.apache.ignite.IgniteCache;
-import org.apache.ignite.cache.CacheAtomicityMode;
-import org.apache.ignite.cache.CacheMode;
-import org.apache.ignite.cache.CacheTypeMetadata;
-import org.apache.ignite.cache.query.SqlFieldsQuery;
-import org.apache.ignite.configuration.BinaryConfiguration;
-import org.apache.ignite.configuration.CacheConfiguration;
-import org.apache.ignite.configuration.IgniteConfiguration;
-import org.apache.ignite.internal.processors.cache.GridCacheAbstractSelfTest;
-import org.apache.ignite.internal.util.typedef.F;
-import org.apache.ignite.internal.binary.BinaryMarshaller;
-import org.apache.ignite.binary.BinaryObject;
-
-/**
- * Tests that portable object is the same in cache entry and in index.
- */
-public abstract class GridPortableDuplicateIndexObjectsAbstractSelfTest extends GridCacheAbstractSelfTest {
-    /** {@inheritDoc} */
-    @Override protected int gridCount() {
-        return 1;
-    }
-
-    /** {@inheritDoc} */
-    @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception {
-        IgniteConfiguration cfg = super.getConfiguration(gridName);
-
-        BinaryConfiguration bCfg = new BinaryConfiguration();
-
-        bCfg.setClassNames(Collections.singletonList(TestPortable.class.getName()));
-
-        cfg.setBinaryConfiguration(bCfg);
-
-        cfg.setMarshaller(new BinaryMarshaller());
-
-        return cfg;
-    }
-
-    /** {@inheritDoc} */
-    @Override protected CacheConfiguration cacheConfiguration(String gridName) throws Exception {
-        CacheConfiguration ccfg = super.cacheConfiguration(gridName);
-
-        ccfg.setCopyOnRead(false);
-
-        CacheTypeMetadata meta = new CacheTypeMetadata();
-
-        meta.setKeyType(Integer.class);
-        meta.setValueType(TestPortable.class.getName());
-
-        Map<String, Class<?>> idx = new HashMap<>();
-
-        idx.put("fieldOne", String.class);
-        idx.put("fieldTwo", Integer.class);
-
-        meta.setAscendingFields(idx);
-
-        ccfg.setTypeMetadata(Collections.singletonList(meta));
-
-        return ccfg;
-    }
-
-    /** {@inheritDoc} */
-    @Override public abstract CacheAtomicityMode atomicityMode();
-
-    /** {@inheritDoc} */
-    @Override public abstract CacheMode cacheMode();
-
-    /**
-     * @throws Exception If failed.
-     */
-    public void testIndexReferences() throws Exception {
-        IgniteCache<Integer, TestPortable> cache = grid(0).cache(null);
-
-        String fieldOneVal = "123";
-        int fieldTwoVal = 123;
-        int key = 0;
-
-        cache.put(key, new TestPortable(fieldOneVal, fieldTwoVal));
-
-        IgniteCache<Integer, BinaryObject> prj = grid(0).cache(null).withKeepBinary();
-
-        BinaryObject cacheVal = prj.get(key);
-
-        assertEquals(fieldOneVal, cacheVal.field("fieldOne"));
-        assertEquals(new Integer(fieldTwoVal), cacheVal.field("fieldTwo"));
-
-        List<?> row = F.first(prj.query(new SqlFieldsQuery("select _val from " +
-            "TestPortable where _key = ?").setArgs(key)).getAll());
-
-        assertEquals(1, row.size());
-
-        BinaryObject qryVal = (BinaryObject)row.get(0);
-
-        assertEquals(fieldOneVal, qryVal.field("fieldOne"));
-        assertEquals(new Integer(fieldTwoVal), qryVal.field("fieldTwo"));
-        assertSame(cacheVal, qryVal);
-    }
-
-    /**
-     * Test portable object.
-     */
-    private static class TestPortable {
-        /** */
-        private String fieldOne;
-
-        /** */
-        private int fieldTwo;
-
-        /**
-         *
-         */
-        private TestPortable() {
-            // No-op.
-        }
-
-        /**
-         * @param fieldOne Field one.
-         * @param fieldTwo Field two.
-         */
-        private TestPortable(String fieldOne, int fieldTwo) {
-            this.fieldOne = fieldOne;
-            this.fieldTwo = fieldTwo;
-        }
-
-        /**
-         * @return Field one.
-         */
-        public String fieldOne() {
-            return fieldOne;
-        }
-
-        /**
-         * @return Field two.
-         */
-        public int fieldTwo() {
-            return fieldTwo;
-        }
-    }
-}

http://git-wip-us.apache.org/repos/asf/ignite/blob/71ad9cea/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/binary/datastreaming/DataStreamProcessorBinarySelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/binary/datastreaming/DataStreamProcessorBinarySelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/binary/datastreaming/DataStreamProcessorBinarySelfTest.java
new file mode 100644
index 0000000..bb53123
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/binary/datastreaming/DataStreamProcessorBinarySelfTest.java
@@ -0,0 +1,71 @@
+/*
+ * 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.processors.cache.binary.datastreaming;
+
+import java.util.Collection;
+import java.util.Map;
+import org.apache.ignite.IgniteCache;
+import org.apache.ignite.binary.BinaryObject;
+import org.apache.ignite.configuration.IgniteConfiguration;
+import org.apache.ignite.internal.processors.datastreamer.DataStreamProcessorSelfTest;
+import org.apache.ignite.internal.binary.BinaryMarshaller;
+import org.apache.ignite.stream.StreamReceiver;
+
+/**
+ *
+ */
+public class DataStreamProcessorBinarySelfTest extends DataStreamProcessorSelfTest {
+    /** {@inheritDoc} */
+    @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception {
+        IgniteConfiguration cfg = super.getConfiguration(gridName);
+
+        BinaryMarshaller marsh = new BinaryMarshaller();
+
+        cfg.setMarshaller(marsh);
+
+        return cfg;
+    }
+
+    /** {@inheritDoc} */
+    @Override protected StreamReceiver<String, TestObject> getStreamReceiver() {
+        return new TestDataReceiver();
+    }
+
+    /** {@inheritDoc} */
+    @Override protected boolean customKeepBinary() {
+        return true;
+    }
+
+    /**
+     *
+     */
+    private static class TestDataReceiver implements StreamReceiver<String, TestObject> {
+        /** {@inheritDoc} */
+        @Override public void receive(IgniteCache<String, TestObject> cache,
+            Collection<Map.Entry<String, TestObject>> entries) {
+            for (Map.Entry<String, TestObject> e : entries) {
+                assertTrue(e.getKey() instanceof String);
+                assertTrue(String.valueOf(e.getValue()), e.getValue() instanceof BinaryObject);
+
+                TestObject obj = ((BinaryObject)e.getValue()).deserialize();
+
+                cache.put(e.getKey(), new TestObject(obj.val + 1));
+            }
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/71ad9cea/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/binary/datastreaming/DataStreamProcessorPortableSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/binary/datastreaming/DataStreamProcessorPortableSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/binary/datastreaming/DataStreamProcessorPortableSelfTest.java
deleted file mode 100644
index 0538b9e..0000000
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/binary/datastreaming/DataStreamProcessorPortableSelfTest.java
+++ /dev/null
@@ -1,71 +0,0 @@
-/*
- * 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.processors.cache.binary.datastreaming;
-
-import java.util.Collection;
-import java.util.Map;
-import org.apache.ignite.IgniteCache;
-import org.apache.ignite.binary.BinaryObject;
-import org.apache.ignite.configuration.IgniteConfiguration;
-import org.apache.ignite.internal.processors.datastreamer.DataStreamProcessorSelfTest;
-import org.apache.ignite.internal.binary.BinaryMarshaller;
-import org.apache.ignite.stream.StreamReceiver;
-
-/**
- *
- */
-public class DataStreamProcessorPortableSelfTest extends DataStreamProcessorSelfTest {
-    /** {@inheritDoc} */
-    @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception {
-        IgniteConfiguration cfg = super.getConfiguration(gridName);
-
-        BinaryMarshaller marsh = new BinaryMarshaller();
-
-        cfg.setMarshaller(marsh);
-
-        return cfg;
-    }
-
-    /** {@inheritDoc} */
-    @Override protected StreamReceiver<String, TestObject> getStreamReceiver() {
-        return new TestDataReceiver();
-    }
-
-    /** {@inheritDoc} */
-    @Override protected boolean customKeepBinary() {
-        return true;
-    }
-
-    /**
-     *
-     */
-    private static class TestDataReceiver implements StreamReceiver<String, TestObject> {
-        /** {@inheritDoc} */
-        @Override public void receive(IgniteCache<String, TestObject> cache,
-            Collection<Map.Entry<String, TestObject>> entries) {
-            for (Map.Entry<String, TestObject> e : entries) {
-                assertTrue(e.getKey() instanceof String);
-                assertTrue(String.valueOf(e.getValue()), e.getValue() instanceof BinaryObject);
-
-                TestObject obj = ((BinaryObject)e.getValue()).deserialize();
-
-                cache.put(e.getKey(), new TestObject(obj.val + 1));
-            }
-        }
-    }
-}

http://git-wip-us.apache.org/repos/asf/ignite/blob/71ad9cea/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/binary/distributed/dht/GridCacheAffinityRoutingBinarySelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/binary/distributed/dht/GridCacheAffinityRoutingBinarySelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/binary/distributed/dht/GridCacheAffinityRoutingBinarySelfTest.java
new file mode 100644
index 0000000..5b21c99
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/binary/distributed/dht/GridCacheAffinityRoutingBinarySelfTest.java
@@ -0,0 +1,54 @@
+/*
+ * 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.processors.cache.binary.distributed.dht;
+
+import java.util.Collections;
+import org.apache.ignite.cache.CacheKeyConfiguration;
+import org.apache.ignite.configuration.BinaryConfiguration;
+import org.apache.ignite.configuration.IgniteConfiguration;
+import org.apache.ignite.internal.processors.cache.GridCacheAffinityRoutingSelfTest;
+import org.apache.ignite.internal.binary.BinaryMarshaller;
+import org.apache.ignite.binary.BinaryTypeConfiguration;
+
+/**
+ *
+ */
+public class GridCacheAffinityRoutingBinarySelfTest extends GridCacheAffinityRoutingSelfTest {
+    /** {@inheritDoc} */
+    @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception {
+        IgniteConfiguration cfg = super.getConfiguration(gridName);
+
+        BinaryTypeConfiguration typeCfg = new BinaryTypeConfiguration();
+
+        typeCfg.setTypeName(AffinityTestKey.class.getName());
+
+        CacheKeyConfiguration keyCfg = new CacheKeyConfiguration(AffinityTestKey.class.getName(), "affKey");
+
+        cfg.setCacheKeyConfiguration(keyCfg);
+
+        BinaryConfiguration bCfg = new BinaryConfiguration();
+
+        bCfg.setTypeConfigurations(Collections.singleton(typeCfg));
+
+        cfg.setBinaryConfiguration(bCfg);
+
+        cfg.setMarshaller(new BinaryMarshaller());
+
+        return cfg;
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/71ad9cea/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/binary/distributed/dht/GridCacheAffinityRoutingPortableSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/binary/distributed/dht/GridCacheAffinityRoutingPortableSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/binary/distributed/dht/GridCacheAffinityRoutingPortableSelfTest.java
deleted file mode 100644
index 9f564dd..0000000
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/binary/distributed/dht/GridCacheAffinityRoutingPortableSelfTest.java
+++ /dev/null
@@ -1,54 +0,0 @@
-/*
- * 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.processors.cache.binary.distributed.dht;
-
-import java.util.Collections;
-import org.apache.ignite.cache.CacheKeyConfiguration;
-import org.apache.ignite.configuration.BinaryConfiguration;
-import org.apache.ignite.configuration.IgniteConfiguration;
-import org.apache.ignite.internal.processors.cache.GridCacheAffinityRoutingSelfTest;
-import org.apache.ignite.internal.binary.BinaryMarshaller;
-import org.apache.ignite.binary.BinaryTypeConfiguration;
-
-/**
- *
- */
-public class GridCacheAffinityRoutingPortableSelfTest extends GridCacheAffinityRoutingSelfTest {
-    /** {@inheritDoc} */
-    @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception {
-        IgniteConfiguration cfg = super.getConfiguration(gridName);
-
-        BinaryTypeConfiguration typeCfg = new BinaryTypeConfiguration();
-
-        typeCfg.setTypeName(AffinityTestKey.class.getName());
-
-        CacheKeyConfiguration keyCfg = new CacheKeyConfiguration(AffinityTestKey.class.getName(), "affKey");
-
-        cfg.setCacheKeyConfiguration(keyCfg);
-
-        BinaryConfiguration bCfg = new BinaryConfiguration();
-
-        bCfg.setTypeConfigurations(Collections.singleton(typeCfg));
-
-        cfg.setBinaryConfiguration(bCfg);
-
-        cfg.setMarshaller(new BinaryMarshaller());
-
-        return cfg;
-    }
-}

http://git-wip-us.apache.org/repos/asf/ignite/blob/71ad9cea/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/binary/distributed/dht/GridCacheAtomicPartitionedOnlyBinaryDataStreamerMultiNodeSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/binary/distributed/dht/GridCacheAtomicPartitionedOnlyBinaryDataStreamerMultiNodeSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/binary/distributed/dht/GridCacheAtomicPartitionedOnlyBinaryDataStreamerMultiNodeSelfTest.java
new file mode 100644
index 0000000..10effbd
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/binary/distributed/dht/GridCacheAtomicPartitionedOnlyBinaryDataStreamerMultiNodeSelfTest.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.processors.cache.binary.distributed.dht;
+
+/**
+ *
+ */
+public class GridCacheAtomicPartitionedOnlyBinaryDataStreamerMultiNodeSelfTest extends
+    GridCacheAtomicPartitionedOnlyBinaryDataStreamerMultithreadedSelfTest {
+    /** {@inheritDoc} */
+    @Override protected int gridCount() {
+        return 4;
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/71ad9cea/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/binary/distributed/dht/GridCacheAtomicPartitionedOnlyBinaryDataStreamerMultithreadedSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/binary/distributed/dht/GridCacheAtomicPartitionedOnlyBinaryDataStreamerMultithreadedSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/binary/distributed/dht/GridCacheAtomicPartitionedOnlyBinaryDataStreamerMultithreadedSelfTest.java
new file mode 100644
index 0000000..c48f2a5
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/binary/distributed/dht/GridCacheAtomicPartitionedOnlyBinaryDataStreamerMultithreadedSelfTest.java
@@ -0,0 +1,47 @@
+/*
+ * 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.processors.cache.binary.distributed.dht;
+
+import org.apache.ignite.cache.CacheAtomicityMode;
+import org.apache.ignite.cache.CacheMode;
+import org.apache.ignite.configuration.NearCacheConfiguration;
+import org.apache.ignite.internal.processors.cache.binary.GridCacheBinaryObjectsAbstractDataStreamerSelfTest;
+
+import static org.apache.ignite.cache.CacheAtomicityMode.ATOMIC;
+import static org.apache.ignite.cache.CacheMode.PARTITIONED;
+
+/**
+ *
+ */
+public class GridCacheAtomicPartitionedOnlyBinaryDataStreamerMultithreadedSelfTest extends
+    GridCacheBinaryObjectsAbstractDataStreamerSelfTest {
+    /** {@inheritDoc} */
+    @Override protected CacheMode cacheMode() {
+        return PARTITIONED;
+    }
+
+    /** {@inheritDoc} */
+    @Override protected CacheAtomicityMode atomicityMode() {
+        return ATOMIC;
+    }
+
+    /** {@inheritDoc} */
+    @Override protected NearCacheConfiguration nearConfiguration() {
+        return null;
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/71ad9cea/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/binary/distributed/dht/GridCacheAtomicPartitionedOnlyBinaryMultiNodeSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/binary/distributed/dht/GridCacheAtomicPartitionedOnlyBinaryMultiNodeSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/binary/distributed/dht/GridCacheAtomicPartitionedOnlyBinaryMultiNodeSelfTest.java
new file mode 100644
index 0000000..064f0c5
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/binary/distributed/dht/GridCacheAtomicPartitionedOnlyBinaryMultiNodeSelfTest.java
@@ -0,0 +1,28 @@
+/*
+ * 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.processors.cache.binary.distributed.dht;
+
+/**
+ *
+ */
+public class GridCacheAtomicPartitionedOnlyBinaryMultiNodeSelfTest extends
+    GridCacheAtomicPartitionedOnlyBinaryMultithreadedSelfTest {
+    /** {@inheritDoc} */
+    @Override protected int gridCount() {
+        return 4;
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/71ad9cea/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/binary/distributed/dht/GridCacheAtomicPartitionedOnlyBinaryMultithreadedSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/binary/distributed/dht/GridCacheAtomicPartitionedOnlyBinaryMultithreadedSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/binary/distributed/dht/GridCacheAtomicPartitionedOnlyBinaryMultithreadedSelfTest.java
new file mode 100644
index 0000000..1836f3a
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/binary/distributed/dht/GridCacheAtomicPartitionedOnlyBinaryMultithreadedSelfTest.java
@@ -0,0 +1,47 @@
+/*
+ * 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.processors.cache.binary.distributed.dht;
+
+import org.apache.ignite.cache.CacheAtomicityMode;
+import org.apache.ignite.cache.CacheMode;
+import org.apache.ignite.configuration.NearCacheConfiguration;
+import org.apache.ignite.internal.processors.cache.binary.GridCacheBinaryObjectsAbstractMultiThreadedSelfTest;
+
+import static org.apache.ignite.cache.CacheAtomicityMode.ATOMIC;
+import static org.apache.ignite.cache.CacheMode.PARTITIONED;
+
+/**
+ *
+ */
+public class GridCacheAtomicPartitionedOnlyBinaryMultithreadedSelfTest extends
+    GridCacheBinaryObjectsAbstractMultiThreadedSelfTest {
+    /** {@inheritDoc} */
+    @Override protected CacheMode cacheMode() {
+        return PARTITIONED;
+    }
+
+    /** {@inheritDoc} */
+    @Override protected CacheAtomicityMode atomicityMode() {
+        return ATOMIC;
+    }
+
+    /** {@inheritDoc} */
+    @Override protected NearCacheConfiguration nearConfiguration() {
+        return null;
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/71ad9cea/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/binary/distributed/dht/GridCacheAtomicPartitionedOnlyPortableDataStreamerMultiNodeSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/binary/distributed/dht/GridCacheAtomicPartitionedOnlyPortableDataStreamerMultiNodeSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/binary/distributed/dht/GridCacheAtomicPartitionedOnlyPortableDataStreamerMultiNodeSelfTest.java
deleted file mode 100644
index 82ad26f..0000000
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/binary/distributed/dht/GridCacheAtomicPartitionedOnlyPortableDataStreamerMultiNodeSelfTest.java
+++ /dev/null
@@ -1,29 +0,0 @@
-/*
- * 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.processors.cache.binary.distributed.dht;
-
-/**
- *
- */
-public class GridCacheAtomicPartitionedOnlyPortableDataStreamerMultiNodeSelfTest extends
-    GridCacheAtomicPartitionedOnlyPortableDataStreamerMultithreadedSelfTest {
-    /** {@inheritDoc} */
-    @Override protected int gridCount() {
-        return 4;
-    }
-}

http://git-wip-us.apache.org/repos/asf/ignite/blob/71ad9cea/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/binary/distributed/dht/GridCacheAtomicPartitionedOnlyPortableDataStreamerMultithreadedSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/binary/distributed/dht/GridCacheAtomicPartitionedOnlyPortableDataStreamerMultithreadedSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/binary/distributed/dht/GridCacheAtomicPartitionedOnlyPortableDataStreamerMultithreadedSelfTest.java
deleted file mode 100644
index 3e37a18..0000000
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/binary/distributed/dht/GridCacheAtomicPartitionedOnlyPortableDataStreamerMultithreadedSelfTest.java
+++ /dev/null
@@ -1,47 +0,0 @@
-/*
- * 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.processors.cache.binary.distributed.dht;
-
-import org.apache.ignite.cache.CacheAtomicityMode;
-import org.apache.ignite.cache.CacheMode;
-import org.apache.ignite.configuration.NearCacheConfiguration;
-import org.apache.ignite.internal.processors.cache.binary.GridCacheBinaryObjectsAbstractDataStreamerSelfTest;
-
-import static org.apache.ignite.cache.CacheAtomicityMode.ATOMIC;
-import static org.apache.ignite.cache.CacheMode.PARTITIONED;
-
-/**
- *
- */
-public class GridCacheAtomicPartitionedOnlyPortableDataStreamerMultithreadedSelfTest extends
-    GridCacheBinaryObjectsAbstractDataStreamerSelfTest {
-    /** {@inheritDoc} */
-    @Override protected CacheMode cacheMode() {
-        return PARTITIONED;
-    }
-
-    /** {@inheritDoc} */
-    @Override protected CacheAtomicityMode atomicityMode() {
-        return ATOMIC;
-    }
-
-    /** {@inheritDoc} */
-    @Override protected NearCacheConfiguration nearConfiguration() {
-        return null;
-    }
-}

http://git-wip-us.apache.org/repos/asf/ignite/blob/71ad9cea/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/binary/distributed/dht/GridCacheAtomicPartitionedOnlyPortableMultiNodeSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/binary/distributed/dht/GridCacheAtomicPartitionedOnlyPortableMultiNodeSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/binary/distributed/dht/GridCacheAtomicPartitionedOnlyPortableMultiNodeSelfTest.java
deleted file mode 100644
index d704dcf..0000000
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/binary/distributed/dht/GridCacheAtomicPartitionedOnlyPortableMultiNodeSelfTest.java
+++ /dev/null
@@ -1,28 +0,0 @@
-/*
- * 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.processors.cache.binary.distributed.dht;
-
-/**
- *
- */
-public class GridCacheAtomicPartitionedOnlyPortableMultiNodeSelfTest extends
-    GridCacheAtomicPartitionedOnlyPortableMultithreadedSelfTest {
-    /** {@inheritDoc} */
-    @Override protected int gridCount() {
-        return 4;
-    }
-}

http://git-wip-us.apache.org/repos/asf/ignite/blob/71ad9cea/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/binary/distributed/dht/GridCacheAtomicPartitionedOnlyPortableMultithreadedSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/binary/distributed/dht/GridCacheAtomicPartitionedOnlyPortableMultithreadedSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/binary/distributed/dht/GridCacheAtomicPartitionedOnlyPortableMultithreadedSelfTest.java
deleted file mode 100644
index 4391b2b..0000000
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/binary/distributed/dht/GridCacheAtomicPartitionedOnlyPortableMultithreadedSelfTest.java
+++ /dev/null
@@ -1,47 +0,0 @@
-/*
- * 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.processors.cache.binary.distributed.dht;
-
-import org.apache.ignite.cache.CacheAtomicityMode;
-import org.apache.ignite.cache.CacheMode;
-import org.apache.ignite.configuration.NearCacheConfiguration;
-import org.apache.ignite.internal.processors.cache.binary.GridCacheBinaryObjectsAbstractMultiThreadedSelfTest;
-
-import static org.apache.ignite.cache.CacheAtomicityMode.ATOMIC;
-import static org.apache.ignite.cache.CacheMode.PARTITIONED;
-
-/**
- *
- */
-public class GridCacheAtomicPartitionedOnlyPortableMultithreadedSelfTest extends
-    GridCacheBinaryObjectsAbstractMultiThreadedSelfTest {
-    /** {@inheritDoc} */
-    @Override protected CacheMode cacheMode() {
-        return PARTITIONED;
-    }
-
-    /** {@inheritDoc} */
-    @Override protected CacheAtomicityMode atomicityMode() {
-        return ATOMIC;
-    }
-
-    /** {@inheritDoc} */
-    @Override protected NearCacheConfiguration nearConfiguration() {
-        return null;
-    }
-}

http://git-wip-us.apache.org/repos/asf/ignite/blob/71ad9cea/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/binary/distributed/dht/GridCacheBinariesPartitionedOnlyByteArrayValuesSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/binary/distributed/dht/GridCacheBinariesPartitionedOnlyByteArrayValuesSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/binary/distributed/dht/GridCacheBinariesPartitionedOnlyByteArrayValuesSelfTest.java
new file mode 100644
index 0000000..8e21dac
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/binary/distributed/dht/GridCacheBinariesPartitionedOnlyByteArrayValuesSelfTest.java
@@ -0,0 +1,42 @@
+/*
+ * 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.processors.cache.binary.distributed.dht;
+
+import org.apache.ignite.configuration.IgniteConfiguration;
+import org.apache.ignite.internal.processors.cache.distributed.dht.GridCacheAbstractPartitionedOnlyByteArrayValuesSelfTest;
+import org.apache.ignite.internal.binary.BinaryMarshaller;
+
+/**
+ *
+ */
+public class GridCacheBinariesPartitionedOnlyByteArrayValuesSelfTest
+    extends GridCacheAbstractPartitionedOnlyByteArrayValuesSelfTest {
+    /** {@inheritDoc} */
+    @Override protected boolean peerClassLoading() {
+        return false;
+    }
+
+    /** {@inheritDoc} */
+    @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception {
+        IgniteConfiguration cfg = super.getConfiguration(gridName);
+
+        cfg.setMarshaller(new BinaryMarshaller());
+
+        return cfg;
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/71ad9cea/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/binary/distributed/dht/GridCacheBinaryDuplicateIndexObjectPartitionedAtomicSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/binary/distributed/dht/GridCacheBinaryDuplicateIndexObjectPartitionedAtomicSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/binary/distributed/dht/GridCacheBinaryDuplicateIndexObjectPartitionedAtomicSelfTest.java
new file mode 100644
index 0000000..459d0ee
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/binary/distributed/dht/GridCacheBinaryDuplicateIndexObjectPartitionedAtomicSelfTest.java
@@ -0,0 +1,38 @@
+/*
+ * 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.processors.cache.binary.distributed.dht;
+
+import org.apache.ignite.cache.CacheAtomicityMode;
+import org.apache.ignite.cache.CacheMode;
+import org.apache.ignite.internal.processors.cache.binary.GridBinaryDuplicateIndexObjectsAbstractSelfTest;
+
+/**
+ * Test PARTITIONED ATOMIC.
+ */
+public class GridCacheBinaryDuplicateIndexObjectPartitionedAtomicSelfTest extends
+    GridBinaryDuplicateIndexObjectsAbstractSelfTest {
+    /** {@inheritDoc} */
+    @Override public CacheAtomicityMode atomicityMode() {
+        return CacheAtomicityMode.ATOMIC;
+    }
+
+    /** {@inheritDoc} */
+    @Override public CacheMode cacheMode() {
+        return CacheMode.PARTITIONED;
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/71ad9cea/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/binary/distributed/dht/GridCacheBinaryDuplicateIndexObjectPartitionedTransactionalSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/binary/distributed/dht/GridCacheBinaryDuplicateIndexObjectPartitionedTransactionalSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/binary/distributed/dht/GridCacheBinaryDuplicateIndexObjectPartitionedTransactionalSelfTest.java
new file mode 100644
index 0000000..e319fe4
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/binary/distributed/dht/GridCacheBinaryDuplicateIndexObjectPartitionedTransactionalSelfTest.java
@@ -0,0 +1,41 @@
+/*
+ * 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.processors.cache.binary.distributed.dht;
+
+import org.apache.ignite.cache.CacheAtomicityMode;
+import org.apache.ignite.cache.CacheMode;
+import org.apache.ignite.internal.processors.cache.binary.GridBinaryDuplicateIndexObjectsAbstractSelfTest;
+
+import static org.apache.ignite.cache.CacheAtomicityMode.TRANSACTIONAL;
+import static org.apache.ignite.cache.CacheMode.PARTITIONED;
+
+/**
+ * Test PARTITIONED and TRANSACTIONAL.
+ */
+public class GridCacheBinaryDuplicateIndexObjectPartitionedTransactionalSelfTest extends
+    GridBinaryDuplicateIndexObjectsAbstractSelfTest {
+    /** {@inheritDoc} */
+    @Override public CacheAtomicityMode atomicityMode() {
+        return TRANSACTIONAL;
+    }
+
+    /** {@inheritDoc} */
+    @Override public CacheMode cacheMode() {
+        return PARTITIONED;
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/71ad9cea/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/binary/distributed/dht/GridCacheMemoryModeBinarySelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/binary/distributed/dht/GridCacheMemoryModeBinarySelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/binary/distributed/dht/GridCacheMemoryModeBinarySelfTest.java
new file mode 100644
index 0000000..119ba03
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/binary/distributed/dht/GridCacheMemoryModeBinarySelfTest.java
@@ -0,0 +1,36 @@
+/*
+ * 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.processors.cache.binary.distributed.dht;
+
+import org.apache.ignite.configuration.IgniteConfiguration;
+import org.apache.ignite.internal.processors.cache.GridCacheMemoryModeSelfTest;
+import org.apache.ignite.internal.binary.BinaryMarshaller;
+
+/**
+ * Memory models test.
+ */
+public class GridCacheMemoryModeBinarySelfTest extends GridCacheMemoryModeSelfTest {
+    /** {@inheritDoc} */
+    @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception {
+        IgniteConfiguration cfg = super.getConfiguration(gridName);
+
+        cfg.setMarshaller(new BinaryMarshaller());
+
+        return cfg;
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/71ad9cea/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/binary/distributed/dht/GridCacheMemoryModePortableSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/binary/distributed/dht/GridCacheMemoryModePortableSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/binary/distributed/dht/GridCacheMemoryModePortableSelfTest.java
deleted file mode 100644
index 7836c17..0000000
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/binary/distributed/dht/GridCacheMemoryModePortableSelfTest.java
+++ /dev/null
@@ -1,36 +0,0 @@
-/*
- * 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.processors.cache.binary.distributed.dht;
-
-import org.apache.ignite.configuration.IgniteConfiguration;
-import org.apache.ignite.internal.processors.cache.GridCacheMemoryModeSelfTest;
-import org.apache.ignite.internal.binary.BinaryMarshaller;
-
-/**
- * Memory models test.
- */
-public class GridCacheMemoryModePortableSelfTest extends GridCacheMemoryModeSelfTest {
-    /** {@inheritDoc} */
-    @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception {
-        IgniteConfiguration cfg = super.getConfiguration(gridName);
-
-        cfg.setMarshaller(new BinaryMarshaller());
-
-        return cfg;
-    }
-}

http://git-wip-us.apache.org/repos/asf/ignite/blob/71ad9cea/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/binary/distributed/dht/GridCacheOffHeapTieredAtomicBinarySelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/binary/distributed/dht/GridCacheOffHeapTieredAtomicBinarySelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/binary/distributed/dht/GridCacheOffHeapTieredAtomicBinarySelfTest.java
new file mode 100644
index 0000000..3494b5c
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/binary/distributed/dht/GridCacheOffHeapTieredAtomicBinarySelfTest.java
@@ -0,0 +1,48 @@
+/*
+ * 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.processors.cache.binary.distributed.dht;
+
+import java.util.Arrays;
+import org.apache.ignite.configuration.BinaryConfiguration;
+import org.apache.ignite.configuration.IgniteConfiguration;
+import org.apache.ignite.internal.processors.cache.GridCacheOffHeapTieredAtomicSelfTest;
+import org.apache.ignite.internal.binary.BinaryMarshaller;
+
+/**
+ *
+ */
+public class GridCacheOffHeapTieredAtomicBinarySelfTest extends GridCacheOffHeapTieredAtomicSelfTest {
+    /** {@inheritDoc} */
+    @Override protected boolean portableEnabled() {
+        return true;
+    }
+
+    /** {@inheritDoc} */
+    @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception {
+        // Enable binary.
+        IgniteConfiguration cfg = super.getConfiguration(gridName);
+
+        BinaryConfiguration bCfg = new BinaryConfiguration();
+
+        bCfg.setClassNames(Arrays.asList(TestValue.class.getName()));
+
+        cfg.setMarshaller(new BinaryMarshaller());
+
+        return cfg;
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/71ad9cea/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/binary/distributed/dht/GridCacheOffHeapTieredAtomicPortableSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/binary/distributed/dht/GridCacheOffHeapTieredAtomicPortableSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/binary/distributed/dht/GridCacheOffHeapTieredAtomicPortableSelfTest.java
deleted file mode 100644
index 0d9b1ec..0000000
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/binary/distributed/dht/GridCacheOffHeapTieredAtomicPortableSelfTest.java
+++ /dev/null
@@ -1,48 +0,0 @@
-/*
- * 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.processors.cache.binary.distributed.dht;
-
-import java.util.Arrays;
-import org.apache.ignite.configuration.BinaryConfiguration;
-import org.apache.ignite.configuration.IgniteConfiguration;
-import org.apache.ignite.internal.processors.cache.GridCacheOffHeapTieredAtomicSelfTest;
-import org.apache.ignite.internal.binary.BinaryMarshaller;
-
-/**
- *
- */
-public class GridCacheOffHeapTieredAtomicPortableSelfTest extends GridCacheOffHeapTieredAtomicSelfTest {
-    /** {@inheritDoc} */
-    @Override protected boolean portableEnabled() {
-        return true;
-    }
-
-    /** {@inheritDoc} */
-    @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception {
-        // Enable binary.
-        IgniteConfiguration cfg = super.getConfiguration(gridName);
-
-        BinaryConfiguration bCfg = new BinaryConfiguration();
-
-        bCfg.setClassNames(Arrays.asList(TestValue.class.getName()));
-
-        cfg.setMarshaller(new BinaryMarshaller());
-
-        return cfg;
-    }
-}

http://git-wip-us.apache.org/repos/asf/ignite/blob/71ad9cea/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/binary/distributed/dht/GridCacheOffHeapTieredBinarySelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/binary/distributed/dht/GridCacheOffHeapTieredBinarySelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/binary/distributed/dht/GridCacheOffHeapTieredBinarySelfTest.java
new file mode 100644
index 0000000..7cde9e7
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/binary/distributed/dht/GridCacheOffHeapTieredBinarySelfTest.java
@@ -0,0 +1,48 @@
+/*
+ * 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.processors.cache.binary.distributed.dht;
+
+import java.util.Arrays;
+import org.apache.ignite.configuration.BinaryConfiguration;
+import org.apache.ignite.configuration.IgniteConfiguration;
+import org.apache.ignite.internal.processors.cache.GridCacheOffHeapTieredSelfTest;
+import org.apache.ignite.internal.binary.BinaryMarshaller;
+
+/**
+ *
+ */
+public class GridCacheOffHeapTieredBinarySelfTest extends GridCacheOffHeapTieredSelfTest {
+    /** {@inheritDoc} */
+    @Override protected boolean portableEnabled() {
+        return true;
+    }
+
+    /** {@inheritDoc} */
+    @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception {
+        // Enable binary.
+        IgniteConfiguration cfg = super.getConfiguration(gridName);
+
+        BinaryConfiguration bCfg = new BinaryConfiguration();
+
+        bCfg.setClassNames(Arrays.asList(TestValue.class.getName()));
+
+        cfg.setMarshaller(new BinaryMarshaller());
+
+        return cfg;
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/71ad9cea/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/binary/distributed/dht/GridCacheOffHeapTieredEvictionAtomicBinarySelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/binary/distributed/dht/GridCacheOffHeapTieredEvictionAtomicBinarySelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/binary/distributed/dht/GridCacheOffHeapTieredEvictionAtomicBinarySelfTest.java
new file mode 100644
index 0000000..79fe8d3
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/binary/distributed/dht/GridCacheOffHeapTieredEvictionAtomicBinarySelfTest.java
@@ -0,0 +1,96 @@
+/*
+ * 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.processors.cache.binary.distributed.dht;
+
+import java.util.Arrays;
+import org.apache.ignite.configuration.BinaryConfiguration;
+import org.apache.ignite.configuration.IgniteConfiguration;
+import org.apache.ignite.internal.processors.cache.GridCacheOffHeapTieredEvictionAtomicSelfTest;
+import org.apache.ignite.internal.binary.BinaryMarshaller;
+import org.apache.ignite.binary.BinaryObject;
+
+/**
+ *
+ */
+public class GridCacheOffHeapTieredEvictionAtomicBinarySelfTest extends GridCacheOffHeapTieredEvictionAtomicSelfTest {
+    /** {@inheritDoc} */
+    @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception {
+        // Enable binary.
+        IgniteConfiguration cfg = super.getConfiguration(gridName);
+
+        BinaryConfiguration bCfg = new BinaryConfiguration();
+
+        bCfg.setClassNames(Arrays.asList(TestValue.class.getName()));
+
+        cfg.setMarshaller(new BinaryMarshaller());
+
+        return cfg;
+    }
+
+    /** {@inheritDoc} */
+    @Override protected TestPredicate testPredicate(String expVal, boolean acceptNull) {
+        return new PortableValuePredicate(expVal, acceptNull);
+    }
+
+    /** {@inheritDoc} */
+    @Override protected TestProcessor testClosure(String expVal, boolean acceptNull) {
+        return new PortableValueClosure(expVal, acceptNull);
+    }
+
+    /**
+     *
+     */
+    @SuppressWarnings("PackageVisibleInnerClass")
+    static class PortableValuePredicate extends TestPredicate {
+        /**
+         * @param expVal Expected value.
+         * @param acceptNull If {@code true} value can be null;
+         */
+        PortableValuePredicate(String expVal, boolean acceptNull) {
+            super(expVal, acceptNull);
+        }
+
+        /** {@inheritDoc} */
+        @Override public void checkValue(Object val) {
+            BinaryObject obj = (BinaryObject)val;
+
+            assertEquals(expVal, obj.field("val"));
+        }
+    }
+
+    /**
+     *
+     */
+    @SuppressWarnings("PackageVisibleInnerClass")
+    static class PortableValueClosure extends TestProcessor {
+        /**
+         * @param expVal Expected value.
+         * @param acceptNull If {@code true} value can be null;
+         */
+        PortableValueClosure(String expVal, boolean acceptNull) {
+            super(expVal, acceptNull);
+        }
+
+        /** {@inheritDoc} */
+        @Override public void checkValue(Object val) {
+            BinaryObject obj = (BinaryObject)val;
+
+            assertEquals(expVal, obj.field("val"));
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/71ad9cea/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/binary/distributed/dht/GridCacheOffHeapTieredEvictionAtomicPortableSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/binary/distributed/dht/GridCacheOffHeapTieredEvictionAtomicPortableSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/binary/distributed/dht/GridCacheOffHeapTieredEvictionAtomicPortableSelfTest.java
deleted file mode 100644
index addee05..0000000
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/binary/distributed/dht/GridCacheOffHeapTieredEvictionAtomicPortableSelfTest.java
+++ /dev/null
@@ -1,96 +0,0 @@
-/*
- * 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.processors.cache.binary.distributed.dht;
-
-import java.util.Arrays;
-import org.apache.ignite.configuration.BinaryConfiguration;
-import org.apache.ignite.configuration.IgniteConfiguration;
-import org.apache.ignite.internal.processors.cache.GridCacheOffHeapTieredEvictionAtomicSelfTest;
-import org.apache.ignite.internal.binary.BinaryMarshaller;
-import org.apache.ignite.binary.BinaryObject;
-
-/**
- *
- */
-public class GridCacheOffHeapTieredEvictionAtomicPortableSelfTest extends GridCacheOffHeapTieredEvictionAtomicSelfTest {
-    /** {@inheritDoc} */
-    @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception {
-        // Enable binary.
-        IgniteConfiguration cfg = super.getConfiguration(gridName);
-
-        BinaryConfiguration bCfg = new BinaryConfiguration();
-
-        bCfg.setClassNames(Arrays.asList(TestValue.class.getName()));
-
-        cfg.setMarshaller(new BinaryMarshaller());
-
-        return cfg;
-    }
-
-    /** {@inheritDoc} */
-    @Override protected TestPredicate testPredicate(String expVal, boolean acceptNull) {
-        return new PortableValuePredicate(expVal, acceptNull);
-    }
-
-    /** {@inheritDoc} */
-    @Override protected TestProcessor testClosure(String expVal, boolean acceptNull) {
-        return new PortableValueClosure(expVal, acceptNull);
-    }
-
-    /**
-     *
-     */
-    @SuppressWarnings("PackageVisibleInnerClass")
-    static class PortableValuePredicate extends TestPredicate {
-        /**
-         * @param expVal Expected value.
-         * @param acceptNull If {@code true} value can be null;
-         */
-        PortableValuePredicate(String expVal, boolean acceptNull) {
-            super(expVal, acceptNull);
-        }
-
-        /** {@inheritDoc} */
-        @Override public void checkValue(Object val) {
-            BinaryObject obj = (BinaryObject)val;
-
-            assertEquals(expVal, obj.field("val"));
-        }
-    }
-
-    /**
-     *
-     */
-    @SuppressWarnings("PackageVisibleInnerClass")
-    static class PortableValueClosure extends TestProcessor {
-        /**
-         * @param expVal Expected value.
-         * @param acceptNull If {@code true} value can be null;
-         */
-        PortableValueClosure(String expVal, boolean acceptNull) {
-            super(expVal, acceptNull);
-        }
-
-        /** {@inheritDoc} */
-        @Override public void checkValue(Object val) {
-            BinaryObject obj = (BinaryObject)val;
-
-            assertEquals(expVal, obj.field("val"));
-        }
-    }
-}

http://git-wip-us.apache.org/repos/asf/ignite/blob/71ad9cea/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/binary/distributed/dht/GridCacheOffHeapTieredEvictionBinarySelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/binary/distributed/dht/GridCacheOffHeapTieredEvictionBinarySelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/binary/distributed/dht/GridCacheOffHeapTieredEvictionBinarySelfTest.java
new file mode 100644
index 0000000..9a47e4f
--- /dev/null
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/binary/distributed/dht/GridCacheOffHeapTieredEvictionBinarySelfTest.java
@@ -0,0 +1,96 @@
+/*
+ * 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.processors.cache.binary.distributed.dht;
+
+import java.util.Arrays;
+import org.apache.ignite.configuration.BinaryConfiguration;
+import org.apache.ignite.configuration.IgniteConfiguration;
+import org.apache.ignite.internal.processors.cache.GridCacheOffHeapTieredEvictionSelfTest;
+import org.apache.ignite.internal.binary.BinaryMarshaller;
+import org.apache.ignite.binary.BinaryObject;
+
+/**
+ *
+ */
+public class GridCacheOffHeapTieredEvictionBinarySelfTest extends GridCacheOffHeapTieredEvictionSelfTest {
+    /** {@inheritDoc} */
+    @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception {
+        // Enable binary.
+        IgniteConfiguration cfg = super.getConfiguration(gridName);
+
+        BinaryConfiguration bCfg = new BinaryConfiguration();
+
+        bCfg.setClassNames(Arrays.asList(TestValue.class.getName()));
+
+        cfg.setMarshaller(new BinaryMarshaller());
+
+        return cfg;
+    }
+
+    /** {@inheritDoc} */
+    @Override protected TestPredicate testPredicate(String expVal, boolean acceptNull) {
+        return new PortableValuePredicate(expVal, acceptNull);
+    }
+
+    /** {@inheritDoc} */
+    @Override protected TestProcessor testClosure(String expVal, boolean acceptNull) {
+        return new PortableValueClosure(expVal, acceptNull);
+    }
+
+    /**
+     *
+     */
+    @SuppressWarnings("PackageVisibleInnerClass")
+    static class PortableValuePredicate extends TestPredicate {
+        /**
+         * @param expVal Expected value.
+         * @param acceptNull If {@code true} value can be null;
+         */
+        PortableValuePredicate(String expVal, boolean acceptNull) {
+            super(expVal, acceptNull);
+        }
+
+        /** {@inheritDoc} */
+        @Override public void checkValue(Object val) {
+            BinaryObject obj = (BinaryObject)val;
+
+            assertEquals(expVal, obj.field("val"));
+        }
+    }
+
+    /**
+     *
+     */
+    @SuppressWarnings("PackageVisibleInnerClass")
+    static class PortableValueClosure extends TestProcessor {
+        /**
+         * @param expVal Expected value.
+         * @param acceptNull If {@code true} value can be null;
+         */
+        PortableValueClosure(String expVal, boolean acceptNull) {
+            super(expVal, acceptNull);
+        }
+
+        /** {@inheritDoc} */
+        @Override public void checkValue(Object val) {
+            BinaryObject obj = (BinaryObject)val;
+
+            assertEquals(expVal, obj.field("val"));
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/ignite/blob/71ad9cea/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/binary/distributed/dht/GridCacheOffHeapTieredEvictionPortableSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/binary/distributed/dht/GridCacheOffHeapTieredEvictionPortableSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/binary/distributed/dht/GridCacheOffHeapTieredEvictionPortableSelfTest.java
deleted file mode 100644
index 3e5d7e0..0000000
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/binary/distributed/dht/GridCacheOffHeapTieredEvictionPortableSelfTest.java
+++ /dev/null
@@ -1,96 +0,0 @@
-/*
- * 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.processors.cache.binary.distributed.dht;
-
-import java.util.Arrays;
-import org.apache.ignite.configuration.BinaryConfiguration;
-import org.apache.ignite.configuration.IgniteConfiguration;
-import org.apache.ignite.internal.processors.cache.GridCacheOffHeapTieredEvictionSelfTest;
-import org.apache.ignite.internal.binary.BinaryMarshaller;
-import org.apache.ignite.binary.BinaryObject;
-
-/**
- *
- */
-public class GridCacheOffHeapTieredEvictionPortableSelfTest extends GridCacheOffHeapTieredEvictionSelfTest {
-    /** {@inheritDoc} */
-    @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception {
-        // Enable binary.
-        IgniteConfiguration cfg = super.getConfiguration(gridName);
-
-        BinaryConfiguration bCfg = new BinaryConfiguration();
-
-        bCfg.setClassNames(Arrays.asList(TestValue.class.getName()));
-
-        cfg.setMarshaller(new BinaryMarshaller());
-
-        return cfg;
-    }
-
-    /** {@inheritDoc} */
-    @Override protected TestPredicate testPredicate(String expVal, boolean acceptNull) {
-        return new PortableValuePredicate(expVal, acceptNull);
-    }
-
-    /** {@inheritDoc} */
-    @Override protected TestProcessor testClosure(String expVal, boolean acceptNull) {
-        return new PortableValueClosure(expVal, acceptNull);
-    }
-
-    /**
-     *
-     */
-    @SuppressWarnings("PackageVisibleInnerClass")
-    static class PortableValuePredicate extends TestPredicate {
-        /**
-         * @param expVal Expected value.
-         * @param acceptNull If {@code true} value can be null;
-         */
-        PortableValuePredicate(String expVal, boolean acceptNull) {
-            super(expVal, acceptNull);
-        }
-
-        /** {@inheritDoc} */
-        @Override public void checkValue(Object val) {
-            BinaryObject obj = (BinaryObject)val;
-
-            assertEquals(expVal, obj.field("val"));
-        }
-    }
-
-    /**
-     *
-     */
-    @SuppressWarnings("PackageVisibleInnerClass")
-    static class PortableValueClosure extends TestProcessor {
-        /**
-         * @param expVal Expected value.
-         * @param acceptNull If {@code true} value can be null;
-         */
-        PortableValueClosure(String expVal, boolean acceptNull) {
-            super(expVal, acceptNull);
-        }
-
-        /** {@inheritDoc} */
-        @Override public void checkValue(Object val) {
-            BinaryObject obj = (BinaryObject)val;
-
-            assertEquals(expVal, obj.field("val"));
-        }
-    }
-}

http://git-wip-us.apache.org/repos/asf/ignite/blob/71ad9cea/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/binary/distributed/dht/GridCacheOffHeapTieredPortableSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/binary/distributed/dht/GridCacheOffHeapTieredPortableSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/binary/distributed/dht/GridCacheOffHeapTieredPortableSelfTest.java
deleted file mode 100644
index 12298c6..0000000
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/binary/distributed/dht/GridCacheOffHeapTieredPortableSelfTest.java
+++ /dev/null
@@ -1,48 +0,0 @@
-/*
- * 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.processors.cache.binary.distributed.dht;
-
-import java.util.Arrays;
-import org.apache.ignite.configuration.BinaryConfiguration;
-import org.apache.ignite.configuration.IgniteConfiguration;
-import org.apache.ignite.internal.processors.cache.GridCacheOffHeapTieredSelfTest;
-import org.apache.ignite.internal.binary.BinaryMarshaller;
-
-/**
- *
- */
-public class GridCacheOffHeapTieredPortableSelfTest extends GridCacheOffHeapTieredSelfTest {
-    /** {@inheritDoc} */
-    @Override protected boolean portableEnabled() {
-        return true;
-    }
-
-    /** {@inheritDoc} */
-    @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception {
-        // Enable binary.
-        IgniteConfiguration cfg = super.getConfiguration(gridName);
-
-        BinaryConfiguration bCfg = new BinaryConfiguration();
-
-        bCfg.setClassNames(Arrays.asList(TestValue.class.getName()));
-
-        cfg.setMarshaller(new BinaryMarshaller());
-
-        return cfg;
-    }
-}

http://git-wip-us.apache.org/repos/asf/ignite/blob/71ad9cea/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/binary/distributed/dht/GridCachePortableDuplicateIndexObjectPartitionedAtomicSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/binary/distributed/dht/GridCachePortableDuplicateIndexObjectPartitionedAtomicSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/binary/distributed/dht/GridCachePortableDuplicateIndexObjectPartitionedAtomicSelfTest.java
deleted file mode 100644
index f01914c..0000000
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/binary/distributed/dht/GridCachePortableDuplicateIndexObjectPartitionedAtomicSelfTest.java
+++ /dev/null
@@ -1,38 +0,0 @@
-/*
- * 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.processors.cache.binary.distributed.dht;
-
-import org.apache.ignite.cache.CacheAtomicityMode;
-import org.apache.ignite.cache.CacheMode;
-import org.apache.ignite.internal.processors.cache.binary.GridPortableDuplicateIndexObjectsAbstractSelfTest;
-
-/**
- * Test PARTITIONED ATOMIC.
- */
-public class GridCachePortableDuplicateIndexObjectPartitionedAtomicSelfTest extends
-    GridPortableDuplicateIndexObjectsAbstractSelfTest {
-    /** {@inheritDoc} */
-    @Override public CacheAtomicityMode atomicityMode() {
-        return CacheAtomicityMode.ATOMIC;
-    }
-
-    /** {@inheritDoc} */
-    @Override public CacheMode cacheMode() {
-        return CacheMode.PARTITIONED;
-    }
-}

http://git-wip-us.apache.org/repos/asf/ignite/blob/71ad9cea/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/binary/distributed/dht/GridCachePortableDuplicateIndexObjectPartitionedTransactionalSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/binary/distributed/dht/GridCachePortableDuplicateIndexObjectPartitionedTransactionalSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/binary/distributed/dht/GridCachePortableDuplicateIndexObjectPartitionedTransactionalSelfTest.java
deleted file mode 100644
index 68305f3..0000000
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/binary/distributed/dht/GridCachePortableDuplicateIndexObjectPartitionedTransactionalSelfTest.java
+++ /dev/null
@@ -1,41 +0,0 @@
-/*
- * 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.processors.cache.binary.distributed.dht;
-
-import org.apache.ignite.cache.CacheAtomicityMode;
-import org.apache.ignite.cache.CacheMode;
-import org.apache.ignite.internal.processors.cache.binary.GridPortableDuplicateIndexObjectsAbstractSelfTest;
-
-import static org.apache.ignite.cache.CacheAtomicityMode.TRANSACTIONAL;
-import static org.apache.ignite.cache.CacheMode.PARTITIONED;
-
-/**
- * Test PARTITIONED and TRANSACTIONAL.
- */
-public class GridCachePortableDuplicateIndexObjectPartitionedTransactionalSelfTest extends
-    GridPortableDuplicateIndexObjectsAbstractSelfTest {
-    /** {@inheritDoc} */
-    @Override public CacheAtomicityMode atomicityMode() {
-        return TRANSACTIONAL;
-    }
-
-    /** {@inheritDoc} */
-    @Override public CacheMode cacheMode() {
-        return PARTITIONED;
-    }
-}