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

[01/13] ignite git commit: ignite-2065: rename "portable" classes to "binary"

Repository: ignite
Updated Branches:
  refs/heads/ignite-1.5 2b3c93ec9 -> 71ad9cead


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;
     }


[04/13] ignite git commit: ignite-2065: rename "portable" classes to "binary"

Posted by sb...@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);
+    }
+}


[12/13] ignite git commit: ignite-2065: rename "portable" classes to "binary"

Posted by sb...@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;
         }
     }
 


[07/13] ignite git commit: ignite-2065: rename "portable" classes to "binary"

Posted by sb...@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);
+    }
+}


[09/13] ignite git commit: ignite-2065: rename "portable" classes to "binary"

Posted by sb...@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;
-            }
-        }
-    }
-}


[13/13] ignite git commit: ignite-2065: rename "portable" classes to "binary"

Posted by sb...@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-1.5
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;
         }
     }


[03/13] ignite git commit: ignite-2065: rename "portable" classes to "binary"

Posted by sb...@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());
-        }
-    }
-}


[08/13] ignite git commit: ignite-2065: rename "portable" classes to "binary"

Posted by sb...@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;
+    }
+}


[02/13] ignite git commit: ignite-2065: rename "portable" classes to "binary"

Posted by sb...@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;
-    }
-}


[10/13] ignite git commit: ignite-2065: rename "portable" classes to "binary"

Posted by sb...@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;
-    }
-}


[11/13] ignite git commit: ignite-2065: rename "portable" classes to "binary"

Posted by sb...@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;
+        }
+    }
+}


[06/13] ignite git commit: ignite-2065: rename "portable" classes to "binary"

Posted by sb...@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);
-    }
-}


[05/13] ignite git commit: ignite-2065: rename "portable" classes to "binary"

Posted by sb...@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;
-    }
-}