IGNITE-61 - Direct marshalling

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

Branch: refs/heads/ignite-sql-tests
Commit: 159c1e84622cdc0c1ab9f4aa60a721fbff0a51df
Parents: 215268f
Author: Valentin Kulichenko <vkuliche...@gridgain.com>
Authored: Sat Feb 7 22:56:42 2015 -0800
Committer: Valentin Kulichenko <vkuliche...@gridgain.com>
Committed: Sat Feb 7 22:56:42 2015 -0800

----------------------------------------------------------------------
 .../ignite/internal/GridJobCancelRequest.java   |  44 +-
 .../ignite/internal/GridJobExecuteRequest.java  | 344 +++------
 .../ignite/internal/GridJobExecuteResponse.java |  84 +--
 .../ignite/internal/GridJobSiblingsRequest.java |  34 +-
 .../internal/GridJobSiblingsResponse.java       |  24 +-
 .../ignite/internal/GridTaskCancelRequest.java  |  24 +-
 .../ignite/internal/GridTaskSessionRequest.java |  44 +-
 .../internal/direct/DirectByteBufferStream.java |   4 +-
 .../internal/direct/DirectMessageReader.java    |   4 +-
 .../GridTcpCommunicationMessageState.java       | 726 -------------------
 .../checkpoint/GridCheckpointRequest.java       |  44 +-
 .../managers/communication/GridIoMessage.java   |  88 ++-
 .../communication/GridIoUserMessage.java        | 157 ++--
 .../deployment/GridDeploymentInfoBean.java      | 137 +---
 .../deployment/GridDeploymentRequest.java       | 111 +--
 .../deployment/GridDeploymentResponse.java      |  44 +-
 .../eventstorage/GridEventStorageMessage.java   | 177 ++---
 .../cache/GridCacheEvictionRequest.java         |  44 +-
 .../cache/GridCacheEvictionResponse.java        |  91 +--
 .../processors/cache/GridCacheMessage.java      |  46 +-
 .../processors/cache/GridCacheValueBytes.java   |  60 +-
 ...idCacheOptimisticCheckPreparedTxRequest.java |  54 +-
 ...dCacheOptimisticCheckPreparedTxResponse.java |  44 +-
 ...CachePessimisticCheckCommittedTxRequest.java |  74 +-
 ...achePessimisticCheckCommittedTxResponse.java |  44 +-
 .../distributed/GridCacheTtlUpdateRequest.java  | 262 ++-----
 .../distributed/GridDistributedBaseMessage.java | 158 +---
 .../distributed/GridDistributedLockRequest.java | 270 +++----
 .../GridDistributedLockResponse.java            |  91 +--
 .../GridDistributedTxFinishRequest.java         | 238 ++----
 .../GridDistributedTxFinishResponse.java        |  34 +-
 .../GridDistributedTxPrepareRequest.java        | 252 +++----
 .../GridDistributedTxPrepareResponse.java       |  34 +-
 .../GridDistributedUnlockRequest.java           |  71 +-
 .../dht/GridDhtAffinityAssignmentRequest.java   |  24 +-
 .../dht/GridDhtAffinityAssignmentResponse.java  |  34 +-
 .../distributed/dht/GridDhtLockRequest.java     | 151 ++--
 .../distributed/dht/GridDhtLockResponse.java    | 195 +----
 .../distributed/dht/GridDhtTxFinishRequest.java | 240 ++----
 .../dht/GridDhtTxFinishResponse.java            |  24 +-
 .../dht/GridDhtTxPrepareRequest.java            | 181 ++---
 .../dht/GridDhtTxPrepareResponse.java           | 205 +-----
 .../distributed/dht/GridDhtUnlockRequest.java   |  71 +-
 .../GridDhtAtomicDeferredUpdateResponse.java    |  71 +-
 .../dht/atomic/GridDhtAtomicUpdateRequest.java  | 592 ++++-----------
 .../dht/atomic/GridDhtAtomicUpdateResponse.java | 101 +--
 .../dht/atomic/GridNearAtomicUpdateRequest.java | 443 +++--------
 .../atomic/GridNearAtomicUpdateResponse.java    | 265 ++-----
 .../dht/preloader/GridDhtForceKeysRequest.java  | 101 +--
 .../dht/preloader/GridDhtForceKeysResponse.java | 101 +--
 .../GridDhtPartitionDemandMessage.java          | 121 +---
 .../preloader/GridDhtPartitionExchangeId.java   |  75 +-
 .../GridDhtPartitionSupplyMessage.java          | 168 ++---
 .../GridDhtPartitionsAbstractMessage.java       |  34 +-
 .../preloader/GridDhtPartitionsFullMessage.java |  44 +-
 .../GridDhtPartitionsSingleMessage.java         |  24 +-
 .../GridDhtPartitionsSingleRequest.java         |  10 +-
 .../distributed/near/GridNearGetRequest.java    | 242 ++-----
 .../distributed/near/GridNearGetResponse.java   | 131 ++--
 .../distributed/near/GridNearLockRequest.java   | 228 ++----
 .../distributed/near/GridNearLockResponse.java  | 205 +-----
 .../near/GridNearTxFinishRequest.java           |  74 +-
 .../near/GridNearTxFinishResponse.java          |  44 +-
 .../near/GridNearTxPrepareRequest.java          | 141 ++--
 .../near/GridNearTxPrepareResponse.java         | 215 ++----
 .../distributed/near/GridNearUnlockRequest.java |  10 +-
 .../cache/query/GridCacheQueryRequest.java      | 206 +++---
 .../cache/query/GridCacheQueryResponse.java     | 168 ++---
 .../cache/version/GridCacheVersion.java         |  90 ++-
 .../clock/GridClockDeltaSnapshotMessage.java    | 105 +--
 .../processors/clock/GridClockDeltaVersion.java |  60 +-
 .../continuous/GridContinuousMessage.java       |  56 +-
 .../dataload/GridDataLoadRequest.java           | 217 ++----
 .../dataload/GridDataLoadResponse.java          |  44 +-
 .../processors/fs/GridGgfsAckMessage.java       |  44 +-
 .../processors/fs/GridGgfsBlockKey.java         |  54 +-
 .../processors/fs/GridGgfsBlocksMessage.java    | 115 +--
 .../fs/GridGgfsCommunicationMessage.java        |  10 +-
 .../processors/fs/GridGgfsDeleteMessage.java    |  34 +-
 .../fs/GridGgfsFileAffinityRange.java           |  64 +-
 .../fs/GridGgfsFragmentizerRequest.java         |  81 +--
 .../fs/GridGgfsFragmentizerResponse.java        |  24 +-
 .../processors/fs/GridGgfsSyncMessage.java      |  34 +-
 .../GridClientHandshakeRequestWrapper.java      |   4 +-
 .../GridClientHandshakeResponseWrapper.java     |   8 +-
 .../message/GridClientMessageWrapper.java       |  28 +-
 .../message/GridClientPingPacketWrapper.java    |  14 +-
 .../handlers/task/GridTaskResultRequest.java    |  34 +-
 .../handlers/task/GridTaskResultResponse.java   |  54 +-
 .../tcp/GridMemcachedMessageWrapper.java        |   4 +-
 .../streamer/GridStreamerCancelRequest.java     |  24 +-
 .../streamer/GridStreamerExecutionRequest.java  | 157 ++--
 .../streamer/GridStreamerResponse.java          |  34 +-
 .../version/GridVersionConverter.java           |  46 --
 .../ignite/internal/util/GridByteArrayList.java |  60 +-
 .../ignite/internal/util/GridLongList.java      |  60 +-
 .../communication/MessageAdapter.java           |  47 --
 .../extensions/communication/MessageReader.java |   2 +-
 .../jobstealing/JobStealingRequest.java         |  24 +-
 .../GridCommunicationSendMessageSelfTest.java   |   4 +-
 .../spi/communication/GridTestMessage.java      |  58 +-
 101 files changed, 3349 insertions(+), 7241 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/159c1e84/modules/core/src/main/java/org/apache/ignite/internal/GridJobCancelRequest.java
----------------------------------------------------------------------
diff --git 
a/modules/core/src/main/java/org/apache/ignite/internal/GridJobCancelRequest.java
 
b/modules/core/src/main/java/org/apache/ignite/internal/GridJobCancelRequest.java
index d55e205..5cb6a27 100644
--- 
a/modules/core/src/main/java/org/apache/ignite/internal/GridJobCancelRequest.java
+++ 
b/modules/core/src/main/java/org/apache/ignite/internal/GridJobCancelRequest.java
@@ -131,33 +131,33 @@ public class GridJobCancelRequest extends MessageAdapter {
     /** {@inheritDoc} */
     @SuppressWarnings("all")
     @Override public boolean writeTo(ByteBuffer buf) {
-        commState.setBuffer(buf);
+        writer.setBuffer(buf);
 
-        if (!commState.typeWritten) {
-            if (!commState.putByte(null, directType()))
+        if (!typeWritten) {
+            if (!writer.writeByte(null, directType()))
                 return false;
 
-            commState.typeWritten = true;
+            typeWritten = true;
         }
 
-        switch (commState.idx) {
+        switch (state) {
             case 0:
-                if (!commState.putGridUuid("jobId", jobId))
+                if (!writer.writeIgniteUuid("jobId", jobId))
                     return false;
 
-                commState.idx++;
+                state++;
 
             case 1:
-                if (!commState.putGridUuid("sesId", sesId))
+                if (!writer.writeIgniteUuid("sesId", sesId))
                     return false;
 
-                commState.idx++;
+                state++;
 
             case 2:
-                if (!commState.putBoolean("sys", sys))
+                if (!writer.writeBoolean("sys", sys))
                     return false;
 
-                commState.idx++;
+                state++;
 
         }
 
@@ -167,32 +167,32 @@ public class GridJobCancelRequest extends MessageAdapter {
     /** {@inheritDoc} */
     @SuppressWarnings("all")
     @Override public boolean readFrom(ByteBuffer buf) {
-        commState.setBuffer(buf);
+        reader.setBuffer(buf);
 
-        switch (commState.idx) {
+        switch (state) {
             case 0:
-                jobId = commState.getGridUuid("jobId");
+                jobId = reader.readIgniteUuid("jobId");
 
-                if (!commState.lastRead())
+                if (!reader.isLastRead())
                     return false;
 
-                commState.idx++;
+                state++;
 
             case 1:
-                sesId = commState.getGridUuid("sesId");
+                sesId = reader.readIgniteUuid("sesId");
 
-                if (!commState.lastRead())
+                if (!reader.isLastRead())
                     return false;
 
-                commState.idx++;
+                state++;
 
             case 2:
-                sys = commState.getBoolean("sys");
+                sys = reader.readBoolean("sys");
 
-                if (!commState.lastRead())
+                if (!reader.isLastRead())
                     return false;
 
-                commState.idx++;
+                state++;
 
         }
 

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/159c1e84/modules/core/src/main/java/org/apache/ignite/internal/GridJobExecuteRequest.java
----------------------------------------------------------------------
diff --git 
a/modules/core/src/main/java/org/apache/ignite/internal/GridJobExecuteRequest.java
 
b/modules/core/src/main/java/org/apache/ignite/internal/GridJobExecuteRequest.java
index cdc6dfa..4631000 100644
--- 
a/modules/core/src/main/java/org/apache/ignite/internal/GridJobExecuteRequest.java
+++ 
b/modules/core/src/main/java/org/apache/ignite/internal/GridJobExecuteRequest.java
@@ -456,194 +456,141 @@ public class GridJobExecuteRequest extends 
MessageAdapter implements GridTaskMes
     /** {@inheritDoc} */
     @SuppressWarnings("all")
     @Override public boolean writeTo(ByteBuffer buf) {
-        commState.setBuffer(buf);
+        writer.setBuffer(buf);
 
-        if (!commState.typeWritten) {
-            if (!commState.putByte(null, directType()))
+        if (!typeWritten) {
+            if (!writer.writeByte(null, directType()))
                 return false;
 
-            commState.typeWritten = true;
+            typeWritten = true;
         }
 
-        switch (commState.idx) {
+        switch (state) {
             case 0:
-                if (!commState.putGridUuid("clsLdrId", clsLdrId))
+                if (!writer.writeIgniteUuid("clsLdrId", clsLdrId))
                     return false;
 
-                commState.idx++;
+                state++;
 
             case 1:
-                if (!commState.putString("cpSpi", cpSpi))
+                if (!writer.writeString("cpSpi", cpSpi))
                     return false;
 
-                commState.idx++;
+                state++;
 
             case 2:
-                if (!commState.putEnum("depMode", depMode))
+                if (!writer.writeEnum("depMode", depMode))
                     return false;
 
-                commState.idx++;
+                state++;
 
             case 3:
-                if (!commState.putBoolean("dynamicSiblings", dynamicSiblings))
+                if (!writer.writeBoolean("dynamicSiblings", dynamicSiblings))
                     return false;
 
-                commState.idx++;
+                state++;
 
             case 4:
-                if (!commState.putBoolean("forceLocDep", forceLocDep))
+                if (!writer.writeBoolean("forceLocDep", forceLocDep))
                     return false;
 
-                commState.idx++;
+                state++;
 
             case 5:
-                if (!commState.putBoolean("internal", internal))
+                if (!writer.writeBoolean("internal", internal))
                     return false;
 
-                commState.idx++;
+                state++;
 
             case 6:
-                if (!commState.putByteArray("jobAttrsBytes", jobAttrsBytes))
+                if (!writer.writeByteArray("jobAttrsBytes", jobAttrsBytes))
                     return false;
 
-                commState.idx++;
+                state++;
 
             case 7:
-                if (!commState.putByteArray("jobBytes", jobBytes))
+                if (!writer.writeByteArray("jobBytes", jobBytes))
                     return false;
 
-                commState.idx++;
+                state++;
 
             case 8:
-                if (!commState.putGridUuid("jobId", jobId))
+                if (!writer.writeIgniteUuid("jobId", jobId))
                     return false;
 
-                commState.idx++;
+                state++;
 
             case 9:
-                if (ldrParticipants != null) {
-                    if (commState.it == null) {
-                        if (!commState.putInt(null, ldrParticipants.size()))
-                            return false;
-
-                        commState.it = ldrParticipants.entrySet().iterator();
-                    }
-
-                    while (commState.it.hasNext() || commState.cur != NULL) {
-                        if (commState.cur == NULL)
-                            commState.cur = commState.it.next();
-
-                        Map.Entry<UUID, IgniteUuid> e = (Map.Entry<UUID, 
IgniteUuid>)commState.cur;
-
-                        if (!commState.keyDone) {
-                            if (!commState.putUuid(null, e.getKey()))
-                                return false;
-
-                            commState.keyDone = true;
-                        }
-
-                        if (!commState.putGridUuid(null, e.getValue()))
-                            return false;
-
-                        commState.keyDone = false;
-
-                        commState.cur = NULL;
-                    }
-
-                    commState.it = null;
-                } else {
-                    if (!commState.putInt(null, -1))
-                        return false;
-                }
+                if (!writer.writeMap("ldrParticipants", ldrParticipants, 
UUID.class, IgniteUuid.class))
+                    return false;
 
-                commState.idx++;
+                state++;
 
             case 10:
-                if (!commState.putByteArray("sesAttrsBytes", sesAttrsBytes))
+                if (!writer.writeByteArray("sesAttrsBytes", sesAttrsBytes))
                     return false;
 
-                commState.idx++;
+                state++;
 
             case 11:
-                if (!commState.putBoolean("sesFullSup", sesFullSup))
+                if (!writer.writeBoolean("sesFullSup", sesFullSup))
                     return false;
 
-                commState.idx++;
+                state++;
 
             case 12:
-                if (!commState.putGridUuid("sesId", sesId))
+                if (!writer.writeIgniteUuid("sesId", sesId))
                     return false;
 
-                commState.idx++;
+                state++;
 
             case 13:
-                if (!commState.putByteArray("siblingsBytes", siblingsBytes))
+                if (!writer.writeByteArray("siblingsBytes", siblingsBytes))
                     return false;
 
-                commState.idx++;
+                state++;
 
             case 14:
-                if (!commState.putLong("startTaskTime", startTaskTime))
+                if (!writer.writeLong("startTaskTime", startTaskTime))
                     return false;
 
-                commState.idx++;
+                state++;
 
             case 15:
-                if (!commState.putUuid("subjId", subjId))
+                if (!writer.writeUuid("subjId", subjId))
                     return false;
 
-                commState.idx++;
+                state++;
 
             case 16:
-                if (!commState.putString("taskClsName", taskClsName))
+                if (!writer.writeString("taskClsName", taskClsName))
                     return false;
 
-                commState.idx++;
+                state++;
 
             case 17:
-                if (!commState.putString("taskName", taskName))
+                if (!writer.writeString("taskName", taskName))
                     return false;
 
-                commState.idx++;
+                state++;
 
             case 18:
-                if (!commState.putLong("timeout", timeout))
+                if (!writer.writeLong("timeout", timeout))
                     return false;
 
-                commState.idx++;
+                state++;
 
             case 19:
-                if (top != null) {
-                    if (commState.it == null) {
-                        if (!commState.putInt(null, top.size()))
-                            return false;
-
-                        commState.it = top.iterator();
-                    }
-
-                    while (commState.it.hasNext() || commState.cur != NULL) {
-                        if (commState.cur == NULL)
-                            commState.cur = commState.it.next();
-
-                        if (!commState.putUuid(null, (UUID)commState.cur))
-                            return false;
-
-                        commState.cur = NULL;
-                    }
-
-                    commState.it = null;
-                } else {
-                    if (!commState.putInt(null, -1))
-                        return false;
-                }
+                if (!writer.writeCollection("top", top, UUID.class))
+                    return false;
 
-                commState.idx++;
+                state++;
 
             case 20:
-                if (!commState.putString("userVer", userVer))
+                if (!writer.writeString("userVer", userVer))
                     return false;
 
-                commState.idx++;
+                state++;
 
         }
 
@@ -653,235 +600,176 @@ public class GridJobExecuteRequest extends 
MessageAdapter implements GridTaskMes
     /** {@inheritDoc} */
     @SuppressWarnings("all")
     @Override public boolean readFrom(ByteBuffer buf) {
-        commState.setBuffer(buf);
+        reader.setBuffer(buf);
 
-        switch (commState.idx) {
+        switch (state) {
             case 0:
-                clsLdrId = commState.getGridUuid("clsLdrId");
+                clsLdrId = reader.readIgniteUuid("clsLdrId");
 
-                if (!commState.lastRead())
+                if (!reader.isLastRead())
                     return false;
 
-                commState.idx++;
+                state++;
 
             case 1:
-                cpSpi = commState.getString("cpSpi");
+                cpSpi = reader.readString("cpSpi");
 
-                if (!commState.lastRead())
+                if (!reader.isLastRead())
                     return false;
 
-                commState.idx++;
+                state++;
 
             case 2:
-                byte depMode0 = commState.getByte("depMode");
+                depMode = reader.readEnum("depMode", DeploymentMode.class);
 
-                if (!commState.lastRead())
+                if (!reader.isLastRead())
                     return false;
 
-                depMode = DeploymentMode.fromOrdinal(depMode0);
-
-                commState.idx++;
+                state++;
 
             case 3:
-                dynamicSiblings = commState.getBoolean("dynamicSiblings");
+                dynamicSiblings = reader.readBoolean("dynamicSiblings");
 
-                if (!commState.lastRead())
+                if (!reader.isLastRead())
                     return false;
 
-                commState.idx++;
+                state++;
 
             case 4:
-                forceLocDep = commState.getBoolean("forceLocDep");
+                forceLocDep = reader.readBoolean("forceLocDep");
 
-                if (!commState.lastRead())
+                if (!reader.isLastRead())
                     return false;
 
-                commState.idx++;
+                state++;
 
             case 5:
-                internal = commState.getBoolean("internal");
+                internal = reader.readBoolean("internal");
 
-                if (!commState.lastRead())
+                if (!reader.isLastRead())
                     return false;
 
-                commState.idx++;
+                state++;
 
             case 6:
-                jobAttrsBytes = commState.getByteArray("jobAttrsBytes");
+                jobAttrsBytes = reader.readByteArray("jobAttrsBytes");
 
-                if (!commState.lastRead())
+                if (!reader.isLastRead())
                     return false;
 
-                commState.idx++;
+                state++;
 
             case 7:
-                jobBytes = commState.getByteArray("jobBytes");
+                jobBytes = reader.readByteArray("jobBytes");
 
-                if (!commState.lastRead())
+                if (!reader.isLastRead())
                     return false;
 
-                commState.idx++;
+                state++;
 
             case 8:
-                jobId = commState.getGridUuid("jobId");
+                jobId = reader.readIgniteUuid("jobId");
 
-                if (!commState.lastRead())
+                if (!reader.isLastRead())
                     return false;
 
-                commState.idx++;
+                state++;
 
             case 9:
-                if (commState.readSize == -1) {
-                    int _val = commState.getInt(null);
-
-                    if (!commState.lastRead())
-                        return false;
-                    commState.readSize = _val;
-                }
+                ldrParticipants = reader.readMap("ldrParticipants", 
UUID.class, IgniteUuid.class);
 
-                if (commState.readSize >= 0) {
-                    if (ldrParticipants == null)
-                        ldrParticipants = new HashMap<>(commState.readSize, 
1.0f);
-
-                    for (int i = commState.readItems; i < commState.readSize; 
i++) {
-                        if (!commState.keyDone) {
-                            UUID _val = commState.getUuid(null);
-
-                            if (!commState.lastRead())
-                                return false;
-
-                            commState.cur = _val;
-                            commState.keyDone = true;
-                        }
-
-                        IgniteUuid _val = commState.getGridUuid(null);
-
-                        if (!commState.lastRead())
-                            return false;
-
-                        ldrParticipants.put((UUID)commState.cur, _val);
-
-                        commState.keyDone = false;
-
-                        commState.readItems++;
-                    }
-                }
-
-                commState.readSize = -1;
-                commState.readItems = 0;
-                commState.cur = null;
+                if (!reader.isLastRead())
+                    return false;
 
-                commState.idx++;
+                state++;
 
             case 10:
-                sesAttrsBytes = commState.getByteArray("sesAttrsBytes");
+                sesAttrsBytes = reader.readByteArray("sesAttrsBytes");
 
-                if (!commState.lastRead())
+                if (!reader.isLastRead())
                     return false;
 
-                commState.idx++;
+                state++;
 
             case 11:
-                sesFullSup = commState.getBoolean("sesFullSup");
+                sesFullSup = reader.readBoolean("sesFullSup");
 
-                if (!commState.lastRead())
+                if (!reader.isLastRead())
                     return false;
 
-                commState.idx++;
+                state++;
 
             case 12:
-                sesId = commState.getGridUuid("sesId");
+                sesId = reader.readIgniteUuid("sesId");
 
-                if (!commState.lastRead())
+                if (!reader.isLastRead())
                     return false;
 
-                commState.idx++;
+                state++;
 
             case 13:
-                siblingsBytes = commState.getByteArray("siblingsBytes");
+                siblingsBytes = reader.readByteArray("siblingsBytes");
 
-                if (!commState.lastRead())
+                if (!reader.isLastRead())
                     return false;
 
-                commState.idx++;
+                state++;
 
             case 14:
-                startTaskTime = commState.getLong("startTaskTime");
+                startTaskTime = reader.readLong("startTaskTime");
 
-                if (!commState.lastRead())
+                if (!reader.isLastRead())
                     return false;
 
-                commState.idx++;
+                state++;
 
             case 15:
-                subjId = commState.getUuid("subjId");
+                subjId = reader.readUuid("subjId");
 
-                if (!commState.lastRead())
+                if (!reader.isLastRead())
                     return false;
 
-                commState.idx++;
+                state++;
 
             case 16:
-                taskClsName = commState.getString("taskClsName");
+                taskClsName = reader.readString("taskClsName");
 
-                if (!commState.lastRead())
+                if (!reader.isLastRead())
                     return false;
 
-                commState.idx++;
+                state++;
 
             case 17:
-                taskName = commState.getString("taskName");
+                taskName = reader.readString("taskName");
 
-                if (!commState.lastRead())
+                if (!reader.isLastRead())
                     return false;
 
-                commState.idx++;
+                state++;
 
             case 18:
-                timeout = commState.getLong("timeout");
+                timeout = reader.readLong("timeout");
 
-                if (!commState.lastRead())
+                if (!reader.isLastRead())
                     return false;
 
-                commState.idx++;
+                state++;
 
             case 19:
-                if (commState.readSize == -1) {
-                    int _val = commState.getInt(null);
-
-                    if (!commState.lastRead())
-                        return false;
-                    commState.readSize = _val;
-                }
-
-                if (commState.readSize >= 0) {
-                    if (top == null)
-                        top = new ArrayList<>(commState.readSize);
-
-                    for (int i = commState.readItems; i < commState.readSize; 
i++) {
-                        UUID _val = commState.getUuid(null);
+                top = reader.readCollection("top", UUID.class);
 
-                        if (!commState.lastRead())
-                            return false;
-
-                        top.add((UUID)_val);
-
-                        commState.readItems++;
-                    }
-                }
-
-                commState.readSize = -1;
-                commState.readItems = 0;
+                if (!reader.isLastRead())
+                    return false;
 
-                commState.idx++;
+                state++;
 
             case 20:
-                userVer = commState.getString("userVer");
+                userVer = reader.readString("userVer");
 
-                if (!commState.lastRead())
+                if (!reader.isLastRead())
                     return false;
 
-                commState.idx++;
+                state++;
 
         }
 

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/159c1e84/modules/core/src/main/java/org/apache/ignite/internal/GridJobExecuteResponse.java
----------------------------------------------------------------------
diff --git 
a/modules/core/src/main/java/org/apache/ignite/internal/GridJobExecuteResponse.java
 
b/modules/core/src/main/java/org/apache/ignite/internal/GridJobExecuteResponse.java
index 5d936c8..3c3352a 100644
--- 
a/modules/core/src/main/java/org/apache/ignite/internal/GridJobExecuteResponse.java
+++ 
b/modules/core/src/main/java/org/apache/ignite/internal/GridJobExecuteResponse.java
@@ -234,57 +234,57 @@ public class GridJobExecuteResponse extends 
MessageAdapter implements GridTaskMe
     /** {@inheritDoc} */
     @SuppressWarnings("all")
     @Override public boolean writeTo(ByteBuffer buf) {
-        commState.setBuffer(buf);
+        writer.setBuffer(buf);
 
-        if (!commState.typeWritten) {
-            if (!commState.putByte(null, directType()))
+        if (!typeWritten) {
+            if (!writer.writeByte(null, directType()))
                 return false;
 
-            commState.typeWritten = true;
+            typeWritten = true;
         }
 
-        switch (commState.idx) {
+        switch (state) {
             case 0:
-                if (!commState.putByteArray("gridExBytes", gridExBytes))
+                if (!writer.writeByteArray("gridExBytes", gridExBytes))
                     return false;
 
-                commState.idx++;
+                state++;
 
             case 1:
-                if (!commState.putBoolean("isCancelled", isCancelled))
+                if (!writer.writeBoolean("isCancelled", isCancelled))
                     return false;
 
-                commState.idx++;
+                state++;
 
             case 2:
-                if (!commState.putByteArray("jobAttrsBytes", jobAttrsBytes))
+                if (!writer.writeByteArray("jobAttrsBytes", jobAttrsBytes))
                     return false;
 
-                commState.idx++;
+                state++;
 
             case 3:
-                if (!commState.putGridUuid("jobId", jobId))
+                if (!writer.writeIgniteUuid("jobId", jobId))
                     return false;
 
-                commState.idx++;
+                state++;
 
             case 4:
-                if (!commState.putUuid("nodeId", nodeId))
+                if (!writer.writeUuid("nodeId", nodeId))
                     return false;
 
-                commState.idx++;
+                state++;
 
             case 5:
-                if (!commState.putByteArray("resBytes", resBytes))
+                if (!writer.writeByteArray("resBytes", resBytes))
                     return false;
 
-                commState.idx++;
+                state++;
 
             case 6:
-                if (!commState.putGridUuid("sesId", sesId))
+                if (!writer.writeIgniteUuid("sesId", sesId))
                     return false;
 
-                commState.idx++;
+                state++;
 
         }
 
@@ -294,64 +294,64 @@ public class GridJobExecuteResponse extends 
MessageAdapter implements GridTaskMe
     /** {@inheritDoc} */
     @SuppressWarnings("all")
     @Override public boolean readFrom(ByteBuffer buf) {
-        commState.setBuffer(buf);
+        reader.setBuffer(buf);
 
-        switch (commState.idx) {
+        switch (state) {
             case 0:
-                gridExBytes = commState.getByteArray("gridExBytes");
+                gridExBytes = reader.readByteArray("gridExBytes");
 
-                if (!commState.lastRead())
+                if (!reader.isLastRead())
                     return false;
 
-                commState.idx++;
+                state++;
 
             case 1:
-                isCancelled = commState.getBoolean("isCancelled");
+                isCancelled = reader.readBoolean("isCancelled");
 
-                if (!commState.lastRead())
+                if (!reader.isLastRead())
                     return false;
 
-                commState.idx++;
+                state++;
 
             case 2:
-                jobAttrsBytes = commState.getByteArray("jobAttrsBytes");
+                jobAttrsBytes = reader.readByteArray("jobAttrsBytes");
 
-                if (!commState.lastRead())
+                if (!reader.isLastRead())
                     return false;
 
-                commState.idx++;
+                state++;
 
             case 3:
-                jobId = commState.getGridUuid("jobId");
+                jobId = reader.readIgniteUuid("jobId");
 
-                if (!commState.lastRead())
+                if (!reader.isLastRead())
                     return false;
 
-                commState.idx++;
+                state++;
 
             case 4:
-                nodeId = commState.getUuid("nodeId");
+                nodeId = reader.readUuid("nodeId");
 
-                if (!commState.lastRead())
+                if (!reader.isLastRead())
                     return false;
 
-                commState.idx++;
+                state++;
 
             case 5:
-                resBytes = commState.getByteArray("resBytes");
+                resBytes = reader.readByteArray("resBytes");
 
-                if (!commState.lastRead())
+                if (!reader.isLastRead())
                     return false;
 
-                commState.idx++;
+                state++;
 
             case 6:
-                sesId = commState.getGridUuid("sesId");
+                sesId = reader.readIgniteUuid("sesId");
 
-                if (!commState.lastRead())
+                if (!reader.isLastRead())
                     return false;
 
-                commState.idx++;
+                state++;
 
         }
 

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/159c1e84/modules/core/src/main/java/org/apache/ignite/internal/GridJobSiblingsRequest.java
----------------------------------------------------------------------
diff --git 
a/modules/core/src/main/java/org/apache/ignite/internal/GridJobSiblingsRequest.java
 
b/modules/core/src/main/java/org/apache/ignite/internal/GridJobSiblingsRequest.java
index db27003..2fc71d9 100644
--- 
a/modules/core/src/main/java/org/apache/ignite/internal/GridJobSiblingsRequest.java
+++ 
b/modules/core/src/main/java/org/apache/ignite/internal/GridJobSiblingsRequest.java
@@ -105,27 +105,27 @@ public class GridJobSiblingsRequest extends 
MessageAdapter {
     /** {@inheritDoc} */
     @SuppressWarnings("all")
     @Override public boolean writeTo(ByteBuffer buf) {
-        commState.setBuffer(buf);
+        writer.setBuffer(buf);
 
-        if (!commState.typeWritten) {
-            if (!commState.putByte(null, directType()))
+        if (!typeWritten) {
+            if (!writer.writeByte(null, directType()))
                 return false;
 
-            commState.typeWritten = true;
+            typeWritten = true;
         }
 
-        switch (commState.idx) {
+        switch (state) {
             case 0:
-                if (!commState.putGridUuid("sesId", sesId))
+                if (!writer.writeIgniteUuid("sesId", sesId))
                     return false;
 
-                commState.idx++;
+                state++;
 
             case 1:
-                if (!commState.putByteArray("topicBytes", topicBytes))
+                if (!writer.writeByteArray("topicBytes", topicBytes))
                     return false;
 
-                commState.idx++;
+                state++;
 
         }
 
@@ -135,24 +135,24 @@ public class GridJobSiblingsRequest extends 
MessageAdapter {
     /** {@inheritDoc} */
     @SuppressWarnings("all")
     @Override public boolean readFrom(ByteBuffer buf) {
-        commState.setBuffer(buf);
+        reader.setBuffer(buf);
 
-        switch (commState.idx) {
+        switch (state) {
             case 0:
-                sesId = commState.getGridUuid("sesId");
+                sesId = reader.readIgniteUuid("sesId");
 
-                if (!commState.lastRead())
+                if (!reader.isLastRead())
                     return false;
 
-                commState.idx++;
+                state++;
 
             case 1:
-                topicBytes = commState.getByteArray("topicBytes");
+                topicBytes = reader.readByteArray("topicBytes");
 
-                if (!commState.lastRead())
+                if (!reader.isLastRead())
                     return false;
 
-                commState.idx++;
+                state++;
 
         }
 

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/159c1e84/modules/core/src/main/java/org/apache/ignite/internal/GridJobSiblingsResponse.java
----------------------------------------------------------------------
diff --git 
a/modules/core/src/main/java/org/apache/ignite/internal/GridJobSiblingsResponse.java
 
b/modules/core/src/main/java/org/apache/ignite/internal/GridJobSiblingsResponse.java
index 0dad8d9..ffaaa1e 100644
--- 
a/modules/core/src/main/java/org/apache/ignite/internal/GridJobSiblingsResponse.java
+++ 
b/modules/core/src/main/java/org/apache/ignite/internal/GridJobSiblingsResponse.java
@@ -97,21 +97,21 @@ public class GridJobSiblingsResponse extends MessageAdapter 
{
     /** {@inheritDoc} */
     @SuppressWarnings("all")
     @Override public boolean writeTo(ByteBuffer buf) {
-        commState.setBuffer(buf);
+        writer.setBuffer(buf);
 
-        if (!commState.typeWritten) {
-            if (!commState.putByte(null, directType()))
+        if (!typeWritten) {
+            if (!writer.writeByte(null, directType()))
                 return false;
 
-            commState.typeWritten = true;
+            typeWritten = true;
         }
 
-        switch (commState.idx) {
+        switch (state) {
             case 0:
-                if (!commState.putByteArray("siblingsBytes", siblingsBytes))
+                if (!writer.writeByteArray("siblingsBytes", siblingsBytes))
                     return false;
 
-                commState.idx++;
+                state++;
 
         }
 
@@ -121,16 +121,16 @@ public class GridJobSiblingsResponse extends 
MessageAdapter {
     /** {@inheritDoc} */
     @SuppressWarnings("all")
     @Override public boolean readFrom(ByteBuffer buf) {
-        commState.setBuffer(buf);
+        reader.setBuffer(buf);
 
-        switch (commState.idx) {
+        switch (state) {
             case 0:
-                siblingsBytes = commState.getByteArray("siblingsBytes");
+                siblingsBytes = reader.readByteArray("siblingsBytes");
 
-                if (!commState.lastRead())
+                if (!reader.isLastRead())
                     return false;
 
-                commState.idx++;
+                state++;
 
         }
 

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/159c1e84/modules/core/src/main/java/org/apache/ignite/internal/GridTaskCancelRequest.java
----------------------------------------------------------------------
diff --git 
a/modules/core/src/main/java/org/apache/ignite/internal/GridTaskCancelRequest.java
 
b/modules/core/src/main/java/org/apache/ignite/internal/GridTaskCancelRequest.java
index 21153af..75ff8ea 100644
--- 
a/modules/core/src/main/java/org/apache/ignite/internal/GridTaskCancelRequest.java
+++ 
b/modules/core/src/main/java/org/apache/ignite/internal/GridTaskCancelRequest.java
@@ -80,21 +80,21 @@ public class GridTaskCancelRequest extends MessageAdapter {
     /** {@inheritDoc} */
     @SuppressWarnings("all")
     @Override public boolean writeTo(ByteBuffer buf) {
-        commState.setBuffer(buf);
+        writer.setBuffer(buf);
 
-        if (!commState.typeWritten) {
-            if (!commState.putByte(null, directType()))
+        if (!typeWritten) {
+            if (!writer.writeByte(null, directType()))
                 return false;
 
-            commState.typeWritten = true;
+            typeWritten = true;
         }
 
-        switch (commState.idx) {
+        switch (state) {
             case 0:
-                if (!commState.putGridUuid("sesId", sesId))
+                if (!writer.writeIgniteUuid("sesId", sesId))
                     return false;
 
-                commState.idx++;
+                state++;
 
         }
 
@@ -104,16 +104,16 @@ public class GridTaskCancelRequest extends MessageAdapter 
{
     /** {@inheritDoc} */
     @SuppressWarnings("all")
     @Override public boolean readFrom(ByteBuffer buf) {
-        commState.setBuffer(buf);
+        reader.setBuffer(buf);
 
-        switch (commState.idx) {
+        switch (state) {
             case 0:
-                sesId = commState.getGridUuid("sesId");
+                sesId = reader.readIgniteUuid("sesId");
 
-                if (!commState.lastRead())
+                if (!reader.isLastRead())
                     return false;
 
-                commState.idx++;
+                state++;
 
         }
 

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/159c1e84/modules/core/src/main/java/org/apache/ignite/internal/GridTaskSessionRequest.java
----------------------------------------------------------------------
diff --git 
a/modules/core/src/main/java/org/apache/ignite/internal/GridTaskSessionRequest.java
 
b/modules/core/src/main/java/org/apache/ignite/internal/GridTaskSessionRequest.java
index f33e97a..1f75ee2 100644
--- 
a/modules/core/src/main/java/org/apache/ignite/internal/GridTaskSessionRequest.java
+++ 
b/modules/core/src/main/java/org/apache/ignite/internal/GridTaskSessionRequest.java
@@ -120,33 +120,33 @@ public class GridTaskSessionRequest extends 
MessageAdapter implements GridTaskMe
     /** {@inheritDoc} */
     @SuppressWarnings("all")
     @Override public boolean writeTo(ByteBuffer buf) {
-        commState.setBuffer(buf);
+        writer.setBuffer(buf);
 
-        if (!commState.typeWritten) {
-            if (!commState.putByte(null, directType()))
+        if (!typeWritten) {
+            if (!writer.writeByte(null, directType()))
                 return false;
 
-            commState.typeWritten = true;
+            typeWritten = true;
         }
 
-        switch (commState.idx) {
+        switch (state) {
             case 0:
-                if (!commState.putByteArray("attrsBytes", attrsBytes))
+                if (!writer.writeByteArray("attrsBytes", attrsBytes))
                     return false;
 
-                commState.idx++;
+                state++;
 
             case 1:
-                if (!commState.putGridUuid("jobId", jobId))
+                if (!writer.writeIgniteUuid("jobId", jobId))
                     return false;
 
-                commState.idx++;
+                state++;
 
             case 2:
-                if (!commState.putGridUuid("sesId", sesId))
+                if (!writer.writeIgniteUuid("sesId", sesId))
                     return false;
 
-                commState.idx++;
+                state++;
 
         }
 
@@ -156,32 +156,32 @@ public class GridTaskSessionRequest extends 
MessageAdapter implements GridTaskMe
     /** {@inheritDoc} */
     @SuppressWarnings("all")
     @Override public boolean readFrom(ByteBuffer buf) {
-        commState.setBuffer(buf);
+        reader.setBuffer(buf);
 
-        switch (commState.idx) {
+        switch (state) {
             case 0:
-                attrsBytes = commState.getByteArray("attrsBytes");
+                attrsBytes = reader.readByteArray("attrsBytes");
 
-                if (!commState.lastRead())
+                if (!reader.isLastRead())
                     return false;
 
-                commState.idx++;
+                state++;
 
             case 1:
-                jobId = commState.getGridUuid("jobId");
+                jobId = reader.readIgniteUuid("jobId");
 
-                if (!commState.lastRead())
+                if (!reader.isLastRead())
                     return false;
 
-                commState.idx++;
+                state++;
 
             case 2:
-                sesId = commState.getGridUuid("sesId");
+                sesId = reader.readIgniteUuid("sesId");
 
-                if (!commState.lastRead())
+                if (!reader.isLastRead())
                     return false;
 
-                commState.idx++;
+                state++;
 
         }
 

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/159c1e84/modules/core/src/main/java/org/apache/ignite/internal/direct/DirectByteBufferStream.java
----------------------------------------------------------------------
diff --git 
a/modules/core/src/main/java/org/apache/ignite/internal/direct/DirectByteBufferStream.java
 
b/modules/core/src/main/java/org/apache/ignite/internal/direct/DirectByteBufferStream.java
index 3234a64..9d79f41 100644
--- 
a/modules/core/src/main/java/org/apache/ignite/internal/direct/DirectByteBufferStream.java
+++ 
b/modules/core/src/main/java/org/apache/ignite/internal/direct/DirectByteBufferStream.java
@@ -969,7 +969,7 @@ public class DirectByteBufferStream {
     }
 
     @SuppressWarnings("unchecked")
-    public <K, V> Map<K, V> readMap(Class<K> keyCls, Class<V> valCls) {
+    public <M extends Map<K, V>, K, V> M readMap(Class<K> keyCls, Class<V> 
valCls) {
         if (readSize == -1) {
             int size = readInt();
 
@@ -1021,7 +1021,7 @@ public class DirectByteBufferStream {
 
         map = null;
 
-        return map0;
+        return (M)map0;
     }
 
     /**

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/159c1e84/modules/core/src/main/java/org/apache/ignite/internal/direct/DirectMessageReader.java
----------------------------------------------------------------------
diff --git 
a/modules/core/src/main/java/org/apache/ignite/internal/direct/DirectMessageReader.java
 
b/modules/core/src/main/java/org/apache/ignite/internal/direct/DirectMessageReader.java
index f0efbae..1bc3d50 100644
--- 
a/modules/core/src/main/java/org/apache/ignite/internal/direct/DirectMessageReader.java
+++ 
b/modules/core/src/main/java/org/apache/ignite/internal/direct/DirectMessageReader.java
@@ -263,8 +263,8 @@ public class DirectMessageReader implements MessageReader {
     }
 
     /** {@inheritDoc} */
-    @Override public <K, V> Map<K, V> readMap(String name, Class<K> keyCls, 
Class<V> valCls) {
-        Map<K, V> map = stream.readMap(keyCls, valCls);
+    @Override public <M extends Map<K, V>, K, V> M readMap(String name, 
Class<K> keyCls, Class<V> valCls) {
+        M map = stream.readMap(keyCls, valCls);
 
         lastRead = stream.lastFinished();
 

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/159c1e84/modules/core/src/main/java/org/apache/ignite/internal/direct/GridTcpCommunicationMessageState.java
----------------------------------------------------------------------
diff --git 
a/modules/core/src/main/java/org/apache/ignite/internal/direct/GridTcpCommunicationMessageState.java
 
b/modules/core/src/main/java/org/apache/ignite/internal/direct/GridTcpCommunicationMessageState.java
deleted file mode 100644
index ad9542a..0000000
--- 
a/modules/core/src/main/java/org/apache/ignite/internal/direct/GridTcpCommunicationMessageState.java
+++ /dev/null
@@ -1,726 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License.  You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.ignite.internal.direct;
-
-import org.apache.ignite.internal.processors.cache.*;
-import org.apache.ignite.internal.processors.cache.distributed.dht.preloader.*;
-import org.apache.ignite.internal.processors.cache.version.*;
-import org.apache.ignite.internal.processors.clock.*;
-import org.apache.ignite.internal.util.*;
-import org.apache.ignite.lang.*;
-import org.apache.ignite.plugin.extensions.communication.*;
-import org.jetbrains.annotations.*;
-import sun.misc.*;
-
-import java.nio.*;
-import java.util.*;
-
-import static 
org.apache.ignite.plugin.extensions.communication.MessageAdapter.*;
-
-/**
- * Communication message state.
- */
-@SuppressWarnings("PublicField")
-public class GridTcpCommunicationMessageState {
-    /** */
-    private static final Unsafe UNSAFE = GridUnsafe.unsafe();
-
-    /** */
-    private static final long BYTE_ARR_OFF = 
UNSAFE.arrayBaseOffset(byte[].class);
-
-    /** */
-    private final MessageWriter writer = new DirectMessageWriter();
-
-    /** */
-    private MessageReader reader;
-
-    /** */
-    public int idx;
-
-    /** */
-    public boolean typeWritten;
-
-    /** */
-    public Iterator<?> it;
-
-    /** */
-    public Object cur;
-
-    /** */
-    public boolean keyDone;
-
-    /** */
-    public int readSize = -1;
-
-    /** */
-    public int readItems;
-
-    /**
-     * @param writer Writer.
-     */
-    public final void setWriter(MessageWriter writer) {
-//        if (this.writer == null)
-//            this.writer = writer;
-    }
-
-    /**
-     * @param reader Reader.
-     */
-    public final void setReader(MessageReader reader) {
-        if (this.reader == null)
-            this.reader = reader;
-    }
-
-    /**
-     * @param buf Buffer.
-     */
-    public final void setBuffer(ByteBuffer buf) {
-        if (writer != null)
-            writer.setBuffer(buf);
-
-        if (reader != null)
-            reader.setBuffer(buf);
-    }
-
-    /**
-     * @param name Field name.
-     * @param b Byte value.
-     * @return Whether value was written.
-     */
-    public final boolean putByte(String name, byte b) {
-        return writer.writeByte(name, b);
-    }
-
-    /**
-     * @param name Field name.
-     * @return Byte value.
-     */
-    public final byte getByte(String name) {
-        return reader.readByte(name);
-    }
-
-    /**
-     * @param name Field name.
-     * @param s Short value.
-     * @return Whether value was written.
-     */
-    public final boolean putShort(String name, short s) {
-        return writer.writeShort(name, s);
-    }
-
-    /**
-     * @param name Field name.
-     * @return Short value.
-     */
-    public final short getShort(String name) {
-        return reader.readShort(name);
-    }
-
-    /**
-     * @param name Field name.
-     * @param i Integer value.
-     * @return Whether value was written.
-     */
-    public final boolean putInt(String name, int i) {
-        return writer.writeInt(name, i);
-    }
-
-    /**
-     * @param name Field name.
-     * @return Integer value.
-     */
-    public final int getInt(String name) {
-        return reader.readInt(name);
-    }
-
-    /**
-     * @param name Field name.
-     * @param l Long value.
-     * @return Whether value was written.
-     */
-    public final boolean putLong(String name, long l) {
-        return writer.writeLong(name, l);
-    }
-
-    /**
-     * @param name Field name.
-     * @return Long value.
-     */
-    public final long getLong(String name) {
-        return reader.readLong(name);
-    }
-
-    /**
-     * @param name Field name.
-     * @param f Float value.
-     * @return Whether value was written.
-     */
-    public final boolean putFloat(String name, float f) {
-        return writer.writeFloat(name, f);
-    }
-
-    /**
-     * @param name Field name.
-     * @return Float value.
-     */
-    public final float getFloat(String name) {
-        return reader.readFloat(name);
-    }
-
-    /**
-     * @param name Field name.
-     * @param d Double value.
-     * @return Whether value was written.
-     */
-    public final boolean putDouble(String name, double d) {
-        return writer.writeDouble(name, d);
-    }
-
-    /**
-     * @param name Field name.
-     * @return Double value.
-     */
-    public final double getDouble(String name) {
-        return reader.readDouble(name);
-    }
-
-    /**
-     * @param name Field name.
-     * @param c Char value.
-     * @return Whether value was written.
-     */
-    public final boolean putChar(String name, char c) {
-        return writer.writeChar(name, c);
-    }
-
-    /**
-     * @param name Field name.
-     * @return Char value.
-     */
-    public final char getChar(String name) {
-        return reader.readChar(name);
-    }
-
-    /**
-     * @param name Field name.
-     * @param b Boolean value.
-     * @return Whether value was written.
-     */
-    public final boolean putBoolean(String name, boolean b) {
-        return writer.writeBoolean(name, b);
-    }
-
-    /**
-     * @param name Field name.
-     * @return Boolean value.
-     */
-    public final boolean getBoolean(String name) {
-        return reader.readBoolean(name);
-    }
-
-    /**
-     * @param name Field name.
-     * @param arr Byte array.
-     * @return Whether array was fully written.
-     */
-    public final boolean putByteArray(String name, @Nullable byte[] arr) {
-        return writer.writeByteArray(name, arr);
-    }
-
-    /**
-     * @param name Field name.
-     * @return Byte array.
-     */
-    public final byte[] getByteArray(String name) {
-        return reader.readByteArray(name);
-    }
-
-    /**
-     * @param name Field name.
-     * @param arr Short array.
-     * @return Whether array was fully written.
-     */
-    public final boolean putShortArray(String name, short[] arr) {
-        return writer.writeShortArray(name, arr);
-    }
-
-    /**
-     * @param name Field name.
-     * @return Short array.
-     */
-    public final short[] getShortArray(String name) {
-        return reader.readShortArray(name);
-    }
-
-    /**
-     * @param name Field name.
-     * @param arr Integer array.
-     * @return Whether array was fully written.
-     */
-    public final boolean putIntArray(String name, int[] arr) {
-        return writer.writeIntArray(name, arr);
-    }
-
-    /**
-     * @param name Field name.
-     * @return Integer array.
-     */
-    public final int[] getIntArray(String name) {
-        return reader.readIntArray(name);
-    }
-
-    /**
-     * @param name Field name.
-     * @param arr Long array.
-     * @return Whether array was fully written.
-     */
-    public final boolean putLongArray(String name, long[] arr) {
-        return writer.writeLongArray(name, arr);
-    }
-
-    /**
-     * @param name Field name.
-     * @return Long array.
-     */
-    public final long[] getLongArray(String name) {
-        return reader.readLongArray(name);
-    }
-
-    /**
-     * @param name Field name.
-     * @param arr Float array.
-     * @return Whether array was fully written.
-     */
-    public final boolean putFloatArray(String name, float[] arr) {
-        return writer.writeFloatArray(name, arr);
-    }
-
-    /**
-     * @param name Field name.
-     * @return Float array.
-     */
-    public final float[] getFloatArray(String name) {
-        return reader.readFloatArray(name);
-    }
-
-    /**
-     * @param name Field name.
-     * @param arr Double array.
-     * @return Whether array was fully written.
-     */
-    public final boolean putDoubleArray(String name, double[] arr) {
-        return writer.writeDoubleArray(name, arr);
-    }
-
-    /**
-     * @param name Field name.
-     * @return Double array.
-     */
-    public final double[] getDoubleArray(String name) {
-        return reader.readDoubleArray(name);
-    }
-
-    /**
-     * @param name Field name.
-     * @param arr Char array.
-     * @return Whether array was fully written.
-     */
-    public final boolean putCharArray(String name, char[] arr) {
-        return writer.writeCharArray(name, arr);
-    }
-
-    /**
-     * @param name Field name.
-     * @return Char array.
-     */
-    public final char[] getCharArray(String name) {
-        return reader.readCharArray(name);
-    }
-
-    /**
-     * @param name Field name.
-     * @param arr Boolean array.
-     * @return Whether array was fully written.
-     */
-    public final boolean putBooleanArray(String name, boolean[] arr) {
-        return writer.writeBooleanArray(name, arr);
-    }
-
-    /**
-     * @param name Field name.
-     * @return Boolean array.
-     */
-    public final boolean[] getBooleanArray(String name) {
-        return reader.readBooleanArray(name);
-    }
-
-
-    /**
-     * @param name Field name.
-     * @param uuid {@link UUID}.
-     * @return Whether value was fully written.
-     */
-    public final boolean putUuid(String name, @Nullable UUID uuid) {
-        byte[] arr = null;
-
-        if (uuid != null) {
-            arr = new byte[16];
-
-            UNSAFE.putLong(arr, BYTE_ARR_OFF, uuid.getMostSignificantBits());
-            UNSAFE.putLong(arr, BYTE_ARR_OFF + 8, 
uuid.getLeastSignificantBits());
-        }
-
-        return putByteArray(name, arr);
-    }
-
-    /**
-     * @param name Field name.
-     * @return {@link UUID}.
-     */
-    public final UUID getUuid(String name) {
-        byte[] arr = getByteArray(name);
-
-        if (arr == null)
-            return null;
-        else {
-            long most = UNSAFE.getLong(arr, BYTE_ARR_OFF);
-            long least = UNSAFE.getLong(arr, BYTE_ARR_OFF + 8);
-
-            return new UUID(most, least);
-        }
-    }
-
-    /**
-     * @param name Field name.
-     * @param uuid {@link IgniteUuid}.
-     * @return Whether value was fully written.
-     */
-    public final boolean putGridUuid(String name, @Nullable IgniteUuid uuid) {
-        byte[] arr = null;
-
-        if (uuid != null) {
-            arr = new byte[24];
-
-            UNSAFE.putLong(arr, BYTE_ARR_OFF, 
uuid.globalId().getMostSignificantBits());
-            UNSAFE.putLong(arr, BYTE_ARR_OFF + 8, 
uuid.globalId().getLeastSignificantBits());
-            UNSAFE.putLong(arr, BYTE_ARR_OFF + 16, uuid.localId());
-        }
-
-        return putByteArray(name, arr);
-    }
-
-    /**
-     * @param name Field name.
-     * @return {@link IgniteUuid}.
-     */
-    public final IgniteUuid getGridUuid(String name) {
-        byte[] arr = getByteArray(name);
-
-        if (arr == null)
-            return null;
-        else {
-            long most = UNSAFE.getLong(arr, BYTE_ARR_OFF);
-            long least = UNSAFE.getLong(arr, BYTE_ARR_OFF + 8);
-            long loc = UNSAFE.getLong(arr, BYTE_ARR_OFF + 16);
-
-            return new IgniteUuid(new UUID(most, least), loc);
-        }
-    }
-
-    /**
-     * @param name Field name.
-     * @param ver {@link GridClockDeltaVersion}.
-     * @return Whether value was fully written.
-     */
-    public final boolean putClockDeltaVersion(String name, @Nullable 
GridClockDeltaVersion ver) {
-        byte[] arr = null;
-
-        if (ver != null) {
-            arr = new byte[16];
-
-            UNSAFE.putLong(arr, BYTE_ARR_OFF, ver.version());
-            UNSAFE.putLong(arr, BYTE_ARR_OFF + 8, ver.topologyVersion());
-        }
-
-        return putByteArray(name, arr);
-    }
-
-    /**
-     * @param name Field name.
-     * @return {@link GridClockDeltaVersion}.
-     */
-    public final GridClockDeltaVersion getClockDeltaVersion(String name) {
-        byte[] arr = getByteArray(name);
-
-        if (arr == null)
-            return null;
-        else {
-            long ver = UNSAFE.getLong(arr, BYTE_ARR_OFF);
-            long topVer = UNSAFE.getLong(arr, BYTE_ARR_OFF + 8);
-
-            return new GridClockDeltaVersion(ver, topVer);
-        }
-    }
-
-    /**
-     * @param name Field name.
-     * @param list {@link GridByteArrayList}.
-     * @return Whether value was fully written.
-     */
-    public final boolean putByteArrayList(String name, @Nullable 
GridByteArrayList list) {
-        return putByteArray(name, list != null ? list.array() : null);
-    }
-
-    /**
-     * @param name Field name.
-     * @return {@link GridByteArrayList}.
-     */
-    public final GridByteArrayList getByteArrayList(String name) {
-        byte[] arr = getByteArray(name);
-
-        return arr != null ? new GridByteArrayList(arr) : null;
-    }
-
-    /**
-     * @param name Field name.
-     * @param list {@link GridLongList}.
-     * @return Whether value was fully written.
-     */
-    public final boolean putLongList(String name, @Nullable GridLongList list) 
{
-        return putLongArray(name, list != null ? list.array() : null);
-    }
-
-    /**
-     * @param name Field name.
-     * @return {@link GridLongList}.
-     */
-    public final GridLongList getLongList(String name) {
-        long[] arr = getLongArray(name);
-
-        return arr != null ? new GridLongList(arr) : null;
-    }
-
-    /**
-     * @param name Field name.
-     * @param ver {@link 
org.apache.ignite.internal.processors.cache.version.GridCacheVersion}.
-     * @return Whether value was fully written.
-     */
-    public final boolean putCacheVersion(String name, @Nullable 
GridCacheVersion ver) {
-        byte[] arr = null;
-
-        if (ver != null) {
-            arr = new byte[24];
-
-            UNSAFE.putInt(arr, BYTE_ARR_OFF, ver.topologyVersion());
-            UNSAFE.putInt(arr, BYTE_ARR_OFF + 4, ver.nodeOrderAndDrIdRaw());
-            UNSAFE.putLong(arr, BYTE_ARR_OFF + 8, ver.globalTime());
-            UNSAFE.putLong(arr, BYTE_ARR_OFF + 16, ver.order());
-        }
-
-        return putByteArray(name, arr);
-    }
-
-    /**
-     * @param name Field name.
-     * @return {@link GridCacheVersion}.
-     */
-    public final GridCacheVersion getCacheVersion(String name) {
-        byte[] arr = getByteArray(name);
-
-        if (arr == null)
-            return null;
-        else {
-            int topVerDrId = UNSAFE.getInt(arr, BYTE_ARR_OFF);
-            int nodeOrder = UNSAFE.getInt(arr, BYTE_ARR_OFF + 4);
-            long globalTime = UNSAFE.getLong(arr, BYTE_ARR_OFF + 8);
-            long order = UNSAFE.getLong(arr, BYTE_ARR_OFF + 16);
-
-            return new GridCacheVersion(topVerDrId, nodeOrder, globalTime, 
order);
-        }
-    }
-
-    /**
-     * @param name Field name.
-     * @param id {@link GridDhtPartitionExchangeId}.
-     * @return Whether value was fully written.
-     */
-    public final boolean putDhtPartitionExchangeId(String name, @Nullable 
GridDhtPartitionExchangeId id) {
-        byte[] arr = null;
-
-        if (id != null) {
-            arr = new byte[28];
-
-            UNSAFE.putLong(arr, BYTE_ARR_OFF, 
id.nodeId().getMostSignificantBits());
-            UNSAFE.putLong(arr, BYTE_ARR_OFF + 8, 
id.nodeId().getLeastSignificantBits());
-            UNSAFE.putInt(arr, BYTE_ARR_OFF + 16, id.event());
-            UNSAFE.putLong(arr, BYTE_ARR_OFF + 20, id.topologyVersion());
-        }
-
-        return putByteArray(name, arr);
-    }
-
-    /**
-     * @param name Field name.
-     * @return {@link GridDhtPartitionExchangeId}.
-     */
-    public final GridDhtPartitionExchangeId getDhtPartitionExchangeId(String 
name) {
-        byte[] arr = getByteArray(name);
-
-        if (arr == null)
-            return null;
-        else {
-            long most = UNSAFE.getLong(arr, BYTE_ARR_OFF);
-            long least = UNSAFE.getLong(arr, BYTE_ARR_OFF + 8);
-            int evt = UNSAFE.getInt(arr, BYTE_ARR_OFF + 16);
-            long topVer = UNSAFE.getLong(arr, BYTE_ARR_OFF + 20);
-
-            return new GridDhtPartitionExchangeId(new UUID(most, least), evt, 
topVer);
-        }
-    }
-
-    /**
-     * @param name Field name.
-     * @param bytes {@link GridCacheValueBytes}.
-     * @return Whether value was fully written.
-     */
-    public final boolean putValueBytes(String name, @Nullable 
GridCacheValueBytes bytes) {
-        byte[] arr = null;
-
-        if (bytes != null) {
-            byte[] bytes0 = bytes.get();
-
-            if (bytes0 != null) {
-                int len = bytes0.length;
-
-                arr = new byte[len + 2];
-
-                UNSAFE.putBoolean(arr, BYTE_ARR_OFF, true);
-                UNSAFE.copyMemory(bytes0, BYTE_ARR_OFF, arr, BYTE_ARR_OFF + 1, 
len);
-                UNSAFE.putBoolean(arr, BYTE_ARR_OFF + 1 + len, 
bytes.isPlain());
-            }
-            else {
-                arr = new byte[1];
-
-                UNSAFE.putBoolean(arr, BYTE_ARR_OFF, false);
-            }
-        }
-
-        return putByteArray(name, arr);
-    }
-
-    /**
-     * @param name Field name.
-     * @return {@link GridCacheValueBytes}.
-     */
-    public final GridCacheValueBytes getValueBytes(String name) {
-        byte[] arr = getByteArray(name);
-
-        if (arr == null)
-            return null;
-        else {
-            boolean notNull = UNSAFE.getBoolean(arr, BYTE_ARR_OFF);
-
-            if (notNull) {
-                int len = arr.length - 2;
-
-                assert len >= 0 : len;
-
-                byte[] bytesArr = new byte[len];
-
-                UNSAFE.copyMemory(arr, BYTE_ARR_OFF + 1, bytesArr, 
BYTE_ARR_OFF, len);
-
-                boolean isPlain = UNSAFE.getBoolean(arr, BYTE_ARR_OFF + 1 + 
len);
-
-                return new GridCacheValueBytes(bytesArr, isPlain);
-            }
-            else
-                return new GridCacheValueBytes();
-        }
-    }
-
-    /**
-     * @param name Field name.
-     * @param str {@link String}.
-     * @return Whether value was fully written.
-     */
-    public final boolean putString(String name, @Nullable String str) {
-        return putByteArray(name, str != null ? str.getBytes() : null);
-    }
-
-    /**
-     * @param name Field name.
-     * @return {@link String}.
-     */
-    public final String getString(String name) {
-        byte[] arr = getByteArray(name);
-
-        return arr != null ? new String(arr) : null;
-    }
-
-    /**
-     * @param name Field name.
-     * @param bits {@link BitSet}.
-     * @return Whether value was fully written.
-     */
-    public final boolean putBitSet(String name, @Nullable BitSet bits) {
-        return putLongArray(name, bits != null ? bits.toLongArray() : null);
-    }
-
-    /**
-     * @param name Field name.
-     * @return {@link BitSet}.
-     */
-    public final BitSet getBitSet(String name) {
-        long[] arr = getLongArray(name);
-
-        return arr != null ? BitSet.valueOf(arr) : null;
-    }
-
-    /**
-     * @param name Field name.
-     * @param e Enum.
-     * @return Whether value was fully written.
-     */
-    public final boolean putEnum(String name, @Nullable Enum<?> e) {
-        return putByte(name, e != null ? (byte)e.ordinal() : -1);
-    }
-
-    /**
-     * @param name Field name.
-     * @param msg {@link MessageAdapter}.
-     * @return Whether value was fully written.
-     */
-    public final boolean putMessage(String name, @Nullable MessageAdapter msg) 
{
-        if (msg != null)
-            msg.setWriter(writer);
-
-        return writer.writeMessage(name, msg);
-    }
-
-    /**
-     * @param name Field name.
-     * @return {@link MessageAdapter}.
-     */
-    public final MessageAdapter getMessage(String name) {
-        return reader.readMessage(name);
-    }
-
-    public final boolean lastRead() {
-        return reader.isLastRead();
-    }
-}

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/159c1e84/modules/core/src/main/java/org/apache/ignite/internal/managers/checkpoint/GridCheckpointRequest.java
----------------------------------------------------------------------
diff --git 
a/modules/core/src/main/java/org/apache/ignite/internal/managers/checkpoint/GridCheckpointRequest.java
 
b/modules/core/src/main/java/org/apache/ignite/internal/managers/checkpoint/GridCheckpointRequest.java
index fda129a..5085a9c 100644
--- 
a/modules/core/src/main/java/org/apache/ignite/internal/managers/checkpoint/GridCheckpointRequest.java
+++ 
b/modules/core/src/main/java/org/apache/ignite/internal/managers/checkpoint/GridCheckpointRequest.java
@@ -105,33 +105,33 @@ public class GridCheckpointRequest extends MessageAdapter 
{
     /** {@inheritDoc} */
     @SuppressWarnings("all")
     @Override public boolean writeTo(ByteBuffer buf) {
-        commState.setBuffer(buf);
+        writer.setBuffer(buf);
 
-        if (!commState.typeWritten) {
-            if (!commState.putByte(null, directType()))
+        if (!typeWritten) {
+            if (!writer.writeByte(null, directType()))
                 return false;
 
-            commState.typeWritten = true;
+            typeWritten = true;
         }
 
-        switch (commState.idx) {
+        switch (state) {
             case 0:
-                if (!commState.putString("cpSpi", cpSpi))
+                if (!writer.writeString("cpSpi", cpSpi))
                     return false;
 
-                commState.idx++;
+                state++;
 
             case 1:
-                if (!commState.putString("key", key))
+                if (!writer.writeString("key", key))
                     return false;
 
-                commState.idx++;
+                state++;
 
             case 2:
-                if (!commState.putGridUuid("sesId", sesId))
+                if (!writer.writeIgniteUuid("sesId", sesId))
                     return false;
 
-                commState.idx++;
+                state++;
 
         }
 
@@ -141,32 +141,32 @@ public class GridCheckpointRequest extends MessageAdapter 
{
     /** {@inheritDoc} */
     @SuppressWarnings("all")
     @Override public boolean readFrom(ByteBuffer buf) {
-        commState.setBuffer(buf);
+        reader.setBuffer(buf);
 
-        switch (commState.idx) {
+        switch (state) {
             case 0:
-                cpSpi = commState.getString("cpSpi");
+                cpSpi = reader.readString("cpSpi");
 
-                if (!commState.lastRead())
+                if (!reader.isLastRead())
                     return false;
 
-                commState.idx++;
+                state++;
 
             case 1:
-                key = commState.getString("key");
+                key = reader.readString("key");
 
-                if (!commState.lastRead())
+                if (!reader.isLastRead())
                     return false;
 
-                commState.idx++;
+                state++;
 
             case 2:
-                sesId = commState.getGridUuid("sesId");
+                sesId = reader.readIgniteUuid("sesId");
 
-                if (!commState.lastRead())
+                if (!reader.isLastRead())
                     return false;
 
-                commState.idx++;
+                state++;
 
         }
 

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/159c1e84/modules/core/src/main/java/org/apache/ignite/internal/managers/communication/GridIoMessage.java
----------------------------------------------------------------------
diff --git 
a/modules/core/src/main/java/org/apache/ignite/internal/managers/communication/GridIoMessage.java
 
b/modules/core/src/main/java/org/apache/ignite/internal/managers/communication/GridIoMessage.java
index 5dc52d8..27d64be 100644
--- 
a/modules/core/src/main/java/org/apache/ignite/internal/managers/communication/GridIoMessage.java
+++ 
b/modules/core/src/main/java/org/apache/ignite/internal/managers/communication/GridIoMessage.java
@@ -200,63 +200,63 @@ public class GridIoMessage extends MessageAdapter {
         _clone.ordered = ordered;
         _clone.timeout = timeout;
         _clone.skipOnTimeout = skipOnTimeout;
-        _clone.msg = msg != null ? (MessageAdapter)msg.clone() : null;
+        _clone.msg = msg;
     }
 
     /** {@inheritDoc} */
     @SuppressWarnings("all")
     @Override public boolean writeTo(ByteBuffer buf) {
-        commState.setBuffer(buf);
+        writer.setBuffer(buf);
 
-        if (!commState.typeWritten) {
-            if (!commState.putByte(null, directType()))
+        if (!typeWritten) {
+            if (!writer.writeByte(null, directType()))
                 return false;
 
-            commState.typeWritten = true;
+            typeWritten = true;
         }
 
-        switch (commState.idx) {
+        switch (state) {
             case 0:
-                if (!commState.putMessage("msg", msg))
+                if (!writer.writeMessage("msg", msg != null ? msg.clone() : 
null))
                     return false;
 
-                commState.idx++;
+                state++;
 
             case 1:
-                if (!commState.putBoolean("ordered", ordered))
+                if (!writer.writeBoolean("ordered", ordered))
                     return false;
 
-                commState.idx++;
+                state++;
 
             case 2:
-                if (!commState.putEnum("plc", plc))
+                if (!writer.writeEnum("plc", plc))
                     return false;
 
-                commState.idx++;
+                state++;
 
             case 3:
-                if (!commState.putBoolean("skipOnTimeout", skipOnTimeout))
+                if (!writer.writeBoolean("skipOnTimeout", skipOnTimeout))
                     return false;
 
-                commState.idx++;
+                state++;
 
             case 4:
-                if (!commState.putLong("timeout", timeout))
+                if (!writer.writeLong("timeout", timeout))
                     return false;
 
-                commState.idx++;
+                state++;
 
             case 5:
-                if (!commState.putByteArray("topicBytes", topicBytes))
+                if (!writer.writeByteArray("topicBytes", topicBytes))
                     return false;
 
-                commState.idx++;
+                state++;
 
             case 6:
-                if (!commState.putInt("topicOrd", topicOrd))
+                if (!writer.writeInt("topicOrd", topicOrd))
                     return false;
 
-                commState.idx++;
+                state++;
 
         }
 
@@ -266,66 +266,64 @@ public class GridIoMessage extends MessageAdapter {
     /** {@inheritDoc} */
     @SuppressWarnings("all")
     @Override public boolean readFrom(ByteBuffer buf) {
-        commState.setBuffer(buf);
+        reader.setBuffer(buf);
 
-        switch (commState.idx) {
+        switch (state) {
             case 0:
-                msg = commState.getMessage("msg");
+                msg = reader.readMessage("msg");
 
-                if (!commState.lastRead())
+                if (!reader.isLastRead())
                     return false;
 
-                commState.idx++;
+                state++;
 
             case 1:
-                ordered = commState.getBoolean("ordered");
+                ordered = reader.readBoolean("ordered");
 
-                if (!commState.lastRead())
+                if (!reader.isLastRead())
                     return false;
 
-                commState.idx++;
+                state++;
 
             case 2:
-                byte plc0 = commState.getByte("plc");
+                plc = reader.readEnum("plc", GridIoPolicy.class);
 
-                if (!commState.lastRead())
+                if (!reader.isLastRead())
                     return false;
 
-                plc = GridIoPolicy.fromOrdinal(plc0);
-
-                commState.idx++;
+                state++;
 
             case 3:
-                skipOnTimeout = commState.getBoolean("skipOnTimeout");
+                skipOnTimeout = reader.readBoolean("skipOnTimeout");
 
-                if (!commState.lastRead())
+                if (!reader.isLastRead())
                     return false;
 
-                commState.idx++;
+                state++;
 
             case 4:
-                timeout = commState.getLong("timeout");
+                timeout = reader.readLong("timeout");
 
-                if (!commState.lastRead())
+                if (!reader.isLastRead())
                     return false;
 
-                commState.idx++;
+                state++;
 
             case 5:
-                topicBytes = commState.getByteArray("topicBytes");
+                topicBytes = reader.readByteArray("topicBytes");
 
-                if (!commState.lastRead())
+                if (!reader.isLastRead())
                     return false;
 
-                commState.idx++;
+                state++;
 
             case 6:
-                topicOrd = commState.getInt("topicOrd");
+                topicOrd = reader.readInt("topicOrd");
 
-                if (!commState.lastRead())
+                if (!reader.isLastRead())
                     return false;
 
-                commState.idx++;
+                state++;
 
         }
 

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/159c1e84/modules/core/src/main/java/org/apache/ignite/internal/managers/communication/GridIoUserMessage.java
----------------------------------------------------------------------
diff --git 
a/modules/core/src/main/java/org/apache/ignite/internal/managers/communication/GridIoUserMessage.java
 
b/modules/core/src/main/java/org/apache/ignite/internal/managers/communication/GridIoUserMessage.java
index 44039a3..0bc81d4 100644
--- 
a/modules/core/src/main/java/org/apache/ignite/internal/managers/communication/GridIoUserMessage.java
+++ 
b/modules/core/src/main/java/org/apache/ignite/internal/managers/communication/GridIoUserMessage.java
@@ -231,89 +231,57 @@ public class GridIoUserMessage extends MessageAdapter {
     /** {@inheritDoc} */
     @SuppressWarnings("all")
     @Override public boolean writeTo(ByteBuffer buf) {
-        commState.setBuffer(buf);
+        writer.setBuffer(buf);
 
-        if (!commState.typeWritten) {
-            if (!commState.putByte(null, directType()))
+        if (!typeWritten) {
+            if (!writer.writeByte(null, directType()))
                 return false;
 
-            commState.typeWritten = true;
+            typeWritten = true;
         }
 
-        switch (commState.idx) {
+        switch (state) {
             case 0:
-                if (!commState.putByteArray("bodyBytes", bodyBytes))
+                if (!writer.writeByteArray("bodyBytes", bodyBytes))
                     return false;
 
-                commState.idx++;
+                state++;
 
             case 1:
-                if (!commState.putGridUuid("clsLdrId", clsLdrId))
+                if (!writer.writeIgniteUuid("clsLdrId", clsLdrId))
                     return false;
 
-                commState.idx++;
+                state++;
 
             case 2:
-                if (!commState.putString("depClsName", depClsName))
+                if (!writer.writeString("depClsName", depClsName))
                     return false;
 
-                commState.idx++;
+                state++;
 
             case 3:
-                if (!commState.putEnum("depMode", depMode))
+                if (!writer.writeEnum("depMode", depMode))
                     return false;
 
-                commState.idx++;
+                state++;
 
             case 4:
-                if (ldrParties != null) {
-                    if (commState.it == null) {
-                        if (!commState.putInt(null, ldrParties.size()))
-                            return false;
-
-                        commState.it = ldrParties.entrySet().iterator();
-                    }
-
-                    while (commState.it.hasNext() || commState.cur != NULL) {
-                        if (commState.cur == NULL)
-                            commState.cur = commState.it.next();
-
-                        Map.Entry<UUID, IgniteUuid> e = (Map.Entry<UUID, 
IgniteUuid>)commState.cur;
-
-                        if (!commState.keyDone) {
-                            if (!commState.putUuid(null, e.getKey()))
-                                return false;
-
-                            commState.keyDone = true;
-                        }
-
-                        if (!commState.putGridUuid(null, e.getValue()))
-                            return false;
-
-                        commState.keyDone = false;
-
-                        commState.cur = NULL;
-                    }
-
-                    commState.it = null;
-                } else {
-                    if (!commState.putInt(null, -1))
-                        return false;
-                }
+                if (!writer.writeMap("ldrParties", ldrParties, UUID.class, 
IgniteUuid.class))
+                    return false;
 
-                commState.idx++;
+                state++;
 
             case 5:
-                if (!commState.putByteArray("topicBytes", topicBytes))
+                if (!writer.writeByteArray("topicBytes", topicBytes))
                     return false;
 
-                commState.idx++;
+                state++;
 
             case 6:
-                if (!commState.putString("userVer", userVer))
+                if (!writer.writeString("userVer", userVer))
                     return false;
 
-                commState.idx++;
+                state++;
 
         }
 
@@ -323,101 +291,64 @@ public class GridIoUserMessage extends MessageAdapter {
     /** {@inheritDoc} */
     @SuppressWarnings("all")
     @Override public boolean readFrom(ByteBuffer buf) {
-        commState.setBuffer(buf);
+        reader.setBuffer(buf);
 
-        switch (commState.idx) {
+        switch (state) {
             case 0:
-                bodyBytes = commState.getByteArray("bodyBytes");
+                bodyBytes = reader.readByteArray("bodyBytes");
 
-                if (!commState.lastRead())
+                if (!reader.isLastRead())
                     return false;
 
-                commState.idx++;
+                state++;
 
             case 1:
-                clsLdrId = commState.getGridUuid("clsLdrId");
+                clsLdrId = reader.readIgniteUuid("clsLdrId");
 
-                if (!commState.lastRead())
+                if (!reader.isLastRead())
                     return false;
 
-                commState.idx++;
+                state++;
 
             case 2:
-                depClsName = commState.getString("depClsName");
+                depClsName = reader.readString("depClsName");
 
-                if (!commState.lastRead())
+                if (!reader.isLastRead())
                     return false;
 
-                commState.idx++;
+                state++;
 
             case 3:
-                byte depMode0 = commState.getByte("depMode");
+                depMode = reader.readEnum("depMode", DeploymentMode.class);
 
-                if (!commState.lastRead())
+                if (!reader.isLastRead())
                     return false;
 
-                depMode = DeploymentMode.fromOrdinal(depMode0);
-
-                commState.idx++;
+                state++;
 
             case 4:
-                if (commState.readSize == -1) {
-                    int _val = commState.getInt(null);
+                ldrParties = reader.readMap("ldrParties", UUID.class, 
IgniteUuid.class);
 
-                    if (!commState.lastRead())
-                        return false;
-                    commState.readSize = _val;
-                }
-
-                if (commState.readSize >= 0) {
-                    if (ldrParties == null)
-                        ldrParties = new HashMap<>(commState.readSize, 1.0f);
-
-                    for (int i = commState.readItems; i < commState.readSize; 
i++) {
-                        if (!commState.keyDone) {
-                            UUID _val = commState.getUuid(null);
-
-                            if (!commState.lastRead())
-                                return false;
-
-                            commState.cur = _val;
-                            commState.keyDone = true;
-                        }
-
-                        IgniteUuid _val = commState.getGridUuid(null);
-
-                        if (!commState.lastRead())
-                            return false;
-
-                        ldrParties.put((UUID)commState.cur, _val);
-
-                        commState.keyDone = false;
-
-                        commState.readItems++;
-                    }
-                }
-
-                commState.readSize = -1;
-                commState.readItems = 0;
-                commState.cur = null;
+                if (!reader.isLastRead())
+                    return false;
 
-                commState.idx++;
+                state++;
 
             case 5:
-                topicBytes = commState.getByteArray("topicBytes");
+                topicBytes = reader.readByteArray("topicBytes");
 
-                if (!commState.lastRead())
+                if (!reader.isLastRead())
                     return false;
 
-                commState.idx++;
+                state++;
 
             case 6:
-                userVer = commState.getString("userVer");
+                userVer = reader.readString("userVer");
 
-                if (!commState.lastRead())
+                if (!reader.isLastRead())
                     return false;
 
-                commState.idx++;
+                state++;
 
         }
 

Reply via email to