Repository: incubator-ignite Updated Branches: refs/heads/ignite-61 5de977c64 -> 1e868face
# IGNITE-61 - Direct marshalling Project: http://git-wip-us.apache.org/repos/asf/incubator-ignite/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-ignite/commit/1e868fac Tree: http://git-wip-us.apache.org/repos/asf/incubator-ignite/tree/1e868fac Diff: http://git-wip-us.apache.org/repos/asf/incubator-ignite/diff/1e868fac Branch: refs/heads/ignite-61 Commit: 1e868face9af143d87283793a78a29ff6e054bf6 Parents: 5de977c Author: Valentin Kulichenko <vkuliche...@gridgain.com> Authored: Thu Feb 5 16:51:50 2015 -0800 Committer: Valentin Kulichenko <vkuliche...@gridgain.com> Committed: Thu Feb 5 16:51:50 2015 -0800 ---------------------------------------------------------------------- .../GridClientConnectionManagerAdapter.java | 6 +- .../GridClientHandshakeRequestWrapper.java | 2 +- .../GridClientHandshakeResponseWrapper.java | 22 +---- .../message/GridClientMessageWrapper.java | 25 +++--- .../message/GridClientPingPacketWrapper.java | 17 +--- .../tcp/GridMemcachedMessageWrapper.java | 17 +--- .../protocols/tcp/GridTcpRestDirectParser.java | 9 ++ .../GridTcpCommunicationMessageAdapter.java | 91 -------------------- .../GridTcpCommunicationMessageState.java | 2 - .../spi/communication/GridTestMessage.java | 4 +- 10 files changed, 34 insertions(+), 161 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/1e868fac/modules/core/src/main/java/org/apache/ignite/client/impl/connection/GridClientConnectionManagerAdapter.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/client/impl/connection/GridClientConnectionManagerAdapter.java b/modules/core/src/main/java/org/apache/ignite/client/impl/connection/GridClientConnectionManagerAdapter.java index c09be9a..e87d7e2 100644 --- a/modules/core/src/main/java/org/apache/ignite/client/impl/connection/GridClientConnectionManagerAdapter.java +++ b/modules/core/src/main/java/org/apache/ignite/client/impl/connection/GridClientConnectionManagerAdapter.java @@ -29,6 +29,7 @@ import org.apache.ignite.internal.util.nio.*; import org.apache.ignite.internal.util.nio.ssl.*; import org.apache.ignite.internal.util.typedef.*; import org.apache.ignite.internal.util.typedef.internal.*; +import org.gridgain.grid.util.direct.*; import org.jetbrains.annotations.*; import javax.net.ssl.*; @@ -670,8 +671,11 @@ abstract class GridClientConnectionManagerAdapter implements GridClientConnectio if (msg == null && buf.hasRemaining()) { byte type = buf.get(); - if (type == GridClientMessageWrapper.REQ_HEADER) + if (type == GridClientMessageWrapper.REQ_HEADER) { msg = new GridClientMessageWrapper(); + + msg.setReader(new GridTcpCommunicationMessageReader(null)); + } else throw new IOException("Invalid message type: " + type); } http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/1e868fac/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/client/message/GridClientHandshakeRequestWrapper.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/client/message/GridClientHandshakeRequestWrapper.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/client/message/GridClientHandshakeRequestWrapper.java index e0dd381..1c0366a 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/client/message/GridClientHandshakeRequestWrapper.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/client/message/GridClientHandshakeRequestWrapper.java @@ -100,7 +100,7 @@ public class GridClientHandshakeRequestWrapper extends GridTcpCommunicationMessa /** {@inheritDoc} */ @Override public byte directType() { - return 72; + return HANDSHAKE_HEADER; } /** {@inheritDoc} */ http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/1e868fac/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/client/message/GridClientHandshakeResponseWrapper.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/client/message/GridClientHandshakeResponseWrapper.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/client/message/GridClientHandshakeResponseWrapper.java index 00ebc5f..8bb10a3 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/client/message/GridClientHandshakeResponseWrapper.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/client/message/GridClientHandshakeResponseWrapper.java @@ -57,15 +57,6 @@ public class GridClientHandshakeResponseWrapper extends GridTcpCommunicationMess commState.typeWritten = true; } - switch (commState.idx) { - case 0: - if (!commState.putByte("code", code)) - return false; - - commState.idx++; - - } - return true; } @@ -73,23 +64,12 @@ public class GridClientHandshakeResponseWrapper extends GridTcpCommunicationMess @Override public boolean readFrom(ByteBuffer buf) { commState.setBuffer(buf); - switch (commState.idx) { - case 0: - code = commState.getByte("code"); - - if (!commState.lastRead()) - return false; - - commState.idx++; - - } - return true; } /** {@inheritDoc} */ @Override public byte directType() { - return 73; + return code; } /** {@inheritDoc} */ http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/1e868fac/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/client/message/GridClientMessageWrapper.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/client/message/GridClientMessageWrapper.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/client/message/GridClientMessageWrapper.java index 04edfc7..4ba6a4f 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/client/message/GridClientMessageWrapper.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/client/message/GridClientMessageWrapper.java @@ -141,31 +141,31 @@ public class GridClientMessageWrapper extends GridTcpCommunicationMessageAdapter switch (commState.idx) { case 0: - if (!commState.putUuid("clientId", clientId)) + if (!commState.putInt("msgSize", msgSize)) return false; commState.idx++; case 1: - if (!commState.putUuid("destId", destId)) + if (!commState.putLong("reqId", reqId)) return false; commState.idx++; case 2: - if (!commState.putByteBuffer("msg", msg)) + if (!commState.putUuid("clientId", clientId)) return false; commState.idx++; case 3: - if (!commState.putInt("msgSize", msgSize)) + if (!commState.putUuid("destId", destId)) return false; commState.idx++; case 4: - if (!commState.putLong("reqId", reqId)) + if (!commState.putByteBuffer("msg", msg)) return false; commState.idx++; @@ -181,7 +181,7 @@ public class GridClientMessageWrapper extends GridTcpCommunicationMessageAdapter switch (commState.idx) { case 0: - clientId = commState.getUuid("clientId"); + msgSize = commState.getInt("msgSize"); if (!commState.lastRead()) return false; @@ -189,7 +189,7 @@ public class GridClientMessageWrapper extends GridTcpCommunicationMessageAdapter commState.idx++; case 1: - destId = commState.getUuid("destId"); + reqId = commState.getLong("reqId"); if (!commState.lastRead()) return false; @@ -197,7 +197,7 @@ public class GridClientMessageWrapper extends GridTcpCommunicationMessageAdapter commState.idx++; case 2: - msg = commState.getByteBuffer("msg"); + clientId = commState.getUuid("clientId"); if (!commState.lastRead()) return false; @@ -205,7 +205,7 @@ public class GridClientMessageWrapper extends GridTcpCommunicationMessageAdapter commState.idx++; case 3: - msgSize = commState.getInt("msgSize"); + destId = commState.getUuid("destId"); if (!commState.lastRead()) return false; @@ -213,13 +213,12 @@ public class GridClientMessageWrapper extends GridTcpCommunicationMessageAdapter commState.idx++; case 4: - reqId = commState.getLong("reqId"); + msg = commState.getByteBuffer("msg"); if (!commState.lastRead()) return false; commState.idx++; - } return true; @@ -227,7 +226,7 @@ public class GridClientMessageWrapper extends GridTcpCommunicationMessageAdapter /** {@inheritDoc} */ @Override public byte directType() { - return 74; + return REQ_HEADER; } /** {@inheritDoc} */ @@ -244,8 +243,8 @@ public class GridClientMessageWrapper extends GridTcpCommunicationMessageAdapter @Override protected void clone0(GridTcpCommunicationMessageAdapter _msg) { GridClientMessageWrapper _clone = (GridClientMessageWrapper)_msg; - _clone.msgSize = msgSize; _clone.reqId = reqId; + _clone.msgSize = msgSize; _clone.clientId = clientId; _clone.destId = destId; _clone.msg = msg; http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/1e868fac/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/client/message/GridClientPingPacketWrapper.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/client/message/GridClientPingPacketWrapper.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/client/message/GridClientPingPacketWrapper.java index 9e42be0..6591bd1 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/client/message/GridClientPingPacketWrapper.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/client/message/GridClientPingPacketWrapper.java @@ -57,25 +57,12 @@ public class GridClientPingPacketWrapper extends GridTcpCommunicationMessageAdap /** {@inheritDoc} */ @Override public boolean readFrom(ByteBuffer buf) { - commState.setBuffer(buf); - - switch (commState.idx) { - case 0: - size = commState.getInt("size"); - - if (!commState.lastRead()) - return false; - - commState.idx++; - - } - - return true; + throw new UnsupportedOperationException(); } /** {@inheritDoc} */ @Override public byte directType() { - return 75; + return GridClientMessageWrapper.REQ_HEADER; } /** {@inheritDoc} */ http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/1e868fac/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/protocols/tcp/GridMemcachedMessageWrapper.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/protocols/tcp/GridMemcachedMessageWrapper.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/protocols/tcp/GridMemcachedMessageWrapper.java index 6223e5e..e258375 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/protocols/tcp/GridMemcachedMessageWrapper.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/protocols/tcp/GridMemcachedMessageWrapper.java @@ -86,25 +86,12 @@ public class GridMemcachedMessageWrapper extends GridTcpCommunicationMessageAdap /** {@inheritDoc} */ @Override public boolean readFrom(ByteBuffer buf) { - commState.setBuffer(buf); - - switch (commState.idx) { - case 0: - bytes = commState.getByteArray("bytes"); - - if (!commState.lastRead()) - return false; - - commState.idx++; - - } - - return true; + throw new UnsupportedOperationException(); } /** {@inheritDoc} */ @Override public byte directType() { - return 78; + return MEMCACHE_RES_FLAG; } /** {@inheritDoc} */ http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/1e868fac/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/protocols/tcp/GridTcpRestDirectParser.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/protocols/tcp/GridTcpRestDirectParser.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/protocols/tcp/GridTcpRestDirectParser.java index 7a95fb2..1fc7a0d 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/protocols/tcp/GridTcpRestDirectParser.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/protocols/tcp/GridTcpRestDirectParser.java @@ -23,6 +23,8 @@ import org.apache.ignite.internal.processors.rest.client.message.*; import org.apache.ignite.internal.util.direct.*; import org.apache.ignite.internal.util.nio.*; import org.apache.ignite.internal.util.typedef.internal.*; +import org.apache.ignite.plugin.extensions.communication.*; +import org.gridgain.grid.util.direct.*; import org.jetbrains.annotations.*; import java.io.*; @@ -43,6 +45,9 @@ public class GridTcpRestDirectParser implements GridNioParser { /** Message metadata key. */ private static final int MSG_META_KEY = GridNioSessionMetaKey.nextUniqueKey(); + /** Message reader. */ + private final MessageReader rdr = new GridTcpCommunicationMessageReader(null); + /** Protocol handler. */ private final GridTcpRestProtocol proto; @@ -78,11 +83,15 @@ public class GridTcpRestDirectParser implements GridNioParser { buf.get(); msg = new GridClientMessageWrapper(); + + msg.setReader(rdr); } else if (type == GridClientHandshakeRequestWrapper.HANDSHAKE_HEADER) { buf.get(); msg = new GridClientHandshakeRequestWrapper(); + + msg.setReader(rdr); } else if (type == MEMCACHE_REQ_FLAG) { state = new ParserState(); http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/1e868fac/modules/core/src/main/java/org/apache/ignite/internal/util/direct/GridTcpCommunicationMessageAdapter.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/internal/util/direct/GridTcpCommunicationMessageAdapter.java b/modules/core/src/main/java/org/apache/ignite/internal/util/direct/GridTcpCommunicationMessageAdapter.java index 3580cb7..e414f55 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/util/direct/GridTcpCommunicationMessageAdapter.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/util/direct/GridTcpCommunicationMessageAdapter.java @@ -17,20 +17,12 @@ package org.apache.ignite.internal.util.direct; -import org.apache.ignite.internal.processors.cache.*; -import org.apache.ignite.internal.processors.cache.distributed.dht.preloader.*; -import org.apache.ignite.internal.processors.cache.version.*; -import org.apache.ignite.internal.processors.clock.*; -import org.apache.ignite.internal.util.*; -import org.apache.ignite.lang.*; import org.apache.ignite.plugin.extensions.communication.*; import java.io.*; import java.nio.*; import java.util.*; -import static org.apache.ignite.events.IgniteEventType.*; - /** * Communication message adapter. */ @@ -39,89 +31,6 @@ public abstract class GridTcpCommunicationMessageAdapter implements Serializable private static final long serialVersionUID = 0L; /** */ - public static final byte[] BYTE_ARR_NOT_READ = new byte[0]; - - /** */ - public static final short[] SHORT_ARR_NOT_READ = new short[0]; - - /** */ - public static final int[] INT_ARR_NOT_READ = new int[0]; - - /** */ - public static final long[] LONG_ARR_NOT_READ = new long[0]; - - /** */ - public static final float[] FLOAT_ARR_NOT_READ = new float[0]; - - /** */ - public static final double[] DOUBLE_ARR_NOT_READ = new double[0]; - - /** */ - public static final char[] CHAR_ARR_NOT_READ = new char[0]; - - /** */ - public static final boolean[] BOOLEAN_ARR_NOT_READ = new boolean[0]; - - /** */ - public static final UUID UUID_NOT_READ = new UUID(0, 0); - - /** */ - public static final ByteBuffer BYTE_BUF_NOT_READ = ByteBuffer.allocate(0); - - /** */ - public static final IgniteUuid GRID_UUID_NOT_READ = new IgniteUuid(new UUID(0, 0), 0); - - /** */ - public static final GridClockDeltaVersion CLOCK_DELTA_VER_NOT_READ = new GridClockDeltaVersion(0, 0); - - /** */ - public static final GridByteArrayList BYTE_ARR_LIST_NOT_READ = new GridByteArrayList(new byte[0]); - - /** */ - public static final GridLongList LONG_LIST_NOT_READ = new GridLongList(0); - - /** */ - public static final GridCacheVersion CACHE_VER_NOT_READ = new GridCacheVersion(0, 0, 0, 0); - - /** */ - public static final GridDhtPartitionExchangeId DHT_PART_EXCHANGE_ID_NOT_READ = - new GridDhtPartitionExchangeId(new UUID(0, 0), EVT_NODE_LEFT, 1); - - /** */ - public static final GridCacheValueBytes VAL_BYTES_NOT_READ = new GridCacheValueBytes(); - - /** */ - @SuppressWarnings("RedundantStringConstructorCall") - public static final String STR_NOT_READ = new String(); - - /** */ - public static final BitSet BIT_SET_NOT_READ = new BitSet(); - - /** */ - public static final GridTcpCommunicationMessageAdapter MSG_NOT_READ = new GridTcpCommunicationMessageAdapter() { - @SuppressWarnings("CloneDoesntCallSuperClone") - @Override public GridTcpCommunicationMessageAdapter clone() { - throw new UnsupportedOperationException(); - } - - @Override protected void clone0(GridTcpCommunicationMessageAdapter _msg) { - throw new UnsupportedOperationException(); - } - - @Override public boolean writeTo(ByteBuffer buf) { - throw new UnsupportedOperationException(); - } - - @Override public boolean readFrom(ByteBuffer buf) { - throw new UnsupportedOperationException(); - } - - @Override public byte directType() { - throw new UnsupportedOperationException(); - } - }; - - /** */ protected static final Object NULL = new Object(); /** */ http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/1e868fac/modules/core/src/main/java/org/apache/ignite/internal/util/direct/GridTcpCommunicationMessageState.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/internal/util/direct/GridTcpCommunicationMessageState.java b/modules/core/src/main/java/org/apache/ignite/internal/util/direct/GridTcpCommunicationMessageState.java index f0ac50e..66a8394 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/util/direct/GridTcpCommunicationMessageState.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/util/direct/GridTcpCommunicationMessageState.java @@ -381,8 +381,6 @@ public class GridTcpCommunicationMessageState { if (buf != null) { ByteBuffer buf0 = buf.duplicate(); - buf0.flip(); - arr = new byte[buf0.remaining()]; buf0.get(arr); http://git-wip-us.apache.org/repos/asf/incubator-ignite/blob/1e868fac/modules/core/src/test/java/org/apache/ignite/spi/communication/GridTestMessage.java ---------------------------------------------------------------------- diff --git a/modules/core/src/test/java/org/apache/ignite/spi/communication/GridTestMessage.java b/modules/core/src/test/java/org/apache/ignite/spi/communication/GridTestMessage.java index 945cb13..f36fa58 100644 --- a/modules/core/src/test/java/org/apache/ignite/spi/communication/GridTestMessage.java +++ b/modules/core/src/test/java/org/apache/ignite/spi/communication/GridTestMessage.java @@ -163,7 +163,7 @@ public class GridTestMessage extends GridTcpCommunicationMessageAdapter { case 0: srcNodeId = commState.getUuid(null); - if (srcNodeId == UUID_NOT_READ) + if (!commState.lastRead()) return false; commState.idx++; @@ -187,7 +187,7 @@ public class GridTestMessage extends GridTcpCommunicationMessageAdapter { case 3: payload = commState.getByteArray(null); - if (payload == BYTE_ARR_NOT_READ) + if (!commState.lastRead()) return false; commState.idx++;