ignite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From vkuliche...@apache.org
Subject [04/17] incubator-ignite git commit: ignite-nio - Removing message clone
Date Sun, 15 Feb 2015 06:44:01 GMT
ignite-nio - Removing message clone


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

Branch: refs/heads/ignite-nio
Commit: e63ce5239df83b8b02e9fe571746a02d6b7c1b28
Parents: dcb4c70
Author: Valentin Kulichenko <vkulichenko@gridgain.com>
Authored: Sat Feb 14 21:21:35 2015 -0800
Committer: Valentin Kulichenko <vkulichenko@gridgain.com>
Committed: Sat Feb 14 21:21:35 2015 -0800

----------------------------------------------------------------------
 .../CommunicationMessageCodeGenerator.java      |  17 +--
 .../org/apache/ignite/events/EventType.java     |   2 +-
 .../ignite/internal/GridJobCancelRequest.java   |  16 ++-
 .../ignite/internal/GridJobExecuteRequest.java  |  52 ++++----
 .../ignite/internal/GridJobExecuteResponse.java |  24 ++--
 .../ignite/internal/GridJobSiblingsRequest.java |  14 +--
 .../internal/GridJobSiblingsResponse.java       |  12 +-
 .../ignite/internal/GridTaskCancelRequest.java  |  12 +-
 .../ignite/internal/GridTaskSessionRequest.java |  16 ++-
 .../internal/direct/DirectByteBufferStream.java |  81 ++++--------
 .../internal/direct/DirectMessageWriter.java    |  53 ++++++--
 .../internal/direct/MessageWriterState.java     | 113 +++++++++++++++++
 .../checkpoint/GridCheckpointRequest.java       |  16 ++-
 .../managers/communication/GridIoMessage.java   |  24 ++--
 .../communication/GridIoUserMessage.java        |  24 ++--
 .../deployment/GridDeploymentInfoBean.java      |  20 ++-
 .../deployment/GridDeploymentRequest.java       |  20 ++-
 .../deployment/GridDeploymentResponse.java      |  16 ++-
 .../eventstorage/GridEventStorageMessage.java   |  28 ++---
 .../cache/GridCacheEvictionRequest.java         |  18 ++-
 .../cache/GridCacheEvictionResponse.java        |  18 ++-
 .../processors/cache/GridCacheMessage.java      |  16 ++-
 .../processors/cache/GridCacheValueBytes.java   |  14 +--
 ...idCacheOptimisticCheckPreparedTxRequest.java |  22 ++--
 ...dCacheOptimisticCheckPreparedTxResponse.java |  18 ++-
 ...CachePessimisticCheckCommittedTxRequest.java |  26 ++--
 ...achePessimisticCheckCommittedTxResponse.java |  20 ++-
 .../distributed/GridCacheTtlUpdateRequest.java  |  24 ++--
 .../distributed/GridDistributedBaseMessage.java |  22 ++--
 .../distributed/GridDistributedLockRequest.java |  44 ++++---
 .../GridDistributedLockResponse.java            |  18 ++-
 .../GridDistributedTxFinishRequest.java         |  38 +++---
 .../GridDistributedTxFinishResponse.java        |  16 ++-
 .../GridDistributedTxPrepareRequest.java        |  40 +++---
 .../GridDistributedTxPrepareResponse.java       |  16 ++-
 .../GridDistributedUnlockRequest.java           |  14 +--
 .../dht/GridDhtAffinityAssignmentRequest.java   |  14 +--
 .../dht/GridDhtAffinityAssignmentResponse.java  |  16 ++-
 .../distributed/dht/GridDhtLockRequest.java     |  30 +++--
 .../distributed/dht/GridDhtLockResponse.java    |  20 ++-
 .../distributed/dht/GridDhtTxFinishRequest.java |  38 +++---
 .../dht/GridDhtTxFinishResponse.java            |  14 +--
 .../dht/GridDhtTxPrepareRequest.java            |  36 +++---
 .../dht/GridDhtTxPrepareResponse.java           |  22 ++--
 .../distributed/dht/GridDhtUnlockRequest.java   |  14 +--
 .../GridDhtAtomicDeferredUpdateResponse.java    |  14 +--
 .../dht/atomic/GridDhtAtomicUpdateRequest.java  |  52 ++++----
 .../dht/atomic/GridDhtAtomicUpdateResponse.java |  20 ++-
 .../dht/atomic/GridNearAtomicUpdateRequest.java |  50 ++++----
 .../atomic/GridNearAtomicUpdateResponse.java    |  34 +++--
 .../dht/preloader/GridDhtForceKeysRequest.java  |  20 ++-
 .../dht/preloader/GridDhtForceKeysResponse.java |  20 ++-
 .../GridDhtPartitionDemandMessage.java          |  24 ++--
 .../preloader/GridDhtPartitionExchangeId.java   |  16 ++-
 .../GridDhtPartitionSupplyMessage.java          |  24 ++--
 .../GridDhtPartitionsAbstractMessage.java       |  16 ++-
 .../preloader/GridDhtPartitionsFullMessage.java |  16 ++-
 .../GridDhtPartitionsSingleMessage.java         |  14 +--
 .../GridDhtPartitionsSingleRequest.java         |  10 +-
 .../distributed/near/GridNearGetRequest.java    |  34 +++--
 .../distributed/near/GridNearGetResponse.java   |  26 ++--
 .../distributed/near/GridNearLockRequest.java   |  36 +++---
 .../distributed/near/GridNearLockResponse.java  |  22 ++--
 .../near/GridNearTxFinishRequest.java           |  24 ++--
 .../near/GridNearTxFinishResponse.java          |  18 ++-
 .../near/GridNearTxPrepareRequest.java          |  28 ++---
 .../near/GridNearTxPrepareResponse.java         |  24 ++--
 .../distributed/near/GridNearUnlockRequest.java |  10 +-
 .../cache/query/GridCacheQueryRequest.java      |  50 ++++----
 .../cache/query/GridCacheQueryResponse.java     |  24 ++--
 .../cache/version/GridCacheVersion.java         |  18 ++-
 .../clock/GridClockDeltaSnapshotMessage.java    |  14 +--
 .../processors/clock/GridClockDeltaVersion.java |  14 +--
 .../continuous/GridContinuousMessage.java       |  18 ++-
 .../dataload/GridDataLoadRequest.java           |  36 +++---
 .../dataload/GridDataLoadResponse.java          |  16 ++-
 .../processors/igfs/IgfsAckMessage.java         |  18 ++-
 .../internal/processors/igfs/IgfsBlockKey.java  |  18 ++-
 .../processors/igfs/IgfsBlocksMessage.java      |  18 ++-
 .../igfs/IgfsCommunicationMessage.java          |   8 +-
 .../processors/igfs/IgfsDeleteMessage.java      |  16 ++-
 .../processors/igfs/IgfsFileAffinityRange.java  |  20 ++-
 .../igfs/IgfsFragmentizerRequest.java           |  16 ++-
 .../igfs/IgfsFragmentizerResponse.java          |  14 +--
 .../processors/igfs/IgfsSyncMessage.java        |  16 ++-
 .../handlers/task/GridTaskResultRequest.java    |  14 +--
 .../handlers/task/GridTaskResultResponse.java   |  18 ++-
 .../streamer/GridStreamerCancelRequest.java     |  12 +-
 .../streamer/GridStreamerExecutionRequest.java  |  24 ++--
 .../streamer/GridStreamerResponse.java          |  14 +--
 .../ignite/internal/util/GridByteArrayList.java |  14 +--
 .../ignite/internal/util/GridLongList.java      |  14 +--
 .../ignite/internal/util/IgniteUtils.java       |  10 +-
 .../internal/util/ipc/IpcToNioAdapter.java      |   2 +-
 .../ignite/internal/util/nio/GridNioServer.java |  28 ++---
 .../util/nio/GridNioSessionMetaKey.java         |   4 +-
 .../util/nio/GridShmemCommunicationClient.java  |   2 +-
 .../util/nio/GridTcpCommunicationClient.java    |   2 +-
 .../communication/MessageAdapter.java           |   4 +-
 .../communication/MessageWriteState.java        | 124 -------------------
 .../extensions/communication/MessageWriter.java |  14 +++
 .../jobstealing/JobStealingRequest.java         |  12 +-
 .../communication/tcp/TcpCommunicationSpi.java  |  10 +-
 .../GridCommunicationSendMessageSelfTest.java   |   2 +-
 .../communication/GridIoManagerSelfTest.java    |   2 +-
 .../communication/GridTestMessage.java          |   2 +-
 .../spi/communication/GridTestMessage.java      |   2 +-
 107 files changed, 1088 insertions(+), 1276 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/e63ce523/modules/codegen/src/main/java/org/apache/ignite/codegen/CommunicationMessageCodeGenerator.java
----------------------------------------------------------------------
diff --git a/modules/codegen/src/main/java/org/apache/ignite/codegen/CommunicationMessageCodeGenerator.java b/modules/codegen/src/main/java/org/apache/ignite/codegen/CommunicationMessageCodeGenerator.java
index a9846d1..d4bea1d 100644
--- a/modules/codegen/src/main/java/org/apache/ignite/codegen/CommunicationMessageCodeGenerator.java
+++ b/modules/codegen/src/main/java/org/apache/ignite/codegen/CommunicationMessageCodeGenerator.java
@@ -209,7 +209,7 @@ public class CommunicationMessageCodeGenerator {
                 if (!skip) {
                     src.add(line);
 
-                    if (line.contains("public boolean writeTo(ByteBuffer buf, MessageWriteState state)")) {
+                    if (line.contains("public boolean writeTo(ByteBuffer buf, MessageWriter writer)")) {
                         src.addAll(write);
 
                         skip = true;
@@ -403,17 +403,12 @@ public class CommunicationMessageCodeGenerator {
     private void start(Collection<String> code, @Nullable String superMtd, boolean write) {
         assert code != null;
 
-        if (write) {
-            code.add(builder().a("MessageWriter writer = state.writer();").toString());
-            code.add(EMPTY);
-        }
-
         code.add(builder().a(write ? "writer" : "reader").a(".setBuffer(").a(BUF_VAR).a(");").toString());
         code.add(EMPTY);
 
         if (superMtd != null) {
             if (write)
-                returnFalseIfFailed(code, "super." + superMtd, BUF_VAR, "state");
+                returnFalseIfFailed(code, "super." + superMtd, BUF_VAR, "writer");
             else
                 returnFalseIfFailed(code, "super." + superMtd, BUF_VAR);
 
@@ -421,14 +416,14 @@ public class CommunicationMessageCodeGenerator {
         }
 
         if (write) {
-            code.add(builder().a("if (!state.isTypeWritten()) {").toString());
+            code.add(builder().a("if (!writer.isTypeWritten()) {").toString());
 
             indent++;
 
             returnFalseIfFailed(code, "writer.writeByte", "null", "directType()");
 
             code.add(EMPTY);
-            code.add(builder().a("state.setTypeWritten();").toString());
+            code.add(builder().a("writer.onTypeWritten();").toString());
 
             indent--;
 
@@ -437,7 +432,7 @@ public class CommunicationMessageCodeGenerator {
         }
 
         if (!fields.isEmpty())
-            code.add(builder().a("switch (").a(write ? "state.index()" : "readState").a(") {").toString());
+            code.add(builder().a("switch (").a(write ? "writer.state()" : "readState").a(") {").toString());
     }
 
     /**
@@ -495,7 +490,7 @@ public class CommunicationMessageCodeGenerator {
             mapAnn != null ? mapAnn.keyType() : null, mapAnn != null ? mapAnn.valueType() : null, false);
 
         write.add(EMPTY);
-        write.add(builder().a("state.increment();").toString());
+        write.add(builder().a("writer.incrementState();").toString());
         write.add(EMPTY);
 
         indent--;

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/e63ce523/modules/core/src/main/java/org/apache/ignite/events/EventType.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/events/EventType.java b/modules/core/src/main/java/org/apache/ignite/events/EventType.java
index 591a705..9f7e2c4 100644
--- a/modules/core/src/main/java/org/apache/ignite/events/EventType.java
+++ b/modules/core/src/main/java/org/apache/ignite/events/EventType.java
@@ -865,7 +865,7 @@ public interface EventType {
      */
     public static final int[] EVTS_JOB_EXECUTION = {
         EVT_JOB_MAPPED,
-        EVT_JOB_RESULTED,+
+        EVT_JOB_RESULTED,
         EVT_JOB_FAILED_OVER,
         EVT_JOB_STARTED,
         EVT_JOB_FINISHED,

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/e63ce523/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 88e6ad3..3cbd5e1 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
@@ -126,36 +126,34 @@ public class GridJobCancelRequest extends MessageAdapter {
 
     /** {@inheritDoc} */
     @SuppressWarnings("all")
-    @Override public boolean writeTo(ByteBuffer buf, MessageWriteState state) {
-        MessageWriter writer = state.writer();
-
+    @Override public boolean writeTo(ByteBuffer buf, MessageWriter writer) {
         writer.setBuffer(buf);
 
-        if (!state.isTypeWritten()) {
+        if (!writer.isTypeWritten()) {
             if (!writer.writeByte(null, directType()))
                 return false;
 
-            state.setTypeWritten();
+            writer.onTypeWritten();
         }
 
-        switch (state.index()) {
+        switch (writer.state()) {
             case 0:
                 if (!writer.writeIgniteUuid("jobId", jobId))
                     return false;
 
-                state.increment();
+                writer.incrementState();
 
             case 1:
                 if (!writer.writeIgniteUuid("sesId", sesId))
                     return false;
 
-                state.increment();
+                writer.incrementState();
 
             case 2:
                 if (!writer.writeBoolean("sys", sys))
                     return false;
 
-                state.increment();
+                writer.incrementState();
 
         }
 

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/e63ce523/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 4dee422..eb928ac 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
@@ -451,144 +451,142 @@ public class GridJobExecuteRequest extends MessageAdapter implements GridTaskMes
 
     /** {@inheritDoc} */
     @SuppressWarnings("all")
-    @Override public boolean writeTo(ByteBuffer buf, MessageWriteState state) {
-        MessageWriter writer = state.writer();
-
+    @Override public boolean writeTo(ByteBuffer buf, MessageWriter writer) {
         writer.setBuffer(buf);
 
-        if (!state.isTypeWritten()) {
+        if (!writer.isTypeWritten()) {
             if (!writer.writeByte(null, directType()))
                 return false;
 
-            state.setTypeWritten();
+            writer.onTypeWritten();
         }
 
-        switch (state.index()) {
+        switch (writer.state()) {
             case 0:
                 if (!writer.writeIgniteUuid("clsLdrId", clsLdrId))
                     return false;
 
-                state.increment();
+                writer.incrementState();
 
             case 1:
                 if (!writer.writeString("cpSpi", cpSpi))
                     return false;
 
-                state.increment();
+                writer.incrementState();
 
             case 2:
                 if (!writer.writeByte("depMode", depMode != null ? (byte)depMode.ordinal() : -1))
                     return false;
 
-                state.increment();
+                writer.incrementState();
 
             case 3:
                 if (!writer.writeBoolean("dynamicSiblings", dynamicSiblings))
                     return false;
 
-                state.increment();
+                writer.incrementState();
 
             case 4:
                 if (!writer.writeBoolean("forceLocDep", forceLocDep))
                     return false;
 
-                state.increment();
+                writer.incrementState();
 
             case 5:
                 if (!writer.writeBoolean("internal", internal))
                     return false;
 
-                state.increment();
+                writer.incrementState();
 
             case 6:
                 if (!writer.writeByteArray("jobAttrsBytes", jobAttrsBytes))
                     return false;
 
-                state.increment();
+                writer.incrementState();
 
             case 7:
                 if (!writer.writeByteArray("jobBytes", jobBytes))
                     return false;
 
-                state.increment();
+                writer.incrementState();
 
             case 8:
                 if (!writer.writeIgniteUuid("jobId", jobId))
                     return false;
 
-                state.increment();
+                writer.incrementState();
 
             case 9:
                 if (!writer.writeMap("ldrParticipants", ldrParticipants, Type.UUID, Type.IGNITE_UUID))
                     return false;
 
-                state.increment();
+                writer.incrementState();
 
             case 10:
                 if (!writer.writeByteArray("sesAttrsBytes", sesAttrsBytes))
                     return false;
 
-                state.increment();
+                writer.incrementState();
 
             case 11:
                 if (!writer.writeBoolean("sesFullSup", sesFullSup))
                     return false;
 
-                state.increment();
+                writer.incrementState();
 
             case 12:
                 if (!writer.writeIgniteUuid("sesId", sesId))
                     return false;
 
-                state.increment();
+                writer.incrementState();
 
             case 13:
                 if (!writer.writeByteArray("siblingsBytes", siblingsBytes))
                     return false;
 
-                state.increment();
+                writer.incrementState();
 
             case 14:
                 if (!writer.writeLong("startTaskTime", startTaskTime))
                     return false;
 
-                state.increment();
+                writer.incrementState();
 
             case 15:
                 if (!writer.writeUuid("subjId", subjId))
                     return false;
 
-                state.increment();
+                writer.incrementState();
 
             case 16:
                 if (!writer.writeString("taskClsName", taskClsName))
                     return false;
 
-                state.increment();
+                writer.incrementState();
 
             case 17:
                 if (!writer.writeString("taskName", taskName))
                     return false;
 
-                state.increment();
+                writer.incrementState();
 
             case 18:
                 if (!writer.writeLong("timeout", timeout))
                     return false;
 
-                state.increment();
+                writer.incrementState();
 
             case 19:
                 if (!writer.writeCollection("top", top, Type.UUID))
                     return false;
 
-                state.increment();
+                writer.incrementState();
 
             case 20:
                 if (!writer.writeString("userVer", userVer))
                     return false;
 
-                state.increment();
+                writer.incrementState();
 
         }
 

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/e63ce523/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 1a01dad..499cc58 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
@@ -229,60 +229,58 @@ public class GridJobExecuteResponse extends MessageAdapter implements GridTaskMe
 
     /** {@inheritDoc} */
     @SuppressWarnings("all")
-    @Override public boolean writeTo(ByteBuffer buf, MessageWriteState state) {
-        MessageWriter writer = state.writer();
-
+    @Override public boolean writeTo(ByteBuffer buf, MessageWriter writer) {
         writer.setBuffer(buf);
 
-        if (!state.isTypeWritten()) {
+        if (!writer.isTypeWritten()) {
             if (!writer.writeByte(null, directType()))
                 return false;
 
-            state.setTypeWritten();
+            writer.onTypeWritten();
         }
 
-        switch (state.index()) {
+        switch (writer.state()) {
             case 0:
                 if (!writer.writeByteArray("gridExBytes", gridExBytes))
                     return false;
 
-                state.increment();
+                writer.incrementState();
 
             case 1:
                 if (!writer.writeBoolean("isCancelled", isCancelled))
                     return false;
 
-                state.increment();
+                writer.incrementState();
 
             case 2:
                 if (!writer.writeByteArray("jobAttrsBytes", jobAttrsBytes))
                     return false;
 
-                state.increment();
+                writer.incrementState();
 
             case 3:
                 if (!writer.writeIgniteUuid("jobId", jobId))
                     return false;
 
-                state.increment();
+                writer.incrementState();
 
             case 4:
                 if (!writer.writeUuid("nodeId", nodeId))
                     return false;
 
-                state.increment();
+                writer.incrementState();
 
             case 5:
                 if (!writer.writeByteArray("resBytes", resBytes))
                     return false;
 
-                state.increment();
+                writer.incrementState();
 
             case 6:
                 if (!writer.writeIgniteUuid("sesId", sesId))
                     return false;
 
-                state.increment();
+                writer.incrementState();
 
         }
 

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/e63ce523/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 5d9621d..d919b50 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
@@ -100,30 +100,28 @@ public class GridJobSiblingsRequest extends MessageAdapter {
 
     /** {@inheritDoc} */
     @SuppressWarnings("all")
-    @Override public boolean writeTo(ByteBuffer buf, MessageWriteState state) {
-        MessageWriter writer = state.writer();
-
+    @Override public boolean writeTo(ByteBuffer buf, MessageWriter writer) {
         writer.setBuffer(buf);
 
-        if (!state.isTypeWritten()) {
+        if (!writer.isTypeWritten()) {
             if (!writer.writeByte(null, directType()))
                 return false;
 
-            state.setTypeWritten();
+            writer.onTypeWritten();
         }
 
-        switch (state.index()) {
+        switch (writer.state()) {
             case 0:
                 if (!writer.writeIgniteUuid("sesId", sesId))
                     return false;
 
-                state.increment();
+                writer.incrementState();
 
             case 1:
                 if (!writer.writeByteArray("topicBytes", topicBytes))
                     return false;
 
-                state.increment();
+                writer.incrementState();
 
         }
 

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/e63ce523/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 7a34f86..e463756 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
@@ -92,24 +92,22 @@ public class GridJobSiblingsResponse extends MessageAdapter {
 
     /** {@inheritDoc} */
     @SuppressWarnings("all")
-    @Override public boolean writeTo(ByteBuffer buf, MessageWriteState state) {
-        MessageWriter writer = state.writer();
-
+    @Override public boolean writeTo(ByteBuffer buf, MessageWriter writer) {
         writer.setBuffer(buf);
 
-        if (!state.isTypeWritten()) {
+        if (!writer.isTypeWritten()) {
             if (!writer.writeByte(null, directType()))
                 return false;
 
-            state.setTypeWritten();
+            writer.onTypeWritten();
         }
 
-        switch (state.index()) {
+        switch (writer.state()) {
             case 0:
                 if (!writer.writeByteArray("siblingsBytes", siblingsBytes))
                     return false;
 
-                state.increment();
+                writer.incrementState();
 
         }
 

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/e63ce523/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 da7b73b..d0a9afb 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
@@ -75,24 +75,22 @@ public class GridTaskCancelRequest extends MessageAdapter {
 
     /** {@inheritDoc} */
     @SuppressWarnings("all")
-    @Override public boolean writeTo(ByteBuffer buf, MessageWriteState state) {
-        MessageWriter writer = state.writer();
-
+    @Override public boolean writeTo(ByteBuffer buf, MessageWriter writer) {
         writer.setBuffer(buf);
 
-        if (!state.isTypeWritten()) {
+        if (!writer.isTypeWritten()) {
             if (!writer.writeByte(null, directType()))
                 return false;
 
-            state.setTypeWritten();
+            writer.onTypeWritten();
         }
 
-        switch (state.index()) {
+        switch (writer.state()) {
             case 0:
                 if (!writer.writeIgniteUuid("sesId", sesId))
                     return false;
 
-                state.increment();
+                writer.incrementState();
 
         }
 

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/e63ce523/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 f47d0aa..09be112 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
@@ -115,36 +115,34 @@ public class GridTaskSessionRequest extends MessageAdapter implements GridTaskMe
 
     /** {@inheritDoc} */
     @SuppressWarnings("all")
-    @Override public boolean writeTo(ByteBuffer buf, MessageWriteState state) {
-        MessageWriter writer = state.writer();
-
+    @Override public boolean writeTo(ByteBuffer buf, MessageWriter writer) {
         writer.setBuffer(buf);
 
-        if (!state.isTypeWritten()) {
+        if (!writer.isTypeWritten()) {
             if (!writer.writeByte(null, directType()))
                 return false;
 
-            state.setTypeWritten();
+            writer.onTypeWritten();
         }
 
-        switch (state.index()) {
+        switch (writer.state()) {
             case 0:
                 if (!writer.writeByteArray("attrsBytes", attrsBytes))
                     return false;
 
-                state.increment();
+                writer.incrementState();
 
             case 1:
                 if (!writer.writeIgniteUuid("jobId", jobId))
                     return false;
 
-                state.increment();
+                writer.incrementState();
 
             case 2:
                 if (!writer.writeIgniteUuid("sesId", sesId))
                     return false;
 
-                state.increment();
+                writer.incrementState();
 
         }
 

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/e63ce523/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 fed6a53..901958f 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
@@ -529,16 +529,16 @@ public class DirectByteBufferStream {
     /**
      * @param msg Message.
      */
-    public void writeMessage(MessageAdapter msg, MessageWriteState state) {
+    public void writeMessage(MessageAdapter msg, MessageWriter writer) {
         if (msg != null) {
             if (buf.hasRemaining()) {
                 try {
-                    state.forward();
+                    writer.beforeInnerMessageWrite();
 
-                    lastFinished = msg.writeTo(buf, state);
+                    lastFinished = msg.writeTo(buf, writer);
                 }
                 finally {
-                    state.backward(lastFinished);
+                    writer.afterInnerMessageWrite(lastFinished);
                 }
             }
             else
@@ -551,9 +551,9 @@ public class DirectByteBufferStream {
     /**
      * @param arr Array.
      * @param itemType Component type.
-     * @param state Current state.
+     * @param writer Writer.
      */
-    public <T> void writeObjectArray(T[] arr, MessageAdapter.Type itemType, MessageWriteState state) {
+    public <T> void writeObjectArray(T[] arr, MessageAdapter.Type itemType, MessageWriter writer) {
         if (arr != null) {
             if (it == null) {
                 writeInt(arr.length);
@@ -565,17 +565,10 @@ public class DirectByteBufferStream {
             }
 
             while (it.hasNext() || cur != NULL) {
-                if (cur == NULL) {
+                if (cur == NULL)
                     cur = it.next();
 
-//                    if (cur != null && itemType == Type.MSG) {
-//                        cur = ((MessageAdapter)cur).clone();
-//
-//                        ((MessageAdapter)cur).setWriter(writer);
-//                    }
-                }
-
-                write(itemType, cur, state);
+                write(itemType, cur, writer);
 
                 if (!lastFinished)
                     return;
@@ -592,9 +585,9 @@ public class DirectByteBufferStream {
     /**
      * @param col Collection.
      * @param itemType Item type.
-     * @param state Current state.
+     * @param writer Writer.
      */
-    public <T> void writeCollection(Collection<T> col, MessageAdapter.Type itemType, MessageWriteState state) {
+    public <T> void writeCollection(Collection<T> col, MessageAdapter.Type itemType, MessageWriter writer) {
         if (col != null) {
             if (it == null) {
                 writeInt(col.size());
@@ -606,17 +599,10 @@ public class DirectByteBufferStream {
             }
 
             while (it.hasNext() || cur != NULL) {
-                if (cur == NULL) {
+                if (cur == NULL)
                     cur = it.next();
 
-//                    if (cur != null && itemType == Type.MSG) {
-//                        cur = ((MessageAdapter)cur).clone();
-//
-//                        ((MessageAdapter)cur).setWriter(writer);
-//                    }
-                }
-
-                write(itemType, cur, state);
+                write(itemType, cur, writer);
 
                 if (!lastFinished)
                     return;
@@ -634,11 +620,11 @@ public class DirectByteBufferStream {
      * @param map Map.
      * @param keyType Key type.
      * @param valType Value type.
-     * @param state Current state.
+     * @param writer Writer.
      */
     @SuppressWarnings("unchecked")
     public <K, V> void writeMap(Map<K, V> map, MessageAdapter.Type keyType, MessageAdapter.Type valType,
-        MessageWriteState state) {
+        MessageWriter writer) {
         if (map != null) {
             if (it == null) {
                 writeInt(map.size());
@@ -652,35 +638,13 @@ public class DirectByteBufferStream {
             while (it.hasNext() || cur != NULL) {
                 Map.Entry<K, V> e;
 
-                if (cur == NULL) {
+                if (cur == NULL)
                     cur = it.next();
 
-                    e = (Map.Entry<K, V>)cur;
-
-//                    if (keyType == Type.MSG || valType == Type.MSG) {
-//                        K k = e.getKey();
-//                        V v = e.getValue();
-//
-//                        if (k != null && keyType == Type.MSG) {
-//                            k = (K)((MessageAdapter)k).clone();
-//
-//                            ((MessageAdapter)k).setWriter(writer);
-//                        }
-//
-//                        if (v != null && valType == Type.MSG) {
-//                            v = (V)((MessageAdapter)v).clone();
-//
-//                            ((MessageAdapter)v).setWriter(writer);
-//                        }
-//
-//                        cur = e = F.t(k, v);
-//                    }
-                }
-                else
-                    e = (Map.Entry<K, V>)cur;
+                e = (Map.Entry<K, V>)cur;
 
                 if (!keyDone) {
-                    write(keyType, e.getKey(), state);
+                    write(keyType, e.getKey(), writer);
 
                     if (!lastFinished)
                         return;
@@ -688,7 +652,7 @@ public class DirectByteBufferStream {
                     keyDone = true;
                 }
 
-                write(valType, e.getValue(), state);
+                write(valType, e.getValue(), writer);
 
                 if (!lastFinished)
                     return;
@@ -1254,8 +1218,9 @@ public class DirectByteBufferStream {
     /**
      * @param type Type.
      * @param val Value.
+     * @param writer Writer.
      */
-    private void write(MessageAdapter.Type type, Object val, MessageWriteState state) {
+    private void write(MessageAdapter.Type type, Object val, MessageWriter writer) {
         switch (type) {
             case BYTE:
                 writeByte((Byte)val);
@@ -1360,13 +1325,13 @@ public class DirectByteBufferStream {
             case MSG:
                 try {
                     if (val != null)
-                        state.forward();
+                        writer.beforeInnerMessageWrite();
 
-                    writeMessage((MessageAdapter)val, state);
+                    writeMessage((MessageAdapter)val, writer);
                 }
                 finally {
                     if (val != null)
-                        state.backward(lastFinished);
+                        writer.afterInnerMessageWrite(lastFinished);
                 }
 
                 break;

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/e63ce523/modules/core/src/main/java/org/apache/ignite/internal/direct/DirectMessageWriter.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/direct/DirectMessageWriter.java b/modules/core/src/main/java/org/apache/ignite/internal/direct/DirectMessageWriter.java
index 9460d74..0438bb2 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/direct/DirectMessageWriter.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/direct/DirectMessageWriter.java
@@ -31,11 +31,8 @@ public class DirectMessageWriter implements MessageWriter {
     /** Stream. */
     private final DirectByteBufferStream stream = new DirectByteBufferStream(null);
 
-    private MessageWriteState state;
-
-    public void state(MessageWriteState state) {
-        this.state = state;
-    }
+    /** State. */
+    private final MessageWriterState state = new MessageWriterState();
 
     /** {@inheritDoc} */
     @Override public void setBuffer(ByteBuffer buf) {
@@ -184,24 +181,21 @@ public class DirectMessageWriter implements MessageWriter {
 
     /** {@inheritDoc} */
     @Override public boolean writeMessage(String name, @Nullable MessageAdapter msg) {
-//        if (msg != null)
-//            msg.setWriter(this);
-
-        stream.writeMessage(msg, state);
+        stream.writeMessage(msg, this);
 
         return stream.lastFinished();
     }
 
     /** {@inheritDoc} */
     @Override public <T> boolean writeObjectArray(String name, T[] arr, MessageAdapter.Type itemType) {
-        stream.writeObjectArray(arr, itemType, state);
+        stream.writeObjectArray(arr, itemType, this);
 
         return stream.lastFinished();
     }
 
     /** {@inheritDoc} */
     @Override public <T> boolean writeCollection(String name, Collection<T> col, MessageAdapter.Type itemType) {
-        stream.writeCollection(col, itemType, state);
+        stream.writeCollection(col, itemType, this);
 
         return stream.lastFinished();
     }
@@ -209,8 +203,43 @@ public class DirectMessageWriter implements MessageWriter {
     /** {@inheritDoc} */
     @Override public <K, V> boolean writeMap(String name, Map<K, V> map, MessageAdapter.Type keyType,
         MessageAdapter.Type valType) {
-        stream.writeMap(map, keyType, valType, state);
+        stream.writeMap(map, keyType, valType, this);
 
         return stream.lastFinished();
     }
+
+    /** {@inheritDoc} */
+    @Override public boolean isTypeWritten() {
+        return state.isTypeWritten();
+    }
+
+    /** {@inheritDoc} */
+    @Override public void onTypeWritten() {
+        state.onTypeWritten();
+    }
+
+    /** {@inheritDoc} */
+    @Override public int state() {
+        return state.state();
+    }
+
+    /** {@inheritDoc} */
+    @Override public void incrementState() {
+        state.incrementState();
+    }
+
+    /** {@inheritDoc} */
+    @Override public void beforeInnerMessageWrite() {
+        state.beforeInnerMessageWrite();
+    }
+
+    /** {@inheritDoc} */
+    @Override public void afterInnerMessageWrite(boolean finished) {
+        state.afterInnerMessageWrite(finished);
+    }
+
+    /** {@inheritDoc} */
+    @Override public void reset() {
+        state.reset();
+    }
 }

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/e63ce523/modules/core/src/main/java/org/apache/ignite/internal/direct/MessageWriterState.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/direct/MessageWriterState.java b/modules/core/src/main/java/org/apache/ignite/internal/direct/MessageWriterState.java
new file mode 100644
index 0000000..e486ad3
--- /dev/null
+++ b/modules/core/src/main/java/org/apache/ignite/internal/direct/MessageWriterState.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.direct;
+
+import java.util.*;
+
+/**
+ * Writer state.
+ */
+public class MessageWriterState {
+    /** Initial array size. */
+    private static final int INIT_SIZE = 10;
+
+    /** Initial value. */
+    private static final int INIT_VAL = -1;
+
+    /** Stack array. */
+    private int[] stack;
+
+    /** Current position. */
+    private int pos;
+
+    public MessageWriterState() {
+        stack = new int[INIT_SIZE];
+
+        Arrays.fill(stack, INIT_VAL);
+    }
+
+    /**
+     * @return Whether type is written.
+     */
+    public boolean isTypeWritten() {
+        return state() >= 0;
+    }
+
+    /**
+     * Callback called after type is written.
+     */
+    public void onTypeWritten() {
+        assert state() == -1;
+
+        incrementState();
+    }
+
+    /**
+     * @return Current state.
+     */
+    public int state() {
+        return stack[pos];
+    }
+
+    /**
+     * Increments state.
+     */
+    public void incrementState() {
+        stack[pos]++;
+    }
+
+    /**
+     * Callback called before inner message is written.
+     */
+    public void beforeInnerMessageWrite() {
+        pos++;
+
+        // Growing never happen for Ignite messages, but we need
+        // to support it for custom messages from plugins.
+        if (pos == stack.length) {
+            int[] stack0 = stack;
+
+            stack = new int[stack.length << 1];
+
+            System.arraycopy(stack0, 0, stack, 0, stack0.length);
+
+            Arrays.fill(stack, stack0.length, stack.length, INIT_VAL);
+        }
+    }
+
+    /**
+     * Callback called after inner message is written.
+     *
+     * @param finished Whether message was fully written.
+     */
+    public void afterInnerMessageWrite(boolean finished) {
+        if (finished)
+            stack[pos] = INIT_VAL;
+
+        pos--;
+    }
+
+    /**
+     * Resets state.
+     */
+    public void reset() {
+        assert pos == 0;
+
+        stack[0] = INIT_VAL;
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/e63ce523/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 0e3b1a8..e34879b 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
@@ -100,36 +100,34 @@ public class GridCheckpointRequest extends MessageAdapter {
 
     /** {@inheritDoc} */
     @SuppressWarnings("all")
-    @Override public boolean writeTo(ByteBuffer buf, MessageWriteState state) {
-        MessageWriter writer = state.writer();
-
+    @Override public boolean writeTo(ByteBuffer buf, MessageWriter writer) {
         writer.setBuffer(buf);
 
-        if (!state.isTypeWritten()) {
+        if (!writer.isTypeWritten()) {
             if (!writer.writeByte(null, directType()))
                 return false;
 
-            state.setTypeWritten();
+            writer.onTypeWritten();
         }
 
-        switch (state.index()) {
+        switch (writer.state()) {
             case 0:
                 if (!writer.writeString("cpSpi", cpSpi))
                     return false;
 
-                state.increment();
+                writer.incrementState();
 
             case 1:
                 if (!writer.writeString("key", key))
                     return false;
 
-                state.increment();
+                writer.incrementState();
 
             case 2:
                 if (!writer.writeIgniteUuid("sesId", sesId))
                     return false;
 
-                state.increment();
+                writer.incrementState();
 
         }
 

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/e63ce523/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 56e24f5..c2ce71c 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
@@ -201,60 +201,58 @@ public class GridIoMessage extends MessageAdapter {
 
     /** {@inheritDoc} */
     @SuppressWarnings("all")
-    @Override public boolean writeTo(ByteBuffer buf, MessageWriteState state) {
-        MessageWriter writer = state.writer();
-
+    @Override public boolean writeTo(ByteBuffer buf, MessageWriter writer) {
         writer.setBuffer(buf);
 
-        if (!state.isTypeWritten()) {
+        if (!writer.isTypeWritten()) {
             if (!writer.writeByte(null, directType()))
                 return false;
 
-            state.setTypeWritten();
+            writer.onTypeWritten();
         }
 
-        switch (state.index()) {
+        switch (writer.state()) {
             case 0:
                 if (!writer.writeMessage("msg", msg))
                     return false;
 
-                state.increment();
+                writer.incrementState();
 
             case 1:
                 if (!writer.writeBoolean("ordered", ordered))
                     return false;
 
-                state.increment();
+                writer.incrementState();
 
             case 2:
                 if (!writer.writeByte("plc", plc != null ? (byte)plc.ordinal() : -1))
                     return false;
 
-                state.increment();
+                writer.incrementState();
 
             case 3:
                 if (!writer.writeBoolean("skipOnTimeout", skipOnTimeout))
                     return false;
 
-                state.increment();
+                writer.incrementState();
 
             case 4:
                 if (!writer.writeLong("timeout", timeout))
                     return false;
 
-                state.increment();
+                writer.incrementState();
 
             case 5:
                 if (!writer.writeByteArray("topicBytes", topicBytes))
                     return false;
 
-                state.increment();
+                writer.incrementState();
 
             case 6:
                 if (!writer.writeInt("topicOrd", topicOrd))
                     return false;
 
-                state.increment();
+                writer.incrementState();
 
         }
 

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/e63ce523/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 4200c10..20a8194 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
@@ -226,60 +226,58 @@ public class GridIoUserMessage extends MessageAdapter {
 
     /** {@inheritDoc} */
     @SuppressWarnings("all")
-    @Override public boolean writeTo(ByteBuffer buf, MessageWriteState state) {
-        MessageWriter writer = state.writer();
-
+    @Override public boolean writeTo(ByteBuffer buf, MessageWriter writer) {
         writer.setBuffer(buf);
 
-        if (!state.isTypeWritten()) {
+        if (!writer.isTypeWritten()) {
             if (!writer.writeByte(null, directType()))
                 return false;
 
-            state.setTypeWritten();
+            writer.onTypeWritten();
         }
 
-        switch (state.index()) {
+        switch (writer.state()) {
             case 0:
                 if (!writer.writeByteArray("bodyBytes", bodyBytes))
                     return false;
 
-                state.increment();
+                writer.incrementState();
 
             case 1:
                 if (!writer.writeIgniteUuid("clsLdrId", clsLdrId))
                     return false;
 
-                state.increment();
+                writer.incrementState();
 
             case 2:
                 if (!writer.writeString("depClsName", depClsName))
                     return false;
 
-                state.increment();
+                writer.incrementState();
 
             case 3:
                 if (!writer.writeByte("depMode", depMode != null ? (byte)depMode.ordinal() : -1))
                     return false;
 
-                state.increment();
+                writer.incrementState();
 
             case 4:
                 if (!writer.writeMap("ldrParties", ldrParties, Type.UUID, Type.IGNITE_UUID))
                     return false;
 
-                state.increment();
+                writer.incrementState();
 
             case 5:
                 if (!writer.writeByteArray("topicBytes", topicBytes))
                     return false;
 
-                state.increment();
+                writer.incrementState();
 
             case 6:
                 if (!writer.writeString("userVer", userVer))
                     return false;
 
-                state.increment();
+                writer.incrementState();
 
         }
 

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/e63ce523/modules/core/src/main/java/org/apache/ignite/internal/managers/deployment/GridDeploymentInfoBean.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/managers/deployment/GridDeploymentInfoBean.java b/modules/core/src/main/java/org/apache/ignite/internal/managers/deployment/GridDeploymentInfoBean.java
index 10ae53c..3f3b4ed 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/managers/deployment/GridDeploymentInfoBean.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/managers/deployment/GridDeploymentInfoBean.java
@@ -156,48 +156,46 @@ public class GridDeploymentInfoBean extends MessageAdapter implements GridDeploy
 
     /** {@inheritDoc} */
     @SuppressWarnings("all")
-    @Override public boolean writeTo(ByteBuffer buf, MessageWriteState state) {
-        MessageWriter writer = state.writer();
-
+    @Override public boolean writeTo(ByteBuffer buf, MessageWriter writer) {
         writer.setBuffer(buf);
 
-        if (!state.isTypeWritten()) {
+        if (!writer.isTypeWritten()) {
             if (!writer.writeByte(null, directType()))
                 return false;
 
-            state.setTypeWritten();
+            writer.onTypeWritten();
         }
 
-        switch (state.index()) {
+        switch (writer.state()) {
             case 0:
                 if (!writer.writeIgniteUuid("clsLdrId", clsLdrId))
                     return false;
 
-                state.increment();
+                writer.incrementState();
 
             case 1:
                 if (!writer.writeByte("depMode", depMode != null ? (byte)depMode.ordinal() : -1))
                     return false;
 
-                state.increment();
+                writer.incrementState();
 
             case 2:
                 if (!writer.writeBoolean("locDepOwner", locDepOwner))
                     return false;
 
-                state.increment();
+                writer.incrementState();
 
             case 3:
                 if (!writer.writeMap("participants", participants, Type.UUID, Type.IGNITE_UUID))
                     return false;
 
-                state.increment();
+                writer.incrementState();
 
             case 4:
                 if (!writer.writeString("userVer", userVer))
                     return false;
 
-                state.increment();
+                writer.incrementState();
 
         }
 

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/e63ce523/modules/core/src/main/java/org/apache/ignite/internal/managers/deployment/GridDeploymentRequest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/managers/deployment/GridDeploymentRequest.java b/modules/core/src/main/java/org/apache/ignite/internal/managers/deployment/GridDeploymentRequest.java
index 2b1544b..03338a1 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/managers/deployment/GridDeploymentRequest.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/managers/deployment/GridDeploymentRequest.java
@@ -175,48 +175,46 @@ public class GridDeploymentRequest extends MessageAdapter {
 
     /** {@inheritDoc} */
     @SuppressWarnings("all")
-    @Override public boolean writeTo(ByteBuffer buf, MessageWriteState state) {
-        MessageWriter writer = state.writer();
-
+    @Override public boolean writeTo(ByteBuffer buf, MessageWriter writer) {
         writer.setBuffer(buf);
 
-        if (!state.isTypeWritten()) {
+        if (!writer.isTypeWritten()) {
             if (!writer.writeByte(null, directType()))
                 return false;
 
-            state.setTypeWritten();
+            writer.onTypeWritten();
         }
 
-        switch (state.index()) {
+        switch (writer.state()) {
             case 0:
                 if (!writer.writeBoolean("isUndeploy", isUndeploy))
                     return false;
 
-                state.increment();
+                writer.incrementState();
 
             case 1:
                 if (!writer.writeIgniteUuid("ldrId", ldrId))
                     return false;
 
-                state.increment();
+                writer.incrementState();
 
             case 2:
                 if (!writer.writeCollection("nodeIds", nodeIds, Type.UUID))
                     return false;
 
-                state.increment();
+                writer.incrementState();
 
             case 3:
                 if (!writer.writeByteArray("resTopicBytes", resTopicBytes))
                     return false;
 
-                state.increment();
+                writer.incrementState();
 
             case 4:
                 if (!writer.writeString("rsrcName", rsrcName))
                     return false;
 
-                state.increment();
+                writer.incrementState();
 
         }
 

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/e63ce523/modules/core/src/main/java/org/apache/ignite/internal/managers/deployment/GridDeploymentResponse.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/managers/deployment/GridDeploymentResponse.java b/modules/core/src/main/java/org/apache/ignite/internal/managers/deployment/GridDeploymentResponse.java
index 285b78c..0538b3b 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/managers/deployment/GridDeploymentResponse.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/managers/deployment/GridDeploymentResponse.java
@@ -122,36 +122,34 @@ public class GridDeploymentResponse extends MessageAdapter {
 
     /** {@inheritDoc} */
     @SuppressWarnings("all")
-    @Override public boolean writeTo(ByteBuffer buf, MessageWriteState state) {
-        MessageWriter writer = state.writer();
-
+    @Override public boolean writeTo(ByteBuffer buf, MessageWriter writer) {
         writer.setBuffer(buf);
 
-        if (!state.isTypeWritten()) {
+        if (!writer.isTypeWritten()) {
             if (!writer.writeByte(null, directType()))
                 return false;
 
-            state.setTypeWritten();
+            writer.onTypeWritten();
         }
 
-        switch (state.index()) {
+        switch (writer.state()) {
             case 0:
                 if (!writer.writeMessage("byteSrc", byteSrc))
                     return false;
 
-                state.increment();
+                writer.incrementState();
 
             case 1:
                 if (!writer.writeString("errMsg", errMsg))
                     return false;
 
-                state.increment();
+                writer.incrementState();
 
             case 2:
                 if (!writer.writeBoolean("success", success))
                     return false;
 
-                state.increment();
+                writer.incrementState();
 
         }
 

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/e63ce523/modules/core/src/main/java/org/apache/ignite/internal/managers/eventstorage/GridEventStorageMessage.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/managers/eventstorage/GridEventStorageMessage.java b/modules/core/src/main/java/org/apache/ignite/internal/managers/eventstorage/GridEventStorageMessage.java
index 342018f..2748d75 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/managers/eventstorage/GridEventStorageMessage.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/managers/eventstorage/GridEventStorageMessage.java
@@ -286,72 +286,70 @@ public class GridEventStorageMessage extends MessageAdapter {
 
     /** {@inheritDoc} */
     @SuppressWarnings("all")
-    @Override public boolean writeTo(ByteBuffer buf, MessageWriteState state) {
-        MessageWriter writer = state.writer();
-
+    @Override public boolean writeTo(ByteBuffer buf, MessageWriter writer) {
         writer.setBuffer(buf);
 
-        if (!state.isTypeWritten()) {
+        if (!writer.isTypeWritten()) {
             if (!writer.writeByte(null, directType()))
                 return false;
 
-            state.setTypeWritten();
+            writer.onTypeWritten();
         }
 
-        switch (state.index()) {
+        switch (writer.state()) {
             case 0:
                 if (!writer.writeIgniteUuid("clsLdrId", clsLdrId))
                     return false;
 
-                state.increment();
+                writer.incrementState();
 
             case 1:
                 if (!writer.writeByte("depMode", depMode != null ? (byte)depMode.ordinal() : -1))
                     return false;
 
-                state.increment();
+                writer.incrementState();
 
             case 2:
                 if (!writer.writeByteArray("evtsBytes", evtsBytes))
                     return false;
 
-                state.increment();
+                writer.incrementState();
 
             case 3:
                 if (!writer.writeByteArray("exBytes", exBytes))
                     return false;
 
-                state.increment();
+                writer.incrementState();
 
             case 4:
                 if (!writer.writeByteArray("filter", filter))
                     return false;
 
-                state.increment();
+                writer.incrementState();
 
             case 5:
                 if (!writer.writeString("filterClsName", filterClsName))
                     return false;
 
-                state.increment();
+                writer.incrementState();
 
             case 6:
                 if (!writer.writeMap("ldrParties", ldrParties, Type.UUID, Type.IGNITE_UUID))
                     return false;
 
-                state.increment();
+                writer.incrementState();
 
             case 7:
                 if (!writer.writeByteArray("resTopicBytes", resTopicBytes))
                     return false;
 
-                state.increment();
+                writer.incrementState();
 
             case 8:
                 if (!writer.writeString("userVer", userVer))
                     return false;
 
-                state.increment();
+                writer.incrementState();
 
         }
 

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/e63ce523/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheEvictionRequest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheEvictionRequest.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheEvictionRequest.java
index 57487d4..aae0e94 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheEvictionRequest.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheEvictionRequest.java
@@ -159,39 +159,37 @@ public class GridCacheEvictionRequest<K, V> extends GridCacheMessage<K, V> imple
 
     /** {@inheritDoc} */
     @SuppressWarnings("all")
-    @Override public boolean writeTo(ByteBuffer buf, MessageWriteState state) {
-        MessageWriter writer = state.writer();
-
+    @Override public boolean writeTo(ByteBuffer buf, MessageWriter writer) {
         writer.setBuffer(buf);
 
-        if (!super.writeTo(buf, state))
+        if (!super.writeTo(buf, writer))
             return false;
 
-        if (!state.isTypeWritten()) {
+        if (!writer.isTypeWritten()) {
             if (!writer.writeByte(null, directType()))
                 return false;
 
-            state.setTypeWritten();
+            writer.onTypeWritten();
         }
 
-        switch (state.index()) {
+        switch (writer.state()) {
             case 3:
                 if (!writer.writeByteArray("entriesBytes", entriesBytes))
                     return false;
 
-                state.increment();
+                writer.incrementState();
 
             case 4:
                 if (!writer.writeLong("futId", futId))
                     return false;
 
-                state.increment();
+                writer.incrementState();
 
             case 5:
                 if (!writer.writeLong("topVer", topVer))
                     return false;
 
-                state.increment();
+                writer.incrementState();
 
         }
 

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/e63ce523/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheEvictionResponse.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheEvictionResponse.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheEvictionResponse.java
index 44a5d81..650b5c9 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheEvictionResponse.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheEvictionResponse.java
@@ -148,39 +148,37 @@ public class GridCacheEvictionResponse<K, V> extends GridCacheMessage<K, V> {
 
     /** {@inheritDoc} */
     @SuppressWarnings("all")
-    @Override public boolean writeTo(ByteBuffer buf, MessageWriteState state) {
-        MessageWriter writer = state.writer();
-
+    @Override public boolean writeTo(ByteBuffer buf, MessageWriter writer) {
         writer.setBuffer(buf);
 
-        if (!super.writeTo(buf, state))
+        if (!super.writeTo(buf, writer))
             return false;
 
-        if (!state.isTypeWritten()) {
+        if (!writer.isTypeWritten()) {
             if (!writer.writeByte(null, directType()))
                 return false;
 
-            state.setTypeWritten();
+            writer.onTypeWritten();
         }
 
-        switch (state.index()) {
+        switch (writer.state()) {
             case 3:
                 if (!writer.writeBoolean("err", err))
                     return false;
 
-                state.increment();
+                writer.incrementState();
 
             case 4:
                 if (!writer.writeLong("futId", futId))
                     return false;
 
-                state.increment();
+                writer.incrementState();
 
             case 5:
                 if (!writer.writeCollection("rejectedKeyBytes", rejectedKeyBytes, Type.BYTE_ARR))
                     return false;
 
-                state.increment();
+                writer.incrementState();
 
         }
 

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/e63ce523/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheMessage.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheMessage.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheMessage.java
index b2bd3c0..3f95081 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheMessage.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheMessage.java
@@ -658,36 +658,34 @@ public abstract class GridCacheMessage<K, V> extends MessageAdapter {
 
     /** {@inheritDoc} */
     @SuppressWarnings("all")
-    @Override public boolean writeTo(ByteBuffer buf, MessageWriteState state) {
-        MessageWriter writer = state.writer();
-
+    @Override public boolean writeTo(ByteBuffer buf, MessageWriter writer) {
         writer.setBuffer(buf);
 
-        if (!state.isTypeWritten()) {
+        if (!writer.isTypeWritten()) {
             if (!writer.writeByte(null, directType()))
                 return false;
 
-            state.setTypeWritten();
+            writer.onTypeWritten();
         }
 
-        switch (state.index()) {
+        switch (writer.state()) {
             case 0:
                 if (!writer.writeInt("cacheId", cacheId))
                     return false;
 
-                state.increment();
+                writer.incrementState();
 
             case 1:
                 if (!writer.writeMessage("depInfo", depInfo))
                     return false;
 
-                state.increment();
+                writer.incrementState();
 
             case 2:
                 if (!writer.writeLong("msgId", msgId))
                     return false;
 
-                state.increment();
+                writer.incrementState();
 
         }
 

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/e63ce523/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheValueBytes.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheValueBytes.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheValueBytes.java
index 8385ec3..426b1e8 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheValueBytes.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheValueBytes.java
@@ -120,30 +120,28 @@ public class GridCacheValueBytes extends MessageAdapter {
     }
 
     /** {@inheritDoc} */
-    @Override public boolean writeTo(ByteBuffer buf, MessageWriteState state) {
-        MessageWriter writer = state.writer();
-
+    @Override public boolean writeTo(ByteBuffer buf, MessageWriter writer) {
         writer.setBuffer(buf);
 
-        if (!state.isTypeWritten()) {
+        if (!writer.isTypeWritten()) {
             if (!writer.writeByte(null, directType()))
                 return false;
 
-            state.setTypeWritten();
+            writer.onTypeWritten();
         }
 
-        switch (state.index()) {
+        switch (writer.state()) {
             case 0:
                 if (!writer.writeByteArray("bytes", bytes))
                     return false;
 
-                state.increment();
+                writer.incrementState();
 
             case 1:
                 if (!writer.writeBoolean("plain", plain))
                     return false;
 
-                state.increment();
+                writer.incrementState();
 
         }
 

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/e63ce523/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/GridCacheOptimisticCheckPreparedTxRequest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/GridCacheOptimisticCheckPreparedTxRequest.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/GridCacheOptimisticCheckPreparedTxRequest.java
index 888d270..8b30254 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/GridCacheOptimisticCheckPreparedTxRequest.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/GridCacheOptimisticCheckPreparedTxRequest.java
@@ -130,51 +130,49 @@ public class GridCacheOptimisticCheckPreparedTxRequest<K, V> extends GridDistrib
 
     /** {@inheritDoc} */
     @SuppressWarnings("all")
-    @Override public boolean writeTo(ByteBuffer buf, MessageWriteState state) {
-        MessageWriter writer = state.writer();
-
+    @Override public boolean writeTo(ByteBuffer buf, MessageWriter writer) {
         writer.setBuffer(buf);
 
-        if (!super.writeTo(buf, state))
+        if (!super.writeTo(buf, writer))
             return false;
 
-        if (!state.isTypeWritten()) {
+        if (!writer.isTypeWritten()) {
             if (!writer.writeByte(null, directType()))
                 return false;
 
-            state.setTypeWritten();
+            writer.onTypeWritten();
         }
 
-        switch (state.index()) {
+        switch (writer.state()) {
             case 8:
                 if (!writer.writeIgniteUuid("futId", futId))
                     return false;
 
-                state.increment();
+                writer.incrementState();
 
             case 9:
                 if (!writer.writeIgniteUuid("miniId", miniId))
                     return false;
 
-                state.increment();
+                writer.incrementState();
 
             case 10:
                 if (!writer.writeMessage("nearXidVer", nearXidVer))
                     return false;
 
-                state.increment();
+                writer.incrementState();
 
             case 11:
                 if (!writer.writeBoolean("sys", sys))
                     return false;
 
-                state.increment();
+                writer.incrementState();
 
             case 12:
                 if (!writer.writeInt("txNum", txNum))
                     return false;
 
-                state.increment();
+                writer.incrementState();
 
         }
 

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/e63ce523/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/GridCacheOptimisticCheckPreparedTxResponse.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/GridCacheOptimisticCheckPreparedTxResponse.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/GridCacheOptimisticCheckPreparedTxResponse.java
index 94991d6..24a099a 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/GridCacheOptimisticCheckPreparedTxResponse.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/GridCacheOptimisticCheckPreparedTxResponse.java
@@ -103,39 +103,37 @@ public class GridCacheOptimisticCheckPreparedTxResponse<K, V> extends GridDistri
 
     /** {@inheritDoc} */
     @SuppressWarnings("all")
-    @Override public boolean writeTo(ByteBuffer buf, MessageWriteState state) {
-        MessageWriter writer = state.writer();
-
+    @Override public boolean writeTo(ByteBuffer buf, MessageWriter writer) {
         writer.setBuffer(buf);
 
-        if (!super.writeTo(buf, state))
+        if (!super.writeTo(buf, writer))
             return false;
 
-        if (!state.isTypeWritten()) {
+        if (!writer.isTypeWritten()) {
             if (!writer.writeByte(null, directType()))
                 return false;
 
-            state.setTypeWritten();
+            writer.onTypeWritten();
         }
 
-        switch (state.index()) {
+        switch (writer.state()) {
             case 8:
                 if (!writer.writeIgniteUuid("futId", futId))
                     return false;
 
-                state.increment();
+                writer.incrementState();
 
             case 9:
                 if (!writer.writeIgniteUuid("miniId", miniId))
                     return false;
 
-                state.increment();
+                writer.incrementState();
 
             case 10:
                 if (!writer.writeBoolean("success", success))
                     return false;
 
-                state.increment();
+                writer.incrementState();
 
         }
 

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/e63ce523/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/GridCachePessimisticCheckCommittedTxRequest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/GridCachePessimisticCheckCommittedTxRequest.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/GridCachePessimisticCheckCommittedTxRequest.java
index 0869c73..9d920ba 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/GridCachePessimisticCheckCommittedTxRequest.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/GridCachePessimisticCheckCommittedTxRequest.java
@@ -162,63 +162,61 @@ public class GridCachePessimisticCheckCommittedTxRequest<K, V> extends GridDistr
 
     /** {@inheritDoc} */
     @SuppressWarnings("all")
-    @Override public boolean writeTo(ByteBuffer buf, MessageWriteState state) {
-        MessageWriter writer = state.writer();
-
+    @Override public boolean writeTo(ByteBuffer buf, MessageWriter writer) {
         writer.setBuffer(buf);
 
-        if (!super.writeTo(buf, state))
+        if (!super.writeTo(buf, writer))
             return false;
 
-        if (!state.isTypeWritten()) {
+        if (!writer.isTypeWritten()) {
             if (!writer.writeByte(null, directType()))
                 return false;
 
-            state.setTypeWritten();
+            writer.onTypeWritten();
         }
 
-        switch (state.index()) {
+        switch (writer.state()) {
             case 8:
                 if (!writer.writeIgniteUuid("futId", futId))
                     return false;
 
-                state.increment();
+                writer.incrementState();
 
             case 9:
                 if (!writer.writeIgniteUuid("miniId", miniId))
                     return false;
 
-                state.increment();
+                writer.incrementState();
 
             case 10:
                 if (!writer.writeBoolean("nearOnlyCheck", nearOnlyCheck))
                     return false;
 
-                state.increment();
+                writer.incrementState();
 
             case 11:
                 if (!writer.writeMessage("nearXidVer", nearXidVer))
                     return false;
 
-                state.increment();
+                writer.incrementState();
 
             case 12:
                 if (!writer.writeUuid("originatingNodeId", originatingNodeId))
                     return false;
 
-                state.increment();
+                writer.incrementState();
 
             case 13:
                 if (!writer.writeLong("originatingThreadId", originatingThreadId))
                     return false;
 
-                state.increment();
+                writer.incrementState();
 
             case 14:
                 if (!writer.writeBoolean("sys", sys))
                     return false;
 
-                state.increment();
+                writer.incrementState();
 
         }
 

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/e63ce523/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/GridCachePessimisticCheckCommittedTxResponse.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/GridCachePessimisticCheckCommittedTxResponse.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/GridCachePessimisticCheckCommittedTxResponse.java
index 594acb8..bfe1b12 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/GridCachePessimisticCheckCommittedTxResponse.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/GridCachePessimisticCheckCommittedTxResponse.java
@@ -148,45 +148,43 @@ public class GridCachePessimisticCheckCommittedTxResponse<K, V> extends GridDist
 
     /** {@inheritDoc} */
     @SuppressWarnings("all")
-    @Override public boolean writeTo(ByteBuffer buf, MessageWriteState state) {
-        MessageWriter writer = state.writer();
-
+    @Override public boolean writeTo(ByteBuffer buf, MessageWriter writer) {
         writer.setBuffer(buf);
 
-        if (!super.writeTo(buf, state))
+        if (!super.writeTo(buf, writer))
             return false;
 
-        if (!state.isTypeWritten()) {
+        if (!writer.isTypeWritten()) {
             if (!writer.writeByte(null, directType()))
                 return false;
 
-            state.setTypeWritten();
+            writer.onTypeWritten();
         }
 
-        switch (state.index()) {
+        switch (writer.state()) {
             case 8:
                 if (!writer.writeByteArray("committedTxInfoBytes", committedTxInfoBytes))
                     return false;
 
-                state.increment();
+                writer.incrementState();
 
             case 9:
                 if (!writer.writeIgniteUuid("futId", futId))
                     return false;
 
-                state.increment();
+                writer.incrementState();
 
             case 10:
                 if (!writer.writeIgniteUuid("miniId", miniId))
                     return false;
 
-                state.increment();
+                writer.incrementState();
 
             case 11:
                 if (!writer.writeBoolean("sys", sys))
                     return false;
 
-                state.increment();
+                writer.incrementState();
 
         }
 

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/e63ce523/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/GridCacheTtlUpdateRequest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/GridCacheTtlUpdateRequest.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/GridCacheTtlUpdateRequest.java
index 078f014..69b929e 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/GridCacheTtlUpdateRequest.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/GridCacheTtlUpdateRequest.java
@@ -193,57 +193,55 @@ public class GridCacheTtlUpdateRequest<K, V> extends GridCacheMessage<K, V> {
     }
 
     /** {@inheritDoc} */
-    @Override public boolean writeTo(ByteBuffer buf, MessageWriteState state) {
-        MessageWriter writer = state.writer();
-
+    @Override public boolean writeTo(ByteBuffer buf, MessageWriter writer) {
         writer.setBuffer(buf);
 
-        if (!super.writeTo(buf, state))
+        if (!super.writeTo(buf, writer))
             return false;
 
-        if (!state.isTypeWritten()) {
+        if (!writer.isTypeWritten()) {
             if (!writer.writeByte(null, directType()))
                 return false;
 
-            state.setTypeWritten();
+            writer.onTypeWritten();
         }
 
-        switch (state.index()) {
+        switch (writer.state()) {
             case 3:
                 if (!writer.writeCollection("keysBytes", keysBytes, Type.BYTE_ARR))
                     return false;
 
-                state.increment();
+                writer.incrementState();
 
             case 4:
                 if (!writer.writeCollection("nearKeysBytes", nearKeysBytes, Type.BYTE_ARR))
                     return false;
 
-                state.increment();
+                writer.incrementState();
 
             case 5:
                 if (!writer.writeCollection("nearVers", nearVers, Type.MSG))
                     return false;
 
-                state.increment();
+                writer.incrementState();
 
             case 6:
                 if (!writer.writeLong("topVer", topVer))
                     return false;
 
-                state.increment();
+                writer.incrementState();
 
             case 7:
                 if (!writer.writeLong("ttl", ttl))
                     return false;
 
-                state.increment();
+                writer.incrementState();
 
             case 8:
                 if (!writer.writeCollection("vers", vers, Type.MSG))
                     return false;
 
-                state.increment();
+                writer.incrementState();
 
         }
 

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/e63ce523/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/GridDistributedBaseMessage.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/GridDistributedBaseMessage.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/GridDistributedBaseMessage.java
index b33bc40..158ff03 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/GridDistributedBaseMessage.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/GridDistributedBaseMessage.java
@@ -257,51 +257,49 @@ public abstract class GridDistributedBaseMessage<K, V> extends GridCacheMessage<
 
     /** {@inheritDoc} */
     @SuppressWarnings("all")
-    @Override public boolean writeTo(ByteBuffer buf, MessageWriteState state) {
-        MessageWriter writer = state.writer();
-
+    @Override public boolean writeTo(ByteBuffer buf, MessageWriter writer) {
         writer.setBuffer(buf);
 
-        if (!super.writeTo(buf, state))
+        if (!super.writeTo(buf, writer))
             return false;
 
-        if (!state.isTypeWritten()) {
+        if (!writer.isTypeWritten()) {
             if (!writer.writeByte(null, directType()))
                 return false;
 
-            state.setTypeWritten();
+            writer.onTypeWritten();
         }
 
-        switch (state.index()) {
+        switch (writer.state()) {
             case 3:
                 if (!writer.writeByteArray("candsByIdxBytes", candsByIdxBytes))
                     return false;
 
-                state.increment();
+                writer.incrementState();
 
             case 4:
                 if (!writer.writeByteArray("candsByKeyBytes", candsByKeyBytes))
                     return false;
 
-                state.increment();
+                writer.incrementState();
 
             case 5:
                 if (!writer.writeCollection("committedVers", committedVers, Type.MSG))
                     return false;
 
-                state.increment();
+                writer.incrementState();
 
             case 6:
                 if (!writer.writeCollection("rolledbackVers", rolledbackVers, Type.MSG))
                     return false;
 
-                state.increment();
+                writer.incrementState();
 
             case 7:
                 if (!writer.writeMessage("ver", ver))
                     return false;
 
-                state.increment();
+                writer.incrementState();
 
         }
 

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/e63ce523/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/GridDistributedLockRequest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/GridDistributedLockRequest.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/GridDistributedLockRequest.java
index c39f571..6d4d6f6 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/GridDistributedLockRequest.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/GridDistributedLockRequest.java
@@ -462,117 +462,115 @@ public class GridDistributedLockRequest<K, V> extends GridDistributedBaseMessage
 
     /** {@inheritDoc} */
     @SuppressWarnings("all")
-    @Override public boolean writeTo(ByteBuffer buf, MessageWriteState state) {
-        MessageWriter writer = state.writer();
-
+    @Override public boolean writeTo(ByteBuffer buf, MessageWriter writer) {
         writer.setBuffer(buf);
 
-        if (!super.writeTo(buf, state))
+        if (!super.writeTo(buf, writer))
             return false;
 
-        if (!state.isTypeWritten()) {
+        if (!writer.isTypeWritten()) {
             if (!writer.writeByte(null, directType()))
                 return false;
 
-            state.setTypeWritten();
+            writer.onTypeWritten();
         }
 
-        switch (state.index()) {
+        switch (writer.state()) {
             case 8:
                 if (!writer.writeObjectArray("drVersByIdx", drVersByIdx, Type.MSG))
                     return false;
 
-                state.increment();
+                writer.incrementState();
 
             case 9:
                 if (!writer.writeIgniteUuid("futId", futId))
                     return false;
 
-                state.increment();
+                writer.incrementState();
 
             case 10:
                 if (!writer.writeByteArray("grpLockKeyBytes", grpLockKeyBytes))
                     return false;
 
-                state.increment();
+                writer.incrementState();
 
             case 11:
                 if (!writer.writeBoolean("isInTx", isInTx))
                     return false;
 
-                state.increment();
+                writer.incrementState();
 
             case 12:
                 if (!writer.writeBoolean("isInvalidate", isInvalidate))
                     return false;
 
-                state.increment();
+                writer.incrementState();
 
             case 13:
                 if (!writer.writeBoolean("isRead", isRead))
                     return false;
 
-                state.increment();
+                writer.incrementState();
 
             case 14:
                 if (!writer.writeByte("isolation", isolation != null ? (byte)isolation.ordinal() : -1))
                     return false;
 
-                state.increment();
+                writer.incrementState();
 
             case 15:
                 if (!writer.writeCollection("keyBytes", keyBytes, Type.BYTE_ARR))
                     return false;
 
-                state.increment();
+                writer.incrementState();
 
             case 16:
                 if (!writer.writeMessage("nearXidVer", nearXidVer))
                     return false;
 
-                state.increment();
+                writer.incrementState();
 
             case 17:
                 if (!writer.writeUuid("nodeId", nodeId))
                     return false;
 
-                state.increment();
+                writer.incrementState();
 
             case 18:
                 if (!writer.writeBoolean("partLock", partLock))
                     return false;
 
-                state.increment();
+                writer.incrementState();
 
             case 19:
                 if (!writer.writeBooleanArray("retVals", retVals))
                     return false;
 
-                state.increment();
+                writer.incrementState();
 
             case 20:
                 if (!writer.writeLong("threadId", threadId))
                     return false;
 
-                state.increment();
+                writer.incrementState();
 
             case 21:
                 if (!writer.writeLong("timeout", timeout))
                     return false;
 
-                state.increment();
+                writer.incrementState();
 
             case 22:
                 if (!writer.writeInt("txSize", txSize))
                     return false;
 
-                state.increment();
+                writer.incrementState();
 
             case 23:
                 if (!writer.writeByteArray("writeEntriesBytes", writeEntriesBytes))
                     return false;
 
-                state.increment();
+                writer.incrementState();
 
         }
 


Mime
View raw message