ignite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From vkuliche...@apache.org
Subject [05/50] [abbrv] incubator-ignite git commit: ignite-nio - Removing message clone
Date Sun, 15 Feb 2015 08:41:47 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/947723c9
Tree: http://git-wip-us.apache.org/repos/asf/incubator-ignite/tree/947723c9
Diff: http://git-wip-us.apache.org/repos/asf/incubator-ignite/diff/947723c9

Branch: refs/heads/sprint-1
Commit: 947723c92df8d430675f04f00762b1d8f0261682
Parents: 82bca8e
Author: Valentin Kulichenko <vkulichenko@gridgain.com>
Authored: Fri Feb 13 19:34:24 2015 -0800
Committer: Valentin Kulichenko <vkulichenko@gridgain.com>
Committed: Fri Feb 13 19:34:24 2015 -0800

----------------------------------------------------------------------
 .../CommunicationMessageCodeGenerator.java      |  14 +-
 .../ignite/internal/GridJobCancelRequest.java   |  29 ++--
 .../ignite/internal/GridJobExecuteRequest.java  | 101 +++++++-------
 .../ignite/internal/GridJobExecuteResponse.java |  45 +++---
 .../ignite/internal/GridJobSiblingsRequest.java |  25 ++--
 .../internal/GridJobSiblingsResponse.java       |  21 ++-
 .../ignite/internal/GridTaskCancelRequest.java  |  21 ++-
 .../ignite/internal/GridTaskSessionRequest.java |  29 ++--
 .../checkpoint/GridCheckpointRequest.java       |  29 ++--
 .../managers/communication/GridIoMessage.java   |  45 +++---
 .../communication/GridIoUserMessage.java        |  45 +++---
 .../deployment/GridDeploymentInfoBean.java      |  37 +++--
 .../deployment/GridDeploymentRequest.java       |  37 +++--
 .../deployment/GridDeploymentResponse.java      |  29 ++--
 .../eventstorage/GridEventStorageMessage.java   |  53 ++++---
 .../cache/GridCacheEvictionRequest.java         |  29 ++--
 .../cache/GridCacheEvictionResponse.java        |  29 ++--
 .../processors/cache/GridCacheMessage.java      |  23 ++--
 .../processors/cache/GridCacheValueBytes.java   |  25 ++--
 ...idCacheOptimisticCheckPreparedTxRequest.java |  37 +++--
 ...dCacheOptimisticCheckPreparedTxResponse.java |  29 ++--
 ...CachePessimisticCheckCommittedTxRequest.java |  45 +++---
 ...achePessimisticCheckCommittedTxResponse.java |  33 +++--
 .../distributed/GridCacheTtlUpdateRequest.java  |  41 +++---
 .../distributed/GridDistributedBaseMessage.java |  31 +++--
 .../distributed/GridDistributedLockRequest.java |  81 ++++++-----
 .../GridDistributedLockResponse.java            |  29 ++--
 .../GridDistributedTxFinishRequest.java         |  69 +++++-----
 .../GridDistributedTxFinishResponse.java        |  25 ++--
 .../GridDistributedTxPrepareRequest.java        |  73 +++++-----
 .../GridDistributedTxPrepareResponse.java       |  25 ++--
 .../GridDistributedUnlockRequest.java           |  21 ++-
 .../dht/GridDhtAffinityAssignmentRequest.java   |  21 ++-
 .../dht/GridDhtAffinityAssignmentResponse.java  |  25 ++--
 .../distributed/dht/GridDhtLockRequest.java     |  53 ++++---
 .../distributed/dht/GridDhtLockResponse.java    |  33 +++--
 .../distributed/dht/GridDhtTxFinishRequest.java |  69 +++++-----
 .../dht/GridDhtTxFinishResponse.java            |  21 ++-
 .../dht/GridDhtTxPrepareRequest.java            |  65 +++++----
 .../dht/GridDhtTxPrepareResponse.java           |  37 +++--
 .../distributed/dht/GridDhtUnlockRequest.java   |  21 ++-
 .../GridDhtAtomicDeferredUpdateResponse.java    |  21 ++-
 .../dht/atomic/GridDhtAtomicUpdateRequest.java  |  97 +++++++------
 .../dht/atomic/GridDhtAtomicUpdateResponse.java |  33 +++--
 .../dht/atomic/GridNearAtomicUpdateRequest.java |  93 +++++++------
 .../atomic/GridNearAtomicUpdateResponse.java    |  61 ++++----
 .../dht/preloader/GridDhtForceKeysRequest.java  |  33 +++--
 .../dht/preloader/GridDhtForceKeysResponse.java |  33 +++--
 .../GridDhtPartitionDemandMessage.java          |  41 +++---
 .../preloader/GridDhtPartitionExchangeId.java   |  29 ++--
 .../GridDhtPartitionSupplyMessage.java          |  41 +++---
 .../GridDhtPartitionsAbstractMessage.java       |  19 +--
 .../preloader/GridDhtPartitionsFullMessage.java |  25 ++--
 .../GridDhtPartitionsSingleMessage.java         |  21 ++-
 .../GridDhtPartitionsSingleRequest.java         |  13 +-
 .../distributed/near/GridNearGetRequest.java    |  61 ++++----
 .../distributed/near/GridNearGetResponse.java   |  45 +++---
 .../distributed/near/GridNearLockRequest.java   |  65 +++++----
 .../distributed/near/GridNearLockResponse.java  |  37 +++--
 .../near/GridNearTxFinishRequest.java           |  41 +++---
 .../near/GridNearTxFinishResponse.java          |  29 ++--
 .../near/GridNearTxPrepareRequest.java          |  49 ++++---
 .../near/GridNearTxPrepareResponse.java         |  41 +++---
 .../distributed/near/GridNearUnlockRequest.java |  13 +-
 .../cache/query/GridCacheQueryRequest.java      |  93 +++++++------
 .../cache/query/GridCacheQueryResponse.java     |  41 +++---
 .../cache/version/GridCacheVersion.java         |  33 +++--
 .../clock/GridClockDeltaSnapshotMessage.java    |  25 ++--
 .../processors/clock/GridClockDeltaVersion.java |  25 ++--
 .../continuous/GridContinuousMessage.java       |  33 +++--
 .../dataload/GridDataLoadRequest.java           |  69 +++++-----
 .../dataload/GridDataLoadResponse.java          |  29 ++--
 .../processors/igfs/IgfsAckMessage.java         |  29 ++--
 .../internal/processors/igfs/IgfsBlockKey.java  |  33 +++--
 .../processors/igfs/IgfsBlocksMessage.java      |  29 ++--
 .../igfs/IgfsCommunicationMessage.java          |   7 +-
 .../processors/igfs/IgfsDeleteMessage.java      |  25 ++--
 .../processors/igfs/IgfsFileAffinityRange.java  |  37 +++--
 .../igfs/IgfsFragmentizerRequest.java           |  25 ++--
 .../igfs/IgfsFragmentizerResponse.java          |  21 ++-
 .../processors/igfs/IgfsSyncMessage.java        |  25 ++--
 .../handlers/task/GridTaskResultRequest.java    |  25 ++--
 .../handlers/task/GridTaskResultResponse.java   |  33 +++--
 .../streamer/GridStreamerCancelRequest.java     |  21 ++-
 .../streamer/GridStreamerExecutionRequest.java  |  45 +++---
 .../streamer/GridStreamerResponse.java          |  25 ++--
 .../ignite/internal/util/GridByteArrayList.java |  25 ++--
 .../ignite/internal/util/GridLongList.java      |  25 ++--
 .../ignite/internal/util/nio/GridNioServer.java |   2 +-
 .../communication/MessageAdapter.java           |  18 ---
 .../jobstealing/JobStealingRequest.java         |  21 ++-
 .../GridCommunicationSendMessageSelfTest.java   |   7 +-
 .../spi/communication/GridTestMessage.java      | 138 +++++++++----------
 93 files changed, 1684 insertions(+), 1771 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/947723c9/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 13a50bf..615e187 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
@@ -260,11 +260,13 @@ public class CommunicationMessageCodeGenerator {
         String clsName = cls.getSimpleName();
 
         if (!Modifier.isAbstract(cls.getModifiers())) {
-            clone.add(builder().a(clsName).a(" _clone = new ").a(clsName).a("();").toString());
-            clone.add(EMPTY);
-            clone.add(builder().a("clone0(_clone);").toString());
-            clone.add(EMPTY);
-            clone.add(builder().a("return _clone;").toString());
+            clone.add(builder().a("throw new UnsupportedOperationException();").toString());
+
+//            clone.add(builder().a(clsName).a(" _clone = new ").a(clsName).a("();").toString());
+//            clone.add(EMPTY);
+//            clone.add(builder().a("clone0(_clone);").toString());
+//            clone.add(EMPTY);
+//            clone.add(builder().a("return _clone;").toString());
         }
 
         if (hasSuper) {
@@ -383,7 +385,7 @@ public class CommunicationMessageCodeGenerator {
         }
 
         if (!fields.isEmpty())
-            code.add(builder().a("switch (state.index()) {").toString());
+            code.add(builder().a("switch (").a(write ? "state.index()" : "readState").a(") {").toString());
     }
 
     /**

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/947723c9/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 5cb6a27..7dc9b43 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
@@ -112,11 +112,7 @@ public class GridJobCancelRequest extends MessageAdapter {
     /** {@inheritDoc} */
     @SuppressWarnings({"CloneDoesntCallSuperClone", "CloneCallsConstructors"})
     @Override public MessageAdapter clone() {
-        GridJobCancelRequest _clone = new GridJobCancelRequest();
-
-        clone0(_clone);
-
-        return _clone;
+        throw new UnsupportedOperationException();
     }
 
     /** {@inheritDoc} */
@@ -131,33 +127,36 @@ public class GridJobCancelRequest extends MessageAdapter {
     /** {@inheritDoc} */
     @SuppressWarnings("all")
     @Override public boolean writeTo(ByteBuffer buf) {
+        MessageWriteState state = MessageWriteState.get();
+        MessageWriter writer = state.writer();
+
         writer.setBuffer(buf);
 
-        if (!typeWritten) {
+        if (!state.isTypeWritten()) {
             if (!writer.writeByte(null, directType()))
                 return false;
 
-            typeWritten = true;
+            state.setTypeWritten();
         }
 
-        switch (state) {
+        switch (state.index()) {
             case 0:
                 if (!writer.writeIgniteUuid("jobId", jobId))
                     return false;
 
-                state++;
+                state.increment();
 
             case 1:
                 if (!writer.writeIgniteUuid("sesId", sesId))
                     return false;
 
-                state++;
+                state.increment();
 
             case 2:
                 if (!writer.writeBoolean("sys", sys))
                     return false;
 
-                state++;
+                state.increment();
 
         }
 
@@ -169,14 +168,14 @@ public class GridJobCancelRequest extends MessageAdapter {
     @Override public boolean readFrom(ByteBuffer buf) {
         reader.setBuffer(buf);
 
-        switch (state) {
+        switch (readState) {
             case 0:
                 jobId = reader.readIgniteUuid("jobId");
 
                 if (!reader.isLastRead())
                     return false;
 
-                state++;
+                readState++;
 
             case 1:
                 sesId = reader.readIgniteUuid("sesId");
@@ -184,7 +183,7 @@ public class GridJobCancelRequest extends MessageAdapter {
                 if (!reader.isLastRead())
                     return false;
 
-                state++;
+                readState++;
 
             case 2:
                 sys = reader.readBoolean("sys");
@@ -192,7 +191,7 @@ public class GridJobCancelRequest extends MessageAdapter {
                 if (!reader.isLastRead())
                     return false;
 
-                state++;
+                readState++;
 
         }
 

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/947723c9/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 004b995..2381092 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
@@ -414,11 +414,7 @@ public class GridJobExecuteRequest extends MessageAdapter implements GridTaskMes
     /** {@inheritDoc} */
     @SuppressWarnings({"CloneDoesntCallSuperClone", "CloneCallsConstructors"})
     @Override public MessageAdapter clone() {
-        GridJobExecuteRequest _clone = new GridJobExecuteRequest();
-
-        clone0(_clone);
-
-        return _clone;
+        throw new UnsupportedOperationException();
     }
 
     /** {@inheritDoc} */
@@ -456,141 +452,144 @@ public class GridJobExecuteRequest extends MessageAdapter implements GridTaskMes
     /** {@inheritDoc} */
     @SuppressWarnings("all")
     @Override public boolean writeTo(ByteBuffer buf) {
+        MessageWriteState state = MessageWriteState.get();
+        MessageWriter writer = state.writer();
+
         writer.setBuffer(buf);
 
-        if (!typeWritten) {
+        if (!state.isTypeWritten()) {
             if (!writer.writeByte(null, directType()))
                 return false;
 
-            typeWritten = true;
+            state.setTypeWritten();
         }
 
-        switch (state) {
+        switch (state.index()) {
             case 0:
                 if (!writer.writeIgniteUuid("clsLdrId", clsLdrId))
                     return false;
 
-                state++;
+                state.increment();
 
             case 1:
                 if (!writer.writeString("cpSpi", cpSpi))
                     return false;
 
-                state++;
+                state.increment();
 
             case 2:
                 if (!writer.writeEnum("depMode", depMode))
                     return false;
 
-                state++;
+                state.increment();
 
             case 3:
                 if (!writer.writeBoolean("dynamicSiblings", dynamicSiblings))
                     return false;
 
-                state++;
+                state.increment();
 
             case 4:
                 if (!writer.writeBoolean("forceLocDep", forceLocDep))
                     return false;
 
-                state++;
+                state.increment();
 
             case 5:
                 if (!writer.writeBoolean("internal", internal))
                     return false;
 
-                state++;
+                state.increment();
 
             case 6:
                 if (!writer.writeByteArray("jobAttrsBytes", jobAttrsBytes))
                     return false;
 
-                state++;
+                state.increment();
 
             case 7:
                 if (!writer.writeByteArray("jobBytes", jobBytes))
                     return false;
 
-                state++;
+                state.increment();
 
             case 8:
                 if (!writer.writeIgniteUuid("jobId", jobId))
                     return false;
 
-                state++;
+                state.increment();
 
             case 9:
                 if (!writer.writeMap("ldrParticipants", ldrParticipants, UUID.class, IgniteUuid.class))
                     return false;
 
-                state++;
+                state.increment();
 
             case 10:
                 if (!writer.writeByteArray("sesAttrsBytes", sesAttrsBytes))
                     return false;
 
-                state++;
+                state.increment();
 
             case 11:
                 if (!writer.writeBoolean("sesFullSup", sesFullSup))
                     return false;
 
-                state++;
+                state.increment();
 
             case 12:
                 if (!writer.writeIgniteUuid("sesId", sesId))
                     return false;
 
-                state++;
+                state.increment();
 
             case 13:
                 if (!writer.writeByteArray("siblingsBytes", siblingsBytes))
                     return false;
 
-                state++;
+                state.increment();
 
             case 14:
                 if (!writer.writeLong("startTaskTime", startTaskTime))
                     return false;
 
-                state++;
+                state.increment();
 
             case 15:
                 if (!writer.writeUuid("subjId", subjId))
                     return false;
 
-                state++;
+                state.increment();
 
             case 16:
                 if (!writer.writeString("taskClsName", taskClsName))
                     return false;
 
-                state++;
+                state.increment();
 
             case 17:
                 if (!writer.writeString("taskName", taskName))
                     return false;
 
-                state++;
+                state.increment();
 
             case 18:
                 if (!writer.writeLong("timeout", timeout))
                     return false;
 
-                state++;
+                state.increment();
 
             case 19:
                 if (!writer.writeCollection("top", top, UUID.class))
                     return false;
 
-                state++;
+                state.increment();
 
             case 20:
                 if (!writer.writeString("userVer", userVer))
                     return false;
 
-                state++;
+                state.increment();
 
         }
 
@@ -602,14 +601,14 @@ public class GridJobExecuteRequest extends MessageAdapter implements GridTaskMes
     @Override public boolean readFrom(ByteBuffer buf) {
         reader.setBuffer(buf);
 
-        switch (state) {
+        switch (readState) {
             case 0:
                 clsLdrId = reader.readIgniteUuid("clsLdrId");
 
                 if (!reader.isLastRead())
                     return false;
 
-                state++;
+                readState++;
 
             case 1:
                 cpSpi = reader.readString("cpSpi");
@@ -617,7 +616,7 @@ public class GridJobExecuteRequest extends MessageAdapter implements GridTaskMes
                 if (!reader.isLastRead())
                     return false;
 
-                state++;
+                readState++;
 
             case 2:
                 depMode = reader.readEnum("depMode", DeploymentMode.class);
@@ -625,7 +624,7 @@ public class GridJobExecuteRequest extends MessageAdapter implements GridTaskMes
                 if (!reader.isLastRead())
                     return false;
 
-                state++;
+                readState++;
 
             case 3:
                 dynamicSiblings = reader.readBoolean("dynamicSiblings");
@@ -633,7 +632,7 @@ public class GridJobExecuteRequest extends MessageAdapter implements GridTaskMes
                 if (!reader.isLastRead())
                     return false;
 
-                state++;
+                readState++;
 
             case 4:
                 forceLocDep = reader.readBoolean("forceLocDep");
@@ -641,7 +640,7 @@ public class GridJobExecuteRequest extends MessageAdapter implements GridTaskMes
                 if (!reader.isLastRead())
                     return false;
 
-                state++;
+                readState++;
 
             case 5:
                 internal = reader.readBoolean("internal");
@@ -649,7 +648,7 @@ public class GridJobExecuteRequest extends MessageAdapter implements GridTaskMes
                 if (!reader.isLastRead())
                     return false;
 
-                state++;
+                readState++;
 
             case 6:
                 jobAttrsBytes = reader.readByteArray("jobAttrsBytes");
@@ -657,7 +656,7 @@ public class GridJobExecuteRequest extends MessageAdapter implements GridTaskMes
                 if (!reader.isLastRead())
                     return false;
 
-                state++;
+                readState++;
 
             case 7:
                 jobBytes = reader.readByteArray("jobBytes");
@@ -665,7 +664,7 @@ public class GridJobExecuteRequest extends MessageAdapter implements GridTaskMes
                 if (!reader.isLastRead())
                     return false;
 
-                state++;
+                readState++;
 
             case 8:
                 jobId = reader.readIgniteUuid("jobId");
@@ -673,7 +672,7 @@ public class GridJobExecuteRequest extends MessageAdapter implements GridTaskMes
                 if (!reader.isLastRead())
                     return false;
 
-                state++;
+                readState++;
 
             case 9:
                 ldrParticipants = reader.readMap("ldrParticipants", UUID.class, IgniteUuid.class, false);
@@ -681,7 +680,7 @@ public class GridJobExecuteRequest extends MessageAdapter implements GridTaskMes
                 if (!reader.isLastRead())
                     return false;
 
-                state++;
+                readState++;
 
             case 10:
                 sesAttrsBytes = reader.readByteArray("sesAttrsBytes");
@@ -689,7 +688,7 @@ public class GridJobExecuteRequest extends MessageAdapter implements GridTaskMes
                 if (!reader.isLastRead())
                     return false;
 
-                state++;
+                readState++;
 
             case 11:
                 sesFullSup = reader.readBoolean("sesFullSup");
@@ -697,7 +696,7 @@ public class GridJobExecuteRequest extends MessageAdapter implements GridTaskMes
                 if (!reader.isLastRead())
                     return false;
 
-                state++;
+                readState++;
 
             case 12:
                 sesId = reader.readIgniteUuid("sesId");
@@ -705,7 +704,7 @@ public class GridJobExecuteRequest extends MessageAdapter implements GridTaskMes
                 if (!reader.isLastRead())
                     return false;
 
-                state++;
+                readState++;
 
             case 13:
                 siblingsBytes = reader.readByteArray("siblingsBytes");
@@ -713,7 +712,7 @@ public class GridJobExecuteRequest extends MessageAdapter implements GridTaskMes
                 if (!reader.isLastRead())
                     return false;
 
-                state++;
+                readState++;
 
             case 14:
                 startTaskTime = reader.readLong("startTaskTime");
@@ -721,7 +720,7 @@ public class GridJobExecuteRequest extends MessageAdapter implements GridTaskMes
                 if (!reader.isLastRead())
                     return false;
 
-                state++;
+                readState++;
 
             case 15:
                 subjId = reader.readUuid("subjId");
@@ -729,7 +728,7 @@ public class GridJobExecuteRequest extends MessageAdapter implements GridTaskMes
                 if (!reader.isLastRead())
                     return false;
 
-                state++;
+                readState++;
 
             case 16:
                 taskClsName = reader.readString("taskClsName");
@@ -737,7 +736,7 @@ public class GridJobExecuteRequest extends MessageAdapter implements GridTaskMes
                 if (!reader.isLastRead())
                     return false;
 
-                state++;
+                readState++;
 
             case 17:
                 taskName = reader.readString("taskName");
@@ -745,7 +744,7 @@ public class GridJobExecuteRequest extends MessageAdapter implements GridTaskMes
                 if (!reader.isLastRead())
                     return false;
 
-                state++;
+                readState++;
 
             case 18:
                 timeout = reader.readLong("timeout");
@@ -753,7 +752,7 @@ public class GridJobExecuteRequest extends MessageAdapter implements GridTaskMes
                 if (!reader.isLastRead())
                     return false;
 
-                state++;
+                readState++;
 
             case 19:
                 top = reader.readCollection("top", UUID.class);
@@ -761,7 +760,7 @@ public class GridJobExecuteRequest extends MessageAdapter implements GridTaskMes
                 if (!reader.isLastRead())
                     return false;
 
-                state++;
+                readState++;
 
             case 20:
                 userVer = reader.readString("userVer");
@@ -769,7 +768,7 @@ public class GridJobExecuteRequest extends MessageAdapter implements GridTaskMes
                 if (!reader.isLastRead())
                     return false;
 
-                state++;
+                readState++;
 
         }
 

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/947723c9/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 3c3352a..933bde6 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
@@ -207,11 +207,7 @@ public class GridJobExecuteResponse extends MessageAdapter implements GridTaskMe
     /** {@inheritDoc} */
     @SuppressWarnings({"CloneDoesntCallSuperClone", "CloneCallsConstructors"})
     @Override public MessageAdapter clone() {
-        GridJobExecuteResponse _clone = new GridJobExecuteResponse();
-
-        clone0(_clone);
-
-        return _clone;
+        throw new UnsupportedOperationException();
     }
 
     /** {@inheritDoc} */
@@ -234,57 +230,60 @@ public class GridJobExecuteResponse extends MessageAdapter implements GridTaskMe
     /** {@inheritDoc} */
     @SuppressWarnings("all")
     @Override public boolean writeTo(ByteBuffer buf) {
+        MessageWriteState state = MessageWriteState.get();
+        MessageWriter writer = state.writer();
+
         writer.setBuffer(buf);
 
-        if (!typeWritten) {
+        if (!state.isTypeWritten()) {
             if (!writer.writeByte(null, directType()))
                 return false;
 
-            typeWritten = true;
+            state.setTypeWritten();
         }
 
-        switch (state) {
+        switch (state.index()) {
             case 0:
                 if (!writer.writeByteArray("gridExBytes", gridExBytes))
                     return false;
 
-                state++;
+                state.increment();
 
             case 1:
                 if (!writer.writeBoolean("isCancelled", isCancelled))
                     return false;
 
-                state++;
+                state.increment();
 
             case 2:
                 if (!writer.writeByteArray("jobAttrsBytes", jobAttrsBytes))
                     return false;
 
-                state++;
+                state.increment();
 
             case 3:
                 if (!writer.writeIgniteUuid("jobId", jobId))
                     return false;
 
-                state++;
+                state.increment();
 
             case 4:
                 if (!writer.writeUuid("nodeId", nodeId))
                     return false;
 
-                state++;
+                state.increment();
 
             case 5:
                 if (!writer.writeByteArray("resBytes", resBytes))
                     return false;
 
-                state++;
+                state.increment();
 
             case 6:
                 if (!writer.writeIgniteUuid("sesId", sesId))
                     return false;
 
-                state++;
+                state.increment();
 
         }
 
@@ -296,14 +295,14 @@ public class GridJobExecuteResponse extends MessageAdapter implements GridTaskMe
     @Override public boolean readFrom(ByteBuffer buf) {
         reader.setBuffer(buf);
 
-        switch (state) {
+        switch (readState) {
             case 0:
                 gridExBytes = reader.readByteArray("gridExBytes");
 
                 if (!reader.isLastRead())
                     return false;
 
-                state++;
+                readState++;
 
             case 1:
                 isCancelled = reader.readBoolean("isCancelled");
@@ -311,7 +310,7 @@ public class GridJobExecuteResponse extends MessageAdapter implements GridTaskMe
                 if (!reader.isLastRead())
                     return false;
 
-                state++;
+                readState++;
 
             case 2:
                 jobAttrsBytes = reader.readByteArray("jobAttrsBytes");
@@ -319,7 +318,7 @@ public class GridJobExecuteResponse extends MessageAdapter implements GridTaskMe
                 if (!reader.isLastRead())
                     return false;
 
-                state++;
+                readState++;
 
             case 3:
                 jobId = reader.readIgniteUuid("jobId");
@@ -327,7 +326,7 @@ public class GridJobExecuteResponse extends MessageAdapter implements GridTaskMe
                 if (!reader.isLastRead())
                     return false;
 
-                state++;
+                readState++;
 
             case 4:
                 nodeId = reader.readUuid("nodeId");
@@ -335,7 +334,7 @@ public class GridJobExecuteResponse extends MessageAdapter implements GridTaskMe
                 if (!reader.isLastRead())
                     return false;
 
-                state++;
+                readState++;
 
             case 5:
                 resBytes = reader.readByteArray("resBytes");
@@ -343,7 +342,7 @@ public class GridJobExecuteResponse extends MessageAdapter implements GridTaskMe
                 if (!reader.isLastRead())
                     return false;
 
-                state++;
+                readState++;
 
             case 6:
                 sesId = reader.readIgniteUuid("sesId");
@@ -351,7 +350,7 @@ public class GridJobExecuteResponse extends MessageAdapter implements GridTaskMe
                 if (!reader.isLastRead())
                     return false;
 
-                state++;
+                readState++;
 
         }
 

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/947723c9/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 2fc71d9..b14876a 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
@@ -86,11 +86,7 @@ public class GridJobSiblingsRequest extends MessageAdapter {
     /** {@inheritDoc} */
     @SuppressWarnings({"CloneDoesntCallSuperClone", "CloneCallsConstructors"})
     @Override public MessageAdapter clone() {
-        GridJobSiblingsRequest _clone = new GridJobSiblingsRequest();
-
-        clone0(_clone);
-
-        return _clone;
+        throw new UnsupportedOperationException();
     }
 
     /** {@inheritDoc} */
@@ -105,27 +101,30 @@ public class GridJobSiblingsRequest extends MessageAdapter {
     /** {@inheritDoc} */
     @SuppressWarnings("all")
     @Override public boolean writeTo(ByteBuffer buf) {
+        MessageWriteState state = MessageWriteState.get();
+        MessageWriter writer = state.writer();
+
         writer.setBuffer(buf);
 
-        if (!typeWritten) {
+        if (!state.isTypeWritten()) {
             if (!writer.writeByte(null, directType()))
                 return false;
 
-            typeWritten = true;
+            state.setTypeWritten();
         }
 
-        switch (state) {
+        switch (state.index()) {
             case 0:
                 if (!writer.writeIgniteUuid("sesId", sesId))
                     return false;
 
-                state++;
+                state.increment();
 
             case 1:
                 if (!writer.writeByteArray("topicBytes", topicBytes))
                     return false;
 
-                state++;
+                state.increment();
 
         }
 
@@ -137,14 +136,14 @@ public class GridJobSiblingsRequest extends MessageAdapter {
     @Override public boolean readFrom(ByteBuffer buf) {
         reader.setBuffer(buf);
 
-        switch (state) {
+        switch (readState) {
             case 0:
                 sesId = reader.readIgniteUuid("sesId");
 
                 if (!reader.isLastRead())
                     return false;
 
-                state++;
+                readState++;
 
             case 1:
                 topicBytes = reader.readByteArray("topicBytes");
@@ -152,7 +151,7 @@ public class GridJobSiblingsRequest extends MessageAdapter {
                 if (!reader.isLastRead())
                     return false;
 
-                state++;
+                readState++;
 
         }
 

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/947723c9/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 ffaaa1e..88b8047 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
@@ -79,11 +79,7 @@ public class GridJobSiblingsResponse extends MessageAdapter {
     /** {@inheritDoc} */
     @SuppressWarnings({"CloneDoesntCallSuperClone", "CloneCallsConstructors"})
     @Override public MessageAdapter clone() {
-        GridJobSiblingsResponse _clone = new GridJobSiblingsResponse();
-
-        clone0(_clone);
-
-        return _clone;
+        throw new UnsupportedOperationException();
     }
 
     /** {@inheritDoc} */
@@ -97,21 +93,24 @@ public class GridJobSiblingsResponse extends MessageAdapter {
     /** {@inheritDoc} */
     @SuppressWarnings("all")
     @Override public boolean writeTo(ByteBuffer buf) {
+        MessageWriteState state = MessageWriteState.get();
+        MessageWriter writer = state.writer();
+
         writer.setBuffer(buf);
 
-        if (!typeWritten) {
+        if (!state.isTypeWritten()) {
             if (!writer.writeByte(null, directType()))
                 return false;
 
-            typeWritten = true;
+            state.setTypeWritten();
         }
 
-        switch (state) {
+        switch (state.index()) {
             case 0:
                 if (!writer.writeByteArray("siblingsBytes", siblingsBytes))
                     return false;
 
-                state++;
+                state.increment();
 
         }
 
@@ -123,14 +122,14 @@ public class GridJobSiblingsResponse extends MessageAdapter {
     @Override public boolean readFrom(ByteBuffer buf) {
         reader.setBuffer(buf);
 
-        switch (state) {
+        switch (readState) {
             case 0:
                 siblingsBytes = reader.readByteArray("siblingsBytes");
 
                 if (!reader.isLastRead())
                     return false;
 
-                state++;
+                readState++;
 
         }
 

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/947723c9/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 75ff8ea..5251d0c 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
@@ -63,11 +63,7 @@ public class GridTaskCancelRequest extends MessageAdapter {
     /** {@inheritDoc} */
     @SuppressWarnings({"CloneDoesntCallSuperClone", "CloneCallsConstructors"})
     @Override public MessageAdapter clone() {
-        GridTaskCancelRequest _clone = new GridTaskCancelRequest();
-
-        clone0(_clone);
-
-        return _clone;
+        throw new UnsupportedOperationException();
     }
 
     /** {@inheritDoc} */
@@ -80,21 +76,24 @@ public class GridTaskCancelRequest extends MessageAdapter {
     /** {@inheritDoc} */
     @SuppressWarnings("all")
     @Override public boolean writeTo(ByteBuffer buf) {
+        MessageWriteState state = MessageWriteState.get();
+        MessageWriter writer = state.writer();
+
         writer.setBuffer(buf);
 
-        if (!typeWritten) {
+        if (!state.isTypeWritten()) {
             if (!writer.writeByte(null, directType()))
                 return false;
 
-            typeWritten = true;
+            state.setTypeWritten();
         }
 
-        switch (state) {
+        switch (state.index()) {
             case 0:
                 if (!writer.writeIgniteUuid("sesId", sesId))
                     return false;
 
-                state++;
+                state.increment();
 
         }
 
@@ -106,14 +105,14 @@ public class GridTaskCancelRequest extends MessageAdapter {
     @Override public boolean readFrom(ByteBuffer buf) {
         reader.setBuffer(buf);
 
-        switch (state) {
+        switch (readState) {
             case 0:
                 sesId = reader.readIgniteUuid("sesId");
 
                 if (!reader.isLastRead())
                     return false;
 
-                state++;
+                readState++;
 
         }
 

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/947723c9/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 1f75ee2..b06cb09 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
@@ -100,11 +100,7 @@ public class GridTaskSessionRequest extends MessageAdapter implements GridTaskMe
     /** {@inheritDoc} */
     @SuppressWarnings({"CloneDoesntCallSuperClone", "CloneCallsConstructors"})
     @Override public MessageAdapter clone() {
-        GridTaskSessionRequest _clone = new GridTaskSessionRequest();
-
-        clone0(_clone);
-
-        return _clone;
+        throw new UnsupportedOperationException();
     }
 
     /** {@inheritDoc} */
@@ -120,33 +116,36 @@ public class GridTaskSessionRequest extends MessageAdapter implements GridTaskMe
     /** {@inheritDoc} */
     @SuppressWarnings("all")
     @Override public boolean writeTo(ByteBuffer buf) {
+        MessageWriteState state = MessageWriteState.get();
+        MessageWriter writer = state.writer();
+
         writer.setBuffer(buf);
 
-        if (!typeWritten) {
+        if (!state.isTypeWritten()) {
             if (!writer.writeByte(null, directType()))
                 return false;
 
-            typeWritten = true;
+            state.setTypeWritten();
         }
 
-        switch (state) {
+        switch (state.index()) {
             case 0:
                 if (!writer.writeByteArray("attrsBytes", attrsBytes))
                     return false;
 
-                state++;
+                state.increment();
 
             case 1:
                 if (!writer.writeIgniteUuid("jobId", jobId))
                     return false;
 
-                state++;
+                state.increment();
 
             case 2:
                 if (!writer.writeIgniteUuid("sesId", sesId))
                     return false;
 
-                state++;
+                state.increment();
 
         }
 
@@ -158,14 +157,14 @@ public class GridTaskSessionRequest extends MessageAdapter implements GridTaskMe
     @Override public boolean readFrom(ByteBuffer buf) {
         reader.setBuffer(buf);
 
-        switch (state) {
+        switch (readState) {
             case 0:
                 attrsBytes = reader.readByteArray("attrsBytes");
 
                 if (!reader.isLastRead())
                     return false;
 
-                state++;
+                readState++;
 
             case 1:
                 jobId = reader.readIgniteUuid("jobId");
@@ -173,7 +172,7 @@ public class GridTaskSessionRequest extends MessageAdapter implements GridTaskMe
                 if (!reader.isLastRead())
                     return false;
 
-                state++;
+                readState++;
 
             case 2:
                 sesId = reader.readIgniteUuid("sesId");
@@ -181,7 +180,7 @@ public class GridTaskSessionRequest extends MessageAdapter implements GridTaskMe
                 if (!reader.isLastRead())
                     return false;
 
-                state++;
+                readState++;
 
         }
 

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/947723c9/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 5085a9c..9fa2706 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
@@ -86,11 +86,7 @@ public class GridCheckpointRequest extends MessageAdapter {
     /** {@inheritDoc} */
     @SuppressWarnings({"CloneDoesntCallSuperClone", "CloneCallsConstructors"})
     @Override public MessageAdapter clone() {
-        GridCheckpointRequest _clone = new GridCheckpointRequest();
-
-        clone0(_clone);
-
-        return _clone;
+        throw new UnsupportedOperationException();
     }
 
     /** {@inheritDoc} */
@@ -105,33 +101,36 @@ public class GridCheckpointRequest extends MessageAdapter {
     /** {@inheritDoc} */
     @SuppressWarnings("all")
     @Override public boolean writeTo(ByteBuffer buf) {
+        MessageWriteState state = MessageWriteState.get();
+        MessageWriter writer = state.writer();
+
         writer.setBuffer(buf);
 
-        if (!typeWritten) {
+        if (!state.isTypeWritten()) {
             if (!writer.writeByte(null, directType()))
                 return false;
 
-            typeWritten = true;
+            state.setTypeWritten();
         }
 
-        switch (state) {
+        switch (state.index()) {
             case 0:
                 if (!writer.writeString("cpSpi", cpSpi))
                     return false;
 
-                state++;
+                state.increment();
 
             case 1:
                 if (!writer.writeString("key", key))
                     return false;
 
-                state++;
+                state.increment();
 
             case 2:
                 if (!writer.writeIgniteUuid("sesId", sesId))
                     return false;
 
-                state++;
+                state.increment();
 
         }
 
@@ -143,14 +142,14 @@ public class GridCheckpointRequest extends MessageAdapter {
     @Override public boolean readFrom(ByteBuffer buf) {
         reader.setBuffer(buf);
 
-        switch (state) {
+        switch (readState) {
             case 0:
                 cpSpi = reader.readString("cpSpi");
 
                 if (!reader.isLastRead())
                     return false;
 
-                state++;
+                readState++;
 
             case 1:
                 key = reader.readString("key");
@@ -158,7 +157,7 @@ public class GridCheckpointRequest extends MessageAdapter {
                 if (!reader.isLastRead())
                     return false;
 
-                state++;
+                readState++;
 
             case 2:
                 sesId = reader.readIgniteUuid("sesId");
@@ -166,7 +165,7 @@ public class GridCheckpointRequest extends MessageAdapter {
                 if (!reader.isLastRead())
                     return false;
 
-                state++;
+                readState++;
 
         }
 

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/947723c9/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 c77f174..31b4f96 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
@@ -181,11 +181,7 @@ public class GridIoMessage extends MessageAdapter {
     /** {@inheritDoc} */
     @SuppressWarnings({"CloneDoesntCallSuperClone", "CloneCallsConstructors"})
     @Override public MessageAdapter clone() {
-        GridIoMessage _clone = new GridIoMessage();
-
-        clone0(_clone);
-
-        return _clone;
+        throw new UnsupportedOperationException();
     }
 
     /** {@inheritDoc} */
@@ -206,57 +202,60 @@ public class GridIoMessage extends MessageAdapter {
     /** {@inheritDoc} */
     @SuppressWarnings("all")
     @Override public boolean writeTo(ByteBuffer buf) {
+        MessageWriteState state = MessageWriteState.get();
+        MessageWriter writer = state.writer();
+
         writer.setBuffer(buf);
 
-        if (!typeWritten) {
+        if (!state.isTypeWritten()) {
             if (!writer.writeByte(null, directType()))
                 return false;
 
-            typeWritten = true;
+            state.setTypeWritten();
         }
 
-        switch (state) {
+        switch (state.index()) {
             case 0:
                 if (!writer.writeMessage("msg", msg))
                     return false;
 
-                state++;
+                state.increment();
 
             case 1:
                 if (!writer.writeBoolean("ordered", ordered))
                     return false;
 
-                state++;
+                state.increment();
 
             case 2:
                 if (!writer.writeEnum("plc", plc))
                     return false;
 
-                state++;
+                state.increment();
 
             case 3:
                 if (!writer.writeBoolean("skipOnTimeout", skipOnTimeout))
                     return false;
 
-                state++;
+                state.increment();
 
             case 4:
                 if (!writer.writeLong("timeout", timeout))
                     return false;
 
-                state++;
+                state.increment();
 
             case 5:
                 if (!writer.writeByteArray("topicBytes", topicBytes))
                     return false;
 
-                state++;
+                state.increment();
 
             case 6:
                 if (!writer.writeInt("topicOrd", topicOrd))
                     return false;
 
-                state++;
+                state.increment();
 
         }
 
@@ -268,14 +267,14 @@ public class GridIoMessage extends MessageAdapter {
     @Override public boolean readFrom(ByteBuffer buf) {
         reader.setBuffer(buf);
 
-        switch (state) {
+        switch (readState) {
             case 0:
                 msg = reader.readMessage("msg");
 
                 if (!reader.isLastRead())
                     return false;
 
-                state++;
+                readState++;
 
             case 1:
                 ordered = reader.readBoolean("ordered");
@@ -283,7 +282,7 @@ public class GridIoMessage extends MessageAdapter {
                 if (!reader.isLastRead())
                     return false;
 
-                state++;
+                readState++;
 
             case 2:
                 plc = reader.readEnum("plc", GridIoPolicy.class);
@@ -291,7 +290,7 @@ public class GridIoMessage extends MessageAdapter {
                 if (!reader.isLastRead())
                     return false;
 
-                state++;
+                readState++;
 
             case 3:
                 skipOnTimeout = reader.readBoolean("skipOnTimeout");
@@ -299,7 +298,7 @@ public class GridIoMessage extends MessageAdapter {
                 if (!reader.isLastRead())
                     return false;
 
-                state++;
+                readState++;
 
             case 4:
                 timeout = reader.readLong("timeout");
@@ -307,7 +306,7 @@ public class GridIoMessage extends MessageAdapter {
                 if (!reader.isLastRead())
                     return false;
 
-                state++;
+                readState++;
 
             case 5:
                 topicBytes = reader.readByteArray("topicBytes");
@@ -315,7 +314,7 @@ public class GridIoMessage extends MessageAdapter {
                 if (!reader.isLastRead())
                     return false;
 
-                state++;
+                readState++;
 
             case 6:
                 topicOrd = reader.readInt("topicOrd");
@@ -323,7 +322,7 @@ public class GridIoMessage extends MessageAdapter {
                 if (!reader.isLastRead())
                     return false;
 
-                state++;
+                readState++;
 
         }
 

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/947723c9/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 05ff2df..5a87102 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
@@ -205,11 +205,7 @@ public class GridIoUserMessage extends MessageAdapter {
     /** {@inheritDoc} */
     @SuppressWarnings({"CloneDoesntCallSuperClone", "CloneCallsConstructors"})
     @Override public MessageAdapter clone() {
-        GridIoUserMessage _clone = new GridIoUserMessage();
-
-        clone0(_clone);
-
-        return _clone;
+        throw new UnsupportedOperationException();
     }
 
     /** {@inheritDoc} */
@@ -231,57 +227,60 @@ public class GridIoUserMessage extends MessageAdapter {
     /** {@inheritDoc} */
     @SuppressWarnings("all")
     @Override public boolean writeTo(ByteBuffer buf) {
+        MessageWriteState state = MessageWriteState.get();
+        MessageWriter writer = state.writer();
+
         writer.setBuffer(buf);
 
-        if (!typeWritten) {
+        if (!state.isTypeWritten()) {
             if (!writer.writeByte(null, directType()))
                 return false;
 
-            typeWritten = true;
+            state.setTypeWritten();
         }
 
-        switch (state) {
+        switch (state.index()) {
             case 0:
                 if (!writer.writeByteArray("bodyBytes", bodyBytes))
                     return false;
 
-                state++;
+                state.increment();
 
             case 1:
                 if (!writer.writeIgniteUuid("clsLdrId", clsLdrId))
                     return false;
 
-                state++;
+                state.increment();
 
             case 2:
                 if (!writer.writeString("depClsName", depClsName))
                     return false;
 
-                state++;
+                state.increment();
 
             case 3:
                 if (!writer.writeEnum("depMode", depMode))
                     return false;
 
-                state++;
+                state.increment();
 
             case 4:
                 if (!writer.writeMap("ldrParties", ldrParties, UUID.class, IgniteUuid.class))
                     return false;
 
-                state++;
+                state.increment();
 
             case 5:
                 if (!writer.writeByteArray("topicBytes", topicBytes))
                     return false;
 
-                state++;
+                state.increment();
 
             case 6:
                 if (!writer.writeString("userVer", userVer))
                     return false;
 
-                state++;
+                state.increment();
 
         }
 
@@ -293,14 +292,14 @@ public class GridIoUserMessage extends MessageAdapter {
     @Override public boolean readFrom(ByteBuffer buf) {
         reader.setBuffer(buf);
 
-        switch (state) {
+        switch (readState) {
             case 0:
                 bodyBytes = reader.readByteArray("bodyBytes");
 
                 if (!reader.isLastRead())
                     return false;
 
-                state++;
+                readState++;
 
             case 1:
                 clsLdrId = reader.readIgniteUuid("clsLdrId");
@@ -308,7 +307,7 @@ public class GridIoUserMessage extends MessageAdapter {
                 if (!reader.isLastRead())
                     return false;
 
-                state++;
+                readState++;
 
             case 2:
                 depClsName = reader.readString("depClsName");
@@ -316,7 +315,7 @@ public class GridIoUserMessage extends MessageAdapter {
                 if (!reader.isLastRead())
                     return false;
 
-                state++;
+                readState++;
 
             case 3:
                 depMode = reader.readEnum("depMode", DeploymentMode.class);
@@ -324,7 +323,7 @@ public class GridIoUserMessage extends MessageAdapter {
                 if (!reader.isLastRead())
                     return false;
 
-                state++;
+                readState++;
 
             case 4:
                 ldrParties = reader.readMap("ldrParties", UUID.class, IgniteUuid.class, false);
@@ -332,7 +331,7 @@ public class GridIoUserMessage extends MessageAdapter {
                 if (!reader.isLastRead())
                     return false;
 
-                state++;
+                readState++;
 
             case 5:
                 topicBytes = reader.readByteArray("topicBytes");
@@ -340,7 +339,7 @@ public class GridIoUserMessage extends MessageAdapter {
                 if (!reader.isLastRead())
                     return false;
 
-                state++;
+                readState++;
 
             case 6:
                 userVer = reader.readString("userVer");
@@ -348,7 +347,7 @@ public class GridIoUserMessage extends MessageAdapter {
                 if (!reader.isLastRead())
                     return false;
 
-                state++;
+                readState++;
 
         }
 

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/947723c9/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 a84d049..3310d5f 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
@@ -140,11 +140,7 @@ public class GridDeploymentInfoBean extends MessageAdapter implements GridDeploy
     /** {@inheritDoc} */
     @SuppressWarnings({"CloneDoesntCallSuperClone", "CloneCallsConstructors"})
     @Override public MessageAdapter clone() {
-        GridDeploymentInfoBean _clone = new GridDeploymentInfoBean();
-
-        clone0(_clone);
-
-        return _clone;
+        throw new UnsupportedOperationException();
     }
 
     /** {@inheritDoc} */
@@ -161,45 +157,48 @@ public class GridDeploymentInfoBean extends MessageAdapter implements GridDeploy
     /** {@inheritDoc} */
     @SuppressWarnings("all")
     @Override public boolean writeTo(ByteBuffer buf) {
+        MessageWriteState state = MessageWriteState.get();
+        MessageWriter writer = state.writer();
+
         writer.setBuffer(buf);
 
-        if (!typeWritten) {
+        if (!state.isTypeWritten()) {
             if (!writer.writeByte(null, directType()))
                 return false;
 
-            typeWritten = true;
+            state.setTypeWritten();
         }
 
-        switch (state) {
+        switch (state.index()) {
             case 0:
                 if (!writer.writeIgniteUuid("clsLdrId", clsLdrId))
                     return false;
 
-                state++;
+                state.increment();
 
             case 1:
                 if (!writer.writeEnum("depMode", depMode))
                     return false;
 
-                state++;
+                state.increment();
 
             case 2:
                 if (!writer.writeBoolean("locDepOwner", locDepOwner))
                     return false;
 
-                state++;
+                state.increment();
 
             case 3:
                 if (!writer.writeMap("participants", participants, UUID.class, IgniteUuid.class))
                     return false;
 
-                state++;
+                state.increment();
 
             case 4:
                 if (!writer.writeString("userVer", userVer))
                     return false;
 
-                state++;
+                state.increment();
 
         }
 
@@ -211,14 +210,14 @@ public class GridDeploymentInfoBean extends MessageAdapter implements GridDeploy
     @Override public boolean readFrom(ByteBuffer buf) {
         reader.setBuffer(buf);
 
-        switch (state) {
+        switch (readState) {
             case 0:
                 clsLdrId = reader.readIgniteUuid("clsLdrId");
 
                 if (!reader.isLastRead())
                     return false;
 
-                state++;
+                readState++;
 
             case 1:
                 depMode = reader.readEnum("depMode", DeploymentMode.class);
@@ -226,7 +225,7 @@ public class GridDeploymentInfoBean extends MessageAdapter implements GridDeploy
                 if (!reader.isLastRead())
                     return false;
 
-                state++;
+                readState++;
 
             case 2:
                 locDepOwner = reader.readBoolean("locDepOwner");
@@ -234,7 +233,7 @@ public class GridDeploymentInfoBean extends MessageAdapter implements GridDeploy
                 if (!reader.isLastRead())
                     return false;
 
-                state++;
+                readState++;
 
             case 3:
                 participants = reader.readMap("participants", UUID.class, IgniteUuid.class, false);
@@ -242,7 +241,7 @@ public class GridDeploymentInfoBean extends MessageAdapter implements GridDeploy
                 if (!reader.isLastRead())
                     return false;
 
-                state++;
+                readState++;
 
             case 4:
                 userVer = reader.readString("userVer");
@@ -250,7 +249,7 @@ public class GridDeploymentInfoBean extends MessageAdapter implements GridDeploy
                 if (!reader.isLastRead())
                     return false;
 
-                state++;
+                readState++;
 
         }
 

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/947723c9/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 50d9b24..cdcccb9 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
@@ -158,11 +158,7 @@ public class GridDeploymentRequest extends MessageAdapter {
     /** {@inheritDoc} */
     @SuppressWarnings({"CloneDoesntCallSuperClone", "CloneCallsConstructors"})
     @Override public MessageAdapter clone() {
-        GridDeploymentRequest _clone = new GridDeploymentRequest();
-
-        clone0(_clone);
-
-        return _clone;
+        throw new UnsupportedOperationException();
     }
 
     /** {@inheritDoc} */
@@ -180,45 +176,48 @@ public class GridDeploymentRequest extends MessageAdapter {
     /** {@inheritDoc} */
     @SuppressWarnings("all")
     @Override public boolean writeTo(ByteBuffer buf) {
+        MessageWriteState state = MessageWriteState.get();
+        MessageWriter writer = state.writer();
+
         writer.setBuffer(buf);
 
-        if (!typeWritten) {
+        if (!state.isTypeWritten()) {
             if (!writer.writeByte(null, directType()))
                 return false;
 
-            typeWritten = true;
+            state.setTypeWritten();
         }
 
-        switch (state) {
+        switch (state.index()) {
             case 0:
                 if (!writer.writeBoolean("isUndeploy", isUndeploy))
                     return false;
 
-                state++;
+                state.increment();
 
             case 1:
                 if (!writer.writeIgniteUuid("ldrId", ldrId))
                     return false;
 
-                state++;
+                state.increment();
 
             case 2:
                 if (!writer.writeCollection("nodeIds", nodeIds, UUID.class))
                     return false;
 
-                state++;
+                state.increment();
 
             case 3:
                 if (!writer.writeByteArray("resTopicBytes", resTopicBytes))
                     return false;
 
-                state++;
+                state.increment();
 
             case 4:
                 if (!writer.writeString("rsrcName", rsrcName))
                     return false;
 
-                state++;
+                state.increment();
 
         }
 
@@ -230,14 +229,14 @@ public class GridDeploymentRequest extends MessageAdapter {
     @Override public boolean readFrom(ByteBuffer buf) {
         reader.setBuffer(buf);
 
-        switch (state) {
+        switch (readState) {
             case 0:
                 isUndeploy = reader.readBoolean("isUndeploy");
 
                 if (!reader.isLastRead())
                     return false;
 
-                state++;
+                readState++;
 
             case 1:
                 ldrId = reader.readIgniteUuid("ldrId");
@@ -245,7 +244,7 @@ public class GridDeploymentRequest extends MessageAdapter {
                 if (!reader.isLastRead())
                     return false;
 
-                state++;
+                readState++;
 
             case 2:
                 nodeIds = reader.readCollection("nodeIds", UUID.class);
@@ -253,7 +252,7 @@ public class GridDeploymentRequest extends MessageAdapter {
                 if (!reader.isLastRead())
                     return false;
 
-                state++;
+                readState++;
 
             case 3:
                 resTopicBytes = reader.readByteArray("resTopicBytes");
@@ -261,7 +260,7 @@ public class GridDeploymentRequest extends MessageAdapter {
                 if (!reader.isLastRead())
                     return false;
 
-                state++;
+                readState++;
 
             case 4:
                 rsrcName = reader.readString("rsrcName");
@@ -269,7 +268,7 @@ public class GridDeploymentRequest extends MessageAdapter {
                 if (!reader.isLastRead())
                     return false;
 
-                state++;
+                readState++;
 
         }
 

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/947723c9/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 9c54b84..6414955 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
@@ -108,11 +108,7 @@ public class GridDeploymentResponse extends MessageAdapter {
     /** {@inheritDoc} */
     @SuppressWarnings({"CloneDoesntCallSuperClone", "CloneCallsConstructors"})
     @Override public MessageAdapter clone() {
-        GridDeploymentResponse _clone = new GridDeploymentResponse();
-
-        clone0(_clone);
-
-        return _clone;
+        throw new UnsupportedOperationException();
     }
 
     /** {@inheritDoc} */
@@ -127,33 +123,36 @@ public class GridDeploymentResponse extends MessageAdapter {
     /** {@inheritDoc} */
     @SuppressWarnings("all")
     @Override public boolean writeTo(ByteBuffer buf) {
+        MessageWriteState state = MessageWriteState.get();
+        MessageWriter writer = state.writer();
+
         writer.setBuffer(buf);
 
-        if (!typeWritten) {
+        if (!state.isTypeWritten()) {
             if (!writer.writeByte(null, directType()))
                 return false;
 
-            typeWritten = true;
+            state.setTypeWritten();
         }
 
-        switch (state) {
+        switch (state.index()) {
             case 0:
                 if (!writer.writeMessage("byteSrc", byteSrc))
                     return false;
 
-                state++;
+                state.increment();
 
             case 1:
                 if (!writer.writeString("errMsg", errMsg))
                     return false;
 
-                state++;
+                state.increment();
 
             case 2:
                 if (!writer.writeBoolean("success", success))
                     return false;
 
-                state++;
+                state.increment();
 
         }
 
@@ -165,14 +164,14 @@ public class GridDeploymentResponse extends MessageAdapter {
     @Override public boolean readFrom(ByteBuffer buf) {
         reader.setBuffer(buf);
 
-        switch (state) {
+        switch (readState) {
             case 0:
                 byteSrc = reader.readMessage("byteSrc");
 
                 if (!reader.isLastRead())
                     return false;
 
-                state++;
+                readState++;
 
             case 1:
                 errMsg = reader.readString("errMsg");
@@ -180,7 +179,7 @@ public class GridDeploymentResponse extends MessageAdapter {
                 if (!reader.isLastRead())
                     return false;
 
-                state++;
+                readState++;
 
             case 2:
                 success = reader.readBoolean("success");
@@ -188,7 +187,7 @@ public class GridDeploymentResponse extends MessageAdapter {
                 if (!reader.isLastRead())
                     return false;
 
-                state++;
+                readState++;
 
         }
 

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/947723c9/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 058ac8e..b89e3fe 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
@@ -263,11 +263,7 @@ public class GridEventStorageMessage extends MessageAdapter {
     /** {@inheritDoc} */
     @SuppressWarnings({"CloneDoesntCallSuperClone", "CloneCallsConstructors"})
     @Override public MessageAdapter clone() {
-        GridEventStorageMessage _clone = new GridEventStorageMessage();
-
-        clone0(_clone);
-
-        return _clone;
+        throw new UnsupportedOperationException();
     }
 
     /** {@inheritDoc} */
@@ -291,69 +287,72 @@ public class GridEventStorageMessage extends MessageAdapter {
     /** {@inheritDoc} */
     @SuppressWarnings("all")
     @Override public boolean writeTo(ByteBuffer buf) {
+        MessageWriteState state = MessageWriteState.get();
+        MessageWriter writer = state.writer();
+
         writer.setBuffer(buf);
 
-        if (!typeWritten) {
+        if (!state.isTypeWritten()) {
             if (!writer.writeByte(null, directType()))
                 return false;
 
-            typeWritten = true;
+            state.setTypeWritten();
         }
 
-        switch (state) {
+        switch (state.index()) {
             case 0:
                 if (!writer.writeIgniteUuid("clsLdrId", clsLdrId))
                     return false;
 
-                state++;
+                state.increment();
 
             case 1:
                 if (!writer.writeEnum("depMode", depMode))
                     return false;
 
-                state++;
+                state.increment();
 
             case 2:
                 if (!writer.writeByteArray("evtsBytes", evtsBytes))
                     return false;
 
-                state++;
+                state.increment();
 
             case 3:
                 if (!writer.writeByteArray("exBytes", exBytes))
                     return false;
 
-                state++;
+                state.increment();
 
             case 4:
                 if (!writer.writeByteArray("filter", filter))
                     return false;
 
-                state++;
+                state.increment();
 
             case 5:
                 if (!writer.writeString("filterClsName", filterClsName))
                     return false;
 
-                state++;
+                state.increment();
 
             case 6:
                 if (!writer.writeMap("ldrParties", ldrParties, UUID.class, IgniteUuid.class))
                     return false;
 
-                state++;
+                state.increment();
 
             case 7:
                 if (!writer.writeByteArray("resTopicBytes", resTopicBytes))
                     return false;
 
-                state++;
+                state.increment();
 
             case 8:
                 if (!writer.writeString("userVer", userVer))
                     return false;
 
-                state++;
+                state.increment();
 
         }
 
@@ -365,14 +364,14 @@ public class GridEventStorageMessage extends MessageAdapter {
     @Override public boolean readFrom(ByteBuffer buf) {
         reader.setBuffer(buf);
 
-        switch (state) {
+        switch (readState) {
             case 0:
                 clsLdrId = reader.readIgniteUuid("clsLdrId");
 
                 if (!reader.isLastRead())
                     return false;
 
-                state++;
+                readState++;
 
             case 1:
                 depMode = reader.readEnum("depMode", DeploymentMode.class);
@@ -380,7 +379,7 @@ public class GridEventStorageMessage extends MessageAdapter {
                 if (!reader.isLastRead())
                     return false;
 
-                state++;
+                readState++;
 
             case 2:
                 evtsBytes = reader.readByteArray("evtsBytes");
@@ -388,7 +387,7 @@ public class GridEventStorageMessage extends MessageAdapter {
                 if (!reader.isLastRead())
                     return false;
 
-                state++;
+                readState++;
 
             case 3:
                 exBytes = reader.readByteArray("exBytes");
@@ -396,7 +395,7 @@ public class GridEventStorageMessage extends MessageAdapter {
                 if (!reader.isLastRead())
                     return false;
 
-                state++;
+                readState++;
 
             case 4:
                 filter = reader.readByteArray("filter");
@@ -404,7 +403,7 @@ public class GridEventStorageMessage extends MessageAdapter {
                 if (!reader.isLastRead())
                     return false;
 
-                state++;
+                readState++;
 
             case 5:
                 filterClsName = reader.readString("filterClsName");
@@ -412,7 +411,7 @@ public class GridEventStorageMessage extends MessageAdapter {
                 if (!reader.isLastRead())
                     return false;
 
-                state++;
+                readState++;
 
             case 6:
                 ldrParties = reader.readMap("ldrParties", UUID.class, IgniteUuid.class, false);
@@ -420,7 +419,7 @@ public class GridEventStorageMessage extends MessageAdapter {
                 if (!reader.isLastRead())
                     return false;
 
-                state++;
+                readState++;
 
             case 7:
                 resTopicBytes = reader.readByteArray("resTopicBytes");
@@ -428,7 +427,7 @@ public class GridEventStorageMessage extends MessageAdapter {
                 if (!reader.isLastRead())
                     return false;
 
-                state++;
+                readState++;
 
             case 8:
                 userVer = reader.readString("userVer");
@@ -436,7 +435,7 @@ public class GridEventStorageMessage extends MessageAdapter {
                 if (!reader.isLastRead())
                     return false;
 
-                state++;
+                readState++;
 
         }
 

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/947723c9/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 ce7d4d7..2b487c9 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
@@ -142,11 +142,7 @@ public class GridCacheEvictionRequest<K, V> extends GridCacheMessage<K, V> imple
     /** {@inheritDoc} */
     @SuppressWarnings({"CloneDoesntCallSuperClone", "CloneCallsConstructors"})
     @Override public MessageAdapter clone() {
-        GridCacheEvictionRequest _clone = new GridCacheEvictionRequest();
-
-        clone0(_clone);
-
-        return _clone;
+        throw new UnsupportedOperationException();
     }
 
     /** {@inheritDoc} */
@@ -164,36 +160,39 @@ public class GridCacheEvictionRequest<K, V> extends GridCacheMessage<K, V> imple
     /** {@inheritDoc} */
     @SuppressWarnings("all")
     @Override public boolean writeTo(ByteBuffer buf) {
+        MessageWriteState state = MessageWriteState.get();
+        MessageWriter writer = state.writer();
+
         writer.setBuffer(buf);
 
         if (!super.writeTo(buf))
             return false;
 
-        if (!typeWritten) {
+        if (!state.isTypeWritten()) {
             if (!writer.writeByte(null, directType()))
                 return false;
 
-            typeWritten = true;
+            state.setTypeWritten();
         }
 
-        switch (state) {
+        switch (state.index()) {
             case 3:
                 if (!writer.writeByteArray("entriesBytes", entriesBytes))
                     return false;
 
-                state++;
+                state.increment();
 
             case 4:
                 if (!writer.writeLong("futId", futId))
                     return false;
 
-                state++;
+                state.increment();
 
             case 5:
                 if (!writer.writeLong("topVer", topVer))
                     return false;
 
-                state++;
+                state.increment();
 
         }
 
@@ -208,14 +207,14 @@ public class GridCacheEvictionRequest<K, V> extends GridCacheMessage<K, V> imple
         if (!super.readFrom(buf))
             return false;
 
-        switch (state) {
+        switch (readState) {
             case 3:
                 entriesBytes = reader.readByteArray("entriesBytes");
 
                 if (!reader.isLastRead())
                     return false;
 
-                state++;
+                readState++;
 
             case 4:
                 futId = reader.readLong("futId");
@@ -223,7 +222,7 @@ public class GridCacheEvictionRequest<K, V> extends GridCacheMessage<K, V> imple
                 if (!reader.isLastRead())
                     return false;
 
-                state++;
+                readState++;
 
             case 5:
                 topVer = reader.readLong("topVer");
@@ -231,7 +230,7 @@ public class GridCacheEvictionRequest<K, V> extends GridCacheMessage<K, V> imple
                 if (!reader.isLastRead())
                     return false;
 
-                state++;
+                readState++;
 
         }
 

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/947723c9/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 2687e95..b57e812 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
@@ -131,11 +131,7 @@ public class GridCacheEvictionResponse<K, V> extends GridCacheMessage<K, V> {
     /** {@inheritDoc} */
     @SuppressWarnings({"CloneDoesntCallSuperClone", "CloneCallsConstructors"})
     @Override public MessageAdapter clone() {
-        GridCacheEvictionResponse _clone = new GridCacheEvictionResponse();
-
-        clone0(_clone);
-
-        return _clone;
+        throw new UnsupportedOperationException();
     }
 
     /** {@inheritDoc} */
@@ -153,36 +149,39 @@ public class GridCacheEvictionResponse<K, V> extends GridCacheMessage<K, V> {
     /** {@inheritDoc} */
     @SuppressWarnings("all")
     @Override public boolean writeTo(ByteBuffer buf) {
+        MessageWriteState state = MessageWriteState.get();
+        MessageWriter writer = state.writer();
+
         writer.setBuffer(buf);
 
         if (!super.writeTo(buf))
             return false;
 
-        if (!typeWritten) {
+        if (!state.isTypeWritten()) {
             if (!writer.writeByte(null, directType()))
                 return false;
 
-            typeWritten = true;
+            state.setTypeWritten();
         }
 
-        switch (state) {
+        switch (state.index()) {
             case 3:
                 if (!writer.writeBoolean("err", err))
                     return false;
 
-                state++;
+                state.increment();
 
             case 4:
                 if (!writer.writeLong("futId", futId))
                     return false;
 
-                state++;
+                state.increment();
 
             case 5:
                 if (!writer.writeCollection("rejectedKeyBytes", rejectedKeyBytes, byte[].class))
                     return false;
 
-                state++;
+                state.increment();
 
         }
 
@@ -197,14 +196,14 @@ public class GridCacheEvictionResponse<K, V> extends GridCacheMessage<K, V> {
         if (!super.readFrom(buf))
             return false;
 
-        switch (state) {
+        switch (readState) {
             case 3:
                 err = reader.readBoolean("err");
 
                 if (!reader.isLastRead())
                     return false;
 
-                state++;
+                readState++;
 
             case 4:
                 futId = reader.readLong("futId");
@@ -212,7 +211,7 @@ public class GridCacheEvictionResponse<K, V> extends GridCacheMessage<K, V> {
                 if (!reader.isLastRead())
                     return false;
 
-                state++;
+                readState++;
 
             case 5:
                 rejectedKeyBytes = reader.readCollection("rejectedKeyBytes", byte[].class);
@@ -220,7 +219,7 @@ public class GridCacheEvictionResponse<K, V> extends GridCacheMessage<K, V> {
                 if (!reader.isLastRead())
                     return false;
 
-                state++;
+                readState++;
 
         }
 

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/947723c9/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 3b07bc7..6fe4216 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
@@ -659,33 +659,36 @@ public abstract class GridCacheMessage<K, V> extends MessageAdapter {
     /** {@inheritDoc} */
     @SuppressWarnings("all")
     @Override public boolean writeTo(ByteBuffer buf) {
+        MessageWriteState state = MessageWriteState.get();
+        MessageWriter writer = state.writer();
+
         writer.setBuffer(buf);
 
-        if (!typeWritten) {
+        if (!state.isTypeWritten()) {
             if (!writer.writeByte(null, directType()))
                 return false;
 
-            typeWritten = true;
+            state.setTypeWritten();
         }
 
-        switch (state) {
+        switch (state.index()) {
             case 0:
                 if (!writer.writeInt("cacheId", cacheId))
                     return false;
 
-                state++;
+                state.increment();
 
             case 1:
                 if (!writer.writeMessage("depInfo", depInfo))
                     return false;
 
-                state++;
+                state.increment();
 
             case 2:
                 if (!writer.writeLong("msgId", msgId))
                     return false;
 
-                state++;
+                state.increment();
 
         }
 
@@ -697,14 +700,14 @@ public abstract class GridCacheMessage<K, V> extends MessageAdapter {
     @Override public boolean readFrom(ByteBuffer buf) {
         reader.setBuffer(buf);
 
-        switch (state) {
+        switch (readState) {
             case 0:
                 cacheId = reader.readInt("cacheId");
 
                 if (!reader.isLastRead())
                     return false;
 
-                state++;
+                readState++;
 
             case 1:
                 depInfo = reader.readMessage("depInfo");
@@ -712,7 +715,7 @@ public abstract class GridCacheMessage<K, V> extends MessageAdapter {
                 if (!reader.isLastRead())
                     return false;
 
-                state++;
+                readState++;
 
             case 2:
                 msgId = reader.readLong("msgId");
@@ -720,7 +723,7 @@ public abstract class GridCacheMessage<K, V> extends MessageAdapter {
                 if (!reader.isLastRead())
                     return false;
 
-                state++;
+                readState++;
 
         }
 

http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/947723c9/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 03f20c6..5729269 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
@@ -121,27 +121,30 @@ public class GridCacheValueBytes extends MessageAdapter {
 
     /** {@inheritDoc} */
     @Override public boolean writeTo(ByteBuffer buf) {
+        MessageWriteState state = MessageWriteState.get();
+        MessageWriter writer = state.writer();
+
         writer.setBuffer(buf);
 
-        if (!typeWritten) {
+        if (!state.isTypeWritten()) {
             if (!writer.writeByte(null, directType()))
                 return false;
 
-            typeWritten = true;
+            state.setTypeWritten();
         }
 
-        switch (state) {
+        switch (state.index()) {
             case 0:
                 if (!writer.writeByteArray("bytes", bytes))
                     return false;
 
-                state++;
+                state.increment();
 
             case 1:
                 if (!writer.writeBoolean("plain", plain))
                     return false;
 
-                state++;
+                state.increment();
 
         }
 
@@ -152,14 +155,14 @@ public class GridCacheValueBytes extends MessageAdapter {
     @Override public boolean readFrom(ByteBuffer buf) {
         reader.setBuffer(buf);
 
-        switch (state) {
+        switch (readState) {
             case 0:
                 bytes = reader.readByteArray("bytes");
 
                 if (!reader.isLastRead())
                     return false;
 
-                state++;
+                readState++;
 
             case 1:
                 plain = reader.readBoolean("plain");
@@ -167,7 +170,7 @@ public class GridCacheValueBytes extends MessageAdapter {
                 if (!reader.isLastRead())
                     return false;
 
-                state++;
+                readState++;
 
         }
 
@@ -182,11 +185,7 @@ public class GridCacheValueBytes extends MessageAdapter {
     /** {@inheritDoc} */
     @SuppressWarnings("CloneDoesntCallSuperClone")
     @Override public MessageAdapter clone() {
-        GridCacheValueBytes _clone = new GridCacheValueBytes();
-
-        clone0(_clone);
-
-        return _clone;
+        throw new UnsupportedOperationException();
     }
 
     /** {@inheritDoc} */


Mime
View raw message